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

docs: dma-api: replace consistent with coherent

For consistency, always use the term "coherent" when talking about memory
that is not subject to CPU caching effects. The term "consistent" is a
relic of a long-removed PCI DMA API (pci_alloc_consistent() and
pci_free_consistent() functions).

Signed-off-by: Petr Tesarik <ptesarik@suse.com>
Tested-by: Randy Dunlap <rdunlap@infradead.org>
Acked-by: Marek Szyprowski <m.szyprowski@samsung.com>
Signed-off-by: Jonathan Corbet <corbet@lwn.net>
Link: https://lore.kernel.org/r/20250627101015.1600042-3-ptesarik@suse.com

authored by

Petr Tesarik and committed by
Jonathan Corbet
4d3c6bc1 7362b6ba

+28 -28
+18 -18
Documentation/core-api/dma-api-howto.rst
··· 155 155 156 156 Special note about PCI: PCI-X specification requires PCI-X devices to support 157 157 64-bit addressing (DAC) for all transactions. And at least one platform (SGI 158 - SN2) requires 64-bit consistent allocations to operate correctly when the IO 158 + SN2) requires 64-bit coherent allocations to operate correctly when the IO 159 159 bus is in PCI-X mode. 160 160 161 161 For correct operation, you must set the DMA mask to inform the kernel about ··· 174 174 175 175 int dma_set_mask(struct device *dev, u64 mask); 176 176 177 - The setup for consistent allocations is performed via a call 177 + The setup for coherent allocations is performed via a call 178 178 to dma_set_coherent_mask():: 179 179 180 180 int dma_set_coherent_mask(struct device *dev, u64 mask); ··· 241 241 242 242 The coherent mask will always be able to set the same or a smaller mask as 243 243 the streaming mask. However for the rare case that a device driver only 244 - uses consistent allocations, one would have to check the return value from 244 + uses coherent allocations, one would have to check the return value from 245 245 dma_set_coherent_mask(). 246 246 247 247 Finally, if your device can only drive the low 24-bits of ··· 298 298 299 299 There are two types of DMA mappings: 300 300 301 - - Consistent DMA mappings which are usually mapped at driver 301 + - Coherent DMA mappings which are usually mapped at driver 302 302 initialization, unmapped at the end and for which the hardware should 303 303 guarantee that the device and the CPU can access the data 304 304 in parallel and will see updates made by each other without any 305 305 explicit software flushing. 306 306 307 - Think of "consistent" as "synchronous" or "coherent". 307 + Think of "coherent" as "synchronous". 308 308 309 - The current default is to return consistent memory in the low 32 309 + The current default is to return coherent memory in the low 32 310 310 bits of the DMA space. However, for future compatibility you should 311 - set the consistent mask even if this default is fine for your 311 + set the coherent mask even if this default is fine for your 312 312 driver. 313 313 314 - Good examples of what to use consistent mappings for are: 314 + Good examples of what to use coherent mappings for are: 315 315 316 316 - Network card DMA ring descriptors. 317 317 - SCSI adapter mailbox command data structures. ··· 320 320 321 321 The invariant these examples all require is that any CPU store 322 322 to memory is immediately visible to the device, and vice 323 - versa. Consistent mappings guarantee this. 323 + versa. Coherent mappings guarantee this. 324 324 325 325 .. important:: 326 326 327 - Consistent DMA memory does not preclude the usage of 327 + Coherent DMA memory does not preclude the usage of 328 328 proper memory barriers. The CPU may reorder stores to 329 - consistent memory just as it may normal memory. Example: 329 + coherent memory just as it may normal memory. Example: 330 330 if it is important for the device to see the first word 331 331 of a descriptor updated before the second, you must do 332 332 something like:: ··· 365 365 when the underlying buffers don't share cache lines with other data. 366 366 367 367 368 - Using Consistent DMA mappings 369 - ============================= 368 + Using Coherent DMA mappings 369 + =========================== 370 370 371 - To allocate and map large (PAGE_SIZE or so) consistent DMA regions, 371 + To allocate and map large (PAGE_SIZE or so) coherent DMA regions, 372 372 you should do:: 373 373 374 374 dma_addr_t dma_handle; ··· 385 385 driver needs regions sized smaller than a page, you may prefer using 386 386 the dma_pool interface, described below. 387 387 388 - The consistent DMA mapping interfaces, will by default return a DMA address 388 + The coherent DMA mapping interfaces, will by default return a DMA address 389 389 which is 32-bit addressable. Even if the device indicates (via the DMA mask) 390 - that it may address the upper 32-bits, consistent allocation will only 391 - return > 32-bit addresses for DMA if the consistent DMA mask has been 390 + that it may address the upper 32-bits, coherent allocation will only 391 + return > 32-bit addresses for DMA if the coherent DMA mask has been 392 392 explicitly changed via dma_set_coherent_mask(). This is true of the 393 393 dma_pool interface as well. 394 394 ··· 497 497 kernel logs when the DMA controller hardware detects violation of the 498 498 permission setting. 499 499 500 - Only streaming mappings specify a direction, consistent mappings 500 + Only streaming mappings specify a direction, coherent mappings 501 501 implicitly have a direction attribute setting of 502 502 DMA_BIDIRECTIONAL. 503 503
+7 -7
Documentation/core-api/dma-api.rst
··· 8 8 of the API (and actual examples), see Documentation/core-api/dma-api-howto.rst. 9 9 10 10 This API is split into two pieces. Part I describes the basic API. 11 - Part II describes extensions for supporting non-consistent memory 11 + Part II describes extensions for supporting non-coherent memory 12 12 machines. Unless you know that your driver absolutely has to support 13 - non-consistent platforms (this is usually only legacy platforms) you 13 + non-coherent platforms (this is usually only legacy platforms) you 14 14 should only use the API described in part I. 15 15 16 16 Part I - DMA API ··· 33 33 dma_alloc_coherent(struct device *dev, size_t size, 34 34 dma_addr_t *dma_handle, gfp_t flag) 35 35 36 - Consistent memory is memory for which a write by either the device or 36 + Coherent memory is memory for which a write by either the device or 37 37 the processor can immediately be read by the processor or device 38 38 without having to worry about caching effects. (You may however need 39 39 to make sure to flush the processor's write buffers before telling 40 40 devices to read that memory.) 41 41 42 - This routine allocates a region of <size> bytes of consistent memory. 42 + This routine allocates a region of <size> bytes of coherent memory. 43 43 44 44 It returns a pointer to the allocated region (in the processor's virtual 45 45 address space) or NULL if the allocation failed. ··· 48 48 same width as the bus and given to the device as the DMA address base of 49 49 the region. 50 50 51 - Note: consistent memory can be expensive on some platforms, and the 51 + Note: coherent memory can be expensive on some platforms, and the 52 52 minimum allocation length may be as big as a page, so you should 53 - consolidate your requests for consistent memory as much as possible. 53 + consolidate your requests for coherent memory as much as possible. 54 54 The simplest way to do that is to use the dma_pool calls (see below). 55 55 56 56 The flag parameter (dma_alloc_coherent() only) allows the caller to ··· 64 64 dma_free_coherent(struct device *dev, size_t size, void *cpu_addr, 65 65 dma_addr_t dma_handle) 66 66 67 - Free a region of consistent memory you previously allocated. dev, 67 + Free a region of coherent memory you previously allocated. dev, 68 68 size and dma_handle must all be the same as those passed into 69 69 dma_alloc_coherent(). cpu_addr must be the virtual address returned by 70 70 the dma_alloc_coherent().
+3 -3
mm/dmapool.c
··· 200 200 201 201 202 202 /** 203 - * dma_pool_create_node - Creates a pool of consistent memory blocks, for dma. 203 + * dma_pool_create_node - Creates a pool of coherent DMA memory blocks. 204 204 * @name: name of pool, for diagnostics 205 205 * @dev: device that will be doing the DMA 206 206 * @size: size of the blocks in this pool. ··· 210 210 * Context: not in_interrupt() 211 211 * 212 212 * Given one of these pools, dma_pool_alloc() 213 - * may be used to allocate memory. Such memory will all have "consistent" 213 + * may be used to allocate memory. Such memory will all have coherent 214 214 * DMA mappings, accessible by the device and its driver without using 215 215 * cache flushing primitives. The actual size of blocks allocated may be 216 216 * larger than requested because of alignment. ··· 395 395 EXPORT_SYMBOL(dma_pool_destroy); 396 396 397 397 /** 398 - * dma_pool_alloc - get a block of consistent memory 398 + * dma_pool_alloc - get a block of coherent memory 399 399 * @pool: dma pool that will produce the block 400 400 * @mem_flags: GFP_* bitmask 401 401 * @handle: pointer to dma address of block