dma.c 4.6 KB

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