xref: /linux/kernel/dma/Kconfig (revision d5cae2261b86913e602452ce4a07e6aefc0f603b)
1# SPDX-License-Identifier: GPL-2.0-only
2
3config NO_DMA
4	bool
5
6config HAS_DMA
7	bool
8	depends on !NO_DMA
9	default y
10
11config DMA_OPS_HELPERS
12	bool
13
14#
15# IOMMU drivers that can bypass the IOMMU code and optionally use the direct
16# mapping fast path should select this option and set the dma_ops_bypass
17# flag in struct device where applicable
18#
19config DMA_OPS_BYPASS
20	bool
21
22# Lets platform IOMMU driver choose between bypass and IOMMU
23config ARCH_HAS_DMA_MAP_DIRECT
24	bool
25
26config NEED_SG_DMA_FLAGS
27	bool
28
29config NEED_SG_DMA_LENGTH
30	bool
31
32config NEED_DMA_MAP_STATE
33	bool
34
35config ARCH_DMA_ADDR_T_64BIT
36	def_bool 64BIT || PHYS_ADDR_T_64BIT
37
38config ARCH_HAS_DMA_SET_MASK
39	bool
40
41#
42# Select this option if the architecture needs special handling for
43# DMA_ATTR_WRITE_COMBINE.  Normally the "uncached" mapping should be what
44# people think of when saying write combine, so very few platforms should
45# need to enable this.
46#
47config ARCH_HAS_DMA_WRITE_COMBINE
48	bool
49
50config DMA_DECLARE_COHERENT
51	bool
52
53config ARCH_HAS_SETUP_DMA_OPS
54	bool
55
56config ARCH_HAS_TEARDOWN_DMA_OPS
57	bool
58
59config ARCH_HAS_SYNC_DMA_FOR_DEVICE
60	bool
61
62config ARCH_HAS_SYNC_DMA_FOR_CPU
63	bool
64	select NEED_DMA_MAP_STATE
65
66config ARCH_HAS_SYNC_DMA_FOR_CPU_ALL
67	bool
68
69config ARCH_HAS_DMA_PREP_COHERENT
70	bool
71
72config ARCH_HAS_FORCE_DMA_UNENCRYPTED
73	bool
74
75config ARCH_HAS_BATCHED_DMA_SYNC
76	bool
77
78#
79# Select this option if the architecture assumes DMA devices are coherent
80# by default.
81#
82config ARCH_DMA_DEFAULT_COHERENT
83	bool
84
85config SWIOTLB
86	bool
87	select NEED_DMA_MAP_STATE
88
89config SWIOTLB_DYNAMIC
90	bool "Dynamic allocation of DMA bounce buffers"
91	default n
92	depends on SWIOTLB
93	help
94	  This enables dynamic resizing of the software IO TLB. The kernel
95	  starts with one memory pool at boot and it will allocate additional
96	  pools as needed. To reduce run-time kernel memory requirements, you
97	  may have to specify a smaller size of the initial pool using
98	  "swiotlb=" on the kernel command line.
99
100	  If unsure, say N.
101
102config DMA_BOUNCE_UNALIGNED_KMALLOC
103	bool
104	depends on SWIOTLB
105
106config DMA_NEED_SYNC
107	def_bool ARCH_HAS_SYNC_DMA_FOR_DEVICE || ARCH_HAS_SYNC_DMA_FOR_CPU || \
108		 ARCH_HAS_SYNC_DMA_FOR_CPU_ALL || DMA_API_DEBUG || \
109		 ARCH_HAS_DMA_OPS || SWIOTLB
110
111config DMA_RESTRICTED_POOL
112	bool "DMA Restricted Pool"
113	depends on OF && OF_RESERVED_MEM && SWIOTLB
114	help
115	  This enables support for restricted DMA pools which provide a level of
116	  DMA memory protection on systems with limited hardware protection
117	  capabilities, such as those lacking an IOMMU.
118
119	  For more information see
120	  <Documentation/devicetree/bindings/reserved-memory/reserved-memory.txt>
121	  and <kernel/dma/swiotlb.c>.
122	  If unsure, say "n".
123
124#
125# Should be selected if we can mmap non-coherent mappings to userspace.
126# The only thing that is really required is a way to set an uncached bit
127# in the pagetables
128#
129config DMA_NONCOHERENT_MMAP
130	default y if !MMU
131	bool
132
133config DMA_COHERENT_POOL
134	select GENERIC_ALLOCATOR
135	bool
136
137config DMA_GLOBAL_POOL
138	select DMA_DECLARE_COHERENT
139	depends on !ARCH_HAS_DMA_SET_UNCACHED
140	depends on !DMA_DIRECT_REMAP
141	bool
142
143config DMA_DIRECT_REMAP
144	bool
145	select DMA_COHERENT_POOL
146	select DMA_NONCOHERENT_MMAP
147
148#
149# Fallback to arch code for DMA allocations.  This should eventually go away.
150#
151config ARCH_HAS_DMA_ALLOC
152	depends on !ARCH_HAS_DMA_SET_UNCACHED
153	depends on !DMA_DIRECT_REMAP
154	depends on !DMA_GLOBAL_POOL
155	bool
156
157config DMA_CMA
158	bool "DMA Contiguous Memory Allocator"
159	depends on HAVE_DMA_CONTIGUOUS && CMA
160	help
161	  This enables the Contiguous Memory Allocator which allows drivers
162	  to allocate big physically-contiguous blocks of memory for use with
163	  hardware components that do not support I/O map nor scatter-gather.
164
165	  You can disable CMA by specifying "cma=0" on the kernel's command
166	  line.
167
168	  For more information see <kernel/dma/contiguous.c>.
169	  If unsure, say "n".
170
171if  DMA_CMA
172
173config DMA_NUMA_CMA
174	bool "Enable separate DMA Contiguous Memory Area for NUMA Node"
175	depends on NUMA
176	help
177	  Enable this option to get numa CMA areas so that NUMA devices
178	  can get local memory by DMA coherent APIs.
179
180	  You can set the size of pernuma CMA by specifying "cma_pernuma=size"
181	  or set the node id and its size of CMA by specifying "numa_cma=
182	  <node>:size[,<node>:size]" on the kernel's command line. And in
183	  rare case that the above 2 are both setup, then the "numa_cma="
184	  takes priority for the specified numa nodes.
185
186config CMA_SIZE_PERNUMA
187	bool "Default CMA area per NUMA node"
188	depends on DMA_NUMA_CMA
189	default y
190	help
191	  On systems with more than one NUMA node, the selected CMA
192	  area size will be also allocated on each additional node,
193	  so that most devices may have benefit from better DMA
194	  locality without an explicit command-line opt-in.
195
196comment "Default contiguous memory area size:"
197
198config CMA_SIZE_MBYTES
199	int "Size in Mega Bytes"
200	depends on !CMA_SIZE_SEL_PERCENTAGE
201	default 0 if X86
202	default 16
203	help
204	  Defines the size (in MiB) of the default memory area for Contiguous
205	  Memory Allocator.  If the size of 0 is selected, CMA is disabled by
206	  default, but it can be enabled by passing cma=size[MG] to the kernel.
207
208
209config CMA_SIZE_PERCENTAGE
210	int "Percentage of total memory"
211	depends on !CMA_SIZE_SEL_MBYTES
212	default 0 if X86
213	default 10
214	help
215	  Defines the size of the default memory area for Contiguous Memory
216	  Allocator as a percentage of the total memory in the system.
217	  If 0 percent is selected, CMA is disabled by default, but it can be
218	  enabled by passing cma=size[MG] to the kernel.
219
220choice
221	prompt "Selected region size"
222	default CMA_SIZE_SEL_MBYTES
223
224config CMA_SIZE_SEL_MBYTES
225	bool "Use mega bytes value only"
226
227config CMA_SIZE_SEL_PERCENTAGE
228	bool "Use percentage value only"
229
230config CMA_SIZE_SEL_MIN
231	bool "Use lower value (minimum)"
232
233config CMA_SIZE_SEL_MAX
234	bool "Use higher value (maximum)"
235
236endchoice
237
238config CMA_ALIGNMENT
239	int "Maximum PAGE_SIZE order of alignment for contiguous buffers"
240	range 2 12
241	default 8
242	help
243	  DMA mapping framework by default aligns all buffers to the smallest
244	  PAGE_SIZE order which is greater than or equal to the requested buffer
245	  size. This works well for buffers up to a few hundreds kilobytes, but
246	  for larger buffers it just a memory waste. With this parameter you can
247	  specify the maximum PAGE_SIZE order for contiguous buffers. Larger
248	  buffers will be aligned only to this specified order. The order is
249	  expressed as a power of two multiplied by the PAGE_SIZE.
250
251	  For example, if your system defaults to 4KiB pages, the order value
252	  of 8 means that the buffers will be aligned up to 1MiB only.
253
254	  If unsure, leave the default value "8".
255
256endif
257
258config DMA_API_DEBUG
259	bool "Enable debugging of DMA-API usage"
260	select NEED_DMA_MAP_STATE
261	help
262	  Enable this option to debug the use of the DMA API by device drivers.
263	  With this option you will be able to detect common bugs in device
264	  drivers like double-freeing of DMA mappings or freeing mappings that
265	  were never allocated.
266
267	  This option causes a performance degradation.  Use only if you want to
268	  debug device drivers and dma interactions.
269
270	  If unsure, say N.
271
272config DMA_MAP_BENCHMARK
273	bool "Enable benchmarking of streaming DMA mapping"
274	depends on DEBUG_FS
275	help
276	  Provides /sys/kernel/debug/dma_map_benchmark that helps with testing
277	  performance of dma_(un)map_page.
278
279	  See tools/testing/selftests/dma/dma_map_benchmark.c
280