132-mips_inline_dma_ops.patch 21 KB

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