From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:55100) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QS9a8-0004Uz-DH for qemu-devel@nongnu.org; Thu, 02 Jun 2011 11:13:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QS9a3-0005Kr-Bu for qemu-devel@nongnu.org; Thu, 02 Jun 2011 11:13:07 -0400 Received: from ozlabs.org ([203.10.76.45]:53227) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QS9a2-0005Iu-5B for qemu-devel@nongnu.org; Thu, 02 Jun 2011 11:13:02 -0400 From: David Gibson Date: Fri, 3 Jun 2011 01:12:41 +1000 Message-Id: <1307027562-3460-14-git-send-email-david@gibson.dropbear.id.au> In-Reply-To: <1307027562-3460-1-git-send-email-david@gibson.dropbear.id.au> References: <1307027562-3460-1-git-send-email-david@gibson.dropbear.id.au> Subject: [Qemu-devel] [PATCH 13/14] usb-ohci: use the DMA memory access interface List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org, eduard.munteanu@linux360.ro, rth@twiddle.net This allows the device to work properly with an emulated IOMMU. Signed-off-by: Eduard - Gabriel Munteanu --- hw/usb-ohci.c | 43 ++++++++++++++++++++++++++++--------------- 1 files changed, 28 insertions(+), 15 deletions(-) diff --git a/hw/usb-ohci.c b/hw/usb-ohci.c index 8b966f7..061aa7b 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]; @@ -422,12 +427,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)); + dma_memory_read(&s->pci_dev.qdev, addr, buf, sizeof(*buf)); *buf = le32_to_cpu(*buf); } @@ -438,13 +444,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)); + dma_memory_write(&s->pci_dev.qdev, addr, &tmp, sizeof(tmp)); } return 1; @@ -454,12 +461,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)); + dma_memory_read(&s->pci_dev.qdev, addr, buf, sizeof(*buf)); *buf = le16_to_cpu(*buf); } @@ -470,13 +478,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)); + dma_memory_write(&s->pci_dev.qdev, addr, &tmp, sizeof(tmp)); } return 1; @@ -504,7 +513,9 @@ 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); + dma_memory_read(&s->pci_dev.qdev, addr + ohci->localmem_base, hcca, + sizeof(*hcca)); return 1; } @@ -530,7 +541,10 @@ 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); + + dma_memory_write(&s->pci_dev.qdev, addr + ohci->localmem_base, hcca, + sizeof(*hcca)); return 1; } @@ -538,6 +552,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; @@ -545,12 +560,13 @@ 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(&s->pci_dev.qdev, 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(&s->pci_dev.qdev, ptr + ohci->localmem_base, + buf, len - n, write); } /* Read/Write the contents of an ISO TD from/to main memory. */ @@ -558,6 +574,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; @@ -565,12 +582,13 @@ 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(&s->pci_dev.qdev, 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(&s->pci_dev.qdev, ptr + ohci->localmem_base, + buf, len - n, write); } static void ohci_process_lists(OHCIState *ohci, int completion); @@ -1703,11 +1721,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 int usb_ohci_initfn_pci(struct PCIDevice *dev) { OHCIPCIState *ohci = DO_UPCAST(OHCIPCIState, pci_dev, dev); -- 1.7.4.4