Skip to contentSkip to conversation

pci: Let PCI DMA API functions propagate a MemTxResult

PATCH In review Philippe Mathieu-Daudé 3 participants 11 messages Sep 4, 2020 – Sep 15, 2020

lore
Share & tools
lore
#0 lore raw

cover pci: Let PCI DMA API functions propagate a MemTxResult

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'.

Based-on: <[email protected]>
https://lists.gnu.org/archive/html/qemu-devel/2020-09/msg02048.html

Philippe Mathieu-Daudé (3):
pci: Let pci_dma_rw() propagate MemTxResult
pci: Let pci_dma_read() propagate MemTxResult
pci: Let pci_dma_write() propagate MemTxResult

 include/hw/pci/pci.h | 50 ++++++++++++++++++++++++++++++++++++++------
 1 file changed, 44 insertions(+), 6 deletions(-)
Signature · 1 line
2.26.2
#1 lore raw

PATCH 1/3 pci: Let pci_dma_rw() propagate MemTxResult

dma_memory_rw() returns a MemTxResult type.
Do not discard it, return it to the caller.

---
 include/hw/pci/pci.h | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)
include/hw/pci/pci.h +16 -2
index a221dfb3b08..a85b0bc3c44 100644
@@ -785,8 +785,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, MEMTXATTRS_UNSPECIFIED);
Signature · 1 line
2.26.2
Reviewed-by on v1 1/3
#2 lore raw

Re: [PATCH 1/3] pci: Let pci_dma_rw() propagate MemTxResult

Quoted 28 lines · Philippe Mathieu-Daudé <[email protected]> 于2020年9月5日周六 上午12:26写道:

dma_memory_rw() returns a MemTxResult type.
Do not discard it, return it to the caller.

---
 include/hw/pci/pci.h | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)
include/hw/pci/pci.h +9 -2
index a221dfb3b08..a85b0bc3c44 100644
@@ -785,8 +785,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

include/hw/pci/pci.h static inline AddressSpace *pci_get_address_space(PCIDevice *dev) · line 806

Quoted 10 lines
include/hw/pci/pci.h +7 -0
+ * @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, MEMTXATTRS_UNSPECIFIED);
Quoted 4 lines

--
2.26.2

Reviewed-by on v1 1/3
#3 lore raw

Re: [PATCH 1/3] pci: Let pci_dma_rw() propagate MemTxResult

In reply to Philippe Mathieu-Daudé
Quoted 7 lines · Philippe Mathieu-Daudé

dma_memory_rw() returns a MemTxResult type.
Do not discard it, return it to the caller.

---
 include/hw/pci/pci.h | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)

r~

#4 lore raw

PATCH 2/3 pci: Let pci_dma_read() propagate MemTxResult

In reply to Philippe Mathieu-Daudé

pci_dma_rw() returns a MemTxResult type.
Do not discard it, return it to the caller.

---
 include/hw/pci/pci.h | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)
include/hw/pci/pci.h +14 -2
index a85b0bc3c44..bb57525dffd 100644
@@ -806,8 +806,20 @@ static inline MemTxResult pci_dma_rw(PCIDevice *dev, dma_addr_t addr,
                          dir, MEMTXATTRS_UNSPECIFIED);
 }
 
-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);
 }
Signature · 1 line
2.26.2
Reviewed-by on v1 2/3
#5 lore raw

Re: [PATCH 2/3] pci: Let pci_dma_read() propagate MemTxResult

Quoted 5 lines · Philippe Mathieu-Daudé <[email protected]> 于2020年9月5日周六 上午12:27写道:

pci_dma_rw() returns a MemTxResult type.
Do not discard it, return it to the caller.

Quoted 35 lines
---
 include/hw/pci/pci.h | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)
include/hw/pci/pci.h +14 -3
index a85b0bc3c44..bb57525dffd 100644
@@ -806,8 +806,20 @@ static inline MemTxResult pci_dma_rw(PCIDevice *dev, dma_addr_t addr,
                          dir, MEMTXATTRS_UNSPECIFIED);
 }
 
-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

Reviewed-by on v1 2/3
#6 lore raw

Re: [PATCH 2/3] pci: Let pci_dma_read() propagate MemTxResult

In reply to Philippe Mathieu-Daudé
Quoted 7 lines · Philippe Mathieu-Daudé

pci_dma_rw() returns a MemTxResult type.
Do not discard it, return it to the caller.

---
 include/hw/pci/pci.h | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

r~

#7 lore raw

PATCH 3/3 pci: Let pci_dma_write() propagate MemTxResult

In reply to Philippe Mathieu-Daudé

pci_dma_rw() returns a MemTxResult type.
Do not discard it, return it to the caller.

---
 include/hw/pci/pci.h | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)
include/hw/pci/pci.h +14 -2
index bb57525dffd..76826e240a9 100644
@@ -824,8 +824,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);
 }
Signature · 1 line
2.26.2
Reviewed-by on v1 3/3
#8 lore raw

Re: [PATCH 3/3] pci: Let pci_dma_write() propagate MemTxResult

Quoted 5 lines · Philippe Mathieu-Daudé <[email protected]> 于2020年9月5日周六 上午12:26写道:

pci_dma_rw() returns a MemTxResult type.
Do not discard it, return it to the caller.

Quoted 35 lines
---
 include/hw/pci/pci.h | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)
include/hw/pci/pci.h +14 -3
index bb57525dffd..76826e240a9 100644
@@ -824,8 +824,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

Reviewed-by on v1 3/3
#9 lore raw

Re: [PATCH 3/3] pci: Let pci_dma_write() propagate MemTxResult

In reply to Philippe Mathieu-Daudé
Quoted 7 lines · Philippe Mathieu-Daudé

pci_dma_rw() returns a MemTxResult type.
Do not discard it, return it to the caller.

---
 include/hw/pci/pci.h | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

r~

#10 lore raw
In reply to Philippe Mathieu-Daudé
Quoted 11 lines · Philippe Mathieu-Daudé

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'.

Based-on: <[email protected]>
https://lists.gnu.org/archive/html/qemu-devel/2020-09/msg02048.html

Quoted 8 lines

Philippe Mathieu-Daudé (3):
pci: Let pci_dma_rw() propagate MemTxResult
pci: Let pci_dma_read() propagate MemTxResult
pci: Let pci_dma_write() propagate MemTxResult

 include/hw/pci/pci.h | 50 ++++++++++++++++++++++++++++++++++++++------
 1 file changed, 44 insertions(+), 6 deletions(-)

This series is fully review.

Paolo, if you take the DMA series on which this one is based, could you take this too?

Thanks :)