dma-mapping_64.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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. struct dma_ops {
  6. void *(*alloc_coherent)(struct device *dev, size_t size,
  7. dma_addr_t *dma_handle, gfp_t flag);
  8. void (*free_coherent)(struct device *dev, size_t size,
  9. void *cpu_addr, dma_addr_t dma_handle);
  10. dma_addr_t (*map_single)(struct device *dev, void *cpu_addr,
  11. size_t size,
  12. enum dma_data_direction direction);
  13. void (*unmap_single)(struct device *dev, dma_addr_t dma_addr,
  14. size_t size,
  15. enum dma_data_direction direction);
  16. int (*map_sg)(struct device *dev, struct scatterlist *sg, int nents,
  17. enum dma_data_direction direction);
  18. void (*unmap_sg)(struct device *dev, struct scatterlist *sg,
  19. int nhwentries,
  20. enum dma_data_direction direction);
  21. void (*sync_single_for_cpu)(struct device *dev,
  22. dma_addr_t dma_handle, size_t size,
  23. enum dma_data_direction direction);
  24. void (*sync_single_for_device)(struct device *dev,
  25. dma_addr_t dma_handle, size_t size,
  26. enum dma_data_direction direction);
  27. void (*sync_sg_for_cpu)(struct device *dev, struct scatterlist *sg,
  28. int nelems,
  29. enum dma_data_direction direction);
  30. void (*sync_sg_for_device)(struct device *dev,
  31. struct scatterlist *sg, int nents,
  32. enum dma_data_direction dir);
  33. };
  34. extern const struct dma_ops *dma_ops;
  35. static inline void *dma_alloc_coherent(struct device *dev, size_t size,
  36. dma_addr_t *dma_handle, gfp_t flag)
  37. {
  38. return dma_ops->alloc_coherent(dev, size, dma_handle, flag);
  39. }
  40. static inline void dma_free_coherent(struct device *dev, size_t size,
  41. void *cpu_addr, dma_addr_t dma_handle)
  42. {
  43. dma_ops->free_coherent(dev, size, cpu_addr, dma_handle);
  44. }
  45. static inline dma_addr_t dma_map_single(struct device *dev, void *cpu_addr,
  46. size_t size,
  47. enum dma_data_direction direction)
  48. {
  49. return dma_ops->map_single(dev, cpu_addr, size, direction);
  50. }
  51. static inline void dma_unmap_single(struct device *dev, dma_addr_t dma_addr,
  52. size_t size,
  53. enum dma_data_direction direction)
  54. {
  55. dma_ops->unmap_single(dev, dma_addr, size, direction);
  56. }
  57. static inline dma_addr_t dma_map_page(struct device *dev, struct page *page,
  58. unsigned long offset, size_t size,
  59. enum dma_data_direction direction)
  60. {
  61. return dma_ops->map_single(dev, page_address(page) + offset,
  62. size, direction);
  63. }
  64. static inline void dma_unmap_page(struct device *dev, dma_addr_t dma_address,
  65. size_t size,
  66. enum dma_data_direction direction)
  67. {
  68. dma_ops->unmap_single(dev, dma_address, size, direction);
  69. }
  70. static inline int dma_map_sg(struct device *dev, struct scatterlist *sg,
  71. int nents, enum dma_data_direction direction)
  72. {
  73. return dma_ops->map_sg(dev, sg, nents, direction);
  74. }
  75. static inline void dma_unmap_sg(struct device *dev, struct scatterlist *sg,
  76. int nents, enum dma_data_direction direction)
  77. {
  78. dma_ops->unmap_sg(dev, sg, nents, direction);
  79. }
  80. static inline void dma_sync_single_for_cpu(struct device *dev,
  81. dma_addr_t dma_handle, size_t size,
  82. enum dma_data_direction direction)
  83. {
  84. dma_ops->sync_single_for_cpu(dev, dma_handle, size, direction);
  85. }
  86. static inline void dma_sync_single_for_device(struct device *dev,
  87. dma_addr_t dma_handle,
  88. size_t size,
  89. enum dma_data_direction direction)
  90. {
  91. /* No flushing needed to sync cpu writes to the device. */
  92. }
  93. static inline void dma_sync_sg_for_cpu(struct device *dev,
  94. struct scatterlist *sg, int nelems,
  95. enum dma_data_direction direction)
  96. {
  97. dma_ops->sync_sg_for_cpu(dev, sg, nelems, direction);
  98. }
  99. static inline void dma_sync_sg_for_device(struct device *dev,
  100. struct scatterlist *sg, int nelems,
  101. enum dma_data_direction direction)
  102. {
  103. /* No flushing needed to sync cpu writes to the device. */
  104. }
  105. #endif /* _ASM_SPARC64_DMA_MAPPING_H */