]> git.proxmox.com Git - mirror_qemu.git/commitdiff
hw/core: Add machine_class_default_cpu_type()
authorPhilippe Mathieu-Daudé <philmd@linaro.org>
Thu, 16 Nov 2023 16:33:12 +0000 (17:33 +0100)
committerPhilippe Mathieu-Daudé <philmd@linaro.org>
Fri, 5 Jan 2024 15:20:14 +0000 (16:20 +0100)
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>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Message-Id: <20231116163726.28952-1-philmd@linaro.org>

hw/core/machine.c
include/hw/boards.h
system/vl.c

index 2699bcba53576f79eb89610a3d4699366fe83566..0198b54b39774a01f5b587b43a74812f849bd7a8 100644 (file)
@@ -1390,6 +1390,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)
 {
index 8af165f4dc937f29deaff45b5c7d1ed6ccbe75c2..bcfde8a84d1025fa795e65ca46d8b6877b586c80 100644 (file)
@@ -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);
index 6b87bfa32ca7ea19a22a756d9c51887a882941f4..fbdf8bd55aabf4de7681e475eb54630c008feb73 100644 (file)
@@ -3737,7 +3737,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);
     }