diff mbox series

[RFC,v4,18/19] hw/core: Introduce MachineClass::get_default_cpu_type() helper

Message ID 20250422145502.70770-19-philmd@linaro.org
State New
Headers show
Series single-binary: Make hw/arm/ common | expand

Commit Message

Philippe Mathieu-Daudé April 22, 2025, 2:55 p.m. UTC
MachineClass::get_default_cpu_type() runs once the machine is
created, being able to evaluate runtime checks; it returns the
machine default CPU type.

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 include/hw/boards.h |  6 ++++++
 hw/core/machine.c   | 10 ++++++++++
 system/vl.c         |  2 +-
 3 files changed, 17 insertions(+), 1 deletion(-)

Comments

Richard Henderson April 22, 2025, 5:59 p.m. UTC | #1
On 4/22/25 07:55, Philippe Mathieu-Daudé wrote:
> MachineClass::get_default_cpu_type() runs once the machine is
> created, being able to evaluate runtime checks; it returns the
> machine default CPU type.
> 
> Signed-off-by: Philippe Mathieu-Daudé<philmd@linaro.org>
> ---
>   include/hw/boards.h |  6 ++++++
>   hw/core/machine.c   | 10 ++++++++++
>   system/vl.c         |  2 +-
>   3 files changed, 17 insertions(+), 1 deletion(-)

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

r~
Pierrick Bouvier April 22, 2025, 6:24 p.m. UTC | #2
On 4/22/25 10:59, Richard Henderson wrote:
> On 4/22/25 07:55, Philippe Mathieu-Daudé wrote:
>> MachineClass::get_default_cpu_type() runs once the machine is
>> created, being able to evaluate runtime checks; it returns the
>> machine default CPU type.
>>
>> Signed-off-by: Philippe Mathieu-Daudé<philmd@linaro.org>
>> ---
>>    include/hw/boards.h |  6 ++++++
>>    hw/core/machine.c   | 10 ++++++++++
>>    system/vl.c         |  2 +-
>>    3 files changed, 17 insertions(+), 1 deletion(-)
> 
> Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
> 
> r~

Reviewed-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>
diff mbox series

Patch

diff --git a/include/hw/boards.h b/include/hw/boards.h
index be0c0f04804..6a0b02db42e 100644
--- a/include/hw/boards.h
+++ b/include/hw/boards.h
@@ -25,6 +25,11 @@  OBJECT_DECLARE_TYPE(MachineState, MachineClass, MACHINE)
 
 extern MachineState *current_machine;
 
+/**
+ * machine_default_cpu_type: Return the machine default CPU type.
+ * @ms: Machine state
+ */
+const char *machine_default_cpu_type(const MachineState *ms);
 /**
  * machine_class_default_cpu_type: Return the machine default CPU type.
  * @mc: Machine class
@@ -310,6 +315,7 @@  struct MachineClass {
     int numa_mem_align_shift;
     const char * const *valid_cpu_types;
     GSList *(*get_valid_cpu_types)(const MachineState *ms);
+    const char *(*get_default_cpu_type)(const MachineState *ms);
     strList *allowed_dynamic_sysbus_devices;
     bool auto_enable_numa_with_memhp;
     bool auto_enable_numa_with_memdev;
diff --git a/hw/core/machine.c b/hw/core/machine.c
index 8b40735ef98..89169a2dbae 100644
--- a/hw/core/machine.c
+++ b/hw/core/machine.c
@@ -1538,6 +1538,16 @@  const char *machine_class_default_cpu_type(MachineClass *mc)
     return mc->default_cpu_type;
 }
 
+const char *machine_default_cpu_type(const MachineState *ms)
+{
+    MachineClass *mc = MACHINE_GET_CLASS(ms);
+
+    if (mc->get_default_cpu_type) {
+        return mc->get_default_cpu_type(ms);
+    }
+    return machine_class_default_cpu_type(mc);
+}
+
 static bool is_cpu_type_supported(const MachineState *machine, Error **errp)
 {
     MachineClass *mc = MACHINE_GET_CLASS(machine);
diff --git a/system/vl.c b/system/vl.c
index e8706a9ce87..338f9d75289 100644
--- a/system/vl.c
+++ b/system/vl.c
@@ -3825,7 +3825,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(machine_class);
+    current_machine->cpu_type = machine_default_cpu_type(current_machine);
     if (cpu_option) {
         current_machine->cpu_type = parse_cpu_option(cpu_option);
     }