xref: /linux/kernel/dma/Kconfig (revision 3fd6c59042dbba50391e30862beac979491145fe)
1ec8f24b7SThomas Gleixner# SPDX-License-Identifier: GPL-2.0-only
2cf65a0f6SChristoph Hellwig
3846f9e1fSChristoph Hellwigconfig NO_DMA
4846f9e1fSChristoph Hellwig	bool
5846f9e1fSChristoph Hellwig
6cf65a0f6SChristoph Hellwigconfig HAS_DMA
7cf65a0f6SChristoph Hellwig	bool
8cf65a0f6SChristoph Hellwig	depends on !NO_DMA
9cf65a0f6SChristoph Hellwig	default y
10cf65a0f6SChristoph Hellwig
11b5c58b2fSLeon Romanovskyconfig DMA_OPS_HELPERS
12b5c58b2fSLeon Romanovsky	bool
13b5c58b2fSLeon Romanovsky
14d35834c6SChristoph Hellwig#
15d35834c6SChristoph Hellwig# IOMMU drivers that can bypass the IOMMU code and optionally use the direct
16d35834c6SChristoph Hellwig# mapping fast path should select this option and set the dma_ops_bypass
17d35834c6SChristoph Hellwig# flag in struct device where applicable
18d35834c6SChristoph Hellwig#
19d35834c6SChristoph Hellwigconfig DMA_OPS_BYPASS
20d35834c6SChristoph Hellwig	bool
21d35834c6SChristoph Hellwig
228d8d53cfSAlexey Kardashevskiy# Lets platform IOMMU driver choose between bypass and IOMMU
238d8d53cfSAlexey Kardashevskiyconfig ARCH_HAS_DMA_MAP_DIRECT
248d8d53cfSAlexey Kardashevskiy	bool
258d8d53cfSAlexey Kardashevskiy
26af2880ecSRobin Murphyconfig NEED_SG_DMA_FLAGS
27af2880ecSRobin Murphy	bool
28af2880ecSRobin Murphy
29cf65a0f6SChristoph Hellwigconfig NEED_SG_DMA_LENGTH
30cf65a0f6SChristoph Hellwig	bool
31cf65a0f6SChristoph Hellwig
32cf65a0f6SChristoph Hellwigconfig NEED_DMA_MAP_STATE
33cf65a0f6SChristoph Hellwig	bool
34cf65a0f6SChristoph Hellwig
35cf65a0f6SChristoph Hellwigconfig ARCH_DMA_ADDR_T_64BIT
36cf65a0f6SChristoph Hellwig	def_bool 64BIT || PHYS_ADDR_T_64BIT
37cf65a0f6SChristoph Hellwig
3811ddce15SChristoph Hellwigconfig ARCH_HAS_DMA_SET_MASK
3911ddce15SChristoph Hellwig	bool
4011ddce15SChristoph Hellwig
41419e2f18SChristoph Hellwig#
42419e2f18SChristoph Hellwig# Select this option if the architecture needs special handling for
43419e2f18SChristoph Hellwig# DMA_ATTR_WRITE_COMBINE.  Normally the "uncached" mapping should be what
444d3af20eSSui Jingfeng# people think of when saying write combine, so very few platforms should
45419e2f18SChristoph Hellwig# need to enable this.
46419e2f18SChristoph Hellwig#
47419e2f18SChristoph Hellwigconfig ARCH_HAS_DMA_WRITE_COMBINE
48419e2f18SChristoph Hellwig	bool
49419e2f18SChristoph Hellwig
50abdaf11aSChristoph Hellwig#
51abdaf11aSChristoph Hellwig# Select if the architectures provides the arch_dma_mark_clean hook
52abdaf11aSChristoph Hellwig#
53abdaf11aSChristoph Hellwigconfig ARCH_HAS_DMA_MARK_CLEAN
54abdaf11aSChristoph Hellwig	bool
55abdaf11aSChristoph Hellwig
56ff4c25f2SChristoph Hellwigconfig DMA_DECLARE_COHERENT
57cf65a0f6SChristoph Hellwig	bool
58cf65a0f6SChristoph Hellwig
59347cb6afSChristoph Hellwigconfig ARCH_HAS_SETUP_DMA_OPS
60347cb6afSChristoph Hellwig	bool
61347cb6afSChristoph Hellwig
62dc2acdedSChristoph Hellwigconfig ARCH_HAS_TEARDOWN_DMA_OPS
63cf65a0f6SChristoph Hellwig	bool
64cf65a0f6SChristoph Hellwig
65cf65a0f6SChristoph Hellwigconfig ARCH_HAS_SYNC_DMA_FOR_DEVICE
66cf65a0f6SChristoph Hellwig	bool
67cf65a0f6SChristoph Hellwig
68cf65a0f6SChristoph Hellwigconfig ARCH_HAS_SYNC_DMA_FOR_CPU
69cf65a0f6SChristoph Hellwig	bool
70cf65a0f6SChristoph Hellwig	select NEED_DMA_MAP_STATE
71cf65a0f6SChristoph Hellwig
72684f7e91SChristoph Hellwigconfig ARCH_HAS_SYNC_DMA_FOR_CPU_ALL
73684f7e91SChristoph Hellwig	bool
74684f7e91SChristoph Hellwig
7513bf5cedSChristoph Hellwigconfig ARCH_HAS_DMA_PREP_COHERENT
7613bf5cedSChristoph Hellwig	bool
7713bf5cedSChristoph Hellwig
789087c375STom Lendackyconfig ARCH_HAS_FORCE_DMA_UNENCRYPTED
799087c375STom Lendacky	bool
809087c375STom Lendacky
811d3f56b2SJiaxun Yang#
821d3f56b2SJiaxun Yang# Select this option if the architecture assumes DMA devices are coherent
831d3f56b2SJiaxun Yang# by default.
841d3f56b2SJiaxun Yang#
851d3f56b2SJiaxun Yangconfig ARCH_DMA_DEFAULT_COHERENT
861d3f56b2SJiaxun Yang	bool
871d3f56b2SJiaxun Yang
88cf65a0f6SChristoph Hellwigconfig SWIOTLB
89cf65a0f6SChristoph Hellwig	bool
90cf65a0f6SChristoph Hellwig	select NEED_DMA_MAP_STATE
91f0edfea8SChristoph Hellwig
9262708b2bSPetr Tesarikconfig SWIOTLB_DYNAMIC
9362708b2bSPetr Tesarik	bool "Dynamic allocation of DMA bounce buffers"
9462708b2bSPetr Tesarik	default n
9562708b2bSPetr Tesarik	depends on SWIOTLB
9662708b2bSPetr Tesarik	help
9762708b2bSPetr Tesarik	  This enables dynamic resizing of the software IO TLB. The kernel
9862708b2bSPetr Tesarik	  starts with one memory pool at boot and it will allocate additional
9962708b2bSPetr Tesarik	  pools as needed. To reduce run-time kernel memory requirements, you
10062708b2bSPetr Tesarik	  may have to specify a smaller size of the initial pool using
10162708b2bSPetr Tesarik	  "swiotlb=" on the kernel command line.
10262708b2bSPetr Tesarik
10362708b2bSPetr Tesarik	  If unsure, say N.
10462708b2bSPetr Tesarik
105370645f4SCatalin Marinasconfig DMA_BOUNCE_UNALIGNED_KMALLOC
106370645f4SCatalin Marinas	bool
107370645f4SCatalin Marinas	depends on SWIOTLB
108370645f4SCatalin Marinas
109fe7514b1SAlexander Lobakinconfig DMA_NEED_SYNC
110fe7514b1SAlexander Lobakin	def_bool ARCH_HAS_SYNC_DMA_FOR_DEVICE || ARCH_HAS_SYNC_DMA_FOR_CPU || \
111*de6c85bfSChristoph Hellwig		 ARCH_HAS_SYNC_DMA_FOR_CPU_ALL || DMA_API_DEBUG || \
112*de6c85bfSChristoph Hellwig		 ARCH_HAS_DMA_OPS || SWIOTLB
113fe7514b1SAlexander Lobakin
1140b84e4f8SClaire Changconfig DMA_RESTRICTED_POOL
1150b84e4f8SClaire Chang	bool "DMA Restricted Pool"
116f3c4b134SClaire Chang	depends on OF && OF_RESERVED_MEM && SWIOTLB
1170b84e4f8SClaire Chang	help
1180b84e4f8SClaire Chang	  This enables support for restricted DMA pools which provide a level of
1190b84e4f8SClaire Chang	  DMA memory protection on systems with limited hardware protection
1200b84e4f8SClaire Chang	  capabilities, such as those lacking an IOMMU.
1210b84e4f8SClaire Chang
1220b84e4f8SClaire Chang	  For more information see
1230b84e4f8SClaire Chang	  <Documentation/devicetree/bindings/reserved-memory/reserved-memory.txt>
1240b84e4f8SClaire Chang	  and <kernel/dma/swiotlb.c>.
1250b84e4f8SClaire Chang	  If unsure, say "n".
1260b84e4f8SClaire Chang
12734dc0ea6SChristoph Hellwig#
12834dc0ea6SChristoph Hellwig# Should be selected if we can mmap non-coherent mappings to userspace.
12934dc0ea6SChristoph Hellwig# The only thing that is really required is a way to set an uncached bit
13034dc0ea6SChristoph Hellwig# in the pagetables
13134dc0ea6SChristoph Hellwig#
13234dc0ea6SChristoph Hellwigconfig DMA_NONCOHERENT_MMAP
1331fbf57d0SChristoph Hellwig	default y if !MMU
13434dc0ea6SChristoph Hellwig	bool
13534dc0ea6SChristoph Hellwig
136dbed452aSDavid Rientjesconfig DMA_COHERENT_POOL
137d07ae4c4SChristoph Hellwig	select GENERIC_ALLOCATOR
138dbed452aSDavid Rientjes	bool
139dbed452aSDavid Rientjes
140faf4ef82SChristoph Hellwigconfig DMA_GLOBAL_POOL
141faf4ef82SChristoph Hellwig	select DMA_DECLARE_COHERENT
142da323d46SChristoph Hellwig	depends on !ARCH_HAS_DMA_SET_UNCACHED
143da323d46SChristoph Hellwig	depends on !DMA_DIRECT_REMAP
144faf4ef82SChristoph Hellwig	bool
145faf4ef82SChristoph Hellwig
146e860c299SDavid Rientjesconfig DMA_DIRECT_REMAP
147e860c299SDavid Rientjes	bool
148e860c299SDavid Rientjes	select DMA_COHERENT_POOL
149f5ff79fdSChristoph Hellwig	select DMA_NONCOHERENT_MMAP
150e860c299SDavid Rientjes
1512c8ed1b9SChristoph Hellwig#
1522c8ed1b9SChristoph Hellwig# Fallback to arch code for DMA allocations.  This should eventually go away.
1532c8ed1b9SChristoph Hellwig#
1542c8ed1b9SChristoph Hellwigconfig ARCH_HAS_DMA_ALLOC
1552c8ed1b9SChristoph Hellwig	depends on !ARCH_HAS_DMA_SET_UNCACHED
1562c8ed1b9SChristoph Hellwig	depends on !DMA_DIRECT_REMAP
1572c8ed1b9SChristoph Hellwig	depends on !DMA_GLOBAL_POOL
1582c8ed1b9SChristoph Hellwig	bool
1592c8ed1b9SChristoph Hellwig
160ddb26d8eSChristoph Hellwigconfig DMA_CMA
161ddb26d8eSChristoph Hellwig	bool "DMA Contiguous Memory Allocator"
162ddb26d8eSChristoph Hellwig	depends on HAVE_DMA_CONTIGUOUS && CMA
163ddb26d8eSChristoph Hellwig	help
164ddb26d8eSChristoph Hellwig	  This enables the Contiguous Memory Allocator which allows drivers
165ddb26d8eSChristoph Hellwig	  to allocate big physically-contiguous blocks of memory for use with
166ddb26d8eSChristoph Hellwig	  hardware components that do not support I/O map nor scatter-gather.
167ddb26d8eSChristoph Hellwig
168ddb26d8eSChristoph Hellwig	  You can disable CMA by specifying "cma=0" on the kernel's command
169ddb26d8eSChristoph Hellwig	  line.
170ddb26d8eSChristoph Hellwig
1710b1abd1fSChristoph Hellwig	  For more information see <kernel/dma/contiguous.c>.
172ddb26d8eSChristoph Hellwig	  If unsure, say "n".
173ddb26d8eSChristoph Hellwig
174ddb26d8eSChristoph Hellwigif  DMA_CMA
175b7176c26SBarry Song
176bf29bfaaSYajun Dengconfig DMA_NUMA_CMA
177bf29bfaaSYajun Deng	bool "Enable separate DMA Contiguous Memory Area for NUMA Node"
1782dcdf8c1SChristoph Hellwig	depends on NUMA
179b7176c26SBarry Song	help
180bf29bfaaSYajun Deng	  Enable this option to get numa CMA areas so that NUMA devices
18122e4a348SYajun Deng	  can get local memory by DMA coherent APIs.
182b7176c26SBarry Song
183b7176c26SBarry Song	  You can set the size of pernuma CMA by specifying "cma_pernuma=size"
184bf29bfaaSYajun Deng	  or set the node id and its size of CMA by specifying "numa_cma=
185bf29bfaaSYajun Deng	  <node>:size[,<node>:size]" on the kernel's command line.
186b7176c26SBarry Song
187ddb26d8eSChristoph Hellwigcomment "Default contiguous memory area size:"
188ddb26d8eSChristoph Hellwig
189ddb26d8eSChristoph Hellwigconfig CMA_SIZE_MBYTES
190ddb26d8eSChristoph Hellwig	int "Size in Mega Bytes"
191ddb26d8eSChristoph Hellwig	depends on !CMA_SIZE_SEL_PERCENTAGE
192ddb26d8eSChristoph Hellwig	default 0 if X86
193ddb26d8eSChristoph Hellwig	default 16
194ddb26d8eSChristoph Hellwig	help
195ddb26d8eSChristoph Hellwig	  Defines the size (in MiB) of the default memory area for Contiguous
196ddb26d8eSChristoph Hellwig	  Memory Allocator.  If the size of 0 is selected, CMA is disabled by
197ddb26d8eSChristoph Hellwig	  default, but it can be enabled by passing cma=size[MG] to the kernel.
198ddb26d8eSChristoph Hellwig
199ddb26d8eSChristoph Hellwig
200ddb26d8eSChristoph Hellwigconfig CMA_SIZE_PERCENTAGE
201ddb26d8eSChristoph Hellwig	int "Percentage of total memory"
202ddb26d8eSChristoph Hellwig	depends on !CMA_SIZE_SEL_MBYTES
203ddb26d8eSChristoph Hellwig	default 0 if X86
204ddb26d8eSChristoph Hellwig	default 10
205ddb26d8eSChristoph Hellwig	help
206ddb26d8eSChristoph Hellwig	  Defines the size of the default memory area for Contiguous Memory
207ddb26d8eSChristoph Hellwig	  Allocator as a percentage of the total memory in the system.
208ddb26d8eSChristoph Hellwig	  If 0 percent is selected, CMA is disabled by default, but it can be
209ddb26d8eSChristoph Hellwig	  enabled by passing cma=size[MG] to the kernel.
210ddb26d8eSChristoph Hellwig
211ddb26d8eSChristoph Hellwigchoice
212ddb26d8eSChristoph Hellwig	prompt "Selected region size"
213ddb26d8eSChristoph Hellwig	default CMA_SIZE_SEL_MBYTES
214ddb26d8eSChristoph Hellwig
215ddb26d8eSChristoph Hellwigconfig CMA_SIZE_SEL_MBYTES
216ddb26d8eSChristoph Hellwig	bool "Use mega bytes value only"
217ddb26d8eSChristoph Hellwig
218ddb26d8eSChristoph Hellwigconfig CMA_SIZE_SEL_PERCENTAGE
219ddb26d8eSChristoph Hellwig	bool "Use percentage value only"
220ddb26d8eSChristoph Hellwig
221ddb26d8eSChristoph Hellwigconfig CMA_SIZE_SEL_MIN
222ddb26d8eSChristoph Hellwig	bool "Use lower value (minimum)"
223ddb26d8eSChristoph Hellwig
224ddb26d8eSChristoph Hellwigconfig CMA_SIZE_SEL_MAX
225ddb26d8eSChristoph Hellwig	bool "Use higher value (maximum)"
226ddb26d8eSChristoph Hellwig
227ddb26d8eSChristoph Hellwigendchoice
228ddb26d8eSChristoph Hellwig
229ddb26d8eSChristoph Hellwigconfig CMA_ALIGNMENT
230ddb26d8eSChristoph Hellwig	int "Maximum PAGE_SIZE order of alignment for contiguous buffers"
2310de32796SPaul Cercueil	range 2 12
232ddb26d8eSChristoph Hellwig	default 8
233ddb26d8eSChristoph Hellwig	help
234ddb26d8eSChristoph Hellwig	  DMA mapping framework by default aligns all buffers to the smallest
235ddb26d8eSChristoph Hellwig	  PAGE_SIZE order which is greater than or equal to the requested buffer
236ddb26d8eSChristoph Hellwig	  size. This works well for buffers up to a few hundreds kilobytes, but
237ddb26d8eSChristoph Hellwig	  for larger buffers it just a memory waste. With this parameter you can
238ddb26d8eSChristoph Hellwig	  specify the maximum PAGE_SIZE order for contiguous buffers. Larger
239ddb26d8eSChristoph Hellwig	  buffers will be aligned only to this specified order. The order is
240ddb26d8eSChristoph Hellwig	  expressed as a power of two multiplied by the PAGE_SIZE.
241ddb26d8eSChristoph Hellwig
242ddb26d8eSChristoph Hellwig	  For example, if your system defaults to 4KiB pages, the order value
243ddb26d8eSChristoph Hellwig	  of 8 means that the buffers will be aligned up to 1MiB only.
244ddb26d8eSChristoph Hellwig
245ddb26d8eSChristoph Hellwig	  If unsure, leave the default value "8".
246ddb26d8eSChristoph Hellwig
247ddb26d8eSChristoph Hellwigendif
248ddb26d8eSChristoph Hellwig
24970ca7ba2SAndy Shevchenkoconfig DMA_API_DEBUG
25070ca7ba2SAndy Shevchenko	bool "Enable debugging of DMA-API usage"
25170ca7ba2SAndy Shevchenko	select NEED_DMA_MAP_STATE
25270ca7ba2SAndy Shevchenko	help
25370ca7ba2SAndy Shevchenko	  Enable this option to debug the use of the DMA API by device drivers.
25470ca7ba2SAndy Shevchenko	  With this option you will be able to detect common bugs in device
25570ca7ba2SAndy Shevchenko	  drivers like double-freeing of DMA mappings or freeing mappings that
25670ca7ba2SAndy Shevchenko	  were never allocated.
25770ca7ba2SAndy Shevchenko
25870ca7ba2SAndy Shevchenko	  This option causes a performance degradation.  Use only if you want to
25970ca7ba2SAndy Shevchenko	  debug device drivers and dma interactions.
26070ca7ba2SAndy Shevchenko
26170ca7ba2SAndy Shevchenko	  If unsure, say N.
26270ca7ba2SAndy Shevchenko
26370ca7ba2SAndy Shevchenkoconfig DMA_MAP_BENCHMARK
26470ca7ba2SAndy Shevchenko	bool "Enable benchmarking of streaming DMA mapping"
26570ca7ba2SAndy Shevchenko	depends on DEBUG_FS
26670ca7ba2SAndy Shevchenko	help
26770ca7ba2SAndy Shevchenko	  Provides /sys/kernel/debug/dma_map_benchmark that helps with testing
26870ca7ba2SAndy Shevchenko	  performance of dma_(un)map_page.
26970ca7ba2SAndy Shevchenko
27070ca7ba2SAndy Shevchenko	  See tools/testing/selftests/dma/dma_map_benchmark.c
27170ca7ba2SAndy Shevchenko