diff mbox

[v3,4/7] ppc: open code cpu creation for machine types

Message ID 146780723427.26232.10779748351110554240.stgit@bahia.lab.toulouse-stg.fr.ibm.com
State New
Headers show

Commit Message

Greg Kurz July 6, 2016, 12:14 p.m. UTC
If we want to generate cpu_dt_id in the machine code, this must occur
before the cpu gets realized. We must open code the cpu creation to be
able to do this.

This patch just does that.

Signed-off-by: Greg Kurz <groug@kaod.org>
---
v3: don't parse cpu features as it is done in a previous patch
---
 hw/ppc/ppc.c |   32 +++++++++++++++++++++++++++++++-
 1 file changed, 31 insertions(+), 1 deletion(-)

Comments

Greg Kurz July 6, 2016, 4:06 p.m. UTC | #1
On Wed, 06 Jul 2016 14:14:25 +0200
Greg Kurz <groug@kaod.org> wrote:

> If we want to generate cpu_dt_id in the machine code, this must occur
> before the cpu gets realized. We must open code the cpu creation to be
> able to do this.
> 
> This patch just does that.
> 
> Signed-off-by: Greg Kurz <groug@kaod.org>
> ---
> v3: don't parse cpu features as it is done in a previous patch
> ---
>  hw/ppc/ppc.c |   32 +++++++++++++++++++++++++++++++-
>  1 file changed, 31 insertions(+), 1 deletion(-)
> 
> diff --git a/hw/ppc/ppc.c b/hw/ppc/ppc.c
> index 313b3f0b9a51..0df32a9b3965 100644
> --- a/hw/ppc/ppc.c
> +++ b/hw/ppc/ppc.c
> @@ -32,6 +32,7 @@
>  #include "sysemu/cpus.h"
>  #include "hw/timer/m48t59.h"
>  #include "qemu/log.h"
> +#include "qapi/error.h"
>  #include "qemu/error-report.h"
>  #include "qapi/error.h"
>  #include "hw/loader.h"
> @@ -1354,7 +1355,36 @@ PowerPCCPU *ppc_get_vcpu_by_dt_id(int cpu_dt_id)
>  
>  PowerPCCPU *ppc_cpu_init(const char *cpu_model)
>  {
> -    return POWERPC_CPU(cpu_generic_init(TYPE_POWERPC_CPU, cpu_model));
> +    PowerPCCPU *cpu;
> +    ObjectClass *oc;
> +    gchar **model_pieces;
> +    Error *err = NULL;
> +
> +    model_pieces = g_strsplit(cpu_model, ",", 2);
> +    if (!model_pieces[0]) {
> +        error_report("Invalid/empty CPU model name");
> +        return NULL;
> +    }
> +
> +    oc = cpu_class_by_name(TYPE_POWERPC_CPU, model_pieces[0]);
> +    if (oc == NULL) {
> +        error_report("Unable to find CPU definition: %s", model_pieces[0]);
> +        goto out;
> +    }
> +
> +    cpu = POWERPC_CPU(object_new(object_class_get_name(oc)));
> +    object_property_set_bool(OBJECT(cpu), true, "realized", &err);
> +
> +out:
> +    g_strfreev(model_pieces);
> +
> +    if (err != NULL) {
> +        error_report_err(err);
> +        object_unref(OBJECT(cpu));

cpu can be uninitialized here (thanks travis)

I will initialize cpu to NULL and do this:

        if (cpu != NULL) {
            object_unref(OBJECT(cpu));
        }

> +        return NULL;
> +    }
> +
> +    return cpu;
>  }
>  
>  void ppc_cpu_parse_features(const char *cpu_model)
> 
>
David Gibson July 7, 2016, 1:54 a.m. UTC | #2
On Wed, Jul 06, 2016 at 02:14:25PM +0200, Greg Kurz wrote:
> If we want to generate cpu_dt_id in the machine code, this must occur
> before the cpu gets realized. We must open code the cpu creation to be
> able to do this.
> 
> This patch just does that.
> 
> Signed-off-by: Greg Kurz <groug@kaod.org>
> ---
> v3: don't parse cpu features as it is done in a previous patch

Reviewed-by: David Gibson <david@gibson.dropbear.id.au>

