dma-mapping.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. #ifndef _ASM_SPARC64_DMA_MAPPING_H
  2. #define _ASM_SPARC64_DMA_MAPPING_H
  3. #include <linux/config.h>
  4. #ifdef CONFIG_PCI
  5. /* we implement the API below in terms of the existing PCI one,
  6. * so include it */
  7. #include <linux/pci.h>
  8. /* need struct page definitions */
  9. #include <linux/mm.h>
  10. static inline int
  11. dma_supported(struct device *dev, u64 mask)
  12. {
  13. BUG_ON(dev->bus != &pci_bus_type);
  14. return pci_dma_supported(to_pci_dev(dev), mask);
  15. }
  16. static inline int
  17. dma_set_mask(struct device *dev, u64 dma_mask)
  18. {
  19. BUG_ON(dev->bus != &pci_bus_type);
  20. return pci_set_dma_mask(to_pci_dev(dev), dma_mask);
  21. }
  22. static inline void *
  23. dma_alloc_coherent(struct device *dev, size_t size, dma_addr_t *dma_handle,
  24. gfp_t flag)
  25. {
  26. BUG_ON(dev->bus != &pci_bus_type);
  27. return pci_iommu_ops->alloc_consistent(to_pci_dev(dev), size, dma_handle, flag);
  28. }
  29. static inline void
  30. dma_free_coherent(struct device *dev, size_t size, void *cpu_addr,
  31. dma_addr_t dma_handle)
  32. {
  33. BUG_ON(dev->bus != &pci_bus_type);
  34. pci_free_consistent(to_pci_dev(dev), size, cpu_addr, dma_handle);
  35. }
  36. static inline dma_addr_t
  37. dma_map_single(struct device *dev, void *cpu_addr, size_t size,
  38. enum dma_data_direction direction)
  39. {
  40. BUG_ON(dev->bus != &pci_bus_type);
  41. return pci_map_single(to_pci_dev(dev), cpu_addr, size, (int)direction);
  42. }
  43. static inline void
  44. dma_unmap_single(struct device *dev, dma_addr_t dma_addr, size_t size,
  45. enum dma_data_direction direction)
  46. {
  47. BUG_ON(dev->bus != &pci_bus_type);
  48. pci_unmap_single(to_pci_dev(dev), dma_addr, size, (int)direction);
  49. }
  50. static inline dma_addr_t
  51. dma_map_page(struct device *dev, struct page *page,
  52. unsigned long offset, size_t size,
  53. enum dma_data_direction direction)
  54. {
  55. BUG_ON(dev->bus != &pci_bus_type);
  56. return pci_map_page(to_pci_dev(dev), page, offset, size, (int)direction);
  57. }
  58. static inline void
  59. dma_unmap_page(struct device *dev, dma_addr_t dma_address, size_t size,
  60. enum dma_data_direction direction)
  61. {
  62. BUG_ON(dev->bus != &pci_bus_type);
  63. pci_unmap_page(to_pci_dev(dev), dma_address, size, (int)direction);
  64. }
  65. static inline int
  66. dma_map_sg(struct device *dev, struct scatterlist *sg, int nents,
  67. enum dma_data_direction direction)
  68. {
  69. BUG_ON(dev->bus != &pci_bus_type);
  70. return pci_map_sg(to_pci_dev(dev), sg, nents, (int)direction);
  71. }
  72. static inline void
  73. dma_unmap_sg(struct device *dev, struct scatterlist *sg, int nhwentries,
  74. enum dma_data_direction direction)
  75. {
  76. BUG_ON(dev->bus != &pci_bus_type);
  77. pci_unmap_sg(to_pci_dev(dev), sg, nhwentries, (int)direction);
  78. }
  79. static inline void
  80. dma_sync_single_for_cpu(struct device *dev, dma_addr_t dma_handle, size_t size,
  81. enum dma_data_direction direction)
  82. {
  83. BUG_ON(dev->bus != &pci_bus_type);
  84. pci_dma_sync_single_for_cpu(to_pci_dev(dev), dma_handle,
  85. size, (int)direction);
  86. }
  87. static inline void
  88. dma_sync_single_for_device(struct device *dev, dma_addr_t dma_handle, size_t size,
  89. enum dma_data_direction direction)
  90. {
  91. BUG_ON(dev->bus != &pci_bus_type);
  92. pci_dma_sync_single_for_device(to_pci_dev(dev), dma_handle,
  93. size, (int)direction);
  94. }
  95. static inline void
  96. dma_sync_sg_for_cpu(struct device *dev, struct scatterlist *sg, int nelems,
  97. enum dma_data_direction direction)
  98. {
  99. BUG_ON(dev->bus != &pci_bus_type);
  100. pci_dma_sync_sg_for_cpu(to_pci_dev(dev), sg, nelems, (int)direction);
  101. }
  102. static inline void
  103. dma_sync_sg_for_device(struct device *dev, struct scatterlist *sg, int nelems,
  104. enum dma_data_direction direction)
  105. {
  106. BUG_ON(dev->bus != &pci_bus_type);
  107. pci_dma_sync_sg_for_device(to_pci_dev(dev), sg, nelems, (int)direction);
  108. }
  109. static inline int
  110. dma_mapping_error(dma_addr_t dma_addr)
  111. {
  112. return pci_dma_mapping_error(dma_addr);
  113. }
  114. #else
  115. struct device;
  116. static inline void *dma_alloc_coherent(struct device *dev, size_t size,
  117. dma_addr_t *dma_handle, gfp_t flag)
  118. {
  119. BUG();
  120. return NULL;
  121. }
  122. static inline void dma_free_coherent(struct device *dev, size_t size,
  123. void *vaddr, dma_addr_t dma_handle)
  124. {
  125. BUG();
  126. }
  127. #endif /* PCI */
  128. #endif /* _ASM_SPARC64_DMA_MAPPING_H */