[RFC v3 48/56] ehci: convert to memory API

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

 



Signed-off-by: Avi Kivity <avi@xxxxxxxxxx>
---
 hw/usb-ehci.c |   53 +++++++++++++++++++++++++++++------------------------
 1 files changed, 29 insertions(+), 24 deletions(-)

diff --git a/hw/usb-ehci.c b/hw/usb-ehci.c
index 91fb7de..bd7fdcb 100644
--- a/hw/usb-ehci.c
+++ b/hw/usb-ehci.c
@@ -371,8 +371,7 @@ struct EHCIState {
     PCIDevice dev;
     USBBus bus;
     qemu_irq irq;
-    target_phys_addr_t mem_base;
-    int mem;
+    MemoryRegion mem;
     int num_ports;
 
     /* properties */
@@ -2094,29 +2093,38 @@ static void ehci_frame_timer(void *opaque)
     qemu_mod_timer(ehci->frame_timer, expire_time);
 }
 
-static CPUReadMemoryFunc *ehci_readfn[3]={
-    ehci_mem_readb,
-    ehci_mem_readw,
-    ehci_mem_readl
-};
+static uint64_t ehci_mem_read(void *opaque, target_phys_addr_t addr,
+                              unsigned size)
+{
+    EHCIState *s = opaque;
 
-static CPUWriteMemoryFunc *ehci_writefn[3]={
-    ehci_mem_writeb,
-    ehci_mem_writew,
-    ehci_mem_writel
-};
+    switch (size) {
+    case 1: return ehci_mem_readb(s, addr);
+    case 2: return ehci_mem_readw(s, addr);
+    case 4: return ehci_mem_readl(s, addr);
+    default: abort();
+    }
+}
 
-static void ehci_map(PCIDevice *pci_dev, int region_num,
-                     pcibus_t addr, pcibus_t size, int type)
+static void ehci_mem_write(void *opaque, target_phys_addr_t addr,
+                           uint64_t data, unsigned size)
 {
-    EHCIState *s =(EHCIState *)pci_dev;
+    EHCIState *s = opaque;
 
-    DPRINTF("ehci_map: region %d, addr %08" PRIx64 ", size %" PRId64 ", s->mem %08X\n",
-            region_num, addr, size, s->mem);
-    s->mem_base = addr;
-    cpu_register_physical_memory(addr, size, s->mem);
+    switch (size) {
+    case 1: return ehci_mem_writeb(s, addr, data);
+    case 2: return ehci_mem_writew(s, addr, data);
+    case 4: return ehci_mem_writel(s, addr, data);
+    default: abort();
+    }
 }
 
+static MemoryRegionOps ehci_mem_ops = {
+    .read = ehci_mem_read,
+    .write = ehci_mem_write,
+    .endianness = DEVICE_LITTLE_ENDIAN,
+};
+
 static void ehci_device_destroy(USBBus *bus, USBDevice *dev)
 {
     EHCIState *s = container_of(bus, EHCIState, bus);
@@ -2215,11 +2223,8 @@ static int usb_ehci_initfn(PCIDevice *dev)
 
     qemu_register_reset(ehci_reset, s);
 
-    s->mem = cpu_register_io_memory(ehci_readfn, ehci_writefn, s,
-                                    DEVICE_LITTLE_ENDIAN);
-
-    pci_register_bar(&s->dev, 0, MMIO_SIZE, PCI_BASE_ADDRESS_SPACE_MEMORY,
-                                                            ehci_map);
+    memory_region_init_io(&s->mem, &ehci_mem_ops, s, "ehci", MMIO_SIZE);
+    pci_register_bar_region(&s->dev, 0, PCI_BASE_ADDRESS_SPACE_MEMORY, &s->mem);
 
     fprintf(stderr, "*** EHCI support is under development ***\n");
 
-- 
1.7.5.3

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux