dma-mapping.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. /* DMA mapping. Nothing tricky here, just virt_to_phys */
  2. #ifndef _ASM_CRIS_DMA_MAPPING_H
  3. #define _ASM_CRIS_DMA_MAPPING_H
  4. #include <linux/mm.h>
  5. #include <linux/kernel.h>
  6. #include <asm/cache.h>
  7. #include <asm/io.h>
  8. #include <asm/scatterlist.h>
  9. #define dma_alloc_noncoherent(d, s, h, f) dma_alloc_coherent(d, s, h, f)
  10. #define dma_free_noncoherent(d, s, v, h) dma_free_coherent(d, s, v, h)
  11. #ifdef CONFIG_PCI
  12. #include <asm-generic/dma-coherent.h>
  13. void *dma_alloc_coherent(struct device *dev, size_t size,
  14. dma_addr_t *dma_handle, gfp_t flag);
  15. void dma_free_coherent(struct device *dev, size_t size,
  16. void *vaddr, dma_addr_t dma_handle);
  17. #else
  18. static inline void *
  19. dma_alloc_coherent(struct device *dev, size_t size, dma_addr_t *dma_handle,
  20. gfp_t flag)
  21. {
  22. BUG();
  23. return NULL;
  24. }
  25. static inline void
  26. dma_free_coherent(struct device *dev, size_t size, void *cpu_addr,
  27. dma_addr_t dma_handle)
  28. {
  29. BUG();
  30. }
  31. #endif
  32. static inline dma_addr_t
  33. dma_map_single(struct device *dev, void *ptr, size_t size,
  34. enum dma_data_direction direction)
  35. {
  36. BUG_ON(direction == DMA_NONE);
  37. return virt_to_phys(ptr);
  38. }
  39. static inline void
  40. dma_unmap_single(struct device *dev, dma_addr_t dma_addr, size_t size,
  41. enum dma_data_direction direction)
  42. {
  43. BUG_ON(direction == DMA_NONE);
  44. }
  45. static inline int
  46. dma_map_sg(struct device *dev, struct scatterlist *sg, int nents,
  47. enum dma_data_direction direction)
  48. {
  49. printk("Map sg\n");
  50. return nents;
  51. }
  52. static inline dma_addr_t
  53. dma_map_page(struct device *dev, struct page *page, unsigned long offset,
  54. size_t size, enum dma_data_direction direction)
  55. {
  56. BUG_ON(direction == DMA_NONE);
  57. return page_to_phys(page) + offset;
  58. }
  59. static inline void
  60. dma_unmap_page(struct device *dev, dma_addr_t dma_address, size_t size,
  61. enum dma_data_direction direction)
  62. {
  63. BUG_ON(direction == DMA_NONE);
  64. }
  65. static inline void
  66. dma_unmap_sg(struct device *dev, struct scatterlist *sg, int nhwentries,
  67. enum dma_data_direction direction)
  68. {
  69. BUG_ON(direction == DMA_NONE);
  70. }
  71. static inline void
  72. dma_sync_single_for_cpu(struct device *dev, dma_addr_t dma_handle, size_t size,
  73. enum dma_data_direction direction)
  74. {
  75. }
  76. static inline void
  77. dma_sync_single_for_device(struct device *dev, dma_addr_t dma_handle, size_t size,
  78. enum dma_data_direction direction)
  79. {
  80. }
  81. static inline void
  82. dma_sync_single_range_for_cpu(struct device *dev, dma_addr_t dma_handle,
  83. unsigned long offset, size_t size,
  84. enum dma_data_direction direction)
  85. {
  86. }
  87. static inline void
  88. dma_sync_single_range_for_device(struct device *dev, dma_addr_t dma_handle,
  89. unsigned long offset, size_t size,
  90. enum dma_data_direction direction)
  91. {
  92. }
  93. static inline void
  94. dma_sync_sg_for_cpu(struct device *dev, struct scatterlist *sg, int nelems,
  95. enum dma_data_direction direction)
  96. {
  97. }
  98. static inline void
  99. dma_sync_sg_for_device(struct device *dev, struct scatterlist *sg, int nelems,
  100. enum dma_data_direction direction)
  101. {
  102. }
  103. static inline int
  104. dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
  105. {
  106. return 0;
  107. }
  108. static inline int
  109. dma_supported(struct device *dev, u64 mask)
  110. {
  111. /*
  112. * we fall back to GFP_DMA when the mask isn't all 1s,
  113. * so we can't guarantee allocations that must be
  114. * within a tighter range than GFP_DMA..
  115. */
  116. if(mask < 0x00ffffff)
  117. return 0;
  118. return 1;
  119. }
  120. static inline int
  121. dma_set_mask(struct device *dev, u64 mask)
  122. {
  123. if(!dev->dma_mask || !dma_supported(dev, mask))
  124. return -EIO;
  125. *dev->dma_mask = mask;
  126. return 0;
  127. }
  128. static inline void
  129. dma_cache_sync(struct device *dev, void *vaddr, size_t size,
  130. enum dma_data_direction direction)
  131. {
  132. }
  133. #endif