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

dma-mapping: clearly mark DMA ops as an architecture feature

DMA ops are a helper for architectures and not for drivers to override
the DMA implementation.

Unfortunately driver authors keep ignoring this. Make the fact more
clear by renaming the symbol to ARCH_HAS_DMA_OPS and having the two drivers
overriding their dma_ops depend on that. These drivers should probably be
marked broken, but we can give them a bit of a grace period for that.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Thomas Gleixner <tglx@linutronix.de>
Acked-by: Sakari Ailus <sakari.ailus@linux.intel.com> # for IPU6
Acked-by: Robin Murphy <robin.murphy@arm.com>

+41 -26
+9
arch/Kconfig
··· 17 17 def_bool y 18 18 endif 19 19 20 + # 21 + # Selected by architectures that need custom DMA operations for e.g. legacy 22 + # IOMMUs not handled by dma-iommu. Drivers must never select this symbol. 23 + # 24 + config ARCH_HAS_DMA_OPS 25 + depends on HAS_DMA 26 + select DMA_OPS_HELPERS 27 + bool 28 + 20 29 menu "General architecture-dependent options" 21 30 22 31 config ARCH_HAS_SUBPAGE_FAULTS
+1 -1
arch/alpha/Kconfig
··· 4 4 default y 5 5 select ARCH_32BIT_USTAT_F_TINODE 6 6 select ARCH_HAS_CURRENT_STACK_POINTER 7 + select ARCH_HAS_DMA_OPS if PCI 7 8 select ARCH_MIGHT_HAVE_PC_PARPORT 8 9 select ARCH_MIGHT_HAVE_PC_SERIO 9 10 select ARCH_NO_PREEMPT 10 11 select ARCH_NO_SG_CHAIN 11 12 select ARCH_USE_CMPXCHG_LOCKREF 12 - select DMA_OPS if PCI 13 13 select FORCE_PCI 14 14 select PCI_DOMAINS if PCI 15 15 select PCI_SYSCALL if PCI
+1 -1
arch/arm/Kconfig
··· 10 10 select ARCH_HAS_CURRENT_STACK_POINTER 11 11 select ARCH_HAS_DEBUG_VIRTUAL if MMU 12 12 select ARCH_HAS_DMA_ALLOC if MMU 13 + select ARCH_HAS_DMA_OPS 13 14 select ARCH_HAS_DMA_WRITE_COMBINE if !ARM_DMA_MEM_BUFFERABLE 14 15 select ARCH_HAS_ELF_RANDOMIZE 15 16 select ARCH_HAS_FORTIFY_SOURCE ··· 55 54 select DCACHE_WORD_ACCESS if HAVE_EFFICIENT_UNALIGNED_ACCESS 56 55 select DMA_DECLARE_COHERENT 57 56 select DMA_GLOBAL_POOL if !MMU 58 - select DMA_OPS 59 57 select DMA_NONCOHERENT_MMAP if MMU 60 58 select EDAC_SUPPORT 61 59 select EDAC_ATOMIC_SCRUB
+1
arch/arm64/Kconfig
··· 24 24 select ARCH_HAS_CURRENT_STACK_POINTER 25 25 select ARCH_HAS_DEBUG_VIRTUAL 26 26 select ARCH_HAS_DEBUG_VM_PGTABLE 27 + select ARCH_HAS_DMA_OPS if XEN 27 28 select ARCH_HAS_DMA_PREP_COHERENT 28 29 select ARCH_HAS_ACPI_TABLE_UPGRADE if ACPI 29 30 select ARCH_HAS_FAST_MULTIPLIER
+1 -1
arch/mips/Kconfig
··· 8 8 select ARCH_HAS_CPU_FINALIZE_INIT 9 9 select ARCH_HAS_CURRENT_STACK_POINTER if !CC_IS_CLANG || CLANG_VERSION >= 140000 10 10 select ARCH_HAS_DEBUG_VIRTUAL if !64BIT 11 + select ARCH_HAS_DMA_OPS if MACH_JAZZ 11 12 select ARCH_HAS_FORTIFY_SOURCE 12 13 select ARCH_HAS_KCOV 13 14 select ARCH_HAS_NON_OVERLAPPING_ADDRESS_SPACE if !EVA ··· 394 393 select ARC_PROMLIB 395 394 select ARCH_MIGHT_HAVE_PC_PARPORT 396 395 select ARCH_MIGHT_HAVE_PC_SERIO 397 - select DMA_OPS 398 396 select FW_ARC 399 397 select FW_ARC32 400 398 select ARCH_MAY_HAVE_PC_FDC
+1 -1
arch/parisc/Kconfig
··· 10 10 select ARCH_WANT_FRAME_POINTERS 11 11 select ARCH_HAS_CPU_CACHE_ALIASING 12 12 select ARCH_HAS_DMA_ALLOC if PA11 13 + select ARCH_HAS_DMA_OPS 13 14 select ARCH_HAS_ELF_RANDOMIZE 14 15 select ARCH_HAS_STRICT_KERNEL_RWX 15 16 select ARCH_HAS_STRICT_MODULE_RWX ··· 24 23 select ARCH_HAS_CACHE_LINE_SIZE 25 24 select ARCH_HAS_DEBUG_VM_PGTABLE 26 25 select HAVE_RELIABLE_STACKTRACE 27 - select DMA_OPS 28 26 select RTC_CLASS 29 27 select RTC_DRV_GENERIC 30 28 select INIT_ALL_POSSIBLE
+1 -1
arch/powerpc/Kconfig
··· 133 133 select ARCH_HAS_DEBUG_WX if STRICT_KERNEL_RWX 134 134 select ARCH_HAS_DEVMEM_IS_ALLOWED 135 135 select ARCH_HAS_DMA_MAP_DIRECT if PPC_PSERIES 136 + select ARCH_HAS_DMA_OPS if PPC64 136 137 select ARCH_HAS_FORTIFY_SOURCE 137 138 select ARCH_HAS_GCOV_PROFILE_ALL 138 139 select ARCH_HAS_KCOV ··· 186 185 select CPUMASK_OFFSTACK if NR_CPUS >= 8192 187 186 select DCACHE_WORD_ACCESS if PPC64 && CPU_LITTLE_ENDIAN 188 187 select DMA_OPS_BYPASS if PPC64 189 - select DMA_OPS if PPC64 190 188 select DYNAMIC_FTRACE if FUNCTION_TRACER 191 189 select EDAC_ATOMIC_SCRUB 192 190 select EDAC_SUPPORT
+1 -1
arch/s390/Kconfig
··· 70 70 select ARCH_HAS_DEBUG_VM_PGTABLE 71 71 select ARCH_HAS_DEBUG_WX 72 72 select ARCH_HAS_DEVMEM_IS_ALLOWED 73 + select ARCH_HAS_DMA_OPS if PCI 73 74 select ARCH_HAS_ELF_RANDOMIZE 74 75 select ARCH_HAS_FORCE_DMA_UNENCRYPTED 75 76 select ARCH_HAS_FORTIFY_SOURCE ··· 138 137 select BUILDTIME_TABLE_SORT 139 138 select CLONE_BACKWARDS2 140 139 select DCACHE_WORD_ACCESS if !KMSAN 141 - select DMA_OPS if PCI 142 140 select DYNAMIC_FTRACE if FUNCTION_TRACER 143 141 select FUNCTION_ALIGNMENT_8B if CC_IS_GCC 144 142 select FUNCTION_ALIGNMENT_16B if !CC_IS_GCC
+1 -1
arch/sparc/Kconfig
··· 14 14 bool 15 15 default y 16 16 select ARCH_HAS_CPU_CACHE_ALIASING 17 + select ARCH_HAS_DMA_OPS 17 18 select ARCH_MIGHT_HAVE_PC_PARPORT if SPARC64 && PCI 18 19 select ARCH_MIGHT_HAVE_PC_SERIO 19 - select DMA_OPS 20 20 select OF 21 21 select OF_PROMTREE 22 22 select HAVE_ASM_MODVERSIONS
+1 -1
arch/x86/Kconfig
··· 79 79 select ARCH_HAS_DEBUG_VIRTUAL 80 80 select ARCH_HAS_DEBUG_VM_PGTABLE if !X86_PAE 81 81 select ARCH_HAS_DEVMEM_IS_ALLOWED 82 + select ARCH_HAS_DMA_OPS if GART_IOMMU || XEN 82 83 select ARCH_HAS_EARLY_DEBUG if KGDB 83 84 select ARCH_HAS_ELF_RANDOMIZE 84 85 select ARCH_HAS_FAST_MULTIPLIER ··· 944 943 945 944 config GART_IOMMU 946 945 bool "Old AMD GART IOMMU support" 947 - select DMA_OPS 948 946 select IOMMU_HELPER 949 947 select SWIOTLB 950 948 depends on X86_64 && PCI && AMD_NB
+2 -2
drivers/macintosh/macio_asic.c
··· 387 387 dma_set_max_seg_size(&dev->ofdev.dev, 65536); 388 388 dma_set_seg_boundary(&dev->ofdev.dev, 0xffffffff); 389 389 390 - #if defined(CONFIG_PCI) && defined(CONFIG_DMA_OPS) 390 + #if defined(CONFIG_PCI) && defined(CONFIG_ARCH_HAS_DMA_OPS) 391 391 /* Set the DMA ops to the ones from the PCI device, this could be 392 392 * fishy if we didn't know that on PowerMac it's always direct ops 393 393 * or iommu ops that will work fine ··· 396 396 */ 397 397 dev->ofdev.dev.archdata = chip->lbus.pdev->dev.archdata; 398 398 dev->ofdev.dev.dma_ops = chip->lbus.pdev->dev.dma_ops; 399 - #endif /* CONFIG_PCI && CONFIG_DMA_OPS */ 399 + #endif /* CONFIG_PCI && CONFIG_ARCH_HAS_DMA_OPS */ 400 400 401 401 #ifdef DEBUG 402 402 printk("preparing mdev @%p, ofdev @%p, dev @%p, kobj @%p\n",
+6 -1
drivers/media/pci/intel/ipu6/Kconfig
··· 4 4 depends on VIDEO_DEV 5 5 depends on X86 && X86_64 && HAS_DMA 6 6 depends on IPU_BRIDGE || !IPU_BRIDGE 7 + # 8 + # This driver incorrectly tries to override the dma_ops. It should 9 + # never have done that, but for now keep it working on architectures 10 + # that use dma ops 11 + # 12 + depends on ARCH_HAS_DMA_OPS 7 13 select AUXILIARY_BUS 8 - select DMA_OPS 9 14 select IOMMU_IOVA 10 15 select VIDEO_V4L2_SUBDEV_API 11 16 select MEDIA_CONTROLLER
+6 -1
drivers/vdpa/Kconfig
··· 35 35 config VDPA_USER 36 36 tristate "VDUSE (vDPA Device in Userspace) support" 37 37 depends on EVENTFD && MMU && HAS_DMA 38 - select DMA_OPS 38 + # 39 + # This driver incorrectly tries to override the dma_ops. It should 40 + # never have done that, but for now keep it working on architectures 41 + # that use dma ops 42 + # 43 + depends on ARCH_HAS_DMA_OPS 39 44 select VHOST_IOTLB 40 45 select IOMMU_IOVA 41 46 help
+2 -2
drivers/xen/Kconfig
··· 177 177 178 178 config SWIOTLB_XEN 179 179 def_bool y 180 + depends on ARCH_HAS_DMA_OPS 180 181 depends on XEN_PV || ARM || ARM64 181 - select DMA_OPS 182 182 select SWIOTLB 183 183 184 184 config XEN_PCI_STUB ··· 348 348 349 349 config XEN_GRANT_DMA_OPS 350 350 bool 351 - select DMA_OPS 352 351 353 352 config XEN_VIRTIO 354 353 bool "Xen virtio support" 354 + depends on ARCH_HAS_DMA_OPS 355 355 depends on VIRTIO 356 356 select XEN_GRANT_DMA_OPS 357 357 select XEN_GRANT_DMA_IOMMU if OF
+1 -1
include/linux/device.h
··· 750 750 struct dev_pin_info *pins; 751 751 #endif 752 752 struct dev_msi_info msi; 753 - #ifdef CONFIG_DMA_OPS 753 + #ifdef CONFIG_ARCH_HAS_DMA_OPS 754 754 const struct dma_map_ops *dma_ops; 755 755 #endif 756 756 u64 *dma_mask; /* dma mask (if dma'able device) */
+3 -3
include/linux/dma-map-ops.h
··· 75 75 unsigned long (*get_merge_boundary)(struct device *dev); 76 76 }; 77 77 78 - #ifdef CONFIG_DMA_OPS 78 + #ifdef CONFIG_ARCH_HAS_DMA_OPS 79 79 #include <asm/dma-mapping.h> 80 80 81 81 static inline const struct dma_map_ops *get_dma_ops(struct device *dev) ··· 90 90 { 91 91 dev->dma_ops = dma_ops; 92 92 } 93 - #else /* CONFIG_DMA_OPS */ 93 + #else /* CONFIG_ARCH_HAS_DMA_OPS */ 94 94 static inline const struct dma_map_ops *get_dma_ops(struct device *dev) 95 95 { 96 96 return NULL; ··· 99 99 const struct dma_map_ops *dma_ops) 100 100 { 101 101 } 102 - #endif /* CONFIG_DMA_OPS */ 102 + #endif /* CONFIG_ARCH_HAS_DMA_OPS */ 103 103 104 104 #ifdef CONFIG_DMA_CMA 105 105 extern struct cma *dma_contiguous_default_area;
+2 -7
kernel/dma/Kconfig
··· 11 11 config DMA_OPS_HELPERS 12 12 bool 13 13 14 - config DMA_OPS 15 - depends on HAS_DMA 16 - select DMA_OPS_HELPERS 17 - bool 18 - 19 14 # 20 15 # IOMMU drivers that can bypass the IOMMU code and optionally use the direct 21 16 # mapping fast path should select this option and set the dma_ops_bypass ··· 108 113 109 114 config DMA_NEED_SYNC 110 115 def_bool ARCH_HAS_SYNC_DMA_FOR_DEVICE || ARCH_HAS_SYNC_DMA_FOR_CPU || \ 111 - ARCH_HAS_SYNC_DMA_FOR_CPU_ALL || DMA_API_DEBUG || DMA_OPS || \ 112 - SWIOTLB 116 + ARCH_HAS_SYNC_DMA_FOR_CPU_ALL || DMA_API_DEBUG || \ 117 + ARCH_HAS_DMA_OPS || SWIOTLB 113 118 114 119 config DMA_RESTRICTED_POOL 115 120 bool "DMA Restricted Pool"
+1 -1
kernel/dma/Makefile
··· 2 2 3 3 obj-$(CONFIG_HAS_DMA) += mapping.o direct.o 4 4 obj-$(CONFIG_DMA_OPS_HELPERS) += ops_helpers.o 5 - obj-$(CONFIG_DMA_OPS) += dummy.o 5 + obj-$(CONFIG_ARCH_HAS_DMA_OPS) += dummy.o 6 6 obj-$(CONFIG_DMA_CMA) += contiguous.o 7 7 obj-$(CONFIG_DMA_DECLARE_COHERENT) += coherent.o 8 8 obj-$(CONFIG_DMA_API_DEBUG) += debug.o