dma-mapping.h 7.1 KB

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