From d5f241834be1b323ea697a469ff0f1335a1823fe Mon Sep 17 00:00:00 2001 From: Philippe Mathieu-Daudé Date: Tue, 22 Apr 2025 10:32:31 +0200 Subject: hw/core: Get default_cpu_type calling machine_class_default_cpu_type() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Since commit 62b4a227a33 the default cpu type can come from the valid_cpu_types[] array. Call the machine_class_default_cpu_type() instead of accessing MachineClass::default_cpu_type field. Cc: qemu-stable@nongnu.org Fixes: 62b4a227a33 ("hw/core: Add machine_class_default_cpu_type()") Signed-off-by: Philippe Mathieu-Daudé Reviewed-by: Richard Henderson Reviewed-by: Pierrick Bouvier Reviewed-by: Zhao Liu Message-Id: <20250422084114.39499-1-philmd@linaro.org> --- hw/core/machine-qmp-cmds.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'hw/core/machine-qmp-cmds.c') diff --git a/hw/core/machine-qmp-cmds.c b/hw/core/machine-qmp-cmds.c index fd8b4e0b44..9447e345b3 100644 --- a/hw/core/machine-qmp-cmds.c +++ b/hw/core/machine-qmp-cmds.c @@ -73,6 +73,7 @@ MachineInfoList *qmp_query_machines(bool has_compat_props, bool compat_props, for (el = machines; el; el = el->next) { MachineClass *mc = el->data; + const char *default_cpu_type = machine_class_default_cpu_type(mc); MachineInfo *info; info = g_malloc0(sizeof(*info)); @@ -91,8 +92,8 @@ MachineInfoList *qmp_query_machines(bool has_compat_props, bool compat_props, info->numa_mem_supported = mc->numa_mem_supported; info->deprecated = !!mc->deprecation_reason; info->acpi = !!object_class_property_find(OBJECT_CLASS(mc), "acpi"); - if (mc->default_cpu_type) { - info->default_cpu_type = g_strdup(mc->default_cpu_type); + if (default_cpu_type) { + info->default_cpu_type = g_strdup(default_cpu_type); } if (mc->default_ram_id) { info->default_ram_id = g_strdup(mc->default_ram_id); -- cgit 1.4.1 From 0c9d76f519c0f67506d276c0ee5637bac0b40121 Mon Sep 17 00:00:00 2001 From: Philippe Mathieu-Daudé Date: Wed, 16 Apr 2025 13:25:23 +0200 Subject: qapi: Rename TargetInfo structure as QemuTargetInfo MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The QAPI-generated 'TargetInfo' structure name is only used in a single file. We want to heavily use another structure similarly named. Rename the QAPI one, since structure names are not part of the public API. Suggested-by: Pierrick Bouvier Signed-off-by: Philippe Mathieu-Daudé Reviewed-by: Pierrick Bouvier Reviewed-by: Richard Henderson Reviewed-by: Markus Armbruster Message-Id: <20250422145502.70770-2-philmd@linaro.org> --- hw/core/machine-qmp-cmds.c | 4 ++-- qapi/machine.json | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) (limited to 'hw/core/machine-qmp-cmds.c') diff --git a/hw/core/machine-qmp-cmds.c b/hw/core/machine-qmp-cmds.c index 9447e345b3..a5e635152d 100644 --- a/hw/core/machine-qmp-cmds.c +++ b/hw/core/machine-qmp-cmds.c @@ -134,9 +134,9 @@ CurrentMachineParams *qmp_query_current_machine(Error **errp) return params; } -TargetInfo *qmp_query_target(Error **errp) +QemuTargetInfo *qmp_query_target(Error **errp) { - TargetInfo *info = g_malloc0(sizeof(*info)); + QemuTargetInfo *info = g_malloc0(sizeof(*info)); info->arch = qapi_enum_parse(&SysEmuTarget_lookup, target_name(), -1, &error_abort); diff --git a/qapi/machine.json b/qapi/machine.json index a9ff807631..c8feb9fe17 100644 --- a/qapi/machine.json +++ b/qapi/machine.json @@ -275,15 +275,15 @@ { 'command': 'query-current-machine', 'returns': 'CurrentMachineParams' } ## -# @TargetInfo: +# @QemuTargetInfo: # -# Information describing the QEMU target. +# Information on the target configuration built into the QEMU binary. # # @arch: the target architecture # # Since: 1.2 ## -{ 'struct': 'TargetInfo', +{ 'struct': 'QemuTargetInfo', 'data': { 'arch': 'SysEmuTarget' } } ## @@ -291,11 +291,11 @@ # # Return information about the target for this QEMU # -# Returns: TargetInfo +# Returns: QemuTargetInfo # # Since: 1.2 ## -{ 'command': 'query-target', 'returns': 'TargetInfo' } +{ 'command': 'query-target', 'returns': 'QemuTargetInfo' } ## # @UuidInfo: -- cgit 1.4.1 From 3d881164d4fb2b0f6791cf28d9725926b8ded0d6 Mon Sep 17 00:00:00 2001 From: Philippe Mathieu-Daudé Date: Sun, 23 Mar 2025 12:47:37 +0100 Subject: qemu: Convert target_name() to TargetInfo API MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Have target_name() be a target-agnostic method, dispatching to a per-target TargetInfo singleton structure. By default a stub singleton is used. No logical change expected. Inspired-by: Pierrick Bouvier Signed-off-by: Philippe Mathieu-Daudé Reviewed-by: Pierrick Bouvier Reviewed-by: Richard Henderson Message-Id: <20250424222112.36194-3-philmd@linaro.org> --- MAINTAINERS | 9 +++++++-- cpu-target.c | 5 ----- hw/core/machine-qmp-cmds.c | 1 + include/hw/core/cpu.h | 2 -- include/qemu/target-info-impl.h | 26 ++++++++++++++++++++++++++ include/qemu/target-info.h | 7 +++++++ meson.build | 1 + plugins/loader.c | 2 +- system/vl.c | 2 +- target-info-stub.c | 10 ++++++++++ target-info.c | 16 ++++++++++++++++ 11 files changed, 70 insertions(+), 11 deletions(-) create mode 100644 include/qemu/target-info-impl.h create mode 100644 target-info.c (limited to 'hw/core/machine-qmp-cmds.c') diff --git a/MAINTAINERS b/MAINTAINERS index 59d9712819..f8fee87c70 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -496,7 +496,6 @@ F: include/exec/cpu*.h F: include/exec/exec-all.h F: include/exec/target_long.h F: include/qemu/accel.h -F: include/qemu/target-info*.h F: include/system/accel-*.h F: include/system/cpus.h F: include/accel/accel-cpu*.h @@ -505,7 +504,6 @@ F: accel/Makefile.objs F: accel/stubs/Makefile.objs F: cpu-common.c F: cpu-target.c -F: target-info*.c F: system/cpus.c Apple Silicon HVF CPUs @@ -1928,6 +1926,13 @@ F: tests/functional/test_empty_cpu_model.py F: tests/unit/test-smp-parse.c T: git https://gitlab.com/ehabkost/qemu.git machine-next +TargetInfo API +M: Pierrick Bouvier +M: Philippe Mathieu-Daudé +S: Supported +F: include/qemu/target-info*.h +F: target-info*.c + Xtensa Machines --------------- sim diff --git a/cpu-target.c b/cpu-target.c index b5645ff0db..1c90a30759 100644 --- a/cpu-target.c +++ b/cpu-target.c @@ -91,8 +91,3 @@ bool target_big_endian(void) { return TARGET_BIG_ENDIAN; } - -const char *target_name(void) -{ - return TARGET_NAME; -} diff --git a/hw/core/machine-qmp-cmds.c b/hw/core/machine-qmp-cmds.c index a5e635152d..d82043e1c6 100644 --- a/hw/core/machine-qmp-cmds.c +++ b/hw/core/machine-qmp-cmds.c @@ -19,6 +19,7 @@ #include "qapi/qobject-input-visitor.h" #include "qapi/type-helpers.h" #include "qemu/uuid.h" +#include "qemu/target-info.h" #include "qom/qom-qobject.h" #include "system/hostmem.h" #include "system/hw_accel.h" diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h index 2a02d4f078..12b2ff1f7d 100644 --- a/include/hw/core/cpu.h +++ b/include/hw/core/cpu.h @@ -1121,8 +1121,6 @@ bool cpu_exec_realizefn(CPUState *cpu, Error **errp); void cpu_exec_unrealizefn(CPUState *cpu); void cpu_exec_reset_hold(CPUState *cpu); -const char *target_name(void); - #ifdef COMPILING_PER_TARGET extern const VMStateDescription vmstate_cpu_common; diff --git a/include/qemu/target-info-impl.h b/include/qemu/target-info-impl.h new file mode 100644 index 0000000000..d30805f7f2 --- /dev/null +++ b/include/qemu/target-info-impl.h @@ -0,0 +1,26 @@ +/* + * QEMU TargetInfo structure definition + * + * Copyright (c) Linaro + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#ifndef QEMU_TARGET_INFO_IMPL_H +#define QEMU_TARGET_INFO_IMPL_H + +#include "qemu/target-info.h" + +typedef struct TargetInfo { + /* runtime equivalent of TARGET_NAME definition */ + const char *target_name; +} TargetInfo; + +/** + * target_info: + * + * Returns: The TargetInfo structure definition for this target binary. + */ +const TargetInfo *target_info(void); + +#endif diff --git a/include/qemu/target-info.h b/include/qemu/target-info.h index b4cc4888ca..58d4136897 100644 --- a/include/qemu/target-info.h +++ b/include/qemu/target-info.h @@ -9,6 +9,13 @@ #ifndef QEMU_TARGET_INFO_H #define QEMU_TARGET_INFO_H +/** + * target_name: + * + * Returns: Canonical target name (i.e. "i386"). + */ +const char *target_name(void); + /** * target_cpu_type: * diff --git a/meson.build b/meson.build index 185c2fb0d1..8ae70dbe45 100644 --- a/meson.build +++ b/meson.build @@ -3795,6 +3795,7 @@ endif common_ss.add(pagevary) specific_ss.add(files('page-target.c', 'page-vary-target.c')) +common_ss.add(files('target-info.c')) specific_ss.add(files('target-info-stub.c')) subdir('backends') diff --git a/plugins/loader.c b/plugins/loader.c index 0d6e082e17..8f0d75c904 100644 --- a/plugins/loader.c +++ b/plugins/loader.c @@ -29,7 +29,7 @@ #include "qemu/xxhash.h" #include "qemu/plugin.h" #include "qemu/memalign.h" -#include "hw/core/cpu.h" +#include "qemu/target-info.h" #include "exec/tb-flush.h" #include "plugin.h" diff --git a/system/vl.c b/system/vl.c index 4ab2001df7..520956f4a1 100644 --- a/system/vl.c +++ b/system/vl.c @@ -40,6 +40,7 @@ #include "qemu/help_option.h" #include "qemu/hw-version.h" #include "qemu/uuid.h" +#include "qemu/target-info.h" #include "system/reset.h" #include "system/runstate.h" #include "system/runstate-action.h" @@ -79,7 +80,6 @@ #include "hw/block/block.h" #include "hw/i386/x86.h" #include "hw/i386/pc.h" -#include "hw/core/cpu.h" #include "migration/cpr.h" #include "migration/misc.h" #include "migration/snapshot.h" diff --git a/target-info-stub.c b/target-info-stub.c index e5d2195e89..773a10188c 100644 --- a/target-info-stub.c +++ b/target-info-stub.c @@ -8,8 +8,18 @@ #include "qemu/osdep.h" #include "qemu/target-info.h" +#include "qemu/target-info-impl.h" #include "cpu.h" +static const TargetInfo target_info_stub = { + .target_name = TARGET_NAME, +}; + +const TargetInfo *target_info(void) +{ + return &target_info_stub; +} + const char *target_cpu_type(void) { return CPU_RESOLVING_TYPE; diff --git a/target-info.c b/target-info.c new file mode 100644 index 0000000000..84b18931e7 --- /dev/null +++ b/target-info.c @@ -0,0 +1,16 @@ +/* + * QEMU target info helpers + * + * Copyright (c) Linaro + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include "qemu/osdep.h" +#include "qemu/target-info.h" +#include "qemu/target-info-impl.h" + +const char *target_name(void) +{ + return target_info()->target_name; +} -- cgit 1.4.1