hw: Let DMA/PCI API take MemTxAttrs argument and propagate MemTxResult
v2 cover hw: Let DMA/PCI API take MemTxAttrs argument and propagate MemTxResult
This is a respin of:
"dma: Let the DMA API take MemTxAttrs argument and propagate MemTxResult"
https://lists.gnu.org/archive/html/qemu-devel/2020-09/msg02048.html
and:
"pci: Let PCI DMA API functions propagate a MemTxResult"
https://lists.gnu.org/archive/html/qemu-devel/2020-09/msg02048.html
The DMA API propagates MemTxResult:
- MEMTX_OK,
- MEMTX_device_ERROR,
- MEMTX_DECODE_ERROR.
Let the PCI DMA API propagate them, as they are
clearer than an undocumented 'int'.
Klaus Jensen (1):
pci: pass along the return value of dma_memory_rw
Philippe Mathieu-Daudé (15):
docs/devel/loads-stores: Add regexp for DMA functions
dma: Document address_space_map/address_space_unmap() prototypes
dma: Let dma_memory_set() propagate MemTxResult
dma: Let dma_memory_rw() propagate MemTxResult
dma: Let dma_memory_read() propagate MemTxResult
dma: Let dma_memory_write() propagate MemTxResult
dma: Let dma_memory_valid() take MemTxAttrs argument
dma: Let dma_memory_set() take MemTxAttrs argument
dma: Let dma_memory_rw_relaxed() take MemTxAttrs argument
dma: Let dma_memory_rw() take MemTxAttrs argument
dma: Let dma_memory_read/write() take MemTxAttrs argument
dma: Let dma_memory_map() take MemTxAttrs argument
pci: Let pci_dma_rw() propagate MemTxResult
pci: Let pci_dma_read() propagate MemTxResult
pci: Let pci_dma_write() propagate MemTxResult
docs/devel/loads-stores.rst | 2 + include/hw/pci/pci.h | 57 +++++++++++-- include/hw/ppc/spapr_vio.h | 11 ++- include/sysemu/dma.h | 155 +++++++++++++++++++++++++++------- dma-helpers.c | 16 ++-- hw/arm/musicpal.c | 13 +-- hw/arm/smmu-common.c | 3 +- hw/arm/smmuv3.c | 14 +-- hw/core/generic-loader.c | 3 +- hw/display/virtio-gpu.c | 8 +- hw/dma/pl330.c | 12 ++- hw/dma/sparc32_dma.c | 16 ++-- hw/dma/xlnx-zynq-devcfg.c | 6 +- hw/dma/xlnx_dpdma.c | 10 ++- hw/hyperv/vmbus.c | 8 +- hw/i386/amd_iommu.c | 16 ++-- hw/i386/intel_iommu.c | 28 +++--- hw/ide/ahci.c | 9 +- hw/ide/macio.c | 2 +- hw/intc/spapr_xive.c | 3 +- hw/intc/xive.c | 7 +- hw/misc/bcm2835_property.c | 3 +- hw/misc/macio/mac_dbdma.c | 10 ++- hw/net/allwinner-sun8i-emac.c | 21 +++-- hw/net/ftgmac100.c | 25 ++++-- hw/net/imx_fec.c | 32 ++++--- hw/nvram/fw_cfg.c | 12 ++- hw/pci-host/pnv_phb3.c | 5 +- hw/pci-host/pnv_phb3_msi.c | 9 +- hw/pci-host/pnv_phb4.c | 7 +- hw/sd/allwinner-sdhost.c | 14 +-- hw/sd/sdhci.c | 35 +++++--- hw/usb/hcd-dwc2.c | 8 +- hw/usb/hcd-ehci.c | 6 +- hw/usb/hcd-ohci.c | 28 +++--- hw/usb/hcd-xhci.c | 18 ++-- hw/usb/libhw.c | 3 +- hw/virtio/virtio.c | 6 +- 38 files changed, 439 insertions(+), 202 deletions(-)
Signature · 1 line
2.26.2
PATCH v2 1/16 pci: pass along the return value of dma_memory_rw
From: Klaus Jensen <[email protected]>
Some might actually care about the return value of dma_memory_rw. So let us pass it along instead of ignoring it.
There are no existing users of the return value, so this patch should be safe.
Message-Id: <[email protected]>
--- include/hw/pci/pci.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
include/hw/pci/pci.h +1 -2
@@ -783,8 +783,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); -return 0 ; +return dma_memory_rw (pci_get_address_space (dev), addr, buf, len, dir); } static inline int pci_dma_read(PCIDevice *dev, dma_addr_t addr,
Signature · 1 line
2.26.2
Quoted 9 lines · Philippe Mathieu-Daudé
This is a respin of:
"dma: Let the DMA API take MemTxAttrs argument and propagate MemTxResult"
https://lists.gnu.org/archive/html/qemu-devel/2020-09/msg02048.htmland:
"pci: Let PCI DMA API functions propagate a MemTxResult"
https://lists.gnu.org/archive/html/qemu-devel/2020-09/msg02048.html
Err, wrong git-profile.
PATCH v2 2/16 docs/devel/loads-stores: Add regexp for DMA functions
In reply to Philippe Mathieu-DaudéFrom: Philippe Mathieu-Daudé <[email protected]>
--- docs/devel/loads-stores.rst | 2 ++ 1 file changed, 2 insertions(+)
docs/devel/loads-stores.rst +2 -0
@@ -477,6 +477,8 @@ make sure our existing code is doing things correctly. Regexes for git grep - ``\<dma_memory_\(read\|write\|rw\)\>`` + - ``\<ldu\?[bwlq]\(_[bl]e\)\?_dma\>`` + - ``\<st[bwlq]\(_[bl]e\)\?_dma\>`` ``pci_dma_*`` and ``{ld,st}*_pci_dma`` ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Signature · 1 line
2.26.2
PATCH v2 3/16 dma: Document address_space_map/address_space_unmap() prototypes
In reply to Philippe Mathieu-DaudéFrom: Philippe Mathieu-Daudé <[email protected]>
Add documentation based on address_space_map / address_space_unmap.
--- include/sysemu/dma.h | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-)
include/sysemu/dma.h +28 -1
@@ -1,7 +1,7 @@/* * DMA helper functions * -* Copyright (c) 2009 Red Hat +* Copyright (c) 2009, 2020 Red Hat * * This work is licensed under the terms of the GNU General Public License * (GNU GPL), version 2 or later.
@@ -125,6 +125,19 @@ static inline int dma_memory_write(AddressSpace *as, dma_addr_t addr,int dma_memory_set (AddressSpace *as,dma_addr_t addr,uint8_t c,dma_addr_t len); +/** +* address_space_map: Map a physical memory region into a host virtual address. +* +* May map a subset of the requested range, given by and returned in @plen. +* May return %NULL and set *@plen to zero(0), if resources needed to perform +* the mapping are exhausted. +* Use only for reads OR writes - not for read-modify-write operations. +* +* @as: #AddressSpace to be accessed +* @addr: address within that address space +* @len: pointer to length of buffer; updated on return +* @dir: indicates the transfer direction +*/ static inline void *dma_memory_map (AddressSpace *as,dma_addr_t addr,dma_addr_t *len,DMADirection dir)
@@ -138,6 +151,20 @@ static inline void *dma_memory_map(AddressSpace *as,return p; } +/** +* address_space_unmap: Unmaps a memory region previously mapped +* by dma_memory_map() +* +* Will also mark the memory as dirty if @dir == %DMA_DIRECTION_FROM_DEVICE. +* @access_len gives the amount of memory that was actually read or written +* by the caller. +* +* @as: #AddressSpace used +* @buffer: host pointer as returned by address_space_map() +* @len: buffer length as returned by address_space_map() +* @dir: indicates the transfer direction +* @access_len: amount of data actually transferred +*/ static inline void dma_memory_unmap (AddressSpace *as,void *buffer,dma_addr_t len,DMADirection dir,dma_addr_t access_len)
Signature · 1 line
2.26.2
PATCH v2 4/16 dma: Let dma_memory_set() propagate MemTxResult
In reply to Philippe Mathieu-DaudéFrom: Philippe Mathieu-Daudé <[email protected]>
address_space_write() returns a MemTxResult type. Do not discard it, return it to the caller.
--- include/sysemu/dma.h | 15 ++++++++++++++- dma-helpers.c | 7 ++++--- 2 files changed, 18 insertions(+), 4 deletions(-)
include/sysemu/dma.h +14 -1
@@ -123,7 +123,20 @@ static inline int dma_memory_write(AddressSpace *as, dma_addr_t addr, DMA_DIRECTION_FROM_DEVICE); } -int dma_memory_set (AddressSpace *as,dma_addr_t addr,uint8_t c,dma_addr_t len); +/** +* dma_memory_set: Fill memory with a constant byte from DMA controller. +* +* Return a MemTxResult indicating whether the operation succeeded +* or failed (eg unassigned memory, device rejected the transaction, +* IOMMU fault). +* +* @as: #AddressSpace to be accessed +* @addr: address within that address space +* @c: constant byte to fill the memory +* @len: the number of bytes to fill with the constant byte +*/ +MemTxResult dma_memory_set (AddressSpace *as,dma_addr_t addr, +uint8_t c,dma_addr_t len);/** * address_space_map: Map a physical memory region into a host virtual address.
dma-helpers.c +4 -3
@@ -1,7 +1,7 @@/* * DMA helper functions * -* Copyright (c) 2009 Red Hat +* Copyright (c) 2009,2020 Red Hat * * This work is licensed under the terms of the GNU General Public License * (GNU GPL), version 2 or later.
@@ -18,14 +18,15 @@/* #define DEBUG_IOMMU */ -int dma_memory_set (AddressSpace *as,dma_addr_t addr,uint8_t c,dma_addr_t len) +MemTxResult dma_memory_set (AddressSpace *as,dma_addr_t addr, +uint8_t c,dma_addr_t len) {dma_barrier (as,DMA_DIRECTION_FROM_DEVICE );#define FILLBUF_SIZE 512uint8_t fillbuf[FILLBUF_SIZE ];int l; -bool error = false; +MemTxResult error =MEMTX_OK ;memset (fillbuf, c,FILLBUF_SIZE );while (len >0 ) {
Signature · 1 line
2.26.2