dma-mapping.h 5.1 KB

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