ARM/dma-mapping: use the generic versions of dma_to_phys/phys_to_dma by default
authorChristoph Hellwig <hch@lst.de>
Tue, 19 Apr 2022 08:00:32 +0000 (10:00 +0200)
committerChristoph Hellwig <hch@lst.de>
Thu, 7 Jul 2022 16:18:57 +0000 (18:18 +0200)
Only the footbridge platforms provide their own DMA address translation
helpers, so switch to the generic version for all other platforms, and
consolidate the footbridge implementation to remove two levels of
indirection.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Arnd Bergmann <arnd@arndb.de>
Tested-by: Marc Zyngier <maz@kernel.org>
arch/arm/Kconfig
arch/arm/include/asm/dma-direct.h
arch/arm/include/asm/memory.h
arch/arm/mach-footbridge/Kconfig
arch/arm/mach-footbridge/common.c
arch/arm/mach-footbridge/include/mach/dma-direct.h [new file with mode: 0644]
arch/arm/mach-footbridge/include/mach/memory.h

index 7630ba9cb6ccc30cd75672c57e0aa248f5a298c9..cd67e359958cb0688bd235a0c43d619bf832f133 100644 (file)
@@ -15,7 +15,6 @@ config ARM
        select ARCH_HAS_MEMBARRIER_SYNC_CORE
        select ARCH_HAS_NON_OVERLAPPING_ADDRESS_SPACE
        select ARCH_HAS_PTE_SPECIAL if ARM_LPAE
-       select ARCH_HAS_PHYS_TO_DMA
        select ARCH_HAS_SETUP_DMA_OPS
        select ARCH_HAS_SET_MEMORY
        select ARCH_HAS_STRICT_KERNEL_RWX if MMU && !XIP_KERNEL
index 6fd52713b5d1292267154593031270addd696446..4f7bcde03abb501884d029444a6a56fb0d624e72 100644 (file)
@@ -1,40 +1 @@
-/* SPDX-License-Identifier: GPL-2.0 */
-#ifndef ASM_ARM_DMA_DIRECT_H
-#define ASM_ARM_DMA_DIRECT_H 1
-
-#include <asm/memory.h>
-
-/*
- * dma_to_pfn/pfn_to_dma are architecture private
- * functions used internally by the DMA-mapping API to provide DMA
- * addresses. They must not be used by drivers.
- */
-static inline dma_addr_t pfn_to_dma(struct device *dev, unsigned long pfn)
-{
-       if (dev && dev->dma_range_map)
-               pfn = PFN_DOWN(translate_phys_to_dma(dev, PFN_PHYS(pfn)));
-       return (dma_addr_t)__pfn_to_bus(pfn);
-}
-
-static inline unsigned long dma_to_pfn(struct device *dev, dma_addr_t addr)
-{
-       unsigned long pfn = __bus_to_pfn(addr);
-
-       if (dev && dev->dma_range_map)
-               pfn = PFN_DOWN(translate_dma_to_phys(dev, PFN_PHYS(pfn)));
-       return pfn;
-}
-
-static inline dma_addr_t phys_to_dma(struct device *dev, phys_addr_t paddr)
-{
-       unsigned int offset = paddr & ~PAGE_MASK;
-       return pfn_to_dma(dev, __phys_to_pfn(paddr)) + offset;
-}
-
-static inline phys_addr_t dma_to_phys(struct device *dev, dma_addr_t dev_addr)
-{
-       unsigned int offset = dev_addr & ~PAGE_MASK;
-       return __pfn_to_phys(dma_to_pfn(dev, dev_addr)) + offset;
-}
-
-#endif /* ASM_ARM_DMA_DIRECT_H */
+#include <mach/dma-direct.h>
index f673e13e0f942279a2fc4b58d71400bbebf14838..a55a9038abc891513b619c12527b3b5cdda8ff17 100644 (file)
@@ -378,8 +378,6 @@ static inline unsigned long __virt_to_idmap(unsigned long x)
 #ifndef __virt_to_bus
 #define __virt_to_bus  __virt_to_phys
 #define __bus_to_virt  __phys_to_virt
