From patchwork Sat Jan 29 17:40:34 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: 516601 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id p0THfLsH005895 for ; Sat, 29 Jan 2011 17:41:21 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754757Ab1A2RlP (ORCPT ); Sat, 29 Jan 2011 12:41:15 -0500 Received: from mail-fx0-f46.google.com ([209.85.161.46]:59681 "EHLO mail-fx0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754697Ab1A2RlN (ORCPT ); Sat, 29 Jan 2011 12:41:13 -0500 Received: by mail-fx0-f46.google.com with SMTP id 20so4372099fxm.19 for ; Sat, 29 Jan 2011 09:41:12 -0800 (PST) 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:in-reply-to:references; bh=THQJJQB2SdNiBLueYdvB5QYfc6p0C0Qrqox/Rms/yxQ=; b=lb5Ny3Jwz6HvEkCDx5mFGCAeRJqLnEwBUrTopPTxOePliDng2H4Ua912IkLd579YYm XWAk1NXt/jxHAbGg9BB2yoSWj88Yuahvo3QQYn96pfvplSlc/NxJ+hI94hLDeinGOo2A qxoUmwATTcmb6DFaQMETd5lwF1+fir3lZFFNg= 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=Vg4ICKWBl1fKsONJrlpyljTCzmNOTXOysCjWjI0whLO+aAukEluO151xkOC8HWDBTN Gz6fKh/tOhq+Vre/RYLT/VbqQYn/eGXMts/jjQw8LkqHBqKSj7igM0sFQe2ziZAJdnmF 1SL+0hkiyo8MoMx2VX4Vac8Daj/Upbucd4cIw= Received: by 10.223.86.13 with SMTP id q13mr3879048fal.53.1296322872753; Sat, 29 Jan 2011 09:41:12 -0800 (PST) Received: from localhost.localdomain ([188.25.244.101]) by mx.google.com with ESMTPS id 21sm6822801fav.17.2011.01.29.09.41.11 (version=SSLv3 cipher=RC4-MD5); Sat, 29 Jan 2011 09:41:12 -0800 (PST) From: Eduard - Gabriel Munteanu 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 Subject: [PATCH 13/13] usb-ohci: use the DMA memory access interface Date: Sat, 29 Jan 2011 19:40:34 +0200 Message-Id: <1736c7062e2521a15ff5af4911307ad6e6472910.1296321798.git.eduard.munteanu@linux360.ro> X-Mailer: git-send-email 1.7.3.4 In-Reply-To: References: In-Reply-To: References: Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter1.kernel.org [140.211.167.41]); Sat, 29 Jan 2011 17:41:21 +0000 (UTC) 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) {