> ---
>  hw/ppc/ppc.c |   32 +++++++++++++++++++++++++++++++-
>  1 file changed, 31 insertions(+), 1 deletion(-)
> 
> diff --git a/hw/ppc/ppc.c b/hw/ppc/ppc.c
> index 313b3f0b9a51..0df32a9b3965 100644
> --- a/hw/ppc/ppc.c
> +++ b/hw/ppc/ppc.c
> @@ -32,6 +32,7 @@
>  #include "sysemu/cpus.h"
>  #include "hw/timer/m48t59.h"
>  #include "qemu/log.h"
> +#include "qapi/error.h"
>  #include "qemu/error-report.h"
>  #include "qapi/error.h"
>  #include "hw/loader.h"
> @@ -1354,7 +1355,36 @@ PowerPCCPU *ppc_get_vcpu_by_dt_id(int cpu_dt_id)
>  
>  PowerPCCPU *ppc_cpu_init(const char *cpu_model)
>  {
> -    return POWERPC_CPU(cpu_generic_init(TYPE_POWERPC_CPU, cpu_model));
> +    PowerPCCPU *cpu;
> +    ObjectClass *oc;
> +    gchar **model_pieces;
> +    Error *err = NULL;
> +
> +    model_pieces = g_strsplit(cpu_model, ",", 2);
> +    if (!model_pieces[0]) {
> +        error_report("Invalid/empty CPU model name");
> +        return NULL;
> +    }
> +
> +    oc = cpu_class_by_name(TYPE_POWERPC_CPU, model_pieces[0]);
> +    if (oc == NULL) {
> +        error_report("Unable to find CPU definition: %s", model_pieces[0]);
> +        goto out;
> +    }
> +
> +    cpu = POWERPC_CPU(object_new(object_class_get_name(oc)));
> +    object_property_set_bool(OBJECT(cpu), true, "realized", &err);
> +
> +out:
> +    g_strfreev(model_pieces);
> +
> +    if (err != NULL) {
> +        error_report_err(err);
> +        object_unref(OBJECT(cpu));
> +        return NULL;
> +    }
> +
> +    return cpu;
>  }
>  
>  void ppc_cpu_parse_features(const char *cpu_model)
>
David Gibson July 7, 2016, 1:59 a.m. UTC | #3
On Wed, Jul 06, 2016 at 06:06:16PM +0200, Greg Kurz wrote:
> On Wed, 06 Jul 2016 14:14:25 +0200
> Greg Kurz <groug@kaod.org> wrote:
> 
> > If we want to generate cpu_dt_id in the machine code, this must occur
> > before the cpu gets realized. We must open code the cpu creation to be
> > able to do this.
> > 
> > This patch just does that.
> > 
> > Signed-off-by: Greg Kurz <groug@kaod.org>
> > ---
> > v3: don't parse cpu features as it is done in a previous patch
> > ---
> >  hw/ppc/ppc.c |   32 +++++++++++++++++++++++++++++++-
> >  1 file changed, 31 insertions(+), 1 deletion(-)
> > 
> > diff --git a/hw/ppc/ppc.c b/hw/ppc/ppc.c
> > index 313b3f0b9a51..0df32a9b3965 100644
> > --- a/hw/ppc/ppc.c
> > +++ b/hw/ppc/ppc.c
> > @@ -32,6 +32,7 @@
> >  #include "sysemu/cpus.h"
> >  #include "hw/timer/m48t59.h"
> >  #include "qemu/log.h"
> > +#include "qapi/error.h"
> >  #include "qemu/error-report.h"
> >  #include "qapi/error.h"
> >  #include "hw/loader.h"
> > @@ -1354,7 +1355,36 @@ PowerPCCPU *ppc_get_vcpu_by_dt_id(int cpu_dt_id)
> >  
> >  PowerPCCPU *ppc_cpu_init(const char *cpu_model)
> >  {
> > -    return POWERPC_CPU(cpu_generic_init(TYPE_POWERPC_CPU, cpu_model));
> > +    PowerPCCPU *cpu;
> > +    ObjectClass *oc;
> > +    gchar **model_pieces;
> > +    Error *err = NULL;
> > +
> > +    model_pieces = g_strsplit(cpu_model, ",", 2);
> > +    if (!model_pieces[0]) {
> > +        error_report("Invalid/empty CPU model name");
> > +        return NULL;
> > +    }
> > +
> > +    oc = cpu_class_by_name(TYPE_POWERPC_CPU, model_pieces[0]);
> > +    if (oc == NULL) {
> > +        error_report("Unable to find CPU definition: %s", model_pieces[0]);
> > +        goto out;
> > +    }
> > +
> > +    cpu = POWERPC_CPU(object_new(object_class_get_name(oc)));
> > +    object_property_set_bool(OBJECT(cpu), true, "realized", &err);
> > +
> > +out:
> > +    g_strfreev(model_pieces);
> > +
> > +    if (err != NULL) {
> > +        error_report_err(err);
> > +        object_unref(OBJECT(cpu));
> 
> cpu can be uninitialized here (thanks travis)
> 
> I will initialize cpu to NULL and do this:
> 
>         if (cpu != NULL) {
>             object_unref(OBJECT(cpu));
>         }

Good catch.

> > +        return NULL;
> > +    }
> > +
> > +    return cpu;
> >  }
> >  
> >  void ppc_cpu_parse_features(const char *cpu_model)
> > 
> > 
>
diff mbox

Patch

diff --git a/hw/ppc/ppc.c b/hw/ppc/ppc.c
index 313b3f0b9a51..0df32a9b3965 100644
--- a/hw/ppc/ppc.c
+++ b/hw/ppc/ppc.c
@@ -32,6 +32,7 @@ 
 #include "sysemu/cpus.h"
 #include "hw/timer/m48t59.h"
 #include "qemu/log.h"
+#include "qapi/error.h"
 #include "qemu/error-report.h"
 #include "qapi/error.h"
 #include "hw/loader.h"
@@ -1354,7 +1355,36 @@  PowerPCCPU *ppc_get_vcpu_by_dt_id(int cpu_dt_id)
 
 PowerPCCPU *ppc_cpu_init(const char *cpu_model)
 {
-    return POWERPC_CPU(cpu_generic_init(TYPE_POWERPC_CPU, cpu_model));
+    PowerPCCPU *cpu;
+    ObjectClass *oc;
+    gchar **model_pieces;
+    Error *err = NULL;
+
+    model_pieces = g_strsplit(cpu_model, ",", 2);
+    if (!model_pieces[0]) {
+        error_report("Invalid/empty CPU model name");
+        return NULL;
+    }
+
+    oc = cpu_class_by_name(TYPE_POWERPC_CPU, model_pieces[0]);
+    if (oc == NULL) {
+        error_report("Unable to find CPU definition: %s", model_pieces[0]);
+        goto out;
+    }
+
+    cpu = POWERPC_CPU(object_new(object_class_get_name(oc)));
+    object_property_set_bool(OBJECT(cpu), true, "realized", &err);
+
+out:
+    g_strfreev(model_pieces);
+
+    if (err != NULL) {
+        error_report_err(err);
+        object_unref(OBJECT(cpu));
+        return NULL;
+    }
+
+    return cpu;
 }
 
 void ppc_cpu_parse_features(const char *cpu_model)