dma-mapping.h 5.1 KB

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