Patchwork [14/15] usb-uhci: convert to new pci interface

login
register
mail settings
Submitter Anthony Liguori
Date Feb. 9, 2010, 10:01 p.m.
Message ID <1265752899-26980-15-git-send-email-aliguori@us.ibm.com>
Download mbox | patch
Permalink /patch/44976/
State New
Headers show

Comments

Anthony Liguori - Feb. 9, 2010, 10:01 p.m.
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
---
 hw/usb-uhci.c |   41 +++++++++++++++++++++++++++++------------
 1 files changed, 29 insertions(+), 12 deletions(-)

Patch

diff --git a/hw/usb-uhci.c b/hw/usb-uhci.c
index 434070e..0d049d8 100644
--- a/hw/usb-uhci.c
+++ b/hw/usb-uhci.c
@@ -1047,17 +1047,34 @@  static void uhci_frame_timer(void *opaque)
     qemu_mod_timer(s->frame_timer, expire_time);
 }
 
-static void uhci_map(PCIDevice *pci_dev, int region_num,
-                    pcibus_t addr, pcibus_t size, int type)
+static uint32_t uhci_ioport_read(PCIDevice *dev, pcibus_t addr, int size)
 {
-    UHCIState *s = (UHCIState *)pci_dev;
-
-    register_ioport_write(addr, 32, 2, uhci_ioport_writew, s);
-    register_ioport_read(addr, 32, 2, uhci_ioport_readw, s);
-    register_ioport_write(addr, 32, 4, uhci_ioport_writel, s);
-    register_ioport_read(addr, 32, 4, uhci_ioport_readl, s);
-    register_ioport_write(addr, 32, 1, uhci_ioport_writeb, s);
-    register_ioport_read(addr, 32, 1, uhci_ioport_readb, s);
+    UHCIState *s = DO_UPCAST(UHCIState, dev, dev);
+    uint32_t value;
+
+    if (size == 1) {
+        value = uhci_ioport_readb(s, addr);
+    } else if (size == 2) {
+        value = uhci_ioport_readw(s, addr);
+    } else {
+        value = uhci_ioport_readl(s, addr);
+    }
+
+    return value;
+}
+
+static void uhci_ioport_write(PCIDevice *dev, pcibus_t addr, int size,
+                              uint32_t value)
+{
+    UHCIState *s = DO_UPCAST(UHCIState, dev, dev);
+
+    if (size == 1) {
+        uhci_ioport_writeb(s, addr, value);
+    } else if (size == 2) {
+        uhci_ioport_writew(s, addr, value);
+    } else {
+        uhci_ioport_writel(s, addr, value);
+    }
 }
 
 static int usb_uhci_common_initfn(UHCIState *s)
@@ -1084,8 +1101,8 @@  static int usb_uhci_common_initfn(UHCIState *s)
 
     /* Use region 4 for consistency with real hardware.  BSD guests seem
        to rely on this.  */
-    pci_register_bar(&s->dev, 4, 0x20,
-                           PCI_BASE_ADDRESS_SPACE_IO, uhci_map);
+    pci_register_io_region(&s->dev, 4, 0x20, PCI_BASE_ADDRESS_SPACE_IO,
+                           uhci_ioport_read, uhci_ioport_write);
 
     return 0;
 }