132-mips_inline_dma_ops.patch 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697
  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. @@ -1571,6 +1571,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. @@ -1866,6 +1867,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,306 @@ 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. + plat_post_dma_flush(dev);
  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. + plat_post_dma_flush(dev);
  252. + debug_dma_sync_single_for_cpu(dev, addr, size, dir);
  253. +}
  254. +
  255. +static inline void dma_sync_single_for_device(struct device *dev,
  256. + dma_addr_t addr, size_t size,
  257. + enum dma_data_direction dir)
  258. +{
  259. + struct dma_map_ops *ops = get_dma_ops(dev);
  260. +
  261. + BUG_ON(!valid_dma_direction(dir));
  262. + if (ops)
  263. + ops->sync_single_for_device(dev, addr, size, dir);
  264. + else if (!plat_device_is_coherent(dev))
  265. + __dma_sync(dma_addr_to_page(dev, addr),
  266. + addr & ~PAGE_MASK, size, dir);
  267. + debug_dma_sync_single_for_device(dev, addr, size, dir);
  268. +}
  269. +
  270. +static inline void dma_sync_single_range_for_cpu(struct device *dev,
  271. + dma_addr_t addr,
  272. + unsigned long offset,
  273. + size_t size,
  274. + enum dma_data_direction dir)
  275. +{
  276. + const struct dma_map_ops *ops = get_dma_ops(dev);
  277. +
  278. + BUG_ON(!valid_dma_direction(dir));
  279. + if (ops)
  280. + ops->sync_single_for_cpu(dev, addr + offset, size, dir);
  281. + else if (cpu_needs_post_dma_flush(dev))
  282. + __dma_sync(dma_addr_to_page(dev, addr + offset),
  283. + (addr + offset) & ~PAGE_MASK, size, dir);
  284. + debug_dma_sync_single_range_for_cpu(dev, addr, offset, size, dir);
  285. +}
  286. +
  287. +static inline void dma_sync_single_range_for_device(struct device *dev,
  288. + dma_addr_t addr,
  289. + unsigned long offset,
  290. + size_t size,
  291. + enum dma_data_direction dir)
  292. +{
  293. + const struct dma_map_ops *ops = get_dma_ops(dev);
  294. +
  295. + BUG_ON(!valid_dma_direction(dir));
  296. + if (ops)
  297. + ops->sync_single_for_device(dev, addr + offset, size, dir);
  298. + else if (!plat_device_is_coherent(dev))
  299. + __dma_sync(dma_addr_to_page(dev, addr + offset),
  300. + (addr + offset) & ~PAGE_MASK, size, dir);
  301. + debug_dma_sync_single_range_for_device(dev, addr, offset, size, dir);
  302. +}
  303. +
  304. +static inline void
  305. +dma_sync_sg_for_cpu(struct device *dev, struct scatterlist *sg,
  306. + int nelems, enum dma_data_direction dir)
  307. +{
  308. + struct dma_map_ops *ops = get_dma_ops(dev);
  309. + struct scatterlist *s;
  310. + int i;
  311. +
  312. + BUG_ON(!valid_dma_direction(dir));
  313. + if (ops)
  314. + ops->sync_sg_for_cpu(dev, sg, nelems, dir);
  315. + else if (cpu_needs_post_dma_flush(dev)) {
  316. + for_each_sg(sg, s, nelems, i)
  317. + __dma_sync(sg_page(s), s->offset, s->length, dir);
  318. + }
  319. + plat_post_dma_flush(dev);
  320. + debug_dma_sync_sg_for_cpu(dev, sg, nelems, dir);
  321. +}
  322. +
  323. +static inline void
  324. +dma_sync_sg_for_device(struct device *dev, struct scatterlist *sg,
  325. + int nelems, enum dma_data_direction dir)
  326. +{
  327. + struct dma_map_ops *ops = get_dma_ops(dev);
  328. + struct scatterlist *s;
  329. + int i;
  330. +
  331. + BUG_ON(!valid_dma_direction(dir));
  332. + if (ops)
  333. + ops->sync_sg_for_device(dev, sg, nelems, dir);
  334. + else if (!plat_device_is_coherent(dev)) {
  335. + for_each_sg(sg, s, nelems, i)
  336. + __dma_sync(sg_page(s), s->offset, s->length, dir);
  337. + }
  338. + debug_dma_sync_sg_for_device(dev, sg, nelems, dir);
  339. +
  340. +}
  341. +
  342. +#define dma_map_single(d, a, s, r) dma_map_single_attrs(d, a, s, r, NULL)
  343. +#define dma_unmap_single(d, a, s, r) dma_unmap_single_attrs(d, a, s, r, NULL)
  344. +#define dma_map_sg(d, s, n, r) dma_map_sg_attrs(d, s, n, r, NULL)
  345. +#define dma_unmap_sg(d, s, n, r) dma_unmap_sg_attrs(d, s, n, r, NULL)
  346. +
  347. +extern int dma_common_mmap(struct device *dev, struct vm_area_struct *vma,
  348. + void *cpu_addr, dma_addr_t dma_addr, size_t size);
  349. +
  350. +/**
  351. + * dma_mmap_attrs - map a coherent DMA allocation into user space
  352. + * @dev: valid struct device pointer, or NULL for ISA and EISA-like devices
  353. + * @vma: vm_area_struct describing requested user mapping
  354. + * @cpu_addr: kernel CPU-view address returned from dma_alloc_attrs
  355. + * @handle: device-view address returned from dma_alloc_attrs
  356. + * @size: size of memory originally requested in dma_alloc_attrs
  357. + * @attrs: attributes of mapping properties requested in dma_alloc_attrs
  358. + *
  359. + * Map a coherent DMA buffer previously allocated by dma_alloc_attrs
  360. + * into user space. The coherent DMA buffer must not be freed by the
  361. + * driver until the user space mapping has been released.
  362. + */
  363. +static inline int
  364. +dma_mmap_attrs(struct device *dev, struct vm_area_struct *vma, 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->mmap)
  370. + return ops->mmap(dev, vma, cpu_addr, dma_addr, size, attrs);
  371. + return dma_common_mmap(dev, vma, cpu_addr, dma_addr, size);
  372. +}
  373. +
  374. +#define dma_mmap_coherent(d, v, c, h, s) dma_mmap_attrs(d, v, c, h, s, NULL)
  375. +
  376. +int
  377. +dma_common_get_sgtable(struct device *dev, struct sg_table *sgt,
  378. + void *cpu_addr, dma_addr_t dma_addr, size_t size);
  379. +
  380. +static inline int
  381. +dma_get_sgtable_attrs(struct device *dev, struct sg_table *sgt, void *cpu_addr,
  382. + dma_addr_t dma_addr, size_t size, struct dma_attrs *attrs)
  383. +{
  384. + struct dma_map_ops *ops = get_dma_ops(dev);
  385. + BUG_ON(!ops);
  386. + if (ops && ops->get_sgtable)
  387. + return ops->get_sgtable(dev, sgt, cpu_addr, dma_addr, size,
  388. + attrs);
  389. + return dma_common_get_sgtable(dev, sgt, cpu_addr, dma_addr, size);
  390. +}
  391. +
  392. +#define dma_get_sgtable(d, t, v, h, s) dma_get_sgtable_attrs(d, t, v, h, s, NULL)
  393. +
  394. static inline int dma_supported(struct device *dev, u64 mask)
  395. {
  396. struct dma_map_ops *ops = get_dma_ops(dev);
  397. - return ops->dma_supported(dev, mask);
  398. + if (ops)
  399. + return ops->dma_supported(dev, mask);
  400. + return plat_dma_supported(dev, mask);
  401. }
  402. static inline int dma_mapping_error(struct device *dev, u64 mask)
  403. @@ -43,7 +380,9 @@ static inline int dma_mapping_error(stru
  404. struct dma_map_ops *ops = get_dma_ops(dev);
  405. debug_dma_mapping_error(dev, mask);
  406. - return ops->mapping_error(dev, mask);
  407. + if (ops)
  408. + return ops->mapping_error(dev, mask);
  409. + return 0;
  410. }
  411. static inline int
  412. @@ -54,7 +393,7 @@ dma_set_mask(struct device *dev, u64 mas
  413. if(!dev->dma_mask || !dma_supported(dev, mask))
  414. return -EIO;
  415. - if (ops->set_dma_mask)
  416. + if (ops && ops->set_dma_mask)
  417. return ops->set_dma_mask(dev, mask);
  418. *dev->dma_mask = mask;
  419. @@ -74,7 +413,11 @@ static inline void *dma_alloc_attrs(stru
  420. void *ret;
  421. struct dma_map_ops *ops = get_dma_ops(dev);
  422. - ret = ops->alloc(dev, size, dma_handle, gfp, attrs);
  423. + if (ops)
  424. + ret = ops->alloc(dev, size, dma_handle, gfp, attrs);
  425. + else
  426. + ret = mips_dma_alloc_coherent(dev, size, dma_handle, gfp,
  427. + attrs);
  428. debug_dma_alloc_coherent(dev, size, *dma_handle, ret);
  429. @@ -89,7 +432,10 @@ static inline void dma_free_attrs(struct
  430. {
  431. struct dma_map_ops *ops = get_dma_ops(dev);
  432. - ops->free(dev, size, vaddr, dma_handle, attrs);
  433. + if (ops)
  434. + ops->free(dev, size, vaddr, dma_handle, attrs);
  435. + else
  436. + mips_dma_free_coherent(dev, size, vaddr, dma_handle, attrs);
  437. debug_dma_free_coherent(dev, size, vaddr, dma_handle);
  438. }
  439. --- a/arch/mips/mm/dma-default.c
  440. +++ b/arch/mips/mm/dma-default.c
  441. @@ -26,7 +26,7 @@
  442. #ifdef CONFIG_DMA_MAYBE_COHERENT
  443. int coherentio = 0; /* User defined DMA coherency from command line. */
  444. -EXPORT_SYMBOL_GPL(coherentio);
  445. +EXPORT_SYMBOL(coherentio);
  446. int hw_coherentio = 0; /* Actual hardware supported DMA coherency setting. */
  447. static int __init setcoherentio(char *str)
  448. @@ -46,35 +46,6 @@ static int __init setnocoherentio(char *
  449. early_param("nocoherentio", setnocoherentio);
  450. #endif
  451. -static inline struct page *dma_addr_to_page(struct device *dev,
  452. - dma_addr_t dma_addr)
  453. -{
  454. - return pfn_to_page(
  455. - plat_dma_addr_to_phys(dev, dma_addr) >> PAGE_SHIFT);
  456. -}
  457. -
  458. -/*
  459. - * The affected CPUs below in 'cpu_needs_post_dma_flush()' can
  460. - * speculatively fill random cachelines with stale data at any time,
  461. - * requiring an extra flush post-DMA.
  462. - *
  463. - * Warning on the terminology - Linux calls an uncached area coherent;
  464. - * MIPS terminology calls memory areas with hardware maintained coherency
  465. - * coherent.
  466. - *
  467. - * Note that the R14000 and R16000 should also be checked for in this
  468. - * condition. However this function is only called on non-I/O-coherent
  469. - * systems and only the R10000 and R12000 are used in such systems, the
  470. - * SGI IP28 Indigo² rsp. SGI IP32 aka O2.
  471. - */
  472. -static inline int cpu_needs_post_dma_flush(struct device *dev)
  473. -{
  474. - return !plat_device_is_coherent(dev) &&
  475. - (boot_cpu_type() == CPU_R10000 ||
  476. - boot_cpu_type() == CPU_R12000 ||
  477. - boot_cpu_type() == CPU_BMIPS5000);
  478. -}
  479. -
  480. static gfp_t massage_gfp_flags(const struct device *dev, gfp_t gfp)
  481. {
  482. gfp_t dma_flag;
  483. @@ -130,8 +101,9 @@ void *dma_alloc_noncoherent(struct devic
  484. }
  485. EXPORT_SYMBOL(dma_alloc_noncoherent);
  486. -static void *mips_dma_alloc_coherent(struct device *dev, size_t size,
  487. - dma_addr_t * dma_handle, gfp_t gfp, struct dma_attrs *attrs)
  488. +void *mips_dma_alloc_coherent(struct device *dev, size_t size,
  489. + dma_addr_t *dma_handle, gfp_t gfp,
  490. + struct dma_attrs *attrs)
  491. {
  492. void *ret;
  493. struct page *page = NULL;
  494. @@ -162,6 +134,7 @@ static void *mips_dma_alloc_coherent(str
  495. return ret;
  496. }
  497. +EXPORT_SYMBOL(mips_dma_alloc_coherent);
  498. void dma_free_noncoherent(struct device *dev, size_t size, void *vaddr,
  499. @@ -172,8 +145,8 @@ void dma_free_noncoherent(struct device
  500. }
  501. EXPORT_SYMBOL(dma_free_noncoherent);
  502. -static void mips_dma_free_coherent(struct device *dev, size_t size, void *vaddr,
  503. - dma_addr_t dma_handle, struct dma_attrs *attrs)
  504. +void mips_dma_free_coherent(struct device *dev, size_t size, void *vaddr,
  505. + dma_addr_t dma_handle, struct dma_attrs *attrs)
  506. {
  507. unsigned long addr = (unsigned long) vaddr;
  508. int order = get_order(size);
  509. @@ -193,6 +166,7 @@ static void mips_dma_free_coherent(struc
  510. if (!dma_release_from_contiguous(dev, page, count))
  511. __free_pages(page, get_order(size));
  512. }
  513. +EXPORT_SYMBOL(mips_dma_free_coherent);
  514. static inline void __dma_sync_virtual(void *addr, size_t size,
  515. enum dma_data_direction direction)
  516. @@ -221,8 +195,8 @@ static inline void __dma_sync_virtual(vo
  517. * If highmem is not configured then the bulk of this loop gets
  518. * optimized out.
  519. */
  520. -static inline void __dma_sync(struct page *page,
  521. - unsigned long offset, size_t size, enum dma_data_direction direction)
  522. +void __dma_sync(struct page *page, unsigned long offset, size_t size,
  523. + enum dma_data_direction direction)
  524. {
  525. size_t left = size;
  526. @@ -251,110 +225,7 @@ static inline void __dma_sync(struct pag
  527. left -= len;
  528. } while (left);
  529. }
  530. -
  531. -static void mips_dma_unmap_page(struct device *dev, dma_addr_t dma_addr,
  532. - size_t size, enum dma_data_direction direction, struct dma_attrs *attrs)
  533. -{
  534. - if (cpu_needs_post_dma_flush(dev))
  535. - __dma_sync(dma_addr_to_page(dev, dma_addr),
  536. - dma_addr & ~PAGE_MASK, size, direction);
  537. - plat_post_dma_flush(dev);
  538. - plat_unmap_dma_mem(dev, dma_addr, size, direction);
  539. -}
  540. -
  541. -static int mips_dma_map_sg(struct device *dev, struct scatterlist *sg,
  542. - int nents, enum dma_data_direction direction, struct dma_attrs *attrs)
  543. -{
  544. - int i;
  545. -
  546. - for (i = 0; i < nents; i++, sg++) {
  547. - if (!plat_device_is_coherent(dev))
  548. - __dma_sync(sg_page(sg), sg->offset, sg->length,
  549. - direction);
  550. -#ifdef CONFIG_NEED_SG_DMA_LENGTH
  551. - sg->dma_length = sg->length;
  552. -#endif
  553. - sg->dma_address = plat_map_dma_mem_page(dev, sg_page(sg)) +
  554. - sg->offset;
  555. - }
  556. -
  557. - return nents;
  558. -}
  559. -
  560. -static dma_addr_t mips_dma_map_page(struct device *dev, struct page *page,
  561. - unsigned long offset, size_t size, enum dma_data_direction direction,
  562. - struct dma_attrs *attrs)
  563. -{
  564. - if (!plat_device_is_coherent(dev))
  565. - __dma_sync(page, offset, size, direction);
  566. -
  567. - return plat_map_dma_mem_page(dev, page) + offset;
  568. -}
  569. -
  570. -static void mips_dma_unmap_sg(struct device *dev, struct scatterlist *sg,
  571. - int nhwentries, enum dma_data_direction direction,
  572. - struct dma_attrs *attrs)
  573. -{
  574. - int i;
  575. -
  576. - for (i = 0; i < nhwentries; i++, sg++) {
  577. - if (!plat_device_is_coherent(dev) &&
  578. - direction != DMA_TO_DEVICE)
  579. - __dma_sync(sg_page(sg), sg->offset, sg->length,
  580. - direction);
  581. - plat_unmap_dma_mem(dev, sg->dma_address, sg->length, direction);
  582. - }
  583. -}
  584. -
  585. -static void mips_dma_sync_single_for_cpu(struct device *dev,
  586. - dma_addr_t dma_handle, size_t size, enum dma_data_direction direction)
  587. -{
  588. - if (cpu_needs_post_dma_flush(dev))
  589. - __dma_sync(dma_addr_to_page(dev, dma_handle),
  590. - dma_handle & ~PAGE_MASK, size, direction);
  591. - plat_post_dma_flush(dev);
  592. -}
  593. -
  594. -static void mips_dma_sync_single_for_device(struct device *dev,
  595. - dma_addr_t dma_handle, size_t size, enum dma_data_direction direction)
  596. -{
  597. - if (!plat_device_is_coherent(dev))
  598. - __dma_sync(dma_addr_to_page(dev, dma_handle),
  599. - dma_handle & ~PAGE_MASK, size, direction);
  600. -}
  601. -
  602. -static void mips_dma_sync_sg_for_cpu(struct device *dev,
  603. - struct scatterlist *sg, int nelems, enum dma_data_direction direction)
  604. -{
  605. - int i;
  606. -
  607. - if (cpu_needs_post_dma_flush(dev))
  608. - for (i = 0; i < nelems; i++, sg++)
  609. - __dma_sync(sg_page(sg), sg->offset, sg->length,
  610. - direction);
  611. - plat_post_dma_flush(dev);
  612. -}
  613. -
  614. -static void mips_dma_sync_sg_for_device(struct device *dev,
  615. - struct scatterlist *sg, int nelems, enum dma_data_direction direction)
  616. -{
  617. - int i;
  618. -
  619. - if (!plat_device_is_coherent(dev))
  620. - for (i = 0; i < nelems; i++, sg++)
  621. - __dma_sync(sg_page(sg), sg->offset, sg->length,
  622. - direction);
  623. -}
  624. -
  625. -int mips_dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
  626. -{
  627. - return 0;
  628. -}
  629. -
  630. -int mips_dma_supported(struct device *dev, u64 mask)
  631. -{
  632. - return plat_dma_supported(dev, mask);
  633. -}
  634. +EXPORT_SYMBOL(__dma_sync);
  635. void dma_cache_sync(struct device *dev, void *vaddr, size_t size,
  636. enum dma_data_direction direction)
  637. @@ -367,23 +238,10 @@ void dma_cache_sync(struct device *dev,
  638. EXPORT_SYMBOL(dma_cache_sync);
  639. -static struct dma_map_ops mips_default_dma_map_ops = {
  640. - .alloc = mips_dma_alloc_coherent,
  641. - .free = mips_dma_free_coherent,
  642. - .map_page = mips_dma_map_page,
  643. - .unmap_page = mips_dma_unmap_page,
  644. - .map_sg = mips_dma_map_sg,
  645. - .unmap_sg = mips_dma_unmap_sg,
  646. - .sync_single_for_cpu = mips_dma_sync_single_for_cpu,
  647. - .sync_single_for_device = mips_dma_sync_single_for_device,
  648. - .sync_sg_for_cpu = mips_dma_sync_sg_for_cpu,
  649. - .sync_sg_for_device = mips_dma_sync_sg_for_device,
  650. - .mapping_error = mips_dma_mapping_error,
  651. - .dma_supported = mips_dma_supported
  652. -};
  653. -
  654. -struct dma_map_ops *mips_dma_map_ops = &mips_default_dma_map_ops;
  655. +#ifdef CONFIG_SYS_HAS_DMA_OPS
  656. +struct dma_map_ops *mips_dma_map_ops = NULL;
  657. EXPORT_SYMBOL(mips_dma_map_ops);
  658. +#endif
  659. #define PREALLOC_DMA_DEBUG_ENTRIES (1 << 16)