Skip to content

Commit eadaa8b

Browse files
rleonmszyprow
authored andcommitted
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 <[email protected]> Signed-off-by: Leon Romanovsky <[email protected]> Signed-off-by: Marek Szyprowski <[email protected]> Link: https://lore.kernel.org/r/6f058ec395c5348014860dbc2eed348c17975843.1757423202.git.leonro@nvidia.com
1 parent b9a6232 commit eadaa8b

4 files changed

Lines changed: 43 additions & 1 deletion

File tree

Documentation/core-api/dma-attributes.rst

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,3 +130,21 @@ accesses to DMA buffers in both privileged "supervisor" and unprivileged
130130
subsystem that the buffer is fully accessible at the elevated privilege
131131
level (and ideally inaccessible or at least read-only at the
132132
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.

include/linux/dma-mapping.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,26 @@
5858
*/
5959
#define DMA_ATTR_PRIVILEGED (1UL << 9)
6060

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+
6181
/*
6282
* A dma_addr_t can hold any valid DMA or bus address for the platform. It can
6383
* be given to a device to use as a DMA source or target. It is specific to a

include/trace/events/dma.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ TRACE_DEFINE_ENUM(DMA_NONE);
3131
{ DMA_ATTR_FORCE_CONTIGUOUS, "FORCE_CONTIGUOUS" }, \
3232
{ DMA_ATTR_ALLOC_SINGLE_PAGES, "ALLOC_SINGLE_PAGES" }, \
3333
{ DMA_ATTR_NO_WARN, "NO_WARN" }, \
34-
{ DMA_ATTR_PRIVILEGED, "PRIVILEGED" })
34+
{ DMA_ATTR_PRIVILEGED, "PRIVILEGED" }, \
35+
{ DMA_ATTR_MMIO, "MMIO" })
3536

3637
DECLARE_EVENT_CLASS(dma_map,
3738
TP_PROTO(struct device *dev, phys_addr_t phys_addr, dma_addr_t dma_addr,

rust/kernel/dma.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,9 @@ pub mod attrs {
242242
/// Indicates that the buffer is fully accessible at an elevated privilege level (and
243243
/// ideally inaccessible or at least read-only at lesser-privileged levels).
244244
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);
245248
}
246249

247250
/// An abstraction of the `dma_alloc_coherent` API.

0 commit comments

Comments
 (0)