Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge tag 'iommu-updates-v5.9' of git://git.kernel.org/pub/scm/linux/kernel/git/joro/iommu

Pull iommu updates from Joerg Roedel:

- Remove of the dev->archdata.iommu (or similar) pointers from most
architectures. Only Sparc is left, but this is private to Sparc as
their drivers don't use the IOMMU-API.

- ARM-SMMU updates from Will Deacon:

- Support for SMMU-500 implementation in Marvell Armada-AP806 SoC

- Support for SMMU-500 implementation in NVIDIA Tegra194 SoC

- DT compatible string updates

- Remove unused IOMMU_SYS_CACHE_ONLY flag

- Move ARM-SMMU drivers into their own subdirectory

- Intel VT-d updates from Lu Baolu:

- Misc tweaks and fixes for vSVA

- Report/response page request events

- Cleanups

- Move the Kconfig and Makefile bits for the AMD and Intel drivers into
their respective subdirectory.

- MT6779 IOMMU Support

- Support for new chipsets in the Renesas IOMMU driver

- Other misc cleanups and fixes (e.g. to improve compile test coverage)

* tag 'iommu-updates-v5.9' of git://git.kernel.org/pub/scm/linux/kernel/git/joro/iommu: (77 commits)
iommu/amd: Move Kconfig and Makefile bits down into amd directory
iommu/vt-d: Move Kconfig and Makefile bits down into intel directory
iommu/arm-smmu: Move Arm SMMU drivers into their own subdirectory
iommu/vt-d: Skip TE disabling on quirky gfx dedicated iommu
iommu: Add gfp parameter to io_pgtable_ops->map()
iommu: Mark __iommu_map_sg() as static
iommu/vt-d: Rename intel-pasid.h to pasid.h
iommu/vt-d: Add page response ops support
iommu/vt-d: Report page request faults for guest SVA
iommu/vt-d: Add a helper to get svm and sdev for pasid
iommu/vt-d: Refactor device_to_iommu() helper
iommu/vt-d: Disable multiple GPASID-dev bind
iommu/vt-d: Warn on out-of-range invalidation address
iommu/vt-d: Fix devTLB flush for vSVA
iommu/vt-d: Handle non-page aligned address
iommu/vt-d: Fix PASID devTLB invalidation
iommu/vt-d: Remove global page support in devTLB flush
iommu/vt-d: Enforce PASID devTLB field mask
iommu: Make some functions static
iommu/amd: Remove double zero check
...

