qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: David Gibson <david@gibson.dropbear.id.au>
To: qemu-devel@nongnu.org
Cc: joerg.roedel@amd.com, aliguori@us.ibm.com, rth@twiddle.net,
	agraf@suse.de, eduard.munteanu@linux360.ro
Subject: [Qemu-devel] [PATCH 09/10] usb-ohci: Use PCI DMA stub functions
Date: Thu,  1 Sep 2011 15:01:02 +1000	[thread overview]
Message-ID: <1314853263-2086-10-git-send-email-david@gibson.dropbear.id.au> (raw)
In-Reply-To: <1314853263-2086-1-git-send-email-david@gibson.dropbear.id.au>

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(-)

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);
-- 
1.7.5.4

  parent reply	other threads:[~2011-09-01  5:01 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-09-01  5:00 [Qemu-devel] [0/10] Preliminary work for IOMMU emulation support; the easy bits David Gibson
2011-09-01  5:00 ` [Qemu-devel] [PATCH 01/10] Add stub functions for PCI device models to do PCI DMA David Gibson
2011-09-01 15:35   ` Michael S. Tsirkin
2011-09-02  0:39     ` David Gibson
2011-09-02  4:38     ` David Gibson
2011-09-05  7:55       ` Michael S. Tsirkin
2011-09-01 15:55   ` Anthony Liguori
2011-09-01 16:03     ` Avi Kivity
2011-09-01 16:05       ` Anthony Liguori
2011-09-01 16:11         ` Avi Kivity
2011-09-01 16:32           ` Anthony Liguori
2011-09-02  8:35             ` Avi Kivity
2011-09-03 12:25               ` Blue Swirl
2011-09-02  0:38         ` David Gibson
2011-09-02  8:37         ` Avi Kivity
2011-09-03  3:04           ` Eduard - Gabriel Munteanu
2011-09-02  4:40       ` David Gibson
2011-09-03  1:16     ` Richard Henderson
2011-09-23 16:37   ` Anthony Liguori
2011-09-01  5:00 ` [Qemu-devel] [PATCH 02/10] rtl8139: Use PCI DMA stub functions David Gibson
2011-09-01  5:00 ` [Qemu-devel] [PATCH 03/10] eepro100: " David Gibson
2011-09-01  5:00 ` [Qemu-devel] [PATCH 04/10] ac97: " David Gibson
2011-09-01  5:00 ` [Qemu-devel] [PATCH 05/10] es1370: " David Gibson
2011-09-01  5:00 ` [Qemu-devel] [PATCH 06/10] e1000: " David Gibson
2011-09-01  5:01 ` [Qemu-devel] [PATCH 07/10] lsi53c895a: " David Gibson
2011-09-01  5:01 ` [Qemu-devel] [PATCH 08/10] pcnet-pci: " David Gibson
2011-09-01  5:01 ` David Gibson [this message]
2011-09-01 10:10   ` [Qemu-devel] [PATCH 09/10] usb-ohci: " Gerd Hoffmann
2011-09-02  1:47     ` David Gibson
2011-09-01  5:01 ` [Qemu-devel] [PATCH 10/10] intel-hda: " David Gibson
2011-09-01 10:16   ` Gerd Hoffmann
2011-09-02  1:42     ` David Gibson
2011-09-01 11:33 ` [Qemu-devel] [0/10] Preliminary work for IOMMU emulation support; the easy bits Eduard - Gabriel Munteanu
2011-09-02  0:36   ` David Gibson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1314853263-2086-10-git-send-email-david@gibson.dropbear.id.au \
    --to=david@gibson.dropbear.id.au \
    --cc=agraf@suse.de \
    --cc=aliguori@us.ibm.com \
    --cc=eduard.munteanu@linux360.ro \
    --cc=joerg.roedel@amd.com \
    --cc=qemu-devel@nongnu.org \
    --cc=rth@twiddle.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).