dma-mapping.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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. void *dma_alloc_coherent(struct device *dev, size_t size,
  13. dma_addr_t *dma_handle, gfp_t flag);
  14. void dma_free_coherent(struct device *dev, size_t size,
  15. void *vaddr, dma_addr_t dma_handle);
  16. #else
  17. static inline void *
  18. dma_alloc_coherent(struct device *dev, size_t size, dma_addr_t *dma_handle,
  19. gfp_t flag)
  20. {
  21. BUG();
  22. return NULL;
  23. }
  24. static inline void
  25. dma_free_coherent(struct device *dev, size_t size, void *cpu_addr,
  26. dma_addr_t dma_handle)
  27. {
  28. BUG();
  29. }
  30. #endif
  31. static inline dma_addr_t
  32. dma_map_single(struct device *dev, void *ptr, size_t size,
  33. enum dma_data_direction direction)
  34. {
  35. BUG_ON(direction == DMA_NONE);
  36. return virt_to_phys(ptr);
  37. }
  38. static inline void
  39. dma_unmap_single(struct device *dev, dma_addr_t dma_addr, size_t size,
  40. enum dma_data_direction direction)
  41. {
  42. BUG_ON(direction == DMA_NONE);
  43. }
  44. static inline int
  45. dma_map_sg(struct device *dev, struct scatterlist *sg, int nents,
  46. enum dma_data_direction direction)
  47. {
  48. printk("Map sg\n");
  49. return nents;
  50. }
  51. static inline dma_addr_t
  52. dma_map_page(struct device *dev, struct page *page, unsigned long offset,
  53. size_t size, enum dma_data_direction direction)
  54. {
  55. BUG_ON(direction == DMA_NONE);
  56. return page_to_phys(page) + offset;
  57. }
  58. static inline void
  59. dma_unmap_page(struct device *dev, dma_addr_t dma_address, size_t size,
  60. enum dma_data_direction direction)
  61. {
  62. BUG_ON(direction == DMA_NONE);
  63. }
  64. static inline void
  65. dma_unmap_sg(struct device *dev, struct scatterlist *sg, int nhwentries,
  66. enum dma_data_direction direction)
  67. {
  68. BUG_ON(direction == DMA_NONE);
  69. }
  70. static inline void
  71. dma_sync_single_for_cpu(struct device *dev, dma_addr_t dma_handle, size_t size,
  72. enum dma_data_direction direction)
  73. {
  74. }
  75. static inline void
  76. dma_sync_single_for_device(struct device *dev, dma_addr_t dma_handle, size_t size,
  77. enum dma_data_direction direction)
  78. {
  79. }
  80. static inline void
  81. dma_sync_single_range_for_cpu(struct device *dev, dma_addr_t dma_handle,
  82. unsigned long offset, size_t size,
  83. enum dma_data_direction direction)
  84. {
  85. }
  86. static inline void
  87. dma_sync_single_range_for_device(struct device *dev, dma_addr_t dma_handle,
  88. unsigned long offset, size_t size,
  89. enum dma_data_direction direction)
  90. {
  91. }
  92. static inline void
  93. dma_sync_sg_for_cpu(struct device *dev, struct scatterlist *sg, int nelems,
  94. enum dma_data_direction direction)
  95. {
  96. }
  97. static inline void
  98. dma_sync_sg_for_device(struct device *dev, struct scatterlist *sg, int nelems,
  99. enum dma_data_direction direction)
  100. {
  101. }
  102. static inline int
  103. dma_mapping_error(dma_addr_t dma_addr)
  104. {
  105. return 0;
  106. }
  107. static inline int
  108. dma_supported(struct device *dev, u64 mask)
  109. {
  110. /*
  111. * we fall back to GFP_DMA when the mask isn't all 1s,
  112. * so we can't guarantee allocations that must be
  113. * within a tighter range than GFP_DMA..
  114. */
  115. if(mask < 0x00ffffff)
  116. return 0;
  117. return 1;
  118. }
  119. static inline int
  120. dma_set_mask(struct device *dev, u64 mask)
  121. {
  122. if(!dev->dma_mask || !dma_supported(dev, mask))
  123. return -EIO;
  124. *dev->dma_mask = mask;
  125. return 0;
  126. }
  127. static inline int
  128. dma_get_cache_alignment(void)
  129. {
  130. return (1 << INTERNODE_CACHE_SHIFT);
  131. }
  132. #define dma_is_consistent(d) (1)
  133. static inline void
  134. dma_cache_sync(void *vaddr, size_t size,
  135. enum dma_data_direction direction)
  136. {
  137. }
  138. #define ARCH_HAS_DMA_DECLARE_COHERENT_MEMORY
  139. extern int
  140. dma_declare_coherent_memory(struct device *dev, dma_addr_t bus_addr,
  141. dma_addr_t device_addr, size_t size, int flags);
  142. extern void
  143. dma_release_declared_memory(struct device *dev);
  144. extern void *
  145. dma_mark_declared_memory_occupied(struct device *dev,
  146. dma_addr_t device_addr, size_t size);
  147. #endif