* [PATCH v2 00/16] hw: Let DMA/PCI API take MemTxAttrs argument and propagate MemTxResult
@ 2020-10-01 17:21 Philippe Mathieu-Daudé
2020-10-01 17:21 ` [PATCH v2 01/16] pci: pass along the return value of dma_memory_rw Philippe Mathieu-Daudé
` (4 more replies)
0 siblings, 5 replies; 6+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-10-01 17:21 UTC (permalink / raw)
To: qemu-devel; +Cc: Paolo Bonzini
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(-)
--
2.26.2
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v2 01/16] pci: pass along the return value of dma_memory_rw
2020-10-01 17:21 [PATCH v2 00/16] hw: Let DMA/PCI API take MemTxAttrs argument and propagate MemTxResult Philippe Mathieu-Daudé
@ 2020-10-01 17:21 ` Philippe Mathieu-Daudé
2020-10-01 17:21 ` [PATCH v2 02/16] docs/devel/loads-stores: Add regexp for DMA functions Philippe Mathieu-Daudé
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-10-01 17:21 UTC (permalink / raw)
To: qemu-devel; +Cc: Paolo Bonzini
From: Klaus Jensen <k.jensen@samsung.com>
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.
Signed-off-by: Klaus Jensen <k.jensen@samsung.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Acked-by: Keith Busch <kbusch@kernel.org>
Message-Id: <20191011070141.188713-2-its@irrelevant.dk>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Reviewed-by: Li Qiang <liq3ea@gmail.com>
Reviewed-by: Edgar E. Iglesias <edgar.iglesias@xilinx.com>
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
---
include/hw/pci/pci.h | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/include/hw/pci/pci.h b/include/hw/pci/pci.h
index 0a59a06b14..f19ffe6b4f 100644
--- a/include/hw/pci/pci.h
+++ b/include/hw/pci/pci.h
@@ -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,
--
2.26.2
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH v2 02/16] docs/devel/loads-stores: Add regexp for DMA functions
2020-10-01 17:21 [PATCH v2 00/16] hw: Let DMA/PCI API take MemTxAttrs argument and propagate MemTxResult Philippe Mathieu-Daudé
2020-10-01 17:21 ` [PATCH v2 01/16] pci: pass along the return value of dma_memory_rw Philippe Mathieu-Daudé
@ 2020-10-01 17:21 ` Philippe Mathieu-Daudé
2020-10-01 17:21 ` [PATCH v2 03/16] dma: Document address_space_map/address_space_unmap() prototypes Philippe Mathieu-Daudé
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-10-01 17:21 UTC (permalink / raw)
To: qemu-devel; +Cc: Paolo Bonzini
From: Philippe Mathieu-Daudé <philmd@redhat.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Reviewed-by: Edgar E. Iglesias <edgar.iglesias@xilinx.com>
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
---
docs/devel/loads-stores.rst | 2 ++
1 file changed, 2 insertions(+)
diff --git a/docs/devel/loads-stores.rst b/docs/devel/loads-stores.rst
index 9a944ef1af..5b20f907e4 100644
--- a/docs/devel/loads-stores.rst
+++ b/docs/devel/loads-stores.rst
@@ -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``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
--
2.26.2
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH v2 03/16] dma: Document address_space_map/address_space_unmap() prototypes
2020-10-01 17:21 [PATCH v2 00/16] hw: Let DMA/PCI API take MemTxAttrs argument and propagate MemTxResult Philippe Mathieu-Daudé
2020-10-01 17:21 ` [PATCH v2 01/16] pci: pass along the return value of dma_memory_rw Philippe Mathieu-Daudé
2020-10-01 17:21 ` [PATCH v2 02/16] docs/devel/loads-stores: Add regexp for DMA functions Philippe Mathieu-Daudé
@ 2020-10-01 17:21 ` Philippe Mathieu-Daudé
2020-10-01 17:21 ` [PATCH v2 04/16] dma: Let dma_memory_set() propagate MemTxResult Philippe Mathieu-Daudé
2020-10-01 17:23 ` [PATCH v2 00/16] hw: Let DMA/PCI API take MemTxAttrs argument and " Philippe Mathieu-Daudé
4 siblings, 0 replies; 6+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-10-01 17:21 UTC (permalink / raw)
To: qemu-devel; +Cc: Paolo Bonzini
From: Philippe Mathieu-Daudé <philmd@redhat.com>
Add documentation based on address_space_map / address_space_unmap.
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Reviewed-by: Edgar E. Iglesias <edgar.iglesias@xilinx.com>
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
---
include/sysemu/dma.h | 29 ++++++++++++++++++++++++++++-
1 file changed, 28 insertions(+), 1 deletion(-)
diff --git a/include/sysemu/dma.h b/include/sysemu/dma.h
index 80c5bc3e02..c6e12b4c24 100644
--- a/include/sysemu/dma.h
+++ b/include/sysemu/dma.h
@@ -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)
--
2.26.2
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH v2 04/16] dma: Let dma_memory_set() propagate MemTxResult
2020-10-01 17:21 [PATCH v2 00/16] hw: Let DMA/PCI API take MemTxAttrs argument and propagate MemTxResult Philippe Mathieu-Daudé
` (2 preceding siblings ...)
2020-10-01 17:21 ` [PATCH v2 03/16] dma: Document address_space_map/address_space_unmap() prototypes Philippe Mathieu-Daudé
@ 2020-10-01 17:21 ` Philippe Mathieu-Daudé
2020-10-01 17:23 ` [PATCH v2 00/16] hw: Let DMA/PCI API take MemTxAttrs argument and " Philippe Mathieu-Daudé
4 siblings, 0 replies; 6+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-10-01 17:21 UTC (permalink / raw)
To: qemu-devel; +Cc: Paolo Bonzini
From: Philippe Mathieu-Daudé <philmd@redhat.com>
address_space_write() returns a MemTxResult type.
Do not discard it, return it to the caller.
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Reviewed-by: Li Qiang <liq3ea@gmail.com>
Reviewed-by: Edgar E. Iglesias <edgar.iglesias@xilinx.com>
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
---
include/sysemu/dma.h | 15 ++++++++++++++-
dma-helpers.c | 7 ++++---
2 files changed, 18 insertions(+), 4 deletions(-)
diff --git a/include/sysemu/dma.h b/include/sysemu/dma.h
index c6e12b4c24..37cd9f1121 100644
--- a/include/sysemu/dma.h
+++ b/include/sysemu/dma.h
@@ -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.
diff --git a/dma-helpers.c b/dma-helpers.c
index 41ef24a63b..4a9e37d6d0 100644
--- a/dma-helpers.c
+++ b/dma-helpers.c
@@ -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 512
uint8_t fillbuf[FILLBUF_SIZE];
int l;
- bool error = false;
+ MemTxResult error = MEMTX_OK;
memset(fillbuf, c, FILLBUF_SIZE);
while (len > 0) {
--
2.26.2
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH v2 00/16] hw: Let DMA/PCI API take MemTxAttrs argument and propagate MemTxResult
2020-10-01 17:21 [PATCH v2 00/16] hw: Let DMA/PCI API take MemTxAttrs argument and propagate MemTxResult Philippe Mathieu-Daudé
` (3 preceding siblings ...)
2020-10-01 17:21 ` [PATCH v2 04/16] dma: Let dma_memory_set() propagate MemTxResult Philippe Mathieu-Daudé
@ 2020-10-01 17:23 ` Philippe Mathieu-Daudé
4 siblings, 0 replies; 6+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-10-01 17:23 UTC (permalink / raw)
To: qemu-devel@nongnu.org Developers; +Cc: Paolo Bonzini
On Thu, Oct 1, 2020 at 7:22 PM Philippe Mathieu-Daudé <f4bug@amsat.org> wrote:
>
> 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
Err, wrong git-profile.
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2020-10-01 17:30 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-01 17:21 [PATCH v2 00/16] hw: Let DMA/PCI API take MemTxAttrs argument and propagate MemTxResult Philippe Mathieu-Daudé
2020-10-01 17:21 ` [PATCH v2 01/16] pci: pass along the return value of dma_memory_rw Philippe Mathieu-Daudé
2020-10-01 17:21 ` [PATCH v2 02/16] docs/devel/loads-stores: Add regexp for DMA functions Philippe Mathieu-Daudé
2020-10-01 17:21 ` [PATCH v2 03/16] dma: Document address_space_map/address_space_unmap() prototypes Philippe Mathieu-Daudé
2020-10-01 17:21 ` [PATCH v2 04/16] dma: Let dma_memory_set() propagate MemTxResult Philippe Mathieu-Daudé
2020-10-01 17:23 ` [PATCH v2 00/16] hw: Let DMA/PCI API take MemTxAttrs argument and " Philippe Mathieu-Daudé
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.