dma.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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. static void *dma32_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. static void dma32_free_coherent(struct device *dev, size_t size,
  42. void *cpu_addr, dma_addr_t dma_handle)
  43. {
  44. #ifdef CONFIG_PCI
  45. if (dev->bus == &pci_bus_type) {
  46. pci_free_consistent(to_pci_dev(dev), size,
  47. cpu_addr, dma_handle);
  48. return;
  49. }
  50. #endif
  51. sbus_free_consistent(dev, size, cpu_addr, dma_handle);
  52. }
  53. static dma_addr_t dma32_map_page(struct device *dev, struct page *page,
  54. unsigned long offset, size_t size,
  55. enum dma_data_direction direction)
  56. {
  57. #ifdef CONFIG_PCI
  58. if (dev->bus == &pci_bus_type)
  59. return pci_map_page(to_pci_dev(dev), page, offset,
  60. size, (int)direction);
  61. #endif
  62. return sbus_map_single(dev, page_address(page) + offset,
  63. size, (int)direction);
  64. }
  65. static void dma32_unmap_page(struct device *dev, dma_addr_t dma_address,
  66. size_t size, enum dma_data_direction direction)
  67. {
  68. #ifdef CONFIG_PCI
  69. if (dev->bus == &pci_bus_type) {
  70. pci_unmap_page(to_pci_dev(dev), dma_address,
  71. size, (int)direction);
  72. return;
  73. }
  74. #endif
  75. sbus_unmap_single(dev, dma_address, size, (int)direction);
  76. }
  77. static int dma32_map_sg(struct device *dev, struct scatterlist *sg,
  78. int nents, enum dma_data_direction direction)
  79. {
  80. #ifdef CONFIG_PCI
  81. if (dev->bus == &pci_bus_type)
  82. return pci_map_sg(to_pci_dev(dev), sg, nents, (int)direction);
  83. #endif
  84. return sbus_map_sg(dev, sg, nents, direction);
  85. }
  86. void dma32_unmap_sg(struct device *dev, struct scatterlist *sg,
  87. int nents, enum dma_data_direction direction)
  88. {
  89. #ifdef CONFIG_PCI
  90. if (dev->bus == &pci_bus_type) {
  91. pci_unmap_sg(to_pci_dev(dev), sg, nents, (int)direction);
  92. return;
  93. }
  94. #endif
  95. sbus_unmap_sg(dev, sg, nents, (int)direction);
  96. }
  97. static void dma32_sync_single_for_cpu(struct device *dev, dma_addr_t dma_handle,
  98. size_t size,
  99. enum dma_data_direction direction)
  100. {
  101. #ifdef CONFIG_PCI
  102. if (dev->bus == &pci_bus_type) {
  103. pci_dma_sync_single_for_cpu(to_pci_dev(dev), dma_handle,
  104. size, (int)direction);
  105. return;
  106. }
  107. #endif
  108. sbus_dma_sync_single_for_cpu(dev, dma_handle, size, (int) direction);
  109. }
  110. static void dma32_sync_single_for_device(struct device *dev,
  111. dma_addr_t dma_handle, size_t size,
  112. enum dma_data_direction direction)
  113. {
  114. #ifdef CONFIG_PCI
  115. if (dev->bus == &pci_bus_type) {
  116. pci_dma_sync_single_for_device(to_pci_dev(dev), dma_handle,
  117. size, (int)direction);
  118. return;
  119. }
  120. #endif
  121. sbus_dma_sync_single_for_device(dev, dma_handle, size, (int) direction);
  122. }
  123. static void dma32_sync_sg_for_cpu(struct device *dev, struct scatterlist *sg,
  124. int nelems, enum dma_data_direction direction)
  125. {
  126. #ifdef CONFIG_PCI
  127. if (dev->bus == &pci_bus_type) {
  128. pci_dma_sync_sg_for_cpu(to_pci_dev(dev), sg,
  129. nelems, (int)direction);
  130. return;
  131. }
  132. #endif
  133. BUG();
  134. }
  135. static void dma32_sync_sg_for_device(struct device *dev,
  136. struct scatterlist *sg, int nelems,
  137. enum dma_data_direction direction)
  138. {
  139. #ifdef CONFIG_PCI
  140. if (dev->bus == &pci_bus_type) {
  141. pci_dma_sync_sg_for_device(to_pci_dev(dev), sg,
  142. nelems, (int)direction);
  143. return;
  144. }
  145. #endif
  146. BUG();
  147. }
  148. static const struct dma_ops dma32_dma_ops = {
  149. .alloc_coherent = dma32_alloc_coherent,
  150. .free_coherent = dma32_free_coherent,
  151. .map_page = dma32_map_page,
  152. .unmap_page = dma32_unmap_page,
  153. .map_sg = dma32_map_sg,
  154. .unmap_sg = dma32_unmap_sg,
  155. .sync_single_for_cpu = dma32_sync_single_for_cpu,
  156. .sync_single_for_device = dma32_sync_single_for_device,
  157. .sync_sg_for_cpu = dma32_sync_sg_for_cpu,
  158. .sync_sg_for_device = dma32_sync_sg_for_device,
  159. };
  160. const struct dma_ops *dma_ops = &dma32_dma_ops;
  161. EXPORT_SYMBOL(dma_ops);