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