dma-mapping.h 7.1 KB

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