All of lore.kernel.org
 help / color / mirror / Atom feed
From: Eduard - Gabriel Munteanu <eduard.munteanu@linux360.ro>
To: joro@8bytes.org
Cc: blauwirbel@gmail.com, paul@codesourcery.com, avi@redhat.com,
	anthony@codemonkey.ws, av1474@comtv.ru, yamahata@valinux.co.jp,
	kvm@vger.kernel.org, qemu-devel@nongnu.org,
	Eduard - Gabriel Munteanu <eduard.munteanu@linux360.ro>
Subject: [PATCH 13/13] usb-ohci: use the DMA memory access interface
Date: Sat, 29 Jan 2011 19:40:34 +0200	[thread overview]
Message-ID: <1736c7062e2521a15ff5af4911307ad6e6472910.1296321798.git.eduard.munteanu@linux360.ro> (raw)
In-Reply-To: <cover.1296321798.git.eduard.munteanu@linux360.ro>
In-Reply-To: <cover.1296321798.git.eduard.munteanu@linux360.ro>

This allows the device to work properly with an emulated IOMMU.

Signed-off-by: Eduard - Gabriel Munteanu <eduard.munteanu@linux360.ro>
---
 hw/usb-ohci.c |   54 +++++++++++++++++++++++++++++++++++++-----------------
 1 files changed, 37 insertions(+), 17 deletions(-)

diff --git a/hw/usb-ohci.c b/hw/usb-ohci.c
index 240e840..ff27024 100644
--- a/hw/usb-ohci.c
+++ b/hw/usb-ohci.c
@@ -116,6 +116,11 @@ typedef struct {
 
 } OHCIState;
 
+typedef struct {
+    PCIDevice pci_dev;
+    OHCIState state;
+} OHCIPCIState;
+
 /* Host Controller Communications Area */
 struct ohci_hcca {
     uint32_t intr[32];
@@ -427,12 +432,14 @@ 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);
+    DMADevice *dma = &s->pci_dev.dma;
     int i;
 
     addr += ohci->localmem_base;
 
     for (i = 0; i < num; i++, buf++, addr += sizeof(*buf)) {
-        cpu_physical_memory_rw(addr, (uint8_t *)buf, sizeof(*buf), 0);
+        dma_memory_rw(dma, addr, (uint8_t *)buf, sizeof(*buf), 0);
         *buf = le32_to_cpu(*buf);
     }
 
@@ -443,13 +450,15 @@ 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);
+    DMADevice *dma = &s->pci_dev.dma;
     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_rw(addr, (uint8_t *)&tmp, sizeof(tmp), 1);
+        dma_memory_rw(dma, addr, (uint8_t *)&tmp, sizeof(tmp), 1);
     }
 
     return 1;
@@ -459,12 +468,14 @@ 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);
+    DMADevice *dma = &s->pci_dev.dma;
     int i;
 
     addr += ohci->localmem_base;
 
     for (i = 0; i < num; i++, buf++, addr += sizeof(*buf)) {
-        cpu_physical_memory_rw(addr, (uint8_t *)buf, sizeof(*buf), 0);
+        dma_memory_rw(dma, addr, (uint8_t *)buf, sizeof(*buf), 0);
         *buf = le16_to_cpu(*buf);
     }
 
@@ -475,13 +486,15 @@ 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);
+    DMADevice *dma = &s->pci_dev.dma;
     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_rw(addr, (uint8_t *)&tmp, sizeof(tmp), 1);
+        dma_memory_rw(dma, addr, (uint8_t *)&tmp, sizeof(tmp), 1);
     }
 
     return 1;
@@ -509,8 +522,12 @@ 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_rw(addr + ohci->localmem_base,
-                           (uint8_t *)hcca, sizeof(*hcca), 0);
+    OHCIPCIState *s = container_of(ohci, OHCIPCIState, state);
+
+    dma_memory_rw(&s->pci_dev.dma,
+                  addr + ohci->localmem_base,
+                  (uint8_t *)hcca, sizeof(*hcca), 0);
+
     return 1;
 }
 
@@ -536,8 +553,12 @@ 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_rw(addr + ohci->localmem_base,
-                           (uint8_t *)hcca, sizeof(*hcca), 1);
+    OHCIPCIState *s = container_of(ohci, OHCIPCIState, state);
+
+    dma_memory_rw(&s->pci_dev.dma,
+                  addr + ohci->localmem_base,
+                  (uint8_t *)hcca, sizeof(*hcca), 1);
+
     return 1;
 }
 
