From patchwork Wed Jun 1 01:38:35 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eduard - Gabriel Munteanu X-Patchwork-Id: 98122 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 5BDF6B6F76 for ; Wed, 1 Jun 2011 15:42:56 +1000 (EST) Received: from localhost ([::1]:60255 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QReCj-0005up-4A for incoming@patchwork.ozlabs.org; Wed, 01 Jun 2011 01:42:53 -0400 Received: from eggs.gnu.org ([140.186.70.92]:50275) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QRaP3-00057j-4K for qemu-devel@nongnu.org; Tue, 31 May 2011 21:39:22 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QRaP0-0007Nl-R8 for qemu-devel@nongnu.org; Tue, 31 May 2011 21:39:20 -0400 Received: from mail-bw0-f45.google.com ([209.85.214.45]:36086) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QRaP0-0007GK-F1 for qemu-devel@nongnu.org; Tue, 31 May 2011 21:39:18 -0400 Received: by mail-bw0-f45.google.com with SMTP id 16so4438176bwz.4 for ; Tue, 31 May 2011 18:39:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:sender:from:to:cc:subject:date:message-id :x-mailer:in-reply-to:references; bh=U0Kjzl01ZqsqisWL6son+1trzq2FslRN0kA/oYPIIk0=; b=l3AypPhZVb6bd05m0pbvAjI2f+yrZVn7311zf2gRkKlHjvvbl2Mb8SoiV9A2pXXuTo jBNC62RM80BGYxUB5dB4GCKR4by2x7YWpo/6cULTKd3HAfKbH91/4MGDnZ64CpRnjxsq vKCufgnlRBys2JlGMPfQrBRSP6Kw2XOS2IXa0= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=sender:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references; b=d1Lv76Zhs8F+8wdht9oIjRAA0xzfblP0iG6S+JpLFJtfTrPTrp91khAuyrMuTJzRvj g/p4re8aJbGrBH/RLHPaEw5pQpL+bvvCjiHz78toG1A5sHDANSnwqXCt6NCt/pkXaNt0 6+vJgNpjCaHfuNjXCSspQAhwov5cOud7sToVQ= Received: by 10.204.136.210 with SMTP id s18mr5971106bkt.56.1306892357637; Tue, 31 May 2011 18:39:17 -0700 (PDT) Received: from localhost.localdomain ([188.25.93.127]) by mx.google.com with ESMTPS id ag6sm453451bkc.18.2011.05.31.18.39.15 (version=SSLv3 cipher=OTHER); Tue, 31 May 2011 18:39:17 -0700 (PDT) From: Eduard - Gabriel Munteanu To: mst@redhat.com Date: Wed, 1 Jun 2011 04:38:35 +0300 Message-Id: <1306892315-7306-14-git-send-email-eduard.munteanu@linux360.ro> X-Mailer: git-send-email 1.7.3.4 In-Reply-To: <1306892315-7306-1-git-send-email-eduard.munteanu@linux360.ro> References: <1306892315-7306-1-git-send-email-eduard.munteanu@linux360.ro> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-Received-From: 209.85.214.45 X-Mailman-Approved-At: Wed, 01 Jun 2011 00:57:36 -0400 Cc: aliguori@us.ibm.com, david@gibson.dropbear.id.au, kvm@vger.kernel.org, rth@twiddle.net, aik@ozlabs.ru, joro@8bytes.org, seabios@seabios.org, qemu-devel@nongnu.org, agraf@suse.de, blauwirbel@gmail.com, yamahata@valinux.co.jp, kevin@koconnor.net, avi@redhat.com, Eduard - Gabriel Munteanu , dwg@au1.ibm.com, paul@codesourcery.com Subject: [Qemu-devel] [RFC PATCH 13/13] usb-ohci: use the DMA memory access interface X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org This allows the device to work properly with an emulated IOMMU. Signed-off-by: Eduard - Gabriel Munteanu --- hw/usb-ohci.c | 46 +++++++++++++++++++++++++++++++--------------- 1 files changed, 31 insertions(+), 15 deletions(-) diff --git a/hw/usb-ohci.c b/hw/usb-ohci.c index d21c820..9d1cf91 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)); + pci_memory_read(&s->pci_dev, 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)); + pci_memory_write(&s->pci_dev, 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)); + pci_memory_read(&s->pci_dev, 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)); + pci_memory_write(&s->pci_dev, addr, &tmp, sizeof(tmp)); } return 1; @@ -504,7 +513,11 @@ 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_memory_read(&s->pci_dev, + addr + ohci->localmem_base, hcca, sizeof(*hcca)); + return 1; } @@ -530,7 +543,11 @@ 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_memory_write(&s->pci_dev, + addr + ohci->localmem_base, hcca, sizeof(*hcca)); + return 1; } @@ -538,6 +555,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; @@ -545,12 +564,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. */ @@ -558,6 +577,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; @@ -565,12 +586,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 +1727,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);