Unified CPU type check
Subsystems (2)
v3 cover Unified CPU type check
There are two places where the user specified CPU type is checked to see if it's supported or allowed by the board: machine_run_board_init() and mc->init(). We don't have to maintain two duplicate sets of logic. This series intends to move the check to machine_run_board_init().
PATCH[01] Adds a generic helper cpu_model_from_type() to convert CPU
type name to CPU model name.
PATCH[02-19] Uses cpu_model_from_type() in the individual targets PATCH[20-23] Implements cpu_list() for the missed targets PATCH[24-27] Improves the CPU type validation in machine_run_board_init() PATCH[28-32] Validate the CPU type in machine_run_board_init() for the
individual boards
v1: https://lists.nongnu.org/archive/html/qemu-arm/2023-07/msg00302.html
v2: https://lists.nongnu.org/archive/html/qemu-arm/2023-07/msg00528.html
Testing
=======
With the following command lines, the output messages are varied before and after the series is applied.
./build/qemu-system-aarch64 \
-accel tcg -machine virt,gic-version=3 \
-cpu cortex-a8 -smp maxcpus=2,cpus=1 \
:Before the series is applied:
qemu-system-aarch64: mach-virt: CPU type cortex-a8-arm-cpu not supported
After the series is applied:
qemu-system-aarch64: Invalid CPU type: cortex-a8-arm-cpu The valid models are: cortex-a7, cortex-a15, cortex-a35, cortex-a55,
cortex-a72, cortex-a76, a64fx, neoverse-n1,
neoverse-v1, cortex-a53, cortex-a57, maxChangelog
=========
v3:
* Generic helper cpu_model_from_type() (Igor) * Apply cpu_model_from_type() to the individual targets (Igor) * Implement cpu_list() for the missed targets (Gavin) * Remove mc->valid_cpu_models (Richard) * Separate patch to constify mc->validate_cpu_types (Gavin) v2: * Constify mc->valid_cpu_types (Richard) * Print the supported CPU models, instead of typenames (Peter) * Misc improvements for the hleper to do the check (Igor) * More patches to move the check (Marcin)
Gavin Shan (32):
cpu: Add helper cpu_model_from_type()
target/alpha: Use generic helper to show CPU model names target/arm: Use generic helper to show CPU model names target/avr: Use generic helper to show CPU model names target/cris: Use generic helper to show CPU model names target/hexagon: Use generic helper to show CPU model names target/i386: Use generic helper to show CPU model names target/loongarch: Use generic helper to show CPU model names target/m68k: Use generic helper to show CPU model names target/mips: Use generic helper to show CPU model names target/openrisc: Use generic helper to show CPU model names target/ppc: Use generic helper to show CPU model names target/riscv: Use generic helper to show CPU model names target/rx: Use generic helper to show CPU model names target/s390x: Use generic helper to show CPU model names target/sh4: Use generic helper to show CPU model names target/tricore: Use generic helper to show CPU model names target/sparc: Improve sparc_cpu_class_by_name() target/xtensa: Improve xtensa_cpu_class_by_name() target/hppa: Implement hppa_cpu_list() target/microblaze: Implement microblaze_cpu_list() target/nios2: Implement nios2_cpu_list()
Mark cpu_list() supported on all targets
machine: Constify MachineClass::valid_cpu_types[i]
machine: Use error handling when CPU type is checked
machine: Introduce helper is_cpu_type_supported()
machine: Print CPU model name instead of CPU type name hw/arm/virt: Check CPU type in machine_run_board_init() hw/arm/virt: Hide host CPU model for tcg hw/arm/sbsa-ref: Check CPU type in machine_run_board_init() hw/arm: Check CPU type in machine_run_board_init() hw/riscv/shakti_c: Check CPU type in machine_run_board_init()
bsd-user/main.c | 3 - cpu.c | 19 +++++- hw/arm/bananapi_m2u.c | 12 ++-- hw/arm/cubieboard.c | 12 ++-- hw/arm/mps2-tz.c | 20 ++++-- hw/arm/mps2.c | 25 ++++++-- hw/arm/msf2-som.c | 12 ++-- hw/arm/musca.c | 13 ++-- hw/arm/npcm7xx_boards.c | 13 ++-- hw/arm/orangepi.c | 12 ++-- hw/arm/sbsa-ref.c | 21 +------ hw/arm/virt.c | 23 ++----- hw/core/machine.c | 90 ++++++++++++++++----------- hw/m68k/q800.c | 2 +- hw/riscv/shakti_c.c | 11 ++-- include/hw/boards.h | 2 +- include/hw/core/cpu.h | 12 ++++ target/alpha/cpu.c | 6 +- target/arm/arm-qmp-cmds.c | 6 +- target/arm/helper.c | 12 ++-- target/avr/cpu.c | 23 +++++-- target/cris/cpu.c | 7 +-- target/hexagon/cpu.c | 12 ++-- target/hppa/cpu.c | 19 ++++++ target/hppa/cpu.h | 3 + target/i386/cpu.c | 7 +-- target/loongarch/cpu.c | 5 +- target/loongarch/loongarch-qmp-cmds.c | 3 +- target/m68k/helper.c | 14 ++--- target/microblaze/cpu.c | 20 ++++++ target/microblaze/cpu.h | 3 + target/mips/cpu-defs.c.inc | 9 --- target/mips/cpu.c | 25 +++++++- target/mips/sysemu/mips-qmp-cmds.c | 3 +- target/nios2/cpu.c | 20 ++++++ target/nios2/cpu.h | 3 + target/openrisc/cpu.c | 23 +++---- target/ppc/cpu_init.c | 11 ++-- target/riscv/cpu.c | 23 ++++--- target/riscv/riscv-qmp-cmds.c | 3 +- target/rx/cpu.c | 16 +++-- target/s390x/cpu_models.c | 18 +++--- target/s390x/cpu_models_sysemu.c | 9 ++- target/sh4/cpu.c | 24 +++---- target/sparc/cpu.c | 7 ++- target/tricore/cpu.c | 9 +-- target/tricore/helper.c | 13 ++-- target/xtensa/cpu.c | 9 +-- 48 files changed, 397 insertions(+), 270 deletions(-)
Signature · 1 line
2.41.0
PATCH v3 1/32 cpu: Add helper cpu_model_from_type()
Add helper cpu_model_from_type() to extract the CPU model name from the CPU type name in two circumstances: (1) The CPU type name is the combination of the CPU model name and suffix. (2) The CPU type name is same to the CPU model name.
The helper will be used in the subsequent patches to conver the CPU type name to the CPU model name.
--- cpu.c | 16 ++++++++++++++++ include/hw/core/cpu.h | 12 ++++++++++++ 2 files changed, 28 insertions(+)
cpu.c +16 -0
@@ -284,6 +284,22 @@ const char *parse_cpu_option(const char *cpu_option)return cpu_type; } +char *cpu_model_from_type (const char *typename) +{ +const char *suffix ="-" CPU_RESOLVING_TYPE ; + +if (!object_class_by_name (typename)) { +return NULL ; + } + +if (strlen (typename) >strlen (suffix) && + !strcmp (typename +strlen (typename) -strlen (suffix), suffix)) { +return g_strndup (typename,strlen (typename) -strlen (suffix)); + } + +return g_strdup (typename); +} +void list_cpus (void ) {/* XXX: implement xxx_cpu_list for targets that still miss it */
include/hw/core/cpu.h +12 -0
@@ -657,6 +657,18 @@ CPUState *cpu_create(const char *typename);*/ const char *parse_cpu_option (const char *cpu_option); +/** +* cpu_model_from_type: +* @typename: The CPU type name +* +* Extract the CPU model name from the CPU type name. The +* CPU type name is either the combination of the CPU model +* name and suffix, or same to the CPU model name. +* +* Returns: CPU model name +*/ +char *cpu_model_from_type (const char *typename); +/** * cpu_has_work: * @cpu: The vCPU to check.
Signature · 1 line
2.41.0
Re: [PATCH v3 01/32] cpu: Add helper cpu_model_from_type()
Quoted 6 lines · Gavin Shan
Add helper
cpu_model_from_type()to extract the CPU model name from the CPU type name in two circumstances: (1) The CPU type name is the combination of the CPU model name and suffix. (2) The CPU type name is same to the CPU model name.The helper will be used in the subsequent patches to conver the
"patches to conver" -> "commits to convert"
Quoted 8 lines
CPU type name to the CPU model name.
Suggested-by Igor Mammedov <[email protected]>Signed-off-by Gavin Shan <[email protected]>--- cpu.c | 16 ++++++++++++++++ include/hw/core/cpu.h | 12 ++++++++++++ 2 files changed, 28 insertions(+)
Re: [PATCH v3 01/32] cpu: Add helper cpu_model_from_type()
Quoted 10 lines · Philippe Mathieu-Daudé
Quoted 6 lines · Gavin Shan
Add helper
cpu_model_from_type()to extract the CPU model name from the CPU type name in two circumstances: (1) The CPU type name is the combination of the CPU model name and suffix. (2) The CPU type name is same to the CPU model name.The helper will be used in the subsequent patches to conver the
"patches to conver" -> "commits to convert"
Thanks, it will be fixed in next respin.
Quoted 9 lines
Quoted 8 lines
CPU type name to the CPU model name.
Suggested-by Igor Mammedov <[email protected]>Signed-off-by Gavin Shan <[email protected]>---
cpu.c | 16 ++++++++++++++++
include/hw/core/cpu.h| 12 ++++++++++++2 files changed, 28 insertions(+)
Thanks,
Gavin
PATCH v3 2/32 target/alpha: Use generic helper to show CPU model names
In reply to Gavin ShanFor target/alpha, the CPU type name can be: (1) the combination of the CPU model name and suffix; (2) same to the CPU model name; (3) pre-defined aliases. It's correct to show the CPU model name for (1) or the CPU type name for (2) in cpu_list() because both of them can be resolved by alpha_cpu_class_by_name() successfully.
Lets follow (1) to show the CPU model names, with the suffix stripped. With this, the output is compabitle with all of most cases.
--- target/alpha/cpu.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
target/alpha/cpu.c +4 -2
@@ -89,9 +89,11 @@ static void alpha_cpu_realizefn(DeviceState *dev, Error **errp)static void alpha_cpu_list_entry (gpointer data,gpointer user_data) { -ObjectClass *oc = data; +const char *typename =object_class_get_name (OBJECT_CLASS (data)); +char *model =cpu_model_from_type (typename); -qemu_printf (" %s\n" ,object_class_get_name (oc)); +qemu_printf (" %s\n" , model); +g_free (model); }void alpha_cpu_list (void )
Signature · 1 line
2.41.0
PATCH v3 3/32 target/arm: Use generic helper to show CPU model names
In reply to Gavin ShanFor target/arm, the CPU type name can be: (1) the combination of the CPU model name and suffix; (2) alias "any" corresponding to "max-arm-cpu" when CONFIG_USER_ONLY is enabled. The CPU model names have been already shown in cpu_list() and query_cpu_definitions() by following (1).
Use generic helper cpu_model_from_type() to show the CPU model names. The variable @name is renamed to @model in arm_cpu_list_entry() since it points to the CPU model name instead of the CPU type name.
--- target/arm/arm-qmp-cmds.c | 6 ++---- target/arm/helper.c | 12 +++++------- 2 files changed, 7 insertions(+), 11 deletions(-)
target/arm/arm-qmp-cmds.c +2 -4
@@ -233,12 +233,10 @@ static void arm_cpu_add_definition(gpointer data, gpointer user_data)ObjectClass *oc = data;CpuDefinitionInfoList **cpu_list = user_data;CpuDefinitionInfo *info; -const char *typename; +const char *typename =object_class_get_name (oc); - typename =object_class_get_name (oc); info =g_malloc0 (sizeof (*info)); - info->name =g_strndup (typename, -strlen (typename) -strlen ("-" TYPE_ARM_CPU )); + info->name =cpu_model_from_type (typename); info->q_typename =g_strdup (typename);QAPI_LIST_PREPEND (*cpu_list, info);
target/arm/helper.c +5 -7
@@ -9409,17 +9409,15 @@ static void arm_cpu_list_entry(gpointer data, gpointer user_data) {ObjectClass *oc = data;CPUClass *cc =CPU_CLASS (oc); -const char *typename; -char *name; +const char *typename =object_class_get_name (oc); +char *model =cpu_model_from_type (typename); - typename =object_class_get_name (oc); - name =g_strndup (typename,strlen (typename) -strlen ("-" TYPE_ARM_CPU ));if (cc->deprecation_note) { -qemu_printf (" %s (deprecated)\n" , name); +qemu_printf (" %s (deprecated)\n" , model); }else { -qemu_printf (" %s\n" , name); +qemu_printf (" %s\n" , model); } -g_free (name); +g_free (model); }void arm_cpu_list (void )
Signature · 1 line
2.41.0
PATCH v3 4/32 target/avr: Use generic helper to show CPU model names
In reply to Gavin ShanFor target/avr, the CPU model name is resolved as same to the CPU type name in avr_cpu_class_by_name(). Actually, the CPU model name is the combination of the CPU model name and suffix.
Support the resolution from the combination of CPU model name and suffix to the CPU type name in avr_cpu_class_by_name(), and use the generic helper cpu_model_from_type() to show CPU model names in cpu_list(), with adjusted format to match with other targets.
--- target/avr/cpu.c | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-)
target/avr/cpu.c +18 -5
@@ -157,13 +157,23 @@ static void avr_cpu_initfn(Object *obj)static ObjectClass *avr_cpu_class_by_name (const char *cpu_model) {ObjectClass *oc; +char *typename; oc =object_class_by_name (cpu_model); -if (object_class_dynamic_cast (oc,TYPE_AVR_CPU ) ==NULL || -object_class_is_abstract (oc)) { - oc =NULL ; +if (object_class_dynamic_cast (oc,TYPE_AVR_CPU ) && + !object_class_is_abstract (oc)) { +return oc; } -return oc; + + typename =g_strdup_printf (AVR_CPU_TYPE_NAME ("%s" ), cpu_model); + oc =object_class_by_name (typename); +g_free (typename); +if (object_class_dynamic_cast (oc,TYPE_AVR_CPU ) && + !object_class_is_abstract (oc)) { +return oc; + } + +return NULL ; }static void avr_cpu_dump_state (CPUState *cs,FILE *f,int flags)
@@ -366,14 +376,17 @@ typedef struct AVRCPUInfo {static void avr_cpu_list_entry (gpointer data,gpointer user_data) {const char *typename =object_class_get_name (OBJECT_CLASS (data)); +char *model =cpu_model_from_type (typename); -qemu_printf ("%s\n" , typename); +qemu_printf (" %s\n" , model); +g_free (model); }void avr_cpu_list (void ) {GSList *list; list =object_class_get_list_sorted (TYPE_AVR_CPU , false); +qemu_printf ("Available CPUs:\n" );g_slist_foreach (list, avr_cpu_list_entry,NULL );g_slist_free (list); }
Signature · 1 line
2.41.0
PATCH v3 5/32 target/cris: Use generic helper to show CPU model names
In reply to Gavin ShanFor target/cris, the CPU type name can be: (1) the combination of the CPU model name and suffix; (2) alias "any" corresponding to "crisv32-cris-cpu". The CPU model names have been shown correctly by following (1).
Use generic helper cpu_model_from_type() to show the CPU model names in arm_cpu_list_entry(), and rename @name to @model since it's points to the CPU model name instead of the CPU type name.
--- target/cris/cpu.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
target/cris/cpu.c +3 -4
@@ -122,11 +122,10 @@ static void cris_cpu_list_entry(gpointer data, gpointer user_data) {ObjectClass *oc = data;const char *typename =object_class_get_name (oc); -char *name; +char *model =cpu_model_from_type (typename); - name =g_strndup (typename,strlen (typename) -strlen (CRIS_CPU_TYPE_SUFFIX )); -qemu_printf (" %s\n" , name); -g_free (name); +qemu_printf (" %s\n" , model); +g_free (model); }void cris_cpu_list (void )
Signature · 1 line
2.41.0
PATCH v3 6/32 target/hexagon: Use generic helper to show CPU model names
In reply to Gavin ShanFor target/hexagon, the CPU type name is always the combination of the CPU model name and suffix. The CPU model names have been shown correctly in hexagon_cpu_list_entry().
Use generic helper cpu_model_from_type() to show the CPU model names in hexagon_cpu_list_entry(), and rename @name to @model since it points to the CPU model name instead of the CPU type name.
--- target/hexagon/cpu.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-)
target/hexagon/cpu.c +5 -7
@@ -34,13 +34,11 @@ static void hexagon_v73_cpu_init(Object *obj) { }static void hexagon_cpu_list_entry (gpointer data,gpointer user_data) { -ObjectClass *oc = data; -char *name =g_strdup (object_class_get_name (oc)); -if (g_str_has_suffix (name,HEXAGON_CPU_TYPE_SUFFIX )) { - name[strlen (name) -strlen (HEXAGON_CPU_TYPE_SUFFIX )] ='\0' ; - } -qemu_printf (" %s\n" , name); -g_free (name); +const char *typename =object_class_get_name (OBJECT_CLASS (data)); +char *model =cpu_model_from_type (typename); + +qemu_printf (" %s\n" , model); +g_free (model); }void hexagon_cpu_list (void )
Signature · 1 line
2.41.0
PATCH v3 7/32 target/i386: Use generic helper to show CPU model names
In reply to Gavin ShanFor target/i386, the CPU type name is always the combination of the CPU model name and suffix. The CPU model names have been shown correctly in x86_cpu_list_entry().
Use generic helper cpu_model_from_type() to get the CPU model name from the CPU type name in x86_cpu_class_get_model_name(), and rename @name to @model in x86_cpu_list_entry() since it points to the CPU model name instead of the CPU type name.
--- target/i386/cpu.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
target/i386/cpu.c +3 -4
@@ -1741,8 +1741,7 @@ static char *x86_cpu_class_get_model_name(X86CPUClass *cc) {const char *class_name =object_class_get_name (OBJECT_CLASS (cc));assert (g_str_has_suffix (class_name,X86_CPU_TYPE_SUFFIX )); -return g_strndup (class_name, -strlen (class_name) -strlen (X86_CPU_TYPE_SUFFIX )); +return cpu_model_from_type (class_name); } typedef struct X86CPUVersionDefinition {
@@ -5544,7 +5543,7 @@ static void x86_cpu_list_entry(gpointer data, gpointer user_data) {ObjectClass *oc = data;X86CPUClass *cc =X86_CPU_CLASS (oc); - g_autofree char *name = x86_cpu_class_get_model_name(cc); + g_autofree char *model = x86_cpu_class_get_model_name(cc); g_autofree char *desc = g_strdup(cc->model_description); g_autofree char *alias_of = x86_cpu_class_get_alias_of(cc); g_autofree char *model_id = x86_cpu_class_get_model_id(cc);
@@ -5568,7 +5567,7 @@ static void x86_cpu_list_entry(gpointer data, gpointer user_data) desc =g_strdup_printf ("%s (deprecated)" , olddesc); } -qemu_printf ("x86 %-20s %s\n" , name, desc); +qemu_printf ("x86 %-20s %s\n" , model, desc); }/* list available CPU models and flags */
Signature · 1 line
2.41.0
PATCH v3 8/32 target/loongarch: Use generic helper to show CPU model names
In reply to Gavin ShanFor target/loongarch, the CPU type name can be: (1) the combination of the CPU model name and suffix; (2) same to the CPU model name. The CPU model names have been shown correctly in loongarch_cpu_list_entry() and loongarch_cpu_add_definition() by following (1).
Use generic helper cpu_model_from_type() in above two functions to show the CPU model names. The format of the output from cpu_list() is also adjusted to match with other targets.
--- target/loongarch/cpu.c | 5 ++++- target/loongarch/loongarch-qmp-cmds.c | 3 +-- 2 files changed, 5 insertions(+), 3 deletions(-)
target/loongarch/cpu.c +4 -1
@@ -473,14 +473,17 @@ static void loongarch_la132_initfn(Object *obj)static void loongarch_cpu_list_entry (gpointer data,gpointer user_data) {const char *typename =object_class_get_name (OBJECT_CLASS (data)); +char *model =cpu_model_from_type (typename); -qemu_printf ("%s\n" , typename); +qemu_printf (" %s\n" , model); +g_free (model); }void loongarch_cpu_list (void ) {GSList *list; list =object_class_get_list_sorted (TYPE_LOONGARCH_CPU , false); +qemu_printf ("Available CPUs:\n" );g_slist_foreach (list, loongarch_cpu_list_entry,NULL );g_slist_free (list); }
target/loongarch/loongarch-qmp-cmds.c +1 -2
@@ -17,8 +17,7 @@ static void loongarch_cpu_add_definition(gpointer data, gpointer user_data)CpuDefinitionInfo *info =g_new0 (CpuDefinitionInfo,1 );const char *typename =object_class_get_name (oc); - info->name =g_strndup (typename, -strlen (typename) -strlen ("-" TYPE_LOONGARCH_CPU )); + info->name =cpu_model_from_type (typename); info->q_typename =g_strdup (typename);QAPI_LIST_PREPEND (*cpu_list, info);
Signature · 1 line
2.41.0
PATCH v3 9/32 target/m68k: Use generic helper to show CPU model names
In reply to Gavin ShanFor target/m68k, the CPU type name is always the combination of the CPU model name and suffix. The CPU model names have been shown correctly in m68k_cpu_list_entry().
Use generic helper cpu_model_from_type() to show the CPU model name in m68k_cpu_list_entry(), rename @name to @model since it's for the CPU model name instead of the CPU type name, and adjusted output format to match with other targets.
--- target/m68k/helper.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-)
target/m68k/helper.c +6 -8
@@ -49,14 +49,11 @@ static gint m68k_cpu_list_compare(gconstpointer a, gconstpointer b)static void m68k_cpu_list_entry (gpointer data,gpointer user_data) { -ObjectClass *c = data; -const char *typename; -char *name; - - typename =object_class_get_name (c); - name =g_strndup (typename,strlen (typename) -strlen ("-" TYPE_M68K_CPU )); -qemu_printf ("%s\n" , name); -g_free (name); +const char *typename =object_class_get_name (OBJECT_CLASS (data)); +char *model =cpu_model_from_type (typename); + +qemu_printf (" %s\n" , model); +g_free (model); }void m68k_cpu_list (void )
@@ -65,6 +62,7 @@ void m68k_cpu_list(void) list =object_class_get_list (TYPE_M68K_CPU , false); list =g_slist_sort (list, m68k_cpu_list_compare); +qemu_printf ("Available CPUs:\n" );g_slist_foreach (list, m68k_cpu_list_entry,NULL );g_slist_free (list); }
Signature · 1 line
2.41.0
PATCH v3 10/32 target/mips: Use generic helper to show CPU model names
In reply to Gavin ShanFor target/mips, the CPU type name is always the combination of the CPU model name and suffix. The CPU model names have been shown correctly in mips_cpu_list(), which fetches the CPU model names from the pre-defined array. It's different from other targets and lack of flexibility.
Implement mips_cpu_list() by fetching the CPU model names from the available CPU classes. Besides, the retrieved class needs to be validated before it's returned in mips_cpu_class_by_name(), as other targets do.
--- target/mips/cpu-defs.c.inc | 9 --------- target/mips/cpu.c | 25 ++++++++++++++++++++++++- target/mips/sysemu/mips-qmp-cmds.c | 3 +-- 3 files changed, 25 insertions(+), 12 deletions(-)
target/mips/cpu-defs.c.inc +0 -9
@@ -1018,15 +1018,6 @@ const mips_def_t mips_defs[] = }; const int mips_defs_number = ARRAY_SIZE(mips_defs); -void mips_cpu_list(void) -{ - int i; - - for (i = 0; i < ARRAY_SIZE(mips_defs); i++) { - qemu_printf("MIPS '%s'\n", mips_defs[i].name); - } -} - static void fpu_init (CPUMIPSState *env, const mips_def_t *def) { int i;
target/mips/cpu.c +24 -1
@@ -532,7 +532,12 @@ static ObjectClass *mips_cpu_class_by_name(const char *cpu_model) typename =mips_cpu_type_name (cpu_model); oc =object_class_by_name (typename);g_free (typename); -return oc; +if (object_class_dynamic_cast (oc,TYPE_MIPS_CPU ) && + !object_class_is_abstract (oc)) { +return oc; + } + +return NULL ; }#ifndef CONFIG_USER_ONLY
@@ -566,6 +571,24 @@ static const struct TCGCPUOps mips_tcg_ops = { };#endif /* CONFIG_TCG */ +static void mips_cpu_list_entry (gpointer data,gpointer user_data) +{ +const char *typename =object_class_get_name (OBJECT_CLASS (data)); +char *model =cpu_model_from_type (typename); + +qemu_printf (" %s\n" , model); +g_free (model); +} + +void mips_cpu_list (void ) +{ +GSList *list; + list =object_class_get_list_sorted (TYPE_MIPS_CPU , false); +qemu_printf ("Available CPUs:\n" ); +g_slist_foreach (list, mips_cpu_list_entry,NULL ); +g_slist_free (list); +} +static void mips_cpu_class_init (ObjectClass *c,void *data) {MIPSCPUClass *mcc =MIPS_CPU_CLASS (c);
target/mips/sysemu/mips-qmp-cmds.c +1 -2
@@ -19,8 +19,7 @@ static void mips_cpu_add_definition(gpointer data, gpointer user_data) typename =object_class_get_name (oc); info =g_malloc0 (sizeof (*info)); - info->name =g_strndup (typename, -strlen (typename) -strlen ("-" TYPE_MIPS_CPU )); + info->name =cpu_model_from_type (typename); info->q_typename =g_strdup (typename);QAPI_LIST_PREPEND (*cpu_list, info);
Signature · 1 line
2.41.0
PATCH v3 11/32 target/openrisc: Use generic helper to show CPU model names
In reply to Gavin ShanFor target/openrisc, the CPU type name is always the combination of the CPU model name and suffix. The CPU model names have been correctly shown in openrisc_cpu_list_entry().
Use generic helper cpu_model_from_type() to show the CPU model names in openrisc_cpu_list_entry(), and @name is renamed to @model since it points to the CPU model name instead of the CPU type name. Besides, openrisc_cpu_class_by_name() is simplified since the condtion of '@oc == NULL' has been covered by object_class_dynamic_cast().
--- target/openrisc/cpu.c | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-)
target/openrisc/cpu.c +10 -13
@@ -168,11 +168,12 @@ static ObjectClass *openrisc_cpu_class_by_name(const char *cpu_model) typename =g_strdup_printf (OPENRISC_CPU_TYPE_NAME ("%s" ), cpu_model); oc =object_class_by_name (typename);g_free (typename); -if (oc !=NULL && (!object_class_dynamic_cast (oc,TYPE_OPENRISC_CPU ) || -object_class_is_abstract (oc))) { -return NULL ; +if (object_class_dynamic_cast (oc,TYPE_OPENRISC_CPU ) && + !object_class_is_abstract (oc)) { +return oc; } -return oc; + +return NULL ; }static void or1200_initfn (Object *obj)
@@ -280,15 +281,11 @@ static gint openrisc_cpu_list_compare(gconstpointer a, gconstpointer b)static void openrisc_cpu_list_entry (gpointer data,gpointer user_data) { -ObjectClass *oc = data; -const char *typename; -char *name; - - typename =object_class_get_name (oc); - name =g_strndup (typename, -strlen (typename) -strlen ("-" TYPE_OPENRISC_CPU )); -qemu_printf (" %s\n" , name); -g_free (name); +const char *typename =object_class_get_name (OBJECT_CLASS (data)); +char *model =cpu_model_from_type (typename); + +qemu_printf (" %s\n" , model); +g_free (model); }void cpu_openrisc_list (void )
Signature · 1 line
2.41.0
PATCH v3 12/32 target/ppc: Use generic helper to show CPU model names
In reply to Gavin ShanFor target/ppc, the CPU type name can be: (1) The combination of the CPU model name and suffix; (2) the type name of the class whose PVR matches with the specified one; (3) alias of the CPU model, plus suffix; (4) MachineClass::default_cpu_type when the CPU model name is "max". All the possible information, the CPU model name, aliases of the CPU models and PVRs are all shown in ppc_cpu_list_entry().
Use generic helper cpu_model_from_type() in ppc_cpu_list_entry(), and rename @name to @model since it points to the CPU model name instead of the CPU type name.
--- target/ppc/cpu_init.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-)
target/ppc/cpu_init.c +5 -6
@@ -7019,16 +7019,15 @@ static void ppc_cpu_list_entry(gpointer data, gpointer user_data)PowerPCCPUClass *pcc =POWERPC_CPU_CLASS (oc);DeviceClass *family =DEVICE_CLASS (ppc_cpu_get_family_class (pcc));const char *typename =object_class_get_name (oc); -char *name; +char *model;int i;if (unlikely (strcmp (typename,TYPE_HOST_POWERPC_CPU ) ==0 )) {return ; } - name =g_strndup (typename, -strlen (typename) -strlen (POWERPC_CPU_TYPE_SUFFIX )); -qemu_printf ("PowerPC %-16s PVR %08x\n" , name, pcc->pvr); + model =cpu_model_from_type (typename); +qemu_printf ("PowerPC %-16s PVR %08x\n" , model, pcc->pvr);for (i =0 ; ppc_cpu_aliases[i].alias !=NULL ; i++) {PowerPCCPUAlias *alias = &ppc_cpu_aliases[i];ObjectClass *alias_oc =ppc_cpu_class_by_name (alias->model);
@@ -7045,10 +7044,10 @@ static void ppc_cpu_list_entry(gpointer data, gpointer user_data) alias->alias, family->desc); }else {qemu_printf ("PowerPC %-16s (alias for %s)\n" , - alias->alias, name); + alias->alias, model); } } -g_free (name); +g_free (model); }void ppc_cpu_list (void )
Signature · 1 line
2.41.0
Re: [PATCH v3 12/32] target/ppc: Use generic helper to show CPU model names
Quoted 7 lines · Gavin Shan
For target/ppc, the CPU type name can be: (1) The combination of the CPU model name and suffix; (2) the type name of the class whose PVR matches with the specified one; (3) alias of the CPU model, plus suffix; (4)
MachineClass::default_cpu_typewhen the CPU model name is "max". All the possible information, the CPU model name, aliases of the CPU models and PVRs are all shown inppc_cpu_list_entry().
Quoted 5 lines
Use generic helper
cpu_model_from_type()inppc_cpu_list_entry(), and rename @name to @model since it points to the CPU model name instead of the CPU type name.Signed-off-by Gavin Shan <[email protected]>
Looks good.
With a quick hack adding a valid_cpu_types list to the pseries machine, QEMU reported:
qemu-system-ppc64 -M pseries -cpu 460exb
qemu-system-ppc64: Invalid CPU type: 460exb
The valid types are: 970_v2.2, 970mp_v1.0, 970mp_v1.1, power5+_v2.1, power7_v2.3, power7+_v2.1, power8_v2.0, power8e_v2.1, power8nvl_v1.0, power9_v1.0, power9_v2.0, power9_v2.2, power10_v1.0, power10_v2.0
This would be a great improvement for the PPC boards since the CPU definitions are numerous :
$ install/bin/qemu-system-ppc64 -cpu ? | wc -l 418
and usually, the board only reports that the CPU specified on the command line is not supported.
Thanks,
C.
Quoted 41 lines
--- target/ppc/cpu_init.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-)target/ppc/cpu_init.c +5
-6@@ -7019,16 +7019,15 @@ static void ppc_cpu_list_entry(gpointer data, gpointer user_data)PowerPCCPUClass *pcc =POWERPC_CPU_CLASS (oc);DeviceClass *family =DEVICE_CLASS (ppc_cpu_get_family_class (pcc));const char *typename =object_class_get_name (oc); -char *name; +char *model;int i;if (unlikely (strcmp (typename,TYPE_HOST_POWERPC_CPU ) ==0 )) {return ; } - name =g_strndup (typename, -strlen (typename) -strlen (POWERPC_CPU_TYPE_SUFFIX )); -qemu_printf ("PowerPC %-16s PVR %08x\n" , name, pcc->pvr); + model =cpu_model_from_type (typename); +qemu_printf ("PowerPC %-16s PVR %08x\n" , model, pcc->pvr);for (i =0 ; ppc_cpu_aliases[i].alias !=NULL ; i++) {PowerPCCPUAlias *alias = &ppc_cpu_aliases[i];ObjectClass *alias_oc =ppc_cpu_class_by_name (alias->model);@@ -7045,10 +7044,10 @@ static void ppc_cpu_list_entry(gpointer data, gpointer user_data) alias->alias, family->desc); }else {qemu_printf ("PowerPC %-16s (alias for %s)\n" , - alias->alias, name); + alias->alias, model); } } -g_free (name); +g_free (model); }void ppc_cpu_list (void )
PATCH v3 13/32 target/riscv: Use generic helper to show CPU model names
In reply to Gavin ShanFor target/riscv, the CPU type name is always the combination of the CPU model name and suffix. The CPU model names have been correctly shown in riscv_cpu_list_entry() and riscv_cpu_add_definition()
Use generic helper cpu_mdoel_from_type() to show the CPU model names in the above two functions, and adjusted format of the output from riscv_cpu_list_entry() to match with other targets. Besides, the function riscv_cpu_class_by_name() is improved by renaming @cpuname to @model since it's for the CPU model name, and merging the condtion of "@oc == NULL" to object_class_dynamic_cast().
--- target/riscv/cpu.c | 23 +++++++++++++---------- target/riscv/riscv-qmp-cmds.c | 3 +-- 2 files changed, 14 insertions(+), 12 deletions(-)
target/riscv/cpu.c +13 -10
@@ -612,18 +612,19 @@ static ObjectClass *riscv_cpu_class_by_name(const char *cpu_model) {ObjectClass *oc;char *typename; -char **cpuname; +char **model; - cpuname =g_strsplit (cpu_model,"," ,1 ); - typename =g_strdup_printf (RISCV_CPU_TYPE_NAME ("%s" ), cpuname[0 ]); + model =g_strsplit (cpu_model,"," ,1 ); + typename =g_strdup_printf (RISCV_CPU_TYPE_NAME ("%s" ), model[0 ]); oc =object_class_by_name (typename); -g_strfreev (cpuname); +g_strfreev (model);g_free (typename); -if (!oc || !object_class_dynamic_cast (oc,TYPE_RISCV_CPU ) || -object_class_is_abstract (oc)) { -return NULL ; +if (object_class_dynamic_cast (oc,TYPE_RISCV_CPU ) && + !object_class_is_abstract (oc)) { +return oc; } -return oc; + +return NULL ; }static void riscv_cpu_dump_state (CPUState *cs,FILE *f,int flags)
@@ -2211,9 +2212,10 @@ static gint riscv_cpu_list_compare(gconstpointer a, gconstpointer b)static void riscv_cpu_list_entry (gpointer data,gpointer user_data) {const char *typename =object_class_get_name (OBJECT_CLASS (data)); -int len =strlen (typename) -strlen (RISCV_CPU_TYPE_SUFFIX ); +char *model =cpu_model_from_type (typename); -qemu_printf ("%.*s\n" , len, typename); +qemu_printf (" %s\n" , model); +g_free (model); }void riscv_cpu_list (void )
@@ -2222,6 +2224,7 @@ void riscv_cpu_list(void) list =object_class_get_list (TYPE_RISCV_CPU , false); list =g_slist_sort (list, riscv_cpu_list_compare); +qemu_printf ("Available CPUs:\n" );g_slist_foreach (list, riscv_cpu_list_entry,NULL );g_slist_free (list); }
target/riscv/riscv-qmp-cmds.c +1 -2
@@ -35,8 +35,7 @@ static void riscv_cpu_add_definition(gpointer data, gpointer user_data)const char *typename =object_class_get_name (oc);ObjectClass *dyn_class; - info->name =g_strndup (typename, -strlen (typename) -strlen ("-" TYPE_RISCV_CPU )); + info->name =cpu_model_from_type (typename); info->q_typename =g_strdup (typename); dyn_class =object_class_dynamic_cast (oc,TYPE_RISCV_DYNAMIC_CPU );
Signature · 1 line
2.41.0
Re: [PATCH v3 13/32] target/riscv: Use generic helper to show CPU model names
Quoted 9 lines · Gavin Shan
For target/riscv, the CPU type name is always the combination of the CPU model name and suffix. The CPU model names have been correctly shown in
riscv_cpu_list_entry()andriscv_cpu_add_definition()Use generic helper
cpu_mdoel_from_type()to show the CPU model names in the above two functions, and adjusted format of the output fromriscv_cpu_list_entry()to match with other targets. Besides, the functionriscv_cpu_class_by_name()is improved by renaming @cpuname to @model since it's for the CPU model name, and merging the condtion
typo: "condition"
Quoted 4 lines
of "@oc == NULL" to
object_class_dynamic_cast().Signed-off-by Gavin Shan <[email protected]>---
Tested with "-cpu help" and "query-cpu-definitions". LGTM
Quoted 71 lines
target/riscv/cpu.c | 23 +++++++++++++---------- target/riscv/riscv-qmp-cmds.c | 3 +-- 2 files changed, 14 insertions(+), 12 deletions(-)target/riscv/cpu.c +13
-10@@ -612,18 +612,19 @@ static ObjectClass *riscv_cpu_class_by_name(const char *cpu_model) {ObjectClass *oc;char *typename; -char **cpuname; +char **model; - cpuname =g_strsplit (cpu_model,"," ,1 ); - typename =g_strdup_printf (RISCV_CPU_TYPE_NAME ("%s" ), cpuname[0 ]); + model =g_strsplit (cpu_model,"," ,1 ); + typename =g_strdup_printf (RISCV_CPU_TYPE_NAME ("%s" ), model[0 ]); oc =object_class_by_name (typename); -g_strfreev (cpuname); +g_strfreev (model);g_free (typename); -if (!oc || !object_class_dynamic_cast (oc,TYPE_RISCV_CPU ) || -object_class_is_abstract (oc)) { -return NULL ; +if (object_class_dynamic_cast (oc,TYPE_RISCV_CPU ) && + !object_class_is_abstract (oc)) { +return oc; } -return oc; + +return NULL ; }static void riscv_cpu_dump_state (CPUState *cs,FILE *f,int flags)@@ -2211,9 +2212,10 @@ static gint riscv_cpu_list_compare(gconstpointer a, gconstpointer b)static void riscv_cpu_list_entry (gpointer data,gpointer user_data) {const char *typename =object_class_get_name (OBJECT_CLASS (data)); -int len =strlen (typename) -strlen (RISCV_CPU_TYPE_SUFFIX ); +char *model =cpu_model_from_type (typename); -qemu_printf ("%.*s\n" , len, typename); +qemu_printf (" %s\n" , model); +g_free (model); }void riscv_cpu_list (void )@@ -2222,6 +2224,7 @@ void riscv_cpu_list(void) list =object_class_get_list (TYPE_RISCV_CPU , false); list =g_slist_sort (list, riscv_cpu_list_compare); +qemu_printf ("Available CPUs:\n" );g_slist_foreach (list, riscv_cpu_list_entry,NULL );g_slist_free (list); }target/riscv/riscv-qmp-cmds.c +1
-2@@ -35,8 +35,7 @@ static void riscv_cpu_add_definition(gpointer data, gpointer user_data)const char *typename =object_class_get_name (oc);ObjectClass *dyn_class; - info->name =g_strndup (typename, -strlen (typename) -strlen ("-" TYPE_RISCV_CPU )); + info->name =cpu_model_from_type (typename); info->q_typename =g_strdup (typename); dyn_class =object_class_dynamic_cast (oc,TYPE_RISCV_DYNAMIC_CPU );
PATCH v3 14/32 target/rx: Use generic helper to show CPU model names
In reply to Gavin ShanFor target/rx, the CPU type name can be: (1) the combination of the CPU model name and suffix; (2) same to the CPU model name. The CPU type names have been shown in rx_cpu_list_entry().
Use generic helper cpu_model_from_type() to show the CPU model names in rx_cpu_list_entry(). Besides, rx_cpu_class_by_name() is improved by merging the condition of '@oc == NULL' to object_class_dynamic_cast().
--- target/rx/cpu.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-)
target/rx/cpu.c +10 -6
@@ -91,9 +91,11 @@ static void rx_cpu_reset_hold(Object *obj)static void rx_cpu_list_entry (gpointer data,gpointer user_data) { -ObjectClass *oc = data; +const char *typename =object_class_get_name (OBJECT_CLASS (data)); +char *model =cpu_model_from_type (typename); -qemu_printf (" %s\n" ,object_class_get_name (oc)); +qemu_printf (" %s\n" , model); +g_free (model); }void rx_cpu_list (void )
@@ -111,18 +113,20 @@ static ObjectClass *rx_cpu_class_by_name(const char *cpu_model)char *typename; oc =object_class_by_name (cpu_model); -if (oc !=NULL &&object_class_dynamic_cast (oc,TYPE_RX_CPU ) !=NULL && +if (object_class_dynamic_cast (oc,TYPE_RX_CPU ) && !object_class_is_abstract (oc)) {return oc; } + typename =g_strdup_printf (RX_CPU_TYPE_NAME ("%s" ), cpu_model); oc =object_class_by_name (typename);g_free (typename); -if (oc !=NULL &&object_class_is_abstract (oc)) { - oc =NULL ; +if (object_class_dynamic_cast (oc,TYPE_RX_CPU ) && + !object_class_is_abstract (oc)) { +return oc; } -return oc; +return NULL ; }static void rx_cpu_realize (DeviceState *dev,Error **errp)
Signature · 1 line
2.41.0
PATCH v3 15/32 target/s390x: Use generic helper to show CPU model names
In reply to Gavin ShanFor target/s390x, the CPU type name is always the combination of the CPU modle name and suffix. The CPU model names have been correctly shown in s390_print_cpu_model_list_entry() and create_cpu_model_list().
Use generic helper cpu_model_from_type() to show the CPU model names in the above two functions. Besides, we need validate the CPU class in s390_cpu_class_by_name(), as other targets do.
--- target/s390x/cpu_models.c | 18 +++++++++++------- target/s390x/cpu_models_sysemu.c | 9 ++++----- 2 files changed, 15 insertions(+), 12 deletions(-)
target/s390x/cpu_models.c +11 -7
@@ -338,7 +338,8 @@ static void s390_print_cpu_model_list_entry(gpointer data, gpointer user_data) {const S390CPUClass *scc =S390_CPU_CLASS ((ObjectClass *)data);CPUClass *cc =CPU_CLASS (scc); -char *name =g_strdup (object_class_get_name ((ObjectClass *)data)); +const char *typename =object_class_get_name ((ObjectClass *)data); +char *model =cpu_model_from_type (typename);g_autoptr (GString) details =g_string_new ("" );if (scc->is_static) {
@@ -355,14 +356,12 @@ static void s390_print_cpu_model_list_entry(gpointer data, gpointer user_data)g_string_truncate (details, details->len -2 ); } -/* strip off the -s390x-cpu */ -g_strrstr (name,"-" TYPE_S390_CPU )[0 ] =0 ;if (details->len) { -qemu_printf ("s390 %-15s %-35s (%s)\n" , name, scc->desc, details->str); +qemu_printf ("s390 %-15s %-35s (%s)\n" , model, scc->desc, details->str); }else { -qemu_printf ("s390 %-15s %-35s\n" , name, scc->desc); +qemu_printf ("s390 %-15s %-35s\n" , model, scc->desc); } -g_free (name); +g_free (model); }static gint s390_cpu_list_compare (gconstpointer a,gconstpointer b)
@@ -916,7 +915,12 @@ ObjectClass *s390_cpu_class_by_name(const char *name) oc =object_class_by_name (typename);g_free (typename); -return oc; +if (object_class_dynamic_cast (oc,TYPE_S390_CPU ) && + !object_class_is_abstract (oc)) { +return oc; + } + +return NULL ; }static const TypeInfo qemu_s390_cpu_type_info = {
target/s390x/cpu_models_sysemu.c +4 -5
@@ -55,17 +55,16 @@ static void create_cpu_model_list(ObjectClass *klass, void *opaque)struct CpuDefinitionInfoListData *cpu_list_data = opaque;CpuDefinitionInfoList **cpu_list = &cpu_list_data->list;CpuDefinitionInfo *info; -char *name =g_strdup (object_class_get_name (klass)); +const char *typename =object_class_get_name (klass); +char *model =cpu_model_from_type (typename);S390CPUClass *scc =S390_CPU_CLASS (klass); -/* strip off the -s390x-cpu */ -g_strrstr (name,"-" TYPE_S390_CPU )[0 ] =0 ; info =g_new0 (CpuDefinitionInfo,1 ); - info->name = name; + info->name = model; info->has_migration_safe = true; info->migration_safe = scc->is_migration_safe; info->q_static = scc->is_static; - info->q_typename =g_strdup (object_class_get_name (klass)); + info->q_typename =g_strdup (typename);/* check for unavailable features */ if (cpu_list_data->model) {Object *obj;
Signature · 1 line
2.41.0
Re: [PATCH v3 15/32] target/s390x: Use generic helper to show CPU model names
Quoted 47 lines · Gavin Shan
For target/s390x, the CPU type name is always the combination of the CPU modle name and suffix. The CPU model names have been correctly shown in
s390_print_cpu_model_list_entry()andcreate_cpu_model_list().Use generic helper
cpu_model_from_type()to show the CPU model names in the above two functions. Besides, we need validate the CPU class ins390_cpu_class_by_name(), as other targets do.Signed-off-by Gavin Shan <[email protected]>--- target/s390x/cpu_models.c | 18 +++++++++++------- target/s390x/cpu_models_sysemu.c | 9 ++++----- 2 files changed, 15 insertions(+), 12 deletions(-)target/s390x/cpu_models.c +5
-6@@ -338,7 +338,8 @@ static void s390_print_cpu_model_list_entry(gpointer data, gpointer user_data) {const S390CPUClass *scc =S390_CPU_CLASS ((ObjectClass *)data);CPUClass *cc =CPU_CLASS (scc); -char *name =g_strdup (object_class_get_name ((ObjectClass *)data)); +const char *typename =object_class_get_name ((ObjectClass *)data); +char *model =cpu_model_from_type (typename);g_autoptr (GString) details =g_string_new ("" );if (scc->is_static) {@@ -355,14 +356,12 @@ static void s390_print_cpu_model_list_entry(gpointer data, gpointer user_data)g_string_truncate (details, details->len -2 ); } -/* strip off the -s390x-cpu */ -g_strrstr (name,"-" TYPE_S390_CPU )[0 ] =0 ;if (details->len) { -qemu_printf ("s390 %-15s %-35s (%s)\n" , name, scc->desc, details->str); +qemu_printf ("s390 %-15s %-35s (%s)\n" , model, scc->desc, details->str); }else { -qemu_printf ("s390 %-15s %-35s\n" , name, scc->desc); +qemu_printf ("s390 %-15s %-35s\n" , model, scc->desc); } -g_free (name); +g_free (model); }static gint s390_cpu_list_compare (gconstpointer a,gconstpointer b)
target/s390x/cpu_models.c ObjectClass *s390_cpu_class_by_name(const char *name) · line 923
Quoted 10 lines
target/s390x/cpu_models.c +6
-1@@ -916,7 +915,12 @@ ObjectClass *s390_cpu_class_by_name(const char *name) oc =object_class_by_name (typename);g_free (typename); -return oc; +if (object_class_dynamic_cast (oc,TYPE_S390_CPU ) && + !object_class_is_abstract (oc)) { +return oc; + } + +return NULL ;
Why is that change required?
Signature · 3 lines
Cheers, David / dhildenb
Re: [PATCH v3 15/32] target/s390x: Use generic helper to show CPU model names
Quoted 48 lines · David Hildenbrand
Quoted 47 lines · Gavin Shan
For target/s390x, the CPU type name is always the combination of the CPU modle name and suffix. The CPU model names have been correctly shown in
s390_print_cpu_model_list_entry()andcreate_cpu_model_list().Use generic helper
cpu_model_from_type()to show the CPU model names in the above two functions. Besides, we need validate the CPU class ins390_cpu_class_by_name(), as other targets do.Signed-off-by Gavin Shan <[email protected]>---
target/s390x/cpu_models.c | 18 +++++++++++-------target/s390x/cpu_models_sysemu.c| 9 ++++-----2 files changed, 15 insertions(+), 12 deletions(-)target/s390x/cpu_models.c +5
-7@@ -338,7 +338,8 @@ static void s390_print_cpu_model_list_entry(gpointer data, gpointer user_data) { const S390CPUClass *scc = S390_CPU_CLASS((ObjectClass *)data); CPUClass *cc = CPU_CLASS(scc); - char *name = g_strdup(object_class_get_name((ObjectClass *)data)); + const char *typename = object_class_get_name((ObjectClass *)data); + char *model = cpu_model_from_type(typename); g_autoptr(GString) details = g_string_new(""); if (scc->is_static) {@@ -355,14 +356,12 @@ static void s390_print_cpu_model_list_entry(gpointer data, gpointer user_data) g_string_truncate(details, details->len - 2); } - /* strip off the -s390x-cpu */ - g_strrstr(name, "-" TYPE_S390_CPU)[0] = 0; if (details->len) { - qemu_printf("s390 %-15s %-35s (%s)\n", name, scc->desc, details->str); + qemu_printf("s390 %-15s %-35s (%s)\n", model, scc->desc, details->str); } else { - qemu_printf("s390 %-15s %-35s\n", name, scc->desc); + qemu_printf("s390 %-15s %-35s\n", model, scc->desc); } - g_free(name); + g_free(model); } static gint s390_cpu_list_compare(gconstpointer a, gconstpointer b)@@ -916,7 +915,12 @@ ObjectClass *s390_cpu_class_by_name(const char *name) oc = object_class_by_name(typename); g_free(typename); - return oc;
Quoted 9 lines
target/s390x/cpu_models.c ObjectClass *s390_cpu_class_by_name(const char *name) · line 923
Quoted 6 lines
target/s390x/cpu_models.c +6
-0+ if (object_class_dynamic_cast(oc, TYPE_S390_CPU) && + !object_class_is_abstract(oc)) { + return oc; + } + + return NULL;Why is that change required?
Good question. It's possible that other class's name conflicts with CPU class's name. For example, class "abc-base-s390x-cpu" has been registered for a misc class other than a CPU class. We don't want s390_cpu_class_by_name() return the class for "abc-base-s390x-cpu". Almost all other target does similar check.
Thanks,
Gavin
Re: [PATCH v3 15/32] target/s390x: Use generic helper to show CPU model names
Quoted 65 lines · Gavin Shan
Quoted 53 lines · David Hildenbrand
Quoted 52 lines · Gavin Shan
For target/s390x, the CPU type name is always the combination of the CPU modle name and suffix. The CPU model names have been correctly shown in
s390_print_cpu_model_list_entry()andcreate_cpu_model_list().Use generic helper
cpu_model_from_type()to show the CPU model names in the above two functions. Besides, we need validate the CPU class ins390_cpu_class_by_name(), as other targets do.Signed-off-by Gavin Shan <[email protected]>---
target/s390x/cpu_models.c | 18 +++++++++++-------target/s390x/cpu_models_sysemu.c| 9 ++++-----2 files changed, 15 insertions(+), 12 deletions(-)target/s390x/cpu_models.c +5
-6@@ -338,7 +338,8 @@ static void s390_print_cpu_model_list_entry(gpointer data, gpointer user_data) { const S390CPUClass *scc = S390_CPU_CLASS((ObjectClass *)data); CPUClass *cc = CPU_CLASS(scc); - char *name = g_strdup(object_class_get_name((ObjectClass *)data)); + const char *typename = object_class_get_name((ObjectClass *)data); + char *model = cpu_model_from_type(typename); g_autoptr(GString) details = g_string_new(""); if (scc->is_static) {@@ -355,14 +356,12 @@ static void s390_print_cpu_model_list_entry(gpointer data, gpointer user_data) g_string_truncate(details, details->len - 2); } - /* strip off the -s390x-cpu */ - g_strrstr(name, "-" TYPE_S390_CPU)[0] = 0; if (details->len) { - qemu_printf("s390 %-15s %-35s (%s)\n", name, scc->desc, details->str); + qemu_printf("s390 %-15s %-35s (%s)\n", model, scc->desc, details->str); } else { - qemu_printf("s390 %-15s %-35s\n", name, scc->desc); + qemu_printf("s390 %-15s %-35s\n", model, scc->desc); } - g_free(name); + g_free(model); }static gint
s390_cpu_list_compare(gconstpointer a, gconstpointer b)target/s390x/cpu_models.c +0
-1@@ -916,7 +915,12 @@ ObjectClass *s390_cpu_class_by_name(const char *name) oc = object_class_by_name(typename); g_free(typename); - return oc;Quoted 9 lines
target/s390x/cpu_models.c ObjectClass *s390_cpu_class_by_name(const char *name) · line 923
Quoted 6 lines
target/s390x/cpu_models.c +6
-0+ if (object_class_dynamic_cast(oc, TYPE_S390_CPU) && + !object_class_is_abstract(oc)) { + return oc; + } + + return NULL;Why is that change required?
Quoted 5 lines
Good question. It's possible that other class's name conflicts with CPU class's name. For example, class "abc-base-s390x-cpu" has been registered for a misc class other than a CPU class. We don't want
s390_cpu_class_by_name()return the class for "abc-base-s390x-cpu". Almost all other target does similar check.
I agree with David there is some code smell here.
IMO this check belong to cpu_class_by_name(), not to each impl.
Re: [PATCH v3 15/32] target/s390x: Use generic helper to show CPU model names
Quoted 41 lines · Philippe Mathieu-Daudé
Quoted 34 lines · Gavin Shan
Quoted 16 lines · David Hildenbrand
Quoted 13 lines · Gavin Shan
For target/s390x, the CPU type name is always the combination of the CPU modle name and suffix. The CPU model names have been correctly shown in
s390_print_cpu_model_list_entry()andcreate_cpu_model_list().Use generic helper
cpu_model_from_type()to show the CPU model names in the above two functions. Besides, we need validate the CPU class ins390_cpu_class_by_name(), as other targets do.Signed-off-by Gavin Shan <[email protected]>---
target/s390x/cpu_models.c | 18 +++++++++++-------target/s390x/cpu_models_sysemu.c| 9 ++++-----2 files changed, 15 insertions(+), 12 deletions(-)Quoted 15 lines
target/s390x/cpu_models.c ObjectClass *s390_cpu_class_by_name(const char · line 923
Quoted 12 lines
static gint
s390_cpu_list_compare(gconstpointer a, gconstpointer b)target/s390x/cpu_models.c +6
-1@@ -916,7 +915,12 @@ ObjectClass *s390_cpu_class_by_name(const char *name) oc = object_class_by_name(typename); g_free(typename); - return oc; + if (object_class_dynamic_cast(oc, TYPE_S390_CPU) && + !object_class_is_abstract(oc)) { + return oc; + } + + return NULL;Why is that change required?
Quoted 5 lines
Good question. It's possible that other class's name conflicts with CPU class's name. For example, class "abc-base-s390x-cpu" has been registered for a misc class other than a CPU class. We don't want
s390_cpu_class_by_name()return the class for "abc-base-s390x-cpu". Almost all other target does similar check.
Quoted 3 lines
I agree with David there is some code smell here.
IMO this check belong to
cpu_class_by_name(), not to each impl.
Suggestion implemented here:
https://lore.kernel.org/qemu-devel/[email protected]/
Re: [PATCH v3 15/32] target/s390x: Use generic helper to show CPU model names
Quoted 41 lines · Philippe Mathieu-Daudé
Quoted 40 lines · Philippe Mathieu-Daudé
Quoted 38 lines · Gavin Shan
Quoted 16 lines · David Hildenbrand
Quoted 13 lines · Gavin Shan
For target/s390x, the CPU type name is always the combination of the CPU modle name and suffix. The CPU model names have been correctly shown in
s390_print_cpu_model_list_entry()andcreate_cpu_model_list().Use generic helper
cpu_model_from_type()to show the CPU model names in the above two functions. Besides, we need validate the CPU class ins390_cpu_class_by_name(), as other targets do.Signed-off-by Gavin Shan <[email protected]>---
target/s390x/cpu_models.c | 18 +++++++++++-------target/s390x/cpu_models_sysemu.c| 9 ++++-----2 files changed, 15 insertions(+), 12 deletions(-)Quoted 14 lines
target/s390x/cpu_models.c ObjectClass *s390_cpu_class_by_name(const char *name) · line 922
Quoted 11 lines
static gint
s390_cpu_list_compare(gconstpointer a, gconstpointer b)target/s390x/cpu_models.c +6
-1@@ -916,7 +915,12 @@ ObjectClass *s390_cpu_class_by_name(const char *name) oc = object_class_by_name(typename); g_free(typename); - return oc; + if (object_class_dynamic_cast(oc, TYPE_S390_CPU) && + !object_class_is_abstract(oc)) { + return oc; + } + + return NULL;Why is that change required?
Good question. It's possible that other class's name conflicts with CPU class's name. For example, class "abc-base-s390x-cpu" has been registered for a misc class other than a CPU class. We don't want
s390_cpu_class_by_name()return the class for "abc-base-s390x-cpu". Almost all other target does similar check.
Quoted 7 lines
Quoted 3 lines
I agree with David there is some code smell here.
IMO this check belong to
cpu_class_by_name(), not to each impl.Suggestion implemented here:
https://lore.kernel.org/qemu-devel/[email protected]/
Right. That is better way to consolidate the checks. I've provided my comments for your code changes. I believe I need to rebase my v4 series on top your changes. Philippe, please let me know if I need include your patches to my v4 series, modify the code accordingly and send them together for review.
Thanks,
Gavin
Re: [PATCH v3 15/32] target/s390x: Use generic helper to show CPU model names
In reply to Gavin ShanQuoted 2 lines · Gavin Shan
For target/s390x, the CPU type name is always the combination of the CPU modle name and suffix. The CPU model names have been correctly
s/modle/model/
Thomas
Re: [PATCH v3 15/32] target/s390x: Use generic helper to show CPU model names
Quoted 6 lines · Thomas Huth
Quoted 2 lines · Gavin Shan
For target/s390x, the CPU type name is always the combination of the CPU modle name and suffix. The CPU model names have been correctly
s/modle/model/
Thanks, will be fixed in next respin.
Thanks,
Gavin
PATCH v3 16/32 target/sh4: Use generic helper to show CPU model names
In reply to Gavin ShanFor target/sh4, the CPU type name can be: (1) the combination of the CPU model name and suffix; (2) TYPE_SH7750R_CPU when the CPU model name is "any". The CPU model names have been correctly shown in superh_cpu_list_entry().
Use generic helper cpu_model_from_type() to show the CPU model name in the above function. Besides, superh_cpu_class_by_name() is improved by avoiding "goto out" and validating the CPU class.
--- target/sh4/cpu.c | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-)
target/sh4/cpu.c +13 -11
@@ -125,9 +125,10 @@ static void superh_cpu_disas_set_info(CPUState *cpu, disassemble_info *info)static void superh_cpu_list_entry (gpointer data,gpointer user_data) {const char *typename =object_class_get_name (OBJECT_CLASS (data)); -int len =strlen (typename) -strlen (SUPERH_CPU_TYPE_SUFFIX ); +char *model =cpu_model_from_type (typename); -qemu_printf ("%.*s\n" , len, typename); +qemu_printf (" %s\n" , model); +g_free (model); }void sh4_cpu_list (void )
@@ -135,6 +136,7 @@ void sh4_cpu_list(void)GSList *list; list =object_class_get_list_sorted (TYPE_SUPERH_CPU , false); +qemu_printf ("Available CPUs:\n" );g_slist_foreach (list, superh_cpu_list_entry,NULL );g_slist_free (list); }
@@ -146,20 +148,20 @@ static ObjectClass *superh_cpu_class_by_name(const char *cpu_model) s =g_ascii_strdown (cpu_model,-1 );if (strcmp (s,"any" ) ==0 ) { - oc =object_class_by_name (TYPE_SH7750R_CPU ); - goto out; + typename =g_strdup (TYPE_SH7750R_CPU ); + }else { + typename =g_strdup_printf (SUPERH_CPU_TYPE_NAME ("%s" ), s); } - typename =g_strdup_printf (SUPERH_CPU_TYPE_NAME ("%s" ), s); oc =object_class_by_name (typename); -if (oc !=NULL &&object_class_is_abstract (oc)) { - oc =NULL ; - } - -out:g_free (s);g_free (typename); -return oc; +if (object_class_dynamic_cast (oc,TYPE_SUPERH_CPU ) && + !object_class_is_abstract (oc)) { +return oc; + } + +return NULL ; }static void sh7750r_cpu_initfn (Object *obj)
Signature · 1 line
2.41.0
PATCH v3 17/32 target/tricore: Use generic helper to show CPU model names
In reply to Gavin ShanFor target/tricore, the CPU type name is always the combination of the CPU model name and suffix. The CPU model names have been correctly shown in tricore_cpu_list_entry().
Use generic helper cpu_model_from_type() to show the CPU model names in the above function. tricore_cpu_class_by_name() is also improved by merging the condition of '@oc == NULL' to object_class_dynamic_cast().
--- target/tricore/cpu.c | 9 +++++---- target/tricore/helper.c | 13 +++++-------- 2 files changed, 10 insertions(+), 12 deletions(-)
target/tricore/cpu.c +5 -4
@@ -140,11 +140,12 @@ static ObjectClass *tricore_cpu_class_by_name(const char *cpu_model) typename =g_strdup_printf (TRICORE_CPU_TYPE_NAME ("%s" ), cpu_model); oc =object_class_by_name (typename);g_free (typename); -if (!oc || !object_class_dynamic_cast (oc,TYPE_TRICORE_CPU ) || -object_class_is_abstract (oc)) { -return NULL ; +if (object_class_dynamic_cast (oc,TYPE_TRICORE_CPU ) && + !object_class_is_abstract (oc)) { +return oc; } -return oc; + +return NULL ; }static void tc1796_initfn (Object *obj)
target/tricore/helper.c +5 -8
@@ -98,14 +98,11 @@ bool tricore_cpu_tlb_fill(CPUState *cs, vaddr address, int size,static void tricore_cpu_list_entry (gpointer data,gpointer user_data) { -ObjectClass *oc = data; -const char *typename; -char *name; - - typename =object_class_get_name (oc); - name =g_strndup (typename,strlen (typename) -strlen ("-" TYPE_TRICORE_CPU )); -qemu_printf (" %s\n" , name); -g_free (name); +const char *typename =object_class_get_name (OBJECT_CLASS (data)); +char *model =cpu_model_from_type (typename); + +qemu_printf (" %s\n" , model); +g_free (model); }void tricore_cpu_list (void )
Signature · 1 line
2.41.0
Re: [PATCH v3 17/32] target/tricore: Use generic helper to show CPU model names
Quoted 8 lines · Gavin Shan
For target/tricore, the CPU type name is always the combination of the CPU model name and suffix. The CPU model names have been correctly shown in
tricore_cpu_list_entry().Use generic helper
cpu_model_from_type()to show the CPU model names in the above function.tricore_cpu_class_by_name()is also improved by merging the condition of '@oc == NULL' toobject_class_dynamic_cast().
Quoted 5 lines
Signed-off-by Gavin Shan <[email protected]>--- target/tricore/cpu.c | 9 +++++---- target/tricore/helper.c | 13 +++++-------- 2 files changed, 10 insertions(+), 12 deletions(-)
Cheers,
Bastian
PATCH v3 18/32 target/sparc: Improve sparc_cpu_class_by_name()
In reply to Gavin ShanImprove sparc_cpu_class_by_name() by validating @oc, to ensure it's child of TYPE_SPARC_CPU since it's possible for other types of classes to have TYPE_SPARC_CPU as the suffix of their type names.
--- target/sparc/cpu.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
target/sparc/cpu.c +6 -1
@@ -745,7 +745,12 @@ static ObjectClass *sparc_cpu_class_by_name(const char *cpu_model) typename =sparc_cpu_type_name (cpu_model); oc =object_class_by_name (typename);g_free (typename); -return oc; +if (object_class_dynamic_cast (oc,TYPE_SPARC_CPU ) && + !object_class_is_abstract (oc)) { +return oc; + } + +return NULL ; }static void sparc_cpu_realizefn (DeviceState *dev,Error **errp)
Signature · 1 line
2.41.0
PATCH v3 19/32 target/xtensa: Improve xtensa_cpu_class_by_name()
In reply to Gavin ShanImprove xtensa_cpu_class_by_name() by merging the condition of '@oc == NULL' to object_class_dynamic_cast().
--- target/xtensa/cpu.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
target/xtensa/cpu.c +5 -4
@@ -141,11 +141,12 @@ static ObjectClass *xtensa_cpu_class_by_name(const char *cpu_model) typename =g_strdup_printf (XTENSA_CPU_TYPE_NAME ("%s" ), cpu_model); oc =object_class_by_name (typename);g_free (typename); -if (oc ==NULL || !object_class_dynamic_cast (oc,TYPE_XTENSA_CPU ) || -object_class_is_abstract (oc)) { -return NULL ; +if (object_class_dynamic_cast (oc,TYPE_XTENSA_CPU ) && + !object_class_is_abstract (oc)) { +return oc; } -return oc; + +return NULL ; }static void xtensa_cpu_disas_set_info (CPUState *cs,disassemble_info *info)
Signature · 1 line
2.41.0
PATCH v3 20/32 target/hppa: Implement hppa_cpu_list()
In reply to Gavin ShanImplement hppa_cpu_list() to support cpu_list(). With this applied, the available CPU model names, same to the CPU type names, are shown as below.
$ ./build/qemu-system-hppa -cpu ?
Available CPUs:
hppa-cpu--- target/hppa/cpu.c | 19 +++++++++++++++++++ target/hppa/cpu.h | 3 +++ 2 files changed, 22 insertions(+)
target/hppa/cpu.c +19 -0
@@ -143,6 +143,25 @@ static void hppa_cpu_realizefn(DeviceState *dev, Error **errp)#endif } +static void hppa_cpu_list_entry (gpointer data,gpointer user_data) +{ +const char *typename =object_class_get_name (OBJECT_CLASS (data)); +char *model =cpu_model_from_type (typename); + +qemu_printf (" %s\n" , model); +g_free (model); +} + +void hppa_cpu_list (void ) +{ +GSList *list; + + list =object_class_get_list_sorted (TYPE_HPPA_CPU , false); +qemu_printf ("Available CPUs:\n" ); +g_slist_foreach (list, hppa_cpu_list_entry,NULL ); +g_slist_free (list); +} +static void hppa_cpu_initfn (Object *obj) {CPUState *cs =CPU (obj);
target/hppa/cpu.h +3 -0
@@ -351,5 +351,8 @@ void hppa_cpu_alarm_timer(void *);int hppa_artype_for_page (CPUHPPAState *env,target_ulong vaddr);#endif G_NORETURN void hppa_dynamic_excp(CPUHPPAState *env, int excp, uintptr_t ra); +void hppa_cpu_list (void ); + +#define cpu_list hppa_cpu_list#endif /* HPPA_CPU_H */
Signature · 1 line
2.41.0
PATCH v3 21/32 target/microblaze: Implement microblaze_cpu_list()
In reply to Gavin ShanImplement microblaze_cpu_list() to support cpu_list(). With this applied, the available CPU model names, same to the CPU type names, are shown as below.
$ ./build/qemu-system-hppa -cpu ?
Available CPUs:
microblaze-cpu--- target/microblaze/cpu.c | 20 ++++++++++++++++++++ target/microblaze/cpu.h | 3 +++ 2 files changed, 23 insertions(+)
target/microblaze/cpu.c +20 -0
@@ -24,6 +24,7 @@#include "qemu/osdep.h" #include "qemu/log.h" #include "qapi/error.h" +#include "qemu/qemu-print.h" #include "cpu.h" #include "qemu/module.h" #include "hw/qdev-properties.h"
@@ -291,6 +292,25 @@ static void mb_cpu_realizefn(DeviceState *dev, Error **errp) mcc->parent_realize (dev, errp); } +static void microblaze_cpu_list_entry (gpointer data,gpointer user_data) +{ +const char *typename =object_class_get_name (OBJECT_CLASS (data)); +char *model =cpu_model_from_type (typename); + +qemu_printf (" %s\n" , model); +g_free (model); +} + +void microblaze_cpu_list (void ) +{ +GSList *list; + + list =object_class_get_list_sorted (TYPE_MICROBLAZE_CPU , false); +qemu_printf ("Available CPUs:\n" ); +g_slist_foreach (list, microblaze_cpu_list_entry,NULL ); +g_slist_free (list); +} +static void mb_cpu_initfn (Object *obj) {MicroBlazeCPU *cpu =MICROBLAZE_CPU (obj);
target/microblaze/cpu.h +3 -0
@@ -372,6 +372,9 @@ int mb_cpu_gdb_read_register(CPUState *cpu, GByteArray *buf, int reg);int mb_cpu_gdb_write_register (CPUState *cpu,uint8_t *buf,int reg);int mb_cpu_gdb_read_stack_protect (CPUArchState *cpu,GByteArray *buf,int reg);int mb_cpu_gdb_write_stack_protect (CPUArchState *cpu,uint8_t *buf,int reg); +void microblaze_cpu_list (void ); + +#define cpu_list microblaze_cpu_liststatic inline uint32_t mb_cpu_read_msr (const CPUMBState *env) {
Signature · 1 line
2.41.0
PATCH v3 22/32 target/nios2: Implement nios2_cpu_list()
In reply to Gavin ShanImplement nios2_cpu_list() to support cpu_list(). With this applied, the available CPU model names, same to the CPU type names, are shown as below.
$ ./build/qemu-system-nios2 -cpu ?
Available CPUs:
nios2-cpu--- target/nios2/cpu.c | 20 ++++++++++++++++++++ target/nios2/cpu.h | 3 +++ 2 files changed, 23 insertions(+)
target/nios2/cpu.c +20 -0
@@ -21,6 +21,7 @@#include "qemu/osdep.h" #include "qemu/module.h" #include "qapi/error.h" +#include "qemu/qemu-print.h" #include "cpu.h" #include "exec/log.h" #include "gdbstub/helpers.h"
@@ -111,6 +112,25 @@ static void iic_set_irq(void *opaque, int irq, int level) }#endif +static void nios2_cpu_list_entry (gpointer data,gpointer user_data) +{ +const char *typename =object_class_get_name (OBJECT_CLASS (data)); +char *model =cpu_model_from_type (typename); + +qemu_printf (" %s\n" , model); +g_free (model); +} + +void nios2_cpu_list (void ) +{ +GSList *list; + + list =object_class_get_list_sorted (TYPE_NIOS2_CPU , false); +qemu_printf ("Available CPUs:\n" ); +g_slist_foreach (list, nios2_cpu_list_entry,NULL ); +g_slist_free (list); +} +static void nios2_cpu_initfn (Object *obj) {Nios2CPU *cpu =NIOS2_CPU (obj);
target/nios2/cpu.h +3 -0
@@ -292,6 +292,9 @@ bool nios2_cpu_tlb_fill(CPUState *cs, vaddr address, int size, MMUAccessType access_type, int mmu_idx, bool probe, uintptr_t retaddr);#endif +void nios2_cpu_list (void ); + +#define cpu_list nios2_cpu_listtypedef CPUNios2State CPUArchState ;typedef Nios2CPU ArchCPU ;
Signature · 1 line
2.41.0
PATCH v3 23/32 Mark cpu_list() supported on all targets
In reply to Gavin ShanRemove the false conditions and comments since cpu_list() has been supported on all targets.
--- bsd-user/main.c | 3 --- cpu.c | 3 --- 2 files changed, 6 deletions(-)
bsd-user/main.c +0 -3
@@ -378,10 +378,7 @@ int main(int argc, char **argv) }else if (!strcmp (r,"cpu" )) { cpu_model = argv[optind++];if (is_help_option (cpu_model)) { -/* XXX: implement xxx_cpu_list for targets that still miss it */ -#if defined(cpu_list)cpu_list (); -#endif exit (1 ); } }else if (!strcmp (r,"B" )) {
cpu.c +0 -3
@@ -302,10 +302,7 @@ char *cpu_model_from_type(const char *typename)void list_cpus (void ) { -/* XXX: implement xxx_cpu_list for targets that still miss it */ -#if defined(cpu_list)cpu_list (); -#endif }#if defined(CONFIG_USER_ONLY )
Signature · 1 line
2.41.0
PATCH v3 24/32 machine: Constify MachineClass::valid_cpu_types[i]
In reply to Gavin ShanConstify MachineClass::valid_cpu_types[i], as suggested by Richard Henderson.
--- hw/m68k/q800.c | 2 +- include/hw/boards.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
hw/m68k/q800.c +1 -1
@@ -596,7 +596,7 @@ static GlobalProperty hw_compat_q800[] = { };static const size_t hw_compat_q800_len =G_N_ELEMENTS (hw_compat_q800); -static const char *q800_machine_valid_cpu_types[] = { +static const char *const q800_machine_valid_cpu_types[] = {M68K_CPU_TYPE_NAME ("m68040" ),NULL };
include/hw/boards.h +1 -1
@@ -268,7 +268,7 @@ struct MachineClass {bool has_hotpluggable_cpus;bool ignore_memory_transaction_failures;int numa_mem_align_shift; -const char **valid_cpu_types; +const char *const *valid_cpu_types;strList *allowed_dynamic_sysbus_devices;bool auto_enable_numa_with_memhp;bool auto_enable_numa_with_memdev;
Signature · 1 line
2.41.0
Re: [PATCH v3 24/32] machine: Constify MachineClass::valid_cpu_types[i]
Quoted 9 lines · Gavin Shan
Constify MachineClass::valid_cpu_types[i], as suggested by Richard Henderson.
Suggested-by Richard Henderson <[email protected]>Signed-off-by Gavin Shan <[email protected]>--- hw/m68k/q800.c | 2 +- include/hw/boards.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
PATCH v3 25/32 machine: Use error handling when CPU type is checked
In reply to Gavin ShanQEMU will be terminated if the specified CPU type isn't supported in machine_run_board_init(). The list of supported CPU type names is tracked by mc->valid_cpu_types.
The error handling can be used to propagate error messages, to be consistent how the errors are handled for other situations in the same function.
No functional change intended.
--- hw/core/machine.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-)
hw/core/machine.c +8 -6
@@ -1358,6 +1358,7 @@ void machine_run_board_init(MachineState *machine, const char *mem_path, Error *MachineClass *machine_class =MACHINE_GET_CLASS (machine);ObjectClass *oc =object_class_by_name (machine->cpu_type);CPUClass *cc; +Error *local_err =NULL ;/* This checkpoint is required by replay to separate prior clock reading from the other reads, because timer polling functions query
@@ -1426,15 +1427,16 @@ void machine_run_board_init(MachineState *machine, const char *mem_path, Error *if (!machine_class->valid_cpu_types[i]) {/* The user specified CPU is not valid */ -error_report ("Invalid CPU type: %s" , machine->cpu_type); -error_printf ("The valid types are: %s" , - machine_class->valid_cpu_types[0 ]); +error_setg (&local_err,"Invalid CPU type: %s" , machine->cpu_type); +error_append_hint (&local_err,"The valid types are: %s" , + machine_class->valid_cpu_types[0 ]);for (i =1 ; machine_class->valid_cpu_types[i]; i++) { -error_printf (", %s" , machine_class->valid_cpu_types[i]); +error_append_hint (&local_err,", %s" , + machine_class->valid_cpu_types[i]); } -error_printf ("\n" ); +error_append_hint (&local_err,"\n" ); -exit (1 ); +error_propagate (errp, local_err); } }
Signature · 1 line
2.41.0
PATCH v3 26/32 machine: Introduce helper is_cpu_type_supported()
In reply to Gavin ShanThe logic, to check if the specified CPU type is supported in machine_run_board_init(), is independent enough. Factor it out into helper is_cpu_type_supported(). With this, machine_run_board_init() looks a bit clean. Since we're here, @machine_class is renamed to @mc to avoid multiple line spanning of code. The comments are tweaked a bit either.
No functional change intended.
--- hw/core/machine.c | 82 +++++++++++++++++++++++++---------------------- 1 file changed, 44 insertions(+), 38 deletions(-)
hw/core/machine.c +44 -38
@@ -1352,12 +1352,50 @@ out:return r; } +static void is_cpu_type_supported (MachineState *machine,Error **errp) +{ +MachineClass *mc =MACHINE_GET_CLASS (machine); +ObjectClass *oc =object_class_by_name (machine->cpu_type); +CPUClass *cc; +int i; + +/* +* Check if the user specified CPU type is supported when the valid +* CPU types have been determined. Note that the user specified CPU +* type is provided through '-cpu' option. +*/ +if (mc->valid_cpu_types && machine->cpu_type) { +for (i =0 ; mc->valid_cpu_types[i]; i++) { +if (object_class_dynamic_cast (oc, mc->valid_cpu_types[i])) { +break ; + } + } + +/* The user specified CPU type isn't valid */ +if (!mc->valid_cpu_types[i]) { +error_setg (errp,"Invalid CPU type: %s" , machine->cpu_type); +error_append_hint (errp,"The valid types are: %s" , + mc->valid_cpu_types[0 ]); +for (i =1 ; mc->valid_cpu_types[i]; i++) { +error_append_hint (errp,", %s" , mc->valid_cpu_types[i]); + } + +error_append_hint (errp,"\n" ); +return ; + } + } + +/* Check if CPU type is deprecated and warn if so */ + cc =CPU_CLASS (oc); +if (cc && cc->deprecation_note) { +warn_report ("CPU model %s is deprecated -- %s" , + machine->cpu_type, cc->deprecation_note); + } +}void machine_run_board_init (MachineState *machine,const char *mem_path,Error **errp) {MachineClass *machine_class =MACHINE_GET_CLASS (machine); -ObjectClass *oc =object_class_by_name (machine->cpu_type); -CPUClass *cc;Error *local_err =NULL ;/* This checkpoint is required by replay to separate prior clock
@@ -1409,42 +1447,10 @@ void machine_run_board_init(MachineState *machine, const char *mem_path, Error * machine->ram =machine_consume_memdev (machine, machine->memdev); } -/* If the machine supports the valid_cpu_types check and the user -* specified a CPU with -cpu check here that the user CPU is supported. -*/ -if (machine_class->valid_cpu_types && machine->cpu_type) { -int i; - -for (i =0 ; machine_class->valid_cpu_types[i]; i++) { -if (object_class_dynamic_cast (oc, - machine_class->valid_cpu_types[i])) { -/* The user specificed CPU is in the valid field, we are -* good to go. -*/ -break ; - } - } - -if (!machine_class->valid_cpu_types[i]) { -/* The user specified CPU is not valid */ -error_setg (&local_err,"Invalid CPU type: %s" , machine->cpu_type); -error_append_hint (&local_err,"The valid types are: %s" , - machine_class->valid_cpu_types[0 ]); -for (i =1 ; machine_class->valid_cpu_types[i]; i++) { -error_append_hint (&local_err,", %s" , - machine_class->valid_cpu_types[i]); - } -error_append_hint (&local_err,"\n" ); - -error_propagate (errp, local_err); - } - } - -/* Check if CPU type is deprecated and warn if so */ - cc =CPU_CLASS (oc); -if (cc && cc->deprecation_note) { -warn_report ("CPU model %s is deprecated -- %s" , machine->cpu_type, - cc->deprecation_note); +/* Check if the CPU type is supported */ +is_cpu_type_supported (machine, &local_err); +if (local_err) { +error_propagate (errp, local_err); }if (machine->cgs) {
Signature · 1 line
2.41.0
PATCH v3 27/32 machine: Print CPU model name instead of CPU type name
In reply to Gavin ShanThe names of supported CPU models instead of CPU types should be printed when the user specified CPU type isn't supported, to be consistent with the output from '-cpu ?'.
Correct the error messages to print CPU model names instead of CPU type names.
--- hw/core/machine.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-)
hw/core/machine.c +12 -4
@@ -1357,6 +1357,7 @@ static void is_cpu_type_supported(MachineState *machine, Error **errp)MachineClass *mc =MACHINE_GET_CLASS (machine);ObjectClass *oc =object_class_by_name (machine->cpu_type);CPUClass *cc; +char *model;int i;/*
@@ -1373,11 +1374,18 @@ static void is_cpu_type_supported(MachineState *machine, Error **errp)/* The user specified CPU type isn't valid */ if (!mc->valid_cpu_types[i]) { -error_setg (errp,"Invalid CPU type: %s" , machine->cpu_type); -error_append_hint (errp,"The valid types are: %s" , - mc->valid_cpu_types[0 ]); + model =cpu_model_from_type (machine->cpu_type); +error_setg (errp,"Invalid CPU type: %s" , model); +g_free (model); + + model =cpu_model_from_type (mc->valid_cpu_types[0 ]); +error_append_hint (errp,"The valid types are: %s" , model); +g_free (model); +for (i =1 ; mc->valid_cpu_types[i]; i++) { -error_append_hint (errp,", %s" , mc->valid_cpu_types[i]); + model =cpu_model_from_type (mc->valid_cpu_types[i]); +error_append_hint (errp,", %s" , model); +g_free (model); }error_append_hint (errp,"\n" );
Signature · 1 line
2.41.0
Re: [PATCH v3 27/32] machine: Print CPU model name instead of CPU type name
Quoted 21 lines · Gavin Shan
The names of supported CPU models instead of CPU types should be printed when the user specified CPU type isn't supported, to be consistent with the output from '-cpu ?'.
Correct the error messages to print CPU model names instead of CPU type names.
Signed-off-by Gavin Shan <[email protected]>--- hw/core/machine.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-)hw/core/machine.c +1
-3@@ -1373,11 +1374,18 @@ static void is_cpu_type_supported(MachineState *machine, Error **errp)/* The user specified CPU type isn't valid */ if (!mc->valid_cpu_types[i]) { -error_setg (errp,"Invalid CPU type: %s" , machine->cpu_type); -error_append_hint (errp,"The valid types are: %s" , - mc->valid_cpu_types[0 ]); + model =cpu_model_from_type (machine->cpu_type);
hw/core/machine.c static void is_cpu_type_supported(MachineState *machine, Error **errp) · line 1386
Quoted 10 lines
hw/core/machine.c +8
-1+error_setg (errp,"Invalid CPU type: %s" , model); +g_free (model); + + model =cpu_model_from_type (mc->valid_cpu_types[0 ]); +error_append_hint (errp,"The valid types are: %s" , model); +g_free (model); +for (i =1 ; mc->valid_cpu_types[i]; i++) { -error_append_hint (errp,", %s" , mc->valid_cpu_types[i]); + model =cpu_model_from_type (mc->valid_cpu_types[i]);
cpu_model_from_type() can return NULL:
char *cpu_model_from_type(const char *typename)
{
const char *suffix = "-" CPU_RESOLVING_TYPE;
if (!object_class_by_name(typename)) {
return NULL;
}Don't we want to skip that case?
if (!model) {
continue;
}Quoted 5 lines
hw/core/machine.c +2
-0+error_append_hint (errp,", %s" , model); +g_free (model); }error_append_hint (errp,"\n" );
Re: [PATCH v3 27/32] machine: Print CPU model name instead of CPU type name
Quoted 42 lines · Philippe Mathieu-Daudé
Quoted 20 lines · Gavin Shan
The names of supported CPU models instead of CPU types should be printed when the user specified CPU type isn't supported, to be consistent with the output from '-cpu ?'.
Correct the error messages to print CPU model names instead of CPU type names.
Signed-off-by Gavin Shan <[email protected]>---
hw/core/machine.c| 16 ++++++++++++----1 file changed, 12 insertions(+), 4 deletions(-)hw/core/machine.c +1
-3@@ -1373,11 +1374,18 @@ static void is_cpu_type_supported(MachineState *machine, Error **errp) /* The user specified CPU type isn't valid */ if (!mc->valid_cpu_types[i]) { - error_setg(errp, "Invalid CPU type: %s", machine->cpu_type); - error_append_hint(errp, "The valid types are: %s", - mc->valid_cpu_types[0]); + model = cpu_model_from_type(machine->cpu_type);hw/core/machine.c static void is_cpu_type_supported(MachineState *machine, Error **errp) · line 1385
Quoted 10 lines
hw/core/machine.c +8
-1+ error_setg(errp, "Invalid CPU type: %s", model); + g_free(model); + + model = cpu_model_from_type(mc->valid_cpu_types[0]); + error_append_hint(errp, "The valid types are: %s", model); + g_free(model); + for (i = 1; mc->valid_cpu_types[i]; i++) { - error_append_hint(errp, ", %s", mc->valid_cpu_types[i]); + model = cpu_model_from_type(mc->valid_cpu_types[i]);
cpu_model_from_type()can return NULL:char *cpu_model_from_type(const char *typename) {
const char *suffix = "-"CPU_RESOLVING_TYPE;if (!object_class_by_name(typename)) {
return NULL;
}
Quoted 6 lines
Don't we want to skip that case?
if (!model) {
continue;
}
No, it's intentional. "(null)" will be printed in this specific case so that it can be identified quickly and mc->valid_cpu_types[] need to be fixed by developers.
Quoted 5 lines
hw/core/machine.c static void is_cpu_type_supported(MachineState *machine, Error **errp) · line 1391
Quoted 4 lines
hw/core/machine.c +2
-0+ error_append_hint(errp, ", %s", model); + g_free(model); } error_append_hint(errp, "\n");
Thanks,
Gavin
Re: [PATCH v3 27/32] machine: Print CPU model name instead of CPU type name
Quoted 48 lines · Gavin Shan
Quoted 47 lines · Philippe Mathieu-Daudé
Quoted 23 lines · Gavin Shan
The names of supported CPU models instead of CPU types should be printed when the user specified CPU type isn't supported, to be consistent with the output from '-cpu ?'.
Correct the error messages to print CPU model names instead of CPU type names.
Signed-off-by Gavin Shan <[email protected]>---
hw/core/machine.c| 16 ++++++++++++----1 file changed, 12 insertions(+), 4 deletions(-)hw/core/machine.c +2
-3@@ -1373,11 +1374,18 @@ static void is_cpu_type_supported(MachineState *machine, Error **errp) /* The user specified CPU type isn't valid */ if (!mc->valid_cpu_types[i]) { - error_setg(errp, "Invalid CPU type: %s", machine->cpu_type); - error_append_hint(errp, "The valid types are: %s", - mc->valid_cpu_types[0]); + model = cpu_model_from_type(machine->cpu_type); + error_setg(errp, "Invalid CPU type: %s", model);hw/core/machine.c static void · line 1388
Quoted 10 lines
hw/core/machine.c +7
-1+ g_free(model); + + model = cpu_model_from_type(mc->valid_cpu_types[0]); + error_append_hint(errp, "The valid types are: %s", model); + g_free(model); + for (i = 1; mc->valid_cpu_types[i]; i++) { - error_append_hint(errp, ", %s", mc->valid_cpu_types[i]); + model = cpu_model_from_type(mc->valid_cpu_types[i]);
cpu_model_from_type()can return NULL:char *cpu_model_from_type(const char *typename) {
const char *suffix = "-"CPU_RESOLVING_TYPE;if (!object_class_by_name(typename)) {
return NULL;
}Don't we want to skip that case?
Quoted 8 lines
Quoted 4 lines
if (!model) {
continue;
}No, it's intentional. "(null)" will be printed in this specific case so that it can be identified quickly and mc->valid_cpu_types[] need to be fixed by developers.
If you want to help developers, use g_assert().
Re: [PATCH v3 27/32] machine: Print CPU model name instead of CPU type name
Quoted 51 lines · Philippe Mathieu-Daudé
Quoted 50 lines · Gavin Shan
Quoted 48 lines · Philippe Mathieu-Daudé
Quoted 20 lines · Gavin Shan
The names of supported CPU models instead of CPU types should be printed when the user specified CPU type isn't supported, to be consistent with the output from '-cpu ?'.
Correct the error messages to print CPU model names instead of CPU type names.
Signed-off-by Gavin Shan <[email protected]>---
hw/core/machine.c| 16 ++++++++++++----1 file changed, 12 insertions(+), 4 deletions(-)hw/core/machine.c +1
-3@@ -1373,11 +1374,18 @@ static void is_cpu_type_supported(MachineState *machine, Error **errp) /* The user specified CPU type isn't valid */ if (!mc->valid_cpu_types[i]) { - error_setg(errp, "Invalid CPU type: %s", machine->cpu_type); - error_append_hint(errp, "The valid types are: %s", - mc->valid_cpu_types[0]); + model = cpu_model_from_type(machine->cpu_type);hw/core/machine.c static void is_cpu_type_supported(MachineState *machine, Error **errp) · line 1385
Quoted 10 lines
hw/core/machine.c +8
-1+ error_setg(errp, "Invalid CPU type: %s", model); + g_free(model); + + model = cpu_model_from_type(mc->valid_cpu_types[0]); + error_append_hint(errp, "The valid types are: %s", model); + g_free(model); + for (i = 1; mc->valid_cpu_types[i]; i++) { - error_append_hint(errp, ", %s", mc->valid_cpu_types[i]); + model = cpu_model_from_type(mc->valid_cpu_types[i]);
cpu_model_from_type()can return NULL:char *cpu_model_from_type(const char *typename) {
const char *suffix = "-"CPU_RESOLVING_TYPE;if (!object_class_by_name(typename)) {
return NULL;
}Don't we want to skip that case?
if (!model) {
continue;
}
Quoted 6 lines
Quoted 3 lines
No, it's intentional. "(null)" will be printed in this specific case so that it can be identified quickly and mc->valid_cpu_types[] need to be fixed by developers.
If you want to help developers, use
g_assert().
g_assert() wins. It will be included into v4 :)
Thanks,
Gavin
PATCH v3 28/32 hw/arm/virt: Check CPU type in machine_run_board_init()
In reply to Gavin ShanSet mc->valid_cpu_types so that the user specified CPU type can be validated in machine_run_board_init(). We needn't to do the check by ourselves.
--- hw/arm/virt.c | 21 +++------------------ 1 file changed, 3 insertions(+), 18 deletions(-)
hw/arm/virt.c +3 -18
@@ -203,7 +203,7 @@ static const int a15irqmap[] = { [VIRT_PLATFORM_BUS] = 112, /* ...to 112 + PLATFORM_BUS_NUM_IRQS -1 */ }; -static const char *valid_cpus[] = { +static const char *const valid_cpu_types[] = { #ifdef CONFIG_TCGARM_CPU_TYPE_NAME ("cortex-a7" ), ARM_CPU_TYPE_NAME("cortex-a15"),
@@ -219,20 +219,9 @@ static const char *valid_cpus[] = {ARM_CPU_TYPE_NAME ("cortex-a57" ),ARM_CPU_TYPE_NAME ("host" ),ARM_CPU_TYPE_NAME ("max" ), +NULL }; -static bool cpu_type_valid (const char *cpu) -{ -int i; - -for (i =0 ; i <ARRAY_SIZE (valid_cpus); i++) { -if (strcmp (cpu, valid_cpus[i]) ==0 ) { -return true; - } - } -return false; -} -static void create_randomness (MachineState *ms,const char *node) { struct {
@@ -2030,11 +2019,6 @@ static void machvirt_init(MachineState *machine)unsigned int smp_cpus = machine->smp.cpus;unsigned int max_cpus = machine->smp.max_cpus; -if (!cpu_type_valid (machine->cpu_type)) { -error_report ("mach-virt: CPU type %s not supported" , machine->cpu_type); -exit (1 ); - } - possible_cpus = mc->possible_cpu_arch_ids (machine);/*
@@ -2953,6 +2937,7 @@ static void virt_machine_class_init(ObjectClass *oc, void *data)#else mc->default_cpu_type =ARM_CPU_TYPE_NAME ("max" );#endif + mc->valid_cpu_types = valid_cpu_types; mc->get_default_cpu_node_id = virt_get_default_cpu_node_id; mc->kvm_type = virt_kvm_type;assert (!mc->get_hotplug_handler);
Signature · 1 line
2.41.0
Re: [PATCH v3 28/32] hw/arm/virt: Check CPU type in machine_run_board_init()
Quoted 8 lines · Gavin Shan
Set
mc->valid_cpu_typesso that the user specified CPU type can be validated inmachine_run_board_init(). We needn't to do the check by ourselves.Signed-off-by Gavin Shan <[email protected]>--- hw/arm/virt.c | 21 +++------------------ 1 file changed, 3 insertions(+), 18 deletions(-)
PATCH v3 29/32 hw/arm/virt: Hide host CPU model for tcg
In reply to Gavin ShanThe 'host' CPU model isn't available until KVM or HVF is enabled. For example, the following error messages are seen when the guest is started with option '-cpu cortex-a8' on tcg.
qemu-system-aarch64: Invalid CPU type: cortex-a8
The valid types are: cortex-a7, cortex-a15, cortex-a35, cortex-a55,
cortex-a72, cortex-a76, a64fx, neoverse-n1,
neoverse-v1, cortex-a53, cortex-a57, (null),
maxHide 'host' CPU model until KVM or HVF is enabled.
--- hw/arm/virt.c | 2 ++ 1 file changed, 2 insertions(+)
hw/arm/virt.c +2 -0
@@ -217,7 +217,9 @@ static const char * const valid_cpu_types[] = {#endif ARM_CPU_TYPE_NAME("cortex-a53"), ARM_CPU_TYPE_NAME("cortex-a57"), +#if defined(CONFIG_KVM ) || defined(CONFIG_HVF )ARM_CPU_TYPE_NAME ("host" ), +#endifARM_CPU_TYPE_NAME ("max" ),NULL };
Signature · 1 line
2.41.0
PATCH v3 30/32 hw/arm/sbsa-ref: Check CPU type in machine_run_board_init()
In reply to Gavin ShanSet mc->valid_cpu_types so that the user specified CPU type can be validated in machine_run_board_init(). We needn't to do it by ourselves.
--- hw/arm/sbsa-ref.c | 21 +++------------------ 1 file changed, 3 insertions(+), 18 deletions(-)
hw/arm/sbsa-ref.c +3 -18
@@ -149,26 +149,15 @@ static const int sbsa_ref_irqmap[] = { [SBSA_GWDT_WS0] = 16, }; -static const char *const valid_cpus[] = { +static const char *const valid_cpu_types[] = {ARM_CPU_TYPE_NAME ("cortex-a57" ),ARM_CPU_TYPE_NAME ("cortex-a72" ),ARM_CPU_TYPE_NAME ("neoverse-n1" ),ARM_CPU_TYPE_NAME ("neoverse-v1" ),ARM_CPU_TYPE_NAME ("max" ), +NULL , }; -static bool cpu_type_valid (const char *cpu) -{ -int i; - -for (i =0 ; i <ARRAY_SIZE (valid_cpus); i++) { -if (strcmp (cpu, valid_cpus[i]) ==0 ) { -return true; - } - } -return false; -} -static uint64_t sbsa_ref_cpu_mp_affinity (SBSAMachineState *sms,int idx) {uint8_t clustersz =ARM_DEFAULT_CPUS_PER_CLUSTER ;
@@ -730,11 +719,6 @@ static void sbsa_ref_init(MachineState *machine)const CPUArchIdList *possible_cpus;int n, sbsa_max_cpus; -if (!cpu_type_valid (machine->cpu_type)) { -error_report ("sbsa-ref: CPU type %s not supported" , machine->cpu_type); -exit (1 ); - } -if (kvm_enabled ()) {error_report ("sbsa-ref: KVM is not supported for this machine" );exit (1 );
@@ -899,6 +883,7 @@ static void sbsa_ref_class_init(ObjectClass *oc, void *data) mc->init = sbsa_ref_init; mc->desc ="QEMU 'SBSA Reference' ARM Virtual Machine" ; mc->default_cpu_type =ARM_CPU_TYPE_NAME ("neoverse-n1" ); + mc->valid_cpu_types = valid_cpu_types; mc->max_cpus =512 ; mc->pci_allow_0_address = true; mc->minimum_page_bits =12 ;
Signature · 1 line
2.41.0
Re: [PATCH v3 30/32] hw/arm/sbsa-ref: Check CPU type in machine_run_board_init()
Quoted 8 lines · Gavin Shan
Set
mc->valid_cpu_typesso that the user specified CPU type can be validated inmachine_run_board_init(). We needn't to do it by ourselves.Signed-off-by Gavin Shan <[email protected]>--- hw/arm/sbsa-ref.c | 21 +++------------------ 1 file changed, 3 insertions(+), 18 deletions(-)
Re: [PATCH v3 30/32] hw/arm/sbsa-ref: Check CPU type in machine_run_board_init()
In reply to Gavin ShanQuoted 5 lines · Gavin Shan
Set
mc->valid_cpu_typesso that the user specified CPU type can be validated inmachine_run_board_init(). We needn't to do it by ourselves.Signed-off-by Gavin Shan <[email protected]>
Quoted 60 lines
--- hw/arm/sbsa-ref.c | 21 +++------------------ 1 file changed, 3 insertions(+), 18 deletions(-)hw/arm/sbsa-ref.c +3
-18@@ -149,26 +149,15 @@ static const int sbsa_ref_irqmap[] = { [SBSA_GWDT_WS0] = 16, }; -static const char *const valid_cpus[] = { +static const char *const valid_cpu_types[] = {ARM_CPU_TYPE_NAME ("cortex-a57" ),ARM_CPU_TYPE_NAME ("cortex-a72" ),ARM_CPU_TYPE_NAME ("neoverse-n1" ),ARM_CPU_TYPE_NAME ("neoverse-v1" ),ARM_CPU_TYPE_NAME ("max" ), +NULL , }; -static bool cpu_type_valid (const char *cpu) -{ -int i; - -for (i =0 ; i <ARRAY_SIZE (valid_cpus); i++) { -if (strcmp (cpu, valid_cpus[i]) ==0 ) { -return true; - } - } -return false; -} -static uint64_t sbsa_ref_cpu_mp_affinity (SBSAMachineState *sms,int idx) {uint8_t clustersz =ARM_DEFAULT_CPUS_PER_CLUSTER ;@@ -730,11 +719,6 @@ static void sbsa_ref_init(MachineState *machine)const CPUArchIdList *possible_cpus;int n, sbsa_max_cpus; -if (!cpu_type_valid (machine->cpu_type)) { -error_report ("sbsa-ref: CPU type %s not supported" , machine->cpu_type); -exit (1 ); - } -if (kvm_enabled ()) {error_report ("sbsa-ref: KVM is not supported for this machine" );exit (1 );@@ -899,6 +883,7 @@ static void sbsa_ref_class_init(ObjectClass *oc, void *data) mc->init = sbsa_ref_init; mc->desc ="QEMU 'SBSA Reference' ARM Virtual Machine" ; mc->default_cpu_type =ARM_CPU_TYPE_NAME ("neoverse-n1" ); + mc->valid_cpu_types = valid_cpu_types; mc->max_cpus =512 ; mc->pci_allow_0_address = true; mc->minimum_page_bits =12 ;Signature · 1 line
2.41.0
PATCH v3 31/32 hw/arm: Check CPU type in machine_run_board_init()
In reply to Gavin ShanSet mc->valid_cpu_types so that the user specified CPU type can be validated in machine_run_board_init(). We needn't to do it by ourselves.
--- hw/arm/bananapi_m2u.c | 12 ++++++------ hw/arm/cubieboard.c | 12 ++++++------ hw/arm/mps2-tz.c | 20 ++++++++++++++------ hw/arm/mps2.c | 25 +++++++++++++++++++------ hw/arm/msf2-som.c | 12 ++++++------ hw/arm/musca.c | 13 ++++++------- hw/arm/npcm7xx_boards.c | 13 ++++++------- hw/arm/orangepi.c | 12 ++++++------ 8 files changed, 69 insertions(+), 50 deletions(-)
hw/arm/bananapi_m2u.c +6 -6
@@ -29,6 +29,11 @@static struct arm_boot_info bpim2u_binfo; +static const char *const valid_cpu_types[] = { +ARM_CPU_TYPE_NAME ("cortex-a7" ), +NULL +}; +/* * R40 can boot from mmc0 and mmc2, and bpim2u has two mmc interface, one is * connected to sdcard and another mount an emmc media.
@@ -70,12 +75,6 @@ static void bpim2u_init(MachineState *machine)exit (1 ); } -/* Only allow Cortex-A7 for this board */ -if (strcmp (machine->cpu_type,ARM_CPU_TYPE_NAME ("cortex-a7" )) !=0 ) { -error_report ("This board can only be used with cortex-a7 CPU" ); -exit (1 ); - } - r40 =AW_R40 (object_new (TYPE_AW_R40 ));object_property_add_child (OBJECT (machine),"soc" ,OBJECT (r40));object_unref (OBJECT (r40));
@@ -138,6 +137,7 @@ static void bpim2u_machine_init(MachineClass *mc) mc->max_cpus =AW_R40_NUM_CPUS ; mc->default_cpus =AW_R40_NUM_CPUS ; mc->default_cpu_type =ARM_CPU_TYPE_NAME ("cortex-a7" ); + mc->valid_cpu_types = valid_cpu_types; mc->default_ram_size =1 * GiB; mc->default_ram_id ="bpim2u.ram" ; }
hw/arm/cubieboard.c +6 -6
@@ -28,6 +28,11 @@ static struct arm_boot_info cubieboard_binfo = { .board_id = 0x1008, }; +static const char *const valid_cpu_types[] = { +ARM_CPU_TYPE_NAME ("cortex-a8" ), +NULL +}; +static void cubieboard_init (MachineState *machine) {AwA10State *a10;
@@ -51,12 +56,6 @@ static void cubieboard_init(MachineState *machine)exit (1 ); } -/* Only allow Cortex-A8 for this board */ -if (strcmp (machine->cpu_type,ARM_CPU_TYPE_NAME ("cortex-a8" )) !=0 ) { -error_report ("This board can only be used with cortex-a8 CPU" ); -exit (1 ); - } - a10 =AW_A10 (object_new (TYPE_AW_A10 ));object_property_add_child (OBJECT (machine),"soc" ,OBJECT (a10));object_unref (OBJECT (a10));
@@ -115,6 +114,7 @@ static void cubieboard_machine_init(MachineClass *mc) { mc->desc ="cubietech cubieboard (Cortex-A8)" ; mc->default_cpu_type =ARM_CPU_TYPE_NAME ("cortex-a8" ); + mc->valid_cpu_types = valid_cpu_types; mc->default_ram_size =1 * GiB; mc->init = cubieboard_init; mc->block_default_type =IF_IDE ;
hw/arm/mps2-tz.c +14 -6
@@ -190,6 +190,16 @@ OBJECT_DECLARE_TYPE(MPS2TZMachineState, MPS2TZMachineClass, MPS2TZ_MACHINE)/* For cpu{0,1}_mpu_{ns,s}, means "leave at SSE's default value" */ #define MPU_REGION_DEFAULT UINT32_MAX +static const char *const valid_cpu_types[] = { +ARM_CPU_TYPE_NAME ("cortex-m33" ), +NULL +}; + +static const char *const mps3tz_an547_valid_cpu_types[] = { +ARM_CPU_TYPE_NAME ("cortex-m55" ), +NULL +}; +static const uint32_t an505_oscclk[] = {40000000 ,24580000 ,
@@ -809,12 +819,6 @@ static void mps2tz_common_init(MachineState *machine)int num_ppcs;int i; -if (strcmp (machine->cpu_type, mc->default_cpu_type) !=0 ) { -error_report ("This board can only be used with CPU %s" , - mc->default_cpu_type); -exit (1 ); - } -if (machine->ram_size != mc->default_ram_size) {char *sz =size_to_str (mc->default_ram_size);error_report ("Invalid RAM size, should be %s" , sz);
@@ -1321,6 +1325,7 @@ static void mps2tz_an505_class_init(ObjectClass *oc, void *data) mc->max_cpus = mc->default_cpus; mmc->fpga_type =FPGA_AN505 ; mc->default_cpu_type =ARM_CPU_TYPE_NAME ("cortex-m33" ); + mc->valid_cpu_types = valid_cpu_types; mmc->scc_id =0x41045050 ; mmc->sysclk_frq =20 *1000 *1000 ;/* 20MHz */ mmc->apb_periph_frq = mmc->sysclk_frq;
@@ -1350,6 +1355,7 @@ static void mps2tz_an521_class_init(ObjectClass *oc, void *data) mc->max_cpus = mc->default_cpus; mmc->fpga_type =FPGA_AN521 ; mc->default_cpu_type =ARM_CPU_TYPE_NAME ("cortex-m33" ); + mc->valid_cpu_types = valid_cpu_types; mmc->scc_id =0x41045210 ; mmc->sysclk_frq =20 *1000 *1000 ;/* 20MHz */ mmc->apb_periph_frq = mmc->sysclk_frq;
@@ -1379,6 +1385,7 @@ static void mps3tz_an524_class_init(ObjectClass *oc, void *data) mc->max_cpus = mc->default_cpus; mmc->fpga_type =FPGA_AN524 ; mc->default_cpu_type =ARM_CPU_TYPE_NAME ("cortex-m33" ); + mc->valid_cpu_types = valid_cpu_types; mmc->scc_id =0x41045240 ; mmc->sysclk_frq =32 *1000 *1000 ;/* 32MHz */ mmc->apb_periph_frq = mmc->sysclk_frq;
@@ -1413,6 +1420,7 @@ static void mps3tz_an547_class_init(ObjectClass *oc, void *data) mc->max_cpus = mc->default_cpus; mmc->fpga_type =FPGA_AN547 ; mc->default_cpu_type =ARM_CPU_TYPE_NAME ("cortex-m55" ); + mc->valid_cpu_types = mps3tz_an547_valid_cpu_types; mmc->scc_id =0x41055470 ; mmc->sysclk_frq =32 *1000 *1000 ;/* 32MHz */ mmc->apb_periph_frq =25 *1000 *1000 ;/* 25MHz */
hw/arm/mps2.c +19 -6
@@ -110,6 +110,21 @@ OBJECT_DECLARE_TYPE(MPS2MachineState, MPS2MachineClass, MPS2_MACHINE)*/ #define REFCLK_FRQ (1 * 1000 * 1000) +static const char *const valid_cpu_types[] = { +ARM_CPU_TYPE_NAME ("cortex-m3" ), +NULL +}; + +static const char *const mps2_an386_valid_cpu_types[] = { +ARM_CPU_TYPE_NAME ("cortex-m4" ), +NULL +}; + +static const char *const mps2_an500_valid_cpu_types[] = { +ARM_CPU_TYPE_NAME ("cortex-m7" ), +NULL +}; +/* Initialize the auxiliary RAM region @mr and map it into * the memory map at @base. */
@@ -140,12 +155,6 @@ static void mps2_common_init(MachineState *machine)DeviceState *armv7m, *sccdev;int i; -if (strcmp (machine->cpu_type, mc->default_cpu_type) !=0 ) { -error_report ("This board can only be used with CPU %s" , - mc->default_cpu_type); -exit (1 ); - } -if (machine->ram_size != mc->default_ram_size) {char *sz =size_to_str (mc->default_ram_size);error_report ("Invalid RAM size, should be %s" , sz);
@@ -484,6 +493,7 @@ static void mps2_an385_class_init(ObjectClass *oc, void *data) mc->desc ="ARM MPS2 with AN385 FPGA image for Cortex-M3" ; mmc->fpga_type =FPGA_AN385 ; mc->default_cpu_type =ARM_CPU_TYPE_NAME ("cortex-m3" ); + mc->valid_cpu_types = valid_cpu_types; mmc->scc_id =0x41043850 ; mmc->psram_base =0x21000000 ; mmc->ethernet_base =0x40200000 ;
@@ -498,6 +508,7 @@ static void mps2_an386_class_init(ObjectClass *oc, void *data) mc->desc ="ARM MPS2 with AN386 FPGA image for Cortex-M4" ; mmc->fpga_type =FPGA_AN386 ; mc->default_cpu_type =ARM_CPU_TYPE_NAME ("cortex-m4" ); + mc->valid_cpu_types = mps2_an386_valid_cpu_types; mmc->scc_id =0x41043860 ; mmc->psram_base =0x21000000 ; mmc->ethernet_base =0x40200000 ;
@@ -512,6 +523,7 @@ static void mps2_an500_class_init(ObjectClass *oc, void *data) mc->desc ="ARM MPS2 with AN500 FPGA image for Cortex-M7" ; mmc->fpga_type =FPGA_AN500 ; mc->default_cpu_type =ARM_CPU_TYPE_NAME ("cortex-m7" ); + mc->valid_cpu_types = mps2_an500_valid_cpu_types; mmc->scc_id =0x41045000 ; mmc->psram_base =0x60000000 ; mmc->ethernet_base =0xa0000000 ;
@@ -526,6 +538,7 @@ static void mps2_an511_class_init(ObjectClass *oc, void *data) mc->desc ="ARM MPS2 with AN511 DesignStart FPGA image for Cortex-M3" ; mmc->fpga_type =FPGA_AN511 ; mc->default_cpu_type =ARM_CPU_TYPE_NAME ("cortex-m3" ); + mc->valid_cpu_types = valid_cpu_types; mmc->scc_id =0x41045110 ; mmc->psram_base =0x21000000 ; mmc->ethernet_base =0x40200000 ;
hw/arm/msf2-som.c +6 -6
@@ -42,6 +42,11 @@#define M2S010_ENVM_SIZE (256 * KiB)#define M2S010_ESRAM_SIZE (64 * KiB) +static const char *const valid_cpu_types[] = { +ARM_CPU_TYPE_NAME ("cortex-m3" ), +NULL +}; +static void emcraft_sf2_s2s010_init (MachineState *machine) {DeviceState *dev;
@@ -55,12 +60,6 @@ static void emcraft_sf2_s2s010_init(MachineState *machine)MemoryRegion *ddr =g_new (MemoryRegion,1 );Clock *m3clk; -if (strcmp (machine->cpu_type, mc->default_cpu_type) !=0 ) { -error_report ("This board can only be used with CPU %s" , - mc->default_cpu_type); -exit (1 ); - } -memory_region_init_ram (ddr,NULL ,"ddr-ram" ,DDR_SIZE , &error_fatal);memory_region_add_subregion (sysmem,DDR_BASE_ADDRESS , ddr);
@@ -109,6 +108,7 @@ static void emcraft_sf2_machine_init(MachineClass *mc) mc->desc ="SmartFusion2 SOM kit from Emcraft (M2S010)" ; mc->init = emcraft_sf2_s2s010_init; mc->default_cpu_type =ARM_CPU_TYPE_NAME ("cortex-m3" ); + mc->valid_cpu_types = valid_cpu_types; }DEFINE_MACHINE ("emcraft-sf2" , emcraft_sf2_machine_init)
hw/arm/musca.c +6 -7
@@ -102,6 +102,11 @@ OBJECT_DECLARE_TYPE(MuscaMachineState, MuscaMachineClass, MUSCA_MACHINE)/* Slow 32Khz S32KCLK frequency in Hz */ #define S32KCLK_FRQ (32 * 1000) +static const char *const valid_cpu_types[] = { +ARM_CPU_TYPE_NAME ("cortex-m33" ), +NULL +}; +static qemu_irq get_sse_irq_in (MuscaMachineState *mms,int irqno) {/* Return a qemu_irq which will signal IRQ n to all CPUs in the SSE. */
@@ -355,7 +360,6 @@ static void musca_init(MachineState *machine) {MuscaMachineState *mms =MUSCA_MACHINE (machine);MuscaMachineClass *mmc =MUSCA_MACHINE_GET_CLASS (mms); -MachineClass *mc =MACHINE_GET_CLASS (machine);MemoryRegion *system_memory =get_system_memory ();DeviceState *ssedev;DeviceState *dev_splitter;
@@ -366,12 +370,6 @@ static void musca_init(MachineState *machine)assert (mmc->num_irqs <=MUSCA_NUMIRQ_MAX );assert (mmc->num_mpcs <=MUSCA_MPC_MAX ); -if (strcmp (machine->cpu_type, mc->default_cpu_type) !=0 ) { -error_report ("This board can only be used with CPU %s" , - mc->default_cpu_type); -exit (1 ); - } - mms->sysclk =clock_new (OBJECT (machine),"SYSCLK" );clock_set_hz (mms->sysclk,SYSCLK_FRQ ); mms->s32kclk =clock_new (OBJECT (machine),"S32KCLK" );
@@ -609,6 +607,7 @@ static void musca_class_init(ObjectClass *oc, void *data) mc->min_cpus = mc->default_cpus; mc->max_cpus = mc->default_cpus; mc->default_cpu_type =ARM_CPU_TYPE_NAME ("cortex-m33" ); + mc->valid_cpu_types = valid_cpu_types; mc->init = musca_init; }
hw/arm/npcm7xx_boards.c +6 -7
@@ -55,6 +55,11 @@static const char npcm7xx_default_bootrom[] ="npcm7xx_bootrom.bin" ; +static const char *const valid_cpu_types[] = { +ARM_CPU_TYPE_NAME ("cortex-a9" ), +NULL +}; +static void npcm7xx_load_bootrom (MachineState *machine,NPCM7xxState *soc) {const char *bios_name = machine->firmware ?: npcm7xx_default_bootrom;
@@ -121,15 +126,8 @@ static NPCM7xxState *npcm7xx_create_soc(MachineState *machine, uint32_t hw_straps) {NPCM7xxMachineClass *nmc =NPCM7XX_MACHINE_GET_CLASS (machine); -MachineClass *mc =MACHINE_CLASS (nmc);Object *obj; -if (strcmp (machine->cpu_type, mc->default_cpu_type) !=0 ) { -error_report ("This board can only be used with %s" , - mc->default_cpu_type); -exit (1 ); - } - obj =object_new_with_props (nmc->soc_type,OBJECT (machine),"soc" , &error_abort,NULL );object_property_set_uint (obj,"power-on-straps" , hw_straps, &error_abort);
@@ -469,6 +467,7 @@ static void npcm7xx_machine_class_init(ObjectClass *oc, void *data) mc->no_parallel =1 ; mc->default_ram_id ="ram" ; mc->default_cpu_type =ARM_CPU_TYPE_NAME ("cortex-a9" ); + mc->valid_cpu_types = valid_cpu_types; }/*
hw/arm/orangepi.c +6 -6
@@ -28,6 +28,11 @@static struct arm_boot_info orangepi_binfo; +static const char *const valid_cpu_types[] = { +ARM_CPU_TYPE_NAME ("cortex-a7" ), +NULL +}; +static void orangepi_init (MachineState *machine) {AwH3State *h3;
@@ -48,12 +53,6 @@ static void orangepi_init(MachineState *machine)exit (1 ); } -/* Only allow Cortex-A7 for this board */ -if (strcmp (machine->cpu_type,ARM_CPU_TYPE_NAME ("cortex-a7" )) !=0 ) { -error_report ("This board can only be used with cortex-a7 CPU" ); -exit (1 ); - } - h3 =AW_H3 (object_new (TYPE_AW_H3 ));object_property_add_child (OBJECT (machine),"soc" ,OBJECT (h3));object_unref (OBJECT (h3));
@@ -118,6 +117,7 @@ static void orangepi_machine_init(MachineClass *mc) mc->max_cpus =AW_H3_NUM_CPUS ; mc->default_cpus =AW_H3_NUM_CPUS ; mc->default_cpu_type =ARM_CPU_TYPE_NAME ("cortex-a7" ); + mc->valid_cpu_types = valid_cpu_types; mc->default_ram_size =1 * GiB; mc->default_ram_id ="orangepi.ram" ; }
Signature · 1 line
2.41.0
PATCH v3 32/32 hw/riscv/shakti_c: Check CPU type in machine_run_board_init()
In reply to Gavin ShanSet mc->valid_cpu_types so that the user specified CPU type can be validated in machine_run_board_init(). We needn't to do it by ourselves.
--- hw/riscv/shakti_c.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-)
hw/riscv/shakti_c.c +5 -6
@@ -28,6 +28,10 @@#include "exec/address-spaces.h" #include "hw/riscv/boot.h" +static const char *const valid_cpu_types[] = { +RISCV_CPU_TYPE_NAME ("shakti-c" ), +NULL +}; static const struct MemmapEntry { hwaddr base;
@@ -47,12 +51,6 @@ static void shakti_c_machine_state_init(MachineState *mstate)ShaktiCMachineState *sms =RISCV_SHAKTI_MACHINE (mstate);MemoryRegion *system_memory =get_system_memory (); -/* Allow only Shakti C CPU for this platform */ -if (strcmp (mstate->cpu_type,TYPE_RISCV_CPU_SHAKTI_C ) !=0 ) { -error_report ("This board can only be used with Shakti C CPU" ); -exit (1 ); - } -/* Initialize SoC */ object_initialize_child (OBJECT (mstate),"soc" , &sms->soc,TYPE_RISCV_SHAKTI_SOC );
@@ -85,6 +83,7 @@ static void shakti_c_machine_class_init(ObjectClass *klass, void *data) mc->desc ="RISC-V Board compatible with Shakti SDK" ; mc->init = shakti_c_machine_state_init; mc->default_cpu_type =TYPE_RISCV_CPU_SHAKTI_C ; + mc->valid_cpu_types = valid_cpu_types; mc->default_ram_id ="riscv.shakti.c.ram" ; }
Signature · 1 line
2.41.0
Re: [PATCH v3 32/32] hw/riscv/shakti_c: Check CPU type in machine_run_board_init()
Quoted 8 lines · Gavin Shan
Set
mc->valid_cpu_typesso that the user specified CPU type can be validated inmachine_run_board_init(). We needn't to do it by ourselves.Signed-off-by Gavin Shan <[email protected]>--- hw/riscv/shakti_c.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-)