aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRussell King <rmk+kernel@arm.linux.org.uk>2011-01-02 19:00:17 -0500
committerRussell King <rmk+kernel@arm.linux.org.uk>2011-01-03 06:27:43 -0500
commit9eedd96301cad8ab58ee8c1e579677d0a75c2ba1 (patch)
tree87f5ebbbd5769516771bef37574b39464177f496
parent3d29005ab8d828e36108ecc2338612ce3acdd86f (diff)
ARM: DMA: Replace page_to_dma()/dma_to_page() with pfn_to_dma()/dma_to_pfn()
Replace the page_to_dma() and dma_to_page() macros with their PFN equivalents. This allows us to map parts of memory which do not have a struct page allocated to them to bus addresses. This will be used internally by dma_alloc_coherent()/dma_alloc_writecombine(). Build tested on Versatile, OMAP1, IOP13xx and KS8695. Tested-by: Janusz Krzysztofik <jkrzyszt@tis.icnet.pl> Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
-rw-r--r--arch/arm/include/asm/dma-mapping.h34
-rw-r--r--arch/arm/mach-iop13xx/include/mach/memory.h6
-rw-r--r--arch/arm/mach-ks8695/include/mach/memory.h8
-rw-r--r--arch/arm/mm/dma-mapping.c4
-rw-r--r--arch/arm/plat-omap/include/plat/memory.h8
5 files changed, 32 insertions, 28 deletions
diff --git a/arch/arm/include/asm/dma-mapping.h b/arch/arm/include/asm/dma-mapping.h
index c568da7dcae4..8f69b98f68fc 100644
--- a/arch/arm/include/asm/dma-mapping.h
+++ b/arch/arm/include/asm/dma-mapping.h
@@ -9,20 +9,24 @@
9#include <asm-generic/dma-coherent.h> 9#include <asm-generic/dma-coherent.h>
10#include <asm/memory.h> 10#include <asm/memory.h>
11 11
12#ifdef __arch_page_to_dma
13#error Please update to __arch_pfn_to_dma
14#endif
15
12/* 16/*
13 * page_to_dma/dma_to_virt/virt_to_dma are architecture private functions 17 * dma_to_pfn/pfn_to_dma/dma_to_virt/virt_to_dma are architecture private
14 * used internally by the DMA-mapping API to provide DMA addresses. They 18 * functions used internally by the DMA-mapping API to provide DMA
15 * must not be used by drivers. 19 * addresses. They must not be used by drivers.
16 */ 20 */
17#ifndef __arch_page_to_dma 21#ifndef __arch_pfn_to_dma
18static inline dma_addr_t page_to_dma(struct device *dev, struct page *page) 22static inline dma_addr_t pfn_to_dma(struct device *dev, unsigned long pfn)
19{ 23{
20 return (dma_addr_t)__pfn_to_bus(page_to_pfn(page)); 24 return (dma_addr_t)__pfn_to_bus(pfn);
21} 25}
22 26
23static inline struct page *dma_to_page(struct device *dev, dma_addr_t addr) 27static inline unsigned long dma_to_pfn(struct device *dev, dma_addr_t addr)
24{ 28{
25 return pfn_to_page(__bus_to_pfn(addr)); 29 return __bus_to_pfn(addr);
26} 30}
27 31
28static inline void *dma_to_virt(struct device *dev, dma_addr_t addr) 32static inline void *dma_to_virt(struct device *dev, dma_addr_t addr)
@@ -35,14 +39,14 @@ static inline dma_addr_t virt_to_dma(struct device *dev, void *addr)
35 return (dma_addr_t)__virt_to_bus((unsigned long)(addr)); 39 return (dma_addr_t)__virt_to_bus((unsigned long)(addr));
36} 40}
37#else 41#else
38static inline dma_addr_t page_to_dma(struct device *dev, struct page *page) 42static inline dma_addr_t pfn_to_dma(struct device *dev, unsigned long pfn)
39{ 43{
40 return __arch_page_to_dma(dev, page); 44 return __arch_pfn_to_dma(dev, pfn);
41} 45}
42 46
43static inline struct page *dma_to_page(struct device *dev, dma_addr_t addr) 47static inline unsigned long dma_to_pfn(struct device *dev, dma_addr_t addr)
44{ 48{
45 return __arch_dma_to_page(dev, addr); 49 return __arch_dma_to_pfn(dev, addr);
46} 50}
47 51
48static inline void *dma_to_virt(struct device *dev, dma_addr_t addr) 52static inline void *dma_to_virt(struct device *dev, dma_addr_t addr)
@@ -368,7 +372,7 @@ static inline dma_addr_t dma_map_page(struct device *dev, struct page *page,
368 372
369 __dma_page_cpu_to_dev(page, offset, size, dir); 373 __dma_page_cpu_to_dev(page, offset, size, dir);
370 374
371 return page_to_dma(dev, page) + offset; 375 return pfn_to_dma(dev, page_to_pfn(page)) + offset;
372} 376}
373 377
374/** 378/**
@@ -408,8 +412,8 @@ static inline void dma_unmap_single(struct device *dev, dma_addr_t handle,
408static inline void dma_unmap_page(struct device *dev, dma_addr_t handle, 412static inline void dma_unmap_page(struct device *dev, dma_addr_t handle,
409 size_t size, enum dma_data_direction dir) 413 size_t size, enum dma_data_direction dir)
410{ 414{
411 __dma_page_dev_to_cpu(dma_to_page(dev, handle), handle & ~PAGE_MASK, 415 __dma_page_dev_to_cpu(pfn_to_page(dma_to_pfn(dev, handle)),
412 size, dir); 416 handle & ~PAGE_MASK, size, dir);
413} 417}
414#endif /* CONFIG_DMABOUNCE */ 418#endif /* CONFIG_DMABOUNCE */
415 419
diff --git a/arch/arm/mach-iop13xx/include/mach/memory.h b/arch/arm/mach-iop13xx/include/mach/memory.h
index 7415e4338651..3ad455318868 100644
--- a/arch/arm/mach-iop13xx/include/mach/memory.h
+++ b/arch/arm/mach-iop13xx/include/mach/memory.h
@@ -58,13 +58,13 @@ static inline unsigned long __lbus_to_virt(dma_addr_t x)
58 __dma; \ 58 __dma; \
59 }) 59 })
60 60
61#define __arch_page_to_dma(dev, page) \ 61#define __arch_pfn_to_dma(dev, pfn) \
62 ({ \ 62 ({ \
63 /* __is_lbus_virt() can never be true for RAM pages */ \ 63 /* __is_lbus_virt() can never be true for RAM pages */ \
64 (dma_addr_t)page_to_phys(page); \ 64 (dma_addr_t)__pfn_to_phys(pfn); \
65 }) 65 })
66 66
67#define __arch_dma_to_page(dev, addr) phys_to_page(addr) 67#define __arch_dma_to_pfn(dev, addr) __phys_to_pfn(addr)
68 68
69#endif /* CONFIG_ARCH_IOP13XX */ 69#endif /* CONFIG_ARCH_IOP13XX */
70#endif /* !ASSEMBLY */ 70#endif /* !ASSEMBLY */
diff --git a/arch/arm/mach-ks8695/include/mach/memory.h b/arch/arm/mach-ks8695/include/mach/memory.h
index ffa19aae6e05..bace9a681adc 100644
--- a/arch/arm/mach-ks8695/include/mach/memory.h
+++ b/arch/arm/mach-ks8695/include/mach/memory.h
@@ -35,17 +35,17 @@ extern struct bus_type platform_bus_type;
35 __phys_to_virt(x) : __bus_to_virt(x)); }) 35 __phys_to_virt(x) : __bus_to_virt(x)); })
36#define __arch_virt_to_dma(dev, x) ({ is_lbus_device(dev) ? \ 36#define __arch_virt_to_dma(dev, x) ({ is_lbus_device(dev) ? \
37 (dma_addr_t)__virt_to_phys(x) : (dma_addr_t)__virt_to_bus(x); }) 37 (dma_addr_t)__virt_to_phys(x) : (dma_addr_t)__virt_to_bus(x); })
38#define __arch_page_to_dma(dev, x) \ 38#define __arch_pfn_to_dma(dev, pfn) \
39 ({ dma_addr_t __dma = page_to_phys(page); \ 39 ({ dma_addr_t __dma = __pfn_to_phys(pfn); \
40 if (!is_lbus_device(dev)) \ 40 if (!is_lbus_device(dev)) \
41 __dma = __dma - PHYS_OFFSET + KS8695_PCIMEM_PA; \ 41 __dma = __dma - PHYS_OFFSET + KS8695_PCIMEM_PA; \
42 __dma; }) 42 __dma; })
43 43
44#define __arch_dma_to_page(dev, x) \ 44#define __arch_dma_to_pfn(dev, x) \
45 ({ dma_addr_t __dma = x; \ 45 ({ dma_addr_t __dma = x; \
46 if (!is_lbus_device(dev)) \ 46 if (!is_lbus_device(dev)) \
47 __dma += PHYS_OFFSET - KS8695_PCIMEM_PA; \ 47 __dma += PHYS_OFFSET - KS8695_PCIMEM_PA; \
48 phys_to_page(__dma); \ 48 __phys_to_pfn(__dma); \
49 }) 49 })
50 50
51#endif 51#endif
diff --git a/arch/arm/mm/dma-mapping.c b/arch/arm/mm/dma-mapping.c
index e4dd0646e859..44e72108d7a7 100644
--- a/arch/arm/mm/dma-mapping.c
+++ b/arch/arm/mm/dma-mapping.c
@@ -311,7 +311,7 @@ __dma_alloc(struct device *dev, size_t size, dma_addr_t *handle, gfp_t gfp,
311 addr = page_address(page); 311 addr = page_address(page);
312 312
313 if (addr) 313 if (addr)
314 *handle = page_to_dma(dev, page); 314 *handle = pfn_to_dma(dev, page_to_pfn(page));
315 315
316 return addr; 316 return addr;
317} 317}
@@ -406,7 +406,7 @@ void dma_free_coherent(struct device *dev, size_t size, void *cpu_addr, dma_addr
406 if (!arch_is_coherent()) 406 if (!arch_is_coherent())
407 __dma_free_remap(cpu_addr, size); 407 __dma_free_remap(cpu_addr, size);
408 408
409 __dma_free_buffer(dma_to_page(dev, handle), size); 409 __dma_free_buffer(pfn_to_page(dma_to_pfn(dev, handle)), size);
410} 410}
411EXPORT_SYMBOL(dma_free_coherent); 411EXPORT_SYMBOL(dma_free_coherent);
412 412
diff --git a/arch/arm/plat-omap/include/plat/memory.h b/arch/arm/plat-omap/include/plat/memory.h
index d5306bee44b2..f8d922fb5584 100644
--- a/arch/arm/plat-omap/include/plat/memory.h
+++ b/arch/arm/plat-omap/include/plat/memory.h
@@ -61,17 +61,17 @@
61#define lbus_to_virt(x) ((x) - OMAP1510_LB_OFFSET + PAGE_OFFSET) 61#define lbus_to_virt(x) ((x) - OMAP1510_LB_OFFSET + PAGE_OFFSET)
62#define is_lbus_device(dev) (cpu_is_omap15xx() && dev && (strncmp(dev_name(dev), "ohci", 4) == 0)) 62#define is_lbus_device(dev) (cpu_is_omap15xx() && dev && (strncmp(dev_name(dev), "ohci", 4) == 0))
63 63
64#define __arch_page_to_dma(dev, page) \ 64#define __arch_pfn_to_dma(dev, pfn) \
65 ({ dma_addr_t __dma = page_to_phys(page); \ 65 ({ dma_addr_t __dma = __pfn_to_phys(pfn); \
66 if (is_lbus_device(dev)) \ 66 if (is_lbus_device(dev)) \
67 __dma = __dma - PHYS_OFFSET + OMAP1510_LB_OFFSET; \ 67 __dma = __dma - PHYS_OFFSET + OMAP1510_LB_OFFSET; \
68 __dma; }) 68 __dma; })
69 69
70#define __arch_dma_to_page(dev, addr) \ 70#define __arch_dma_to_pfn(dev, addr) \
71 ({ dma_addr_t __dma = addr; \ 71 ({ dma_addr_t __dma = addr; \
72 if (is_lbus_device(dev)) \ 72 if (is_lbus_device(dev)) \
73 __dma += PHYS_OFFSET - OMAP1510_LB_OFFSET; \ 73 __dma += PHYS_OFFSET - OMAP1510_LB_OFFSET; \
74 phys_to_page(__dma); \ 74 __phys_to_pfn(__dma); \
75 }) 75 })
76 76
77#define __arch_dma_to_virt(dev, addr) ({ (void *) (is_lbus_device(dev) ? \ 77#define __arch_dma_to_virt(dev, addr) ({ (void *) (is_lbus_device(dev) ? \