diff mbox series

[v2,21/24] ppc: pnv: drop PnvCoreClass::cpu_oc field

Message ID 1507578671-158758-22-git-send-email-imammedo@redhat.com
State New
Headers show
Series generalize parsing of cpu_model (part 3/PPC) | expand

Commit Message

Igor Mammedov Oct. 9, 2017, 7:51 p.m. UTC
deduce cpu type directly from core type instead of
maintaining type mapping in PnvCoreClass::cpu_oc and doing
extra cpu_model parsing in pnv_core_class_init()

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
---
v2:
  - fix typo: s/pvn_core_cpu_typename/pnv_core_cpu_typename/
---
 include/hw/ppc/pnv_core.h |  1 -
 hw/ppc/pnv_core.c         | 18 ++++++++++++------
 2 files changed, 12 insertions(+), 7 deletions(-)

Comments

Philippe Mathieu-Daudé Oct. 11, 2017, 5:24 p.m. UTC | #1
On 10/09/2017 04:51 PM, Igor Mammedov wrote:
> deduce cpu type directly from core type instead of
> maintaining type mapping in PnvCoreClass::cpu_oc and doing
> extra cpu_model parsing in pnv_core_class_init()
> 
> Signed-off-by: Igor Mammedov <imammedo@redhat.com>

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

