Patchwork [16/22] usb-ohci: Remove unneeded double indirection of OHCIPCIState

login
register
mail settings
Submitter Juan Quintela
Date Aug. 24, 2009, 11:03 a.m.
Message ID <ddcfe67106f73c4d92682894c43a7311adefb9c8.1251111439.git.quintela@redhat.com>
Download mbox | patch
Permalink /patch/31917/
State Superseded
Headers show

Comments

Juan Quintela - Aug. 24, 2009, 11:03 a.m.
Signed-off-by: Juan Quintela <quintela@redhat.com>
---
 hw/usb-ohci.c |   34 ++++++++++++++--------------------
 1 files changed, 14 insertions(+), 20 deletions(-)
Gerd Hoffmann - Aug. 24, 2009, 12:46 p.m.
> --- a/hw/usb-ohci.c
> +++ b/hw/usb-ohci.c

NACK.  There are non-pci OHCI users.

cheers,
   Gerd

Patch

diff --git a/hw/usb-ohci.c b/hw/usb-ohci.c
index 4c42ec0..14139b8 100644
--- a/hw/usb-ohci.c
+++ b/hw/usb-ohci.c
@@ -65,6 +65,7 @@  enum ohci_type {
 };

 typedef struct {
+    PCIDevice dev;
     qemu_irq irq;
     enum ohci_type type;
     int mem;
@@ -1698,41 +1699,34 @@  static void usb_ohci_init(OHCIState *ohci, int num_ports, int devfn,
     ohci_reset(ohci);
 }

-typedef struct {
-    PCIDevice pci_dev;
-    OHCIState state;
-} OHCIPCIState;
-
 static void ohci_mapfunc(PCIDevice *pci_dev, int i,
             uint32_t addr, uint32_t size, int type)
 {
-    OHCIPCIState *ohci = (OHCIPCIState *)pci_dev;
-    cpu_register_physical_memory(addr, size, ohci->state.mem);
+    OHCIState *ohci = DO_UPCAST(OHCIState, dev, pci_dev);
+    cpu_register_physical_memory(addr, size, ohci->mem);
 }

 void usb_ohci_init_pci(struct PCIBus *bus, int num_ports, int devfn)
 {
-    OHCIPCIState *ohci;
+    PCIDevice *pci_dev = pci_register_device(bus, "OHCI USB", sizeof(OHCIState),
+                                             devfn, NULL, NULL);
+    OHCIState *ohci = DO_UPCAST(OHCIState, dev, pci_dev);

-    ohci = (OHCIPCIState *)pci_register_device(bus, "OHCI USB", sizeof(*ohci),
-                                               devfn, NULL, NULL);
     if (ohci == NULL) {
         fprintf(stderr, "usb-ohci: Failed to register PCI device\n");
         return;
     }

-    pci_config_set_vendor_id(ohci->pci_dev.config, PCI_VENDOR_ID_APPLE);
-    pci_config_set_device_id(ohci->pci_dev.config,
-                             PCI_DEVICE_ID_APPLE_IPID_USB);
-    ohci->pci_dev.config[0x09] = 0x10; /* OHCI */
-    pci_config_set_class(ohci->pci_dev.config, PCI_CLASS_SERIAL_USB);
-    ohci->pci_dev.config[0x3d] = 0x01; /* interrupt pin 1 */
+    pci_config_set_vendor_id(ohci->dev.config, PCI_VENDOR_ID_APPLE);
+    pci_config_set_device_id(ohci->dev.config, PCI_DEVICE_ID_APPLE_IPID_USB);
+    ohci->dev.config[0x09] = 0x10; /* OHCI */
+    pci_config_set_class(ohci->dev.config, PCI_CLASS_SERIAL_USB);
+    ohci->dev.config[0x3d] = 0x01; /* interrupt pin 1 */

-    usb_ohci_init(&ohci->state, num_ports, devfn, ohci->pci_dev.irq[0],
-                  OHCI_TYPE_PCI, ohci->pci_dev.name, 0);
+    usb_ohci_init(ohci, num_ports, devfn, ohci->dev.irq[0],
+                  OHCI_TYPE_PCI, ohci->dev.name, 0);

-    pci_register_bar((struct PCIDevice *)ohci, 0, 256,
-                           PCI_ADDRESS_SPACE_MEM, ohci_mapfunc);
+    pci_register_bar(pci_dev, 0, 256, PCI_ADDRESS_SPACE_MEM, ohci_mapfunc);
 }

 void usb_ohci_init_pxa(target_phys_addr_t base, int num_ports, int devfn,