qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH 16/22] usb-ohci: Remove unneeded double indirection


From: Juan Quintela
Subject: [Qemu-devel] [PATCH 16/22] usb-ohci: Remove unneeded double indirection of OHCIPCIState
Date: Mon, 24 Aug 2009 13:03:37 +0200

Signed-off-by: Juan Quintela <address@hidden>
---
 hw/usb-ohci.c |   34 ++++++++++++++--------------------
 1 files changed, 14 insertions(+), 20 deletions(-)

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,
-- 
1.6.2.5





reply via email to

[Prev in Thread] Current Thread [Next in Thread]