@@ -545,6 +566,8 @@ 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);
+    DMADevice *dma = &s->pci_dev.dma;
     uint32_t ptr;
     uint32_t n;
 
@@ -552,12 +575,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);
+    dma_memory_rw(dma, 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);
+    dma_memory_rw(dma, ptr + ohci->localmem_base, buf, len - n, write);
 }
 
 /* Read/Write the contents of an ISO TD from/to main memory.  */
@@ -565,6 +588,8 @@ 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);
+    DMADevice *dma = &s->pci_dev.dma;
     uint32_t ptr;
     uint32_t n;
 
@@ -572,12 +597,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);
+    dma_memory_rw(dma, 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);
+    dma_memory_rw(dma, ptr + ohci->localmem_base, buf, len - n, write);
 }
 
 static void ohci_process_lists(OHCIState *ohci, int completion);
@@ -1706,11 +1731,6 @@ static void usb_ohci_init(OHCIState *ohci, DeviceState *dev,
     qemu_register_reset(ohci_reset, ohci);
 }
 
-typedef struct {
-    PCIDevice pci_dev;
-    OHCIState state;
-} OHCIPCIState;
-
 static void ohci_mapfunc(PCIDevice *pci_dev, int i,
             pcibus_t addr, pcibus_t size, int type)
 {
-- 
1.7.3.4


WARNING: multiple messages have this Message-ID (diff)
From: Eduard - Gabriel Munteanu <eduard.munteanu@linux360.ro>
To: joro@8bytes.org
Cc: kvm@vger.kernel.org, qemu-devel@nongnu.org, blauwirbel@gmail.com,
	yamahata@valinux.co.jp, paul@codesourcery.com,
	Eduard - Gabriel Munteanu <eduard.munteanu@linux360.ro>,
	avi@redhat.com
Subject: [Qemu-devel] [PATCH 13/13] usb-ohci: use the DMA memory access interface
Date: Sat, 29 Jan 2011 19:40:34 +0200	[thread overview]
Message-ID: <1736c7062e2521a15ff5af4911307ad6e6472910.1296321798.git.eduard.munteanu@linux360.ro> (raw)
In-Reply-To: <cover.1296321798.git.eduard.munteanu@linux360.ro>
In-Reply-To: <cover.1296321798.git.eduard.munteanu@linux360.ro>

This allows the device to work properly with an emulated IOMMU.

Signed-off-by: Eduard - Gabriel Munteanu <eduard.munteanu@linux360.ro>
---
 hw/usb-ohci.c |   54 +++++++++++++++++++++++++++++++++++++-----------------
 1 files changed, 37 insertions(+), 17 deletions(-)

diff --git a/hw/usb-ohci.c b/hw/usb-ohci.c
index 240e840..ff27024 100644
--- a/hw/usb-ohci.c
+++ b/hw/usb-ohci.c
@@ -116,6 +116,11 @@ typedef struct {
 
 } OHCIState;
 
+typedef struct {
+    PCIDevice pci_dev;
+    OHCIState state;
+} OHCIPCIState;
+
 /* Host Controller Communications Area */
 struct ohci_hcca {
     uint32_t intr[32];
@@ -427,12 +432,14 @@ 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);
+    DMADevice *dma = &s->pci_dev.dma;
     int i;
 
     addr += ohci->localmem_base;
 
     for (i = 0; i < num; i++, buf++, addr += sizeof(*buf)) {
-        cpu_physical_memory_rw(addr, (uint8_t *)buf, sizeof(*buf), 0);
+        dma_memory_rw(dma, addr, (uint8_t *)buf, sizeof(*buf), 0);
         *buf = le32_to_cpu(*buf);
     }
 
@@ -443,13 +450,15 @@ 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);
+    DMADevice *dma = &s->pci_dev.dma;
     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_rw(addr, (uint8_t *)&tmp, sizeof(tmp), 1);
+        dma_memory_rw(dma, addr, (uint8_t *)&tmp, sizeof(tmp), 1);
     }
 
     return 1;
@@ -459,12 +468,14 @@ 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);
+    DMADevice *dma = &s->pci_dev.dma;
     int i;
 
     addr += ohci->localmem_base;
 
     for (i = 0; i < num; i++, buf++, addr += sizeof(*buf)) {
-        cpu_physical_memory_rw(addr, (uint8_t *)buf, sizeof(*buf), 0);
+        dma_memory_rw(dma, addr, (uint8_t *)buf, sizeof(*buf), 0);
         *buf = le16_to_cpu(*buf);
     }
 
