Patchwork [v2,02/26] ohci: QOM'ify some more

login
register
mail settings
Submitter Hu Tao
Date July 1, 2013, 10:18 a.m.
Message ID <f267577f12ce21da5896e6660a5601fcda8de7f9.1372673778.git.hutao@cn.fujitsu.com>
Download mbox | patch
Permalink /patch/256069/
State New
Headers show

Comments

Hu Tao - July 1, 2013, 10:18 a.m.
Introduce type constant and avoid DO_UPCAST().

Signed-off-by: Hu Tao <hutao@cn.fujitsu.com>
---
 hw/usb/hcd-ohci.c | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)
Andreas Färber - July 3, 2013, 1:52 a.m.
Am 01.07.2013 12:18, schrieb Hu Tao:
> Introduce type constant and avoid DO_UPCAST().
> 
> Signed-off-by: Hu Tao <hutao@cn.fujitsu.com>
> ---
>  hw/usb/hcd-ohci.c | 20 ++++++++++++--------
>  1 file changed, 12 insertions(+), 8 deletions(-)
> 
> diff --git a/hw/usb/hcd-ohci.c b/hw/usb/hcd-ohci.c
> index 5513924..912255d 100644
> --- a/hw/usb/hcd-ohci.c
> +++ b/hw/usb/hcd-ohci.c
> @@ -1842,6 +1842,8 @@ static int usb_ohci_init(OHCIState *ohci, DeviceState *dev,
>      return 0;
>  }
>  
> +#define TYPE_PCI_OHCI "pci-ohci"
> +#define PCI_OHCI(obj) OBJECT_CHECK(OHCIPCIState, (obj), TYPE_PCI_OHCI)

I added a while line here and converted the last three remaining uses of
pci_dev in the initfn so that both fields could be renamed to parent_obj
as proof of complete conversion.

Thanks, queued this and the following one on qom-next:
https://github.com/afaerber/qemu-cpu/commits/qom-next

There was an overlap with Peter's usb/* PCIDevice patch, I believe this
one is a superset of the ohci part.

Andreas

