Re: [Qemu-devel] [RFC PATCH v2.1 08/12] spapr: Add CPU type specific core devices

2016-04-08 Thread Michael Roth
Quoting David Gibson (2016-04-03 19:13:54)
> On Fri, Apr 01, 2016 at 11:42:23AM +0530, Bharata B Rao wrote:
> > On Fri, Apr 01, 2016 at 04:08:44PM +1100, David Gibson wrote:
> > > On Thu, Mar 31, 2016 at 02:09:17PM +0530, Bharata B Rao wrote:
> > > > Introduce core devices for each CPU type supported by sPAPR. These
> > > > core devices are derived from the base spapr-cpu-core device type.
> > > > 
> > > > TODO:
> > > > - Add core types for other remaining CPU types
> > > > - Handle CPU model alias correctly
> > > > 
> > > > Signed-off-by: Bharata B Rao 
> > > > ---
> > > >  hw/ppc/spapr.c  |   3 +-
> > > >  hw/ppc/spapr_cpu_core.c | 118 
> > > > 
> > > >  include/hw/ppc/spapr.h  |   1 +
> > > >  include/hw/ppc/spapr_cpu_core.h |  36 
> > > >  4 files changed, 156 insertions(+), 2 deletions(-)
> > > > 
> > > > diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c
> > > > index 64c4acc..45ac5dc 100644
> > > > --- a/hw/ppc/spapr.c
> > > > +++ b/hw/ppc/spapr.c
> > > > @@ -1614,8 +1614,7 @@ static void spapr_boot_set(void *opaque, const 
> > > > char *boot_device,
> > > >  machine->boot_order = g_strdup(boot_device);
> > > >  }
> > > >  
> > > > -static void spapr_cpu_init(sPAPRMachineState *spapr, PowerPCCPU *cpu,
> > > > -   Error **errp)
> > > > +void spapr_cpu_init(sPAPRMachineState *spapr, PowerPCCPU *cpu, Error 
> > > > **errp)
> > > >  {
> > > >  CPUPPCState *env = >env;
> > > >  
> > > > diff --git a/hw/ppc/spapr_cpu_core.c b/hw/ppc/spapr_cpu_core.c
> > > > index 8cbe2a5..3751a54 100644
> > > > --- a/hw/ppc/spapr_cpu_core.c
> > > > +++ b/hw/ppc/spapr_cpu_core.c
> > > > @@ -22,9 +22,127 @@ static const TypeInfo spapr_cpu_core_type_info = {
> > > >  .instance_size = sizeof(sPAPRCPUCore),
> > > >  };
> > > >  
> > > > +#define DEFINE_SPAPR_CPU_CORE(_name)   
> > > > \
> > > > +static void
> > > > \
> > > > +glue(_name, _spapr_cpu_core_create_threads)(DeviceState *dev, int 
> > > > threads, \
> > > > +Error **errp)  
> > > > \
> > > > +{  
> > > > \
> > > > +int i; 
> > > > \
> > > > +Error *local_err = NULL;   
> > > > \
> > > > +sPAPRCPUCore *sc = SPAPR_CPU_CORE(OBJECT(dev));
> > > > \
> > > > +glue(_name, sPAPRCPUCore) * core = 
> > > > \
> > > > + glue(_name, _SPAPR_CPU_CORE)(OBJECT(dev));
> > > > \
> > > > +   
> > > > \
> > > > +for (i = 0; i < threads; i++) {
> > > > \
> > > > +char id[32];   
> > > > \
> > > > +   
> > > > \
> > > > +object_initialize(>threads[i], sizeof(sc->threads[i]), 
> > > > \
> > > > +  object_class_get_name(core->cpu));   
> > > > \
> > > > +snprintf(id, sizeof(id), "thread[%d]", i); 
> > > > \
> > > > +object_property_add_child(OBJECT(core), id, 
> > > > OBJECT(>threads[i]),   \
> > > > +  _err); 
> > > > \
> > > > +if (local_err) {   
> > > > \
> > > > +goto err;  
> > > > \
> > > > +}  
> > > > \
> > > > +}  
> > > > \
> > > > +return;
> > > > \
> > > > +   
> > > > \
> > > > +err:   
> > > > \
> > > > +while (--i) {  
> > > > \
> > > > +object_unparent(OBJECT(>threads[i]));  
> > > > \
> > > > +}  
> > > > \
> > > > +error_propagate(errp, local_err);  
> > > > \
> > > > +}  
> > > > \
> > > > +   

Re: [Qemu-devel] [RFC PATCH v2.1 08/12] spapr: Add CPU type specific core devices

2016-04-08 Thread Michael Roth
Quoting Bharata B Rao (2016-03-31 03:39:17)
> Introduce core devices for each CPU type supported by sPAPR. These
> core devices are derived from the base spapr-cpu-core device type.
> 
> TODO:
> - Add core types for other remaining CPU types
> - Handle CPU model alias correctly
> 
> Signed-off-by: Bharata B Rao 
> ---
>  hw/ppc/spapr.c  |   3 +-
>  hw/ppc/spapr_cpu_core.c | 118 
> 
>  include/hw/ppc/spapr.h  |   1 +
>  include/hw/ppc/spapr_cpu_core.h |  36 
>  4 files changed, 156 insertions(+), 2 deletions(-)
> 
> diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c
> index 64c4acc..45ac5dc 100644
> --- a/hw/ppc/spapr.c
> +++ b/hw/ppc/spapr.c
> @@ -1614,8 +1614,7 @@ static void spapr_boot_set(void *opaque, const char 
> *boot_device,
>  machine->boot_order = g_strdup(boot_device);
>  }
> 
> -static void spapr_cpu_init(sPAPRMachineState *spapr, PowerPCCPU *cpu,
> -   Error **errp)
> +void spapr_cpu_init(sPAPRMachineState *spapr, PowerPCCPU *cpu, Error **errp)
>  {
>  CPUPPCState *env = >env;
> 
> diff --git a/hw/ppc/spapr_cpu_core.c b/hw/ppc/spapr_cpu_core.c
> index 8cbe2a5..3751a54 100644
> --- a/hw/ppc/spapr_cpu_core.c
> +++ b/hw/ppc/spapr_cpu_core.c
> @@ -22,9 +22,127 @@ static const TypeInfo spapr_cpu_core_type_info = {
>  .instance_size = sizeof(sPAPRCPUCore),
>  };
> 
> +#define DEFINE_SPAPR_CPU_CORE(_name) 
>   \
> +static void  
>   \
> +glue(_name, _spapr_cpu_core_create_threads)(DeviceState *dev, int threads,   
>   \
> +Error **errp)
>   \
> +{
>   \
> +int i;   
>   \
> +Error *local_err = NULL; 
>   \
> +sPAPRCPUCore *sc = SPAPR_CPU_CORE(OBJECT(dev));  
>   \
> +glue(_name, sPAPRCPUCore) * core =   
>   \
> + glue(_name, _SPAPR_CPU_CORE)(OBJECT(dev));  
>   \
> + 
>   \
> +for (i = 0; i < threads; i++) {  
>   \
> +char id[32]; 
>   \
> + 
>   \
> +object_initialize(>threads[i], sizeof(sc->threads[i]),   
>   \
> +  object_class_get_name(core->cpu)); 
>   \
> +snprintf(id, sizeof(id), "thread[%d]", i);   
>   \
> +object_property_add_child(OBJECT(core), id, OBJECT(>threads[i]), 
>   \
> +  _err);   
>   \
> +if (local_err) { 
>   \
> +goto err;
>   \
> +}
>   \
> +}
>   \
> +return;  
>   \
> + 
>   \
> +err: 
>   \
> +while (--i) {
>   \
> +object_unparent(OBJECT(>threads[i]));
>   \
> +}
>   \
> +error_propagate(errp, local_err);
>   \
> +}
>   \
> + 
>   \
> +static int   
>   \
> +glue(_name, _spapr_cpu_core_realize_child)(Object *child, void *opaque)  
>   \
> +{
>   \
> +Error **errp = opaque;   
>   \
> +sPAPRMachineState *spapr = SPAPR_MACHINE(qdev_get_machine());
>   \
> +CPUState *cs = CPU(child);   
>   \
> +PowerPCCPU *cpu = POWERPC_CPU(cs);   
>   \
> + 
>   \
> +object_property_set_bool(child, true, "realized", errp); 
>   \
> +if 

Re: [Qemu-devel] [RFC PATCH v2.1 08/12] spapr: Add CPU type specific core devices

2016-04-03 Thread David Gibson
On Fri, Apr 01, 2016 at 11:42:23AM +0530, Bharata B Rao wrote:
> On Fri, Apr 01, 2016 at 04:08:44PM +1100, David Gibson wrote:
> > On Thu, Mar 31, 2016 at 02:09:17PM +0530, Bharata B Rao wrote:
> > > Introduce core devices for each CPU type supported by sPAPR. These
> > > core devices are derived from the base spapr-cpu-core device type.
> > > 
> > > TODO:
> > > - Add core types for other remaining CPU types
> > > - Handle CPU model alias correctly
> > > 
> > > Signed-off-by: Bharata B Rao 
> > > ---
> > >  hw/ppc/spapr.c  |   3 +-
> > >  hw/ppc/spapr_cpu_core.c | 118 
> > > 
> > >  include/hw/ppc/spapr.h  |   1 +
> > >  include/hw/ppc/spapr_cpu_core.h |  36 
> > >  4 files changed, 156 insertions(+), 2 deletions(-)
> > > 
> > > diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c
> > > index 64c4acc..45ac5dc 100644
> > > --- a/hw/ppc/spapr.c
> > > +++ b/hw/ppc/spapr.c
> > > @@ -1614,8 +1614,7 @@ static void spapr_boot_set(void *opaque, const char 
> > > *boot_device,
> > >  machine->boot_order = g_strdup(boot_device);
> > >  }
> > >  
> > > -static void spapr_cpu_init(sPAPRMachineState *spapr, PowerPCCPU *cpu,
> > > -   Error **errp)
> > > +void spapr_cpu_init(sPAPRMachineState *spapr, PowerPCCPU *cpu, Error 
> > > **errp)
> > >  {
> > >  CPUPPCState *env = >env;
> > >  
> > > diff --git a/hw/ppc/spapr_cpu_core.c b/hw/ppc/spapr_cpu_core.c
> > > index 8cbe2a5..3751a54 100644
> > > --- a/hw/ppc/spapr_cpu_core.c
> > > +++ b/hw/ppc/spapr_cpu_core.c
> > > @@ -22,9 +22,127 @@ static const TypeInfo spapr_cpu_core_type_info = {
> > >  .instance_size = sizeof(sPAPRCPUCore),
> > >  };
> > >  
> > > +#define DEFINE_SPAPR_CPU_CORE(_name) 
> > >   \
> > > +static void  
> > >   \
> > > +glue(_name, _spapr_cpu_core_create_threads)(DeviceState *dev, int 
> > > threads, \
> > > +Error **errp)
> > >   \
> > > +{
> > >   \
> > > +int i;   
> > >   \
> > > +Error *local_err = NULL; 
> > >   \
> > > +sPAPRCPUCore *sc = SPAPR_CPU_CORE(OBJECT(dev));  
> > >   \
> > > +glue(_name, sPAPRCPUCore) * core =   
> > >   \
> > > + glue(_name, _SPAPR_CPU_CORE)(OBJECT(dev));  
> > >   \
> > > + 
> > >   \
> > > +for (i = 0; i < threads; i++) {  
> > >   \
> > > +char id[32]; 
> > >   \
> > > + 
> > >   \
> > > +object_initialize(>threads[i], sizeof(sc->threads[i]),   
> > >   \
> > > +  object_class_get_name(core->cpu)); 
> > >   \
> > > +snprintf(id, sizeof(id), "thread[%d]", i);   
> > >   \
> > > +object_property_add_child(OBJECT(core), id, 
> > > OBJECT(>threads[i]),   \
> > > +  _err);   
> > >   \
> > > +if (local_err) { 
> > >   \
> > > +goto err;
> > >   \
> > > +}
> > >   \
> > > +}
> > >   \
> > > +return;  
> > >   \
> > > + 
> > >   \
> > > +err: 
> > >   \
> > > +while (--i) {
> > >   \
> > > +object_unparent(OBJECT(>threads[i]));
> > >   \
> > > +}
> > >   \
> > > +error_propagate(errp, local_err);
> > >   \
> > > +}
> > >   \
> > > + 
> > >   \
> > > +static int   
> > >   \
> > > +glue(_name, _spapr_cpu_core_realize_child)(Object *child, void *opaque)  
> > >   \
> > > +{

Re: [Qemu-devel] [RFC PATCH v2.1 08/12] spapr: Add CPU type specific core devices

2016-04-03 Thread David Gibson
On Thu, Mar 31, 2016 at 02:09:17PM +0530, Bharata B Rao wrote:
> Introduce core devices for each CPU type supported by sPAPR. These
> core devices are derived from the base spapr-cpu-core device type.
> 
> TODO:
> - Add core types for other remaining CPU types
> - Handle CPU model alias correctly
> 
> Signed-off-by: Bharata B Rao 
> ---
>  hw/ppc/spapr.c  |   3 +-
>  hw/ppc/spapr_cpu_core.c | 118 
> 
>  include/hw/ppc/spapr.h  |   1 +
>  include/hw/ppc/spapr_cpu_core.h |  36 
>  4 files changed, 156 insertions(+), 2 deletions(-)
> 
> diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c
> index 64c4acc..45ac5dc 100644
> --- a/hw/ppc/spapr.c
> +++ b/hw/ppc/spapr.c
> @@ -1614,8 +1614,7 @@ static void spapr_boot_set(void *opaque, const char 
> *boot_device,
>  machine->boot_order = g_strdup(boot_device);
>  }
>  
> -static void spapr_cpu_init(sPAPRMachineState *spapr, PowerPCCPU *cpu,
> -   Error **errp)
> +void spapr_cpu_init(sPAPRMachineState *spapr, PowerPCCPU *cpu, Error **errp)
>  {
>  CPUPPCState *env = >env;
>  
> diff --git a/hw/ppc/spapr_cpu_core.c b/hw/ppc/spapr_cpu_core.c
> index 8cbe2a5..3751a54 100644
> --- a/hw/ppc/spapr_cpu_core.c
> +++ b/hw/ppc/spapr_cpu_core.c
> @@ -22,9 +22,127 @@ static const TypeInfo spapr_cpu_core_type_info = {
>  .instance_size = sizeof(sPAPRCPUCore),
>  };
>  
> +#define DEFINE_SPAPR_CPU_CORE(_name) 
>   \
> +static void  
>   \
> +glue(_name, _spapr_cpu_core_create_threads)(DeviceState *dev, int threads,   
>   \
> +Error **errp)
>   \
> +{
>   \
> +int i;   
>   \
> +Error *local_err = NULL; 
>   \
> +sPAPRCPUCore *sc = SPAPR_CPU_CORE(OBJECT(dev));  
>   \
> +glue(_name, sPAPRCPUCore) * core =   
>   \
> + glue(_name, _SPAPR_CPU_CORE)(OBJECT(dev));  
>   \
> + 
>   \
> +for (i = 0; i < threads; i++) {  
>   \
> +char id[32]; 
>   \
> + 
>   \
> +object_initialize(>threads[i], sizeof(sc->threads[i]),   
>   \
> +  object_class_get_name(core->cpu)); 
>   \
> +snprintf(id, sizeof(id), "thread[%d]", i);   
>   \
> +object_property_add_child(OBJECT(core), id, OBJECT(>threads[i]), 
>   \
> +  _err);   
>   \
> +if (local_err) { 
>   \
> +goto err;
>   \
> +}
>   \
> +}
>   \
> +return;  
>   \
> + 
>   \
> +err: 
>   \
> +while (--i) {
>   \
> +object_unparent(OBJECT(>threads[i]));
>   \
> +}
>   \
> +error_propagate(errp, local_err);
>   \
> +}
>   \
> + 
>   \
> +static int   
>   \
> +glue(_name, _spapr_cpu_core_realize_child)(Object *child, void *opaque)  
>   \
> +{
>   \
> +Error **errp = opaque;   
>   \
> +sPAPRMachineState *spapr = SPAPR_MACHINE(qdev_get_machine());
>   \
> +CPUState *cs = CPU(child);   
>   \
> +PowerPCCPU *cpu = POWERPC_CPU(cs);   
>   \
> + 
>   \
> +object_property_set_bool(child, true, "realized", errp); 

Re: [Qemu-devel] [RFC PATCH v2.1 08/12] spapr: Add CPU type specific core devices

2016-04-01 Thread Bharata B Rao
On Fri, Apr 01, 2016 at 04:08:44PM +1100, David Gibson wrote:
> On Thu, Mar 31, 2016 at 02:09:17PM +0530, Bharata B Rao wrote:
> > Introduce core devices for each CPU type supported by sPAPR. These
> > core devices are derived from the base spapr-cpu-core device type.
> > 
> > TODO:
> > - Add core types for other remaining CPU types
> > - Handle CPU model alias correctly
> > 
> > Signed-off-by: Bharata B Rao 
> > ---
> >  hw/ppc/spapr.c  |   3 +-
> >  hw/ppc/spapr_cpu_core.c | 118 
> > 
> >  include/hw/ppc/spapr.h  |   1 +
> >  include/hw/ppc/spapr_cpu_core.h |  36 
> >  4 files changed, 156 insertions(+), 2 deletions(-)
> > 
> > diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c
> > index 64c4acc..45ac5dc 100644
> > --- a/hw/ppc/spapr.c
> > +++ b/hw/ppc/spapr.c
> > @@ -1614,8 +1614,7 @@ static void spapr_boot_set(void *opaque, const char 
> > *boot_device,
> >  machine->boot_order = g_strdup(boot_device);
> >  }
> >  
> > -static void spapr_cpu_init(sPAPRMachineState *spapr, PowerPCCPU *cpu,
> > -   Error **errp)
> > +void spapr_cpu_init(sPAPRMachineState *spapr, PowerPCCPU *cpu, Error 
> > **errp)
> >  {
> >  CPUPPCState *env = >env;
> >  
> > diff --git a/hw/ppc/spapr_cpu_core.c b/hw/ppc/spapr_cpu_core.c
> > index 8cbe2a5..3751a54 100644
> > --- a/hw/ppc/spapr_cpu_core.c
> > +++ b/hw/ppc/spapr_cpu_core.c
> > @@ -22,9 +22,127 @@ static const TypeInfo spapr_cpu_core_type_info = {
> >  .instance_size = sizeof(sPAPRCPUCore),
> >  };
> >  
> > +#define DEFINE_SPAPR_CPU_CORE(_name)   
> > \
> > +static void
> > \
> > +glue(_name, _spapr_cpu_core_create_threads)(DeviceState *dev, int threads, 
> > \
> > +Error **errp)  
> > \
> > +{  
> > \
> > +int i; 
> > \
> > +Error *local_err = NULL;   
> > \
> > +sPAPRCPUCore *sc = SPAPR_CPU_CORE(OBJECT(dev));
> > \
> > +glue(_name, sPAPRCPUCore) * core = 
> > \
> > + glue(_name, _SPAPR_CPU_CORE)(OBJECT(dev));
> > \
> > +   
> > \
> > +for (i = 0; i < threads; i++) {
> > \
> > +char id[32];   
> > \
> > +   
> > \
> > +object_initialize(>threads[i], sizeof(sc->threads[i]), 
> > \
> > +  object_class_get_name(core->cpu));   
> > \
> > +snprintf(id, sizeof(id), "thread[%d]", i); 
> > \
> > +object_property_add_child(OBJECT(core), id, 
> > OBJECT(>threads[i]),   \
> > +  _err); 
> > \
> > +if (local_err) {   
> > \
> > +goto err;  
> > \
> > +}  
> > \
> > +}  
> > \
> > +return;
> > \
> > +   
> > \
> > +err:   
> > \
> > +while (--i) {  
> > \
> > +object_unparent(OBJECT(>threads[i]));  
> > \
> > +}  
> > \
> > +error_propagate(errp, local_err);  
> > \
> > +}  
> > \
> > +   
> > \
> > +static int 
> > \
> > +glue(_name, _spapr_cpu_core_realize_child)(Object *child, void *opaque)
> > \
> > +{  
> > \
> > +Error **errp = opaque; 
> > \
> > +sPAPRMachineState *spapr = SPAPR_MACHINE(qdev_get_machine());  
> > \
> > +CPUState *cs = CPU(child);   

Re: [Qemu-devel] [RFC PATCH v2.1 08/12] spapr: Add CPU type specific core devices

2016-03-31 Thread David Gibson
On Thu, Mar 31, 2016 at 02:09:17PM +0530, Bharata B Rao wrote:
> Introduce core devices for each CPU type supported by sPAPR. These
> core devices are derived from the base spapr-cpu-core device type.
> 
> TODO:
> - Add core types for other remaining CPU types
> - Handle CPU model alias correctly
> 
> Signed-off-by: Bharata B Rao 
> ---
>  hw/ppc/spapr.c  |   3 +-
>  hw/ppc/spapr_cpu_core.c | 118 
> 
>  include/hw/ppc/spapr.h  |   1 +
>  include/hw/ppc/spapr_cpu_core.h |  36 
>  4 files changed, 156 insertions(+), 2 deletions(-)
> 
> diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c
> index 64c4acc..45ac5dc 100644
> --- a/hw/ppc/spapr.c
> +++ b/hw/ppc/spapr.c
> @@ -1614,8 +1614,7 @@ static void spapr_boot_set(void *opaque, const char 
> *boot_device,
>  machine->boot_order = g_strdup(boot_device);
>  }
>  
> -static void spapr_cpu_init(sPAPRMachineState *spapr, PowerPCCPU *cpu,
> -   Error **errp)
> +void spapr_cpu_init(sPAPRMachineState *spapr, PowerPCCPU *cpu, Error **errp)
>  {
>  CPUPPCState *env = >env;
>  
> diff --git a/hw/ppc/spapr_cpu_core.c b/hw/ppc/spapr_cpu_core.c
> index 8cbe2a5..3751a54 100644
> --- a/hw/ppc/spapr_cpu_core.c
> +++ b/hw/ppc/spapr_cpu_core.c
> @@ -22,9 +22,127 @@ static const TypeInfo spapr_cpu_core_type_info = {
>  .instance_size = sizeof(sPAPRCPUCore),
>  };
>  
> +#define DEFINE_SPAPR_CPU_CORE(_name) 
>   \
> +static void  
>   \
> +glue(_name, _spapr_cpu_core_create_threads)(DeviceState *dev, int threads,   
>   \
> +Error **errp)
>   \
> +{
>   \
> +int i;   
>   \
> +Error *local_err = NULL; 
>   \
> +sPAPRCPUCore *sc = SPAPR_CPU_CORE(OBJECT(dev));  
>   \
> +glue(_name, sPAPRCPUCore) * core =   
>   \
> + glue(_name, _SPAPR_CPU_CORE)(OBJECT(dev));  
>   \
> + 
>   \
> +for (i = 0; i < threads; i++) {  
>   \
> +char id[32]; 
>   \
> + 
>   \
> +object_initialize(>threads[i], sizeof(sc->threads[i]),   
>   \
> +  object_class_get_name(core->cpu)); 
>   \
> +snprintf(id, sizeof(id), "thread[%d]", i);   
>   \
> +object_property_add_child(OBJECT(core), id, OBJECT(>threads[i]), 
>   \
> +  _err);   
>   \
> +if (local_err) { 
>   \
> +goto err;
>   \
> +}
>   \
> +}
>   \
> +return;  
>   \
> + 
>   \
> +err: 
>   \
> +while (--i) {
>   \
> +object_unparent(OBJECT(>threads[i]));
>   \
> +}
>   \
> +error_propagate(errp, local_err);
>   \
> +}
>   \
> + 
>   \
> +static int   
>   \
> +glue(_name, _spapr_cpu_core_realize_child)(Object *child, void *opaque)  
>   \
> +{
>   \
> +Error **errp = opaque;   
>   \
> +sPAPRMachineState *spapr = SPAPR_MACHINE(qdev_get_machine());
>   \
> +CPUState *cs = CPU(child);   
>   \
> +PowerPCCPU *cpu = POWERPC_CPU(cs);   
>   \
> + 
>   \
> +object_property_set_bool(child, true, "realized", errp); 

[Qemu-devel] [RFC PATCH v2.1 08/12] spapr: Add CPU type specific core devices

2016-03-31 Thread Bharata B Rao
Introduce core devices for each CPU type supported by sPAPR. These
core devices are derived from the base spapr-cpu-core device type.

TODO:
- Add core types for other remaining CPU types
- Handle CPU model alias correctly

Signed-off-by: Bharata B Rao 
---
 hw/ppc/spapr.c  |   3 +-
 hw/ppc/spapr_cpu_core.c | 118 
 include/hw/ppc/spapr.h  |   1 +
 include/hw/ppc/spapr_cpu_core.h |  36 
 4 files changed, 156 insertions(+), 2 deletions(-)

diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c
index 64c4acc..45ac5dc 100644
--- a/hw/ppc/spapr.c
+++ b/hw/ppc/spapr.c
@@ -1614,8 +1614,7 @@ static void spapr_boot_set(void *opaque, const char 
*boot_device,
 machine->boot_order = g_strdup(boot_device);
 }
 
-static void spapr_cpu_init(sPAPRMachineState *spapr, PowerPCCPU *cpu,
-   Error **errp)
+void spapr_cpu_init(sPAPRMachineState *spapr, PowerPCCPU *cpu, Error **errp)
 {
 CPUPPCState *env = >env;
 
diff --git a/hw/ppc/spapr_cpu_core.c b/hw/ppc/spapr_cpu_core.c
index 8cbe2a5..3751a54 100644
--- a/hw/ppc/spapr_cpu_core.c
+++ b/hw/ppc/spapr_cpu_core.c
@@ -22,9 +22,127 @@ static const TypeInfo spapr_cpu_core_type_info = {
 .instance_size = sizeof(sPAPRCPUCore),
 };
 
+#define DEFINE_SPAPR_CPU_CORE(_name)   
\
+static void
\
+glue(_name, _spapr_cpu_core_create_threads)(DeviceState *dev, int threads, 
\
+Error **errp)  
\
+{  
\
+int i; 
\
+Error *local_err = NULL;   
\
+sPAPRCPUCore *sc = SPAPR_CPU_CORE(OBJECT(dev));
\
+glue(_name, sPAPRCPUCore) * core = 
\
+ glue(_name, _SPAPR_CPU_CORE)(OBJECT(dev));
\
+   
\
+for (i = 0; i < threads; i++) {
\
+char id[32];   
\
+   
\
+object_initialize(>threads[i], sizeof(sc->threads[i]), 
\
+  object_class_get_name(core->cpu));   
\
+snprintf(id, sizeof(id), "thread[%d]", i); 
\
+object_property_add_child(OBJECT(core), id, OBJECT(>threads[i]),   
\
+  _err); 
\
+if (local_err) {   
\
+goto err;  
\
+}  
\
+}  
\
+return;
\
+   
\
+err:   
\
+while (--i) {  
\
+object_unparent(OBJECT(>threads[i]));  
\
+}  
\
+error_propagate(errp, local_err);  
\
+}  
\
+   
\
+static int 
\
+glue(_name, _spapr_cpu_core_realize_child)(Object *child, void *opaque)
\
+{  
\
+Error **errp = opaque; 
\
+sPAPRMachineState *spapr = SPAPR_MACHINE(qdev_get_machine());  
\
+CPUState *cs = CPU(child); 
\
+PowerPCCPU *cpu = POWERPC_CPU(cs); 
\
+   
\
+object_property_set_bool(child, true, "realized", errp);   
\
+if (*errp) {   
\
+return 1;  
\
+}  
\
+