dma-mapping.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  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. 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 void
  142. dma_sync_single_for_cpu(struct device *dev, dma_addr_t dma_handle, size_t size,
  143. enum dma_data_direction direction)
  144. {
  145. BUG();
  146. }
  147. static inline void
  148. dma_sync_single_for_device(struct device *dev, dma_addr_t dma_handle, size_t size,
  149. enum dma_data_direction direction)
  150. {
  151. BUG();
  152. }
  153. #endif /* PCI */
  154. /* Now for the API extensions over the pci_ one */
  155. #define dma_alloc_noncoherent(d, s, h, f) dma_alloc_coherent(d, s, h, f)
  156. #define dma_free_noncoherent(d, s, v, h) dma_free_coherent(d, s, v, h)
  157. #define dma_is_consistent(d, h) (1)
  158. static inline int
  159. dma_get_cache_alignment(void)
  160. {
  161. /* no easy way to get cache size on all processors, so return
  162. * the maximum possible, to be safe */
  163. return (1 << INTERNODE_CACHE_SHIFT);
  164. }
  165. static inline void
  166. dma_sync_single_range_for_cpu(struct device *dev, dma_addr_t dma_handle,
  167. unsigned long offset, size_t size,
  168. enum dma_data_direction direction)
  169. {
  170. /* just sync everything, that's all the pci API can do */
  171. dma_sync_single_for_cpu(dev, dma_handle, offset+size, direction);
  172. }
  173. static inline void
  174. dma_sync_single_range_for_device(struct device *dev, dma_addr_t dma_handle,
  175. unsigned long offset, size_t size,
  176. enum dma_data_direction direction)
  177. {
  178. /* just sync everything, that's all the pci API can do */
  179. dma_sync_single_for_device(dev, dma_handle, offset+size, direction);
  180. }
  181. static inline void
  182. dma_cache_sync(struct device *dev, void *vaddr, size_t size,
  183. enum dma_data_direction direction)
  184. {
  185. /* could define this in terms of the dma_cache ... operations,
  186. * but if you get this on a platform, you should convert the platform
  187. * to using the generic device DMA API */
  188. BUG();
  189. }
  190. #endif /* _ASM_SPARC64_DMA_MAPPING_H */