162306a36Sopenharmony_ci============== 262306a36Sopenharmony_ciDMA attributes 362306a36Sopenharmony_ci============== 462306a36Sopenharmony_ci 562306a36Sopenharmony_ciThis document describes the semantics of the DMA attributes that are 662306a36Sopenharmony_cidefined in linux/dma-mapping.h. 762306a36Sopenharmony_ci 862306a36Sopenharmony_ciDMA_ATTR_WEAK_ORDERING 962306a36Sopenharmony_ci---------------------- 1062306a36Sopenharmony_ci 1162306a36Sopenharmony_ciDMA_ATTR_WEAK_ORDERING specifies that reads and writes to the mapping 1262306a36Sopenharmony_cimay be weakly ordered, that is that reads and writes may pass each other. 1362306a36Sopenharmony_ci 1462306a36Sopenharmony_ciSince it is optional for platforms to implement DMA_ATTR_WEAK_ORDERING, 1562306a36Sopenharmony_cithose that do not will simply ignore the attribute and exhibit default 1662306a36Sopenharmony_cibehavior. 1762306a36Sopenharmony_ci 1862306a36Sopenharmony_ciDMA_ATTR_WRITE_COMBINE 1962306a36Sopenharmony_ci---------------------- 2062306a36Sopenharmony_ci 2162306a36Sopenharmony_ciDMA_ATTR_WRITE_COMBINE specifies that writes to the mapping may be 2262306a36Sopenharmony_cibuffered to improve performance. 2362306a36Sopenharmony_ci 2462306a36Sopenharmony_ciSince it is optional for platforms to implement DMA_ATTR_WRITE_COMBINE, 2562306a36Sopenharmony_cithose that do not will simply ignore the attribute and exhibit default 2662306a36Sopenharmony_cibehavior. 2762306a36Sopenharmony_ci 2862306a36Sopenharmony_ciDMA_ATTR_NO_KERNEL_MAPPING 2962306a36Sopenharmony_ci-------------------------- 3062306a36Sopenharmony_ci 3162306a36Sopenharmony_ciDMA_ATTR_NO_KERNEL_MAPPING lets the platform to avoid creating a kernel 3262306a36Sopenharmony_civirtual mapping for the allocated buffer. On some architectures creating 3362306a36Sopenharmony_cisuch mapping is non-trivial task and consumes very limited resources 3462306a36Sopenharmony_ci(like kernel virtual address space or dma consistent address space). 3562306a36Sopenharmony_ciBuffers allocated with this attribute can be only passed to user space 3662306a36Sopenharmony_ciby calling dma_mmap_attrs(). By using this API, you are guaranteeing 3762306a36Sopenharmony_cithat you won't dereference the pointer returned by dma_alloc_attr(). You 3862306a36Sopenharmony_cican treat it as a cookie that must be passed to dma_mmap_attrs() and 3962306a36Sopenharmony_cidma_free_attrs(). Make sure that both of these also get this attribute 4062306a36Sopenharmony_ciset on each call. 4162306a36Sopenharmony_ci 4262306a36Sopenharmony_ciSince it is optional for platforms to implement 4362306a36Sopenharmony_ciDMA_ATTR_NO_KERNEL_MAPPING, those that do not will simply ignore the 4462306a36Sopenharmony_ciattribute and exhibit default behavior. 4562306a36Sopenharmony_ci 4662306a36Sopenharmony_ciDMA_ATTR_SKIP_CPU_SYNC 4762306a36Sopenharmony_ci---------------------- 4862306a36Sopenharmony_ci 4962306a36Sopenharmony_ciBy default dma_map_{single,page,sg} functions family transfer a given 5062306a36Sopenharmony_cibuffer from CPU domain to device domain. Some advanced use cases might 5162306a36Sopenharmony_cirequire sharing a buffer between more than one device. This requires 5262306a36Sopenharmony_cihaving a mapping created separately for each device and is usually 5362306a36Sopenharmony_ciperformed by calling dma_map_{single,page,sg} function more than once 5462306a36Sopenharmony_cifor the given buffer with device pointer to each device taking part in 5562306a36Sopenharmony_cithe buffer sharing. The first call transfers a buffer from 'CPU' domain 5662306a36Sopenharmony_cito 'device' domain, what synchronizes CPU caches for the given region 5762306a36Sopenharmony_ci(usually it means that the cache has been flushed or invalidated 5862306a36Sopenharmony_cidepending on the dma direction). However, next calls to 5962306a36Sopenharmony_cidma_map_{single,page,sg}() for other devices will perform exactly the 6062306a36Sopenharmony_cisame synchronization operation on the CPU cache. CPU cache synchronization 6162306a36Sopenharmony_cimight be a time consuming operation, especially if the buffers are 6262306a36Sopenharmony_cilarge, so it is highly recommended to avoid it if possible. 6362306a36Sopenharmony_ciDMA_ATTR_SKIP_CPU_SYNC allows platform code to skip synchronization of 6462306a36Sopenharmony_cithe CPU cache for the given buffer assuming that it has been already 6562306a36Sopenharmony_citransferred to 'device' domain. This attribute can be also used for 6662306a36Sopenharmony_cidma_unmap_{single,page,sg} functions family to force buffer to stay in 6762306a36Sopenharmony_cidevice domain after releasing a mapping for it. Use this attribute with 6862306a36Sopenharmony_cicare! 6962306a36Sopenharmony_ci 7062306a36Sopenharmony_ciDMA_ATTR_FORCE_CONTIGUOUS 7162306a36Sopenharmony_ci------------------------- 7262306a36Sopenharmony_ci 7362306a36Sopenharmony_ciBy default DMA-mapping subsystem is allowed to assemble the buffer 7462306a36Sopenharmony_ciallocated by dma_alloc_attrs() function from individual pages if it can 7562306a36Sopenharmony_cibe mapped as contiguous chunk into device dma address space. By 7662306a36Sopenharmony_cispecifying this attribute the allocated buffer is forced to be contiguous 7762306a36Sopenharmony_cialso in physical memory. 7862306a36Sopenharmony_ci 7962306a36Sopenharmony_ciDMA_ATTR_ALLOC_SINGLE_PAGES 8062306a36Sopenharmony_ci--------------------------- 8162306a36Sopenharmony_ci 8262306a36Sopenharmony_ciThis is a hint to the DMA-mapping subsystem that it's probably not worth 8362306a36Sopenharmony_cithe time to try to allocate memory to in a way that gives better TLB 8462306a36Sopenharmony_ciefficiency (AKA it's not worth trying to build the mapping out of larger 8562306a36Sopenharmony_cipages). You might want to specify this if: 8662306a36Sopenharmony_ci 8762306a36Sopenharmony_ci- You know that the accesses to this memory won't thrash the TLB. 8862306a36Sopenharmony_ci You might know that the accesses are likely to be sequential or 8962306a36Sopenharmony_ci that they aren't sequential but it's unlikely you'll ping-pong 9062306a36Sopenharmony_ci between many addresses that are likely to be in different physical 9162306a36Sopenharmony_ci pages. 9262306a36Sopenharmony_ci- You know that the penalty of TLB misses while accessing the 9362306a36Sopenharmony_ci memory will be small enough to be inconsequential. If you are 9462306a36Sopenharmony_ci doing a heavy operation like decryption or decompression this 9562306a36Sopenharmony_ci might be the case. 9662306a36Sopenharmony_ci- You know that the DMA mapping is fairly transitory. If you expect 9762306a36Sopenharmony_ci the mapping to have a short lifetime then it may be worth it to 9862306a36Sopenharmony_ci optimize allocation (avoid coming up with large pages) instead of 9962306a36Sopenharmony_ci getting the slight performance win of larger pages. 10062306a36Sopenharmony_ci 10162306a36Sopenharmony_ciSetting this hint doesn't guarantee that you won't get huge pages, but it 10262306a36Sopenharmony_cimeans that we won't try quite as hard to get them. 10362306a36Sopenharmony_ci 10462306a36Sopenharmony_ci.. note:: At the moment DMA_ATTR_ALLOC_SINGLE_PAGES is only implemented on ARM, 10562306a36Sopenharmony_ci though ARM64 patches will likely be posted soon. 10662306a36Sopenharmony_ci 10762306a36Sopenharmony_ciDMA_ATTR_NO_WARN 10862306a36Sopenharmony_ci---------------- 10962306a36Sopenharmony_ci 11062306a36Sopenharmony_ciThis tells the DMA-mapping subsystem to suppress allocation failure reports 11162306a36Sopenharmony_ci(similarly to __GFP_NOWARN). 11262306a36Sopenharmony_ci 11362306a36Sopenharmony_ciOn some architectures allocation failures are reported with error messages 11462306a36Sopenharmony_cito the system logs. Although this can help to identify and debug problems, 11562306a36Sopenharmony_cidrivers which handle failures (eg, retry later) have no problems with them, 11662306a36Sopenharmony_ciand can actually flood the system logs with error messages that aren't any 11762306a36Sopenharmony_ciproblem at all, depending on the implementation of the retry mechanism. 11862306a36Sopenharmony_ci 11962306a36Sopenharmony_ciSo, this provides a way for drivers to avoid those error messages on calls 12062306a36Sopenharmony_ciwhere allocation failures are not a problem, and shouldn't bother the logs. 12162306a36Sopenharmony_ci 12262306a36Sopenharmony_ci.. note:: At the moment DMA_ATTR_NO_WARN is only implemented on PowerPC. 12362306a36Sopenharmony_ci 12462306a36Sopenharmony_ciDMA_ATTR_PRIVILEGED 12562306a36Sopenharmony_ci------------------- 12662306a36Sopenharmony_ci 12762306a36Sopenharmony_ciSome advanced peripherals such as remote processors and GPUs perform 12862306a36Sopenharmony_ciaccesses to DMA buffers in both privileged "supervisor" and unprivileged 12962306a36Sopenharmony_ci"user" modes. This attribute is used to indicate to the DMA-mapping 13062306a36Sopenharmony_cisubsystem that the buffer is fully accessible at the elevated privilege 13162306a36Sopenharmony_cilevel (and ideally inaccessible or at least read-only at the 13262306a36Sopenharmony_cilesser-privileged levels). 133