Add a target bitmask to MachineClass, defaulting to QEMU_ARCH_ALL. Update "clipper" machine as a demo/test
Signed-off-by: Yonggang Luo <[email protected]> --- hw/alpha/dp264.c | 2 ++ hw/core/machine.c | 3 +++ include/hw/core/boards.h | 6 ++++++ tests/unit/test-multi-target.c | 33 ++++++++++++++++++++++++++++++++- 4 files changed, 43 insertions(+), 1 deletion(-) diff --git a/hw/alpha/dp264.c b/hw/alpha/dp264.c index f928e0cee82..6be573c88bc 100644 --- a/hw/alpha/dp264.c +++ b/hw/alpha/dp264.c @@ -7,6 +7,7 @@ */ #include "qemu/osdep.h" +#include "qemu/base-arch-defs.h" #include "target/alpha/cpu.h" #include "exec/target_page.h" #include "elf.h" @@ -203,6 +204,7 @@ static void clipper_init(MachineState *machine) static void clipper_machine_init(MachineClass *mc) { + mc->targets = QEMU_ARCH_ALPHA; mc->desc = "Alpha DP264/CLIPPER"; mc->init = clipper_init; mc->block_default_type = IF_IDE; diff --git a/hw/core/machine.c b/hw/core/machine.c index d9ac4b419a3..5c6f3cb0f68 100644 --- a/hw/core/machine.c +++ b/hw/core/machine.c @@ -11,6 +11,7 @@ */ #include "qemu/osdep.h" +#include "qemu/base-arch-defs.h" #include "qemu/units.h" #include "qemu/accel.h" #include "system/replay.h" @@ -1068,6 +1069,8 @@ static void machine_class_init(ObjectClass *oc, const void *data) { MachineClass *mc = MACHINE_CLASS(oc); + mc->targets = QEMU_ARCH_ALL; + /* Default 128 MB as guest ram size */ mc->default_ram_size = 128 * MiB; mc->rom_file_has_mr = true; diff --git a/include/hw/core/boards.h b/include/hw/core/boards.h index d0e4ad98201..d7713c45836 100644 --- a/include/hw/core/boards.h +++ b/include/hw/core/boards.h @@ -186,6 +186,11 @@ typedef struct { * MachineClass: * @deprecation_reason: If set, the machine is marked as deprecated. The * string should provide some clear information about what to use instead. + * @targets: bitmask of EmuTarget values supported by this machine. Each + * target is represented by QEMU_ARCH_BIT(EMU_TARGET_*). + * QEMU_ARCH_* masks may be used when the machine supports every target + * in that architecture family. Defaults to QEMU_ARCH_ALL; machines that + * support a narrower set of targets should declare that set explicitly. * @max_cpus: maximum number of CPUs supported. Default: 1 * @min_cpus: minimum number of CPUs supported. Default: 1 * @default_cpus: number of CPUs instantiated if none are specified. Default: 1 @@ -273,6 +278,7 @@ struct MachineClass { const char *alias; const char *desc; const char *deprecation_reason; + uint64_t targets; void (*init)(MachineState *state); void (*reset)(MachineState *state, ResetType type); diff --git a/tests/unit/test-multi-target.c b/tests/unit/test-multi-target.c index a91fe8e6d07..c2922e0fed5 100644 --- a/tests/unit/test-multi-target.c +++ b/tests/unit/test-multi-target.c @@ -13,6 +13,8 @@ */ #include "qemu/osdep.h" +#include "hw/core/boards.h" +#include "qemu/base-arch-defs.h" #include "qemu/module.h" #include "qemu/target-info.h" #include "qemu/target-info-qom.h" @@ -32,6 +34,17 @@ int (*qemu_main)(void); static GSList *targets; +static bool target_arch_available(uint64_t arch_mask) +{ + for (GSList *l = targets; l; l = l->next) { + const TargetInfo *ti = TARGET_INFO_CLASS(l->data)->target_info; + if (QEMU_ARCH_BIT(ti->target_arch) & arch_mask) { + return true; + } + } + return false; +} + static void test_qom_types_are_unique(void) { g_assert(targets); @@ -41,6 +54,22 @@ static void test_qom_types_are_unique(void) g_assert_true(targets == target_info_qom_get_targets()); } +static void test_machine_targets(void) +{ + ObjectClass *oc; + + oc = object_class_by_name(TYPE_MACHINE); + g_assert_nonnull(oc); + g_assert_cmpuint(MACHINE_CLASS(oc)->targets, ==, QEMU_ARCH_ALL); + + if (target_arch_available(QEMU_ARCH_ALPHA)) { + oc = object_class_by_name(MACHINE_TYPE_NAME("clipper")); + g_assert_nonnull(oc); + g_assert_cmpuint(MACHINE_CLASS(oc)->targets, ==, + QEMU_ARCH_BIT(EMU_TARGET_ALPHA)); + } +} + int main(int argc, char **argv) { g_test_init(&argc, &argv, NULL); @@ -54,6 +83,8 @@ int main(int argc, char **argv) module_call_init(MODULE_INIT_QOM); g_test_add_func("/multi-targets/qom-types-are-unique", - test_qom_types_are_unique); + test_qom_types_are_unique); + g_test_add_func("/multi-targets/machine-targets", + test_machine_targets); return g_test_run(); } -- 2.55.0.windows.3
