dma-mapping.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. #ifndef __ASM_SH_DMA_MAPPING_H
  2. #define __ASM_SH_DMA_MAPPING_H
  3. #include <linux/mm.h>
  4. #include <linux/scatterlist.h>
  5. #include <asm/cacheflush.h>
  6. #include <asm/io.h>
  7. extern struct bus_type pci_bus_type;
  8. #define dma_supported(dev, mask) (1)
  9. static inline int dma_set_mask(struct device *dev, u64 mask)
  10. {
  11. if (!dev->dma_mask || !dma_supported(dev, mask))
  12. return -EIO;
  13. *dev->dma_mask = mask;
  14. return 0;
  15. }
  16. void *dma_alloc_coherent(struct device *dev, size_t size,
  17. dma_addr_t *dma_handle, gfp_t flag);
  18. void dma_free_coherent(struct device *dev, size_t size,
  19. void *vaddr, dma_addr_t dma_handle);
  20. void dma_cache_sync(struct device *dev, void *vaddr, size_t size,
  21. enum dma_data_direction dir);
  22. #define dma_alloc_noncoherent(d, s, h, f) dma_alloc_coherent(d, s, h, f)
  23. #define dma_free_noncoherent(d, s, v, h) dma_free_coherent(d, s, v, h)
  24. #define dma_is_consistent(d, h) (1)
  25. static inline dma_addr_t dma_map_single(struct device *dev,
  26. void *ptr, size_t size,
  27. enum dma_data_direction dir)
  28. {
  29. #if defined(CONFIG_PCI) && !defined(CONFIG_SH_PCIDMA_NONCOHERENT)
  30. if (dev->bus == &pci_bus_type)
  31. return virt_to_phys(ptr);
  32. #endif
  33. dma_cache_sync(dev, ptr, size, dir);
  34. return virt_to_phys(ptr);
  35. }
  36. #define dma_unmap_single(dev, addr, size, dir) do { } while (0)
  37. static inline int dma_map_sg(struct device *dev, struct scatterlist *sg,
  38. int nents, enum dma_data_direction dir)
  39. {
  40. int i;
  41. for (i = 0; i < nents; i++) {
  42. #if !defined(CONFIG_PCI) || defined(CONFIG_SH_PCIDMA_NONCOHERENT)
  43. dma_cache_sync(dev, sg_virt(&sg[i]), sg[i].length, dir);
  44. #endif
  45. sg[i].dma_address = sg_phys(&sg[i]);
  46. }
  47. return nents;
  48. }
  49. #define dma_unmap_sg(dev, sg, nents, dir) do { } while (0)
  50. static inline dma_addr_t dma_map_page(struct device *dev, struct page *page,
  51. unsigned long offset, size_t size,
  52. enum dma_data_direction dir)
  53. {
  54. return dma_map_single(dev, page_address(page) + offset, size, dir);
  55. }
  56. static inline void dma_unmap_page(struct device *dev, dma_addr_t dma_address,
  57. size_t size, enum dma_data_direction dir)
  58. {
  59. dma_unmap_single(dev, dma_address, size, dir);
  60. }
  61. static inline void dma_sync_single(struct device *dev, dma_addr_t dma_handle,
  62. size_t size, enum dma_data_direction dir)
  63. {
  64. #if defined(CONFIG_PCI) && !defined(CONFIG_SH_PCIDMA_NONCOHERENT)
  65. if (dev->bus == &pci_bus_type)
  66. return;
  67. #endif
  68. dma_cache_sync(dev, phys_to_virt(dma_handle), size, dir);
  69. }
  70. static inline void dma_sync_single_range(struct device *dev,
  71. dma_addr_t dma_handle,
  72. unsigned long offset, size_t size,
  73. enum dma_data_direction dir)
  74. {
  75. #if defined(CONFIG_PCI) && !defined(CONFIG_SH_PCIDMA_NONCOHERENT)
  76. if (dev->bus == &pci_bus_type)
  77. return;
  78. #endif
  79. dma_cache_sync(dev, phys_to_virt(dma_handle) + offset, size, dir);
  80. }
  81. static inline void dma_sync_sg(struct device *dev, struct scatterlist *sg,
  82. int nelems, enum dma_data_direction dir)
  83. {
  84. int i;
  85. for (i = 0; i < nelems; i++) {
  86. #if !defined(CONFIG_PCI) || defined(CONFIG_SH_PCIDMA_NONCOHERENT)
  87. dma_cache_sync(dev, sg_virt(&sg[i]), sg[i].length, dir);
  88. #endif
  89. sg[i].dma_address = sg_phys(&sg[i]);
  90. }
  91. }
  92. static inline void dma_sync_single_for_cpu(struct device *dev,
  93. dma_addr_t dma_handle, size_t size,
  94. enum dma_data_direction dir)
  95. {
  96. dma_sync_single(dev, dma_handle, size, dir);
  97. }
  98. static inline void dma_sync_single_for_device(struct device *dev,
  99. dma_addr_t dma_handle,
  100. size_t size,
  101. enum dma_data_direction dir)
  102. {
  103. dma_sync_single(dev, dma_handle, size, dir);
  104. }
  105. static inline void dma_sync_single_range_for_cpu(struct device *dev,
  106. dma_addr_t dma_handle,
  107. unsigned long offset,
  108. size_t size,
  109. enum dma_data_direction direction)
  110. {
  111. dma_sync_single_for_cpu(dev, dma_handle+offset, size, direction);
  112. }
  113. static inline void dma_sync_single_range_for_device(struct device *dev,
  114. dma_addr_t dma_handle,
  115. unsigned long offset,
  116. size_t size,
  117. enum dma_data_direction direction)
  118. {
  119. dma_sync_single_for_device(dev, dma_handle+offset, size, direction);
  120. }
  121. static inline void dma_sync_sg_for_cpu(struct device *dev,
  122. struct scatterlist *sg, int nelems,
  123. enum dma_data_direction dir)
  124. {
  125. dma_sync_sg(dev, sg, nelems, dir);
  126. }
  127. static inline void dma_sync_sg_for_device(struct device *dev,
  128. struct scatterlist *sg, int nelems,
  129. enum dma_data_direction dir)
  130. {
  131. dma_sync_sg(dev, sg, nelems, dir);
  132. }
  133. static inline int dma_get_cache_alignment(void)
  134. {
  135. /*
  136. * Each processor family will define its own L1_CACHE_SHIFT,
  137. * L1_CACHE_BYTES wraps to this, so this is always safe.
  138. */
  139. return L1_CACHE_BYTES;
  140. }
  141. static inline int dma_mapping_error(dma_addr_t dma_addr)
  142. {
  143. return dma_addr == 0;
  144. }
  145. #define ARCH_HAS_DMA_DECLARE_COHERENT_MEMORY
  146. extern int
  147. dma_declare_coherent_memory(struct device *dev, dma_addr_t bus_addr,
  148. dma_addr_t device_addr, size_t size, int flags);
  149. extern void
  150. dma_release_declared_memory(struct device *dev);
  151. extern void *
  152. dma_mark_declared_memory_occupied(struct device *dev,
  153. dma_addr_t device_addr, size_t size);
  154. #endif /* __ASM_SH_DMA_MAPPING_H */