ppc: QOM'ify openpic device
cover ppc: QOM'ify openpic device
Hi Alex,
Here's another mini-series cleaning up and converting the original OpenPIC device.
Regards,
Andreas
Andreas Färber (2):
intc/openpic: QOM'ify
intc/openpic: Convert to QOM realize
hw/intc/openpic.c | 49 ++++++++++++++++++++++++++++-------------------- hw/ppc/e500.c | 2 +- hw/ppc/mac_newworld.c | 2 +- include/hw/ppc/openpic.h | 2 ++ 4 files changed, 33 insertions(+), 22 deletions(-)
Signature · 1 line
1.8.1.4
PATCH 1/2 intc/openpic: QOM'ify
Introduce type constant and cast macro.
--- hw/intc/openpic.c | 17 +++++++++++------ hw/ppc/e500.c | 2 +- hw/ppc/mac_newworld.c | 2 +- include/hw/ppc/openpic.h | 2 ++ 4 files changed, 15 insertions(+), 8 deletions(-)
hw/intc/openpic.c +11 -6
@@ -255,8 +255,13 @@ typedef struct IRQDest {uint32_t outputs_active[OPENPIC_OUTPUT_NB ]; } IRQDest; +#define OPENPIC (obj) OBJECT_CHECK(OpenPICState, (obj), TYPE_OPENPIC) + typedef struct OpenPICState { - SysBusDevice busdev; + /*< private >*/ + SysBusDevice parent_obj; + /*< public >*/ + MemoryRegion mem; /* Behavior control */
@@ -537,7 +542,7 @@ static void openpic_set_irq(void *opaque, int n_IRQ, int level)static void openpic_reset (DeviceState *d) { -OpenPICState *opp =FROM_SYSBUS (typeof (*opp),SYS_BUS_DEVICE (d)); +OpenPICState *opp =OPENPIC (d);int i; opp->gcr =GCR_RESET ;
@@ -703,7 +708,7 @@ static void openpic_gcr_write(OpenPICState *opp, uint64_t val)bool mpic_proxy = false;if (val &GCR_RESET ) { -openpic_reset (&opp->busdev.qdev); +openpic_reset (DEVICE (opp));return ; }
@@ -1528,7 +1533,7 @@ static void map_list(OpenPICState *opp, const MemReg *list, int *count)static int openpic_init (SysBusDevice *dev) { -OpenPICState *opp =FROM_SYSBUS (typeof (*opp), dev); +OpenPICState *opp =OPENPIC (dev);int i, j;int list_count =0 ;static const MemReg list_le[] = {
@@ -1621,7 +1626,7 @@ static int openpic_init(SysBusDevice *dev) } } -register_savevm (&opp->busdev.qdev,"openpic" ,0 ,2 , +register_savevm (DEVICE (opp),"openpic" ,0 ,2 , openpic_save, openpic_load, opp);sysbus_init_mmio (dev, &opp->mem);
@@ -1647,7 +1652,7 @@ static void openpic_class_init(ObjectClass *klass, void *data) }static const TypeInfo openpic_info = { - .name ="openpic" , + .name =TYPE_OPENPIC , .parent =TYPE_SYS_BUS_DEVICE , .instance_size =sizeof (OpenPICState), .class_init = openpic_class_init,
hw/ppc/e500.c +1 -1
@@ -565,7 +565,7 @@ void ppce500_init(PPCE500Params *params)/* MPIC */ mpic =g_new (qemu_irq,256 ); - dev =qdev_create (NULL ,"openpic" ); + dev =qdev_create (NULL ,TYPE_OPENPIC );qdev_prop_set_uint32 (dev,"nb_cpus" , smp_cpus);qdev_prop_set_uint32 (dev,"model" , params->mpic_version);qdev_init_nofail (dev);
hw/ppc/mac_newworld.c +1 -1
@@ -329,7 +329,7 @@ static void ppc_core99_init(QEMUMachineInitArgs *args) pic =g_new (qemu_irq,64 ); - dev =qdev_create (NULL ,"openpic" ); + dev =qdev_create (NULL ,TYPE_OPENPIC );qdev_prop_set_uint32 (dev,"model" ,OPENPIC_MODEL_RAVEN );qdev_init_nofail (dev); s =SYS_BUS_DEVICE (dev);
include/hw/ppc/openpic.h +2 -0
@@ -1,6 +1,8 @@#if !defined(__OPENPIC_H__)#define __OPENPIC_H__ +#define TYPE_OPENPIC "openpic" +/* OpenPIC have 5 outputs per CPU connected and one IRQ out single output */ enum { OPENPIC_OUTPUT_INT = 0, /* IRQ */
Signature · 1 line
1.8.1.4
PATCH 2/2 intc/openpic: Convert to QOM realize
In reply to Andreas FärberSplit qdev initfn into instance_init and realize functions. Change one occurrence of "klass" while at it.
--- hw/intc/openpic.c | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-)
hw/intc/openpic.c +19 -15
@@ -1531,8 +1531,16 @@ static void map_list(OpenPICState *opp, const MemReg *list, int *count) } } -static int openpic_init (SysBusDevice *dev) +static void openpic_init (Object *obj) { +OpenPICState *opp =OPENPIC (obj); + +memory_region_init (&opp->mem,"openpic" ,0x40000 ); +} + +static void openpic_realize (DeviceState *dev,Error **errp) +{ +SysBusDevice *d =SYS_BUS_DEVICE (dev);OpenPICState *opp =OPENPIC (dev);int i, j;int list_count =0 ;
@@ -1566,8 +1574,6 @@ static int openpic_init(SysBusDevice *dev) {NULL} }; -memory_region_init (&opp->mem,"openpic" ,0x40000 ); -switch (opp->model) {case OPENPIC_MODEL_FSL_MPIC_20 :default :
@@ -1610,9 +1616,9 @@ static int openpic_init(SysBusDevice *dev) opp->brr1 =-1 ; opp->mpic_mode_mask =GCR_MODE_MIXED ; -/* Only UP supported today */ if (opp->nb_cpus !=1 ) { -return -EINVAL ; +error_setg (errp,"Only UP supported today" ); +return ; }map_list (opp, list_le, &list_count);
@@ -1622,17 +1628,15 @@ static int openpic_init(SysBusDevice *dev)for (i =0 ; i < opp->nb_cpus; i++) { opp->dst[i].irqs =g_new (qemu_irq,OPENPIC_OUTPUT_NB );for (j =0 ; j <OPENPIC_OUTPUT_NB ; j++) { -sysbus_init_irq (dev, &opp->dst[i].irqs[j]); +sysbus_init_irq (d, &opp->dst[i].irqs[j]); } } -register_savevm (DEVICE (opp),"openpic" ,0 ,2 , +register_savevm (dev,"openpic" ,0 ,2 , openpic_save, openpic_load, opp); -sysbus_init_mmio (dev, &opp->mem); -qdev_init_gpio_in (&dev->qdev, openpic_set_irq, opp->max_irq); - -return 0 ; +sysbus_init_mmio (d, &opp->mem); +qdev_init_gpio_in (dev, openpic_set_irq, opp->max_irq); }static Property openpic_properties[] = {
@@ -1641,12 +1645,11 @@ static Property openpic_properties[] = { DEFINE_PROP_END_OF_LIST(), }; -static void openpic_class_init (ObjectClass *klass,void *data) +static void openpic_class_init (ObjectClass *oc,void *data) { -DeviceClass *dc =DEVICE_CLASS (klass); -SysBusDeviceClass *k =SYS_BUS_DEVICE_CLASS (klass); +DeviceClass *dc =DEVICE_CLASS (oc); - k->init = openpic_init; + dc->realize = openpic_realize; dc->props = openpic_properties; dc->reset = openpic_reset; }
@@ -1655,6 +1658,7 @@ static const TypeInfo openpic_info = { .name = TYPE_OPENPIC, .parent = TYPE_SYS_BUS_DEVICE, .instance_size = sizeof(OpenPICState), + .instance_init = openpic_init, .class_init = openpic_class_init, };
Signature · 1 line
1.8.1.4
Re: [Qemu-devel] [PATCH 1/2] intc/openpic: QOM'ify
In reply to Andreas FärberQuoted 3 lines · Andreas Färber
Introduce type constant and cast macro.
Signed-off-by Andreas Färber <[email protected]>
Quoted 114 lines
--- hw/intc/openpic.c | 17 +++++++++++------ hw/ppc/e500.c | 2 +- hw/ppc/mac_newworld.c | 2 +- include/hw/ppc/openpic.h | 2 ++ 4 files changed, 15 insertions(+), 8 deletions(-)hw/intc/openpic.c +11
-6@@ -255,8 +255,13 @@ typedef struct IRQDest {uint32_t outputs_active[OPENPIC_OUTPUT_NB ]; } IRQDest; +#define OPENPIC (obj) OBJECT_CHECK(OpenPICState, (obj), TYPE_OPENPIC) + typedef struct OpenPICState { - SysBusDevice busdev; + /*< private >*/ + SysBusDevice parent_obj; + /*< public >*/ + MemoryRegion mem; /* Behavior control */@@ -537,7 +542,7 @@ static void openpic_set_irq(void *opaque, int n_IRQ, int level)static void openpic_reset (DeviceState *d) { -OpenPICState *opp =FROM_SYSBUS (typeof (*opp),SYS_BUS_DEVICE (d)); +OpenPICState *opp =OPENPIC (d);int i; opp->gcr =GCR_RESET ;@@ -703,7 +708,7 @@ static void openpic_gcr_write(OpenPICState *opp, uint64_t val)bool mpic_proxy = false;if (val &GCR_RESET ) { -openpic_reset (&opp->busdev.qdev); +openpic_reset (DEVICE (opp));return ; }@@ -1528,7 +1533,7 @@ static void map_list(OpenPICState *opp, const MemReg *list, int *count)static int openpic_init (SysBusDevice *dev) { -OpenPICState *opp =FROM_SYSBUS (typeof (*opp), dev); +OpenPICState *opp =OPENPIC (dev);int i, j;int list_count =0 ;static const MemReg list_le[] = {@@ -1621,7 +1626,7 @@ static int openpic_init(SysBusDevice *dev) } } -register_savevm (&opp->busdev.qdev,"openpic" ,0 ,2 , +register_savevm (DEVICE (opp),"openpic" ,0 ,2 , openpic_save, openpic_load, opp);sysbus_init_mmio (dev, &opp->mem);@@ -1647,7 +1652,7 @@ static void openpic_class_init(ObjectClass *klass, void *data) }static const TypeInfo openpic_info = { - .name ="openpic" , + .name =TYPE_OPENPIC , .parent =TYPE_SYS_BUS_DEVICE , .instance_size =sizeof (OpenPICState), .class_init = openpic_class_init,hw/ppc/e500.c +1
-1@@ -565,7 +565,7 @@ void ppce500_init(PPCE500Params *params)/* MPIC */ mpic =g_new (qemu_irq,256 ); - dev =qdev_create (NULL ,"openpic" ); + dev =qdev_create (NULL ,TYPE_OPENPIC );qdev_prop_set_uint32 (dev,"nb_cpus" , smp_cpus);qdev_prop_set_uint32 (dev,"model" , params->mpic_version);qdev_init_nofail (dev);hw/ppc/mac_newworld.c +1
-1@@ -329,7 +329,7 @@ static void ppc_core99_init(QEMUMachineInitArgs *args) pic =g_new (qemu_irq,64 ); - dev =qdev_create (NULL ,"openpic" ); + dev =qdev_create (NULL ,TYPE_OPENPIC );qdev_prop_set_uint32 (dev,"model" ,OPENPIC_MODEL_RAVEN );qdev_init_nofail (dev); s =SYS_BUS_DEVICE (dev);include/hw/ppc/openpic.h +2
-1@@ -1,6 +1,8 @@#if !defined(__OPENPIC_H__)#define __OPENPIC_H__ +#define TYPE_OPENPIC "openpic" +/* OpenPIC have 5 outputs per CPU connected and one IRQ out single output */ enum { OPENPIC_OUTPUT_INT = 0, /* IRQ */ --1.8.1.4
Re: [Qemu-devel] [PATCH 2/2] intc/openpic: Convert to QOM realize
In reply to Andreas FärberHi Andreas,
Quoted 4 lines · Andreas Färber
Split qdev initfn into
instance_initand realize functions. Change one occurrence of "klass" while at it.Signed-off-by Andreas Färber <[email protected]>
Quoted 13 lines
--- hw/intc/openpic.c | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-)hw/intc/openpic.c +0
-1@@ -1531,8 +1531,16 @@ static void map_list(OpenPICState *opp, const MemReg *list, int *count) } } -static int openpic_init (SysBusDevice *dev)
hw/intc/openpic.c static void map_list(OpenPICState *opp, const MemReg *list, int *count) · line 1543
Quoted 10 lines
hw/intc/openpic.c +9
-0+static void openpic_init (Object *obj) { +OpenPICState *opp =OPENPIC (obj); + +memory_region_init (&opp->mem,"openpic" ,0x40000 ); +} + +static void openpic_realize (DeviceState *dev,Error **errp) +{ +SysBusDevice *d =SYS_BUS_DEVICE (dev);
FWIW, i have been using "sbd" for this variable name in similar conversions (sdhci, xilinx_spips, axidma, axienet and a few friends). There are also a few other precedents out there such as arm_gic.
Regards,
Peter
Quoted 74 lines
hw/intc/openpic.c +10
-15OpenPICState *opp =OPENPIC (dev);int i, j;int list_count =0 ;@@ -1566,8 +1574,6 @@ static int openpic_init(SysBusDevice *dev) {NULL} }; -memory_region_init (&opp->mem,"openpic" ,0x40000 ); -switch (opp->model) {case OPENPIC_MODEL_FSL_MPIC_20 :default :@@ -1610,9 +1616,9 @@ static int openpic_init(SysBusDevice *dev) opp->brr1 =-1 ; opp->mpic_mode_mask =GCR_MODE_MIXED ; -/* Only UP supported today */ if (opp->nb_cpus !=1 ) { -return -EINVAL ; +error_setg (errp,"Only UP supported today" ); +return ; }map_list (opp, list_le, &list_count);@@ -1622,17 +1628,15 @@ static int openpic_init(SysBusDevice *dev)for (i =0 ; i < opp->nb_cpus; i++) { opp->dst[i].irqs =g_new (qemu_irq,OPENPIC_OUTPUT_NB );for (j =0 ; j <OPENPIC_OUTPUT_NB ; j++) { -sysbus_init_irq (dev, &opp->dst[i].irqs[j]); +sysbus_init_irq (d, &opp->dst[i].irqs[j]); } } -register_savevm (DEVICE (opp),"openpic" ,0 ,2 , +register_savevm (dev,"openpic" ,0 ,2 , openpic_save, openpic_load, opp); -sysbus_init_mmio (dev, &opp->mem); -qdev_init_gpio_in (&dev->qdev, openpic_set_irq, opp->max_irq); - -return 0 ; +sysbus_init_mmio (d, &opp->mem); +qdev_init_gpio_in (dev, openpic_set_irq, opp->max_irq); }static Property openpic_properties[] = {@@ -1641,12 +1645,11 @@ static Property openpic_properties[] = { DEFINE_PROP_END_OF_LIST(), }; -static void openpic_class_init (ObjectClass *klass,void *data) +static void openpic_class_init (ObjectClass *oc,void *data) { -DeviceClass *dc =DEVICE_CLASS (klass); -SysBusDeviceClass *k =SYS_BUS_DEVICE_CLASS (klass); +DeviceClass *dc =DEVICE_CLASS (oc); - k->init = openpic_init; + dc->realize = openpic_realize; dc->props = openpic_properties; dc->reset = openpic_reset; }@@ -1655,6 +1658,7 @@ static const TypeInfo openpic_info = { .name = TYPE_OPENPIC, .parent = TYPE_SYS_BUS_DEVICE, .instance_size = sizeof(OpenPICState), + .instance_init = openpic_init, .class_init = openpic_class_init, }; --1.8.1.4
Alexander Graf
AppliedQuoted 3 lines · Andreas Färber
Hi Alex,
Here's another mini-series cleaning up and converting the original OpenPIC device.
Thanks, applied both.
Scott, could you please send a follow-up patch that converts the kvm mpic device the same way?
Thanks!
Alex
Am 18.06.2013 14:32, schrieb Alexander Graf:
Quoted 8 lines · Andreas Färber
Quoted 4 lines
Hi Alex,
Here's another mini-series cleaning up and converting the original OpenPIC device.
Thanks, applied both.
Thanks.
Quoted 1 line
Scott, could you please send a follow-up patch that converts the kvm mpic device the same way?
I had already sent that out.
Andreas
Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
Quoted 8 lines · Andreas Färber
Am 18.06.2013 14:32, schrieb Alexander Graf:
Quoted 7 lines · Andreas Färber
Quoted 4 lines
Hi Alex,
Here's another mini-series cleaning up and converting the original OpenPIC device.
Quoted 7 lines
Quoted 1 line
Thanks, applied both.
Thanks.
Quoted 1 line
Scott, could you please send a follow-up patch that converts the kvm mpic device the same way?
I had already sent that out.
Ah, sorry, missed it. So LIFO works as badly as FIFO for processing mails - meh :)
Alex
Re: [Qemu-devel] [PATCH 2/2] intc/openpic: Convert to QOM realize
In reply to Peter CrosthwaiteHi,
Am 18.06.2013 05:28, schrieb Peter Crosthwaite:
Quoted 20 lines · Andreas Färber
Quoted 4 lines
Split qdev initfn into
instance_initand realize functions. Change one occurrence of "klass" while at it.Signed-off-by Andreas Färber <[email protected]>Reviewed-by Peter Crosthwaite <[email protected]>Quoted 12 lines
--- hw/intc/openpic.c | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-)hw/intc/openpic.c +0
-0@@ -1531,8 +1531,16 @@ static void map_list(OpenPICState *opp, const MemReg *list, int *count) } }
Quoted 15 lines
hw/intc/openpic.c static void map_list(OpenPICState *opp, const MemReg *list, int *count) · line 1543
Quoted 11 lines
hw/intc/openpic.c +9
-1-static int openpic_init (SysBusDevice *dev) +static void openpic_init (Object *obj) { +OpenPICState *opp =OPENPIC (obj); + +memory_region_init (&opp->mem,"openpic" ,0x40000 ); +} + +static void openpic_realize (DeviceState *dev,Error **errp) +{ +SysBusDevice *d =SYS_BUS_DEVICE (dev);FWIW, i have been using "sbd" for this variable name in similar conversions (sdhci,
xilinx_spips, axidma, axienet and a few friends). There are also a few other precedents out there such asarm_gic.
So far we don't seem to have a consistent convention. I've seen busdev, sysbusdev, d; also pcidev vs. pci_dev vs. d for PCIDevice etc.
sbd is fine with me, too. But since we're not yet consistent in using oc rather than klass either (including in your super class RFC), do you see a strong need to respin? Or can we just follow-up with a sed across the tree at some point once there is agreement on the naming?
We should collect naming conventions into the QOMConventions Wiki page.
Regards,
Andreas
Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
Re: [Qemu-devel] [PATCH 2/2] intc/openpic: Convert to QOM realize
Hi Andreas,
Quoted 39 lines · Andreas Färber
Hi,
Am 18.06.2013 05:28, schrieb Peter Crosthwaite:
Quoted 20 lines · Andreas Färber
Quoted 4 lines
Split qdev initfn into
instance_initand realize functions. Change one occurrence of "klass" while at it.Signed-off-by Andreas Färber <[email protected]>Reviewed-by Peter Crosthwaite <[email protected]>Quoted 12 lines
--- hw/intc/openpic.c | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-)hw/intc/openpic.c +0
-0@@ -1531,8 +1531,16 @@ static void map_list(OpenPICState *opp, const MemReg *list, int *count) } }Quoted 15 lines
hw/intc/openpic.c static void map_list(OpenPICState *opp, const MemReg *list, int *count) · line 1543
Quoted 11 lines
hw/intc/openpic.c +9
-1-static int openpic_init (SysBusDevice *dev) +static void openpic_init (Object *obj) { +OpenPICState *opp =OPENPIC (obj); + +memory_region_init (&opp->mem,"openpic" ,0x40000 ); +} + +static void openpic_realize (DeviceState *dev,Error **errp) +{ +SysBusDevice *d =SYS_BUS_DEVICE (dev);FWIW, i have been using "sbd" for this variable name in similar conversions (sdhci,
xilinx_spips, axidma, axienet and a few friends). There are also a few other precedents out there such asarm_gic.
Quoted 6 lines
So far we don't seem to have a consistent convention. I've seen busdev, sysbusdev, d; also pcidev vs.
pci_devvs. d for PCIDevice etc.sbd is fine with me, too. But since we're not yet consistent in using oc rather than klass either (including in your super class RFC), do you see a strong need to respin?
No definitely not. Just trying to open the discussion so we can do this consistently in future.
Quoted 3 lines
Or can we just follow-up with a sed across the tree at some point once there is agreement on the naming?
Yes. Sound like a plan. No point blocking these cleanups on undecided issues.
Regards.
Peter
Quoted 9 lines
We should collect naming conventions into the QOMConventions Wiki page.
Regards,
Andreas--
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg