ARM: mm: introduce arch hooks for dma address translation routines
Currently arch specific DMA address translation routines can be enabled
using only defines which makes impossible to use them in with
multi-platform builds.
Hence, introduce arch specific hooks for DMA address translations
routines to be compatible with multi-platform builds:
dma_addr_t (*arch_pfn_to_dma)(struct device *dev, unsigned long pfn);
unsigned long (*arch_dma_to_pfn)(struct device *dev, dma_addr_t addr);
void* (*arch_dma_to_virt)(struct device *dev, dma_addr_t addr);
dma_addr_t (*arch_virt_to_dma)(struct device *dev, void *addr);
In case if architecture won't use it - DMA address translation routines
will fall-back to existing implementation.
Also, modify machines omap1, ks8695, iop13xx to use new DMA hooks.
Cc: Russell King <linux@arm.linux.org.uk>
Cc: Will Deacon <will.deacon@arm.com>
Cc: Nicolas Pitre <nicolas.pitre@linaro.org>
Cc: Greg Ungerer <gerg@uclinux.org>
Cc: Tony Lindgren <tony@atomide.com>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Olof Johansson <olof@lixom.net>
Signed-off-by: Grygorii Strashko <grygorii.strashko@ti.com>
Signed-of-by: Santosh Shilimkar <santosh.shilimkar@ti.com>
diff --git a/arch/arm/include/asm/dma-mapping.h b/arch/arm/include/asm/dma-mapping.h
index e701a4d..84acc46 100644
--- a/arch/arm/include/asm/dma-mapping.h
+++ b/arch/arm/include/asm/dma-mapping.h
@@ -55,28 +55,16 @@
* functions used internally by the DMA-mapping API to provide DMA
* addresses. They must not be used by drivers.
*/
-#ifndef __arch_pfn_to_dma
-static inline dma_addr_t pfn_to_dma(struct device *dev, unsigned long pfn)
-{
- return (dma_addr_t)__pfn_to_bus(pfn);
-}
-static inline unsigned long dma_to_pfn(struct device *dev, dma_addr_t addr)
-{
- return __bus_to_pfn(addr);
-}
+extern dma_addr_t (*__arch_pfn_to_dma)(struct device *dev, unsigned long pfn);
+extern unsigned long (*__arch_dma_to_pfn)(struct device *dev, dma_addr_t addr);
+extern void* (*__arch_dma_to_virt)(struct device *dev, dma_addr_t addr);
+extern dma_addr_t (*__arch_virt_to_dma)(struct device *dev, void *addr);
-static inline void *dma_to_virt(struct device *dev, dma_addr_t addr)
-{
- return (void *)__bus_to_virt((unsigned long)addr);
-}
-static inline dma_addr_t virt_to_dma(struct device *dev, void *addr)
-{
- return (dma_addr_t)__virt_to_bus((unsigned long)(addr));
-}
+/* Keep __arch_pfn_to_dma defined as it's used by some drivers (V4L2)*/
+#define __arch_pfn_to_dma __arch_pfn_to_dma
-#else
static inline dma_addr_t pfn_to_dma(struct device *dev, unsigned long pfn)
{
return __arch_pfn_to_dma(dev, pfn);
@@ -96,7 +84,6 @@
{
return __arch_virt_to_dma(dev, addr);
}
-#endif
/* The ARM override for dma_max_pfn() */
static inline unsigned long dma_max_pfn(struct device *dev)
diff --git a/arch/arm/mach-iop13xx/include/mach/memory.h b/arch/arm/mach-iop13xx/include/mach/memory.h
index 7c032d0..eab7930 100644
--- a/arch/arm/mach-iop13xx/include/mach/memory.h
+++ b/arch/arm/mach-iop13xx/include/mach/memory.h
@@ -8,65 +8,4 @@
*/
#define PLAT_PHYS_OFFSET UL(0x00000000)
-#ifndef __ASSEMBLY__
-
-#if defined(CONFIG_ARCH_IOP13XX)
-#define IOP13XX_PMMR_V_START (IOP13XX_PMMR_VIRT_MEM_BASE)
-#define IOP13XX_PMMR_V_END (IOP13XX_PMMR_VIRT_MEM_BASE + IOP13XX_PMMR_SIZE)
-#define IOP13XX_PMMR_P_START (IOP13XX_PMMR_PHYS_MEM_BASE)
-#define IOP13XX_PMMR_P_END (IOP13XX_PMMR_PHYS_MEM_BASE + IOP13XX_PMMR_SIZE)
-
-static inline dma_addr_t __virt_to_lbus(void __iomem *x)
-{
- return x + IOP13XX_PMMR_PHYS_MEM_BASE - IOP13XX_PMMR_VIRT_MEM_BASE;
-}
-
-static inline void __iomem *__lbus_to_virt(dma_addr_t x)
-{
- return x + IOP13XX_PMMR_VIRT_MEM_BASE - IOP13XX_PMMR_PHYS_MEM_BASE;
-}
-
-#define __is_lbus_dma(a) \
- ((a) >= IOP13XX_PMMR_P_START && (a) < IOP13XX_PMMR_P_END)
-
-#define __is_lbus_virt(a) \
- ((a) >= IOP13XX_PMMR_V_START && (a) < IOP13XX_PMMR_V_END)
-
-/* Device is an lbus device if it is on the platform bus of the IOP13XX */
-#define is_lbus_device(dev) \
- (dev && strncmp(dev->bus->name, "platform", 8) == 0)
-
-#define __arch_dma_to_virt(dev, addr) \
- ({ \
- void * __virt; \
- dma_addr_t __dma = addr; \
- if (is_lbus_device(dev) && __is_lbus_dma(__dma)) \
- __virt = __lbus_to_virt(__dma); \
- else \
- __virt = (void *)__phys_to_virt(__dma); \
- __virt; \
- })
-
-#define __arch_virt_to_dma(dev, addr) \
- ({ \
- void * __virt = addr; \
- dma_addr_t __dma; \
- if (is_lbus_device(dev) && __is_lbus_virt(__virt)) \
- __dma = __virt_to_lbus(__virt); \
- else \
- __dma = __virt_to_phys((unsigned long)__virt); \
- __dma; \
- })
-
-#define __arch_pfn_to_dma(dev, pfn) \
- ({ \
- /* __is_lbus_virt() can never be true for RAM pages */ \
- (dma_addr_t)__pfn_to_phys(pfn); \
- })
-
-#define __arch_dma_to_pfn(dev, addr) __phys_to_pfn(addr)
-
-#endif /* CONFIG_ARCH_IOP13XX */
-#endif /* !ASSEMBLY */
-
#endif
diff --git a/arch/arm/mach-iop13xx/setup.c b/arch/arm/mach-iop13xx/setup.c
index 96e6c7a..0f44101 100644
--- a/arch/arm/mach-iop13xx/setup.c
+++ b/arch/arm/mach-iop13xx/setup.c
@@ -351,8 +351,66 @@
},
};
+#define IOP13XX_PMMR_V_START (IOP13XX_PMMR_VIRT_MEM_BASE)
+#define IOP13XX_PMMR_V_END (IOP13XX_PMMR_VIRT_MEM_BASE + IOP13XX_PMMR_SIZE)
+#define IOP13XX_PMMR_P_START (IOP13XX_PMMR_PHYS_MEM_BASE)
+#define IOP13XX_PMMR_P_END (IOP13XX_PMMR_PHYS_MEM_BASE + IOP13XX_PMMR_SIZE)
+
+static inline dma_addr_t __virt_to_lbus(void __iomem *x)
+{
+ return x + IOP13XX_PMMR_PHYS_MEM_BASE - IOP13XX_PMMR_VIRT_MEM_BASE;
+}
+
+static inline void __iomem *__lbus_to_virt(dma_addr_t x)
+{
+ return x + IOP13XX_PMMR_VIRT_MEM_BASE - IOP13XX_PMMR_PHYS_MEM_BASE;
+}
+
+#define __is_lbus_dma(a) \
+ ((a) >= IOP13XX_PMMR_P_START && (a) < IOP13XX_PMMR_P_END)
+
+#define __is_lbus_virt(a) \
+ ((a) >= IOP13XX_PMMR_V_START && (a) < IOP13XX_PMMR_V_END)
+
+/* Device is an lbus device if it is on the platform bus of the IOP13XX */
+#define is_lbus_device(dev) \
+ (dev && strncmp(dev->bus->name, "platform", 8) == 0)
+
+static dma_addr_t iop13xx_pfn_to_dma(struct device *dev, unsigned long pfn)
+{
+ /* __is_lbus_virt() can never be true for RAM pages */
+ return __pfn_to_phys(pfn);
+}
+
+static unsigned long iop13xx_dma_to_pfn(struct device *dev, dma_addr_t addr)
+{
+ return __phys_to_pfn(addr);
+}
+
+static void *iop13xx_dma_to_virt(struct device *dev, dma_addr_t addr)
+{
+ if (is_lbus_device(dev) && __is_lbus_dma(addr))
+ return __lbus_to_virt(addr);
+ else
+ return (void *)__phys_to_virt(addr);
+}
+
+static dma_addr_t iop13xx_virt_to_dma(struct device *dev, void *addr)
+{
+ if (is_lbus_device(dev) && __is_lbus_virt(addr))
+ return __virt_to_lbus(addr);
+ else
+ return __virt_to_phys((unsigned long)addr);
+}
+
+
void __init iop13xx_map_io(void)
{
+ __arch_pfn_to_dma = iop13xx_pfn_to_dma;
+ __arch_dma_to_pfn = iop13xx_dma_to_pfn;
+ __arch_dma_to_virt = iop13xx_dma_to_virt;
+ __arch_virt_to_dma = iop13xx_virt_to_dma;
+
/* Initialize the Static Page Table maps */
iotable_init(iop13xx_std_desc, ARRAY_SIZE(iop13xx_std_desc));
}
diff --git a/arch/arm/mach-ks8695/cpu.c b/arch/arm/mach-ks8695/cpu.c
index ddb2422..018fe46 100644
--- a/arch/arm/mach-ks8695/cpu.c
+++ b/arch/arm/mach-ks8695/cpu.c
@@ -25,6 +25,8 @@
#include <linux/module.h>
#include <linux/init.h>
#include <linux/io.h>
+#include <linux/device.h>
+#include <linux/dma-mapping.h>
#include <mach/hardware.h>
#include <asm/mach/arch.h>
@@ -64,8 +66,56 @@
sysclk[scdc] / 1000000, cpuclk[scdc] / 1000000);
}
+#ifdef CONFIG_PCI
+
+/* PCI mappings */
+#define __virt_to_lbus(x) ((x) - PAGE_OFFSET + KS8695_PCIMEM_PA)
+#define __lbus_to_virt(x) ((x) - KS8695_PCIMEM_PA + PAGE_OFFSET)
+
+/* Platform-bus mapping */
+extern struct bus_type platform_bus_type;
+#define is_lbus_device(dev) (dev && dev->bus == &platform_bus_type)
+
+static dma_addr_t ks8695_pfn_to_dma(struct device *dev, unsigned long pfn)
+{
+ dma_addr_t __dma = __pfn_to_phys(pfn);
+
+ if (!is_lbus_device(dev))
+ __dma = __dma - PHYS_OFFSET + KS8695_PCIMEM_PA;
+ return __dma;
+}
+static unsigned long ks8695_dma_to_pfn(struct device *dev, dma_addr_t addr)
+{
+ dma_addr_t __dma = addr;
+
+ if (!is_lbus_device(dev))
+ __dma += PHYS_OFFSET - KS8695_PCIMEM_PA;
+ return __phys_to_pfn(__dma);
+}
+
+static void *ks8695_dma_to_virt(struct device *dev, dma_addr_t addr)
+{
+ return (void *) (is_lbus_device(dev) ? __phys_to_virt(addr) : __lbus_to_virt(addr));
+}
+
+static dma_addr_t ks8695_virt_to_dma(struct device *dev, void *addr)
+{
+ unsigned long __addr = (unsigned long)(addr);
+ return (dma_addr_t) (is_lbus_device(dev) ? __virt_to_phys(__addr) : __virt_to_lbus(__addr));
+}
+
+#endif
+
+
void __init ks8695_map_io(void)
{
+#ifdef CONFIG_PCI
+ __arch_pfn_to_dma = ks8695_pfn_to_dma;
+ __arch_dma_to_pfn = ks8695_dma_to_pfn;
+ __arch_dma_to_virt = ks8695_dma_to_virt;
+ __arch_virt_to_dma = ks8695_virt_to_dma;
+#endif
+
iotable_init(ks8695_io_desc, ARRAY_SIZE(ks8695_io_desc));
ks8695_processor_info();
diff --git a/arch/arm/mach-ks8695/include/mach/memory.h b/arch/arm/mach-ks8695/include/mach/memory.h
index 95e731a..029486d 100644
--- a/arch/arm/mach-ks8695/include/mach/memory.h
+++ b/arch/arm/mach-ks8695/include/mach/memory.h
@@ -20,37 +20,4 @@
*/
#define PLAT_PHYS_OFFSET KS8695_SDRAM_PA
-#ifndef __ASSEMBLY__
-
-#ifdef CONFIG_PCI
-
-/* PCI mappings */
-#define __virt_to_bus(x) ((x) - PAGE_OFFSET + KS8695_PCIMEM_PA)
-#define __bus_to_virt(x) ((x) - KS8695_PCIMEM_PA + PAGE_OFFSET)
-
-/* Platform-bus mapping */
-extern struct bus_type platform_bus_type;
-#define is_lbus_device(dev) (dev && dev->bus == &platform_bus_type)
-#define __arch_dma_to_virt(dev, x) ({ (void *) (is_lbus_device(dev) ? \
- __phys_to_virt(x) : __bus_to_virt(x)); })
-#define __arch_virt_to_dma(dev, x) ({ is_lbus_device(dev) ? \
- (dma_addr_t)__virt_to_phys((unsigned long)x) \
- : (dma_addr_t)__virt_to_bus(x); })
-#define __arch_pfn_to_dma(dev, pfn) \
- ({ dma_addr_t __dma = __pfn_to_phys(pfn); \
- if (!is_lbus_device(dev)) \
- __dma = __dma - PHYS_OFFSET + KS8695_PCIMEM_PA; \
- __dma; })
-
-#define __arch_dma_to_pfn(dev, x) \
- ({ dma_addr_t __dma = x; \
- if (!is_lbus_device(dev)) \
- __dma += PHYS_OFFSET - KS8695_PCIMEM_PA; \
- __phys_to_pfn(__dma); \
- })
-
-#endif
-
-#endif
-
#endif
diff --git a/arch/arm/mach-omap1/include/mach/memory.h b/arch/arm/mach-omap1/include/mach/memory.h
index 3c25305..beae905 100644
--- a/arch/arm/mach-omap1/include/mach/memory.h
+++ b/arch/arm/mach-omap1/include/mach/memory.h
@@ -11,47 +11,8 @@
#define PLAT_PHYS_OFFSET UL(0x10000000)
/*
- * Bus address is physical address, except for OMAP-1510 Local Bus.
- * OMAP-1510 bus address is translated into a Local Bus address if the
- * OMAP bus type is lbus. We do the address translation based on the
- * device overriding the defaults used in the dma-mapping API.
- * Note that the is_lbus_device() test is not very efficient on 1510
- * because of the strncmp().
- */
-#if defined(CONFIG_ARCH_OMAP15XX) && !defined(__ASSEMBLER__)
-#include <mach/soc.h>
-
-/*
* OMAP-1510 Local Bus address offset
*/
#define OMAP1510_LB_OFFSET UL(0x30000000)
-#define virt_to_lbus(x) ((x) - PAGE_OFFSET + OMAP1510_LB_OFFSET)
-#define lbus_to_virt(x) ((x) - OMAP1510_LB_OFFSET + PAGE_OFFSET)
-#define is_lbus_device(dev) (cpu_is_omap15xx() && dev && (strncmp(dev_name(dev), "ohci", 4) == 0))
-
-#define __arch_pfn_to_dma(dev, pfn) \
- ({ dma_addr_t __dma = __pfn_to_phys(pfn); \
- if (is_lbus_device(dev)) \
- __dma = __dma - PHYS_OFFSET + OMAP1510_LB_OFFSET; \
- __dma; })
-
-#define __arch_dma_to_pfn(dev, addr) \
- ({ dma_addr_t __dma = addr; \
- if (is_lbus_device(dev)) \
- __dma += PHYS_OFFSET - OMAP1510_LB_OFFSET; \
- __phys_to_pfn(__dma); \
- })
-
-#define __arch_dma_to_virt(dev, addr) ({ (void *) (is_lbus_device(dev) ? \
- lbus_to_virt(addr) : \
- __phys_to_virt(addr)); })
-
-#define __arch_virt_to_dma(dev, addr) ({ unsigned long __addr = (unsigned long)(addr); \
- (dma_addr_t) (is_lbus_device(dev) ? \
- virt_to_lbus(__addr) : \
- __virt_to_phys(__addr)); })
-
-#endif /* CONFIG_ARCH_OMAP15XX */
-
#endif
diff --git a/arch/arm/mach-omap1/io.c b/arch/arm/mach-omap1/io.c
index 499b8ac..422527b 100644
--- a/arch/arm/mach-omap1/io.c
+++ b/arch/arm/mach-omap1/io.c
@@ -19,6 +19,7 @@
#include <mach/mux.h>
#include <mach/tc.h>
#include <linux/omap-dma.h>
+#include <linux/dma-mapping.h>
#include "iomap.h"
#include "common.h"
@@ -86,10 +87,61 @@
#endif
/*
+ * Bus address is physical address, except for OMAP-1510 Local Bus.
+ * OMAP-1510 bus address is translated into a Local Bus address if the
+ * OMAP bus type is lbus. We do the address translation based on the
+ * device overriding the defaults used in the dma-mapping API.
+ * Note that the is_lbus_device() test is not very efficient on 1510
+ * because of the strncmp().
+ */
+#if defined(CONFIG_ARCH_OMAP15XX)
+
+#define virt_to_lbus(x) ((x) - PAGE_OFFSET + OMAP1510_LB_OFFSET)
+#define lbus_to_virt(x) ((x) - OMAP1510_LB_OFFSET + PAGE_OFFSET)
+#define is_lbus_device(dev) (cpu_is_omap15xx() && dev && (strncmp(dev_name(dev), "ohci", 4) == 0))
+
+static dma_addr_t omap1_pfn_to_dma(struct device *dev, unsigned long pfn)
+{
+ dma_addr_t __dma = __pfn_to_phys(pfn);
+
+ if (is_lbus_device(dev))
+ __dma = __dma - PHYS_OFFSET + OMAP1510_LB_OFFSET;
+ return __dma;
+}
+static unsigned long omap1_dma_to_pfn(struct device *dev, dma_addr_t addr)
+{
+ dma_addr_t __dma = addr;
+
+ if (is_lbus_device(dev))
+ __dma += PHYS_OFFSET - OMAP1510_LB_OFFSET;
+ return __phys_to_pfn(__dma);
+}
+
+static void *omap1_dma_to_virt(struct device *dev, dma_addr_t addr)
+{
+ return (void *) (is_lbus_device(dev) ? lbus_to_virt(addr) : __phys_to_virt(addr));
+}
+
+static dma_addr_t omap1_virt_to_dma(struct device *dev, void *addr)
+{
+ unsigned long __addr = (unsigned long)(addr);
+ return (dma_addr_t) (is_lbus_device(dev) ? virt_to_lbus(__addr) : __virt_to_phys(__addr));
+}
+
+#endif /* CONFIG_ARCH_OMAP15XX */
+
+/*
* Maps common IO regions for omap1
*/
static void __init omap1_map_common_io(void)
{
+#if defined(CONFIG_ARCH_OMAP15XX)
+ __arch_pfn_to_dma = omap1_pfn_to_dma;
+ __arch_dma_to_pfn = omap1_dma_to_pfn;
+ __arch_dma_to_virt = omap1_dma_to_virt;
+ __arch_virt_to_dma = omap1_virt_to_dma;
+#endif
+
iotable_init(omap_io_desc, ARRAY_SIZE(omap_io_desc));
}
diff --git a/arch/arm/mm/dma-mapping.c b/arch/arm/mm/dma-mapping.c
index ed1e38a..74a807b 100644
--- a/arch/arm/mm/dma-mapping.c
+++ b/arch/arm/mm/dma-mapping.c
@@ -39,6 +39,35 @@
#include "mm.h"
+static inline dma_addr_t __pfn_to_dma(struct device *dev, unsigned long pfn)
+{
+ return (dma_addr_t)__pfn_to_bus(pfn);
+}
+
+static inline unsigned long __dma_to_pfn(struct device *dev, dma_addr_t addr)
+{
+ return __bus_to_pfn(addr);
+}
+
+static inline void *__dma_to_virt(struct device *dev, dma_addr_t addr)
+{
+ return (void *)__bus_to_virt((unsigned long)addr);
+}
+
+static inline dma_addr_t __virt_to_dma(struct device *dev, void *addr)
+{
+ return (dma_addr_t)__virt_to_bus((unsigned long)(addr));
+}
+
+dma_addr_t (*__arch_pfn_to_dma)(struct device *dev, unsigned long pfn) = __pfn_to_dma;
+EXPORT_SYMBOL(__arch_pfn_to_dma);
+unsigned long (*__arch_dma_to_pfn)(struct device *dev, dma_addr_t addr) = __dma_to_pfn;
+EXPORT_SYMBOL(__arch_dma_to_pfn);
+void* (*__arch_dma_to_virt)(struct device *dev, dma_addr_t addr) = __dma_to_virt;
+EXPORT_SYMBOL(__arch_dma_to_virt);
+dma_addr_t (*__arch_virt_to_dma)(struct device *dev, void *addr) = __virt_to_dma;
+EXPORT_SYMBOL(__arch_virt_to_dma);
+
/*
* The DMA API is built upon the notion of "buffer ownership". A buffer
* is either exclusively owned by the CPU (and therefore may be accessed