>  typedef struct {
>      PCIDevice pci_dev;
>      OHCIState state;
> @@ -1852,23 +1854,25 @@ typedef struct {
>  
>  static int usb_ohci_initfn_pci(struct PCIDevice *dev)
>  {
> -    OHCIPCIState *ohci = DO_UPCAST(OHCIPCIState, pci_dev, dev);
> +    OHCIPCIState *ohci = PCI_OHCI(dev);
>  
>      ohci->pci_dev.config[PCI_CLASS_PROG] = 0x10; /* OHCI */
>      ohci->pci_dev.config[PCI_INTERRUPT_PIN] = 0x01; /* interrupt pin A */
>  
> -    if (usb_ohci_init(&ohci->state, &dev->qdev, ohci->num_ports, 0,
> +    if (usb_ohci_init(&ohci->state, DEVICE(dev), ohci->num_ports, 0,
>                        ohci->masterbus, ohci->firstport,
>                        pci_get_address_space(dev)) != 0) {
>          return -1;
>      }
>      ohci->state.irq = ohci->pci_dev.irq[0];
>  
> -    /* TODO: avoid cast below by using dev */
> -    pci_register_bar(&ohci->pci_dev, 0, 0, &ohci->state.mem);
> +    pci_register_bar(dev, 0, 0, &ohci->state.mem);
>      return 0;
>  }
>  
> +#define TYPE_SYSBUS_OHCI "sysbus-ohci"
> +#define SYSBUS_OHCI(obj) OBJECT_CHECK(OHCISysBusState, (obj), TYPE_SYSBUS_OHCI)
> +
>  typedef struct {
>      SysBusDevice busdev;
>      OHCIState ohci;
> @@ -1878,10 +1882,10 @@ typedef struct {
>  
>  static int ohci_init_pxa(SysBusDevice *dev)
>  {
> -    OHCISysBusState *s = FROM_SYSBUS(OHCISysBusState, dev);
> +    OHCISysBusState *s = SYSBUS_OHCI(dev);
>  
>      /* Cannot fail as we pass NULL for masterbus */
> -    usb_ohci_init(&s->ohci, &dev->qdev, s->num_ports, s->dma_offset, NULL, 0,
> +    usb_ohci_init(&s->ohci, DEVICE(dev), s->num_ports, s->dma_offset, NULL, 0,
>                    &address_space_memory);
>      sysbus_init_irq(dev, &s->ohci.irq);
>      sysbus_init_mmio(dev, &s->ohci.mem);
> @@ -1911,7 +1915,7 @@ static void ohci_pci_class_init(ObjectClass *klass, void *data)
>  }
>  
>  static const TypeInfo ohci_pci_info = {
> -    .name          = "pci-ohci",
> +    .name          = TYPE_PCI_OHCI,
>      .parent        = TYPE_PCI_DEVICE,
>      .instance_size = sizeof(OHCIPCIState),
>      .class_init    = ohci_pci_class_init,
> @@ -1934,7 +1938,7 @@ static void ohci_sysbus_class_init(ObjectClass *klass, void *data)
>  }
>  
>  static const TypeInfo ohci_sysbus_info = {
> -    .name          = "sysbus-ohci",
> +    .name          = TYPE_SYSBUS_OHCI,
>      .parent        = TYPE_SYS_BUS_DEVICE,
>      .instance_size = sizeof(OHCISysBusState),
>      .class_init    = ohci_sysbus_class_init,
>

Patch

diff --git a/hw/usb/hcd-ohci.c b/hw/usb/hcd-ohci.c
index 5513924..912255d 100644
--- a/hw/usb/hcd-ohci.c
+++ b/hw/usb/hcd-ohci.c
@@ -1842,6 +1842,8 @@  static int usb_ohci_init(OHCIState *ohci, DeviceState *dev,
     return 0;
 }
 
+#define TYPE_PCI_OHCI "pci-ohci"
+#define PCI_OHCI(obj) OBJECT_CHECK(OHCIPCIState, (obj), TYPE_PCI_OHCI)
 typedef struct {
     PCIDevice pci_dev;
     OHCIState state;
@@ -1852,23 +1854,25 @@  typedef struct {
 
 static int usb_ohci_initfn_pci(struct PCIDevice *dev)
 {
-    OHCIPCIState *ohci = DO_UPCAST(OHCIPCIState, pci_dev, dev);
+    OHCIPCIState *ohci = PCI_OHCI(dev);
 
     ohci->pci_dev.config[PCI_CLASS_PROG] = 0x10; /* OHCI */
     ohci->pci_dev.config[PCI_INTERRUPT_PIN] = 0x01; /* interrupt pin A */
 
-    if (usb_ohci_init(&ohci->state, &dev->qdev, ohci->num_ports, 0,
+    if (usb_ohci_init(&ohci->state, DEVICE(dev), ohci->num_ports, 0,
                       ohci->masterbus, ohci->firstport,
                       pci_get_address_space(dev)) != 0) {
         return -1;
     }
     ohci->state.irq = ohci->pci_dev.irq[0];
 
-    /* TODO: avoid cast below by using dev */
-    pci_register_bar(&ohci->pci_dev, 0, 0, &ohci->state.mem);
+    pci_register_bar(dev, 0, 0, &ohci->state.mem);
     return 0;
 }
 
+#define TYPE_SYSBUS_OHCI "sysbus-ohci"
+#define SYSBUS_OHCI(obj) OBJECT_CHECK(OHCISysBusState, (obj), TYPE_SYSBUS_OHCI)
+
 typedef struct {
     SysBusDevice busdev;
     OHCIState ohci;
@@ -1878,10 +1882,10 @@  typedef struct {
 
 static int ohci_init_pxa(SysBusDevice *dev)
 {
-    OHCISysBusState *s = FROM_SYSBUS(OHCISysBusState, dev);
+    OHCISysBusState *s = SYSBUS_OHCI(dev);
 
     /* Cannot fail as we pass NULL for masterbus */
-    usb_ohci_init(&s->ohci, &dev->qdev, s->num_ports, s->dma_offset, NULL, 0,
+    usb_ohci_init(&s->ohci, DEVICE(dev), s->num_ports, s->dma_offset, NULL, 0,
                   &address_space_memory);
     sysbus_init_irq(dev, &s->ohci.irq);
     sysbus_init_mmio(dev, &s->ohci.mem);
@@ -1911,7 +1915,7 @@  static void ohci_pci_class_init(ObjectClass *klass, void *data)
 }
 
 static const TypeInfo ohci_pci_info = {
-    .name          = "pci-ohci",
+    .name          = TYPE_PCI_OHCI,
     .parent        = TYPE_PCI_DEVICE,
     .instance_size = sizeof(OHCIPCIState),
     .class_init    = ohci_pci_class_init,
@@ -1934,7 +1938,7 @@  static void ohci_sysbus_class_init(ObjectClass *klass, void *data)
 }
 
 static const TypeInfo ohci_sysbus_info = {
-    .name          = "sysbus-ohci",
+    .name          = TYPE_SYSBUS_OHCI,
     .parent        = TYPE_SYS_BUS_DEVICE,
     .instance_size = sizeof(OHCISysBusState),
     .class_init    = ohci_sysbus_class_init,