diff mbox

[09/10] usb-ohci: Use PCI DMA stub functions

Message ID 1314853263-2086-10-git-send-email-david@gibson.dropbear.id.au
State New
Headers show

Commit Message

David Gibson Sept. 1, 2011, 5:01 a.m. UTC
From: Eduard - Gabriel Munteanu <eduard.munteanu@linux360.ro>

This updates the usb-ohci device emulation to use the explicit PCI DMA
functions, instead of directly calling physical memory access functions.

Signed-off-by: Eduard - Gabriel Munteanu <eduard.munteanu@linux360.ro>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
---
 hw/usb-ohci.c |   46 ++++++++++++++++++++++++++++------------------
 1 files changed, 28 insertions(+), 18 deletions(-)

Comments

Gerd Hoffmann Sept. 1, 2011, 10:10 a.m. UTC | #1
On 09/01/11 07:01, David Gibson wrote:
> From: Eduard - Gabriel Munteanu<eduard.munteanu@linux360.ro>
>
> This updates the usb-ohci device emulation to use the explicit PCI DMA
> functions, instead of directly calling physical memory access functions.

It isn't that simple.

There are non-PCI ohci devices which I think you break with this patch.

cheers,
   Gerd
David Gibson Sept. 2, 2011, 1:47 a.m. UTC | #2
On Thu, Sep 01, 2011 at 12:10:48PM +0200, Gerd Hoffmann wrote:
> On 09/01/11 07:01, David Gibson wrote:
> >From: Eduard - Gabriel Munteanu<eduard.munteanu@linux360.ro>
> >
> >This updates the usb-ohci device emulation to use the explicit PCI DMA
> >functions, instead of directly calling physical memory access functions.
> 
> It isn't that simple.
> 
> There are non-PCI ohci devices which I think you break with this
> patch.

Ah, good point.  I'll remove the OHCI patch from the next iteration of
this series, and fix it properly later with some of the other harder
cases like ne2k.
diff mbox

Patch

diff --git a/hw/usb-ohci.c b/hw/usb-ohci.c
index d30db3f..d3c0641 100644
--- a/hw/usb-ohci.c
+++ b/hw/usb-ohci.c
@@ -30,6 +30,7 @@ 
 #include "qemu-timer.h"
 #include "usb.h"
 #include "pci.h"
+#include "dma.h"
 #include "usb-ohci.h"
 #include "sysbus.h"
 #include "qdev-addr.h"
@@ -116,6 +117,14 @@  typedef struct {
 
 } OHCIState;
 
