18c2ecf20Sopenharmony_ci==============
28c2ecf20Sopenharmony_ciDMA attributes
38c2ecf20Sopenharmony_ci==============
48c2ecf20Sopenharmony_ci
58c2ecf20Sopenharmony_ciThis document describes the semantics of the DMA attributes that are
68c2ecf20Sopenharmony_cidefined in linux/dma-mapping.h.
78c2ecf20Sopenharmony_ci
88c2ecf20Sopenharmony_ciDMA_ATTR_WEAK_ORDERING
98c2ecf20Sopenharmony_ci----------------------
108c2ecf20Sopenharmony_ci
118c2ecf20Sopenharmony_ciDMA_ATTR_WEAK_ORDERING specifies that reads and writes to the mapping
128c2ecf20Sopenharmony_cimay be weakly ordered, that is that reads and writes may pass each other.
138c2ecf20Sopenharmony_ci
148c2ecf20Sopenharmony_ciSince it is optional for platforms to implement DMA_ATTR_WEAK_ORDERING,
158c2ecf20Sopenharmony_cithose that do not will simply ignore the attribute and exhibit default
168c2ecf20Sopenharmony_cibehavior.
178c2ecf20Sopenharmony_ci
188c2ecf20Sopenharmony_ciDMA_ATTR_WRITE_COMBINE
198c2ecf20Sopenharmony_ci----------------------
208c2ecf20Sopenharmony_ci
218c2ecf20Sopenharmony_ciDMA_ATTR_WRITE_COMBINE specifies that writes to the mapping may be
228c2ecf20Sopenharmony_cibuffered to improve performance.
238c2ecf20Sopenharmony_ci
248c2ecf20Sopenharmony_ciSince it is optional for platforms to implement DMA_ATTR_WRITE_COMBINE,
258c2ecf20Sopenharmony_cithose that do not will simply ignore the attribute and exhibit default
268c2ecf20Sopenharmony_cibehavior.
278c2ecf20Sopenharmony_ci
288c2ecf20Sopenharmony_ciDMA_ATTR_NO_KERNEL_MAPPING
298c2ecf20Sopenharmony_ci--------------------------
308c2ecf20Sopenharmony_ci
318c2ecf20Sopenharmony_ciDMA_ATTR_NO_KERNEL_MAPPING lets the platform to avoid creating a kernel
328c2ecf20Sopenharmony_civirtual mapping for the allocated buffer. On some architectures creating
338c2ecf20Sopenharmony_cisuch mapping is non-trivial task and consumes very limited resources
348c2ecf20Sopenharmony_ci(like kernel virtual address space or dma consistent address space).
358c2ecf20Sopenharmony_ciBuffers allocated with this attribute can be only passed to user space
368c2ecf20Sopenharmony_ciby calling dma_mmap_attrs(). By using this API, you are guaranteeing
378c2ecf20Sopenharmony_cithat you won't dereference the pointer returned by dma_alloc_attr(). You
388c2ecf20Sopenharmony_cican treat it as a cookie that must be passed to dma_mmap_attrs() and
398c2ecf20Sopenharmony_cidma_free_attrs(). Make sure that both of these also get this attribute
408c2ecf20Sopenharmony_ciset on each call.
418c2ecf20Sopenharmony_ci
428c2ecf20Sopenharmony_ciSince it is optional for platforms to implement
438c2ecf20Sopenharmony_ciDMA_ATTR_NO_KERNEL_MAPPING, those that do not will simply ignore the
448c2ecf20Sopenharmony_ciattribute and exhibit default behavior.
458c2ecf20Sopenharmony_ci
468c2ecf20Sopenharmony_ciDMA_ATTR_SKIP_CPU_SYNC
478c2ecf20Sopenharmony_ci----------------------
488c2ecf20Sopenharmony_ci
498c2ecf20Sopenharmony_ciBy default dma_map_{single,page,sg} functions family transfer a given
508c2ecf20Sopenharmony_cibuffer from CPU domain to device domain. Some advanced use cases might
518c2ecf20Sopenharmony_cirequire sharing a buffer between more than one device. This requires
528c2ecf20Sopenharmony_cihaving a mapping created separately for each device and is usually
538c2ecf20Sopenharmony_ciperformed by calling dma_map_{single,page,sg} function more than once
548c2ecf20Sopenharmony_cifor the given buffer with device pointer to each device taking part in
558c2ecf20Sopenharmony_cithe buffer sharing. The first call transfers a buffer from 'CPU' domain
568c2ecf20Sopenharmony_cito 'device' domain, what synchronizes CPU caches for the given region
578c2ecf20Sopenharmony_ci(usually it means that the cache has been flushed or invalidated
588c2ecf20Sopenharmony_cidepending on the dma direction). However, next calls to
598c2ecf20Sopenharmony_cidma_map_{single,page,sg}() for other devices will perform exactly the
608c2ecf20Sopenharmony_cisame synchronization operation on the CPU cache. CPU cache synchronization
618c2ecf20Sopenharmony_cimight be a time consuming operation, especially if the buffers are
628c2ecf20Sopenharmony_cilarge, so it is highly recommended to avoid it if possible.
638c2ecf20Sopenharmony_ciDMA_ATTR_SKIP_CPU_SYNC allows platform code to skip synchronization of
648c2ecf20Sopenharmony_cithe CPU cache for the given buffer assuming that it has been already
658c2ecf20Sopenharmony_citransferred to 'device' domain. This attribute can be also used for
668c2ecf20Sopenharmony_cidma_unmap_{single,page,sg} functions family to force buffer to stay in
678c2ecf20Sopenharmony_cidevice domain after releasing a mapping for it. Use this attribute with
688c2ecf20Sopenharmony_cicare!
698c2ecf20Sopenharmony_ci
708c2ecf20Sopenharmony_ciDMA_ATTR_FORCE_CONTIGUOUS
718c2ecf20Sopenharmony_ci-------------------------
728c2ecf20Sopenharmony_ci
738c2ecf20Sopenharmony_ciBy default DMA-mapping subsystem is allowed to assemble the buffer
748c2ecf20Sopenharmony_ciallocated by dma_alloc_attrs() function from individual pages if it can
758c2ecf20Sopenharmony_cibe mapped as contiguous chunk into device dma address space. By
768c2ecf20Sopenharmony_cispecifying this attribute the allocated buffer is forced to be contiguous
778c2ecf20Sopenharmony_cialso in physical memory.
788c2ecf20Sopenharmony_ci
798c2ecf20Sopenharmony_ciDMA_ATTR_ALLOC_SINGLE_PAGES
808c2ecf20Sopenharmony_ci---------------------------
818c2ecf20Sopenharmony_ci
828c2ecf20Sopenharmony_ciThis is a hint to the DMA-mapping subsystem that it's probably not worth
838c2ecf20Sopenharmony_cithe time to try to allocate memory to in a way that gives better TLB
848c2ecf20Sopenharmony_ciefficiency (AKA it's not worth trying to build the mapping out of larger
858c2ecf20Sopenharmony_cipages).  You might want to specify this if:
868c2ecf20Sopenharmony_ci
878c2ecf20Sopenharmony_ci- You know that the accesses to this memory won't thrash the TLB.
888c2ecf20Sopenharmony_ci  You might know that the accesses are likely to be sequential or
898c2ecf20Sopenharmony_ci  that they aren't sequential but it's unlikely you'll ping-pong
908c2ecf20Sopenharmony_ci  between many addresses that are likely to be in different physical
918c2ecf20Sopenharmony_ci  pages.
928c2ecf20Sopenharmony_ci- You know that the penalty of TLB misses while accessing the
938c2ecf20Sopenharmony_ci  memory will be small enough to be inconsequential.  If you are
948c2ecf20Sopenharmony_ci  doing a heavy operation like decryption or decompression this
958c2ecf20Sopenharmony_ci  might be the case.
968c2ecf20Sopenharmony_ci- You know that the DMA mapping is fairly transitory.  If you expect
978c2ecf20Sopenharmony_ci  the mapping to have a short lifetime then it may be worth it to
988c2ecf20Sopenharmony_ci  optimize allocation (avoid coming up with large pages) instead of
998c2ecf20Sopenharmony_ci  getting the slight performance win of larger pages.
1008c2ecf20Sopenharmony_ci
1018c2ecf20Sopenharmony_ciSetting this hint doesn't guarantee that you won't get huge pages, but it
1028c2ecf20Sopenharmony_cimeans that we won't try quite as hard to get them.
1038c2ecf20Sopenharmony_ci
1048c2ecf20Sopenharmony_ci.. note:: At the moment DMA_ATTR_ALLOC_SINGLE_PAGES is only implemented on ARM,
1058c2ecf20Sopenharmony_ci	  though ARM64 patches will likely be posted soon.
1068c2ecf20Sopenharmony_ci
1078c2ecf20Sopenharmony_ciDMA_ATTR_NO_WARN
1088c2ecf20Sopenharmony_ci----------------
1098c2ecf20Sopenharmony_ci
1108c2ecf20Sopenharmony_ciThis tells the DMA-mapping subsystem to suppress allocation failure reports
1118c2ecf20Sopenharmony_ci(similarly to __GFP_NOWARN).
1128c2ecf20Sopenharmony_ci
1138c2ecf20Sopenharmony_ciOn some architectures allocation failures are reported with error messages
1148c2ecf20Sopenharmony_cito the system logs.  Although this can help to identify and debug problems,
1158c2ecf20Sopenharmony_cidrivers which handle failures (eg, retry later) have no problems with them,
1168c2ecf20Sopenharmony_ciand can actually flood the system logs with error messages that aren't any
1178c2ecf20Sopenharmony_ciproblem at all, depending on the implementation of the retry mechanism.
1188c2ecf20Sopenharmony_ci
1198c2ecf20Sopenharmony_ciSo, this provides a way for drivers to avoid those error messages on calls
1208c2ecf20Sopenharmony_ciwhere allocation failures are not a problem, and shouldn't bother the logs.
1218c2ecf20Sopenharmony_ci
1228c2ecf20Sopenharmony_ci.. note:: At the moment DMA_ATTR_NO_WARN is only implemented on PowerPC.
1238c2ecf20Sopenharmony_ci
1248c2ecf20Sopenharmony_ciDMA_ATTR_PRIVILEGED
1258c2ecf20Sopenharmony_ci-------------------
1268c2ecf20Sopenharmony_ci
1278c2ecf20Sopenharmony_ciSome advanced peripherals such as remote processors and GPUs perform
1288c2ecf20Sopenharmony_ciaccesses to DMA buffers in both privileged "supervisor" and unprivileged
1298c2ecf20Sopenharmony_ci"user" modes.  This attribute is used to indicate to the DMA-mapping
1308c2ecf20Sopenharmony_cisubsystem that the buffer is fully accessible at the elevated privilege
1318c2ecf20Sopenharmony_cilevel (and ideally inaccessible or at least read-only at the
1328c2ecf20Sopenharmony_cilesser-privileged levels).
133