-#define __pfn_to_bus(x)        __pfn_to_phys(x)
-#define __bus_to_pfn(x)        __phys_to_pfn(x)
 #endif
 
 /*
index 728aff93fba9d288da785916d7dd5cf93ea1ceb5..b5bbdcf2e48966f01d38a8cd69d65d4d53b2d90e 100644 (file)
@@ -60,6 +60,7 @@ endmenu
 
 # Footbridge support
 config FOOTBRIDGE
+       select ARCH_HAS_PHYS_TO_DMA
        bool
 
 # Footbridge in host mode
index 322495df271d548fd2e7476e117a5d9383e90cb0..5020eb96b025dd3562fc03b069dcfdcb0d739b11 100644 (file)
@@ -12,6 +12,7 @@
 #include <linux/init.h>
 #include <linux/io.h>
 #include <linux/spinlock.h>
+#include <linux/dma-direct.h>
 #include <video/vga.h>
 
 #include <asm/page.h>
@@ -335,17 +336,19 @@ unsigned long __bus_to_virt(unsigned long res)
        return res;
 }
 EXPORT_SYMBOL(__bus_to_virt);
-
-unsigned long __pfn_to_bus(unsigned long pfn)
+#else
+static inline unsigned long fb_bus_sdram_offset(void)
 {
-       return __pfn_to_phys(pfn) + (fb_bus_sdram_offset() - PHYS_OFFSET);
+       return BUS_OFFSET;
 }
-EXPORT_SYMBOL(__pfn_to_bus);
+#endif /* CONFIG_FOOTBRIDGE_ADDIN */
 
-unsigned long __bus_to_pfn(unsigned long bus)
+dma_addr_t phys_to_dma(struct device *dev, phys_addr_t paddr)
 {
-       return __phys_to_pfn(bus - (fb_bus_sdram_offset() - PHYS_OFFSET));
+       return paddr + (fb_bus_sdram_offset() - PHYS_OFFSET);
 }
-EXPORT_SYMBOL(__bus_to_pfn);
 
-#endif
+phys_addr_t dma_to_phys(struct device *dev, dma_addr_t dev_addr)
+{
+       return dev_addr - (fb_bus_sdram_offset() - PHYS_OFFSET);
+}
diff --git a/arch/arm/mach-footbridge/include/mach/dma-direct.h b/arch/arm/mach-footbridge/include/mach/dma-direct.h
new file mode 100644 (file)
index 0000000..01f9e83
--- /dev/null
@@ -0,0 +1,8 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef MACH_FOOTBRIDGE_DMA_DIRECT_H
+#define MACH_FOOTBRIDGE_DMA_DIRECT_H 1
+
+dma_addr_t phys_to_dma(struct device *dev, phys_addr_t paddr);
+phys_addr_t dma_to_phys(struct device *dev, dma_addr_t dev_addr);
+
+#endif /* MACH_FOOTBRIDGE_DMA_DIRECT_H */
index 46fd4a8872b9a34ff835ff45bf905c92a9ba82d5..3a5d2638c18f88034e1083009c7f4ab6e8c8631e 100644 (file)
@@ -26,8 +26,6 @@
 #ifndef __ASSEMBLY__
 extern unsigned long __virt_to_bus(unsigned long);
 extern unsigned long __bus_to_virt(unsigned long);
-extern unsigned long __pfn_to_bus(unsigned long);
-extern unsigned long __bus_to_pfn(unsigned long);
 #endif
 #define __virt_to_bus  __virt_to_bus
 #define __bus_to_virt  __bus_to_virt
@@ -42,8 +40,6 @@ extern unsigned long __bus_to_pfn(unsigned long);
 #define BUS_OFFSET             0xe0000000
 #define __virt_to_bus(x)       ((x) + (BUS_OFFSET - PAGE_OFFSET))
 #define __bus_to_virt(x)       ((x) - (BUS_OFFSET - PAGE_OFFSET))
-#define __pfn_to_bus(x)                (__pfn_to_phys(x) + (BUS_OFFSET - PHYS_OFFSET))
-#define __bus_to_pfn(x)                __phys_to_pfn((x) - (BUS_OFFSET - PHYS_OFFSET))
 
 #else