132-mips_inline_dma_ops.patch 21 KB

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