Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

dma-mapping: introduce new DMA attribute to indicate MMIO memory

This patch introduces the DMA_ATTR_MMIO attribute to mark DMA buffers
that reside in memory-mapped I/O (MMIO) regions, such as device BARs
exposed through the host bridge, which are accessible for peer-to-peer
(P2P) DMA.

This attribute is especially useful for exporting device memory to other
devices for DMA without CPU involvement, and avoids unnecessary or
potentially detrimental CPU cache maintenance calls.

DMA_ATTR_MMIO is supposed to provide dma_map_resource() functionality
without need to call to special function and perform branching when
processing generic containers like bio_vec by the callers.

Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
Signed-off-by: Leon Romanovsky <leonro@nvidia.com>
Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com>
Link: https://lore.kernel.org/r/6f058ec395c5348014860dbc2eed348c17975843.1757423202.git.leonro@nvidia.com

authored by

Leon Romanovsky and committed by
Marek Szyprowski
eadaa8b2 b9a62320

+43 -1
+18
Documentation/core-api/dma-attributes.rst
··· 130 130 subsystem that the buffer is fully accessible at the elevated privilege 131 131 level (and ideally inaccessible or at least read-only at the 132 132 lesser-privileged levels). 133 + 134 + DMA_ATTR_MMIO 135 + ------------- 136 + 137 + This attribute indicates the physical address is not normal system 138 + memory. It may not be used with kmap*()/phys_to_virt()/phys_to_page() 139 + functions, it may not be cacheable, and access using CPU load/store 140 + instructions may not be allowed. 141 + 142 + Usually this will be used to describe MMIO addresses, or other non-cacheable 143 + register addresses. When DMA mapping this sort of address we call 144 + the operation Peer to Peer as a one device is DMA'ing to another device. 145 + For PCI devices the p2pdma APIs must be used to determine if 146 + DMA_ATTR_MMIO is appropriate. 147 + 148 + For architectures that require cache flushing for DMA coherence 149 + DMA_ATTR_MMIO will not perform any cache flushing. The address 150 + provided must never be mapped cacheable into the CPU.
+20
include/linux/dma-mapping.h
··· 59 59 #define DMA_ATTR_PRIVILEGED (1UL << 9) 60 60 61 61 /* 62 + * DMA_ATTR_MMIO - Indicates memory-mapped I/O (MMIO) region for DMA mapping 63 + * 64 + * This attribute indicates the physical address is not normal system 65 + * memory. It may not be used with kmap*()/phys_to_virt()/phys_to_page() 66 + * functions, it may not be cacheable, and access using CPU load/store 67 + * instructions may not be allowed. 68 + * 69 + * Usually this will be used to describe MMIO addresses, or other non-cacheable 70 + * register addresses. When DMA mapping this sort of address we call 71 + * the operation Peer to Peer as a one device is DMA'ing to another device. 72 + * For PCI devices the p2pdma APIs must be used to determine if DMA_ATTR_MMIO 73 + * is appropriate. 74 + * 75 + * For architectures that require cache flushing for DMA coherence 76 + * DMA_ATTR_MMIO will not perform any cache flushing. The address 77 + * provided must never be mapped cacheable into the CPU. 78 + */ 79 + #define DMA_ATTR_MMIO (1UL << 10) 80 + 81 + /* 62 82 * A dma_addr_t can hold any valid DMA or bus address for the platform. It can 63 83 * be given to a device to use as a DMA source or target. It is specific to a 64 84 * given device and there may be a translation between the CPU physical address
+2 -1
include/trace/events/dma.h
··· 31 31 { DMA_ATTR_FORCE_CONTIGUOUS, "FORCE_CONTIGUOUS" }, \ 32 32 { DMA_ATTR_ALLOC_SINGLE_PAGES, "ALLOC_SINGLE_PAGES" }, \ 33 33 { DMA_ATTR_NO_WARN, "NO_WARN" }, \ 34 - { DMA_ATTR_PRIVILEGED, "PRIVILEGED" }) 34 + { DMA_ATTR_PRIVILEGED, "PRIVILEGED" }, \ 35 + { DMA_ATTR_MMIO, "MMIO" }) 35 36 36 37 DECLARE_EVENT_CLASS(dma_map, 37 38 TP_PROTO(struct device *dev, phys_addr_t phys_addr, dma_addr_t dma_addr,
+3
rust/kernel/dma.rs
··· 242 242 /// Indicates that the buffer is fully accessible at an elevated privilege level (and 243 243 /// ideally inaccessible or at least read-only at lesser-privileged levels). 244 244 pub const DMA_ATTR_PRIVILEGED: Attrs = Attrs(bindings::DMA_ATTR_PRIVILEGED); 245 + 246 + /// Indicates that the buffer is MMIO memory. 247 + pub const DMA_ATTR_MMIO: Attrs = Attrs(bindings::DMA_ATTR_MMIO); 245 248 } 246 249 247 250 /// An abstraction of the `dma_alloc_coherent` API.