dma-mapping.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. #ifndef _ASM_DMA_MAPPING_H
  2. #define _ASM_DMA_MAPPING_H
  3. #include <linux/device.h>
  4. #include <linux/scatterlist.h>
  5. #include <asm/cache.h>
  6. #include <asm/cacheflush.h>
  7. #include <asm/io.h>
  8. /*
  9. * See Documentation/DMA-API.txt for the description of how the
  10. * following DMA API should work.
  11. */
  12. #define dma_alloc_noncoherent(d, s, h, f) dma_alloc_coherent(d, s, h, f)
  13. #define dma_free_noncoherent(d, s, v, h) dma_free_coherent(d, s, v, h)
  14. extern unsigned long __nongprelbss dma_coherent_mem_start;
  15. extern unsigned long __nongprelbss dma_coherent_mem_end;
  16. void *dma_alloc_coherent(struct device *dev, size_t size, dma_addr_t *dma_handle, gfp_t gfp);
  17. void dma_free_coherent(struct device *dev, size_t size, void *vaddr, dma_addr_t dma_handle);
  18. extern dma_addr_t dma_map_single(struct device *dev, void *ptr, size_t size,
  19. enum dma_data_direction direction);
  20. static inline
  21. void dma_unmap_single(struct device *dev, dma_addr_t dma_addr, size_t size,
  22. enum dma_data_direction direction)
  23. {
  24. BUG_ON(direction == DMA_NONE);
  25. }
  26. extern int dma_map_sg(struct device *dev, struct scatterlist *sg, int nents,
  27. enum dma_data_direction direction);
  28. static inline
  29. void dma_unmap_sg(struct device *dev, struct scatterlist *sg, int nhwentries,
  30. enum dma_data_direction direction)
  31. {
  32. BUG_ON(direction == DMA_NONE);
  33. }
  34. extern
  35. dma_addr_t dma_map_page(struct device *dev, struct page *page, unsigned long offset,
  36. size_t size, enum dma_data_direction direction);
  37. static inline
  38. void dma_unmap_page(struct device *dev, dma_addr_t dma_address, size_t size,
  39. enum dma_data_direction direction)
  40. {
  41. BUG_ON(direction == DMA_NONE);
  42. }
  43. static inline
  44. void dma_sync_single_for_cpu(struct device *dev, dma_addr_t dma_handle, size_t size,
  45. enum dma_data_direction direction)
  46. {
  47. }
  48. static inline
  49. void dma_sync_single_for_device(struct device *dev, dma_addr_t dma_handle, size_t size,
  50. enum dma_data_direction direction)
  51. {
  52. flush_write_buffers();
  53. }
  54. static inline
  55. void dma_sync_single_range_for_cpu(struct device *dev, dma_addr_t dma_handle,
  56. unsigned long offset, size_t size,
  57. enum dma_data_direction direction)
  58. {
  59. }
  60. static inline
  61. void dma_sync_single_range_for_device(struct device *dev, dma_addr_t dma_handle,
  62. unsigned long offset, size_t size,
  63. enum dma_data_direction direction)
  64. {
  65. flush_write_buffers();
  66. }
  67. static inline
  68. void dma_sync_sg_for_cpu(struct device *dev, struct scatterlist *sg, int nelems,
  69. enum dma_data_direction direction)
  70. {
  71. }
  72. static inline
  73. void dma_sync_sg_for_device(struct device *dev, struct scatterlist *sg, int nelems,
  74. enum dma_data_direction direction)
  75. {
  76. flush_write_buffers();
  77. }
  78. static inline
  79. int dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
  80. {
  81. return 0;
  82. }
  83. static inline
  84. int dma_supported(struct device *dev, u64 mask)
  85. {
  86. /*
  87. * we fall back to GFP_DMA when the mask isn't all 1s,
  88. * so we can't guarantee allocations that must be
  89. * within a tighter range than GFP_DMA..
  90. */
  91. if (mask < 0x00ffffff)
  92. return 0;
  93. return 1;
  94. }
  95. static inline
  96. int dma_set_mask(struct device *dev, u64 mask)
  97. {
  98. if (!dev->dma_mask || !dma_supported(dev, mask))
  99. return -EIO;
  100. *dev->dma_mask = mask;
  101. return 0;
  102. }
  103. static inline
  104. void dma_cache_sync(struct device *dev, void *vaddr, size_t size,
  105. enum dma_data_direction direction)
  106. {
  107. flush_write_buffers();
  108. }
  109. /* Not supported for now */
  110. static inline int dma_mmap_coherent(struct device *dev,
  111. struct vm_area_struct *vma, void *cpu_addr,
  112. dma_addr_t dma_addr, size_t size)
  113. {
  114. return -EINVAL;
  115. }
  116. static inline int dma_get_sgtable(struct device *dev, struct sg_table *sgt,
  117. void *cpu_addr, dma_addr_t dma_addr,
  118. size_t size)
  119. {
  120. return -EINVAL;
  121. }
  122. #endif /* _ASM_DMA_MAPPING_H */