> ---
> v2:
>   - fix typo: s/pvn_core_cpu_typename/pnv_core_cpu_typename/
> ---
>  include/hw/ppc/pnv_core.h |  1 -
>  hw/ppc/pnv_core.c         | 18 ++++++++++++------
>  2 files changed, 12 insertions(+), 7 deletions(-)
> 
> diff --git a/include/hw/ppc/pnv_core.h b/include/hw/ppc/pnv_core.h
> index 3360c4b..a336a1f 100644
> --- a/include/hw/ppc/pnv_core.h
> +++ b/include/hw/ppc/pnv_core.h
> @@ -42,7 +42,6 @@ typedef struct PnvCore {
>  
>  typedef struct PnvCoreClass {
>      DeviceClass parent_class;
> -    ObjectClass *cpu_oc;
>  } PnvCoreClass;
>  
>  #define PNV_CORE_TYPE_SUFFIX "-" TYPE_PNV_CORE
> diff --git a/hw/ppc/pnv_core.c b/hw/ppc/pnv_core.c
> index b3e3f23..bd7f2c9 100644
> --- a/hw/ppc/pnv_core.c
> +++ b/hw/ppc/pnv_core.c
> @@ -27,6 +27,16 @@
>  #include "hw/ppc/pnv_xscom.h"
>  #include "hw/ppc/xics.h"
>  
> +static const char *pnv_core_cpu_typename(PnvCore *pc)
> +{
> +    const char *core_type = object_class_get_name(object_get_class(OBJECT(pc)));
> +    int len = strlen(core_type) - strlen(PNV_CORE_TYPE_SUFFIX);
> +    char *s = g_strdup_printf(POWERPC_CPU_TYPE_NAME("%.*s"), len, core_type);
> +    const char *cpu_type = object_class_get_name(object_class_by_name(s));
> +    g_free(s);
> +    return cpu_type;
> +}
> +
>  static void powernv_cpu_reset(void *opaque)
>  {
>      PowerPCCPU *cpu = opaque;
> @@ -148,8 +158,7 @@ static void pnv_core_realize(DeviceState *dev, Error **errp)
>  {
>      PnvCore *pc = PNV_CORE(OBJECT(dev));
>      CPUCore *cc = CPU_CORE(OBJECT(dev));
> -    PnvCoreClass *pcc = PNV_CORE_GET_CLASS(OBJECT(dev));
> -    const char *typename = object_class_get_name(pcc->cpu_oc);
> +    const char *typename = pnv_core_cpu_typename(pc);
>      size_t size = object_type_get_instance_size(typename);
>      Error *local_err = NULL;
>      void *obj;
> @@ -211,11 +220,9 @@ static Property pnv_core_properties[] = {
>  static void pnv_core_class_init(ObjectClass *oc, void *data)
>  {
>      DeviceClass *dc = DEVICE_CLASS(oc);
> -    PnvCoreClass *pcc = PNV_CORE_CLASS(oc);
>  
>      dc->realize = pnv_core_realize;
>      dc->props = pnv_core_properties;
> -    pcc->cpu_oc = cpu_class_by_name(TYPE_POWERPC_CPU, data);
>  }
>  
>  static const TypeInfo pnv_core_info = {
> @@ -223,6 +230,7 @@ static const TypeInfo pnv_core_info = {
>      .parent         = TYPE_CPU_CORE,
>      .instance_size  = sizeof(PnvCore),
>      .class_size     = sizeof(PnvCoreClass),
> +    .class_init = pnv_core_class_init,
>      .abstract       = true,
>  };
>  
> @@ -239,8 +247,6 @@ static void pnv_core_register_types(void)
>          TypeInfo ti = {
>              .parent = TYPE_PNV_CORE,
>              .instance_size = sizeof(PnvCore),
> -            .class_init = pnv_core_class_init,
> -            .class_data = (void *) pnv_core_models[i],
>          };
>          ti.name = pnv_core_typename(pnv_core_models[i]);
>          type_register(&ti);
>
diff mbox series

Patch

diff --git a/include/hw/ppc/pnv_core.h b/include/hw/ppc/pnv_core.h
index 3360c4b..a336a1f 100644
--- a/include/hw/ppc/pnv_core.h
+++ b/include/hw/ppc/pnv_core.h
@@ -42,7 +42,6 @@  typedef struct PnvCore {
 
 typedef struct PnvCoreClass {
     DeviceClass parent_class;
-    ObjectClass *cpu_oc;
 } PnvCoreClass;
 
 #define PNV_CORE_TYPE_SUFFIX "-" TYPE_PNV_CORE
diff --git a/hw/ppc/pnv_core.c b/hw/ppc/pnv_core.c
index b3e3f23..bd7f2c9 100644
--- a/hw/ppc/pnv_core.c
+++ b/hw/ppc/pnv_core.c
@@ -27,6 +27,16 @@ 
 #include "hw/ppc/pnv_xscom.h"
 #include "hw/ppc/xics.h"
 
+static const char *pnv_core_cpu_typename(PnvCore *pc)
+{
+    const char *core_type = object_class_get_name(object_get_class(OBJECT(pc)));
+    int len = strlen(core_type) - strlen(PNV_CORE_TYPE_SUFFIX);
+    char *s = g_strdup_printf(POWERPC_CPU_TYPE_NAME("%.*s"), len, core_type);
+    const char *cpu_type = object_class_get_name(object_class_by_name(s));
+    g_free(s);
+    return cpu_type;
+}
+
 static void powernv_cpu_reset(void *opaque)
 {
     PowerPCCPU *cpu = opaque;
@@ -148,8 +158,7 @@  static void pnv_core_realize(DeviceState *dev, Error **errp)
 {
     PnvCore *pc = PNV_CORE(OBJECT(dev));
     CPUCore *cc = CPU_CORE(OBJECT(dev));
-    PnvCoreClass *pcc = PNV_CORE_GET_CLASS(OBJECT(dev));
-    const char *typename = object_class_get_name(pcc->cpu_oc);
+    const char *typename = pnv_core_cpu_typename(pc);
     size_t size = object_type_get_instance_size(typename);
     Error *local_err = NULL;
     void *obj;
@@ -211,11 +220,9 @@  static Property pnv_core_properties[] = {
 static void pnv_core_class_init(ObjectClass *oc, void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(oc);
-    PnvCoreClass *pcc = PNV_CORE_CLASS(oc);
 
     dc->realize = pnv_core_realize;
     dc->props = pnv_core_properties;
-    pcc->cpu_oc = cpu_class_by_name(TYPE_POWERPC_CPU, data);
 }
 
 static const TypeInfo pnv_core_info = {
@@ -223,6 +230,7 @@  static const TypeInfo pnv_core_info = {
     .parent         = TYPE_CPU_CORE,
     .instance_size  = sizeof(PnvCore),
     .class_size     = sizeof(PnvCoreClass),
+    .class_init = pnv_core_class_init,
     .abstract       = true,
 };
 
@@ -239,8 +247,6 @@  static void pnv_core_register_types(void)
         TypeInfo ti = {
             .parent = TYPE_PNV_CORE,
             .instance_size = sizeof(PnvCore),
-            .class_init = pnv_core_class_init,
-            .class_data = (void *) pnv_core_models[i],
         };
         ti.name = pnv_core_typename(pnv_core_models[i]);
         type_register(&ti);