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