dma-mapping.h 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. #ifndef _PARISC_DMA_MAPPING_H
  2. #define _PARISC_DMA_MAPPING_H
  3. #include <linux/mm.h>
  4. #include <linux/scatterlist.h>
  5. #include <asm/cacheflush.h>
  6. /* See Documentation/DMA-API-HOWTO.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. #define dma_alloc_attrs(d, s, h, f, a) dma_alloc_coherent(d, s, h, f)
  44. #define dma_free_attrs(d, s, h, f, a) dma_free_coherent(d, s, h, f)
  45. static inline void *
  46. dma_alloc_coherent(struct device *dev, size_t size, dma_addr_t *dma_handle,
  47. gfp_t flag)
  48. {
  49. return hppa_dma_ops->alloc_consistent(dev, size, dma_handle, flag);
  50. }
  51. static inline void *
  52. dma_alloc_noncoherent(struct device *dev, size_t size, dma_addr_t *dma_handle,
  53. gfp_t flag)
  54. {
  55. return hppa_dma_ops->alloc_noncoherent(dev, size, dma_handle, flag);
  56. }
  57. static inline void
  58. dma_free_coherent(struct device *dev, size_t size,
  59. void *vaddr, dma_addr_t dma_handle)
  60. {
  61. hppa_dma_ops->free_consistent(dev, size, vaddr, dma_handle);
  62. }
  63. static inline void
  64. dma_free_noncoherent(struct device *dev, size_t size,
  65. void *vaddr, dma_addr_t dma_handle)
  66. {
  67. hppa_dma_ops->free_consistent(dev, size, vaddr, dma_handle);
  68. }
  69. static inline dma_addr_t
  70. dma_map_single(struct device *dev, void *ptr, size_t size,
  71. enum dma_data_direction direction)
  72. {
  73. return hppa_dma_ops->map_single(dev, ptr, size, direction);
  74. }
  75. static inline void
  76. dma_unmap_single(struct device *dev, dma_addr_t dma_addr, size_t size,
  77. enum dma_data_direction direction)
  78. {
  79. hppa_dma_ops->unmap_single(dev, dma_addr, size, direction);
  80. }
  81. static inline int
  82. dma_map_sg(struct device *dev, struct scatterlist *sg, int nents,
  83. enum dma_data_direction direction)
  84. {
  85. return hppa_dma_ops->map_sg(dev, sg, nents, direction);
  86. }
  87. static inline void
  88. dma_unmap_sg(struct device *dev, struct scatterlist *sg, int nhwentries,
  89. enum dma_data_direction direction)
  90. {
  91. hppa_dma_ops->unmap_sg(dev, sg, nhwentries, direction);
  92. }
  93. static inline dma_addr_t
  94. dma_map_page(struct device *dev, struct page *page, unsigned long offset,
  95. size_t size, enum dma_data_direction direction)
  96. {
  97. return dma_map_single(dev, (page_address(page) + (offset)), size, direction);
  98. }
  99. static inline void
  100. dma_unmap_page(struct device *dev, dma_addr_t dma_address, size_t size,
  101. enum dma_data_direction direction)
  102. {
  103. dma_unmap_single(dev, dma_address, size, direction);
  104. }
  105. static inline void
  106. dma_sync_single_for_cpu(struct device *dev, dma_addr_t dma_handle, size_t size,
  107. enum dma_data_direction direction)
  108. {
  109. if(hppa_dma_ops->dma_sync_single_for_cpu)
  110. hppa_dma_ops->dma_sync_single_for_cpu(dev, dma_handle, 0, size, direction);
  111. }
  112. static inline void
  113. dma_sync_single_for_device(struct device *dev, dma_addr_t dma_handle, size_t size,
  114. enum dma_data_direction direction)
  115. {
  116. if(hppa_dma_ops->dma_sync_single_for_device)
  117. hppa_dma_ops->dma_sync_single_for_device(dev, dma_handle, 0, size, direction);
  118. }
  119. static inline void
  120. dma_sync_single_range_for_cpu(struct device *dev, dma_addr_t dma_handle,
  121. unsigned long offset, size_t size,
  122. enum dma_data_direction direction)
  123. {
  124. if(hppa_dma_ops->dma_sync_single_for_cpu)
  125. hppa_dma_ops->dma_sync_single_for_cpu(dev, dma_handle, offset, size, direction);
  126. }
  127. static inline void
  128. dma_sync_single_range_for_device(struct device *dev, dma_addr_t dma_handle,
  129. unsigned long offset, size_t size,
  130. enum dma_data_direction direction)
  131. {
  132. if(hppa_dma_ops->dma_sync_single_for_device)
  133. hppa_dma_ops->dma_sync_single_for_device(dev, dma_handle, offset, size, direction);
  134. }
  135. static inline void
  136. dma_sync_sg_for_cpu(struct device *dev, struct scatterlist *sg, int nelems,
  137. enum dma_data_direction direction)
  138. {
  139. if(hppa_dma_ops->dma_sync_sg_for_cpu)
  140. hppa_dma_ops->dma_sync_sg_for_cpu(dev, sg, nelems, direction);
  141. }
  142. static inline void
  143. dma_sync_sg_for_device(struct device *dev, struct scatterlist *sg, int nelems,
  144. enum dma_data_direction direction)
  145. {
  146. if(hppa_dma_ops->dma_sync_sg_for_device)
  147. hppa_dma_ops->dma_sync_sg_for_device(dev, sg, nelems, direction);
  148. }
  149. static inline int
  150. dma_supported(struct device *dev, u64 mask)
  151. {
  152. return hppa_dma_ops->dma_supported(dev, mask);
  153. }
  154. static inline int
  155. dma_set_mask(struct device *dev, u64 mask)
  156. {
  157. if(!dev->dma_mask || !dma_supported(dev, mask))
  158. return -EIO;
  159. *dev->dma_mask = mask;
  160. return 0;
  161. }
  162. static inline void
  163. dma_cache_sync(struct device *dev, void *vaddr, size_t size,
  164. enum dma_data_direction direction)
  165. {
  166. if(hppa_dma_ops->dma_sync_single_for_cpu)
  167. flush_kernel_dcache_range((unsigned long)vaddr, size);
  168. }
  169. static inline void *
  170. parisc_walk_tree(struct device *dev)
  171. {
  172. struct device *otherdev;
  173. if(likely(dev->platform_data != NULL))
  174. return dev->platform_data;
  175. /* OK, just traverse the bus to find it */
  176. for(otherdev = dev->parent; otherdev;
  177. otherdev = otherdev->parent) {
  178. if(otherdev->platform_data) {
  179. dev->platform_data = otherdev->platform_data;
  180. break;
  181. }
  182. }
  183. BUG_ON(!dev->platform_data);
  184. return dev->platform_data;
  185. }
  186. #define GET_IOC(dev) (HBA_DATA(parisc_walk_tree(dev))->iommu)
  187. #ifdef CONFIG_IOMMU_CCIO
  188. struct parisc_device;
  189. struct ioc;
  190. void * ccio_get_iommu(const struct parisc_device *dev);
  191. int ccio_request_resource(const struct parisc_device *dev,
  192. struct resource *res);
  193. int ccio_allocate_resource(const struct parisc_device *dev,
  194. struct resource *res, unsigned long size,
  195. unsigned long min, unsigned long max, unsigned long align);
  196. #else /* !CONFIG_IOMMU_CCIO */
  197. #define ccio_get_iommu(dev) NULL
  198. #define ccio_request_resource(dev, res) insert_resource(&iomem_resource, res)
  199. #define ccio_allocate_resource(dev, res, size, min, max, align) \
  200. allocate_resource(&iomem_resource, res, size, min, max, \
  201. align, NULL, NULL)
  202. #endif /* !CONFIG_IOMMU_CCIO */
  203. #ifdef CONFIG_IOMMU_SBA
  204. struct parisc_device;
  205. void * sba_get_iommu(struct parisc_device *dev);
  206. #endif
  207. /* At the moment, we panic on error for IOMMU resource exaustion */
  208. #define dma_mapping_error(dev, x) 0
  209. /* This API cannot be supported on PA-RISC */
  210. static inline int dma_mmap_coherent(struct device *dev,
  211. struct vm_area_struct *vma, void *cpu_addr,
  212. dma_addr_t dma_addr, size_t size)
  213. {
  214. return -EINVAL;
  215. }
  216. static inline int dma_get_sgtable(struct device *dev, struct sg_table *sgt,
  217. void *cpu_addr, dma_addr_t dma_addr,
  218. size_t size)
  219. {
  220. return -EINVAL;
  221. }
  222. #endif