* [PATCH-for-9.0] hw/core: Add machine_class_default_cpu_type()
@ 2023-11-16 16:37 Philippe Mathieu-Daudé
2023-11-16 16:48 ` Richard Henderson
0 siblings, 1 reply; 2+ messages in thread
From: Philippe Mathieu-Daudé @ 2023-11-16 16:37 UTC (permalink / raw)
To: qemu-devel
Cc: Gavin Shan, Philippe Mathieu-Daudé, Yanan Wang,
Paolo Bonzini, Eduardo Habkost, Marcel Apfelbaum
Add a helper to return a machine default CPU type.
If this machine is restricted to a single CPU type,
use it as default, obviously.
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
include/hw/boards.h | 6 ++++++
hw/core/machine.c | 8 ++++++++
system/vl.c | 2 +-
3 files changed, 15 insertions(+), 1 deletion(-)
diff --git a/include/hw/boards.h b/include/hw/boards.h
index da85f86efb..160a10036e 100644
--- a/include/hw/boards.h
+++ b/include/hw/boards.h
@@ -24,6 +24,12 @@ OBJECT_DECLARE_TYPE(MachineState, MachineClass, MACHINE)
extern MachineState *current_machine;
+/**
+ * machine_class_default_cpu_type: Return the machine default CPU type.
+ * @mc: Machine class
+ */
+const char *machine_class_default_cpu_type(MachineClass *mc);
+
void machine_add_audiodev_property(MachineClass *mc);
void machine_run_board_init(MachineState *machine, const char *mem_path, Error **errp);
bool machine_usb(MachineState *machine);
diff --git a/hw/core/machine.c b/hw/core/machine.c
index 0c17398141..baf25c3fc5 100644
--- a/hw/core/machine.c
+++ b/hw/core/machine.c
@@ -1387,6 +1387,14 @@ out:
return r;
}
+const char *machine_class_default_cpu_type(MachineClass *mc)
+{
+ if (mc->valid_cpu_types && !mc->valid_cpu_types[1]) {
+ /* Only a single CPU type allowed: use it as default. */
+ return mc->valid_cpu_types[0];
+ }
+ return mc->default_cpu_type;
+}
void machine_run_board_init(MachineState *machine, const char *mem_path, Error **errp)
{
diff --git a/system/vl.c b/system/vl.c
index 5af7ced2a1..1c28162b21 100644
--- a/system/vl.c
+++ b/system/vl.c
@@ -3730,7 +3730,7 @@ void qemu_init(int argc, char **argv)
migration_object_init();
/* parse features once if machine provides default cpu_type */
- current_machine->cpu_type = machine_class->default_cpu_type;
+ current_machine->cpu_type = machine_class_default_cpu_type(machine_class);
if (cpu_option) {
current_machine->cpu_type = parse_cpu_option(cpu_option);
}
--
2.41.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH-for-9.0] hw/core: Add machine_class_default_cpu_type()
2023-11-16 16:37 [PATCH-for-9.0] hw/core: Add machine_class_default_cpu_type() Philippe Mathieu-Daudé
@ 2023-11-16 16:48 ` Richard Henderson
0 siblings, 0 replies; 2+ messages in thread
From: Richard Henderson @ 2023-11-16 16:48 UTC (permalink / raw)
To: Philippe Mathieu-Daudé, qemu-devel
Cc: Gavin Shan, Yanan Wang, Paolo Bonzini, Eduardo Habkost,
Marcel Apfelbaum
On 11/16/23 08:37, Philippe Mathieu-Daudé wrote:
> Add a helper to return a machine default CPU type.
>
> If this machine is restricted to a single CPU type,
> use it as default, obviously.
>
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---
> include/hw/boards.h | 6 ++++++
> hw/core/machine.c | 8 ++++++++
> system/vl.c | 2 +-
> 3 files changed, 15 insertions(+), 1 deletion(-)
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
r~
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-11-16 16:49 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-11-16 16:37 [PATCH-for-9.0] hw/core: Add machine_class_default_cpu_type() Philippe Mathieu-Daudé
2023-11-16 16:48 ` Richard Henderson
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).