dma-mapping.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. #ifndef _X8664_DMA_MAPPING_H
  2. #define _X8664_DMA_MAPPING_H 1
  3. /*
  4. * IOMMU interface. See Documentation/DMA-mapping.txt and DMA-API.txt for
  5. * documentation.
  6. */
  7. #include <asm/scatterlist.h>
  8. #include <asm/io.h>
  9. #include <asm/swiotlb.h>
  10. struct dma_mapping_ops {
  11. int (*mapping_error)(dma_addr_t dma_addr);
  12. void* (*alloc_coherent)(struct device *dev, size_t size,
  13. dma_addr_t *dma_handle, gfp_t gfp);
  14. void (*free_coherent)(struct device *dev, size_t size,
  15. void *vaddr, dma_addr_t dma_handle);
  16. dma_addr_t (*map_single)(struct device *hwdev, void *ptr,
  17. size_t size, int direction);
  18. /* like map_single, but doesn't check the device mask */
  19. dma_addr_t (*map_simple)(struct device *hwdev, char *ptr,
  20. size_t size, int direction);
  21. void (*unmap_single)(struct device *dev, dma_addr_t addr,
  22. size_t size, int direction);
  23. void (*sync_single_for_cpu)(struct device *hwdev,
  24. dma_addr_t dma_handle, size_t size,
  25. int direction);
  26. void (*sync_single_for_device)(struct device *hwdev,
  27. dma_addr_t dma_handle, size_t size,
  28. int direction);
  29. void (*sync_single_range_for_cpu)(struct device *hwdev,
  30. dma_addr_t dma_handle, unsigned long offset,
  31. size_t size, int direction);
  32. void (*sync_single_range_for_device)(struct device *hwdev,
  33. dma_addr_t dma_handle, unsigned long offset,
  34. size_t size, int direction);
  35. void (*sync_sg_for_cpu)(struct device *hwdev,
  36. struct scatterlist *sg, int nelems,
  37. int direction);
  38. void (*sync_sg_for_device)(struct device *hwdev,
  39. struct scatterlist *sg, int nelems,
  40. int direction);
  41. int (*map_sg)(struct device *hwdev, struct scatterlist *sg,
  42. int nents, int direction);
  43. void (*unmap_sg)(struct device *hwdev,
  44. struct scatterlist *sg, int nents,
  45. int direction);
  46. int (*dma_supported)(struct device *hwdev, u64 mask);
  47. int is_phys;
  48. };
  49. extern dma_addr_t bad_dma_address;
  50. extern struct dma_mapping_ops* dma_ops;
  51. extern int iommu_merge;
  52. static inline int dma_mapping_error(dma_addr_t dma_addr)
  53. {
  54. if (dma_ops->mapping_error)
  55. return dma_ops->mapping_error(dma_addr);
  56. return (dma_addr == bad_dma_address);
  57. }
  58. #define dma_alloc_noncoherent(d, s, h, f) dma_alloc_coherent(d, s, h, f)
  59. #define dma_free_noncoherent(d, s, v, h) dma_free_coherent(d, s, v, h)
  60. extern void *dma_alloc_coherent(struct device *dev, size_t size,
  61. dma_addr_t *dma_handle, gfp_t gfp);
  62. extern void dma_free_coherent(struct device *dev, size_t size, void *vaddr,
  63. dma_addr_t dma_handle);
  64. static inline dma_addr_t
  65. dma_map_single(struct device *hwdev, void *ptr, size_t size,
  66. int direction)
  67. {
  68. BUG_ON(!valid_dma_direction(direction));
  69. return dma_ops->map_single(hwdev, ptr, size, direction);
  70. }
  71. static inline void
  72. dma_unmap_single(struct device *dev, dma_addr_t addr,size_t size,
  73. int direction)
  74. {
  75. BUG_ON(!valid_dma_direction(direction));
  76. dma_ops->unmap_single(dev, addr, size, direction);
  77. }
  78. #define dma_map_page(dev,page,offset,size,dir) \
  79. dma_map_single((dev), page_address(page)+(offset), (size), (dir))
  80. #define dma_unmap_page dma_unmap_single
  81. static inline void
  82. dma_sync_single_for_cpu(struct device *hwdev, dma_addr_t dma_handle,
  83. size_t size, int direction)
  84. {
  85. BUG_ON(!valid_dma_direction(direction));
  86. if (dma_ops->sync_single_for_cpu)
  87. dma_ops->sync_single_for_cpu(hwdev, dma_handle, size,
  88. direction);
  89. flush_write_buffers();
  90. }
  91. static inline void
  92. dma_sync_single_for_device(struct device *hwdev, dma_addr_t dma_handle,
  93. size_t size, int direction)
  94. {
  95. BUG_ON(!valid_dma_direction(direction));
  96. if (dma_ops->sync_single_for_device)
  97. dma_ops->sync_single_for_device(hwdev, dma_handle, size,
  98. direction);
  99. flush_write_buffers();
  100. }
  101. static inline void
  102. dma_sync_single_range_for_cpu(struct device *hwdev, dma_addr_t dma_handle,
  103. unsigned long offset, size_t size, int direction)
  104. {
  105. BUG_ON(!valid_dma_direction(direction));
  106. if (dma_ops->sync_single_range_for_cpu) {
  107. dma_ops->sync_single_range_for_cpu(hwdev, dma_handle, offset, size, direction);
  108. }
  109. flush_write_buffers();
  110. }
  111. static inline void
  112. dma_sync_single_range_for_device(struct device *hwdev, dma_addr_t dma_handle,
  113. unsigned long offset, size_t size, int direction)
  114. {
  115. BUG_ON(!valid_dma_direction(direction));
  116. if (dma_ops->sync_single_range_for_device)
  117. dma_ops->sync_single_range_for_device(hwdev, dma_handle,
  118. offset, size, direction);
  119. flush_write_buffers();
  120. }
  121. static inline void
  122. dma_sync_sg_for_cpu(struct device *hwdev, struct scatterlist *sg,
  123. int nelems, int direction)
  124. {
  125. BUG_ON(!valid_dma_direction(direction));
  126. if (dma_ops->sync_sg_for_cpu)
  127. dma_ops->sync_sg_for_cpu(hwdev, sg, nelems, direction);
  128. flush_write_buffers();
  129. }
  130. static inline void
  131. dma_sync_sg_for_device(struct device *hwdev, struct scatterlist *sg,
  132. int nelems, int direction)
  133. {
  134. BUG_ON(!valid_dma_direction(direction));
  135. if (dma_ops->sync_sg_for_device) {
  136. dma_ops->sync_sg_for_device(hwdev, sg, nelems, direction);
  137. }
  138. flush_write_buffers();
  139. }
  140. static inline int
  141. dma_map_sg(struct device *hwdev, struct scatterlist *sg, int nents, int direction)
  142. {
  143. BUG_ON(!valid_dma_direction(direction));
  144. return dma_ops->map_sg(hwdev, sg, nents, direction);
  145. }
  146. static inline void
  147. dma_unmap_sg(struct device *hwdev, struct scatterlist *sg, int nents,
  148. int direction)
  149. {
  150. BUG_ON(!valid_dma_direction(direction));
  151. dma_ops->unmap_sg(hwdev, sg, nents, direction);
  152. }
  153. extern int dma_supported(struct device *hwdev, u64 mask);
  154. /* same for gart, swiotlb, and nommu */
  155. static inline int dma_get_cache_alignment(void)
  156. {
  157. return boot_cpu_data.x86_clflush_size;
  158. }
  159. #define dma_is_consistent(d, h) 1
  160. extern int dma_set_mask(struct device *dev, u64 mask);
  161. static inline void
  162. dma_cache_sync(struct device *dev, void *vaddr, size_t size,
  163. enum dma_data_direction dir)
  164. {
  165. flush_write_buffers();
  166. }
  167. extern struct device fallback_dev;
  168. extern int panic_on_overflow;
  169. #endif /* _X8664_DMA_MAPPING_H */