1# SPDX-License-Identifier: GPL-2.0-only
2# The IOVA library may also be used by non-IOMMU_API users
3config IOMMU_IOVA
4	tristate
5
6# IOMMU_API always gets selected by whoever wants it.
7config IOMMU_API
8	bool
9
10config IOMMUFD_DRIVER
11	bool
12	default n
13
14menuconfig IOMMU_SUPPORT
15	bool "IOMMU Hardware Support"
16	depends on MMU
17	default y
18	help
19	  Say Y here if you want to compile device drivers for IO Memory
20	  Management Units into the kernel. These devices usually allow to
21	  remap DMA requests and/or remap interrupts from other devices on the
22	  system.
23
24if IOMMU_SUPPORT
25
26menu "Generic IOMMU Pagetable Support"
27
28# Selected by the actual pagetable implementations
29config IOMMU_IO_PGTABLE
30	bool
31
32config IOMMU_IO_PGTABLE_LPAE
33	bool "ARMv7/v8 Long Descriptor Format"
34	select IOMMU_IO_PGTABLE
35	depends on ARM || ARM64 || COMPILE_TEST
36	depends on !GENERIC_ATOMIC64	# for cmpxchg64()
37	help
38	  Enable support for the ARM long descriptor pagetable format.
39	  This allocator supports 4K/2M/1G, 16K/32M and 64K/512M page
40	  sizes at both stage-1 and stage-2, as well as address spaces
41	  up to 48-bits in size.
42
43config IOMMU_IO_PGTABLE_LPAE_SELFTEST
44	bool "LPAE selftests"
45	depends on IOMMU_IO_PGTABLE_LPAE
46	help
47	  Enable self-tests for LPAE page table allocator. This performs
48	  a series of page-table consistency checks during boot.
49
50	  If unsure, say N here.
51
52config IOMMU_IO_PGTABLE_ARMV7S
53	bool "ARMv7/v8 Short Descriptor Format"
54	select IOMMU_IO_PGTABLE
55	depends on ARM || ARM64 || COMPILE_TEST
56	help
57	  Enable support for the ARM Short-descriptor pagetable format.
58	  This supports 32-bit virtual and physical addresses mapped using
59	  2-level tables with 4KB pages/1MB sections, and contiguous entries
60	  for 64KB pages/16MB supersections if indicated by the IOMMU driver.
61
62config IOMMU_IO_PGTABLE_ARMV7S_SELFTEST
63	bool "ARMv7s selftests"
64	depends on IOMMU_IO_PGTABLE_ARMV7S
65	help
66	  Enable self-tests for ARMv7s page table allocator. This performs
67	  a series of page-table consistency checks during boot.
68
69	  If unsure, say N here.
70
71config IOMMU_IO_PGTABLE_DART
72	bool "Apple DART Formats"
73	select IOMMU_IO_PGTABLE
74	depends on ARM64 || COMPILE_TEST
75	depends on !GENERIC_ATOMIC64	# for cmpxchg64()
76	help
77	  Enable support for the Apple DART pagetable formats. These include
78	  the t8020 and t6000/t8110 DART formats used in Apple M1/M2 family
79	  SoCs.
80
81	  If unsure, say N here.
82
83endmenu
84
85config IOMMU_DEBUGFS
86	bool "Export IOMMU internals in DebugFS"
87	depends on DEBUG_FS
88	help
89	  Allows exposure of IOMMU device internals. This option enables
90	  the use of debugfs by IOMMU drivers as required. Devices can,
91	  at initialization time, cause the IOMMU code to create a top-level
92	  debug/iommu directory, and then populate a subdirectory with
93	  entries as required.
94
95choice
96	prompt "IOMMU default domain type"
97	depends on IOMMU_API
98	default IOMMU_DEFAULT_DMA_LAZY if X86 || S390
99	default IOMMU_DEFAULT_DMA_STRICT
100	help
101	  Choose the type of IOMMU domain used to manage DMA API usage by
102	  device drivers. The options here typically represent different
103	  levels of tradeoff between robustness/security and performance,
104	  depending on the IOMMU driver. Not all IOMMUs support all options.
105	  This choice can be overridden at boot via the command line, and for
106	  some devices also at runtime via sysfs.
107
108	  If unsure, keep the default.
109
110config IOMMU_DEFAULT_DMA_STRICT
111	bool "Translated - Strict"
112	help
113	  Trusted devices use translation to restrict their access to only
114	  DMA-mapped pages, with strict TLB invalidation on unmap. Equivalent
115	  to passing "iommu.passthrough=0 iommu.strict=1" on the command line.
116
117	  Untrusted devices always use this mode, with an additional layer of
118	  bounce-buffering such that they cannot gain access to any unrelated
119	  data within a mapped page.
120
121config IOMMU_DEFAULT_DMA_LAZY
122	bool "Translated - Lazy"
123	help
124	  Trusted devices use translation to restrict their access to only
125	  DMA-mapped pages, but with "lazy" batched TLB invalidation. This
126	  mode allows higher performance with some IOMMUs due to reduced TLB
127	  flushing, but at the cost of reduced isolation since devices may be
128	  able to access memory for some time after it has been unmapped.
129	  Equivalent to passing "iommu.passthrough=0 iommu.strict=0" on the
130	  command line.
131
132	  If this mode is not supported by the IOMMU driver, the effective
133	  runtime default will fall back to IOMMU_DEFAULT_DMA_STRICT.
134
135config IOMMU_DEFAULT_PASSTHROUGH
136	bool "Passthrough"
137	help
138	  Trusted devices are identity-mapped, giving them unrestricted access
139	  to memory with minimal performance overhead. Equivalent to passing
140	  "iommu.passthrough=1" (historically "iommu=pt") on the command line.
141
142	  If this mode is not supported by the IOMMU driver, the effective
143	  runtime default will fall back to IOMMU_DEFAULT_DMA_STRICT.
144
145endchoice
146
147config OF_IOMMU
148	def_bool y
149	depends on OF && IOMMU_API
150
151# IOMMU-agnostic DMA-mapping layer
152config IOMMU_DMA
153	def_bool ARM64 || X86 || S390
154	select DMA_OPS_HELPERS
155	select IOMMU_API
156	select IOMMU_IOVA
157	select IRQ_MSI_IOMMU
158	select NEED_SG_DMA_LENGTH
159	select NEED_SG_DMA_FLAGS if SWIOTLB
160
161# Shared Virtual Addressing
162config IOMMU_SVA
163	select IOMMU_MM_DATA
164	bool
165
166config IOMMU_IOPF
167	bool
168
169config FSL_PAMU
170	bool "Freescale IOMMU support"
171	depends on PCI
172	depends on PHYS_64BIT
173	depends on PPC_E500MC || (COMPILE_TEST && PPC)
174	select IOMMU_API
175	select GENERIC_ALLOCATOR
176	help
177	  Freescale PAMU support. PAMU is the IOMMU present on Freescale QorIQ platforms.
178	  PAMU can authorize memory access, remap the memory address, and remap I/O
179	  transaction types.
180
181# MSM IOMMU support
182config MSM_IOMMU
183	bool "MSM IOMMU Support"
184	depends on ARM
185	depends on ARCH_QCOM || COMPILE_TEST
186	select IOMMU_API
187	select IOMMU_IO_PGTABLE_ARMV7S
188	help
189	  Support for the IOMMUs found on certain Qualcomm SOCs.
190	  These IOMMUs allow virtualization of the address space used by most
191	  cores within the multimedia subsystem.
192
193	  If unsure, say N here.
194
195source "drivers/iommu/amd/Kconfig"
196source "drivers/iommu/intel/Kconfig"
197source "drivers/iommu/iommufd/Kconfig"
198source "drivers/iommu/riscv/Kconfig"
199
200config IRQ_REMAP
201	bool "Support for Interrupt Remapping"
202	depends on X86_64 && X86_IO_APIC && PCI_MSI && ACPI
203	select DMAR_TABLE if INTEL_IOMMU
204	help
205	  Supports Interrupt remapping for IO-APIC and MSI devices.
206	  To use x2apic mode in the CPU's which support x2APIC enhancements or
207	  to support platforms with CPU's having > 8 bit APIC ID, say Y.
208
209# OMAP IOMMU support
210config OMAP_IOMMU
211	bool "OMAP IOMMU Support"
212	depends on ARCH_OMAP2PLUS || COMPILE_TEST
213	select IOMMU_API
214	help
215	  The OMAP3 media platform drivers depend on iommu support,
216	  if you need them say Y here.
217
218config OMAP_IOMMU_DEBUG
219	bool "Export OMAP IOMMU internals in DebugFS"
220	depends on OMAP_IOMMU && DEBUG_FS
221	help
222	  Select this to see extensive information about
223	  the internal state of OMAP IOMMU in debugfs.
224
225	  Say N unless you know you need this.
226
227config ROCKCHIP_IOMMU
228	bool "Rockchip IOMMU Support"
229	depends on ARCH_ROCKCHIP || COMPILE_TEST
230	select IOMMU_API
231	select ARM_DMA_USE_IOMMU
232	help
233	  Support for IOMMUs found on Rockchip rk32xx SOCs.
234	  These IOMMUs allow virtualization of the address space used by most
235	  cores within the multimedia subsystem.
236	  Say Y here if you are using a Rockchip SoC that includes an IOMMU
237	  device.
238
239config SUN50I_IOMMU
240	bool "Allwinner H6 IOMMU Support"
241	depends on HAS_DMA
242	depends on ARCH_SUNXI || COMPILE_TEST
243	select ARM_DMA_USE_IOMMU
244	select IOMMU_API
245	help
246	  Support for the IOMMU introduced in the Allwinner H6 SoCs.
247
248config TEGRA_IOMMU_SMMU
249	bool "NVIDIA Tegra SMMU Support"
250	depends on ARCH_TEGRA
251	depends on TEGRA_AHB
252	depends on TEGRA_MC
253	select IOMMU_API
254	help
255	  This driver supports the IOMMU hardware (SMMU) found on NVIDIA Tegra
256	  SoCs (Tegra30 up to Tegra210).
257
258config EXYNOS_IOMMU
259	bool "Exynos IOMMU Support"
260	depends on ARCH_EXYNOS || COMPILE_TEST
261	depends on !CPU_BIG_ENDIAN # revisit driver if we can enable big-endian ptes
262	select IOMMU_API
263	select ARM_DMA_USE_IOMMU
264	help
265	  Support for the IOMMU (System MMU) of Samsung Exynos application
266	  processor family. This enables H/W multimedia accelerators to see
267	  non-linear physical memory chunks as linear memory in their
268	  address space.
269
270	  If unsure, say N here.
271
272config EXYNOS_IOMMU_DEBUG
273	bool "Debugging log for Exynos IOMMU"
274	depends on EXYNOS_IOMMU
275	help
276	  Select this to see the detailed log message that shows what
277	  happens in the IOMMU driver.
278
279	  Say N unless you need kernel log message for IOMMU debugging.
280
281config IPMMU_VMSA
282	bool "Renesas VMSA-compatible IPMMU"
283	depends on ARCH_RENESAS || COMPILE_TEST
284	depends on ARM || ARM64 || COMPILE_TEST
285	depends on !GENERIC_ATOMIC64	# for IOMMU_IO_PGTABLE_LPAE
286	select IOMMU_API
287	select IOMMU_IO_PGTABLE_LPAE
288	select ARM_DMA_USE_IOMMU
289	help
290	  Support for the Renesas VMSA-compatible IPMMU found in the R-Mobile
291	  APE6, R-Car Gen{2,3} and RZ/G{1,2} SoCs.
292
293	  If unsure, say N.
294
295config SPAPR_TCE_IOMMU
296	bool "sPAPR TCE IOMMU Support"
297	depends on PPC_POWERNV || PPC_PSERIES
298	select IOMMU_API
299	help
300	  Enables bits of IOMMU API required by VFIO. The iommu_ops
301	  is not implemented as it is not necessary for VFIO.
302
303config APPLE_DART
304	tristate "Apple DART IOMMU Support"
305	depends on ARCH_APPLE || COMPILE_TEST
306	depends on !GENERIC_ATOMIC64	# for IOMMU_IO_PGTABLE_DART
307	select IOMMU_API
308	select IOMMU_IO_PGTABLE_DART
309	default ARCH_APPLE
310	help
311	  Support for Apple DART (Device Address Resolution Table) IOMMUs
312	  found in Apple ARM SoCs like the M1.
313	  This IOMMU is required for most peripherals using DMA to access
314	  the main memory.
315
316	  Say Y here if you are using an Apple SoC.
317
318# ARM IOMMU support
319config ARM_SMMU
320	tristate "ARM Ltd. System MMU (SMMU) Support"
321	depends on ARM64 || ARM || COMPILE_TEST
322	depends on !GENERIC_ATOMIC64	# for IOMMU_IO_PGTABLE_LPAE
323	select IOMMU_API
324	select IOMMU_IO_PGTABLE_LPAE
325	select ARM_DMA_USE_IOMMU if ARM
326	help
327	  Support for implementations of the ARM System MMU architecture
328	  versions 1 and 2.
329
330	  Say Y here if your SoC includes an IOMMU device implementing
331	  the ARM SMMU architecture.
332
333config ARM_SMMU_LEGACY_DT_BINDINGS
334	bool "Support the legacy \"mmu-masters\" devicetree bindings"
335	depends on ARM_SMMU=y && OF
336	help
337	  Support for the badly designed and deprecated "mmu-masters"
338	  devicetree bindings. This allows some DMA masters to attach
339	  to the SMMU but does not provide any support via the DMA API.
340	  If you're lucky, you might be able to get VFIO up and running.
341
342	  If you say Y here then you'll make me very sad. Instead, say N
343	  and move your firmware to the utopian future that was 2016.
344
345config ARM_SMMU_DISABLE_BYPASS_BY_DEFAULT
346	bool "Default to disabling bypass on ARM SMMU v1 and v2"
347	depends on ARM_SMMU
348	default y
349	help
350	  Say Y here to (by default) disable bypass streams such that
351	  incoming transactions from devices that are not attached to
352	  an iommu domain will report an abort back to the device and
353	  will not be allowed to pass through the SMMU.
354
355	  Any old kernels that existed before this KConfig was
356	  introduced would default to _allowing_ bypass (AKA the
357	  equivalent of NO for this config).  However the default for
358	  this option is YES because the old behavior is insecure.
359
360	  There are few reasons to allow unmatched stream bypass, and
361	  even fewer good ones.  If saying YES here breaks your board
362	  you should work on fixing your board.  This KConfig option
363	  is expected to be removed in the future and we'll simply
364	  hardcode the bypass disable in the code.
365
366	  NOTE: the kernel command line parameter
367	  'arm-smmu.disable_bypass' will continue to override this
368	  config.
369
370config ARM_SMMU_MMU_500_CPRE_ERRATA
371	bool "Enable errata workaround for CPRE in SMMU reset path"
372	depends on ARM_SMMU
373	default y
374	help
375	  Say Y here (by default) to apply workaround to disable
376	  MMU-500's next-page prefetcher for sake of 4 known errata.
377
378	  Say N here only when it is sure that any errata related to
379	  prefetch enablement are not applicable on the platform.
380	  Refer silicon-errata.rst for info on errata IDs.
381
382config ARM_SMMU_QCOM
383	def_tristate y
384	depends on ARM_SMMU && ARCH_QCOM
385	select QCOM_SCM
386	help
387	  When running on a Qualcomm platform that has the custom variant
388	  of the ARM SMMU, this needs to be built into the SMMU driver.
389
390config ARM_SMMU_QCOM_DEBUG
391	bool "ARM SMMU QCOM implementation defined debug support"
392	depends on ARM_SMMU_QCOM=y
393	help
394	  Support for implementation specific debug features in ARM SMMU
395	  hardware found in QTI platforms. This include support for
396	  the Translation Buffer Units (TBU) that can be used to obtain
397	  additional information when debugging memory management issues
398	  like context faults.
399
400	  Say Y here to enable debug for issues such as context faults
401	  or TLB sync timeouts which requires implementation defined
402	  register dumps.
403
404config ARM_SMMU_V3
405	tristate "ARM Ltd. System MMU Version 3 (SMMUv3) Support"
406	depends on ARM64
407	select IOMMU_API
408	select IOMMU_IO_PGTABLE_LPAE
409	select GENERIC_MSI_IRQ
410	select IOMMUFD_DRIVER if IOMMUFD
411	help
412	  Support for implementations of the ARM System MMU architecture
413	  version 3 providing translation support to a PCIe root complex.
414
415	  Say Y here if your system includes an IOMMU device implementing
416	  the ARM SMMUv3 architecture.
417
418if ARM_SMMU_V3
419config ARM_SMMU_V3_SVA
420	bool "Shared Virtual Addressing support for the ARM SMMUv3"
421	select IOMMU_SVA
422	select IOMMU_IOPF
423	select MMU_NOTIFIER
424	help
425	  Support for sharing process address spaces with devices using the
426	  SMMUv3.
427
428	  Say Y here if your system supports SVA extensions such as PCIe PASID
429	  and PRI.
430
431config ARM_SMMU_V3_IOMMUFD
432	bool "Enable IOMMUFD features for ARM SMMUv3 (EXPERIMENTAL)"
433	depends on IOMMUFD
434	help
435	  Support for IOMMUFD features intended to support virtual machines
436	  with accelerated virtual IOMMUs.
437
438	  Say Y here if you are doing development and testing on this feature.
439
440config ARM_SMMU_V3_KUNIT_TEST
441	tristate "KUnit tests for arm-smmu-v3 driver"  if !KUNIT_ALL_TESTS
442	depends on KUNIT
443	depends on ARM_SMMU_V3_SVA
444	default KUNIT_ALL_TESTS
445	help
446	  Enable this option to unit-test arm-smmu-v3 driver functions.
447
448	  If unsure, say N.
449
450config TEGRA241_CMDQV
451	bool "NVIDIA Tegra241 CMDQ-V extension support for ARM SMMUv3"
452	depends on ACPI
453	help
454	  Support for NVIDIA CMDQ-Virtualization extension for ARM SMMUv3. The
455	  CMDQ-V extension is similar to v3.3 ECMDQ for multi command queues
456	  support, except with virtualization capabilities.
457
458	  Say Y here if your system is NVIDIA Tegra241 (Grace) or it has the same
459	  CMDQ-V extension.
460endif
461
462config S390_IOMMU
463	def_bool y if S390 && PCI
464	depends on S390 && PCI
465	select IOMMU_API
466	help
467	  Support for the IOMMU API for s390 PCI devices.
468
469config MTK_IOMMU
470	tristate "MediaTek IOMMU Support"
471	depends on ARCH_MEDIATEK || COMPILE_TEST
472	select ARM_DMA_USE_IOMMU
473	select IOMMU_API
474	select IOMMU_IO_PGTABLE_ARMV7S
475	select MEMORY
476	select MTK_SMI
477	help
478	  Support for the M4U on certain Mediatek SOCs. M4U is MultiMedia
479	  Memory Management Unit. This option enables remapping of DMA memory
480	  accesses for the multimedia subsystem.
481
482	  If unsure, say N here.
483
484config MTK_IOMMU_V1
485	tristate "MediaTek IOMMU Version 1 (M4U gen1) Support"
486	depends on ARM
487	depends on ARCH_MEDIATEK || COMPILE_TEST
488	select ARM_DMA_USE_IOMMU
489	select IOMMU_API
490	select MEMORY
491	select MTK_SMI
492	help
493	  Support for the M4U on certain Mediatek SoCs. M4U generation 1 HW is
494	  Multimedia Memory Managememt Unit. This option enables remapping of
495	  DMA memory accesses for the multimedia subsystem.
496
497	  if unsure, say N here.
498
499config QCOM_IOMMU
500	# Note: iommu drivers cannot (yet?) be built as modules
501	bool "Qualcomm IOMMU Support"
502	depends on ARCH_QCOM || COMPILE_TEST
503	depends on !GENERIC_ATOMIC64	# for IOMMU_IO_PGTABLE_LPAE
504	select QCOM_SCM
505	select IOMMU_API
506	select IOMMU_IO_PGTABLE_LPAE
507	select ARM_DMA_USE_IOMMU
508	help
509	  Support for IOMMU on certain Qualcomm SoCs.
510
511config HYPERV_IOMMU
512	bool "Hyper-V IRQ Handling"
513	depends on HYPERV && X86
514	select IOMMU_API
515	default HYPERV
516	help
517	  Stub IOMMU driver to handle IRQs to support Hyper-V Linux
518	  guest and root partitions.
519
520config VIRTIO_IOMMU
521	tristate "Virtio IOMMU driver"
522	depends on VIRTIO
523	depends on (ARM64 || X86)
524	select IOMMU_API
525	select INTERVAL_TREE
526	select ACPI_VIOT if ACPI
527	help
528	  Para-virtualised IOMMU driver with virtio.
529
530	  Say Y here if you intend to run this kernel as a guest.
531
532config SPRD_IOMMU
533	tristate "Unisoc IOMMU Support"
534	depends on ARCH_SPRD || COMPILE_TEST
535	select IOMMU_API
536	help
537	  Support for IOMMU on Unisoc's SoCs, this IOMMU can be used by
538	  Unisoc's multimedia devices, such as display, Image codec(jpeg)
539	  and a few signal processors, including VSP(video), GSP(graphic),
540	  ISP(image), and CPP(camera pixel processor), etc.
541
542	  Say Y here if you want to use the multimedia devices listed above.
543
544endif # IOMMU_SUPPORT
545