132-mips_inline_dma_ops.patch 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668
  1. --- a/arch/mips/Kconfig
  2. +++ b/arch/mips/Kconfig
  3. @@ -1377,6 +1377,7 @@ config CPU_CAVIUM_OCTEON
  4. select LIBFDT
  5. select USE_OF
  6. select USB_EHCI_BIG_ENDIAN_MMIO
  7. + select SYS_HAS_DMA_OPS
  8. help
  9. The Cavium Octeon processor is a highly integrated chip containing
  10. many ethernet hardware widgets for networking tasks. The processor
  11. @@ -1599,6 +1600,9 @@ config SYS_HAS_CPU_XLR
  12. config SYS_HAS_CPU_XLP
  13. bool
  14. +config SYS_HAS_DMA_OPS
  15. + bool
  16. +
  17. #
  18. # CPU may reorder R->R, R->W, W->R, W->W
  19. # Reordering beyond LL and SC is handled in WEAK_REORDERING_BEYOND_LLSC
  20. --- a/arch/mips/include/asm/dma-mapping.h
  21. +++ b/arch/mips/include/asm/dma-mapping.h
  22. @@ -1,9 +1,16 @@
  23. #ifndef _ASM_DMA_MAPPING_H
  24. #define _ASM_DMA_MAPPING_H
  25. +#include <linux/kmemcheck.h>
  26. +#include <linux/bug.h>
  27. +#include <linux/scatterlist.h>
  28. +#include <linux/dma-debug.h>
  29. +#include <linux/dma-attrs.h>
  30. +
  31. #include <asm/scatterlist.h>
  32. #include <asm/dma-coherence.h>
  33. #include <asm/cache.h>
  34. +#include <asm/cpu-type.h>
  35. #include <asm-generic/dma-coherent.h>
  36. #ifndef CONFIG_SGI_IP27 /* Kludge to fix 2.6.39 build for IP27 */
  37. @@ -12,12 +19,48 @@
  38. extern struct dma_map_ops *mips_dma_map_ops;
  39. +void __dma_sync(struct page *page, unsigned long offset, size_t size,
  40. + enum dma_data_direction direction);
  41. +void *mips_dma_alloc_coherent(struct device *dev, size_t size,
  42. + dma_addr_t *dma_handle, gfp_t gfp,
  43. + struct dma_attrs *attrs);
  44. +void mips_dma_free_coherent(struct device *dev, size_t size, void *vaddr,
  45. + dma_addr_t dma_handle, struct dma_attrs *attrs);
  46. +
  47. static inline struct dma_map_ops *get_dma_ops(struct device *dev)
  48. {
  49. +#ifdef CONFIG_SYS_HAS_DMA_OPS
  50. if (dev && dev->archdata.dma_ops)
  51. return dev->archdata.dma_ops;
  52. else
  53. return mips_dma_map_ops;
  54. +#else
  55. + return NULL;
  56. +#endif
  57. +}
  58. +
  59. +/*
  60. + * Warning on the terminology - Linux calls an uncached area coherent;
  61. + * MIPS terminology calls memory areas with hardware maintained coherency
  62. + * coherent.
  63. + */
  64. +
  65. +static inline int cpu_needs_post_dma_flush(struct device *dev)
  66. +{
  67. +#ifndef CONFIG_SYS_HAS_CPU_R10000
  68. + return 0;
  69. +#endif
  70. + return !plat_device_is_coherent(dev) &&
  71. + (boot_cpu_type() == CPU_R10000 ||
  72. + boot_cpu_type() == CPU_R12000 ||
  73. + boot_cpu_type() == CPU_BMIPS5000);
  74. +}
  75. +
  76. +static inline struct page *dma_addr_to_page(struct device *dev,
  77. + dma_addr_t dma_addr)
  78. +{
  79. + return pfn_to_page(
  80. + plat_dma_addr_to_phys(dev, dma_addr) >> PAGE_SHIFT);
  81. }
  82. static inline bool dma_capable(struct device *dev, dma_addr_t addr, size_t size)
  83. @@ -30,12 +73,312 @@ static inline bool dma_capable(struct de
  84. static inline void dma_mark_clean(void *addr, size_t size) {}
  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. +static inline int dma_mmap_writecombine(struct device *dev, struct vm_area_struct *vma,
  360. + void *cpu_addr, dma_addr_t dma_addr, size_t size)
  361. +{
  362. + DEFINE_DMA_ATTRS(attrs);
  363. + dma_set_attr(DMA_ATTR_WRITE_COMBINE, &attrs);
  364. + return dma_mmap_attrs(dev, vma, cpu_addr, dma_addr, size, &attrs);
  365. +}
  366. +
  367. +int
  368. +dma_common_get_sgtable(struct device *dev, struct sg_table *sgt,
  369. + void *cpu_addr, dma_addr_t dma_addr, size_t size);
  370. +
  371. +static inline int
  372. +dma_get_sgtable_attrs(struct device *dev, struct sg_table *sgt, void *cpu_addr,
  373. + dma_addr_t dma_addr, size_t size, struct dma_attrs *attrs)
  374. +{
  375. + struct dma_map_ops *ops = get_dma_ops(dev);
  376. + BUG_ON(!ops);
  377. + if (ops && ops->get_sgtable)
  378. + return ops->get_sgtable(dev, sgt, cpu_addr, dma_addr, size,
  379. + attrs);
  380. + return dma_common_get_sgtable(dev, sgt, cpu_addr, dma_addr, size);
  381. +}
  382. +
  383. +#define dma_get_sgtable(d, t, v, h, s) dma_get_sgtable_attrs(d, t, v, h, s, NULL)
  384. +
  385. static inline int dma_supported(struct device *dev, u64 mask)
  386. {
  387. struct dma_map_ops *ops = get_dma_ops(dev);
  388. - return ops->dma_supported(dev, mask);
  389. + if (ops)
  390. + return ops->dma_supported(dev, mask);
  391. + return plat_dma_supported(dev, mask);
  392. }
  393. static inline int dma_mapping_error(struct device *dev, u64 mask)
  394. @@ -43,7 +386,9 @@ static inline int dma_mapping_error(stru
  395. struct dma_map_ops *ops = get_dma_ops(dev);
  396. debug_dma_mapping_error(dev, mask);
  397. - return ops->mapping_error(dev, mask);
  398. + if (ops)
  399. + return ops->mapping_error(dev, mask);
  400. + return 0;
  401. }
  402. static inline int
  403. @@ -69,7 +414,11 @@ static inline void *dma_alloc_attrs(stru
  404. void *ret;
  405. struct dma_map_ops *ops = get_dma_ops(dev);
  406. - ret = ops->alloc(dev, size, dma_handle, gfp, attrs);
  407. + if (ops)
  408. + ret = ops->alloc(dev, size, dma_handle, gfp, attrs);
  409. + else
  410. + ret = mips_dma_alloc_coherent(dev, size, dma_handle, gfp,
  411. + attrs);
  412. debug_dma_alloc_coherent(dev, size, *dma_handle, ret);
  413. @@ -84,7 +433,10 @@ static inline void dma_free_attrs(struct
  414. {
  415. struct dma_map_ops *ops = get_dma_ops(dev);
  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. debug_dma_free_coherent(dev, size, vaddr, dma_handle);
  422. }
  423. --- a/arch/mips/mm/dma-default.c
  424. +++ b/arch/mips/mm/dma-default.c
  425. @@ -25,7 +25,7 @@
  426. #ifdef CONFIG_DMA_MAYBE_COHERENT
  427. int coherentio = 0; /* User defined DMA coherency from command line. */
  428. -EXPORT_SYMBOL_GPL(coherentio);
  429. +EXPORT_SYMBOL(coherentio);
  430. int hw_coherentio = 0; /* Actual hardware supported DMA coherency setting. */
  431. static int __init setcoherentio(char *str)
  432. @@ -45,30 +45,6 @@ static int __init setnocoherentio(char *
  433. early_param("nocoherentio", setnocoherentio);
  434. #endif
  435. -static inline struct page *dma_addr_to_page(struct device *dev,
  436. - dma_addr_t dma_addr)
  437. -{
  438. - return pfn_to_page(
  439. - plat_dma_addr_to_phys(dev, dma_addr) >> PAGE_SHIFT);
  440. -}
  441. -
  442. -/*
  443. - * The affected CPUs below in 'cpu_needs_post_dma_flush()' can
  444. - * speculatively fill random cachelines with stale data at any time,
  445. - * requiring an extra flush post-DMA.
  446. - *
  447. - * Warning on the terminology - Linux calls an uncached area coherent;
  448. - * MIPS terminology calls memory areas with hardware maintained coherency
  449. - * coherent.
  450. - */
  451. -static inline int cpu_needs_post_dma_flush(struct device *dev)
  452. -{
  453. - return !plat_device_is_coherent(dev) &&
  454. - (boot_cpu_type() == CPU_R10000 ||
  455. - boot_cpu_type() == CPU_R12000 ||
  456. - boot_cpu_type() == CPU_BMIPS5000);
  457. -}
  458. -
  459. static gfp_t massage_gfp_flags(const struct device *dev, gfp_t gfp)
  460. {
  461. gfp_t dma_flag;
  462. @@ -124,8 +100,9 @@ void *dma_alloc_noncoherent(struct devic
  463. }
  464. EXPORT_SYMBOL(dma_alloc_noncoherent);
  465. -static void *mips_dma_alloc_coherent(struct device *dev, size_t size,
  466. - dma_addr_t * dma_handle, gfp_t gfp, struct dma_attrs *attrs)
  467. +void *mips_dma_alloc_coherent(struct device *dev, size_t size,
  468. + dma_addr_t *dma_handle, gfp_t gfp,
  469. + struct dma_attrs *attrs)
  470. {
  471. void *ret;
  472. @@ -149,6 +126,7 @@ static void *mips_dma_alloc_coherent(str
  473. return ret;
  474. }
  475. +EXPORT_SYMBOL(mips_dma_alloc_coherent);
  476. void dma_free_noncoherent(struct device *dev, size_t size, void *vaddr,
  477. @@ -159,8 +137,8 @@ void dma_free_noncoherent(struct device
  478. }
  479. EXPORT_SYMBOL(dma_free_noncoherent);
  480. -static void mips_dma_free_coherent(struct device *dev, size_t size, void *vaddr,
  481. - dma_addr_t dma_handle, struct dma_attrs *attrs)
  482. +void mips_dma_free_coherent(struct device *dev, size_t size, void *vaddr,
  483. + dma_addr_t dma_handle, struct dma_attrs *attrs)
  484. {
  485. unsigned long addr = (unsigned long) vaddr;
  486. int order = get_order(size);
  487. @@ -175,6 +153,7 @@ static void mips_dma_free_coherent(struc
  488. free_pages(addr, get_order(size));
  489. }
  490. +EXPORT_SYMBOL(mips_dma_free_coherent);
  491. static inline void __dma_sync_virtual(void *addr, size_t size,
  492. enum dma_data_direction direction)
  493. @@ -203,8 +182,8 @@ static inline void __dma_sync_virtual(vo
  494. * If highmem is not configured then the bulk of this loop gets
  495. * optimized out.
  496. */
  497. -static inline void __dma_sync(struct page *page,
  498. - unsigned long offset, size_t size, enum dma_data_direction direction)
  499. +void __dma_sync(struct page *page, unsigned long offset, size_t size,
  500. + enum dma_data_direction direction)
  501. {
  502. size_t left = size;
  503. @@ -233,108 +212,7 @@ static inline void __dma_sync(struct pag
  504. left -= len;
  505. } while (left);
  506. }
  507. -
  508. -static void mips_dma_unmap_page(struct device *dev, dma_addr_t dma_addr,
  509. - size_t size, enum dma_data_direction direction, struct dma_attrs *attrs)
  510. -{
  511. - if (cpu_needs_post_dma_flush(dev))
  512. - __dma_sync(dma_addr_to_page(dev, dma_addr),
  513. - dma_addr & ~PAGE_MASK, size, direction);
  514. -
  515. - plat_unmap_dma_mem(dev, dma_addr, size, direction);
  516. -}
  517. -
  518. -static int mips_dma_map_sg(struct device *dev, struct scatterlist *sg,
  519. - int nents, enum dma_data_direction direction, struct dma_attrs *attrs)
  520. -{
  521. - int i;
  522. -
  523. - for (i = 0; i < nents; i++, sg++) {
  524. - if (!plat_device_is_coherent(dev))
  525. - __dma_sync(sg_page(sg), sg->offset, sg->length,
  526. - direction);
  527. -#ifdef CONFIG_NEED_SG_DMA_LENGTH
  528. - sg->dma_length = sg->length;
  529. -#endif
  530. - sg->dma_address = plat_map_dma_mem_page(dev, sg_page(sg)) +
  531. - sg->offset;
  532. - }
  533. -
  534. - return nents;
  535. -}
  536. -
  537. -static dma_addr_t mips_dma_map_page(struct device *dev, struct page *page,
  538. - unsigned long offset, size_t size, enum dma_data_direction direction,
  539. - struct dma_attrs *attrs)
  540. -{
  541. - if (!plat_device_is_coherent(dev))
  542. - __dma_sync(page, offset, size, direction);
  543. -
  544. - return plat_map_dma_mem_page(dev, page) + offset;
  545. -}
  546. -
  547. -static void mips_dma_unmap_sg(struct device *dev, struct scatterlist *sg,
  548. - int nhwentries, enum dma_data_direction direction,
  549. - struct dma_attrs *attrs)
  550. -{
  551. - int i;
  552. -
  553. - for (i = 0; i < nhwentries; i++, sg++) {
  554. - if (!plat_device_is_coherent(dev) &&
  555. - direction != DMA_TO_DEVICE)
  556. - __dma_sync(sg_page(sg), sg->offset, sg->length,
  557. - direction);
  558. - plat_unmap_dma_mem(dev, sg->dma_address, sg->length, direction);
  559. - }
  560. -}
  561. -
  562. -static void mips_dma_sync_single_for_cpu(struct device *dev,
  563. - dma_addr_t dma_handle, size_t size, enum dma_data_direction direction)
  564. -{
  565. - if (cpu_needs_post_dma_flush(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_single_for_device(struct device *dev,
  571. - dma_addr_t dma_handle, size_t size, enum dma_data_direction direction)
  572. -{
  573. - if (!plat_device_is_coherent(dev))
  574. - __dma_sync(dma_addr_to_page(dev, dma_handle),
  575. - dma_handle & ~PAGE_MASK, size, direction);
  576. -}
  577. -
  578. -static void mips_dma_sync_sg_for_cpu(struct device *dev,
  579. - struct scatterlist *sg, int nelems, enum dma_data_direction direction)
  580. -{
  581. - int i;
  582. -
  583. - if (cpu_needs_post_dma_flush(dev))
  584. - for (i = 0; i < nelems; i++, sg++)
  585. - __dma_sync(sg_page(sg), sg->offset, sg->length,
  586. - direction);
  587. -}
  588. -
  589. -static void mips_dma_sync_sg_for_device(struct device *dev,
  590. - struct scatterlist *sg, int nelems, enum dma_data_direction direction)
  591. -{
  592. - int i;
  593. -
  594. - if (!plat_device_is_coherent(dev))
  595. - for (i = 0; i < nelems; i++, sg++)
  596. - __dma_sync(sg_page(sg), sg->offset, sg->length,
  597. - direction);
  598. -}
  599. -
  600. -int mips_dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
  601. -{
  602. - return 0;
  603. -}
  604. -
  605. -int mips_dma_supported(struct device *dev, u64 mask)
  606. -{
  607. - return plat_dma_supported(dev, mask);
  608. -}
  609. +EXPORT_SYMBOL(__dma_sync);
  610. void dma_cache_sync(struct device *dev, void *vaddr, size_t size,
  611. enum dma_data_direction direction)
  612. @@ -347,23 +225,10 @@ void dma_cache_sync(struct device *dev,
  613. EXPORT_SYMBOL(dma_cache_sync);
  614. -static struct dma_map_ops mips_default_dma_map_ops = {
  615. - .alloc = mips_dma_alloc_coherent,
  616. - .free = mips_dma_free_coherent,
  617. - .map_page = mips_dma_map_page,
  618. - .unmap_page = mips_dma_unmap_page,
  619. - .map_sg = mips_dma_map_sg,
  620. - .unmap_sg = mips_dma_unmap_sg,
  621. - .sync_single_for_cpu = mips_dma_sync_single_for_cpu,
  622. - .sync_single_for_device = mips_dma_sync_single_for_device,
  623. - .sync_sg_for_cpu = mips_dma_sync_sg_for_cpu,
  624. - .sync_sg_for_device = mips_dma_sync_sg_for_device,
  625. - .mapping_error = mips_dma_mapping_error,
  626. - .dma_supported = mips_dma_supported
  627. -};
  628. -
  629. -struct dma_map_ops *mips_dma_map_ops = &mips_default_dma_map_ops;
  630. +#ifdef CONFIG_SYS_HAS_DMA_OPS
  631. +struct dma_map_ops *mips_dma_map_ops = NULL;
  632. EXPORT_SYMBOL(mips_dma_map_ops);
  633. +#endif
  634. #define PREALLOC_DMA_DEBUG_ENTRIES (1 << 16)