+typedef struct {
+    PCIDevice pci_dev;
+    OHCIState state;
+    char *masterbus;
+    uint32_t num_ports;
+    uint32_t firstport;
+} OHCIPCIState;
+
 /* Host Controller Communications Area */
 struct ohci_hcca {
     uint32_t intr[32];
@@ -463,12 +472,13 @@  static void ohci_reset(void *opaque)
 static inline int get_dwords(OHCIState *ohci,
                              uint32_t addr, uint32_t *buf, int num)
 {
+    OHCIPCIState *s = container_of(ohci, OHCIPCIState, state);
     int i;
 
     addr += ohci->localmem_base;
 
     for (i = 0; i < num; i++, buf++, addr += sizeof(*buf)) {
-        cpu_physical_memory_read(addr, buf, sizeof(*buf));
+        pci_dma_read(&s->pci_dev, addr, buf, sizeof(*buf));
         *buf = le32_to_cpu(*buf);
     }
 
@@ -479,13 +489,14 @@  static inline int get_dwords(OHCIState *ohci,
 static inline int put_dwords(OHCIState *ohci,
                              uint32_t addr, uint32_t *buf, int num)
 {
+    OHCIPCIState *s = container_of(ohci, OHCIPCIState, state);
     int i;
 
     addr += ohci->localmem_base;
 
     for (i = 0; i < num; i++, buf++, addr += sizeof(*buf)) {
         uint32_t tmp = cpu_to_le32(*buf);
-        cpu_physical_memory_write(addr, &tmp, sizeof(tmp));
+        pci_dma_write(&s->pci_dev, addr, &tmp, sizeof(tmp));
     }
 
     return 1;
@@ -495,12 +506,13 @@  static inline int put_dwords(OHCIState *ohci,
 static inline int get_words(OHCIState *ohci,
                             uint32_t addr, uint16_t *buf, int num)
 {
+    OHCIPCIState *s = container_of(ohci, OHCIPCIState, state);
     int i;
 
     addr += ohci->localmem_base;
 
     for (i = 0; i < num; i++, buf++, addr += sizeof(*buf)) {
-        cpu_physical_memory_read(addr, buf, sizeof(*buf));
+        pci_dma_read(&s->pci_dev, addr, buf, sizeof(*buf));
         *buf = le16_to_cpu(*buf);
     }
 
@@ -511,13 +523,14 @@  static inline int get_words(OHCIState *ohci,
 static inline int put_words(OHCIState *ohci,
                             uint32_t addr, uint16_t *buf, int num)
 {
+    OHCIPCIState *s = container_of(ohci, OHCIPCIState, state);
     int i;
 
     addr += ohci->localmem_base;
 
     for (i = 0; i < num; i++, buf++, addr += sizeof(*buf)) {
         uint16_t tmp = cpu_to_le16(*buf);
-        cpu_physical_memory_write(addr, &tmp, sizeof(tmp));
+        pci_dma_write(&s->pci_dev, addr, &tmp, sizeof(tmp));
     }
 
     return 1;
@@ -545,7 +558,8 @@  static inline int ohci_read_iso_td(OHCIState *ohci,
 static inline int ohci_read_hcca(OHCIState *ohci,
                                  uint32_t addr, struct ohci_hcca *hcca)
 {
-    cpu_physical_memory_read(addr + ohci->localmem_base, hcca, sizeof(*hcca));
+    OHCIPCIState *s = container_of(ohci, OHCIPCIState, state);
+    pci_dma_read(&s->pci_dev, addr + ohci->localmem_base, hcca, sizeof(*hcca));
     return 1;
 }
 
@@ -571,7 +585,9 @@  static inline int ohci_put_iso_td(OHCIState *ohci,
 static inline int ohci_put_hcca(OHCIState *ohci,
                                 uint32_t addr, struct ohci_hcca *hcca)
 {
-    cpu_physical_memory_write(addr + ohci->localmem_base, hcca, sizeof(*hcca));
+    OHCIPCIState *s = container_of(ohci, OHCIPCIState, state);
+
+    pci_dma_write(&s->pci_dev, addr + ohci->localmem_base, hcca, sizeof(*hcca));
     return 1;
 }
 
@@ -579,6 +595,7 @@  static inline int ohci_put_hcca(OHCIState *ohci,
 static void ohci_copy_td(OHCIState *ohci, struct ohci_td *td,
                          uint8_t *buf, int len, int write)
 {
+    OHCIPCIState *s = container_of(ohci, OHCIPCIState, state);
     uint32_t ptr;
     uint32_t n;
 
@@ -586,12 +603,12 @@  static void ohci_copy_td(OHCIState *ohci, struct ohci_td *td,
     n = 0x1000 - (ptr & 0xfff);
     if (n > len)
         n = len;
-    cpu_physical_memory_rw(ptr + ohci->localmem_base, buf, n, write);
+    pci_dma_rw(&s->pci_dev, ptr + ohci->localmem_base, buf, n, write);
     if (n == len)
         return;
     ptr = td->be & ~0xfffu;
     buf += n;
-    cpu_physical_memory_rw(ptr + ohci->localmem_base, buf, len - n, write);
+    pci_dma_rw(&s->pci_dev, ptr + ohci->localmem_base, buf, len - n, write);
 }
 
 /* Read/Write the contents of an ISO TD from/to main memory.  */
@@ -599,6 +616,7 @@  static void ohci_copy_iso_td(OHCIState *ohci,
                              uint32_t start_addr, uint32_t end_addr,
                              uint8_t *buf, int len, int write)
 {
+    OHCIPCIState *s = container_of(ohci, OHCIPCIState, state);
     uint32_t ptr;
     uint32_t n;
 
@@ -606,12 +624,12 @@  static void ohci_copy_iso_td(OHCIState *ohci,
     n = 0x1000 - (ptr & 0xfff);
     if (n > len)
         n = len;
-    cpu_physical_memory_rw(ptr + ohci->localmem_base, buf, n, write);
+    pci_dma_rw(&s->pci_dev, ptr + ohci->localmem_base, buf, n, write);
     if (n == len)
         return;
     ptr = end_addr & ~0xfffu;
     buf += n;
-    cpu_physical_memory_rw(ptr + ohci->localmem_base, buf, len - n, write);
+    pci_dma_rw(&s->pci_dev, ptr + ohci->localmem_base, buf, len - n, write);
 }
 
 static void ohci_process_lists(OHCIState *ohci, int completion);
@@ -1767,14 +1785,6 @@  static int usb_ohci_init(OHCIState *ohci, DeviceState *dev,
     return 0;
 }
 
-typedef struct {
-    PCIDevice pci_dev;
-    OHCIState state;
-    char *masterbus;
-    uint32_t num_ports;
-    uint32_t firstport;
-} OHCIPCIState;
-
 static int usb_ohci_initfn_pci(struct PCIDevice *dev)
 {
     OHCIPCIState *ohci = DO_UPCAST(OHCIPCIState, pci_dev, dev);