dma-mapping_64.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. #ifndef _ASM_SPARC64_DMA_MAPPING_H
  2. #define _ASM_SPARC64_DMA_MAPPING_H
  3. #include <linux/scatterlist.h>
  4. #include <linux/mm.h>
  5. #define DMA_ERROR_CODE (~(dma_addr_t)0x0)
  6. struct dma_ops {
  7. void *(*alloc_coherent)(struct device *dev, size_t size,
  8. dma_addr_t *dma_handle, gfp_t flag);
  9. void (*free_coherent)(struct device *dev, size_t size,
  10. void *cpu_addr, dma_addr_t dma_handle);
  11. dma_addr_t (*map_single)(struct device *dev, void *cpu_addr,
  12. size_t size,
  13. enum dma_data_direction direction);
  14. void (*unmap_single)(struct device *dev, dma_addr_t dma_addr,
  15. size_t size,
  16. enum dma_data_direction direction);
  17. int (*map_sg)(struct device *dev, struct scatterlist *sg, int nents,
  18. enum dma_data_direction direction);
  19. void (*unmap_sg)(struct device *dev, struct scatterlist *sg,
  20. int nhwentries,
  21. enum dma_data_direction direction);
  22. void (*sync_single_for_cpu)(struct device *dev,
  23. dma_addr_t dma_handle, size_t size,
  24. enum dma_data_direction direction);
  25. void (*sync_sg_for_cpu)(struct device *dev, struct scatterlist *sg,
  26. int nelems,
  27. enum dma_data_direction direction);
  28. };
  29. extern const struct dma_ops *dma_ops;
  30. extern int dma_supported(struct device *dev, u64 mask);
  31. extern int dma_set_mask(struct device *dev, u64 dma_mask);
  32. static inline void *dma_alloc_coherent(struct device *dev, size_t size,
  33. dma_addr_t *dma_handle, gfp_t flag)
  34. {
  35. return dma_ops->alloc_coherent(dev, size, dma_handle, flag);
  36. }
  37. static inline void dma_free_coherent(struct device *dev, size_t size,
  38. void *cpu_addr, dma_addr_t dma_handle)
  39. {
  40. dma_ops->free_coherent(dev, size, cpu_addr, dma_handle);
  41. }
  42. static inline dma_addr_t dma_map_single(struct device *dev, void *cpu_addr,
  43. size_t size,
  44. enum dma_data_direction direction)
  45. {
  46. return dma_ops->map_single(dev, cpu_addr, size, direction);
  47. }
  48. static inline void dma_unmap_single(struct device *dev, dma_addr_t dma_addr,
  49. size_t size,
  50. enum dma_data_direction direction)
  51. {
  52. dma_ops->unmap_single(dev, dma_addr, size, direction);
  53. }
  54. static inline dma_addr_t dma_map_page(struct device *dev, struct page *page,
  55. unsigned long offset, size_t size,
  56. enum dma_data_direction direction)
  57. {
  58. return dma_ops->map_single(dev, page_address(page) + offset,
  59. size, direction);
  60. }
  61. static inline void dma_unmap_page(struct device *dev, dma_addr_t dma_address,
  62. size_t size,
  63. enum dma_data_direction direction)
  64. {
  65. dma_ops->unmap_single(dev, dma_address, size, direction);
  66. }
  67. static inline int dma_map_sg(struct device *dev, struct scatterlist *sg,
  68. int nents, enum dma_data_direction direction)
  69. {
  70. return dma_ops->map_sg(dev, sg, nents, direction);
  71. }
  72. static inline void dma_unmap_sg(struct device *dev, struct scatterlist *sg,
  73. int nents, enum dma_data_direction direction)
  74. {
  75. dma_ops->unmap_sg(dev, sg, nents, direction);
  76. }
  77. static inline void dma_sync_single_for_cpu(struct device *dev,
  78. dma_addr_t dma_handle, size_t size,
  79. enum dma_data_direction direction)
  80. {
  81. dma_ops->sync_single_for_cpu(dev, dma_handle, size, direction);
  82. }
  83. static inline void dma_sync_single_for_device(struct device *dev,
  84. dma_addr_t dma_handle,
  85. size_t size,
  86. enum dma_data_direction direction)
  87. {
  88. /* No flushing needed to sync cpu writes to the device. */
  89. }
  90. static inline void dma_sync_single_range_for_cpu(struct device *dev,
  91. dma_addr_t dma_handle,
  92. unsigned long offset,
  93. size_t size,
  94. enum dma_data_direction direction)
  95. {
  96. dma_sync_single_for_cpu(dev, dma_handle+offset, size, direction);
  97. }
  98. static inline void dma_sync_single_range_for_device(struct device *dev,
  99. dma_addr_t dma_handle,
  100. unsigned long offset,
  101. size_t size,
  102. enum dma_data_direction direction)
  103. {
  104. /* No flushing needed to sync cpu writes to the device. */
  105. }
  106. static inline void dma_sync_sg_for_cpu(struct device *dev,
  107. struct scatterlist *sg, int nelems,
  108. enum dma_data_direction direction)
  109. {
  110. dma_ops->sync_sg_for_cpu(dev, sg, nelems, direction);
  111. }
  112. static inline void dma_sync_sg_for_device(struct device *dev,
  113. struct scatterlist *sg, int nelems,
  114. enum dma_data_direction direction)
  115. {
  116. /* No flushing needed to sync cpu writes to the device. */
  117. }
  118. static inline int dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
  119. {
  120. return (dma_addr == DMA_ERROR_CODE);
  121. }
  122. static inline int dma_get_cache_alignment(void)
  123. {
  124. /* no easy way to get cache size on all processors, so return
  125. * the maximum possible, to be safe */
  126. return (1 << INTERNODE_CACHE_SHIFT);
  127. }
  128. #define dma_alloc_noncoherent(d, s, h, f) dma_alloc_coherent(d, s, h, f)
  129. #define dma_free_noncoherent(d, s, v, h) dma_free_coherent(d, s, v, h)
  130. #define dma_is_consistent(d, h) (1)
  131. #endif /* _ASM_SPARC64_DMA_MAPPING_H */