dma-mapping.h 7.1 KB

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