132-mips_inline_dma_ops.patch 20 KB

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