Skip to content

Commit 0ebbc69

Browse files
ptesarikJonathan Corbet
authored andcommitted
docs: dma-api: update streaming DMA physical address constraints
Add an introductory paragraph to Part Id - Streaming DMA mappings and move the explanation of address constraints there, because it applies to all map functions. Clarify that streaming DMA can be used with memory which does not meet the addressing constraints of a device, but it may fail in that case. Make a note about SWIOTLB and link to the detailed description of it. Do not mention platform-dependent allocation flags. The note may mislead device driver authors into thinking that they should poke into and try to second-guess the DMA API implementation. They definitely shouldn't. Remove the claim that platforms with an IOMMU may not require physically contiguous buffers. The current implementation explicitly rejects vmalloc addresses, regardless of IOMMU. Signed-off-by: Petr Tesarik <[email protected]> Reviewed-by: Bagas Sanjaya <[email protected]> Tested-by: Randy Dunlap <[email protected]> Acked-by: Marek Szyprowski <[email protected]> Signed-off-by: Jonathan Corbet <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent faa7c7e commit 0ebbc69

File tree

1 file changed

+21
-15
lines changed

1 file changed

+21
-15
lines changed

Documentation/core-api/dma-api.rst

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,26 @@ segments, the function returns 0.
184184
Part Id - Streaming DMA mappings
185185
--------------------------------
186186

187+
Streaming DMA allows to map an existing buffer for DMA transfers and then
188+
unmap it when finished. Map functions are not guaranteed to succeed, so the
189+
return value must be checked.
190+
191+
.. note::
192+
193+
In particular, mapping may fail for memory not addressable by the
194+
device, e.g. if it is not within the DMA mask of the device and/or a
195+
connecting bus bridge. Streaming DMA functions try to overcome such
196+
addressing constraints, either by using an IOMMU (a device which maps
197+
I/O DMA addresses to physical memory addresses), or by copying the
198+
data to/from a bounce buffer if the kernel is configured with a
199+
:doc:`SWIOTLB <swiotlb>`. However, these methods are not always
200+
available, and even if they are, they may still fail for a number of
201+
reasons.
202+
203+
In short, a device driver may need to be wary of where buffers are
204+
located in physical memory, especially if the DMA mask is less than 32
205+
bits.
206+
187207
::
188208

189209
dma_addr_t
@@ -204,27 +224,13 @@ DMA_BIDIRECTIONAL direction isn't known
204224

205225
.. note::
206226

207-
Not all memory regions in a machine can be mapped by this API.
208-
Further, contiguous kernel virtual space may not be contiguous as
227+
Contiguous kernel virtual space may not be contiguous as
209228
physical memory. Since this API does not provide any scatter/gather
210229
capability, it will fail if the user tries to map a non-physically
211230
contiguous piece of memory. For this reason, memory to be mapped by
212231
this API should be obtained from sources which guarantee it to be
213232
physically contiguous (like kmalloc).
214233

215-
Further, the DMA address of the memory must be within the dma_mask of
216-
the device. To ensure that the memory allocated by kmalloc is within
217-
the dma_mask, the driver may specify various platform-dependent flags
218-
to restrict the DMA address range of the allocation (e.g., on x86,
219-
GFP_DMA guarantees to be within the first 16MB of available DMA
220-
addresses, as required by ISA devices).
221-
222-
Note also that the above constraints on physical contiguity and
223-
dma_mask may not apply if the platform has an IOMMU (a device which
224-
maps an I/O DMA address to a physical memory address). However, to be
225-
portable, device driver writers may *not* assume that such an IOMMU
226-
exists.
227-
228234
.. warning::
229235

230236
Memory coherency operates at a granularity called the cache

0 commit comments

Comments
 (0)