dma-mapping.h 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  1. #ifndef _ASM_SPARC64_DMA_MAPPING_H
  2. #define _ASM_SPARC64_DMA_MAPPING_H
  3. #ifdef CONFIG_PCI
  4. /* we implement the API below in terms of the existing PCI one,
  5. * so include it */
  6. #include <linux/pci.h>
  7. /* need struct page definitions */
  8. #include <linux/mm.h>
  9. #include <asm/of_device.h>
  10. static inline int
  11. dma_supported(struct device *dev, u64 mask)
  12. {
  13. BUG_ON(dev->bus != &pci_bus_type &&
  14. dev->bus != &ebus_bus_type);
  15. return pci_dma_supported(to_pci_dev(dev), mask);
  16. }
  17. static inline int
  18. dma_set_mask(struct device *dev, u64 dma_mask)
  19. {
  20. BUG_ON(dev->bus != &pci_bus_type &&
  21. dev->bus != &ebus_bus_type);
  22. return pci_set_dma_mask(to_pci_dev(dev), dma_mask);
  23. }
  24. static inline void *
  25. dma_alloc_coherent(struct device *dev, size_t size, dma_addr_t *dma_handle,
  26. gfp_t flag)
  27. {
  28. BUG_ON(dev->bus != &pci_bus_type &&
  29. dev->bus != &ebus_bus_type);
  30. return pci_iommu_ops->alloc_consistent(to_pci_dev(dev), size, dma_handle, flag);
  31. }
  32. static inline void
  33. dma_free_coherent(struct device *dev, size_t size, void *cpu_addr,
  34. dma_addr_t dma_handle)
  35. {
  36. BUG_ON(dev->bus != &pci_bus_type &&
  37. dev->bus != &ebus_bus_type);
  38. pci_free_consistent(to_pci_dev(dev), size, cpu_addr, dma_handle);
  39. }
  40. static inline dma_addr_t
  41. dma_map_single(struct device *dev, void *cpu_addr, size_t size,
  42. enum dma_data_direction direction)
  43. {
  44. BUG_ON(dev->bus != &pci_bus_type &&
  45. dev->bus != &ebus_bus_type);
  46. return pci_map_single(to_pci_dev(dev), cpu_addr, size, (int)direction);
  47. }
  48. static inline void
  49. dma_unmap_single(struct device *dev, dma_addr_t dma_addr, size_t size,
  50. enum dma_data_direction direction)
  51. {
  52. BUG_ON(dev->bus != &pci_bus_type &&
  53. dev->bus != &ebus_bus_type);
  54. pci_unmap_single(to_pci_dev(dev), dma_addr, size, (int)direction);
  55. }
  56. static inline dma_addr_t
  57. dma_map_page(struct device *dev, struct page *page,
  58. unsigned long offset, size_t size,
  59. enum dma_data_direction direction)
  60. {
  61. BUG_ON(dev->bus != &pci_bus_type &&
  62. dev->bus != &ebus_bus_type);
  63. return pci_map_page(to_pci_dev(dev), page, offset, size, (int)direction);
  64. }
  65. static inline void
  66. dma_unmap_page(struct device *dev, dma_addr_t dma_address, size_t size,
  67. enum dma_data_direction direction)
  68. {
  69. BUG_ON(dev->bus != &pci_bus_type &&
  70. dev->bus != &ebus_bus_type);
  71. pci_unmap_page(to_pci_dev(dev), dma_address, size, (int)direction);
  72. }
  73. static inline int
  74. dma_map_sg(struct device *dev, struct scatterlist *sg, int nents,
  75. enum dma_data_direction direction)
  76. {
  77. BUG_ON(dev->bus != &pci_bus_type &&
  78. dev->bus != &ebus_bus_type);
  79. return pci_map_sg(to_pci_dev(dev), sg, nents, (int)direction);
  80. }
  81. static inline void
  82. dma_unmap_sg(struct device *dev, struct scatterlist *sg, int nhwentries,
  83. enum dma_data_direction direction)
  84. {
  85. BUG_ON(dev->bus != &pci_bus_type &&
  86. dev->bus != &ebus_bus_type);
  87. pci_unmap_sg(to_pci_dev(dev), sg, nhwentries, (int)direction);
  88. }
  89. static inline void
  90. dma_sync_single_for_cpu(struct device *dev, dma_addr_t dma_handle, size_t size,
  91. enum dma_data_direction direction)
  92. {
  93. BUG_ON(dev->bus != &pci_bus_type &&
  94. dev->bus != &ebus_bus_type);
  95. pci_dma_sync_single_for_cpu(to_pci_dev(dev), dma_handle,
  96. size, (int)direction);
  97. }
  98. static inline void
  99. dma_sync_single_for_device(struct device *dev, dma_addr_t dma_handle, size_t size,
  100. enum dma_data_direction direction)
  101. {
  102. BUG_ON(dev->bus != &pci_bus_type &&
  103. dev->bus != &ebus_bus_type);
  104. pci_dma_sync_single_for_device(to_pci_dev(dev), dma_handle,
  105. size, (int)direction);
  106. }
  107. static inline void
  108. dma_sync_sg_for_cpu(struct device *dev, struct scatterlist *sg, int nelems,
  109. enum dma_data_direction direction)
  110. {
  111. BUG_ON(dev->bus != &pci_bus_type &&
  112. dev->bus != &ebus_bus_type);
  113. pci_dma_sync_sg_for_cpu(to_pci_dev(dev), sg, nelems, (int)direction);
  114. }
  115. static inline void
  116. dma_sync_sg_for_device(struct device *dev, struct scatterlist *sg, int nelems,
  117. enum dma_data_direction direction)
  118. {
  119. BUG_ON(dev->bus != &pci_bus_type &&
  120. dev->bus != &ebus_bus_type);
  121. pci_dma_sync_sg_for_device(to_pci_dev(dev), sg, nelems, (int)direction);
  122. }
  123. static inline int
  124. dma_mapping_error(dma_addr_t dma_addr)
  125. {
  126. return pci_dma_mapping_error(dma_addr);
  127. }
  128. #else
  129. struct device;
  130. struct page;
  131. struct scatterlist;
  132. static inline int
  133. dma_supported(struct device *dev, u64 mask)
  134. {
  135. BUG();
  136. return 0;
  137. }
  138. static inline int
  139. dma_set_mask(struct device *dev, u64 dma_mask)
  140. {
  141. BUG();
  142. return 0;
  143. }
  144. static inline void *dma_alloc_coherent(struct device *dev, size_t size,
  145. dma_addr_t *dma_handle, gfp_t flag)
  146. {
  147. BUG();
  148. return NULL;
  149. }
  150. static inline void dma_free_coherent(struct device *dev, size_t size,
  151. void *vaddr, dma_addr_t dma_handle)
  152. {
  153. BUG();
  154. }
  155. static inline dma_addr_t
  156. dma_map_single(struct device *dev, void *cpu_addr, size_t size,
  157. enum dma_data_direction direction)
  158. {
  159. BUG();
  160. return 0;
  161. }
  162. static inline void
  163. dma_unmap_single(struct device *dev, dma_addr_t dma_addr, size_t size,
  164. enum dma_data_direction direction)
  165. {
  166. BUG();
  167. }
  168. static inline dma_addr_t
  169. dma_map_page(struct device *dev, struct page *page,
  170. unsigned long offset, size_t size,
  171. enum dma_data_direction direction)
  172. {
  173. BUG();
  174. return 0;
  175. }
  176. static inline void
  177. dma_unmap_page(struct device *dev, dma_addr_t dma_address, size_t size,
  178. enum dma_data_direction direction)
  179. {
  180. BUG();
  181. }
  182. static inline int
  183. dma_map_sg(struct device *dev, struct scatterlist *sg, int nents,
  184. enum dma_data_direction direction)
  185. {
  186. BUG();
  187. return 0;
  188. }
  189. static inline void
  190. dma_unmap_sg(struct device *dev, struct scatterlist *sg, int nhwentries,
  191. enum dma_data_direction direction)
  192. {
  193. BUG();
  194. }
  195. static inline void
  196. dma_sync_single_for_cpu(struct device *dev, dma_addr_t dma_handle, size_t size,
  197. enum dma_data_direction direction)
  198. {
  199. BUG();
  200. }
  201. static inline void
  202. dma_sync_single_for_device(struct device *dev, dma_addr_t dma_handle, size_t size,
  203. enum dma_data_direction direction)
  204. {
  205. BUG();
  206. }
  207. static inline void
  208. dma_sync_sg_for_cpu(struct device *dev, struct scatterlist *sg, int nelems,
  209. enum dma_data_direction direction)
  210. {
  211. BUG();
  212. }
  213. static inline void
  214. dma_sync_sg_for_device(struct device *dev, struct scatterlist *sg, int nelems,
  215. enum dma_data_direction direction)
  216. {
  217. BUG();
  218. }
  219. static inline int
  220. dma_mapping_error(dma_addr_t dma_addr)
  221. {
  222. BUG();
  223. return 0;
  224. }
  225. #endif /* PCI */
  226. /* Now for the API extensions over the pci_ one */
  227. #define dma_alloc_noncoherent(d, s, h, f) dma_alloc_coherent(d, s, h, f)
  228. #define dma_free_noncoherent(d, s, v, h) dma_free_coherent(d, s, v, h)
  229. #define dma_is_consistent(d, h) (1)
  230. static inline int
  231. dma_get_cache_alignment(void)
  232. {
  233. /* no easy way to get cache size on all processors, so return
  234. * the maximum possible, to be safe */
  235. return (1 << INTERNODE_CACHE_SHIFT);
  236. }
  237. static inline void
  238. dma_sync_single_range_for_cpu(struct device *dev, dma_addr_t dma_handle,
  239. unsigned long offset, size_t size,
  240. enum dma_data_direction direction)
  241. {
  242. /* just sync everything, that's all the pci API can do */
  243. dma_sync_single_for_cpu(dev, dma_handle, offset+size, direction);
  244. }
  245. static inline void
  246. dma_sync_single_range_for_device(struct device *dev, dma_addr_t dma_handle,
  247. unsigned long offset, size_t size,
  248. enum dma_data_direction direction)
  249. {
  250. /* just sync everything, that's all the pci API can do */
  251. dma_sync_single_for_device(dev, dma_handle, offset+size, direction);
  252. }
  253. static inline void
  254. dma_cache_sync(struct device *dev, void *vaddr, size_t size,
  255. enum dma_data_direction direction)
  256. {
  257. /* could define this in terms of the dma_cache ... operations,
  258. * but if you get this on a platform, you should convert the platform
  259. * to using the generic device DMA API */
  260. BUG();
  261. }
  262. #endif /* _ASM_SPARC64_DMA_MAPPING_H */