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

arm64: simplify dma_get_ops

Including linux/acpi.h from asm/dma-mapping.h causes tons of compile-time
warnings, e.g.

drivers/isdn/mISDN/dsp_ecdis.h:43:0: warning: "FALSE" redefined
drivers/isdn/mISDN/dsp_ecdis.h:44:0: warning: "TRUE" redefined
drivers/net/fddi/skfp/h/targetos.h:62:0: warning: "TRUE" redefined
drivers/net/fddi/skfp/h/targetos.h:63:0: warning: "FALSE" redefined

However, it looks like the dependency should not even there as
I do not see why __generic_dma_ops() cares about whether we have
an ACPI based system or not.

The current behavior is to fall back to the global dma_ops when
a device has not set its own dma_ops, but only for DT based systems.
This seems dangerous, as a random device might have different
requirements regarding IOMMU or coherency, so we should really
never have that fallback and just forbid DMA when we have not
initialized DMA for a device.

This removes the global dma_ops variable and the special-casing
for ACPI, and just returns the dma ops that got set for the
device, or the dummy_dma_ops if none were present.

The original code has apparently been copied from arm32 where we
rely on it for ISA devices things like the floppy controller, but
we should have no such devices on ARM64.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
[catalin.marinas@arm.com: removed acpi_disabled check in arch_setup_dma_ops()]
Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>

authored by

Arnd Bergmann and committed by
Catalin Marinas
1dccb598 4fee9f36

+7 -22
+3 -10
arch/arm64/include/asm/dma-mapping.h
··· 18 18 19 19 #ifdef __KERNEL__ 20 20 21 - #include <linux/acpi.h> 22 21 #include <linux/types.h> 23 22 #include <linux/vmalloc.h> 24 23 ··· 25 26 #include <asm/xen/hypervisor.h> 26 27 27 28 #define DMA_ERROR_CODE (~(dma_addr_t)0) 28 - extern struct dma_map_ops *dma_ops; 29 29 extern struct dma_map_ops dummy_dma_ops; 30 30 31 31 static inline struct dma_map_ops *__generic_dma_ops(struct device *dev) 32 32 { 33 - if (unlikely(!dev)) 34 - return dma_ops; 35 - else if (dev->archdata.dma_ops) 33 + if (dev && dev->archdata.dma_ops) 36 34 return dev->archdata.dma_ops; 37 - else if (acpi_disabled) 38 - return dma_ops; 39 35 40 36 /* 41 - * When ACPI is enabled, if arch_set_dma_ops is not called, 42 - * we will disable device DMA capability by setting it 43 - * to dummy_dma_ops. 37 + * We expect no ISA devices, and all other DMA masters are expected to 38 + * have someone call arch_setup_dma_ops at device creation time. 44 39 */ 45 40 return &dummy_dma_ops; 46 41 }
+4 -12
arch/arm64/mm/dma-mapping.c
··· 18 18 */ 19 19 20 20 #include <linux/gfp.h> 21 + #include <linux/acpi.h> 21 22 #include <linux/export.h> 22 23 #include <linux/slab.h> 23 24 #include <linux/genalloc.h> ··· 28 27 #include <linux/swiotlb.h> 29 28 30 29 #include <asm/cacheflush.h> 31 - 32 - struct dma_map_ops *dma_ops; 33 - EXPORT_SYMBOL(dma_ops); 34 30 35 31 static pgprot_t __get_dma_pgprot(struct dma_attrs *attrs, pgprot_t prot, 36 32 bool coherent) ··· 513 515 514 516 static int __init arm64_dma_init(void) 515 517 { 516 - int ret; 517 - 518 - dma_ops = &swiotlb_dma_ops; 519 - 520 - ret = atomic_pool_init(); 521 - 522 - return ret; 518 + return atomic_pool_init(); 523 519 } 524 520 arch_initcall(arm64_dma_init); 525 521 ··· 983 991 void arch_setup_dma_ops(struct device *dev, u64 dma_base, u64 size, 984 992 struct iommu_ops *iommu, bool coherent) 985 993 { 986 - if (!acpi_disabled && !dev->archdata.dma_ops) 987 - dev->archdata.dma_ops = dma_ops; 994 + if (!dev->archdata.dma_ops) 995 + dev->archdata.dma_ops = &swiotlb_dma_ops; 988 996 989 997 dev->archdata.dma_coherent = coherent; 990 998 __iommu_setup_dma_ops(dev, dma_base, size, iommu);