* [PATCH RESEND v3 01/10] pci: pass along the return value of dma_memory_rw
2020-10-23 15:19 [PATCH RESEND v3 00/10] hw: Let DMA/PCI API propagate MemTxResult Philippe Mathieu-Daudé
@ 2020-10-23 15:19 ` Philippe Mathieu-Daudé
2020-10-23 15:19 ` [PATCH RESEND v3 02/10] docs/devel/loads-stores: Add regexp for DMA functions Philippe Mathieu-Daudé
` (9 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-10-23 15:19 UTC (permalink / raw)
To: qemu-devel
Cc: Edgar E . Iglesias, Li Qiang, Michael S . Tsirkin, Klaus Jensen,
Richard Henderson, Keith Busch, Paolo Bonzini,
Philippe Mathieu-Daudé
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 0a59a06b149..f19ffe6b4fe 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] 12+ messages in thread
* [PATCH RESEND v3 02/10] docs/devel/loads-stores: Add regexp for DMA functions
2020-10-23 15:19 [PATCH RESEND v3 00/10] hw: Let DMA/PCI API propagate MemTxResult Philippe Mathieu-Daudé
2020-10-23 15:19 ` [PATCH RESEND v3 01/10] pci: pass along the return value of dma_memory_rw Philippe Mathieu-Daudé
@ 2020-10-23 15:19 ` Philippe Mathieu-Daudé
2020-10-23 15:19 ` [PATCH RESEND v3 03/10] dma: Document address_space_map/address_space_unmap() prototypes Philippe Mathieu-Daudé
` (8 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-10-23 15:19 UTC (permalink / raw)
To: qemu-devel
Cc: Edgar E . Iglesias, Paolo Bonzini, Richard Henderson,
Philippe Mathieu-Daudé
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 59c1225391c..ee43f5dfee2 100644
--- a/docs/devel/loads-stores.rst
+++ b/docs/devel/loads-stores.rst
@@ -483,6 +483,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] 12+ messages in thread
* [PATCH RESEND v3 03/10] dma: Document address_space_map/address_space_unmap() prototypes
2020-10-23 15:19 [PATCH RESEND v3 00/10] hw: Let DMA/PCI API propagate MemTxResult Philippe Mathieu-Daudé
2020-10-23 15:19 ` [PATCH RESEND v3 01/10] pci: pass along the return value of dma_memory_rw Philippe Mathieu-Daudé
2020-10-23 15:19 ` [PATCH RESEND v3 02/10] docs/devel/loads-stores: Add regexp for DMA functions Philippe Mathieu-Daudé
@ 2020-10-23 15:19 ` Philippe Mathieu-Daudé
2020-10-23 15:19 ` [PATCH RESEND v3 04/10] dma: Let dma_memory_set() propagate MemTxResult Philippe Mathieu-Daudé
` (7 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-10-23 15:19 UTC (permalink / raw)
To: qemu-devel
Cc: Edgar E . Iglesias, Paolo Bonzini, Richard Henderson,
Philippe Mathieu-Daudé
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 80c5bc3e02d..c6e12b4c243 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] 12+ messages in thread
* [PATCH RESEND v3 04/10] dma: Let dma_memory_set() propagate MemTxResult
2020-10-23 15:19 [PATCH RESEND v3 00/10] hw: Let DMA/PCI API propagate MemTxResult Philippe Mathieu-Daudé
` (2 preceding siblings ...)
2020-10-23 15:19 ` [PATCH RESEND v3 03/10] dma: Document address_space_map/address_space_unmap() prototypes Philippe Mathieu-Daudé
@ 2020-10-23 15:19 ` Philippe Mathieu-Daudé
2020-10-23 15:19 ` [PATCH RESEND v3 05/10] dma: Let dma_memory_rw() " Philippe Mathieu-Daudé
` (6 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-10-23 15:19 UTC (permalink / raw)
To: qemu-devel
Cc: Edgar E . Iglesias, Paolo Bonzini, Li Qiang, Richard Henderson,
Philippe Mathieu-Daudé
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 ++++++++++++++-
softmmu/dma-helpers.c | 7 ++++---
2 files changed, 18 insertions(+), 4 deletions(-)
diff --git a/include/sysemu/dma.h b/include/sysemu/dma.h
index c6e12b4c243..37cd9f11217 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/softmmu/dma-helpers.c b/softmmu/dma-helpers.c
index 03c92e0cc60..29001b54595 100644
--- a/softmmu/dma-helpers.c
+++ b/softmmu/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] 12+ messages in thread
* [PATCH RESEND v3 05/10] dma: Let dma_memory_rw() propagate MemTxResult
2020-10-23 15:19 [PATCH RESEND v3 00/10] hw: Let DMA/PCI API propagate MemTxResult Philippe Mathieu-Daudé
` (3 preceding siblings ...)
2020-10-23 15:19 ` [PATCH RESEND v3 04/10] dma: Let dma_memory_set() propagate MemTxResult Philippe Mathieu-Daudé
@ 2020-10-23 15:19 ` Philippe Mathieu-Daudé
2020-10-23 15:19 ` [PATCH RESEND v3 06/10] dma: Let dma_memory_read() " Philippe Mathieu-Daudé
` (5 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-10-23 15:19 UTC (permalink / raw)
To: qemu-devel
Cc: Edgar E . Iglesias, Paolo Bonzini, Li Qiang, Richard Henderson,
Philippe Mathieu-Daudé
address_space_rw() 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 | 30 ++++++++++++++++++++++--------
1 file changed, 22 insertions(+), 8 deletions(-)
diff --git a/include/sysemu/dma.h b/include/sysemu/dma.h
index 37cd9f11217..04687d8825e 100644
--- a/include/sysemu/dma.h
+++ b/include/sysemu/dma.h
@@ -80,12 +80,13 @@ static inline bool dma_memory_valid(AddressSpace *as,
MEMTXATTRS_UNSPECIFIED);
}
-static inline int dma_memory_rw_relaxed(AddressSpace *as, dma_addr_t addr,
- void *buf, dma_addr_t len,
- DMADirection dir)
+static inline MemTxResult dma_memory_rw_relaxed(AddressSpace *as,
+ dma_addr_t addr,
+ void *buf, dma_addr_t len,
+ DMADirection dir)
{
- return (bool)address_space_rw(as, addr, MEMTXATTRS_UNSPECIFIED,
- buf, len, dir == DMA_DIRECTION_FROM_DEVICE);
+ return address_space_rw(as, addr, MEMTXATTRS_UNSPECIFIED,
+ buf, len, dir == DMA_DIRECTION_FROM_DEVICE);
}
static inline int dma_memory_read_relaxed(AddressSpace *as, dma_addr_t addr,
@@ -101,9 +102,22 @@ static inline int dma_memory_write_relaxed(AddressSpace *as, dma_addr_t addr,
DMA_DIRECTION_FROM_DEVICE);
}
-static inline int dma_memory_rw(AddressSpace *as, dma_addr_t addr,
- void *buf, dma_addr_t len,
- DMADirection dir)
+/**
+ * dma_memory_rw: Read from or write to an address space 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
+ * @buf: buffer with the data transferred
+ * @len: the number of bytes to read or write
+ * @dir: indicates the transfer direction
+ */
+static inline MemTxResult dma_memory_rw(AddressSpace *as, dma_addr_t addr,
+ void *buf, dma_addr_t len,
+ DMADirection dir)
{
dma_barrier(as, dir);
--
2.26.2
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH RESEND v3 06/10] dma: Let dma_memory_read() propagate MemTxResult
2020-10-23 15:19 [PATCH RESEND v3 00/10] hw: Let DMA/PCI API propagate MemTxResult Philippe Mathieu-Daudé
` (4 preceding siblings ...)
2020-10-23 15:19 ` [PATCH RESEND v3 05/10] dma: Let dma_memory_rw() " Philippe Mathieu-Daudé
@ 2020-10-23 15:19 ` Philippe Mathieu-Daudé
2020-10-23 15:19 ` [PATCH RESEND v3 07/10] dma: Let dma_memory_write() " Philippe Mathieu-Daudé
` (4 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-10-23 15:19 UTC (permalink / raw)
To: qemu-devel
Cc: Edgar E . Iglesias, Paolo Bonzini, Li Qiang, Richard Henderson,
Philippe Mathieu-Daudé
dma_memory_rw_relaxed() 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 | 21 +++++++++++++++++----
1 file changed, 17 insertions(+), 4 deletions(-)
diff --git a/include/sysemu/dma.h b/include/sysemu/dma.h
index 04687d8825e..df170047eb3 100644
--- a/include/sysemu/dma.h
+++ b/include/sysemu/dma.h
@@ -89,8 +89,9 @@ static inline MemTxResult dma_memory_rw_relaxed(AddressSpace *as,
buf, len, dir == DMA_DIRECTION_FROM_DEVICE);
}
-static inline int dma_memory_read_relaxed(AddressSpace *as, dma_addr_t addr,
- void *buf, dma_addr_t len)
+static inline MemTxResult dma_memory_read_relaxed(AddressSpace *as,
+ dma_addr_t addr,
+ void *buf, dma_addr_t len)
{
return dma_memory_rw_relaxed(as, addr, buf, len, DMA_DIRECTION_TO_DEVICE);
}
@@ -124,8 +125,20 @@ static inline MemTxResult dma_memory_rw(AddressSpace *as, dma_addr_t addr,
return dma_memory_rw_relaxed(as, addr, buf, len, dir);
}
-static inline int dma_memory_read(AddressSpace *as, dma_addr_t addr,
- void *buf, dma_addr_t len)
+/**
+ * dma_memory_read: Read from an address space from DMA controller.
+ *
+ * Return a MemTxResult indicating whether the operation succeeded
+ * or failed (eg unassigned memory, device rejected the transaction,
+ * IOMMU fault). Called within RCU critical section.
+ *
+ * @as: #AddressSpace to be accessed
+ * @addr: address within that address space
+ * @buf: buffer with the data transferred
+ * @len: length of the data transferred
+ */
+static inline MemTxResult dma_memory_read(AddressSpace *as, dma_addr_t addr,
+ void *buf, dma_addr_t len)
{
return dma_memory_rw(as, addr, buf, len, DMA_DIRECTION_TO_DEVICE);
}
--
2.26.2
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH RESEND v3 07/10] dma: Let dma_memory_write() propagate MemTxResult
2020-10-23 15:19 [PATCH RESEND v3 00/10] hw: Let DMA/PCI API propagate MemTxResult Philippe Mathieu-Daudé
` (5 preceding siblings ...)
2020-10-23 15:19 ` [PATCH RESEND v3 06/10] dma: Let dma_memory_read() " Philippe Mathieu-Daudé
@ 2020-10-23 15:19 ` Philippe Mathieu-Daudé
2020-10-23 15:19 ` [PATCH RESEND v3 08/10] pci: Let pci_dma_rw() " Philippe Mathieu-Daudé
` (3 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-10-23 15:19 UTC (permalink / raw)
To: qemu-devel
Cc: Edgar E . Iglesias, Paolo Bonzini, Li Qiang, Richard Henderson,
Philippe Mathieu-Daudé
dma_memory_rw_relaxed() 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 | 22 ++++++++++++++++++----
1 file changed, 18 insertions(+), 4 deletions(-)
diff --git a/include/sysemu/dma.h b/include/sysemu/dma.h
index df170047eb3..a052f7bca3f 100644
--- a/include/sysemu/dma.h
+++ b/include/sysemu/dma.h
@@ -96,8 +96,10 @@ static inline MemTxResult dma_memory_read_relaxed(AddressSpace *as,
return dma_memory_rw_relaxed(as, addr, buf, len, DMA_DIRECTION_TO_DEVICE);
}
-static inline int dma_memory_write_relaxed(AddressSpace *as, dma_addr_t addr,
- const void *buf, dma_addr_t len)
+static inline MemTxResult dma_memory_write_relaxed(AddressSpace *as,
+ dma_addr_t addr,
+ const void *buf,
+ dma_addr_t len)
{
return dma_memory_rw_relaxed(as, addr, (void *)buf, len,
DMA_DIRECTION_FROM_DEVICE);
@@ -143,8 +145,20 @@ static inline MemTxResult dma_memory_read(AddressSpace *as, dma_addr_t addr,
return dma_memory_rw(as, addr, buf, len, DMA_DIRECTION_TO_DEVICE);
}
-static inline int dma_memory_write(AddressSpace *as, dma_addr_t addr,
- const void *buf, dma_addr_t len)
+/**
+ * address_space_write: Write to address space 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
+ * @buf: buffer with the data transferred
+ * @len: the number of bytes to write
+ */
+static inline MemTxResult dma_memory_write(AddressSpace *as, dma_addr_t addr,
+ const void *buf, dma_addr_t len)
{
return dma_memory_rw(as, addr, (void *)buf, len,
DMA_DIRECTION_FROM_DEVICE);
--
2.26.2
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH RESEND v3 08/10] pci: Let pci_dma_rw() propagate MemTxResult
2020-10-23 15:19 [PATCH RESEND v3 00/10] hw: Let DMA/PCI API propagate MemTxResult Philippe Mathieu-Daudé
` (6 preceding siblings ...)
2020-10-23 15:19 ` [PATCH RESEND v3 07/10] dma: Let dma_memory_write() " Philippe Mathieu-Daudé
@ 2020-10-23 15:19 ` Philippe Mathieu-Daudé
2020-10-23 15:19 ` [PATCH RESEND v3 09/10] pci: Let pci_dma_read() " Philippe Mathieu-Daudé
` (2 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-10-23 15:19 UTC (permalink / raw)
To: qemu-devel
Cc: Paolo Bonzini, Richard Henderson, Li Qiang,
Philippe Mathieu-Daudé
dma_memory_rw() returns a MemTxResult type.
Do not discard it, return it to the caller.
Reviewed-by: Li Qiang <liq3ea@gmail.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
---
include/hw/pci/pci.h | 18 ++++++++++++++++--
1 file changed, 16 insertions(+), 2 deletions(-)
diff --git a/include/hw/pci/pci.h b/include/hw/pci/pci.h
index f19ffe6b4fe..b8780ea18c1 100644
--- a/include/hw/pci/pci.h
+++ b/include/hw/pci/pci.h
@@ -780,8 +780,22 @@ static inline AddressSpace *pci_get_address_space(PCIDevice *dev)
return &dev->bus_master_as;
}
-static inline int pci_dma_rw(PCIDevice *dev, dma_addr_t addr,
- void *buf, dma_addr_t len, DMADirection dir)
+/**
+ * pci_dma_rw: Read from or write to an address space from PCI device.
+ *
+ * Return a MemTxResult indicating whether the operation succeeded
+ * or failed (eg unassigned memory, device rejected the transaction,
+ * IOMMU fault).
+ *
+ * @dev: #PCIDevice doing the memory access
+ * @addr: address within the #PCIDevice address space
+ * @buf: buffer with the data transferred
+ * @len: the number of bytes to read or write
+ * @dir: indicates the transfer direction
+ */
+static inline MemTxResult pci_dma_rw(PCIDevice *dev, dma_addr_t addr,
+ void *buf, dma_addr_t len,
+ DMADirection dir)
{
return dma_memory_rw(pci_get_address_space(dev), addr, buf, len, dir);
}
--
2.26.2
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH RESEND v3 09/10] pci: Let pci_dma_read() propagate MemTxResult
2020-10-23 15:19 [PATCH RESEND v3 00/10] hw: Let DMA/PCI API propagate MemTxResult Philippe Mathieu-Daudé
` (7 preceding siblings ...)
2020-10-23 15:19 ` [PATCH RESEND v3 08/10] pci: Let pci_dma_rw() " Philippe Mathieu-Daudé
@ 2020-10-23 15:19 ` Philippe Mathieu-Daudé
2020-10-23 15:19 ` [PATCH RESEND v3 10/10] pci: Let pci_dma_write() " Philippe Mathieu-Daudé
2020-10-23 15:20 ` [PATCH RESEND v3 00/10] hw: Let DMA/PCI API " Philippe Mathieu-Daudé
10 siblings, 0 replies; 12+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-10-23 15:19 UTC (permalink / raw)
To: qemu-devel
Cc: Paolo Bonzini, Richard Henderson, Li Qiang,
Philippe Mathieu-Daudé
pci_dma_rw() returns a MemTxResult type.
Do not discard it, return it to the caller.
Reviewed-by: Li Qiang <liq3ea@gmail.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
---
include/hw/pci/pci.h | 16 ++++++++++++++--
1 file changed, 14 insertions(+), 2 deletions(-)
diff --git a/include/hw/pci/pci.h b/include/hw/pci/pci.h
index b8780ea18c1..85b5786a5da 100644
--- a/include/hw/pci/pci.h
+++ b/include/hw/pci/pci.h
@@ -800,8 +800,20 @@ static inline MemTxResult pci_dma_rw(PCIDevice *dev, dma_addr_t addr,
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,
- void *buf, dma_addr_t len)
+/**
+ * pci_dma_read: Read from an address space from PCI device.
+ *
+ * Return a MemTxResult indicating whether the operation succeeded
+ * or failed (eg unassigned memory, device rejected the transaction,
+ * IOMMU fault). Called within RCU critical section.
+ *
+ * @dev: #PCIDevice doing the memory access
+ * @addr: address within the #PCIDevice address space
+ * @buf: buffer with the data transferred
+ * @len: length of the data transferred
+ */
+static inline MemTxResult pci_dma_read(PCIDevice *dev, dma_addr_t addr,
+ void *buf, dma_addr_t len)
{
return pci_dma_rw(dev, addr, buf, len, DMA_DIRECTION_TO_DEVICE);
}
--
2.26.2
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH RESEND v3 10/10] pci: Let pci_dma_write() propagate MemTxResult
2020-10-23 15:19 [PATCH RESEND v3 00/10] hw: Let DMA/PCI API propagate MemTxResult Philippe Mathieu-Daudé
` (8 preceding siblings ...)
2020-10-23 15:19 ` [PATCH RESEND v3 09/10] pci: Let pci_dma_read() " Philippe Mathieu-Daudé
@ 2020-10-23 15:19 ` Philippe Mathieu-Daudé
2020-10-23 15:20 ` [PATCH RESEND v3 00/10] hw: Let DMA/PCI API " Philippe Mathieu-Daudé
10 siblings, 0 replies; 12+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-10-23 15:19 UTC (permalink / raw)
To: qemu-devel
Cc: Paolo Bonzini, Richard Henderson, Li Qiang,
Philippe Mathieu-Daudé
pci_dma_rw() returns a MemTxResult type.
Do not discard it, return it to the caller.
Reviewed-by: Li Qiang <liq3ea@gmail.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
---
include/hw/pci/pci.h | 16 ++++++++++++++--
1 file changed, 14 insertions(+), 2 deletions(-)
diff --git a/include/hw/pci/pci.h b/include/hw/pci/pci.h
index 85b5786a5da..dd486cd941a 100644
--- a/include/hw/pci/pci.h
+++ b/include/hw/pci/pci.h
@@ -818,8 +818,20 @@ static inline MemTxResult pci_dma_read(PCIDevice *dev, dma_addr_t addr,
return pci_dma_rw(dev, addr, buf, len, DMA_DIRECTION_TO_DEVICE);
}
-static inline int pci_dma_write(PCIDevice *dev, dma_addr_t addr,
- const void *buf, dma_addr_t len)
+/**
+ * pci_dma_write: Write to address space from PCI device.
+ *
+ * Return a MemTxResult indicating whether the operation succeeded
+ * or failed (eg unassigned memory, device rejected the transaction,
+ * IOMMU fault).
+ *
+ * @dev: #PCIDevice doing the memory access
+ * @addr: address within the #PCIDevice address space
+ * @buf: buffer with the data transferred
+ * @len: the number of bytes to write
+ */
+static inline MemTxResult pci_dma_write(PCIDevice *dev, dma_addr_t addr,
+ const void *buf, dma_addr_t len)
{
return pci_dma_rw(dev, addr, (void *) buf, len, DMA_DIRECTION_FROM_DEVICE);
}
--
2.26.2
^ permalink raw reply related [flat|nested] 12+ messages in thread
* Re: [PATCH RESEND v3 00/10] hw: Let DMA/PCI API propagate MemTxResult
2020-10-23 15:19 [PATCH RESEND v3 00/10] hw: Let DMA/PCI API propagate MemTxResult Philippe Mathieu-Daudé
` (9 preceding siblings ...)
2020-10-23 15:19 ` [PATCH RESEND v3 10/10] pci: Let pci_dma_write() " Philippe Mathieu-Daudé
@ 2020-10-23 15:20 ` Philippe Mathieu-Daudé
10 siblings, 0 replies; 12+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-10-23 15:20 UTC (permalink / raw)
To: qemu-devel; +Cc: Paolo Bonzini
On 10/23/20 5:19 PM, Philippe Mathieu-Daudé wrote:
> Currently the MemTxResult return value is not propagated,
> so lost. The motivation behind this series is to make the
> API more robust to enforce correct use by the consumers.
>
> All series reviewed.
>
> Since v2:
> - Rebased
> - Removed patches adding MemTxAttrs argument to DMA/PCI API
> (we will discuss them later).
Sorry this is not a RESEND, this is first post of v3,
I forgot to use '--clear-subject-prefix' and git-publish
reused the same prefix from v2.
^ permalink raw reply [flat|nested] 12+ messages in thread