]> git.ipfire.org Git - thirdparty/qemu.git/commitdiff
cpus: Introduce CPUClass::list_cpus() callback
authorPhilippe Mathieu-Daudé <philmd@linaro.org>
Sun, 23 Mar 2025 15:09:06 +0000 (16:09 +0100)
committerPhilippe Mathieu-Daudé <philmd@linaro.org>
Fri, 25 Apr 2025 10:59:09 +0000 (12:59 +0200)
Some targets define cpu_list to a method listing their
CPUs on stdout. In order to make list_cpus() generic,
introduce the CPUClass::list_cpus() callback.
When no callback is registered, list_cpus() defaults
to the cpu_list definition.

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Thomas Huth <thuth@redhat.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Reviewed-by: Zhao Liu <zhao1.liu@intel.com>
Message-Id: <20250324185837.46506-2-philmd@linaro.org>

cpu-target.c
include/hw/core/cpu.h

index 14cd623bffe0b1da45a1b646f584c13ca57fc179..d139a18f5b1bc020680cfa0d81bb52899ba4ae71 100644 (file)
@@ -104,7 +104,13 @@ static void cpu_list(void)
 
 void list_cpus(void)
 {
-    cpu_list();
+    CPUClass *cc = CPU_CLASS(object_class_by_name(CPU_RESOLVING_TYPE));
+
+    if (cc->list_cpus) {
+        cc->list_cpus();
+    } else {
+        cpu_list();
+    }
 }
 
 /* enable or disable single step mode. EXCP_DEBUG is returned by the
index c8d6abff19a6fd4df5c38bf5d97ed7729b8250d8..5b645df59f58fa94eaf19711fcfd73848b265ede 100644 (file)
@@ -102,6 +102,7 @@ struct SysemuCPUOps;
  * CPUClass:
  * @class_by_name: Callback to map -cpu command line model name to an
  *                 instantiatable CPU type.
+ * @list_cpus: list available CPU models and flags.
  * @parse_features: Callback to parse command line arguments.
  * @reset_dump_flags: #CPUDumpFlags to use for reset logging.
  * @memory_rw_debug: Callback for GDB memory access.
@@ -148,6 +149,7 @@ struct CPUClass {
     /*< public >*/
 
     ObjectClass *(*class_by_name)(const char *cpu_model);
+    void (*list_cpus)(void);
     void (*parse_features)(const char *typename, char *str, Error **errp);
 
     int (*memory_rw_debug)(CPUState *cpu, vaddr addr,