@@ -475,13 +486,15 @@ 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);
+    DMADevice *dma = &s->pci_dev.dma;
     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_rw(addr, (uint8_t *)&tmp, sizeof(tmp), 1);
+        dma_memory_rw(dma, addr, (uint8_t *)&tmp, sizeof(tmp), 1);
     }
 
     return 1;
@@ -509,8 +522,12 @@ 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_rw(addr + ohci->localmem_base,
-                           (uint8_t *)hcca, sizeof(*hcca), 0);
+    OHCIPCIState *s = container_of(ohci, OHCIPCIState, state);
+
+    dma_memory_rw(&s->pci_dev.dma,
+                  addr + ohci->localmem_base,
+                  (uint8_t *)hcca, sizeof(*hcca), 0);
+
     return 1;
 }
 
@@ -536,8 +553,12 @@ 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_rw(addr + ohci->localmem_base,
-                           (uint8_t *)hcca, sizeof(*hcca), 1);
+    OHCIPCIState *s = container_of(ohci, OHCIPCIState, state);
+
+    dma_memory_rw(&s->pci_dev.dma,
+                  addr + ohci->localmem_base,
+                  (uint8_t *)hcca, sizeof(*hcca), 1);
+
     return 1;
 }
 
@@ -545,6 +566,8 @@ 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);
+    DMADevice *dma = &s->pci_dev.dma;
     uint32_t ptr;
     uint32_t n;
 
@@ -552,12 +575,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);
+    dma_memory_rw(dma, 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);
+    dma_memory_rw(dma, ptr + ohci->localmem_base, buf, len - n, write);
 }
 
 /* Read/Write the contents of an ISO TD from/to main memory.  */
@@ -565,6 +588,8 @@ 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);
+    DMADevice *dma = &s->pci_dev.dma;
     uint32_t ptr;
     uint32_t n;
 
@@ -572,12 +597,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);
+    dma_memory_rw(dma, 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);
+    dma_memory_rw(dma, ptr + ohci->localmem_base, buf, len - n, write);
 }
 
 static void ohci_process_lists(OHCIState *ohci, int completion);
@@ -1706,11 +1731,6 @@ static void usb_ohci_init(OHCIState *ohci, DeviceState *dev,
     qemu_register_reset(ohci_reset, ohci);
 }
 
