dma-mapping.h 8.0 KB

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