The goal is a single binary that links several targets, where every QOM type is registered once for all of them. Types that share a name go into one bucket per name, each variant tagged with the targets it serves, and the selected target picks the variant at lookup time. For that to work, registering a type and building its class must not depend on which target is selected.
Today some class_init and type_init functions call target_info(), directly or through helpers such as target_s390x(). The result is fixed for the one target selected when the class is built, so the other targets never get their own form of that type. max-v8 called target_aarch64() from its type_init to pick an instance initializer. scsi-hd, scsi-cd, virtio-blk-pci, virtio-net-pci and virtio-mem called target_s390x() or target_arch() from class_init to add properties. The PetaLogix machine called target_big_endian() from class_init to set the default endianness. Instead, each target-specific form becomes its own TypeInfo under the same name. Its is_available callback says which target it belongs to. Today QOM registers only the one that matches; a bucket can later keep all of them. LoongArch and Xtensa virt machines are handled the same way, since both share the virt-machine name. PetaLogix keeps one type: its endianness default is "unspecified" until the machine starts. A few target_*() helpers are added for the new callbacks. v1: https://lore.kernel.org/qemu-devel/[email protected]/ Changes v1 -> v2: - Drop target_not_s390x() from target-info. v1 exported it for scsi-disk, virtio-blk-pci, and virtio-net-pci. Each file keeps a static copy - Drop target_not_base_i386() from target-info. Keep target_base_i386(), and a static target_not_base_i386() in virtio-mem - Split hw/xtensa/virt: select virt machine types with is_available out of the DEFINE_MACHINE expansion, so later only that small patch needs a revert Yonggang Luo (12): target-info: add target_loongarch() hw/loongarch/virt: select virt machine types with is_available target-info: add target_xtensa() hw/xtensa: expand DEFINE_MACHINE in virt.c hw/xtensa/virt: select virt machine types with is_available target/arm: register separate max-v8 CPU types for arm and aarch64 hw/scsi/scsi-disk: register s390x scsi-hd and scsi-cd variants hw/virtio/virtio-pci: pass is_available through VirtioPCIDeviceTypeInfo hw/virtio: register s390x virtio-blk-pci and virtio-net-pci variants target-info: add target_base_i386() hw/virtio/virtio-mem: register legacy-guest variant with is_available hw/microblaze: defer PetaLogix endianness default until init hw/loongarch/virt.c | 3 ++ hw/microblaze/petalogix_s3adsp1800_mmu.c | 11 +++-- hw/pci/pci.c | 13 +++--- hw/scsi/scsi-disk.c | 48 +++++++++++++++++----- hw/virtio/virtio-blk-pci.c | 27 +++++++++++- hw/virtio/virtio-mem.c | 52 +++++++++++++++--------- hw/virtio/virtio-net-pci.c | 27 +++++++++++- hw/virtio/virtio-pci.c | 4 ++ hw/xtensa/virt.c | 20 ++++++++- include/hw/virtio/virtio-mem.h | 2 + include/hw/virtio/virtio-pci.h | 1 + include/qemu/target-info.h | 21 ++++++++++ target-info.c | 27 ++++++++++++ target/arm/cpu.c | 1 + target/arm/cpu.h | 1 + target/arm/tcg/cpu-max-v8.c | 16 ++++++-- 16 files changed, 225 insertions(+), 49 deletions(-) -- 2.55.0.windows.3
