dma-mapping.h 4.4 KB

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