+1469 -575
+3
Documentation/arm64/silicon-errata.rst
··· 125 125 | Cavium | ThunderX2 Core | #219 | CAVIUM_TX2_ERRATUM_219 | 126 126 +----------------+-----------------+-----------------+-----------------------------+ 127 127 +----------------+-----------------+-----------------+-----------------------------+ 128 + | Marvell | ARM-MMU-500 | #582743 | N/A | 129 + +----------------+-----------------+-----------------+-----------------------------+ 130 + +----------------+-----------------+-----------------+-----------------------------+ 128 131 | Freescale/NXP | LS2080A/LS1043A | A-008585 | FSL_ERRATUM_A008585 | 129 132 +----------------+-----------------+-----------------+-----------------------------+ 130 133 +----------------+-----------------+-----------------+-----------------------------+
+30 -1
Documentation/devicetree/bindings/iommu/arm,smmu.yaml
··· 37 37 - enum: 38 38 - qcom,sc7180-smmu-500 39 39 - qcom,sdm845-smmu-500 40 + - qcom,sm8150-smmu-500 41 + - qcom,sm8250-smmu-500 40 42 - const: arm,mmu-500 43 + - description: Marvell SoCs implementing "arm,mmu-500" 44 + items: 45 + - const: marvell,ap806-smmu-500 46 + - const: arm,mmu-500 47 + - description: NVIDIA SoCs that program two ARM MMU-500s identically 48 + items: 49 + - enum: 50 + - nvidia,tegra194-smmu 51 + - const: nvidia,smmu-500 41 52 - items: 42 53 - const: arm,mmu-500 43 54 - const: arm,smmu-v2 ··· 66 55 - cavium,smmu-v2 67 56 68 57 reg: 69 - maxItems: 1 58 + minItems: 1 59 + maxItems: 2 70 60 71 61 '#global-interrupts': 72 62 description: The number of global interrupts exposed by the device. ··· 149 137 - interrupts 150 138 151 139 additionalProperties: false 140 + 141 + allOf: 142 + - if: 143 + properties: 144 + compatible: 145 + contains: 146 + enum: 147 + - nvidia,tegra194-smmu 148 + then: 149 + properties: 150 + reg: 151 + minItems: 2 152 + maxItems: 2 153 + else: 154 + properties: 155 + reg: 156 + maxItems: 1 152 157 153 158 examples: 154 159 - |+
+2
Documentation/devicetree/bindings/iommu/mediatek,iommu.txt
··· 58 58 - compatible : must be one of the following string: 59 59 "mediatek,mt2701-m4u" for mt2701 which uses generation one m4u HW. 60 60 "mediatek,mt2712-m4u" for mt2712 which uses generation two m4u HW. 61 + "mediatek,mt6779-m4u" for mt6779 which uses generation two m4u HW. 61 62 "mediatek,mt7623-m4u", "mediatek,mt2701-m4u" for mt7623 which uses 62 63 generation one m4u HW. 63 64 "mediatek,mt8173-m4u" for mt8173 which uses generation two m4u HW. ··· 79 78 Specifies the mtk_m4u_id as defined in 80 79 dt-binding/memory/mt2701-larb-port.h for mt2701, mt7623 81 80 dt-binding/memory/mt2712-larb-port.h for mt2712, 81 + dt-binding/memory/mt6779-larb-port.h for mt6779, 82 82 dt-binding/memory/mt8173-larb-port.h for mt8173, and 83 83 dt-binding/memory/mt8183-larb-port.h for mt8183. 84 84
+1
Documentation/devicetree/bindings/iommu/renesas,ipmmu-vmsa.yaml
··· 36 36 - renesas,ipmmu-r8a774c0 # RZ/G2E 37 37 - renesas,ipmmu-r8a7795 # R-Car H3 38 38 - renesas,ipmmu-r8a7796 # R-Car M3-W 39 + - renesas,ipmmu-r8a77961 # R-Car M3-W+ 39 40 - renesas,ipmmu-r8a77965 # R-Car M3-N 40 41 - renesas,ipmmu-r8a77970 # R-Car V3M 41 42 - renesas,ipmmu-r8a77980 # R-Car V3H
+3 -2
Documentation/devicetree/bindings/memory-controllers/mediatek,smi-common.txt
··· 5 5 Mediatek SMI have two generations of HW architecture, here is the list 6 6 which generation the SoCs use: 7 7 generation 1: mt2701 and mt7623. 8 - generation 2: mt2712, mt8173 and mt8183. 8 + generation 2: mt2712, mt6779, mt8173 and mt8183. 9 9 10 10 There's slight differences between the two SMI, for generation 2, the 11 11 register which control the iommu port is at each larb's register base. But ··· 18 18 - compatible : must be one of : 19 19 "mediatek,mt2701-smi-common" 20 20 "mediatek,mt2712-smi-common" 21 + "mediatek,mt6779-smi-common" 21 22 "mediatek,mt7623-smi-common", "mediatek,mt2701-smi-common" 22 23 "mediatek,mt8173-smi-common" 23 24 "mediatek,mt8183-smi-common" ··· 36 35 and these 2 option clocks for generation 2 smi HW: 37 36 - "gals0": the path0 clock of GALS(Global Async Local Sync). 38 37 - "gals1": the path1 clock of GALS(Global Async Local Sync). 39 - Here is the list which has this GALS: mt8183. 38 + Here is the list which has this GALS: mt6779 and mt8183. 40 39 41 40 Example: 42 41 smi_common: smi@14022000 {
+2 -1
Documentation/devicetree/bindings/memory-controllers/mediatek,smi-larb.txt
··· 6 6 - compatible : must be one of : 7 7 "mediatek,mt2701-smi-larb" 8 8 "mediatek,mt2712-smi-larb" 9 + "mediatek,mt6779-smi-larb" 9 10 "mediatek,mt7623-smi-larb", "mediatek,mt2701-smi-larb" 10 11 "mediatek,mt8173-smi-larb" 11 12 "mediatek,mt8183-smi-larb" ··· 22 21 - "gals": the clock for GALS(Global Async Local Sync). 23 22 Here is the list which has this GALS: mt8183. 24 23 25 - Required property for mt2701, mt2712 and mt7623: 24 + Required property for mt2701, mt2712, mt6779 and mt7623: 26 25 - mediatek,larb-id :the hardware id of this larb. 27 26 28 27 Example:
+4 -1
MAINTAINERS
··· 1505 1505 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers) 1506 1506 S: Maintained 1507 1507 F: Documentation/devicetree/bindings/iommu/arm,smmu* 1508 - F: drivers/iommu/arm-smmu* 1508 + F: drivers/iommu/arm/ 1509 1509 F: drivers/iommu/io-pgtable-arm-v7s.c 1510 1510 F: drivers/iommu/io-pgtable-arm.c 1511 1511 ··· 9102 9102 F: include/linux/iommu.h 9103 9103 F: include/linux/iova.h 9104 9104 F: include/linux/of_iommu.h 9105 + F: include/uapi/linux/iommu.h 9105 9106 9106 9107 IO_URING 9107 9108 M: Jens Axboe <axboe@kernel.dk> ··· 16974 16973 16975 16974 TEGRA IOMMU DRIVERS 16976 16975 M: Thierry Reding <thierry.reding@gmail.com> 16976 + R: Krishna Reddy <vdumpa@nvidia.com> 16977 16977 L: linux-tegra@vger.kernel.org 16978 16978 S: Supported 16979 + F: drivers/iommu/arm/arm-smmu/arm-smmu-nvidia.c 16979 16980 F: drivers/iommu/tegra* 16980 16981 16981 16982 TEGRA KBC DRIVER
-3
arch/arm/include/asm/device.h
··· 9 9 #ifdef CONFIG_DMABOUNCE 10 10 struct dmabounce_device_info *dmabounce; 11 11 #endif 12 - #ifdef CONFIG_IOMMU_API 13 - void *iommu; /* private IOMMU data */ 14 - #endif 15 12 #ifdef CONFIG_ARM_DMA_USE_IOMMU 16 13 struct dma_iommu_mapping *mapping; 17 14 #endif
-3
arch/arm64/include/asm/device.h
··· 6 6 #define __ASM_DEVICE_H 7 7 8 8 struct dev_archdata { 9 - #ifdef CONFIG_IOMMU_API 10 - void *iommu; /* private IOMMU data */ 11 - #endif 12 9 }; 13 10 14 11 struct pdev_archdata {
-3
arch/ia64/include/asm/device.h
··· 6 6 #define _ASM_IA64_DEVICE_H 7 7 8 8 struct dev_archdata { 9 - #ifdef CONFIG_IOMMU_API 10 - void *iommu; /* hook for IOMMU specific extension */ 11 - #endif 12 9 }; 13 10 14 11 struct pdev_archdata {
-3
arch/powerpc/include/asm/device.h
··· 29 29 struct iommu_table *iommu_table_base; 30 30 #endif 31 31 32 - #ifdef CONFIG_IOMMU_API 33 - void *iommu_domain; 34 - #endif 35 32 #ifdef CONFIG_PPC64 36 33 struct pci_dn *pci_data; 37 34 #endif
-3
arch/x86/include/asm/device.h
··· 3 3 #define _ASM_X86_DEVICE_H 4 4 5 5 struct dev_archdata { 6 - #ifdef CONFIG_IOMMU_API 7 - void *iommu; /* hook for IOMMU specific extension */ 8 - #endif 9 6 }; 10 7 11 8 struct pdev_archdata {
+8 -2
drivers/gpu/drm/i915/selftests/mock_gem_device.c
··· 24 24 25 25 #include <linux/pm_domain.h> 26 26 #include <linux/pm_runtime.h> 27 + #include <linux/iommu.h> 27 28 28 29 #include <drm/drm_managed.h> 29 30 ··· 119 118 { 120 119 struct drm_i915_private *i915; 121 120 struct pci_dev *pdev; 121 + #if IS_ENABLED(CONFIG_IOMMU_API) && defined(CONFIG_INTEL_IOMMU) 122 + struct dev_iommu iommu; 123 + #endif 122 124 int err; 123 125 124 126 pdev = kzalloc(sizeof(*pdev), GFP_KERNEL); ··· 140 136 dma_coerce_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64)); 141 137 142 138 #if IS_ENABLED(CONFIG_IOMMU_API) && defined(CONFIG_INTEL_IOMMU) 143 - /* hack to disable iommu for the fake device; force identity mapping */ 144 - pdev->dev.archdata.iommu = (void *)-1; 139 + /* HACK HACK HACK to disable iommu for the fake device; force identity mapping */ 140 + memset(&iommu, 0, sizeof(iommu)); 141 + iommu.priv = (void *)-1; 142 + pdev->dev.iommu = &iommu; 145 143 #endif 146 144 147 145 pci_set_drvdata(pdev, i915);
+1 -1
drivers/gpu/drm/panfrost/panfrost_mmu.c
··· 262 262 while (len) { 263 263 size_t pgsize = get_pgsize(iova | paddr, len); 264 264 265 - ops->map(ops, iova, paddr, pgsize, prot); 265 + ops->map(ops, iova, paddr, pgsize, prot, GFP_KERNEL); 266 266 iova += pgsize; 267 267 paddr += pgsize; 268 268 len -= pgsize;
+4 -142
drivers/iommu/Kconfig
··· 129 129 130 130 If unsure, say N here. 131 131 132 - config IOMMU_PGTABLES_L2 133 - def_bool y 134 - depends on MSM_IOMMU && MMU && SMP && CPU_DCACHE_DISABLE=n 135 - 136 - # AMD IOMMU support 137 - config AMD_IOMMU 138 - bool "AMD IOMMU support" 139 - select SWIOTLB 140 - select PCI_MSI 141 - select PCI_ATS 142 - select PCI_PRI 143 - select PCI_PASID 144 - select IOMMU_API 145 - select IOMMU_IOVA 146 - select IOMMU_DMA 147 - depends on X86_64 && PCI && ACPI 148 - help 149 - With this option you can enable support for AMD IOMMU hardware in 150 - your system. An IOMMU is a hardware component which provides 151 - remapping of DMA memory accesses from devices. With an AMD IOMMU you 152 - can isolate the DMA memory of different devices and protect the 153 - system from misbehaving device drivers or hardware. 154 - 155 - You can find out if your system has an AMD IOMMU if you look into 156 - your BIOS for an option to enable it or if you have an IVRS ACPI 157 - table. 158 - 159 - config AMD_IOMMU_V2 160 - tristate "AMD IOMMU Version 2 driver" 161 - depends on AMD_IOMMU 162 - select MMU_NOTIFIER 163 - help 164 - This option enables support for the AMD IOMMUv2 features of the IOMMU 165 - hardware. Select this option if you want to use devices that support 166 - the PCI PRI and PASID interface. 167 - 168 - config AMD_IOMMU_DEBUGFS 169 - bool "Enable AMD IOMMU internals in DebugFS" 170 - depends on AMD_IOMMU && IOMMU_DEBUGFS 171 - help 172 - !!!WARNING!!! !!!WARNING!!! !!!WARNING!!! !!!WARNING!!! 173 - 174 - DO NOT ENABLE THIS OPTION UNLESS YOU REALLY, -REALLY- KNOW WHAT YOU ARE DOING!!! 175 - Exposes AMD IOMMU device internals in DebugFS. 176 - 177 - This option is -NOT- intended for production environments, and should 178 - not generally be enabled. 179 - 180 - # Intel IOMMU support 181 - config DMAR_TABLE 182 - bool 183 - 184 - config INTEL_IOMMU 185 - bool "Support for Intel IOMMU using DMA Remapping Devices" 186 - depends on PCI_MSI && ACPI && (X86 || IA64) 187 - select DMA_OPS 188 - select IOMMU_API 189 - select IOMMU_IOVA 190 - select NEED_DMA_MAP_STATE 191 - select DMAR_TABLE 192 - select SWIOTLB 193 - select IOASID 194 - help 195 - DMA remapping (DMAR) devices support enables independent address 196 - translations for Direct Memory Access (DMA) from devices. 197 - These DMA remapping devices are reported via ACPI tables 198 - and include PCI device scope covered by these DMA 199 - remapping devices. 200 - 201 - config INTEL_IOMMU_DEBUGFS 202 - bool "Export Intel IOMMU internals in Debugfs" 203 - depends on INTEL_IOMMU && IOMMU_DEBUGFS 204 - help 205 - !!!WARNING!!! 206 - 207 - DO NOT ENABLE THIS OPTION UNLESS YOU REALLY KNOW WHAT YOU ARE DOING!!! 208 - 209 - Expose Intel IOMMU internals in Debugfs. 210 - 211 - This option is -NOT- intended for production environments, and should 212 - only be enabled for debugging Intel IOMMU. 213 - 214 - config INTEL_IOMMU_SVM 215 - bool "Support for Shared Virtual Memory with Intel IOMMU" 216 - depends on INTEL_IOMMU && X86_64 217 - select PCI_PASID 218 - select PCI_PRI 219 - select MMU_NOTIFIER 220 - select IOASID 221 - help 222 - Shared Virtual Memory (SVM) provides a facility for devices 223 - to access DMA resources through process address space by 224 - means of a Process Address Space ID (PASID). 225 - 226 - config INTEL_IOMMU_DEFAULT_ON 227 - def_bool y 228 - prompt "Enable Intel DMA Remapping Devices by default" 229 - depends on INTEL_IOMMU 230 - help 231 - Selecting this option will enable a DMAR device at boot time if 232 - one is found. If this option is not selected, DMAR support can 233 - be enabled by passing intel_iommu=on to the kernel. 234 - 235 - config INTEL_IOMMU_BROKEN_GFX_WA 236 - bool "Workaround broken graphics drivers (going away soon)" 237 - depends on INTEL_IOMMU && BROKEN && X86 238 - help 239 - Current Graphics drivers tend to use physical address 240 - for DMA and avoid using DMA APIs. Setting this config 241 - option permits the IOMMU driver to set a unity map for 242 - all the OS-visible memory. Hence the driver can continue 243 - to use physical addresses for DMA, at least until this 244 - option is removed in the 2.6.32 kernel. 245 - 246 - config INTEL_IOMMU_FLOPPY_WA 247 - def_bool y 248 - depends on INTEL_IOMMU && X86 249 - help 250 - Floppy disk drivers are known to bypass DMA API calls 251 - thereby failing to work when IOMMU is enabled. This 252 - workaround will setup a 1:1 mapping for the first 253 - 16MiB to make floppy (an ISA device) work. 254 - 255 - config INTEL_IOMMU_SCALABLE_MODE_DEFAULT_ON 256 - bool "Enable Intel IOMMU scalable mode by default" 257 - depends on INTEL_IOMMU 258 - help 259 - Selecting this option will enable by default the scalable mode if 260 - hardware presents the capability. The scalable mode is defined in 261 - VT-d 3.0. The scalable mode capability could be checked by reading 262 - /sys/devices/virtual/iommu/dmar*/intel-iommu/ecap. If this option 263 - is not selected, scalable mode support could also be enabled by 264 - passing intel_iommu=sm_on to the kernel. If not sure, please use 265 - the default value. 132 + source "drivers/iommu/amd/Kconfig" 133 + source "drivers/iommu/intel/Kconfig" 266 134 267 135 config IRQ_REMAP 268 136 bool "Support for Interrupt Remapping" ··· 144 276 # OMAP IOMMU support 145 277 config OMAP_IOMMU 146 278 bool "OMAP IOMMU Support" 147 - depends on ARM && MMU || (COMPILE_TEST && (ARM || ARM64 || IA64 || SPARC)) 148 279 depends on ARCH_OMAP2PLUS || COMPILE_TEST 149 280 select IOMMU_API 150 281 help ··· 161 294 162 295 config ROCKCHIP_IOMMU 163 296 bool "Rockchip IOMMU Support" 164 - depends on ARM || ARM64 || (COMPILE_TEST && (ARM64 || IA64 || SPARC)) 165 297 depends on ARCH_ROCKCHIP || COMPILE_TEST 166 298 select IOMMU_API 167 299 select ARM_DMA_USE_IOMMU ··· 177 311 depends on ARCH_SUNXI || COMPILE_TEST 178 312 select ARM_DMA_USE_IOMMU 179 313 select IOMMU_API 180 - select IOMMU_DMA 181 314 help 182 315 Support for the IOMMU introduced in the Allwinner H6 SoCs. 183 316 ··· 203 338 204 339 config EXYNOS_IOMMU 205 340 bool "Exynos IOMMU Support" 206 - depends on ARCH_EXYNOS && MMU || (COMPILE_TEST && (ARM || ARM64 || IA64 || SPARC)) 341 + depends on ARCH_EXYNOS || COMPILE_TEST 207 342 depends on !CPU_BIG_ENDIAN # revisit driver if we can enable big-endian ptes 208 343 select IOMMU_API 209 344 select ARM_DMA_USE_IOMMU ··· 226 361 227 362 config IPMMU_VMSA 228 363 bool "Renesas VMSA-compatible IPMMU" 229 - depends on ARM || IOMMU_DMA 230 364 depends on ARCH_RENESAS || (COMPILE_TEST && !GENERIC_ATOMIC64) 231 365 select IOMMU_API 232 366 select IOMMU_IO_PGTABLE_LPAE ··· 247 383 # ARM IOMMU support 248 384 config ARM_SMMU 249 385 tristate "ARM Ltd. System MMU (SMMU) Support" 250 - depends on (ARM64 || ARM || (COMPILE_TEST && !GENERIC_ATOMIC64)) && MMU 386 + depends on ARM64 || ARM || (COMPILE_TEST && !GENERIC_ATOMIC64) 251 387 select IOMMU_API 252 388 select IOMMU_IO_PGTABLE_LPAE 253 389 select ARM_DMA_USE_IOMMU if ARM ··· 333 469 334 470 config MTK_IOMMU 335 471 bool "MTK IOMMU Support" 336 - depends on HAS_DMA 337 472 depends on ARCH_MEDIATEK || COMPILE_TEST 338 473 select ARM_DMA_USE_IOMMU 339 474 select IOMMU_API 340 - select IOMMU_DMA 341 475 select IOMMU_IO_PGTABLE_ARMV7S 342 476 select MEMORY 343 477 select MTK_SMI
+2 -13
drivers/iommu/Makefile
··· 1 1 # SPDX-License-Identifier: GPL-2.0 2 + obj-y += amd/ intel/ arm/ 2 3 obj-$(CONFIG_IOMMU_API) += iommu.o 3 4 obj-$(CONFIG_IOMMU_API) += iommu-traces.o 4 5 obj-$(CONFIG_IOMMU_API) += iommu-sysfs.o ··· 12 11 obj-$(CONFIG_IOMMU_IOVA) += iova.o 13 12 obj-$(CONFIG_OF_IOMMU) += of_iommu.o 14 13 obj-$(CONFIG_MSM_IOMMU) += msm_iommu.o 15 - obj-$(CONFIG_AMD_IOMMU) += amd/iommu.o amd/init.o amd/quirks.o 16 - obj-$(CONFIG_AMD_IOMMU_DEBUGFS) += amd/debugfs.o 17 - obj-$(CONFIG_AMD_IOMMU_V2) += amd/iommu_v2.o 18 - obj-$(CONFIG_ARM_SMMU) += arm_smmu.o 19 - arm_smmu-objs += arm-smmu.o arm-smmu-impl.o arm-smmu-qcom.o 20 - obj-$(CONFIG_ARM_SMMU_V3) += arm-smmu-v3.o 21 - obj-$(CONFIG_DMAR_TABLE) += intel/dmar.o 22 - obj-$(CONFIG_INTEL_IOMMU) += intel/iommu.o intel/pasid.o 23 - obj-$(CONFIG_INTEL_IOMMU) += intel/trace.o 24 - obj-$(CONFIG_INTEL_IOMMU_DEBUGFS) += intel/debugfs.o 25 - obj-$(CONFIG_INTEL_IOMMU_SVM) += intel/svm.o 26 14 obj-$(CONFIG_IPMMU_VMSA) += ipmmu-vmsa.o 27 - obj-$(CONFIG_IRQ_REMAP) += intel/irq_remapping.o irq_remapping.o 15 + obj-$(CONFIG_IRQ_REMAP) += irq_remapping.o 28 16 obj-$(CONFIG_MTK_IOMMU) += mtk_iommu.o 29 17 obj-$(CONFIG_MTK_IOMMU_V1) += mtk_iommu_v1.o 30 18 obj-$(CONFIG_OMAP_IOMMU) += omap-iommu.o ··· 25 35 obj-$(CONFIG_EXYNOS_IOMMU) += exynos-iommu.o 26 36 obj-$(CONFIG_FSL_PAMU) += fsl_pamu.o fsl_pamu_domain.o 27 37 obj-$(CONFIG_S390_IOMMU) += s390-iommu.o 28 - obj-$(CONFIG_QCOM_IOMMU) += qcom_iommu.o 29 38 obj-$(CONFIG_HYPERV_IOMMU) += hyperv-iommu.o 30 39 obj-$(CONFIG_VIRTIO_IOMMU) += virtio-iommu.o
+44
drivers/iommu/amd/Kconfig
··· 1 + # SPDX-License-Identifier: GPL-2.0-only 2 + # AMD IOMMU support 3 + config AMD_IOMMU 4 + bool "AMD IOMMU support" 5 + select SWIOTLB 6 + select PCI_MSI 7 + select PCI_ATS 8 + select PCI_PRI 9 + select PCI_PASID 10 + select IOMMU_API 11 + select IOMMU_IOVA 12 + select IOMMU_DMA 13 + depends on X86_64 && PCI && ACPI 14 + help 15 + With this option you can enable support for AMD IOMMU hardware in 16 + your system. An IOMMU is a hardware component which provides 17 + remapping of DMA memory accesses from devices. With an AMD IOMMU you 18 + can isolate the DMA memory of different devices and protect the 19 + system from misbehaving device drivers or hardware. 20 + 21 + You can find out if your system has an AMD IOMMU if you look into 22 + your BIOS for an option to enable it or if you have an IVRS ACPI 23 + table. 24 + 25 + config AMD_IOMMU_V2 26 + tristate "AMD IOMMU Version 2 driver" 27 + depends on AMD_IOMMU 28 + select MMU_NOTIFIER 29 + help 30 + This option enables support for the AMD IOMMUv2 features of the IOMMU 31 + hardware. Select this option if you want to use devices that support 32 + the PCI PRI and PASID interface. 33 + 34 + config AMD_IOMMU_DEBUGFS 35 + bool "Enable AMD IOMMU internals in DebugFS" 36 + depends on AMD_IOMMU && IOMMU_DEBUGFS 37 + help 38 + !!!WARNING!!! !!!WARNING!!! !!!WARNING!!! !!!WARNING!!! 39 + 40 + DO NOT ENABLE THIS OPTION UNLESS YOU REALLY, -REALLY- KNOW WHAT YOU ARE DOING!!! 41 + Exposes AMD IOMMU device internals in DebugFS. 42 + 43 + This option is -NOT- intended for production environments, and should 44 + not generally be enabled.
+4
drivers/iommu/amd/Makefile
··· 1 + # SPDX-License-Identifier: GPL-2.0-only 2 + obj-$(CONFIG_AMD_IOMMU) += iommu.o init.o quirks.o 3 + obj-$(CONFIG_AMD_IOMMU_DEBUGFS) += debugfs.o 4 + obj-$(CONFIG_AMD_IOMMU_V2) += iommu_v2.o
+3 -10
drivers/iommu/amd/init.c
··· 720 720 721 721 static void __init free_ppr_log(struct amd_iommu *iommu) 722 722 { 723 - if (iommu->ppr_log == NULL) 724 - return; 725 - 726 723 free_pages((unsigned long)iommu->ppr_log, get_order(PPR_LOG_SIZE)); 727 724 } 728 725 729 726 static void free_ga_log(struct amd_iommu *iommu) 730 727 { 731 728 #ifdef CONFIG_IRQ_REMAP 732 - if (iommu->ga_log) 733 - free_pages((unsigned long)iommu->ga_log, 734 - get_order(GA_LOG_SIZE)); 735 - if (iommu->ga_log_tail) 736 - free_pages((unsigned long)iommu->ga_log_tail, 737 - get_order(8)); 729 + free_pages((unsigned long)iommu->ga_log, get_order(GA_LOG_SIZE)); 730 + free_pages((unsigned long)iommu->ga_log_tail, get_order(8)); 738 731 #endif 739 732 } 740 733 ··· 1835 1842 pci_info(pdev, "Found IOMMU cap 0x%hx\n", iommu->cap_ptr); 1836 1843 1837 1844 if (iommu->cap & (1 << IOMMU_CAP_EFR)) { 1838 - pci_info(pdev, "Extended features (%#llx):\n", 1845 + pci_info(pdev, "Extended features (%#llx):", 1839 1846 iommu->features); 1840 1847 for (i = 0; i < ARRAY_SIZE(feat_str); ++i) { 1841 1848 if (iommu_feature(iommu, (1ULL << i)))
+20 -11
drivers/iommu/amd/iommu.c
··· 162 162 pgtable->mode = pt_root & 7; /* lowest 3 bits encode pgtable mode */ 163 163 } 164 164 165 - static u64 amd_iommu_domain_encode_pgtable(u64 *root, int mode) 165 + static void amd_iommu_domain_set_pt_root(struct protection_domain *domain, u64 root) 166 + { 167 + atomic64_set(&domain->pt_root, root); 168 + } 169 + 170 + static void amd_iommu_domain_clr_pt_root(struct protection_domain *domain) 171 + { 172 + amd_iommu_domain_set_pt_root(domain, 0); 173 + } 174 + 175 + static void amd_iommu_domain_set_pgtable(struct protection_domain *domain, 176 + u64 *root, int mode) 166 177 { 167 178 u64 pt_root; 168 179 ··· 181 170 pt_root = mode & 7; 182 171 pt_root |= (u64)root; 183 172 184 - return pt_root; 173 + amd_iommu_domain_set_pt_root(domain, pt_root); 185 174 } 186 175 187 176 static struct iommu_dev_data *alloc_dev_data(u16 devid) ··· 1421 1410 struct domain_pgtable pgtable; 1422 1411 unsigned long flags; 1423 1412 bool ret = true; 1424 - u64 *pte, root; 1413 + u64 *pte; 1425 1414 1426 1415 spin_lock_irqsave(&domain->lock, flags); 1427 1416 ··· 1449 1438 * Device Table needs to be updated and flushed before the new root can 1450 1439 * be published. 1451 1440 */ 1452 - root = amd_iommu_domain_encode_pgtable(pte, pgtable.mode); 1453 - atomic64_set(&domain->pt_root, root); 1441 + amd_iommu_domain_set_pgtable(domain, pte, pgtable.mode); 1454 1442 1455 1443 ret = true; 1456 1444 ··· 2329 2319 domain_id_free(domain->id); 2330 2320 2331 2321 amd_iommu_domain_get_pgtable(domain, &pgtable); 2332 - atomic64_set(&domain->pt_root, 0); 2322 + amd_iommu_domain_clr_pt_root(domain); 2333 2323 free_pagetable(&pgtable); 2334 2324 2335 2325 kfree(domain); ··· 2337 2327 2338 2328 static int protection_domain_init(struct protection_domain *domain, int mode) 2339 2329 { 2340 - u64 *pt_root = NULL, root; 2330 + u64 *pt_root = NULL; 2341 2331 2342 2332 BUG_ON(mode < PAGE_MODE_NONE || mode > PAGE_MODE_6_LEVEL); 2343 2333 ··· 2353 2343 return -ENOMEM; 2354 2344 } 2355 2345 2356 - root = amd_iommu_domain_encode_pgtable(pt_root, mode); 2357 - atomic64_set(&domain->pt_root, root); 2346 + amd_iommu_domain_set_pgtable(domain, pt_root, mode); 2358 2347 2359 2348 return 0; 2360 2349 } ··· 2722 2713 /* First save pgtable configuration*/ 2723 2714 amd_iommu_domain_get_pgtable(domain, &pgtable); 2724 2715 2725 - /* Update data structure */ 2726 - atomic64_set(&domain->pt_root, 0); 2716 + /* Remove page-table from domain */ 2717 + amd_iommu_domain_clr_pt_root(domain); 2727 2718 2728 2719 /* Make changes visible to IOMMUs */ 2729 2720 update_domain(domain);
+55 -5
drivers/iommu/arm-smmu-impl.c drivers/iommu/arm/arm-smmu/arm-smmu-impl.c
··· 147 147 .reset = arm_mmu500_reset, 148 148 }; 149 149 150 + static u64 mrvl_mmu500_readq(struct arm_smmu_device *smmu, int page, int off) 151 + { 152 + /* 153 + * Marvell Armada-AP806 erratum #582743. 154 + * Split all the readq to double readl 155 + */ 156 + return hi_lo_readq_relaxed(arm_smmu_page(smmu, page) + off); 157 + } 158 + 159 + static void mrvl_mmu500_writeq(struct arm_smmu_device *smmu, int page, int off, 160 + u64 val) 161 + { 162 + /* 163 + * Marvell Armada-AP806 erratum #582743. 164 + * Split all the writeq to double writel 165 + */ 166 + hi_lo_writeq_relaxed(val, arm_smmu_page(smmu, page) + off); 167 + } 168 + 169 + static int mrvl_mmu500_cfg_probe(struct arm_smmu_device *smmu) 170 + { 171 + 172 + /* 173 + * Armada-AP806 erratum #582743. 174 + * Hide the SMMU_IDR2.PTFSv8 fields to sidestep the AArch64 175 + * formats altogether and allow using 32 bits access on the 176 + * interconnect. 177 + */ 178 + smmu->features &= ~(ARM_SMMU_FEAT_FMT_AARCH64_4K | 179 + ARM_SMMU_FEAT_FMT_AARCH64_16K | 180 + ARM_SMMU_FEAT_FMT_AARCH64_64K); 181 + 182 + return 0; 183 + } 184 + 185 + static const struct arm_smmu_impl mrvl_mmu500_impl = { 186 + .read_reg64 = mrvl_mmu500_readq, 187 + .write_reg64 = mrvl_mmu500_writeq, 188 + .cfg_probe = mrvl_mmu500_cfg_probe, 189 + .reset = arm_mmu500_reset, 190 + }; 191 + 150 192 151 193 struct arm_smmu_device *arm_smmu_impl_init(struct arm_smmu_device *smmu) 152 194 { 153 195 const struct device_node *np = smmu->dev->of_node; 154 196 155 197 /* 156 - * We will inevitably have to combine model-specific implementation 157 - * quirks with platform-specific integration quirks, but everything 158 - * we currently support happens to work out as straightforward 159 - * mutually-exclusive assignments. 198 + * Set the impl for model-specific implementation quirks first, 199 + * such that platform integration quirks can pick it up and 200 + * inherit from it if necessary. 160 201 */ 161 202 switch (smmu->model) { 162 203 case ARM_MMU500: ··· 209 168 break; 210 169 } 211 170 171 + /* This is implicitly MMU-400 */ 212 172 if (of_property_read_bool(np, "calxeda,smmu-secure-config-access")) 213 173 smmu->impl = &calxeda_impl; 214 174 175 + if (of_device_is_compatible(np, "nvidia,tegra194-smmu")) 176 + return nvidia_smmu_impl_init(smmu); 177 + 215 178 if (of_device_is_compatible(np, "qcom,sdm845-smmu-500") || 216 - of_device_is_compatible(np, "qcom,sc7180-smmu-500")) 179 + of_device_is_compatible(np, "qcom,sc7180-smmu-500") || 180 + of_device_is_compatible(np, "qcom,sm8150-smmu-500") || 181 + of_device_is_compatible(np, "qcom,sm8250-smmu-500")) 217 182 return qcom_smmu_impl_init(smmu); 183 + 184 + if (of_device_is_compatible(np, "marvell,ap806-smmu-500")) 185 + smmu->impl = &mrvl_mmu500_impl; 218 186 219 187 return smmu; 220 188 }
drivers/iommu/arm-smmu-qcom.c drivers/iommu/arm/arm-smmu/arm-smmu-qcom.c
+2 -2
drivers/iommu/arm-smmu-v3.c drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c
··· 1479 1479 } 1480 1480 1481 1481 /* 1482 - * Try to unlock the cmq lock. This will fail if we're the last 1482 + * Try to unlock the cmdq lock. This will fail if we're the last 1483 1483 * reader, in which case we can safely update cmdq->q.llq.cons 1484 1484 */ 1485 1485 if (!arm_smmu_cmdq_shared_tryunlock(cmdq)) { ··· 2850 2850 if (!ops) 2851 2851 return -ENODEV; 2852 2852 2853 - return ops->map(ops, iova, paddr, size, prot); 2853 + return ops->map(ops, iova, paddr, size, prot, gfp); 2854 2854 } 2855 2855 2856 2856 static size_t arm_smmu_unmap(struct iommu_domain *domain, unsigned long iova,
+28 -14
drivers/iommu/arm-smmu.c drivers/iommu/arm/arm-smmu/arm-smmu.c
··· 52 52 */ 53 53 #define QCOM_DUMMY_VAL -1 54 54 55 - #define TLB_LOOP_TIMEOUT 1000000 /* 1s! */ 56 - #define TLB_SPIN_COUNT 10 57 - 58 55 #define MSI_IOVA_BASE 0x8000000 59 56 #define MSI_IOVA_LENGTH 0x100000 60 57 ··· 670 673 enum io_pgtable_fmt fmt; 671 674 struct arm_smmu_domain *smmu_domain = to_smmu_domain(domain); 672 675 struct arm_smmu_cfg *cfg = &smmu_domain->cfg; 676 + irqreturn_t (*context_fault)(int irq, void *dev); 673 677 674 678 mutex_lock(&smmu_domain->init_mutex); 675 679 if (smmu_domain->smmu) ··· 833 835 * handler seeing a half-initialised domain state. 834 836 */ 835 837 irq = smmu->irqs[smmu->num_global_irqs + cfg->irptndx]; 836 - ret = devm_request_irq(smmu->dev, irq, arm_smmu_context_fault, 838 + 839 + if (smmu->impl && smmu->impl->context_fault) 840 + context_fault = smmu->impl->context_fault; 841 + else 842 + context_fault = arm_smmu_context_fault; 843 + 844 + ret = devm_request_irq(smmu->dev, irq, context_fault, 837 845 IRQF_SHARED, "arm-smmu-context-fault", domain); 838 846 if (ret < 0) { 839 847 dev_err(smmu->dev, "failed to request context IRQ %d (%u)\n", ··· 1231 1227 return -ENODEV; 1232 1228 1233 1229 arm_smmu_rpm_get(smmu); 1234 - ret = ops->map(ops, iova, paddr, size, prot); 1230 + ret = ops->map(ops, iova, paddr, size, prot, gfp); 1235 1231 arm_smmu_rpm_put(smmu); 1236 1232 1237 1233 return ret; ··· 1732 1728 unsigned int size; 1733 1729 u32 id; 1734 1730 bool cttw_reg, cttw_fw = smmu->features & ARM_SMMU_FEAT_COHERENT_WALK; 1735 - int i; 1731 + int i, ret; 1736 1732 1737 1733 dev_notice(smmu->dev, "probing hardware configuration...\n"); 1738 1734 dev_notice(smmu->dev, "SMMUv%d with:\n", ··· 1895 1891 smmu->features |= ARM_SMMU_FEAT_FMT_AARCH64_64K; 1896 1892 } 1897 1893 1894 + if (smmu->impl && smmu->impl->cfg_probe) { 1895 + ret = smmu->impl->cfg_probe(smmu); 1896 + if (ret) 1897 + return ret; 1898 + } 1899 + 1898 1900 /* Now we've corralled the various formats, what'll it do? */ 1899 1901 if (smmu->features & ARM_SMMU_FEAT_FMT_AARCH32_S) 1900 1902 smmu->pgsize_bitmap |= SZ_4K | SZ_64K | SZ_1M | SZ_16M; ··· 1928 1918 dev_notice(smmu->dev, "\tStage-2: %lu-bit IPA -> %lu-bit PA\n", 1929 1919 smmu->ipa_size, smmu->pa_size); 1930 1920 1931 - if (smmu->impl && smmu->impl->cfg_probe) 1932 - return smmu->impl->cfg_probe(smmu); 1933 - 1934 1921 return 0; 1935 1922 } 1936 1923 ··· 1953 1946 { .compatible = "arm,mmu-401", .data = &arm_mmu401 }, 1954 1947 { .compatible = "arm,mmu-500", .data = &arm_mmu500 }, 1955 1948 { .compatible = "cavium,smmu-v2", .data = &cavium_smmuv2 }, 1949 + { .compatible = "nvidia,smmu-500", .data = &arm_mmu500 }, 1956 1950 { .compatible = "qcom,smmu-v2", .data = &qcom_smmuv2 }, 1957 1951 { }, 1958 1952 }; ··· 2115 2107 struct arm_smmu_device *smmu; 2116 2108 struct device *dev = &pdev->dev; 2117 2109 int num_irqs, i, err; 2110 + irqreturn_t (*global_fault)(int irq, void *dev); 2118 2111 2119 2112 smmu = devm_kzalloc(dev, sizeof(*smmu), GFP_KERNEL); 2120 2113 if (!smmu) { ··· 2132 2123 if (err) 2133 2124 return err; 2134 2125 2135 - smmu = arm_smmu_impl_init(smmu); 2136 - if (IS_ERR(smmu)) 2137 - return PTR_ERR(smmu); 2138 - 2139 2126 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 2140 2127 ioaddr = res->start; 2141 2128 smmu->base = devm_ioremap_resource(dev, res); ··· 2142 2137 * stash that temporarily until we know PAGESIZE to validate it with. 2143 2138 */ 2144 2139 smmu->numpage = resource_size(res); 2140 + 2141 + smmu = arm_smmu_impl_init(smmu); 2142 + if (IS_ERR(smmu)) 2143 + return PTR_ERR(smmu); 2145 2144 2146 2145 num_irqs = 0; 2147 2146 while ((res = platform_get_resource(pdev, IORESOURCE_IRQ, num_irqs))) { ··· 2202 2193 smmu->num_context_irqs = smmu->num_context_banks; 2203 2194 } 2204 2195 2196 + if (smmu->impl && smmu->impl->global_fault) 2197 + global_fault = smmu->impl->global_fault; 2198 + else 2199 + global_fault = arm_smmu_global_fault; 2200 + 2205 2201 for (i = 0; i < smmu->num_global_irqs; ++i) { 2206 2202 err = devm_request_irq(smmu->dev, smmu->irqs[i], 2207 - arm_smmu_global_fault, 2203 + global_fault, 2208 2204 IRQF_SHARED, 2209 2205 "arm-smmu global fault", 2210 2206 smmu);
+6
drivers/iommu/arm-smmu.h drivers/iommu/arm/arm-smmu/arm-smmu.h
··· 18 18 #include <linux/io-64-nonatomic-hi-lo.h> 19 19 #include <linux/io-pgtable.h> 20 20 #include <linux/iommu.h> 21 + #include <linux/irqreturn.h> 21 22 #include <linux/mutex.h> 22 23 #include <linux/spinlock.h> 23 24 #include <linux/types.h> ··· 237 236 /* Maximum number of context banks per SMMU */ 238 237 #define ARM_SMMU_MAX_CBS 128 239 238 239 + #define TLB_LOOP_TIMEOUT 1000000 /* 1s! */ 240 + #define TLB_SPIN_COUNT 10 240 241 241 242 /* Shared driver definitions */ 242 243 enum arm_smmu_arch_version { ··· 390 387 void (*tlb_sync)(struct arm_smmu_device *smmu, int page, int sync, 391 388 int status); 392 389 int (*def_domain_type)(struct device *dev); 390 + irqreturn_t (*global_fault)(int irq, void *dev); 391 + irqreturn_t (*context_fault)(int irq, void *dev); 393 392 }; 394 393 395 394 static inline void __iomem *arm_smmu_page(struct arm_smmu_device *smmu, int n) ··· 455 450 arm_smmu_writeq((s), ARM_SMMU_CB((s), (n)), (o), (v)) 456 451 457 452 struct arm_smmu_device *arm_smmu_impl_init(struct arm_smmu_device *smmu); 453 + struct arm_smmu_device *nvidia_smmu_impl_init(struct arm_smmu_device *smmu); 458 454 struct arm_smmu_device *qcom_smmu_impl_init(struct arm_smmu_device *smmu); 459 455 460 456 int arm_mmu500_reset(struct arm_smmu_device *smmu);
+2
drivers/iommu/arm/Makefile
··· 1 + # SPDX-License-Identifier: GPL-2.0 2 + obj-y += arm-smmu/ arm-smmu-v3/
+2
drivers/iommu/arm/arm-smmu-v3/Makefile
··· 1 + # SPDX-License-Identifier: GPL-2.0 2 + obj-$(CONFIG_ARM_SMMU_V3) += arm-smmu-v3.o
+4
drivers/iommu/arm/arm-smmu/Makefile
··· 1 + # SPDX-License-Identifier: GPL-2.0 2 + obj-$(CONFIG_QCOM_IOMMU) += qcom_iommu.o 3 + obj-$(CONFIG_ARM_SMMU) += arm_smmu.o 4 + arm_smmu-objs += arm-smmu.o arm-smmu-impl.o arm-smmu-nvidia.o arm-smmu-qcom.o
+278
drivers/iommu/arm/arm-smmu/arm-smmu-nvidia.c
··· 1 + // SPDX-License-Identifier: GPL-2.0-only 2 + // Copyright (C) 2019-2020 NVIDIA CORPORATION. All rights reserved. 3 + 4 + #include <linux/bitfield.h> 5 + #include <linux/delay.h> 6 + #include <linux/of.h> 7 + #include <linux/platform_device.h> 8 + #include <linux/slab.h> 9 + 10 + #include "arm-smmu.h" 11 + 12 + /* 13 + * Tegra194 has three ARM MMU-500 Instances. 14 + * Two of them are used together and must be programmed identically for 15 + * interleaved IOVA accesses across them and translates accesses from 16 + * non-isochronous HW devices. 17 + * Third one is used for translating accesses from isochronous HW devices. 18 + * This implementation supports programming of the two instances that must 19 + * be programmed identically. 20 + * The third instance usage is through standard arm-smmu driver itself and 21 + * is out of scope of this implementation. 22 + */ 23 + #define NUM_SMMU_INSTANCES 2 24 + 25 + struct nvidia_smmu { 26 + struct arm_smmu_device smmu; 27 + void __iomem *bases[NUM_SMMU_INSTANCES]; 28 + }; 29 + 30 + static inline void __iomem *nvidia_smmu_page(struct arm_smmu_device *smmu, 31 + unsigned int inst, int page) 32 + { 33 + struct nvidia_smmu *nvidia_smmu; 34 + 35 + nvidia_smmu = container_of(smmu, struct nvidia_smmu, smmu); 36 + return nvidia_smmu->bases[inst] + (page << smmu->pgshift); 37 + } 38 + 39 + static u32 nvidia_smmu_read_reg(struct arm_smmu_device *smmu, 40 + int page, int offset) 41 + { 42 + void __iomem *reg = nvidia_smmu_page(smmu, 0, page) + offset; 43 + 44 + return readl_relaxed(reg); 45 + } 46 + 47 + static void nvidia_smmu_write_reg(struct arm_smmu_device *smmu, 48 + int page, int offset, u32 val) 49 + { 50 + unsigned int i; 51 + 52 + for (i = 0; i < NUM_SMMU_INSTANCES; i++) { 53 + void __iomem *reg = nvidia_smmu_page(smmu, i, page) + offset; 54 + 55 + writel_relaxed(val, reg); 56 + } 57 + } 58 + 59 + static u64 nvidia_smmu_read_reg64(struct arm_smmu_device *smmu, 60 + int page, int offset) 61 + { 62 + void __iomem *reg = nvidia_smmu_page(smmu, 0, page) + offset; 63 + 64 + return readq_relaxed(reg); 65 + } 66 + 67 + static void nvidia_smmu_write_reg64(struct arm_smmu_device *smmu, 68 + int page, int offset, u64 val) 69 + { 70 + unsigned int i; 71 + 72 + for (i = 0; i < NUM_SMMU_INSTANCES; i++) { 73 + void __iomem *reg = nvidia_smmu_page(smmu, i, page) + offset; 74 + 75 + writeq_relaxed(val, reg); 76 + } 77 + } 78 + 79 + static void nvidia_smmu_tlb_sync(struct arm_smmu_device *smmu, int page, 80 + int sync, int status) 81 + { 82 + unsigned int delay; 83 + 84 + arm_smmu_writel(smmu, page, sync, 0); 85 + 86 + for (delay = 1; delay < TLB_LOOP_TIMEOUT; delay *= 2) { 87 + unsigned int spin_cnt; 88 + 89 + for (spin_cnt = TLB_SPIN_COUNT; spin_cnt > 0; spin_cnt--) { 90 + u32 val = 0; 91 + unsigned int i; 92 + 93 + for (i = 0; i < NUM_SMMU_INSTANCES; i++) { 94 + void __iomem *reg; 95 + 96 + reg = nvidia_smmu_page(smmu, i, page) + status; 97 + val |= readl_relaxed(reg); 98 + } 99 + 100 + if (!(val & ARM_SMMU_sTLBGSTATUS_GSACTIVE)) 101 + return; 102 + 103 + cpu_relax(); 104 + } 105 + 106 + udelay(delay); 107 + } 108 + 109 + dev_err_ratelimited(smmu->dev, 110 + "TLB sync timed out -- SMMU may be deadlocked\n"); 111 + } 112 + 113 + static int nvidia_smmu_reset(struct arm_smmu_device *smmu) 114 + { 115 + unsigned int i; 116 + 117 + for (i = 0; i < NUM_SMMU_INSTANCES; i++) { 118 + u32 val; 119 + void __iomem *reg = nvidia_smmu_page(smmu, i, ARM_SMMU_GR0) + 120 + ARM_SMMU_GR0_sGFSR; 121 + 122 + /* clear global FSR */ 123 + val = readl_relaxed(reg); 124 + writel_relaxed(val, reg); 125 + } 126 + 127 + return 0; 128 + } 129 + 130 + static irqreturn_t nvidia_smmu_global_fault_inst(int irq, 131 + struct arm_smmu_device *smmu, 132 + int inst) 133 + { 134 + u32 gfsr, gfsynr0, gfsynr1, gfsynr2; 135 + void __iomem *gr0_base = nvidia_smmu_page(smmu, inst, 0); 136 + 137 + gfsr = readl_relaxed(gr0_base + ARM_SMMU_GR0_sGFSR); 138 + if (!gfsr) 139 + return IRQ_NONE; 140 + 141 + gfsynr0 = readl_relaxed(gr0_base + ARM_SMMU_GR0_sGFSYNR0); 142 + gfsynr1 = readl_relaxed(gr0_base + ARM_SMMU_GR0_sGFSYNR1); 143 + gfsynr2 = readl_relaxed(gr0_base + ARM_SMMU_GR0_sGFSYNR2); 144 + 145 + dev_err_ratelimited(smmu->dev, 146 + "Unexpected global fault, this could be serious\n"); 147 + dev_err_ratelimited(smmu->dev, 148 + "\tGFSR 0x%08x, GFSYNR0 0x%08x, GFSYNR1 0x%08x, GFSYNR2 0x%08x\n", 149 + gfsr, gfsynr0, gfsynr1, gfsynr2); 150 + 151 + writel_relaxed(gfsr, gr0_base + ARM_SMMU_GR0_sGFSR); 152 + return IRQ_HANDLED; 153 + } 154 + 155 + static irqreturn_t nvidia_smmu_global_fault(int irq, void *dev) 156 + { 157 + unsigned int inst; 158 + irqreturn_t ret = IRQ_NONE; 159 + struct arm_smmu_device *smmu = dev; 160 + 161 + for (inst = 0; inst < NUM_SMMU_INSTANCES; inst++) { 162 + irqreturn_t irq_ret; 163 + 164 + irq_ret = nvidia_smmu_global_fault_inst(irq, smmu, inst); 165 + if (irq_ret == IRQ_HANDLED) 166 + ret = IRQ_HANDLED; 167 + } 168 + 169 + return ret; 170 + } 171 + 172 + static irqreturn_t nvidia_smmu_context_fault_bank(int irq, 173 + struct arm_smmu_device *smmu, 174 + int idx, int inst) 175 + { 176 + u32 fsr, fsynr, cbfrsynra; 177 + unsigned long iova; 178 + void __iomem *gr1_base = nvidia_smmu_page(smmu, inst, 1); 179 + void __iomem *cb_base = nvidia_smmu_page(smmu, inst, smmu->numpage + idx); 180 + 181 + fsr = readl_relaxed(cb_base + ARM_SMMU_CB_FSR); 182 + if (!(fsr & ARM_SMMU_FSR_FAULT)) 183 + return IRQ_NONE; 184 + 185 + fsynr = readl_relaxed(cb_base + ARM_SMMU_CB_FSYNR0); 186 + iova = readq_relaxed(cb_base + ARM_SMMU_CB_FAR); 187 + cbfrsynra = readl_relaxed(gr1_base + ARM_SMMU_GR1_CBFRSYNRA(idx)); 188 + 189 + dev_err_ratelimited(smmu->dev, 190 + "Unhandled context fault: fsr=0x%x, iova=0x%08lx, fsynr=0x%x, cbfrsynra=0x%x, cb=%d\n", 191 + fsr, iova, fsynr, cbfrsynra, idx); 192 + 193 + writel_relaxed(fsr, cb_base + ARM_SMMU_CB_FSR); 194 + return IRQ_HANDLED; 195 + } 196 + 197 + static irqreturn_t nvidia_smmu_context_fault(int irq, void *dev) 198 + { 199 + int idx; 200 + unsigned int inst; 201 + irqreturn_t ret = IRQ_NONE; 202 + struct arm_smmu_device *smmu; 203 + struct iommu_domain *domain = dev; 204 + struct arm_smmu_domain *smmu_domain; 205 + 206 + smmu_domain = container_of(domain, struct arm_smmu_domain, domain); 207 + smmu = smmu_domain->smmu; 208 + 209 + for (inst = 0; inst < NUM_SMMU_INSTANCES; inst++) { 210 + irqreturn_t irq_ret; 211 + 212 + /* 213 + * Interrupt line is shared between all contexts. 214 + * Check for faults across all contexts. 215 + */ 216 + for (idx = 0; idx < smmu->num_context_banks; idx++) { 217 + irq_ret = nvidia_smmu_context_fault_bank(irq, smmu, 218 + idx, inst); 219 + if (irq_ret == IRQ_HANDLED) 220 + ret = IRQ_HANDLED; 221 + } 222 + } 223 + 224 + return ret; 225 + } 226 + 227 + static const struct arm_smmu_impl nvidia_smmu_impl = { 228 + .read_reg = nvidia_smmu_read_reg, 229 + .write_reg = nvidia_smmu_write_reg, 230 + .read_reg64 = nvidia_smmu_read_reg64, 231 + .write_reg64 = nvidia_smmu_write_reg64, 232 + .reset = nvidia_smmu_reset, 233 + .tlb_sync = nvidia_smmu_tlb_sync, 234 + .global_fault = nvidia_smmu_global_fault, 235 + .context_fault = nvidia_smmu_context_fault, 236 + }; 237 + 238 + struct arm_smmu_device *nvidia_smmu_impl_init(struct arm_smmu_device *smmu) 239 + { 240 + struct resource *res; 241 + struct device *dev = smmu->dev; 242 + struct nvidia_smmu *nvidia_smmu; 243 + struct platform_device *pdev = to_platform_device(dev); 244 + 245 + nvidia_smmu = devm_kzalloc(dev, sizeof(*nvidia_smmu), GFP_KERNEL); 246 + if (!nvidia_smmu) 247 + return ERR_PTR(-ENOMEM); 248 + 249 + /* 250 + * Copy the data from struct arm_smmu_device *smmu allocated in 251 + * arm-smmu.c. The smmu from struct nvidia_smmu replaces the smmu 252 + * pointer used in arm-smmu.c once this function returns. 253 + * This is necessary to derive nvidia_smmu from smmu pointer passed 254 + * through arm_smmu_impl function calls subsequently. 255 + */ 256 + nvidia_smmu->smmu = *smmu; 257 + /* Instance 0 is ioremapped by arm-smmu.c. */ 258 + nvidia_smmu->bases[0] = smmu->base; 259 + 260 + res = platform_get_resource(pdev, IORESOURCE_MEM, 1); 261 + if (!res) 262 + return ERR_PTR(-ENODEV); 263 + 264 + nvidia_smmu->bases[1] = devm_ioremap_resource(dev, res); 265 + if (IS_ERR(nvidia_smmu->bases[1])) 266 + return ERR_CAST(nvidia_smmu->bases[1]); 267 + 268 + nvidia_smmu->smmu.impl = &nvidia_smmu_impl; 269 + 270 + /* 271 + * Free the struct arm_smmu_device *smmu allocated in arm-smmu.c. 272 + * Once this function returns, arm-smmu.c would use arm_smmu_device 273 + * allocated as part of struct nvidia_smmu. 274 + */ 275 + devm_kfree(dev, smmu); 276 + 277 + return &nvidia_smmu->smmu; 278 + }
+16 -16
drivers/iommu/exynos-iommu.c
··· 173 173 #define REG_V5_FAULT_AR_VA 0x070 174 174 #define REG_V5_FAULT_AW_VA 0x080 175 175 176 - #define has_sysmmu(dev) (dev->archdata.iommu != NULL) 176 + #define has_sysmmu(dev) (dev_iommu_priv_get(dev) != NULL) 177 177 178 178 static struct device *dma_dev; 179 179 static struct kmem_cache *lv2table_kmem_cache; ··· 226 226 }; 227 227 228 228 /* 229 - * This structure is attached to dev.archdata.iommu of the master device 229 + * This structure is attached to dev->iommu->priv of the master device 230 230 * on device add, contains a list of SYSMMU controllers defined by device tree, 231 231 * which are bound to given master device. It is usually referenced by 'owner' 232 232 * pointer. ··· 670 670 struct device *master = data->master; 671 671 672 672 if (master) { 673 - struct exynos_iommu_owner *owner = master->archdata.iommu; 673 + struct exynos_iommu_owner *owner = dev_iommu_priv_get(master); 674 674 675 675 mutex_lock(&owner->rpm_lock); 676 676 if (data->domain) { ··· 688 688 struct device *master = data->master; 689 689 690 690 if (master) { 691 - struct exynos_iommu_owner *owner = master->archdata.iommu; 691 + struct exynos_iommu_owner *owner = dev_iommu_priv_get(master); 692 692 693 693 mutex_lock(&owner->rpm_lock); 694 694 if (data->domain) { ··· 721 721 } 722 722 }; 723 723 724 - static inline void update_pte(sysmmu_pte_t *ent, sysmmu_pte_t val) 724 + static inline void exynos_iommu_set_pte(sysmmu_pte_t *ent, sysmmu_pte_t val) 725 725 { 726 726 dma_sync_single_for_cpu(dma_dev, virt_to_phys(ent), sizeof(*ent), 727 727 DMA_TO_DEVICE); ··· 837 837 static void exynos_iommu_detach_device(struct iommu_domain *iommu_domain, 838 838 struct device *dev) 839 839 { 840 - struct exynos_iommu_owner *owner = dev->archdata.iommu; 841 840 struct exynos_iommu_domain *domain = to_exynos_domain(iommu_domain); 841 + struct exynos_iommu_owner *owner = dev_iommu_priv_get(dev); 842 842 phys_addr_t pagetable = virt_to_phys(domain->pgtable); 843 843 struct sysmmu_drvdata *data, *next; 844 844 unsigned long flags; ··· 875 875 static int exynos_iommu_attach_device(struct iommu_domain *iommu_domain, 876 876 struct device *dev) 877 877 { 878 - struct exynos_iommu_owner *owner = dev->archdata.iommu; 879 878 struct exynos_iommu_domain *domain = to_exynos_domain(iommu_domain); 879 + struct exynos_iommu_owner *owner = dev_iommu_priv_get(dev); 880 880 struct sysmmu_drvdata *data; 881 881 phys_addr_t pagetable = virt_to_phys(domain->pgtable); 882 882 unsigned long flags; ··· 933 933 if (!pent) 934 934 return ERR_PTR(-ENOMEM); 935 935 936 - update_pte(sent, mk_lv1ent_page(virt_to_phys(pent))); 936 + exynos_iommu_set_pte(sent, mk_lv1ent_page(virt_to_phys(pent))); 937 937 kmemleak_ignore(pent); 938 938 *pgcounter = NUM_LV2ENTRIES; 939 939 handle = dma_map_single(dma_dev, pent, LV2TABLE_SIZE, ··· 994 994 *pgcnt = 0; 995 995 } 996 996 997 - update_pte(sent, mk_lv1ent_sect(paddr, prot)); 997 + exynos_iommu_set_pte(sent, mk_lv1ent_sect(paddr, prot)); 998 998 999 999 spin_lock(&domain->lock); 1000 1000 if (lv1ent_page_zero(sent)) { ··· 1018 1018 if (WARN_ON(!lv2ent_fault(pent))) 1019 1019 return -EADDRINUSE; 1020 1020 1021 - update_pte(pent, mk_lv2ent_spage(paddr, prot)); 1021 + exynos_iommu_set_pte(pent, mk_lv2ent_spage(paddr, prot)); 1022 1022 *pgcnt -= 1; 1023 1023 } else { /* size == LPAGE_SIZE */ 1024 1024 int i; ··· 1150 1150 } 1151 1151 1152 1152 /* workaround for h/w bug in System MMU v3.3 */ 1153 - update_pte(ent, ZERO_LV2LINK); 1153 + exynos_iommu_set_pte(ent, ZERO_LV2LINK); 1154 1154 size = SECT_SIZE; 1155 1155 goto done; 1156 1156 } ··· 1171 1171 } 1172 1172 1173 1173 if (lv2ent_small(ent)) { 1174 - update_pte(ent, 0); 1174 + exynos_iommu_set_pte(ent, 0); 1175 1175 size = SPAGE_SIZE; 1176 1176 domain->lv2entcnt[lv1ent_offset(iova)] += 1; 1177 1177 goto done; ··· 1237 1237 1238 1238 static struct iommu_device *exynos_iommu_probe_device(struct device *dev) 1239 1239 { 1240 - struct exynos_iommu_owner *owner = dev->archdata.iommu; 1240 + struct exynos_iommu_owner *owner = dev_iommu_priv_get(dev); 1241 1241 struct sysmmu_drvdata *data; 1242 1242 1243 1243 if (!has_sysmmu(dev)) ··· 1263 1263 1264 1264 static void exynos_iommu_release_device(struct device *dev) 1265 1265 { 1266 - struct exynos_iommu_owner *owner = dev->archdata.iommu; 1266 + struct exynos_iommu_owner *owner = dev_iommu_priv_get(dev); 1267 1267 struct sysmmu_drvdata *data; 1268 1268 1269 1269 if (!has_sysmmu(dev)) ··· 1287 1287 static int exynos_iommu_of_xlate(struct device *dev, 1288 1288 struct of_phandle_args *spec) 1289 1289 { 1290 - struct exynos_iommu_owner *owner = dev->archdata.iommu; 1291 1290 struct platform_device *sysmmu = of_find_device_by_node(spec->np); 1291 + struct exynos_iommu_owner *owner = dev_iommu_priv_get(dev); 1292 1292 struct sysmmu_drvdata *data, *entry; 1293 1293 1294 1294 if (!sysmmu) ··· 1305 1305 1306 1306 INIT_LIST_HEAD(&owner->controllers); 1307 1307 mutex_init(&owner->rpm_lock); 1308 - dev->archdata.iommu = owner; 1308 + dev_iommu_priv_set(dev, owner); 1309 1309 } 1310 1310 1311 1311 list_for_each_entry(entry, &owner->controllers, owner_node)
+1 -4
drivers/iommu/fsl_pamu.c
··· 1174 1174 if (irq != NO_IRQ) 1175 1175 free_irq(irq, data); 1176 1176 1177 - if (data) { 1178 - memset(data, 0, sizeof(struct pamu_isr_data)); 1179 - kfree(data); 1180 - } 1177 + kzfree(data); 1181 1178 1182 1179 if (pamu_regs) 1183 1180 iounmap(pamu_regs);
+4 -4
drivers/iommu/fsl_pamu_domain.c
··· 323 323 pamu_disable_liodn(info->liodn); 324 324 spin_unlock_irqrestore(&iommu_lock, flags); 325 325 spin_lock_irqsave(&device_domain_lock, flags); 326 - info->dev->archdata.iommu_domain = NULL; 326 + dev_iommu_priv_set(info->dev, NULL); 327 327 kmem_cache_free(iommu_devinfo_cache, info); 328 328 spin_unlock_irqrestore(&device_domain_lock, flags); 329 329 } ··· 352 352 * Check here if the device is already attached to domain or not. 353 353 * If the device is already attached to a domain detach it. 354 354 */ 355 - old_domain_info = dev->archdata.iommu_domain; 355 + old_domain_info = dev_iommu_priv_get(dev); 356 356 if (old_domain_info && old_domain_info->domain != dma_domain) { 357 357 spin_unlock_irqrestore(&device_domain_lock, flags); 358 358 detach_device(dev, old_domain_info->domain); ··· 371 371 * the info for the first LIODN as all 372 372 * LIODNs share the same domain 373 373 */ 374 - if (!dev->archdata.iommu_domain) 375 - dev->archdata.iommu_domain = info; 374 + if (!dev_iommu_priv_get(dev)) 375 + dev_iommu_priv_set(dev, info); 376 376 spin_unlock_irqrestore(&device_domain_lock, flags); 377 377 } 378 378
+87
drivers/iommu/intel/Kconfig
··· 1 + # SPDX-License-Identifier: GPL-2.0-only 2 + # Intel IOMMU support 3 + config DMAR_TABLE 4 + bool 5 + 6 + config INTEL_IOMMU 7 + bool "Support for Intel IOMMU using DMA Remapping Devices" 8 + depends on PCI_MSI && ACPI && (X86 || IA64) 9 + select DMA_OPS 10 + select IOMMU_API 11 + select IOMMU_IOVA 12 + select NEED_DMA_MAP_STATE 13 + select DMAR_TABLE 14 + select SWIOTLB 15 + select IOASID 16 + help 17 + DMA remapping (DMAR) devices support enables independent address 18 + translations for Direct Memory Access (DMA) from devices. 19 + These DMA remapping devices are reported via ACPI tables 20 + and include PCI device scope covered by these DMA 21 + remapping devices. 22 + 23 + config INTEL_IOMMU_DEBUGFS 24 + bool "Export Intel IOMMU internals in Debugfs" 25 + depends on INTEL_IOMMU && IOMMU_DEBUGFS 26 + help 27 + !!!WARNING!!! 28 + 29 + DO NOT ENABLE THIS OPTION UNLESS YOU REALLY KNOW WHAT YOU ARE DOING!!! 30 + 31 + Expose Intel IOMMU internals in Debugfs. 32 + 33 + This option is -NOT- intended for production environments, and should 34 + only be enabled for debugging Intel IOMMU. 35 + 36 + config INTEL_IOMMU_SVM 37 + bool "Support for Shared Virtual Memory with Intel IOMMU" 38 + depends on INTEL_IOMMU && X86_64 39 + select PCI_PASID 40 + select PCI_PRI 41 + select MMU_NOTIFIER 42 + select IOASID 43 + help 44 + Shared Virtual Memory (SVM) provides a facility for devices 45 + to access DMA resources through process address space by 46 + means of a Process Address Space ID (PASID). 47 + 48 + config INTEL_IOMMU_DEFAULT_ON 49 + def_bool y 50 + prompt "Enable Intel DMA Remapping Devices by default" 51 + depends on INTEL_IOMMU 52 + help 53 + Selecting this option will enable a DMAR device at boot time if 54 + one is found. If this option is not selected, DMAR support can 55 + be enabled by passing intel_iommu=on to the kernel. 56 + 57 + config INTEL_IOMMU_BROKEN_GFX_WA 58 + bool "Workaround broken graphics drivers (going away soon)" 59 + depends on INTEL_IOMMU && BROKEN && X86 60 + help 61 + Current Graphics drivers tend to use physical address 62 + for DMA and avoid using DMA APIs. Setting this config 63 + option permits the IOMMU driver to set a unity map for 64 + all the OS-visible memory. Hence the driver can continue 65 + to use physical addresses for DMA, at least until this 66 + option is removed in the 2.6.32 kernel. 67 + 68 + config INTEL_IOMMU_FLOPPY_WA 69 + def_bool y 70 + depends on INTEL_IOMMU && X86 71 + help 72 + Floppy disk drivers are known to bypass DMA API calls 73 + thereby failing to work when IOMMU is enabled. This 74 + workaround will setup a 1:1 mapping for the first 75 + 16MiB to make floppy (an ISA device) work. 76 + 77 + config INTEL_IOMMU_SCALABLE_MODE_DEFAULT_ON 78 + bool "Enable Intel IOMMU scalable mode by default" 79 + depends on INTEL_IOMMU 80 + help 81 + Selecting this option will enable by default the scalable mode if 82 + hardware presents the capability. The scalable mode is defined in 83 + VT-d 3.0. The scalable mode capability could be checked by reading 84 + /sys/devices/virtual/iommu/dmar*/intel-iommu/ecap. If this option 85 + is not selected, scalable mode support could also be enabled by 86 + passing intel_iommu=sm_on to the kernel. If not sure, please use 87 + the default value.
+7
drivers/iommu/intel/Makefile
··· 1 + # SPDX-License-Identifier: GPL-2.0 2 + obj-$(CONFIG_DMAR_TABLE) += dmar.o 3 + obj-$(CONFIG_INTEL_IOMMU) += iommu.o pasid.o 4 + obj-$(CONFIG_INTEL_IOMMU) += trace.o 5 + obj-$(CONFIG_INTEL_IOMMU_DEBUGFS) += debugfs.o 6 + obj-$(CONFIG_INTEL_IOMMU_SVM) += svm.o 7 + obj-$(CONFIG_IRQ_REMAP) += irq_remapping.o
+1 -1
drivers/iommu/intel/debugfs.c
··· 15 15 16 16 #include <asm/irq_remapping.h> 17 17 18 - #include "intel-pasid.h" 18 + #include "pasid.h" 19 19 20 20 struct tbl_walk { 21 21 u16 bus;
+21 -5
drivers/iommu/intel/dmar.c
··· 1102 1102 } 1103 1103 1104 1104 drhd->iommu = iommu; 1105 + iommu->drhd = drhd; 1105 1106 1106 1107 return 0; 1107 1108 ··· 1439 1438 1440 1439 /* PASID-based device IOTLB Invalidate */ 1441 1440 void qi_flush_dev_iotlb_pasid(struct intel_iommu *iommu, u16 sid, u16 pfsid, 1442 - u32 pasid, u16 qdep, u64 addr, 1443 - unsigned int size_order, u64 granu) 1441 + u32 pasid, u16 qdep, u64 addr, unsigned int size_order) 1444 1442 { 1445 1443 unsigned long mask = 1UL << (VTD_PAGE_SHIFT + size_order - 1); 1446 1444 struct qi_desc desc = {.qw1 = 0, .qw2 = 0, .qw3 = 0}; ··· 1447 1447 desc.qw0 = QI_DEV_EIOTLB_PASID(pasid) | QI_DEV_EIOTLB_SID(sid) | 1448 1448 QI_DEV_EIOTLB_QDEP(qdep) | QI_DEIOTLB_TYPE | 1449 1449 QI_DEV_IOTLB_PFSID(pfsid); 1450 - desc.qw1 = QI_DEV_EIOTLB_GLOB(granu); 1451 1450 1452 1451 /* 1453 1452 * If S bit is 0, we only flush a single page. If S bit is set, ··· 1457 1458 * Max Invs Pending (MIP) is set to 0 for now until we have DIT in 1458 1459 * ECAP. 1459 1460 */ 1460 - desc.qw1 |= addr & ~mask; 1461 - if (size_order) 1461 + if (addr & GENMASK_ULL(size_order + VTD_PAGE_SHIFT, 0)) 1462 + pr_warn_ratelimited("Invalidate non-aligned address %llx, order %d\n", 1463 + addr, size_order); 1464 + 1465 + /* Take page address */ 1466 + desc.qw1 = QI_DEV_EIOTLB_ADDR(addr); 1467 + 1468 + if (size_order) { 1469 + /* 1470 + * Existing 0s in address below size_order may be the least 1471 + * significant bit, we must set them to 1s to avoid having 1472 + * smaller size than desired. 1473 + */ 1474 + desc.qw1 |= GENMASK_ULL(size_order + VTD_PAGE_SHIFT - 1, 1475 + VTD_PAGE_SHIFT); 1476 + /* Clear size_order bit to indicate size */ 1477 + desc.qw1 &= ~mask; 1478 + /* Set the S bit to indicate flushing more than 1 page */ 1462 1479 desc.qw1 |= QI_DEV_EIOTLB_SIZE; 1480 + } 1463 1481 1464 1482 qi_submit_sync(iommu, &desc, 1, 0); 1465 1483 }
+1 -1
drivers/iommu/intel/intel-pasid.h drivers/iommu/intel/pasid.h
··· 1 1 /* SPDX-License-Identifier: GPL-2.0 */ 2 2 /* 3 - * intel-pasid.h - PASID idr, table and entry header 3 + * pasid.h - PASID idr, table and entry header 4 4 * 5 5 * Copyright (C) 2018 Intel Corporation 6 6 *
+78 -63
drivers/iommu/intel/iommu.c
··· 48 48 #include <trace/events/intel_iommu.h> 49 49 50 50 #include "../irq_remapping.h" 51 - #include "intel-pasid.h" 51 + #include "pasid.h" 52 52 53 53 #define ROOT_SIZE VTD_PAGE_SIZE 54 54 #define CONTEXT_SIZE VTD_PAGE_SIZE ··· 356 356 static int intel_iommu_superpage = 1; 357 357 static int iommu_identity_mapping; 358 358 static int intel_no_bounce; 359 + static int iommu_skip_te_disable; 359 360 360 361 #define IDENTMAP_GFX 2 361 362 #define IDENTMAP_AZALIA 4 ··· 373 372 if (!dev) 374 373 return NULL; 375 374 376 - info = dev->archdata.iommu; 375 + info = dev_iommu_priv_get(dev); 377 376 if (unlikely(info == DUMMY_DEVICE_DOMAIN_INFO || 378 377 info == DEFER_DEVICE_DOMAIN_INFO)) 379 378 return NULL; ··· 744 743 745 744 static int iommu_dummy(struct device *dev) 746 745 { 747 - return dev->archdata.iommu == DUMMY_DEVICE_DOMAIN_INFO; 746 + return dev_iommu_priv_get(dev) == DUMMY_DEVICE_DOMAIN_INFO; 748 747 } 749 748 750 749 static bool attach_deferred(struct device *dev) 751 750 { 752 - return dev->archdata.iommu == DEFER_DEVICE_DOMAIN_INFO; 751 + return dev_iommu_priv_get(dev) == DEFER_DEVICE_DOMAIN_INFO; 753 752 } 754 753 755 754 /** ··· 779 778 return false; 780 779 } 781 780 782 - static struct intel_iommu *device_to_iommu(struct device *dev, u8 *bus, u8 *devfn) 781 + struct intel_iommu *device_to_iommu(struct device *dev, u8 *bus, u8 *devfn) 783 782 { 784 783 struct dmar_drhd_unit *drhd = NULL; 784 + struct pci_dev *pdev = NULL; 785 785 struct intel_iommu *iommu; 786 786 struct device *tmp; 787 - struct pci_dev *pdev = NULL; 788 787 u16 segment = 0; 789 788 int i; 790 789 791 - if (iommu_dummy(dev)) 790 + if (!dev || iommu_dummy(dev)) 792 791 return NULL; 793 792 794 793 if (dev_is_pci(dev)) { ··· 819 818 if (pdev && pdev->is_virtfn) 820 819 goto got_pdev; 821 820 822 - *bus = drhd->devices[i].bus; 823 - *devfn = drhd->devices[i].devfn; 821 + if (bus && devfn) { 822 + *bus = drhd->devices[i].bus; 823 + *devfn = drhd->devices[i].devfn; 824 + } 824 825 goto out; 825 826 } 826 827 ··· 832 829 833 830 if (pdev && drhd->include_all) { 834 831 got_pdev: 835 - *bus = pdev->bus->number; 836 - *devfn = pdev->devfn; 832 + if (bus && devfn) { 833 + *bus = pdev->bus->number; 834 + *devfn = pdev->devfn; 835 + } 837 836 goto out; 838 837 } 839 838 } ··· 1634 1629 u32 sts; 1635 1630 unsigned long flag; 1636 1631 1632 + if (iommu_skip_te_disable && iommu->drhd->gfx_dedicated && 1633 + (cap_read_drain(iommu->cap) || cap_write_drain(iommu->cap))) 1634 + return; 1635 + 1637 1636 raw_spin_lock_irqsave(&iommu->register_lock, flag); 1638 1637 iommu->gcmd &= ~DMA_GCMD_TE; 1639 1638 writel(iommu->gcmd, iommu->reg + DMAR_GCMD_REG); ··· 2429 2420 list_del(&info->link); 2430 2421 list_del(&info->global); 2431 2422 if (info->dev) 2432 - info->dev->archdata.iommu = NULL; 2423 + dev_iommu_priv_set(info->dev, NULL); 2433 2424 } 2434 2425 2435 2426 static void domain_remove_dev_info(struct dmar_domain *domain) ··· 2462 2453 { 2463 2454 struct iommu_domain *domain; 2464 2455 2465 - dev->archdata.iommu = NULL; 2456 + dev_iommu_priv_set(dev, NULL); 2466 2457 domain = iommu_get_domain_for_dev(dev); 2467 2458 if (domain) 2468 2459 intel_iommu_attach_device(domain, dev); ··· 2608 2599 list_add(&info->link, &domain->devices); 2609 2600 list_add(&info->global, &device_domain_list); 2610 2601 if (dev) 2611 - dev->archdata.iommu = info; 2602 + dev_iommu_priv_set(dev, info); 2612 2603 spin_unlock_irqrestore(&device_domain_lock, flags); 2613 2604 2614 2605 /* PASID table is mandatory for a PCI device in scalable mode. */ ··· 4013 4004 if (!drhd || drhd->reg_base_addr - vtbar != 0xa000) { 4014 4005 pr_warn_once(FW_BUG "BIOS assigned incorrect VT-d unit for Intel(R) QuickData Technology device\n"); 4015 4006 add_taint(TAINT_FIRMWARE_WORKAROUND, LOCKDEP_STILL_OK); 4016 - pdev->dev.archdata.iommu = DUMMY_DEVICE_DOMAIN_INFO; 4007 + dev_iommu_priv_set(&pdev->dev, DUMMY_DEVICE_DOMAIN_INFO); 4017 4008 } 4018 4009 } 4019 4010 DECLARE_PCI_FIXUP_ENABLE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_IOAT_SNB, quirk_ioat_snb_local_iommu); ··· 4048 4039 4049 4040 /* This IOMMU has *only* gfx devices. Either bypass it or 4050 4041 set the gfx_mapped flag, as appropriate */ 4042 + drhd->gfx_dedicated = 1; 4051 4043 if (!dmar_map_gfx) { 4052 4044 drhd->ignored = 1; 4053 4045 for_each_active_dev_scope(drhd->devices, 4054 4046 drhd->devices_cnt, i, dev) 4055 - dev->archdata.iommu = DUMMY_DEVICE_DOMAIN_INFO; 4047 + dev_iommu_priv_set(dev, DUMMY_DEVICE_DOMAIN_INFO); 4056 4048 } 4057 4049 } 4058 4050 } ··· 5156 5146 struct device *dev) 5157 5147 { 5158 5148 int ret; 5159 - u8 bus, devfn; 5160 5149 unsigned long flags; 5161 5150 struct intel_iommu *iommu; 5162 5151 5163 - iommu = device_to_iommu(dev, &bus, &devfn); 5152 + iommu = device_to_iommu(dev, NULL, NULL); 5164 5153 if (!iommu) 5165 5154 return -ENODEV; 5166 5155 ··· 5245 5236 struct dmar_domain *dmar_domain = to_dmar_domain(domain); 5246 5237 struct intel_iommu *iommu; 5247 5238 int addr_width; 5248 - u8 bus, devfn; 5249 5239 5250 - iommu = device_to_iommu(dev, &bus, &devfn); 5240 + iommu = device_to_iommu(dev, NULL, NULL); 5251 5241 if (!iommu) 5252 5242 return -ENODEV; 5253 5243 ··· 5424 5416 sid = PCI_DEVID(bus, devfn); 5425 5417 5426 5418 /* Size is only valid in address selective invalidation */ 5427 - if (inv_info->granularity != IOMMU_INV_GRANU_PASID) 5419 + if (inv_info->granularity == IOMMU_INV_GRANU_ADDR) 5428 5420 size = to_vtd_size(inv_info->addr_info.granule_size, 5429 5421 inv_info->addr_info.nb_granules); 5430 5422 ··· 5433 5425 IOMMU_CACHE_INV_TYPE_NR) { 5434 5426 int granu = 0; 5435 5427 u64 pasid = 0; 5428 + u64 addr = 0; 5436 5429 5437 5430 granu = to_vtd_granularity(cache_type, inv_info->granularity); 5438 5431 if (granu == -EINVAL) { ··· 5455 5446 5456 5447 switch (BIT(cache_type)) { 5457 5448 case IOMMU_CACHE_INV_TYPE_IOTLB: 5449 + /* HW will ignore LSB bits based on address mask */ 5458 5450 if (inv_info->granularity == IOMMU_INV_GRANU_ADDR && 5459 5451 size && 5460 5452 (inv_info->addr_info.addr & ((BIT(VTD_PAGE_SHIFT + size)) - 1))) { 5461 - pr_err_ratelimited("Address out of range, 0x%llx, size order %llu\n", 5453 + pr_err_ratelimited("User address not aligned, 0x%llx, size order %llu\n", 5462 5454 inv_info->addr_info.addr, size); 5463 - ret = -ERANGE; 5464 - goto out_unlock; 5465 5455 } 5466 5456 5467 5457 /* ··· 5472 5464 (granu == QI_GRAN_NONG_PASID) ? -1 : 1 << size, 5473 5465 inv_info->addr_info.flags & IOMMU_INV_ADDR_FLAGS_LEAF); 5474 5466 5467 + if (!info->ats_enabled) 5468 + break; 5475 5469 /* 5476 5470 * Always flush device IOTLB if ATS is enabled. vIOMMU 5477 5471 * in the guest may assume IOTLB flush is inclusive, 5478 5472 * which is more efficient. 5479 5473 */ 5480 - if (info->ats_enabled) 5481 - qi_flush_dev_iotlb_pasid(iommu, sid, 5482 - info->pfsid, pasid, 5483 - info->ats_qdep, 5484 - inv_info->addr_info.addr, 5485 - size, granu); 5486 - break; 5474 + fallthrough; 5487 5475 case IOMMU_CACHE_INV_TYPE_DEV_IOTLB: 5476 + /* 5477 + * PASID based device TLB invalidation does not support 5478 + * IOMMU_INV_GRANU_PASID granularity but only supports 5479 + * IOMMU_INV_GRANU_ADDR. 5480 + * The equivalent of that is we set the size to be the 5481 + * entire range of 64 bit. User only provides PASID info 5482 + * without address info. So we set addr to 0. 5483 + */ 5484 + if (inv_info->granularity == IOMMU_INV_GRANU_PASID) { 5485 + size = 64 - VTD_PAGE_SHIFT; 5486 + addr = 0; 5487 + } else if (inv_info->granularity == IOMMU_INV_GRANU_ADDR) { 5488 + addr = inv_info->addr_info.addr; 5489 + } 5490 + 5488 5491 if (info->ats_enabled) 5489 5492 qi_flush_dev_iotlb_pasid(iommu, sid, 5490 5493 info->pfsid, pasid, 5491 - info->ats_qdep, 5492 - inv_info->addr_info.addr, 5493 - size, granu); 5494 + info->ats_qdep, addr, 5495 + size); 5494 5496 else 5495 5497 pr_warn_ratelimited("Passdown device IOTLB flush w/o ATS!\n"); 5496 5498 break; ··· 5676 5658 static struct iommu_device *intel_iommu_probe_device(struct device *dev) 5677 5659 { 5678 5660 struct intel_iommu *iommu; 5679 - u8 bus, devfn; 5680 5661 5681 - iommu = device_to_iommu(dev, &bus, &devfn); 5662 + iommu = device_to_iommu(dev, NULL, NULL); 5682 5663 if (!iommu) 5683 5664 return ERR_PTR(-ENODEV); 5684 5665 5685 5666 if (translation_pre_enabled(iommu)) 5686 - dev->archdata.iommu = DEFER_DEVICE_DOMAIN_INFO; 5667 + dev_iommu_priv_set(dev, DEFER_DEVICE_DOMAIN_INFO); 5687 5668 5688 5669 return &iommu->iommu; 5689 5670 } ··· 5690 5673 static void intel_iommu_release_device(struct device *dev) 5691 5674 { 5692 5675 struct intel_iommu *iommu; 5693 - u8 bus, devfn; 5694 5676 5695 - iommu = device_to_iommu(dev, &bus, &devfn); 5677 + iommu = device_to_iommu(dev, NULL, NULL); 5696 5678 if (!iommu) 5697 5679 return; 5698 5680 ··· 5841 5825 return generic_device_group(dev); 5842 5826 } 5843 5827 5844 - #ifdef CONFIG_INTEL_IOMMU_SVM 5845 - struct intel_iommu *intel_svm_device_to_iommu(struct device *dev) 5846 - { 5847 - struct intel_iommu *iommu; 5848 - u8 bus, devfn; 5849 - 5850 - if (iommu_dummy(dev)) { 5851 - dev_warn(dev, 5852 - "No IOMMU translation for device; cannot enable SVM\n"); 5853 - return NULL; 5854 - } 5855 - 5856 - iommu = device_to_iommu(dev, &bus, &devfn); 5857 - if ((!iommu)) { 5858 - dev_err(dev, "No IOMMU for device; cannot enable SVM\n"); 5859 - return NULL; 5860 - } 5861 - 5862 - return iommu; 5863 - } 5864 - #endif /* CONFIG_INTEL_IOMMU_SVM */ 5865 - 5866 5828 static int intel_iommu_enable_auxd(struct device *dev) 5867 5829 { 5868 5830 struct device_domain_info *info; 5869 5831 struct intel_iommu *iommu; 5870 5832 unsigned long flags; 5871 - u8 bus, devfn; 5872 5833 int ret; 5873 5834 5874 - iommu = device_to_iommu(dev, &bus, &devfn); 5835 + iommu = device_to_iommu(dev, NULL, NULL); 5875 5836 if (!iommu || dmar_disabled) 5876 5837 return -EINVAL; 5877 5838 ··· 6073 6080 .sva_bind = intel_svm_bind, 6074 6081 .sva_unbind = intel_svm_unbind, 6075 6082 .sva_get_pasid = intel_svm_get_pasid, 6083 + .page_response = intel_svm_page_response, 6076 6084 #endif 6077 6085 }; 6078 6086 ··· 6175 6181 DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x0044, quirk_calpella_no_shadow_gtt); 6176 6182 DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x0062, quirk_calpella_no_shadow_gtt); 6177 6183 DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x006a, quirk_calpella_no_shadow_gtt); 6184 + 6185 + static void quirk_igfx_skip_te_disable(struct pci_dev *dev) 6186 + { 6187 + unsigned short ver; 6188 + 6189 + if (!IS_GFX_DEVICE(dev)) 6190 + return; 6191 + 6192 + ver = (dev->device >> 8) & 0xff; 6193 + if (ver != 0x45 && ver != 0x46 && ver != 0x4c && 6194 + ver != 0x4e && ver != 0x8a && ver != 0x98 && 6195 + ver != 0x9a) 6196 + return; 6197 + 6198 + if (risky_device(dev)) 6199 + return; 6200 + 6201 + pci_info(dev, "Skip IOMMU disabling for graphics\n"); 6202 + iommu_skip_te_disable = 1; 6203 + } 6204 + DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_ANY_ID, quirk_igfx_skip_te_disable); 6178 6205 6179 6206 /* On Tylersburg chipsets, some BIOSes have been known to enable the 6180 6207 ISOCH DMAR unit for the Azalia sound device, but not give it any
+11 -2
drivers/iommu/intel/pasid.c
··· 19 19 #include <linux/pci-ats.h> 20 20 #include <linux/spinlock.h> 21 21 22 - #include "intel-pasid.h" 22 + #include "pasid.h" 23 23 24 24 /* 25 25 * Intel IOMMU system wide PASID name space: ··· 486 486 qdep = info->ats_qdep; 487 487 pfsid = info->pfsid; 488 488 489 - qi_flush_dev_iotlb(iommu, sid, pfsid, qdep, 0, 64 - VTD_PAGE_SHIFT); 489 + /* 490 + * When PASID 0 is used, it indicates RID2PASID(DMA request w/o PASID), 491 + * devTLB flush w/o PASID should be used. For non-zero PASID under 492 + * SVA usage, device could do DMA with multiple PASIDs. It is more 493 + * efficient to flush devTLB specific to the PASID. 494 + */ 495 + if (pasid == PASID_RID2PASID) 496 + qi_flush_dev_iotlb(iommu, sid, pfsid, qdep, 0, 64 - VTD_PAGE_SHIFT); 497 + else 498 + qi_flush_dev_iotlb_pasid(iommu, sid, pfsid, pasid, qdep, 0, 64 - VTD_PAGE_SHIFT); 490 499 } 491 500 492 501 void intel_pasid_tear_down_entry(struct intel_iommu *iommu, struct device *dev,
+258 -81
drivers/iommu/intel/svm.c
··· 20 20 #include <linux/ioasid.h> 21 21 #include <asm/page.h> 22 22 23 - #include "intel-pasid.h" 23 + #include "pasid.h" 24 24 25 25 static irqreturn_t prq_event_thread(int irq, void *d); 26 26 static void intel_svm_drain_prq(struct device *dev, int pasid); ··· 228 228 list_for_each_entry((sdev), &(svm)->devs, list) \ 229 229 if ((d) != (sdev)->dev) {} else 230 230 231 + static int pasid_to_svm_sdev(struct device *dev, unsigned int pasid, 232 + struct intel_svm **rsvm, 233 + struct intel_svm_dev **rsdev) 234 + { 235 + struct intel_svm_dev *d, *sdev = NULL; 236 + struct intel_svm *svm; 237 + 238 + /* The caller should hold the pasid_mutex lock */ 239 + if (WARN_ON(!mutex_is_locked(&pasid_mutex))) 240 + return -EINVAL; 241 + 242 + if (pasid == INVALID_IOASID || pasid >= PASID_MAX) 243 + return -EINVAL; 244 + 245 + svm = ioasid_find(NULL, pasid, NULL); 246 + if (IS_ERR(svm)) 247 + return PTR_ERR(svm); 248 + 249 + if (!svm) 250 + goto out; 251 + 252 + /* 253 + * If we found svm for the PASID, there must be at least one device 254 + * bond. 255 + */ 256 + if (WARN_ON(list_empty(&svm->devs))) 257 + return -EINVAL; 258 + 259 + rcu_read_lock(); 260 + list_for_each_entry_rcu(d, &svm->devs, list) { 261 + if (d->dev == dev) { 262 + sdev = d; 263 + break; 264 + } 265 + } 266 + rcu_read_unlock(); 267 + 268 + out: 269 + *rsvm = svm; 270 + *rsdev = sdev; 271 + 272 + return 0; 273 + } 274 + 231 275 int intel_svm_bind_gpasid(struct iommu_domain *domain, struct device *dev, 232 276 struct iommu_gpasid_bind_data *data) 233 277 { 234 - struct intel_iommu *iommu = intel_svm_device_to_iommu(dev); 278 + struct intel_iommu *iommu = device_to_iommu(dev, NULL, NULL); 279 + struct intel_svm_dev *sdev = NULL; 235 280 struct dmar_domain *dmar_domain; 236 - struct intel_svm_dev *sdev; 237 - struct intel_svm *svm; 281 + struct intel_svm *svm = NULL; 238 282 int ret = 0; 239 283 240 284 if (WARN_ON(!iommu) || !data) ··· 305 261 dmar_domain = to_dmar_domain(domain); 306 262 307 263 mutex_lock(&pasid_mutex); 308 - svm = ioasid_find(NULL, data->hpasid, NULL); 309 - if (IS_ERR(svm)) { 310 - ret = PTR_ERR(svm); 264 + ret = pasid_to_svm_sdev(dev, data->hpasid, &svm, &sdev); 265 + if (ret) 266 + goto out; 267 + 268 + if (sdev) { 269 + /* 270 + * Do not allow multiple bindings of the same device-PASID since 271 + * there is only one SL page tables per PASID. We may revisit 272 + * once sharing PGD across domains are supported. 273 + */ 274 + dev_warn_ratelimited(dev, "Already bound with PASID %u\n", 275 + svm->pasid); 276 + ret = -EBUSY; 311 277 goto out; 312 278 } 313 279 314 - if (svm) { 315 - /* 316 - * If we found svm for the PASID, there must be at 317 - * least one device bond, otherwise svm should be freed. 318 - */ 319 - if (WARN_ON(list_empty(&svm->devs))) { 320 - ret = -EINVAL; 321 - goto out; 322 - } 323 - 324 - for_each_svm_dev(sdev, svm, dev) { 325 - /* 326 - * For devices with aux domains, we should allow 327 - * multiple bind calls with the same PASID and pdev. 328 - */ 329 - if (iommu_dev_feature_enabled(dev, 330 - IOMMU_DEV_FEAT_AUX)) { 331 - sdev->users++; 332 - } else { 333 - dev_warn_ratelimited(dev, 334 - "Already bound with PASID %u\n", 335 - svm->pasid); 336 - ret = -EBUSY; 337 - } 338 - goto out; 339 - } 340 - } else { 280 + if (!svm) { 341 281 /* We come here when PASID has never been bond to a device. */ 342 282 svm = kzalloc(sizeof(*svm), GFP_KERNEL); 343 283 if (!svm) { ··· 401 373 402 374 int intel_svm_unbind_gpasid(struct device *dev, int pasid) 403 375 { 404 - struct intel_iommu *iommu = intel_svm_device_to_iommu(dev); 376 + struct intel_iommu *iommu = device_to_iommu(dev, NULL, NULL); 405 377 struct intel_svm_dev *sdev; 406 378 struct intel_svm *svm; 407 - int ret = -EINVAL; 379 + int ret; 408 380 409 381 if (WARN_ON(!iommu)) 410 382 return -EINVAL; 411 383 412 384 mutex_lock(&pasid_mutex); 413 - svm = ioasid_find(NULL, pasid, NULL); 414 - if (!svm) { 415 - ret = -EINVAL; 385 + ret = pasid_to_svm_sdev(dev, pasid, &svm, &sdev); 386 + if (ret) 416 387 goto out; 417 - } 418 388 419 - if (IS_ERR(svm)) { 420 - ret = PTR_ERR(svm); 421 - goto out; 422 - } 423 - 424 - for_each_svm_dev(sdev, svm, dev) { 425 - ret = 0; 389 + if (sdev) { 426 390 if (iommu_dev_feature_enabled(dev, IOMMU_DEV_FEAT_AUX)) 427 391 sdev->users--; 428 392 if (!sdev->users) { ··· 438 418 kfree(svm); 439 419 } 440 420 } 441 - break; 442 421 } 443 422 out: 444 423 mutex_unlock(&pasid_mutex); ··· 449 430 intel_svm_bind_mm(struct device *dev, int flags, struct svm_dev_ops *ops, 450 431 struct mm_struct *mm, struct intel_svm_dev **sd) 451 432 { 452 - struct intel_iommu *iommu = intel_svm_device_to_iommu(dev); 433 + struct intel_iommu *iommu = device_to_iommu(dev, NULL, NULL); 453 434 struct device_domain_info *info; 454 435 struct intel_svm_dev *sdev; 455 436 struct intel_svm *svm = NULL; ··· 615 596 if (sd) 616 597 *sd = sdev; 617 598 ret = 0; 618 - out: 599 + out: 619 600 return ret; 620 601 } 621 602 ··· 627 608 struct intel_svm *svm; 628 609 int ret = -EINVAL; 629 610 630 - iommu = intel_svm_device_to_iommu(dev); 611 + iommu = device_to_iommu(dev, NULL, NULL); 631 612 if (!iommu) 632 613 goto out; 633 614 634 - svm = ioasid_find(NULL, pasid, NULL); 635 - if (!svm) 615 + ret = pasid_to_svm_sdev(dev, pasid, &svm, &sdev); 616 + if (ret) 636 617 goto out; 637 618 638 - if (IS_ERR(svm)) { 639 - ret = PTR_ERR(svm); 640 - goto out; 641 - } 642 - 643 - for_each_svm_dev(sdev, svm, dev) { 644 - ret = 0; 619 + if (sdev) { 645 620 sdev->users--; 646 621 if (!sdev->users) { 647 622 list_del_rcu(&sdev->list); ··· 664 651 kfree(svm); 665 652 } 666 653 } 667 - break; 668 654 } 669 - out: 670 - 655 + out: 671 656 return ret; 672 657 } 673 658 ··· 811 800 } 812 801 } 813 802 803 + static int prq_to_iommu_prot(struct page_req_dsc *req) 804 + { 805 + int prot = 0; 806 + 807 + if (req->rd_req) 808 + prot |= IOMMU_FAULT_PERM_READ; 809 + if (req->wr_req) 810 + prot |= IOMMU_FAULT_PERM_WRITE; 811 + if (req->exe_req) 812 + prot |= IOMMU_FAULT_PERM_EXEC; 813 + if (req->pm_req) 814 + prot |= IOMMU_FAULT_PERM_PRIV; 815 + 816 + return prot; 817 + } 818 + 819 + static int 820 + intel_svm_prq_report(struct device *dev, struct page_req_dsc *desc) 821 + { 822 + struct iommu_fault_event event; 823 + 824 + if (!dev || !dev_is_pci(dev)) 825 + return -ENODEV; 826 + 827 + /* Fill in event data for device specific processing */ 828 + memset(&event, 0, sizeof(struct iommu_fault_event)); 829 + event.fault.type = IOMMU_FAULT_PAGE_REQ; 830 + event.fault.prm.addr = desc->addr; 831 + event.fault.prm.pasid = desc->pasid; 832 + event.fault.prm.grpid = desc->prg_index; 833 + event.fault.prm.perm = prq_to_iommu_prot(desc); 834 + 835 + if (desc->lpig) 836 + event.fault.prm.flags |= IOMMU_FAULT_PAGE_REQUEST_LAST_PAGE; 837 + if (desc->pasid_present) { 838 + event.fault.prm.flags |= IOMMU_FAULT_PAGE_REQUEST_PASID_VALID; 839 + event.fault.prm.flags |= IOMMU_FAULT_PAGE_RESPONSE_NEEDS_PASID; 840 + } 841 + if (desc->priv_data_present) { 842 + /* 843 + * Set last page in group bit if private data is present, 844 + * page response is required as it does for LPIG. 845 + * iommu_report_device_fault() doesn't understand this vendor 846 + * specific requirement thus we set last_page as a workaround. 847 + */ 848 + event.fault.prm.flags |= IOMMU_FAULT_PAGE_REQUEST_LAST_PAGE; 849 + event.fault.prm.flags |= IOMMU_FAULT_PAGE_REQUEST_PRIV_DATA; 850 + memcpy(event.fault.prm.private_data, desc->priv_data, 851 + sizeof(desc->priv_data)); 852 + } 853 + 854 + return iommu_report_device_fault(dev, &event); 855 + } 856 + 814 857 static irqreturn_t prq_event_thread(int irq, void *d) 815 858 { 859 + struct intel_svm_dev *sdev = NULL; 816 860 struct intel_iommu *iommu = d; 817 861 struct intel_svm *svm = NULL; 818 862 int head, tail, handled = 0; ··· 879 813 tail = dmar_readq(iommu->reg + DMAR_PQT_REG) & PRQ_RING_MASK; 880 814 head = dmar_readq(iommu->reg + DMAR_PQH_REG) & PRQ_RING_MASK; 881 815 while (head != tail) { 882 - struct intel_svm_dev *sdev; 883 816 struct vm_area_struct *vma; 884 817 struct page_req_dsc *req; 885 818 struct qi_desc resp; ··· 914 849 } 915 850 } 916 851 852 + if (!sdev || sdev->sid != req->rid) { 853 + struct intel_svm_dev *t; 854 + 855 + sdev = NULL; 856 + rcu_read_lock(); 857 + list_for_each_entry_rcu(t, &svm->devs, list) { 858 + if (t->sid == req->rid) { 859 + sdev = t; 860 + break; 861 + } 862 + } 863 + rcu_read_unlock(); 864 + } 865 + 917 866 result = QI_RESP_INVALID; 918 867 /* Since we're using init_mm.pgd directly, we should never take 919 868 * any faults on kernel addresses. */ ··· 937 858 /* If address is not canonical, return invalid response */ 938 859 if (!is_canonical_address(address)) 939 860 goto bad_req; 861 + 862 + /* 863 + * If prq is to be handled outside iommu driver via receiver of 864 + * the fault notifiers, we skip the page response here. 865 + */ 866 + if (svm->flags & SVM_FLAG_GUEST_MODE) { 867 + if (sdev && !intel_svm_prq_report(sdev->dev, req)) 868 + goto prq_advance; 869 + else 870 + goto bad_req; 871 + } 940 872 941 873 /* If the mm is already defunct, don't handle faults. */ 942 874 if (!mmget_not_zero(svm->mm)) ··· 967 877 goto invalid; 968 878 969 879 result = QI_RESP_SUCCESS; 970 - invalid: 880 + invalid: 971 881 mmap_read_unlock(svm->mm); 972 882 mmput(svm->mm); 973 - bad_req: 974 - /* Accounting for major/minor faults? */ 975 - rcu_read_lock(); 976 - list_for_each_entry_rcu(sdev, &svm->devs, list) { 977 - if (sdev->sid == req->rid) 978 - break; 979 - } 980 - /* Other devices can go away, but the drivers are not permitted 981 - * to unbind while any page faults might be in flight. So it's 982 - * OK to drop the 'lock' here now we have it. */ 983 - rcu_read_unlock(); 984 - 985 - if (WARN_ON(&sdev->list == &svm->devs)) 986 - sdev = NULL; 987 - 883 + bad_req: 884 + WARN_ON(!sdev); 988 885 if (sdev && sdev->ops && sdev->ops->fault_cb) { 989 886 int rwxp = (req->rd_req << 3) | (req->wr_req << 2) | 990 887 (req->exe_req << 1) | (req->pm_req); ··· 982 905 and these can be NULL. Do not use them below this point! */ 983 906 sdev = NULL; 984 907 svm = NULL; 985 - no_pasid: 908 + no_pasid: 986 909 if (req->lpig || req->priv_data_present) { 987 910 /* 988 911 * Per VT-d spec. v3.0 ch7.7, system software must ··· 1007 930 resp.qw3 = 0; 1008 931 qi_submit_sync(iommu, &resp, 1, 0); 1009 932 } 933 + prq_advance: 1010 934 head = (head + sizeof(*req)) & PRQ_RING_MASK; 1011 935 } 1012 936 ··· 1077 999 mutex_unlock(&pasid_mutex); 1078 1000 1079 1001 return pasid; 1002 + } 1003 + 1004 + int intel_svm_page_response(struct device *dev, 1005 + struct iommu_fault_event *evt, 1006 + struct iommu_page_response *msg) 1007 + { 1008 + struct iommu_fault_page_request *prm; 1009 + struct intel_svm_dev *sdev = NULL; 1010 + struct intel_svm *svm = NULL; 1011 + struct intel_iommu *iommu; 1012 + bool private_present; 1013 + bool pasid_present; 1014 + bool last_page; 1015 + u8 bus, devfn; 1016 + int ret = 0; 1017 + u16 sid; 1018 + 1019 + if (!dev || !dev_is_pci(dev)) 1020 + return -ENODEV; 1021 + 1022 + iommu = device_to_iommu(dev, &bus, &devfn); 1023 + if (!iommu) 1024 + return -ENODEV; 1025 + 1026 + if (!msg || !evt) 1027 + return -EINVAL; 1028 + 1029 + mutex_lock(&pasid_mutex); 1030 + 1031 + prm = &evt->fault.prm; 1032 + sid = PCI_DEVID(bus, devfn); 1033 + pasid_present = prm->flags & IOMMU_FAULT_PAGE_REQUEST_PASID_VALID; 1034 + private_present = prm->flags & IOMMU_FAULT_PAGE_REQUEST_PRIV_DATA; 1035 + last_page = prm->flags & IOMMU_FAULT_PAGE_REQUEST_LAST_PAGE; 1036 + 1037 + if (!pasid_present) { 1038 + ret = -EINVAL; 1039 + goto out; 1040 + } 1041 + 1042 + if (prm->pasid == 0 || prm->pasid >= PASID_MAX) { 1043 + ret = -EINVAL; 1044 + goto out; 1045 + } 1046 + 1047 + ret = pasid_to_svm_sdev(dev, prm->pasid, &svm, &sdev); 1048 + if (ret || !sdev) { 1049 + ret = -ENODEV; 1050 + goto out; 1051 + } 1052 + 1053 + /* 1054 + * For responses from userspace, need to make sure that the 1055 + * pasid has been bound to its mm. 1056 + */ 1057 + if (svm->flags & SVM_FLAG_GUEST_MODE) { 1058 + struct mm_struct *mm; 1059 + 1060 + mm = get_task_mm(current); 1061 + if (!mm) { 1062 + ret = -EINVAL; 1063 + goto out; 1064 + } 1065 + 1066 + if (mm != svm->mm) { 1067 + ret = -ENODEV; 1068 + mmput(mm); 1069 + goto out; 1070 + } 1071 + 1072 + mmput(mm); 1073 + } 1074 + 1075 + /* 1076 + * Per VT-d spec. v3.0 ch7.7, system software must respond 1077 + * with page group response if private data is present (PDP) 1078 + * or last page in group (LPIG) bit is set. This is an 1079 + * additional VT-d requirement beyond PCI ATS spec. 1080 + */ 1081 + if (last_page || private_present) { 1082 + struct qi_desc desc; 1083 + 1084 + desc.qw0 = QI_PGRP_PASID(prm->pasid) | QI_PGRP_DID(sid) | 1085 + QI_PGRP_PASID_P(pasid_present) | 1086 + QI_PGRP_PDP(private_present) | 1087 + QI_PGRP_RESP_CODE(msg->code) | 1088 + QI_PGRP_RESP_TYPE; 1089 + desc.qw1 = QI_PGRP_IDX(prm->grpid) | QI_PGRP_LPIG(last_page); 1090 + desc.qw2 = 0; 1091 + desc.qw3 = 0; 1092 + if (private_present) 1093 + memcpy(&desc.qw2, prm->private_data, 1094 + sizeof(prm->private_data)); 1095 + 1096 + qi_submit_sync(iommu, &desc, 1, 0); 1097 + } 1098 + out: 1099 + mutex_unlock(&pasid_mutex); 1100 + return ret; 1080 1101 }
+9 -9
drivers/iommu/io-pgtable-arm-v7s.c
··· 470 470 471 471 static int __arm_v7s_map(struct arm_v7s_io_pgtable *data, unsigned long iova, 472 472 phys_addr_t paddr, size_t size, int prot, 473 - int lvl, arm_v7s_iopte *ptep) 473 + int lvl, arm_v7s_iopte *ptep, gfp_t gfp) 474 474 { 475 475 struct io_pgtable_cfg *cfg = &data->iop.cfg; 476 476 arm_v7s_iopte pte, *cptep; ··· 491 491 /* Grab a pointer to the next level */ 492 492 pte = READ_ONCE(*ptep); 493 493 if (!pte) { 494 - cptep = __arm_v7s_alloc_table(lvl + 1, GFP_ATOMIC, data); 494 + cptep = __arm_v7s_alloc_table(lvl + 1, gfp, data); 495 495 if (!cptep) 496 496 return -ENOMEM; 497 497 ··· 512 512 } 513 513 514 514 /* Rinse, repeat */ 515 - return __arm_v7s_map(data, iova, paddr, size, prot, lvl + 1, cptep); 515 + return __arm_v7s_map(data, iova, paddr, size, prot, lvl + 1, cptep, gfp); 516 516 } 517 517 518 518 static int arm_v7s_map(struct io_pgtable_ops *ops, unsigned long iova, 519 - phys_addr_t paddr, size_t size, int prot) 519 + phys_addr_t paddr, size_t size, int prot, gfp_t gfp) 520 520 { 521 521 struct arm_v7s_io_pgtable *data = io_pgtable_ops_to_data(ops); 522 522 struct io_pgtable *iop = &data->iop; ··· 530 530 paddr >= (1ULL << data->iop.cfg.oas))) 531 531 return -ERANGE; 532 532 533 - ret = __arm_v7s_map(data, iova, paddr, size, prot, 1, data->pgd); 533 + ret = __arm_v7s_map(data, iova, paddr, size, prot, 1, data->pgd, gfp); 534 534 /* 535 535 * Synchronise all PTE updates for the new mapping before there's 536 536 * a chance for anything to kick off a table walk for the new iova. ··· 922 922 if (ops->map(ops, iova, iova, size, IOMMU_READ | 923 923 IOMMU_WRITE | 924 924 IOMMU_NOEXEC | 925 - IOMMU_CACHE)) 925 + IOMMU_CACHE, GFP_KERNEL)) 926 926 return __FAIL(ops); 927 927 928 928 /* Overlapping mappings */ 929 929 if (!ops->map(ops, iova, iova + size, size, 930 - IOMMU_READ | IOMMU_NOEXEC)) 930 + IOMMU_READ | IOMMU_NOEXEC, GFP_KERNEL)) 931 931 return __FAIL(ops); 932 932 933 933 if (ops->iova_to_phys(ops, iova + 42) != (iova + 42)) ··· 946 946 return __FAIL(ops); 947 947 948 948 /* Remap of partial unmap */ 949 - if (ops->map(ops, iova_start + size, size, size, IOMMU_READ)) 949 + if (ops->map(ops, iova_start + size, size, size, IOMMU_READ, GFP_KERNEL)) 950 950 return __FAIL(ops); 951 951 952 952 if (ops->iova_to_phys(ops, iova_start + size + 42) ··· 967 967 return __FAIL(ops); 968 968 969 969 /* Remap full block */ 970 - if (ops->map(ops, iova, iova, size, IOMMU_WRITE)) 970 + if (ops->map(ops, iova, iova, size, IOMMU_WRITE, GFP_KERNEL)) 971 971 return __FAIL(ops); 972 972 973 973 if (ops->iova_to_phys(ops, iova + 42) != (iova + 42))
+9 -12
drivers/iommu/io-pgtable-arm.c
··· 355 355 356 356 static int __arm_lpae_map(struct arm_lpae_io_pgtable *data, unsigned long iova, 357 357 phys_addr_t paddr, size_t size, arm_lpae_iopte prot, 358 - int lvl, arm_lpae_iopte *ptep) 358 + int lvl, arm_lpae_iopte *ptep, gfp_t gfp) 359 359 { 360 360 arm_lpae_iopte *cptep, pte; 361 361 size_t block_size = ARM_LPAE_BLOCK_SIZE(lvl, data); ··· 376 376 /* Grab a pointer to the next level */ 377 377 pte = READ_ONCE(*ptep); 378 378 if (!pte) { 379 - cptep = __arm_lpae_alloc_pages(tblsz, GFP_ATOMIC, cfg); 379 + cptep = __arm_lpae_alloc_pages(tblsz, gfp, cfg); 380 380 if (!cptep) 381 381 return -ENOMEM; 382 382 ··· 396 396 } 397 397 398 398 /* Rinse, repeat */ 399 - return __arm_lpae_map(data, iova, paddr, size, prot, lvl + 1, cptep); 399 + return __arm_lpae_map(data, iova, paddr, size, prot, lvl + 1, cptep, gfp); 400 400 } 401 401 402 402 static arm_lpae_iopte arm_lpae_prot_to_pte(struct arm_lpae_io_pgtable *data, ··· 438 438 else if (prot & IOMMU_CACHE) 439 439 pte |= (ARM_LPAE_MAIR_ATTR_IDX_CACHE 440 440 << ARM_LPAE_PTE_ATTRINDX_SHIFT); 441 - else if (prot & IOMMU_SYS_CACHE_ONLY) 442 - pte |= (ARM_LPAE_MAIR_ATTR_IDX_INC_OCACHE 443 - << ARM_LPAE_PTE_ATTRINDX_SHIFT); 444 441 } 445 442 446 443 if (prot & IOMMU_CACHE) ··· 458 461 } 459 462 460 463 static int arm_lpae_map(struct io_pgtable_ops *ops, unsigned long iova, 461 - phys_addr_t paddr, size_t size, int iommu_prot) 464 + phys_addr_t paddr, size_t size, int iommu_prot, gfp_t gfp) 462 465 { 463 466 struct arm_lpae_io_pgtable *data = io_pgtable_ops_to_data(ops); 464 467 struct io_pgtable_cfg *cfg = &data->iop.cfg; ··· 480 483 return -ERANGE; 481 484 482 485 prot = arm_lpae_prot_to_pte(data, iommu_prot); 483 - ret = __arm_lpae_map(data, iova, paddr, size, prot, lvl, ptep); 486 + ret = __arm_lpae_map(data, iova, paddr, size, prot, lvl, ptep, gfp); 484 487 /* 485 488 * Synchronise all PTE updates for the new mapping before there's 486 489 * a chance for anything to kick off a table walk for the new iova. ··· 1175 1178 if (ops->map(ops, iova, iova, size, IOMMU_READ | 1176 1179 IOMMU_WRITE | 1177 1180 IOMMU_NOEXEC | 1178 - IOMMU_CACHE)) 1181 + IOMMU_CACHE, GFP_KERNEL)) 1179 1182 return __FAIL(ops, i); 1180 1183 1181 1184 /* Overlapping mappings */ 1182 1185 if (!ops->map(ops, iova, iova + size, size, 1183 - IOMMU_READ | IOMMU_NOEXEC)) 1186 + IOMMU_READ | IOMMU_NOEXEC, GFP_KERNEL)) 1184 1187 return __FAIL(ops, i); 1185 1188 1186 1189 if (ops->iova_to_phys(ops, iova + 42) != (iova + 42)) ··· 1195 1198 return __FAIL(ops, i); 1196 1199 1197 1200 /* Remap of partial unmap */ 1198 - if (ops->map(ops, SZ_1G + size, size, size, IOMMU_READ)) 1201 + if (ops->map(ops, SZ_1G + size, size, size, IOMMU_READ, GFP_KERNEL)) 1199 1202 return __FAIL(ops, i); 1200 1203 1201 1204 if (ops->iova_to_phys(ops, SZ_1G + size + 42) != (size + 42)) ··· 1213 1216 return __FAIL(ops, i); 1214 1217 1215 1218 /* Remap full block */ 1216 - if (ops->map(ops, iova, iova, size, IOMMU_WRITE)) 1219 + if (ops->map(ops, iova, iova, size, IOMMU_WRITE, GFP_KERNEL)) 1217 1220 return __FAIL(ops, i); 1218 1221 1219 1222 if (ops->iova_to_phys(ops, iova + 42) != (iova + 42))
+25 -14
drivers/iommu/iommu.c
··· 383 383 * Elements are sorted by start address and overlapping segments 384 384 * of the same type are merged. 385 385 */ 386 - int iommu_insert_resv_region(struct iommu_resv_region *new, 387 - struct list_head *regions) 386 + static int iommu_insert_resv_region(struct iommu_resv_region *new, 387 + struct list_head *regions) 388 388 { 389 389 struct iommu_resv_region *iter, *tmp, *nr, *top; 390 390 LIST_HEAD(stack); ··· 1185 1185 int iommu_page_response(struct device *dev, 1186 1186 struct iommu_page_response *msg) 1187 1187 { 1188 - bool pasid_valid; 1188 + bool needs_pasid; 1189 1189 int ret = -EINVAL; 1190 1190 struct iommu_fault_event *evt; 1191 1191 struct iommu_fault_page_request *prm; 1192 1192 struct dev_iommu *param = dev->iommu; 1193 + bool has_pasid = msg->flags & IOMMU_PAGE_RESP_PASID_VALID; 1193 1194 struct iommu_domain *domain = iommu_get_domain_for_dev(dev); 1194 1195 1195 1196 if (!domain || !domain->ops->page_response) ··· 1215 1214 */ 1216 1215 list_for_each_entry(evt, &param->fault_param->faults, list) { 1217 1216 prm = &evt->fault.prm; 1218 - pasid_valid = prm->flags & IOMMU_FAULT_PAGE_REQUEST_PASID_VALID; 1219 - 1220 - if ((pasid_valid && prm->pasid != msg->pasid) || 1221 - prm->grpid != msg->grpid) 1217 + if (prm->grpid != msg->grpid) 1222 1218 continue; 1223 1219 1224 - /* Sanitize the reply */ 1225 - msg->flags = pasid_valid ? IOMMU_PAGE_RESP_PASID_VALID : 0; 1220 + /* 1221 + * If the PASID is required, the corresponding request is 1222 + * matched using the group ID, the PASID valid bit and the PASID 1223 + * value. Otherwise only the group ID matches request and 1224 + * response. 1225 + */ 1226 + needs_pasid = prm->flags & IOMMU_FAULT_PAGE_RESPONSE_NEEDS_PASID; 1227 + if (needs_pasid && (!has_pasid || msg->pasid != prm->pasid)) 1228 + continue; 1229 + 1230 + if (!needs_pasid && has_pasid) { 1231 + /* No big deal, just clear it. */ 1232 + msg->flags &= ~IOMMU_PAGE_RESP_PASID_VALID; 1233 + msg->pasid = 0; 1234 + } 1226 1235 1227 1236 ret = domain->ops->page_response(dev, evt, msg); 1228 1237 list_del(&evt->list); ··· 2179 2168 return pgsize; 2180 2169 } 2181 2170 2182 - int __iommu_map(struct iommu_domain *domain, unsigned long iova, 2183 - phys_addr_t paddr, size_t size, int prot, gfp_t gfp) 2171 + static int __iommu_map(struct iommu_domain *domain, unsigned long iova, 2172 + phys_addr_t paddr, size_t size, int prot, gfp_t gfp) 2184 2173 { 2185 2174 const struct iommu_ops *ops = domain->ops; 2186 2175 unsigned long orig_iova = iova; ··· 2330 2319 } 2331 2320 EXPORT_SYMBOL_GPL(iommu_unmap_fast); 2332 2321 2333 - size_t __iommu_map_sg(struct iommu_domain *domain, unsigned long iova, 2334 - struct scatterlist *sg, unsigned int nents, int prot, 2335 - gfp_t gfp) 2322 + static size_t __iommu_map_sg(struct iommu_domain *domain, unsigned long iova, 2323 + struct scatterlist *sg, unsigned int nents, int prot, 2324 + gfp_t gfp) 2336 2325 { 2337 2326 size_t len = 0, mapped = 0; 2338 2327 phys_addr_t start;
+3 -1
drivers/iommu/iova.c
··· 811 811 for (i = 0 ; i < mag->size; ++i) { 812 812 struct iova *iova = private_find_iova(iovad, mag->pfns[i]); 813 813 814 - BUG_ON(!iova); 814 + if (WARN_ON(!iova)) 815 + continue; 816 + 815 817 private_free_iova(iovad, iova); 816 818 } 817 819
+12 -2
drivers/iommu/ipmmu-vmsa.c
··· 3 3 * IOMMU API for Renesas VMSA-compatible IPMMU 4 4 * Author: Laurent Pinchart <laurent.pinchart@ideasonboard.com> 5 5 * 6 - * Copyright (C) 2014 Renesas Electronics Corporation 6 + * Copyright (C) 2014-2020 Renesas Electronics Corporation 7 7 */ 8 8 9 9 #include <linux/bitmap.h> ··· 686 686 if (!domain) 687 687 return -ENODEV; 688 688 689 - return domain->iop->map(domain->iop, iova, paddr, size, prot); 689 + return domain->iop->map(domain->iop, iova, paddr, size, prot, gfp); 690 690 } 691 691 692 692 static size_t ipmmu_unmap(struct iommu_domain *io_domain, unsigned long iova, ··· 739 739 { .soc_id = "r8a774a1", }, 740 740 { .soc_id = "r8a774b1", }, 741 741 { .soc_id = "r8a774c0", }, 742 + { .soc_id = "r8a774e1", }, 742 743 { .soc_id = "r8a7795", }, 744 + { .soc_id = "r8a77961", }, 743 745 { .soc_id = "r8a7796", }, 744 746 { .soc_id = "r8a77965", }, 745 747 { .soc_id = "r8a77970", }, ··· 753 751 static const struct soc_device_attribute soc_rcar_gen3_whitelist[] = { 754 752 { .soc_id = "r8a774b1", }, 755 753 { .soc_id = "r8a774c0", }, 754 + { .soc_id = "r8a774e1", }, 756 755 { .soc_id = "r8a7795", .revision = "ES3.*" }, 756 + { .soc_id = "r8a77961", }, 757 757 { .soc_id = "r8a77965", }, 758 758 { .soc_id = "r8a77990", }, 759 759 { .soc_id = "r8a77995", }, ··· 967 963 .compatible = "renesas,ipmmu-r8a774c0", 968 964 .data = &ipmmu_features_rcar_gen3, 969 965 }, { 966 + .compatible = "renesas,ipmmu-r8a774e1", 967 + .data = &ipmmu_features_rcar_gen3, 968 + }, { 970 969 .compatible = "renesas,ipmmu-r8a7795", 971 970 .data = &ipmmu_features_rcar_gen3, 972 971 }, { 973 972 .compatible = "renesas,ipmmu-r8a7796", 973 + .data = &ipmmu_features_rcar_gen3, 974 + }, { 975 + .compatible = "renesas,ipmmu-r8a77961", 974 976 .data = &ipmmu_features_rcar_gen3, 975 977 }, { 976 978 .compatible = "renesas,ipmmu-r8a77965",
+3 -3
drivers/iommu/msm_iommu.c
··· 491 491 int ret; 492 492 493 493 spin_lock_irqsave(&priv->pgtlock, flags); 494 - ret = priv->iop->map(priv->iop, iova, pa, len, prot); 494 + ret = priv->iop->map(priv->iop, iova, pa, len, prot, GFP_ATOMIC); 495 495 spin_unlock_irqrestore(&priv->pgtlock, flags); 496 496 497 497 return ret; ··· 593 593 struct msm_iommu_dev **iommu, 594 594 struct of_phandle_args *spec) 595 595 { 596 - struct msm_iommu_ctx_dev *master = dev->archdata.iommu; 596 + struct msm_iommu_ctx_dev *master = dev_iommu_priv_get(dev); 597 597 int sid; 598 598 599 599 if (list_empty(&(*iommu)->ctx_list)) { 600 600 master = kzalloc(sizeof(*master), GFP_ATOMIC); 601 601 master->of_node = dev->of_node; 602 602 list_add(&master->list, &(*iommu)->ctx_list); 603 - dev->archdata.iommu = master; 603 + dev_iommu_priv_set(dev, master); 604 604 } 605 605 606 606 for (sid = 0; sid < master->num_mids; sid++)
+80 -32
drivers/iommu/mtk_iommu.c
··· 37 37 #define REG_MMU_INVLD_START_A 0x024 38 38 #define REG_MMU_INVLD_END_A 0x028 39 39 40 - #define REG_MMU_INV_SEL 0x038 40 + #define REG_MMU_INV_SEL_GEN2 0x02c 41 + #define REG_MMU_INV_SEL_GEN1 0x038 41 42 #define F_INVLD_EN0 BIT(0) 42 43 #define F_INVLD_EN1 BIT(1) 43 44 44 - #define REG_MMU_STANDARD_AXI_MODE 0x048 45 + #define REG_MMU_MISC_CTRL 0x048 46 + #define F_MMU_IN_ORDER_WR_EN_MASK (BIT(1) | BIT(17)) 47 + #define F_MMU_STANDARD_AXI_MODE_MASK (BIT(3) | BIT(19)) 48 + 45 49 #define REG_MMU_DCM_DIS 0x050 50 + #define REG_MMU_WR_LEN_CTRL 0x054 51 + #define F_MMU_WR_THROT_DIS_MASK (BIT(5) | BIT(21)) 46 52 47 53 #define REG_MMU_CTRL_REG 0x110 48 54 #define F_MMU_TF_PROT_TO_PROGRAM_ADDR (2 << 4) ··· 94 88 #define REG_MMU1_INVLD_PA 0x148 95 89 #define REG_MMU0_INT_ID 0x150 96 90 #define REG_MMU1_INT_ID 0x154 91 + #define F_MMU_INT_ID_COMM_ID(a) (((a) >> 9) & 0x7) 92 + #define F_MMU_INT_ID_SUB_COMM_ID(a) (((a) >> 7) & 0x3) 97 93 #define F_MMU_INT_ID_LARB_ID(a) (((a) >> 7) & 0x7) 98 94 #define F_MMU_INT_ID_PORT_ID(a) (((a) >> 2) & 0x1f) 99 95 100 - #define MTK_PROTECT_PA_ALIGN 128 96 + #define MTK_PROTECT_PA_ALIGN 256 101 97 102 98 /* 103 99 * Get the local arbiter ID and the portid within the larb arbiter ··· 107 99 */ 108 100 #define MTK_M4U_TO_LARB(id) (((id) >> 5) & 0xf) 109 101 #define MTK_M4U_TO_PORT(id) ((id) & 0x1f) 102 + 103 + #define HAS_4GB_MODE BIT(0) 104 + /* HW will use the EMI clock if there isn't the "bclk". */ 105 + #define HAS_BCLK BIT(1) 106 + #define HAS_VLD_PA_RNG BIT(2) 107 + #define RESET_AXI BIT(3) 108 + #define OUT_ORDER_WR_EN BIT(4) 109 + #define HAS_SUB_COMM BIT(5) 110 + #define WR_THROT_EN BIT(6) 111 + 112 + #define MTK_IOMMU_HAS_FLAG(pdata, _x) \ 113 + ((((pdata)->flags) & (_x)) == (_x)) 110 114 111 115 struct mtk_iommu_domain { 112 116 struct io_pgtable_cfg cfg; ··· 185 165 186 166 for_each_m4u(data) { 187 167 writel_relaxed(F_INVLD_EN1 | F_INVLD_EN0, 188 - data->base + REG_MMU_INV_SEL); 168 + data->base + data->plat_data->inv_sel_reg); 189 169 writel_relaxed(F_ALL_INVLD, data->base + REG_MMU_INVALIDATE); 190 170 wmb(); /* Make sure the tlb flush all done */ 191 171 } ··· 202 182 for_each_m4u(data) { 203 183 spin_lock_irqsave(&data->tlb_lock, flags); 204 184 writel_relaxed(F_INVLD_EN1 | F_INVLD_EN0, 205 - data->base + REG_MMU_INV_SEL); 185 + data->base + data->plat_data->inv_sel_reg); 206 186 207 187 writel_relaxed(iova, data->base + REG_MMU_INVLD_START_A); 208 188 writel_relaxed(iova + size - 1, ··· 246 226 struct mtk_iommu_data *data = dev_id; 247 227 struct mtk_iommu_domain *dom = data->m4u_dom; 248 228 u32 int_state, regval, fault_iova, fault_pa; 249 - unsigned int fault_larb, fault_port; 229 + unsigned int fault_larb, fault_port, sub_comm = 0; 250 230 bool layer, write; 251 231 252 232 /* Read error info from registers */ ··· 262 242 } 263 243 layer = fault_iova & F_MMU_FAULT_VA_LAYER_BIT; 264 244 write = fault_iova & F_MMU_FAULT_VA_WRITE_BIT; 265 - fault_larb = F_MMU_INT_ID_LARB_ID(regval); 266 245 fault_port = F_MMU_INT_ID_PORT_ID(regval); 267 - 268 - fault_larb = data->plat_data->larbid_remap[fault_larb]; 246 + if (MTK_IOMMU_HAS_FLAG(data->plat_data, HAS_SUB_COMM)) { 247 + fault_larb = F_MMU_INT_ID_COMM_ID(regval); 248 + sub_comm = F_MMU_INT_ID_SUB_COMM_ID(regval); 249 + } else { 250 + fault_larb = F_MMU_INT_ID_LARB_ID(regval); 251 + } 252 + fault_larb = data->plat_data->larbid_remap[fault_larb][sub_comm]; 269 253 270 254 if (report_iommu_fault(&dom->domain, data->dev, fault_iova, 271 255 write ? IOMMU_FAULT_WRITE : IOMMU_FAULT_READ)) { ··· 421 397 paddr |= BIT_ULL(32); 422 398 423 399 /* Synchronize with the tlb_lock */ 424 - return dom->iop->map(dom->iop, iova, paddr, size, prot); 400 + return dom->iop->map(dom->iop, iova, paddr, size, prot, gfp); 425 401 } 426 402 427 403 static size_t mtk_iommu_unmap(struct iommu_domain *domain, ··· 556 532 return ret; 557 533 } 558 534 559 - if (data->plat_data->m4u_plat == M4U_MT8173) 535 + if (data->plat_data->m4u_plat == M4U_MT8173) { 560 536 regval = F_MMU_PREFETCH_RT_REPLACE_MOD | 561 537 F_MMU_TF_PROT_TO_PROGRAM_ADDR_MT8173; 562 - else 563 - regval = F_MMU_TF_PROT_TO_PROGRAM_ADDR; 538 + } else { 539 + regval = readl_relaxed(data->base + REG_MMU_CTRL_REG); 540 + regval |= F_MMU_TF_PROT_TO_PROGRAM_ADDR; 541 + } 564 542 writel_relaxed(regval, data->base + REG_MMU_CTRL_REG); 565 543 566 544 regval = F_L2_MULIT_HIT_EN | ··· 589 563 upper_32_bits(data->protect_base); 590 564 writel_relaxed(regval, data->base + REG_MMU_IVRP_PADDR); 591 565 592 - if (data->enable_4GB && data->plat_data->has_vld_pa_rng) { 566 + if (data->enable_4GB && 567 + MTK_IOMMU_HAS_FLAG(data->plat_data, HAS_VLD_PA_RNG)) { 593 568 /* 594 569 * If 4GB mode is enabled, the validate PA range is from 595 570 * 0x1_0000_0000 to 0x1_ffff_ffff. here record bit[32:30]. ··· 599 572 writel_relaxed(regval, data->base + REG_MMU_VLD_PA_RNG); 600 573 } 601 574 writel_relaxed(0, data->base + REG_MMU_DCM_DIS); 575 + if (MTK_IOMMU_HAS_FLAG(data->plat_data, WR_THROT_EN)) { 576 + /* write command throttling mode */ 577 + regval = readl_relaxed(data->base + REG_MMU_WR_LEN_CTRL); 578 + regval &= ~F_MMU_WR_THROT_DIS_MASK; 579 + writel_relaxed(regval, data->base + REG_MMU_WR_LEN_CTRL); 580 + } 602 581 603 - if (data->plat_data->reset_axi) 604 - writel_relaxed(0, data->base + REG_MMU_STANDARD_AXI_MODE); 582 + if (MTK_IOMMU_HAS_FLAG(data->plat_data, RESET_AXI)) { 583 + /* The register is called STANDARD_AXI_MODE in this case */ 584 + regval = 0; 585 + } else { 586 + regval = readl_relaxed(data->base + REG_MMU_MISC_CTRL); 587 + regval &= ~F_MMU_STANDARD_AXI_MODE_MASK; 588 + if (MTK_IOMMU_HAS_FLAG(data->plat_data, OUT_ORDER_WR_EN)) 589 + regval &= ~F_MMU_IN_ORDER_WR_EN_MASK; 590 + } 591 + writel_relaxed(regval, data->base + REG_MMU_MISC_CTRL); 605 592 606 593 if (devm_request_irq(data->dev, data->irq, mtk_iommu_isr, 0, 607 594 dev_name(data->dev), (void *)data)) { ··· 657 616 658 617 /* Whether the current dram is over 4GB */ 659 618 data->enable_4GB = !!(max_pfn > (BIT_ULL(32) >> PAGE_SHIFT)); 660 - if (!data->plat_data->has_4gb_mode) 619 + if (!MTK_IOMMU_HAS_FLAG(data->plat_data, HAS_4GB_MODE)) 661 620 data->enable_4GB = false; 662 621 663 622 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); ··· 670 629 if (data->irq < 0) 671 630 return data->irq; 672 631 673 - if (data->plat_data->has_bclk) { 632 + if (MTK_IOMMU_HAS_FLAG(data->plat_data, HAS_BCLK)) { 674 633 data->bclk = devm_clk_get(dev, "bclk"); 675 634 if (IS_ERR(data->bclk)) 676 635 return PTR_ERR(data->bclk); ··· 759 718 struct mtk_iommu_suspend_reg *reg = &data->reg; 760 719 void __iomem *base = data->base; 761 720 762 - reg->standard_axi_mode = readl_relaxed(base + 763 - REG_MMU_STANDARD_AXI_MODE); 721 + reg->wr_len_ctrl = readl_relaxed(base + REG_MMU_WR_LEN_CTRL); 722 + reg->misc_ctrl = readl_relaxed(base + REG_MMU_MISC_CTRL); 764 723 reg->dcm_dis = readl_relaxed(base + REG_MMU_DCM_DIS); 765 724 reg->ctrl_reg = readl_relaxed(base + REG_MMU_CTRL_REG); 766 725 reg->int_control0 = readl_relaxed(base + REG_MMU_INT_CONTROL0); ··· 784 743 dev_err(data->dev, "Failed to enable clk(%d) in resume\n", ret); 785 744 return ret; 786 745 } 787 - writel_relaxed(reg->standard_axi_mode, 788 - base + REG_MMU_STANDARD_AXI_MODE); 746 + writel_relaxed(reg->wr_len_ctrl, base + REG_MMU_WR_LEN_CTRL); 747 + writel_relaxed(reg->misc_ctrl, base + REG_MMU_MISC_CTRL); 789 748 writel_relaxed(reg->dcm_dis, base + REG_MMU_DCM_DIS); 790 749 writel_relaxed(reg->ctrl_reg, base + REG_MMU_CTRL_REG); 791 750 writel_relaxed(reg->int_control0, base + REG_MMU_INT_CONTROL0); ··· 804 763 805 764 static const struct mtk_iommu_plat_data mt2712_data = { 806 765 .m4u_plat = M4U_MT2712, 807 - .has_4gb_mode = true, 808 - .has_bclk = true, 809 - .has_vld_pa_rng = true, 810 - .larbid_remap = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}, 766 + .flags = HAS_4GB_MODE | HAS_BCLK | HAS_VLD_PA_RNG, 767 + .inv_sel_reg = REG_MMU_INV_SEL_GEN1, 768 + .larbid_remap = {{0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}}, 769 + }; 770 + 771 + static const struct mtk_iommu_plat_data mt6779_data = { 772 + .m4u_plat = M4U_MT6779, 773 + .flags = HAS_SUB_COMM | OUT_ORDER_WR_EN | WR_THROT_EN, 774 + .inv_sel_reg = REG_MMU_INV_SEL_GEN2, 775 + .larbid_remap = {{0}, {1}, {2}, {3}, {5}, {7, 8}, {10}, {9}}, 811 776 }; 812 777 813 778 static const struct mtk_iommu_plat_data mt8173_data = { 814 779 .m4u_plat = M4U_MT8173, 815 - .has_4gb_mode = true, 816 - .has_bclk = true, 817 - .reset_axi = true, 818 - .larbid_remap = {0, 1, 2, 3, 4, 5}, /* Linear mapping. */ 780 + .flags = HAS_4GB_MODE | HAS_BCLK | RESET_AXI, 781 + .inv_sel_reg = REG_MMU_INV_SEL_GEN1, 782 + .larbid_remap = {{0}, {1}, {2}, {3}, {4}, {5}}, /* Linear mapping. */ 819 783 }; 820 784 821 785 static const struct mtk_iommu_plat_data mt8183_data = { 822 786 .m4u_plat = M4U_MT8183, 823 - .reset_axi = true, 824 - .larbid_remap = {0, 4, 5, 6, 7, 2, 3, 1}, 787 + .flags = RESET_AXI, 788 + .inv_sel_reg = REG_MMU_INV_SEL_GEN1, 789 + .larbid_remap = {{0}, {4}, {5}, {6}, {7}, {2}, {3}, {1}}, 825 790 }; 826 791 827 792 static const struct of_device_id mtk_iommu_of_ids[] = { 828 793 { .compatible = "mediatek,mt2712-m4u", .data = &mt2712_data}, 794 + { .compatible = "mediatek,mt6779-m4u", .data = &mt6779_data}, 829 795 { .compatible = "mediatek,mt8173-m4u", .data = &mt8173_data}, 830 796 { .compatible = "mediatek,mt8183-m4u", .data = &mt8183_data}, 831 797 {}
+15 -8
drivers/iommu/mtk_iommu.h
··· 15 15 #include <linux/iommu.h> 16 16 #include <linux/list.h> 17 17 #include <linux/spinlock.h> 18 + #include <linux/dma-mapping.h> 18 19 #include <soc/mediatek/smi.h> 19 20 21 + #define MTK_LARB_COM_MAX 8 22 + #define MTK_LARB_SUBCOM_MAX 4 23 + 20 24 struct mtk_iommu_suspend_reg { 21 - u32 standard_axi_mode; 25 + union { 26 + u32 standard_axi_mode;/* v1 */ 27 + u32 misc_ctrl;/* v2 */ 28 + }; 22 29 u32 dcm_dis; 23 30 u32 ctrl_reg; 24 31 u32 int_control0; 25 32 u32 int_main_control; 26 33 u32 ivrp_paddr; 27 34 u32 vld_pa_rng; 35 + u32 wr_len_ctrl; 28 36 }; 29 37 30 38 enum mtk_iommu_plat { 31 39 M4U_MT2701, 32 40 M4U_MT2712, 41 + M4U_MT6779, 33 42 M4U_MT8173, 34 43 M4U_MT8183, 35 44 }; 36 45 37 46 struct mtk_iommu_plat_data { 38 47 enum mtk_iommu_plat m4u_plat; 39 - bool has_4gb_mode; 40 - 41 - /* HW will use the EMI clock if there isn't the "bclk". */ 42 - bool has_bclk; 43 - bool has_vld_pa_rng; 44 - bool reset_axi; 45 - unsigned char larbid_remap[MTK_LARB_NR_MAX]; 48 + u32 flags; 49 + u32 inv_sel_reg; 50 + unsigned char larbid_remap[MTK_LARB_COM_MAX][MTK_LARB_SUBCOM_MAX]; 46 51 }; 47 52 48 53 struct mtk_iommu_domain; ··· 66 61 67 62 struct iommu_device iommu; 68 63 const struct mtk_iommu_plat_data *plat_data; 64 + 65 + struct dma_iommu_mapping *mapping; /* For mtk_iommu_v1.c */ 69 66 70 67 struct list_head list; 71 68 struct mtk_smi_larb_iommu larb_imu[MTK_LARB_NR_MAX];
+4 -6
drivers/iommu/mtk_iommu_v1.c
··· 269 269 int ret; 270 270 271 271 /* Only allow the domain created internally. */ 272 - mtk_mapping = data->dev->archdata.iommu; 272 + mtk_mapping = data->mapping; 273 273 if (mtk_mapping->domain != domain) 274 274 return 0; 275 275 ··· 369 369 struct mtk_iommu_data *data; 370 370 struct platform_device *m4updev; 371 371 struct dma_iommu_mapping *mtk_mapping; 372 - struct device *m4udev; 373 372 int ret; 374 373 375 374 if (args->args_count != 1) { ··· 400 401 return ret; 401 402 402 403 data = dev_iommu_priv_get(dev); 403 - m4udev = data->dev; 404 - mtk_mapping = m4udev->archdata.iommu; 404 + mtk_mapping = data->mapping; 405 405 if (!mtk_mapping) { 406 406 /* MTK iommu support 4GB iova address space. */ 407 407 mtk_mapping = arm_iommu_create_mapping(&platform_bus_type, ··· 408 410 if (IS_ERR(mtk_mapping)) 409 411 return PTR_ERR(mtk_mapping); 410 412 411 - m4udev->archdata.iommu = mtk_mapping; 413 + data->mapping = mtk_mapping; 412 414 } 413 415 414 416 return 0; ··· 457 459 int err; 458 460 459 461 data = dev_iommu_priv_get(dev); 460 - mtk_mapping = data->dev->archdata.iommu; 462 + mtk_mapping = data->mapping; 461 463 462 464 err = arm_iommu_attach_device(dev, mtk_mapping); 463 465 if (err)
+3
drivers/iommu/omap-iommu-debug.c
··· 98 98 mutex_lock(&iommu_debug_lock); 99 99 100 100 bytes = omap_iommu_dump_ctx(obj, p, count); 101 + if (bytes < 0) 102 + goto err; 101 103 bytes = simple_read_from_buffer(userbuf, count, ppos, buf, bytes); 102 104 105 + err: 103 106 mutex_unlock(&iommu_debug_lock); 104 107 kfree(buf); 105 108
+11 -11
drivers/iommu/omap-iommu.c
··· 3 3 * omap iommu: tlb and pagetable primitives 4 4 * 5 5 * Copyright (C) 2008-2010 Nokia Corporation 6 - * Copyright (C) 2013-2017 Texas Instruments Incorporated - http://www.ti.com/ 6 + * Copyright (C) 2013-2017 Texas Instruments Incorporated - https://www.ti.com/ 7 7 * 8 8 * Written by Hiroshi DOYU <Hiroshi.DOYU@nokia.com>, 9 9 * Paul Mundt and Toshihiro Kobayashi ··· 71 71 **/ 72 72 void omap_iommu_save_ctx(struct device *dev) 73 73 { 74 - struct omap_iommu_arch_data *arch_data = dev->archdata.iommu; 74 + struct omap_iommu_arch_data *arch_data = dev_iommu_priv_get(dev); 75 75 struct omap_iommu *obj; 76 76 u32 *p; 77 77 int i; ··· 101 101 **/ 102 102 void omap_iommu_restore_ctx(struct device *dev) 103 103 { 104 - struct omap_iommu_arch_data *arch_data = dev->archdata.iommu; 104 + struct omap_iommu_arch_data *arch_data = dev_iommu_priv_get(dev); 105 105 struct omap_iommu *obj; 106 106 u32 *p; 107 107 int i; ··· 1398 1398 1399 1399 static int omap_iommu_count(struct device *dev) 1400 1400 { 1401 - struct omap_iommu_arch_data *arch_data = dev->archdata.iommu; 1401 + struct omap_iommu_arch_data *arch_data = dev_iommu_priv_get(dev); 1402 1402 int count = 0; 1403 1403 1404 1404 while (arch_data->iommu_dev) { ··· 1459 1459 static int 1460 1460 omap_iommu_attach_dev(struct iommu_domain *domain, struct device *dev) 1461 1461 { 1462 + struct omap_iommu_arch_data *arch_data = dev_iommu_priv_get(dev); 1462 1463 struct omap_iommu_domain *omap_domain = to_omap_domain(domain); 1463 - struct omap_iommu_arch_data *arch_data = dev->archdata.iommu; 1464 1464 struct omap_iommu_device *iommu; 1465 1465 struct omap_iommu *oiommu; 1466 1466 int ret = 0; ··· 1524 1524 static void _omap_iommu_detach_dev(struct omap_iommu_domain *omap_domain, 1525 1525 struct device *dev) 1526 1526 { 1527 - struct omap_iommu_arch_data *arch_data = dev->archdata.iommu; 1527 + struct omap_iommu_arch_data *arch_data = dev_iommu_priv_get(dev); 1528 1528 struct omap_iommu_device *iommu = omap_domain->iommus; 1529 1529 struct omap_iommu *oiommu; 1530 1530 int i; ··· 1650 1650 int num_iommus, i; 1651 1651 1652 1652 /* 1653 - * Allocate the archdata iommu structure for DT-based devices. 1653 + * Allocate the per-device iommu structure for DT-based devices. 1654 1654 * 1655 1655 * TODO: Simplify this when removing non-DT support completely from the 1656 1656 * IOMMU users. ··· 1698 1698 of_node_put(np); 1699 1699 } 1700 1700 1701 - dev->archdata.iommu = arch_data; 1701 + dev_iommu_priv_set(dev, arch_data); 1702 1702 1703 1703 /* 1704 1704 * use the first IOMMU alone for the sysfs device linking. ··· 1712 1712 1713 1713 static void omap_iommu_release_device(struct device *dev) 1714 1714 { 1715 - struct omap_iommu_arch_data *arch_data = dev->archdata.iommu; 1715 + struct omap_iommu_arch_data *arch_data = dev_iommu_priv_get(dev); 1716 1716 1717 1717 if (!dev->of_node || !arch_data) 1718 1718 return; 1719 1719 1720 - dev->archdata.iommu = NULL; 1720 + dev_iommu_priv_set(dev, NULL); 1721 1721 kfree(arch_data); 1722 1722 1723 1723 } 1724 1724 1725 1725 static struct iommu_group *omap_iommu_device_group(struct device *dev) 1726 1726 { 1727 - struct omap_iommu_arch_data *arch_data = dev->archdata.iommu; 1727 + struct omap_iommu_arch_data *arch_data = dev_iommu_priv_get(dev); 1728 1728 struct iommu_group *group = ERR_PTR(-EINVAL); 1729 1729 1730 1730 if (!arch_data)
+28 -38
drivers/iommu/qcom_iommu.c drivers/iommu/arm/arm-smmu/qcom_iommu.c
··· 37 37 38 38 #define SMMU_INTR_SEL_NS 0x2000 39 39 40 + enum qcom_iommu_clk { 41 + CLK_IFACE, 42 + CLK_BUS, 43 + CLK_TBU, 44 + CLK_NUM, 45 + }; 46 + 40 47 struct qcom_iommu_ctx; 41 48 42 49 struct qcom_iommu_dev { 43 50 /* IOMMU core code handle */ 44 51 struct iommu_device iommu; 45 52 struct device *dev; 46 - struct clk *iface_clk; 47 - struct clk *bus_clk; 53 + struct clk_bulk_data clks[CLK_NUM]; 48 54 void __iomem *local_base; 49 55 u32 sec_id; 50 56 u8 num_ctxs; ··· 307 301 ARM_SMMU_SCTLR_M | ARM_SMMU_SCTLR_S1_ASIDPNE | 308 302 ARM_SMMU_SCTLR_CFCFG; 309 303 310 - if (IS_ENABLED(CONFIG_BIG_ENDIAN)) 304 + if (IS_ENABLED(CONFIG_CPU_BIG_ENDIAN)) 311 305 reg |= ARM_SMMU_SCTLR_E; 312 306 313 307 iommu_writel(ctx, ARM_SMMU_CB_SCTLR, reg); ··· 444 438 return -ENODEV; 445 439 446 440 spin_lock_irqsave(&qcom_domain->pgtbl_lock, flags); 447 - ret = ops->map(ops, iova, paddr, size, prot); 441 + ret = ops->map(ops, iova, paddr, size, prot, GFP_ATOMIC); 448 442 spin_unlock_irqrestore(&qcom_domain->pgtbl_lock, flags); 449 443 return ret; 450 444 } ··· 619 613 .pgsize_bitmap = SZ_4K | SZ_64K | SZ_1M | SZ_16M, 620 614 }; 621 615 622 - static int qcom_iommu_enable_clocks(struct qcom_iommu_dev *qcom_iommu) 623 - { 624 - int ret; 625 - 626 - ret = clk_prepare_enable(qcom_iommu->iface_clk); 627 - if (ret) { 628 - dev_err(qcom_iommu->dev, "Couldn't enable iface_clk\n"); 629 - return ret; 630 - } 631 - 632 - ret = clk_prepare_enable(qcom_iommu->bus_clk); 633 - if (ret) { 634 - dev_err(qcom_iommu->dev, "Couldn't enable bus_clk\n"); 635 - clk_disable_unprepare(qcom_iommu->iface_clk); 636 - return ret; 637 - } 638 - 639 - return 0; 640 - } 641 - 642 - static void qcom_iommu_disable_clocks(struct qcom_iommu_dev *qcom_iommu) 643 - { 644 - clk_disable_unprepare(qcom_iommu->bus_clk); 645 - clk_disable_unprepare(qcom_iommu->iface_clk); 646 - } 647 - 648 616 static int qcom_iommu_sec_ptbl_init(struct device *dev) 649 617 { 650 618 size_t psize = 0; ··· 775 795 struct qcom_iommu_dev *qcom_iommu; 776 796 struct device *dev = &pdev->dev; 777 797 struct resource *res; 798 + struct clk *clk; 778 799 int ret, max_asid = 0; 779 800 780 801 /* find the max asid (which is 1:1 to ctx bank idx), so we know how ··· 798 817 return PTR_ERR(qcom_iommu->local_base); 799 818 } 800 819 801 - qcom_iommu->iface_clk = devm_clk_get(dev, "iface"); 802 - if (IS_ERR(qcom_iommu->iface_clk)) { 820 + clk = devm_clk_get(dev, "iface"); 821 + if (IS_ERR(clk)) { 803 822 dev_err(dev, "failed to get iface clock\n"); 804 - return PTR_ERR(qcom_iommu->iface_clk); 823 + return PTR_ERR(clk); 805 824 } 825 + qcom_iommu->clks[CLK_IFACE].clk = clk; 806 826 807 - qcom_iommu->bus_clk = devm_clk_get(dev, "bus"); 808 - if (IS_ERR(qcom_iommu->bus_clk)) { 827 + clk = devm_clk_get(dev, "bus"); 828 + if (IS_ERR(clk)) { 809 829 dev_err(dev, "failed to get bus clock\n"); 810 - return PTR_ERR(qcom_iommu->bus_clk); 830 + return PTR_ERR(clk); 811 831 } 832 + qcom_iommu->clks[CLK_BUS].clk = clk; 833 + 834 + clk = devm_clk_get_optional(dev, "tbu"); 835 + if (IS_ERR(clk)) { 836 + dev_err(dev, "failed to get tbu clock\n"); 837 + return PTR_ERR(clk); 838 + } 839 + qcom_iommu->clks[CLK_TBU].clk = clk; 812 840 813 841 if (of_property_read_u32(dev->of_node, "qcom,iommu-secure-id", 814 842 &qcom_iommu->sec_id)) { ··· 889 899 { 890 900 struct qcom_iommu_dev *qcom_iommu = dev_get_drvdata(dev); 891 901 892 - return qcom_iommu_enable_clocks(qcom_iommu); 902 + return clk_bulk_prepare_enable(CLK_NUM, qcom_iommu->clks); 893 903 } 894 904 895 905 static int __maybe_unused qcom_iommu_suspend(struct device *dev) 896 906 { 897 907 struct qcom_iommu_dev *qcom_iommu = dev_get_drvdata(dev); 898 908 899 - qcom_iommu_disable_clocks(qcom_iommu); 909 + clk_bulk_disable_unprepare(CLK_NUM, qcom_iommu->clks); 900 910 901 911 return 0; 902 912 }
+4 -4
drivers/iommu/rockchip-iommu.c
··· 836 836 837 837 static struct rk_iommu *rk_iommu_from_dev(struct device *dev) 838 838 { 839 - struct rk_iommudata *data = dev->archdata.iommu; 839 + struct rk_iommudata *data = dev_iommu_priv_get(dev); 840 840 841 841 return data ? data->iommu : NULL; 842 842 } ··· 1059 1059 struct rk_iommudata *data; 1060 1060 struct rk_iommu *iommu; 1061 1061 1062 - data = dev->archdata.iommu; 1062 + data = dev_iommu_priv_get(dev); 1063 1063 if (!data) 1064 1064 return ERR_PTR(-ENODEV); 1065 1065 ··· 1073 1073 1074 1074 static void rk_iommu_release_device(struct device *dev) 1075 1075 { 1076 - struct rk_iommudata *data = dev->archdata.iommu; 1076 + struct rk_iommudata *data = dev_iommu_priv_get(dev); 1077 1077 1078 1078 device_link_del(data->link); 1079 1079 } ··· 1100 1100 iommu_dev = of_find_device_by_node(args->np); 1101 1101 1102 1102 data->iommu = platform_get_drvdata(iommu_dev); 1103 - dev->archdata.iommu = data; 1103 + dev_iommu_priv_set(dev, data); 1104 1104 1105 1105 platform_device_put(iommu_dev); 1106 1106
+4 -4
drivers/iommu/tegra-gart.c
··· 113 113 114 114 if (gart->active_domain && gart->active_domain != domain) { 115 115 ret = -EBUSY; 116 - } else if (dev->archdata.iommu != domain) { 117 - dev->archdata.iommu = domain; 116 + } else if (dev_iommu_priv_get(dev) != domain) { 117 + dev_iommu_priv_set(dev, domain); 118 118 gart->active_domain = domain; 119 119 gart->active_devices++; 120 120 } ··· 131 131 132 132 spin_lock(&gart->dom_lock); 133 133 134 - if (dev->archdata.iommu == domain) { 135 - dev->archdata.iommu = NULL; 134 + if (dev_iommu_priv_get(dev) == domain) { 135 + dev_iommu_priv_set(dev, NULL); 136 136 137 137 if (--gart->active_devices == 0) 138 138 gart->active_domain = NULL;
+4 -4
drivers/iommu/tegra-smmu.c
··· 465 465 static int tegra_smmu_attach_dev(struct iommu_domain *domain, 466 466 struct device *dev) 467 467 { 468 - struct tegra_smmu *smmu = dev->archdata.iommu; 468 + struct tegra_smmu *smmu = dev_iommu_priv_get(dev); 469 469 struct tegra_smmu_as *as = to_smmu_as(domain); 470 470 struct device_node *np = dev->of_node; 471 471 struct of_phandle_args args; ··· 780 780 * supported by the Linux kernel, so abort after the 781 781 * first match. 782 782 */ 783 - dev->archdata.iommu = smmu; 783 + dev_iommu_priv_set(dev, smmu); 784 784 785 785 break; 786 786 } ··· 797 797 798 798 static void tegra_smmu_release_device(struct device *dev) 799 799 { 800 - dev->archdata.iommu = NULL; 800 + dev_iommu_priv_set(dev, NULL); 801 801 } 802 802 803 803 static const struct tegra_smmu_group_soc * ··· 856 856 static struct iommu_group *tegra_smmu_device_group(struct device *dev) 857 857 { 858 858 struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(dev); 859 - struct tegra_smmu *smmu = dev->archdata.iommu; 859 + struct tegra_smmu *smmu = dev_iommu_priv_get(dev); 860 860 struct iommu_group *group; 861 861 862 862 group = tegra_smmu_group_get(smmu, fwspec->ids[0]);
+3 -1
drivers/media/platform/s5p-mfc/s5p_mfc_iommu.h
··· 9 9 10 10 #if defined(CONFIG_EXYNOS_IOMMU) 11 11 12 + #include <linux/iommu.h> 13 + 12 14 static inline bool exynos_is_iommu_available(struct device *dev) 13 15 { 14 - return dev->archdata.iommu != NULL; 16 + return dev_iommu_priv_get(dev) != NULL; 15 17 } 16 18 17 19 #else
+22
drivers/memory/mtk-smi.c
··· 239 239 .larb_direct_to_common_mask = BIT(8) | BIT(9), /* bdpsys */ 240 240 }; 241 241 242 + static const struct mtk_smi_larb_gen mtk_smi_larb_mt6779 = { 243 + .config_port = mtk_smi_larb_config_port_gen2_general, 244 + .larb_direct_to_common_mask = 245 + BIT(4) | BIT(6) | BIT(11) | BIT(12) | BIT(13), 246 + /* DUMMY | IPU0 | IPU1 | CCU | MDLA */ 247 + }; 248 + 242 249 static const struct mtk_smi_larb_gen mtk_smi_larb_mt8183 = { 243 250 .has_gals = true, 244 251 .config_port = mtk_smi_larb_config_port_gen2_general, ··· 265 258 { 266 259 .compatible = "mediatek,mt2712-smi-larb", 267 260 .data = &mtk_smi_larb_mt2712 261 + }, 262 + { 263 + .compatible = "mediatek,mt6779-smi-larb", 264 + .data = &mtk_smi_larb_mt6779 268 265 }, 269 266 { 270 267 .compatible = "mediatek,mt8183-smi-larb", ··· 399 388 .gen = MTK_SMI_GEN2, 400 389 }; 401 390 391 + static const struct mtk_smi_common_plat mtk_smi_common_mt6779 = { 392 + .gen = MTK_SMI_GEN2, 393 + .has_gals = true, 394 + .bus_sel = F_MMU1_LARB(1) | F_MMU1_LARB(2) | F_MMU1_LARB(4) | 395 + F_MMU1_LARB(5) | F_MMU1_LARB(6) | F_MMU1_LARB(7), 396 + }; 397 + 402 398 static const struct mtk_smi_common_plat mtk_smi_common_mt8183 = { 403 399 .gen = MTK_SMI_GEN2, 404 400 .has_gals = true, ··· 425 407 { 426 408 .compatible = "mediatek,mt2712-smi-common", 427 409 .data = &mtk_smi_common_gen2, 410 + }, 411 + { 412 + .compatible = "mediatek,mt6779-smi-common", 413 + .data = &mtk_smi_common_mt6779, 428 414 }, 429 415 { 430 416 .compatible = "mediatek,mt8183-smi-common",
+206
include/dt-bindings/memory/mt6779-larb-port.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0 */ 2 + /* 3 + * Copyright (c) 2019 MediaTek Inc. 4 + * Author: Chao Hao <chao.hao@mediatek.com> 5 + */ 6 + 7 + #ifndef _DTS_IOMMU_PORT_MT6779_H_ 8 + #define _DTS_IOMMU_PORT_MT6779_H_ 9 + 10 + #define MTK_M4U_ID(larb, port) (((larb) << 5) | (port)) 11 + 12 + #define M4U_LARB0_ID 0 13 + #define M4U_LARB1_ID 1 14 + #define M4U_LARB2_ID 2 15 + #define M4U_LARB3_ID 3 16 + #define M4U_LARB4_ID 4 17 + #define M4U_LARB5_ID 5 18 + #define M4U_LARB6_ID 6 19 + #define M4U_LARB7_ID 7 20 + #define M4U_LARB8_ID 8 21 + #define M4U_LARB9_ID 9 22 + #define M4U_LARB10_ID 10 23 + #define M4U_LARB11_ID 11 24 + 25 + /* larb0 */ 26 + #define M4U_PORT_DISP_POSTMASK0 MTK_M4U_ID(M4U_LARB0_ID, 0) 27 + #define M4U_PORT_DISP_OVL0_HDR MTK_M4U_ID(M4U_LARB0_ID, 1) 28 + #define M4U_PORT_DISP_OVL1_HDR MTK_M4U_ID(M4U_LARB0_ID, 2) 29 + #define M4U_PORT_DISP_OVL0 MTK_M4U_ID(M4U_LARB0_ID, 3) 30 + #define M4U_PORT_DISP_OVL1 MTK_M4U_ID(M4U_LARB0_ID, 4) 31 + #define M4U_PORT_DISP_PVRIC0 MTK_M4U_ID(M4U_LARB0_ID, 5) 32 + #define M4U_PORT_DISP_RDMA0 MTK_M4U_ID(M4U_LARB0_ID, 6) 33 + #define M4U_PORT_DISP_WDMA0 MTK_M4U_ID(M4U_LARB0_ID, 7) 34 + #define M4U_PORT_DISP_FAKE0 MTK_M4U_ID(M4U_LARB0_ID, 8) 35 + 36 + /* larb1 */ 37 + #define M4U_PORT_DISP_OVL0_2L_HDR MTK_M4U_ID(M4U_LARB1_ID, 0) 38 + #define M4U_PORT_DISP_OVL1_2L_HDR MTK_M4U_ID(M4U_LARB1_ID, 1) 39 + #define M4U_PORT_DISP_OVL0_2L MTK_M4U_ID(M4U_LARB1_ID, 2) 40 + #define M4U_PORT_DISP_OVL1_2L MTK_M4U_ID(M4U_LARB1_ID, 3) 41 + #define M4U_PORT_DISP_RDMA1 MTK_M4U_ID(M4U_LARB1_ID, 4) 42 + #define M4U_PORT_MDP_PVRIC0 MTK_M4U_ID(M4U_LARB1_ID, 5) 43 + #define M4U_PORT_MDP_PVRIC1 MTK_M4U_ID(M4U_LARB1_ID, 6) 44 + #define M4U_PORT_MDP_RDMA0 MTK_M4U_ID(M4U_LARB1_ID, 7) 45 + #define M4U_PORT_MDP_RDMA1 MTK_M4U_ID(M4U_LARB1_ID, 8) 46 + #define M4U_PORT_MDP_WROT0_R MTK_M4U_ID(M4U_LARB1_ID, 9) 47 + #define M4U_PORT_MDP_WROT0_W MTK_M4U_ID(M4U_LARB1_ID, 10) 48 + #define M4U_PORT_MDP_WROT1_R MTK_M4U_ID(M4U_LARB1_ID, 11) 49 + #define M4U_PORT_MDP_WROT1_W MTK_M4U_ID(M4U_LARB1_ID, 12) 50 + #define M4U_PORT_DISP_FAKE1 MTK_M4U_ID(M4U_LARB1_ID, 13) 51 + 52 + /* larb2-VDEC */ 53 + #define M4U_PORT_HW_VDEC_MC_EXT MTK_M4U_ID(M4U_LARB2_ID, 0) 54 + #define M4U_PORT_HW_VDEC_UFO_EXT MTK_M4U_ID(M4U_LARB2_ID, 1) 55 + #define M4U_PORT_HW_VDEC_PP_EXT MTK_M4U_ID(M4U_LARB2_ID, 2) 56 + #define M4U_PORT_HW_VDEC_PRED_RD_EXT MTK_M4U_ID(M4U_LARB2_ID, 3) 57 + #define M4U_PORT_HW_VDEC_PRED_WR_EXT MTK_M4U_ID(M4U_LARB2_ID, 4) 58 + #define M4U_PORT_HW_VDEC_PPWRAP_EXT MTK_M4U_ID(M4U_LARB2_ID, 5) 59 + #define M4U_PORT_HW_VDEC_TILE_EXT MTK_M4U_ID(M4U_LARB2_ID, 6) 60 + #define M4U_PORT_HW_VDEC_VLD_EXT MTK_M4U_ID(M4U_LARB2_ID, 7) 61 + #define M4U_PORT_HW_VDEC_VLD2_EXT MTK_M4U_ID(M4U_LARB2_ID, 8) 62 + #define M4U_PORT_HW_VDEC_AVC_MV_EXT MTK_M4U_ID(M4U_LARB2_ID, 9) 63 + #define M4U_PORT_HW_VDEC_UFO_ENC_EXT MTK_M4U_ID(M4U_LARB2_ID, 10) 64 + #define M4U_PORT_HW_VDEC_RG_CTRL_DMA_EXT MTK_M4U_ID(M4U_LARB2_ID, 11) 65 + 66 + /* larb3-VENC */ 67 + #define M4U_PORT_VENC_RCPU MTK_M4U_ID(M4U_LARB3_ID, 0) 68 + #define M4U_PORT_VENC_REC MTK_M4U_ID(M4U_LARB3_ID, 1) 69 + #define M4U_PORT_VENC_BSDMA MTK_M4U_ID(M4U_LARB3_ID, 2) 70 + #define M4U_PORT_VENC_SV_COMV MTK_M4U_ID(M4U_LARB3_ID, 3) 71 + #define M4U_PORT_VENC_RD_COMV MTK_M4U_ID(M4U_LARB3_ID, 4) 72 + #define M4U_PORT_VENC_NBM_RDMA MTK_M4U_ID(M4U_LARB3_ID, 5) 73 + #define M4U_PORT_VENC_NBM_RDMA_LITE MTK_M4U_ID(M4U_LARB3_ID, 6) 74 + #define M4U_PORT_JPGENC_Y_RDMA MTK_M4U_ID(M4U_LARB3_ID, 7) 75 + #define M4U_PORT_JPGENC_C_RDMA MTK_M4U_ID(M4U_LARB3_ID, 8) 76 + #define M4U_PORT_JPGENC_Q_TABLE MTK_M4U_ID(M4U_LARB3_ID, 9) 77 + #define M4U_PORT_JPGENC_BSDMA MTK_M4U_ID(M4U_LARB3_ID, 10) 78 + #define M4U_PORT_JPGDEC_WDMA MTK_M4U_ID(M4U_LARB3_ID, 11) 79 + #define M4U_PORT_JPGDEC_BSDMA MTK_M4U_ID(M4U_LARB3_ID, 12) 80 + #define M4U_PORT_VENC_NBM_WDMA MTK_M4U_ID(M4U_LARB3_ID, 13) 81 + #define M4U_PORT_VENC_NBM_WDMA_LITE MTK_M4U_ID(M4U_LARB3_ID, 14) 82 + #define M4U_PORT_VENC_CUR_LUMA MTK_M4U_ID(M4U_LARB3_ID, 15) 83 + #define M4U_PORT_VENC_CUR_CHROMA MTK_M4U_ID(M4U_LARB3_ID, 16) 84 + #define M4U_PORT_VENC_REF_LUMA MTK_M4U_ID(M4U_LARB3_ID, 17) 85 + #define M4U_PORT_VENC_REF_CHROMA MTK_M4U_ID(M4U_LARB3_ID, 18) 86 + 87 + /* larb4-dummy */ 88 + 89 + /* larb5-IMG */ 90 + #define M4U_PORT_IMGI_D1 MTK_M4U_ID(M4U_LARB5_ID, 0) 91 + #define M4U_PORT_IMGBI_D1 MTK_M4U_ID(M4U_LARB5_ID, 1) 92 + #define M4U_PORT_DMGI_D1 MTK_M4U_ID(M4U_LARB5_ID, 2) 93 + #define M4U_PORT_DEPI_D1 MTK_M4U_ID(M4U_LARB5_ID, 3) 94 + #define M4U_PORT_LCEI_D1 MTK_M4U_ID(M4U_LARB5_ID, 4) 95 + #define M4U_PORT_SMTI_D1 MTK_M4U_ID(M4U_LARB5_ID, 5) 96 + #define M4U_PORT_SMTO_D2 MTK_M4U_ID(M4U_LARB5_ID, 6) 97 + #define M4U_PORT_SMTO_D1 MTK_M4U_ID(M4U_LARB5_ID, 7) 98 + #define M4U_PORT_CRZO_D1 MTK_M4U_ID(M4U_LARB5_ID, 8) 99 + #define M4U_PORT_IMG3O_D1 MTK_M4U_ID(M4U_LARB5_ID, 9) 100 + #define M4U_PORT_VIPI_D1 MTK_M4U_ID(M4U_LARB5_ID, 10) 101 + #define M4U_PORT_WPE_RDMA1 MTK_M4U_ID(M4U_LARB5_ID, 11) 102 + #define M4U_PORT_WPE_RDMA0 MTK_M4U_ID(M4U_LARB5_ID, 12) 103 + #define M4U_PORT_WPE_WDMA MTK_M4U_ID(M4U_LARB5_ID, 13) 104 + #define M4U_PORT_TIMGO_D1 MTK_M4U_ID(M4U_LARB5_ID, 14) 105 + #define M4U_PORT_MFB_RDMA0 MTK_M4U_ID(M4U_LARB5_ID, 15) 106 + #define M4U_PORT_MFB_RDMA1 MTK_M4U_ID(M4U_LARB5_ID, 16) 107 + #define M4U_PORT_MFB_RDMA2 MTK_M4U_ID(M4U_LARB5_ID, 17) 108 + #define M4U_PORT_MFB_RDMA3 MTK_M4U_ID(M4U_LARB5_ID, 18) 109 + #define M4U_PORT_MFB_WDMA MTK_M4U_ID(M4U_LARB5_ID, 19) 110 + #define M4U_PORT_RESERVE1 MTK_M4U_ID(M4U_LARB5_ID, 20) 111 + #define M4U_PORT_RESERVE2 MTK_M4U_ID(M4U_LARB5_ID, 21) 112 + #define M4U_PORT_RESERVE3 MTK_M4U_ID(M4U_LARB5_ID, 22) 113 + #define M4U_PORT_RESERVE4 MTK_M4U_ID(M4U_LARB5_ID, 23) 114 + #define M4U_PORT_RESERVE5 MTK_M4U_ID(M4U_LARB5_ID, 24) 115 + #define M4U_PORT_RESERVE6 MTK_M4U_ID(M4U_LARB5_ID, 25) 116 + 117 + /* larb6-IMG-VPU */ 118 + #define M4U_PORT_IMG_IPUO MTK_M4U_ID(M4U_LARB6_ID, 0) 119 + #define M4U_PORT_IMG_IPU3O MTK_M4U_ID(M4U_LARB6_ID, 1) 120 + #define M4U_PORT_IMG_IPUI MTK_M4U_ID(M4U_LARB6_ID, 2) 121 + 122 + /* larb7-DVS */ 123 + #define M4U_PORT_DVS_RDMA MTK_M4U_ID(M4U_LARB7_ID, 0) 124 + #define M4U_PORT_DVS_WDMA MTK_M4U_ID(M4U_LARB7_ID, 1) 125 + #define M4U_PORT_DVP_RDMA MTK_M4U_ID(M4U_LARB7_ID, 2) 126 + #define M4U_PORT_DVP_WDMA MTK_M4U_ID(M4U_LARB7_ID, 3) 127 + 128 + /* larb8-IPESYS */ 129 + #define M4U_PORT_FDVT_RDA MTK_M4U_ID(M4U_LARB8_ID, 0) 130 + #define M4U_PORT_FDVT_RDB MTK_M4U_ID(M4U_LARB8_ID, 1) 131 + #define M4U_PORT_FDVT_WRA MTK_M4U_ID(M4U_LARB8_ID, 2) 132 + #define M4U_PORT_FDVT_WRB MTK_M4U_ID(M4U_LARB8_ID, 3) 133 + #define M4U_PORT_FE_RD0 MTK_M4U_ID(M4U_LARB8_ID, 4) 134 + #define M4U_PORT_FE_RD1 MTK_M4U_ID(M4U_LARB8_ID, 5) 135 + #define M4U_PORT_FE_WR0 MTK_M4U_ID(M4U_LARB8_ID, 6) 136 + #define M4U_PORT_FE_WR1 MTK_M4U_ID(M4U_LARB8_ID, 7) 137 + #define M4U_PORT_RSC_RDMA0 MTK_M4U_ID(M4U_LARB8_ID, 8) 138 + #define M4U_PORT_RSC_WDMA MTK_M4U_ID(M4U_LARB8_ID, 9) 139 + 140 + /* larb9-CAM */ 141 + #define M4U_PORT_CAM_IMGO_R1_C MTK_M4U_ID(M4U_LARB9_ID, 0) 142 + #define M4U_PORT_CAM_RRZO_R1_C MTK_M4U_ID(M4U_LARB9_ID, 1) 143 + #define M4U_PORT_CAM_LSCI_R1_C MTK_M4U_ID(M4U_LARB9_ID, 2) 144 + #define M4U_PORT_CAM_BPCI_R1_C MTK_M4U_ID(M4U_LARB9_ID, 3) 145 + #define M4U_PORT_CAM_YUVO_R1_C MTK_M4U_ID(M4U_LARB9_ID, 4) 146 + #define M4U_PORT_CAM_UFDI_R2_C MTK_M4U_ID(M4U_LARB9_ID, 5) 147 + #define M4U_PORT_CAM_RAWI_R2_C MTK_M4U_ID(M4U_LARB9_ID, 6) 148 + #define M4U_PORT_CAM_RAWI_R5_C MTK_M4U_ID(M4U_LARB9_ID, 7) 149 + #define M4U_PORT_CAM_CAMSV_1 MTK_M4U_ID(M4U_LARB9_ID, 8) 150 + #define M4U_PORT_CAM_CAMSV_2 MTK_M4U_ID(M4U_LARB9_ID, 9) 151 + #define M4U_PORT_CAM_CAMSV_3 MTK_M4U_ID(M4U_LARB9_ID, 10) 152 + #define M4U_PORT_CAM_CAMSV_4 MTK_M4U_ID(M4U_LARB9_ID, 11) 153 + #define M4U_PORT_CAM_CAMSV_5 MTK_M4U_ID(M4U_LARB9_ID, 12) 154 + #define M4U_PORT_CAM_CAMSV_6 MTK_M4U_ID(M4U_LARB9_ID, 13) 155 + #define M4U_PORT_CAM_AAO_R1_C MTK_M4U_ID(M4U_LARB9_ID, 14) 156 + #define M4U_PORT_CAM_AFO_R1_C MTK_M4U_ID(M4U_LARB9_ID, 15) 157 + #define M4U_PORT_CAM_FLKO_R1_C MTK_M4U_ID(M4U_LARB9_ID, 16) 158 + #define M4U_PORT_CAM_LCESO_R1_C MTK_M4U_ID(M4U_LARB9_ID, 17) 159 + #define M4U_PORT_CAM_CRZO_R1_C MTK_M4U_ID(M4U_LARB9_ID, 18) 160 + #define M4U_PORT_CAM_LTMSO_R1_C MTK_M4U_ID(M4U_LARB9_ID, 19) 161 + #define M4U_PORT_CAM_RSSO_R1_C MTK_M4U_ID(M4U_LARB9_ID, 20) 162 + #define M4U_PORT_CAM_CCUI MTK_M4U_ID(M4U_LARB9_ID, 21) 163 + #define M4U_PORT_CAM_CCUO MTK_M4U_ID(M4U_LARB9_ID, 22) 164 + #define M4U_PORT_CAM_FAKE MTK_M4U_ID(M4U_LARB9_ID, 23) 165 + 166 + /* larb10-CAM_A */ 167 + #define M4U_PORT_CAM_IMGO_R1_A MTK_M4U_ID(M4U_LARB10_ID, 0) 168 + #define M4U_PORT_CAM_RRZO_R1_A MTK_M4U_ID(M4U_LARB10_ID, 1) 169 + #define M4U_PORT_CAM_LSCI_R1_A MTK_M4U_ID(M4U_LARB10_ID, 2) 170 + #define M4U_PORT_CAM_BPCI_R1_A MTK_M4U_ID(M4U_LARB10_ID, 3) 171 + #define M4U_PORT_CAM_YUVO_R1_A MTK_M4U_ID(M4U_LARB10_ID, 4) 172 + #define M4U_PORT_CAM_UFDI_R2_A MTK_M4U_ID(M4U_LARB10_ID, 5) 173 + #define M4U_PORT_CAM_RAWI_R2_A MTK_M4U_ID(M4U_LARB10_ID, 6) 174 + #define M4U_PORT_CAM_RAWI_R5_A MTK_M4U_ID(M4U_LARB10_ID, 7) 175 + #define M4U_PORT_CAM_IMGO_R1_B MTK_M4U_ID(M4U_LARB10_ID, 8) 176 + #define M4U_PORT_CAM_RRZO_R1_B MTK_M4U_ID(M4U_LARB10_ID, 9) 177 + #define M4U_PORT_CAM_LSCI_R1_B MTK_M4U_ID(M4U_LARB10_ID, 10) 178 + #define M4U_PORT_CAM_BPCI_R1_B MTK_M4U_ID(M4U_LARB10_ID, 11) 179 + #define M4U_PORT_CAM_YUVO_R1_B MTK_M4U_ID(M4U_LARB10_ID, 12) 180 + #define M4U_PORT_CAM_UFDI_R2_B MTK_M4U_ID(M4U_LARB10_ID, 13) 181 + #define M4U_PORT_CAM_RAWI_R2_B MTK_M4U_ID(M4U_LARB10_ID, 14) 182 + #define M4U_PORT_CAM_RAWI_R5_B MTK_M4U_ID(M4U_LARB10_ID, 15) 183 + #define M4U_PORT_CAM_CAMSV_0 MTK_M4U_ID(M4U_LARB10_ID, 16) 184 + #define M4U_PORT_CAM_AAO_R1_A MTK_M4U_ID(M4U_LARB10_ID, 17) 185 + #define M4U_PORT_CAM_AFO_R1_A MTK_M4U_ID(M4U_LARB10_ID, 18) 186 + #define M4U_PORT_CAM_FLKO_R1_A MTK_M4U_ID(M4U_LARB10_ID, 19) 187 + #define M4U_PORT_CAM_LCESO_R1_A MTK_M4U_ID(M4U_LARB10_ID, 20) 188 + #define M4U_PORT_CAM_CRZO_R1_A MTK_M4U_ID(M4U_LARB10_ID, 21) 189 + #define M4U_PORT_CAM_AAO_R1_B MTK_M4U_ID(M4U_LARB10_ID, 22) 190 + #define M4U_PORT_CAM_AFO_R1_B MTK_M4U_ID(M4U_LARB10_ID, 23) 191 + #define M4U_PORT_CAM_FLKO_R1_B MTK_M4U_ID(M4U_LARB10_ID, 24) 192 + #define M4U_PORT_CAM_LCESO_R1_B MTK_M4U_ID(M4U_LARB10_ID, 25) 193 + #define M4U_PORT_CAM_CRZO_R1_B MTK_M4U_ID(M4U_LARB10_ID, 26) 194 + #define M4U_PORT_CAM_LTMSO_R1_A MTK_M4U_ID(M4U_LARB10_ID, 27) 195 + #define M4U_PORT_CAM_RSSO_R1_A MTK_M4U_ID(M4U_LARB10_ID, 28) 196 + #define M4U_PORT_CAM_LTMSO_R1_B MTK_M4U_ID(M4U_LARB10_ID, 29) 197 + #define M4U_PORT_CAM_RSSO_R1_B MTK_M4U_ID(M4U_LARB10_ID, 30) 198 + 199 + /* larb11-CAM-VPU */ 200 + #define M4U_PORT_CAM_IPUO MTK_M4U_ID(M4U_LARB11_ID, 0) 201 + #define M4U_PORT_CAM_IPU2O MTK_M4U_ID(M4U_LARB11_ID, 1) 202 + #define M4U_PORT_CAM_IPU3O MTK_M4U_ID(M4U_LARB11_ID, 2) 203 + #define M4U_PORT_CAM_IPUI MTK_M4U_ID(M4U_LARB11_ID, 3) 204 + #define M4U_PORT_CAM_IPU2I MTK_M4U_ID(M4U_LARB11_ID, 4) 205 + 206 + #endif
+1
include/linux/dmar.h
··· 48 48 u16 segment; /* PCI domain */ 49 49 u8 ignored:1; /* ignore drhd */ 50 50 u8 include_all:1; 51 + u8 gfx_dedicated:1; /* graphic dedicated */ 51 52 struct intel_iommu *iommu; 52 53 }; 53 54
+8 -5
include/linux/intel-iommu.h
··· 381 381 382 382 #define QI_DEV_EIOTLB_ADDR(a) ((u64)(a) & VTD_PAGE_MASK) 383 383 #define QI_DEV_EIOTLB_SIZE (((u64)1) << 11) 384 - #define QI_DEV_EIOTLB_GLOB(g) ((u64)g) 385 - #define QI_DEV_EIOTLB_PASID(p) (((u64)p) << 32) 384 + #define QI_DEV_EIOTLB_PASID(p) ((u64)((p) & 0xfffff) << 32) 386 385 #define QI_DEV_EIOTLB_SID(sid) ((u64)((sid) & 0xffff) << 16) 387 386 #define QI_DEV_EIOTLB_QDEP(qd) ((u64)((qd) & 0x1f) << 4) 388 387 #define QI_DEV_EIOTLB_PFSID(pfsid) (((u64)(pfsid & 0xf) << 12) | \ ··· 599 600 struct iommu_device iommu; /* IOMMU core code handle */ 600 601 int node; 601 602 u32 flags; /* Software defined flags */ 603 + 604 + struct dmar_drhd_unit *drhd; 602 605 }; 603 606 604 607 /* PCI domain-device relationship */ ··· 706 705 707 706 void qi_flush_dev_iotlb_pasid(struct intel_iommu *iommu, u16 sid, u16 pfsid, 708 707 u32 pasid, u16 qdep, u64 addr, 709 - unsigned int size_order, u64 granu); 708 + unsigned int size_order); 710 709 void qi_flush_pasid_cache(struct intel_iommu *iommu, u16 did, u64 granu, 711 710 int pasid); 712 711 ··· 729 728 int intel_iommu_enable_pasid(struct intel_iommu *iommu, struct device *dev); 730 729 struct dmar_domain *find_domain(struct device *dev); 731 730 struct device_domain_info *get_domain_info(struct device *dev); 731 + struct intel_iommu *device_to_iommu(struct device *dev, u8 *bus, u8 *devfn); 732 732 733 733 #ifdef CONFIG_INTEL_IOMMU_SVM 734 734 extern void intel_svm_check(struct intel_iommu *iommu); ··· 742 740 void *drvdata); 743 741 void intel_svm_unbind(struct iommu_sva *handle); 744 742 int intel_svm_get_pasid(struct iommu_sva *handle); 743 + int intel_svm_page_response(struct device *dev, struct iommu_fault_event *evt, 744 + struct iommu_page_response *msg); 745 + 745 746 struct svm_dev_ops; 746 747 747 748 struct intel_svm_dev { ··· 771 766 struct list_head devs; 772 767 struct list_head list; 773 768 }; 774 - 775 - extern struct intel_iommu *intel_svm_device_to_iommu(struct device *dev); 776 769 #else 777 770 static inline void intel_svm_check(struct intel_iommu *iommu) {} 778 771 #endif
+1 -1
include/linux/io-pgtable.h
··· 155 155 */ 156 156 struct io_pgtable_ops { 157 157 int (*map)(struct io_pgtable_ops *ops, unsigned long iova, 158 - phys_addr_t paddr, size_t size, int prot); 158 + phys_addr_t paddr, size_t size, int prot, gfp_t gfp); 159 159 size_t (*unmap)(struct io_pgtable_ops *ops, unsigned long iova, 160 160 size_t size, struct iommu_iotlb_gather *gather); 161 161 phys_addr_t (*iova_to_phys)(struct io_pgtable_ops *ops,
+16 -22
include/linux/iommu.h
··· 31 31 * if the IOMMU page table format is equivalent. 32 32 */ 33 33 #define IOMMU_PRIV (1 << 5) 34 - /* 35 - * Non-coherent masters can use this page protection flag to set cacheable 36 - * memory attributes for only a transparent outer level of cache, also known as 37 - * the last-level or system cache. 38 - */ 39 - #define IOMMU_SYS_CACHE_ONLY (1 << 6) 40 34 41 35 struct iommu_ops; 42 36 struct iommu_group; ··· 450 456 extern phys_addr_t iommu_iova_to_phys(struct iommu_domain *domain, dma_addr_t iova); 451 457 extern void iommu_set_fault_handler(struct iommu_domain *domain, 452 458 iommu_fault_handler_t handler, void *token); 453 - 454 - /** 455 - * iommu_map_sgtable - Map the given buffer to the IOMMU domain 456 - * @domain: The IOMMU domain to perform the mapping 457 - * @iova: The start address to map the buffer 458 - * @sgt: The sg_table object describing the buffer 459 - * @prot: IOMMU protection bits 460 - * 461 - * Creates a mapping at @iova for the buffer described by a scatterlist 462 - * stored in the given sg_table object in the provided IOMMU domain. 463 - */ 464 - static inline size_t iommu_map_sgtable(struct iommu_domain *domain, 465 - unsigned long iova, struct sg_table *sgt, int prot) 466 - { 467 - return iommu_map_sg(domain, iova, sgt->sgl, sgt->orig_nents, prot); 468 - } 469 459 470 460 extern void iommu_get_resv_regions(struct device *dev, struct list_head *list); 471 461 extern void iommu_put_resv_regions(struct device *dev, struct list_head *list); ··· 1056 1078 return NULL; 1057 1079 } 1058 1080 #endif /* CONFIG_IOMMU_API */ 1081 + 1082 + /** 1083 + * iommu_map_sgtable - Map the given buffer to the IOMMU domain 1084 + * @domain: The IOMMU domain to perform the mapping 1085 + * @iova: The start address to map the buffer 1086 + * @sgt: The sg_table object describing the buffer 1087 + * @prot: IOMMU protection bits 1088 + * 1089 + * Creates a mapping at @iova for the buffer described by a scatterlist 1090 + * stored in the given sg_table object in the provided IOMMU domain. 1091 + */ 1092 + static inline size_t iommu_map_sgtable(struct iommu_domain *domain, 1093 + unsigned long iova, struct sg_table *sgt, int prot) 1094 + { 1095 + return iommu_map_sg(domain, iova, sgt->sgl, sgt->orig_nents, prot); 1096 + } 1059 1097 1060 1098 #ifdef CONFIG_IOMMU_DEBUGFS 1061 1099 extern struct dentry *iommu_debugfs_dir;
+5 -1
include/uapi/linux/iommu.h
··· 81 81 /** 82 82 * struct iommu_fault_page_request - Page Request data 83 83 * @flags: encodes whether the corresponding fields are valid and whether this 84 - * is the last page in group (IOMMU_FAULT_PAGE_REQUEST_* values) 84 + * is the last page in group (IOMMU_FAULT_PAGE_REQUEST_* values). 85 + * When IOMMU_FAULT_PAGE_RESPONSE_NEEDS_PASID is set, the page response 86 + * must have the same PASID value as the page request. When it is clear, 87 + * the page response should not have a PASID. 85 88 * @pasid: Process Address Space ID 86 89 * @grpid: Page Request Group Index 87 90 * @perm: requested page permissions (IOMMU_FAULT_PERM_* values) ··· 95 92 #define IOMMU_FAULT_PAGE_REQUEST_PASID_VALID (1 << 0) 96 93 #define IOMMU_FAULT_PAGE_REQUEST_LAST_PAGE (1 << 1) 97 94 #define IOMMU_FAULT_PAGE_REQUEST_PRIV_DATA (1 << 2) 95 + #define IOMMU_FAULT_PAGE_RESPONSE_NEEDS_PASID (1 << 3) 98 96 __u32 flags; 99 97 __u32 pasid; 100 98 __u32 grpid;