dma.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. /* dma.c: PCI and SBUS DMA accessors for 32-bit sparc.
  2. *
  3. * Copyright (C) 2008 David S. Miller <davem@davemloft.net>
  4. */
  5. #include <linux/kernel.h>
  6. #include <linux/module.h>
  7. #include <linux/dma-mapping.h>
  8. #include <linux/scatterlist.h>
  9. #include <linux/mm.h>
  10. #ifdef CONFIG_PCI
  11. #include <linux/pci.h>
  12. #endif
  13. #include "dma.h"
  14. int dma_supported(struct device *dev, u64 mask)
  15. {
  16. #ifdef CONFIG_PCI
  17. if (dev->bus == &pci_bus_type)
  18. return pci_dma_supported(to_pci_dev(dev), mask);
  19. #endif
  20. return 0;
  21. }
  22. EXPORT_SYMBOL(dma_supported);
  23. int dma_set_mask(struct device *dev, u64 dma_mask)
  24. {
  25. #ifdef CONFIG_PCI
  26. if (dev->bus == &pci_bus_type)
  27. return pci_set_dma_mask(to_pci_dev(dev), dma_mask);
  28. #endif
  29. return -EOPNOTSUPP;
  30. }
  31. EXPORT_SYMBOL(dma_set_mask);
  32. void *dma_alloc_coherent(struct device *dev, size_t size,
  33. dma_addr_t *dma_handle, gfp_t flag)
  34. {
  35. #ifdef CONFIG_PCI
  36. if (dev->bus == &pci_bus_type)
  37. return pci_alloc_consistent(to_pci_dev(dev), size, dma_handle);
  38. #endif
  39. return sbus_alloc_consistent(dev, size, dma_handle);
  40. }
  41. EXPORT_SYMBOL(dma_alloc_coherent);
  42. void dma_free_coherent(struct device *dev, size_t size,
  43. void *cpu_addr, dma_addr_t dma_handle)
  44. {
  45. #ifdef CONFIG_PCI
  46. if (dev->bus == &pci_bus_type) {
  47. pci_free_consistent(to_pci_dev(dev), size,
  48. cpu_addr, dma_handle);
  49. return;
  50. }
  51. #endif
  52. sbus_free_consistent(dev, size, cpu_addr, dma_handle);
  53. }
  54. EXPORT_SYMBOL(dma_free_coherent);
  55. dma_addr_t dma_map_single(struct device *dev, void *cpu_addr,
  56. size_t size, enum dma_data_direction direction)
  57. {
  58. #ifdef CONFIG_PCI
  59. if (dev->bus == &pci_bus_type)
  60. return pci_map_single(to_pci_dev(dev), cpu_addr,
  61. size, (int)direction);
  62. #endif
  63. return sbus_map_single(dev, cpu_addr, size, (int)direction);
  64. }
  65. EXPORT_SYMBOL(dma_map_single);
  66. void dma_unmap_single(struct device *dev, dma_addr_t dma_addr,
  67. size_t size,
  68. enum dma_data_direction direction)
  69. {
  70. #ifdef CONFIG_PCI
  71. if (dev->bus == &pci_bus_type) {
  72. pci_unmap_single(to_pci_dev(dev), dma_addr,
  73. size, (int)direction);
  74. return;
  75. }
  76. #endif
  77. sbus_unmap_single(dev, dma_addr, size, (int)direction);
  78. }
  79. EXPORT_SYMBOL(dma_unmap_single);
  80. dma_addr_t dma_map_page(struct device *dev, struct page *page,
  81. unsigned long offset, size_t size,
  82. enum dma_data_direction direction)
  83. {
  84. #ifdef CONFIG_PCI
  85. if (dev->bus == &pci_bus_type)
  86. return pci_map_page(to_pci_dev(dev), page, offset,
  87. size, (int)direction);
  88. #endif
  89. return sbus_map_single(dev, page_address(page) + offset,
  90. size, (int)direction);
  91. }
  92. EXPORT_SYMBOL(dma_map_page);
  93. void dma_unmap_page(struct device *dev, dma_addr_t dma_address,
  94. size_t size, enum dma_data_direction direction)
  95. {
  96. #ifdef CONFIG_PCI
  97. if (dev->bus == &pci_bus_type) {
  98. pci_unmap_page(to_pci_dev(dev), dma_address,
  99. size, (int)direction);
  100. return;
  101. }
  102. #endif
  103. sbus_unmap_single(dev, dma_address, size, (int)direction);
  104. }
  105. EXPORT_SYMBOL(dma_unmap_page);
  106. int dma_map_sg(struct device *dev, struct scatterlist *sg,
  107. int nents, enum dma_data_direction direction)
  108. {
  109. #ifdef CONFIG_PCI
  110. if (dev->bus == &pci_bus_type)
  111. return pci_map_sg(to_pci_dev(dev), sg, nents, (int)direction);
  112. #endif
  113. return sbus_map_sg(dev, sg, nents, direction);
  114. }
  115. EXPORT_SYMBOL(dma_map_sg);
  116. void dma_unmap_sg(struct device *dev, struct scatterlist *sg,
  117. int nents, enum dma_data_direction direction)
  118. {
  119. #ifdef CONFIG_PCI
  120. if (dev->bus == &pci_bus_type) {
  121. pci_unmap_sg(to_pci_dev(dev), sg, nents, (int)direction);
  122. return;
  123. }
  124. #endif
  125. sbus_unmap_sg(dev, sg, nents, (int)direction);
  126. }
  127. EXPORT_SYMBOL(dma_unmap_sg);
  128. void dma_sync_single_for_cpu(struct device *dev, dma_addr_t dma_handle,
  129. size_t size, enum dma_data_direction direction)
  130. {
  131. #ifdef CONFIG_PCI
  132. if (dev->bus == &pci_bus_type) {
  133. pci_dma_sync_single_for_cpu(to_pci_dev(dev), dma_handle,
  134. size, (int)direction);
  135. return;
  136. }
  137. #endif
  138. sbus_dma_sync_single_for_cpu(dev, dma_handle, size, (int) direction);
  139. }
  140. EXPORT_SYMBOL(dma_sync_single_for_cpu);
  141. void dma_sync_single_for_device(struct device *dev, dma_addr_t dma_handle,
  142. size_t size, enum dma_data_direction direction)
  143. {
  144. #ifdef CONFIG_PCI
  145. if (dev->bus == &pci_bus_type) {
  146. pci_dma_sync_single_for_device(to_pci_dev(dev), dma_handle,
  147. size, (int)direction);
  148. return;
  149. }
  150. #endif
  151. sbus_dma_sync_single_for_device(dev, dma_handle, size, (int) direction);
  152. }
  153. EXPORT_SYMBOL(dma_sync_single_for_device);
  154. void dma_sync_single_range_for_cpu(struct device *dev,
  155. dma_addr_t dma_handle,
  156. unsigned long offset,
  157. size_t size,
  158. enum dma_data_direction direction)
  159. {
  160. dma_sync_single_for_cpu(dev, dma_handle+offset, size, direction);
  161. }
  162. EXPORT_SYMBOL(dma_sync_single_range_for_cpu);
  163. void dma_sync_single_range_for_device(struct device *dev, dma_addr_t dma_handle,
  164. unsigned long offset, size_t size,
  165. enum dma_data_direction direction)
  166. {
  167. dma_sync_single_for_device(dev, dma_handle+offset, size, direction);
  168. }
  169. EXPORT_SYMBOL(dma_sync_single_range_for_device);
  170. void dma_sync_sg_for_cpu(struct device *dev, struct scatterlist *sg,
  171. int nelems, enum dma_data_direction direction)
  172. {
  173. #ifdef CONFIG_PCI
  174. if (dev->bus == &pci_bus_type) {
  175. pci_dma_sync_sg_for_cpu(to_pci_dev(dev), sg,
  176. nelems, (int)direction);
  177. return;
  178. }
  179. #endif
  180. BUG();
  181. }
  182. EXPORT_SYMBOL(dma_sync_sg_for_cpu);
  183. void dma_sync_sg_for_device(struct device *dev,
  184. struct scatterlist *sg, int nelems,
  185. enum dma_data_direction direction)
  186. {
  187. #ifdef CONFIG_PCI
  188. if (dev->bus == &pci_bus_type) {
  189. pci_dma_sync_sg_for_device(to_pci_dev(dev), sg,
  190. nelems, (int)direction);
  191. return;
  192. }
  193. #endif
  194. BUG();
  195. }
  196. EXPORT_SYMBOL(dma_sync_sg_for_device);
  197. int dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
  198. {
  199. return (dma_addr == DMA_ERROR_CODE);
  200. }
  201. EXPORT_SYMBOL(dma_mapping_error);
  202. int dma_get_cache_alignment(void)
  203. {
  204. return 32;
  205. }
  206. EXPORT_SYMBOL(dma_get_cache_alignment);