diff options
author | Christoph Hellwig <hch@lst.de> | 2015-09-09 18:39:39 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2015-09-10 16:29:01 -0400 |
commit | 6894258eda2f9badc28c878086c0e54bd5b7fb30 (patch) | |
tree | 97f59bd766c2d70858d7f683e7302efafe07a349 /arch | |
parent | fb6dd5fa4165c4b82f1a11416c2fc192ae3a84e2 (diff) |
dma-mapping: consolidate dma_{alloc,free}_{attrs,coherent}
Since 2009 we have a nice asm-generic header implementing lots of DMA API
functions for architectures using struct dma_map_ops, but unfortunately
it's still missing a lot of APIs that all architectures still have to
duplicate.
This series consolidates the remaining functions, although we still need
arch opt outs for two of them as a few architectures have very
non-standard implementations.
This patch (of 5):
The coherent DMA allocator works the same over all architectures supporting
dma_map operations.
This patch consolidates them and converges the minor differences:
- the debug_dma helpers are now called from all architectures, including
those that were previously missing them
- dma_alloc_from_coherent and dma_release_from_coherent are now always
called from the generic alloc/free routines instead of the ops
dma-mapping-common.h always includes dma-coherent.h to get the defintions
for them, or the stubs if the architecture doesn't support this feature
- checks for ->alloc / ->free presence are removed. There is only one
magic instead of dma_map_ops without them (mic_dma_ops) and that one
is x86 only anyway.
Besides that only x86 needs special treatment to replace a default devices
if none is passed and tweak the gfp_flags. An optional arch hook is provided
for that.
[linux@roeck-us.net: fix build]
[jcmvbkbc@gmail.com: fix xtensa]
Signed-off-by: Christoph Hellwig <hch@lst.de>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Russell King <linux@arm.linux.org.uk>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Will Deacon <will.deacon@arm.com>
Cc: Yoshinori Sato <ysato@users.sourceforge.jp>
Cc: Michal Simek <monstr@monstr.eu>
Cc: Jonas Bonn <jonas@southpole.se>
Cc: Chris Metcalf <cmetcalf@ezchip.com>
Cc: Guan Xuetao <gxt@mprc.pku.edu.cn>
Cc: Ralf Baechle <ralf@linux-mips.org>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: Andy Shevchenko <andy.shevchenko@gmail.com>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Max Filippov <jcmvbkbc@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'arch')
23 files changed, 12 insertions, 563 deletions
diff --git a/arch/alpha/include/asm/dma-mapping.h b/arch/alpha/include/asm/dma-mapping.h index dfa32f061320..9fef5bd59a82 100644 --- a/arch/alpha/include/asm/dma-mapping.h +++ b/arch/alpha/include/asm/dma-mapping.h | |||
@@ -12,24 +12,6 @@ static inline struct dma_map_ops *get_dma_ops(struct device *dev) | |||
12 | 12 | ||
13 | #include <asm-generic/dma-mapping-common.h> | 13 | #include <asm-generic/dma-mapping-common.h> |
14 | 14 | ||
15 | #define dma_alloc_coherent(d,s,h,f) dma_alloc_attrs(d,s,h,f,NULL) | ||
16 | |||
17 | static inline void *dma_alloc_attrs(struct device *dev, size_t size, | ||
18 | dma_addr_t *dma_handle, gfp_t gfp, | ||
19 | struct dma_attrs *attrs) | ||
20 | { | ||
21 | return get_dma_ops(dev)->alloc(dev, size, dma_handle, gfp, attrs); | ||
22 | } | ||
23 | |||
24 | #define dma_free_coherent(d,s,c,h) dma_free_attrs(d,s,c,h,NULL) | ||
25 | |||
26 | static inline void dma_free_attrs(struct device *dev, size_t size, | ||
27 | void *vaddr, dma_addr_t dma_handle, | ||
28 | struct dma_attrs *attrs) | ||
29 | { | ||
30 | get_dma_ops(dev)->free(dev, size, vaddr, dma_handle, attrs); | ||
31 | } | ||
32 | |||
33 | static inline int dma_mapping_error(struct device *dev, dma_addr_t dma_addr) | 15 | static inline int dma_mapping_error(struct device *dev, dma_addr_t dma_addr) |
34 | { | 16 | { |
35 | return get_dma_ops(dev)->mapping_error(dev, dma_addr); | 17 | return get_dma_ops(dev)->mapping_error(dev, dma_addr); |
diff --git a/arch/arm/include/asm/dma-mapping.h b/arch/arm/include/asm/dma-mapping.h index a68b9d8a71fe..bc404473f1ca 100644 --- a/arch/arm/include/asm/dma-mapping.h +++ b/arch/arm/include/asm/dma-mapping.h | |||
@@ -8,7 +8,6 @@ | |||
8 | #include <linux/dma-attrs.h> | 8 | #include <linux/dma-attrs.h> |
9 | #include <linux/dma-debug.h> | 9 | #include <linux/dma-debug.h> |
10 | 10 | ||
11 | #include <asm-generic/dma-coherent.h> | ||
12 | #include <asm/memory.h> | 11 | #include <asm/memory.h> |
13 | 12 | ||
14 | #include <xen/xen.h> | 13 | #include <xen/xen.h> |
@@ -209,21 +208,6 @@ extern int arm_dma_set_mask(struct device *dev, u64 dma_mask); | |||
209 | extern void *arm_dma_alloc(struct device *dev, size_t size, dma_addr_t *handle, | 208 | extern void *arm_dma_alloc(struct device *dev, size_t size, dma_addr_t *handle, |
210 | gfp_t gfp, struct dma_attrs *attrs); | 209 | gfp_t gfp, struct dma_attrs *attrs); |
211 | 210 | ||
212 | #define dma_alloc_coherent(d, s, h, f) dma_alloc_attrs(d, s, h, f, NULL) | ||
213 | |||
214 | static inline void *dma_alloc_attrs(struct device *dev, size_t size, | ||
215 | dma_addr_t *dma_handle, gfp_t flag, | ||
216 | struct dma_attrs *attrs) | ||
217 | { | ||
218 | struct dma_map_ops *ops = get_dma_ops(dev); | ||
219 | void *cpu_addr; | ||
220 | BUG_ON(!ops); | ||
221 | |||
222 | cpu_addr = ops->alloc(dev, size, dma_handle, flag, attrs); | ||
223 | debug_dma_alloc_coherent(dev, size, *dma_handle, cpu_addr); | ||
224 | return cpu_addr; | ||
225 | } | ||
226 | |||
227 | /** | 211 | /** |
228 | * arm_dma_free - free memory allocated by arm_dma_alloc | 212 | * arm_dma_free - free memory allocated by arm_dma_alloc |
229 | * @dev: valid struct device pointer, or NULL for ISA and EISA-like devices | 213 | * @dev: valid struct device pointer, or NULL for ISA and EISA-like devices |
@@ -241,19 +225,6 @@ static inline void *dma_alloc_attrs(struct device *dev, size_t size, | |||
241 | extern void arm_dma_free(struct device *dev, size_t size, void *cpu_addr, | 225 | extern void arm_dma_free(struct device *dev, size_t size, void *cpu_addr, |
242 | dma_addr_t handle, struct dma_attrs *attrs); | 226 | dma_addr_t handle, struct dma_attrs *attrs); |
243 | 227 | ||
244 | #define dma_free_coherent(d, s, c, h) dma_free_attrs(d, s, c, h, NULL) | ||
245 | |||
246 | static inline void dma_free_attrs(struct device *dev, size_t size, | ||
247 | void *cpu_addr, dma_addr_t dma_handle, | ||
248 | struct dma_attrs *attrs) | ||
249 | { | ||
250 | struct dma_map_ops *ops = get_dma_ops(dev); | ||
251 | BUG_ON(!ops); | ||
252 | |||
253 | debug_dma_free_coherent(dev, size, cpu_addr, dma_handle); | ||
254 | ops->free(dev, size, cpu_addr, dma_handle, attrs); | ||
255 | } | ||
256 | |||
257 | /** | 228 | /** |
258 | * arm_dma_mmap - map a coherent DMA allocation into user space | 229 | * arm_dma_mmap - map a coherent DMA allocation into user space |
259 | * @dev: valid struct device pointer, or NULL for ISA and EISA-like devices | 230 | * @dev: valid struct device pointer, or NULL for ISA and EISA-like devices |
diff --git a/arch/arm/mm/dma-mapping.c b/arch/arm/mm/dma-mapping.c index bf35abcc7d59..e62604384945 100644 --- a/arch/arm/mm/dma-mapping.c +++ b/arch/arm/mm/dma-mapping.c | |||
@@ -676,10 +676,6 @@ void *arm_dma_alloc(struct device *dev, size_t size, dma_addr_t *handle, | |||
676 | gfp_t gfp, struct dma_attrs *attrs) | 676 | gfp_t gfp, struct dma_attrs *attrs) |
677 | { | 677 | { |
678 | pgprot_t prot = __get_dma_pgprot(attrs, PAGE_KERNEL); | 678 | pgprot_t prot = __get_dma_pgprot(attrs, PAGE_KERNEL); |
679 | void *memory; | ||
680 | |||
681 | if (dma_alloc_from_coherent(dev, size, handle, &memory)) | ||
682 | return memory; | ||
683 | 679 | ||
684 | return __dma_alloc(dev, size, handle, gfp, prot, false, | 680 | return __dma_alloc(dev, size, handle, gfp, prot, false, |
685 | attrs, __builtin_return_address(0)); | 681 | attrs, __builtin_return_address(0)); |
@@ -688,11 +684,6 @@ void *arm_dma_alloc(struct device *dev, size_t size, dma_addr_t *handle, | |||
688 | static void *arm_coherent_dma_alloc(struct device *dev, size_t size, | 684 | static void *arm_coherent_dma_alloc(struct device *dev, size_t size, |
689 | dma_addr_t *handle, gfp_t gfp, struct dma_attrs *attrs) | 685 | dma_addr_t *handle, gfp_t gfp, struct dma_attrs *attrs) |
690 | { | 686 | { |
691 | void *memory; | ||
692 | |||
693 | if (dma_alloc_from_coherent(dev, size, handle, &memory)) | ||
694 | return memory; | ||
695 | |||
696 | return __dma_alloc(dev, size, handle, gfp, PAGE_KERNEL, true, | 687 | return __dma_alloc(dev, size, handle, gfp, PAGE_KERNEL, true, |
697 | attrs, __builtin_return_address(0)); | 688 | attrs, __builtin_return_address(0)); |
698 | } | 689 | } |
@@ -752,9 +743,6 @@ static void __arm_dma_free(struct device *dev, size_t size, void *cpu_addr, | |||
752 | struct page *page = pfn_to_page(dma_to_pfn(dev, handle)); | 743 | struct page *page = pfn_to_page(dma_to_pfn(dev, handle)); |
753 | bool want_vaddr = !dma_get_attr(DMA_ATTR_NO_KERNEL_MAPPING, attrs); | 744 | bool want_vaddr = !dma_get_attr(DMA_ATTR_NO_KERNEL_MAPPING, attrs); |
754 | 745 | ||
755 | if (dma_release_from_coherent(dev, get_order(size), cpu_addr)) | ||
756 | return; | ||
757 | |||
758 | size = PAGE_ALIGN(size); | 746 | size = PAGE_ALIGN(size); |
759 | 747 | ||
760 | if (nommu()) { | 748 | if (nommu()) { |
diff --git a/arch/arm64/include/asm/dma-mapping.h b/arch/arm64/include/asm/dma-mapping.h index f0d6d0bfe55c..5e11b3f0fe3a 100644 --- a/arch/arm64/include/asm/dma-mapping.h +++ b/arch/arm64/include/asm/dma-mapping.h | |||
@@ -22,8 +22,6 @@ | |||
22 | #include <linux/types.h> | 22 | #include <linux/types.h> |
23 | #include <linux/vmalloc.h> | 23 | #include <linux/vmalloc.h> |
24 | 24 | ||
25 | #include <asm-generic/dma-coherent.h> | ||
26 | |||
27 | #include <xen/xen.h> | 25 | #include <xen/xen.h> |
28 | #include <asm/xen/hypervisor.h> | 26 | #include <asm/xen/hypervisor.h> |
29 | 27 | ||
@@ -120,37 +118,6 @@ static inline void dma_mark_clean(void *addr, size_t size) | |||
120 | { | 118 | { |
121 | } | 119 | } |
122 | 120 | ||
123 | #define dma_alloc_coherent(d, s, h, f) dma_alloc_attrs(d, s, h, f, NULL) | ||
124 | #define dma_free_coherent(d, s, h, f) dma_free_attrs(d, s, h, f, NULL) | ||
125 | |||
126 | static inline void *dma_alloc_attrs(struct device *dev, size_t size, | ||
127 | dma_addr_t *dma_handle, gfp_t flags, | ||
128 | struct dma_attrs *attrs) | ||
129 | { | ||
130 | struct dma_map_ops *ops = get_dma_ops(dev); | ||
131 | void *vaddr; | ||
132 | |||
133 | if (dma_alloc_from_coherent(dev, size, dma_handle, &vaddr)) | ||
134 | return vaddr; | ||
135 | |||
136 | vaddr = ops->alloc(dev, size, dma_handle, flags, attrs); | ||
137 | debug_dma_alloc_coherent(dev, size, *dma_handle, vaddr); | ||
138 | return vaddr; | ||
139 | } | ||
140 | |||
141 | static inline void dma_free_attrs(struct device *dev, size_t size, | ||
142 | void *vaddr, dma_addr_t dev_addr, | ||
143 | struct dma_attrs *attrs) | ||
144 | { | ||
145 | struct dma_map_ops *ops = get_dma_ops(dev); | ||
146 | |||
147 | if (dma_release_from_coherent(dev, get_order(size), vaddr)) | ||
148 | return; | ||
149 | |||
150 | debug_dma_free_coherent(dev, size, vaddr, dev_addr); | ||
151 | ops->free(dev, size, vaddr, dev_addr, attrs); | ||
152 | } | ||
153 | |||
154 | /* | 121 | /* |
155 | * There is no dma_cache_sync() implementation, so just return NULL here. | 122 | * There is no dma_cache_sync() implementation, so just return NULL here. |
156 | */ | 123 | */ |
diff --git a/arch/h8300/include/asm/dma-mapping.h b/arch/h8300/include/asm/dma-mapping.h index 6e67a90902f2..826aa9b519b7 100644 --- a/arch/h8300/include/asm/dma-mapping.h +++ b/arch/h8300/include/asm/dma-mapping.h | |||
@@ -1,8 +1,6 @@ | |||
1 | #ifndef _H8300_DMA_MAPPING_H | 1 | #ifndef _H8300_DMA_MAPPING_H |
2 | #define _H8300_DMA_MAPPING_H | 2 | #define _H8300_DMA_MAPPING_H |
3 | 3 | ||
4 | #include <asm-generic/dma-coherent.h> | ||
5 | |||
6 | extern struct dma_map_ops h8300_dma_map_ops; | 4 | extern struct dma_map_ops h8300_dma_map_ops; |
7 | 5 | ||
8 | static inline struct dma_map_ops *get_dma_ops(struct device *dev) | 6 | static inline struct dma_map_ops *get_dma_ops(struct device *dev) |
@@ -25,30 +23,6 @@ static inline int dma_set_mask(struct device *dev, u64 mask) | |||
25 | #define dma_alloc_noncoherent(d, s, h, f) dma_alloc_coherent(d, s, h, f) | 23 | #define dma_alloc_noncoherent(d, s, h, f) dma_alloc_coherent(d, s, h, f) |
26 | #define dma_free_noncoherent(d, s, v, h) dma_free_coherent(d, s, v, h) | 24 | #define dma_free_noncoherent(d, s, v, h) dma_free_coherent(d, s, v, h) |
27 | 25 | ||
28 | #define dma_alloc_coherent(d, s, h, f) dma_alloc_attrs(d, s, h, f, NULL) | ||
29 | |||
30 | static inline void *dma_alloc_attrs(struct device *dev, size_t size, | ||
31 | dma_addr_t *dma_handle, gfp_t flag, | ||
32 | struct dma_attrs *attrs) | ||
33 | { | ||
34 | struct dma_map_ops *ops = get_dma_ops(dev); | ||
35 | void *memory; | ||
36 | |||
37 | memory = ops->alloc(dev, size, dma_handle, flag, attrs); | ||
38 | return memory; | ||
39 | } | ||
40 | |||
41 | #define dma_free_coherent(d, s, c, h) dma_free_attrs(d, s, c, h, NULL) | ||
42 | |||
43 | static inline void dma_free_attrs(struct device *dev, size_t size, | ||
44 | void *cpu_addr, dma_addr_t dma_handle, | ||
45 | struct dma_attrs *attrs) | ||
46 | { | ||
47 | struct dma_map_ops *ops = get_dma_ops(dev); | ||
48 | |||
49 | ops->free(dev, size, cpu_addr, dma_handle, attrs); | ||
50 | } | ||
51 | |||
52 | static inline int dma_mapping_error(struct device *dev, dma_addr_t dma_addr) | 26 | static inline int dma_mapping_error(struct device *dev, dma_addr_t dma_addr) |
53 | { | 27 | { |
54 | return 0; | 28 | return 0; |
diff --git a/arch/hexagon/include/asm/dma-mapping.h b/arch/hexagon/include/asm/dma-mapping.h index 16965427f6b4..c20d3caa7dad 100644 --- a/arch/hexagon/include/asm/dma-mapping.h +++ b/arch/hexagon/include/asm/dma-mapping.h | |||
@@ -70,37 +70,4 @@ static inline int dma_mapping_error(struct device *dev, dma_addr_t dma_addr) | |||
70 | return (dma_addr == bad_dma_address); | 70 | return (dma_addr == bad_dma_address); |
71 | } | 71 | } |
72 | 72 | ||
73 | #define dma_alloc_coherent(d,s,h,f) dma_alloc_attrs(d,s,h,f,NULL) | ||
74 | |||
75 | static inline void *dma_alloc_attrs(struct device *dev, size_t size, | ||
76 | dma_addr_t *dma_handle, gfp_t flag, | ||
77 | struct dma_attrs *attrs) | ||
78 | { | ||
79 | void *ret; | ||
80 | struct dma_map_ops *ops = get_dma_ops(dev); | ||
81 | |||
82 | BUG_ON(!dma_ops); | ||
83 | |||
84 | ret = ops->alloc(dev, size, dma_handle, flag, attrs); | ||
85 | |||
86 | debug_dma_alloc_coherent(dev, size, *dma_handle, ret); | ||
87 | |||
88 | return ret; | ||
89 | } | ||
90 | |||
91 | #define dma_free_coherent(d,s,c,h) dma_free_attrs(d,s,c,h,NULL) | ||
92 | |||
93 | static inline void dma_free_attrs(struct device *dev, size_t size, | ||
94 | void *cpu_addr, dma_addr_t dma_handle, | ||
95 | struct dma_attrs *attrs) | ||
96 | { | ||
97 | struct dma_map_ops *dma_ops = get_dma_ops(dev); | ||
98 | |||
99 | BUG_ON(!dma_ops); | ||
100 | |||
101 | dma_ops->free(dev, size, cpu_addr, dma_handle, attrs); | ||
102 | |||
103 | debug_dma_free_coherent(dev, size, cpu_addr, dma_handle); | ||
104 | } | ||
105 | |||
106 | #endif | 73 | #endif |
diff --git a/arch/ia64/include/asm/dma-mapping.h b/arch/ia64/include/asm/dma-mapping.h index cf3ab7e784b5..d36f83cc226a 100644 --- a/arch/ia64/include/asm/dma-mapping.h +++ b/arch/ia64/include/asm/dma-mapping.h | |||
@@ -23,31 +23,6 @@ extern void machvec_dma_sync_single(struct device *, dma_addr_t, size_t, | |||
23 | extern void machvec_dma_sync_sg(struct device *, struct scatterlist *, int, | 23 | extern void machvec_dma_sync_sg(struct device *, struct scatterlist *, int, |
24 | enum dma_data_direction); | 24 | enum dma_data_direction); |
25 | 25 | ||
26 | #define dma_alloc_coherent(d,s,h,f) dma_alloc_attrs(d,s,h,f,NULL) | ||
27 | |||
28 | static inline void *dma_alloc_attrs(struct device *dev, size_t size, | ||
29 | dma_addr_t *daddr, gfp_t gfp, | ||
30 | struct dma_attrs *attrs) | ||
31 | { | ||
32 | struct dma_map_ops *ops = platform_dma_get_ops(dev); | ||
33 | void *caddr; | ||
34 | |||
35 | caddr = ops->alloc(dev, size, daddr, gfp, attrs); | ||
36 | debug_dma_alloc_coherent(dev, size, *daddr, caddr); | ||
37 | return caddr; | ||
38 | } | ||
39 | |||
40 | #define dma_free_coherent(d,s,c,h) dma_free_attrs(d,s,c,h,NULL) | ||
41 | |||
42 | static inline void dma_free_attrs(struct device *dev, size_t size, | ||
43 | void *caddr, dma_addr_t daddr, | ||
44 | struct dma_attrs *attrs) | ||
45 | { | ||
46 | struct dma_map_ops *ops = platform_dma_get_ops(dev); | ||
47 | debug_dma_free_coherent(dev, size, caddr, daddr); | ||
48 | ops->free(dev, size, caddr, daddr, attrs); | ||
49 | } | ||
50 | |||
51 | #define dma_alloc_noncoherent(d, s, h, f) dma_alloc_coherent(d, s, h, f) | 26 | #define dma_alloc_noncoherent(d, s, h, f) dma_alloc_coherent(d, s, h, f) |
52 | #define dma_free_noncoherent(d, s, v, h) dma_free_coherent(d, s, v, h) | 27 | #define dma_free_noncoherent(d, s, v, h) dma_free_coherent(d, s, v, h) |
53 | 28 | ||
diff --git a/arch/microblaze/include/asm/dma-mapping.h b/arch/microblaze/include/asm/dma-mapping.h index ab353723076a..801dbe215a8c 100644 --- a/arch/microblaze/include/asm/dma-mapping.h +++ b/arch/microblaze/include/asm/dma-mapping.h | |||
@@ -27,7 +27,6 @@ | |||
27 | #include <linux/dma-debug.h> | 27 | #include <linux/dma-debug.h> |
28 | #include <linux/dma-attrs.h> | 28 | #include <linux/dma-attrs.h> |
29 | #include <asm/io.h> | 29 | #include <asm/io.h> |
30 | #include <asm-generic/dma-coherent.h> | ||
31 | #include <asm/cacheflush.h> | 30 | #include <asm/cacheflush.h> |
32 | 31 | ||
33 | #define DMA_ERROR_CODE (~(dma_addr_t)0x0) | 32 | #define DMA_ERROR_CODE (~(dma_addr_t)0x0) |
@@ -102,36 +101,6 @@ static inline int dma_mapping_error(struct device *dev, dma_addr_t dma_addr) | |||
102 | #define dma_alloc_noncoherent(d, s, h, f) dma_alloc_coherent(d, s, h, f) | 101 | #define dma_alloc_noncoherent(d, s, h, f) dma_alloc_coherent(d, s, h, f) |
103 | #define dma_free_noncoherent(d, s, v, h) dma_free_coherent(d, s, v, h) | 102 | #define dma_free_noncoherent(d, s, v, h) dma_free_coherent(d, s, v, h) |
104 | 103 | ||
105 | #define dma_alloc_coherent(d, s, h, f) dma_alloc_attrs(d, s, h, f, NULL) | ||
106 | |||
107 | static inline void *dma_alloc_attrs(struct device *dev, size_t size, | ||
108 | dma_addr_t *dma_handle, gfp_t flag, | ||
109 | struct dma_attrs *attrs) | ||
110 | { | ||
111 | struct dma_map_ops *ops = get_dma_ops(dev); | ||
112 | void *memory; | ||
113 | |||
114 | BUG_ON(!ops); | ||
115 | |||
116 | memory = ops->alloc(dev, size, dma_handle, flag, attrs); | ||
117 | |||
118 | debug_dma_alloc_coherent(dev, size, *dma_handle, memory); | ||
119 | return memory; | ||
120 | } | ||
121 | |||
122 | #define dma_free_coherent(d,s,c,h) dma_free_attrs(d, s, c, h, NULL) | ||
123 | |||
124 | static inline void dma_free_attrs(struct device *dev, size_t size, | ||
125 | void *cpu_addr, dma_addr_t dma_handle, | ||
126 | struct dma_attrs *attrs) | ||
127 | { | ||
128 | struct dma_map_ops *ops = get_dma_ops(dev); | ||
129 | |||
130 | BUG_ON(!ops); | ||
131 | debug_dma_free_coherent(dev, size, cpu_addr, dma_handle); | ||
132 | ops->free(dev, size, cpu_addr, dma_handle, attrs); | ||
133 | } | ||
134 | |||
135 | static inline void dma_cache_sync(struct device *dev, void *vaddr, size_t size, | 104 | static inline void dma_cache_sync(struct device *dev, void *vaddr, size_t size, |
136 | enum dma_data_direction direction) | 105 | enum dma_data_direction direction) |
137 | { | 106 | { |
diff --git a/arch/mips/cavium-octeon/dma-octeon.c b/arch/mips/cavium-octeon/dma-octeon.c index d8960d46417b..2cd45f5f9481 100644 --- a/arch/mips/cavium-octeon/dma-octeon.c +++ b/arch/mips/cavium-octeon/dma-octeon.c | |||
@@ -161,9 +161,6 @@ static void *octeon_dma_alloc_coherent(struct device *dev, size_t size, | |||
161 | { | 161 | { |
162 | void *ret; | 162 | void *ret; |
163 | 163 | ||
164 | if (dma_alloc_from_coherent(dev, size, dma_handle, &ret)) | ||
165 | return ret; | ||
166 | |||
167 | /* ignore region specifiers */ | 164 | /* ignore region specifiers */ |
168 | gfp &= ~(__GFP_DMA | __GFP_DMA32 | __GFP_HIGHMEM); | 165 | gfp &= ~(__GFP_DMA | __GFP_DMA32 | __GFP_HIGHMEM); |
169 | 166 | ||
@@ -194,11 +191,6 @@ static void *octeon_dma_alloc_coherent(struct device *dev, size_t size, | |||
194 | static void octeon_dma_free_coherent(struct device *dev, size_t size, | 191 | static void octeon_dma_free_coherent(struct device *dev, size_t size, |
195 | void *vaddr, dma_addr_t dma_handle, struct dma_attrs *attrs) | 192 | void *vaddr, dma_addr_t dma_handle, struct dma_attrs *attrs) |
196 | { | 193 | { |
197 | int order = get_order(size); | ||
198 | |||
199 | if (dma_release_from_coherent(dev, order, vaddr)) | ||
200 | return; | ||
201 | |||
202 | swiotlb_free_coherent(dev, size, vaddr, dma_handle); | 194 | swiotlb_free_coherent(dev, size, vaddr, dma_handle); |
203 | } | 195 | } |
204 | 196 | ||
diff --git a/arch/mips/include/asm/dma-mapping.h b/arch/mips/include/asm/dma-mapping.h index 360b3387182a..b197595134ba 100644 --- a/arch/mips/include/asm/dma-mapping.h +++ b/arch/mips/include/asm/dma-mapping.h | |||
@@ -4,7 +4,6 @@ | |||
4 | #include <linux/scatterlist.h> | 4 | #include <linux/scatterlist.h> |
5 | #include <asm/dma-coherence.h> | 5 | #include <asm/dma-coherence.h> |
6 | #include <asm/cache.h> | 6 | #include <asm/cache.h> |
7 | #include <asm-generic/dma-coherent.h> | ||
8 | 7 | ||
9 | #ifndef CONFIG_SGI_IP27 /* Kludge to fix 2.6.39 build for IP27 */ | 8 | #ifndef CONFIG_SGI_IP27 /* Kludge to fix 2.6.39 build for IP27 */ |
10 | #include <dma-coherence.h> | 9 | #include <dma-coherence.h> |
@@ -65,36 +64,6 @@ dma_set_mask(struct device *dev, u64 mask) | |||
65 | extern void dma_cache_sync(struct device *dev, void *vaddr, size_t size, | 64 | extern void dma_cache_sync(struct device *dev, void *vaddr, size_t size, |
66 | enum dma_data_direction direction); | 65 | enum dma_data_direction direction); |
67 | 66 | ||
68 | #define dma_alloc_coherent(d,s,h,f) dma_alloc_attrs(d,s,h,f,NULL) | ||
69 | |||
70 | static inline void *dma_alloc_attrs(struct device *dev, size_t size, | ||
71 | dma_addr_t *dma_handle, gfp_t gfp, | ||
72 | struct dma_attrs *attrs) | ||
73 | { | ||
74 | void *ret; | ||
75 | struct dma_map_ops *ops = get_dma_ops(dev); | ||
76 | |||
77 | ret = ops->alloc(dev, size, dma_handle, gfp, attrs); | ||
78 | |||
79 | debug_dma_alloc_coherent(dev, size, *dma_handle, ret); | ||
80 | |||
81 | return ret; | ||
82 | } | ||
83 | |||
84 | #define dma_free_coherent(d,s,c,h) dma_free_attrs(d,s,c,h,NULL) | ||
85 | |||
86 | static inline void dma_free_attrs(struct device *dev, size_t size, | ||
87 | void *vaddr, dma_addr_t dma_handle, | ||
88 | struct dma_attrs *attrs) | ||
89 | { | ||
90 | struct dma_map_ops *ops = get_dma_ops(dev); | ||
91 | |||
92 | ops->free(dev, size, vaddr, dma_handle, attrs); | ||
93 | |||
94 | debug_dma_free_coherent(dev, size, vaddr, dma_handle); | ||
95 | } | ||
96 | |||
97 | |||
98 | void *dma_alloc_noncoherent(struct device *dev, size_t size, | 67 | void *dma_alloc_noncoherent(struct device *dev, size_t size, |
99 | dma_addr_t *dma_handle, gfp_t flag); | 68 | dma_addr_t *dma_handle, gfp_t flag); |
100 | 69 | ||
diff --git a/arch/mips/loongson64/common/dma-swiotlb.c b/arch/mips/loongson64/common/dma-swiotlb.c index 2c6b989c1bc4..ef9da3b5c543 100644 --- a/arch/mips/loongson64/common/dma-swiotlb.c +++ b/arch/mips/loongson64/common/dma-swiotlb.c | |||
@@ -14,9 +14,6 @@ static void *loongson_dma_alloc_coherent(struct device *dev, size_t size, | |||
14 | { | 14 | { |
15 | void *ret; | 15 | void *ret; |
16 | 16 | ||
17 | if (dma_alloc_from_coherent(dev, size, dma_handle, &ret)) | ||
18 | return ret; | ||
19 | |||
20 | /* ignore region specifiers */ | 17 | /* ignore region specifiers */ |
21 | gfp &= ~(__GFP_DMA | __GFP_DMA32 | __GFP_HIGHMEM); | 18 | gfp &= ~(__GFP_DMA | __GFP_DMA32 | __GFP_HIGHMEM); |
22 | 19 | ||
@@ -46,11 +43,6 @@ static void *loongson_dma_alloc_coherent(struct device *dev, size_t size, | |||
46 | static void loongson_dma_free_coherent(struct device *dev, size_t size, | 43 | static void loongson_dma_free_coherent(struct device *dev, size_t size, |
47 | void *vaddr, dma_addr_t dma_handle, struct dma_attrs *attrs) | 44 | void *vaddr, dma_addr_t dma_handle, struct dma_attrs *attrs) |
48 | { | 45 | { |
49 | int order = get_order(size); | ||
50 | |||
51 | if (dma_release_from_coherent(dev, order, vaddr)) | ||
52 | return; | ||
53 | |||
54 | swiotlb_free_coherent(dev, size, vaddr, dma_handle); | 46 | swiotlb_free_coherent(dev, size, vaddr, dma_handle); |
55 | } | 47 | } |
56 | 48 | ||
diff --git a/arch/mips/mm/dma-default.c b/arch/mips/mm/dma-default.c index 8f23cf08f4ba..6c0fd13fa8e8 100644 --- a/arch/mips/mm/dma-default.c +++ b/arch/mips/mm/dma-default.c | |||
@@ -137,9 +137,6 @@ static void *mips_dma_alloc_coherent(struct device *dev, size_t size, | |||
137 | struct page *page = NULL; | 137 | struct page *page = NULL; |
138 | unsigned int count = PAGE_ALIGN(size) >> PAGE_SHIFT; | 138 | unsigned int count = PAGE_ALIGN(size) >> PAGE_SHIFT; |
139 | 139 | ||
140 | if (dma_alloc_from_coherent(dev, size, dma_handle, &ret)) | ||
141 | return ret; | ||
142 | |||
143 | gfp = massage_gfp_flags(dev, gfp); | 140 | gfp = massage_gfp_flags(dev, gfp); |
144 | 141 | ||
145 | if (IS_ENABLED(CONFIG_DMA_CMA) && !(gfp & GFP_ATOMIC)) | 142 | if (IS_ENABLED(CONFIG_DMA_CMA) && !(gfp & GFP_ATOMIC)) |
@@ -176,13 +173,9 @@ static void mips_dma_free_coherent(struct device *dev, size_t size, void *vaddr, | |||
176 | dma_addr_t dma_handle, struct dma_attrs *attrs) | 173 | dma_addr_t dma_handle, struct dma_attrs *attrs) |
177 | { | 174 | { |
178 | unsigned long addr = (unsigned long) vaddr; | 175 | unsigned long addr = (unsigned long) vaddr; |
179 | int order = get_order(size); | ||
180 | unsigned int count = PAGE_ALIGN(size) >> PAGE_SHIFT; | 176 | unsigned int count = PAGE_ALIGN(size) >> PAGE_SHIFT; |
181 | struct page *page = NULL; | 177 | struct page *page = NULL; |
182 | 178 | ||
183 | if (dma_release_from_coherent(dev, order, vaddr)) | ||
184 | return; | ||
185 | |||
186 | plat_unmap_dma_mem(dev, dma_handle, size, DMA_BIDIRECTIONAL); | 179 | plat_unmap_dma_mem(dev, dma_handle, size, DMA_BIDIRECTIONAL); |
187 | 180 | ||
188 | if (!plat_device_is_coherent(dev) && !hw_coherentio) | 181 | if (!plat_device_is_coherent(dev) && !hw_coherentio) |
diff --git a/arch/mips/netlogic/common/nlm-dma.c b/arch/mips/netlogic/common/nlm-dma.c index f3d4ae87abc7..3758715d4ab6 100644 --- a/arch/mips/netlogic/common/nlm-dma.c +++ b/arch/mips/netlogic/common/nlm-dma.c | |||
@@ -47,11 +47,6 @@ static char *nlm_swiotlb; | |||
47 | static void *nlm_dma_alloc_coherent(struct device *dev, size_t size, | 47 | static void *nlm_dma_alloc_coherent(struct device *dev, size_t size, |
48 | dma_addr_t *dma_handle, gfp_t gfp, struct dma_attrs *attrs) | 48 | dma_addr_t *dma_handle, gfp_t gfp, struct dma_attrs *attrs) |
49 | { | 49 | { |
50 | void *ret; | ||
51 | |||
52 | if (dma_alloc_from_coherent(dev, size, dma_handle, &ret)) | ||
53 | return ret; | ||
54 | |||
55 | /* ignore region specifiers */ | 50 | /* ignore region specifiers */ |
56 | gfp &= ~(__GFP_DMA | __GFP_DMA32 | __GFP_HIGHMEM); | 51 | gfp &= ~(__GFP_DMA | __GFP_DMA32 | __GFP_HIGHMEM); |
57 | 52 | ||
@@ -69,11 +64,6 @@ static void *nlm_dma_alloc_coherent(struct device *dev, size_t size, | |||
69 | static void nlm_dma_free_coherent(struct device *dev, size_t size, | 64 | static void nlm_dma_free_coherent(struct device *dev, size_t size, |
70 | void *vaddr, dma_addr_t dma_handle, struct dma_attrs *attrs) | 65 | void *vaddr, dma_addr_t dma_handle, struct dma_attrs *attrs) |
71 | { | 66 | { |
72 | int order = get_order(size); | ||
73 | |||
74 | if (dma_release_from_coherent(dev, order, vaddr)) | ||
75 | return; | ||
76 | |||
77 | swiotlb_free_coherent(dev, size, vaddr, dma_handle); | 67 | swiotlb_free_coherent(dev, size, vaddr, dma_handle); |
78 | } | 68 | } |
79 | 69 | ||
diff --git a/arch/openrisc/include/asm/dma-mapping.h b/arch/openrisc/include/asm/dma-mapping.h index fab8628e1b6e..a81d6f68e9c8 100644 --- a/arch/openrisc/include/asm/dma-mapping.h +++ b/arch/openrisc/include/asm/dma-mapping.h | |||
@@ -23,7 +23,6 @@ | |||
23 | */ | 23 | */ |
24 | 24 | ||
25 | #include <linux/dma-debug.h> | 25 | #include <linux/dma-debug.h> |
26 | #include <asm-generic/dma-coherent.h> | ||
27 | #include <linux/kmemcheck.h> | 26 | #include <linux/kmemcheck.h> |
28 | #include <linux/dma-mapping.h> | 27 | #include <linux/dma-mapping.h> |
29 | 28 | ||
@@ -38,35 +37,6 @@ static inline struct dma_map_ops *get_dma_ops(struct device *dev) | |||
38 | 37 | ||
39 | #include <asm-generic/dma-mapping-common.h> | 38 | #include <asm-generic/dma-mapping-common.h> |
40 | 39 | ||
41 | #define dma_alloc_coherent(d,s,h,f) dma_alloc_attrs(d,s,h,f,NULL) | ||
42 | |||
43 | static inline void *dma_alloc_attrs(struct device *dev, size_t size, | ||
44 | dma_addr_t *dma_handle, gfp_t gfp, | ||
45 | struct dma_attrs *attrs) | ||
46 | { | ||
47 | struct dma_map_ops *ops = get_dma_ops(dev); | ||
48 | void *memory; | ||
49 | |||
50 | memory = ops->alloc(dev, size, dma_handle, gfp, attrs); | ||
51 | |||
52 | debug_dma_alloc_coherent(dev, size, *dma_handle, memory); | ||
53 | |||
54 | return memory; | ||
55 | } | ||
56 | |||
57 | #define dma_free_coherent(d,s,c,h) dma_free_attrs(d,s,c,h,NULL) | ||
58 | |||
59 | static inline void dma_free_attrs(struct device *dev, size_t size, | ||
60 | void *cpu_addr, dma_addr_t dma_handle, | ||
61 | struct dma_attrs *attrs) | ||
62 | { | ||
63 | struct dma_map_ops *ops = get_dma_ops(dev); | ||
64 | |||
65 | debug_dma_free_coherent(dev, size, cpu_addr, dma_handle); | ||
66 | |||
67 | ops->free(dev, size, cpu_addr, dma_handle, attrs); | ||
68 | } | ||
69 | |||
70 | static inline void *dma_alloc_noncoherent(struct device *dev, size_t size, | 40 | static inline void *dma_alloc_noncoherent(struct device *dev, size_t size, |
71 | dma_addr_t *dma_handle, gfp_t gfp) | 41 | dma_addr_t *dma_handle, gfp_t gfp) |
72 | { | 42 | { |
diff --git a/arch/powerpc/include/asm/dma-mapping.h b/arch/powerpc/include/asm/dma-mapping.h index 710f60e380e0..e6ca63ac4c6c 100644 --- a/arch/powerpc/include/asm/dma-mapping.h +++ b/arch/powerpc/include/asm/dma-mapping.h | |||
@@ -137,39 +137,6 @@ extern int dma_set_mask(struct device *dev, u64 dma_mask); | |||
137 | extern int __dma_set_mask(struct device *dev, u64 dma_mask); | 137 | extern int __dma_set_mask(struct device *dev, u64 dma_mask); |
138 | extern u64 __dma_get_required_mask(struct device *dev); | 138 | extern u64 __dma_get_required_mask(struct device *dev); |
139 | 139 | ||
140 | #define dma_alloc_coherent(d,s,h,f) dma_alloc_attrs(d,s,h,f,NULL) | ||
141 | |||
142 | static inline void *dma_alloc_attrs(struct device *dev, size_t size, | ||
143 | dma_addr_t *dma_handle, gfp_t flag, | ||
144 | struct dma_attrs *attrs) | ||
145 | { | ||
146 | struct dma_map_ops *dma_ops = get_dma_ops(dev); | ||
147 | void *cpu_addr; | ||
148 | |||
149 | BUG_ON(!dma_ops); | ||
150 | |||
151 | cpu_addr = dma_ops->alloc(dev, size, dma_handle, flag, attrs); | ||
152 | |||
153 | debug_dma_alloc_coherent(dev, size, *dma_handle, cpu_addr); | ||
154 | |||
155 | return cpu_addr; | ||
156 | } | ||
157 | |||
158 | #define dma_free_coherent(d,s,c,h) dma_free_attrs(d,s,c,h,NULL) | ||
159 | |||
160 | static inline void dma_free_attrs(struct device *dev, size_t size, | ||
161 | void *cpu_addr, dma_addr_t dma_handle, | ||
162 | struct dma_attrs *attrs) | ||
163 | { | ||
164 | struct dma_map_ops *dma_ops = get_dma_ops(dev); | ||
165 | |||
166 | BUG_ON(!dma_ops); | ||
167 | |||
168 | debug_dma_free_coherent(dev, size, cpu_addr, dma_handle); | ||
169 | |||
170 | dma_ops->free(dev, size, cpu_addr, dma_handle, attrs); | ||
171 | } | ||
172 | |||
173 | static inline int dma_mapping_error(struct device *dev, dma_addr_t dma_addr) | 140 | static inline int dma_mapping_error(struct device *dev, dma_addr_t dma_addr) |
174 | { | 141 | { |
175 | struct dma_map_ops *dma_ops = get_dma_ops(dev); | 142 | struct dma_map_ops *dma_ops = get_dma_ops(dev); |
diff --git a/arch/s390/include/asm/dma-mapping.h b/arch/s390/include/asm/dma-mapping.h index 9d395961e713..c29c9c7d81e8 100644 --- a/arch/s390/include/asm/dma-mapping.h +++ b/arch/s390/include/asm/dma-mapping.h | |||
@@ -56,35 +56,4 @@ static inline int dma_mapping_error(struct device *dev, dma_addr_t dma_addr) | |||
56 | return dma_addr == DMA_ERROR_CODE; | 56 | return dma_addr == DMA_ERROR_CODE; |
57 | } | 57 | } |
58 | 58 | ||
59 | #define dma_alloc_coherent(d, s, h, f) dma_alloc_attrs(d, s, h, f, NULL) | ||
60 | |||
61 | static inline void *dma_alloc_attrs(struct device *dev, size_t size, | ||
62 | dma_addr_t *dma_handle, gfp_t flags, | ||
63 | struct dma_attrs *attrs) | ||
64 | { | ||
65 | struct dma_map_ops *ops = get_dma_ops(dev); | ||
66 | void *cpu_addr; | ||
67 | |||
68 | BUG_ON(!ops); | ||
69 | |||
70 | cpu_addr = ops->alloc(dev, size, dma_handle, flags, attrs); | ||
71 | debug_dma_alloc_coherent(dev, size, *dma_handle, cpu_addr); | ||
72 | |||
73 | return cpu_addr; | ||
74 | } | ||
75 | |||
76 | #define dma_free_coherent(d, s, c, h) dma_free_attrs(d, s, c, h, NULL) | ||
77 | |||
78 | static inline void dma_free_attrs(struct device *dev, size_t size, | ||
79 | void *cpu_addr, dma_addr_t dma_handle, | ||
80 | struct dma_attrs *attrs) | ||
81 | { | ||
82 | struct dma_map_ops *ops = get_dma_ops(dev); | ||
83 | |||
84 | BUG_ON(!ops); | ||
85 | |||
86 | debug_dma_free_coherent(dev, size, cpu_addr, dma_handle); | ||
87 | ops->free(dev, size, cpu_addr, dma_handle, attrs); | ||
88 | } | ||
89 | |||
90 | #endif /* _ASM_S390_DMA_MAPPING_H */ | 59 | #endif /* _ASM_S390_DMA_MAPPING_H */ |
diff --git a/arch/sh/include/asm/dma-mapping.h b/arch/sh/include/asm/dma-mapping.h index b437f2c780b8..3c78059e66ff 100644 --- a/arch/sh/include/asm/dma-mapping.h +++ b/arch/sh/include/asm/dma-mapping.h | |||
@@ -9,7 +9,6 @@ static inline struct dma_map_ops *get_dma_ops(struct device *dev) | |||
9 | return dma_ops; | 9 | return dma_ops; |
10 | } | 10 | } |
11 | 11 | ||
12 | #include <asm-generic/dma-coherent.h> | ||
13 | #include <asm-generic/dma-mapping-common.h> | 12 | #include <asm-generic/dma-mapping-common.h> |
14 | 13 | ||
15 | static inline int dma_supported(struct device *dev, u64 mask) | 14 | static inline int dma_supported(struct device *dev, u64 mask) |
@@ -53,42 +52,6 @@ static inline int dma_mapping_error(struct device *dev, dma_addr_t dma_addr) | |||
53 | return dma_addr == 0; | 52 | return dma_addr == 0; |
54 | } | 53 | } |
55 | 54 | ||
56 | #define dma_alloc_coherent(d,s,h,f) dma_alloc_attrs(d,s,h,f,NULL) | ||
57 | |||
58 | static inline void *dma_alloc_attrs(struct device *dev, size_t size, | ||
59 | dma_addr_t *dma_handle, gfp_t gfp, | ||
60 | struct dma_attrs *attrs) | ||
61 | { | ||
62 | struct dma_map_ops *ops = get_dma_ops(dev); | ||
63 | void *memory; | ||
64 | |||
65 | if (dma_alloc_from_coherent(dev, size, dma_handle, &memory)) | ||
66 | return memory; | ||
67 | if (!ops->alloc) | ||
68 | return NULL; | ||
69 | |||
70 | memory = ops->alloc(dev, size, dma_handle, gfp, attrs); | ||
71 | debug_dma_alloc_coherent(dev, size, *dma_handle, memory); | ||
72 | |||
73 | return memory; | ||
74 | } | ||
75 | |||
76 | #define dma_free_coherent(d,s,c,h) dma_free_attrs(d,s,c,h,NULL) | ||
77 | |||
78 | static inline void dma_free_attrs(struct device *dev, size_t size, | ||
79 | void *vaddr, dma_addr_t dma_handle, | ||
80 | struct dma_attrs *attrs) | ||
81 | { | ||
82 | struct dma_map_ops *ops = get_dma_ops(dev); | ||
83 | |||
84 | if (dma_release_from_coherent(dev, get_order(size), vaddr)) | ||
85 | return; | ||
86 | |||
87 | debug_dma_free_coherent(dev, size, vaddr, dma_handle); | ||
88 | if (ops->free) | ||
89 | ops->free(dev, size, vaddr, dma_handle, attrs); | ||
90 | } | ||
91 | |||
92 | /* arch/sh/mm/consistent.c */ | 55 | /* arch/sh/mm/consistent.c */ |
93 | extern void *dma_generic_alloc_coherent(struct device *dev, size_t size, | 56 | extern void *dma_generic_alloc_coherent(struct device *dev, size_t size, |
94 | dma_addr_t *dma_addr, gfp_t flag, | 57 | dma_addr_t *dma_addr, gfp_t flag, |
diff --git a/arch/sparc/include/asm/dma-mapping.h b/arch/sparc/include/asm/dma-mapping.h index 7e064c68c5ec..a8c678494ce7 100644 --- a/arch/sparc/include/asm/dma-mapping.h +++ b/arch/sparc/include/asm/dma-mapping.h | |||
@@ -41,32 +41,6 @@ static inline struct dma_map_ops *get_dma_ops(struct device *dev) | |||
41 | 41 | ||
42 | #include <asm-generic/dma-mapping-common.h> | 42 | #include <asm-generic/dma-mapping-common.h> |
43 | 43 | ||
44 | #define dma_alloc_coherent(d,s,h,f) dma_alloc_attrs(d,s,h,f,NULL) | ||
45 | |||
46 | static inline void *dma_alloc_attrs(struct device *dev, size_t size, | ||
47 | dma_addr_t *dma_handle, gfp_t flag, | ||
48 | struct dma_attrs *attrs) | ||
49 | { | ||
50 | struct dma_map_ops *ops = get_dma_ops(dev); | ||
51 | void *cpu_addr; | ||
52 | |||
53 | cpu_addr = ops->alloc(dev, size, dma_handle, flag, attrs); | ||
54 | debug_dma_alloc_coherent(dev, size, *dma_handle, cpu_addr); | ||
55 | return cpu_addr; | ||
56 | } | ||
57 | |||
58 | #define dma_free_coherent(d,s,c,h) dma_free_attrs(d,s,c,h,NULL) | ||
59 | |||
60 | static inline void dma_free_attrs(struct device *dev, size_t size, | ||
61 | void *cpu_addr, dma_addr_t dma_handle, | ||
62 | struct dma_attrs *attrs) | ||
63 | { | ||
64 | struct dma_map_ops *ops = get_dma_ops(dev); | ||
65 | |||
66 | debug_dma_free_coherent(dev, size, cpu_addr, dma_handle); | ||
67 | ops->free(dev, size, cpu_addr, dma_handle, attrs); | ||
68 | } | ||
69 | |||
70 | static inline int dma_mapping_error(struct device *dev, dma_addr_t dma_addr) | 44 | static inline int dma_mapping_error(struct device *dev, dma_addr_t dma_addr) |
71 | { | 45 | { |
72 | debug_dma_mapping_error(dev, dma_addr); | 46 | debug_dma_mapping_error(dev, dma_addr); |
diff --git a/arch/tile/include/asm/dma-mapping.h b/arch/tile/include/asm/dma-mapping.h index 1eae359d8315..4aba10e49310 100644 --- a/arch/tile/include/asm/dma-mapping.h +++ b/arch/tile/include/asm/dma-mapping.h | |||
@@ -116,34 +116,7 @@ dma_set_mask(struct device *dev, u64 mask) | |||
116 | return 0; | 116 | return 0; |
117 | } | 117 | } |
118 | 118 | ||
119 | static inline void *dma_alloc_attrs(struct device *dev, size_t size, | ||
120 | dma_addr_t *dma_handle, gfp_t flag, | ||
121 | struct dma_attrs *attrs) | ||
122 | { | ||
123 | struct dma_map_ops *dma_ops = get_dma_ops(dev); | ||
124 | void *cpu_addr; | ||
125 | |||
126 | cpu_addr = dma_ops->alloc(dev, size, dma_handle, flag, attrs); | ||
127 | |||
128 | debug_dma_alloc_coherent(dev, size, *dma_handle, cpu_addr); | ||
129 | |||
130 | return cpu_addr; | ||
131 | } | ||
132 | |||
133 | static inline void dma_free_attrs(struct device *dev, size_t size, | ||
134 | void *cpu_addr, dma_addr_t dma_handle, | ||
135 | struct dma_attrs *attrs) | ||
136 | { | ||
137 | struct dma_map_ops *dma_ops = get_dma_ops(dev); | ||
138 | |||
139 | debug_dma_free_coherent(dev, size, cpu_addr, dma_handle); | ||
140 | |||
141 | dma_ops->free(dev, size, cpu_addr, dma_handle, attrs); | ||
142 | } | ||
143 | |||
144 | #define dma_alloc_coherent(d, s, h, f) dma_alloc_attrs(d, s, h, f, NULL) | ||
145 | #define dma_alloc_noncoherent(d, s, h, f) dma_alloc_attrs(d, s, h, f, NULL) | 119 | #define dma_alloc_noncoherent(d, s, h, f) dma_alloc_attrs(d, s, h, f, NULL) |
146 | #define dma_free_coherent(d, s, v, h) dma_free_attrs(d, s, v, h, NULL) | ||
147 | #define dma_free_noncoherent(d, s, v, h) dma_free_attrs(d, s, v, h, NULL) | 120 | #define dma_free_noncoherent(d, s, v, h) dma_free_attrs(d, s, v, h, NULL) |
148 | 121 | ||
149 | /* | 122 | /* |
diff --git a/arch/unicore32/include/asm/dma-mapping.h b/arch/unicore32/include/asm/dma-mapping.h index 366460a81796..5294d03e59de 100644 --- a/arch/unicore32/include/asm/dma-mapping.h +++ b/arch/unicore32/include/asm/dma-mapping.h | |||
@@ -18,8 +18,6 @@ | |||
18 | #include <linux/scatterlist.h> | 18 | #include <linux/scatterlist.h> |
19 | #include <linux/swiotlb.h> | 19 | #include <linux/swiotlb.h> |
20 | 20 | ||
21 | #include <asm-generic/dma-coherent.h> | ||
22 | |||
23 | #include <asm/memory.h> | 21 | #include <asm/memory.h> |
24 | #include <asm/cacheflush.h> | 22 | #include <asm/cacheflush.h> |
25 | 23 | ||
@@ -82,28 +80,6 @@ static inline int dma_set_mask(struct device *dev, u64 dma_mask) | |||
82 | return 0; | 80 | return 0; |
83 | } | 81 | } |
84 | 82 | ||
85 | #define dma_alloc_coherent(d,s,h,f) dma_alloc_attrs(d,s,h,f,NULL) | ||
86 | |||
87 | static inline void *dma_alloc_attrs(struct device *dev, size_t size, | ||
88 | dma_addr_t *dma_handle, gfp_t flag, | ||
89 | struct dma_attrs *attrs) | ||
90 | { | ||
91 | struct dma_map_ops *dma_ops = get_dma_ops(dev); | ||
92 | |||
93 | return dma_ops->alloc(dev, size, dma_handle, flag, attrs); | ||
94 | } | ||
95 | |||
96 | #define dma_free_coherent(d,s,c,h) dma_free_attrs(d,s,c,h,NULL) | ||
97 | |||
98 | static inline void dma_free_attrs(struct device *dev, size_t size, | ||
99 | void *cpu_addr, dma_addr_t dma_handle, | ||
100 | struct dma_attrs *attrs) | ||
101 | { | ||
102 | struct dma_map_ops *dma_ops = get_dma_ops(dev); | ||
103 | |||
104 | dma_ops->free(dev, size, cpu_addr, dma_handle, attrs); | ||
105 | } | ||
106 | |||
107 | #define dma_alloc_noncoherent(d, s, h, f) dma_alloc_coherent(d, s, h, f) | 83 | #define dma_alloc_noncoherent(d, s, h, f) dma_alloc_coherent(d, s, h, f) |
108 | #define dma_free_noncoherent(d, s, v, h) dma_free_coherent(d, s, v, h) | 84 | #define dma_free_noncoherent(d, s, v, h) dma_free_coherent(d, s, v, h) |
109 | 85 | ||
diff --git a/arch/x86/include/asm/dma-mapping.h b/arch/x86/include/asm/dma-mapping.h index 1f5b7287d1ad..f9b1b6cc48b6 100644 --- a/arch/x86/include/asm/dma-mapping.h +++ b/arch/x86/include/asm/dma-mapping.h | |||
@@ -12,7 +12,6 @@ | |||
12 | #include <linux/dma-attrs.h> | 12 | #include <linux/dma-attrs.h> |
13 | #include <asm/io.h> | 13 | #include <asm/io.h> |
14 | #include <asm/swiotlb.h> | 14 | #include <asm/swiotlb.h> |
15 | #include <asm-generic/dma-coherent.h> | ||
16 | #include <linux/dma-contiguous.h> | 15 | #include <linux/dma-contiguous.h> |
17 | 16 | ||
18 | #ifdef CONFIG_ISA | 17 | #ifdef CONFIG_ISA |
@@ -41,6 +40,9 @@ static inline struct dma_map_ops *get_dma_ops(struct device *dev) | |||
41 | #endif | 40 | #endif |
42 | } | 41 | } |
43 | 42 | ||
43 | bool arch_dma_alloc_attrs(struct device **dev, gfp_t *gfp); | ||
44 | #define arch_dma_alloc_attrs arch_dma_alloc_attrs | ||
45 | |||
44 | #include <asm-generic/dma-mapping-common.h> | 46 | #include <asm-generic/dma-mapping-common.h> |
45 | 47 | ||
46 | /* Make sure we keep the same behaviour */ | 48 | /* Make sure we keep the same behaviour */ |
@@ -125,16 +127,4 @@ static inline gfp_t dma_alloc_coherent_gfp_flags(struct device *dev, gfp_t gfp) | |||
125 | return gfp; | 127 | return gfp; |
126 | } | 128 | } |
127 | 129 | ||
128 | #define dma_alloc_coherent(d,s,h,f) dma_alloc_attrs(d,s,h,f,NULL) | ||
129 | |||
130 | void * | ||
131 | dma_alloc_attrs(struct device *dev, size_t size, dma_addr_t *dma_handle, | ||
132 | gfp_t gfp, struct dma_attrs *attrs); | ||
133 | |||
134 | #define dma_free_coherent(d,s,c,h) dma_free_attrs(d,s,c,h,NULL) | ||
135 | |||
136 | void dma_free_attrs(struct device *dev, size_t size, | ||
137 | void *vaddr, dma_addr_t bus, | ||
138 | struct dma_attrs *attrs); | ||
139 | |||
140 | #endif | 130 | #endif |
diff --git a/arch/x86/kernel/pci-dma.c b/arch/x86/kernel/pci-dma.c index 353972c1946c..bd23971e8f1d 100644 --- a/arch/x86/kernel/pci-dma.c +++ b/arch/x86/kernel/pci-dma.c | |||
@@ -140,50 +140,19 @@ void dma_generic_free_coherent(struct device *dev, size_t size, void *vaddr, | |||
140 | free_pages((unsigned long)vaddr, get_order(size)); | 140 | free_pages((unsigned long)vaddr, get_order(size)); |
141 | } | 141 | } |
142 | 142 | ||
143 | void *dma_alloc_attrs(struct device *dev, size_t size, dma_addr_t *dma_handle, | 143 | bool arch_dma_alloc_attrs(struct device **dev, gfp_t *gfp) |
144 | gfp_t gfp, struct dma_attrs *attrs) | ||
145 | { | 144 | { |
146 | struct dma_map_ops *ops = get_dma_ops(dev); | 145 | *gfp = dma_alloc_coherent_gfp_flags(*dev, *gfp); |
147 | void *memory; | 146 | *gfp &= ~(__GFP_DMA | __GFP_HIGHMEM | __GFP_DMA32); |
148 | |||
149 | gfp &= ~(__GFP_DMA | __GFP_HIGHMEM | __GFP_DMA32); | ||
150 | |||
151 | if (dma_alloc_from_coherent(dev, size, dma_handle, &memory)) | ||
152 | return memory; | ||
153 | |||
154 | if (!dev) | ||
155 | dev = &x86_dma_fallback_dev; | ||
156 | |||
157 | if (!is_device_dma_capable(dev)) | ||
158 | return NULL; | ||
159 | |||
160 | if (!ops->alloc) | ||
161 | return NULL; | ||
162 | |||
163 | memory = ops->alloc(dev, size, dma_handle, | ||
164 | dma_alloc_coherent_gfp_flags(dev, gfp), attrs); | ||
165 | debug_dma_alloc_coherent(dev, size, *dma_handle, memory); | ||
166 | |||
167 | return memory; | ||
168 | } | ||
169 | EXPORT_SYMBOL(dma_alloc_attrs); | ||
170 | |||
171 | void dma_free_attrs(struct device *dev, size_t size, | ||
172 | void *vaddr, dma_addr_t bus, | ||
173 | struct dma_attrs *attrs) | ||
174 | { | ||
175 | struct dma_map_ops *ops = get_dma_ops(dev); | ||
176 | |||
177 | WARN_ON(irqs_disabled()); /* for portability */ | ||
178 | 147 | ||
179 | if (dma_release_from_coherent(dev, get_order(size), vaddr)) | 148 | if (!*dev) |
180 | return; | 149 | *dev = &x86_dma_fallback_dev; |
150 | if (!is_device_dma_capable(*dev)) | ||
151 | return false; | ||
152 | return true; | ||
181 | 153 | ||
182 | debug_dma_free_coherent(dev, size, vaddr, bus); | ||
183 | if (ops->free) | ||
184 | ops->free(dev, size, vaddr, bus, attrs); | ||
185 | } | 154 | } |
186 | EXPORT_SYMBOL(dma_free_attrs); | 155 | EXPORT_SYMBOL(arch_dma_alloc_attrs); |
187 | 156 | ||
188 | /* | 157 | /* |
189 | * See <Documentation/x86/x86_64/boot-options.txt> for the iommu kernel | 158 | * See <Documentation/x86/x86_64/boot-options.txt> for the iommu kernel |
diff --git a/arch/xtensa/include/asm/dma-mapping.h b/arch/xtensa/include/asm/dma-mapping.h index f01cb3044e50..bf24c908e5ff 100644 --- a/arch/xtensa/include/asm/dma-mapping.h +++ b/arch/xtensa/include/asm/dma-mapping.h | |||
@@ -34,37 +34,6 @@ static inline struct dma_map_ops *get_dma_ops(struct device *dev) | |||
34 | 34 | ||
35 | #define dma_alloc_noncoherent(d, s, h, f) dma_alloc_attrs(d, s, h, f, NULL) | 35 | #define dma_alloc_noncoherent(d, s, h, f) dma_alloc_attrs(d, s, h, f, NULL) |
36 | #define dma_free_noncoherent(d, s, v, h) dma_free_attrs(d, s, v, h, NULL) | 36 | #define dma_free_noncoherent(d, s, v, h) dma_free_attrs(d, s, v, h, NULL) |
37 | #define dma_alloc_coherent(d, s, h, f) dma_alloc_attrs(d, s, h, f, NULL) | ||
38 | #define dma_free_coherent(d, s, c, h) dma_free_attrs(d, s, c, h, NULL) | ||
39 | |||
40 | static inline void *dma_alloc_attrs(struct device *dev, size_t size, | ||
41 | dma_addr_t *dma_handle, gfp_t gfp, | ||
42 | struct dma_attrs *attrs) | ||
43 | { | ||
44 | void *ret; | ||
45 | struct dma_map_ops *ops = get_dma_ops(dev); | ||
46 | |||
47 | if (dma_alloc_from_coherent(dev, size, dma_handle, &ret)) | ||
48 | return ret; | ||
49 | |||
50 | ret = ops->alloc(dev, size, dma_handle, gfp, attrs); | ||
51 | debug_dma_alloc_coherent(dev, size, *dma_handle, ret); | ||
52 | |||
53 | return ret; | ||
54 | } | ||
55 | |||
56 | static inline void dma_free_attrs(struct device *dev, size_t size, | ||
57 | void *vaddr, dma_addr_t dma_handle, | ||
58 | struct dma_attrs *attrs) | ||
59 | { | ||
60 | struct dma_map_ops *ops = get_dma_ops(dev); | ||
61 | |||
62 | if (dma_release_from_coherent(dev, get_order(size), vaddr)) | ||
63 | return; | ||
64 | |||
65 | ops->free(dev, size, vaddr, dma_handle, attrs); | ||
66 | debug_dma_free_coherent(dev, size, vaddr, dma_handle); | ||
67 | } | ||
68 | 37 | ||
69 | static inline int | 38 | static inline int |
70 | dma_mapping_error(struct device *dev, dma_addr_t dma_addr) | 39 | dma_mapping_error(struct device *dev, dma_addr_t dma_addr) |