kernel: define RB_ID_HW_OPTIONS in include/linux/routerboot.h
[openwrt.git] / target / linux / generic / patches-3.10 / 132-mips_inline_dma_ops.patch
1 From 2c58080407554e1bac8fd50d23cb02420524caed Mon Sep 17 00:00:00 2001
2 From: Felix Fietkau <nbd@openwrt.org>
3 Date: Mon, 12 Aug 2013 12:50:22 +0200
4 Subject: [PATCH] MIPS: partially inline dma ops
5
6 Several DMA ops are no-op on many platforms, and the indirection through
7 the mips_dma_map_ops function table is causing the compiler to emit
8 unnecessary code.
9
10 Inlining visibly improves network performance in my tests (on a 24Kc
11 based system), and also slightly reduces code size of a few drivers.
12
13 Signed-off-by: Felix Fietkau <nbd@openwrt.org>
14 ---
15  arch/mips/Kconfig                   |   4 +
16  arch/mips/include/asm/dma-mapping.h | 360 +++++++++++++++++++++++++++++++++++-
17  arch/mips/mm/dma-default.c          | 163 ++--------------
18  3 files changed, 373 insertions(+), 154 deletions(-)
19
20 --- a/arch/mips/Kconfig
21 +++ b/arch/mips/Kconfig
22 @@ -1431,6 +1431,7 @@ config CPU_CAVIUM_OCTEON
23         select LIBFDT
24         select USE_OF
25         select USB_EHCI_BIG_ENDIAN_MMIO
26 +       select SYS_HAS_DMA_OPS
27         help
28           The Cavium Octeon processor is a highly integrated chip containing
29           many ethernet hardware widgets for networking tasks. The processor
30 @@ -1651,6 +1652,9 @@ config SYS_HAS_CPU_XLR
31  config SYS_HAS_CPU_XLP
32         bool
33  
34 +config SYS_HAS_DMA_OPS
35 +       bool
36 +
37  #
38  # CPU may reorder R->R, R->W, W->R, W->W
39  # Reordering beyond LL and SC is handled in WEAK_REORDERING_BEYOND_LLSC
40 --- a/arch/mips/include/asm/dma-mapping.h
41 +++ b/arch/mips/include/asm/dma-mapping.h
42 @@ -1,6 +1,12 @@
43  #ifndef _ASM_DMA_MAPPING_H
44  #define _ASM_DMA_MAPPING_H
45  
46 +#include <linux/kmemcheck.h>
47 +#include <linux/bug.h>
48 +#include <linux/scatterlist.h>
49 +#include <linux/dma-debug.h>
50 +#include <linux/dma-attrs.h>
51 +
52  #include <asm/scatterlist.h>
53  #include <asm/dma-coherence.h>
54  #include <asm/cache.h>
55 @@ -12,12 +18,47 @@
56  
57  extern struct dma_map_ops *mips_dma_map_ops;
58  
59 +void __dma_sync(struct page *page, unsigned long offset, size_t size,
60 +               enum dma_data_direction direction);
61 +void *mips_dma_alloc_coherent(struct device *dev, size_t size,
62 +                             dma_addr_t *dma_handle, gfp_t gfp,
63 +                             struct dma_attrs *attrs);
64 +void mips_dma_free_coherent(struct device *dev, size_t size, void *vaddr,
65 +                           dma_addr_t dma_handle, struct dma_attrs *attrs);
66 +
67  static inline struct dma_map_ops *get_dma_ops(struct device *dev)
68  {
69 +#ifdef CONFIG_SYS_HAS_DMA_OPS
70         if (dev && dev->archdata.dma_ops)
71                 return dev->archdata.dma_ops;
72         else
73                 return mips_dma_map_ops;
74 +#else
75 +       return NULL;
76 +#endif
77 +}
78 +
79 +/*
80 + * Warning on the terminology - Linux calls an uncached area coherent;
81 + * MIPS terminology calls memory areas with hardware maintained coherency
82 + * coherent.
83 + */
84 +
85 +static inline int cpu_is_noncoherent_r10000(struct device *dev)
86 +{
87 +#ifndef CONFIG_SYS_HAS_CPU_R10000
88 +       return 0;
89 +#endif
90 +       return !plat_device_is_coherent(dev) &&
91 +              (current_cpu_type() == CPU_R10000 ||
92 +              current_cpu_type() == CPU_R12000);
93 +}
94 +
95 +static inline struct page *dma_addr_to_page(struct device *dev,
96 +       dma_addr_t dma_addr)
97 +{
98 +       return pfn_to_page(
99 +               plat_dma_addr_to_phys(dev, dma_addr) >> PAGE_SHIFT);
100  }
101  
102  static inline bool dma_capable(struct device *dev, dma_addr_t addr, size_t size)
103 @@ -30,12 +71,309 @@ static inline bool dma_capable(struct de
104  
105  static inline void dma_mark_clean(void *addr, size_t size) {}
106  
107 -#include <asm-generic/dma-mapping-common.h>
108 +static inline dma_addr_t dma_map_single_attrs(struct device *dev, void *ptr,
109 +                                             size_t size,
110 +                                             enum dma_data_direction dir,
111 +                                             struct dma_attrs *attrs)
112 +{
113 +       struct dma_map_ops *ops = get_dma_ops(dev);
114 +       unsigned long offset = (unsigned long)ptr & ~PAGE_MASK;
115 +       struct page *page = virt_to_page(ptr);
116 +       dma_addr_t addr;
117 +
118 +       kmemcheck_mark_initialized(ptr, size);
119 +       BUG_ON(!valid_dma_direction(dir));
120 +       if (ops) {
121 +               addr = ops->map_page(dev, page, offset, size, dir, attrs);
122 +       } else {
123 +               if (!plat_device_is_coherent(dev))
124 +                       __dma_sync(page, offset, size, dir);
125 +
126 +               addr = plat_map_dma_mem_page(dev, page) + offset;
127 +       }
128 +       debug_dma_map_page(dev, page, offset, size, dir, addr, true);
129 +       return addr;
130 +}
131 +
132 +static inline void dma_unmap_single_attrs(struct device *dev, dma_addr_t addr,
133 +                                         size_t size,
134 +                                         enum dma_data_direction dir,
135 +                                         struct dma_attrs *attrs)
136 +{
137 +       struct dma_map_ops *ops = get_dma_ops(dev);
138 +
139 +       BUG_ON(!valid_dma_direction(dir));
140 +       if (ops) {
141 +               ops->unmap_page(dev, addr, size, dir, attrs);
142 +       } else {
143 +               if (cpu_is_noncoherent_r10000(dev))
144 +                       __dma_sync(dma_addr_to_page(dev, addr),
145 +                                  addr & ~PAGE_MASK, size, dir);
146 +
147 +               plat_unmap_dma_mem(dev, addr, size, dir);
148 +       }
149 +       debug_dma_unmap_page(dev, addr, size, dir, true);
150 +}
151 +
152 +static inline int dma_map_sg_attrs(struct device *dev, struct scatterlist *sg,
153 +                                  int nents, enum dma_data_direction dir,
154 +                                  struct dma_attrs *attrs)
155 +{
156 +       struct dma_map_ops *ops = get_dma_ops(dev);
157 +       int i, ents;
158 +       struct scatterlist *s;
159 +
160 +       for_each_sg(sg, s, nents, i)
161 +               kmemcheck_mark_initialized(sg_virt(s), s->length);
162 +       BUG_ON(!valid_dma_direction(dir));
163 +       if (ops) {
164 +               ents = ops->map_sg(dev, sg, nents, dir, attrs);
165 +       } else {
166 +               for_each_sg(sg, s, nents, i) {
167 +                       struct page *page = sg_page(s);
168 +
169 +                       if (!plat_device_is_coherent(dev))
170 +                               __dma_sync(page, s->offset, s->length, dir);
171 +                       s->dma_address =
172 +                               plat_map_dma_mem_page(dev, page) + s->offset;
173 +               }
174 +               ents = nents;
175 +       }
176 +       debug_dma_map_sg(dev, sg, nents, ents, dir);
177 +
178 +       return ents;
179 +}
180 +
181 +static inline void dma_unmap_sg_attrs(struct device *dev, struct scatterlist *sg,
182 +                                     int nents, enum dma_data_direction dir,
183 +                                     struct dma_attrs *attrs)
184 +{
185 +       struct dma_map_ops *ops = get_dma_ops(dev);
186 +       struct scatterlist *s;
187 +       int i;
188 +
189 +       BUG_ON(!valid_dma_direction(dir));
190 +       debug_dma_unmap_sg(dev, sg, nents, dir);
191 +       if (ops) {
192 +               ops->unmap_sg(dev, sg, nents, dir, attrs);
193 +               return;
194 +       }
195 +
196 +       for_each_sg(sg, s, nents, i) {
197 +               if (!plat_device_is_coherent(dev) && dir != DMA_TO_DEVICE)
198 +                       __dma_sync(sg_page(s), s->offset, s->length, dir);
199 +               plat_unmap_dma_mem(dev, s->dma_address, s->length, dir);
200 +       }
201 +}
202 +
203 +static inline dma_addr_t dma_map_page(struct device *dev, struct page *page,
204 +                                     size_t offset, size_t size,
205 +                                     enum dma_data_direction dir)
206 +{
207 +       struct dma_map_ops *ops = get_dma_ops(dev);
208 +       dma_addr_t addr;
209 +
210 +       kmemcheck_mark_initialized(page_address(page) + offset, size);
211 +       BUG_ON(!valid_dma_direction(dir));
212 +       if (ops) {
213 +               addr = ops->map_page(dev, page, offset, size, dir, NULL);
214 +       } else {
215 +               if (!plat_device_is_coherent(dev))
216 +                       __dma_sync(page, offset, size, dir);
217 +
218 +               addr = plat_map_dma_mem_page(dev, page) + offset;
219 +       }
220 +       debug_dma_map_page(dev, page, offset, size, dir, addr, false);
221 +
222 +       return addr;
223 +}
224 +
225 +static inline void dma_unmap_page(struct device *dev, dma_addr_t addr,
226 +                                 size_t size, enum dma_data_direction dir)
227 +{
228 +       struct dma_map_ops *ops = get_dma_ops(dev);
229 +
230 +       BUG_ON(!valid_dma_direction(dir));
231 +       if (ops) {
232 +               ops->unmap_page(dev, addr, size, dir, NULL);
233 +       } else {
234 +               if (cpu_is_noncoherent_r10000(dev))
235 +                       __dma_sync(dma_addr_to_page(dev, addr),
236 +                                  addr & ~PAGE_MASK, size, dir);
237 +
238 +               plat_unmap_dma_mem(dev, addr, size, dir);
239 +       }
240 +       debug_dma_unmap_page(dev, addr, size, dir, false);
241 +}
242 +
243 +static inline void dma_sync_single_for_cpu(struct device *dev, dma_addr_t addr,
244 +                                          size_t size,
245 +                                          enum dma_data_direction dir)
246 +{
247 +       struct dma_map_ops *ops = get_dma_ops(dev);
248 +
249 +       BUG_ON(!valid_dma_direction(dir));
250 +       if (ops)
251 +               ops->sync_single_for_cpu(dev, addr, size, dir);
252 +       else if (cpu_is_noncoherent_r10000(dev))
253 +               __dma_sync(dma_addr_to_page(dev, addr),
254 +                          addr & ~PAGE_MASK, size, dir);
255 +       debug_dma_sync_single_for_cpu(dev, addr, size, dir);
256 +}
257 +
258 +static inline void dma_sync_single_for_device(struct device *dev,
259 +                                             dma_addr_t addr, size_t size,
260 +                                             enum dma_data_direction dir)
261 +{
262 +       struct dma_map_ops *ops = get_dma_ops(dev);
263 +
264 +       BUG_ON(!valid_dma_direction(dir));
265 +       if (ops)
266 +               ops->sync_single_for_device(dev, addr, size, dir);
267 +       else if (!plat_device_is_coherent(dev))
268 +               __dma_sync(dma_addr_to_page(dev, addr),
269 +                          addr & ~PAGE_MASK, size, dir);
270 +       debug_dma_sync_single_for_device(dev, addr, size, dir);
271 +}
272 +
273 +static inline void dma_sync_single_range_for_cpu(struct device *dev,
274 +                                                dma_addr_t addr,
275 +                                                unsigned long offset,
276 +                                                size_t size,
277 +                                                enum dma_data_direction dir)
278 +{
279 +       const struct dma_map_ops *ops = get_dma_ops(dev);
280 +
281 +       BUG_ON(!valid_dma_direction(dir));
282 +       if (ops)
283 +               ops->sync_single_for_cpu(dev, addr + offset, size, dir);
284 +       else if (cpu_is_noncoherent_r10000(dev))
285 +               __dma_sync(dma_addr_to_page(dev, addr + offset),
286 +                          (addr + offset) & ~PAGE_MASK, size, dir);
287 +       debug_dma_sync_single_range_for_cpu(dev, addr, offset, size, dir);
288 +}
289 +
290 +static inline void dma_sync_single_range_for_device(struct device *dev,
291 +                                                   dma_addr_t addr,
292 +                                                   unsigned long offset,
293 +                                                   size_t size,
294 +                                                   enum dma_data_direction dir)
295 +{
296 +       const struct dma_map_ops *ops = get_dma_ops(dev);
297 +
298 +       BUG_ON(!valid_dma_direction(dir));
299 +       if (ops)
300 +               ops->sync_single_for_device(dev, addr + offset, size, dir);
301 +       else if (!plat_device_is_coherent(dev))
302 +               __dma_sync(dma_addr_to_page(dev, addr + offset),
303 +                          (addr + offset) & ~PAGE_MASK, size, dir);
304 +       debug_dma_sync_single_range_for_device(dev, addr, offset, size, dir);
305 +}
306 +
307 +static inline void
308 +dma_sync_sg_for_cpu(struct device *dev, struct scatterlist *sg,
309 +                   int nelems, enum dma_data_direction dir)
310 +{
311 +       struct dma_map_ops *ops = get_dma_ops(dev);
312 +       struct scatterlist *s;
313 +       int i;
314 +
315 +       BUG_ON(!valid_dma_direction(dir));
316 +       if (ops)
317 +               ops->sync_sg_for_cpu(dev, sg, nelems, dir);
318 +       else if (cpu_is_noncoherent_r10000(dev)) {
319 +               for_each_sg(sg, s, nelems, i)
320 +                       __dma_sync(sg_page(s), s->offset, s->length, dir);
321 +       }
322 +       debug_dma_sync_sg_for_cpu(dev, sg, nelems, dir);
323 +}
324 +
325 +static inline void
326 +dma_sync_sg_for_device(struct device *dev, struct scatterlist *sg,
327 +                      int nelems, enum dma_data_direction dir)
328 +{
329 +       struct dma_map_ops *ops = get_dma_ops(dev);
330 +       struct scatterlist *s;
331 +       int i;
332 +
333 +       BUG_ON(!valid_dma_direction(dir));
334 +       if (ops)
335 +               ops->sync_sg_for_device(dev, sg, nelems, dir);
336 +       else if (!plat_device_is_coherent(dev)) {
337 +               for_each_sg(sg, s, nelems, i)
338 +                       __dma_sync(sg_page(s), s->offset, s->length, dir);
339 +       }
340 +       debug_dma_sync_sg_for_device(dev, sg, nelems, dir);
341 +
342 +}
343 +
344 +#define dma_map_single(d, a, s, r) dma_map_single_attrs(d, a, s, r, NULL)
345 +#define dma_unmap_single(d, a, s, r) dma_unmap_single_attrs(d, a, s, r, NULL)
346 +#define dma_map_sg(d, s, n, r) dma_map_sg_attrs(d, s, n, r, NULL)
347 +#define dma_unmap_sg(d, s, n, r) dma_unmap_sg_attrs(d, s, n, r, NULL)
348 +
349 +extern int dma_common_mmap(struct device *dev, struct vm_area_struct *vma,
350 +                          void *cpu_addr, dma_addr_t dma_addr, size_t size);
351 +
352 +/**
353 + * dma_mmap_attrs - map a coherent DMA allocation into user space
354 + * @dev: valid struct device pointer, or NULL for ISA and EISA-like devices
355 + * @vma: vm_area_struct describing requested user mapping
356 + * @cpu_addr: kernel CPU-view address returned from dma_alloc_attrs
357 + * @handle: device-view address returned from dma_alloc_attrs
358 + * @size: size of memory originally requested in dma_alloc_attrs
359 + * @attrs: attributes of mapping properties requested in dma_alloc_attrs
360 + *
361 + * Map a coherent DMA buffer previously allocated by dma_alloc_attrs
362 + * into user space.  The coherent DMA buffer must not be freed by the
363 + * driver until the user space mapping has been released.
364 + */
365 +static inline int
366 +dma_mmap_attrs(struct device *dev, struct vm_area_struct *vma, void *cpu_addr,
367 +              dma_addr_t dma_addr, size_t size, struct dma_attrs *attrs)
368 +{
369 +       struct dma_map_ops *ops = get_dma_ops(dev);
370 +       BUG_ON(!ops);
371 +       if (ops && ops->mmap)
372 +               return ops->mmap(dev, vma, cpu_addr, dma_addr, size, attrs);
373 +       return dma_common_mmap(dev, vma, cpu_addr, dma_addr, size);
374 +}
375 +
376 +#define dma_mmap_coherent(d, v, c, h, s) dma_mmap_attrs(d, v, c, h, s, NULL)
377 +
378 +static inline int dma_mmap_writecombine(struct device *dev, struct vm_area_struct *vma,
379 +                     void *cpu_addr, dma_addr_t dma_addr, size_t size)
380 +{
381 +       DEFINE_DMA_ATTRS(attrs);
382 +       dma_set_attr(DMA_ATTR_WRITE_COMBINE, &attrs);
383 +       return dma_mmap_attrs(dev, vma, cpu_addr, dma_addr, size, &attrs);
384 +}
385 +
386 +int
387 +dma_common_get_sgtable(struct device *dev, struct sg_table *sgt,
388 +                      void *cpu_addr, dma_addr_t dma_addr, size_t size);
389 +
390 +static inline int
391 +dma_get_sgtable_attrs(struct device *dev, struct sg_table *sgt, void *cpu_addr,
392 +                     dma_addr_t dma_addr, size_t size, struct dma_attrs *attrs)
393 +{
394 +       struct dma_map_ops *ops = get_dma_ops(dev);
395 +       BUG_ON(!ops);
396 +       if (ops && ops->get_sgtable)
397 +               return ops->get_sgtable(dev, sgt, cpu_addr, dma_addr, size,
398 +                                       attrs);
399 +       return dma_common_get_sgtable(dev, sgt, cpu_addr, dma_addr, size);
400 +}
401 +
402 +#define dma_get_sgtable(d, t, v, h, s) dma_get_sgtable_attrs(d, t, v, h, s, NULL)
403 +
404  
405  static inline int dma_supported(struct device *dev, u64 mask)
406  {
407         struct dma_map_ops *ops = get_dma_ops(dev);
408 -       return ops->dma_supported(dev, mask);
409 +       if (ops)
410 +               return ops->dma_supported(dev, mask);
411 +       return plat_dma_supported(dev, mask);
412  }
413  
414  static inline int dma_mapping_error(struct device *dev, u64 mask)
415 @@ -43,7 +381,9 @@ static inline int dma_mapping_error(stru
416         struct dma_map_ops *ops = get_dma_ops(dev);
417  
418         debug_dma_mapping_error(dev, mask);
419 -       return ops->mapping_error(dev, mask);
420 +       if (ops)
421 +               return ops->mapping_error(dev, mask);
422 +       return 0;
423  }
424  
425  static inline int
426 @@ -69,7 +409,11 @@ static inline void *dma_alloc_attrs(stru
427         void *ret;
428         struct dma_map_ops *ops = get_dma_ops(dev);
429  
430 -       ret = ops->alloc(dev, size, dma_handle, gfp, attrs);
431 +       if (ops)
432 +               ret = ops->alloc(dev, size, dma_handle, gfp, attrs);
433 +       else
434 +               ret = mips_dma_alloc_coherent(dev, size, dma_handle, gfp,
435 +                                             attrs);
436  
437         debug_dma_alloc_coherent(dev, size, *dma_handle, ret);
438  
439 @@ -84,7 +428,10 @@ static inline void dma_free_attrs(struct
440  {
441         struct dma_map_ops *ops = get_dma_ops(dev);
442  
443 -       ops->free(dev, size, vaddr, dma_handle, attrs);
444 +       if (ops)
445 +               ops->free(dev, size, vaddr, dma_handle, attrs);
446 +       else
447 +               mips_dma_free_coherent(dev, size, vaddr, dma_handle, attrs);
448  
449         debug_dma_free_coherent(dev, size, vaddr, dma_handle);
450  }
451 --- a/arch/mips/mm/dma-default.c
452 +++ b/arch/mips/mm/dma-default.c
453 @@ -24,7 +24,7 @@
454  
455  #ifdef CONFIG_DMA_MAYBE_COHERENT
456  int coherentio = 0;    /* User defined DMA coherency from command line. */
457 -EXPORT_SYMBOL_GPL(coherentio);
458 +EXPORT_SYMBOL(coherentio);
459  int hw_coherentio = 0; /* Actual hardware supported DMA coherency setting. */
460  
461  static int __init setcoherentio(char *str)
462 @@ -44,26 +44,6 @@ static int __init setnocoherentio(char *
463  early_param("nocoherentio", setnocoherentio);
464  #endif
465  
466 -static inline struct page *dma_addr_to_page(struct device *dev,
467 -       dma_addr_t dma_addr)
468 -{
469 -       return pfn_to_page(
470 -               plat_dma_addr_to_phys(dev, dma_addr) >> PAGE_SHIFT);
471 -}
472 -
473 -/*
474 - * Warning on the terminology - Linux calls an uncached area coherent;
475 - * MIPS terminology calls memory areas with hardware maintained coherency
476 - * coherent.
477 - */
478 -
479 -static inline int cpu_is_noncoherent_r10000(struct device *dev)
480 -{
481 -       return !plat_device_is_coherent(dev) &&
482 -              (current_cpu_type() == CPU_R10000 ||
483 -              current_cpu_type() == CPU_R12000);
484 -}
485 -
486  static gfp_t massage_gfp_flags(const struct device *dev, gfp_t gfp)
487  {
488         gfp_t dma_flag;
489 @@ -119,8 +99,9 @@ void *dma_alloc_noncoherent(struct devic
490  }
491  EXPORT_SYMBOL(dma_alloc_noncoherent);
492  
493 -static void *mips_dma_alloc_coherent(struct device *dev, size_t size,
494 -       dma_addr_t * dma_handle, gfp_t gfp, struct dma_attrs *attrs)
495 +void *mips_dma_alloc_coherent(struct device *dev, size_t size,
496 +                             dma_addr_t *dma_handle, gfp_t gfp,
497 +                             struct dma_attrs *attrs)
498  {
499         void *ret;
500  
501 @@ -144,6 +125,7 @@ static void *mips_dma_alloc_coherent(str
502  
503         return ret;
504  }
505 +EXPORT_SYMBOL(mips_dma_alloc_coherent);
506  
507  
508  void dma_free_noncoherent(struct device *dev, size_t size, void *vaddr,
509 @@ -154,8 +136,8 @@ void dma_free_noncoherent(struct device
510  }
511  EXPORT_SYMBOL(dma_free_noncoherent);
512  
513 -static void mips_dma_free_coherent(struct device *dev, size_t size, void *vaddr,
514 -       dma_addr_t dma_handle, struct dma_attrs *attrs)
515 +void mips_dma_free_coherent(struct device *dev, size_t size, void *vaddr,
516 +                           dma_addr_t dma_handle, struct dma_attrs *attrs)
517  {
518         unsigned long addr = (unsigned long) vaddr;
519         int order = get_order(size);
520 @@ -170,6 +152,7 @@ static void mips_dma_free_coherent(struc
521  
522         free_pages(addr, get_order(size));
523  }
524 +EXPORT_SYMBOL(mips_dma_free_coherent);
525  
526  static inline void __dma_sync_virtual(void *addr, size_t size,
527         enum dma_data_direction direction)
528 @@ -198,8 +181,8 @@ static inline void __dma_sync_virtual(vo
529   * If highmem is not configured then the bulk of this loop gets
530   * optimized out.
531   */
532 -static inline void __dma_sync(struct page *page,
533 -       unsigned long offset, size_t size, enum dma_data_direction direction)
534 +void __dma_sync(struct page *page, unsigned long offset, size_t size,
535 +               enum dma_data_direction direction)
536  {
537         size_t left = size;
538  
539 @@ -228,109 +211,7 @@ static inline void __dma_sync(struct pag
540                 left -= len;
541         } while (left);
542  }
543 -
544 -static void mips_dma_unmap_page(struct device *dev, dma_addr_t dma_addr,
545 -       size_t size, enum dma_data_direction direction, struct dma_attrs *attrs)
546 -{
547 -       if (cpu_is_noncoherent_r10000(dev))
548 -               __dma_sync(dma_addr_to_page(dev, dma_addr),
549 -                          dma_addr & ~PAGE_MASK, size, direction);
550 -
551 -       plat_unmap_dma_mem(dev, dma_addr, size, direction);
552 -}
553 -
554 -static int mips_dma_map_sg(struct device *dev, struct scatterlist *sg,
555 -       int nents, enum dma_data_direction direction, struct dma_attrs *attrs)
556 -{
557 -       int i;
558 -
559 -       for (i = 0; i < nents; i++, sg++) {
560 -               if (!plat_device_is_coherent(dev))
561 -                       __dma_sync(sg_page(sg), sg->offset, sg->length,
562 -                                  direction);
563 -               sg->dma_address = plat_map_dma_mem_page(dev, sg_page(sg)) +
564 -                                 sg->offset;
565 -       }
566 -
567 -       return nents;
568 -}
569 -
570 -static dma_addr_t mips_dma_map_page(struct device *dev, struct page *page,
571 -       unsigned long offset, size_t size, enum dma_data_direction direction,
572 -       struct dma_attrs *attrs)
573 -{
574 -       if (!plat_device_is_coherent(dev))
575 -               __dma_sync(page, offset, size, direction);
576 -
577 -       return plat_map_dma_mem_page(dev, page) + offset;
578 -}
579 -
580 -static void mips_dma_unmap_sg(struct device *dev, struct scatterlist *sg,
581 -       int nhwentries, enum dma_data_direction direction,
582 -       struct dma_attrs *attrs)
583 -{
584 -       int i;
585 -
586 -       for (i = 0; i < nhwentries; i++, sg++) {
587 -               if (!plat_device_is_coherent(dev) &&
588 -                   direction != DMA_TO_DEVICE)
589 -                       __dma_sync(sg_page(sg), sg->offset, sg->length,
590 -                                  direction);
591 -               plat_unmap_dma_mem(dev, sg->dma_address, sg->length, direction);
592 -       }
593 -}
594 -
595 -static void mips_dma_sync_single_for_cpu(struct device *dev,
596 -       dma_addr_t dma_handle, size_t size, enum dma_data_direction direction)
597 -{
598 -       if (cpu_is_noncoherent_r10000(dev))
599 -               __dma_sync(dma_addr_to_page(dev, dma_handle),
600 -                          dma_handle & ~PAGE_MASK, size, direction);
601 -}
602 -
603 -static void mips_dma_sync_single_for_device(struct device *dev,
604 -       dma_addr_t dma_handle, size_t size, enum dma_data_direction direction)
605 -{
606 -       if (!plat_device_is_coherent(dev))
607 -               __dma_sync(dma_addr_to_page(dev, dma_handle),
608 -                          dma_handle & ~PAGE_MASK, size, direction);
609 -}
610 -
611 -static void mips_dma_sync_sg_for_cpu(struct device *dev,
612 -       struct scatterlist *sg, int nelems, enum dma_data_direction direction)
613 -{
614 -       int i;
615 -
616 -       /* Make sure that gcc doesn't leave the empty loop body.  */
617 -       for (i = 0; i < nelems; i++, sg++) {
618 -               if (cpu_is_noncoherent_r10000(dev))
619 -                       __dma_sync(sg_page(sg), sg->offset, sg->length,
620 -                                  direction);
621 -       }
622 -}
623 -
624 -static void mips_dma_sync_sg_for_device(struct device *dev,
625 -       struct scatterlist *sg, int nelems, enum dma_data_direction direction)
626 -{
627 -       int i;
628 -
629 -       /* Make sure that gcc doesn't leave the empty loop body.  */
630 -       for (i = 0; i < nelems; i++, sg++) {
631 -               if (!plat_device_is_coherent(dev))
632 -                       __dma_sync(sg_page(sg), sg->offset, sg->length,
633 -                                  direction);
634 -       }
635 -}
636 -
637 -int mips_dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
638 -{
639 -       return 0;
640 -}
641 -
642 -int mips_dma_supported(struct device *dev, u64 mask)
643 -{
644 -       return plat_dma_supported(dev, mask);
645 -}
646 +EXPORT_SYMBOL(__dma_sync);
647  
648  void dma_cache_sync(struct device *dev, void *vaddr, size_t size,
649                          enum dma_data_direction direction)
650 @@ -343,23 +224,10 @@ void dma_cache_sync(struct device *dev,
651  
652  EXPORT_SYMBOL(dma_cache_sync);
653  
654 -static struct dma_map_ops mips_default_dma_map_ops = {
655 -       .alloc = mips_dma_alloc_coherent,
656 -       .free = mips_dma_free_coherent,
657 -       .map_page = mips_dma_map_page,
658 -       .unmap_page = mips_dma_unmap_page,
659 -       .map_sg = mips_dma_map_sg,
660 -       .unmap_sg = mips_dma_unmap_sg,
661 -       .sync_single_for_cpu = mips_dma_sync_single_for_cpu,
662 -       .sync_single_for_device = mips_dma_sync_single_for_device,
663 -       .sync_sg_for_cpu = mips_dma_sync_sg_for_cpu,
664 -       .sync_sg_for_device = mips_dma_sync_sg_for_device,
665 -       .mapping_error = mips_dma_mapping_error,
666 -       .dma_supported = mips_dma_supported
667 -};
668 -
669 -struct dma_map_ops *mips_dma_map_ops = &mips_default_dma_map_ops;
670 +#ifdef CONFIG_SYS_HAS_DMA_OPS
671 +struct dma_map_ops *mips_dma_map_ops = NULL;
672  EXPORT_SYMBOL(mips_dma_map_ops);
673 +#endif
674  
675  #define PREALLOC_DMA_DEBUG_ENTRIES (1 << 16)
676