dma-mapping.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. #ifndef _ASM_DMA_MAPPING_H
  2. #define _ASM_DMA_MAPPING_H
  3. #include <linux/device.h>
  4. #include <asm/cache.h>
  5. #include <asm/cacheflush.h>
  6. #include <asm/scatterlist.h>
  7. #include <asm/io.h>
  8. #define dma_alloc_noncoherent(d, s, h, f) dma_alloc_coherent(d, s, h, f)
  9. #define dma_free_noncoherent(d, s, v, h) dma_free_coherent(d, s, v, h)
  10. extern unsigned long __nongprelbss dma_coherent_mem_start;
  11. extern unsigned long __nongprelbss dma_coherent_mem_end;
  12. void *dma_alloc_coherent(struct device *dev, size_t size, dma_addr_t *dma_handle, gfp_t gfp);
  13. void dma_free_coherent(struct device *dev, size_t size, void *vaddr, dma_addr_t dma_handle);
  14. /*
  15. * These macros should be used after a pci_map_sg call has been done
  16. * to get bus addresses of each of the SG entries and their lengths.
  17. * You should only work with the number of sg entries pci_map_sg
  18. * returns, or alternatively stop on the first sg_dma_len(sg) which
  19. * is 0.
  20. */
  21. #define sg_dma_address(sg) ((sg)->dma_address)
  22. #define sg_dma_len(sg) ((sg)->length)
  23. /*
  24. * Map a single buffer of the indicated size for DMA in streaming mode.
  25. * The 32-bit bus address to use is returned.
  26. *
  27. * Once the device is given the dma address, the device owns this memory
  28. * until either pci_unmap_single or pci_dma_sync_single is performed.
  29. */
  30. extern dma_addr_t dma_map_single(struct device *dev, void *ptr, size_t size,
  31. enum dma_data_direction direction);
  32. /*
  33. * Unmap a single streaming mode DMA translation. The dma_addr and size
  34. * must match what was provided for in a previous pci_map_single call. All
  35. * other usages are undefined.
  36. *
  37. * After this call, reads by the cpu to the buffer are guarenteed to see
  38. * whatever the device wrote there.
  39. */
  40. static inline
  41. void dma_unmap_single(struct device *dev, dma_addr_t dma_addr, size_t size,
  42. enum dma_data_direction direction)
  43. {
  44. BUG_ON(direction == DMA_NONE);
  45. }
  46. /*
  47. * Map a set of buffers described by scatterlist in streaming
  48. * mode for DMA. This is the scather-gather version of the
  49. * above pci_map_single interface. Here the scatter gather list
  50. * elements are each tagged with the appropriate dma address
  51. * and length. They are obtained via sg_dma_{address,length}(SG).
  52. *
  53. * NOTE: An implementation may be able to use a smaller number of
  54. * DMA address/length pairs than there are SG table elements.
  55. * (for example via virtual mapping capabilities)
  56. * The routine returns the number of addr/length pairs actually
  57. * used, at most nents.
  58. *
  59. * Device ownership issues as mentioned above for pci_map_single are
  60. * the same here.
  61. */
  62. extern int dma_map_sg(struct device *dev, struct scatterlist *sg, int nents,
  63. enum dma_data_direction direction);
  64. /*
  65. * Unmap a set of streaming mode DMA translations.
  66. * Again, cpu read rules concerning calls here are the same as for
  67. * pci_unmap_single() above.
  68. */
  69. static inline
  70. void dma_unmap_sg(struct device *dev, struct scatterlist *sg, int nhwentries,
  71. enum dma_data_direction direction)
  72. {
  73. BUG_ON(direction == DMA_NONE);
  74. }
  75. extern
  76. dma_addr_t dma_map_page(struct device *dev, struct page *page, unsigned long offset,
  77. size_t size, enum dma_data_direction direction);
  78. static inline
  79. void dma_unmap_page(struct device *dev, dma_addr_t dma_address, size_t size,
  80. enum dma_data_direction direction)
  81. {
  82. BUG_ON(direction == DMA_NONE);
  83. }
  84. static inline
  85. void dma_sync_single_for_cpu(struct device *dev, dma_addr_t dma_handle, size_t size,
  86. enum dma_data_direction direction)
  87. {
  88. }
  89. static inline
  90. void dma_sync_single_for_device(struct device *dev, dma_addr_t dma_handle, size_t size,
  91. enum dma_data_direction direction)
  92. {
  93. flush_write_buffers();
  94. }
  95. static inline
  96. void dma_sync_single_range_for_cpu(struct device *dev, dma_addr_t dma_handle,
  97. unsigned long offset, size_t size,
  98. enum dma_data_direction direction)
  99. {
  100. }
  101. static inline
  102. void dma_sync_single_range_for_device(struct device *dev, dma_addr_t dma_handle,
  103. unsigned long offset, size_t size,
  104. enum dma_data_direction direction)
  105. {
  106. flush_write_buffers();
  107. }
  108. static inline
  109. void dma_sync_sg_for_cpu(struct device *dev, struct scatterlist *sg, int nelems,
  110. enum dma_data_direction direction)
  111. {
  112. }
  113. static inline
  114. void dma_sync_sg_for_device(struct device *dev, struct scatterlist *sg, int nelems,
  115. enum dma_data_direction direction)
  116. {
  117. flush_write_buffers();
  118. }
  119. static inline
  120. int dma_mapping_error(dma_addr_t dma_addr)
  121. {
  122. return 0;
  123. }
  124. static inline
  125. int dma_supported(struct device *dev, u64 mask)
  126. {
  127. /*
  128. * we fall back to GFP_DMA when the mask isn't all 1s,
  129. * so we can't guarantee allocations that must be
  130. * within a tighter range than GFP_DMA..
  131. */
  132. if (mask < 0x00ffffff)
  133. return 0;
  134. return 1;
  135. }
  136. static inline
  137. int dma_set_mask(struct device *dev, u64 mask)
  138. {
  139. if (!dev->dma_mask || !dma_supported(dev, mask))
  140. return -EIO;
  141. *dev->dma_mask = mask;
  142. return 0;
  143. }
  144. static inline
  145. int dma_get_cache_alignment(void)
  146. {
  147. return 1 << L1_CACHE_SHIFT;
  148. }
  149. #define dma_is_consistent(d) (1)
  150. static inline
  151. void dma_cache_sync(void *vaddr, size_t size,
  152. enum dma_data_direction direction)
  153. {
  154. flush_write_buffers();
  155. }
  156. #endif /* _ASM_DMA_MAPPING_H */