-typedef struct {
-    PCIDevice pci_dev;
-    OHCIState state;
-} OHCIPCIState;
-
 static void ohci_mapfunc(PCIDevice *pci_dev, int i,
             pcibus_t addr, pcibus_t size, int type)
 {
-- 
1.7.3.4

  parent reply	other threads:[~2011-01-29 17:41 UTC|newest]

Thread overview: 58+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-01-29 17:40 [PATCH 00/13] AMD IOMMU emulation patchset Eduard - Gabriel Munteanu
2011-01-29 17:40 ` [Qemu-devel] " Eduard - Gabriel Munteanu
2011-01-29 17:40 ` [PATCH 01/13] Generic DMA memory access interface Eduard - Gabriel Munteanu
2011-01-29 17:40   ` [Qemu-devel] " Eduard - Gabriel Munteanu
2011-02-05 10:20   ` Blue Swirl
2011-02-05 10:20     ` [Qemu-devel] " Blue Swirl
2011-02-06 11:13   ` Michael S. Tsirkin
2011-02-06 11:13     ` [Qemu-devel] " Michael S. Tsirkin
2011-02-06 11:16   ` Michael S. Tsirkin
2011-02-06 11:16     ` [Qemu-devel] " Michael S. Tsirkin
2011-01-29 17:40 ` [PATCH 02/13] pci: add IOMMU support via the generic DMA layer Eduard - Gabriel Munteanu
2011-01-29 17:40   ` [Qemu-devel] " Eduard - Gabriel Munteanu
2011-01-29 17:40 ` [PATCH 03/13] AMD IOMMU emulation Eduard - Gabriel Munteanu
2011-01-29 17:40   ` [Qemu-devel] " Eduard - Gabriel Munteanu
2011-02-06 10:54   ` Michael S. Tsirkin
2011-02-06 10:54     ` [Qemu-devel] " Michael S. Tsirkin
2011-01-29 17:40 ` [PATCH 04/13] ide: use the DMA memory access interface for PCI IDE controllers Eduard - Gabriel Munteanu
2011-01-29 17:40   ` [Qemu-devel] " Eduard - Gabriel Munteanu
2011-02-06 11:14   ` Michael S. Tsirkin
2011-02-06 11:14     ` [Qemu-devel] " Michael S. Tsirkin
2011-01-29 17:40 ` [PATCH 05/13] rtl8139: use the DMA memory access interface Eduard - Gabriel Munteanu
2011-01-29 17:40   ` [Qemu-devel] " Eduard - Gabriel Munteanu
2011-01-29 17:40 ` [PATCH 06/13] eepro100: " Eduard - Gabriel Munteanu
2011-01-29 17:40   ` [Qemu-devel] " Eduard - Gabriel Munteanu
2011-01-29 17:40 ` [PATCH 07/13] ac97: " Eduard - Gabriel Munteanu
2011-01-29 17:40   ` [Qemu-devel] " Eduard - Gabriel Munteanu
2011-01-29 17:40 ` [PATCH 08/13] es1370: " Eduard - Gabriel Munteanu
2011-01-29 17:40   ` [Qemu-devel] " Eduard - Gabriel Munteanu
2011-01-29 17:40 ` [PATCH 09/13] e1000: " Eduard - Gabriel Munteanu
2011-01-29 17:40   ` [Qemu-devel] " Eduard - Gabriel Munteanu
2011-01-29 17:40 ` [PATCH 10/13] lsi53c895a: " Eduard - Gabriel Munteanu
2011-01-29 17:40   ` [Qemu-devel] " Eduard - Gabriel Munteanu
2011-01-29 17:40 ` [PATCH 11/13] pcnet: " Eduard - Gabriel Munteanu
2011-01-29 17:40   ` [Qemu-devel] " Eduard - Gabriel Munteanu
2011-01-29 17:40 ` [PATCH 12/13] usb-uhci: " Eduard - Gabriel Munteanu
2011-01-29 17:40   ` [Qemu-devel] " Eduard - Gabriel Munteanu
2011-01-29 17:40 ` Eduard - Gabriel Munteanu [this message]
2011-01-29 17:40   ` [Qemu-devel] [PATCH 13/13] usb-ohci: " Eduard - Gabriel Munteanu
2011-01-29 20:19 ` [PATCH 00/13] AMD IOMMU emulation patchset malc
2011-01-29 20:19   ` [Qemu-devel] " malc
2011-02-03 23:24 ` [PATCH 0/3] SeaBIOS AMD IOMMU initialization patches Eduard - Gabriel Munteanu
2011-02-03 23:24   ` [Qemu-devel] " Eduard - Gabriel Munteanu
2011-02-03 23:24   ` [PATCH 1/3] pci: add pci_find_capability() helper Eduard - Gabriel Munteanu
2011-02-03 23:24     ` [Qemu-devel] " Eduard - Gabriel Munteanu
2011-02-03 23:24   ` [PATCH 2/3] AMD IOMMU support Eduard - Gabriel Munteanu
2011-02-03 23:24     ` [Qemu-devel] " Eduard - Gabriel Munteanu
2011-02-04  2:37     ` Isaku Yamahata
2011-02-04  2:37       ` [Qemu-devel] " Isaku Yamahata
2011-02-06 11:47     ` Michael S. Tsirkin
2011-02-06 11:47       ` [Qemu-devel] " Michael S. Tsirkin
2011-02-06 13:41       ` Eduard - Gabriel Munteanu
2011-02-06 13:41         ` [Qemu-devel] " Eduard - Gabriel Munteanu
2011-02-06 15:22         ` Michael S. Tsirkin
2011-02-06 15:22           ` [Qemu-devel] " Michael S. Tsirkin
2011-02-03 23:24   ` [PATCH 3/3] Clarify address space layout Eduard - Gabriel Munteanu
2011-02-03 23:24     ` [Qemu-devel] " Eduard - Gabriel Munteanu
2011-02-05 13:07 ` [PATCH 00/13] AMD IOMMU emulation patchset (reworked cc/to) Blue Swirl
2011-02-05 13:07   ` [Qemu-devel] " Blue Swirl

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=1736c7062e2521a15ff5af4911307ad6e6472910.1296321798.git.eduard.munteanu@linux360.ro \
    --to=eduard.munteanu@linux360.ro \
    --cc=anthony@codemonkey.ws \
    --cc=av1474@comtv.ru \
    --cc=avi@redhat.com \
    --cc=blauwirbel@gmail.com \
    --cc=joro@8bytes.org \
    --cc=kvm@vger.kernel.org \
    --cc=paul@codesourcery.com \
    --cc=qemu-devel@nongnu.org \
    --cc=yamahata@valinux.co.jp \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.