dma-mapping.h 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. #ifndef _PARISC_DMA_MAPPING_H
  2. #define _PARISC_DMA_MAPPING_H
  3. #include <linux/config.h>
  4. #include <linux/mm.h>
  5. #include <asm/cacheflush.h>
  6. #include <asm/scatterlist.h>
  7. /* See Documentation/DMA-mapping.txt */
  8. struct hppa_dma_ops {
  9. int (*dma_supported)(struct device *dev, u64 mask);
  10. void *(*alloc_consistent)(struct device *dev, size_t size, dma_addr_t *iova, gfp_t flag);
  11. void *(*alloc_noncoherent)(struct device *dev, size_t size, dma_addr_t *iova, gfp_t flag);
  12. void (*free_consistent)(struct device *dev, size_t size, void *vaddr, dma_addr_t iova);
  13. dma_addr_t (*map_single)(struct device *dev, void *addr, size_t size, enum dma_data_direction direction);
  14. void (*unmap_single)(struct device *dev, dma_addr_t iova, size_t size, enum dma_data_direction direction);
  15. int (*map_sg)(struct device *dev, struct scatterlist *sg, int nents, enum dma_data_direction direction);
  16. void (*unmap_sg)(struct device *dev, struct scatterlist *sg, int nhwents, enum dma_data_direction direction);
  17. void (*dma_sync_single_for_cpu)(struct device *dev, dma_addr_t iova, unsigned long offset, size_t size, enum dma_data_direction direction);
  18. void (*dma_sync_single_for_device)(struct device *dev, dma_addr_t iova, unsigned long offset, size_t size, enum dma_data_direction direction);
  19. void (*dma_sync_sg_for_cpu)(struct device *dev, struct scatterlist *sg, int nelems, enum dma_data_direction direction);
  20. void (*dma_sync_sg_for_device)(struct device *dev, struct scatterlist *sg, int nelems, enum dma_data_direction direction);
  21. };
  22. /*
  23. ** We could live without the hppa_dma_ops indirection if we didn't want
  24. ** to support 4 different coherent dma models with one binary (they will
  25. ** someday be loadable modules):
  26. ** I/O MMU consistent method dma_sync behavior
  27. ** ============= ====================== =======================
  28. ** a) PA-7x00LC uncachable host memory flush/purge
  29. ** b) U2/Uturn cachable host memory NOP
  30. ** c) Ike/Astro cachable host memory NOP
  31. ** d) EPIC/SAGA memory on EPIC/SAGA flush/reset DMA channel
  32. **
  33. ** PA-7[13]00LC processors have a GSC bus interface and no I/O MMU.
  34. **
  35. ** Systems (eg PCX-T workstations) that don't fall into the above
  36. ** categories will need to modify the needed drivers to perform
  37. ** flush/purge and allocate "regular" cacheable pages for everything.
  38. */
  39. #ifdef CONFIG_PA11
  40. extern struct hppa_dma_ops pcxl_dma_ops;
  41. extern struct hppa_dma_ops pcx_dma_ops;
  42. #endif
  43. extern struct hppa_dma_ops *hppa_dma_ops;
  44. static inline void *
  45. dma_alloc_coherent(struct device *dev, size_t size, dma_addr_t *dma_handle,
  46. gfp_t flag)
  47. {
  48. return hppa_dma_ops->alloc_consistent(dev, size, dma_handle, flag);
  49. }
  50. static inline void *
  51. dma_alloc_noncoherent(struct device *dev, size_t size, dma_addr_t *dma_handle,
  52. gfp_t flag)
  53. {
  54. return hppa_dma_ops->alloc_noncoherent(dev, size, dma_handle, flag);
  55. }
  56. static inline void
  57. dma_free_coherent(struct device *dev, size_t size,
  58. void *vaddr, dma_addr_t dma_handle)
  59. {
  60. hppa_dma_ops->free_consistent(dev, size, vaddr, dma_handle);
  61. }
  62. static inline void
  63. dma_free_noncoherent(struct device *dev, size_t size,
  64. void *vaddr, dma_addr_t dma_handle)
  65. {
  66. hppa_dma_ops->free_consistent(dev, size, vaddr, dma_handle);
  67. }
  68. static inline dma_addr_t
  69. dma_map_single(struct device *dev, void *ptr, size_t size,
  70. enum dma_data_direction direction)
  71. {
  72. return hppa_dma_ops->map_single(dev, ptr, size, direction);
  73. }
  74. static inline void
  75. dma_unmap_single(struct device *dev, dma_addr_t dma_addr, size_t size,
  76. enum dma_data_direction direction)
  77. {
  78. hppa_dma_ops->unmap_single(dev, dma_addr, size, direction);
  79. }
  80. static inline int
  81. dma_map_sg(struct device *dev, struct scatterlist *sg, int nents,
  82. enum dma_data_direction direction)
  83. {
  84. return hppa_dma_ops->map_sg(dev, sg, nents, direction);
  85. }
  86. static inline void
  87. dma_unmap_sg(struct device *dev, struct scatterlist *sg, int nhwentries,
  88. enum dma_data_direction direction)
  89. {
  90. hppa_dma_ops->unmap_sg(dev, sg, nhwentries, direction);
  91. }
  92. static inline dma_addr_t
  93. dma_map_page(struct device *dev, struct page *page, unsigned long offset,
  94. size_t size, enum dma_data_direction direction)
  95. {
  96. return dma_map_single(dev, (page_address(page) + (offset)), size, direction);
  97. }
  98. static inline void
  99. dma_unmap_page(struct device *dev, dma_addr_t dma_address, size_t size,
  100. enum dma_data_direction direction)
  101. {
  102. dma_unmap_single(dev, dma_address, size, direction);
  103. }
  104. static inline void
  105. dma_sync_single_for_cpu(struct device *dev, dma_addr_t dma_handle, size_t size,
  106. enum dma_data_direction direction)
  107. {
  108. if(hppa_dma_ops->dma_sync_single_for_cpu)
  109. hppa_dma_ops->dma_sync_single_for_cpu(dev, dma_handle, 0, size, direction);
  110. }
  111. static inline void
  112. dma_sync_single_for_device(struct device *dev, dma_addr_t dma_handle, size_t size,
  113. enum dma_data_direction direction)
  114. {
  115. if(hppa_dma_ops->dma_sync_single_for_device)
  116. hppa_dma_ops->dma_sync_single_for_device(dev, dma_handle, 0, size, direction);
  117. }
  118. static inline void
  119. dma_sync_single_range_for_cpu(struct device *dev, dma_addr_t dma_handle,
  120. unsigned long offset, size_t size,
  121. enum dma_data_direction direction)
  122. {
  123. if(hppa_dma_ops->dma_sync_single_for_cpu)
  124. hppa_dma_ops->dma_sync_single_for_cpu(dev, dma_handle, offset, size, direction);
  125. }
  126. static inline void
  127. dma_sync_single_range_for_device(struct device *dev, dma_addr_t dma_handle,
  128. unsigned long offset, size_t size,
  129. enum dma_data_direction direction)
  130. {
  131. if(hppa_dma_ops->dma_sync_single_for_device)
  132. hppa_dma_ops->dma_sync_single_for_device(dev, dma_handle, offset, size, direction);
  133. }
  134. static inline void
  135. dma_sync_sg_for_cpu(struct device *dev, struct scatterlist *sg, int nelems,
  136. enum dma_data_direction direction)
  137. {
  138. if(hppa_dma_ops->dma_sync_sg_for_cpu)
  139. hppa_dma_ops->dma_sync_sg_for_cpu(dev, sg, nelems, direction);
  140. }
  141. static inline void
  142. dma_sync_sg_for_device(struct device *dev, struct scatterlist *sg, int nelems,
  143. enum dma_data_direction direction)
  144. {
  145. if(hppa_dma_ops->dma_sync_sg_for_device)
  146. hppa_dma_ops->dma_sync_sg_for_device(dev, sg, nelems, direction);
  147. }
  148. static inline int
  149. dma_supported(struct device *dev, u64 mask)
  150. {
  151. return hppa_dma_ops->dma_supported(dev, mask);
  152. }
  153. static inline int
  154. dma_set_mask(struct device *dev, u64 mask)
  155. {
  156. if(!dev->dma_mask || !dma_supported(dev, mask))
  157. return -EIO;
  158. *dev->dma_mask = mask;
  159. return 0;
  160. }
  161. static inline int
  162. dma_get_cache_alignment(void)
  163. {
  164. return dcache_stride;
  165. }
  166. static inline int
  167. dma_is_consistent(dma_addr_t dma_addr)
  168. {
  169. return (hppa_dma_ops->dma_sync_single_for_cpu == NULL);
  170. }
  171. static inline void
  172. dma_cache_sync(void *vaddr, size_t size,
  173. enum dma_data_direction direction)
  174. {
  175. if(hppa_dma_ops->dma_sync_single_for_cpu)
  176. flush_kernel_dcache_range((unsigned long)vaddr, size);
  177. }
  178. static inline void *
  179. parisc_walk_tree(struct device *dev)
  180. {
  181. struct device *otherdev;
  182. if(likely(dev->platform_data != NULL))
  183. return dev->platform_data;
  184. /* OK, just traverse the bus to find it */
  185. for(otherdev = dev->parent; otherdev;
  186. otherdev = otherdev->parent) {
  187. if(otherdev->platform_data) {
  188. dev->platform_data = otherdev->platform_data;
  189. break;
  190. }
  191. }
  192. BUG_ON(!dev->platform_data);
  193. return dev->platform_data;
  194. }
  195. #define GET_IOC(dev) (HBA_DATA(parisc_walk_tree(dev))->iommu);
  196. #ifdef CONFIG_IOMMU_CCIO
  197. struct parisc_device;
  198. struct ioc;
  199. void * ccio_get_iommu(const struct parisc_device *dev);
  200. int ccio_request_resource(const struct parisc_device *dev,
  201. struct resource *res);
  202. int ccio_allocate_resource(const struct parisc_device *dev,
  203. struct resource *res, unsigned long size,
  204. unsigned long min, unsigned long max, unsigned long align);
  205. #else /* !CONFIG_IOMMU_CCIO */
  206. #define ccio_get_iommu(dev) NULL
  207. #define ccio_request_resource(dev, res) request_resource(&iomem_resource, res)
  208. #define ccio_allocate_resource(dev, res, size, min, max, align) \
  209. allocate_resource(&iomem_resource, res, size, min, max, \
  210. align, NULL, NULL)
  211. #endif /* !CONFIG_IOMMU_CCIO */
  212. #ifdef CONFIG_IOMMU_SBA
  213. struct parisc_device;
  214. void * sba_get_iommu(struct parisc_device *dev);
  215. #endif
  216. /* At the moment, we panic on error for IOMMU resource exaustion */
  217. #define dma_mapping_error(x) 0
  218. #endif