All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH 00/38] generalize parsing of cpu_model (part 2)
@ 2017-10-02  9:07 Igor Mammedov
  2017-10-02  9:07 ` [Qemu-devel] [PATCH 01/38] qom: add helper type_init_from_array() Igor Mammedov
                   ` (37 more replies)
  0 siblings, 38 replies; 113+ messages in thread
From: Igor Mammedov @ 2017-10-02  9:07 UTC (permalink / raw)
  To: qemu-devel; +Cc: Philippe Mathieu-Daudé

this series is continuation of effort to remove boards dependency on
cpu_model parsing and generalizing default cpu type handling.
For background story look at merged: 

  [PATCH v2 0/5] generalize parsing of cpu_model (x86/arm)
  https://lists.gnu.org/archive/html/qemu-devel/2017-09/msg03564.html

thisi series mostly consist of 3 types of patches:
 1: unifying cpu type name composing by introdicing 
        FOO_CPU_TYPE_NAME() macro across targets
 2: replacing simple static(and needlessly dynamic) cpu type registrations
    with common pattern where typinfo is put into array which
    is used to batch register cpu types with new helper type_init_from_array()
 3: main patches that generalize cpu_model parsing for boards

I'm releasing independent subset that takes care of all
targets/boards except null-machine, ppc and *-user targets
(as they are still work in progress and PPC part is big
enough to deserve its own series)

I've tried to test all converted boards but there were a lot
so I've might have missed some.

git tree for testing:
  https://github.com/imammedo/qemu/branches cpu_init_removal_part2_v1

PS:
 rebased on top of ehabkost/machine-next tree to avoid resolve conflicts with
 queued "qom/cpu: move cpu_model null check to  cpu_class_by_name()"

CC: Philippe Mathieu-Daudé <f4bug@amsat.org>


Igor Mammedov (38):
  qom: add helper type_init_from_array()
  alpha: cleanup cpu type name composition
  alpha: use generic cpu_model parsing
  cris: cleanup cpu type name composition
  cris: use generic cpu_model parsing
  lm32: cleanup cpu type name composition
  lm32: milkymist: use generic cpu_model parsing
  lm32: lm32_boards: use generic cpu_model parsing
  m68k: cleanup cpu type name composition
  m68k: an5206: use generic cpu_model parsing
  m68k: mcf5208: use generic cpu_model parsing
  moxie: fix qemu-system-moxie failing to start with CLI "-cpu
    MoxieLite"
  moxie: cleanup cpu type name composition
  moxie: use generic cpu_model parsing
  openrisc: cleanup cpu type name composition
  openrisc: use generic cpu_model parsing
  sh4: r2d: use generic cpu_model parsing
  sh4: shix: use generic cpu_model parsing
  sh4: cleanup cpu type name composition
  sh4: simplify superh_cpu_class_by_name()
  sh4: remove SuperHCPUClass::name field
  xtensa: cleanup cpu type name composition
  xtensa: sim: use generic cpu_model parsing
  xtensa: lx60/lx200/ml605/kc705: use generic cpu_model parsing
  unicore32: cleanup cpu type name composition
  unicore32: use generic cpu_model parsing
  tricore: cleanup cpu type name composition
  tricore: use generic cpu_model parsing
  sparc: cleanup cpu type name composition
  sparc: sun4u/sun4v/niagara: use generic cpu_model parsing
  sparc: sparc: use generic cpu_model parsing
  sparc: leon3: use generic cpu_model parsing
  mips: use object_new() instead of gnew()+object_initialize()
  mips: malta/boston: replace cpu_model with cpu_type
  mips: fulong2e: replace cpu_model with cpu_type
  mips: Magnum/Acer Pica 61: replace cpu_model with cpu_type
  mips: mipssim: replace cpu_model with cpu_type
  mips: r4k: replace cpu_model with cpu_type

 include/hw/mips/cps.h          |   2 +-
 include/hw/sparc/sparc64.h     |   3 +-
 include/qemu/module.h          |  10 ++++
 target/alpha/cpu.h             |   3 ++
 target/cris/cpu.h              |   3 ++
 target/lm32/cpu.h              |   3 ++
 target/m68k/cpu.h              |   3 ++
 target/mips/cpu.h              |   8 ++-
 target/moxie/cpu.h             |   3 ++
 target/openrisc/cpu.h          |   3 ++
 target/sh4/cpu-qom.h           |   8 ++-
 target/sh4/cpu.h               |   3 ++
 target/sparc/cpu.h             |   3 ++
 target/tricore/cpu.h           |   2 +
 target/unicore32/cpu.h         |   3 ++
 target/xtensa/cpu.h            |   4 ++
 hw/alpha/dp264.c               |   4 +-
 hw/cris/axis_dev88.c           |   7 +--
 hw/lm32/lm32_boards.c          |  14 ++----
 hw/lm32/milkymist.c            |   7 +--
 hw/m68k/an5206.c               |   7 +--
 hw/m68k/mcf5208.c              |   7 +--
 hw/mips/boston.c               |  14 +++---
 hw/mips/cps.c                  |   4 +-
 hw/mips/mips_fulong2e.c        |   7 +--
 hw/mips/mips_jazz.c            |   8 ++-
 hw/mips/mips_malta.c           |  36 ++++++--------
 hw/mips/mips_mipssim.c         |  15 +++---
 hw/mips/mips_r4k.c             |  16 +++---
 hw/moxie/moxiesim.c            |   7 +--
 hw/openrisc/openrisc_sim.c     |   8 +--
 hw/sh4/r2d.c                   |   8 +--
 hw/sh4/shix.c                  |   7 +--
 hw/sparc/leon3.c               |   8 +--
 hw/sparc/sun4m.c               |  29 +++++------
 hw/sparc64/niagara.c           |   4 +-
 hw/sparc64/sparc64.c           |   8 +--
 hw/sparc64/sun4u.c             |   8 ++-
 hw/tricore/tricore_testboard.c |   6 +--
 hw/unicore32/puv3.c            |   8 +--
 hw/xtensa/sim.c                |   8 +--
 hw/xtensa/xtfpga.c             |  11 ++---
 target/alpha/cpu.c             | 107 +++++++++++++---------------------------
 target/cris/cpu.c              |  93 +++++++++++++++--------------------
 target/lm32/cpu.c              |  74 +++++++++-------------------
 target/m68k/cpu.c              |  75 ++++++++++------------------
 target/mips/cpu.c              |   2 +-
 target/mips/translate.c        |  20 +++-----
 target/mips/translate_init.c   |  12 -----
 target/moxie/cpu.c             |  61 +++++++++--------------
 target/openrisc/cpu.c          |  69 +++++++++-----------------
 target/sh4/cpu.c               | 109 ++++++++++++++++-------------------------
 target/sparc/cpu.c             |   2 +-
 target/tricore/cpu.c           |  68 ++++++++-----------------
 target/unicore32/cpu.c         |  61 ++++++++---------------
 target/xtensa/cpu.c            |   2 +-
 target/xtensa/helper.c         |   2 +-
 57 files changed, 408 insertions(+), 679 deletions(-)

-- 
2.7.4

^ permalink raw reply	[flat|nested] 113+ messages in thread

* [Qemu-devel] [PATCH 01/38] qom: add helper type_init_from_array()
  2017-10-02  9:07 [Qemu-devel] [PATCH 00/38] generalize parsing of cpu_model (part 2) Igor Mammedov
@ 2017-10-02  9:07 ` Igor Mammedov
  2017-10-02 14:15   ` Philippe Mathieu-Daudé
                     ` (2 more replies)
  2017-10-02  9:07 ` [Qemu-devel] [PATCH 02/38] alpha: cleanup cpu type name composition Igor Mammedov
                   ` (36 subsequent siblings)
  37 siblings, 3 replies; 113+ messages in thread
From: Igor Mammedov @ 2017-10-02  9:07 UTC (permalink / raw)
  To: qemu-devel; +Cc: Philippe Mathieu-Daudé, ehabkost

it will help to remove code duplication in places
that currently open code registration of several
types.

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
---
I'm going to use it for CPU types in followup patches

CC: ehabkost@redhat.com
---
 include/qemu/module.h | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/include/qemu/module.h b/include/qemu/module.h
index 56dd218..29f9089 100644
--- a/include/qemu/module.h
+++ b/include/qemu/module.h
@@ -52,6 +52,16 @@ typedef enum {
 #define type_init(function) module_init(function, MODULE_INIT_QOM)
 #define trace_init(function) module_init(function, MODULE_INIT_TRACE)
 
+#define type_init_from_array(array)                                        \
+static void do_qemu_init_ ## array(void)                                   \
+{                                                                          \
+    int i;                                                                 \
+    for (i = 0; i < ARRAY_SIZE(array); i++) {                              \
+        type_register_static(&array[i]);                                   \
+    }                                                                      \
+}                                                                          \
+module_init(do_qemu_init_ ## array, MODULE_INIT_QOM)
+
 #define block_module_load_one(lib) module_load_one("block-", lib)
 
 void register_module_init(void (*fn)(void), module_init_type type);
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 113+ messages in thread

* [Qemu-devel] [PATCH 02/38] alpha: cleanup cpu type name composition
  2017-10-02  9:07 [Qemu-devel] [PATCH 00/38] generalize parsing of cpu_model (part 2) Igor Mammedov
  2017-10-02  9:07 ` [Qemu-devel] [PATCH 01/38] qom: add helper type_init_from_array() Igor Mammedov
@ 2017-10-02  9:07 ` Igor Mammedov
  2017-10-02 12:01   ` Richard Henderson
  2017-10-02 14:46   ` Philippe Mathieu-Daudé
  2017-10-02  9:07 ` [Qemu-devel] [PATCH 03/38] alpha: use generic cpu_model parsing Igor Mammedov
                   ` (35 subsequent siblings)
  37 siblings, 2 replies; 113+ messages in thread
From: Igor Mammedov @ 2017-10-02  9:07 UTC (permalink / raw)
  To: qemu-devel; +Cc: Philippe Mathieu-Daudé, rth

Introduce ALPHA_CPU_TYPE_NAME macro to replace rather ununique
TYPE macro that alpha uses. With new macro it will follow
the same naming convention as other targets.

While at it put scattered TypeInfo into one array which places
type desriptions at one place and reduces code a bit.

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
---
CC: rth@twiddle.net
---
 target/alpha/cpu.h |   3 ++
 target/alpha/cpu.c | 107 +++++++++++++++++------------------------------------
 2 files changed, 37 insertions(+), 73 deletions(-)

diff --git a/target/alpha/cpu.h b/target/alpha/cpu.h
index 6ae2409..0a9ad35 100644
--- a/target/alpha/cpu.h
+++ b/target/alpha/cpu.h
@@ -470,6 +470,9 @@ void alpha_translate_init(void);
 
 #define cpu_init(cpu_model) cpu_generic_init(TYPE_ALPHA_CPU, cpu_model)
 
+#define ALPHA_CPU_TYPE_SUFFIX "-" TYPE_ALPHA_CPU
+#define ALPHA_CPU_TYPE_NAME(model) model ALPHA_CPU_TYPE_SUFFIX
+
 void alpha_cpu_list(FILE *f, fprintf_function cpu_fprintf);
 /* you can call this signal handler from your SIGBUS and SIGSEGV
    signal handlers to inform the virtual CPU of exceptions. non zero
diff --git a/target/alpha/cpu.c b/target/alpha/cpu.c
index b8a21f4..81a39c4 100644
--- a/target/alpha/cpu.c
+++ b/target/alpha/cpu.c
@@ -108,21 +108,18 @@ void alpha_cpu_list(FILE *f, fprintf_function cpu_fprintf)
 }
 
 /* Models */
-
-#define TYPE(model) model "-" TYPE_ALPHA_CPU
-
 typedef struct AlphaCPUAlias {
     const char *alias;
     const char *typename;
 } AlphaCPUAlias;
 
 static const AlphaCPUAlias alpha_cpu_aliases[] = {
-    { "21064",   TYPE("ev4") },
-    { "21164",   TYPE("ev5") },
-    { "21164a",  TYPE("ev56") },
-    { "21164pc", TYPE("pca56") },
-    { "21264",   TYPE("ev6") },
-    { "21264a",  TYPE("ev67") },
+    { "21064",   ALPHA_CPU_TYPE_NAME("ev4") },
+    { "21164",   ALPHA_CPU_TYPE_NAME("ev5") },
+    { "21164a",  ALPHA_CPU_TYPE_NAME("ev56") },
+    { "21164pc", ALPHA_CPU_TYPE_NAME("pca56") },
+    { "21264",   ALPHA_CPU_TYPE_NAME("ev6") },
+    { "21264a",  ALPHA_CPU_TYPE_NAME("ev67") },
 };
 
 static ObjectClass *alpha_cpu_class_by_name(const char *cpu_model)
@@ -145,7 +142,7 @@ static ObjectClass *alpha_cpu_class_by_name(const char *cpu_model)
         }
     }
 
-    typename = g_strdup_printf("%s-" TYPE_ALPHA_CPU, cpu_model);
+    typename = g_strdup_printf(ALPHA_CPU_TYPE_NAME("%s"), cpu_model);
     oc = object_class_by_name(typename);
     g_free(typename);
     if (oc != NULL && object_class_is_abstract(oc)) {
@@ -155,7 +152,7 @@ static ObjectClass *alpha_cpu_class_by_name(const char *cpu_model)
     /* TODO: remove match everything nonsense */
     /* Default to ev67; no reason not to emulate insns by default. */
     if (!oc) {
-        oc = object_class_by_name(TYPE("ev67"));
+        oc = object_class_by_name(ALPHA_CPU_TYPE_NAME("ev67"));
     }
 
     return oc;
@@ -169,12 +166,6 @@ static void ev4_cpu_initfn(Object *obj)
     env->implver = IMPLVER_2106x;
 }
 
-static const TypeInfo ev4_cpu_type_info = {
-    .name = TYPE("ev4"),
-    .parent = TYPE_ALPHA_CPU,
-    .instance_init = ev4_cpu_initfn,
-};
-
 static void ev5_cpu_initfn(Object *obj)
 {
     AlphaCPU *cpu = ALPHA_CPU(obj);
@@ -183,12 +174,6 @@ static void ev5_cpu_initfn(Object *obj)
     env->implver = IMPLVER_21164;
 }
 
-static const TypeInfo ev5_cpu_type_info = {
-    .name = TYPE("ev5"),
-    .parent = TYPE_ALPHA_CPU,
-    .instance_init = ev5_cpu_initfn,
-};
-
 static void ev56_cpu_initfn(Object *obj)
 {
     AlphaCPU *cpu = ALPHA_CPU(obj);
@@ -197,12 +182,6 @@ static void ev56_cpu_initfn(Object *obj)
     env->amask |= AMASK_BWX;
 }
 
-static const TypeInfo ev56_cpu_type_info = {
-    .name = TYPE("ev56"),
-    .parent = TYPE("ev5"),
-    .instance_init = ev56_cpu_initfn,
-};
-
 static void pca56_cpu_initfn(Object *obj)
 {
     AlphaCPU *cpu = ALPHA_CPU(obj);
@@ -211,12 +190,6 @@ static void pca56_cpu_initfn(Object *obj)
     env->amask |= AMASK_MVI;
 }
 
-static const TypeInfo pca56_cpu_type_info = {
-    .name = TYPE("pca56"),
-    .parent = TYPE("ev56"),
-    .instance_init = pca56_cpu_initfn,
-};
-
 static void ev6_cpu_initfn(Object *obj)
 {
     AlphaCPU *cpu = ALPHA_CPU(obj);
@@ -226,12 +199,6 @@ static void ev6_cpu_initfn(Object *obj)
     env->amask = AMASK_BWX | AMASK_FIX | AMASK_MVI | AMASK_TRAP;
 }
 
-static const TypeInfo ev6_cpu_type_info = {
-    .name = TYPE("ev6"),
-    .parent = TYPE_ALPHA_CPU,
-    .instance_init = ev6_cpu_initfn,
-};
-
 static void ev67_cpu_initfn(Object *obj)
 {
     AlphaCPU *cpu = ALPHA_CPU(obj);
@@ -240,17 +207,6 @@ static void ev67_cpu_initfn(Object *obj)
     env->amask |= AMASK_CIX | AMASK_PREFETCH;
 }
 
-static const TypeInfo ev67_cpu_type_info = {
-    .name = TYPE("ev67"),
-    .parent = TYPE("ev6"),
-    .instance_init = ev67_cpu_initfn,
-};
-
-static const TypeInfo ev68_cpu_type_info = {
-    .name = TYPE("ev68"),
-    .parent = TYPE("ev67"),
-};
-
 static void alpha_cpu_initfn(Object *obj)
 {
     CPUState *cs = CPU(obj);
@@ -303,26 +259,31 @@ static void alpha_cpu_class_init(ObjectClass *oc, void *data)
     cc->gdb_num_core_regs = 67;
 }
 
-static const TypeInfo alpha_cpu_type_info = {
-    .name = TYPE_ALPHA_CPU,
-    .parent = TYPE_CPU,
-    .instance_size = sizeof(AlphaCPU),
-    .instance_init = alpha_cpu_initfn,
-    .abstract = true,
-    .class_size = sizeof(AlphaCPUClass),
-    .class_init = alpha_cpu_class_init,
+#define DEFINE_ALPHA_CPU_TYPE(base_type, cpu_model, initfn) \
+     {                                                      \
+         .parent = base_type,                               \
+         .instance_init = initfn,                           \
+         .name = ALPHA_CPU_TYPE_NAME(cpu_model),            \
+     }
+
+static const TypeInfo alpha_cpu_type_infos[] = {
+    {
+        .name = TYPE_ALPHA_CPU,
+        .parent = TYPE_CPU,
+        .instance_size = sizeof(AlphaCPU),
+        .instance_init = alpha_cpu_initfn,
+        .abstract = true,
+        .class_size = sizeof(AlphaCPUClass),
+        .class_init = alpha_cpu_class_init,
+    },
+    DEFINE_ALPHA_CPU_TYPE(TYPE_ALPHA_CPU, "ev4", ev4_cpu_initfn),
+    DEFINE_ALPHA_CPU_TYPE(TYPE_ALPHA_CPU, "ev5", ev5_cpu_initfn),
+    DEFINE_ALPHA_CPU_TYPE(ALPHA_CPU_TYPE_NAME("ev5"), "ev56", ev56_cpu_initfn),
+    DEFINE_ALPHA_CPU_TYPE(ALPHA_CPU_TYPE_NAME("ev56"), "pca56",
+                          pca56_cpu_initfn),
+    DEFINE_ALPHA_CPU_TYPE(TYPE_ALPHA_CPU, "ev6", ev6_cpu_initfn),
+    DEFINE_ALPHA_CPU_TYPE(ALPHA_CPU_TYPE_NAME("ev6"), "ev67", ev67_cpu_initfn),
+    DEFINE_ALPHA_CPU_TYPE(ALPHA_CPU_TYPE_NAME("ev67"), "ev68", NULL),
 };
 
-static void alpha_cpu_register_types(void)
-{
-    type_register_static(&alpha_cpu_type_info);
-    type_register_static(&ev4_cpu_type_info);
-    type_register_static(&ev5_cpu_type_info);
-    type_register_static(&ev56_cpu_type_info);
-    type_register_static(&pca56_cpu_type_info);
-    type_register_static(&ev6_cpu_type_info);
-    type_register_static(&ev67_cpu_type_info);
-    type_register_static(&ev68_cpu_type_info);
-}
-
-type_init(alpha_cpu_register_types)
+type_init_from_array(alpha_cpu_type_infos)
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 113+ messages in thread

* [Qemu-devel] [PATCH 03/38] alpha: use generic cpu_model parsing
  2017-10-02  9:07 [Qemu-devel] [PATCH 00/38] generalize parsing of cpu_model (part 2) Igor Mammedov
  2017-10-02  9:07 ` [Qemu-devel] [PATCH 01/38] qom: add helper type_init_from_array() Igor Mammedov
  2017-10-02  9:07 ` [Qemu-devel] [PATCH 02/38] alpha: cleanup cpu type name composition Igor Mammedov
@ 2017-10-02  9:07 ` Igor Mammedov
  2017-10-02 12:01   ` Richard Henderson
  2017-10-02 14:46   ` Philippe Mathieu-Daudé
  2017-10-02  9:07 ` [Qemu-devel] [PATCH 04/38] cris: cleanup cpu type name composition Igor Mammedov
                   ` (34 subsequent siblings)
  37 siblings, 2 replies; 113+ messages in thread
From: Igor Mammedov @ 2017-10-02  9:07 UTC (permalink / raw)
  To: qemu-devel; +Cc: Philippe Mathieu-Daudé, rth

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
---
CC: rth@twiddle.net
---
 hw/alpha/dp264.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/hw/alpha/dp264.c b/hw/alpha/dp264.c
index 1b12130..babd6ea 100644
--- a/hw/alpha/dp264.c
+++ b/hw/alpha/dp264.c
@@ -51,7 +51,6 @@ static int clipper_pci_map_irq(PCIDevice *d, int irq_num)
 static void clipper_init(MachineState *machine)
 {
     ram_addr_t ram_size = machine->ram_size;
-    const char *cpu_model = machine->cpu_model ? machine->cpu_model : "ev67";
     const char *kernel_filename = machine->kernel_filename;
     const char *kernel_cmdline = machine->kernel_cmdline;
     const char *initrd_filename = machine->initrd_filename;
@@ -67,7 +66,7 @@ static void clipper_init(MachineState *machine)
     /* Create up to 4 cpus.  */
     memset(cpus, 0, sizeof(cpus));
     for (i = 0; i < smp_cpus; ++i) {
-        cpus[i] = ALPHA_CPU(cpu_generic_init(TYPE_ALPHA_CPU, cpu_model));
+        cpus[i] = ALPHA_CPU(cpu_create(machine->cpu_type));
     }
 
     cpus[0]->env.trap_arg0 = ram_size;
@@ -179,6 +178,7 @@ static void clipper_machine_init(MachineClass *mc)
     mc->block_default_type = IF_IDE;
     mc->max_cpus = 4;
     mc->is_default = 1;
+    mc->default_cpu_type = ALPHA_CPU_TYPE_NAME("ev67");
 }
 
 DEFINE_MACHINE("clipper", clipper_machine_init)
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 113+ messages in thread

* [Qemu-devel] [PATCH 04/38] cris: cleanup cpu type name composition
  2017-10-02  9:07 [Qemu-devel] [PATCH 00/38] generalize parsing of cpu_model (part 2) Igor Mammedov
                   ` (2 preceding siblings ...)
  2017-10-02  9:07 ` [Qemu-devel] [PATCH 03/38] alpha: use generic cpu_model parsing Igor Mammedov
@ 2017-10-02  9:07 ` Igor Mammedov
  2017-10-02 14:51   ` Philippe Mathieu-Daudé
  2017-10-02  9:07 ` [Qemu-devel] [PATCH 05/38] cris: use generic cpu_model parsing Igor Mammedov
                   ` (33 subsequent siblings)
  37 siblings, 1 reply; 113+ messages in thread
From: Igor Mammedov @ 2017-10-02  9:07 UTC (permalink / raw)
  To: qemu-devel; +Cc: Philippe Mathieu-Daudé, edgar.iglesias

replace ambiguous TYPE macro with a new CRIS_CPU_TYPE_NAME
and use it consistently in the code.

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
---
CC: edgar.iglesias@gmail.com
---
 target/cris/cpu.h |  3 ++
 target/cris/cpu.c | 93 +++++++++++++++++++++++--------------------------------
 2 files changed, 42 insertions(+), 54 deletions(-)

diff --git a/target/cris/cpu.h b/target/cris/cpu.h
index 5d822de..b64fa35 100644
--- a/target/cris/cpu.h
+++ b/target/cris/cpu.h
@@ -269,6 +269,9 @@ enum {
 
 #define cpu_init(cpu_model) cpu_generic_init(TYPE_CRIS_CPU, cpu_model)
 
+#define CRIS_CPU_TYPE_SUFFIX "-" TYPE_CRIS_CPU
+#define CRIS_CPU_TYPE_NAME(name) (name CRIS_CPU_TYPE_SUFFIX)
+
 #define cpu_signal_handler cpu_cris_signal_handler
 
 /* MMU modes definitions */
diff --git a/target/cris/cpu.c b/target/cris/cpu.c
index 88d93f2..8681c84 100644
--- a/target/cris/cpu.c
+++ b/target/cris/cpu.c
@@ -71,11 +71,11 @@ static ObjectClass *cris_cpu_class_by_name(const char *cpu_model)
 
 #if defined(CONFIG_USER_ONLY)
     if (strcasecmp(cpu_model, "any") == 0) {
-        return object_class_by_name("crisv32-" TYPE_CRIS_CPU);
+        return object_class_by_name(CRIS_CPU_TYPE_NAME("crisv32"));
     }
 #endif
 
-    typename = g_strdup_printf("%s-" TYPE_CRIS_CPU, cpu_model);
+    typename = g_strdup_printf(CRIS_CPU_TYPE_NAME("%s"), cpu_model);
     oc = object_class_by_name(typename);
     g_free(typename);
     if (oc != NULL && (!object_class_dynamic_cast(oc, TYPE_CRIS_CPU) ||
@@ -108,7 +108,7 @@ static void cris_cpu_list_entry(gpointer data, gpointer user_data)
     const char *typename = object_class_get_name(oc);
     char *name;
 
-    name = g_strndup(typename, strlen(typename) - strlen("-" TYPE_CRIS_CPU));
+    name = g_strndup(typename, strlen(typename) - strlen(CRIS_CPU_TYPE_SUFFIX));
     (*s->cpu_fprintf)(s->file, "  %s\n", name);
     g_free(name);
 }
@@ -259,38 +259,6 @@ static void crisv32_cpu_class_init(ObjectClass *oc, void *data)
     ccc->vr = 32;
 }
 
-#define TYPE(model) model "-" TYPE_CRIS_CPU
-
-static const TypeInfo cris_cpu_model_type_infos[] = {
-    {
-        .name = TYPE("crisv8"),
-        .parent = TYPE_CRIS_CPU,
-        .class_init = crisv8_cpu_class_init,
-    }, {
-        .name = TYPE("crisv9"),
-        .parent = TYPE_CRIS_CPU,
-        .class_init = crisv9_cpu_class_init,
-    }, {
-        .name = TYPE("crisv10"),
-        .parent = TYPE_CRIS_CPU,
-        .class_init = crisv10_cpu_class_init,
-    }, {
-        .name = TYPE("crisv11"),
-        .parent = TYPE_CRIS_CPU,
-        .class_init = crisv11_cpu_class_init,
-    }, {
-        .name = TYPE("crisv17"),
-        .parent = TYPE_CRIS_CPU,
-        .class_init = crisv17_cpu_class_init,
-    }, {
-        .name = TYPE("crisv32"),
-        .parent = TYPE_CRIS_CPU,
-        .class_init = crisv32_cpu_class_init,
-    }
-};
-
-#undef TYPE
-
 static void cris_cpu_class_init(ObjectClass *oc, void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(oc);
@@ -324,24 +292,41 @@ static void cris_cpu_class_init(ObjectClass *oc, void *data)
     cc->disas_set_info = cris_disas_set_info;
 }
 
-static const TypeInfo cris_cpu_type_info = {
-    .name = TYPE_CRIS_CPU,
-    .parent = TYPE_CPU,
-    .instance_size = sizeof(CRISCPU),
-    .instance_init = cris_cpu_initfn,
-    .abstract = true,
-    .class_size = sizeof(CRISCPUClass),
-    .class_init = cris_cpu_class_init,
-};
-
-static void cris_cpu_register_types(void)
-{
-    int i;
-
-    type_register_static(&cris_cpu_type_info);
-    for (i = 0; i < ARRAY_SIZE(cris_cpu_model_type_infos); i++) {
-        type_register_static(&cris_cpu_model_type_infos[i]);
+static const TypeInfo cris_cpu_model_type_infos[] = {
+    {
+        .name = TYPE_CRIS_CPU,
+        .parent = TYPE_CPU,
+        .instance_size = sizeof(CRISCPU),
+        .instance_init = cris_cpu_initfn,
+        .abstract = true,
+        .class_size = sizeof(CRISCPUClass),
+        .class_init = cris_cpu_class_init,
+    },
+    {
+        .name = CRIS_CPU_TYPE_NAME("crisv8"),
+        .parent = TYPE_CRIS_CPU,
+        .class_init = crisv8_cpu_class_init,
+    }, {
+        .name = CRIS_CPU_TYPE_NAME("crisv9"),
+        .parent = TYPE_CRIS_CPU,
+        .class_init = crisv9_cpu_class_init,
+    }, {
+        .name = CRIS_CPU_TYPE_NAME("crisv10"),
+        .parent = TYPE_CRIS_CPU,
+        .class_init = crisv10_cpu_class_init,
+    }, {
+        .name = CRIS_CPU_TYPE_NAME("crisv11"),
+        .parent = TYPE_CRIS_CPU,
+        .class_init = crisv11_cpu_class_init,
+    }, {
+        .name = CRIS_CPU_TYPE_NAME("crisv17"),
+        .parent = TYPE_CRIS_CPU,
+        .class_init = crisv17_cpu_class_init,
+    }, {
+        .name = CRIS_CPU_TYPE_NAME("crisv32"),
+        .parent = TYPE_CRIS_CPU,
+        .class_init = crisv32_cpu_class_init,
     }
-}
+};
 
-type_init(cris_cpu_register_types)
+type_init_from_array(cris_cpu_model_type_infos)
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 113+ messages in thread

* [Qemu-devel] [PATCH 05/38] cris: use generic cpu_model parsing
  2017-10-02  9:07 [Qemu-devel] [PATCH 00/38] generalize parsing of cpu_model (part 2) Igor Mammedov
                   ` (3 preceding siblings ...)
  2017-10-02  9:07 ` [Qemu-devel] [PATCH 04/38] cris: cleanup cpu type name composition Igor Mammedov
@ 2017-10-02  9:07 ` Igor Mammedov
  2017-10-02 14:52   ` Philippe Mathieu-Daudé
  2017-10-02  9:07 ` [Qemu-devel] [PATCH 06/38] lm32: cleanup cpu type name composition Igor Mammedov
                   ` (32 subsequent siblings)
  37 siblings, 1 reply; 113+ messages in thread
From: Igor Mammedov @ 2017-10-02  9:07 UTC (permalink / raw)
  To: qemu-devel; +Cc: Philippe Mathieu-Daudé, edgar.iglesias

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
---
CC: edgar.iglesias@gmail.com
---
 hw/cris/axis_dev88.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/hw/cris/axis_dev88.c b/hw/cris/axis_dev88.c
index 5eb552b..9ccc435 100644
--- a/hw/cris/axis_dev88.c
+++ b/hw/cris/axis_dev88.c
@@ -251,7 +251,6 @@ static
 void axisdev88_init(MachineState *machine)
 {
     ram_addr_t ram_size = machine->ram_size;
-    const char *cpu_model = machine->cpu_model;
     const char *kernel_filename = machine->kernel_filename;
     const char *kernel_cmdline = machine->kernel_cmdline;
     CRISCPU *cpu;
@@ -268,10 +267,7 @@ void axisdev88_init(MachineState *machine)
     MemoryRegion *phys_intmem = g_new(MemoryRegion, 1);
 
     /* init CPUs */
-    if (cpu_model == NULL) {
-        cpu_model = "crisv32";
-    }
-    cpu = CRIS_CPU(cpu_generic_init(TYPE_CRIS_CPU, cpu_model));
+    cpu = CRIS_CPU(cpu_create(machine->cpu_type));
     env = &cpu->env;
 
     /* allocate RAM */
@@ -359,6 +355,7 @@ static void axisdev88_machine_init(MachineClass *mc)
     mc->desc = "AXIS devboard 88";
     mc->init = axisdev88_init;
     mc->is_default = 1;
+    mc->default_cpu_type = CRIS_CPU_TYPE_NAME("crisv32");
 }
 
 DEFINE_MACHINE("axis-dev88", axisdev88_machine_init)
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 113+ messages in thread

* [Qemu-devel] [PATCH 06/38] lm32: cleanup cpu type name composition
  2017-10-02  9:07 [Qemu-devel] [PATCH 00/38] generalize parsing of cpu_model (part 2) Igor Mammedov
                   ` (4 preceding siblings ...)
  2017-10-02  9:07 ` [Qemu-devel] [PATCH 05/38] cris: use generic cpu_model parsing Igor Mammedov
@ 2017-10-02  9:07 ` Igor Mammedov
  2017-10-02 20:28   ` Philippe Mathieu-Daudé
  2017-10-03 13:00   ` Michael Walle
  2017-10-02  9:07 ` [Qemu-devel] [PATCH 07/38] lm32: milkymist: use generic cpu_model parsing Igor Mammedov
                   ` (31 subsequent siblings)
  37 siblings, 2 replies; 113+ messages in thread
From: Igor Mammedov @ 2017-10-02  9:07 UTC (permalink / raw)
  To: qemu-devel; +Cc: Philippe Mathieu-Daudé, michael

introduce LM32_CPU_TYPE_NAME macro and consistently use it
to construct cpu type names. While at it replace dynamic
cpu type name composition with static data.

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
---
CC: michael@walle.cc
---
 target/lm32/cpu.h |  3 +++
 target/lm32/cpu.c | 74 +++++++++++++++++--------------------------------------
 2 files changed, 25 insertions(+), 52 deletions(-)

diff --git a/target/lm32/cpu.h b/target/lm32/cpu.h
index de265b5..2279594 100644
--- a/target/lm32/cpu.h
+++ b/target/lm32/cpu.h
@@ -257,6 +257,9 @@ bool lm32_cpu_do_semihosting(CPUState *cs);
 
 #define cpu_init(cpu_model) cpu_generic_init(TYPE_LM32_CPU, cpu_model)
 
+#define LM32_CPU_TYPE_SUFFIX "-" TYPE_LM32_CPU
+#define LM32_CPU_TYPE_NAME(model) model LM32_CPU_TYPE_SUFFIX
+
 #define cpu_list lm32_cpu_list
 #define cpu_signal_handler cpu_lm32_signal_handler
 
diff --git a/target/lm32/cpu.c b/target/lm32/cpu.c
index bf081f5..4d0da50 100644
--- a/target/lm32/cpu.c
+++ b/target/lm32/cpu.c
@@ -51,7 +51,7 @@ static void lm32_cpu_list_entry(gpointer data, gpointer user_data)
     const char *typename = object_class_get_name(oc);
     char *name;
 
-    name = g_strndup(typename, strlen(typename) - strlen("-" TYPE_LM32_CPU));
+    name = g_strndup(typename, strlen(typename) - strlen(LM32_CPU_TYPE_SUFFIX));
     (*s->cpu_fprintf)(s->file, "  %s\n", name);
     g_free(name);
 }
@@ -221,32 +221,12 @@ static void lm32_full_cpu_initfn(Object *obj)
                   | LM32_FEATURE_CYCLE_COUNT;
 }
 
-typedef struct LM32CPUInfo {
-    const char *name;
-    void (*initfn)(Object *obj);
-} LM32CPUInfo;
-
-static const LM32CPUInfo lm32_cpus[] = {
-    {
-        .name = "lm32-basic",
-        .initfn = lm32_basic_cpu_initfn,
-    },
-    {
-        .name = "lm32-standard",
-        .initfn = lm32_standard_cpu_initfn,
-    },
-    {
-        .name = "lm32-full",
-        .initfn = lm32_full_cpu_initfn,
-    },
-};
-
 static ObjectClass *lm32_cpu_class_by_name(const char *cpu_model)
 {
     ObjectClass *oc;
     char *typename;
 
-    typename = g_strdup_printf("%s-" TYPE_LM32_CPU, cpu_model);
+    typename = g_strdup_printf(LM32_CPU_TYPE_NAME("%s"), cpu_model);
     oc = object_class_by_name(typename);
     g_free(typename);
     if (oc != NULL && (!object_class_dynamic_cast(oc, TYPE_LM32_CPU) ||
@@ -288,36 +268,26 @@ static void lm32_cpu_class_init(ObjectClass *oc, void *data)
     cc->disas_set_info = lm32_cpu_disas_set_info;
 }
 
-static void lm32_register_cpu_type(const LM32CPUInfo *info)
-{
-    TypeInfo type_info = {
-        .parent = TYPE_LM32_CPU,
-        .instance_init = info->initfn,
-    };
-
-    type_info.name = g_strdup_printf("%s-" TYPE_LM32_CPU, info->name);
-    type_register(&type_info);
-    g_free((void *)type_info.name);
-}
+#define DEFINE_LM32_CPU_TYPE(cpu_model, initfn) \
+    { \
+        .parent = TYPE_LM32_CPU, \
+        .name = LM32_CPU_TYPE_NAME(cpu_model), \
+        .instance_init = initfn, \
+    }
 
-static const TypeInfo lm32_cpu_type_info = {
-    .name = TYPE_LM32_CPU,
-    .parent = TYPE_CPU,
-    .instance_size = sizeof(LM32CPU),
-    .instance_init = lm32_cpu_initfn,
-    .abstract = true,
-    .class_size = sizeof(LM32CPUClass),
-    .class_init = lm32_cpu_class_init,
+static const TypeInfo lm32_cpus_type_infos[] = {
+    { /* base class should be registered first */
+         .name = TYPE_LM32_CPU,
+         .parent = TYPE_CPU,
+         .instance_size = sizeof(LM32CPU),
+         .instance_init = lm32_cpu_initfn,
+         .abstract = true,
+         .class_size = sizeof(LM32CPUClass),
+         .class_init = lm32_cpu_class_init,
+    },
+    DEFINE_LM32_CPU_TYPE("lm32-basic", lm32_basic_cpu_initfn),
+    DEFINE_LM32_CPU_TYPE("lm32-standard", lm32_standard_cpu_initfn),
+    DEFINE_LM32_CPU_TYPE("lm32-full", lm32_full_cpu_initfn),
 };
 
-static void lm32_cpu_register_types(void)
-{
-    int i;
-
-    type_register_static(&lm32_cpu_type_info);
-    for (i = 0; i < ARRAY_SIZE(lm32_cpus); i++) {
-        lm32_register_cpu_type(&lm32_cpus[i]);
-    }
-}
-
-type_init(lm32_cpu_register_types)
+type_init_from_array(lm32_cpus_type_infos)
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 113+ messages in thread

* [Qemu-devel] [PATCH 07/38] lm32: milkymist: use generic cpu_model parsing
  2017-10-02  9:07 [Qemu-devel] [PATCH 00/38] generalize parsing of cpu_model (part 2) Igor Mammedov
                   ` (5 preceding siblings ...)
  2017-10-02  9:07 ` [Qemu-devel] [PATCH 06/38] lm32: cleanup cpu type name composition Igor Mammedov
@ 2017-10-02  9:07 ` Igor Mammedov
  2017-10-02 20:28   ` Philippe Mathieu-Daudé
  2017-10-03 13:01   ` Michael Walle
  2017-10-02  9:07 ` [Qemu-devel] [PATCH 08/38] lm32: lm32_boards: " Igor Mammedov
                   ` (30 subsequent siblings)
  37 siblings, 2 replies; 113+ messages in thread
From: Igor Mammedov @ 2017-10-02  9:07 UTC (permalink / raw)
  To: qemu-devel; +Cc: Philippe Mathieu-Daudé, michael

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
---
CC: michael@walle.cc
---
 hw/lm32/milkymist.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/hw/lm32/milkymist.c b/hw/lm32/milkymist.c
index 4db4d2d..d4e765f 100644
--- a/hw/lm32/milkymist.c
+++ b/hw/lm32/milkymist.c
@@ -80,7 +80,6 @@ static void main_cpu_reset(void *opaque)
 static void
 milkymist_init(MachineState *machine)
 {
-    const char *cpu_model = machine->cpu_model;
     const char *kernel_filename = machine->kernel_filename;
     const char *kernel_cmdline = machine->kernel_cmdline;
     const char *initrd_filename = machine->initrd_filename;
@@ -108,10 +107,7 @@ milkymist_init(MachineState *machine)
 
     reset_info = g_malloc0(sizeof(ResetInfo));
 
-    if (cpu_model == NULL) {
-        cpu_model = "lm32-full";
-    }
-    cpu = LM32_CPU(cpu_generic_init(TYPE_LM32_CPU, cpu_model));
+    cpu = LM32_CPU(cpu_create(machine->cpu_type));
 
     env = &cpu->env;
     reset_info->cpu = cpu;
@@ -216,6 +212,7 @@ static void milkymist_machine_init(MachineClass *mc)
     mc->desc = "Milkymist One";
     mc->init = milkymist_init;
     mc->is_default = 0;
+    mc->default_cpu_type = LM32_CPU_TYPE_NAME("lm32-full");
 }
 
 DEFINE_MACHINE("milkymist", milkymist_machine_init)
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 113+ messages in thread

* [Qemu-devel] [PATCH 08/38] lm32: lm32_boards: use generic cpu_model parsing
  2017-10-02  9:07 [Qemu-devel] [PATCH 00/38] generalize parsing of cpu_model (part 2) Igor Mammedov
                   ` (6 preceding siblings ...)
  2017-10-02  9:07 ` [Qemu-devel] [PATCH 07/38] lm32: milkymist: use generic cpu_model parsing Igor Mammedov
@ 2017-10-02  9:07 ` Igor Mammedov
  2017-10-02 20:29   ` Philippe Mathieu-Daudé
  2017-10-03 13:01   ` Michael Walle
  2017-10-02  9:07 ` [Qemu-devel] [PATCH 09/38] m68k: cleanup cpu type name composition Igor Mammedov
                   ` (29 subsequent siblings)
  37 siblings, 2 replies; 113+ messages in thread
From: Igor Mammedov @ 2017-10-02  9:07 UTC (permalink / raw)
  To: qemu-devel; +Cc: Philippe Mathieu-Daudé, michael

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
---
CC: michael@walle.cc
---
 hw/lm32/lm32_boards.c | 14 ++++----------
 1 file changed, 4 insertions(+), 10 deletions(-)

diff --git a/hw/lm32/lm32_boards.c b/hw/lm32/lm32_boards.c
index b0bb3ef..002d638 100644
--- a/hw/lm32/lm32_boards.c
+++ b/hw/lm32/lm32_boards.c
@@ -75,7 +75,6 @@ static void main_cpu_reset(void *opaque)
 
 static void lm32_evr_init(MachineState *machine)
 {
-    const char *cpu_model = machine->cpu_model;
     const char *kernel_filename = machine->kernel_filename;
     LM32CPU *cpu;
     CPULM32State *env;
@@ -101,10 +100,7 @@ static void lm32_evr_init(MachineState *machine)
 
     reset_info = g_malloc0(sizeof(ResetInfo));
 
-    if (cpu_model == NULL) {
-        cpu_model = "lm32-full";
-    }
-    cpu = LM32_CPU(cpu_generic_init(TYPE_LM32_CPU, cpu_model));
+    cpu = LM32_CPU(cpu_create(machine->cpu_type));
 
     env = &cpu->env;
     reset_info->cpu = cpu;
@@ -163,7 +159,6 @@ static void lm32_evr_init(MachineState *machine)
 
 static void lm32_uclinux_init(MachineState *machine)
 {
-    const char *cpu_model = machine->cpu_model;
     const char *kernel_filename = machine->kernel_filename;
     const char *kernel_cmdline = machine->kernel_cmdline;
     const char *initrd_filename = machine->initrd_filename;
@@ -198,10 +193,7 @@ static void lm32_uclinux_init(MachineState *machine)
 
     reset_info = g_malloc0(sizeof(ResetInfo));
 
-    if (cpu_model == NULL) {
-        cpu_model = "lm32-full";
-    }
-    cpu = LM32_CPU(cpu_generic_init(TYPE_LM32_CPU, cpu_model));
+    cpu = LM32_CPU(cpu_create(machine->cpu_type));
 
     env = &cpu->env;
     reset_info->cpu = cpu;
@@ -295,6 +287,7 @@ static void lm32_evr_class_init(ObjectClass *oc, void *data)
     mc->desc = "LatticeMico32 EVR32 eval system";
     mc->init = lm32_evr_init;
     mc->is_default = 1;
+    mc->default_cpu_type = LM32_CPU_TYPE_NAME("lm32-full");
 }
 
 static const TypeInfo lm32_evr_type = {
@@ -310,6 +303,7 @@ static void lm32_uclinux_class_init(ObjectClass *oc, void *data)
     mc->desc = "lm32 platform for uClinux and u-boot by Theobroma Systems";
     mc->init = lm32_uclinux_init;
     mc->is_default = 0;
+    mc->default_cpu_type = LM32_CPU_TYPE_NAME("lm32-full");
 }
 
 static const TypeInfo lm32_uclinux_type = {
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 113+ messages in thread

* [Qemu-devel] [PATCH 09/38] m68k: cleanup cpu type name composition
  2017-10-02  9:07 [Qemu-devel] [PATCH 00/38] generalize parsing of cpu_model (part 2) Igor Mammedov
                   ` (7 preceding siblings ...)
  2017-10-02  9:07 ` [Qemu-devel] [PATCH 08/38] lm32: lm32_boards: " Igor Mammedov
@ 2017-10-02  9:07 ` Igor Mammedov
  2017-10-03 13:31   ` Philippe Mathieu-Daudé
  2017-10-03 14:50   ` Laurent Vivier
  2017-10-02  9:07 ` [Qemu-devel] [PATCH 10/38] m68k: an5206: use generic cpu_model parsing Igor Mammedov
                   ` (28 subsequent siblings)
  37 siblings, 2 replies; 113+ messages in thread
From: Igor Mammedov @ 2017-10-02  9:07 UTC (permalink / raw)
  To: qemu-devel; +Cc: Philippe Mathieu-Daudé, laurent

use new M68K_CPU_TYPE_NAME to compose CPU type names
and get rid of intermediate M68kCPUInfo/register_cpu_type()
which is replaced by static TypeInfo array.

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
---
CC: laurent@vivier.eu
---
 target/m68k/cpu.h |  3 +++
 target/m68k/cpu.c | 75 ++++++++++++++++++++-----------------------------------
 2 files changed, 30 insertions(+), 48 deletions(-)

diff --git a/target/m68k/cpu.h b/target/m68k/cpu.h
index d936547..afae5f6 100644
--- a/target/m68k/cpu.h
+++ b/target/m68k/cpu.h
@@ -323,6 +323,9 @@ void register_m68k_insns (CPUM68KState *env);
 
 #define cpu_init(cpu_model) cpu_generic_init(TYPE_M68K_CPU, cpu_model)
 
+#define M68K_CPU_TYPE_SUFFIX "-" TYPE_M68K_CPU
+#define M68K_CPU_TYPE_NAME(model) model M68K_CPU_TYPE_SUFFIX
+
 #define cpu_signal_handler cpu_m68k_signal_handler
 #define cpu_list m68k_cpu_list
 
diff --git a/target/m68k/cpu.c b/target/m68k/cpu.c
index 8c70e08..f0f90e9 100644
--- a/target/m68k/cpu.c
+++ b/target/m68k/cpu.c
@@ -87,7 +87,7 @@ static ObjectClass *m68k_cpu_class_by_name(const char *cpu_model)
     ObjectClass *oc;
     char *typename;
 
-    typename = g_strdup_printf("%s-" TYPE_M68K_CPU, cpu_model);
+    typename = g_strdup_printf(M68K_CPU_TYPE_NAME("%s"), cpu_model);
     oc = object_class_by_name(typename);
     g_free(typename);
     if (oc != NULL && (object_class_dynamic_cast(oc, TYPE_M68K_CPU) == NULL ||
@@ -202,23 +202,6 @@ static void any_cpu_initfn(Object *obj)
     m68k_set_feature(env, M68K_FEATURE_WORD_INDEX);
 }
 
-typedef struct M68kCPUInfo {
-    const char *name;
-    void (*instance_init)(Object *obj);
-} M68kCPUInfo;
-
-static const M68kCPUInfo m68k_cpus[] = {
-    { .name = "m68000", .instance_init = m68000_cpu_initfn },
-    { .name = "m68020", .instance_init = m68020_cpu_initfn },
-    { .name = "m68030", .instance_init = m68030_cpu_initfn },
-    { .name = "m68040", .instance_init = m68040_cpu_initfn },
-    { .name = "m68060", .instance_init = m68060_cpu_initfn },
-    { .name = "m5206", .instance_init = m5206_cpu_initfn },
-    { .name = "m5208", .instance_init = m5208_cpu_initfn },
-    { .name = "cfv4e", .instance_init = cfv4e_cpu_initfn },
-    { .name = "any",   .instance_init = any_cpu_initfn },
-};
-
 static void m68k_cpu_realizefn(DeviceState *dev, Error **errp)
 {
     CPUState *cs = CPU(dev);
@@ -295,36 +278,32 @@ static void m68k_cpu_class_init(ObjectClass *c, void *data)
     dc->vmsd = &vmstate_m68k_cpu;
 }
 
-static void register_cpu_type(const M68kCPUInfo *info)
-{
-    TypeInfo type_info = {
-        .parent = TYPE_M68K_CPU,
-        .instance_init = info->instance_init,
-    };
-
-    type_info.name = g_strdup_printf("%s-" TYPE_M68K_CPU, info->name);
-    type_register(&type_info);
-    g_free((void *)type_info.name);
-}
+#define DEFINE_M68K_CPU_TYPE(cpu_model, initfn) \
+    {                                           \
+        .name = M68K_CPU_TYPE_NAME(cpu_model),  \
+        .instance_init = initfn,                \
+        .parent = TYPE_M68K_CPU,                \
+    }
 
-static const TypeInfo m68k_cpu_type_info = {
-    .name = TYPE_M68K_CPU,
-    .parent = TYPE_CPU,
-    .instance_size = sizeof(M68kCPU),
-    .instance_init = m68k_cpu_initfn,
-    .abstract = true,
-    .class_size = sizeof(M68kCPUClass),
-    .class_init = m68k_cpu_class_init,
+static const TypeInfo m68k_cpus_type_infos[] = {
+    { /* base class should be registered first */
+        .name = TYPE_M68K_CPU,
+        .parent = TYPE_CPU,
+        .instance_size = sizeof(M68kCPU),
+        .instance_init = m68k_cpu_initfn,
+        .abstract = true,
+        .class_size = sizeof(M68kCPUClass),
+        .class_init = m68k_cpu_class_init,
+    },
+    DEFINE_M68K_CPU_TYPE("m68000", m68000_cpu_initfn),
+    DEFINE_M68K_CPU_TYPE("m68020", m68020_cpu_initfn),
+    DEFINE_M68K_CPU_TYPE("m68030", m68030_cpu_initfn),
+    DEFINE_M68K_CPU_TYPE("m68040", m68040_cpu_initfn),
+    DEFINE_M68K_CPU_TYPE("m68060", m68060_cpu_initfn),
+    DEFINE_M68K_CPU_TYPE("m5206", m5206_cpu_initfn),
+    DEFINE_M68K_CPU_TYPE("m5208", m5208_cpu_initfn),
+    DEFINE_M68K_CPU_TYPE("cfv4e", cfv4e_cpu_initfn),
+    DEFINE_M68K_CPU_TYPE("any", any_cpu_initfn),
 };
 
-static void m68k_cpu_register_types(void)
-{
-    int i;
-
-    type_register_static(&m68k_cpu_type_info);
-    for (i = 0; i < ARRAY_SIZE(m68k_cpus); i++) {
-        register_cpu_type(&m68k_cpus[i]);
-    }
-}
-
-type_init(m68k_cpu_register_types)
+type_init_from_array(m68k_cpus_type_infos)
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 113+ messages in thread

* [Qemu-devel] [PATCH 10/38] m68k: an5206: use generic cpu_model parsing
  2017-10-02  9:07 [Qemu-devel] [PATCH 00/38] generalize parsing of cpu_model (part 2) Igor Mammedov
                   ` (8 preceding siblings ...)
  2017-10-02  9:07 ` [Qemu-devel] [PATCH 09/38] m68k: cleanup cpu type name composition Igor Mammedov
@ 2017-10-02  9:07 ` Igor Mammedov
  2017-10-03  9:13   ` Thomas Huth
                     ` (2 more replies)
  2017-10-02  9:07 ` [Qemu-devel] [PATCH 11/38] m68k: mcf5208: " Igor Mammedov
                   ` (27 subsequent siblings)
  37 siblings, 3 replies; 113+ messages in thread
From: Igor Mammedov @ 2017-10-02  9:07 UTC (permalink / raw)
  To: qemu-devel; +Cc: Philippe Mathieu-Daudé, huth, laurent

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
---
CC: huth@tuxfamily.org
CC: laurent@vivier.eu
---
 hw/m68k/an5206.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/hw/m68k/an5206.c b/hw/m68k/an5206.c
index 9002c46..0cedc54 100644
--- a/hw/m68k/an5206.c
+++ b/hw/m68k/an5206.c
@@ -28,7 +28,6 @@
 static void an5206_init(MachineState *machine)
 {
     ram_addr_t ram_size = machine->ram_size;
-    const char *cpu_model = machine->cpu_model;
     const char *kernel_filename = machine->kernel_filename;
     M68kCPU *cpu;
     CPUM68KState *env;
@@ -39,10 +38,7 @@ static void an5206_init(MachineState *machine)
     MemoryRegion *ram = g_new(MemoryRegion, 1);
     MemoryRegion *sram = g_new(MemoryRegion, 1);
 
-    if (!cpu_model) {
-        cpu_model = "m5206";
-    }
-    cpu = M68K_CPU(cpu_generic_init(TYPE_M68K_CPU, cpu_model));
+    cpu = M68K_CPU(cpu_create(machine->cpu_type));
     env = &cpu->env;
 
     /* Initialize CPU registers.  */
@@ -94,6 +90,7 @@ static void an5206_machine_init(MachineClass *mc)
 {
     mc->desc = "Arnewsh 5206";
     mc->init = an5206_init;
+    mc->default_cpu_type = M68K_CPU_TYPE_NAME("m5206");
 }
 
 DEFINE_MACHINE("an5206", an5206_machine_init)
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 113+ messages in thread

* [Qemu-devel] [PATCH 11/38] m68k: mcf5208: use generic cpu_model parsing
  2017-10-02  9:07 [Qemu-devel] [PATCH 00/38] generalize parsing of cpu_model (part 2) Igor Mammedov
                   ` (9 preceding siblings ...)
  2017-10-02  9:07 ` [Qemu-devel] [PATCH 10/38] m68k: an5206: use generic cpu_model parsing Igor Mammedov
@ 2017-10-02  9:07 ` Igor Mammedov
  2017-10-03  9:28   ` Thomas Huth
                     ` (2 more replies)
  2017-10-02  9:07 ` [Qemu-devel] [PATCH 12/38] moxie: fix qemu-system-moxie failing to start with CLI "-cpu MoxieLite" Igor Mammedov
                   ` (26 subsequent siblings)
  37 siblings, 3 replies; 113+ messages in thread
From: Igor Mammedov @ 2017-10-02  9:07 UTC (permalink / raw)
  To: qemu-devel; +Cc: Philippe Mathieu-Daudé, laurent, huth

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
---
CC: laurent@vivier.eu
CC: huth@tuxfamily.org
---
 hw/m68k/mcf5208.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/hw/m68k/mcf5208.c b/hw/m68k/mcf5208.c
index b9dde75..cfac845 100644
--- a/hw/m68k/mcf5208.c
+++ b/hw/m68k/mcf5208.c
@@ -217,7 +217,6 @@ static void mcf_fec_init(MemoryRegion *sysmem, NICInfo *nd, hwaddr base,
 static void mcf5208evb_init(MachineState *machine)
 {
     ram_addr_t ram_size = machine->ram_size;
-    const char *cpu_model = machine->cpu_model;
     const char *kernel_filename = machine->kernel_filename;
     M68kCPU *cpu;
     CPUM68KState *env;
@@ -229,10 +228,7 @@ static void mcf5208evb_init(MachineState *machine)
     MemoryRegion *ram = g_new(MemoryRegion, 1);
     MemoryRegion *sram = g_new(MemoryRegion, 1);
 
-    if (!cpu_model) {
-        cpu_model = "m5208";
-    }
-    cpu = M68K_CPU(cpu_generic_init(TYPE_M68K_CPU, cpu_model));
+    cpu = M68K_CPU(cpu_create(machine->cpu_type));
     env = &cpu->env;
 
     /* Initialize CPU registers.  */
@@ -321,6 +317,7 @@ static void mcf5208evb_machine_init(MachineClass *mc)
     mc->desc = "MCF5206EVB";
     mc->init = mcf5208evb_init;
     mc->is_default = 1;
+    mc->default_cpu_type = M68K_CPU_TYPE_NAME("m5208");
 }
 
 DEFINE_MACHINE("mcf5208evb", mcf5208evb_machine_init)
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 113+ messages in thread

* [Qemu-devel] [PATCH 12/38] moxie: fix qemu-system-moxie failing to start with CLI "-cpu MoxieLite"
  2017-10-02  9:07 [Qemu-devel] [PATCH 00/38] generalize parsing of cpu_model (part 2) Igor Mammedov
                   ` (10 preceding siblings ...)
  2017-10-02  9:07 ` [Qemu-devel] [PATCH 11/38] m68k: mcf5208: " Igor Mammedov
@ 2017-10-02  9:07 ` Igor Mammedov
  2017-10-03 13:37   ` Philippe Mathieu-Daudé
  2017-10-02  9:07 ` [Qemu-devel] [PATCH 13/38] moxie: cleanup cpu type name composition Igor Mammedov
                   ` (25 subsequent siblings)
  37 siblings, 1 reply; 113+ messages in thread
From: Igor Mammedov @ 2017-10-02  9:07 UTC (permalink / raw)
  To: qemu-devel; +Cc: Philippe Mathieu-Daudé, green

It 'works' with default CPU only because of bug in
moxie_cpu_class_by_name() where it treats cpu_model
as type name and default cpu_model also happens to be
type name. But specifying explicitly cpu on CLI,
ex: '-cpu MoxieLite', makes QEMU fail since
moxie_cpu_class_by_name() doesn't traslate cpu_model
to cpu type and fails to find corresponding object class.

Fix moxie_cpu_class_by_name() to do proper
   cpu_model -> cpu type
translation and fix default cpu_model to be cpu_model
instead of being typename.

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
---
CC: green@moxielogic.com
---
 hw/moxie/moxiesim.c | 2 +-
 target/moxie/cpu.c  | 7 ++++++-
 2 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/hw/moxie/moxiesim.c b/hw/moxie/moxiesim.c
index 5ea8dd3..01b9f34 100644
--- a/hw/moxie/moxiesim.c
+++ b/hw/moxie/moxiesim.c
@@ -116,7 +116,7 @@ static void moxiesim_init(MachineState *machine)
 
     /* Init CPUs. */
     if (cpu_model == NULL) {
-        cpu_model = "MoxieLite-moxie-cpu";
+        cpu_model = "MoxieLite";
     }
     cpu = MOXIE_CPU(cpu_generic_init(TYPE_MOXIE_CPU, cpu_model));
     env = &cpu->env;
diff --git a/target/moxie/cpu.c b/target/moxie/cpu.c
index 30bd44f..d4626a1 100644
--- a/target/moxie/cpu.c
+++ b/target/moxie/cpu.c
@@ -89,7 +89,12 @@ static void moxie_cpu_initfn(Object *obj)
 
 static ObjectClass *moxie_cpu_class_by_name(const char *cpu_model)
 {
-    ObjectClass *oc = object_class_by_name(cpu_model);
+    ObjectClass *oc;
+    char *typename;
+
+    typename = g_strdup_printf("%s-" TYPE_MOXIE_CPU, cpu_model);
+    oc = object_class_by_name(typename);
+    g_free(typename);
     if (oc != NULL && (!object_class_dynamic_cast(oc, TYPE_MOXIE_CPU) ||
                        object_class_is_abstract(oc))) {
         return NULL;
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 113+ messages in thread

* [Qemu-devel] [PATCH 13/38] moxie: cleanup cpu type name composition
  2017-10-02  9:07 [Qemu-devel] [PATCH 00/38] generalize parsing of cpu_model (part 2) Igor Mammedov
                   ` (11 preceding siblings ...)
  2017-10-02  9:07 ` [Qemu-devel] [PATCH 12/38] moxie: fix qemu-system-moxie failing to start with CLI "-cpu MoxieLite" Igor Mammedov
@ 2017-10-02  9:07 ` Igor Mammedov
  2017-10-02 14:54   ` Philippe Mathieu-Daudé
  2017-10-02  9:07 ` [Qemu-devel] [PATCH 14/38] moxie: use generic cpu_model parsing Igor Mammedov
                   ` (24 subsequent siblings)
  37 siblings, 1 reply; 113+ messages in thread
From: Igor Mammedov @ 2017-10-02  9:07 UTC (permalink / raw)
  To: qemu-devel; +Cc: Philippe Mathieu-Daudé, green

introduce MOXIE_CPU_TYPE_NAME macro and consistently use it
to construct cpu type names. While at it replace dynamic
cpu type name composition with static data.

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
---
CC: green@moxielogic.com
---
 target/moxie/cpu.h |  3 +++
 target/moxie/cpu.c | 56 +++++++++++++++++-------------------------------------
 2 files changed, 20 insertions(+), 39 deletions(-)

diff --git a/target/moxie/cpu.h b/target/moxie/cpu.h
index 75decaa..d37e6a5 100644
--- a/target/moxie/cpu.h
+++ b/target/moxie/cpu.h
@@ -122,6 +122,9 @@ int cpu_moxie_signal_handler(int host_signum, void *pinfo,
 
 #define cpu_init(cpu_model) cpu_generic_init(TYPE_MOXIE_CPU, cpu_model)
 
+#define MOXIE_CPU_TYPE_SUFFIX "-" TYPE_MOXIE_CPU
+#define MOXIE_CPU_TYPE_NAME(model) model MOXIE_CPU_TYPE_SUFFIX
+
 #define cpu_signal_handler cpu_moxie_signal_handler
 
 static inline int cpu_mmu_index(CPUMoxieState *env, bool ifetch)
diff --git a/target/moxie/cpu.c b/target/moxie/cpu.c
index d4626a1..1ca8f1a 100644
--- a/target/moxie/cpu.c
+++ b/target/moxie/cpu.c
@@ -92,7 +92,7 @@ static ObjectClass *moxie_cpu_class_by_name(const char *cpu_model)
     ObjectClass *oc;
     char *typename;
 
-    typename = g_strdup_printf("%s-" TYPE_MOXIE_CPU, cpu_model);
+    typename = g_strdup_printf(MOXIE_CPU_TYPE_NAME("%s"), cpu_model);
     oc = object_class_by_name(typename);
     g_free(typename);
     if (oc != NULL && (!object_class_dynamic_cast(oc, TYPE_MOXIE_CPU) ||
@@ -139,46 +139,24 @@ static void moxie_any_initfn(Object *obj)
     /* Set cpu feature flags */
 }
 
-typedef struct MoxieCPUInfo {
-    const char *name;
-    void (*initfn)(Object *obj);
-} MoxieCPUInfo;
-
-static const MoxieCPUInfo moxie_cpus[] = {
-    { .name = "MoxieLite",      .initfn = moxielite_initfn },
-    { .name = "any",            .initfn = moxie_any_initfn },
-};
+#define DEFINE_MOXIE_CPU_TYPE(cpu_model, initfn) \
+    {                                            \
+        .parent = TYPE_MOXIE_CPU,                \
+        .instance_init = initfn,                 \
+        .name = MOXIE_CPU_TYPE_NAME(cpu_model),  \
+    }
 
-static void cpu_register(const MoxieCPUInfo *info)
-{
-    TypeInfo type_info = {
-        .parent = TYPE_MOXIE_CPU,
+static const TypeInfo moxie_cpus_type_infos[] = {
+    { /* base class should be registered first */
+        .name = TYPE_MOXIE_CPU,
+        .parent = TYPE_CPU,
         .instance_size = sizeof(MoxieCPU),
-        .instance_init = info->initfn,
+        .instance_init = moxie_cpu_initfn,
         .class_size = sizeof(MoxieCPUClass),
-    };
-
-    type_info.name = g_strdup_printf("%s-" TYPE_MOXIE_CPU, info->name);
-    type_register(&type_info);
-    g_free((void *)type_info.name);
-}
-
-static const TypeInfo moxie_cpu_type_info = {
-    .name = TYPE_MOXIE_CPU,
-    .parent = TYPE_CPU,
-    .instance_size = sizeof(MoxieCPU),
-    .instance_init = moxie_cpu_initfn,
-    .class_size = sizeof(MoxieCPUClass),
-    .class_init = moxie_cpu_class_init,
+        .class_init = moxie_cpu_class_init,
+    },
+    DEFINE_MOXIE_CPU_TYPE("MoxieLite", moxielite_initfn),
+    DEFINE_MOXIE_CPU_TYPE("any", moxie_any_initfn),
 };
 
-static void moxie_cpu_register_types(void)
-{
-    int i;
-    type_register_static(&moxie_cpu_type_info);
-    for (i = 0; i < ARRAY_SIZE(moxie_cpus); i++) {
-        cpu_register(&moxie_cpus[i]);
-    }
-}
-
-type_init(moxie_cpu_register_types)
+type_init_from_array(moxie_cpus_type_infos)
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 113+ messages in thread

* [Qemu-devel] [PATCH 14/38] moxie: use generic cpu_model parsing
  2017-10-02  9:07 [Qemu-devel] [PATCH 00/38] generalize parsing of cpu_model (part 2) Igor Mammedov
                   ` (12 preceding siblings ...)
  2017-10-02  9:07 ` [Qemu-devel] [PATCH 13/38] moxie: cleanup cpu type name composition Igor Mammedov
@ 2017-10-02  9:07 ` Igor Mammedov
  2017-10-02 14:13   ` Philippe Mathieu-Daudé
  2017-10-02  9:07 ` [Qemu-devel] [PATCH 15/38] openrisc: cleanup cpu type name composition Igor Mammedov
                   ` (23 subsequent siblings)
  37 siblings, 1 reply; 113+ messages in thread
From: Igor Mammedov @ 2017-10-02  9:07 UTC (permalink / raw)
  To: qemu-devel; +Cc: Philippe Mathieu-Daudé, green

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
---
CC: green@moxielogic.com
---
 hw/moxie/moxiesim.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/hw/moxie/moxiesim.c b/hw/moxie/moxiesim.c
index 01b9f34..3ba5848 100644
--- a/hw/moxie/moxiesim.c
+++ b/hw/moxie/moxiesim.c
@@ -103,7 +103,6 @@ static void moxiesim_init(MachineState *machine)
 {
     MoxieCPU *cpu = NULL;
     ram_addr_t ram_size = machine->ram_size;
-    const char *cpu_model = machine->cpu_model;
     const char *kernel_filename = machine->kernel_filename;
     const char *kernel_cmdline = machine->kernel_cmdline;
     const char *initrd_filename = machine->initrd_filename;
@@ -115,10 +114,7 @@ static void moxiesim_init(MachineState *machine)
     LoaderParams loader_params;
 
     /* Init CPUs. */
-    if (cpu_model == NULL) {
-        cpu_model = "MoxieLite";
-    }
-    cpu = MOXIE_CPU(cpu_generic_init(TYPE_MOXIE_CPU, cpu_model));
+    cpu = MOXIE_CPU(cpu_create(machine->cpu_type));
     env = &cpu->env;
 
     qemu_register_reset(main_cpu_reset, cpu);
@@ -150,6 +146,7 @@ static void moxiesim_machine_init(MachineClass *mc)
     mc->desc = "Moxie simulator platform";
     mc->init = moxiesim_init;
     mc->is_default = 1;
+    mc->default_cpu_type = MOXIE_CPU_TYPE_NAME("MoxieLite");
 }
 
 DEFINE_MACHINE("moxiesim", moxiesim_machine_init)
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 113+ messages in thread

* [Qemu-devel] [PATCH 15/38] openrisc: cleanup cpu type name composition
  2017-10-02  9:07 [Qemu-devel] [PATCH 00/38] generalize parsing of cpu_model (part 2) Igor Mammedov
                   ` (13 preceding siblings ...)
  2017-10-02  9:07 ` [Qemu-devel] [PATCH 14/38] moxie: use generic cpu_model parsing Igor Mammedov
@ 2017-10-02  9:07 ` Igor Mammedov
  2017-10-02 20:19   ` Philippe Mathieu-Daudé
  2017-10-02  9:07 ` [Qemu-devel] [PATCH 16/38] openrisc: use generic cpu_model parsing Igor Mammedov
                   ` (22 subsequent siblings)
  37 siblings, 1 reply; 113+ messages in thread
From: Igor Mammedov @ 2017-10-02  9:07 UTC (permalink / raw)
  To: qemu-devel; +Cc: Philippe Mathieu-Daudé, shorne

use new OPENRISC_CPU_TYPE_NAME to compose CPU type name and get
rid of intermediate OpenRISCCPUInfo/openrisc_cpu_register_types()
which is replaced by static TypeInfo array.

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
---
CC: shorne@gmail.com
---
 target/openrisc/cpu.h |  3 +++
 target/openrisc/cpu.c | 69 +++++++++++++++++----------------------------------
 2 files changed, 26 insertions(+), 46 deletions(-)

diff --git a/target/openrisc/cpu.h b/target/openrisc/cpu.h
index f51b89a..576cf66 100644
--- a/target/openrisc/cpu.h
+++ b/target/openrisc/cpu.h
@@ -390,6 +390,9 @@ int cpu_openrisc_get_phys_data(OpenRISCCPU *cpu,
 
 #define cpu_init(cpu_model) cpu_generic_init(TYPE_OPENRISC_CPU, cpu_model)
 
+#define OPENRISC_CPU_TYPE_SUFFIX "-" TYPE_OPENRISC_CPU
+#define OPENRISC_CPU_TYPE_NAME(model) model OPENRISC_CPU_TYPE_SUFFIX
+
 #include "exec/cpu-all.h"
 
 #define TB_FLAGS_DFLAG 1
diff --git a/target/openrisc/cpu.c b/target/openrisc/cpu.c
index af9cdcc..4dfb777 100644
--- a/target/openrisc/cpu.c
+++ b/target/openrisc/cpu.c
@@ -108,7 +108,7 @@ static ObjectClass *openrisc_cpu_class_by_name(const char *cpu_model)
     ObjectClass *oc;
     char *typename;
 
-    typename = g_strdup_printf("%s-" TYPE_OPENRISC_CPU, 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) ||
@@ -133,16 +133,6 @@ static void openrisc_any_initfn(Object *obj)
     cpu->env.cpucfgr = CPUCFGR_NSGF | CPUCFGR_OB32S | CPUCFGR_EVBARP;
 }
 
-typedef struct OpenRISCCPUInfo {
-    const char *name;
-    void (*initfn)(Object *obj);
-} OpenRISCCPUInfo;
-
-static const OpenRISCCPUInfo openrisc_cpus[] = {
-    { .name = "or1200",      .initfn = or1200_initfn },
-    { .name = "any",         .initfn = openrisc_any_initfn },
-};
-
 static void openrisc_cpu_class_init(ObjectClass *oc, void *data)
 {
     OpenRISCCPUClass *occ = OPENRISC_CPU_CLASS(oc);
@@ -172,40 +162,6 @@ static void openrisc_cpu_class_init(ObjectClass *oc, void *data)
     cc->gdb_num_core_regs = 32 + 3;
 }
 
-static void cpu_register(const OpenRISCCPUInfo *info)
-{
-    TypeInfo type_info = {
-        .parent = TYPE_OPENRISC_CPU,
-        .instance_size = sizeof(OpenRISCCPU),
-        .instance_init = info->initfn,
-        .class_size = sizeof(OpenRISCCPUClass),
-    };
-
-    type_info.name = g_strdup_printf("%s-" TYPE_OPENRISC_CPU, info->name);
-    type_register(&type_info);
-    g_free((void *)type_info.name);
-}
-
-static const TypeInfo openrisc_cpu_type_info = {
-    .name = TYPE_OPENRISC_CPU,
-    .parent = TYPE_CPU,
-    .instance_size = sizeof(OpenRISCCPU),
-    .instance_init = openrisc_cpu_initfn,
-    .abstract = true,
-    .class_size = sizeof(OpenRISCCPUClass),
-    .class_init = openrisc_cpu_class_init,
-};
-
-static void openrisc_cpu_register_types(void)
-{
-    int i;
-
-    type_register_static(&openrisc_cpu_type_info);
-    for (i = 0; i < ARRAY_SIZE(openrisc_cpus); i++) {
-        cpu_register(&openrisc_cpus[i]);
-    }
-}
-
 /* Sort alphabetically by type name, except for "any". */
 static gint openrisc_cpu_list_compare(gconstpointer a, gconstpointer b)
 {
@@ -254,4 +210,25 @@ void cpu_openrisc_list(FILE *f, fprintf_function cpu_fprintf)
     g_slist_free(list);
 }
 
-type_init(openrisc_cpu_register_types)
+#define DEFINE_OPENRISC_CPU_TYPE(cpu_model, initfn) \
+    {                                               \
+        .parent = TYPE_OPENRISC_CPU,                \
+        .instance_init = initfn,                    \
+        .name = OPENRISC_CPU_TYPE_NAME(cpu_model),  \
+    }
+
+static const TypeInfo openrisc_cpus_type_infos[] = {
+    { /* base class should be registered first */
+        .name = TYPE_OPENRISC_CPU,
+        .parent = TYPE_CPU,
+        .instance_size = sizeof(OpenRISCCPU),
+        .instance_init = openrisc_cpu_initfn,
+        .abstract = true,
+        .class_size = sizeof(OpenRISCCPUClass),
+        .class_init = openrisc_cpu_class_init,
+    },
+    DEFINE_OPENRISC_CPU_TYPE("or1200", or1200_initfn),
+    DEFINE_OPENRISC_CPU_TYPE("any", openrisc_any_initfn),
+};
+
+type_init_from_array(openrisc_cpus_type_infos)
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 113+ messages in thread

* [Qemu-devel] [PATCH 16/38] openrisc: use generic cpu_model parsing
  2017-10-02  9:07 [Qemu-devel] [PATCH 00/38] generalize parsing of cpu_model (part 2) Igor Mammedov
                   ` (14 preceding siblings ...)
  2017-10-02  9:07 ` [Qemu-devel] [PATCH 15/38] openrisc: cleanup cpu type name composition Igor Mammedov
@ 2017-10-02  9:07 ` Igor Mammedov
  2017-10-02 20:20   ` Philippe Mathieu-Daudé
  2017-10-02  9:07 ` [Qemu-devel] [PATCH 17/38] sh4: r2d: " Igor Mammedov
                   ` (21 subsequent siblings)
  37 siblings, 1 reply; 113+ messages in thread
From: Igor Mammedov @ 2017-10-02  9:07 UTC (permalink / raw)
  To: qemu-devel; +Cc: Philippe Mathieu-Daudé, shorne

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
---
CC: shorne@gmail.com
---
 hw/openrisc/openrisc_sim.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/hw/openrisc/openrisc_sim.c b/hw/openrisc/openrisc_sim.c
index 86bf284..f61b63d 100644
--- a/hw/openrisc/openrisc_sim.c
+++ b/hw/openrisc/openrisc_sim.c
@@ -98,18 +98,13 @@ static void cpu_openrisc_load_kernel(ram_addr_t ram_size,
 static void openrisc_sim_init(MachineState *machine)
 {
     ram_addr_t ram_size = machine->ram_size;
-    const char *cpu_model = machine->cpu_model;
     const char *kernel_filename = machine->kernel_filename;
     OpenRISCCPU *cpu = NULL;
     MemoryRegion *ram;
     int n;
 
-    if (!cpu_model) {
-        cpu_model = "or1200";
-    }
-
     for (n = 0; n < smp_cpus; n++) {
-        cpu = OPENRISC_CPU(cpu_generic_init(TYPE_OPENRISC_CPU, cpu_model));
+        cpu = OPENRISC_CPU(cpu_create(machine->cpu_type));
         qemu_register_reset(main_cpu_reset, cpu);
         main_cpu_reset(cpu);
     }
@@ -138,6 +133,7 @@ static void openrisc_sim_machine_init(MachineClass *mc)
     mc->init = openrisc_sim_init;
     mc->max_cpus = 1;
     mc->is_default = 1;
+    mc->default_cpu_type = OPENRISC_CPU_TYPE_NAME("or1200");
 }
 
 DEFINE_MACHINE("or1k-sim", openrisc_sim_machine_init)
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 113+ messages in thread

* [Qemu-devel] [PATCH 17/38] sh4: r2d: use generic cpu_model parsing
  2017-10-02  9:07 [Qemu-devel] [PATCH 00/38] generalize parsing of cpu_model (part 2) Igor Mammedov
                   ` (15 preceding siblings ...)
  2017-10-02  9:07 ` [Qemu-devel] [PATCH 16/38] openrisc: use generic cpu_model parsing Igor Mammedov
@ 2017-10-02  9:07 ` Igor Mammedov
  2017-10-05 12:37   ` Philippe Mathieu-Daudé
  2017-10-02  9:08 ` [Qemu-devel] [PATCH 18/38] sh4: shix: " Igor Mammedov
                   ` (20 subsequent siblings)
  37 siblings, 1 reply; 113+ messages in thread
From: Igor Mammedov @ 2017-10-02  9:07 UTC (permalink / raw)
  To: qemu-devel; +Cc: Philippe Mathieu-Daudé, Magnus Damm, Aurelien Jarno

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
---
CC: Magnus Damm <magnus.damm@gmail.com>
CC: Aurelien Jarno <aurelien@aurel32.net>
---
 hw/sh4/r2d.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/hw/sh4/r2d.c b/hw/sh4/r2d.c
index 16b9ed2..458ed83 100644
--- a/hw/sh4/r2d.c
+++ b/hw/sh4/r2d.c
@@ -225,7 +225,6 @@ static struct QEMU_PACKED
 
 static void r2d_init(MachineState *machine)
 {
-    const char *cpu_model = machine->cpu_model;
     const char *kernel_filename = machine->kernel_filename;
     const char *kernel_cmdline = machine->kernel_cmdline;
     const char *initrd_filename = machine->initrd_filename;
@@ -242,11 +241,7 @@ static void r2d_init(MachineState *machine)
     MemoryRegion *address_space_mem = get_system_memory();
     PCIBus *pci_bus;
 
-    if (cpu_model == NULL) {
-        cpu_model = "SH7751R";
-    }
-
-    cpu = SUPERH_CPU(cpu_generic_init(TYPE_SUPERH_CPU, cpu_model));
+    cpu = SUPERH_CPU(cpu_create(machine->cpu_type));
     env = &cpu->env;
 
     reset_info = g_malloc0(sizeof(ResetData));
@@ -365,6 +360,7 @@ static void r2d_machine_init(MachineClass *mc)
     mc->desc = "r2d-plus board";
     mc->init = r2d_init;
     mc->block_default_type = IF_IDE;
+    mc->default_cpu_type = TYPE_SH7751R_CPU;
 }
 
 DEFINE_MACHINE("r2d", r2d_machine_init)
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 113+ messages in thread

* [Qemu-devel] [PATCH 18/38] sh4: shix: use generic cpu_model parsing
  2017-10-02  9:07 [Qemu-devel] [PATCH 00/38] generalize parsing of cpu_model (part 2) Igor Mammedov
                   ` (16 preceding siblings ...)
  2017-10-02  9:07 ` [Qemu-devel] [PATCH 17/38] sh4: r2d: " Igor Mammedov
@ 2017-10-02  9:08 ` Igor Mammedov
  2017-10-05 12:48   ` Philippe Mathieu-Daudé
  2017-10-02  9:08 ` [Qemu-devel] [PATCH 19/38] sh4: cleanup cpu type name composition Igor Mammedov
                   ` (19 subsequent siblings)
  37 siblings, 1 reply; 113+ messages in thread
From: Igor Mammedov @ 2017-10-02  9:08 UTC (permalink / raw)
  To: qemu-devel; +Cc: Philippe Mathieu-Daudé, Magnus Damm, Aurelien Jarno

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
---
CC: Magnus Damm <magnus.damm@gmail.com>
CC: Aurelien Jarno <aurelien@aurel32.net>
---
 hw/sh4/shix.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/hw/sh4/shix.c b/hw/sh4/shix.c
index 50ee36a..4add230 100644
--- a/hw/sh4/shix.c
+++ b/hw/sh4/shix.c
@@ -45,7 +45,6 @@
 
 static void shix_init(MachineState *machine)
 {
-    const char *cpu_model = machine->cpu_model;
     int ret;
     SuperHCPU *cpu;
     struct SH7750State *s;
@@ -53,10 +52,7 @@ static void shix_init(MachineState *machine)
     MemoryRegion *rom = g_new(MemoryRegion, 1);
     MemoryRegion *sdram = g_new(MemoryRegion, 2);
     
-    if (!cpu_model)
-        cpu_model = "any";
-
-    cpu = SUPERH_CPU(cpu_generic_init(TYPE_SUPERH_CPU, cpu_model));
+    cpu = SUPERH_CPU(cpu_create(machine->cpu_type));
 
     /* Allocate memory space */
     memory_region_init_ram(rom, NULL, "shix.rom", 0x4000, &error_fatal);
@@ -89,6 +85,7 @@ static void shix_machine_init(MachineClass *mc)
     mc->desc = "shix card";
     mc->init = shix_init;
     mc->is_default = 1;
+    mc->default_cpu_type = TYPE_SH7750R_CPU;
 }
 
 DEFINE_MACHINE("shix", shix_machine_init)
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 113+ messages in thread

* [Qemu-devel] [PATCH 19/38] sh4: cleanup cpu type name composition
  2017-10-02  9:07 [Qemu-devel] [PATCH 00/38] generalize parsing of cpu_model (part 2) Igor Mammedov
                   ` (17 preceding siblings ...)
  2017-10-02  9:08 ` [Qemu-devel] [PATCH 18/38] sh4: shix: " Igor Mammedov
@ 2017-10-02  9:08 ` Igor Mammedov
  2017-10-05 12:39   ` Philippe Mathieu-Daudé
  2017-10-02  9:08 ` [Qemu-devel] [PATCH 20/38] sh4: simplify superh_cpu_class_by_name() Igor Mammedov
                   ` (18 subsequent siblings)
  37 siblings, 1 reply; 113+ messages in thread
From: Igor Mammedov @ 2017-10-02  9:08 UTC (permalink / raw)
  To: qemu-devel; +Cc: Philippe Mathieu-Daudé, aurelien

introduce SUPERH_CPU_TYPE_NAME macro and use it to construct
cpu type names. While at it move cpu type_infos into one
array and register it directly with type_init_from_array()
instead of custom superh_cpu_register_types()

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
---
CC: aurelien@aurel32.net
---
 target/sh4/cpu-qom.h |  6 ++---
 target/sh4/cpu.h     |  3 +++
 target/sh4/cpu.c     | 63 +++++++++++++++++++++-------------------------------
 3 files changed, 31 insertions(+), 41 deletions(-)

diff --git a/target/sh4/cpu-qom.h b/target/sh4/cpu-qom.h
index 01abb20..17deeb6 100644
--- a/target/sh4/cpu-qom.h
+++ b/target/sh4/cpu-qom.h
@@ -24,9 +24,9 @@
 
 #define TYPE_SUPERH_CPU "superh-cpu"
 
-#define TYPE_SH7750R_CPU "sh7750r-" TYPE_SUPERH_CPU
-#define TYPE_SH7751R_CPU "sh7751r-" TYPE_SUPERH_CPU
-#define TYPE_SH7785_CPU "sh7785-" TYPE_SUPERH_CPU
+#define TYPE_SH7750R_CPU SUPERH_CPU_TYPE_NAME("sh7750r")
+#define TYPE_SH7751R_CPU SUPERH_CPU_TYPE_NAME("sh7751r")
+#define TYPE_SH7785_CPU  SUPERH_CPU_TYPE_NAME("sh7785")
 
 #define SUPERH_CPU_CLASS(klass) \
     OBJECT_CLASS_CHECK(SuperHCPUClass, (klass), TYPE_SUPERH_CPU)
diff --git a/target/sh4/cpu.h b/target/sh4/cpu.h
index 79f85d3..a25a3f6 100644
--- a/target/sh4/cpu.h
+++ b/target/sh4/cpu.h
@@ -270,6 +270,9 @@ void cpu_load_tlb(CPUSH4State * env);
 
 #define cpu_init(cpu_model) cpu_generic_init(TYPE_SUPERH_CPU, cpu_model)
 
+#define SUPERH_CPU_TYPE_SUFFIX "-" TYPE_SUPERH_CPU
+#define SUPERH_CPU_TYPE_NAME(model) model SUPERH_CPU_TYPE_SUFFIX
+
 #define cpu_signal_handler cpu_sh4_signal_handler
 #define cpu_list sh4_cpu_list
 
diff --git a/target/sh4/cpu.c b/target/sh4/cpu.c
index 252440e..9198460 100644
--- a/target/sh4/cpu.c
+++ b/target/sh4/cpu.c
@@ -172,13 +172,6 @@ static void sh7750r_class_init(ObjectClass *oc, void *data)
     scc->cvr = 0x00110000;
 }
 
-static const TypeInfo sh7750r_type_info = {
-    .name = TYPE_SH7750R_CPU,
-    .parent = TYPE_SUPERH_CPU,
-    .class_init = sh7750r_class_init,
-    .instance_init = sh7750r_cpu_initfn,
-};
-
 static void sh7751r_cpu_initfn(Object *obj)
 {
     SuperHCPU *cpu = SUPERH_CPU(obj);
@@ -198,13 +191,6 @@ static void sh7751r_class_init(ObjectClass *oc, void *data)
     scc->cvr = 0x00110000; /* Neutered caches, should be 0x20480000 */
 }
 
-static const TypeInfo sh7751r_type_info = {
-    .name = TYPE_SH7751R_CPU,
-    .parent = TYPE_SUPERH_CPU,
-    .class_init = sh7751r_class_init,
-    .instance_init = sh7751r_cpu_initfn,
-};
-
 static void sh7785_cpu_initfn(Object *obj)
 {
     SuperHCPU *cpu = SUPERH_CPU(obj);
@@ -224,13 +210,6 @@ static void sh7785_class_init(ObjectClass *oc, void *data)
     scc->cvr = 0x71440211;
 }
 
-static const TypeInfo sh7785_type_info = {
-    .name = TYPE_SH7785_CPU,
-    .parent = TYPE_SUPERH_CPU,
-    .class_init = sh7785_class_init,
-    .instance_init = sh7785_cpu_initfn,
-};
-
 static void superh_cpu_realizefn(DeviceState *dev, Error **errp)
 {
     CPUState *cs = CPU(dev);
@@ -303,22 +282,30 @@ static void superh_cpu_class_init(ObjectClass *oc, void *data)
     dc->vmsd = &vmstate_sh_cpu;
 }
 
-static const TypeInfo superh_cpu_type_info = {
-    .name = TYPE_SUPERH_CPU,
-    .parent = TYPE_CPU,
-    .instance_size = sizeof(SuperHCPU),
-    .instance_init = superh_cpu_initfn,
-    .abstract = true,
-    .class_size = sizeof(SuperHCPUClass),
-    .class_init = superh_cpu_class_init,
-};
+#define DEFINE_SUPERH_CPU_TYPE(type_name, cinit, initfn) \
+    {                                                    \
+        .name = type_name,                               \
+        .parent = TYPE_SUPERH_CPU,                       \
+        .class_init = cinit,                             \
+        .instance_init = initfn,                         \
+    }
+static const TypeInfo superh_cpu_type_infos[] = {
+    {
+        .name = TYPE_SUPERH_CPU,
+        .parent = TYPE_CPU,
+        .instance_size = sizeof(SuperHCPU),
+        .instance_init = superh_cpu_initfn,
+        .abstract = true,
+        .class_size = sizeof(SuperHCPUClass),
+        .class_init = superh_cpu_class_init,
+    },
+    DEFINE_SUPERH_CPU_TYPE(TYPE_SH7750R_CPU, sh7750r_class_init,
+                           sh7750r_cpu_initfn),
+    DEFINE_SUPERH_CPU_TYPE(TYPE_SH7751R_CPU, sh7751r_class_init,
+                           sh7751r_cpu_initfn),
+    DEFINE_SUPERH_CPU_TYPE(TYPE_SH7785_CPU, sh7785_class_init,
+                           sh7785_cpu_initfn),
 
-static void superh_cpu_register_types(void)
-{
-    type_register_static(&superh_cpu_type_info);
-    type_register_static(&sh7750r_type_info);
-    type_register_static(&sh7751r_type_info);
-    type_register_static(&sh7785_type_info);
-}
+};
 
-type_init(superh_cpu_register_types)
+type_init_from_array(superh_cpu_type_infos)
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 113+ messages in thread

* [Qemu-devel] [PATCH 20/38] sh4: simplify superh_cpu_class_by_name()
  2017-10-02  9:07 [Qemu-devel] [PATCH 00/38] generalize parsing of cpu_model (part 2) Igor Mammedov
                   ` (18 preceding siblings ...)
  2017-10-02  9:08 ` [Qemu-devel] [PATCH 19/38] sh4: cleanup cpu type name composition Igor Mammedov
@ 2017-10-02  9:08 ` Igor Mammedov
  2017-10-05 12:56   ` Philippe Mathieu-Daudé
  2017-10-02  9:08 ` [Qemu-devel] [PATCH 21/38] sh4: remove SuperHCPUClass::name field Igor Mammedov
                   ` (17 subsequent siblings)
  37 siblings, 1 reply; 113+ messages in thread
From: Igor Mammedov @ 2017-10-02  9:08 UTC (permalink / raw)
  To: qemu-devel; +Cc: Philippe Mathieu-Daudé, aurelien

currently for sh4 cpu_model argument for '-cpu' option
could be either 'cpu model' name or cpu_typename.

however typically '-cpu' takes 'cpu model' name and
cpu type for sh4 target isn't advertised publicly
('-cpu help' prints only 'cpu model' names) so we
shouldn't care about this use case (it's more of a bug).

1. Drop '-cpu cpu_typename' to align with the rest of
   targets.
2. Compose searched for typename from cpu model and use
   it with object_class_by_name() directly instead of
   over-complicated
       object_class_get_list()
       g_slist_find_custom() + superh_cpu_name_compare()

With #1 droped, #2 could be used for both lookups which
simplifies superh_cpu_class_by_name() quite a bit.

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
---
CC: aurelien@aurel32.net
---
 target/sh4/cpu.c | 36 +++++++++++++-----------------------
 1 file changed, 13 insertions(+), 23 deletions(-)

diff --git a/target/sh4/cpu.c b/target/sh4/cpu.c
index 9198460..b71ff01 100644
--- a/target/sh4/cpu.c
+++ b/target/sh4/cpu.c
@@ -120,36 +120,26 @@ void sh4_cpu_list(FILE *f, fprintf_function cpu_fprintf)
     g_slist_free(list);
 }
 
-static gint superh_cpu_name_compare(gconstpointer a, gconstpointer b)
-{
-    const SuperHCPUClass *scc = SUPERH_CPU_CLASS(a);
-    const char *name = b;
-
-    return strcasecmp(scc->name, name);
-}
-
 static ObjectClass *superh_cpu_class_by_name(const char *cpu_model)
 {
-    ObjectClass *oc;
-    GSList *list, *item;
+    ObjectClass *oc = NULL;;
+    char *s, *typename = NULL;
 
-    if (strcasecmp(cpu_model, "any") == 0) {
-        return object_class_by_name(TYPE_SH7750R_CPU);
+    s = g_ascii_strdown(cpu_model, -1);
+    if (strcmp(s, "any") == 0) {
+        oc = object_class_by_name(TYPE_SH7750R_CPU);
+        goto out;
     }
 
-    oc = object_class_by_name(cpu_model);
-    if (oc != NULL && object_class_dynamic_cast(oc, TYPE_SUPERH_CPU) != NULL
-        && !object_class_is_abstract(oc)) {
-        return oc;
+    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;
     }
 
-    oc = NULL;
-    list = object_class_get_list(TYPE_SUPERH_CPU, false);
-    item = g_slist_find_custom(list, cpu_model, superh_cpu_name_compare);
-    if (item != NULL) {
-        oc = item->data;
-    }
-    g_slist_free(list);
+out:
+    g_free(s);
+    g_free(typename);
     return oc;
 }
 
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 113+ messages in thread

* [Qemu-devel] [PATCH 21/38] sh4: remove SuperHCPUClass::name field
  2017-10-02  9:07 [Qemu-devel] [PATCH 00/38] generalize parsing of cpu_model (part 2) Igor Mammedov
                   ` (19 preceding siblings ...)
  2017-10-02  9:08 ` [Qemu-devel] [PATCH 20/38] sh4: simplify superh_cpu_class_by_name() Igor Mammedov
@ 2017-10-02  9:08 ` Igor Mammedov
  2017-10-05 12:42   ` Philippe Mathieu-Daudé
  2017-10-02  9:08 ` [Qemu-devel] [PATCH 22/38] xtensa: cleanup cpu type name composition Igor Mammedov
                   ` (16 subsequent siblings)
  37 siblings, 1 reply; 113+ messages in thread
From: Igor Mammedov @ 2017-10-02  9:08 UTC (permalink / raw)
  To: qemu-devel; +Cc: Philippe Mathieu-Daudé, aurelien

the field contains upper-cased cpu model name and is used
for printing supported cpu model names for '-cpu help'.

Considering that cpu model lookup in superh_cpu_class_by_name()
is case-insensitive, we can drop upper-casing when
printing supported cpus list and use cpu type directly
to do the same by cutting out SUPERH_CPU_TYPE_SUFFIX from
typename.

It allows to remove SuperHCPUClass::name, which practically
duplicates names defined by TYPE_SH*_CPU definitions and
simplify sh*_class_init()/SuperHCPUClass a bit.

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
---
CC: aurelien@aurel32.net
---
 target/sh4/cpu-qom.h |  2 --
 target/sh4/cpu.c     | 10 +++-------
 2 files changed, 3 insertions(+), 9 deletions(-)

diff --git a/target/sh4/cpu-qom.h b/target/sh4/cpu-qom.h
index 17deeb6..0f9fb4d 100644
--- a/target/sh4/cpu-qom.h
+++ b/target/sh4/cpu-qom.h
@@ -39,7 +39,6 @@
  * SuperHCPUClass:
  * @parent_realize: The parent class' realize handler.
  * @parent_reset: The parent class' reset handler.
- * @name: The name.
  * @pvr: Processor Version Register
  * @prr: Processor Revision Register
  * @cvr: Cache Version Register
@@ -54,7 +53,6 @@ typedef struct SuperHCPUClass {
     DeviceRealize parent_realize;
     void (*parent_reset)(CPUState *cpu);
 
-    const char *name;
     uint32_t pvr;
     uint32_t prr;
     uint32_t cvr;
diff --git a/target/sh4/cpu.c b/target/sh4/cpu.c
index b71ff01..8dfbdeb 100644
--- a/target/sh4/cpu.c
+++ b/target/sh4/cpu.c
@@ -98,12 +98,11 @@ static gint superh_cpu_list_compare(gconstpointer a, gconstpointer b)
 
 static void superh_cpu_list_entry(gpointer data, gpointer user_data)
 {
-    ObjectClass *oc = data;
-    SuperHCPUClass *scc = SUPERH_CPU_CLASS(oc);
     SuperHCPUListState *s = user_data;
+    const char *typename = object_class_get_name(OBJECT_CLASS(data));
+    int len = strlen(typename) - strlen(SUPERH_CPU_TYPE_SUFFIX);
 
-    (*s->cpu_fprintf)(s->file, "%s\n",
-                      scc->name);
+    (*s->cpu_fprintf)(s->file, "%.*s\n", len, typename);
 }
 
 void sh4_cpu_list(FILE *f, fprintf_function cpu_fprintf)
@@ -156,7 +155,6 @@ static void sh7750r_class_init(ObjectClass *oc, void *data)
 {
     SuperHCPUClass *scc = SUPERH_CPU_CLASS(oc);
 
-    scc->name = "SH7750R";
     scc->pvr = 0x00050000;
     scc->prr = 0x00000100;
     scc->cvr = 0x00110000;
@@ -175,7 +173,6 @@ static void sh7751r_class_init(ObjectClass *oc, void *data)
 {
     SuperHCPUClass *scc = SUPERH_CPU_CLASS(oc);
 
-    scc->name = "SH7751R";
     scc->pvr = 0x04050005;
     scc->prr = 0x00000113;
     scc->cvr = 0x00110000; /* Neutered caches, should be 0x20480000 */
@@ -194,7 +191,6 @@ static void sh7785_class_init(ObjectClass *oc, void *data)
 {
     SuperHCPUClass *scc = SUPERH_CPU_CLASS(oc);
 
-    scc->name = "SH7785";
     scc->pvr = 0x10300700;
     scc->prr = 0x00000200;
     scc->cvr = 0x71440211;
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 113+ messages in thread

* [Qemu-devel] [PATCH 22/38] xtensa: cleanup cpu type name composition
  2017-10-02  9:07 [Qemu-devel] [PATCH 00/38] generalize parsing of cpu_model (part 2) Igor Mammedov
                   ` (20 preceding siblings ...)
  2017-10-02  9:08 ` [Qemu-devel] [PATCH 21/38] sh4: remove SuperHCPUClass::name field Igor Mammedov
@ 2017-10-02  9:08 ` Igor Mammedov
  2017-10-02 20:35   ` Philippe Mathieu-Daudé
  2017-10-02  9:08 ` [Qemu-devel] [PATCH 23/38] xtensa: sim: use generic cpu_model parsing Igor Mammedov
                   ` (15 subsequent siblings)
  37 siblings, 1 reply; 113+ messages in thread
From: Igor Mammedov @ 2017-10-02  9:08 UTC (permalink / raw)
  To: qemu-devel; +Cc: Philippe Mathieu-Daudé, jcmvbkbc

use new XTENSA_CPU_TYPE_NAME to compose CPU type name
to bring xtensa in line with all other targets that
will similar macro.

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
---
CC: jcmvbkbc@gmail.com
---
 target/xtensa/cpu.h    | 4 ++++
 target/xtensa/cpu.c    | 2 +-
 target/xtensa/helper.c | 2 +-
 3 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/target/xtensa/cpu.h b/target/xtensa/cpu.h
index 4803331..b17d7d9 100644
--- a/target/xtensa/cpu.h
+++ b/target/xtensa/cpu.h
@@ -469,11 +469,15 @@ void xtensa_cpu_do_unaligned_access(CPUState *cpu, vaddr addr,
 #define cpu_signal_handler cpu_xtensa_signal_handler
 #define cpu_list xtensa_cpu_list
 
+#define XTENSA_CPU_TYPE_SUFFIX "-" TYPE_XTENSA_CPU
+#define XTENSA_CPU_TYPE_NAME(model) model XTENSA_CPU_TYPE_SUFFIX
+
 #ifdef TARGET_WORDS_BIGENDIAN
 #define XTENSA_DEFAULT_CPU_MODEL "fsf"
 #else
 #define XTENSA_DEFAULT_CPU_MODEL "dc232b"
 #endif
+#define XTENSA_DEFAULT_CPU_TYPE XTENSA_CPU_TYPE_NAME(XTENSA_DEFAULT_CPU_MODEL)
 
 #define cpu_init(cpu_model) cpu_generic_init(TYPE_XTENSA_CPU, cpu_model)
 
diff --git a/target/xtensa/cpu.c b/target/xtensa/cpu.c
index dcdc765..b5f7079 100644
--- a/target/xtensa/cpu.c
+++ b/target/xtensa/cpu.c
@@ -83,7 +83,7 @@ static ObjectClass *xtensa_cpu_class_by_name(const char *cpu_model)
     ObjectClass *oc;
     char *typename;
 
-    typename = g_strdup_printf("%s-" TYPE_XTENSA_CPU, 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) ||
diff --git a/target/xtensa/helper.c b/target/xtensa/helper.c
index e8fba20..216f198 100644
--- a/target/xtensa/helper.c
+++ b/target/xtensa/helper.c
@@ -76,7 +76,7 @@ void xtensa_register_core(XtensaConfigList *node)
 
     node->next = xtensa_cores;
     xtensa_cores = node;
-    type.name = g_strdup_printf("%s-" TYPE_XTENSA_CPU, node->config->name);
+    type.name = g_strdup_printf(XTENSA_CPU_TYPE_NAME("%s"), node->config->name);
     type_register(&type);
     g_free((gpointer)type.name);
 }
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 113+ messages in thread

* [Qemu-devel] [PATCH 23/38] xtensa: sim: use generic cpu_model parsing
  2017-10-02  9:07 [Qemu-devel] [PATCH 00/38] generalize parsing of cpu_model (part 2) Igor Mammedov
                   ` (21 preceding siblings ...)
  2017-10-02  9:08 ` [Qemu-devel] [PATCH 22/38] xtensa: cleanup cpu type name composition Igor Mammedov
@ 2017-10-02  9:08 ` Igor Mammedov
  2017-10-03 13:34   ` Philippe Mathieu-Daudé
  2017-10-02  9:08 ` [Qemu-devel] [PATCH 24/38] xtensa: lx60/lx200/ml605/kc705: " Igor Mammedov
                   ` (14 subsequent siblings)
  37 siblings, 1 reply; 113+ messages in thread
From: Igor Mammedov @ 2017-10-02  9:08 UTC (permalink / raw)
  To: qemu-devel; +Cc: Philippe Mathieu-Daudé, jcmvbkbc

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
---
CC: jcmvbkbc@gmail.com
---
 hw/xtensa/sim.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/hw/xtensa/sim.c b/hw/xtensa/sim.c
index b3580b1..2bb883b 100644
--- a/hw/xtensa/sim.c
+++ b/hw/xtensa/sim.c
@@ -75,16 +75,11 @@ static void xtensa_sim_init(MachineState *machine)
     XtensaCPU *cpu = NULL;
     CPUXtensaState *env = NULL;
     ram_addr_t ram_size = machine->ram_size;
-    const char *cpu_model = machine->cpu_model;
     const char *kernel_filename = machine->kernel_filename;
     int n;
 
-    if (!cpu_model) {
-        cpu_model = XTENSA_DEFAULT_CPU_MODEL;
-    }
-
     for (n = 0; n < smp_cpus; n++) {
-        cpu = XTENSA_CPU(cpu_generic_init(TYPE_XTENSA_CPU, cpu_model));
+        cpu = XTENSA_CPU(cpu_create(machine->cpu_type));
         env = &cpu->env;
 
         env->sregs[PRID] = n;
@@ -133,6 +128,7 @@ static void xtensa_sim_machine_init(MachineClass *mc)
     mc->init = xtensa_sim_init;
     mc->max_cpus = 4;
     mc->no_serial = 1;
+    mc->default_cpu_type = XTENSA_DEFAULT_CPU_TYPE;
 }
 
 DEFINE_MACHINE("sim", xtensa_sim_machine_init)
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 113+ messages in thread

* [Qemu-devel] [PATCH 24/38] xtensa: lx60/lx200/ml605/kc705: use generic cpu_model parsing
  2017-10-02  9:07 [Qemu-devel] [PATCH 00/38] generalize parsing of cpu_model (part 2) Igor Mammedov
                   ` (22 preceding siblings ...)
  2017-10-02  9:08 ` [Qemu-devel] [PATCH 23/38] xtensa: sim: use generic cpu_model parsing Igor Mammedov
@ 2017-10-02  9:08 ` Igor Mammedov
  2017-10-03 13:34   ` Philippe Mathieu-Daudé
  2017-10-02  9:08 ` [Qemu-devel] [PATCH 25/38] unicore32: cleanup cpu type name composition Igor Mammedov
                   ` (13 subsequent siblings)
  37 siblings, 1 reply; 113+ messages in thread
From: Igor Mammedov @ 2017-10-02  9:08 UTC (permalink / raw)
  To: qemu-devel; +Cc: Philippe Mathieu-Daudé, jcmvbkbc

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
---
CC: jcmvbkbc@gmail.com
---
 hw/xtensa/xtfpga.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/hw/xtensa/xtfpga.c b/hw/xtensa/xtfpga.c
index a19cceb..1971ecf 100644
--- a/hw/xtensa/xtfpga.c
+++ b/hw/xtensa/xtfpga.c
@@ -220,19 +220,14 @@ static void lx_init(const LxBoardDesc *board, MachineState *machine)
     DriveInfo *dinfo;
     pflash_t *flash = NULL;
     QemuOpts *machine_opts = qemu_get_machine_opts();
-    const char *cpu_model = machine->cpu_model;
     const char *kernel_filename = qemu_opt_get(machine_opts, "kernel");
     const char *kernel_cmdline = qemu_opt_get(machine_opts, "append");
     const char *dtb_filename = qemu_opt_get(machine_opts, "dtb");
     const char *initrd_filename = qemu_opt_get(machine_opts, "initrd");
     int n;
 
-    if (!cpu_model) {
-        cpu_model = XTENSA_DEFAULT_CPU_MODEL;
-    }
-
     for (n = 0; n < smp_cpus; n++) {
-        cpu = XTENSA_CPU(cpu_generic_init(TYPE_XTENSA_CPU, cpu_model));
+        cpu = XTENSA_CPU(cpu_create(machine->cpu_type));
         env = &cpu->env;
 
         env->sregs[PRID] = n;
@@ -454,6 +449,7 @@ static void xtensa_lx60_class_init(ObjectClass *oc, void *data)
     mc->desc = "lx60 EVB (" XTENSA_DEFAULT_CPU_MODEL ")";
     mc->init = xtensa_lx60_init;
     mc->max_cpus = 4;
+    mc->default_cpu_type = XTENSA_DEFAULT_CPU_TYPE;
 }
 
 static const TypeInfo xtensa_lx60_type = {
@@ -469,6 +465,7 @@ static void xtensa_lx200_class_init(ObjectClass *oc, void *data)
     mc->desc = "lx200 EVB (" XTENSA_DEFAULT_CPU_MODEL ")";
     mc->init = xtensa_lx200_init;
     mc->max_cpus = 4;
+    mc->default_cpu_type = XTENSA_DEFAULT_CPU_TYPE;
 }
 
 static const TypeInfo xtensa_lx200_type = {
@@ -484,6 +481,7 @@ static void xtensa_ml605_class_init(ObjectClass *oc, void *data)
     mc->desc = "ml605 EVB (" XTENSA_DEFAULT_CPU_MODEL ")";
     mc->init = xtensa_ml605_init;
     mc->max_cpus = 4;
+    mc->default_cpu_type = XTENSA_DEFAULT_CPU_TYPE;
 }
 
 static const TypeInfo xtensa_ml605_type = {
@@ -499,6 +497,7 @@ static void xtensa_kc705_class_init(ObjectClass *oc, void *data)
     mc->desc = "kc705 EVB (" XTENSA_DEFAULT_CPU_MODEL ")";
     mc->init = xtensa_kc705_init;
     mc->max_cpus = 4;
+    mc->default_cpu_type = XTENSA_DEFAULT_CPU_TYPE;
 }
 
 static const TypeInfo xtensa_kc705_type = {
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 113+ messages in thread

* [Qemu-devel] [PATCH 25/38] unicore32: cleanup cpu type name composition
  2017-10-02  9:07 [Qemu-devel] [PATCH 00/38] generalize parsing of cpu_model (part 2) Igor Mammedov
                   ` (23 preceding siblings ...)
  2017-10-02  9:08 ` [Qemu-devel] [PATCH 24/38] xtensa: lx60/lx200/ml605/kc705: " Igor Mammedov
@ 2017-10-02  9:08 ` Igor Mammedov
  2017-10-02 20:18   ` Philippe Mathieu-Daudé
  2017-10-02  9:08 ` [Qemu-devel] [PATCH 26/38] unicore32: use generic cpu_model parsing Igor Mammedov
                   ` (12 subsequent siblings)
  37 siblings, 1 reply; 113+ messages in thread
From: Igor Mammedov @ 2017-10-02  9:08 UTC (permalink / raw)
  To: qemu-devel; +Cc: Philippe Mathieu-Daudé, gxt

use new UNICORE32_CPU_TYPE_NAME to compose CPU type
name and get rid of intermediate
   UniCore32CPUInfo/uc32_cpu_register_types()
which is replaced by static TypeInfo array and
type_init_from_array()

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
---
CC: gxt@mprc.pku.edu.cn
---
 target/unicore32/cpu.h |  3 +++
 target/unicore32/cpu.c | 61 +++++++++++++++++---------------------------------
 2 files changed, 23 insertions(+), 41 deletions(-)

diff --git a/target/unicore32/cpu.h b/target/unicore32/cpu.h
index 7724108..3dc6fbc 100644
--- a/target/unicore32/cpu.h
+++ b/target/unicore32/cpu.h
@@ -167,6 +167,9 @@ static inline int cpu_mmu_index(CPUUniCore32State *env, bool ifetch)
 
 #define cpu_init(cpu_model) cpu_generic_init(TYPE_UNICORE32_CPU, cpu_model)
 
+#define UNICORE32_CPU_TYPE_SUFFIX "-" TYPE_UNICORE32_CPU
+#define UNICORE32_CPU_TYPE_NAME(model) model UNICORE32_CPU_TYPE_SUFFIX
+
 static inline void cpu_get_tb_cpu_state(CPUUniCore32State *env, target_ulong *pc,
                                         target_ulong *cs_base, uint32_t *flags)
 {
diff --git a/target/unicore32/cpu.c b/target/unicore32/cpu.c
index 138acc9..3345cfd 100644
--- a/target/unicore32/cpu.c
+++ b/target/unicore32/cpu.c
@@ -44,7 +44,7 @@ static ObjectClass *uc32_cpu_class_by_name(const char *cpu_model)
     ObjectClass *oc;
     char *typename;
 
-    typename = g_strdup_printf("%s-" TYPE_UNICORE32_CPU, cpu_model);
+    typename = g_strdup_printf(UNICORE32_CPU_TYPE_NAME("%s"), cpu_model);
     oc = object_class_by_name(typename);
     g_free(typename);
     if (oc != NULL && (!object_class_dynamic_cast(oc, TYPE_UNICORE32_CPU) ||
@@ -54,11 +54,6 @@ static ObjectClass *uc32_cpu_class_by_name(const char *cpu_model)
     return oc;
 }
 
-typedef struct UniCore32CPUInfo {
-    const char *name;
-    void (*instance_init)(Object *obj);
-} UniCore32CPUInfo;
-
 static void unicore_ii_cpu_initfn(Object *obj)
 {
     UniCore32CPU *cpu = UNICORE32_CPU(obj);
@@ -90,11 +85,6 @@ static void uc32_any_cpu_initfn(Object *obj)
     set_snan_bit_is_one(1, &env->ucf64.fp_status);
 }
 
-static const UniCore32CPUInfo uc32_cpus[] = {
-    { .name = "UniCore-II", .instance_init = unicore_ii_cpu_initfn },
-    { .name = "any",        .instance_init = uc32_any_cpu_initfn },
-};
-
 static void uc32_cpu_realizefn(DeviceState *dev, Error **errp)
 {
     CPUState *cs = CPU(dev);
@@ -165,36 +155,25 @@ static void uc32_cpu_class_init(ObjectClass *oc, void *data)
     dc->vmsd = &vmstate_uc32_cpu;
 }
 
-static void uc32_register_cpu_type(const UniCore32CPUInfo *info)
-{
-    TypeInfo type_info = {
-        .parent = TYPE_UNICORE32_CPU,
-        .instance_init = info->instance_init,
-    };
-
-    type_info.name = g_strdup_printf("%s-" TYPE_UNICORE32_CPU, info->name);
-    type_register(&type_info);
-    g_free((void *)type_info.name);
-}
+#define DEFINE_UNICORE32_CPU_TYPE(cpu_model, initfn) \
+    {                                                \
+        .parent = TYPE_UNICORE32_CPU,                \
+        .instance_init = initfn,                     \
+        .name = UNICORE32_CPU_TYPE_NAME(cpu_model),  \
+    }
 
-static const TypeInfo uc32_cpu_type_info = {
-    .name = TYPE_UNICORE32_CPU,
-    .parent = TYPE_CPU,
-    .instance_size = sizeof(UniCore32CPU),
-    .instance_init = uc32_cpu_initfn,
-    .abstract = true,
-    .class_size = sizeof(UniCore32CPUClass),
-    .class_init = uc32_cpu_class_init,
+static const TypeInfo uc32_cpu_type_infos[] = {
+    {
+        .name = TYPE_UNICORE32_CPU,
+        .parent = TYPE_CPU,
+        .instance_size = sizeof(UniCore32CPU),
+        .instance_init = uc32_cpu_initfn,
+        .abstract = true,
+        .class_size = sizeof(UniCore32CPUClass),
+        .class_init = uc32_cpu_class_init,
+    },
+    DEFINE_UNICORE32_CPU_TYPE("UniCore-II", unicore_ii_cpu_initfn),
+    DEFINE_UNICORE32_CPU_TYPE("any", uc32_any_cpu_initfn),
 };
 
-static void uc32_cpu_register_types(void)
-{
-    int i;
-
-    type_register_static(&uc32_cpu_type_info);
-    for (i = 0; i < ARRAY_SIZE(uc32_cpus); i++) {
-        uc32_register_cpu_type(&uc32_cpus[i]);
-    }
-}
-
-type_init(uc32_cpu_register_types)
+type_init_from_array(uc32_cpu_type_infos)
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 113+ messages in thread

* [Qemu-devel] [PATCH 26/38] unicore32: use generic cpu_model parsing
  2017-10-02  9:07 [Qemu-devel] [PATCH 00/38] generalize parsing of cpu_model (part 2) Igor Mammedov
                   ` (24 preceding siblings ...)
  2017-10-02  9:08 ` [Qemu-devel] [PATCH 25/38] unicore32: cleanup cpu type name composition Igor Mammedov
@ 2017-10-02  9:08 ` Igor Mammedov
  2017-10-02 20:18   ` Philippe Mathieu-Daudé
  2017-10-02  9:08 ` [Qemu-devel] [PATCH 27/38] tricore: cleanup cpu type name composition Igor Mammedov
                   ` (11 subsequent siblings)
  37 siblings, 1 reply; 113+ messages in thread
From: Igor Mammedov @ 2017-10-02  9:08 UTC (permalink / raw)
  To: qemu-devel; +Cc: Philippe Mathieu-Daudé, Guan Xuetao

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
---
CC: Guan Xuetao <gxt@mprc.pku.edu.cn>
---
 hw/unicore32/puv3.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/hw/unicore32/puv3.c b/hw/unicore32/puv3.c
index 504ea46..1b39cc0 100644
--- a/hw/unicore32/puv3.c
+++ b/hw/unicore32/puv3.c
@@ -112,7 +112,6 @@ static void puv3_load_kernel(const char *kernel_filename)
 static void puv3_init(MachineState *machine)
 {
     ram_addr_t ram_size = machine->ram_size;
-    const char *cpu_model = machine->cpu_model;
     const char *kernel_filename = machine->kernel_filename;
     const char *initrd_filename = machine->initrd_filename;
     CPUUniCore32State *env;
@@ -123,11 +122,7 @@ static void puv3_init(MachineState *machine)
         exit(1);
     }
 
-    if (!cpu_model) {
-        cpu_model = "UniCore-II";
-    }
-
-    cpu = UNICORE32_CPU(cpu_generic_init(TYPE_UNICORE32_CPU, cpu_model));
+    cpu = UNICORE32_CPU(cpu_create(machine->cpu_type));
     env = &cpu->env;
 
     puv3_soc_init(env);
@@ -140,6 +135,7 @@ static void puv3_machine_init(MachineClass *mc)
     mc->desc = "PKUnity Version-3 based on UniCore32";
     mc->init = puv3_init;
     mc->is_default = 1;
+    mc->default_cpu_type = UNICORE32_CPU_TYPE_NAME("UniCore-II");
 }
 
 DEFINE_MACHINE("puv3", puv3_machine_init)
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 113+ messages in thread

* [Qemu-devel] [PATCH 27/38] tricore: cleanup cpu type name composition
  2017-10-02  9:07 [Qemu-devel] [PATCH 00/38] generalize parsing of cpu_model (part 2) Igor Mammedov
                   ` (25 preceding siblings ...)
  2017-10-02  9:08 ` [Qemu-devel] [PATCH 26/38] unicore32: use generic cpu_model parsing Igor Mammedov
@ 2017-10-02  9:08 ` Igor Mammedov
  2017-10-02 20:30   ` Philippe Mathieu-Daudé
  2017-10-02  9:08 ` [Qemu-devel] [PATCH 28/38] tricore: use generic cpu_model parsing Igor Mammedov
                   ` (10 subsequent siblings)
  37 siblings, 1 reply; 113+ messages in thread
From: Igor Mammedov @ 2017-10-02  9:08 UTC (permalink / raw)
  To: qemu-devel; +Cc: Philippe Mathieu-Daudé, kbastian

introduce TRICORE_CPU_TYPE_NAME macro and use it to construct
cpu type names. While at it move cpu type_infos into one
array and register it directly with type_init_from_array()
instead of custom tricore_cpu_register_types()/cpu_register()

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
---
CC: kbastian@mail.uni-paderborn.de
---
 target/tricore/cpu.h |  2 ++
 target/tricore/cpu.c | 68 ++++++++++++++++------------------------------------
 2 files changed, 22 insertions(+), 48 deletions(-)

diff --git a/target/tricore/cpu.h b/target/tricore/cpu.h
index bc53c40..f41d2ce 100644
--- a/target/tricore/cpu.h
+++ b/target/tricore/cpu.h
@@ -413,6 +413,8 @@ static inline void cpu_get_tb_cpu_state(CPUTriCoreState *env, target_ulong *pc,
 
 #define cpu_init(cpu_model) cpu_generic_init(TYPE_TRICORE_CPU, cpu_model)
 
+#define TRICORE_CPU_TYPE_SUFFIX "-" TYPE_TRICORE_CPU
+#define TRICORE_CPU_TYPE_NAME(model) model TRICORE_CPU_TYPE_SUFFIX
 
 /* helpers.c */
 int cpu_tricore_handle_mmu_fault(CPUState *cpu, target_ulong address,
diff --git a/target/tricore/cpu.c b/target/tricore/cpu.c
index 871eb35..69d7720 100644
--- a/target/tricore/cpu.c
+++ b/target/tricore/cpu.c
@@ -120,7 +120,7 @@ static ObjectClass *tricore_cpu_class_by_name(const char *cpu_model)
     ObjectClass *oc;
     char *typename;
 
-    typename = g_strdup_printf("%s-" TYPE_TRICORE_CPU, 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) ||
@@ -151,19 +151,6 @@ static void tc27x_initfn(Object *obj)
     set_feature(&cpu->env, TRICORE_FEATURE_161);
 }
 
-typedef struct TriCoreCPUInfo {
-    const char *name;
-    void (*initfn)(Object *obj);
-    void (*class_init)(ObjectClass *oc, void *data);
-} TriCoreCPUInfo;
-
-static const TriCoreCPUInfo tricore_cpus[] = {
-    { .name = "tc1796",      .initfn = tc1796_initfn },
-    { .name = "tc1797",      .initfn = tc1797_initfn },
-    { .name = "tc27x",       .initfn = tc27x_initfn },
-    { .name = NULL }
-};
-
 static void tricore_cpu_class_init(ObjectClass *c, void *data)
 {
     TriCoreCPUClass *mcc = TRICORE_CPU_CLASS(c);
@@ -184,41 +171,26 @@ static void tricore_cpu_class_init(ObjectClass *c, void *data)
     cc->get_phys_page_attrs_debug = tricore_cpu_get_phys_page_attrs_debug;
 }
 
-static void cpu_register(const TriCoreCPUInfo *info)
-{
-    TypeInfo type_info = {
-        .parent = TYPE_TRICORE_CPU,
+#define DEFINE_TRICORE_CPU_TYPE(cpu_model, initfn) \
+    {                                              \
+        .parent = TYPE_TRICORE_CPU,                \
+        .instance_init = initfn,                   \
+        .name = TRICORE_CPU_TYPE_NAME(cpu_model),  \
+    }
+
+static const TypeInfo tricore_cpu_type_infos[] = {
+    {
+        .name = TYPE_TRICORE_CPU,
+        .parent = TYPE_CPU,
         .instance_size = sizeof(TriCoreCPU),
-        .instance_init = info->initfn,
+        .instance_init = tricore_cpu_initfn,
+        .abstract = true,
         .class_size = sizeof(TriCoreCPUClass),
-        .class_init = info->class_init,
-    };
-
-    type_info.name = g_strdup_printf("%s-" TYPE_TRICORE_CPU, info->name);
-    type_register(&type_info);
-    g_free((void *)type_info.name);
-}
-
-static const TypeInfo tricore_cpu_type_info = {
-    .name = TYPE_TRICORE_CPU,
-    .parent = TYPE_CPU,
-    .instance_size = sizeof(TriCoreCPU),
-    .instance_init = tricore_cpu_initfn,
-    .abstract = true,
-    .class_size = sizeof(TriCoreCPUClass),
-    .class_init = tricore_cpu_class_init,
+        .class_init = tricore_cpu_class_init,
+    },
+    DEFINE_TRICORE_CPU_TYPE("tc1796", tc1796_initfn),
+    DEFINE_TRICORE_CPU_TYPE("tc1797", tc1797_initfn),
+    DEFINE_TRICORE_CPU_TYPE("tc27x", tc27x_initfn),
 };
 
-static void tricore_cpu_register_types(void)
-{
-    const TriCoreCPUInfo *info = tricore_cpus;
-
-    type_register_static(&tricore_cpu_type_info);
-
-    while (info->name) {
-        cpu_register(info);
-        info++;
-    }
-}
-
-type_init(tricore_cpu_register_types)
+type_init_from_array(tricore_cpu_type_infos)
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 113+ messages in thread

* [Qemu-devel] [PATCH 28/38] tricore: use generic cpu_model parsing
  2017-10-02  9:07 [Qemu-devel] [PATCH 00/38] generalize parsing of cpu_model (part 2) Igor Mammedov
                   ` (26 preceding siblings ...)
  2017-10-02  9:08 ` [Qemu-devel] [PATCH 27/38] tricore: cleanup cpu type name composition Igor Mammedov
@ 2017-10-02  9:08 ` Igor Mammedov
  2017-10-02 20:30   ` Philippe Mathieu-Daudé
  2017-10-02  9:08 ` [Qemu-devel] [PATCH 29/38] sparc: cleanup cpu type name composition Igor Mammedov
                   ` (9 subsequent siblings)
  37 siblings, 1 reply; 113+ messages in thread
From: Igor Mammedov @ 2017-10-02  9:08 UTC (permalink / raw)
  To: qemu-devel; +Cc: Philippe Mathieu-Daudé, Bastian Koppelmann

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
---
CC: Bastian Koppelmann <kbastian@mail.uni-paderborn.de>
---
 hw/tricore/tricore_testboard.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/hw/tricore/tricore_testboard.c b/hw/tricore/tricore_testboard.c
index 0486f8a..ac75eb2 100644
--- a/hw/tricore/tricore_testboard.c
+++ b/hw/tricore/tricore_testboard.c
@@ -71,10 +71,7 @@ static void tricore_testboard_init(MachineState *machine, int board_id)
     MemoryRegion *pcp_data = g_new(MemoryRegion, 1);
     MemoryRegion *pcp_text = g_new(MemoryRegion, 1);
 
-    if (!machine->cpu_model) {
-        machine->cpu_model = "tc1796";
-    }
-    cpu = TRICORE_CPU(cpu_generic_init(TYPE_TRICORE_CPU, machine->cpu_model));
+    cpu = TRICORE_CPU(cpu_create(machine->cpu_type));
     env = &cpu->env;
     memory_region_init_ram(ext_cram, NULL, "powerlink_ext_c.ram",
                            2 * 1024 * 1024, &error_fatal);
@@ -114,6 +111,7 @@ static void ttb_machine_init(MachineClass *mc)
     mc->desc = "a minimal TriCore board";
     mc->init = tricoreboard_init;
     mc->is_default = 0;
+    mc->default_cpu_type = TRICORE_CPU_TYPE_NAME("tc1796");
 }
 
 DEFINE_MACHINE("tricore_testboard", ttb_machine_init)
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 113+ messages in thread

* [Qemu-devel] [PATCH 29/38] sparc: cleanup cpu type name composition
  2017-10-02  9:07 [Qemu-devel] [PATCH 00/38] generalize parsing of cpu_model (part 2) Igor Mammedov
                   ` (27 preceding siblings ...)
  2017-10-02  9:08 ` [Qemu-devel] [PATCH 28/38] tricore: use generic cpu_model parsing Igor Mammedov
@ 2017-10-02  9:08 ` Igor Mammedov
  2017-10-02 15:01   ` Philippe Mathieu-Daudé
  2017-10-02  9:08 ` [Qemu-devel] [PATCH 30/38] sparc: sun4u/sun4v/niagara: use generic cpu_model parsing Igor Mammedov
                   ` (8 subsequent siblings)
  37 siblings, 1 reply; 113+ messages in thread
From: Igor Mammedov @ 2017-10-02  9:08 UTC (permalink / raw)
  To: qemu-devel; +Cc: Philippe Mathieu-Daudé, mark.cave-ayland, atar4qemu

introduce SPARC_CPU_TYPE_NAME macro and use it to
construct cpu type names.

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
---
macro will also be used in follow up patches to define
default cpu types per board

CC: mark.cave-ayland@ilande.co.uk
CC: atar4qemu@gmail.com
---
 target/sparc/cpu.h | 3 +++
 target/sparc/cpu.c | 2 +-
 2 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/target/sparc/cpu.h b/target/sparc/cpu.h
index 1598f65..7aa45c9 100644
--- a/target/sparc/cpu.h
+++ b/target/sparc/cpu.h
@@ -658,6 +658,9 @@ int cpu_sparc_signal_handler(int host_signum, void *pinfo, void *puc);
 #define cpu_init(cpu_model) cpu_generic_init(TYPE_SPARC_CPU, cpu_model)
 #endif
 
+#define SPARC_CPU_TYPE_SUFFIX "-" TYPE_SPARC_CPU
+#define SPARC_CPU_TYPE_NAME(model) model SPARC_CPU_TYPE_SUFFIX
+
 #define cpu_signal_handler cpu_sparc_signal_handler
 #define cpu_list sparc_cpu_list
 
diff --git a/target/sparc/cpu.c b/target/sparc/cpu.c
index beab90f..f09ba50 100644
--- a/target/sparc/cpu.c
+++ b/target/sparc/cpu.c
@@ -712,7 +712,7 @@ static bool sparc_cpu_has_work(CPUState *cs)
 
 static char *sparc_cpu_type_name(const char *cpu_model)
 {
-    char *name = g_strdup_printf("%s-" TYPE_SPARC_CPU, cpu_model);
+    char *name = g_strdup_printf(SPARC_CPU_TYPE_NAME("%s"), cpu_model);
     char *s = name;
 
     /* SPARC cpu model names happen to have whitespaces,
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 113+ messages in thread

* [Qemu-devel] [PATCH 30/38] sparc: sun4u/sun4v/niagara: use generic cpu_model parsing
  2017-10-02  9:07 [Qemu-devel] [PATCH 00/38] generalize parsing of cpu_model (part 2) Igor Mammedov
                   ` (28 preceding siblings ...)
  2017-10-02  9:08 ` [Qemu-devel] [PATCH 29/38] sparc: cleanup cpu type name composition Igor Mammedov
@ 2017-10-02  9:08 ` Igor Mammedov
  2017-10-02 20:16   ` Philippe Mathieu-Daudé
  2017-10-02  9:08 ` [Qemu-devel] [PATCH 31/38] sparc: sparc: " Igor Mammedov
                   ` (7 subsequent siblings)
  37 siblings, 1 reply; 113+ messages in thread
From: Igor Mammedov @ 2017-10-02  9:08 UTC (permalink / raw)
  To: qemu-devel; +Cc: Philippe Mathieu-Daudé, mark.cave-ayland, atar4qemu

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
---
CC: mark.cave-ayland@ilande.co.uk
CC: atar4qemu@gmail.com
---
 include/hw/sparc/sparc64.h | 3 +--
 hw/sparc64/niagara.c       | 4 ++--
 hw/sparc64/sparc64.c       | 8 ++------
 hw/sparc64/sun4u.c         | 8 +++-----
 4 files changed, 8 insertions(+), 15 deletions(-)

diff --git a/include/hw/sparc/sparc64.h b/include/hw/sparc/sparc64.h
index 7748939..ca3bb4b 100644
--- a/include/hw/sparc/sparc64.h
+++ b/include/hw/sparc/sparc64.h
@@ -1,5 +1,4 @@
 
-SPARCCPU *sparc64_cpu_devinit(const char *cpu_model,
-                              const char *dflt_cpu_model, uint64_t prom_addr);
+SPARCCPU *sparc64_cpu_devinit(const char *cpu_type, uint64_t prom_addr);
 
 void sparc64_cpu_set_ivec_irq(void *opaque, int irq, int level);
diff --git a/hw/sparc64/niagara.c b/hw/sparc64/niagara.c
index 9a8d610..7a72332 100644
--- a/hw/sparc64/niagara.c
+++ b/hw/sparc64/niagara.c
@@ -106,8 +106,7 @@ static void niagara_init(MachineState *machine)
     MemoryRegion *sysmem = get_system_memory();
 
     /* init CPUs */
-    sparc64_cpu_devinit(machine->cpu_model, "Sun UltraSparc T1",
-                        NIAGARA_PROM_BASE);
+    sparc64_cpu_devinit(machine->cpu_type, NIAGARA_PROM_BASE);
     /* set up devices */
     memory_region_allocate_system_memory(&s->hv_ram, NULL, "sun4v-hv.ram",
                                          NIAGARA_HV_RAM_SIZE);
@@ -174,6 +173,7 @@ static void niagara_class_init(ObjectClass *oc, void *data)
     mc->init = niagara_init;
     mc->max_cpus = 1; /* XXX for now */
     mc->default_boot_order = "c";
+    mc->default_cpu_type = SPARC_CPU_TYPE_NAME("Sun-UltraSparc-T1");
 }
 
 static const TypeInfo niagara_type = {
diff --git a/hw/sparc64/sparc64.c b/hw/sparc64/sparc64.c
index 097d529..9453e2c 100644
--- a/hw/sparc64/sparc64.c
+++ b/hw/sparc64/sparc64.c
@@ -339,8 +339,7 @@ void cpu_tick_set_limit(CPUTimer *timer, uint64_t limit)
     }
 }
 
-SPARCCPU *sparc64_cpu_devinit(const char *cpu_model,
-                              const char *default_cpu_model, uint64_t prom_addr)
+SPARCCPU *sparc64_cpu_devinit(const char *cpu_type, uint64_t prom_addr)
 {
     SPARCCPU *cpu;
     CPUSPARCState *env;
@@ -350,10 +349,7 @@ SPARCCPU *sparc64_cpu_devinit(const char *cpu_model,
     uint32_t  stick_frequency = 100 * 1000000;
     uint32_t hstick_frequency = 100 * 1000000;
 
-    if (cpu_model == NULL) {
-        cpu_model = default_cpu_model;
-    }
-    cpu = SPARC_CPU(cpu_generic_init(TYPE_SPARC_CPU, cpu_model));
+    cpu = SPARC_CPU(cpu_create(cpu_type));
     env = &cpu->env;
 
     env->tick = cpu_timer_create("tick", cpu, tick_irq,
diff --git a/hw/sparc64/sun4u.c b/hw/sparc64/sun4u.c
index c3280aa..d53fad8 100644
--- a/hw/sparc64/sun4u.c
+++ b/hw/sparc64/sun4u.c
@@ -73,7 +73,6 @@
 #define IVEC_MAX             0x40
 
 struct hwdef {
-    const char * const default_cpu_model;
     uint16_t machine_id;
     uint64_t prom_addr;
     uint64_t console_serial_base;
@@ -439,8 +438,7 @@ static void sun4uv_init(MemoryRegion *address_space_mem,
     int onboard_nic_idx;
 
     /* init CPUs */
-    cpu = sparc64_cpu_devinit(machine->cpu_model, hwdef->default_cpu_model,
-                              hwdef->prom_addr);
+    cpu = sparc64_cpu_devinit(machine->cpu_type, hwdef->prom_addr);
 
     /* set up devices */
     ram_init(0, machine->ram_size);
@@ -569,14 +567,12 @@ enum {
 static const struct hwdef hwdefs[] = {
     /* Sun4u generic PC-like machine */
     {
-        .default_cpu_model = "TI UltraSparc IIi",
         .machine_id = sun4u_id,
         .prom_addr = 0x1fff0000000ULL,
         .console_serial_base = 0,
     },
     /* Sun4v generic PC-like machine */
     {
-        .default_cpu_model = "Sun UltraSparc T1",
         .machine_id = sun4v_id,
         .prom_addr = 0x1fff0000000ULL,
         .console_serial_base = 0,
@@ -605,6 +601,7 @@ static void sun4u_class_init(ObjectClass *oc, void *data)
     mc->max_cpus = 1; /* XXX for now */
     mc->is_default = 1;
     mc->default_boot_order = "c";
+    mc->default_cpu_type = SPARC_CPU_TYPE_NAME("TI-UltraSparc-IIi");
 }
 
 static const TypeInfo sun4u_type = {
@@ -622,6 +619,7 @@ static void sun4v_class_init(ObjectClass *oc, void *data)
     mc->block_default_type = IF_IDE;
     mc->max_cpus = 1; /* XXX for now */
     mc->default_boot_order = "c";
+    mc->default_cpu_type = SPARC_CPU_TYPE_NAME("Sun-UltraSparc-T1");
 }
 
 static const TypeInfo sun4v_type = {
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 113+ messages in thread

* [Qemu-devel] [PATCH 31/38] sparc: sparc: use generic cpu_model parsing
  2017-10-02  9:07 [Qemu-devel] [PATCH 00/38] generalize parsing of cpu_model (part 2) Igor Mammedov
                   ` (29 preceding siblings ...)
  2017-10-02  9:08 ` [Qemu-devel] [PATCH 30/38] sparc: sun4u/sun4v/niagara: use generic cpu_model parsing Igor Mammedov
@ 2017-10-02  9:08 ` Igor Mammedov
  2017-10-02 15:02   ` Philippe Mathieu-Daudé
  2017-10-02  9:08 ` [Qemu-devel] [PATCH 32/38] sparc: leon3: " Igor Mammedov
                   ` (6 subsequent siblings)
  37 siblings, 1 reply; 113+ messages in thread
From: Igor Mammedov @ 2017-10-02  9:08 UTC (permalink / raw)
  To: qemu-devel; +Cc: Philippe Mathieu-Daudé, mark.cave-ayland, atar4qemu

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
---
CC: mark.cave-ayland@ilande.co.uk
CC: atar4qemu@gmail.com
---
 hw/sparc/sun4m.c | 29 ++++++++++++-----------------
 1 file changed, 12 insertions(+), 17 deletions(-)

diff --git a/hw/sparc/sun4m.c b/hw/sparc/sun4m.c
index e1bdd48..68b2378 100644
--- a/hw/sparc/sun4m.c
+++ b/hw/sparc/sun4m.c
@@ -94,7 +94,6 @@ struct sun4m_hwdef {
     } vsimm[MAX_VSIMMS];
     hwaddr ecc_base;
     uint64_t max_mem;
-    const char * const default_cpu_model;
     uint32_t ecc_version;
     uint32_t iommu_version;
     uint16_t machine_id;
@@ -790,14 +789,14 @@ static const TypeInfo ram_info = {
     .class_init    = ram_class_init,
 };
 
-static void cpu_devinit(const char *cpu_model, unsigned int id,
+static void cpu_devinit(const char *cpu_type, unsigned int id,
                         uint64_t prom_addr, qemu_irq **cpu_irqs)
 {
     CPUState *cs;
     SPARCCPU *cpu;
     CPUSPARCState *env;
 
-    cpu = SPARC_CPU(cpu_generic_init(TYPE_SPARC_CPU, cpu_model));
+    cpu = SPARC_CPU(cpu_create(cpu_type));
     env = &cpu->env;
 
     cpu_sparc_set_id(env, id);
@@ -820,7 +819,6 @@ static void sun4m_hw_init(const struct sun4m_hwdef *hwdef,
                           MachineState *machine)
 {
     DeviceState *slavio_intctl;
-    const char *cpu_model = machine->cpu_model;
     unsigned int i;
     void *iommu, *espdma, *ledma, *nvram;
     qemu_irq *cpu_irqs[MAX_CPUS], slavio_irq[32], slavio_cpu_irq[MAX_CPUS],
@@ -833,11 +831,8 @@ static void sun4m_hw_init(const struct sun4m_hwdef *hwdef,
     unsigned int num_vsimms;
 
     /* init CPUs */
-    if (!cpu_model)
-        cpu_model = hwdef->default_cpu_model;
-
     for(i = 0; i < smp_cpus; i++) {
-        cpu_devinit(cpu_model, i, hwdef->slavio_base, &cpu_irqs[i]);
+        cpu_devinit(machine->cpu_type, i, hwdef->slavio_base, &cpu_irqs[i]);
     }
 
     for (i = smp_cpus; i < MAX_CPUS; i++)
@@ -1074,7 +1069,6 @@ static const struct sun4m_hwdef sun4m_hwdefs[] = {
         .machine_id = ss5_id,
         .iommu_version = 0x05000000,
         .max_mem = 0x10000000,
-        .default_cpu_model = "Fujitsu MB86904",
     },
     /* SS-10 */
     {
@@ -1100,7 +1094,6 @@ static const struct sun4m_hwdef sun4m_hwdefs[] = {
         .machine_id = ss10_id,
         .iommu_version = 0x03000000,
         .max_mem = 0xf00000000ULL,
-        .default_cpu_model = "TI SuperSparc II",
     },
     /* SS-600MP */
     {
@@ -1124,7 +1117,6 @@ static const struct sun4m_hwdef sun4m_hwdefs[] = {
         .machine_id = ss600mp_id,
         .iommu_version = 0x01000000,
         .max_mem = 0xf00000000ULL,
-        .default_cpu_model = "TI SuperSparc II",
     },
     /* SS-20 */
     {
@@ -1166,7 +1158,6 @@ static const struct sun4m_hwdef sun4m_hwdefs[] = {
         .machine_id = ss20_id,
         .iommu_version = 0x13000000,
         .max_mem = 0xf00000000ULL,
-        .default_cpu_model = "TI SuperSparc II",
     },
     /* Voyager */
     {
@@ -1190,7 +1181,6 @@ static const struct sun4m_hwdef sun4m_hwdefs[] = {
         .machine_id = vger_id,
         .iommu_version = 0x05000000,
         .max_mem = 0x10000000,
-        .default_cpu_model = "Fujitsu MB86904",
     },
     /* LX */
     {
@@ -1215,7 +1205,6 @@ static const struct sun4m_hwdef sun4m_hwdefs[] = {
         .machine_id = lx_id,
         .iommu_version = 0x04000000,
         .max_mem = 0x10000000,
-        .default_cpu_model = "TI MicroSparc I",
     },
     /* SS-4 */
     {
@@ -1240,7 +1229,6 @@ static const struct sun4m_hwdef sun4m_hwdefs[] = {
         .machine_id = ss4_id,
         .iommu_version = 0x05000000,
         .max_mem = 0x10000000,
-        .default_cpu_model = "Fujitsu MB86904",
     },
     /* SPARCClassic */
     {
@@ -1264,7 +1252,6 @@ static const struct sun4m_hwdef sun4m_hwdefs[] = {
         .machine_id = scls_id,
         .iommu_version = 0x05000000,
         .max_mem = 0x10000000,
-        .default_cpu_model = "TI MicroSparc I",
     },
     /* SPARCbook */
     {
@@ -1288,7 +1275,6 @@ static const struct sun4m_hwdef sun4m_hwdefs[] = {
         .machine_id = sbook_id,
         .iommu_version = 0x05000000,
         .max_mem = 0x10000000,
-        .default_cpu_model = "TI MicroSparc I",
     },
 };
 
@@ -1355,6 +1341,7 @@ static void ss5_class_init(ObjectClass *oc, void *data)
     mc->block_default_type = IF_SCSI;
     mc->is_default = 1;
     mc->default_boot_order = "c";
+    mc->default_cpu_type = SPARC_CPU_TYPE_NAME("Fujitsu-MB86904");
 }
 
 static const TypeInfo ss5_type = {
@@ -1372,6 +1359,7 @@ static void ss10_class_init(ObjectClass *oc, void *data)
     mc->block_default_type = IF_SCSI;
     mc->max_cpus = 4;
     mc->default_boot_order = "c";
+    mc->default_cpu_type = SPARC_CPU_TYPE_NAME("TI-SuperSparc-II");
 }
 
 static const TypeInfo ss10_type = {
@@ -1389,6 +1377,7 @@ static void ss600mp_class_init(ObjectClass *oc, void *data)
     mc->block_default_type = IF_SCSI;
     mc->max_cpus = 4;
     mc->default_boot_order = "c";
+    mc->default_cpu_type = SPARC_CPU_TYPE_NAME("TI-SuperSparc-II");
 }
 
 static const TypeInfo ss600mp_type = {
@@ -1406,6 +1395,7 @@ static void ss20_class_init(ObjectClass *oc, void *data)
     mc->block_default_type = IF_SCSI;
     mc->max_cpus = 4;
     mc->default_boot_order = "c";
+    mc->default_cpu_type = SPARC_CPU_TYPE_NAME("TI-SuperSparc-II");
 }
 
 static const TypeInfo ss20_type = {
@@ -1422,6 +1412,7 @@ static void voyager_class_init(ObjectClass *oc, void *data)
     mc->init = vger_init;
     mc->block_default_type = IF_SCSI;
     mc->default_boot_order = "c";
+    mc->default_cpu_type = SPARC_CPU_TYPE_NAME("Fujitsu-MB86904");
 }
 
 static const TypeInfo voyager_type = {
@@ -1438,6 +1429,7 @@ static void ss_lx_class_init(ObjectClass *oc, void *data)
     mc->init = ss_lx_init;
     mc->block_default_type = IF_SCSI;
     mc->default_boot_order = "c";
+    mc->default_cpu_type = SPARC_CPU_TYPE_NAME("TI-MicroSparc-I");
 }
 
 static const TypeInfo ss_lx_type = {
@@ -1454,6 +1446,7 @@ static void ss4_class_init(ObjectClass *oc, void *data)
     mc->init = ss4_init;
     mc->block_default_type = IF_SCSI;
     mc->default_boot_order = "c";
+    mc->default_cpu_type = SPARC_CPU_TYPE_NAME("Fujitsu-MB86904");
 }
 
 static const TypeInfo ss4_type = {
@@ -1470,6 +1463,7 @@ static void scls_class_init(ObjectClass *oc, void *data)
     mc->init = scls_init;
     mc->block_default_type = IF_SCSI;
     mc->default_boot_order = "c";
+    mc->default_cpu_type = SPARC_CPU_TYPE_NAME("TI-MicroSparc-I");
 }
 
 static const TypeInfo scls_type = {
@@ -1486,6 +1480,7 @@ static void sbook_class_init(ObjectClass *oc, void *data)
     mc->init = sbook_init;
     mc->block_default_type = IF_SCSI;
     mc->default_boot_order = "c";
+    mc->default_cpu_type = SPARC_CPU_TYPE_NAME("TI-MicroSparc-I");
 }
 
 static const TypeInfo sbook_type = {
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 113+ messages in thread

* [Qemu-devel] [PATCH 32/38] sparc: leon3: use generic cpu_model parsing
  2017-10-02  9:07 [Qemu-devel] [PATCH 00/38] generalize parsing of cpu_model (part 2) Igor Mammedov
                   ` (30 preceding siblings ...)
  2017-10-02  9:08 ` [Qemu-devel] [PATCH 31/38] sparc: sparc: " Igor Mammedov
@ 2017-10-02  9:08 ` Igor Mammedov
  2017-10-02 15:54   ` Philippe Mathieu-Daudé
  2017-10-02  9:08 ` [Qemu-devel] [PATCH 33/38] mips: use object_new() instead of gnew()+object_initialize() Igor Mammedov
                   ` (5 subsequent siblings)
  37 siblings, 1 reply; 113+ messages in thread
From: Igor Mammedov @ 2017-10-02  9:08 UTC (permalink / raw)
  To: qemu-devel
  Cc: Philippe Mathieu-Daudé, mark.cave-ayland, atar4qemu, chouteau

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
---
CC: mark.cave-ayland@ilande.co.uk
CC: atar4qemu@gmail.com
CC: chouteau@adacore.com
---
 hw/sparc/leon3.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/hw/sparc/leon3.c b/hw/sparc/leon3.c
index ec2816b..8c66d5a 100644
--- a/hw/sparc/leon3.c
+++ b/hw/sparc/leon3.c
@@ -107,7 +107,6 @@ static void leon3_set_pil_in(void *opaque, uint32_t pil_in)
 static void leon3_generic_hw_init(MachineState *machine)
 {
     ram_addr_t ram_size = machine->ram_size;
-    const char *cpu_model = machine->cpu_model;
     const char *kernel_filename = machine->kernel_filename;
     SPARCCPU *cpu;
     CPUSPARCState   *env;
@@ -122,11 +121,7 @@ static void leon3_generic_hw_init(MachineState *machine)
     ResetData  *reset_info;
 
     /* Init CPU */
-    if (!cpu_model) {
-        cpu_model = "LEON3";
-    }
-
-    cpu = SPARC_CPU(cpu_generic_init(TYPE_SPARC_CPU, cpu_model));
+    cpu = SPARC_CPU(cpu_create(machine->cpu_type));
     env = &cpu->env;
 
     cpu_sparc_set_id(env, 0);
@@ -222,6 +217,7 @@ static void leon3_generic_machine_init(MachineClass *mc)
 {
     mc->desc = "Leon-3 generic";
     mc->init = leon3_generic_hw_init;
+    mc->default_cpu_type = SPARC_CPU_TYPE_NAME("LEON3");
 }
 
 DEFINE_MACHINE("leon3_generic", leon3_generic_machine_init)
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 113+ messages in thread

* [Qemu-devel] [PATCH 33/38] mips: use object_new() instead of gnew()+object_initialize()
  2017-10-02  9:07 [Qemu-devel] [PATCH 00/38] generalize parsing of cpu_model (part 2) Igor Mammedov
                   ` (31 preceding siblings ...)
  2017-10-02  9:08 ` [Qemu-devel] [PATCH 32/38] sparc: leon3: " Igor Mammedov
@ 2017-10-02  9:08 ` Igor Mammedov
  2017-10-02 14:09   ` Philippe Mathieu-Daudé
  2017-10-02  9:08 ` [Qemu-devel] [PATCH 34/38] mips: malta/boston: replace cpu_model with cpu_type Igor Mammedov
                   ` (4 subsequent siblings)
  37 siblings, 1 reply; 113+ messages in thread
From: Igor Mammedov @ 2017-10-02  9:08 UTC (permalink / raw)
  To: qemu-devel
  Cc: Philippe Mathieu-Daudé, paul.burton, aurelien, yongbok.kim

object_initialize() is intended for inplace initialization of
objects, but here it's first allocated with g_new0() and then
initialized with object_initialize(). QEMU already has API
to do this (object_new), so do object creation with suitable
for usecase API.

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
---
CC: paul.burton@imgtec.com
CC: aurelien@aurel32.net
CC: yongbok.kim@imgtec.com
---
 hw/mips/boston.c     | 3 +--
 hw/mips/mips_malta.c | 3 +--
 2 files changed, 2 insertions(+), 4 deletions(-)

diff --git a/hw/mips/boston.c b/hw/mips/boston.c
index 776ee28..e815be6 100644
--- a/hw/mips/boston.c
+++ b/hw/mips/boston.c
@@ -460,7 +460,6 @@ static void boston_mach_init(MachineState *machine)
 
     s = BOSTON(dev);
     s->mach = machine;
-    s->cps = g_new0(MIPSCPSState, 1);
 
     if (!cpu_supports_cps_smp(cpu_model)) {
         error_report("Boston requires CPUs which support CPS");
@@ -469,7 +468,7 @@ static void boston_mach_init(MachineState *machine)
 
     is_64b = cpu_supports_isa(cpu_model, ISA_MIPS64);
 
-    object_initialize(s->cps, sizeof(MIPSCPSState), TYPE_MIPS_CPS);
+    s->cps = MIPS_CPS(object_new(TYPE_MIPS_CPS));
     qdev_set_parent_bus(DEVICE(s->cps), sysbus_get_default());
 
     object_property_set_str(OBJECT(s->cps), cpu_model, "cpu-model", &err);
diff --git a/hw/mips/mips_malta.c b/hw/mips/mips_malta.c
index 2adb9bc..b6a58c7 100644
--- a/hw/mips/mips_malta.c
+++ b/hw/mips/mips_malta.c
@@ -949,9 +949,8 @@ static void create_cps(MaltaState *s, const char *cpu_model,
                        qemu_irq *cbus_irq, qemu_irq *i8259_irq)
 {
     Error *err = NULL;
-    s->cps = g_new0(MIPSCPSState, 1);
 
-    object_initialize(s->cps, sizeof(MIPSCPSState), TYPE_MIPS_CPS);
+    s->cps = MIPS_CPS(object_new(TYPE_MIPS_CPS));
     qdev_set_parent_bus(DEVICE(s->cps), sysbus_get_default());
 
     object_property_set_str(OBJECT(s->cps), cpu_model, "cpu-model", &err);
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 113+ messages in thread

* [Qemu-devel] [PATCH 34/38] mips: malta/boston: replace cpu_model with cpu_type
  2017-10-02  9:07 [Qemu-devel] [PATCH 00/38] generalize parsing of cpu_model (part 2) Igor Mammedov
                   ` (32 preceding siblings ...)
  2017-10-02  9:08 ` [Qemu-devel] [PATCH 33/38] mips: use object_new() instead of gnew()+object_initialize() Igor Mammedov
@ 2017-10-02  9:08 ` Igor Mammedov
  2017-10-02 14:10   ` Philippe Mathieu-Daudé
  2017-10-02  9:08 ` [Qemu-devel] [PATCH 35/38] mips: fulong2e: " Igor Mammedov
                   ` (3 subsequent siblings)
  37 siblings, 1 reply; 113+ messages in thread
From: Igor Mammedov @ 2017-10-02  9:08 UTC (permalink / raw)
  To: qemu-devel
  Cc: Philippe Mathieu-Daudé, paul.burton, aurelien, yongbok.kim

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
---
CC: paul.burton@imgtec.com
CC: aurelien@aurel32.net
CC: yongbok.kim@imgtec.com
---
 include/hw/mips/cps.h        |  2 +-
 target/mips/cpu.h            |  8 ++++++--
 hw/mips/boston.c             | 11 +++++------
 hw/mips/cps.c                |  4 ++--
 hw/mips/mips_malta.c         | 33 +++++++++++++++------------------
 target/mips/cpu.c            |  2 +-
 target/mips/translate.c      | 20 ++++++--------------
 target/mips/translate_init.c | 12 ------------
 8 files changed, 36 insertions(+), 56 deletions(-)

diff --git a/include/hw/mips/cps.h b/include/hw/mips/cps.h
index 526b8d0..aab1af9 100644
--- a/include/hw/mips/cps.h
+++ b/include/hw/mips/cps.h
@@ -34,7 +34,7 @@ typedef struct MIPSCPSState {
 
     uint32_t num_vp;
     uint32_t num_irq;
-    char *cpu_model;
+    char *cpu_type;
 
     MemoryRegion container;
     MIPSGCRState gcr;
diff --git a/target/mips/cpu.h b/target/mips/cpu.h
index 66265e4..7f8ba5f 100644
--- a/target/mips/cpu.h
+++ b/target/mips/cpu.h
@@ -740,8 +740,12 @@ enum {
 int cpu_mips_signal_handler(int host_signum, void *pinfo, void *puc);
 
 #define cpu_init(cpu_model) cpu_generic_init(TYPE_MIPS_CPU, cpu_model)
-bool cpu_supports_cps_smp(const char *cpu_model);
-bool cpu_supports_isa(const char *cpu_model, unsigned int isa);
+
+#define MIPS_CPU_TYPE_SUFFIX "-" TYPE_MIPS_CPU
+#define MIPS_CPU_TYPE_NAME(model) model MIPS_CPU_TYPE_SUFFIX
+
+bool cpu_supports_cps_smp(const char *cpu_type);
+bool cpu_supports_isa(const char *cpu_type, unsigned int isa);
 void cpu_set_exception_base(int vp_index, target_ulong address);
 
 /* mips_int.c */
diff --git a/hw/mips/boston.c b/hw/mips/boston.c
index e815be6..1cb4b6a 100644
--- a/hw/mips/boston.c
+++ b/hw/mips/boston.c
@@ -437,7 +437,6 @@ static void boston_mach_init(MachineState *machine)
     DeviceState *dev;
     BostonState *s;
     Error *err = NULL;
-    const char *cpu_model;
     MemoryRegion *flash, *ddr, *ddr_low_alias, *lcd, *platreg;
     MemoryRegion *sys_mem = get_system_memory();
     XilinxPCIEHost *pcie2;
@@ -453,25 +452,24 @@ static void boston_mach_init(MachineState *machine)
         exit(1);
     }
 
-    cpu_model = machine->cpu_model ?: "I6400";
-
     dev = qdev_create(NULL, TYPE_MIPS_BOSTON);
     qdev_init_nofail(dev);
 
     s = BOSTON(dev);
     s->mach = machine;
 
-    if (!cpu_supports_cps_smp(cpu_model)) {
+    if (!cpu_supports_cps_smp(machine->cpu_type)) {
         error_report("Boston requires CPUs which support CPS");
         exit(1);
     }
 
-    is_64b = cpu_supports_isa(cpu_model, ISA_MIPS64);
+    is_64b = cpu_supports_isa(machine->cpu_type, ISA_MIPS64);
 
     s->cps = MIPS_CPS(object_new(TYPE_MIPS_CPS));
     qdev_set_parent_bus(DEVICE(s->cps), sysbus_get_default());
 
-    object_property_set_str(OBJECT(s->cps), cpu_model, "cpu-model", &err);
+    object_property_set_str(OBJECT(s->cps), machine->cpu_type, "cpu-type",
+                            &err);
     object_property_set_int(OBJECT(s->cps), smp_cpus, "num-vp", &err);
     object_property_set_bool(OBJECT(s->cps), true, "realized", &err);
 
@@ -571,6 +569,7 @@ static void boston_mach_class_init(MachineClass *mc)
     mc->block_default_type = IF_IDE;
     mc->default_ram_size = 1 * G_BYTE;
     mc->max_cpus = 16;
+    mc->default_cpu_type = MIPS_CPU_TYPE_NAME("I6400");
 }
 
 DEFINE_MACHINE("boston", boston_mach_class_init)
diff --git a/hw/mips/cps.c b/hw/mips/cps.c
index fe5c630..4285d19 100644
--- a/hw/mips/cps.c
+++ b/hw/mips/cps.c
@@ -71,7 +71,7 @@ static void mips_cps_realize(DeviceState *dev, Error **errp)
     bool itu_present = false;
 
     for (i = 0; i < s->num_vp; i++) {
-        cpu = MIPS_CPU(cpu_generic_init(TYPE_MIPS_CPU, s->cpu_model));
+        cpu = MIPS_CPU(cpu_create(s->cpu_type));
 
         /* Init internal devices */
         cpu_mips_irq_init_cpu(cpu);
@@ -160,7 +160,7 @@ static void mips_cps_realize(DeviceState *dev, Error **errp)
 static Property mips_cps_properties[] = {
     DEFINE_PROP_UINT32("num-vp", MIPSCPSState, num_vp, 1),
     DEFINE_PROP_UINT32("num-irq", MIPSCPSState, num_irq, 256),
-    DEFINE_PROP_STRING("cpu-model", MIPSCPSState, cpu_model),
+    DEFINE_PROP_STRING("cpu-type", MIPSCPSState, cpu_type),
     DEFINE_PROP_END_OF_LIST()
 };
 
diff --git a/hw/mips/mips_malta.c b/hw/mips/mips_malta.c
index b6a58c7..ec6af4a 100644
--- a/hw/mips/mips_malta.c
+++ b/hw/mips/mips_malta.c
@@ -923,7 +923,7 @@ static void main_cpu_reset(void *opaque)
     }
 }
 
-static void create_cpu_without_cps(const char *cpu_model,
+static void create_cpu_without_cps(const char *cpu_type,
                                    qemu_irq *cbus_irq, qemu_irq *i8259_irq)
 {
     CPUMIPSState *env;
@@ -931,7 +931,7 @@ static void create_cpu_without_cps(const char *cpu_model,
     int i;
 
     for (i = 0; i < smp_cpus; i++) {
-        cpu = MIPS_CPU(cpu_generic_init(TYPE_MIPS_CPU, cpu_model));
+        cpu = MIPS_CPU(cpu_create(cpu_type));
 
         /* Init internal devices */
         cpu_mips_irq_init_cpu(cpu);
@@ -945,7 +945,7 @@ static void create_cpu_without_cps(const char *cpu_model,
     *cbus_irq = env->irq[4];
 }
 
-static void create_cps(MaltaState *s, const char *cpu_model,
+static void create_cps(MaltaState *s, const char *cpu_type,
                        qemu_irq *cbus_irq, qemu_irq *i8259_irq)
 {
     Error *err = NULL;
@@ -953,7 +953,7 @@ static void create_cps(MaltaState *s, const char *cpu_model,
     s->cps = MIPS_CPS(object_new(TYPE_MIPS_CPS));
     qdev_set_parent_bus(DEVICE(s->cps), sysbus_get_default());
 
-    object_property_set_str(OBJECT(s->cps), cpu_model, "cpu-model", &err);
+    object_property_set_str(OBJECT(s->cps), cpu_type, "cpu-type", &err);
     object_property_set_int(OBJECT(s->cps), smp_cpus, "num-vp", &err);
     object_property_set_bool(OBJECT(s->cps), true, "realized", &err);
     if (err != NULL) {
@@ -967,21 +967,13 @@ static void create_cps(MaltaState *s, const char *cpu_model,
     *cbus_irq = NULL;
 }
 
-static void create_cpu(MaltaState *s, const char *cpu_model,
-                       qemu_irq *cbus_irq, qemu_irq *i8259_irq)
+static void mips_create_cpu(MaltaState *s, const char *cpu_type,
+                            qemu_irq *cbus_irq, qemu_irq *i8259_irq)
 {
-    if (cpu_model == NULL) {
-#ifdef TARGET_MIPS64
-        cpu_model = "20Kc";
-#else
-        cpu_model = "24Kf";
-#endif
-    }
-
-    if ((smp_cpus > 1) && cpu_supports_cps_smp(cpu_model)) {
-        create_cps(s, cpu_model, cbus_irq, i8259_irq);
+    if ((smp_cpus > 1) && cpu_supports_cps_smp(cpu_type)) {
+        create_cps(s, cpu_type, cbus_irq, i8259_irq);
     } else {
-        create_cpu_without_cps(cpu_model, cbus_irq, i8259_irq);
+        create_cpu_without_cps(cpu_type, cbus_irq, i8259_irq);
     }
 }
 
@@ -1038,7 +1030,7 @@ void mips_malta_init(MachineState *machine)
     }
 
     /* create CPU */
-    create_cpu(s, machine->cpu_model, &cbus_irq, &i8259_irq);
+    mips_create_cpu(s, machine->cpu_type, &cbus_irq, &i8259_irq);
 
     /* allocate RAM */
     if (ram_size > (2048u << 20)) {
@@ -1264,6 +1256,11 @@ static void mips_malta_machine_init(MachineClass *mc)
     mc->block_default_type = IF_IDE;
     mc->max_cpus = 16;
     mc->is_default = 1;
+#ifdef TARGET_MIPS64
+    mc->default_cpu_type = MIPS_CPU_TYPE_NAME("20Kc");
+#else
+    mc->default_cpu_type = MIPS_CPU_TYPE_NAME("24Kf");
+#endif
 }
 
 DEFINE_MACHINE("malta", mips_malta_machine_init)
diff --git a/target/mips/cpu.c b/target/mips/cpu.c
index c15b894..24a8907 100644
--- a/target/mips/cpu.c
+++ b/target/mips/cpu.c
@@ -158,7 +158,7 @@ static void mips_cpu_initfn(Object *obj)
 
 static char *mips_cpu_type_name(const char *cpu_model)
 {
-    return g_strdup_printf("%s-" TYPE_MIPS_CPU, cpu_model);
+    return g_strdup_printf(MIPS_CPU_TYPE_NAME("%s"), cpu_model);
 }
 
 static ObjectClass *mips_cpu_class_by_name(const char *cpu_model)
diff --git a/target/mips/translate.c b/target/mips/translate.c
index d16d879..3d76fc6 100644
--- a/target/mips/translate.c
+++ b/target/mips/translate.c
@@ -20523,24 +20523,16 @@ void cpu_mips_realize_env(CPUMIPSState *env)
     mvp_init(env, env->cpu_model);
 }
 
-bool cpu_supports_cps_smp(const char *cpu_model)
+bool cpu_supports_cps_smp(const char *cpu_type)
 {
-    const mips_def_t *def = cpu_mips_find_by_name(cpu_model);
-    if (!def) {
-        return false;
-    }
-
-    return (def->CP0_Config3 & (1 << CP0C3_CMGCR)) != 0;
+    const MIPSCPUClass *mcc = MIPS_CPU_CLASS(object_class_by_name(cpu_type));
+    return (mcc->cpu_def->CP0_Config3 & (1 << CP0C3_CMGCR)) != 0;
 }
 
-bool cpu_supports_isa(const char *cpu_model, unsigned int isa)
+bool cpu_supports_isa(const char *cpu_type, unsigned int isa)
 {
-    const mips_def_t *def = cpu_mips_find_by_name(cpu_model);
-    if (!def) {
-        return false;
-    }
-
-    return (def->insn_flags & isa) != 0;
+    const MIPSCPUClass *mcc = MIPS_CPU_CLASS(object_class_by_name(cpu_type));
+    return (mcc->cpu_def->insn_flags & isa) != 0;
 }
 
 void cpu_set_exception_base(int vp_index, target_ulong address)
diff --git a/target/mips/translate_init.c b/target/mips/translate_init.c
index 8bbded4..c7ba6ee 100644
--- a/target/mips/translate_init.c
+++ b/target/mips/translate_init.c
@@ -755,18 +755,6 @@ const mips_def_t mips_defs[] =
 };
 const int mips_defs_number = ARRAY_SIZE(mips_defs);
 
-static const mips_def_t *cpu_mips_find_by_name (const char *name)
-{
-    int i;
-
-    for (i = 0; i < ARRAY_SIZE(mips_defs); i++) {
-        if (strcasecmp(name, mips_defs[i].name) == 0) {
-            return &mips_defs[i];
-        }
-    }
-    return NULL;
-}
-
 void mips_cpu_list (FILE *f, fprintf_function cpu_fprintf)
 {
     int i;
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 113+ messages in thread

* [Qemu-devel] [PATCH 35/38] mips: fulong2e: replace cpu_model with cpu_type
  2017-10-02  9:07 [Qemu-devel] [PATCH 00/38] generalize parsing of cpu_model (part 2) Igor Mammedov
                   ` (33 preceding siblings ...)
  2017-10-02  9:08 ` [Qemu-devel] [PATCH 34/38] mips: malta/boston: replace cpu_model with cpu_type Igor Mammedov
@ 2017-10-02  9:08 ` Igor Mammedov
  2017-10-02 14:11   ` Philippe Mathieu-Daudé
  2017-10-02  9:08 ` [Qemu-devel] [PATCH 36/38] mips: Magnum/Acer Pica 61: " Igor Mammedov
                   ` (2 subsequent siblings)
  37 siblings, 1 reply; 113+ messages in thread
From: Igor Mammedov @ 2017-10-02  9:08 UTC (permalink / raw)
  To: qemu-devel; +Cc: Philippe Mathieu-Daudé, yongbok.kim, aurelien

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
---
CC: yongbok.kim@imgtec.com
CC: aurelien@aurel32.net
---
 hw/mips/mips_fulong2e.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/hw/mips/mips_fulong2e.c b/hw/mips/mips_fulong2e.c
index 7531868..146cf0f 100644
--- a/hw/mips/mips_fulong2e.c
+++ b/hw/mips/mips_fulong2e.c
@@ -258,7 +258,6 @@ static void network_init (PCIBus *pci_bus)
 static void mips_fulong2e_init(MachineState *machine)
 {
     ram_addr_t ram_size = machine->ram_size;
-    const char *cpu_model = machine->cpu_model;
     const char *kernel_filename = machine->kernel_filename;
     const char *kernel_cmdline = machine->kernel_cmdline;
     const char *initrd_filename = machine->initrd_filename;
@@ -277,10 +276,7 @@ static void mips_fulong2e_init(MachineState *machine)
     CPUMIPSState *env;
 
     /* init CPUs */
-    if (cpu_model == NULL) {
-        cpu_model = "Loongson-2E";
-    }
-    cpu = MIPS_CPU(cpu_generic_init(TYPE_MIPS_CPU, cpu_model));
+    cpu = MIPS_CPU(cpu_create(machine->cpu_type));
     env = &cpu->env;
 
     qemu_register_reset(main_cpu_reset, cpu);
@@ -385,6 +381,7 @@ static void mips_fulong2e_machine_init(MachineClass *mc)
     mc->desc = "Fulong 2e mini pc";
     mc->init = mips_fulong2e_init;
     mc->block_default_type = IF_IDE;
+    mc->default_cpu_type = MIPS_CPU_TYPE_NAME("Loongson-2E");
 }
 
 DEFINE_MACHINE("fulong2e", mips_fulong2e_machine_init)
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 113+ messages in thread

* [Qemu-devel] [PATCH 36/38] mips: Magnum/Acer Pica 61: replace cpu_model with cpu_type
  2017-10-02  9:07 [Qemu-devel] [PATCH 00/38] generalize parsing of cpu_model (part 2) Igor Mammedov
                   ` (34 preceding siblings ...)
  2017-10-02  9:08 ` [Qemu-devel] [PATCH 35/38] mips: fulong2e: " Igor Mammedov
@ 2017-10-02  9:08 ` Igor Mammedov
  2017-10-02 14:11   ` Philippe Mathieu-Daudé
  2017-10-03  4:59   ` Hervé Poussineau
  2017-10-02  9:08 ` [Qemu-devel] [PATCH 37/38] mips: mipssim: " Igor Mammedov
  2017-10-02  9:08 ` [Qemu-devel] [PATCH 38/38] mips: r4k: " Igor Mammedov
  37 siblings, 2 replies; 113+ messages in thread
From: Igor Mammedov @ 2017-10-02  9:08 UTC (permalink / raw)
  To: qemu-devel; +Cc: Philippe Mathieu-Daudé, hpoussin, aurelien, yongbok.kim

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
---
CC: hpoussin@reactos.org
CC: aurelien@aurel32.net
CC: yongbok.kim@imgtec.com
---
 hw/mips/mips_jazz.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/hw/mips/mips_jazz.c b/hw/mips/mips_jazz.c
index 7e6626d..fe4f173 100644
--- a/hw/mips/mips_jazz.c
+++ b/hw/mips/mips_jazz.c
@@ -122,7 +122,6 @@ static void mips_jazz_init(MachineState *machine,
                            enum jazz_model_e jazz_model)
 {
     MemoryRegion *address_space = get_system_memory();
-    const char *cpu_model = machine->cpu_model;
     char *filename;
     int bios_size, n;
     MIPSCPU *cpu;
@@ -148,10 +147,7 @@ static void mips_jazz_init(MachineState *machine,
     MemoryRegion *bios2 = g_new(MemoryRegion, 1);
 
     /* init CPUs */
-    if (cpu_model == NULL) {
-        cpu_model = "R4000";
-    }
-    cpu = MIPS_CPU(cpu_generic_init(TYPE_MIPS_CPU, cpu_model));
+    cpu = MIPS_CPU(cpu_create(machine->cpu_type));
     env = &cpu->env;
     qemu_register_reset(main_cpu_reset, cpu);
 
@@ -349,6 +345,7 @@ static void mips_magnum_class_init(ObjectClass *oc, void *data)
     mc->desc = "MIPS Magnum";
     mc->init = mips_magnum_init;
     mc->block_default_type = IF_SCSI;
+    mc->default_cpu_type = MIPS_CPU_TYPE_NAME("R4000");
 }
 
 static const TypeInfo mips_magnum_type = {
@@ -364,6 +361,7 @@ static void mips_pica61_class_init(ObjectClass *oc, void *data)
     mc->desc = "Acer Pica 61";
     mc->init = mips_pica61_init;
     mc->block_default_type = IF_SCSI;
+    mc->default_cpu_type = MIPS_CPU_TYPE_NAME("R4000");
 }
 
 static const TypeInfo mips_pica61_type = {
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 113+ messages in thread

* [Qemu-devel] [PATCH 37/38] mips: mipssim: replace cpu_model with cpu_type
  2017-10-02  9:07 [Qemu-devel] [PATCH 00/38] generalize parsing of cpu_model (part 2) Igor Mammedov
                   ` (35 preceding siblings ...)
  2017-10-02  9:08 ` [Qemu-devel] [PATCH 36/38] mips: Magnum/Acer Pica 61: " Igor Mammedov
@ 2017-10-02  9:08 ` Igor Mammedov
  2017-10-02 14:12   ` Philippe Mathieu-Daudé
  2017-10-02  9:08 ` [Qemu-devel] [PATCH 38/38] mips: r4k: " Igor Mammedov
  37 siblings, 1 reply; 113+ messages in thread
From: Igor Mammedov @ 2017-10-02  9:08 UTC (permalink / raw)
  To: qemu-devel; +Cc: Philippe Mathieu-Daudé, yongbok.kim, aurelien

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
---
CC: yongbok.kim@imgtec.com
CC: aurelien@aurel32.net
---
 hw/mips/mips_mipssim.c | 15 ++++++---------
 1 file changed, 6 insertions(+), 9 deletions(-)

diff --git a/hw/mips/mips_mipssim.c b/hw/mips/mips_mipssim.c
index a092072..e5d3654 100644
--- a/hw/mips/mips_mipssim.c
+++ b/hw/mips/mips_mipssim.c
@@ -141,7 +141,6 @@ static void
 mips_mipssim_init(MachineState *machine)
 {
     ram_addr_t ram_size = machine->ram_size;
-    const char *cpu_model = machine->cpu_model;
     const char *kernel_filename = machine->kernel_filename;
     const char *kernel_cmdline = machine->kernel_cmdline;
     const char *initrd_filename = machine->initrd_filename;
@@ -156,14 +155,7 @@ mips_mipssim_init(MachineState *machine)
     int bios_size;
 
     /* Init CPUs. */
-    if (cpu_model == NULL) {
-#ifdef TARGET_MIPS64
-        cpu_model = "5Kf";
-#else
-        cpu_model = "24Kf";
-#endif
-    }
-    cpu = MIPS_CPU(cpu_generic_init(TYPE_MIPS_CPU, cpu_model));
+    cpu = MIPS_CPU(cpu_create(machine->cpu_type));
     env = &cpu->env;
 
     reset_info = g_malloc0(sizeof(ResetData));
@@ -235,6 +227,11 @@ static void mips_mipssim_machine_init(MachineClass *mc)
 {
     mc->desc = "MIPS MIPSsim platform";
     mc->init = mips_mipssim_init;
+#ifdef TARGET_MIPS64
+    mc->default_cpu_type = MIPS_CPU_TYPE_NAME("5Kf");
+#else
+    mc->default_cpu_type = MIPS_CPU_TYPE_NAME("24Kf");
+#endif
 }
 
 DEFINE_MACHINE("mipssim", mips_mipssim_machine_init)
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 113+ messages in thread

* [Qemu-devel] [PATCH 38/38] mips: r4k: replace cpu_model with cpu_type
  2017-10-02  9:07 [Qemu-devel] [PATCH 00/38] generalize parsing of cpu_model (part 2) Igor Mammedov
                   ` (36 preceding siblings ...)
  2017-10-02  9:08 ` [Qemu-devel] [PATCH 37/38] mips: mipssim: " Igor Mammedov
@ 2017-10-02  9:08 ` Igor Mammedov
  2017-10-02 14:12   ` Philippe Mathieu-Daudé
  37 siblings, 1 reply; 113+ messages in thread
From: Igor Mammedov @ 2017-10-02  9:08 UTC (permalink / raw)
  To: qemu-devel; +Cc: Philippe Mathieu-Daudé, aurelien, yongbok.kim

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
---
CC: aurelien@aurel32.net
CC: yongbok.kim@imgtec.com
---
 hw/mips/mips_r4k.c | 16 +++++++---------
 1 file changed, 7 insertions(+), 9 deletions(-)

diff --git a/hw/mips/mips_r4k.c b/hw/mips/mips_r4k.c
index 1272d4e..3bbb182 100644
--- a/hw/mips/mips_r4k.c
+++ b/hw/mips/mips_r4k.c
@@ -163,7 +163,6 @@ static
 void mips_r4k_init(MachineState *machine)
 {
     ram_addr_t ram_size = machine->ram_size;
-    const char *cpu_model = machine->cpu_model;
     const char *kernel_filename = machine->kernel_filename;
     const char *kernel_cmdline = machine->kernel_cmdline;
     const char *initrd_filename = machine->initrd_filename;
@@ -186,14 +185,7 @@ void mips_r4k_init(MachineState *machine)
     int be;
 
     /* init CPUs */
-    if (cpu_model == NULL) {
-#ifdef TARGET_MIPS64
-        cpu_model = "R4000";
-#else
-        cpu_model = "24Kf";
-#endif
-    }
-    cpu = MIPS_CPU(cpu_generic_init(TYPE_MIPS_CPU, cpu_model));
+    cpu = MIPS_CPU(cpu_create(machine->cpu_type));
     env = &cpu->env;
 
     reset_info = g_malloc0(sizeof(ResetData));
@@ -303,6 +295,12 @@ static void mips_machine_init(MachineClass *mc)
     mc->desc = "mips r4k platform";
     mc->init = mips_r4k_init;
     mc->block_default_type = IF_IDE;
+#ifdef TARGET_MIPS64
+    mc->default_cpu_type = MIPS_CPU_TYPE_NAME("R4000");
+#else
+    mc->default_cpu_type = MIPS_CPU_TYPE_NAME("24Kf");
+#endif
+
 }
 
 DEFINE_MACHINE("mips", mips_machine_init)
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 113+ messages in thread

* Re: [Qemu-devel] [PATCH 02/38] alpha: cleanup cpu type name composition
  2017-10-02  9:07 ` [Qemu-devel] [PATCH 02/38] alpha: cleanup cpu type name composition Igor Mammedov
@ 2017-10-02 12:01   ` Richard Henderson
  2017-10-02 14:46   ` Philippe Mathieu-Daudé
  1 sibling, 0 replies; 113+ messages in thread
From: Richard Henderson @ 2017-10-02 12:01 UTC (permalink / raw)
  To: Igor Mammedov, qemu-devel; +Cc: Philippe Mathieu-Daudé

On 10/02/2017 02:07 AM, Igor Mammedov wrote:
> Introduce ALPHA_CPU_TYPE_NAME macro to replace rather ununique
> TYPE macro that alpha uses. With new macro it will follow
> the same naming convention as other targets.
> 
> While at it put scattered TypeInfo into one array which places
> type desriptions at one place and reduces code a bit.
> 
> Signed-off-by: Igor Mammedov <imammedo@redhat.com>
> ---
> CC: rth@twiddle.net
> ---
>  target/alpha/cpu.h |   3 ++
>  target/alpha/cpu.c | 107 +++++++++++++++++------------------------------------
>  2 files changed, 37 insertions(+), 73 deletions(-)

Acked-by: Richard Henderson <rth@twiddle.net>


r~

^ permalink raw reply	[flat|nested] 113+ messages in thread

* Re: [Qemu-devel] [PATCH 03/38] alpha: use generic cpu_model parsing
  2017-10-02  9:07 ` [Qemu-devel] [PATCH 03/38] alpha: use generic cpu_model parsing Igor Mammedov
@ 2017-10-02 12:01   ` Richard Henderson
  2017-10-02 14:46   ` Philippe Mathieu-Daudé
  1 sibling, 0 replies; 113+ messages in thread
From: Richard Henderson @ 2017-10-02 12:01 UTC (permalink / raw)
  To: Igor Mammedov, qemu-devel; +Cc: Philippe Mathieu-Daudé

On 10/02/2017 02:07 AM, Igor Mammedov wrote:
> Signed-off-by: Igor Mammedov <imammedo@redhat.com>
> ---
> CC: rth@twiddle.net
> ---
>  hw/alpha/dp264.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)

Acked-by: Richard Henderson <rth@twiddle.net>


r~

^ permalink raw reply	[flat|nested] 113+ messages in thread

* Re: [Qemu-devel] [PATCH 33/38] mips: use object_new() instead of gnew()+object_initialize()
  2017-10-02  9:08 ` [Qemu-devel] [PATCH 33/38] mips: use object_new() instead of gnew()+object_initialize() Igor Mammedov
@ 2017-10-02 14:09   ` Philippe Mathieu-Daudé
  0 siblings, 0 replies; 113+ messages in thread
From: Philippe Mathieu-Daudé @ 2017-10-02 14:09 UTC (permalink / raw)
  To: Igor Mammedov, aurelien; +Cc: qemu-devel, paul.burton, yongbok.kim

On 10/02/2017 06:08 AM, Igor Mammedov wrote:
> object_initialize() is intended for inplace initialization of
> objects, but here it's first allocated with g_new0() and then
> initialized with object_initialize(). QEMU already has API
> to do this (object_new), so do object creation with suitable
> for usecase API.
> 
> Signed-off-by: Igor Mammedov <imammedo@redhat.com>

Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org>

> ---
> CC: paul.burton@imgtec.com
> CC: aurelien@aurel32.net
> CC: yongbok.kim@imgtec.com
> ---
>   hw/mips/boston.c     | 3 +--
>   hw/mips/mips_malta.c | 3 +--
>   2 files changed, 2 insertions(+), 4 deletions(-)
> 
> diff --git a/hw/mips/boston.c b/hw/mips/boston.c
> index 776ee28..e815be6 100644
> --- a/hw/mips/boston.c
> +++ b/hw/mips/boston.c
> @@ -460,7 +460,6 @@ static void boston_mach_init(MachineState *machine)
>   
>       s = BOSTON(dev);
>       s->mach = machine;
> -    s->cps = g_new0(MIPSCPSState, 1);
>   
>       if (!cpu_supports_cps_smp(cpu_model)) {
>           error_report("Boston requires CPUs which support CPS");
> @@ -469,7 +468,7 @@ static void boston_mach_init(MachineState *machine)
>   
>       is_64b = cpu_supports_isa(cpu_model, ISA_MIPS64);
>   
> -    object_initialize(s->cps, sizeof(MIPSCPSState), TYPE_MIPS_CPS);
> +    s->cps = MIPS_CPS(object_new(TYPE_MIPS_CPS));
>       qdev_set_parent_bus(DEVICE(s->cps), sysbus_get_default());
>   
>       object_property_set_str(OBJECT(s->cps), cpu_model, "cpu-model", &err);
> diff --git a/hw/mips/mips_malta.c b/hw/mips/mips_malta.c
> index 2adb9bc..b6a58c7 100644
> --- a/hw/mips/mips_malta.c
> +++ b/hw/mips/mips_malta.c
> @@ -949,9 +949,8 @@ static void create_cps(MaltaState *s, const char *cpu_model,
>                          qemu_irq *cbus_irq, qemu_irq *i8259_irq)
>   {
>       Error *err = NULL;
> -    s->cps = g_new0(MIPSCPSState, 1);
>   
> -    object_initialize(s->cps, sizeof(MIPSCPSState), TYPE_MIPS_CPS);
> +    s->cps = MIPS_CPS(object_new(TYPE_MIPS_CPS));
>       qdev_set_parent_bus(DEVICE(s->cps), sysbus_get_default());
>   
>       object_property_set_str(OBJECT(s->cps), cpu_model, "cpu-model", &err);
> 

^ permalink raw reply	[flat|nested] 113+ messages in thread

* Re: [Qemu-devel] [PATCH 34/38] mips: malta/boston: replace cpu_model with cpu_type
  2017-10-02  9:08 ` [Qemu-devel] [PATCH 34/38] mips: malta/boston: replace cpu_model with cpu_type Igor Mammedov
@ 2017-10-02 14:10   ` Philippe Mathieu-Daudé
  0 siblings, 0 replies; 113+ messages in thread
From: Philippe Mathieu-Daudé @ 2017-10-02 14:10 UTC (permalink / raw)
  To: Igor Mammedov, aurelien; +Cc: qemu-devel, paul.burton, yongbok.kim

On 10/02/2017 06:08 AM, Igor Mammedov wrote:
> Signed-off-by: Igor Mammedov <imammedo@redhat.com>
> ---
> CC: paul.burton@imgtec.com
> CC: aurelien@aurel32.net
> CC: yongbok.kim@imgtec.com
> ---
>   include/hw/mips/cps.h        |  2 +-
>   target/mips/cpu.h            |  8 ++++++--
>   hw/mips/boston.c             | 11 +++++------
>   hw/mips/cps.c                |  4 ++--
>   hw/mips/mips_malta.c         | 33 +++++++++++++++------------------
>   target/mips/cpu.c            |  2 +-
>   target/mips/translate.c      | 20 ++++++--------------
>   target/mips/translate_init.c | 12 ------------
>   8 files changed, 36 insertions(+), 56 deletions(-)
> 
> diff --git a/include/hw/mips/cps.h b/include/hw/mips/cps.h
> index 526b8d0..aab1af9 100644
> --- a/include/hw/mips/cps.h
> +++ b/include/hw/mips/cps.h
> @@ -34,7 +34,7 @@ typedef struct MIPSCPSState {
>   
>       uint32_t num_vp;
>       uint32_t num_irq;
> -    char *cpu_model;
> +    char *cpu_type;
>   
>       MemoryRegion container;
>       MIPSGCRState gcr;
> diff --git a/target/mips/cpu.h b/target/mips/cpu.h
> index 66265e4..7f8ba5f 100644
> --- a/target/mips/cpu.h
> +++ b/target/mips/cpu.h
> @@ -740,8 +740,12 @@ enum {
>   int cpu_mips_signal_handler(int host_signum, void *pinfo, void *puc);
>   
>   #define cpu_init(cpu_model) cpu_generic_init(TYPE_MIPS_CPU, cpu_model)
> -bool cpu_supports_cps_smp(const char *cpu_model);
> -bool cpu_supports_isa(const char *cpu_model, unsigned int isa);
> +
> +#define MIPS_CPU_TYPE_SUFFIX "-" TYPE_MIPS_CPU
> +#define MIPS_CPU_TYPE_NAME(model) model MIPS_CPU_TYPE_SUFFIX
> +
> +bool cpu_supports_cps_smp(const char *cpu_type);
> +bool cpu_supports_isa(const char *cpu_type, unsigned int isa);
>   void cpu_set_exception_base(int vp_index, target_ulong address);
>   
>   /* mips_int.c */
> diff --git a/hw/mips/boston.c b/hw/mips/boston.c
> index e815be6..1cb4b6a 100644
> --- a/hw/mips/boston.c
> +++ b/hw/mips/boston.c
> @@ -437,7 +437,6 @@ static void boston_mach_init(MachineState *machine)
>       DeviceState *dev;
>       BostonState *s;
>       Error *err = NULL;
> -    const char *cpu_model;
>       MemoryRegion *flash, *ddr, *ddr_low_alias, *lcd, *platreg;
>       MemoryRegion *sys_mem = get_system_memory();
>       XilinxPCIEHost *pcie2;
> @@ -453,25 +452,24 @@ static void boston_mach_init(MachineState *machine)
>           exit(1);
>       }
>   
> -    cpu_model = machine->cpu_model ?: "I6400";
> -
>       dev = qdev_create(NULL, TYPE_MIPS_BOSTON);
>       qdev_init_nofail(dev);
>   
>       s = BOSTON(dev);
>       s->mach = machine;
>   
> -    if (!cpu_supports_cps_smp(cpu_model)) {
> +    if (!cpu_supports_cps_smp(machine->cpu_type)) {
>           error_report("Boston requires CPUs which support CPS");
>           exit(1);
>       }
>   
> -    is_64b = cpu_supports_isa(cpu_model, ISA_MIPS64);
> +    is_64b = cpu_supports_isa(machine->cpu_type, ISA_MIPS64);
>   
>       s->cps = MIPS_CPS(object_new(TYPE_MIPS_CPS));
>       qdev_set_parent_bus(DEVICE(s->cps), sysbus_get_default());
>   
> -    object_property_set_str(OBJECT(s->cps), cpu_model, "cpu-model", &err);
> +    object_property_set_str(OBJECT(s->cps), machine->cpu_type, "cpu-type",
> +                            &err);
>       object_property_set_int(OBJECT(s->cps), smp_cpus, "num-vp", &err);
>       object_property_set_bool(OBJECT(s->cps), true, "realized", &err);
>   
> @@ -571,6 +569,7 @@ static void boston_mach_class_init(MachineClass *mc)
>       mc->block_default_type = IF_IDE;
>       mc->default_ram_size = 1 * G_BYTE;
>       mc->max_cpus = 16;
> +    mc->default_cpu_type = MIPS_CPU_TYPE_NAME("I6400");
>   }
>   
>   DEFINE_MACHINE("boston", boston_mach_class_init)
> diff --git a/hw/mips/cps.c b/hw/mips/cps.c
> index fe5c630..4285d19 100644
> --- a/hw/mips/cps.c
> +++ b/hw/mips/cps.c
> @@ -71,7 +71,7 @@ static void mips_cps_realize(DeviceState *dev, Error **errp)
>       bool itu_present = false;
>   
>       for (i = 0; i < s->num_vp; i++) {
> -        cpu = MIPS_CPU(cpu_generic_init(TYPE_MIPS_CPU, s->cpu_model));
> +        cpu = MIPS_CPU(cpu_create(s->cpu_type));
>   
>           /* Init internal devices */
>           cpu_mips_irq_init_cpu(cpu);
> @@ -160,7 +160,7 @@ static void mips_cps_realize(DeviceState *dev, Error **errp)
>   static Property mips_cps_properties[] = {
>       DEFINE_PROP_UINT32("num-vp", MIPSCPSState, num_vp, 1),
>       DEFINE_PROP_UINT32("num-irq", MIPSCPSState, num_irq, 256),
> -    DEFINE_PROP_STRING("cpu-model", MIPSCPSState, cpu_model),
> +    DEFINE_PROP_STRING("cpu-type", MIPSCPSState, cpu_type),
>       DEFINE_PROP_END_OF_LIST()
>   };
>   
> diff --git a/hw/mips/mips_malta.c b/hw/mips/mips_malta.c
> index b6a58c7..ec6af4a 100644
> --- a/hw/mips/mips_malta.c
> +++ b/hw/mips/mips_malta.c
> @@ -923,7 +923,7 @@ static void main_cpu_reset(void *opaque)
>       }
>   }
>   
> -static void create_cpu_without_cps(const char *cpu_model,
> +static void create_cpu_without_cps(const char *cpu_type,
>                                      qemu_irq *cbus_irq, qemu_irq *i8259_irq)
>   {
>       CPUMIPSState *env;
> @@ -931,7 +931,7 @@ static void create_cpu_without_cps(const char *cpu_model,
>       int i;
>   
>       for (i = 0; i < smp_cpus; i++) {
> -        cpu = MIPS_CPU(cpu_generic_init(TYPE_MIPS_CPU, cpu_model));
> +        cpu = MIPS_CPU(cpu_create(cpu_type));
>   
>           /* Init internal devices */
>           cpu_mips_irq_init_cpu(cpu);
> @@ -945,7 +945,7 @@ static void create_cpu_without_cps(const char *cpu_model,
>       *cbus_irq = env->irq[4];
>   }
>   
> -static void create_cps(MaltaState *s, const char *cpu_model,
> +static void create_cps(MaltaState *s, const char *cpu_type,
>                          qemu_irq *cbus_irq, qemu_irq *i8259_irq)
>   {
>       Error *err = NULL;
> @@ -953,7 +953,7 @@ static void create_cps(MaltaState *s, const char *cpu_model,
>       s->cps = MIPS_CPS(object_new(TYPE_MIPS_CPS));
>       qdev_set_parent_bus(DEVICE(s->cps), sysbus_get_default());
>   
> -    object_property_set_str(OBJECT(s->cps), cpu_model, "cpu-model", &err);
> +    object_property_set_str(OBJECT(s->cps), cpu_type, "cpu-type", &err);
>       object_property_set_int(OBJECT(s->cps), smp_cpus, "num-vp", &err);
>       object_property_set_bool(OBJECT(s->cps), true, "realized", &err);
>       if (err != NULL) {
> @@ -967,21 +967,13 @@ static void create_cps(MaltaState *s, const char *cpu_model,
>       *cbus_irq = NULL;
>   }
>   
> -static void create_cpu(MaltaState *s, const char *cpu_model,
> -                       qemu_irq *cbus_irq, qemu_irq *i8259_irq)
> +static void mips_create_cpu(MaltaState *s, const char *cpu_type,
> +                            qemu_irq *cbus_irq, qemu_irq *i8259_irq)
>   {
> -    if (cpu_model == NULL) {
> -#ifdef TARGET_MIPS64
> -        cpu_model = "20Kc";
> -#else
> -        cpu_model = "24Kf";
> -#endif
> -    }
> -
> -    if ((smp_cpus > 1) && cpu_supports_cps_smp(cpu_model)) {
> -        create_cps(s, cpu_model, cbus_irq, i8259_irq);
> +    if ((smp_cpus > 1) && cpu_supports_cps_smp(cpu_type)) {
> +        create_cps(s, cpu_type, cbus_irq, i8259_irq);
>       } else {
> -        create_cpu_without_cps(cpu_model, cbus_irq, i8259_irq);
> +        create_cpu_without_cps(cpu_type, cbus_irq, i8259_irq);
>       }
>   }
>   
> @@ -1038,7 +1030,7 @@ void mips_malta_init(MachineState *machine)
>       }
>   
>       /* create CPU */
> -    create_cpu(s, machine->cpu_model, &cbus_irq, &i8259_irq);
> +    mips_create_cpu(s, machine->cpu_type, &cbus_irq, &i8259_irq);
>   
>       /* allocate RAM */
>       if (ram_size > (2048u << 20)) {
> @@ -1264,6 +1256,11 @@ static void mips_malta_machine_init(MachineClass *mc)
>       mc->block_default_type = IF_IDE;
>       mc->max_cpus = 16;
>       mc->is_default = 1;
> +#ifdef TARGET_MIPS64
> +    mc->default_cpu_type = MIPS_CPU_TYPE_NAME("20Kc");
> +#else
> +    mc->default_cpu_type = MIPS_CPU_TYPE_NAME("24Kf");
> +#endif
>   }
>   
>   DEFINE_MACHINE("malta", mips_malta_machine_init)
> diff --git a/target/mips/cpu.c b/target/mips/cpu.c
> index c15b894..24a8907 100644
> --- a/target/mips/cpu.c
> +++ b/target/mips/cpu.c
> @@ -158,7 +158,7 @@ static void mips_cpu_initfn(Object *obj)
>   
>   static char *mips_cpu_type_name(const char *cpu_model)
>   {
> -    return g_strdup_printf("%s-" TYPE_MIPS_CPU, cpu_model);
> +    return g_strdup_printf(MIPS_CPU_TYPE_NAME("%s"), cpu_model);
>   }
>   
>   static ObjectClass *mips_cpu_class_by_name(const char *cpu_model)
> diff --git a/target/mips/translate.c b/target/mips/translate.c
> index d16d879..3d76fc6 100644
> --- a/target/mips/translate.c
> +++ b/target/mips/translate.c
> @@ -20523,24 +20523,16 @@ void cpu_mips_realize_env(CPUMIPSState *env)
>       mvp_init(env, env->cpu_model);
>   }
>   
> -bool cpu_supports_cps_smp(const char *cpu_model)
> +bool cpu_supports_cps_smp(const char *cpu_type)
>   {
> -    const mips_def_t *def = cpu_mips_find_by_name(cpu_model);
> -    if (!def) {
> -        return false;
> -    }
> -
> -    return (def->CP0_Config3 & (1 << CP0C3_CMGCR)) != 0;
> +    const MIPSCPUClass *mcc = MIPS_CPU_CLASS(object_class_by_name(cpu_type));

:)

> +    return (mcc->cpu_def->CP0_Config3 & (1 << CP0C3_CMGCR)) != 0;
>   }
>   
> -bool cpu_supports_isa(const char *cpu_model, unsigned int isa)
> +bool cpu_supports_isa(const char *cpu_type, unsigned int isa)
>   {
> -    const mips_def_t *def = cpu_mips_find_by_name(cpu_model);
> -    if (!def) {
> -        return false;
> -    }
> -
> -    return (def->insn_flags & isa) != 0;
> +    const MIPSCPUClass *mcc = MIPS_CPU_CLASS(object_class_by_name(cpu_type));
> +    return (mcc->cpu_def->insn_flags & isa) != 0;
>   }
>   
>   void cpu_set_exception_base(int vp_index, target_ulong address)
> diff --git a/target/mips/translate_init.c b/target/mips/translate_init.c
> index 8bbded4..c7ba6ee 100644
> --- a/target/mips/translate_init.c
> +++ b/target/mips/translate_init.c
> @@ -755,18 +755,6 @@ const mips_def_t mips_defs[] =
>   };
>   const int mips_defs_number = ARRAY_SIZE(mips_defs);
>   
> -static const mips_def_t *cpu_mips_find_by_name (const char *name)

finally :)

> -{
> -    int i;
> -
> -    for (i = 0; i < ARRAY_SIZE(mips_defs); i++) {
> -        if (strcasecmp(name, mips_defs[i].name) == 0) {
> -            return &mips_defs[i];
> -        }
> -    }
> -    return NULL;
> -}
> -
>   void mips_cpu_list (FILE *f, fprintf_function cpu_fprintf)
>   {
>       int i;
> 
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org>

^ permalink raw reply	[flat|nested] 113+ messages in thread

* Re: [Qemu-devel] [PATCH 35/38] mips: fulong2e: replace cpu_model with cpu_type
  2017-10-02  9:08 ` [Qemu-devel] [PATCH 35/38] mips: fulong2e: " Igor Mammedov
@ 2017-10-02 14:11   ` Philippe Mathieu-Daudé
  0 siblings, 0 replies; 113+ messages in thread
From: Philippe Mathieu-Daudé @ 2017-10-02 14:11 UTC (permalink / raw)
  To: Igor Mammedov; +Cc: qemu-devel, yongbok.kim, aurelien

On 10/02/2017 06:08 AM, Igor Mammedov wrote:
> Signed-off-by: Igor Mammedov <imammedo@redhat.com>

Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>

> ---
> CC: yongbok.kim@imgtec.com
> CC: aurelien@aurel32.net
> ---
>   hw/mips/mips_fulong2e.c | 7 ++-----
>   1 file changed, 2 insertions(+), 5 deletions(-)
> 
> diff --git a/hw/mips/mips_fulong2e.c b/hw/mips/mips_fulong2e.c
> index 7531868..146cf0f 100644
> --- a/hw/mips/mips_fulong2e.c
> +++ b/hw/mips/mips_fulong2e.c
> @@ -258,7 +258,6 @@ static void network_init (PCIBus *pci_bus)
>   static void mips_fulong2e_init(MachineState *machine)
>   {
>       ram_addr_t ram_size = machine->ram_size;
> -    const char *cpu_model = machine->cpu_model;
>       const char *kernel_filename = machine->kernel_filename;
>       const char *kernel_cmdline = machine->kernel_cmdline;
>       const char *initrd_filename = machine->initrd_filename;
> @@ -277,10 +276,7 @@ static void mips_fulong2e_init(MachineState *machine)
>       CPUMIPSState *env;
>   
>       /* init CPUs */
> -    if (cpu_model == NULL) {
> -        cpu_model = "Loongson-2E";
> -    }
> -    cpu = MIPS_CPU(cpu_generic_init(TYPE_MIPS_CPU, cpu_model));
> +    cpu = MIPS_CPU(cpu_create(machine->cpu_type));
>       env = &cpu->env;
>   
>       qemu_register_reset(main_cpu_reset, cpu);
> @@ -385,6 +381,7 @@ static void mips_fulong2e_machine_init(MachineClass *mc)
>       mc->desc = "Fulong 2e mini pc";
>       mc->init = mips_fulong2e_init;
>       mc->block_default_type = IF_IDE;
> +    mc->default_cpu_type = MIPS_CPU_TYPE_NAME("Loongson-2E");
>   }
>   
>   DEFINE_MACHINE("fulong2e", mips_fulong2e_machine_init)
> 

^ permalink raw reply	[flat|nested] 113+ messages in thread

* Re: [Qemu-devel] [PATCH 36/38] mips: Magnum/Acer Pica 61: replace cpu_model with cpu_type
  2017-10-02  9:08 ` [Qemu-devel] [PATCH 36/38] mips: Magnum/Acer Pica 61: " Igor Mammedov
@ 2017-10-02 14:11   ` Philippe Mathieu-Daudé
  2017-10-03  4:59   ` Hervé Poussineau
  1 sibling, 0 replies; 113+ messages in thread
From: Philippe Mathieu-Daudé @ 2017-10-02 14:11 UTC (permalink / raw)
  To: Igor Mammedov; +Cc: qemu-devel, hpoussin, aurelien, yongbok.kim

On 10/02/2017 06:08 AM, Igor Mammedov wrote:
> Signed-off-by: Igor Mammedov <imammedo@redhat.com>

Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>

> ---
> CC: hpoussin@reactos.org
> CC: aurelien@aurel32.net
> CC: yongbok.kim@imgtec.com
> ---
>   hw/mips/mips_jazz.c | 8 +++-----
>   1 file changed, 3 insertions(+), 5 deletions(-)
> 
> diff --git a/hw/mips/mips_jazz.c b/hw/mips/mips_jazz.c
> index 7e6626d..fe4f173 100644
> --- a/hw/mips/mips_jazz.c
> +++ b/hw/mips/mips_jazz.c
> @@ -122,7 +122,6 @@ static void mips_jazz_init(MachineState *machine,
>                              enum jazz_model_e jazz_model)
>   {
>       MemoryRegion *address_space = get_system_memory();
> -    const char *cpu_model = machine->cpu_model;
>       char *filename;
>       int bios_size, n;
>       MIPSCPU *cpu;
> @@ -148,10 +147,7 @@ static void mips_jazz_init(MachineState *machine,
>       MemoryRegion *bios2 = g_new(MemoryRegion, 1);
>   
>       /* init CPUs */
> -    if (cpu_model == NULL) {
> -        cpu_model = "R4000";
> -    }
> -    cpu = MIPS_CPU(cpu_generic_init(TYPE_MIPS_CPU, cpu_model));
> +    cpu = MIPS_CPU(cpu_create(machine->cpu_type));
>       env = &cpu->env;
>       qemu_register_reset(main_cpu_reset, cpu);
>   
> @@ -349,6 +345,7 @@ static void mips_magnum_class_init(ObjectClass *oc, void *data)
>       mc->desc = "MIPS Magnum";
>       mc->init = mips_magnum_init;
>       mc->block_default_type = IF_SCSI;
> +    mc->default_cpu_type = MIPS_CPU_TYPE_NAME("R4000");
>   }
>   
>   static const TypeInfo mips_magnum_type = {
> @@ -364,6 +361,7 @@ static void mips_pica61_class_init(ObjectClass *oc, void *data)
>       mc->desc = "Acer Pica 61";
>       mc->init = mips_pica61_init;
>       mc->block_default_type = IF_SCSI;
> +    mc->default_cpu_type = MIPS_CPU_TYPE_NAME("R4000");
>   }
>   
>   static const TypeInfo mips_pica61_type = {
> 

^ permalink raw reply	[flat|nested] 113+ messages in thread

* Re: [Qemu-devel] [PATCH 37/38] mips: mipssim: replace cpu_model with cpu_type
  2017-10-02  9:08 ` [Qemu-devel] [PATCH 37/38] mips: mipssim: " Igor Mammedov
@ 2017-10-02 14:12   ` Philippe Mathieu-Daudé
  0 siblings, 0 replies; 113+ messages in thread
From: Philippe Mathieu-Daudé @ 2017-10-02 14:12 UTC (permalink / raw)
  To: Igor Mammedov, qemu-devel; +Cc: yongbok.kim, aurelien

On 10/02/2017 06:08 AM, Igor Mammedov wrote:
> Signed-off-by: Igor Mammedov <imammedo@redhat.com>

Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>

> ---
> CC: yongbok.kim@imgtec.com
> CC: aurelien@aurel32.net
> ---
>   hw/mips/mips_mipssim.c | 15 ++++++---------
>   1 file changed, 6 insertions(+), 9 deletions(-)
> 
> diff --git a/hw/mips/mips_mipssim.c b/hw/mips/mips_mipssim.c
> index a092072..e5d3654 100644
> --- a/hw/mips/mips_mipssim.c
> +++ b/hw/mips/mips_mipssim.c
> @@ -141,7 +141,6 @@ static void
>   mips_mipssim_init(MachineState *machine)
>   {
>       ram_addr_t ram_size = machine->ram_size;
> -    const char *cpu_model = machine->cpu_model;
>       const char *kernel_filename = machine->kernel_filename;
>       const char *kernel_cmdline = machine->kernel_cmdline;
>       const char *initrd_filename = machine->initrd_filename;
> @@ -156,14 +155,7 @@ mips_mipssim_init(MachineState *machine)
>       int bios_size;
>   
>       /* Init CPUs. */
> -    if (cpu_model == NULL) {
> -#ifdef TARGET_MIPS64
> -        cpu_model = "5Kf";
> -#else
> -        cpu_model = "24Kf";
> -#endif
> -    }
> -    cpu = MIPS_CPU(cpu_generic_init(TYPE_MIPS_CPU, cpu_model));
> +    cpu = MIPS_CPU(cpu_create(machine->cpu_type));
>       env = &cpu->env;
>   
>       reset_info = g_malloc0(sizeof(ResetData));
> @@ -235,6 +227,11 @@ static void mips_mipssim_machine_init(MachineClass *mc)
>   {
>       mc->desc = "MIPS MIPSsim platform";
>       mc->init = mips_mipssim_init;
> +#ifdef TARGET_MIPS64
> +    mc->default_cpu_type = MIPS_CPU_TYPE_NAME("5Kf");
> +#else
> +    mc->default_cpu_type = MIPS_CPU_TYPE_NAME("24Kf");
> +#endif
>   }
>   
>   DEFINE_MACHINE("mipssim", mips_mipssim_machine_init)
> 

^ permalink raw reply	[flat|nested] 113+ messages in thread

* Re: [Qemu-devel] [PATCH 38/38] mips: r4k: replace cpu_model with cpu_type
  2017-10-02  9:08 ` [Qemu-devel] [PATCH 38/38] mips: r4k: " Igor Mammedov
@ 2017-10-02 14:12   ` Philippe Mathieu-Daudé
  0 siblings, 0 replies; 113+ messages in thread
From: Philippe Mathieu-Daudé @ 2017-10-02 14:12 UTC (permalink / raw)
  To: Igor Mammedov; +Cc: qemu-devel, aurelien, yongbok.kim

On 10/02/2017 06:08 AM, Igor Mammedov wrote:
> Signed-off-by: Igor Mammedov <imammedo@redhat.com>

Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>

> ---
> CC: aurelien@aurel32.net
> CC: yongbok.kim@imgtec.com
> ---
>   hw/mips/mips_r4k.c | 16 +++++++---------
>   1 file changed, 7 insertions(+), 9 deletions(-)
> 
> diff --git a/hw/mips/mips_r4k.c b/hw/mips/mips_r4k.c
> index 1272d4e..3bbb182 100644
> --- a/hw/mips/mips_r4k.c
> +++ b/hw/mips/mips_r4k.c
> @@ -163,7 +163,6 @@ static
>   void mips_r4k_init(MachineState *machine)
>   {
>       ram_addr_t ram_size = machine->ram_size;
> -    const char *cpu_model = machine->cpu_model;
>       const char *kernel_filename = machine->kernel_filename;
>       const char *kernel_cmdline = machine->kernel_cmdline;
>       const char *initrd_filename = machine->initrd_filename;
> @@ -186,14 +185,7 @@ void mips_r4k_init(MachineState *machine)
>       int be;
>   
>       /* init CPUs */
> -    if (cpu_model == NULL) {
> -#ifdef TARGET_MIPS64
> -        cpu_model = "R4000";
> -#else
> -        cpu_model = "24Kf";
> -#endif
> -    }
> -    cpu = MIPS_CPU(cpu_generic_init(TYPE_MIPS_CPU, cpu_model));
> +    cpu = MIPS_CPU(cpu_create(machine->cpu_type));
>       env = &cpu->env;
>   
>       reset_info = g_malloc0(sizeof(ResetData));
> @@ -303,6 +295,12 @@ static void mips_machine_init(MachineClass *mc)
>       mc->desc = "mips r4k platform";
>       mc->init = mips_r4k_init;
>       mc->block_default_type = IF_IDE;
> +#ifdef TARGET_MIPS64
> +    mc->default_cpu_type = MIPS_CPU_TYPE_NAME("R4000");
> +#else
> +    mc->default_cpu_type = MIPS_CPU_TYPE_NAME("24Kf");
> +#endif
> +
>   }
>   
>   DEFINE_MACHINE("mips", mips_machine_init)
> 

^ permalink raw reply	[flat|nested] 113+ messages in thread

* Re: [Qemu-devel] [PATCH 14/38] moxie: use generic cpu_model parsing
  2017-10-02  9:07 ` [Qemu-devel] [PATCH 14/38] moxie: use generic cpu_model parsing Igor Mammedov
@ 2017-10-02 14:13   ` Philippe Mathieu-Daudé
  0 siblings, 0 replies; 113+ messages in thread
From: Philippe Mathieu-Daudé @ 2017-10-02 14:13 UTC (permalink / raw)
  To: Igor Mammedov, qemu-devel; +Cc: green

On 10/02/2017 06:07 AM, Igor Mammedov wrote:
> Signed-off-by: Igor Mammedov <imammedo@redhat.com>

Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>

> ---
> CC: green@moxielogic.com
> ---
>   hw/moxie/moxiesim.c | 7 ++-----
>   1 file changed, 2 insertions(+), 5 deletions(-)
> 
> diff --git a/hw/moxie/moxiesim.c b/hw/moxie/moxiesim.c
> index 01b9f34..3ba5848 100644
> --- a/hw/moxie/moxiesim.c
> +++ b/hw/moxie/moxiesim.c
> @@ -103,7 +103,6 @@ static void moxiesim_init(MachineState *machine)
>   {
>       MoxieCPU *cpu = NULL;
>       ram_addr_t ram_size = machine->ram_size;
> -    const char *cpu_model = machine->cpu_model;
>       const char *kernel_filename = machine->kernel_filename;
>       const char *kernel_cmdline = machine->kernel_cmdline;
>       const char *initrd_filename = machine->initrd_filename;
> @@ -115,10 +114,7 @@ static void moxiesim_init(MachineState *machine)
>       LoaderParams loader_params;
>   
>       /* Init CPUs. */
> -    if (cpu_model == NULL) {
> -        cpu_model = "MoxieLite";
> -    }
> -    cpu = MOXIE_CPU(cpu_generic_init(TYPE_MOXIE_CPU, cpu_model));
> +    cpu = MOXIE_CPU(cpu_create(machine->cpu_type));
>       env = &cpu->env;
>   
>       qemu_register_reset(main_cpu_reset, cpu);
> @@ -150,6 +146,7 @@ static void moxiesim_machine_init(MachineClass *mc)
>       mc->desc = "Moxie simulator platform";
>       mc->init = moxiesim_init;
>       mc->is_default = 1;
> +    mc->default_cpu_type = MOXIE_CPU_TYPE_NAME("MoxieLite");
>   }
>   
>   DEFINE_MACHINE("moxiesim", moxiesim_machine_init)
> 

^ permalink raw reply	[flat|nested] 113+ messages in thread

* Re: [Qemu-devel] [PATCH 01/38] qom: add helper type_init_from_array()
  2017-10-02  9:07 ` [Qemu-devel] [PATCH 01/38] qom: add helper type_init_from_array() Igor Mammedov
@ 2017-10-02 14:15   ` Philippe Mathieu-Daudé
  2017-10-02 19:24   ` Eduardo Habkost
  2017-10-04 10:07   ` [Qemu-devel] [PATCH v2 0/3] add DEFINE_TYPES() helper to simplify batch type registration Igor Mammedov
  2 siblings, 0 replies; 113+ messages in thread
From: Philippe Mathieu-Daudé @ 2017-10-02 14:15 UTC (permalink / raw)
  To: Igor Mammedov; +Cc: qemu-devel, ehabkost

On 10/02/2017 06:07 AM, Igor Mammedov wrote:
> it will help to remove code duplication in places
> that currently open code registration of several
> types.
> 
> Signed-off-by: Igor Mammedov <imammedo@redhat.com>

Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org>

> ---
> I'm going to use it for CPU types in followup patches
> 
> CC: ehabkost@redhat.com
> ---
>   include/qemu/module.h | 10 ++++++++++
>   1 file changed, 10 insertions(+)
> 
> diff --git a/include/qemu/module.h b/include/qemu/module.h
> index 56dd218..29f9089 100644
> --- a/include/qemu/module.h
> +++ b/include/qemu/module.h
> @@ -52,6 +52,16 @@ typedef enum {
>   #define type_init(function) module_init(function, MODULE_INIT_QOM)
>   #define trace_init(function) module_init(function, MODULE_INIT_TRACE)
>   
> +#define type_init_from_array(array)                                        \
> +static void do_qemu_init_ ## array(void)                                   \
> +{                                                                          \
> +    int i;                                                                 \
> +    for (i = 0; i < ARRAY_SIZE(array); i++) {                              \
> +        type_register_static(&array[i]);                                   \
> +    }                                                                      \
> +}                                                                          \
> +module_init(do_qemu_init_ ## array, MODULE_INIT_QOM)
> +
>   #define block_module_load_one(lib) module_load_one("block-", lib)
>   
>   void register_module_init(void (*fn)(void), module_init_type type);
> 

^ permalink raw reply	[flat|nested] 113+ messages in thread

* Re: [Qemu-devel] [PATCH 02/38] alpha: cleanup cpu type name composition
  2017-10-02  9:07 ` [Qemu-devel] [PATCH 02/38] alpha: cleanup cpu type name composition Igor Mammedov
  2017-10-02 12:01   ` Richard Henderson
@ 2017-10-02 14:46   ` Philippe Mathieu-Daudé
  1 sibling, 0 replies; 113+ messages in thread
From: Philippe Mathieu-Daudé @ 2017-10-02 14:46 UTC (permalink / raw)
  To: Igor Mammedov, rth; +Cc: qemu-devel

On 10/02/2017 06:07 AM, Igor Mammedov wrote:
> Introduce ALPHA_CPU_TYPE_NAME macro to replace rather ununique
> TYPE macro that alpha uses. With new macro it will follow
> the same naming convention as other targets.
> 
> While at it put scattered TypeInfo into one array which places
> type desriptions at one place and reduces code a bit.
> 
> Signed-off-by: Igor Mammedov <imammedo@redhat.com>

Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>

> ---
> CC: rth@twiddle.net
> ---
>   target/alpha/cpu.h |   3 ++
>   target/alpha/cpu.c | 107 +++++++++++++++++------------------------------------
>   2 files changed, 37 insertions(+), 73 deletions(-)
> 
> diff --git a/target/alpha/cpu.h b/target/alpha/cpu.h
> index 6ae2409..0a9ad35 100644
> --- a/target/alpha/cpu.h
> +++ b/target/alpha/cpu.h
> @@ -470,6 +470,9 @@ void alpha_translate_init(void);
>   
>   #define cpu_init(cpu_model) cpu_generic_init(TYPE_ALPHA_CPU, cpu_model)
>   
> +#define ALPHA_CPU_TYPE_SUFFIX "-" TYPE_ALPHA_CPU
> +#define ALPHA_CPU_TYPE_NAME(model) model ALPHA_CPU_TYPE_SUFFIX
> +
>   void alpha_cpu_list(FILE *f, fprintf_function cpu_fprintf);
>   /* you can call this signal handler from your SIGBUS and SIGSEGV
>      signal handlers to inform the virtual CPU of exceptions. non zero
> diff --git a/target/alpha/cpu.c b/target/alpha/cpu.c
> index b8a21f4..81a39c4 100644
> --- a/target/alpha/cpu.c
> +++ b/target/alpha/cpu.c
> @@ -108,21 +108,18 @@ void alpha_cpu_list(FILE *f, fprintf_function cpu_fprintf)
>   }
>   
>   /* Models */
> -
> -#define TYPE(model) model "-" TYPE_ALPHA_CPU
> -
>   typedef struct AlphaCPUAlias {
>       const char *alias;
>       const char *typename;
>   } AlphaCPUAlias;
>   
>   static const AlphaCPUAlias alpha_cpu_aliases[] = {
> -    { "21064",   TYPE("ev4") },
> -    { "21164",   TYPE("ev5") },
> -    { "21164a",  TYPE("ev56") },
> -    { "21164pc", TYPE("pca56") },
> -    { "21264",   TYPE("ev6") },
> -    { "21264a",  TYPE("ev67") },
> +    { "21064",   ALPHA_CPU_TYPE_NAME("ev4") },
> +    { "21164",   ALPHA_CPU_TYPE_NAME("ev5") },
> +    { "21164a",  ALPHA_CPU_TYPE_NAME("ev56") },
> +    { "21164pc", ALPHA_CPU_TYPE_NAME("pca56") },
> +    { "21264",   ALPHA_CPU_TYPE_NAME("ev6") },
> +    { "21264a",  ALPHA_CPU_TYPE_NAME("ev67") },
>   };
>   
>   static ObjectClass *alpha_cpu_class_by_name(const char *cpu_model)
> @@ -145,7 +142,7 @@ static ObjectClass *alpha_cpu_class_by_name(const char *cpu_model)
>           }
>       }
>   
> -    typename = g_strdup_printf("%s-" TYPE_ALPHA_CPU, cpu_model);
> +    typename = g_strdup_printf(ALPHA_CPU_TYPE_NAME("%s"), cpu_model);
>       oc = object_class_by_name(typename);
>       g_free(typename);
>       if (oc != NULL && object_class_is_abstract(oc)) {
> @@ -155,7 +152,7 @@ static ObjectClass *alpha_cpu_class_by_name(const char *cpu_model)
>       /* TODO: remove match everything nonsense */
>       /* Default to ev67; no reason not to emulate insns by default. */
>       if (!oc) {
> -        oc = object_class_by_name(TYPE("ev67"));
> +        oc = object_class_by_name(ALPHA_CPU_TYPE_NAME("ev67"));
>       }
>   
>       return oc;
> @@ -169,12 +166,6 @@ static void ev4_cpu_initfn(Object *obj)
>       env->implver = IMPLVER_2106x;
>   }
>   
> -static const TypeInfo ev4_cpu_type_info = {
> -    .name = TYPE("ev4"),
> -    .parent = TYPE_ALPHA_CPU,
> -    .instance_init = ev4_cpu_initfn,
> -};
> -
>   static void ev5_cpu_initfn(Object *obj)
>   {
>       AlphaCPU *cpu = ALPHA_CPU(obj);
> @@ -183,12 +174,6 @@ static void ev5_cpu_initfn(Object *obj)
>       env->implver = IMPLVER_21164;
>   }
>   
> -static const TypeInfo ev5_cpu_type_info = {
> -    .name = TYPE("ev5"),
> -    .parent = TYPE_ALPHA_CPU,
> -    .instance_init = ev5_cpu_initfn,
> -};
> -
>   static void ev56_cpu_initfn(Object *obj)
>   {
>       AlphaCPU *cpu = ALPHA_CPU(obj);
> @@ -197,12 +182,6 @@ static void ev56_cpu_initfn(Object *obj)
>       env->amask |= AMASK_BWX;
>   }
>   
> -static const TypeInfo ev56_cpu_type_info = {
> -    .name = TYPE("ev56"),
> -    .parent = TYPE("ev5"),
> -    .instance_init = ev56_cpu_initfn,
> -};
> -
>   static void pca56_cpu_initfn(Object *obj)
>   {
>       AlphaCPU *cpu = ALPHA_CPU(obj);
> @@ -211,12 +190,6 @@ static void pca56_cpu_initfn(Object *obj)
>       env->amask |= AMASK_MVI;
>   }
>   
> -static const TypeInfo pca56_cpu_type_info = {
> -    .name = TYPE("pca56"),
> -    .parent = TYPE("ev56"),
> -    .instance_init = pca56_cpu_initfn,
> -};
> -
>   static void ev6_cpu_initfn(Object *obj)
>   {
>       AlphaCPU *cpu = ALPHA_CPU(obj);
> @@ -226,12 +199,6 @@ static void ev6_cpu_initfn(Object *obj)
>       env->amask = AMASK_BWX | AMASK_FIX | AMASK_MVI | AMASK_TRAP;
>   }
>   
> -static const TypeInfo ev6_cpu_type_info = {
> -    .name = TYPE("ev6"),
> -    .parent = TYPE_ALPHA_CPU,
> -    .instance_init = ev6_cpu_initfn,
> -};
> -
>   static void ev67_cpu_initfn(Object *obj)
>   {
>       AlphaCPU *cpu = ALPHA_CPU(obj);
> @@ -240,17 +207,6 @@ static void ev67_cpu_initfn(Object *obj)
>       env->amask |= AMASK_CIX | AMASK_PREFETCH;
>   }
>   
> -static const TypeInfo ev67_cpu_type_info = {
> -    .name = TYPE("ev67"),
> -    .parent = TYPE("ev6"),
> -    .instance_init = ev67_cpu_initfn,
> -};
> -
> -static const TypeInfo ev68_cpu_type_info = {
> -    .name = TYPE("ev68"),
> -    .parent = TYPE("ev67"),
> -};
> -
>   static void alpha_cpu_initfn(Object *obj)
>   {
>       CPUState *cs = CPU(obj);
> @@ -303,26 +259,31 @@ static void alpha_cpu_class_init(ObjectClass *oc, void *data)
>       cc->gdb_num_core_regs = 67;
>   }
>   
> -static const TypeInfo alpha_cpu_type_info = {
> -    .name = TYPE_ALPHA_CPU,
> -    .parent = TYPE_CPU,
> -    .instance_size = sizeof(AlphaCPU),
> -    .instance_init = alpha_cpu_initfn,
> -    .abstract = true,
> -    .class_size = sizeof(AlphaCPUClass),
> -    .class_init = alpha_cpu_class_init,
> +#define DEFINE_ALPHA_CPU_TYPE(base_type, cpu_model, initfn) \
> +     {                                                      \
> +         .parent = base_type,                               \
> +         .instance_init = initfn,                           \
> +         .name = ALPHA_CPU_TYPE_NAME(cpu_model),            \
> +     }
> +
> +static const TypeInfo alpha_cpu_type_infos[] = {
> +    {
> +        .name = TYPE_ALPHA_CPU,
> +        .parent = TYPE_CPU,
> +        .instance_size = sizeof(AlphaCPU),
> +        .instance_init = alpha_cpu_initfn,
> +        .abstract = true,
> +        .class_size = sizeof(AlphaCPUClass),
> +        .class_init = alpha_cpu_class_init,
> +    },
> +    DEFINE_ALPHA_CPU_TYPE(TYPE_ALPHA_CPU, "ev4", ev4_cpu_initfn),
> +    DEFINE_ALPHA_CPU_TYPE(TYPE_ALPHA_CPU, "ev5", ev5_cpu_initfn),
> +    DEFINE_ALPHA_CPU_TYPE(ALPHA_CPU_TYPE_NAME("ev5"), "ev56", ev56_cpu_initfn),
> +    DEFINE_ALPHA_CPU_TYPE(ALPHA_CPU_TYPE_NAME("ev56"), "pca56",
> +                          pca56_cpu_initfn),
> +    DEFINE_ALPHA_CPU_TYPE(TYPE_ALPHA_CPU, "ev6", ev6_cpu_initfn),
> +    DEFINE_ALPHA_CPU_TYPE(ALPHA_CPU_TYPE_NAME("ev6"), "ev67", ev67_cpu_initfn),
> +    DEFINE_ALPHA_CPU_TYPE(ALPHA_CPU_TYPE_NAME("ev67"), "ev68", NULL),
>   };
>   
> -static void alpha_cpu_register_types(void)
> -{
> -    type_register_static(&alpha_cpu_type_info);
> -    type_register_static(&ev4_cpu_type_info);
> -    type_register_static(&ev5_cpu_type_info);
> -    type_register_static(&ev56_cpu_type_info);
> -    type_register_static(&pca56_cpu_type_info);
> -    type_register_static(&ev6_cpu_type_info);
> -    type_register_static(&ev67_cpu_type_info);
> -    type_register_static(&ev68_cpu_type_info);
> -}
> -
> -type_init(alpha_cpu_register_types)
> +type_init_from_array(alpha_cpu_type_infos)
> 

^ permalink raw reply	[flat|nested] 113+ messages in thread

* Re: [Qemu-devel] [PATCH 03/38] alpha: use generic cpu_model parsing
  2017-10-02  9:07 ` [Qemu-devel] [PATCH 03/38] alpha: use generic cpu_model parsing Igor Mammedov
  2017-10-02 12:01   ` Richard Henderson
@ 2017-10-02 14:46   ` Philippe Mathieu-Daudé
  1 sibling, 0 replies; 113+ messages in thread
From: Philippe Mathieu-Daudé @ 2017-10-02 14:46 UTC (permalink / raw)
  To: Igor Mammedov, rth; +Cc: qemu-devel

On 10/02/2017 06:07 AM, Igor Mammedov wrote:
> Signed-off-by: Igor Mammedov <imammedo@redhat.com>

Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>

> ---
> CC: rth@twiddle.net
> ---
>   hw/alpha/dp264.c | 4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/hw/alpha/dp264.c b/hw/alpha/dp264.c
> index 1b12130..babd6ea 100644
> --- a/hw/alpha/dp264.c
> +++ b/hw/alpha/dp264.c
> @@ -51,7 +51,6 @@ static int clipper_pci_map_irq(PCIDevice *d, int irq_num)
>   static void clipper_init(MachineState *machine)
>   {
>       ram_addr_t ram_size = machine->ram_size;
> -    const char *cpu_model = machine->cpu_model ? machine->cpu_model : "ev67";
>       const char *kernel_filename = machine->kernel_filename;
>       const char *kernel_cmdline = machine->kernel_cmdline;
>       const char *initrd_filename = machine->initrd_filename;
> @@ -67,7 +66,7 @@ static void clipper_init(MachineState *machine)
>       /* Create up to 4 cpus.  */
>       memset(cpus, 0, sizeof(cpus));
>       for (i = 0; i < smp_cpus; ++i) {
> -        cpus[i] = ALPHA_CPU(cpu_generic_init(TYPE_ALPHA_CPU, cpu_model));
> +        cpus[i] = ALPHA_CPU(cpu_create(machine->cpu_type));
>       }
>   
>       cpus[0]->env.trap_arg0 = ram_size;
> @@ -179,6 +178,7 @@ static void clipper_machine_init(MachineClass *mc)
>       mc->block_default_type = IF_IDE;
>       mc->max_cpus = 4;
>       mc->is_default = 1;
> +    mc->default_cpu_type = ALPHA_CPU_TYPE_NAME("ev67");
>   }
>   
>   DEFINE_MACHINE("clipper", clipper_machine_init)
> 

^ permalink raw reply	[flat|nested] 113+ messages in thread

* Re: [Qemu-devel] [PATCH 04/38] cris: cleanup cpu type name composition
  2017-10-02  9:07 ` [Qemu-devel] [PATCH 04/38] cris: cleanup cpu type name composition Igor Mammedov
@ 2017-10-02 14:51   ` Philippe Mathieu-Daudé
  2017-10-02 15:03     ` Igor Mammedov
  0 siblings, 1 reply; 113+ messages in thread
From: Philippe Mathieu-Daudé @ 2017-10-02 14:51 UTC (permalink / raw)
  To: Igor Mammedov; +Cc: qemu-devel, edgar.iglesias

Hi Igor,

On 10/02/2017 06:07 AM, Igor Mammedov wrote:
> replace ambiguous TYPE macro with a new CRIS_CPU_TYPE_NAME
> and use it consistently in the code.
> 
> Signed-off-by: Igor Mammedov <imammedo@redhat.com>
> ---
> CC: edgar.iglesias@gmail.com
> ---
>   target/cris/cpu.h |  3 ++
>   target/cris/cpu.c | 93 +++++++++++++++++++++++--------------------------------
>   2 files changed, 42 insertions(+), 54 deletions(-)
> 
> diff --git a/target/cris/cpu.h b/target/cris/cpu.h
> index 5d822de..b64fa35 100644
> --- a/target/cris/cpu.h
> +++ b/target/cris/cpu.h
> @@ -269,6 +269,9 @@ enum {
>   
>   #define cpu_init(cpu_model) cpu_generic_init(TYPE_CRIS_CPU, cpu_model)
>   
> +#define CRIS_CPU_TYPE_SUFFIX "-" TYPE_CRIS_CPU
> +#define CRIS_CPU_TYPE_NAME(name) (name CRIS_CPU_TYPE_SUFFIX)
> +
>   #define cpu_signal_handler cpu_cris_signal_handler
>   
>   /* MMU modes definitions */
> diff --git a/target/cris/cpu.c b/target/cris/cpu.c
> index 88d93f2..8681c84 100644
> --- a/target/cris/cpu.c
> +++ b/target/cris/cpu.c
> @@ -71,11 +71,11 @@ static ObjectClass *cris_cpu_class_by_name(const char *cpu_model)
>   
>   #if defined(CONFIG_USER_ONLY)
>       if (strcasecmp(cpu_model, "any") == 0) {
> -        return object_class_by_name("crisv32-" TYPE_CRIS_CPU);
> +        return object_class_by_name(CRIS_CPU_TYPE_NAME("crisv32"));
>       }
>   #endif
>   
> -    typename = g_strdup_printf("%s-" TYPE_CRIS_CPU, cpu_model);
> +    typename = g_strdup_printf(CRIS_CPU_TYPE_NAME("%s"), cpu_model);
>       oc = object_class_by_name(typename);
>       g_free(typename);
>       if (oc != NULL && (!object_class_dynamic_cast(oc, TYPE_CRIS_CPU) ||
> @@ -108,7 +108,7 @@ static void cris_cpu_list_entry(gpointer data, gpointer user_data)
>       const char *typename = object_class_get_name(oc);
>       char *name;
>   
> -    name = g_strndup(typename, strlen(typename) - strlen("-" TYPE_CRIS_CPU));
> +    name = g_strndup(typename, strlen(typename) - strlen(CRIS_CPU_TYPE_SUFFIX));
>       (*s->cpu_fprintf)(s->file, "  %s\n", name);
>       g_free(name);
>   }
> @@ -259,38 +259,6 @@ static void crisv32_cpu_class_init(ObjectClass *oc, void *data)
>       ccc->vr = 32;
>   }
>   
> -#define TYPE(model) model "-" TYPE_CRIS_CPU
> -
> -static const TypeInfo cris_cpu_model_type_infos[] = {
> -    {
> -        .name = TYPE("crisv8"),
> -        .parent = TYPE_CRIS_CPU,
> -        .class_init = crisv8_cpu_class_init,
> -    }, {
> -        .name = TYPE("crisv9"),
> -        .parent = TYPE_CRIS_CPU,
> -        .class_init = crisv9_cpu_class_init,
> -    }, {
> -        .name = TYPE("crisv10"),
> -        .parent = TYPE_CRIS_CPU,
> -        .class_init = crisv10_cpu_class_init,
> -    }, {
> -        .name = TYPE("crisv11"),
> -        .parent = TYPE_CRIS_CPU,
> -        .class_init = crisv11_cpu_class_init,
> -    }, {
> -        .name = TYPE("crisv17"),
> -        .parent = TYPE_CRIS_CPU,
> -        .class_init = crisv17_cpu_class_init,
> -    }, {
> -        .name = TYPE("crisv32"),
> -        .parent = TYPE_CRIS_CPU,
> -        .class_init = crisv32_cpu_class_init,
> -    }
> -};
> -
> -#undef TYPE
> -
>   static void cris_cpu_class_init(ObjectClass *oc, void *data)
>   {
>       DeviceClass *dc = DEVICE_CLASS(oc);
> @@ -324,24 +292,41 @@ static void cris_cpu_class_init(ObjectClass *oc, void *data)
>       cc->disas_set_info = cris_disas_set_info;
>   }
>   
> -static const TypeInfo cris_cpu_type_info = {
> -    .name = TYPE_CRIS_CPU,
> -    .parent = TYPE_CPU,
> -    .instance_size = sizeof(CRISCPU),
> -    .instance_init = cris_cpu_initfn,
> -    .abstract = true,
> -    .class_size = sizeof(CRISCPUClass),
> -    .class_init = cris_cpu_class_init,
> -};
> -
> -static void cris_cpu_register_types(void)
> -{
> -    int i;
> -
> -    type_register_static(&cris_cpu_type_info);
> -    for (i = 0; i < ARRAY_SIZE(cris_cpu_model_type_infos); i++) {
> -        type_register_static(&cris_cpu_model_type_infos[i]);
> +static const TypeInfo cris_cpu_model_type_infos[] = {
> +    {
> +        .name = TYPE_CRIS_CPU,
> +        .parent = TYPE_CPU,
> +        .instance_size = sizeof(CRISCPU),
> +        .instance_init = cris_cpu_initfn,
> +        .abstract = true,
> +        .class_size = sizeof(CRISCPUClass),
> +        .class_init = cris_cpu_class_init,
> +    },
> +    {
> +        .name = CRIS_CPU_TYPE_NAME("crisv8"),
> +        .parent = TYPE_CRIS_CPU,
> +        .class_init = crisv8_cpu_class_init,

what about using your scattering macro like in the Alpha port? i.e.:

      DEFINE_CRIS_CPU_TYPE("crisv8", crisv8_cpu_class_init),

> +    }, {
> +        .name = CRIS_CPU_TYPE_NAME("crisv9"),
> +        .parent = TYPE_CRIS_CPU,
> +        .class_init = crisv9_cpu_class_init,

      ...

> +    }, {
> +        .name = CRIS_CPU_TYPE_NAME("crisv10"),
> +        .parent = TYPE_CRIS_CPU,
> +        .class_init = crisv10_cpu_class_init,
> +    }, {
> +        .name = CRIS_CPU_TYPE_NAME("crisv11"),
> +        .parent = TYPE_CRIS_CPU,
> +        .class_init = crisv11_cpu_class_init,
> +    }, {
> +        .name = CRIS_CPU_TYPE_NAME("crisv17"),
> +        .parent = TYPE_CRIS_CPU,
> +        .class_init = crisv17_cpu_class_init,
> +    }, {
> +        .name = CRIS_CPU_TYPE_NAME("crisv32"),
> +        .parent = TYPE_CRIS_CPU,
> +        .class_init = crisv32_cpu_class_init,
>       }
> -}
> +};
>   
> -type_init(cris_cpu_register_types)
> +type_init_from_array(cris_cpu_model_type_infos)
> 

^ permalink raw reply	[flat|nested] 113+ messages in thread

* Re: [Qemu-devel] [PATCH 05/38] cris: use generic cpu_model parsing
  2017-10-02  9:07 ` [Qemu-devel] [PATCH 05/38] cris: use generic cpu_model parsing Igor Mammedov
@ 2017-10-02 14:52   ` Philippe Mathieu-Daudé
  0 siblings, 0 replies; 113+ messages in thread
From: Philippe Mathieu-Daudé @ 2017-10-02 14:52 UTC (permalink / raw)
  To: Igor Mammedov; +Cc: qemu-devel, edgar.iglesias

On 10/02/2017 06:07 AM, Igor Mammedov wrote:
> Signed-off-by: Igor Mammedov <imammedo@redhat.com>

Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>

> ---
> CC: edgar.iglesias@gmail.com
> ---
>   hw/cris/axis_dev88.c | 7 ++-----
>   1 file changed, 2 insertions(+), 5 deletions(-)
> 
> diff --git a/hw/cris/axis_dev88.c b/hw/cris/axis_dev88.c
> index 5eb552b..9ccc435 100644
> --- a/hw/cris/axis_dev88.c
> +++ b/hw/cris/axis_dev88.c
> @@ -251,7 +251,6 @@ static
>   void axisdev88_init(MachineState *machine)
>   {
>       ram_addr_t ram_size = machine->ram_size;
> -    const char *cpu_model = machine->cpu_model;
>       const char *kernel_filename = machine->kernel_filename;
>       const char *kernel_cmdline = machine->kernel_cmdline;
>       CRISCPU *cpu;
> @@ -268,10 +267,7 @@ void axisdev88_init(MachineState *machine)
>       MemoryRegion *phys_intmem = g_new(MemoryRegion, 1);
>   
>       /* init CPUs */
> -    if (cpu_model == NULL) {
> -        cpu_model = "crisv32";
> -    }
> -    cpu = CRIS_CPU(cpu_generic_init(TYPE_CRIS_CPU, cpu_model));
> +    cpu = CRIS_CPU(cpu_create(machine->cpu_type));
>       env = &cpu->env;
>   
>       /* allocate RAM */
> @@ -359,6 +355,7 @@ static void axisdev88_machine_init(MachineClass *mc)
>       mc->desc = "AXIS devboard 88";
>       mc->init = axisdev88_init;
>       mc->is_default = 1;
> +    mc->default_cpu_type = CRIS_CPU_TYPE_NAME("crisv32");
>   }
>   
>   DEFINE_MACHINE("axis-dev88", axisdev88_machine_init)
> 

^ permalink raw reply	[flat|nested] 113+ messages in thread

* Re: [Qemu-devel] [PATCH 13/38] moxie: cleanup cpu type name composition
  2017-10-02  9:07 ` [Qemu-devel] [PATCH 13/38] moxie: cleanup cpu type name composition Igor Mammedov
@ 2017-10-02 14:54   ` Philippe Mathieu-Daudé
  0 siblings, 0 replies; 113+ messages in thread
From: Philippe Mathieu-Daudé @ 2017-10-02 14:54 UTC (permalink / raw)
  To: Igor Mammedov; +Cc: qemu-devel, green

On 10/02/2017 06:07 AM, Igor Mammedov wrote:
> introduce MOXIE_CPU_TYPE_NAME macro and consistently use it
> to construct cpu type names. While at it replace dynamic
> cpu type name composition with static data.
> 
> Signed-off-by: Igor Mammedov <imammedo@redhat.com>

Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>

> ---
> CC: green@moxielogic.com
> ---
>   target/moxie/cpu.h |  3 +++
>   target/moxie/cpu.c | 56 +++++++++++++++++-------------------------------------
>   2 files changed, 20 insertions(+), 39 deletions(-)
> 
> diff --git a/target/moxie/cpu.h b/target/moxie/cpu.h
> index 75decaa..d37e6a5 100644
> --- a/target/moxie/cpu.h
> +++ b/target/moxie/cpu.h
> @@ -122,6 +122,9 @@ int cpu_moxie_signal_handler(int host_signum, void *pinfo,
>   
>   #define cpu_init(cpu_model) cpu_generic_init(TYPE_MOXIE_CPU, cpu_model)
>   
> +#define MOXIE_CPU_TYPE_SUFFIX "-" TYPE_MOXIE_CPU
> +#define MOXIE_CPU_TYPE_NAME(model) model MOXIE_CPU_TYPE_SUFFIX
> +
>   #define cpu_signal_handler cpu_moxie_signal_handler
>   
>   static inline int cpu_mmu_index(CPUMoxieState *env, bool ifetch)
> diff --git a/target/moxie/cpu.c b/target/moxie/cpu.c
> index d4626a1..1ca8f1a 100644
> --- a/target/moxie/cpu.c
> +++ b/target/moxie/cpu.c
> @@ -92,7 +92,7 @@ static ObjectClass *moxie_cpu_class_by_name(const char *cpu_model)
>       ObjectClass *oc;
>       char *typename;
>   
> -    typename = g_strdup_printf("%s-" TYPE_MOXIE_CPU, cpu_model);
> +    typename = g_strdup_printf(MOXIE_CPU_TYPE_NAME("%s"), cpu_model);
>       oc = object_class_by_name(typename);
>       g_free(typename);
>       if (oc != NULL && (!object_class_dynamic_cast(oc, TYPE_MOXIE_CPU) ||
> @@ -139,46 +139,24 @@ static void moxie_any_initfn(Object *obj)
>       /* Set cpu feature flags */
>   }
>   
> -typedef struct MoxieCPUInfo {
> -    const char *name;
> -    void (*initfn)(Object *obj);
> -} MoxieCPUInfo;
> -
> -static const MoxieCPUInfo moxie_cpus[] = {
> -    { .name = "MoxieLite",      .initfn = moxielite_initfn },
> -    { .name = "any",            .initfn = moxie_any_initfn },
> -};
> +#define DEFINE_MOXIE_CPU_TYPE(cpu_model, initfn) \
> +    {                                            \
> +        .parent = TYPE_MOXIE_CPU,                \
> +        .instance_init = initfn,                 \
> +        .name = MOXIE_CPU_TYPE_NAME(cpu_model),  \
> +    }
>   
> -static void cpu_register(const MoxieCPUInfo *info)
> -{
> -    TypeInfo type_info = {
> -        .parent = TYPE_MOXIE_CPU,
> +static const TypeInfo moxie_cpus_type_infos[] = {
> +    { /* base class should be registered first */
> +        .name = TYPE_MOXIE_CPU,
> +        .parent = TYPE_CPU,
>           .instance_size = sizeof(MoxieCPU),
> -        .instance_init = info->initfn,
> +        .instance_init = moxie_cpu_initfn,
>           .class_size = sizeof(MoxieCPUClass),
> -    };
> -
> -    type_info.name = g_strdup_printf("%s-" TYPE_MOXIE_CPU, info->name);
> -    type_register(&type_info);
> -    g_free((void *)type_info.name);
> -}
> -
> -static const TypeInfo moxie_cpu_type_info = {
> -    .name = TYPE_MOXIE_CPU,
> -    .parent = TYPE_CPU,
> -    .instance_size = sizeof(MoxieCPU),
> -    .instance_init = moxie_cpu_initfn,
> -    .class_size = sizeof(MoxieCPUClass),
> -    .class_init = moxie_cpu_class_init,
> +        .class_init = moxie_cpu_class_init,
> +    },
> +    DEFINE_MOXIE_CPU_TYPE("MoxieLite", moxielite_initfn),
> +    DEFINE_MOXIE_CPU_TYPE("any", moxie_any_initfn),
>   };
>   
> -static void moxie_cpu_register_types(void)
> -{
> -    int i;
> -    type_register_static(&moxie_cpu_type_info);
> -    for (i = 0; i < ARRAY_SIZE(moxie_cpus); i++) {
> -        cpu_register(&moxie_cpus[i]);
> -    }
> -}
> -
> -type_init(moxie_cpu_register_types)
> +type_init_from_array(moxie_cpus_type_infos)
> 

^ permalink raw reply	[flat|nested] 113+ messages in thread

* Re: [Qemu-devel] [PATCH 29/38] sparc: cleanup cpu type name composition
  2017-10-02  9:08 ` [Qemu-devel] [PATCH 29/38] sparc: cleanup cpu type name composition Igor Mammedov
@ 2017-10-02 15:01   ` Philippe Mathieu-Daudé
  0 siblings, 0 replies; 113+ messages in thread
From: Philippe Mathieu-Daudé @ 2017-10-02 15:01 UTC (permalink / raw)
  To: Igor Mammedov, mark.cave-ayland; +Cc: qemu-devel, atar4qemu

On 10/02/2017 06:08 AM, Igor Mammedov wrote:
> introduce SPARC_CPU_TYPE_NAME macro and use it to
> construct cpu type names.
> 
> Signed-off-by: Igor Mammedov <imammedo@redhat.com>

Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org>

> ---
> macro will also be used in follow up patches to define
> default cpu types per board
> 
> CC: mark.cave-ayland@ilande.co.uk
> CC: atar4qemu@gmail.com
> ---
>   target/sparc/cpu.h | 3 +++
>   target/sparc/cpu.c | 2 +-
>   2 files changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/target/sparc/cpu.h b/target/sparc/cpu.h
> index 1598f65..7aa45c9 100644
> --- a/target/sparc/cpu.h
> +++ b/target/sparc/cpu.h
> @@ -658,6 +658,9 @@ int cpu_sparc_signal_handler(int host_signum, void *pinfo, void *puc);
>   #define cpu_init(cpu_model) cpu_generic_init(TYPE_SPARC_CPU, cpu_model)
>   #endif
>   
> +#define SPARC_CPU_TYPE_SUFFIX "-" TYPE_SPARC_CPU
> +#define SPARC_CPU_TYPE_NAME(model) model SPARC_CPU_TYPE_SUFFIX
> +
>   #define cpu_signal_handler cpu_sparc_signal_handler
>   #define cpu_list sparc_cpu_list
>   
> diff --git a/target/sparc/cpu.c b/target/sparc/cpu.c
> index beab90f..f09ba50 100644
> --- a/target/sparc/cpu.c
> +++ b/target/sparc/cpu.c
> @@ -712,7 +712,7 @@ static bool sparc_cpu_has_work(CPUState *cs)
>   
>   static char *sparc_cpu_type_name(const char *cpu_model)
>   {
> -    char *name = g_strdup_printf("%s-" TYPE_SPARC_CPU, cpu_model);
> +    char *name = g_strdup_printf(SPARC_CPU_TYPE_NAME("%s"), cpu_model);
>       char *s = name;
>   
>       /* SPARC cpu model names happen to have whitespaces,
> 

^ permalink raw reply	[flat|nested] 113+ messages in thread

* Re: [Qemu-devel] [PATCH 31/38] sparc: sparc: use generic cpu_model parsing
  2017-10-02  9:08 ` [Qemu-devel] [PATCH 31/38] sparc: sparc: " Igor Mammedov
@ 2017-10-02 15:02   ` Philippe Mathieu-Daudé
  0 siblings, 0 replies; 113+ messages in thread
From: Philippe Mathieu-Daudé @ 2017-10-02 15:02 UTC (permalink / raw)
  To: Igor Mammedov, mark.cave-ayland; +Cc: qemu-devel, atar4qemu

On 10/02/2017 06:08 AM, Igor Mammedov wrote:
> Signed-off-by: Igor Mammedov <imammedo@redhat.com>

Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org>

> ---
> CC: mark.cave-ayland@ilande.co.uk
> CC: atar4qemu@gmail.com
> ---
>   hw/sparc/sun4m.c | 29 ++++++++++++-----------------
>   1 file changed, 12 insertions(+), 17 deletions(-)
> 
> diff --git a/hw/sparc/sun4m.c b/hw/sparc/sun4m.c
> index e1bdd48..68b2378 100644
> --- a/hw/sparc/sun4m.c
> +++ b/hw/sparc/sun4m.c
> @@ -94,7 +94,6 @@ struct sun4m_hwdef {
>       } vsimm[MAX_VSIMMS];
>       hwaddr ecc_base;
>       uint64_t max_mem;
> -    const char * const default_cpu_model;
>       uint32_t ecc_version;
>       uint32_t iommu_version;
>       uint16_t machine_id;
> @@ -790,14 +789,14 @@ static const TypeInfo ram_info = {
>       .class_init    = ram_class_init,
>   };
>   
> -static void cpu_devinit(const char *cpu_model, unsigned int id,
> +static void cpu_devinit(const char *cpu_type, unsigned int id,
>                           uint64_t prom_addr, qemu_irq **cpu_irqs)
>   {
>       CPUState *cs;
>       SPARCCPU *cpu;
>       CPUSPARCState *env;
>   
> -    cpu = SPARC_CPU(cpu_generic_init(TYPE_SPARC_CPU, cpu_model));
> +    cpu = SPARC_CPU(cpu_create(cpu_type));
>       env = &cpu->env;
>   
>       cpu_sparc_set_id(env, id);
> @@ -820,7 +819,6 @@ static void sun4m_hw_init(const struct sun4m_hwdef *hwdef,
>                             MachineState *machine)
>   {
>       DeviceState *slavio_intctl;
> -    const char *cpu_model = machine->cpu_model;
>       unsigned int i;
>       void *iommu, *espdma, *ledma, *nvram;
>       qemu_irq *cpu_irqs[MAX_CPUS], slavio_irq[32], slavio_cpu_irq[MAX_CPUS],
> @@ -833,11 +831,8 @@ static void sun4m_hw_init(const struct sun4m_hwdef *hwdef,
>       unsigned int num_vsimms;
>   
>       /* init CPUs */
> -    if (!cpu_model)
> -        cpu_model = hwdef->default_cpu_model;
> -
>       for(i = 0; i < smp_cpus; i++) {
> -        cpu_devinit(cpu_model, i, hwdef->slavio_base, &cpu_irqs[i]);
> +        cpu_devinit(machine->cpu_type, i, hwdef->slavio_base, &cpu_irqs[i]);
>       }
>   
>       for (i = smp_cpus; i < MAX_CPUS; i++)
> @@ -1074,7 +1069,6 @@ static const struct sun4m_hwdef sun4m_hwdefs[] = {
>           .machine_id = ss5_id,
>           .iommu_version = 0x05000000,
>           .max_mem = 0x10000000,
> -        .default_cpu_model = "Fujitsu MB86904",
>       },
>       /* SS-10 */
>       {
> @@ -1100,7 +1094,6 @@ static const struct sun4m_hwdef sun4m_hwdefs[] = {
>           .machine_id = ss10_id,
>           .iommu_version = 0x03000000,
>           .max_mem = 0xf00000000ULL,
> -        .default_cpu_model = "TI SuperSparc II",
>       },
>       /* SS-600MP */
>       {
> @@ -1124,7 +1117,6 @@ static const struct sun4m_hwdef sun4m_hwdefs[] = {
>           .machine_id = ss600mp_id,
>           .iommu_version = 0x01000000,
>           .max_mem = 0xf00000000ULL,
> -        .default_cpu_model = "TI SuperSparc II",
>       },
>       /* SS-20 */
>       {
> @@ -1166,7 +1158,6 @@ static const struct sun4m_hwdef sun4m_hwdefs[] = {
>           .machine_id = ss20_id,
>           .iommu_version = 0x13000000,
>           .max_mem = 0xf00000000ULL,
> -        .default_cpu_model = "TI SuperSparc II",
>       },
>       /* Voyager */
>       {
> @@ -1190,7 +1181,6 @@ static const struct sun4m_hwdef sun4m_hwdefs[] = {
>           .machine_id = vger_id,
>           .iommu_version = 0x05000000,
>           .max_mem = 0x10000000,
> -        .default_cpu_model = "Fujitsu MB86904",
>       },
>       /* LX */
>       {
> @@ -1215,7 +1205,6 @@ static const struct sun4m_hwdef sun4m_hwdefs[] = {
>           .machine_id = lx_id,
>           .iommu_version = 0x04000000,
>           .max_mem = 0x10000000,
> -        .default_cpu_model = "TI MicroSparc I",
>       },
>       /* SS-4 */
>       {
> @@ -1240,7 +1229,6 @@ static const struct sun4m_hwdef sun4m_hwdefs[] = {
>           .machine_id = ss4_id,
>           .iommu_version = 0x05000000,
>           .max_mem = 0x10000000,
> -        .default_cpu_model = "Fujitsu MB86904",
>       },
>       /* SPARCClassic */
>       {
> @@ -1264,7 +1252,6 @@ static const struct sun4m_hwdef sun4m_hwdefs[] = {
>           .machine_id = scls_id,
>           .iommu_version = 0x05000000,
>           .max_mem = 0x10000000,
> -        .default_cpu_model = "TI MicroSparc I",
>       },
>       /* SPARCbook */
>       {
> @@ -1288,7 +1275,6 @@ static const struct sun4m_hwdef sun4m_hwdefs[] = {
>           .machine_id = sbook_id,
>           .iommu_version = 0x05000000,
>           .max_mem = 0x10000000,
> -        .default_cpu_model = "TI MicroSparc I",
>       },
>   };
>   
> @@ -1355,6 +1341,7 @@ static void ss5_class_init(ObjectClass *oc, void *data)
>       mc->block_default_type = IF_SCSI;
>       mc->is_default = 1;
>       mc->default_boot_order = "c";
> +    mc->default_cpu_type = SPARC_CPU_TYPE_NAME("Fujitsu-MB86904");
>   }
>   
>   static const TypeInfo ss5_type = {
> @@ -1372,6 +1359,7 @@ static void ss10_class_init(ObjectClass *oc, void *data)
>       mc->block_default_type = IF_SCSI;
>       mc->max_cpus = 4;
>       mc->default_boot_order = "c";
> +    mc->default_cpu_type = SPARC_CPU_TYPE_NAME("TI-SuperSparc-II");
>   }
>   
>   static const TypeInfo ss10_type = {
> @@ -1389,6 +1377,7 @@ static void ss600mp_class_init(ObjectClass *oc, void *data)
>       mc->block_default_type = IF_SCSI;
>       mc->max_cpus = 4;
>       mc->default_boot_order = "c";
> +    mc->default_cpu_type = SPARC_CPU_TYPE_NAME("TI-SuperSparc-II");
>   }
>   
>   static const TypeInfo ss600mp_type = {
> @@ -1406,6 +1395,7 @@ static void ss20_class_init(ObjectClass *oc, void *data)
>       mc->block_default_type = IF_SCSI;
>       mc->max_cpus = 4;
>       mc->default_boot_order = "c";
> +    mc->default_cpu_type = SPARC_CPU_TYPE_NAME("TI-SuperSparc-II");
>   }
>   
>   static const TypeInfo ss20_type = {
> @@ -1422,6 +1412,7 @@ static void voyager_class_init(ObjectClass *oc, void *data)
>       mc->init = vger_init;
>       mc->block_default_type = IF_SCSI;
>       mc->default_boot_order = "c";
> +    mc->default_cpu_type = SPARC_CPU_TYPE_NAME("Fujitsu-MB86904");
>   }
>   
>   static const TypeInfo voyager_type = {
> @@ -1438,6 +1429,7 @@ static void ss_lx_class_init(ObjectClass *oc, void *data)
>       mc->init = ss_lx_init;
>       mc->block_default_type = IF_SCSI;
>       mc->default_boot_order = "c";
> +    mc->default_cpu_type = SPARC_CPU_TYPE_NAME("TI-MicroSparc-I");
>   }
>   
>   static const TypeInfo ss_lx_type = {
> @@ -1454,6 +1446,7 @@ static void ss4_class_init(ObjectClass *oc, void *data)
>       mc->init = ss4_init;
>       mc->block_default_type = IF_SCSI;
>       mc->default_boot_order = "c";
> +    mc->default_cpu_type = SPARC_CPU_TYPE_NAME("Fujitsu-MB86904");
>   }
>   
>   static const TypeInfo ss4_type = {
> @@ -1470,6 +1463,7 @@ static void scls_class_init(ObjectClass *oc, void *data)
>       mc->init = scls_init;
>       mc->block_default_type = IF_SCSI;
>       mc->default_boot_order = "c";
> +    mc->default_cpu_type = SPARC_CPU_TYPE_NAME("TI-MicroSparc-I");
>   }
>   
>   static const TypeInfo scls_type = {
> @@ -1486,6 +1480,7 @@ static void sbook_class_init(ObjectClass *oc, void *data)
>       mc->init = sbook_init;
>       mc->block_default_type = IF_SCSI;
>       mc->default_boot_order = "c";
> +    mc->default_cpu_type = SPARC_CPU_TYPE_NAME("TI-MicroSparc-I");
>   }
>   
>   static const TypeInfo sbook_type = {
> 

^ permalink raw reply	[flat|nested] 113+ messages in thread

* Re: [Qemu-devel] [PATCH 04/38] cris: cleanup cpu type name composition
  2017-10-02 14:51   ` Philippe Mathieu-Daudé
@ 2017-10-02 15:03     ` Igor Mammedov
  0 siblings, 0 replies; 113+ messages in thread
From: Igor Mammedov @ 2017-10-02 15:03 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé; +Cc: qemu-devel, edgar.iglesias

On Mon, 2 Oct 2017 11:51:42 -0300
Philippe Mathieu-Daudé <f4bug@amsat.org> wrote:

> Hi Igor,
> 
> On 10/02/2017 06:07 AM, Igor Mammedov wrote:
> > replace ambiguous TYPE macro with a new CRIS_CPU_TYPE_NAME
> > and use it consistently in the code.
> > 
> > Signed-off-by: Igor Mammedov <imammedo@redhat.com>
> > ---
> > CC: edgar.iglesias@gmail.com
> > ---
> >   target/cris/cpu.h |  3 ++
> >   target/cris/cpu.c | 93 +++++++++++++++++++++++--------------------------------
> >   2 files changed, 42 insertions(+), 54 deletions(-)
> > 
> > diff --git a/target/cris/cpu.h b/target/cris/cpu.h
> > index 5d822de..b64fa35 100644
> > --- a/target/cris/cpu.h
> > +++ b/target/cris/cpu.h
> > @@ -269,6 +269,9 @@ enum {
> >   
> >   #define cpu_init(cpu_model) cpu_generic_init(TYPE_CRIS_CPU, cpu_model)
> >   
> > +#define CRIS_CPU_TYPE_SUFFIX "-" TYPE_CRIS_CPU
> > +#define CRIS_CPU_TYPE_NAME(name) (name CRIS_CPU_TYPE_SUFFIX)
> > +
> >   #define cpu_signal_handler cpu_cris_signal_handler
> >   
> >   /* MMU modes definitions */
> > diff --git a/target/cris/cpu.c b/target/cris/cpu.c
> > index 88d93f2..8681c84 100644
> > --- a/target/cris/cpu.c
> > +++ b/target/cris/cpu.c
> > @@ -71,11 +71,11 @@ static ObjectClass *cris_cpu_class_by_name(const char *cpu_model)
> >   
> >   #if defined(CONFIG_USER_ONLY)
> >       if (strcasecmp(cpu_model, "any") == 0) {
> > -        return object_class_by_name("crisv32-" TYPE_CRIS_CPU);
> > +        return object_class_by_name(CRIS_CPU_TYPE_NAME("crisv32"));
> >       }
> >   #endif
> >   
> > -    typename = g_strdup_printf("%s-" TYPE_CRIS_CPU, cpu_model);
> > +    typename = g_strdup_printf(CRIS_CPU_TYPE_NAME("%s"), cpu_model);
> >       oc = object_class_by_name(typename);
> >       g_free(typename);
> >       if (oc != NULL && (!object_class_dynamic_cast(oc, TYPE_CRIS_CPU) ||
> > @@ -108,7 +108,7 @@ static void cris_cpu_list_entry(gpointer data, gpointer user_data)
> >       const char *typename = object_class_get_name(oc);
> >       char *name;
> >   
> > -    name = g_strndup(typename, strlen(typename) - strlen("-" TYPE_CRIS_CPU));
> > +    name = g_strndup(typename, strlen(typename) - strlen(CRIS_CPU_TYPE_SUFFIX));
> >       (*s->cpu_fprintf)(s->file, "  %s\n", name);
> >       g_free(name);
> >   }
> > @@ -259,38 +259,6 @@ static void crisv32_cpu_class_init(ObjectClass *oc, void *data)
> >       ccc->vr = 32;
> >   }
> >   
> > -#define TYPE(model) model "-" TYPE_CRIS_CPU
> > -
> > -static const TypeInfo cris_cpu_model_type_infos[] = {
> > -    {
> > -        .name = TYPE("crisv8"),
> > -        .parent = TYPE_CRIS_CPU,
> > -        .class_init = crisv8_cpu_class_init,
> > -    }, {
> > -        .name = TYPE("crisv9"),
> > -        .parent = TYPE_CRIS_CPU,
> > -        .class_init = crisv9_cpu_class_init,
> > -    }, {
> > -        .name = TYPE("crisv10"),
> > -        .parent = TYPE_CRIS_CPU,
> > -        .class_init = crisv10_cpu_class_init,
> > -    }, {
> > -        .name = TYPE("crisv11"),
> > -        .parent = TYPE_CRIS_CPU,
> > -        .class_init = crisv11_cpu_class_init,
> > -    }, {
> > -        .name = TYPE("crisv17"),
> > -        .parent = TYPE_CRIS_CPU,
> > -        .class_init = crisv17_cpu_class_init,
> > -    }, {
> > -        .name = TYPE("crisv32"),
> > -        .parent = TYPE_CRIS_CPU,
> > -        .class_init = crisv32_cpu_class_init,
> > -    }
> > -};
> > -
> > -#undef TYPE
> > -
> >   static void cris_cpu_class_init(ObjectClass *oc, void *data)
> >   {
> >       DeviceClass *dc = DEVICE_CLASS(oc);
> > @@ -324,24 +292,41 @@ static void cris_cpu_class_init(ObjectClass *oc, void *data)
> >       cc->disas_set_info = cris_disas_set_info;
> >   }
> >   
> > -static const TypeInfo cris_cpu_type_info = {
> > -    .name = TYPE_CRIS_CPU,
> > -    .parent = TYPE_CPU,
> > -    .instance_size = sizeof(CRISCPU),
> > -    .instance_init = cris_cpu_initfn,
> > -    .abstract = true,
> > -    .class_size = sizeof(CRISCPUClass),
> > -    .class_init = cris_cpu_class_init,
> > -};
> > -
> > -static void cris_cpu_register_types(void)
> > -{
> > -    int i;
> > -
> > -    type_register_static(&cris_cpu_type_info);
> > -    for (i = 0; i < ARRAY_SIZE(cris_cpu_model_type_infos); i++) {
> > -        type_register_static(&cris_cpu_model_type_infos[i]);
> > +static const TypeInfo cris_cpu_model_type_infos[] = {
> > +    {
> > +        .name = TYPE_CRIS_CPU,
> > +        .parent = TYPE_CPU,
> > +        .instance_size = sizeof(CRISCPU),
> > +        .instance_init = cris_cpu_initfn,
> > +        .abstract = true,
> > +        .class_size = sizeof(CRISCPUClass),
> > +        .class_init = cris_cpu_class_init,
> > +    },
> > +    {
> > +        .name = CRIS_CPU_TYPE_NAME("crisv8"),
> > +        .parent = TYPE_CRIS_CPU,
> > +        .class_init = crisv8_cpu_class_init,  
> 
> what about using your scattering macro like in the Alpha port? i.e.:
I've thought that I did it but it seems that it got lost along the way,
I'll post here v2 that will do it

> 
>       DEFINE_CRIS_CPU_TYPE("crisv8", crisv8_cpu_class_init),
> 
> > +    }, {
> > +        .name = CRIS_CPU_TYPE_NAME("crisv9"),
> > +        .parent = TYPE_CRIS_CPU,
> > +        .class_init = crisv9_cpu_class_init,  
> 
>       ...
> 
> > +    }, {
> > +        .name = CRIS_CPU_TYPE_NAME("crisv10"),
> > +        .parent = TYPE_CRIS_CPU,
> > +        .class_init = crisv10_cpu_class_init,
> > +    }, {
> > +        .name = CRIS_CPU_TYPE_NAME("crisv11"),
> > +        .parent = TYPE_CRIS_CPU,
> > +        .class_init = crisv11_cpu_class_init,
> > +    }, {
> > +        .name = CRIS_CPU_TYPE_NAME("crisv17"),
> > +        .parent = TYPE_CRIS_CPU,
> > +        .class_init = crisv17_cpu_class_init,
> > +    }, {
> > +        .name = CRIS_CPU_TYPE_NAME("crisv32"),
> > +        .parent = TYPE_CRIS_CPU,
> > +        .class_init = crisv32_cpu_class_init,
> >       }
> > -}
> > +};
> >   
> > -type_init(cris_cpu_register_types)
> > +type_init_from_array(cris_cpu_model_type_infos)
> >   

^ permalink raw reply	[flat|nested] 113+ messages in thread

* Re: [Qemu-devel] [PATCH 32/38] sparc: leon3: use generic cpu_model parsing
  2017-10-02  9:08 ` [Qemu-devel] [PATCH 32/38] sparc: leon3: " Igor Mammedov
@ 2017-10-02 15:54   ` Philippe Mathieu-Daudé
  0 siblings, 0 replies; 113+ messages in thread
From: Philippe Mathieu-Daudé @ 2017-10-02 15:54 UTC (permalink / raw)
  To: Igor Mammedov, mark.cave-ayland; +Cc: qemu-devel, atar4qemu, chouteau

On 10/02/2017 06:08 AM, Igor Mammedov wrote:
> Signed-off-by: Igor Mammedov <imammedo@redhat.com>

Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>

not easy to boot this one, I wonder who still uses it...

building u-boot with:
http://git.denx.de/?p=u-boot.git;a=commit;h=9eed48c8bec98425dbd995dd72c40e9ad7a8c26b

I can't get further than:
https://lists.gnu.org/archive/html/qemu-discuss/2016-05/msg00025.html

Anyway:
Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org>

> ---
> CC: mark.cave-ayland@ilande.co.uk
> CC: atar4qemu@gmail.com
> CC: chouteau@adacore.com
> ---
>   hw/sparc/leon3.c | 8 ++------
>   1 file changed, 2 insertions(+), 6 deletions(-)
> 
> diff --git a/hw/sparc/leon3.c b/hw/sparc/leon3.c
> index ec2816b..8c66d5a 100644
> --- a/hw/sparc/leon3.c
> +++ b/hw/sparc/leon3.c
> @@ -107,7 +107,6 @@ static void leon3_set_pil_in(void *opaque, uint32_t pil_in)
>   static void leon3_generic_hw_init(MachineState *machine)
>   {
>       ram_addr_t ram_size = machine->ram_size;
> -    const char *cpu_model = machine->cpu_model;
>       const char *kernel_filename = machine->kernel_filename;
>       SPARCCPU *cpu;
>       CPUSPARCState   *env;
> @@ -122,11 +121,7 @@ static void leon3_generic_hw_init(MachineState *machine)
>       ResetData  *reset_info;
>   
>       /* Init CPU */
> -    if (!cpu_model) {
> -        cpu_model = "LEON3";
> -    }
> -
> -    cpu = SPARC_CPU(cpu_generic_init(TYPE_SPARC_CPU, cpu_model));
> +    cpu = SPARC_CPU(cpu_create(machine->cpu_type));
>       env = &cpu->env;
>   
>       cpu_sparc_set_id(env, 0);
> @@ -222,6 +217,7 @@ static void leon3_generic_machine_init(MachineClass *mc)
>   {
>       mc->desc = "Leon-3 generic";
>       mc->init = leon3_generic_hw_init;
> +    mc->default_cpu_type = SPARC_CPU_TYPE_NAME("LEON3");
>   }
>   
>   DEFINE_MACHINE("leon3_generic", leon3_generic_machine_init)
> 

^ permalink raw reply	[flat|nested] 113+ messages in thread

* Re: [Qemu-devel] [PATCH 01/38] qom: add helper type_init_from_array()
  2017-10-02  9:07 ` [Qemu-devel] [PATCH 01/38] qom: add helper type_init_from_array() Igor Mammedov
  2017-10-02 14:15   ` Philippe Mathieu-Daudé
@ 2017-10-02 19:24   ` Eduardo Habkost
  2017-10-03 12:13     ` Igor Mammedov
  2017-10-03 12:14     ` [Qemu-devel] [PATCH] qom: add helpers REGISTER_STATIC_TYPE[S]() Igor Mammedov
  2017-10-04 10:07   ` [Qemu-devel] [PATCH v2 0/3] add DEFINE_TYPES() helper to simplify batch type registration Igor Mammedov
  2 siblings, 2 replies; 113+ messages in thread
From: Eduardo Habkost @ 2017-10-02 19:24 UTC (permalink / raw)
  To: Igor Mammedov; +Cc: qemu-devel, Philippe Mathieu-Daudé

On Mon, Oct 02, 2017 at 11:07:43AM +0200, Igor Mammedov wrote:
> it will help to remove code duplication in places
> that currently open code registration of several
> types.
> 
> Signed-off-by: Igor Mammedov <imammedo@redhat.com>
> ---
> I'm going to use it for CPU types in followup patches
> 
> CC: ehabkost@redhat.com
> ---
>  include/qemu/module.h | 10 ++++++++++
>  1 file changed, 10 insertions(+)
> 
> diff --git a/include/qemu/module.h b/include/qemu/module.h
> index 56dd218..29f9089 100644
> --- a/include/qemu/module.h
> +++ b/include/qemu/module.h
> @@ -52,6 +52,16 @@ typedef enum {
>  #define type_init(function) module_init(function, MODULE_INIT_QOM)
>  #define trace_init(function) module_init(function, MODULE_INIT_TRACE)
>  
> +#define type_init_from_array(array)                                        \

So we're moving from a imperative way to register types to a
declarative way.  Sounds nice.

You are also adding a way to register a TypeInfo array easily.
That's nice, too.

But, why do we need to address both at the same time?  I think
this adds some confusing gaps to the module/QOM APIs:

* If you want to register a type at runtime, there are only
  functions to register a single type (type_register(),
  type_register_static().  What if I want to register a TypeInfo
  array from an existing type_init() function?
* If you want to declare types to be registered automatically at
  module_call_init(MODULE_INIT_QOM), you are adding a helper that
  avoids manual type_register*() calls, but only for arrays.
  What if I want to register a single type?  (There are 440+
  functions containing a single type_register*() call in the
  tree)

I have two suggestions:

* Adding a type_register_static_array() helper first, call it
  from a type_init() function, and think about a module.h-based
  helper for arrays later.

* (For later) adding a module_init() helper that works for
  registering a single type too. So, this very common pattern:

      static const TypeInfo FOO_type = {
          /* ... */
      };
      
      static void register_FOO_type(void)
      {
          type_register_static(&FOO_type);
      }
      
      QOM_TYPE(register_FOO_type);

  could be written as:

      static const TypeInfo FOO_type = {
          /* ... */
      };
      
      QOM_TYPE(FOO_type);

(I'm suggesting QOM_TYPE as the macro name, but I'm not sure
about it.  But I think type_init_*() is confusing because it
doesn't work like the other *_init() helpers in module.h)

QOM_TYPE(T) could be just a shortcut to:
QOM_TYPES_PTR(&T, 1).

Your type_init_from_array(A) helper could be just a shortcut to:
QOM_TYPES_PTR(A, ARRAY_SIZE(A)).

> +static void do_qemu_init_ ## array(void)                                   \
> +{                                                                          \
> +    int i;                                                                 \
> +    for (i = 0; i < ARRAY_SIZE(array); i++) {                              \
> +        type_register_static(&array[i]);                                   \

type_register_static() is in qom/object.[ch], and module.[ch] has
no dependency on QOM at all.  I believe this belongs in
qom/object.h, not module.h.

> +    }                                                                      \
> +}                                                                          \
> +module_init(do_qemu_init_ ## array, MODULE_INIT_QOM)

Why not use type_init(do_qemu_init_ ## array)?

> +

Also for later: this is not the first time we generate function
bodies on the fly for module_init().  Maybe module_init could
support a void* data argument?

>  #define block_module_load_one(lib) module_load_one("block-", lib)
>  
>  void register_module_init(void (*fn)(void), module_init_type type);
> -- 
> 2.7.4
> 

-- 
Eduardo

^ permalink raw reply	[flat|nested] 113+ messages in thread

* Re: [Qemu-devel] [PATCH 30/38] sparc: sun4u/sun4v/niagara: use generic cpu_model parsing
  2017-10-02  9:08 ` [Qemu-devel] [PATCH 30/38] sparc: sun4u/sun4v/niagara: use generic cpu_model parsing Igor Mammedov
@ 2017-10-02 20:16   ` Philippe Mathieu-Daudé
  0 siblings, 0 replies; 113+ messages in thread
From: Philippe Mathieu-Daudé @ 2017-10-02 20:16 UTC (permalink / raw)
  To: Igor Mammedov; +Cc: qemu-devel, mark.cave-ayland, atar4qemu

On 10/02/2017 06:08 AM, Igor Mammedov wrote:
> Signed-off-by: Igor Mammedov <imammedo@redhat.com>

Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>

> ---
> CC: mark.cave-ayland@ilande.co.uk
> CC: atar4qemu@gmail.com
> ---
>   include/hw/sparc/sparc64.h | 3 +--
>   hw/sparc64/niagara.c       | 4 ++--
>   hw/sparc64/sparc64.c       | 8 ++------
>   hw/sparc64/sun4u.c         | 8 +++-----
>   4 files changed, 8 insertions(+), 15 deletions(-)
> 
> diff --git a/include/hw/sparc/sparc64.h b/include/hw/sparc/sparc64.h
> index 7748939..ca3bb4b 100644
> --- a/include/hw/sparc/sparc64.h
> +++ b/include/hw/sparc/sparc64.h
> @@ -1,5 +1,4 @@
>   
> -SPARCCPU *sparc64_cpu_devinit(const char *cpu_model,
> -                              const char *dflt_cpu_model, uint64_t prom_addr);
> +SPARCCPU *sparc64_cpu_devinit(const char *cpu_type, uint64_t prom_addr);
>   
>   void sparc64_cpu_set_ivec_irq(void *opaque, int irq, int level);
> diff --git a/hw/sparc64/niagara.c b/hw/sparc64/niagara.c
> index 9a8d610..7a72332 100644
> --- a/hw/sparc64/niagara.c
> +++ b/hw/sparc64/niagara.c
> @@ -106,8 +106,7 @@ static void niagara_init(MachineState *machine)
>       MemoryRegion *sysmem = get_system_memory();
>   
>       /* init CPUs */
> -    sparc64_cpu_devinit(machine->cpu_model, "Sun UltraSparc T1",
> -                        NIAGARA_PROM_BASE);
> +    sparc64_cpu_devinit(machine->cpu_type, NIAGARA_PROM_BASE);
>       /* set up devices */
>       memory_region_allocate_system_memory(&s->hv_ram, NULL, "sun4v-hv.ram",
>                                            NIAGARA_HV_RAM_SIZE);
> @@ -174,6 +173,7 @@ static void niagara_class_init(ObjectClass *oc, void *data)
>       mc->init = niagara_init;
>       mc->max_cpus = 1; /* XXX for now */
>       mc->default_boot_order = "c";
> +    mc->default_cpu_type = SPARC_CPU_TYPE_NAME("Sun-UltraSparc-T1");
>   }
>   
>   static const TypeInfo niagara_type = {
> diff --git a/hw/sparc64/sparc64.c b/hw/sparc64/sparc64.c
> index 097d529..9453e2c 100644
> --- a/hw/sparc64/sparc64.c
> +++ b/hw/sparc64/sparc64.c
> @@ -339,8 +339,7 @@ void cpu_tick_set_limit(CPUTimer *timer, uint64_t limit)
>       }
>   }
>   
> -SPARCCPU *sparc64_cpu_devinit(const char *cpu_model,
> -                              const char *default_cpu_model, uint64_t prom_addr)
> +SPARCCPU *sparc64_cpu_devinit(const char *cpu_type, uint64_t prom_addr)
>   {
>       SPARCCPU *cpu;
>       CPUSPARCState *env;
> @@ -350,10 +349,7 @@ SPARCCPU *sparc64_cpu_devinit(const char *cpu_model,
>       uint32_t  stick_frequency = 100 * 1000000;
>       uint32_t hstick_frequency = 100 * 1000000;
>   
> -    if (cpu_model == NULL) {
> -        cpu_model = default_cpu_model;
> -    }
> -    cpu = SPARC_CPU(cpu_generic_init(TYPE_SPARC_CPU, cpu_model));
> +    cpu = SPARC_CPU(cpu_create(cpu_type));
>       env = &cpu->env;
>   
>       env->tick = cpu_timer_create("tick", cpu, tick_irq,
> diff --git a/hw/sparc64/sun4u.c b/hw/sparc64/sun4u.c
> index c3280aa..d53fad8 100644
> --- a/hw/sparc64/sun4u.c
> +++ b/hw/sparc64/sun4u.c
> @@ -73,7 +73,6 @@
>   #define IVEC_MAX             0x40
>   
>   struct hwdef {
> -    const char * const default_cpu_model;
>       uint16_t machine_id;
>       uint64_t prom_addr;
>       uint64_t console_serial_base;
> @@ -439,8 +438,7 @@ static void sun4uv_init(MemoryRegion *address_space_mem,
>       int onboard_nic_idx;
>   
>       /* init CPUs */
> -    cpu = sparc64_cpu_devinit(machine->cpu_model, hwdef->default_cpu_model,
> -                              hwdef->prom_addr);
> +    cpu = sparc64_cpu_devinit(machine->cpu_type, hwdef->prom_addr);
>   
>       /* set up devices */
>       ram_init(0, machine->ram_size);
> @@ -569,14 +567,12 @@ enum {
>   static const struct hwdef hwdefs[] = {
>       /* Sun4u generic PC-like machine */
>       {
> -        .default_cpu_model = "TI UltraSparc IIi",
>           .machine_id = sun4u_id,
>           .prom_addr = 0x1fff0000000ULL,
>           .console_serial_base = 0,
>       },
>       /* Sun4v generic PC-like machine */
>       {
> -        .default_cpu_model = "Sun UltraSparc T1",
>           .machine_id = sun4v_id,
>           .prom_addr = 0x1fff0000000ULL,
>           .console_serial_base = 0,
> @@ -605,6 +601,7 @@ static void sun4u_class_init(ObjectClass *oc, void *data)
>       mc->max_cpus = 1; /* XXX for now */
>       mc->is_default = 1;
>       mc->default_boot_order = "c";
> +    mc->default_cpu_type = SPARC_CPU_TYPE_NAME("TI-UltraSparc-IIi");
>   }
>   
>   static const TypeInfo sun4u_type = {
> @@ -622,6 +619,7 @@ static void sun4v_class_init(ObjectClass *oc, void *data)
>       mc->block_default_type = IF_IDE;
>       mc->max_cpus = 1; /* XXX for now */
>       mc->default_boot_order = "c";
> +    mc->default_cpu_type = SPARC_CPU_TYPE_NAME("Sun-UltraSparc-T1");
>   }
>   
>   static const TypeInfo sun4v_type = {
> 

^ permalink raw reply	[flat|nested] 113+ messages in thread

* Re: [Qemu-devel] [PATCH 25/38] unicore32: cleanup cpu type name composition
  2017-10-02  9:08 ` [Qemu-devel] [PATCH 25/38] unicore32: cleanup cpu type name composition Igor Mammedov
@ 2017-10-02 20:18   ` Philippe Mathieu-Daudé
  0 siblings, 0 replies; 113+ messages in thread
From: Philippe Mathieu-Daudé @ 2017-10-02 20:18 UTC (permalink / raw)
  To: Igor Mammedov; +Cc: qemu-devel, gxt

On 10/02/2017 06:08 AM, Igor Mammedov wrote:
> use new UNICORE32_CPU_TYPE_NAME to compose CPU type
> name and get rid of intermediate
>     UniCore32CPUInfo/uc32_cpu_register_types()
> which is replaced by static TypeInfo array and
> type_init_from_array()
> 
> Signed-off-by: Igor Mammedov <imammedo@redhat.com>

Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>

> ---
> CC: gxt@mprc.pku.edu.cn
> ---
>   target/unicore32/cpu.h |  3 +++
>   target/unicore32/cpu.c | 61 +++++++++++++++++---------------------------------
>   2 files changed, 23 insertions(+), 41 deletions(-)
> 
> diff --git a/target/unicore32/cpu.h b/target/unicore32/cpu.h
> index 7724108..3dc6fbc 100644
> --- a/target/unicore32/cpu.h
> +++ b/target/unicore32/cpu.h
> @@ -167,6 +167,9 @@ static inline int cpu_mmu_index(CPUUniCore32State *env, bool ifetch)
>   
>   #define cpu_init(cpu_model) cpu_generic_init(TYPE_UNICORE32_CPU, cpu_model)
>   
> +#define UNICORE32_CPU_TYPE_SUFFIX "-" TYPE_UNICORE32_CPU
> +#define UNICORE32_CPU_TYPE_NAME(model) model UNICORE32_CPU_TYPE_SUFFIX
> +
>   static inline void cpu_get_tb_cpu_state(CPUUniCore32State *env, target_ulong *pc,
>                                           target_ulong *cs_base, uint32_t *flags)
>   {
> diff --git a/target/unicore32/cpu.c b/target/unicore32/cpu.c
> index 138acc9..3345cfd 100644
> --- a/target/unicore32/cpu.c
> +++ b/target/unicore32/cpu.c
> @@ -44,7 +44,7 @@ static ObjectClass *uc32_cpu_class_by_name(const char *cpu_model)
>       ObjectClass *oc;
>       char *typename;
>   
> -    typename = g_strdup_printf("%s-" TYPE_UNICORE32_CPU, cpu_model);
> +    typename = g_strdup_printf(UNICORE32_CPU_TYPE_NAME("%s"), cpu_model);
>       oc = object_class_by_name(typename);
>       g_free(typename);
>       if (oc != NULL && (!object_class_dynamic_cast(oc, TYPE_UNICORE32_CPU) ||
> @@ -54,11 +54,6 @@ static ObjectClass *uc32_cpu_class_by_name(const char *cpu_model)
>       return oc;
>   }
>   
> -typedef struct UniCore32CPUInfo {
> -    const char *name;
> -    void (*instance_init)(Object *obj);
> -} UniCore32CPUInfo;
> -
>   static void unicore_ii_cpu_initfn(Object *obj)
>   {
>       UniCore32CPU *cpu = UNICORE32_CPU(obj);
> @@ -90,11 +85,6 @@ static void uc32_any_cpu_initfn(Object *obj)
>       set_snan_bit_is_one(1, &env->ucf64.fp_status);
>   }
>   
> -static const UniCore32CPUInfo uc32_cpus[] = {
> -    { .name = "UniCore-II", .instance_init = unicore_ii_cpu_initfn },
> -    { .name = "any",        .instance_init = uc32_any_cpu_initfn },
> -};
> -
>   static void uc32_cpu_realizefn(DeviceState *dev, Error **errp)
>   {
>       CPUState *cs = CPU(dev);
> @@ -165,36 +155,25 @@ static void uc32_cpu_class_init(ObjectClass *oc, void *data)
>       dc->vmsd = &vmstate_uc32_cpu;
>   }
>   
> -static void uc32_register_cpu_type(const UniCore32CPUInfo *info)
> -{
> -    TypeInfo type_info = {
> -        .parent = TYPE_UNICORE32_CPU,
> -        .instance_init = info->instance_init,
> -    };
> -
> -    type_info.name = g_strdup_printf("%s-" TYPE_UNICORE32_CPU, info->name);
> -    type_register(&type_info);
> -    g_free((void *)type_info.name);
> -}
> +#define DEFINE_UNICORE32_CPU_TYPE(cpu_model, initfn) \
> +    {                                                \
> +        .parent = TYPE_UNICORE32_CPU,                \
> +        .instance_init = initfn,                     \
> +        .name = UNICORE32_CPU_TYPE_NAME(cpu_model),  \
> +    }
>   
> -static const TypeInfo uc32_cpu_type_info = {
> -    .name = TYPE_UNICORE32_CPU,
> -    .parent = TYPE_CPU,
> -    .instance_size = sizeof(UniCore32CPU),
> -    .instance_init = uc32_cpu_initfn,
> -    .abstract = true,
> -    .class_size = sizeof(UniCore32CPUClass),
> -    .class_init = uc32_cpu_class_init,
> +static const TypeInfo uc32_cpu_type_infos[] = {
> +    {
> +        .name = TYPE_UNICORE32_CPU,
> +        .parent = TYPE_CPU,
> +        .instance_size = sizeof(UniCore32CPU),
> +        .instance_init = uc32_cpu_initfn,
> +        .abstract = true,
> +        .class_size = sizeof(UniCore32CPUClass),
> +        .class_init = uc32_cpu_class_init,
> +    },
> +    DEFINE_UNICORE32_CPU_TYPE("UniCore-II", unicore_ii_cpu_initfn),
> +    DEFINE_UNICORE32_CPU_TYPE("any", uc32_any_cpu_initfn),
>   };
>   
> -static void uc32_cpu_register_types(void)
> -{
> -    int i;
> -
> -    type_register_static(&uc32_cpu_type_info);
> -    for (i = 0; i < ARRAY_SIZE(uc32_cpus); i++) {
> -        uc32_register_cpu_type(&uc32_cpus[i]);
> -    }
> -}
> -
> -type_init(uc32_cpu_register_types)
> +type_init_from_array(uc32_cpu_type_infos)
> 

^ permalink raw reply	[flat|nested] 113+ messages in thread

* Re: [Qemu-devel] [PATCH 26/38] unicore32: use generic cpu_model parsing
  2017-10-02  9:08 ` [Qemu-devel] [PATCH 26/38] unicore32: use generic cpu_model parsing Igor Mammedov
@ 2017-10-02 20:18   ` Philippe Mathieu-Daudé
  0 siblings, 0 replies; 113+ messages in thread
From: Philippe Mathieu-Daudé @ 2017-10-02 20:18 UTC (permalink / raw)
  To: Igor Mammedov; +Cc: qemu-devel, Guan Xuetao

On 10/02/2017 06:08 AM, Igor Mammedov wrote:
> Signed-off-by: Igor Mammedov <imammedo@redhat.com>

Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>

> ---
> CC: Guan Xuetao <gxt@mprc.pku.edu.cn>
> ---
>   hw/unicore32/puv3.c | 8 ++------
>   1 file changed, 2 insertions(+), 6 deletions(-)
> 
> diff --git a/hw/unicore32/puv3.c b/hw/unicore32/puv3.c
> index 504ea46..1b39cc0 100644
> --- a/hw/unicore32/puv3.c
> +++ b/hw/unicore32/puv3.c
> @@ -112,7 +112,6 @@ static void puv3_load_kernel(const char *kernel_filename)
>   static void puv3_init(MachineState *machine)
>   {
>       ram_addr_t ram_size = machine->ram_size;
> -    const char *cpu_model = machine->cpu_model;
>       const char *kernel_filename = machine->kernel_filename;
>       const char *initrd_filename = machine->initrd_filename;
>       CPUUniCore32State *env;
> @@ -123,11 +122,7 @@ static void puv3_init(MachineState *machine)
>           exit(1);
>       }
>   
> -    if (!cpu_model) {
> -        cpu_model = "UniCore-II";
> -    }
> -
> -    cpu = UNICORE32_CPU(cpu_generic_init(TYPE_UNICORE32_CPU, cpu_model));
> +    cpu = UNICORE32_CPU(cpu_create(machine->cpu_type));
>       env = &cpu->env;
>   
>       puv3_soc_init(env);
> @@ -140,6 +135,7 @@ static void puv3_machine_init(MachineClass *mc)
>       mc->desc = "PKUnity Version-3 based on UniCore32";
>       mc->init = puv3_init;
>       mc->is_default = 1;
> +    mc->default_cpu_type = UNICORE32_CPU_TYPE_NAME("UniCore-II");
>   }
>   
>   DEFINE_MACHINE("puv3", puv3_machine_init)
> 

^ permalink raw reply	[flat|nested] 113+ messages in thread

* Re: [Qemu-devel] [PATCH 15/38] openrisc: cleanup cpu type name composition
  2017-10-02  9:07 ` [Qemu-devel] [PATCH 15/38] openrisc: cleanup cpu type name composition Igor Mammedov
@ 2017-10-02 20:19   ` Philippe Mathieu-Daudé
  0 siblings, 0 replies; 113+ messages in thread
From: Philippe Mathieu-Daudé @ 2017-10-02 20:19 UTC (permalink / raw)
  To: Igor Mammedov; +Cc: qemu-devel, shorne

On 10/02/2017 06:07 AM, Igor Mammedov wrote:
> use new OPENRISC_CPU_TYPE_NAME to compose CPU type name and get
> rid of intermediate OpenRISCCPUInfo/openrisc_cpu_register_types()
> which is replaced by static TypeInfo array.
> 
> Signed-off-by: Igor Mammedov <imammedo@redhat.com>

Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>

> ---
> CC: shorne@gmail.com
> ---
>   target/openrisc/cpu.h |  3 +++
>   target/openrisc/cpu.c | 69 +++++++++++++++++----------------------------------
>   2 files changed, 26 insertions(+), 46 deletions(-)
> 
> diff --git a/target/openrisc/cpu.h b/target/openrisc/cpu.h
> index f51b89a..576cf66 100644
> --- a/target/openrisc/cpu.h
> +++ b/target/openrisc/cpu.h
> @@ -390,6 +390,9 @@ int cpu_openrisc_get_phys_data(OpenRISCCPU *cpu,
>   
>   #define cpu_init(cpu_model) cpu_generic_init(TYPE_OPENRISC_CPU, cpu_model)
>   
> +#define OPENRISC_CPU_TYPE_SUFFIX "-" TYPE_OPENRISC_CPU
> +#define OPENRISC_CPU_TYPE_NAME(model) model OPENRISC_CPU_TYPE_SUFFIX
> +
>   #include "exec/cpu-all.h"
>   
>   #define TB_FLAGS_DFLAG 1
> diff --git a/target/openrisc/cpu.c b/target/openrisc/cpu.c
> index af9cdcc..4dfb777 100644
> --- a/target/openrisc/cpu.c
> +++ b/target/openrisc/cpu.c
> @@ -108,7 +108,7 @@ static ObjectClass *openrisc_cpu_class_by_name(const char *cpu_model)
>       ObjectClass *oc;
>       char *typename;
>   
> -    typename = g_strdup_printf("%s-" TYPE_OPENRISC_CPU, 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) ||
> @@ -133,16 +133,6 @@ static void openrisc_any_initfn(Object *obj)
>       cpu->env.cpucfgr = CPUCFGR_NSGF | CPUCFGR_OB32S | CPUCFGR_EVBARP;
>   }
>   
> -typedef struct OpenRISCCPUInfo {
> -    const char *name;
> -    void (*initfn)(Object *obj);
> -} OpenRISCCPUInfo;
> -
> -static const OpenRISCCPUInfo openrisc_cpus[] = {
> -    { .name = "or1200",      .initfn = or1200_initfn },
> -    { .name = "any",         .initfn = openrisc_any_initfn },
> -};
> -
>   static void openrisc_cpu_class_init(ObjectClass *oc, void *data)
>   {
>       OpenRISCCPUClass *occ = OPENRISC_CPU_CLASS(oc);
> @@ -172,40 +162,6 @@ static void openrisc_cpu_class_init(ObjectClass *oc, void *data)
>       cc->gdb_num_core_regs = 32 + 3;
>   }
>   
> -static void cpu_register(const OpenRISCCPUInfo *info)
> -{
> -    TypeInfo type_info = {
> -        .parent = TYPE_OPENRISC_CPU,
> -        .instance_size = sizeof(OpenRISCCPU),
> -        .instance_init = info->initfn,
> -        .class_size = sizeof(OpenRISCCPUClass),
> -    };
> -
> -    type_info.name = g_strdup_printf("%s-" TYPE_OPENRISC_CPU, info->name);
> -    type_register(&type_info);
> -    g_free((void *)type_info.name);
> -}
> -
> -static const TypeInfo openrisc_cpu_type_info = {
> -    .name = TYPE_OPENRISC_CPU,
> -    .parent = TYPE_CPU,
> -    .instance_size = sizeof(OpenRISCCPU),
> -    .instance_init = openrisc_cpu_initfn,
> -    .abstract = true,
> -    .class_size = sizeof(OpenRISCCPUClass),
> -    .class_init = openrisc_cpu_class_init,
> -};
> -
> -static void openrisc_cpu_register_types(void)
> -{
> -    int i;
> -
> -    type_register_static(&openrisc_cpu_type_info);
> -    for (i = 0; i < ARRAY_SIZE(openrisc_cpus); i++) {
> -        cpu_register(&openrisc_cpus[i]);
> -    }
> -}
> -
>   /* Sort alphabetically by type name, except for "any". */
>   static gint openrisc_cpu_list_compare(gconstpointer a, gconstpointer b)
>   {
> @@ -254,4 +210,25 @@ void cpu_openrisc_list(FILE *f, fprintf_function cpu_fprintf)
>       g_slist_free(list);
>   }
>   
> -type_init(openrisc_cpu_register_types)
> +#define DEFINE_OPENRISC_CPU_TYPE(cpu_model, initfn) \
> +    {                                               \
> +        .parent = TYPE_OPENRISC_CPU,                \
> +        .instance_init = initfn,                    \
> +        .name = OPENRISC_CPU_TYPE_NAME(cpu_model),  \
> +    }
> +
> +static const TypeInfo openrisc_cpus_type_infos[] = {
> +    { /* base class should be registered first */
> +        .name = TYPE_OPENRISC_CPU,
> +        .parent = TYPE_CPU,
> +        .instance_size = sizeof(OpenRISCCPU),
> +        .instance_init = openrisc_cpu_initfn,
> +        .abstract = true,
> +        .class_size = sizeof(OpenRISCCPUClass),
> +        .class_init = openrisc_cpu_class_init,
> +    },
> +    DEFINE_OPENRISC_CPU_TYPE("or1200", or1200_initfn),
> +    DEFINE_OPENRISC_CPU_TYPE("any", openrisc_any_initfn),
> +};
> +
> +type_init_from_array(openrisc_cpus_type_infos)
> 

^ permalink raw reply	[flat|nested] 113+ messages in thread

* Re: [Qemu-devel] [PATCH 16/38] openrisc: use generic cpu_model parsing
  2017-10-02  9:07 ` [Qemu-devel] [PATCH 16/38] openrisc: use generic cpu_model parsing Igor Mammedov
@ 2017-10-02 20:20   ` Philippe Mathieu-Daudé
  0 siblings, 0 replies; 113+ messages in thread
From: Philippe Mathieu-Daudé @ 2017-10-02 20:20 UTC (permalink / raw)
  To: Igor Mammedov, qemu-devel; +Cc: shorne

On 10/02/2017 06:07 AM, Igor Mammedov wrote:
> Signed-off-by: Igor Mammedov <imammedo@redhat.com>

Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>

> ---
> CC: shorne@gmail.com
> ---
>   hw/openrisc/openrisc_sim.c | 8 ++------
>   1 file changed, 2 insertions(+), 6 deletions(-)
> 
> diff --git a/hw/openrisc/openrisc_sim.c b/hw/openrisc/openrisc_sim.c
> index 86bf284..f61b63d 100644
> --- a/hw/openrisc/openrisc_sim.c
> +++ b/hw/openrisc/openrisc_sim.c
> @@ -98,18 +98,13 @@ static void cpu_openrisc_load_kernel(ram_addr_t ram_size,
>   static void openrisc_sim_init(MachineState *machine)
>   {
>       ram_addr_t ram_size = machine->ram_size;
> -    const char *cpu_model = machine->cpu_model;
>       const char *kernel_filename = machine->kernel_filename;
>       OpenRISCCPU *cpu = NULL;
>       MemoryRegion *ram;
>       int n;
>   
> -    if (!cpu_model) {
> -        cpu_model = "or1200";
> -    }
> -
>       for (n = 0; n < smp_cpus; n++) {
> -        cpu = OPENRISC_CPU(cpu_generic_init(TYPE_OPENRISC_CPU, cpu_model));
> +        cpu = OPENRISC_CPU(cpu_create(machine->cpu_type));
>           qemu_register_reset(main_cpu_reset, cpu);
>           main_cpu_reset(cpu);
>       }
> @@ -138,6 +133,7 @@ static void openrisc_sim_machine_init(MachineClass *mc)
>       mc->init = openrisc_sim_init;
>       mc->max_cpus = 1;
>       mc->is_default = 1;
> +    mc->default_cpu_type = OPENRISC_CPU_TYPE_NAME("or1200");
>   }
>   
>   DEFINE_MACHINE("or1k-sim", openrisc_sim_machine_init)
> 

^ permalink raw reply	[flat|nested] 113+ messages in thread

* Re: [Qemu-devel] [PATCH 06/38] lm32: cleanup cpu type name composition
  2017-10-02  9:07 ` [Qemu-devel] [PATCH 06/38] lm32: cleanup cpu type name composition Igor Mammedov
@ 2017-10-02 20:28   ` Philippe Mathieu-Daudé
  2017-10-03 13:00   ` Michael Walle
  1 sibling, 0 replies; 113+ messages in thread
From: Philippe Mathieu-Daudé @ 2017-10-02 20:28 UTC (permalink / raw)
  To: Igor Mammedov; +Cc: qemu-devel, michael

On 10/02/2017 06:07 AM, Igor Mammedov wrote:
> introduce LM32_CPU_TYPE_NAME macro and consistently use it
> to construct cpu type names. While at it replace dynamic
> cpu type name composition with static data.
> 
> Signed-off-by: Igor Mammedov <imammedo@redhat.com>

Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>

> ---
> CC: michael@walle.cc
> ---
>   target/lm32/cpu.h |  3 +++
>   target/lm32/cpu.c | 74 +++++++++++++++++--------------------------------------
>   2 files changed, 25 insertions(+), 52 deletions(-)
> 
> diff --git a/target/lm32/cpu.h b/target/lm32/cpu.h
> index de265b5..2279594 100644
> --- a/target/lm32/cpu.h
> +++ b/target/lm32/cpu.h
> @@ -257,6 +257,9 @@ bool lm32_cpu_do_semihosting(CPUState *cs);
>   
>   #define cpu_init(cpu_model) cpu_generic_init(TYPE_LM32_CPU, cpu_model)
>   
> +#define LM32_CPU_TYPE_SUFFIX "-" TYPE_LM32_CPU
> +#define LM32_CPU_TYPE_NAME(model) model LM32_CPU_TYPE_SUFFIX
> +
>   #define cpu_list lm32_cpu_list
>   #define cpu_signal_handler cpu_lm32_signal_handler
>   
> diff --git a/target/lm32/cpu.c b/target/lm32/cpu.c
> index bf081f5..4d0da50 100644
> --- a/target/lm32/cpu.c
> +++ b/target/lm32/cpu.c
> @@ -51,7 +51,7 @@ static void lm32_cpu_list_entry(gpointer data, gpointer user_data)
>       const char *typename = object_class_get_name(oc);
>       char *name;
>   
> -    name = g_strndup(typename, strlen(typename) - strlen("-" TYPE_LM32_CPU));
> +    name = g_strndup(typename, strlen(typename) - strlen(LM32_CPU_TYPE_SUFFIX));
>       (*s->cpu_fprintf)(s->file, "  %s\n", name);
>       g_free(name);
>   }
> @@ -221,32 +221,12 @@ static void lm32_full_cpu_initfn(Object *obj)
>                     | LM32_FEATURE_CYCLE_COUNT;
>   }
>   
> -typedef struct LM32CPUInfo {
> -    const char *name;
> -    void (*initfn)(Object *obj);
> -} LM32CPUInfo;
> -
> -static const LM32CPUInfo lm32_cpus[] = {
> -    {
> -        .name = "lm32-basic",
> -        .initfn = lm32_basic_cpu_initfn,
> -    },
> -    {
> -        .name = "lm32-standard",
> -        .initfn = lm32_standard_cpu_initfn,
> -    },
> -    {
> -        .name = "lm32-full",
> -        .initfn = lm32_full_cpu_initfn,
> -    },
> -};
> -
>   static ObjectClass *lm32_cpu_class_by_name(const char *cpu_model)
>   {
>       ObjectClass *oc;
>       char *typename;
>   
> -    typename = g_strdup_printf("%s-" TYPE_LM32_CPU, cpu_model);
> +    typename = g_strdup_printf(LM32_CPU_TYPE_NAME("%s"), cpu_model);
>       oc = object_class_by_name(typename);
>       g_free(typename);
>       if (oc != NULL && (!object_class_dynamic_cast(oc, TYPE_LM32_CPU) ||
> @@ -288,36 +268,26 @@ static void lm32_cpu_class_init(ObjectClass *oc, void *data)
>       cc->disas_set_info = lm32_cpu_disas_set_info;
>   }
>   
> -static void lm32_register_cpu_type(const LM32CPUInfo *info)
> -{
> -    TypeInfo type_info = {
> -        .parent = TYPE_LM32_CPU,
> -        .instance_init = info->initfn,
> -    };
> -
> -    type_info.name = g_strdup_printf("%s-" TYPE_LM32_CPU, info->name);
> -    type_register(&type_info);
> -    g_free((void *)type_info.name);
> -}
> +#define DEFINE_LM32_CPU_TYPE(cpu_model, initfn) \
> +    { \
> +        .parent = TYPE_LM32_CPU, \
> +        .name = LM32_CPU_TYPE_NAME(cpu_model), \
> +        .instance_init = initfn, \
> +    }
>   
> -static const TypeInfo lm32_cpu_type_info = {
> -    .name = TYPE_LM32_CPU,
> -    .parent = TYPE_CPU,
> -    .instance_size = sizeof(LM32CPU),
> -    .instance_init = lm32_cpu_initfn,
> -    .abstract = true,
> -    .class_size = sizeof(LM32CPUClass),
> -    .class_init = lm32_cpu_class_init,
> +static const TypeInfo lm32_cpus_type_infos[] = {
> +    { /* base class should be registered first */
> +         .name = TYPE_LM32_CPU,
> +         .parent = TYPE_CPU,
> +         .instance_size = sizeof(LM32CPU),
> +         .instance_init = lm32_cpu_initfn,
> +         .abstract = true,
> +         .class_size = sizeof(LM32CPUClass),
> +         .class_init = lm32_cpu_class_init,
> +    },
> +    DEFINE_LM32_CPU_TYPE("lm32-basic", lm32_basic_cpu_initfn),
> +    DEFINE_LM32_CPU_TYPE("lm32-standard", lm32_standard_cpu_initfn),
> +    DEFINE_LM32_CPU_TYPE("lm32-full", lm32_full_cpu_initfn),
>   };
>   
> -static void lm32_cpu_register_types(void)
> -{
> -    int i;
> -
> -    type_register_static(&lm32_cpu_type_info);
> -    for (i = 0; i < ARRAY_SIZE(lm32_cpus); i++) {
> -        lm32_register_cpu_type(&lm32_cpus[i]);
> -    }
> -}
> -
> -type_init(lm32_cpu_register_types)
> +type_init_from_array(lm32_cpus_type_infos)
> 

^ permalink raw reply	[flat|nested] 113+ messages in thread

* Re: [Qemu-devel] [PATCH 07/38] lm32: milkymist: use generic cpu_model parsing
  2017-10-02  9:07 ` [Qemu-devel] [PATCH 07/38] lm32: milkymist: use generic cpu_model parsing Igor Mammedov
@ 2017-10-02 20:28   ` Philippe Mathieu-Daudé
  2017-10-03 13:01   ` Michael Walle
  1 sibling, 0 replies; 113+ messages in thread
From: Philippe Mathieu-Daudé @ 2017-10-02 20:28 UTC (permalink / raw)
  To: Igor Mammedov, qemu-devel; +Cc: michael

On 10/02/2017 06:07 AM, Igor Mammedov wrote:
> Signed-off-by: Igor Mammedov <imammedo@redhat.com>

Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>

> ---
> CC: michael@walle.cc
> ---
>   hw/lm32/milkymist.c | 7 ++-----
>   1 file changed, 2 insertions(+), 5 deletions(-)
> 
> diff --git a/hw/lm32/milkymist.c b/hw/lm32/milkymist.c
> index 4db4d2d..d4e765f 100644
> --- a/hw/lm32/milkymist.c
> +++ b/hw/lm32/milkymist.c
> @@ -80,7 +80,6 @@ static void main_cpu_reset(void *opaque)
>   static void
>   milkymist_init(MachineState *machine)
>   {
> -    const char *cpu_model = machine->cpu_model;
>       const char *kernel_filename = machine->kernel_filename;
>       const char *kernel_cmdline = machine->kernel_cmdline;
>       const char *initrd_filename = machine->initrd_filename;
> @@ -108,10 +107,7 @@ milkymist_init(MachineState *machine)
>   
>       reset_info = g_malloc0(sizeof(ResetInfo));
>   
> -    if (cpu_model == NULL) {
> -        cpu_model = "lm32-full";
> -    }
> -    cpu = LM32_CPU(cpu_generic_init(TYPE_LM32_CPU, cpu_model));
> +    cpu = LM32_CPU(cpu_create(machine->cpu_type));
>   
>       env = &cpu->env;
>       reset_info->cpu = cpu;
> @@ -216,6 +212,7 @@ static void milkymist_machine_init(MachineClass *mc)
>       mc->desc = "Milkymist One";
>       mc->init = milkymist_init;
>       mc->is_default = 0;
> +    mc->default_cpu_type = LM32_CPU_TYPE_NAME("lm32-full");
>   }
>   
>   DEFINE_MACHINE("milkymist", milkymist_machine_init)
> 

^ permalink raw reply	[flat|nested] 113+ messages in thread

* Re: [Qemu-devel] [PATCH 08/38] lm32: lm32_boards: use generic cpu_model parsing
  2017-10-02  9:07 ` [Qemu-devel] [PATCH 08/38] lm32: lm32_boards: " Igor Mammedov
@ 2017-10-02 20:29   ` Philippe Mathieu-Daudé
  2017-10-03 13:01   ` Michael Walle
  1 sibling, 0 replies; 113+ messages in thread
From: Philippe Mathieu-Daudé @ 2017-10-02 20:29 UTC (permalink / raw)
  To: Igor Mammedov; +Cc: qemu-devel, michael

On 10/02/2017 06:07 AM, Igor Mammedov wrote:
> Signed-off-by: Igor Mammedov <imammedo@redhat.com>

Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>

> ---
> CC: michael@walle.cc
> ---
>   hw/lm32/lm32_boards.c | 14 ++++----------
>   1 file changed, 4 insertions(+), 10 deletions(-)
> 
> diff --git a/hw/lm32/lm32_boards.c b/hw/lm32/lm32_boards.c
> index b0bb3ef..002d638 100644
> --- a/hw/lm32/lm32_boards.c
> +++ b/hw/lm32/lm32_boards.c
> @@ -75,7 +75,6 @@ static void main_cpu_reset(void *opaque)
>   
>   static void lm32_evr_init(MachineState *machine)
>   {
> -    const char *cpu_model = machine->cpu_model;
>       const char *kernel_filename = machine->kernel_filename;
>       LM32CPU *cpu;
>       CPULM32State *env;
> @@ -101,10 +100,7 @@ static void lm32_evr_init(MachineState *machine)
>   
>       reset_info = g_malloc0(sizeof(ResetInfo));
>   
> -    if (cpu_model == NULL) {
> -        cpu_model = "lm32-full";
> -    }
> -    cpu = LM32_CPU(cpu_generic_init(TYPE_LM32_CPU, cpu_model));
> +    cpu = LM32_CPU(cpu_create(machine->cpu_type));
>   
>       env = &cpu->env;
>       reset_info->cpu = cpu;
> @@ -163,7 +159,6 @@ static void lm32_evr_init(MachineState *machine)
>   
>   static void lm32_uclinux_init(MachineState *machine)
>   {
> -    const char *cpu_model = machine->cpu_model;
>       const char *kernel_filename = machine->kernel_filename;
>       const char *kernel_cmdline = machine->kernel_cmdline;
>       const char *initrd_filename = machine->initrd_filename;
> @@ -198,10 +193,7 @@ static void lm32_uclinux_init(MachineState *machine)
>   
>       reset_info = g_malloc0(sizeof(ResetInfo));
>   
> -    if (cpu_model == NULL) {
> -        cpu_model = "lm32-full";
> -    }
> -    cpu = LM32_CPU(cpu_generic_init(TYPE_LM32_CPU, cpu_model));
> +    cpu = LM32_CPU(cpu_create(machine->cpu_type));
>   
>       env = &cpu->env;
>       reset_info->cpu = cpu;
> @@ -295,6 +287,7 @@ static void lm32_evr_class_init(ObjectClass *oc, void *data)
>       mc->desc = "LatticeMico32 EVR32 eval system";
>       mc->init = lm32_evr_init;
>       mc->is_default = 1;
> +    mc->default_cpu_type = LM32_CPU_TYPE_NAME("lm32-full");
>   }
>   
>   static const TypeInfo lm32_evr_type = {
> @@ -310,6 +303,7 @@ static void lm32_uclinux_class_init(ObjectClass *oc, void *data)
>       mc->desc = "lm32 platform for uClinux and u-boot by Theobroma Systems";
>       mc->init = lm32_uclinux_init;
>       mc->is_default = 0;
> +    mc->default_cpu_type = LM32_CPU_TYPE_NAME("lm32-full");
>   }
>   
>   static const TypeInfo lm32_uclinux_type = {
> 

^ permalink raw reply	[flat|nested] 113+ messages in thread

* Re: [Qemu-devel] [PATCH 27/38] tricore: cleanup cpu type name composition
  2017-10-02  9:08 ` [Qemu-devel] [PATCH 27/38] tricore: cleanup cpu type name composition Igor Mammedov
@ 2017-10-02 20:30   ` Philippe Mathieu-Daudé
  0 siblings, 0 replies; 113+ messages in thread
From: Philippe Mathieu-Daudé @ 2017-10-02 20:30 UTC (permalink / raw)
  To: Igor Mammedov; +Cc: qemu-devel, kbastian

On 10/02/2017 06:08 AM, Igor Mammedov wrote:
> introduce TRICORE_CPU_TYPE_NAME macro and use it to construct
> cpu type names. While at it move cpu type_infos into one
> array and register it directly with type_init_from_array()
> instead of custom tricore_cpu_register_types()/cpu_register()
> 
> Signed-off-by: Igor Mammedov <imammedo@redhat.com>

Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>

> ---
> CC: kbastian@mail.uni-paderborn.de
> ---
>   target/tricore/cpu.h |  2 ++
>   target/tricore/cpu.c | 68 ++++++++++++++++------------------------------------
>   2 files changed, 22 insertions(+), 48 deletions(-)
> 
> diff --git a/target/tricore/cpu.h b/target/tricore/cpu.h
> index bc53c40..f41d2ce 100644
> --- a/target/tricore/cpu.h
> +++ b/target/tricore/cpu.h
> @@ -413,6 +413,8 @@ static inline void cpu_get_tb_cpu_state(CPUTriCoreState *env, target_ulong *pc,
>   
>   #define cpu_init(cpu_model) cpu_generic_init(TYPE_TRICORE_CPU, cpu_model)
>   
> +#define TRICORE_CPU_TYPE_SUFFIX "-" TYPE_TRICORE_CPU
> +#define TRICORE_CPU_TYPE_NAME(model) model TRICORE_CPU_TYPE_SUFFIX
>   
>   /* helpers.c */
>   int cpu_tricore_handle_mmu_fault(CPUState *cpu, target_ulong address,
> diff --git a/target/tricore/cpu.c b/target/tricore/cpu.c
> index 871eb35..69d7720 100644
> --- a/target/tricore/cpu.c
> +++ b/target/tricore/cpu.c
> @@ -120,7 +120,7 @@ static ObjectClass *tricore_cpu_class_by_name(const char *cpu_model)
>       ObjectClass *oc;
>       char *typename;
>   
> -    typename = g_strdup_printf("%s-" TYPE_TRICORE_CPU, 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) ||
> @@ -151,19 +151,6 @@ static void tc27x_initfn(Object *obj)
>       set_feature(&cpu->env, TRICORE_FEATURE_161);
>   }
>   
> -typedef struct TriCoreCPUInfo {
> -    const char *name;
> -    void (*initfn)(Object *obj);
> -    void (*class_init)(ObjectClass *oc, void *data);
> -} TriCoreCPUInfo;
> -
> -static const TriCoreCPUInfo tricore_cpus[] = {
> -    { .name = "tc1796",      .initfn = tc1796_initfn },
> -    { .name = "tc1797",      .initfn = tc1797_initfn },
> -    { .name = "tc27x",       .initfn = tc27x_initfn },
> -    { .name = NULL }
> -};
> -
>   static void tricore_cpu_class_init(ObjectClass *c, void *data)
>   {
>       TriCoreCPUClass *mcc = TRICORE_CPU_CLASS(c);
> @@ -184,41 +171,26 @@ static void tricore_cpu_class_init(ObjectClass *c, void *data)
>       cc->get_phys_page_attrs_debug = tricore_cpu_get_phys_page_attrs_debug;
>   }
>   
> -static void cpu_register(const TriCoreCPUInfo *info)
> -{
> -    TypeInfo type_info = {
> -        .parent = TYPE_TRICORE_CPU,
> +#define DEFINE_TRICORE_CPU_TYPE(cpu_model, initfn) \
> +    {                                              \
> +        .parent = TYPE_TRICORE_CPU,                \
> +        .instance_init = initfn,                   \
> +        .name = TRICORE_CPU_TYPE_NAME(cpu_model),  \
> +    }
> +
> +static const TypeInfo tricore_cpu_type_infos[] = {
> +    {
> +        .name = TYPE_TRICORE_CPU,
> +        .parent = TYPE_CPU,
>           .instance_size = sizeof(TriCoreCPU),
> -        .instance_init = info->initfn,
> +        .instance_init = tricore_cpu_initfn,
> +        .abstract = true,
>           .class_size = sizeof(TriCoreCPUClass),
> -        .class_init = info->class_init,
> -    };
> -
> -    type_info.name = g_strdup_printf("%s-" TYPE_TRICORE_CPU, info->name);
> -    type_register(&type_info);
> -    g_free((void *)type_info.name);
> -}
> -
> -static const TypeInfo tricore_cpu_type_info = {
> -    .name = TYPE_TRICORE_CPU,
> -    .parent = TYPE_CPU,
> -    .instance_size = sizeof(TriCoreCPU),
> -    .instance_init = tricore_cpu_initfn,
> -    .abstract = true,
> -    .class_size = sizeof(TriCoreCPUClass),
> -    .class_init = tricore_cpu_class_init,
> +        .class_init = tricore_cpu_class_init,
> +    },
> +    DEFINE_TRICORE_CPU_TYPE("tc1796", tc1796_initfn),
> +    DEFINE_TRICORE_CPU_TYPE("tc1797", tc1797_initfn),
> +    DEFINE_TRICORE_CPU_TYPE("tc27x", tc27x_initfn),
>   };
>   
> -static void tricore_cpu_register_types(void)
> -{
> -    const TriCoreCPUInfo *info = tricore_cpus;
> -
> -    type_register_static(&tricore_cpu_type_info);
> -
> -    while (info->name) {
> -        cpu_register(info);
> -        info++;
> -    }
> -}
> -
> -type_init(tricore_cpu_register_types)
> +type_init_from_array(tricore_cpu_type_infos)
> 

^ permalink raw reply	[flat|nested] 113+ messages in thread

* Re: [Qemu-devel] [PATCH 28/38] tricore: use generic cpu_model parsing
  2017-10-02  9:08 ` [Qemu-devel] [PATCH 28/38] tricore: use generic cpu_model parsing Igor Mammedov
@ 2017-10-02 20:30   ` Philippe Mathieu-Daudé
  0 siblings, 0 replies; 113+ messages in thread
From: Philippe Mathieu-Daudé @ 2017-10-02 20:30 UTC (permalink / raw)
  To: Igor Mammedov; +Cc: qemu-devel, Bastian Koppelmann

On 10/02/2017 06:08 AM, Igor Mammedov wrote:
> Signed-off-by: Igor Mammedov <imammedo@redhat.com>

Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>

> ---
> CC: Bastian Koppelmann <kbastian@mail.uni-paderborn.de>
> ---
>   hw/tricore/tricore_testboard.c | 6 ++----
>   1 file changed, 2 insertions(+), 4 deletions(-)
> 
> diff --git a/hw/tricore/tricore_testboard.c b/hw/tricore/tricore_testboard.c
> index 0486f8a..ac75eb2 100644
> --- a/hw/tricore/tricore_testboard.c
> +++ b/hw/tricore/tricore_testboard.c
> @@ -71,10 +71,7 @@ static void tricore_testboard_init(MachineState *machine, int board_id)
>       MemoryRegion *pcp_data = g_new(MemoryRegion, 1);
>       MemoryRegion *pcp_text = g_new(MemoryRegion, 1);
>   
> -    if (!machine->cpu_model) {
> -        machine->cpu_model = "tc1796";
> -    }
> -    cpu = TRICORE_CPU(cpu_generic_init(TYPE_TRICORE_CPU, machine->cpu_model));
> +    cpu = TRICORE_CPU(cpu_create(machine->cpu_type));
>       env = &cpu->env;
>       memory_region_init_ram(ext_cram, NULL, "powerlink_ext_c.ram",
>                              2 * 1024 * 1024, &error_fatal);
> @@ -114,6 +111,7 @@ static void ttb_machine_init(MachineClass *mc)
>       mc->desc = "a minimal TriCore board";
>       mc->init = tricoreboard_init;
>       mc->is_default = 0;
> +    mc->default_cpu_type = TRICORE_CPU_TYPE_NAME("tc1796");
>   }
>   
>   DEFINE_MACHINE("tricore_testboard", ttb_machine_init)
> 

^ permalink raw reply	[flat|nested] 113+ messages in thread

* Re: [Qemu-devel] [PATCH 22/38] xtensa: cleanup cpu type name composition
  2017-10-02  9:08 ` [Qemu-devel] [PATCH 22/38] xtensa: cleanup cpu type name composition Igor Mammedov
@ 2017-10-02 20:35   ` Philippe Mathieu-Daudé
  2017-10-03 10:37     ` Igor Mammedov
  0 siblings, 1 reply; 113+ messages in thread
From: Philippe Mathieu-Daudé @ 2017-10-02 20:35 UTC (permalink / raw)
  To: Igor Mammedov; +Cc: qemu-devel, jcmvbkbc

On 10/02/2017 06:08 AM, Igor Mammedov wrote:
> use new XTENSA_CPU_TYPE_NAME to compose CPU type name
> to bring xtensa in line with all other targets that
> will similar macro.
> 
> Signed-off-by: Igor Mammedov <imammedo@redhat.com>
> ---
> CC: jcmvbkbc@gmail.com
> ---
>   target/xtensa/cpu.h    | 4 ++++
>   target/xtensa/cpu.c    | 2 +-
>   target/xtensa/helper.c | 2 +-
>   3 files changed, 6 insertions(+), 2 deletions(-)
> 
> diff --git a/target/xtensa/cpu.h b/target/xtensa/cpu.h
> index 4803331..b17d7d9 100644
> --- a/target/xtensa/cpu.h
> +++ b/target/xtensa/cpu.h
> @@ -469,11 +469,15 @@ void xtensa_cpu_do_unaligned_access(CPUState *cpu, vaddr addr,
>   #define cpu_signal_handler cpu_xtensa_signal_handler
>   #define cpu_list xtensa_cpu_list
>   
> +#define XTENSA_CPU_TYPE_SUFFIX "-" TYPE_XTENSA_CPU
> +#define XTENSA_CPU_TYPE_NAME(model) model XTENSA_CPU_TYPE_SUFFIX
> +
>   #ifdef TARGET_WORDS_BIGENDIAN
>   #define XTENSA_DEFAULT_CPU_MODEL "fsf"
>   #else
>   #define XTENSA_DEFAULT_CPU_MODEL "dc232b"
>   #endif
> +#define XTENSA_DEFAULT_CPU_TYPE XTENSA_CPU_TYPE_NAME(XTENSA_DEFAULT_CPU_MODEL)

I see XTENSA_DEFAULT_CPU_MODEL is used in mc->desc, any idea to be able 
to use this instead?

#ifdef TARGET_WORDS_BIGENDIAN
# define XTENSA_DEFAULT_CPU_TYPE XTENSA_CPU_TYPE_NAME("fsf")
#else
# define XTENSA_DEFAULT_CPU_TYPE XTENSA_CPU_TYPE_NAME("dc232b")
#endif

>   
>   #define cpu_init(cpu_model) cpu_generic_init(TYPE_XTENSA_CPU, cpu_model)
>   
> diff --git a/target/xtensa/cpu.c b/target/xtensa/cpu.c
> index dcdc765..b5f7079 100644
> --- a/target/xtensa/cpu.c
> +++ b/target/xtensa/cpu.c
> @@ -83,7 +83,7 @@ static ObjectClass *xtensa_cpu_class_by_name(const char *cpu_model)
>       ObjectClass *oc;
>       char *typename;
>   
> -    typename = g_strdup_printf("%s-" TYPE_XTENSA_CPU, 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) ||
> diff --git a/target/xtensa/helper.c b/target/xtensa/helper.c
> index e8fba20..216f198 100644
> --- a/target/xtensa/helper.c
> +++ b/target/xtensa/helper.c
> @@ -76,7 +76,7 @@ void xtensa_register_core(XtensaConfigList *node)
>   
>       node->next = xtensa_cores;
>       xtensa_cores = node;
> -    type.name = g_strdup_printf("%s-" TYPE_XTENSA_CPU, node->config->name);
> +    type.name = g_strdup_printf(XTENSA_CPU_TYPE_NAME("%s"), node->config->name);
>       type_register(&type);
>       g_free((gpointer)type.name);
>   }
> 

^ permalink raw reply	[flat|nested] 113+ messages in thread

* Re: [Qemu-devel] [PATCH 36/38] mips: Magnum/Acer Pica 61: replace cpu_model with cpu_type
  2017-10-02  9:08 ` [Qemu-devel] [PATCH 36/38] mips: Magnum/Acer Pica 61: " Igor Mammedov
  2017-10-02 14:11   ` Philippe Mathieu-Daudé
@ 2017-10-03  4:59   ` Hervé Poussineau
  1 sibling, 0 replies; 113+ messages in thread
From: Hervé Poussineau @ 2017-10-03  4:59 UTC (permalink / raw)
  To: Igor Mammedov, qemu-devel
  Cc: Philippe Mathieu-Daudé, aurelien, yongbok.kim

Le 02/10/2017 à 11:08, Igor Mammedov a écrit :
> Signed-off-by: Igor Mammedov <imammedo@redhat.com>
> ---
> CC: hpoussin@reactos.org
> CC: aurelien@aurel32.net
> CC: yongbok.kim@imgtec.com
> ---
>   hw/mips/mips_jazz.c | 8 +++-----
>   1 file changed, 3 insertions(+), 5 deletions(-)
>

Reviewed-by: Hervé Poussineau <hpoussin@reactos.org>

^ permalink raw reply	[flat|nested] 113+ messages in thread

* Re: [Qemu-devel] [PATCH 10/38] m68k: an5206: use generic cpu_model parsing
  2017-10-02  9:07 ` [Qemu-devel] [PATCH 10/38] m68k: an5206: use generic cpu_model parsing Igor Mammedov
@ 2017-10-03  9:13   ` Thomas Huth
  2017-10-03 13:31   ` Philippe Mathieu-Daudé
  2017-10-03 14:51   ` Laurent Vivier
  2 siblings, 0 replies; 113+ messages in thread
From: Thomas Huth @ 2017-10-03  9:13 UTC (permalink / raw)
  To: Igor Mammedov, qemu-devel; +Cc: Philippe Mathieu-Daudé, laurent

On 02.10.2017 11:07, Igor Mammedov wrote:
> Signed-off-by: Igor Mammedov <imammedo@redhat.com>
> ---
> CC: huth@tuxfamily.org
> CC: laurent@vivier.eu
> ---
>  hw/m68k/an5206.c | 7 ++-----
>  1 file changed, 2 insertions(+), 5 deletions(-)
> 
> diff --git a/hw/m68k/an5206.c b/hw/m68k/an5206.c
> index 9002c46..0cedc54 100644
> --- a/hw/m68k/an5206.c
> +++ b/hw/m68k/an5206.c
> @@ -28,7 +28,6 @@
>  static void an5206_init(MachineState *machine)
>  {
>      ram_addr_t ram_size = machine->ram_size;
> -    const char *cpu_model = machine->cpu_model;
>      const char *kernel_filename = machine->kernel_filename;
>      M68kCPU *cpu;
>      CPUM68KState *env;
> @@ -39,10 +38,7 @@ static void an5206_init(MachineState *machine)
>      MemoryRegion *ram = g_new(MemoryRegion, 1);
>      MemoryRegion *sram = g_new(MemoryRegion, 1);
>  
> -    if (!cpu_model) {
> -        cpu_model = "m5206";
> -    }
> -    cpu = M68K_CPU(cpu_generic_init(TYPE_M68K_CPU, cpu_model));
> +    cpu = M68K_CPU(cpu_create(machine->cpu_type));
>      env = &cpu->env;
>  
>      /* Initialize CPU registers.  */
> @@ -94,6 +90,7 @@ static void an5206_machine_init(MachineClass *mc)
>  {
>      mc->desc = "Arnewsh 5206";
>      mc->init = an5206_init;
> +    mc->default_cpu_type = M68K_CPU_TYPE_NAME("m5206");
>  }
>  
>  DEFINE_MACHINE("an5206", an5206_machine_init)
> 

Acked-by: Thomas Huth <huth@tuxfamily.org>

^ permalink raw reply	[flat|nested] 113+ messages in thread

* Re: [Qemu-devel] [PATCH 11/38] m68k: mcf5208: use generic cpu_model parsing
  2017-10-02  9:07 ` [Qemu-devel] [PATCH 11/38] m68k: mcf5208: " Igor Mammedov
@ 2017-10-03  9:28   ` Thomas Huth
  2017-10-03 13:32   ` Philippe Mathieu-Daudé
  2017-10-03 14:52   ` Laurent Vivier
  2 siblings, 0 replies; 113+ messages in thread
From: Thomas Huth @ 2017-10-03  9:28 UTC (permalink / raw)
  To: Igor Mammedov, qemu-devel; +Cc: Philippe Mathieu-Daudé, laurent

On 02.10.2017 11:07, Igor Mammedov wrote:
> Signed-off-by: Igor Mammedov <imammedo@redhat.com>
> ---
> CC: laurent@vivier.eu
> CC: huth@tuxfamily.org
> ---
>  hw/m68k/mcf5208.c | 7 ++-----
>  1 file changed, 2 insertions(+), 5 deletions(-)
> 
> diff --git a/hw/m68k/mcf5208.c b/hw/m68k/mcf5208.c
> index b9dde75..cfac845 100644
> --- a/hw/m68k/mcf5208.c
> +++ b/hw/m68k/mcf5208.c
> @@ -217,7 +217,6 @@ static void mcf_fec_init(MemoryRegion *sysmem, NICInfo *nd, hwaddr base,
>  static void mcf5208evb_init(MachineState *machine)
>  {
>      ram_addr_t ram_size = machine->ram_size;
> -    const char *cpu_model = machine->cpu_model;
>      const char *kernel_filename = machine->kernel_filename;
>      M68kCPU *cpu;
>      CPUM68KState *env;
> @@ -229,10 +228,7 @@ static void mcf5208evb_init(MachineState *machine)
>      MemoryRegion *ram = g_new(MemoryRegion, 1);
>      MemoryRegion *sram = g_new(MemoryRegion, 1);
>  
> -    if (!cpu_model) {
> -        cpu_model = "m5208";
> -    }
> -    cpu = M68K_CPU(cpu_generic_init(TYPE_M68K_CPU, cpu_model));
> +    cpu = M68K_CPU(cpu_create(machine->cpu_type));
>      env = &cpu->env;
>  
>      /* Initialize CPU registers.  */
> @@ -321,6 +317,7 @@ static void mcf5208evb_machine_init(MachineClass *mc)
>      mc->desc = "MCF5206EVB";
>      mc->init = mcf5208evb_init;
>      mc->is_default = 1;
> +    mc->default_cpu_type = M68K_CPU_TYPE_NAME("m5208");
>  }
>  
>  DEFINE_MACHINE("mcf5208evb", mcf5208evb_machine_init)
> 

Acked-by: Thomas Huth <huth@tuxfamily.org>

^ permalink raw reply	[flat|nested] 113+ messages in thread

* Re: [Qemu-devel] [PATCH 22/38] xtensa: cleanup cpu type name composition
  2017-10-02 20:35   ` Philippe Mathieu-Daudé
@ 2017-10-03 10:37     ` Igor Mammedov
  2017-10-03 13:33       ` Philippe Mathieu-Daudé
  0 siblings, 1 reply; 113+ messages in thread
From: Igor Mammedov @ 2017-10-03 10:37 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé; +Cc: qemu-devel, jcmvbkbc

On Mon, 2 Oct 2017 17:35:39 -0300
Philippe Mathieu-Daudé <f4bug@amsat.org> wrote:

> On 10/02/2017 06:08 AM, Igor Mammedov wrote:
> > use new XTENSA_CPU_TYPE_NAME to compose CPU type name
> > to bring xtensa in line with all other targets that
> > will similar macro.
> > 
> > Signed-off-by: Igor Mammedov <imammedo@redhat.com>
> > ---
> > CC: jcmvbkbc@gmail.com
> > ---
> >   target/xtensa/cpu.h    | 4 ++++
> >   target/xtensa/cpu.c    | 2 +-
> >   target/xtensa/helper.c | 2 +-
> >   3 files changed, 6 insertions(+), 2 deletions(-)
> > 
> > diff --git a/target/xtensa/cpu.h b/target/xtensa/cpu.h
> > index 4803331..b17d7d9 100644
> > --- a/target/xtensa/cpu.h
> > +++ b/target/xtensa/cpu.h
> > @@ -469,11 +469,15 @@ void xtensa_cpu_do_unaligned_access(CPUState *cpu, vaddr addr,
> >   #define cpu_signal_handler cpu_xtensa_signal_handler
> >   #define cpu_list xtensa_cpu_list
> >   
> > +#define XTENSA_CPU_TYPE_SUFFIX "-" TYPE_XTENSA_CPU
> > +#define XTENSA_CPU_TYPE_NAME(model) model XTENSA_CPU_TYPE_SUFFIX
> > +
> >   #ifdef TARGET_WORDS_BIGENDIAN
> >   #define XTENSA_DEFAULT_CPU_MODEL "fsf"
> >   #else
> >   #define XTENSA_DEFAULT_CPU_MODEL "dc232b"
> >   #endif
> > +#define XTENSA_DEFAULT_CPU_TYPE XTENSA_CPU_TYPE_NAME(XTENSA_DEFAULT_CPU_MODEL)  
> 
> I see XTENSA_DEFAULT_CPU_MODEL is used in mc->desc, any idea to be able 
> to use this instead?
mc-desc is the reason why I've left XTENSA_DEFAULT_CPU_MODEL as is, and
having that there were no point in adding yet another ifdef for type,
XTENSA_DEFAULT_CPU_MODEL works just fine here.

> 
> #ifdef TARGET_WORDS_BIGENDIAN
> # define XTENSA_DEFAULT_CPU_TYPE XTENSA_CPU_TYPE_NAME("fsf")
> #else
> # define XTENSA_DEFAULT_CPU_TYPE XTENSA_CPU_TYPE_NAME("dc232b")
> #endif
> 
> >   
> >   #define cpu_init(cpu_model) cpu_generic_init(TYPE_XTENSA_CPU, cpu_model)
> >   
> > diff --git a/target/xtensa/cpu.c b/target/xtensa/cpu.c
> > index dcdc765..b5f7079 100644
> > --- a/target/xtensa/cpu.c
> > +++ b/target/xtensa/cpu.c
> > @@ -83,7 +83,7 @@ static ObjectClass *xtensa_cpu_class_by_name(const char *cpu_model)
> >       ObjectClass *oc;
> >       char *typename;
> >   
> > -    typename = g_strdup_printf("%s-" TYPE_XTENSA_CPU, 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) ||
> > diff --git a/target/xtensa/helper.c b/target/xtensa/helper.c
> > index e8fba20..216f198 100644
> > --- a/target/xtensa/helper.c
> > +++ b/target/xtensa/helper.c
> > @@ -76,7 +76,7 @@ void xtensa_register_core(XtensaConfigList *node)
> >   
> >       node->next = xtensa_cores;
> >       xtensa_cores = node;
> > -    type.name = g_strdup_printf("%s-" TYPE_XTENSA_CPU, node->config->name);
> > +    type.name = g_strdup_printf(XTENSA_CPU_TYPE_NAME("%s"), node->config->name);
> >       type_register(&type);
> >       g_free((gpointer)type.name);
> >   }
> >   

^ permalink raw reply	[flat|nested] 113+ messages in thread

* Re: [Qemu-devel] [PATCH 01/38] qom: add helper type_init_from_array()
  2017-10-02 19:24   ` Eduardo Habkost
@ 2017-10-03 12:13     ` Igor Mammedov
  2017-10-03 12:14     ` [Qemu-devel] [PATCH] qom: add helpers REGISTER_STATIC_TYPE[S]() Igor Mammedov
  1 sibling, 0 replies; 113+ messages in thread
From: Igor Mammedov @ 2017-10-03 12:13 UTC (permalink / raw)
  To: Eduardo Habkost; +Cc: qemu-devel, Philippe Mathieu-Daudé

On Mon, 2 Oct 2017 16:24:04 -0300
Eduardo Habkost <ehabkost@redhat.com> wrote:

> On Mon, Oct 02, 2017 at 11:07:43AM +0200, Igor Mammedov wrote:
> > it will help to remove code duplication in places
> > that currently open code registration of several
> > types.
> > 
> > Signed-off-by: Igor Mammedov <imammedo@redhat.com>
> > ---
> > I'm going to use it for CPU types in followup patches
> > 
> > CC: ehabkost@redhat.com
> > ---
> >  include/qemu/module.h | 10 ++++++++++
> >  1 file changed, 10 insertions(+)
> > 
> > diff --git a/include/qemu/module.h b/include/qemu/module.h
> > index 56dd218..29f9089 100644
> > --- a/include/qemu/module.h
> > +++ b/include/qemu/module.h
> > @@ -52,6 +52,16 @@ typedef enum {
> >  #define type_init(function) module_init(function, MODULE_INIT_QOM)
> >  #define trace_init(function) module_init(function, MODULE_INIT_TRACE)
> >  
> > +#define type_init_from_array(array)                                        \  
> 
> So we're moving from a imperative way to register types to a
> declarative way.  Sounds nice.
> 
> You are also adding a way to register a TypeInfo array easily.
> That's nice, too.
> 
> But, why do we need to address both at the same time?  I think
> this adds some confusing gaps to the module/QOM APIs:
> 
> * If you want to register a type at runtime, there are only
>   functions to register a single type (type_register(),
>   type_register_static().  What if I want to register a TypeInfo
>   array from an existing type_init() function?
> * If you want to declare types to be registered automatically at
>   module_call_init(MODULE_INIT_QOM), you are adding a helper that
>   avoids manual type_register*() calls, but only for arrays.
>   What if I want to register a single type?  (There are 440+
>   functions containing a single type_register*() call in the
>   tree)
just array is sufficient for code touched in this series.
I'll add helper for single type as well, but I'd leave for someone
else to use it (i.e. do cleanup).

> I have two suggestions:
> 
> * Adding a type_register_static_array() helper first, call it
>   from a type_init() function, and think about a module.h-based
>   helper for arrays later.
> 
> * (For later) adding a module_init() helper that works for
>   registering a single type too. So, this very common pattern:
> 
>       static const TypeInfo FOO_type = {
>           /* ... */
>       };
>       
>       static void register_FOO_type(void)
>       {
>           type_register_static(&FOO_type);
>       }
>       
>       QOM_TYPE(register_FOO_type);
> 
>   could be written as:
> 
>       static const TypeInfo FOO_type = {
>           /* ... */
>       };
>       
>       QOM_TYPE(FOO_type);
> 
> (I'm suggesting QOM_TYPE as the macro name, but I'm not sure
> about it.  But I think type_init_*() is confusing because it
> doesn't work like the other *_init() helpers in module.h)
> 
> QOM_TYPE(T) could be just a shortcut to:
> QOM_TYPES_PTR(&T, 1).
QOM here seems redundant, how about
REGISTER_STATIC_TYPE/REGISTER_STATIC_TYPES

> 
> Your type_init_from_array(A) helper could be just a shortcut to:
> QOM_TYPES_PTR(A, ARRAY_SIZE(A)).
> 
> > +static void do_qemu_init_ ## array(void)                                   \
> > +{                                                                          \
> > +    int i;                                                                 \
> > +    for (i = 0; i < ARRAY_SIZE(array); i++) {                              \
> > +        type_register_static(&array[i]);                                   \  
> 
> type_register_static() is in qom/object.[ch], and module.[ch] has
> no dependency on QOM at all.  I believe this belongs in
> qom/object.h, not module.h.
ok

> 
> > +    }                                                                      \
> > +}                                                                          \
> > +module_init(do_qemu_init_ ## array, MODULE_INIT_QOM)  
> 
> Why not use type_init(do_qemu_init_ ## array)?
I'll will use it in v2

> 
> > +  
> 
> Also for later: this is not the first time we generate function
> bodies on the fly for module_init().  Maybe module_init could
> support a void* data argument?
> 
> >  #define block_module_load_one(lib) module_load_one("block-", lib)
> >  
> >  void register_module_init(void (*fn)(void), module_init_type type);
> > -- 
> > 2.7.4
> >   
> 

^ permalink raw reply	[flat|nested] 113+ messages in thread

* [Qemu-devel] [PATCH] qom: add helpers REGISTER_STATIC_TYPE[S]()
  2017-10-02 19:24   ` Eduardo Habkost
  2017-10-03 12:13     ` Igor Mammedov
@ 2017-10-03 12:14     ` Igor Mammedov
  2017-10-03 13:29       ` Philippe Mathieu-Daudé
                         ` (2 more replies)
  1 sibling, 3 replies; 113+ messages in thread
From: Igor Mammedov @ 2017-10-03 12:14 UTC (permalink / raw)
  To: qemu-devel; +Cc: ehabkost

it will help to remove code duplication in places
that currently open code registration of static
type[s] and remove necessity to declare function
for type_init() to call, when only static types
need to be registered.

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
---
I'm going to use it for CPU types in followup patches

CC: ehabkost@redhat.com
---
 include/qemu/module.h | 10 ++++++++++
 include/qom/object.h  | 10 ++++++++++
 qom/object.c          |  9 +++++++++
 3 files changed, 29 insertions(+)

diff --git a/include/qemu/module.h b/include/qemu/module.h
index 56dd218..60dd632 100644
--- a/include/qemu/module.h
+++ b/include/qemu/module.h
@@ -52,6 +52,16 @@ typedef enum {
 #define type_init(function) module_init(function, MODULE_INIT_QOM)
 #define trace_init(function) module_init(function, MODULE_INIT_TRACE)
 
+#define REGISTER_STATIC_TYPES(t, nr)                                        \
+static void do_qemu_init_ ## t(void)                                        \
+{                                                                           \
+    type_register_static_array(t, nr);                                      \
+}                                                                           \
+type_init(do_qemu_init_ ## t)
+
+#define REGISTER_STATIC_TYPE(t)                                             \
+    REGISTER_STATIC_TYPES(t, 1)
+
 #define block_module_load_one(lib) module_load_one("block-", lib)
 
 void register_module_init(void (*fn)(void), module_init_type type);
diff --git a/include/qom/object.h b/include/qom/object.h
index f3e5cff..17fcadd 100644
--- a/include/qom/object.h
+++ b/include/qom/object.h
@@ -789,6 +789,16 @@ Type type_register_static(const TypeInfo *info);
 Type type_register(const TypeInfo *info);
 
 /**
+ * type_register_static_array:
+ * @infos: The array of the new type #TypeInfo structures.
+ * @nr_infos: number of entries in @infos
+ *
+ * @infos and all of the strings it points to should exist for the life time
+ * that the type is registered.
+ */
+void type_register_static_array(const TypeInfo *infos, int nr_infos);
+
+/**
  * object_class_dynamic_cast_assert:
  * @klass: The #ObjectClass to attempt to cast.
  * @typename: The QOM typename of the class to cast to.
diff --git a/qom/object.c b/qom/object.c
index 3e18537..40b1729 100644
--- a/qom/object.c
+++ b/qom/object.c
@@ -151,6 +151,15 @@ TypeImpl *type_register_static(const TypeInfo *info)
     return type_register(info);
 }
 
+void type_register_static_array(const TypeInfo *infos, int nr_infos)
+{
+    int i;
+
+    for (i = 0; i < nr_infos; i++) {
+        assert(type_register_static(&infos[i]));
+    }
+}
+
 static TypeImpl *type_get_by_name(const char *name)
 {
     if (name == NULL) {
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 113+ messages in thread

* Re: [Qemu-devel] [PATCH 06/38] lm32: cleanup cpu type name composition
  2017-10-02  9:07 ` [Qemu-devel] [PATCH 06/38] lm32: cleanup cpu type name composition Igor Mammedov
  2017-10-02 20:28   ` Philippe Mathieu-Daudé
@ 2017-10-03 13:00   ` Michael Walle
  1 sibling, 0 replies; 113+ messages in thread
From: Michael Walle @ 2017-10-03 13:00 UTC (permalink / raw)
  To: Igor Mammedov; +Cc: qemu-devel, Philippe Mathieu-Daudé

Am 2017-10-02 11:07, schrieb Igor Mammedov:
> introduce LM32_CPU_TYPE_NAME macro and consistently use it
> to construct cpu type names. While at it replace dynamic
> cpu type name composition with static data.
> 
> Signed-off-by: Igor Mammedov <imammedo@redhat.com>
> ---
> CC: michael@walle.cc
> ---
>  target/lm32/cpu.h |  3 +++
>  target/lm32/cpu.c | 74 
> +++++++++++++++++--------------------------------------
>  2 files changed, 25 insertions(+), 52 deletions(-)
> 

Acked-by: Michael Walle <michael@walle.cc>

^ permalink raw reply	[flat|nested] 113+ messages in thread

* Re: [Qemu-devel] [PATCH 07/38] lm32: milkymist: use generic cpu_model parsing
  2017-10-02  9:07 ` [Qemu-devel] [PATCH 07/38] lm32: milkymist: use generic cpu_model parsing Igor Mammedov
  2017-10-02 20:28   ` Philippe Mathieu-Daudé
@ 2017-10-03 13:01   ` Michael Walle
  1 sibling, 0 replies; 113+ messages in thread
From: Michael Walle @ 2017-10-03 13:01 UTC (permalink / raw)
  To: Igor Mammedov; +Cc: qemu-devel, Philippe Mathieu-Daudé

Am 2017-10-02 11:07, schrieb Igor Mammedov:
> Signed-off-by: Igor Mammedov <imammedo@redhat.com>
> ---
> CC: michael@walle.cc
> ---
>  hw/lm32/milkymist.c | 7 ++-----
>  1 file changed, 2 insertions(+), 5 deletions(-)
> 

Acked-by: Michael Walle <michael@walle.cc>

^ permalink raw reply	[flat|nested] 113+ messages in thread

* Re: [Qemu-devel] [PATCH 08/38] lm32: lm32_boards: use generic cpu_model parsing
  2017-10-02  9:07 ` [Qemu-devel] [PATCH 08/38] lm32: lm32_boards: " Igor Mammedov
  2017-10-02 20:29   ` Philippe Mathieu-Daudé
@ 2017-10-03 13:01   ` Michael Walle
  1 sibling, 0 replies; 113+ messages in thread
From: Michael Walle @ 2017-10-03 13:01 UTC (permalink / raw)
  To: Igor Mammedov; +Cc: qemu-devel, Philippe Mathieu-Daudé

Am 2017-10-02 11:07, schrieb Igor Mammedov:
> Signed-off-by: Igor Mammedov <imammedo@redhat.com>
> ---
> CC: michael@walle.cc
> ---
>  hw/lm32/lm32_boards.c | 14 ++++----------
>  1 file changed, 4 insertions(+), 10 deletions(-)
> 

Acked-by: Michael Walle <michael@walle.cc>

^ permalink raw reply	[flat|nested] 113+ messages in thread

* Re: [Qemu-devel] [PATCH] qom: add helpers REGISTER_STATIC_TYPE[S]()
  2017-10-03 12:14     ` [Qemu-devel] [PATCH] qom: add helpers REGISTER_STATIC_TYPE[S]() Igor Mammedov
@ 2017-10-03 13:29       ` Philippe Mathieu-Daudé
  2017-10-03 15:38         ` Igor Mammedov
  2017-10-03 14:25       ` Eduardo Habkost
  2017-10-03 15:44       ` Peter Maydell
  2 siblings, 1 reply; 113+ messages in thread
From: Philippe Mathieu-Daudé @ 2017-10-03 13:29 UTC (permalink / raw)
  To: Igor Mammedov, ehabkost; +Cc: qemu-devel

Hi Igor,

On 10/03/2017 09:14 AM, Igor Mammedov wrote:
> it will help to remove code duplication in places
> that currently open code registration of static
> type[s] and remove necessity to declare function
> for type_init() to call, when only static types
> need to be registered.
> 
> Signed-off-by: Igor Mammedov <imammedo@redhat.com>
> ---
> I'm going to use it for CPU types in followup patches
> 
> CC: ehabkost@redhat.com
> ---
>  include/qemu/module.h | 10 ++++++++++
>  include/qom/object.h  | 10 ++++++++++
>  qom/object.c          |  9 +++++++++
>  3 files changed, 29 insertions(+)
> 
> diff --git a/include/qemu/module.h b/include/qemu/module.h
> index 56dd218..60dd632 100644
> --- a/include/qemu/module.h
> +++ b/include/qemu/module.h
> @@ -52,6 +52,16 @@ typedef enum {
>  #define type_init(function) module_init(function, MODULE_INIT_QOM)
>  #define trace_init(function) module_init(function, MODULE_INIT_TRACE)
>  
> +#define REGISTER_STATIC_TYPES(t, nr)                                        \

ok

> +static void do_qemu_init_ ## t(void)                                        \
> +{                                                                           \
> +    type_register_static_array(t, nr);                                      \
> +}                                                                           \
> +type_init(do_qemu_init_ ## t)
> +
> +#define REGISTER_STATIC_TYPE(t)                                             \

eh why not...

What's your plan for your "generalize parsing of cpu_model (2)" series?
re-post the whole? If you just change this macro you can keep my R-b for it.

> +    REGISTER_STATIC_TYPES(t, 1)
> +
>  #define block_module_load_one(lib) module_load_one("block-", lib)
>  
>  void register_module_init(void (*fn)(void), module_init_type type);
> diff --git a/include/qom/object.h b/include/qom/object.h
> index f3e5cff..17fcadd 100644
> --- a/include/qom/object.h
> +++ b/include/qom/object.h
> @@ -789,6 +789,16 @@ Type type_register_static(const TypeInfo *info);
>  Type type_register(const TypeInfo *info);
>  
>  /**
> + * type_register_static_array:
> + * @infos: The array of the new type #TypeInfo structures.
> + * @nr_infos: number of entries in @infos
> + *
> + * @infos and all of the strings it points to should exist for the life time
> + * that the type is registered.
> + */
> +void type_register_static_array(const TypeInfo *infos, int nr_infos);
> +
> +/**
>   * object_class_dynamic_cast_assert:
>   * @klass: The #ObjectClass to attempt to cast.
>   * @typename: The QOM typename of the class to cast to.
> diff --git a/qom/object.c b/qom/object.c
> index 3e18537..40b1729 100644
> --- a/qom/object.c
> +++ b/qom/object.c
> @@ -151,6 +151,15 @@ TypeImpl *type_register_static(const TypeInfo *info)
>      return type_register(info);
>  }
>  
> +void type_register_static_array(const TypeInfo *infos, int nr_infos)
> +{
> +    int i;
> +
> +    for (i = 0; i < nr_infos; i++) {
> +        assert(type_register_static(&infos[i]));
> +    }
> +}

Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>

> +
>  static TypeImpl *type_get_by_name(const char *name)
>  {
>      if (name == NULL) {
> 

^ permalink raw reply	[flat|nested] 113+ messages in thread

* Re: [Qemu-devel] [PATCH 09/38] m68k: cleanup cpu type name composition
  2017-10-02  9:07 ` [Qemu-devel] [PATCH 09/38] m68k: cleanup cpu type name composition Igor Mammedov
@ 2017-10-03 13:31   ` Philippe Mathieu-Daudé
  2017-10-03 14:50   ` Laurent Vivier
  1 sibling, 0 replies; 113+ messages in thread
From: Philippe Mathieu-Daudé @ 2017-10-03 13:31 UTC (permalink / raw)
  To: Igor Mammedov, laurent; +Cc: qemu-devel

On 10/02/2017 06:07 AM, Igor Mammedov wrote:
> use new M68K_CPU_TYPE_NAME to compose CPU type names
> and get rid of intermediate M68kCPUInfo/register_cpu_type()
> which is replaced by static TypeInfo array.
> 
> Signed-off-by: Igor Mammedov <imammedo@redhat.com>

Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>

> ---
> CC: laurent@vivier.eu
> ---
>  target/m68k/cpu.h |  3 +++
>  target/m68k/cpu.c | 75 ++++++++++++++++++++-----------------------------------
>  2 files changed, 30 insertions(+), 48 deletions(-)
> 
> diff --git a/target/m68k/cpu.h b/target/m68k/cpu.h
> index d936547..afae5f6 100644
> --- a/target/m68k/cpu.h
> +++ b/target/m68k/cpu.h
> @@ -323,6 +323,9 @@ void register_m68k_insns (CPUM68KState *env);
>  
>  #define cpu_init(cpu_model) cpu_generic_init(TYPE_M68K_CPU, cpu_model)
>  
> +#define M68K_CPU_TYPE_SUFFIX "-" TYPE_M68K_CPU
> +#define M68K_CPU_TYPE_NAME(model) model M68K_CPU_TYPE_SUFFIX
> +
>  #define cpu_signal_handler cpu_m68k_signal_handler
>  #define cpu_list m68k_cpu_list
>  
> diff --git a/target/m68k/cpu.c b/target/m68k/cpu.c
> index 8c70e08..f0f90e9 100644
> --- a/target/m68k/cpu.c
> +++ b/target/m68k/cpu.c
> @@ -87,7 +87,7 @@ static ObjectClass *m68k_cpu_class_by_name(const char *cpu_model)
>      ObjectClass *oc;
>      char *typename;
>  
> -    typename = g_strdup_printf("%s-" TYPE_M68K_CPU, cpu_model);
> +    typename = g_strdup_printf(M68K_CPU_TYPE_NAME("%s"), cpu_model);
>      oc = object_class_by_name(typename);
>      g_free(typename);
>      if (oc != NULL && (object_class_dynamic_cast(oc, TYPE_M68K_CPU) == NULL ||
> @@ -202,23 +202,6 @@ static void any_cpu_initfn(Object *obj)
>      m68k_set_feature(env, M68K_FEATURE_WORD_INDEX);
>  }
>  
> -typedef struct M68kCPUInfo {
> -    const char *name;
> -    void (*instance_init)(Object *obj);
> -} M68kCPUInfo;
> -
> -static const M68kCPUInfo m68k_cpus[] = {
> -    { .name = "m68000", .instance_init = m68000_cpu_initfn },
> -    { .name = "m68020", .instance_init = m68020_cpu_initfn },
> -    { .name = "m68030", .instance_init = m68030_cpu_initfn },
> -    { .name = "m68040", .instance_init = m68040_cpu_initfn },
> -    { .name = "m68060", .instance_init = m68060_cpu_initfn },
> -    { .name = "m5206", .instance_init = m5206_cpu_initfn },
> -    { .name = "m5208", .instance_init = m5208_cpu_initfn },
> -    { .name = "cfv4e", .instance_init = cfv4e_cpu_initfn },
> -    { .name = "any",   .instance_init = any_cpu_initfn },
> -};
> -
>  static void m68k_cpu_realizefn(DeviceState *dev, Error **errp)
>  {
>      CPUState *cs = CPU(dev);
> @@ -295,36 +278,32 @@ static void m68k_cpu_class_init(ObjectClass *c, void *data)
>      dc->vmsd = &vmstate_m68k_cpu;
>  }
>  
> -static void register_cpu_type(const M68kCPUInfo *info)
> -{
> -    TypeInfo type_info = {
> -        .parent = TYPE_M68K_CPU,
> -        .instance_init = info->instance_init,
> -    };
> -
> -    type_info.name = g_strdup_printf("%s-" TYPE_M68K_CPU, info->name);
> -    type_register(&type_info);
> -    g_free((void *)type_info.name);
> -}
> +#define DEFINE_M68K_CPU_TYPE(cpu_model, initfn) \
> +    {                                           \
> +        .name = M68K_CPU_TYPE_NAME(cpu_model),  \
> +        .instance_init = initfn,                \
> +        .parent = TYPE_M68K_CPU,                \
> +    }
>  
> -static const TypeInfo m68k_cpu_type_info = {
> -    .name = TYPE_M68K_CPU,
> -    .parent = TYPE_CPU,
> -    .instance_size = sizeof(M68kCPU),
> -    .instance_init = m68k_cpu_initfn,
> -    .abstract = true,
> -    .class_size = sizeof(M68kCPUClass),
> -    .class_init = m68k_cpu_class_init,
> +static const TypeInfo m68k_cpus_type_infos[] = {
> +    { /* base class should be registered first */
> +        .name = TYPE_M68K_CPU,
> +        .parent = TYPE_CPU,
> +        .instance_size = sizeof(M68kCPU),
> +        .instance_init = m68k_cpu_initfn,
> +        .abstract = true,
> +        .class_size = sizeof(M68kCPUClass),
> +        .class_init = m68k_cpu_class_init,
> +    },
> +    DEFINE_M68K_CPU_TYPE("m68000", m68000_cpu_initfn),
> +    DEFINE_M68K_CPU_TYPE("m68020", m68020_cpu_initfn),
> +    DEFINE_M68K_CPU_TYPE("m68030", m68030_cpu_initfn),
> +    DEFINE_M68K_CPU_TYPE("m68040", m68040_cpu_initfn),
> +    DEFINE_M68K_CPU_TYPE("m68060", m68060_cpu_initfn),
> +    DEFINE_M68K_CPU_TYPE("m5206", m5206_cpu_initfn),
> +    DEFINE_M68K_CPU_TYPE("m5208", m5208_cpu_initfn),
> +    DEFINE_M68K_CPU_TYPE("cfv4e", cfv4e_cpu_initfn),
> +    DEFINE_M68K_CPU_TYPE("any", any_cpu_initfn),
>  };
>  
> -static void m68k_cpu_register_types(void)
> -{
> -    int i;
> -
> -    type_register_static(&m68k_cpu_type_info);
> -    for (i = 0; i < ARRAY_SIZE(m68k_cpus); i++) {
> -        register_cpu_type(&m68k_cpus[i]);
> -    }
> -}
> -
> -type_init(m68k_cpu_register_types)
> +type_init_from_array(m68k_cpus_type_infos)
> 

^ permalink raw reply	[flat|nested] 113+ messages in thread

* Re: [Qemu-devel] [PATCH 10/38] m68k: an5206: use generic cpu_model parsing
  2017-10-02  9:07 ` [Qemu-devel] [PATCH 10/38] m68k: an5206: use generic cpu_model parsing Igor Mammedov
  2017-10-03  9:13   ` Thomas Huth
@ 2017-10-03 13:31   ` Philippe Mathieu-Daudé
  2017-10-03 14:51   ` Laurent Vivier
  2 siblings, 0 replies; 113+ messages in thread
From: Philippe Mathieu-Daudé @ 2017-10-03 13:31 UTC (permalink / raw)
  To: Igor Mammedov, laurent; +Cc: qemu-devel, huth

On 10/02/2017 06:07 AM, Igor Mammedov wrote:
> Signed-off-by: Igor Mammedov <imammedo@redhat.com>

Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>

> ---
> CC: huth@tuxfamily.org
> CC: laurent@vivier.eu
> ---
>  hw/m68k/an5206.c | 7 ++-----
>  1 file changed, 2 insertions(+), 5 deletions(-)
> 
> diff --git a/hw/m68k/an5206.c b/hw/m68k/an5206.c
> index 9002c46..0cedc54 100644
> --- a/hw/m68k/an5206.c
> +++ b/hw/m68k/an5206.c
> @@ -28,7 +28,6 @@
>  static void an5206_init(MachineState *machine)
>  {
>      ram_addr_t ram_size = machine->ram_size;
> -    const char *cpu_model = machine->cpu_model;
>      const char *kernel_filename = machine->kernel_filename;
>      M68kCPU *cpu;
>      CPUM68KState *env;
> @@ -39,10 +38,7 @@ static void an5206_init(MachineState *machine)
>      MemoryRegion *ram = g_new(MemoryRegion, 1);
>      MemoryRegion *sram = g_new(MemoryRegion, 1);
>  
> -    if (!cpu_model) {
> -        cpu_model = "m5206";
> -    }
> -    cpu = M68K_CPU(cpu_generic_init(TYPE_M68K_CPU, cpu_model));
> +    cpu = M68K_CPU(cpu_create(machine->cpu_type));
>      env = &cpu->env;
>  
>      /* Initialize CPU registers.  */
> @@ -94,6 +90,7 @@ static void an5206_machine_init(MachineClass *mc)
>  {
>      mc->desc = "Arnewsh 5206";
>      mc->init = an5206_init;
> +    mc->default_cpu_type = M68K_CPU_TYPE_NAME("m5206");
>  }
>  
>  DEFINE_MACHINE("an5206", an5206_machine_init)
> 

^ permalink raw reply	[flat|nested] 113+ messages in thread

* Re: [Qemu-devel] [PATCH 11/38] m68k: mcf5208: use generic cpu_model parsing
  2017-10-02  9:07 ` [Qemu-devel] [PATCH 11/38] m68k: mcf5208: " Igor Mammedov
  2017-10-03  9:28   ` Thomas Huth
@ 2017-10-03 13:32   ` Philippe Mathieu-Daudé
  2017-10-03 14:52   ` Laurent Vivier
  2 siblings, 0 replies; 113+ messages in thread
From: Philippe Mathieu-Daudé @ 2017-10-03 13:32 UTC (permalink / raw)
  To: Igor Mammedov, laurent; +Cc: qemu-devel, huth

On 10/02/2017 06:07 AM, Igor Mammedov wrote:
> Signed-off-by: Igor Mammedov <imammedo@redhat.com>

Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>

> ---
> CC: laurent@vivier.eu
> CC: huth@tuxfamily.org
> ---
>  hw/m68k/mcf5208.c | 7 ++-----
>  1 file changed, 2 insertions(+), 5 deletions(-)
> 
> diff --git a/hw/m68k/mcf5208.c b/hw/m68k/mcf5208.c
> index b9dde75..cfac845 100644
> --- a/hw/m68k/mcf5208.c
> +++ b/hw/m68k/mcf5208.c
> @@ -217,7 +217,6 @@ static void mcf_fec_init(MemoryRegion *sysmem, NICInfo *nd, hwaddr base,
>  static void mcf5208evb_init(MachineState *machine)
>  {
>      ram_addr_t ram_size = machine->ram_size;
> -    const char *cpu_model = machine->cpu_model;
>      const char *kernel_filename = machine->kernel_filename;
>      M68kCPU *cpu;
>      CPUM68KState *env;
> @@ -229,10 +228,7 @@ static void mcf5208evb_init(MachineState *machine)
>      MemoryRegion *ram = g_new(MemoryRegion, 1);
>      MemoryRegion *sram = g_new(MemoryRegion, 1);
>  
> -    if (!cpu_model) {
> -        cpu_model = "m5208";
> -    }
> -    cpu = M68K_CPU(cpu_generic_init(TYPE_M68K_CPU, cpu_model));
> +    cpu = M68K_CPU(cpu_create(machine->cpu_type));
>      env = &cpu->env;
>  
>      /* Initialize CPU registers.  */
> @@ -321,6 +317,7 @@ static void mcf5208evb_machine_init(MachineClass *mc)
>      mc->desc = "MCF5206EVB";
>      mc->init = mcf5208evb_init;
>      mc->is_default = 1;
> +    mc->default_cpu_type = M68K_CPU_TYPE_NAME("m5208");
>  }
>  
>  DEFINE_MACHINE("mcf5208evb", mcf5208evb_machine_init)
> 

^ permalink raw reply	[flat|nested] 113+ messages in thread

* Re: [Qemu-devel] [PATCH 22/38] xtensa: cleanup cpu type name composition
  2017-10-03 10:37     ` Igor Mammedov
@ 2017-10-03 13:33       ` Philippe Mathieu-Daudé
  0 siblings, 0 replies; 113+ messages in thread
From: Philippe Mathieu-Daudé @ 2017-10-03 13:33 UTC (permalink / raw)
  To: Igor Mammedov; +Cc: qemu-devel, jcmvbkbc

On 10/03/2017 07:37 AM, Igor Mammedov wrote:
> On Mon, 2 Oct 2017 17:35:39 -0300
> Philippe Mathieu-Daudé <f4bug@amsat.org> wrote:
> 
>> On 10/02/2017 06:08 AM, Igor Mammedov wrote:
>>> use new XTENSA_CPU_TYPE_NAME to compose CPU type name
>>> to bring xtensa in line with all other targets that
>>> will similar macro.
>>>
>>> Signed-off-by: Igor Mammedov <imammedo@redhat.com>
>>> ---
>>> CC: jcmvbkbc@gmail.com
>>> ---
>>>   target/xtensa/cpu.h    | 4 ++++
>>>   target/xtensa/cpu.c    | 2 +-
>>>   target/xtensa/helper.c | 2 +-
>>>   3 files changed, 6 insertions(+), 2 deletions(-)
>>>
>>> diff --git a/target/xtensa/cpu.h b/target/xtensa/cpu.h
>>> index 4803331..b17d7d9 100644
>>> --- a/target/xtensa/cpu.h
>>> +++ b/target/xtensa/cpu.h
>>> @@ -469,11 +469,15 @@ void xtensa_cpu_do_unaligned_access(CPUState *cpu, vaddr addr,
>>>   #define cpu_signal_handler cpu_xtensa_signal_handler
>>>   #define cpu_list xtensa_cpu_list
>>>   
>>> +#define XTENSA_CPU_TYPE_SUFFIX "-" TYPE_XTENSA_CPU
>>> +#define XTENSA_CPU_TYPE_NAME(model) model XTENSA_CPU_TYPE_SUFFIX
>>> +
>>>   #ifdef TARGET_WORDS_BIGENDIAN
>>>   #define XTENSA_DEFAULT_CPU_MODEL "fsf"
>>>   #else
>>>   #define XTENSA_DEFAULT_CPU_MODEL "dc232b"
>>>   #endif
>>> +#define XTENSA_DEFAULT_CPU_TYPE XTENSA_CPU_TYPE_NAME(XTENSA_DEFAULT_CPU_MODEL)  
>>
>> I see XTENSA_DEFAULT_CPU_MODEL is used in mc->desc, any idea to be able 
>> to use this instead?
> mc-desc is the reason why I've left XTENSA_DEFAULT_CPU_MODEL as is, and
> having that there were no point in adding yet another ifdef for type,
> XTENSA_DEFAULT_CPU_MODEL works just fine here.

Fine enough,

Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>

> 
>>
>> #ifdef TARGET_WORDS_BIGENDIAN
>> # define XTENSA_DEFAULT_CPU_TYPE XTENSA_CPU_TYPE_NAME("fsf")
>> #else
>> # define XTENSA_DEFAULT_CPU_TYPE XTENSA_CPU_TYPE_NAME("dc232b")
>> #endif
>>
>>>   
>>>   #define cpu_init(cpu_model) cpu_generic_init(TYPE_XTENSA_CPU, cpu_model)
>>>   
>>> diff --git a/target/xtensa/cpu.c b/target/xtensa/cpu.c
>>> index dcdc765..b5f7079 100644
>>> --- a/target/xtensa/cpu.c
>>> +++ b/target/xtensa/cpu.c
>>> @@ -83,7 +83,7 @@ static ObjectClass *xtensa_cpu_class_by_name(const char *cpu_model)
>>>       ObjectClass *oc;
>>>       char *typename;
>>>   
>>> -    typename = g_strdup_printf("%s-" TYPE_XTENSA_CPU, 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) ||
>>> diff --git a/target/xtensa/helper.c b/target/xtensa/helper.c
>>> index e8fba20..216f198 100644
>>> --- a/target/xtensa/helper.c
>>> +++ b/target/xtensa/helper.c
>>> @@ -76,7 +76,7 @@ void xtensa_register_core(XtensaConfigList *node)
>>>   
>>>       node->next = xtensa_cores;
>>>       xtensa_cores = node;
>>> -    type.name = g_strdup_printf("%s-" TYPE_XTENSA_CPU, node->config->name);
>>> +    type.name = g_strdup_printf(XTENSA_CPU_TYPE_NAME("%s"), node->config->name);
>>>       type_register(&type);
>>>       g_free((gpointer)type.name);
>>>   }
>>>   
> 

^ permalink raw reply	[flat|nested] 113+ messages in thread

* Re: [Qemu-devel] [PATCH 23/38] xtensa: sim: use generic cpu_model parsing
  2017-10-02  9:08 ` [Qemu-devel] [PATCH 23/38] xtensa: sim: use generic cpu_model parsing Igor Mammedov
@ 2017-10-03 13:34   ` Philippe Mathieu-Daudé
  0 siblings, 0 replies; 113+ messages in thread
From: Philippe Mathieu-Daudé @ 2017-10-03 13:34 UTC (permalink / raw)
  To: Igor Mammedov, qemu-devel; +Cc: jcmvbkbc

On 10/02/2017 06:08 AM, Igor Mammedov wrote:
> Signed-off-by: Igor Mammedov <imammedo@redhat.com>

Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>

> ---
> CC: jcmvbkbc@gmail.com
> ---
>  hw/xtensa/sim.c | 8 ++------
>  1 file changed, 2 insertions(+), 6 deletions(-)
> 
> diff --git a/hw/xtensa/sim.c b/hw/xtensa/sim.c
> index b3580b1..2bb883b 100644
> --- a/hw/xtensa/sim.c
> +++ b/hw/xtensa/sim.c
> @@ -75,16 +75,11 @@ static void xtensa_sim_init(MachineState *machine)
>      XtensaCPU *cpu = NULL;
>      CPUXtensaState *env = NULL;
>      ram_addr_t ram_size = machine->ram_size;
> -    const char *cpu_model = machine->cpu_model;
>      const char *kernel_filename = machine->kernel_filename;
>      int n;
>  
> -    if (!cpu_model) {
> -        cpu_model = XTENSA_DEFAULT_CPU_MODEL;
> -    }
> -
>      for (n = 0; n < smp_cpus; n++) {
> -        cpu = XTENSA_CPU(cpu_generic_init(TYPE_XTENSA_CPU, cpu_model));
> +        cpu = XTENSA_CPU(cpu_create(machine->cpu_type));
>          env = &cpu->env;
>  
>          env->sregs[PRID] = n;
> @@ -133,6 +128,7 @@ static void xtensa_sim_machine_init(MachineClass *mc)
>      mc->init = xtensa_sim_init;
>      mc->max_cpus = 4;
>      mc->no_serial = 1;
> +    mc->default_cpu_type = XTENSA_DEFAULT_CPU_TYPE;
>  }
>  
>  DEFINE_MACHINE("sim", xtensa_sim_machine_init)
> 

^ permalink raw reply	[flat|nested] 113+ messages in thread

* Re: [Qemu-devel] [PATCH 24/38] xtensa: lx60/lx200/ml605/kc705: use generic cpu_model parsing
  2017-10-02  9:08 ` [Qemu-devel] [PATCH 24/38] xtensa: lx60/lx200/ml605/kc705: " Igor Mammedov
@ 2017-10-03 13:34   ` Philippe Mathieu-Daudé
  0 siblings, 0 replies; 113+ messages in thread
From: Philippe Mathieu-Daudé @ 2017-10-03 13:34 UTC (permalink / raw)
  To: Igor Mammedov, qemu-devel; +Cc: jcmvbkbc

On 10/02/2017 06:08 AM, Igor Mammedov wrote:
> Signed-off-by: Igor Mammedov <imammedo@redhat.com>

Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>

> ---
> CC: jcmvbkbc@gmail.com
> ---
>  hw/xtensa/xtfpga.c | 11 +++++------
>  1 file changed, 5 insertions(+), 6 deletions(-)
> 
> diff --git a/hw/xtensa/xtfpga.c b/hw/xtensa/xtfpga.c
> index a19cceb..1971ecf 100644
> --- a/hw/xtensa/xtfpga.c
> +++ b/hw/xtensa/xtfpga.c
> @@ -220,19 +220,14 @@ static void lx_init(const LxBoardDesc *board, MachineState *machine)
>      DriveInfo *dinfo;
>      pflash_t *flash = NULL;
>      QemuOpts *machine_opts = qemu_get_machine_opts();
> -    const char *cpu_model = machine->cpu_model;
>      const char *kernel_filename = qemu_opt_get(machine_opts, "kernel");
>      const char *kernel_cmdline = qemu_opt_get(machine_opts, "append");
>      const char *dtb_filename = qemu_opt_get(machine_opts, "dtb");
>      const char *initrd_filename = qemu_opt_get(machine_opts, "initrd");
>      int n;
>  
> -    if (!cpu_model) {
> -        cpu_model = XTENSA_DEFAULT_CPU_MODEL;
> -    }
> -
>      for (n = 0; n < smp_cpus; n++) {
> -        cpu = XTENSA_CPU(cpu_generic_init(TYPE_XTENSA_CPU, cpu_model));
> +        cpu = XTENSA_CPU(cpu_create(machine->cpu_type));
>          env = &cpu->env;
>  
>          env->sregs[PRID] = n;
> @@ -454,6 +449,7 @@ static void xtensa_lx60_class_init(ObjectClass *oc, void *data)
>      mc->desc = "lx60 EVB (" XTENSA_DEFAULT_CPU_MODEL ")";
>      mc->init = xtensa_lx60_init;
>      mc->max_cpus = 4;
> +    mc->default_cpu_type = XTENSA_DEFAULT_CPU_TYPE;
>  }
>  
>  static const TypeInfo xtensa_lx60_type = {
> @@ -469,6 +465,7 @@ static void xtensa_lx200_class_init(ObjectClass *oc, void *data)
>      mc->desc = "lx200 EVB (" XTENSA_DEFAULT_CPU_MODEL ")";
>      mc->init = xtensa_lx200_init;
>      mc->max_cpus = 4;
> +    mc->default_cpu_type = XTENSA_DEFAULT_CPU_TYPE;
>  }
>  
>  static const TypeInfo xtensa_lx200_type = {
> @@ -484,6 +481,7 @@ static void xtensa_ml605_class_init(ObjectClass *oc, void *data)
>      mc->desc = "ml605 EVB (" XTENSA_DEFAULT_CPU_MODEL ")";
>      mc->init = xtensa_ml605_init;
>      mc->max_cpus = 4;
> +    mc->default_cpu_type = XTENSA_DEFAULT_CPU_TYPE;
>  }
>  
>  static const TypeInfo xtensa_ml605_type = {
> @@ -499,6 +497,7 @@ static void xtensa_kc705_class_init(ObjectClass *oc, void *data)
>      mc->desc = "kc705 EVB (" XTENSA_DEFAULT_CPU_MODEL ")";
>      mc->init = xtensa_kc705_init;
>      mc->max_cpus = 4;
> +    mc->default_cpu_type = XTENSA_DEFAULT_CPU_TYPE;
>  }
>  
>  static const TypeInfo xtensa_kc705_type = {
> 

^ permalink raw reply	[flat|nested] 113+ messages in thread

* Re: [Qemu-devel] [PATCH 12/38] moxie: fix qemu-system-moxie failing to start with CLI "-cpu MoxieLite"
  2017-10-02  9:07 ` [Qemu-devel] [PATCH 12/38] moxie: fix qemu-system-moxie failing to start with CLI "-cpu MoxieLite" Igor Mammedov
@ 2017-10-03 13:37   ` Philippe Mathieu-Daudé
  0 siblings, 0 replies; 113+ messages in thread
From: Philippe Mathieu-Daudé @ 2017-10-03 13:37 UTC (permalink / raw)
  To: Igor Mammedov, green; +Cc: qemu-devel

On 10/02/2017 06:07 AM, Igor Mammedov wrote:
> It 'works' with default CPU only because of bug in
> moxie_cpu_class_by_name() where it treats cpu_model
> as type name and default cpu_model also happens to be
> type name. But specifying explicitly cpu on CLI,
> ex: '-cpu MoxieLite', makes QEMU fail since
> moxie_cpu_class_by_name() doesn't traslate cpu_model
> to cpu type and fails to find corresponding object class.
> 
> Fix moxie_cpu_class_by_name() to do proper
>    cpu_model -> cpu type
> translation and fix default cpu_model to be cpu_model
> instead of being typename.
> 
> Signed-off-by: Igor Mammedov <imammedo@redhat.com>

Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>

> ---
> CC: green@moxielogic.com
> ---
>  hw/moxie/moxiesim.c | 2 +-
>  target/moxie/cpu.c  | 7 ++++++-
>  2 files changed, 7 insertions(+), 2 deletions(-)
> 
> diff --git a/hw/moxie/moxiesim.c b/hw/moxie/moxiesim.c
> index 5ea8dd3..01b9f34 100644
> --- a/hw/moxie/moxiesim.c
> +++ b/hw/moxie/moxiesim.c
> @@ -116,7 +116,7 @@ static void moxiesim_init(MachineState *machine)
>  
>      /* Init CPUs. */
>      if (cpu_model == NULL) {
> -        cpu_model = "MoxieLite-moxie-cpu";
> +        cpu_model = "MoxieLite";
>      }
>      cpu = MOXIE_CPU(cpu_generic_init(TYPE_MOXIE_CPU, cpu_model));
>      env = &cpu->env;
> diff --git a/target/moxie/cpu.c b/target/moxie/cpu.c
> index 30bd44f..d4626a1 100644
> --- a/target/moxie/cpu.c
> +++ b/target/moxie/cpu.c
> @@ -89,7 +89,12 @@ static void moxie_cpu_initfn(Object *obj)
>  
>  static ObjectClass *moxie_cpu_class_by_name(const char *cpu_model)
>  {
> -    ObjectClass *oc = object_class_by_name(cpu_model);
> +    ObjectClass *oc;
> +    char *typename;
> +
> +    typename = g_strdup_printf("%s-" TYPE_MOXIE_CPU, cpu_model);
> +    oc = object_class_by_name(typename);
> +    g_free(typename);
>      if (oc != NULL && (!object_class_dynamic_cast(oc, TYPE_MOXIE_CPU) ||
>                         object_class_is_abstract(oc))) {
>          return NULL;
> 

^ permalink raw reply	[flat|nested] 113+ messages in thread

* Re: [Qemu-devel] [PATCH] qom: add helpers REGISTER_STATIC_TYPE[S]()
  2017-10-03 12:14     ` [Qemu-devel] [PATCH] qom: add helpers REGISTER_STATIC_TYPE[S]() Igor Mammedov
  2017-10-03 13:29       ` Philippe Mathieu-Daudé
@ 2017-10-03 14:25       ` Eduardo Habkost
  2017-10-03 15:01         ` Igor Mammedov
  2017-10-03 15:44       ` Peter Maydell
  2 siblings, 1 reply; 113+ messages in thread
From: Eduardo Habkost @ 2017-10-03 14:25 UTC (permalink / raw)
  To: Igor Mammedov; +Cc: qemu-devel

On Tue, Oct 03, 2017 at 02:14:46PM +0200, Igor Mammedov wrote:
> it will help to remove code duplication in places
> that currently open code registration of static
> type[s] and remove necessity to declare function
> for type_init() to call, when only static types
> need to be registered.
> 
> Signed-off-by: Igor Mammedov <imammedo@redhat.com>
> ---
> I'm going to use it for CPU types in followup patches
> 
> CC: ehabkost@redhat.com
> ---
>  include/qemu/module.h | 10 ++++++++++
>  include/qom/object.h  | 10 ++++++++++
>  qom/object.c          |  9 +++++++++
>  3 files changed, 29 insertions(+)
> 
> diff --git a/include/qemu/module.h b/include/qemu/module.h
> index 56dd218..60dd632 100644
> --- a/include/qemu/module.h
> +++ b/include/qemu/module.h
> @@ -52,6 +52,16 @@ typedef enum {
>  #define type_init(function) module_init(function, MODULE_INIT_QOM)
>  #define trace_init(function) module_init(function, MODULE_INIT_TRACE)
>  
> +#define REGISTER_STATIC_TYPES(t, nr)                                        \

I'm unsure about the name.  We already have a declarative way to
register machine types (DEFINE_MACHINE), maybe use "DEFINE_*" for
consistency?

Also, this function won't work if t isn't a static variable, will
it?  The "STATIC" part looks redundant.

In other words, how about "DEFINE_TYPE" and "DEFINE_TYPES"?


> +static void do_qemu_init_ ## t(void)                                        \
> +{                                                                           \
> +    type_register_static_array(t, nr);                                      \

qemu/module.h doesn't include qom/object.h.  I think this should
go to either qom/object.h or a new header file.

> +}                                                                           \
> +type_init(do_qemu_init_ ## t)
> +
> +#define REGISTER_STATIC_TYPE(t)                                             \
> +    REGISTER_STATIC_TYPES(t, 1)
> +
>  #define block_module_load_one(lib) module_load_one("block-", lib)
>  
>  void register_module_init(void (*fn)(void), module_init_type type);
> diff --git a/include/qom/object.h b/include/qom/object.h
> index f3e5cff..17fcadd 100644
> --- a/include/qom/object.h
> +++ b/include/qom/object.h
> @@ -789,6 +789,16 @@ Type type_register_static(const TypeInfo *info);
>  Type type_register(const TypeInfo *info);
>  
>  /**
> + * type_register_static_array:
> + * @infos: The array of the new type #TypeInfo structures.
> + * @nr_infos: number of entries in @infos
> + *
> + * @infos and all of the strings it points to should exist for the life time
> + * that the type is registered.
> + */
> +void type_register_static_array(const TypeInfo *infos, int nr_infos);

This new function is probably less controversial than the new
module.h-based code.  Maybe worth moving to a separate patch so
it can be merged earlier?

(If I were you, I would just use type_register_static_array()
inside the existing *_cpu_register_types() functions by now, so
this won't block the whole series, and worry about
REGISTER_STATIC_TYPE*/DEFINE_TYPE* later.)


> +
> +/**
>   * object_class_dynamic_cast_assert:
>   * @klass: The #ObjectClass to attempt to cast.
>   * @typename: The QOM typename of the class to cast to.
> diff --git a/qom/object.c b/qom/object.c
> index 3e18537..40b1729 100644
> --- a/qom/object.c
> +++ b/qom/object.c
> @@ -151,6 +151,15 @@ TypeImpl *type_register_static(const TypeInfo *info)
>      return type_register(info);
>  }
>  
> +void type_register_static_array(const TypeInfo *infos, int nr_infos)
> +{
> +    int i;
> +
> +    for (i = 0; i < nr_infos; i++) {
> +        assert(type_register_static(&infos[i]));

Why the assert()?  type_register_static() is already guaranteed
to never return NULL.

This will break if compiled with -DNDEBUG: assert() won't even
evaluate the expression if NDEBUG is defined.

> +    }
> +}
> +
>  static TypeImpl *type_get_by_name(const char *name)
>  {
>      if (name == NULL) {
> -- 
> 2.7.4
> 

-- 
Eduardo

^ permalink raw reply	[flat|nested] 113+ messages in thread

* Re: [Qemu-devel] [PATCH 09/38] m68k: cleanup cpu type name composition
  2017-10-02  9:07 ` [Qemu-devel] [PATCH 09/38] m68k: cleanup cpu type name composition Igor Mammedov
  2017-10-03 13:31   ` Philippe Mathieu-Daudé
@ 2017-10-03 14:50   ` Laurent Vivier
  1 sibling, 0 replies; 113+ messages in thread
From: Laurent Vivier @ 2017-10-03 14:50 UTC (permalink / raw)
  To: Igor Mammedov, qemu-devel; +Cc: Philippe Mathieu-Daudé

Le 02/10/2017 à 11:07, Igor Mammedov a écrit :
> use new M68K_CPU_TYPE_NAME to compose CPU type names
> and get rid of intermediate M68kCPUInfo/register_cpu_type()
> which is replaced by static TypeInfo array.
> 
> Signed-off-by: Igor Mammedov <imammedo@redhat.com>
> ---
> CC: laurent@vivier.eu
> ---
>  target/m68k/cpu.h |  3 +++
>  target/m68k/cpu.c | 75 ++++++++++++++++++++-----------------------------------
>  2 files changed, 30 insertions(+), 48 deletions(-)
> 
> diff --git a/target/m68k/cpu.h b/target/m68k/cpu.h
> index d936547..afae5f6 100644
> --- a/target/m68k/cpu.h
> +++ b/target/m68k/cpu.h
> @@ -323,6 +323,9 @@ void register_m68k_insns (CPUM68KState *env);
>  
>  #define cpu_init(cpu_model) cpu_generic_init(TYPE_M68K_CPU, cpu_model)
>  
> +#define M68K_CPU_TYPE_SUFFIX "-" TYPE_M68K_CPU
> +#define M68K_CPU_TYPE_NAME(model) model M68K_CPU_TYPE_SUFFIX
> +
>  #define cpu_signal_handler cpu_m68k_signal_handler
>  #define cpu_list m68k_cpu_list
>  
> diff --git a/target/m68k/cpu.c b/target/m68k/cpu.c
> index 8c70e08..f0f90e9 100644
> --- a/target/m68k/cpu.c
> +++ b/target/m68k/cpu.c
> @@ -87,7 +87,7 @@ static ObjectClass *m68k_cpu_class_by_name(const char *cpu_model)
>      ObjectClass *oc;
>      char *typename;
>  
> -    typename = g_strdup_printf("%s-" TYPE_M68K_CPU, cpu_model);
> +    typename = g_strdup_printf(M68K_CPU_TYPE_NAME("%s"), cpu_model);
>      oc = object_class_by_name(typename);
>      g_free(typename);
>      if (oc != NULL && (object_class_dynamic_cast(oc, TYPE_M68K_CPU) == NULL ||
> @@ -202,23 +202,6 @@ static void any_cpu_initfn(Object *obj)
>      m68k_set_feature(env, M68K_FEATURE_WORD_INDEX);
>  }
>  
> -typedef struct M68kCPUInfo {
> -    const char *name;
> -    void (*instance_init)(Object *obj);
> -} M68kCPUInfo;
> -
> -static const M68kCPUInfo m68k_cpus[] = {
> -    { .name = "m68000", .instance_init = m68000_cpu_initfn },
> -    { .name = "m68020", .instance_init = m68020_cpu_initfn },
> -    { .name = "m68030", .instance_init = m68030_cpu_initfn },
> -    { .name = "m68040", .instance_init = m68040_cpu_initfn },
> -    { .name = "m68060", .instance_init = m68060_cpu_initfn },
> -    { .name = "m5206", .instance_init = m5206_cpu_initfn },
> -    { .name = "m5208", .instance_init = m5208_cpu_initfn },
> -    { .name = "cfv4e", .instance_init = cfv4e_cpu_initfn },
> -    { .name = "any",   .instance_init = any_cpu_initfn },
> -};
> -
>  static void m68k_cpu_realizefn(DeviceState *dev, Error **errp)
>  {
>      CPUState *cs = CPU(dev);
> @@ -295,36 +278,32 @@ static void m68k_cpu_class_init(ObjectClass *c, void *data)
>      dc->vmsd = &vmstate_m68k_cpu;
>  }
>  
> -static void register_cpu_type(const M68kCPUInfo *info)
> -{
> -    TypeInfo type_info = {
> -        .parent = TYPE_M68K_CPU,
> -        .instance_init = info->instance_init,
> -    };
> -
> -    type_info.name = g_strdup_printf("%s-" TYPE_M68K_CPU, info->name);
> -    type_register(&type_info);
> -    g_free((void *)type_info.name);
> -}
> +#define DEFINE_M68K_CPU_TYPE(cpu_model, initfn) \
> +    {                                           \
> +        .name = M68K_CPU_TYPE_NAME(cpu_model),  \
> +        .instance_init = initfn,                \
> +        .parent = TYPE_M68K_CPU,                \
> +    }
>  
> -static const TypeInfo m68k_cpu_type_info = {
> -    .name = TYPE_M68K_CPU,
> -    .parent = TYPE_CPU,
> -    .instance_size = sizeof(M68kCPU),
> -    .instance_init = m68k_cpu_initfn,
> -    .abstract = true,
> -    .class_size = sizeof(M68kCPUClass),
> -    .class_init = m68k_cpu_class_init,
> +static const TypeInfo m68k_cpus_type_infos[] = {
> +    { /* base class should be registered first */
> +        .name = TYPE_M68K_CPU,
> +        .parent = TYPE_CPU,
> +        .instance_size = sizeof(M68kCPU),
> +        .instance_init = m68k_cpu_initfn,
> +        .abstract = true,
> +        .class_size = sizeof(M68kCPUClass),
> +        .class_init = m68k_cpu_class_init,
> +    },
> +    DEFINE_M68K_CPU_TYPE("m68000", m68000_cpu_initfn),
> +    DEFINE_M68K_CPU_TYPE("m68020", m68020_cpu_initfn),
> +    DEFINE_M68K_CPU_TYPE("m68030", m68030_cpu_initfn),
> +    DEFINE_M68K_CPU_TYPE("m68040", m68040_cpu_initfn),
> +    DEFINE_M68K_CPU_TYPE("m68060", m68060_cpu_initfn),
> +    DEFINE_M68K_CPU_TYPE("m5206", m5206_cpu_initfn),
> +    DEFINE_M68K_CPU_TYPE("m5208", m5208_cpu_initfn),
> +    DEFINE_M68K_CPU_TYPE("cfv4e", cfv4e_cpu_initfn),
> +    DEFINE_M68K_CPU_TYPE("any", any_cpu_initfn),
>  };
>  
> -static void m68k_cpu_register_types(void)
> -{
> -    int i;
> -
> -    type_register_static(&m68k_cpu_type_info);
> -    for (i = 0; i < ARRAY_SIZE(m68k_cpus); i++) {
> -        register_cpu_type(&m68k_cpus[i]);
> -    }
> -}
> -
> -type_init(m68k_cpu_register_types)
> +type_init_from_array(m68k_cpus_type_infos)
> 

Acked-by: Laurent Vivier <laurent@vivier.eu>

^ permalink raw reply	[flat|nested] 113+ messages in thread

* Re: [Qemu-devel] [PATCH 10/38] m68k: an5206: use generic cpu_model parsing
  2017-10-02  9:07 ` [Qemu-devel] [PATCH 10/38] m68k: an5206: use generic cpu_model parsing Igor Mammedov
  2017-10-03  9:13   ` Thomas Huth
  2017-10-03 13:31   ` Philippe Mathieu-Daudé
@ 2017-10-03 14:51   ` Laurent Vivier
  2 siblings, 0 replies; 113+ messages in thread
From: Laurent Vivier @ 2017-10-03 14:51 UTC (permalink / raw)
  To: Igor Mammedov, qemu-devel; +Cc: Philippe Mathieu-Daudé, huth

Le 02/10/2017 à 11:07, Igor Mammedov a écrit :
> Signed-off-by: Igor Mammedov <imammedo@redhat.com>
> ---
> CC: huth@tuxfamily.org
> CC: laurent@vivier.eu
> ---
>  hw/m68k/an5206.c | 7 ++-----
>  1 file changed, 2 insertions(+), 5 deletions(-)
> 
> diff --git a/hw/m68k/an5206.c b/hw/m68k/an5206.c
> index 9002c46..0cedc54 100644
> --- a/hw/m68k/an5206.c
> +++ b/hw/m68k/an5206.c
> @@ -28,7 +28,6 @@
>  static void an5206_init(MachineState *machine)
>  {
>      ram_addr_t ram_size = machine->ram_size;
> -    const char *cpu_model = machine->cpu_model;
>      const char *kernel_filename = machine->kernel_filename;
>      M68kCPU *cpu;
>      CPUM68KState *env;
> @@ -39,10 +38,7 @@ static void an5206_init(MachineState *machine)
>      MemoryRegion *ram = g_new(MemoryRegion, 1);
>      MemoryRegion *sram = g_new(MemoryRegion, 1);
>  
> -    if (!cpu_model) {
> -        cpu_model = "m5206";
> -    }
> -    cpu = M68K_CPU(cpu_generic_init(TYPE_M68K_CPU, cpu_model));
> +    cpu = M68K_CPU(cpu_create(machine->cpu_type));
>      env = &cpu->env;
>  
>      /* Initialize CPU registers.  */
> @@ -94,6 +90,7 @@ static void an5206_machine_init(MachineClass *mc)
>  {
>      mc->desc = "Arnewsh 5206";
>      mc->init = an5206_init;
> +    mc->default_cpu_type = M68K_CPU_TYPE_NAME("m5206");
>  }
>  
>  DEFINE_MACHINE("an5206", an5206_machine_init)
> 
Reviewed-by: Laurent Vivier <laurent@vivier.eu>

^ permalink raw reply	[flat|nested] 113+ messages in thread

* Re: [Qemu-devel] [PATCH 11/38] m68k: mcf5208: use generic cpu_model parsing
  2017-10-02  9:07 ` [Qemu-devel] [PATCH 11/38] m68k: mcf5208: " Igor Mammedov
  2017-10-03  9:28   ` Thomas Huth
  2017-10-03 13:32   ` Philippe Mathieu-Daudé
@ 2017-10-03 14:52   ` Laurent Vivier
  2 siblings, 0 replies; 113+ messages in thread
From: Laurent Vivier @ 2017-10-03 14:52 UTC (permalink / raw)
  To: Igor Mammedov, qemu-devel; +Cc: Philippe Mathieu-Daudé, huth

Le 02/10/2017 à 11:07, Igor Mammedov a écrit :
> Signed-off-by: Igor Mammedov <imammedo@redhat.com>
> ---
> CC: laurent@vivier.eu
> CC: huth@tuxfamily.org
> ---
>  hw/m68k/mcf5208.c | 7 ++-----
>  1 file changed, 2 insertions(+), 5 deletions(-)
> 
> diff --git a/hw/m68k/mcf5208.c b/hw/m68k/mcf5208.c
> index b9dde75..cfac845 100644
> --- a/hw/m68k/mcf5208.c
> +++ b/hw/m68k/mcf5208.c
> @@ -217,7 +217,6 @@ static void mcf_fec_init(MemoryRegion *sysmem, NICInfo *nd, hwaddr base,
>  static void mcf5208evb_init(MachineState *machine)
>  {
>      ram_addr_t ram_size = machine->ram_size;
> -    const char *cpu_model = machine->cpu_model;
>      const char *kernel_filename = machine->kernel_filename;
>      M68kCPU *cpu;
>      CPUM68KState *env;
> @@ -229,10 +228,7 @@ static void mcf5208evb_init(MachineState *machine)
>      MemoryRegion *ram = g_new(MemoryRegion, 1);
>      MemoryRegion *sram = g_new(MemoryRegion, 1);
>  
> -    if (!cpu_model) {
> -        cpu_model = "m5208";
> -    }
> -    cpu = M68K_CPU(cpu_generic_init(TYPE_M68K_CPU, cpu_model));
> +    cpu = M68K_CPU(cpu_create(machine->cpu_type));
>      env = &cpu->env;
>  
>      /* Initialize CPU registers.  */
> @@ -321,6 +317,7 @@ static void mcf5208evb_machine_init(MachineClass *mc)
>      mc->desc = "MCF5206EVB";
>      mc->init = mcf5208evb_init;
>      mc->is_default = 1;
> +    mc->default_cpu_type = M68K_CPU_TYPE_NAME("m5208");
>  }
>  
>  DEFINE_MACHINE("mcf5208evb", mcf5208evb_machine_init)
> 
Reviewed-by: Laurent Vivier <laurent@vivier.eu>

^ permalink raw reply	[flat|nested] 113+ messages in thread

* Re: [Qemu-devel] [PATCH] qom: add helpers REGISTER_STATIC_TYPE[S]()
  2017-10-03 14:25       ` Eduardo Habkost
@ 2017-10-03 15:01         ` Igor Mammedov
  2017-10-03 15:37           ` Eduardo Habkost
  0 siblings, 1 reply; 113+ messages in thread
From: Igor Mammedov @ 2017-10-03 15:01 UTC (permalink / raw)
  To: Eduardo Habkost; +Cc: qemu-devel

On Tue, 3 Oct 2017 11:25:01 -0300
Eduardo Habkost <ehabkost@redhat.com> wrote:

> On Tue, Oct 03, 2017 at 02:14:46PM +0200, Igor Mammedov wrote:
> > it will help to remove code duplication in places
> > that currently open code registration of static
> > type[s] and remove necessity to declare function
> > for type_init() to call, when only static types
> > need to be registered.
> > 
> > Signed-off-by: Igor Mammedov <imammedo@redhat.com>
> > ---
> > I'm going to use it for CPU types in followup patches
> > 
> > CC: ehabkost@redhat.com
> > ---
> >  include/qemu/module.h | 10 ++++++++++
> >  include/qom/object.h  | 10 ++++++++++
> >  qom/object.c          |  9 +++++++++
> >  3 files changed, 29 insertions(+)
> > 
> > diff --git a/include/qemu/module.h b/include/qemu/module.h
> > index 56dd218..60dd632 100644
> > --- a/include/qemu/module.h
> > +++ b/include/qemu/module.h
> > @@ -52,6 +52,16 @@ typedef enum {
> >  #define type_init(function) module_init(function, MODULE_INIT_QOM)
> >  #define trace_init(function) module_init(function, MODULE_INIT_TRACE)
> >  
> > +#define REGISTER_STATIC_TYPES(t, nr)                                        \  
> 
> I'm unsure about the name.  We already have a declarative way to
> register machine types (DEFINE_MACHINE), maybe use "DEFINE_*" for
> consistency?
> 
> Also, this function won't work if t isn't a static variable, will
> it?  The "STATIC" part looks redundant.
> 
> In other words, how about "DEFINE_TYPE" and "DEFINE_TYPES"?
'define' word remind me more of declaration but here we actually
register types that's why 'register' looks better to me as it says
exactly what's going here.

> 
> 
> > +static void do_qemu_init_ ## t(void)                                        \
> > +{                                                                           \
> > +    type_register_static_array(t, nr);                                      \  
> 
> qemu/module.h doesn't include qom/object.h.  I think this should
> go to either qom/object.h or a new header file.
I could move it to qom/object.h

> 
> > +}                                                                           \
> > +type_init(do_qemu_init_ ## t)
> > +
> > +#define REGISTER_STATIC_TYPE(t)                                             \
> > +    REGISTER_STATIC_TYPES(t, 1)
> > +
> >  #define block_module_load_one(lib) module_load_one("block-", lib)
> >  
> >  void register_module_init(void (*fn)(void), module_init_type type);
> > diff --git a/include/qom/object.h b/include/qom/object.h
> > index f3e5cff..17fcadd 100644
> > --- a/include/qom/object.h
> > +++ b/include/qom/object.h
> > @@ -789,6 +789,16 @@ Type type_register_static(const TypeInfo *info);
> >  Type type_register(const TypeInfo *info);
> >  
> >  /**
> > + * type_register_static_array:
> > + * @infos: The array of the new type #TypeInfo structures.
> > + * @nr_infos: number of entries in @infos
> > + *
> > + * @infos and all of the strings it points to should exist for the life time
> > + * that the type is registered.
> > + */
> > +void type_register_static_array(const TypeInfo *infos, int nr_infos);  
> 
> This new function is probably less controversial than the new
> module.h-based code.  Maybe worth moving to a separate patch so
> it can be merged earlier?
> 
> (If I were you, I would just use type_register_static_array()
> inside the existing *_cpu_register_types() functions by now, so
> this won't block the whole series, and worry about
> REGISTER_STATIC_TYPE*/DEFINE_TYPE* later.)
it would be nice to have both in one series so that
we won't have to touch/rewrite more than once code where
static cpu types are registered.

If you prefer I can do what you suggest and keep
*_cpu_register_types() functions
but I can't promise to return back to cleaning them up
or to REGISTER_STATIC_TYPE*/DEFINE_TYPE, so probably
someone else will have to pickup that work.

> > +
> > +/**
> >   * object_class_dynamic_cast_assert:
> >   * @klass: The #ObjectClass to attempt to cast.
> >   * @typename: The QOM typename of the class to cast to.
> > diff --git a/qom/object.c b/qom/object.c
> > index 3e18537..40b1729 100644
> > --- a/qom/object.c
> > +++ b/qom/object.c
> > @@ -151,6 +151,15 @@ TypeImpl *type_register_static(const TypeInfo *info)
> >      return type_register(info);
> >  }
> >  
> > +void type_register_static_array(const TypeInfo *infos, int nr_infos)
> > +{
> > +    int i;
> > +
> > +    for (i = 0; i < nr_infos; i++) {
> > +        assert(type_register_static(&infos[i]));  
> 
> Why the assert()?  type_register_static() is already guaranteed
> to never return NULL.
according to doc comment type_register_static might return 0 on failure
so qemu should die in that case.

> 
> This will break if compiled with -DNDEBUG: assert() won't even
> evaluate the expression if NDEBUG is defined.
> 
> > +    }
> > +}
> > +
> >  static TypeImpl *type_get_by_name(const char *name)
> >  {
> >      if (name == NULL) {
> > -- 
> > 2.7.4
> >   
> 

^ permalink raw reply	[flat|nested] 113+ messages in thread

* Re: [Qemu-devel] [PATCH] qom: add helpers REGISTER_STATIC_TYPE[S]()
  2017-10-03 15:01         ` Igor Mammedov
@ 2017-10-03 15:37           ` Eduardo Habkost
  2017-10-03 16:37             ` Igor Mammedov
  0 siblings, 1 reply; 113+ messages in thread
From: Eduardo Habkost @ 2017-10-03 15:37 UTC (permalink / raw)
  To: Igor Mammedov; +Cc: qemu-devel

On Tue, Oct 03, 2017 at 05:01:39PM +0200, Igor Mammedov wrote:
> On Tue, 3 Oct 2017 11:25:01 -0300
> Eduardo Habkost <ehabkost@redhat.com> wrote:
> 
> > On Tue, Oct 03, 2017 at 02:14:46PM +0200, Igor Mammedov wrote:
> > > it will help to remove code duplication in places
> > > that currently open code registration of static
> > > type[s] and remove necessity to declare function
> > > for type_init() to call, when only static types
> > > need to be registered.
> > > 
> > > Signed-off-by: Igor Mammedov <imammedo@redhat.com>
> > > ---
> > > I'm going to use it for CPU types in followup patches
> > > 
> > > CC: ehabkost@redhat.com
> > > ---
> > >  include/qemu/module.h | 10 ++++++++++
> > >  include/qom/object.h  | 10 ++++++++++
> > >  qom/object.c          |  9 +++++++++
> > >  3 files changed, 29 insertions(+)
> > > 
> > > diff --git a/include/qemu/module.h b/include/qemu/module.h
> > > index 56dd218..60dd632 100644
> > > --- a/include/qemu/module.h
> > > +++ b/include/qemu/module.h
> > > @@ -52,6 +52,16 @@ typedef enum {
> > >  #define type_init(function) module_init(function, MODULE_INIT_QOM)
> > >  #define trace_init(function) module_init(function, MODULE_INIT_TRACE)
> > >  
> > > +#define REGISTER_STATIC_TYPES(t, nr)                                        \  
> > 
> > I'm unsure about the name.  We already have a declarative way to
> > register machine types (DEFINE_MACHINE), maybe use "DEFINE_*" for
> > consistency?
> > 
> > Also, this function won't work if t isn't a static variable, will
> > it?  The "STATIC" part looks redundant.
> > 
> > In other words, how about "DEFINE_TYPE" and "DEFINE_TYPES"?
> 'define' word remind me more of declaration but here we actually
> register types that's why 'register' looks better to me as it says
> exactly what's going here.

Making it look like a declaration and not an action like
"register" is on purpose, as it's not a function call anymore:
it's a declaration that will make the type get registered
automatically.

> 
> > 
> > 
> > > +static void do_qemu_init_ ## t(void)                                        \
> > > +{                                                                           \
> > > +    type_register_static_array(t, nr);                                      \  
> > 
> > qemu/module.h doesn't include qom/object.h.  I think this should
> > go to either qom/object.h or a new header file.
> I could move it to qom/object.h
> 
> > 
> > > +}                                                                           \
> > > +type_init(do_qemu_init_ ## t)
> > > +
> > > +#define REGISTER_STATIC_TYPE(t)                                             \
> > > +    REGISTER_STATIC_TYPES(t, 1)
> > > +
> > >  #define block_module_load_one(lib) module_load_one("block-", lib)
> > >  
> > >  void register_module_init(void (*fn)(void), module_init_type type);
> > > diff --git a/include/qom/object.h b/include/qom/object.h
> > > index f3e5cff..17fcadd 100644
> > > --- a/include/qom/object.h
> > > +++ b/include/qom/object.h
> > > @@ -789,6 +789,16 @@ Type type_register_static(const TypeInfo *info);
> > >  Type type_register(const TypeInfo *info);
> > >  
> > >  /**
> > > + * type_register_static_array:
> > > + * @infos: The array of the new type #TypeInfo structures.
> > > + * @nr_infos: number of entries in @infos
> > > + *
> > > + * @infos and all of the strings it points to should exist for the life time
> > > + * that the type is registered.
> > > + */
> > > +void type_register_static_array(const TypeInfo *infos, int nr_infos);  
> > 
> > This new function is probably less controversial than the new
> > module.h-based code.  Maybe worth moving to a separate patch so
> > it can be merged earlier?
> > 
> > (If I were you, I would just use type_register_static_array()
> > inside the existing *_cpu_register_types() functions by now, so
> > this won't block the whole series, and worry about
> > REGISTER_STATIC_TYPE*/DEFINE_TYPE* later.)
> it would be nice to have both in one series so that
> we won't have to touch/rewrite more than once code where
> static cpu types are registered.
> 
> If you prefer I can do what you suggest and keep
> *_cpu_register_types() functions
> but I can't promise to return back to cleaning them up
> or to REGISTER_STATIC_TYPE*/DEFINE_TYPE, so probably
> someone else will have to pickup that work.

No problem to me, if this is left for later.  The macro saves
only 3 lines of code.

I think REGISTER_STATIC_TYPE*/DEFINE_TYPE* is a good idea, but
considering that QOM types are not the only kind of entity we
register at module_init(), we need to pick a style that can be
consistently used by other subsystems (e.g. for QemuOpts,
BlockDrivers, and TraceEvents).  This means this could take a
little longer to be discussed, and I guess you wouldn't like the
discussion to block the cleanups in this series.

> 
> > > +
> > > +/**
> > >   * object_class_dynamic_cast_assert:
> > >   * @klass: The #ObjectClass to attempt to cast.
> > >   * @typename: The QOM typename of the class to cast to.
> > > diff --git a/qom/object.c b/qom/object.c
> > > index 3e18537..40b1729 100644
> > > --- a/qom/object.c
> > > +++ b/qom/object.c
> > > @@ -151,6 +151,15 @@ TypeImpl *type_register_static(const TypeInfo *info)
> > >      return type_register(info);
> > >  }
> > >  
> > > +void type_register_static_array(const TypeInfo *infos, int nr_infos)
> > > +{
> > > +    int i;
> > > +
> > > +    for (i = 0; i < nr_infos; i++) {
> > > +        assert(type_register_static(&infos[i]));  
> > 
> > Why the assert()?  type_register_static() is already guaranteed
> > to never return NULL.
> according to doc comment type_register_static might return 0 on failure
> so qemu should die in that case.

We have absolutely no callers of type_register*() that check its
return value, and the existing implementation guarantees it will
never return NULL.  Instead of making
type_register_static_array() more commplex, we could just update
the documentation.

> 
> > 
> > This will break if compiled with -DNDEBUG: assert() won't even
> > evaluate the expression if NDEBUG is defined.
> > 
> > > +    }
> > > +}
> > > +
> > >  static TypeImpl *type_get_by_name(const char *name)
> > >  {
> > >      if (name == NULL) {
> > > -- 
> > > 2.7.4
> > >   
> > 
> 

-- 
Eduardo

^ permalink raw reply	[flat|nested] 113+ messages in thread

* Re: [Qemu-devel] [PATCH] qom: add helpers REGISTER_STATIC_TYPE[S]()
  2017-10-03 13:29       ` Philippe Mathieu-Daudé
@ 2017-10-03 15:38         ` Igor Mammedov
  0 siblings, 0 replies; 113+ messages in thread
From: Igor Mammedov @ 2017-10-03 15:38 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé; +Cc: ehabkost, qemu-devel

On Tue, 3 Oct 2017 10:29:22 -0300
Philippe Mathieu-Daudé <f4bug@amsat.org> wrote:

> Hi Igor,
> 
> On 10/03/2017 09:14 AM, Igor Mammedov wrote:
> > it will help to remove code duplication in places
> > that currently open code registration of static
> > type[s] and remove necessity to declare function
> > for type_init() to call, when only static types
> > need to be registered.
> > 
> > Signed-off-by: Igor Mammedov <imammedo@redhat.com>
> > ---
> > I'm going to use it for CPU types in followup patches
> > 
> > CC: ehabkost@redhat.com
> > ---
> >  include/qemu/module.h | 10 ++++++++++
> >  include/qom/object.h  | 10 ++++++++++
> >  qom/object.c          |  9 +++++++++
> >  3 files changed, 29 insertions(+)
> > 
> > diff --git a/include/qemu/module.h b/include/qemu/module.h
> > index 56dd218..60dd632 100644
> > --- a/include/qemu/module.h
> > +++ b/include/qemu/module.h
> > @@ -52,6 +52,16 @@ typedef enum {
> >  #define type_init(function) module_init(function, MODULE_INIT_QOM)
> >  #define trace_init(function) module_init(function, MODULE_INIT_TRACE)
> >  
> > +#define REGISTER_STATIC_TYPES(t, nr)                                        \  
> 
> ok
> 
> > +static void do_qemu_init_ ## t(void)                                        \
> > +{                                                                           \
> > +    type_register_static_array(t, nr);                                      \
> > +}                                                                           \
> > +type_init(do_qemu_init_ ## t)
> > +
> > +#define REGISTER_STATIC_TYPE(t)                                             \  
> 
> eh why not...
> 
> What's your plan for your "generalize parsing of cpu_model (2)" series?
> re-post the whole? If you just change this macro you can keep my R-b for it.
It looks like I'll have to amend and repost series.
I'd prefer to keep type_init_from_array() patch for now as it does what's need
and in line with current type_init().
But it seems Eduardo doesn't like it and want's a more generalized way
to handle typeinfo array or single typeinfo.
So most likely I'll end-up keeping *_cpu_register_types() functions and call
type_register_static_array() from there replacing only loops.

> 
> > +    REGISTER_STATIC_TYPES(t, 1)
> > +
> >  #define block_module_load_one(lib) module_load_one("block-", lib)
> >  
> >  void register_module_init(void (*fn)(void), module_init_type type);
> > diff --git a/include/qom/object.h b/include/qom/object.h
> > index f3e5cff..17fcadd 100644
> > --- a/include/qom/object.h
> > +++ b/include/qom/object.h
> > @@ -789,6 +789,16 @@ Type type_register_static(const TypeInfo *info);
> >  Type type_register(const TypeInfo *info);
> >  
> >  /**
> > + * type_register_static_array:
> > + * @infos: The array of the new type #TypeInfo structures.
> > + * @nr_infos: number of entries in @infos
> > + *
> > + * @infos and all of the strings it points to should exist for the life time
> > + * that the type is registered.
> > + */
> > +void type_register_static_array(const TypeInfo *infos, int nr_infos);
> > +
> > +/**
> >   * object_class_dynamic_cast_assert:
> >   * @klass: The #ObjectClass to attempt to cast.
> >   * @typename: The QOM typename of the class to cast to.
> > diff --git a/qom/object.c b/qom/object.c
> > index 3e18537..40b1729 100644
> > --- a/qom/object.c
> > +++ b/qom/object.c
> > @@ -151,6 +151,15 @@ TypeImpl *type_register_static(const TypeInfo *info)
> >      return type_register(info);
> >  }
> >  
> > +void type_register_static_array(const TypeInfo *infos, int nr_infos)
> > +{
> > +    int i;
> > +
> > +    for (i = 0; i < nr_infos; i++) {
> > +        assert(type_register_static(&infos[i]));
> > +    }
> > +}  
> 
> Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
> 
> > +
> >  static TypeImpl *type_get_by_name(const char *name)
> >  {
> >      if (name == NULL) {
> >   
> 

^ permalink raw reply	[flat|nested] 113+ messages in thread

* Re: [Qemu-devel] [PATCH] qom: add helpers REGISTER_STATIC_TYPE[S]()
  2017-10-03 12:14     ` [Qemu-devel] [PATCH] qom: add helpers REGISTER_STATIC_TYPE[S]() Igor Mammedov
  2017-10-03 13:29       ` Philippe Mathieu-Daudé
  2017-10-03 14:25       ` Eduardo Habkost
@ 2017-10-03 15:44       ` Peter Maydell
  2017-10-03 16:41         ` Igor Mammedov
  2 siblings, 1 reply; 113+ messages in thread
From: Peter Maydell @ 2017-10-03 15:44 UTC (permalink / raw)
  To: Igor Mammedov; +Cc: QEMU Developers, Eduardo Habkost

On 3 October 2017 at 13:14, Igor Mammedov <imammedo@redhat.com> wrote:
> it will help to remove code duplication in places
> that currently open code registration of static
> type[s] and remove necessity to declare function
> for type_init() to call, when only static types
> need to be registered.
>
> Signed-off-by: Igor Mammedov <imammedo@redhat.com>
> ---
> I'm going to use it for CPU types in followup patches
>
> CC: ehabkost@redhat.com
> ---
>  include/qemu/module.h | 10 ++++++++++
>  include/qom/object.h  | 10 ++++++++++
>  qom/object.c          |  9 +++++++++
>  3 files changed, 29 insertions(+)
>
> diff --git a/include/qemu/module.h b/include/qemu/module.h
> index 56dd218..60dd632 100644
> --- a/include/qemu/module.h
> +++ b/include/qemu/module.h
> @@ -52,6 +52,16 @@ typedef enum {
>  #define type_init(function) module_init(function, MODULE_INIT_QOM)
>  #define trace_init(function) module_init(function, MODULE_INIT_TRACE)
>
> +#define REGISTER_STATIC_TYPES(t, nr)                                        \
> +static void do_qemu_init_ ## t(void)                                        \
> +{                                                                           \
> +    type_register_static_array(t, nr);                                      \
> +}                                                                           \
> +type_init(do_qemu_init_ ## t)

Could we use
    type_register_static_array(t, ARRAY_SIZE(t));
here to save the caller having to pass the array size,
or is that too magic?

thanks
-- PMM

^ permalink raw reply	[flat|nested] 113+ messages in thread

* Re: [Qemu-devel] [PATCH] qom: add helpers REGISTER_STATIC_TYPE[S]()
  2017-10-03 15:37           ` Eduardo Habkost
@ 2017-10-03 16:37             ` Igor Mammedov
  2017-10-03 18:24               ` Eduardo Habkost
  0 siblings, 1 reply; 113+ messages in thread
From: Igor Mammedov @ 2017-10-03 16:37 UTC (permalink / raw)
  To: Eduardo Habkost; +Cc: qemu-devel, Peter Maydell

On Tue, 3 Oct 2017 12:37:22 -0300
Eduardo Habkost <ehabkost@redhat.com> wrote:

> On Tue, Oct 03, 2017 at 05:01:39PM +0200, Igor Mammedov wrote:
> > On Tue, 3 Oct 2017 11:25:01 -0300
> > Eduardo Habkost <ehabkost@redhat.com> wrote:
> >   
> > > On Tue, Oct 03, 2017 at 02:14:46PM +0200, Igor Mammedov wrote:  
> > > > it will help to remove code duplication in places
> > > > that currently open code registration of static
> > > > type[s] and remove necessity to declare function
> > > > for type_init() to call, when only static types
> > > > need to be registered.
> > > > 
> > > > Signed-off-by: Igor Mammedov <imammedo@redhat.com>
> > > > ---
> > > > I'm going to use it for CPU types in followup patches
> > > > 
> > > > CC: ehabkost@redhat.com
> > > > ---
> > > >  include/qemu/module.h | 10 ++++++++++
> > > >  include/qom/object.h  | 10 ++++++++++
> > > >  qom/object.c          |  9 +++++++++
> > > >  3 files changed, 29 insertions(+)
> > > > 
> > > > diff --git a/include/qemu/module.h b/include/qemu/module.h
> > > > index 56dd218..60dd632 100644
> > > > --- a/include/qemu/module.h
> > > > +++ b/include/qemu/module.h
> > > > @@ -52,6 +52,16 @@ typedef enum {
> > > >  #define type_init(function) module_init(function, MODULE_INIT_QOM)
> > > >  #define trace_init(function) module_init(function, MODULE_INIT_TRACE)
> > > >  
> > > > +#define REGISTER_STATIC_TYPES(t, nr)                                        \    
> > > 
> > > I'm unsure about the name.  We already have a declarative way to
> > > register machine types (DEFINE_MACHINE), maybe use "DEFINE_*" for
> > > consistency?
> > > 
> > > Also, this function won't work if t isn't a static variable, will
> > > it?  The "STATIC" part looks redundant.
> > > 
> > > In other words, how about "DEFINE_TYPE" and "DEFINE_TYPES"?  
> > 'define' word remind me more of declaration but here we actually
> > register types that's why 'register' looks better to me as it says
> > exactly what's going here.  
> 
> Making it look like a declaration and not an action like
> "register" is on purpose, as it's not a function call anymore:
> it's a declaration that will make the type get registered
> automatically.

so if there is no objections I'd respin patch with
 "DEFINE_TYPE" and "DEFINE_TYPES"
that Eduardo suggested and put these into object.h instead of module.h

I also would prefer to drop/postpone "DEFINE_TYPE" till someone takes
on a quest to actually use it.

> 
> >   
> > > 
> > >   
> > > > +static void do_qemu_init_ ## t(void)                                        \
> > > > +{                                                                           \
> > > > +    type_register_static_array(t, nr);                                      \    
> > > 
> > > qemu/module.h doesn't include qom/object.h.  I think this should
> > > go to either qom/object.h or a new header file.  
> > I could move it to qom/object.h
> >   
> > >   
> > > > +}                                                                           \
> > > > +type_init(do_qemu_init_ ## t)
> > > > +
> > > > +#define REGISTER_STATIC_TYPE(t)                                             \
> > > > +    REGISTER_STATIC_TYPES(t, 1)
> > > > +
> > > >  #define block_module_load_one(lib) module_load_one("block-", lib)
> > > >  
> > > >  void register_module_init(void (*fn)(void), module_init_type type);
> > > > diff --git a/include/qom/object.h b/include/qom/object.h
> > > > index f3e5cff..17fcadd 100644
> > > > --- a/include/qom/object.h
> > > > +++ b/include/qom/object.h
> > > > @@ -789,6 +789,16 @@ Type type_register_static(const TypeInfo *info);
> > > >  Type type_register(const TypeInfo *info);
> > > >  
> > > >  /**
> > > > + * type_register_static_array:
> > > > + * @infos: The array of the new type #TypeInfo structures.
> > > > + * @nr_infos: number of entries in @infos
> > > > + *
> > > > + * @infos and all of the strings it points to should exist for the life time
> > > > + * that the type is registered.
> > > > + */
> > > > +void type_register_static_array(const TypeInfo *infos, int nr_infos);    
> > > 
> > > This new function is probably less controversial than the new
> > > module.h-based code.  Maybe worth moving to a separate patch so
> > > it can be merged earlier?
> > > 
> > > (If I were you, I would just use type_register_static_array()
> > > inside the existing *_cpu_register_types() functions by now, so
> > > this won't block the whole series, and worry about
> > > REGISTER_STATIC_TYPE*/DEFINE_TYPE* later.)  
> > it would be nice to have both in one series so that
> > we won't have to touch/rewrite more than once code where
> > static cpu types are registered.
> > 
> > If you prefer I can do what you suggest and keep
> > *_cpu_register_types() functions
> > but I can't promise to return back to cleaning them up
> > or to REGISTER_STATIC_TYPE*/DEFINE_TYPE, so probably
> > someone else will have to pickup that work.  
> 
> No problem to me, if this is left for later.  The macro saves
> only 3 lines of code.
> 
> I think REGISTER_STATIC_TYPE*/DEFINE_TYPE* is a good idea, but
> considering that QOM types are not the only kind of entity we
> register at module_init(), we need to pick a style that can be
> consistently used by other subsystems (e.g. for QemuOpts,
> BlockDrivers, and TraceEvents).  This means this could take a
> little longer to be discussed, and I guess you wouldn't like the
> discussion to block the cleanups in this series.
> 
> >   
> > > > +
> > > > +/**
> > > >   * object_class_dynamic_cast_assert:
> > > >   * @klass: The #ObjectClass to attempt to cast.
> > > >   * @typename: The QOM typename of the class to cast to.
> > > > diff --git a/qom/object.c b/qom/object.c
> > > > index 3e18537..40b1729 100644
> > > > --- a/qom/object.c
> > > > +++ b/qom/object.c
> > > > @@ -151,6 +151,15 @@ TypeImpl *type_register_static(const TypeInfo *info)
> > > >      return type_register(info);
> > > >  }
> > > >  
> > > > +void type_register_static_array(const TypeInfo *infos, int nr_infos)
> > > > +{
> > > > +    int i;
> > > > +
> > > > +    for (i = 0; i < nr_infos; i++) {
> > > > +        assert(type_register_static(&infos[i]));    
> > > 
> > > Why the assert()?  type_register_static() is already guaranteed
> > > to never return NULL.  
> > according to doc comment type_register_static might return 0 on failure
> > so qemu should die in that case.  
> 
> We have absolutely no callers of type_register*() that check its
> return value, and the existing implementation guarantees it will
> never return NULL.  Instead of making
> type_register_static_array() more commplex, we could just update
> the documentation.
> 
> >   
> > > 
> > > This will break if compiled with -DNDEBUG: assert() won't even
> > > evaluate the expression if NDEBUG is defined.
> > >   
> > > > +    }
> > > > +}
> > > > +
> > > >  static TypeImpl *type_get_by_name(const char *name)
> > > >  {
> > > >      if (name == NULL) {
> > > > -- 
> > > > 2.7.4
> > > >     
> > >   
> >   
> 

^ permalink raw reply	[flat|nested] 113+ messages in thread

* Re: [Qemu-devel] [PATCH] qom: add helpers REGISTER_STATIC_TYPE[S]()
  2017-10-03 15:44       ` Peter Maydell
@ 2017-10-03 16:41         ` Igor Mammedov
  0 siblings, 0 replies; 113+ messages in thread
From: Igor Mammedov @ 2017-10-03 16:41 UTC (permalink / raw)
  To: Peter Maydell; +Cc: QEMU Developers, Eduardo Habkost

On Tue, 3 Oct 2017 16:44:28 +0100
Peter Maydell <peter.maydell@linaro.org> wrote:

> On 3 October 2017 at 13:14, Igor Mammedov <imammedo@redhat.com> wrote:
> > it will help to remove code duplication in places
> > that currently open code registration of static
> > type[s] and remove necessity to declare function
> > for type_init() to call, when only static types
> > need to be registered.
> >
> > Signed-off-by: Igor Mammedov <imammedo@redhat.com>
> > ---
> > I'm going to use it for CPU types in followup patches
> >
> > CC: ehabkost@redhat.com
> > ---
> >  include/qemu/module.h | 10 ++++++++++
> >  include/qom/object.h  | 10 ++++++++++
> >  qom/object.c          |  9 +++++++++
> >  3 files changed, 29 insertions(+)
> >
> > diff --git a/include/qemu/module.h b/include/qemu/module.h
> > index 56dd218..60dd632 100644
> > --- a/include/qemu/module.h
> > +++ b/include/qemu/module.h
> > @@ -52,6 +52,16 @@ typedef enum {
> >  #define type_init(function) module_init(function, MODULE_INIT_QOM)
> >  #define trace_init(function) module_init(function, MODULE_INIT_TRACE)
> >
> > +#define REGISTER_STATIC_TYPES(t, nr)                                        \
> > +static void do_qemu_init_ ## t(void)                                        \
> > +{                                                                           \
> > +    type_register_static_array(t, nr);                                      \
> > +}                                                                           \
> > +type_init(do_qemu_init_ ## t)  
> 
> Could we use
>     type_register_static_array(t, ARRAY_SIZE(t));
> here to save the caller having to pass the array size,
> or is that too magic?
+1
this way user will not have to type ARRAY_SIZE(t) and make mistake by chance 

^ permalink raw reply	[flat|nested] 113+ messages in thread

* Re: [Qemu-devel] [PATCH] qom: add helpers REGISTER_STATIC_TYPE[S]()
  2017-10-03 16:37             ` Igor Mammedov
@ 2017-10-03 18:24               ` Eduardo Habkost
  0 siblings, 0 replies; 113+ messages in thread
From: Eduardo Habkost @ 2017-10-03 18:24 UTC (permalink / raw)
  To: Igor Mammedov; +Cc: qemu-devel, Peter Maydell

On Tue, Oct 03, 2017 at 06:37:37PM +0200, Igor Mammedov wrote:
> On Tue, 3 Oct 2017 12:37:22 -0300
> Eduardo Habkost <ehabkost@redhat.com> wrote:
> 
> > On Tue, Oct 03, 2017 at 05:01:39PM +0200, Igor Mammedov wrote:
> > > On Tue, 3 Oct 2017 11:25:01 -0300
> > > Eduardo Habkost <ehabkost@redhat.com> wrote:
> > >   
> > > > On Tue, Oct 03, 2017 at 02:14:46PM +0200, Igor Mammedov wrote:  
> > > > > it will help to remove code duplication in places
> > > > > that currently open code registration of static
> > > > > type[s] and remove necessity to declare function
> > > > > for type_init() to call, when only static types
> > > > > need to be registered.
> > > > > 
> > > > > Signed-off-by: Igor Mammedov <imammedo@redhat.com>
> > > > > ---
> > > > > I'm going to use it for CPU types in followup patches
> > > > > 
> > > > > CC: ehabkost@redhat.com
> > > > > ---
> > > > >  include/qemu/module.h | 10 ++++++++++
> > > > >  include/qom/object.h  | 10 ++++++++++
> > > > >  qom/object.c          |  9 +++++++++
> > > > >  3 files changed, 29 insertions(+)
> > > > > 
> > > > > diff --git a/include/qemu/module.h b/include/qemu/module.h
> > > > > index 56dd218..60dd632 100644
> > > > > --- a/include/qemu/module.h
> > > > > +++ b/include/qemu/module.h
> > > > > @@ -52,6 +52,16 @@ typedef enum {
> > > > >  #define type_init(function) module_init(function, MODULE_INIT_QOM)
> > > > >  #define trace_init(function) module_init(function, MODULE_INIT_TRACE)
> > > > >  
> > > > > +#define REGISTER_STATIC_TYPES(t, nr)                                        \    
> > > > 
> > > > I'm unsure about the name.  We already have a declarative way to
> > > > register machine types (DEFINE_MACHINE), maybe use "DEFINE_*" for
> > > > consistency?
> > > > 
> > > > Also, this function won't work if t isn't a static variable, will
> > > > it?  The "STATIC" part looks redundant.
> > > > 
> > > > In other words, how about "DEFINE_TYPE" and "DEFINE_TYPES"?  
> > > 'define' word remind me more of declaration but here we actually
> > > register types that's why 'register' looks better to me as it says
> > > exactly what's going here.  
> > 
> > Making it look like a declaration and not an action like
> > "register" is on purpose, as it's not a function call anymore:
> > it's a declaration that will make the type get registered
> > automatically.
> 
> so if there is no objections I'd respin patch with
>  "DEFINE_TYPE" and "DEFINE_TYPES"
> that Eduardo suggested and put these into object.h instead of module.h
> 
> I also would prefer to drop/postpone "DEFINE_TYPE" till someone takes
> on a quest to actually use it.

No problem to me.  Missing type_register_static_array() was a
problem, but missing DEFINE_TYPE is not a big deal.

-- 
Eduardo

^ permalink raw reply	[flat|nested] 113+ messages in thread

* [Qemu-devel] [PATCH v2 0/3] add DEFINE_TYPES() helper to simplify batch type registration
  2017-10-02  9:07 ` [Qemu-devel] [PATCH 01/38] qom: add helper type_init_from_array() Igor Mammedov
  2017-10-02 14:15   ` Philippe Mathieu-Daudé
  2017-10-02 19:24   ` Eduardo Habkost
@ 2017-10-04 10:07   ` Igor Mammedov
  2017-10-04 10:08     ` [Qemu-devel] [PATCH v2 1/3] qom: update doc comment for type_register[_static]() Igor Mammedov
                       ` (2 more replies)
  2 siblings, 3 replies; 113+ messages in thread
From: Igor Mammedov @ 2017-10-04 10:07 UTC (permalink / raw)
  To: qemu-devel; +Cc: ehabkost, peter.maydell

following thread '[PATCH 01/38] qom: add helper type_init_from_array()'
here is reworked variant of above patch as Eduardo have suggested
(+ split in several atomic parts)

PS:
posting for early review, I'll wait for a couple of days before reposting whole
series that will use DEFINE_TYPES() to simplify cpu types registration

CC: ehabkost@redhat.com
CC: peter.maydell@linaro.org

Igor Mammedov (3):
  qom: update doc comment for type_register[_static]()
  qom: introduce type_register_static_array()
  qom: add helper macro DEFINE_TYPES()

 include/qom/object.h | 50 ++++++++++++++++++++++++++++++++++++++++++++++++--
 qom/object.c         |  9 +++++++++
 2 files changed, 57 insertions(+), 2 deletions(-)

-- 
2.7.4

^ permalink raw reply	[flat|nested] 113+ messages in thread

* [Qemu-devel] [PATCH v2 1/3] qom: update doc comment for type_register[_static]()
  2017-10-04 10:07   ` [Qemu-devel] [PATCH v2 0/3] add DEFINE_TYPES() helper to simplify batch type registration Igor Mammedov
@ 2017-10-04 10:08     ` Igor Mammedov
  2017-10-04 20:58       ` Eduardo Habkost
  2017-10-04 10:08     ` [Qemu-devel] [PATCH v2 2/3] qom: introduce type_register_static_array() Igor Mammedov
  2017-10-04 10:08     ` [Qemu-devel] [PATCH v2 3/3] qom: add helper macro DEFINE_TYPES() Igor Mammedov
  2 siblings, 1 reply; 113+ messages in thread
From: Igor Mammedov @ 2017-10-04 10:08 UTC (permalink / raw)
  To: qemu-devel; +Cc: ehabkost, peter.maydell

type_register()/type_register_static() functions in current impl.
can't fail returning 0, also none of the users check for error
so update doc comment to reflect current behaviour.

Suggested-by: Eduardo Habkost <ehabkost@redhat.com>
Signed-off-by: Igor Mammedov <imammedo@redhat.com>
---
 include/qom/object.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/include/qom/object.h b/include/qom/object.h
index f3e5cff..76a5e3a 100644
--- a/include/qom/object.h
+++ b/include/qom/object.h
@@ -773,7 +773,7 @@ const char *object_get_typename(const Object *obj);
  * @info and all of the strings it points to should exist for the life time
  * that the type is registered.
  *
- * Returns: 0 on failure, the new #Type on success.
+ * Returns: the new #Type.
  */
 Type type_register_static(const TypeInfo *info);
 
@@ -784,7 +784,7 @@ Type type_register_static(const TypeInfo *info);
  * Unlike type_register_static(), this call does not require @info or its
  * string members to continue to exist after the call returns.
  *
- * Returns: 0 on failure, the new #Type on success.
+ * Returns: the new #Type.
  */
 Type type_register(const TypeInfo *info);
 
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 113+ messages in thread

* [Qemu-devel] [PATCH v2 2/3] qom: introduce type_register_static_array()
  2017-10-04 10:07   ` [Qemu-devel] [PATCH v2 0/3] add DEFINE_TYPES() helper to simplify batch type registration Igor Mammedov
  2017-10-04 10:08     ` [Qemu-devel] [PATCH v2 1/3] qom: update doc comment for type_register[_static]() Igor Mammedov
@ 2017-10-04 10:08     ` Igor Mammedov
  2017-10-04 21:03       ` Eduardo Habkost
  2017-10-05 12:36       ` Philippe Mathieu-Daudé
  2017-10-04 10:08     ` [Qemu-devel] [PATCH v2 3/3] qom: add helper macro DEFINE_TYPES() Igor Mammedov
  2 siblings, 2 replies; 113+ messages in thread
From: Igor Mammedov @ 2017-10-04 10:08 UTC (permalink / raw)
  To: qemu-devel; +Cc: ehabkost, peter.maydell

it will help to remove code duplication of registration
static types in places that have open coded loop to
perform batch type registering.

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
---
 include/qom/object.h | 10 ++++++++++
 qom/object.c         |  9 +++++++++
 2 files changed, 19 insertions(+)

diff --git a/include/qom/object.h b/include/qom/object.h
index 76a5e3a..ce25567 100644
--- a/include/qom/object.h
+++ b/include/qom/object.h
@@ -789,6 +789,16 @@ Type type_register_static(const TypeInfo *info);
 Type type_register(const TypeInfo *info);
 
 /**
+ * type_register_static_array:
+ * @infos: The array of the new type #TypeInfo structures.
+ * @nr_infos: number of entries in @infos
+ *
+ * @infos and all of the strings it points to should exist for the life time
+ * that the type is registered.
+ */
+void type_register_static_array(const TypeInfo *infos, int nr_infos);
+
+/**
  * object_class_dynamic_cast_assert:
  * @klass: The #ObjectClass to attempt to cast.
  * @typename: The QOM typename of the class to cast to.
diff --git a/qom/object.c b/qom/object.c
index 3e18537..f4c377a 100644
--- a/qom/object.c
+++ b/qom/object.c
@@ -151,6 +151,15 @@ TypeImpl *type_register_static(const TypeInfo *info)
     return type_register(info);
 }
 
+void type_register_static_array(const TypeInfo *infos, int nr_infos)
+{
+    int i;
+
+    for (i = 0; i < nr_infos; i++) {
+        type_register_static(&infos[i]);
+    }
+}
+
 static TypeImpl *type_get_by_name(const char *name)
 {
     if (name == NULL) {
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 113+ messages in thread

* [Qemu-devel] [PATCH v2 3/3] qom: add helper macro DEFINE_TYPES()
  2017-10-04 10:07   ` [Qemu-devel] [PATCH v2 0/3] add DEFINE_TYPES() helper to simplify batch type registration Igor Mammedov
  2017-10-04 10:08     ` [Qemu-devel] [PATCH v2 1/3] qom: update doc comment for type_register[_static]() Igor Mammedov
  2017-10-04 10:08     ` [Qemu-devel] [PATCH v2 2/3] qom: introduce type_register_static_array() Igor Mammedov
@ 2017-10-04 10:08     ` Igor Mammedov
  2017-10-04 21:04       ` Eduardo Habkost
  2017-10-05 12:36       ` Philippe Mathieu-Daudé
  2 siblings, 2 replies; 113+ messages in thread
From: Igor Mammedov @ 2017-10-04 10:08 UTC (permalink / raw)
  To: qemu-devel; +Cc: ehabkost, peter.maydell

DEFINE_TYPES() will help to simplify following routine patterns:

 static void foo_register_types(void)
 {
    type_register_static(&foo1_type_info);
    type_register_static(&foo2_type_info);
    ...
 }

 type_init(foo_register_types)

or

 static void foo_register_types(void)
 {
    int i;

    for (i = 0; i < ARRAY_SIZE(type_infos); i++) {
        type_register_static(&type_infos[i]);
    }
 }

 type_init(foo_register_types)

with a single line

 DEFINE_TYPES(type_infos)

where types have static definition which could be consolidated in
a single array of TypeInfo structures.
It saves us ~6-10LOC per use case and would help to replace
imperative foo_register_types() there with declarative style of
type registration.

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
---
 include/qom/object.h | 36 ++++++++++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)

diff --git a/include/qom/object.h b/include/qom/object.h
index ce25567..a615066 100644
--- a/include/qom/object.h
+++ b/include/qom/object.h
@@ -79,6 +79,28 @@ typedef struct InterfaceInfo InterfaceInfo;
  * #TypeInfo describes information about the type including what it inherits
  * from, the instance and class size, and constructor/destructor hooks.
  *
+ * Alternatively several static types could be registered using helper macro
+ * DEFINE_TYPES()
+ *
+ * <example>
+ *   <programlisting>
+ * static const TypeInfo device_types_info[] = {
+ *     {
+ *         .name = TYPE_MY_DEVICE_A,
+ *         .parent = TYPE_DEVICE,
+ *         .instance_size = sizeof(MyDeviceA),
+ *     },
+ *     {
+ *         .name = TYPE_MY_DEVICE_B,
+ *         .parent = TYPE_DEVICE,
+ *         .instance_size = sizeof(MyDeviceB),
+ *     },
+ * };
+ *
+ * DEFINE_TYPES(device_types_info)
+ *   </programlisting>
+ * </example>
+ *
  * Every type has an #ObjectClass associated with it.  #ObjectClass derivatives
  * are instantiated dynamically but there is only ever one instance for any
  * given type.  The #ObjectClass typically holds a table of function pointers
@@ -799,6 +821,20 @@ Type type_register(const TypeInfo *info);
 void type_register_static_array(const TypeInfo *infos, int nr_infos);
 
 /**
+ * DEFINE_TYPES:
+ * @type_array: The array containing #TypeInfo structures to register
+ *
+ * @type_array should be static constant that exists for the life time
+ * that the type is registered.
+ */
+#define DEFINE_TYPES(type_array)                                            \
+static void do_qemu_init_ ## type_array(void)                               \
+{                                                                           \
+    type_register_static_array(type_array, ARRAY_SIZE(type_array));         \
+}                                                                           \
+type_init(do_qemu_init_ ## type_array)
+
+/**
  * object_class_dynamic_cast_assert:
  * @klass: The #ObjectClass to attempt to cast.
  * @typename: The QOM typename of the class to cast to.
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 113+ messages in thread

* Re: [Qemu-devel] [PATCH v2 1/3] qom: update doc comment for type_register[_static]()
  2017-10-04 10:08     ` [Qemu-devel] [PATCH v2 1/3] qom: update doc comment for type_register[_static]() Igor Mammedov
@ 2017-10-04 20:58       ` Eduardo Habkost
  0 siblings, 0 replies; 113+ messages in thread
From: Eduardo Habkost @ 2017-10-04 20:58 UTC (permalink / raw)
  To: Igor Mammedov; +Cc: qemu-devel, peter.maydell

On Wed, Oct 04, 2017 at 12:08:00PM +0200, Igor Mammedov wrote:
> type_register()/type_register_static() functions in current impl.
> can't fail returning 0, also none of the users check for error
> so update doc comment to reflect current behaviour.
> 
> Suggested-by: Eduardo Habkost <ehabkost@redhat.com>
> Signed-off-by: Igor Mammedov <imammedo@redhat.com>

Reviewed-by: Eduardo Habkost <ehabkost@redhat.com>

I'm queueing it on machine-next.

-- 
Eduardo

^ permalink raw reply	[flat|nested] 113+ messages in thread

* Re: [Qemu-devel] [PATCH v2 2/3] qom: introduce type_register_static_array()
  2017-10-04 10:08     ` [Qemu-devel] [PATCH v2 2/3] qom: introduce type_register_static_array() Igor Mammedov
@ 2017-10-04 21:03       ` Eduardo Habkost
  2017-10-05 12:36       ` Philippe Mathieu-Daudé
  1 sibling, 0 replies; 113+ messages in thread
From: Eduardo Habkost @ 2017-10-04 21:03 UTC (permalink / raw)
  To: Igor Mammedov; +Cc: qemu-devel, peter.maydell

On Wed, Oct 04, 2017 at 12:08:01PM +0200, Igor Mammedov wrote:
> it will help to remove code duplication of registration
> static types in places that have open coded loop to
> perform batch type registering.
> 
> Signed-off-by: Igor Mammedov <imammedo@redhat.com>

Reviewed-by: Eduardo Habkost <ehabkost@redhat.com>

I will wait for 1 day or 2 before queueing it.

-- 
Eduardo

^ permalink raw reply	[flat|nested] 113+ messages in thread

* Re: [Qemu-devel] [PATCH v2 3/3] qom: add helper macro DEFINE_TYPES()
  2017-10-04 10:08     ` [Qemu-devel] [PATCH v2 3/3] qom: add helper macro DEFINE_TYPES() Igor Mammedov
@ 2017-10-04 21:04       ` Eduardo Habkost
  2017-10-05  8:10         ` Igor Mammedov
  2017-10-05 12:36       ` Philippe Mathieu-Daudé
  1 sibling, 1 reply; 113+ messages in thread
From: Eduardo Habkost @ 2017-10-04 21:04 UTC (permalink / raw)
  To: Igor Mammedov; +Cc: qemu-devel, peter.maydell

On Wed, Oct 04, 2017 at 12:08:02PM +0200, Igor Mammedov wrote:
> DEFINE_TYPES() will help to simplify following routine patterns:
> 
>  static void foo_register_types(void)
>  {
>     type_register_static(&foo1_type_info);
>     type_register_static(&foo2_type_info);
>     ...
>  }
> 
>  type_init(foo_register_types)
> 
> or
> 
>  static void foo_register_types(void)
>  {
>     int i;
> 
>     for (i = 0; i < ARRAY_SIZE(type_infos); i++) {
>         type_register_static(&type_infos[i]);
>     }
>  }
> 
>  type_init(foo_register_types)
> 
> with a single line
> 
>  DEFINE_TYPES(type_infos)
> 
> where types have static definition which could be consolidated in
> a single array of TypeInfo structures.
> It saves us ~6-10LOC per use case and would help to replace
> imperative foo_register_types() there with declarative style of
> type registration.
> 
> Signed-off-by: Igor Mammedov <imammedo@redhat.com>

Reviewed-by: Eduardo Habkost <ehabkost@redhat.com>

I will wait for 1 day or 2 before queueing it.

-- 
Eduardo

^ permalink raw reply	[flat|nested] 113+ messages in thread

* Re: [Qemu-devel] [PATCH v2 3/3] qom: add helper macro DEFINE_TYPES()
  2017-10-04 21:04       ` Eduardo Habkost
@ 2017-10-05  8:10         ` Igor Mammedov
  0 siblings, 0 replies; 113+ messages in thread
From: Igor Mammedov @ 2017-10-05  8:10 UTC (permalink / raw)
  To: Eduardo Habkost; +Cc: peter.maydell, qemu-devel

On Wed, 4 Oct 2017 18:04:59 -0300
Eduardo Habkost <ehabkost@redhat.com> wrote:

> On Wed, Oct 04, 2017 at 12:08:02PM +0200, Igor Mammedov wrote:
> > DEFINE_TYPES() will help to simplify following routine patterns:
> > 
> >  static void foo_register_types(void)
> >  {
> >     type_register_static(&foo1_type_info);
> >     type_register_static(&foo2_type_info);
> >     ...
> >  }
> > 
> >  type_init(foo_register_types)
> > 
> > or
> > 
> >  static void foo_register_types(void)
> >  {
> >     int i;
> > 
> >     for (i = 0; i < ARRAY_SIZE(type_infos); i++) {
> >         type_register_static(&type_infos[i]);
> >     }
> >  }
> > 
> >  type_init(foo_register_types)
> > 
> > with a single line
> > 
> >  DEFINE_TYPES(type_infos)
> > 
> > where types have static definition which could be consolidated in
> > a single array of TypeInfo structures.
> > It saves us ~6-10LOC per use case and would help to replace
> > imperative foo_register_types() there with declarative style of
> > type registration.
> > 
> > Signed-off-by: Igor Mammedov <imammedo@redhat.com>  
> 
> Reviewed-by: Eduardo Habkost <ehabkost@redhat.com>
> 
> I will wait for 1 day or 2 before queueing it.
Thanks!

I'll respin whole series with amended "foo: cleanup cpu type name composition"
patches due to s/type_init_from_array/DEFINE_TYPES/ change

^ permalink raw reply	[flat|nested] 113+ messages in thread

* Re: [Qemu-devel] [PATCH v2 2/3] qom: introduce type_register_static_array()
  2017-10-04 10:08     ` [Qemu-devel] [PATCH v2 2/3] qom: introduce type_register_static_array() Igor Mammedov
  2017-10-04 21:03       ` Eduardo Habkost
@ 2017-10-05 12:36       ` Philippe Mathieu-Daudé
  1 sibling, 0 replies; 113+ messages in thread
From: Philippe Mathieu-Daudé @ 2017-10-05 12:36 UTC (permalink / raw)
  To: Igor Mammedov, qemu-devel; +Cc: peter.maydell, ehabkost

On 10/04/2017 07:08 AM, Igor Mammedov wrote:
> it will help to remove code duplication of registration
> static types in places that have open coded loop to
> perform batch type registering.
> 
> Signed-off-by: Igor Mammedov <imammedo@redhat.com>

Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>

> ---
>  include/qom/object.h | 10 ++++++++++
>  qom/object.c         |  9 +++++++++
>  2 files changed, 19 insertions(+)
> 
> diff --git a/include/qom/object.h b/include/qom/object.h
> index 76a5e3a..ce25567 100644
> --- a/include/qom/object.h
> +++ b/include/qom/object.h
> @@ -789,6 +789,16 @@ Type type_register_static(const TypeInfo *info);
>  Type type_register(const TypeInfo *info);
>  
>  /**
> + * type_register_static_array:
> + * @infos: The array of the new type #TypeInfo structures.
> + * @nr_infos: number of entries in @infos
> + *
> + * @infos and all of the strings it points to should exist for the life time
> + * that the type is registered.
> + */
> +void type_register_static_array(const TypeInfo *infos, int nr_infos);
> +
> +/**
>   * object_class_dynamic_cast_assert:
>   * @klass: The #ObjectClass to attempt to cast.
>   * @typename: The QOM typename of the class to cast to.
> diff --git a/qom/object.c b/qom/object.c
> index 3e18537..f4c377a 100644
> --- a/qom/object.c
> +++ b/qom/object.c
> @@ -151,6 +151,15 @@ TypeImpl *type_register_static(const TypeInfo *info)
>      return type_register(info);
>  }
>  
> +void type_register_static_array(const TypeInfo *infos, int nr_infos)
> +{
> +    int i;
> +
> +    for (i = 0; i < nr_infos; i++) {
> +        type_register_static(&infos[i]);
> +    }
> +}
> +
>  static TypeImpl *type_get_by_name(const char *name)
>  {
>      if (name == NULL) {
> 

^ permalink raw reply	[flat|nested] 113+ messages in thread

* Re: [Qemu-devel] [PATCH v2 3/3] qom: add helper macro DEFINE_TYPES()
  2017-10-04 10:08     ` [Qemu-devel] [PATCH v2 3/3] qom: add helper macro DEFINE_TYPES() Igor Mammedov
  2017-10-04 21:04       ` Eduardo Habkost
@ 2017-10-05 12:36       ` Philippe Mathieu-Daudé
  1 sibling, 0 replies; 113+ messages in thread
From: Philippe Mathieu-Daudé @ 2017-10-05 12:36 UTC (permalink / raw)
  To: Igor Mammedov, qemu-devel; +Cc: peter.maydell, ehabkost

On 10/04/2017 07:08 AM, Igor Mammedov wrote:
> DEFINE_TYPES() will help to simplify following routine patterns:
> 
>  static void foo_register_types(void)
>  {
>     type_register_static(&foo1_type_info);
>     type_register_static(&foo2_type_info);
>     ...
>  }
> 
>  type_init(foo_register_types)
> 
> or
> 
>  static void foo_register_types(void)
>  {
>     int i;
> 
>     for (i = 0; i < ARRAY_SIZE(type_infos); i++) {
>         type_register_static(&type_infos[i]);
>     }
>  }
> 
>  type_init(foo_register_types)
> 
> with a single line
> 
>  DEFINE_TYPES(type_infos)
> 
> where types have static definition which could be consolidated in
> a single array of TypeInfo structures.
> It saves us ~6-10LOC per use case and would help to replace
> imperative foo_register_types() there with declarative style of
> type registration.
> 
> Signed-off-by: Igor Mammedov <imammedo@redhat.com>

Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>

> ---
>  include/qom/object.h | 36 ++++++++++++++++++++++++++++++++++++
>  1 file changed, 36 insertions(+)
> 
> diff --git a/include/qom/object.h b/include/qom/object.h
> index ce25567..a615066 100644
> --- a/include/qom/object.h
> +++ b/include/qom/object.h
> @@ -79,6 +79,28 @@ typedef struct InterfaceInfo InterfaceInfo;
>   * #TypeInfo describes information about the type including what it inherits
>   * from, the instance and class size, and constructor/destructor hooks.
>   *
> + * Alternatively several static types could be registered using helper macro
> + * DEFINE_TYPES()
> + *
> + * <example>
> + *   <programlisting>
> + * static const TypeInfo device_types_info[] = {
> + *     {
> + *         .name = TYPE_MY_DEVICE_A,
> + *         .parent = TYPE_DEVICE,
> + *         .instance_size = sizeof(MyDeviceA),
> + *     },
> + *     {
> + *         .name = TYPE_MY_DEVICE_B,
> + *         .parent = TYPE_DEVICE,
> + *         .instance_size = sizeof(MyDeviceB),
> + *     },
> + * };
> + *
> + * DEFINE_TYPES(device_types_info)
> + *   </programlisting>
> + * </example>
> + *
>   * Every type has an #ObjectClass associated with it.  #ObjectClass derivatives
>   * are instantiated dynamically but there is only ever one instance for any
>   * given type.  The #ObjectClass typically holds a table of function pointers
> @@ -799,6 +821,20 @@ Type type_register(const TypeInfo *info);
>  void type_register_static_array(const TypeInfo *infos, int nr_infos);
>  
>  /**
> + * DEFINE_TYPES:
> + * @type_array: The array containing #TypeInfo structures to register
> + *
> + * @type_array should be static constant that exists for the life time
> + * that the type is registered.
> + */
> +#define DEFINE_TYPES(type_array)                                            \
> +static void do_qemu_init_ ## type_array(void)                               \
> +{                                                                           \
> +    type_register_static_array(type_array, ARRAY_SIZE(type_array));         \
> +}                                                                           \
> +type_init(do_qemu_init_ ## type_array)
> +
> +/**
>   * object_class_dynamic_cast_assert:
>   * @klass: The #ObjectClass to attempt to cast.
>   * @typename: The QOM typename of the class to cast to.
> 

^ permalink raw reply	[flat|nested] 113+ messages in thread

* Re: [Qemu-devel] [PATCH 17/38] sh4: r2d: use generic cpu_model parsing
  2017-10-02  9:07 ` [Qemu-devel] [PATCH 17/38] sh4: r2d: " Igor Mammedov
@ 2017-10-05 12:37   ` Philippe Mathieu-Daudé
  0 siblings, 0 replies; 113+ messages in thread
From: Philippe Mathieu-Daudé @ 2017-10-05 12:37 UTC (permalink / raw)
  To: Igor Mammedov, qemu-devel; +Cc: Magnus Damm, Aurelien Jarno

On 10/02/2017 06:07 AM, Igor Mammedov wrote:
> Signed-off-by: Igor Mammedov <imammedo@redhat.com>

Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>

> ---
> CC: Magnus Damm <magnus.damm@gmail.com>
> CC: Aurelien Jarno <aurelien@aurel32.net>
> ---
>  hw/sh4/r2d.c | 8 ++------
>  1 file changed, 2 insertions(+), 6 deletions(-)
> 
> diff --git a/hw/sh4/r2d.c b/hw/sh4/r2d.c
> index 16b9ed2..458ed83 100644
> --- a/hw/sh4/r2d.c
> +++ b/hw/sh4/r2d.c
> @@ -225,7 +225,6 @@ static struct QEMU_PACKED
>  
>  static void r2d_init(MachineState *machine)
>  {
> -    const char *cpu_model = machine->cpu_model;
>      const char *kernel_filename = machine->kernel_filename;
>      const char *kernel_cmdline = machine->kernel_cmdline;
>      const char *initrd_filename = machine->initrd_filename;
> @@ -242,11 +241,7 @@ static void r2d_init(MachineState *machine)
>      MemoryRegion *address_space_mem = get_system_memory();
>      PCIBus *pci_bus;
>  
> -    if (cpu_model == NULL) {
> -        cpu_model = "SH7751R";
> -    }
> -
> -    cpu = SUPERH_CPU(cpu_generic_init(TYPE_SUPERH_CPU, cpu_model));
> +    cpu = SUPERH_CPU(cpu_create(machine->cpu_type));
>      env = &cpu->env;
>  
>      reset_info = g_malloc0(sizeof(ResetData));
> @@ -365,6 +360,7 @@ static void r2d_machine_init(MachineClass *mc)
>      mc->desc = "r2d-plus board";
>      mc->init = r2d_init;
>      mc->block_default_type = IF_IDE;
> +    mc->default_cpu_type = TYPE_SH7751R_CPU;
>  }
>  
>  DEFINE_MACHINE("r2d", r2d_machine_init)
> 

^ permalink raw reply	[flat|nested] 113+ messages in thread

* Re: [Qemu-devel] [PATCH 19/38] sh4: cleanup cpu type name composition
  2017-10-02  9:08 ` [Qemu-devel] [PATCH 19/38] sh4: cleanup cpu type name composition Igor Mammedov
@ 2017-10-05 12:39   ` Philippe Mathieu-Daudé
  0 siblings, 0 replies; 113+ messages in thread
From: Philippe Mathieu-Daudé @ 2017-10-05 12:39 UTC (permalink / raw)
  To: Igor Mammedov, qemu-devel; +Cc: aurelien

On 10/02/2017 06:08 AM, Igor Mammedov wrote:
> introduce SUPERH_CPU_TYPE_NAME macro and use it to construct
> cpu type names. While at it move cpu type_infos into one
> array and register it directly with type_init_from_array()
> instead of custom superh_cpu_register_types()
> 
> Signed-off-by: Igor Mammedov <imammedo@redhat.com>

Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>

> ---
> CC: aurelien@aurel32.net
> ---
>  target/sh4/cpu-qom.h |  6 ++---
>  target/sh4/cpu.h     |  3 +++
>  target/sh4/cpu.c     | 63 +++++++++++++++++++++-------------------------------
>  3 files changed, 31 insertions(+), 41 deletions(-)
> 
> diff --git a/target/sh4/cpu-qom.h b/target/sh4/cpu-qom.h
> index 01abb20..17deeb6 100644
> --- a/target/sh4/cpu-qom.h
> +++ b/target/sh4/cpu-qom.h
> @@ -24,9 +24,9 @@
>  
>  #define TYPE_SUPERH_CPU "superh-cpu"
>  
> -#define TYPE_SH7750R_CPU "sh7750r-" TYPE_SUPERH_CPU
> -#define TYPE_SH7751R_CPU "sh7751r-" TYPE_SUPERH_CPU
> -#define TYPE_SH7785_CPU "sh7785-" TYPE_SUPERH_CPU
> +#define TYPE_SH7750R_CPU SUPERH_CPU_TYPE_NAME("sh7750r")
> +#define TYPE_SH7751R_CPU SUPERH_CPU_TYPE_NAME("sh7751r")
> +#define TYPE_SH7785_CPU  SUPERH_CPU_TYPE_NAME("sh7785")
>  
>  #define SUPERH_CPU_CLASS(klass) \
>      OBJECT_CLASS_CHECK(SuperHCPUClass, (klass), TYPE_SUPERH_CPU)
> diff --git a/target/sh4/cpu.h b/target/sh4/cpu.h
> index 79f85d3..a25a3f6 100644
> --- a/target/sh4/cpu.h
> +++ b/target/sh4/cpu.h
> @@ -270,6 +270,9 @@ void cpu_load_tlb(CPUSH4State * env);
>  
>  #define cpu_init(cpu_model) cpu_generic_init(TYPE_SUPERH_CPU, cpu_model)
>  
> +#define SUPERH_CPU_TYPE_SUFFIX "-" TYPE_SUPERH_CPU
> +#define SUPERH_CPU_TYPE_NAME(model) model SUPERH_CPU_TYPE_SUFFIX
> +
>  #define cpu_signal_handler cpu_sh4_signal_handler
>  #define cpu_list sh4_cpu_list
>  
> diff --git a/target/sh4/cpu.c b/target/sh4/cpu.c
> index 252440e..9198460 100644
> --- a/target/sh4/cpu.c
> +++ b/target/sh4/cpu.c
> @@ -172,13 +172,6 @@ static void sh7750r_class_init(ObjectClass *oc, void *data)
>      scc->cvr = 0x00110000;
>  }
>  
> -static const TypeInfo sh7750r_type_info = {
> -    .name = TYPE_SH7750R_CPU,
> -    .parent = TYPE_SUPERH_CPU,
> -    .class_init = sh7750r_class_init,
> -    .instance_init = sh7750r_cpu_initfn,
> -};
> -
>  static void sh7751r_cpu_initfn(Object *obj)
>  {
>      SuperHCPU *cpu = SUPERH_CPU(obj);
> @@ -198,13 +191,6 @@ static void sh7751r_class_init(ObjectClass *oc, void *data)
>      scc->cvr = 0x00110000; /* Neutered caches, should be 0x20480000 */
>  }
>  
> -static const TypeInfo sh7751r_type_info = {
> -    .name = TYPE_SH7751R_CPU,
> -    .parent = TYPE_SUPERH_CPU,
> -    .class_init = sh7751r_class_init,
> -    .instance_init = sh7751r_cpu_initfn,
> -};
> -
>  static void sh7785_cpu_initfn(Object *obj)
>  {
>      SuperHCPU *cpu = SUPERH_CPU(obj);
> @@ -224,13 +210,6 @@ static void sh7785_class_init(ObjectClass *oc, void *data)
>      scc->cvr = 0x71440211;
>  }
>  
> -static const TypeInfo sh7785_type_info = {
> -    .name = TYPE_SH7785_CPU,
> -    .parent = TYPE_SUPERH_CPU,
> -    .class_init = sh7785_class_init,
> -    .instance_init = sh7785_cpu_initfn,
> -};
> -
>  static void superh_cpu_realizefn(DeviceState *dev, Error **errp)
>  {
>      CPUState *cs = CPU(dev);
> @@ -303,22 +282,30 @@ static void superh_cpu_class_init(ObjectClass *oc, void *data)
>      dc->vmsd = &vmstate_sh_cpu;
>  }
>  
> -static const TypeInfo superh_cpu_type_info = {
> -    .name = TYPE_SUPERH_CPU,
> -    .parent = TYPE_CPU,
> -    .instance_size = sizeof(SuperHCPU),
> -    .instance_init = superh_cpu_initfn,
> -    .abstract = true,
> -    .class_size = sizeof(SuperHCPUClass),
> -    .class_init = superh_cpu_class_init,
> -};
> +#define DEFINE_SUPERH_CPU_TYPE(type_name, cinit, initfn) \
> +    {                                                    \
> +        .name = type_name,                               \
> +        .parent = TYPE_SUPERH_CPU,                       \
> +        .class_init = cinit,                             \
> +        .instance_init = initfn,                         \
> +    }
> +static const TypeInfo superh_cpu_type_infos[] = {
> +    {
> +        .name = TYPE_SUPERH_CPU,
> +        .parent = TYPE_CPU,
> +        .instance_size = sizeof(SuperHCPU),
> +        .instance_init = superh_cpu_initfn,
> +        .abstract = true,
> +        .class_size = sizeof(SuperHCPUClass),
> +        .class_init = superh_cpu_class_init,
> +    },
> +    DEFINE_SUPERH_CPU_TYPE(TYPE_SH7750R_CPU, sh7750r_class_init,
> +                           sh7750r_cpu_initfn),
> +    DEFINE_SUPERH_CPU_TYPE(TYPE_SH7751R_CPU, sh7751r_class_init,
> +                           sh7751r_cpu_initfn),
> +    DEFINE_SUPERH_CPU_TYPE(TYPE_SH7785_CPU, sh7785_class_init,
> +                           sh7785_cpu_initfn),
>  
> -static void superh_cpu_register_types(void)
> -{
> -    type_register_static(&superh_cpu_type_info);
> -    type_register_static(&sh7750r_type_info);
> -    type_register_static(&sh7751r_type_info);
> -    type_register_static(&sh7785_type_info);
> -}
> +};
>  
> -type_init(superh_cpu_register_types)
> +type_init_from_array(superh_cpu_type_infos)
> 

^ permalink raw reply	[flat|nested] 113+ messages in thread

* Re: [Qemu-devel] [PATCH 21/38] sh4: remove SuperHCPUClass::name field
  2017-10-02  9:08 ` [Qemu-devel] [PATCH 21/38] sh4: remove SuperHCPUClass::name field Igor Mammedov
@ 2017-10-05 12:42   ` Philippe Mathieu-Daudé
  0 siblings, 0 replies; 113+ messages in thread
From: Philippe Mathieu-Daudé @ 2017-10-05 12:42 UTC (permalink / raw)
  To: Igor Mammedov, qemu-devel; +Cc: aurelien

On 10/02/2017 06:08 AM, Igor Mammedov wrote:
> the field contains upper-cased cpu model name and is used
> for printing supported cpu model names for '-cpu help'.
> 
> Considering that cpu model lookup in superh_cpu_class_by_name()
> is case-insensitive, we can drop upper-casing when
> printing supported cpus list and use cpu type directly
> to do the same by cutting out SUPERH_CPU_TYPE_SUFFIX from
> typename.
> 
> It allows to remove SuperHCPUClass::name, which practically
> duplicates names defined by TYPE_SH*_CPU definitions and
> simplify sh*_class_init()/SuperHCPUClass a bit.
> 
> Signed-off-by: Igor Mammedov <imammedo@redhat.com>

Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>

> ---
> CC: aurelien@aurel32.net
> ---
>  target/sh4/cpu-qom.h |  2 --
>  target/sh4/cpu.c     | 10 +++-------
>  2 files changed, 3 insertions(+), 9 deletions(-)
> 
> diff --git a/target/sh4/cpu-qom.h b/target/sh4/cpu-qom.h
> index 17deeb6..0f9fb4d 100644
> --- a/target/sh4/cpu-qom.h
> +++ b/target/sh4/cpu-qom.h
> @@ -39,7 +39,6 @@
>   * SuperHCPUClass:
>   * @parent_realize: The parent class' realize handler.
>   * @parent_reset: The parent class' reset handler.
> - * @name: The name.
>   * @pvr: Processor Version Register
>   * @prr: Processor Revision Register
>   * @cvr: Cache Version Register
> @@ -54,7 +53,6 @@ typedef struct SuperHCPUClass {
>      DeviceRealize parent_realize;
>      void (*parent_reset)(CPUState *cpu);
>  
> -    const char *name;
>      uint32_t pvr;
>      uint32_t prr;
>      uint32_t cvr;
> diff --git a/target/sh4/cpu.c b/target/sh4/cpu.c
> index b71ff01..8dfbdeb 100644
> --- a/target/sh4/cpu.c
> +++ b/target/sh4/cpu.c
> @@ -98,12 +98,11 @@ static gint superh_cpu_list_compare(gconstpointer a, gconstpointer b)
>  
>  static void superh_cpu_list_entry(gpointer data, gpointer user_data)
>  {
> -    ObjectClass *oc = data;
> -    SuperHCPUClass *scc = SUPERH_CPU_CLASS(oc);
>      SuperHCPUListState *s = user_data;
> +    const char *typename = object_class_get_name(OBJECT_CLASS(data));
> +    int len = strlen(typename) - strlen(SUPERH_CPU_TYPE_SUFFIX);
>  
> -    (*s->cpu_fprintf)(s->file, "%s\n",
> -                      scc->name);
> +    (*s->cpu_fprintf)(s->file, "%.*s\n", len, typename);
>  }
>  
>  void sh4_cpu_list(FILE *f, fprintf_function cpu_fprintf)
> @@ -156,7 +155,6 @@ static void sh7750r_class_init(ObjectClass *oc, void *data)
>  {
>      SuperHCPUClass *scc = SUPERH_CPU_CLASS(oc);
>  
> -    scc->name = "SH7750R";
>      scc->pvr = 0x00050000;
>      scc->prr = 0x00000100;
>      scc->cvr = 0x00110000;
> @@ -175,7 +173,6 @@ static void sh7751r_class_init(ObjectClass *oc, void *data)
>  {
>      SuperHCPUClass *scc = SUPERH_CPU_CLASS(oc);
>  
> -    scc->name = "SH7751R";
>      scc->pvr = 0x04050005;
>      scc->prr = 0x00000113;
>      scc->cvr = 0x00110000; /* Neutered caches, should be 0x20480000 */
> @@ -194,7 +191,6 @@ static void sh7785_class_init(ObjectClass *oc, void *data)
>  {
>      SuperHCPUClass *scc = SUPERH_CPU_CLASS(oc);
>  
> -    scc->name = "SH7785";
>      scc->pvr = 0x10300700;
>      scc->prr = 0x00000200;
>      scc->cvr = 0x71440211;
> 

^ permalink raw reply	[flat|nested] 113+ messages in thread

* Re: [Qemu-devel] [PATCH 18/38] sh4: shix: use generic cpu_model parsing
  2017-10-02  9:08 ` [Qemu-devel] [PATCH 18/38] sh4: shix: " Igor Mammedov
@ 2017-10-05 12:48   ` Philippe Mathieu-Daudé
  0 siblings, 0 replies; 113+ messages in thread
From: Philippe Mathieu-Daudé @ 2017-10-05 12:48 UTC (permalink / raw)
  To: Igor Mammedov, qemu-devel; +Cc: Magnus Damm, Aurelien Jarno

Hi Igor,

On 10/02/2017 06:08 AM, Igor Mammedov wrote:
> Signed-off-by: Igor Mammedov <imammedo@redhat.com>
> ---
> CC: Magnus Damm <magnus.damm@gmail.com>
> CC: Aurelien Jarno <aurelien@aurel32.net>
> ---
>  hw/sh4/shix.c | 7 ++-----
>  1 file changed, 2 insertions(+), 5 deletions(-)
> 
> diff --git a/hw/sh4/shix.c b/hw/sh4/shix.c
> index 50ee36a..4add230 100644
> --- a/hw/sh4/shix.c
> +++ b/hw/sh4/shix.c
> @@ -45,7 +45,6 @@
>  
>  static void shix_init(MachineState *machine)
>  {
> -    const char *cpu_model = machine->cpu_model;
>      int ret;
>      SuperHCPU *cpu;
>      struct SH7750State *s;
> @@ -53,10 +52,7 @@ static void shix_init(MachineState *machine)
>      MemoryRegion *rom = g_new(MemoryRegion, 1);
>      MemoryRegion *sdram = g_new(MemoryRegion, 2);
>      
> -    if (!cpu_model)
> -        cpu_model = "any";
> -
> -    cpu = SUPERH_CPU(cpu_generic_init(TYPE_SUPERH_CPU, cpu_model));
> +    cpu = SUPERH_CPU(cpu_create(machine->cpu_type));
>  
>      /* Allocate memory space */
>      memory_region_init_ram(rom, NULL, "shix.rom", 0x4000, &error_fatal);
> @@ -89,6 +85,7 @@ static void shix_machine_init(MachineClass *mc)
>      mc->desc = "shix card";
>      mc->init = shix_init;
>      mc->is_default = 1;
> +    mc->default_cpu_type = TYPE_SH7750R_CPU;

Maybe worth a comment explaining this.

After checking superh_cpu_class_by_name():
Acked-by: Philippe Mathieu-Daudé <f4bug@amsat.org>

>  }
>  
>  DEFINE_MACHINE("shix", shix_machine_init)
> 

^ permalink raw reply	[flat|nested] 113+ messages in thread

* Re: [Qemu-devel] [PATCH 20/38] sh4: simplify superh_cpu_class_by_name()
  2017-10-02  9:08 ` [Qemu-devel] [PATCH 20/38] sh4: simplify superh_cpu_class_by_name() Igor Mammedov
@ 2017-10-05 12:56   ` Philippe Mathieu-Daudé
  0 siblings, 0 replies; 113+ messages in thread
From: Philippe Mathieu-Daudé @ 2017-10-05 12:56 UTC (permalink / raw)
  To: Igor Mammedov, qemu-devel; +Cc: aurelien

Hi Igor,

On 10/02/2017 06:08 AM, Igor Mammedov wrote:
> currently for sh4 cpu_model argument for '-cpu' option
> could be either 'cpu model' name or cpu_typename.
> 
> however typically '-cpu' takes 'cpu model' name and
> cpu type for sh4 target isn't advertised publicly
> ('-cpu help' prints only 'cpu model' names) so we
> shouldn't care about this use case (it's more of a bug).
> 
> 1. Drop '-cpu cpu_typename' to align with the rest of
>    targets.
> 2. Compose searched for typename from cpu model and use
>    it with object_class_by_name() directly instead of
>    over-complicated
>        object_class_get_list()
>        g_slist_find_custom() + superh_cpu_name_compare()
> 
> With #1 droped, #2 could be used for both lookups which
> simplifies superh_cpu_class_by_name() quite a bit.
> 
> Signed-off-by: Igor Mammedov <imammedo@redhat.com>
> ---
> CC: aurelien@aurel32.net
> ---
>  target/sh4/cpu.c | 36 +++++++++++++-----------------------
>  1 file changed, 13 insertions(+), 23 deletions(-)
> 
> diff --git a/target/sh4/cpu.c b/target/sh4/cpu.c
> index 9198460..b71ff01 100644
> --- a/target/sh4/cpu.c
> +++ b/target/sh4/cpu.c
> @@ -120,36 +120,26 @@ void sh4_cpu_list(FILE *f, fprintf_function cpu_fprintf)
>      g_slist_free(list);
>  }
>  
> -static gint superh_cpu_name_compare(gconstpointer a, gconstpointer b)
> -{
> -    const SuperHCPUClass *scc = SUPERH_CPU_CLASS(a);
> -    const char *name = b;
> -
> -    return strcasecmp(scc->name, name);
> -}
> -
>  static ObjectClass *superh_cpu_class_by_name(const char *cpu_model)
>  {
> -    ObjectClass *oc;
> +    ObjectClass *oc = NULL;;

No need to NULL-initialize (neither double ;) ;)

Acked-by: Philippe Mathieu-Daudé <f4bug@amsat.org>

> -    GSList *list, *item;
> +    char *s, *typename = NULL;
>  
> -    if (strcasecmp(cpu_model, "any") == 0) {
> -        return object_class_by_name(TYPE_SH7750R_CPU);
> +    s = g_ascii_strdown(cpu_model, -1);
> +    if (strcmp(s, "any") == 0) {
> +        oc = object_class_by_name(TYPE_SH7750R_CPU);
> +        goto out;
>      }
>  
> -    oc = object_class_by_name(cpu_model);
> -    if (oc != NULL && object_class_dynamic_cast(oc, TYPE_SUPERH_CPU) != NULL
> -        && !object_class_is_abstract(oc)) {
> -        return oc;
> +    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;
>      }
>  
> -    oc = NULL;
> -    list = object_class_get_list(TYPE_SUPERH_CPU, false);
> -    item = g_slist_find_custom(list, cpu_model, superh_cpu_name_compare);
> -    if (item != NULL) {
> -        oc = item->data;
> -    }
> -    g_slist_free(list);
> +out:
> +    g_free(s);
> +    g_free(typename);
>      return oc;
>  }
>  
> 

^ permalink raw reply	[flat|nested] 113+ messages in thread

end of thread, other threads:[~2017-10-05 12:56 UTC | newest]

Thread overview: 113+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-10-02  9:07 [Qemu-devel] [PATCH 00/38] generalize parsing of cpu_model (part 2) Igor Mammedov
2017-10-02  9:07 ` [Qemu-devel] [PATCH 01/38] qom: add helper type_init_from_array() Igor Mammedov
2017-10-02 14:15   ` Philippe Mathieu-Daudé
2017-10-02 19:24   ` Eduardo Habkost
2017-10-03 12:13     ` Igor Mammedov
2017-10-03 12:14     ` [Qemu-devel] [PATCH] qom: add helpers REGISTER_STATIC_TYPE[S]() Igor Mammedov
2017-10-03 13:29       ` Philippe Mathieu-Daudé
2017-10-03 15:38         ` Igor Mammedov
2017-10-03 14:25       ` Eduardo Habkost
2017-10-03 15:01         ` Igor Mammedov
2017-10-03 15:37           ` Eduardo Habkost
2017-10-03 16:37             ` Igor Mammedov
2017-10-03 18:24               ` Eduardo Habkost
2017-10-03 15:44       ` Peter Maydell
2017-10-03 16:41         ` Igor Mammedov
2017-10-04 10:07   ` [Qemu-devel] [PATCH v2 0/3] add DEFINE_TYPES() helper to simplify batch type registration Igor Mammedov
2017-10-04 10:08     ` [Qemu-devel] [PATCH v2 1/3] qom: update doc comment for type_register[_static]() Igor Mammedov
2017-10-04 20:58       ` Eduardo Habkost
2017-10-04 10:08     ` [Qemu-devel] [PATCH v2 2/3] qom: introduce type_register_static_array() Igor Mammedov
2017-10-04 21:03       ` Eduardo Habkost
2017-10-05 12:36       ` Philippe Mathieu-Daudé
2017-10-04 10:08     ` [Qemu-devel] [PATCH v2 3/3] qom: add helper macro DEFINE_TYPES() Igor Mammedov
2017-10-04 21:04       ` Eduardo Habkost
2017-10-05  8:10         ` Igor Mammedov
2017-10-05 12:36       ` Philippe Mathieu-Daudé
2017-10-02  9:07 ` [Qemu-devel] [PATCH 02/38] alpha: cleanup cpu type name composition Igor Mammedov
2017-10-02 12:01   ` Richard Henderson
2017-10-02 14:46   ` Philippe Mathieu-Daudé
2017-10-02  9:07 ` [Qemu-devel] [PATCH 03/38] alpha: use generic cpu_model parsing Igor Mammedov
2017-10-02 12:01   ` Richard Henderson
2017-10-02 14:46   ` Philippe Mathieu-Daudé
2017-10-02  9:07 ` [Qemu-devel] [PATCH 04/38] cris: cleanup cpu type name composition Igor Mammedov
2017-10-02 14:51   ` Philippe Mathieu-Daudé
2017-10-02 15:03     ` Igor Mammedov
2017-10-02  9:07 ` [Qemu-devel] [PATCH 05/38] cris: use generic cpu_model parsing Igor Mammedov
2017-10-02 14:52   ` Philippe Mathieu-Daudé
2017-10-02  9:07 ` [Qemu-devel] [PATCH 06/38] lm32: cleanup cpu type name composition Igor Mammedov
2017-10-02 20:28   ` Philippe Mathieu-Daudé
2017-10-03 13:00   ` Michael Walle
2017-10-02  9:07 ` [Qemu-devel] [PATCH 07/38] lm32: milkymist: use generic cpu_model parsing Igor Mammedov
2017-10-02 20:28   ` Philippe Mathieu-Daudé
2017-10-03 13:01   ` Michael Walle
2017-10-02  9:07 ` [Qemu-devel] [PATCH 08/38] lm32: lm32_boards: " Igor Mammedov
2017-10-02 20:29   ` Philippe Mathieu-Daudé
2017-10-03 13:01   ` Michael Walle
2017-10-02  9:07 ` [Qemu-devel] [PATCH 09/38] m68k: cleanup cpu type name composition Igor Mammedov
2017-10-03 13:31   ` Philippe Mathieu-Daudé
2017-10-03 14:50   ` Laurent Vivier
2017-10-02  9:07 ` [Qemu-devel] [PATCH 10/38] m68k: an5206: use generic cpu_model parsing Igor Mammedov
2017-10-03  9:13   ` Thomas Huth
2017-10-03 13:31   ` Philippe Mathieu-Daudé
2017-10-03 14:51   ` Laurent Vivier
2017-10-02  9:07 ` [Qemu-devel] [PATCH 11/38] m68k: mcf5208: " Igor Mammedov
2017-10-03  9:28   ` Thomas Huth
2017-10-03 13:32   ` Philippe Mathieu-Daudé
2017-10-03 14:52   ` Laurent Vivier
2017-10-02  9:07 ` [Qemu-devel] [PATCH 12/38] moxie: fix qemu-system-moxie failing to start with CLI "-cpu MoxieLite" Igor Mammedov
2017-10-03 13:37   ` Philippe Mathieu-Daudé
2017-10-02  9:07 ` [Qemu-devel] [PATCH 13/38] moxie: cleanup cpu type name composition Igor Mammedov
2017-10-02 14:54   ` Philippe Mathieu-Daudé
2017-10-02  9:07 ` [Qemu-devel] [PATCH 14/38] moxie: use generic cpu_model parsing Igor Mammedov
2017-10-02 14:13   ` Philippe Mathieu-Daudé
2017-10-02  9:07 ` [Qemu-devel] [PATCH 15/38] openrisc: cleanup cpu type name composition Igor Mammedov
2017-10-02 20:19   ` Philippe Mathieu-Daudé
2017-10-02  9:07 ` [Qemu-devel] [PATCH 16/38] openrisc: use generic cpu_model parsing Igor Mammedov
2017-10-02 20:20   ` Philippe Mathieu-Daudé
2017-10-02  9:07 ` [Qemu-devel] [PATCH 17/38] sh4: r2d: " Igor Mammedov
2017-10-05 12:37   ` Philippe Mathieu-Daudé
2017-10-02  9:08 ` [Qemu-devel] [PATCH 18/38] sh4: shix: " Igor Mammedov
2017-10-05 12:48   ` Philippe Mathieu-Daudé
2017-10-02  9:08 ` [Qemu-devel] [PATCH 19/38] sh4: cleanup cpu type name composition Igor Mammedov
2017-10-05 12:39   ` Philippe Mathieu-Daudé
2017-10-02  9:08 ` [Qemu-devel] [PATCH 20/38] sh4: simplify superh_cpu_class_by_name() Igor Mammedov
2017-10-05 12:56   ` Philippe Mathieu-Daudé
2017-10-02  9:08 ` [Qemu-devel] [PATCH 21/38] sh4: remove SuperHCPUClass::name field Igor Mammedov
2017-10-05 12:42   ` Philippe Mathieu-Daudé
2017-10-02  9:08 ` [Qemu-devel] [PATCH 22/38] xtensa: cleanup cpu type name composition Igor Mammedov
2017-10-02 20:35   ` Philippe Mathieu-Daudé
2017-10-03 10:37     ` Igor Mammedov
2017-10-03 13:33       ` Philippe Mathieu-Daudé
2017-10-02  9:08 ` [Qemu-devel] [PATCH 23/38] xtensa: sim: use generic cpu_model parsing Igor Mammedov
2017-10-03 13:34   ` Philippe Mathieu-Daudé
2017-10-02  9:08 ` [Qemu-devel] [PATCH 24/38] xtensa: lx60/lx200/ml605/kc705: " Igor Mammedov
2017-10-03 13:34   ` Philippe Mathieu-Daudé
2017-10-02  9:08 ` [Qemu-devel] [PATCH 25/38] unicore32: cleanup cpu type name composition Igor Mammedov
2017-10-02 20:18   ` Philippe Mathieu-Daudé
2017-10-02  9:08 ` [Qemu-devel] [PATCH 26/38] unicore32: use generic cpu_model parsing Igor Mammedov
2017-10-02 20:18   ` Philippe Mathieu-Daudé
2017-10-02  9:08 ` [Qemu-devel] [PATCH 27/38] tricore: cleanup cpu type name composition Igor Mammedov
2017-10-02 20:30   ` Philippe Mathieu-Daudé
2017-10-02  9:08 ` [Qemu-devel] [PATCH 28/38] tricore: use generic cpu_model parsing Igor Mammedov
2017-10-02 20:30   ` Philippe Mathieu-Daudé
2017-10-02  9:08 ` [Qemu-devel] [PATCH 29/38] sparc: cleanup cpu type name composition Igor Mammedov
2017-10-02 15:01   ` Philippe Mathieu-Daudé
2017-10-02  9:08 ` [Qemu-devel] [PATCH 30/38] sparc: sun4u/sun4v/niagara: use generic cpu_model parsing Igor Mammedov
2017-10-02 20:16   ` Philippe Mathieu-Daudé
2017-10-02  9:08 ` [Qemu-devel] [PATCH 31/38] sparc: sparc: " Igor Mammedov
2017-10-02 15:02   ` Philippe Mathieu-Daudé
2017-10-02  9:08 ` [Qemu-devel] [PATCH 32/38] sparc: leon3: " Igor Mammedov
2017-10-02 15:54   ` Philippe Mathieu-Daudé
2017-10-02  9:08 ` [Qemu-devel] [PATCH 33/38] mips: use object_new() instead of gnew()+object_initialize() Igor Mammedov
2017-10-02 14:09   ` Philippe Mathieu-Daudé
2017-10-02  9:08 ` [Qemu-devel] [PATCH 34/38] mips: malta/boston: replace cpu_model with cpu_type Igor Mammedov
2017-10-02 14:10   ` Philippe Mathieu-Daudé
2017-10-02  9:08 ` [Qemu-devel] [PATCH 35/38] mips: fulong2e: " Igor Mammedov
2017-10-02 14:11   ` Philippe Mathieu-Daudé
2017-10-02  9:08 ` [Qemu-devel] [PATCH 36/38] mips: Magnum/Acer Pica 61: " Igor Mammedov
2017-10-02 14:11   ` Philippe Mathieu-Daudé
2017-10-03  4:59   ` Hervé Poussineau
2017-10-02  9:08 ` [Qemu-devel] [PATCH 37/38] mips: mipssim: " Igor Mammedov
2017-10-02 14:12   ` Philippe Mathieu-Daudé
2017-10-02  9:08 ` [Qemu-devel] [PATCH 38/38] mips: r4k: " Igor Mammedov
2017-10-02 14:12   ` Philippe Mathieu-Daudé

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.