From patchwork Mon May 18 06:38:21 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: pmallapp@broadcom.com X-Patchwork-Id: 473606 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 5DB67140D4D for ; Tue, 19 May 2015 07:32:13 +1000 (AEST) Received: from localhost ([::1]:43031 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YuSdv-0005En-Bq for incoming@patchwork.ozlabs.org; Mon, 18 May 2015 17:32:11 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35540) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YuEhW-0006qA-23 for qemu-devel@nongnu.org; Mon, 18 May 2015 02:38:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YuEhP-0006xX-RW for qemu-devel@nongnu.org; Mon, 18 May 2015 02:38:58 -0400 Received: from mail-gw2-out.broadcom.com ([216.31.210.63]:14863) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YuEhP-0006wh-Gk for qemu-devel@nongnu.org; Mon, 18 May 2015 02:38:51 -0400 X-IronPort-AV: E=Sophos;i="5.13,451,1427785200"; d="scan'208";a="65079637" Received: from irvexchcas08.broadcom.com (HELO IRVEXCHCAS08.corp.ad.broadcom.com) ([10.9.208.57]) by mail-gw2-out.broadcom.com with ESMTP; 17 May 2015 23:48:46 -0700 Received: from IRVEXCHSMTP2.corp.ad.broadcom.com (10.9.207.52) by IRVEXCHCAS08.corp.ad.broadcom.com (10.9.208.57) with Microsoft SMTP Server (TLS) id 14.3.235.1; Sun, 17 May 2015 23:38:46 -0700 Received: from mail-irva-13.broadcom.com (10.10.10.20) by IRVEXCHSMTP2.corp.ad.broadcom.com (10.9.207.52) with Microsoft SMTP Server id 14.3.235.1; Sun, 17 May 2015 23:38:46 -0700 Received: from lbblr-srv-cps-97.ban.broadcom.com (unknown [10.131.60.97]) by mail-irva-13.broadcom.com (Postfix) with ESMTP id 45E2940FE8; Sun, 17 May 2015 23:37:03 -0700 (PDT) From: To: Date: Mon, 18 May 2015 12:08:21 +0530 Message-ID: <1431931101-31296-2-git-send-email-pmallapp@broadcom.com> X-Mailer: git-send-email 2.3.6 In-Reply-To: <1431931101-31296-1-git-send-email-pmallapp@broadcom.com> References: <1431931101-31296-1-git-send-email-pmallapp@broadcom.com> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 216.31.210.63 X-Mailman-Approved-At: Mon, 18 May 2015 17:31:24 -0400 Cc: Prem Mallappa Subject: [Qemu-devel] [PATCH] PCI: Added new API which propogates the DMA initiator info 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 From: Prem Mallappa Signed-off-by: Prem Mallappa --- exec.c | 48 +++++++++++++++++++++++++++++++++++++++++------- include/exec/memory.h | 9 +++++++++ include/hw/pci/pci.h | 8 +++++++- include/sysemu/dma.h | 17 +++++++++++++++++ 4 files changed, 74 insertions(+), 8 deletions(-) diff --git a/exec.c b/exec.c index e97071a..81f536a 100644 --- a/exec.c +++ b/exec.c @@ -373,9 +373,9 @@ static inline bool memory_access_is_direct(MemoryRegion *mr, bool is_write) return false; } -MemoryRegion *address_space_translate(AddressSpace *as, hwaddr addr, - hwaddr *xlat, hwaddr *plen, - bool is_write) +static MemoryRegion *_address_space_translate(AddressSpace *as, DeviceState *dev, + hwaddr addr, hwaddr *xlat, + hwaddr *plen, bool is_write) { IOMMUTLBEntry iotlb; MemoryRegionSection *section; @@ -392,7 +392,11 @@ MemoryRegion *address_space_translate(AddressSpace *as, hwaddr addr, break; } - iotlb = mr->iommu_ops->translate(mr, addr, is_write); + if (mr->iommu_ops->translate_dev && dev) + iotlb = mr->iommu_ops->translate_dev(mr, dev, addr, is_write); + else + iotlb = mr->iommu_ops->translate(mr, addr, is_write); + addr = ((iotlb.translated_addr & ~iotlb.addr_mask) | (addr & iotlb.addr_mask)); len = MIN(len, (addr | iotlb.addr_mask) - addr + 1); @@ -415,6 +419,20 @@ MemoryRegion *address_space_translate(AddressSpace *as, hwaddr addr, return mr; } +MemoryRegion *address_space_translate_dev(AddressSpace *as, DeviceState *dev, + hwaddr addr, hwaddr *xlat, + hwaddr *plen, bool is_write) +{ + return _address_space_translate(as, dev, addr, xlat, plen, is_write); +} + +MemoryRegion *address_space_translate(AddressSpace *as, hwaddr addr, + hwaddr *xlat, hwaddr *plen, + bool is_write) +{ + return _address_space_translate(as, NULL, addr, xlat, plen, is_write); +} + /* Called from RCU critical section */ MemoryRegionSection * address_space_translate_for_iotlb(CPUState *cpu, hwaddr addr, @@ -2305,8 +2323,9 @@ static int memory_access_size(MemoryRegion *mr, unsigned l, hwaddr addr) return l; } -bool address_space_rw(AddressSpace *as, hwaddr addr, uint8_t *buf, - int len, bool is_write) + +static bool _address_space_rw(AddressSpace *as, DeviceState *dev, hwaddr addr, uint8_t *buf, + int len, bool is_write) { hwaddr l; uint8_t *ptr; @@ -2317,7 +2336,10 @@ bool address_space_rw(AddressSpace *as, hwaddr addr, uint8_t *buf, while (len > 0) { l = len; - mr = address_space_translate(as, addr, &addr1, &l, is_write); + if (dev) + mr = address_space_translate_dev(as, dev, addr, &addr1, &l, is_write); + else + mr = address_space_translate(as, addr, &addr1, &l, is_write); if (is_write) { if (!memory_access_is_direct(mr, is_write)) { @@ -2397,6 +2419,18 @@ bool address_space_rw(AddressSpace *as, hwaddr addr, uint8_t *buf, return error; } +bool address_space_rw_dev(AddressSpace *as, DeviceState *dev, hwaddr addr, + uint8_t *buf, int len, bool is_write) +{ + return _address_space_rw(as, dev, addr, buf, len, is_write); +} + +bool address_space_rw(AddressSpace *as, hwaddr addr, uint8_t *buf, + int len, bool is_write) +{ + return _address_space_rw(as, NULL, addr, buf, len, is_write); +} + bool address_space_write(AddressSpace *as, hwaddr addr, const uint8_t *buf, int len) { diff --git a/include/exec/memory.h b/include/exec/memory.h index 06ffa1d..8d6b7a9 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -131,6 +131,8 @@ typedef struct MemoryRegionIOMMUOps MemoryRegionIOMMUOps; struct MemoryRegionIOMMUOps { /* Return a TLB entry that contains a given address. */ IOMMUTLBEntry (*translate)(MemoryRegion *iommu, hwaddr addr, bool is_write); + IOMMUTLBEntry (*translate_dev)(MemoryRegion *iommu, DeviceState *dev, + hwaddr addr, bool is_write); }; typedef struct CoalescedMemoryRange CoalescedMemoryRange; @@ -1054,6 +1056,7 @@ void address_space_destroy(AddressSpace *as); /** * address_space_rw: read from or write to an address space. + * address_space_rw_dev: A variant of address_space_rw, to pass on requesting device id. * * Return true if the operation hit any unassigned memory or encountered an * IOMMU fault. @@ -1066,6 +1069,8 @@ void address_space_destroy(AddressSpace *as); bool address_space_rw(AddressSpace *as, hwaddr addr, uint8_t *buf, int len, bool is_write); +bool address_space_rw_dev(AddressSpace *as, DeviceState *dev, hwaddr addr, + uint8_t *buf, int len, bool is_write); /** * address_space_write: write to address space. * @@ -1105,6 +1110,10 @@ MemoryRegion *address_space_translate(AddressSpace *as, hwaddr addr, hwaddr *xlat, hwaddr *len, bool is_write); +MemoryRegion *address_space_translate_dev(AddressSpace *as, DeviceState *dev, hwaddr addr, + hwaddr *xlat, hwaddr *len, + bool is_write); + /* address_space_access_valid: check for validity of accessing an address * space range * diff --git a/include/hw/pci/pci.h b/include/hw/pci/pci.h index be2d9b8..faa1df3 100644 --- a/include/hw/pci/pci.h +++ b/include/hw/pci/pci.h @@ -493,6 +493,12 @@ pci_config_set_interrupt_pin(uint8_t *pci_config, uint8_t val) pci_set_byte(&pci_config[PCI_INTERRUPT_PIN], val); } +static inline uint16_t +pci_get_arid(PCIDevice *pcidev) +{ + uint16_t busnum = (pci_bus_num(pcidev->bus)) & 0xff << 8; + return busnum | (pcidev->devfn & 0x7); +} /* * helper functions to do bit mask operation on configuration space. * Just to set bit, use test-and-set and discard returned value. @@ -674,7 +680,7 @@ static inline AddressSpace *pci_get_address_space(PCIDevice *dev) static inline int pci_dma_rw(PCIDevice *dev, dma_addr_t addr, void *buf, dma_addr_t len, DMADirection dir) { - dma_memory_rw(pci_get_address_space(dev), addr, buf, len, dir); + dma_memory_rw_dev(pci_get_address_space(dev), DEVICE(dev), addr, buf, len, dir); return 0; } diff --git a/include/sysemu/dma.h b/include/sysemu/dma.h index 3f2f4c8..ae84080 100644 --- a/include/sysemu/dma.h +++ b/include/sysemu/dma.h @@ -84,6 +84,14 @@ static inline bool dma_memory_valid(AddressSpace *as, dir == DMA_DIRECTION_FROM_DEVICE); } +/* @dev: Requesting Device */ +static inline int dma_memory_rw_relaxed_dev(AddressSpace *as, DeviceState *dev, + dma_addr_t addr, void *buf, dma_addr_t len, + DMADirection dir) +{ + return address_space_rw_dev(as, dev, addr, buf, len, dir == DMA_DIRECTION_FROM_DEVICE); +} + static inline int dma_memory_rw_relaxed(AddressSpace *as, dma_addr_t addr, void *buf, dma_addr_t len, DMADirection dir) @@ -104,6 +112,15 @@ static inline int dma_memory_write_relaxed(AddressSpace *as, dma_addr_t addr, DMA_DIRECTION_FROM_DEVICE); } +/* @dev: Requesting Device */ +static inline int dma_memory_rw_dev(AddressSpace *as, DeviceState *dev, + dma_addr_t addr, void *buf, dma_addr_t len, + DMADirection dir) +{ + dma_barrier(as, dir); + return dma_memory_rw_relaxed_dev(as, dev, addr, buf, len, dir); +} + static inline int dma_memory_rw(AddressSpace *as, dma_addr_t addr, void *buf, dma_addr_t len, DMADirection dir)