dma-mapping.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. #ifndef _ASM_IA64_DMA_MAPPING_H
  2. #define _ASM_IA64_DMA_MAPPING_H
  3. /*
  4. * Copyright (C) 2003-2004 Hewlett-Packard Co
  5. * David Mosberger-Tang <davidm@hpl.hp.com>
  6. */
  7. #include <asm/machvec.h>
  8. #include <linux/scatterlist.h>
  9. #include <asm/swiotlb.h>
  10. #define ARCH_HAS_DMA_GET_REQUIRED_MASK
  11. struct dma_mapping_ops {
  12. int (*mapping_error)(struct device *dev,
  13. dma_addr_t dma_addr);
  14. void* (*alloc_coherent)(struct device *dev, size_t size,
  15. dma_addr_t *dma_handle, gfp_t gfp);
  16. void (*free_coherent)(struct device *dev, size_t size,
  17. void *vaddr, dma_addr_t dma_handle);
  18. dma_addr_t (*map_single)(struct device *hwdev, unsigned long ptr,
  19. size_t size, int direction);
  20. void (*unmap_single)(struct device *dev, dma_addr_t addr,
  21. size_t size, int direction);
  22. void (*sync_single_for_cpu)(struct device *hwdev,
  23. dma_addr_t dma_handle, size_t size,
  24. int direction);
  25. void (*sync_single_for_device)(struct device *hwdev,
  26. dma_addr_t dma_handle, size_t size,
  27. int direction);
  28. void (*sync_single_range_for_cpu)(struct device *hwdev,
  29. dma_addr_t dma_handle, unsigned long offset,
  30. size_t size, int direction);
  31. void (*sync_single_range_for_device)(struct device *hwdev,
  32. dma_addr_t dma_handle, unsigned long offset,
  33. size_t size, int direction);
  34. void (*sync_sg_for_cpu)(struct device *hwdev,
  35. struct scatterlist *sg, int nelems,
  36. int direction);
  37. void (*sync_sg_for_device)(struct device *hwdev,
  38. struct scatterlist *sg, int nelems,
  39. int direction);
  40. int (*map_sg)(struct device *hwdev, struct scatterlist *sg,
  41. int nents, int direction);
  42. void (*unmap_sg)(struct device *hwdev,
  43. struct scatterlist *sg, int nents,
  44. int direction);
  45. int (*dma_supported_op)(struct device *hwdev, u64 mask);
  46. int is_phys;
  47. };
  48. extern struct dma_mapping_ops *dma_ops;
  49. extern struct ia64_machine_vector ia64_mv;
  50. extern void set_iommu_machvec(void);
  51. #define dma_alloc_coherent(dev, size, handle, gfp) \
  52. platform_dma_alloc_coherent(dev, size, handle, (gfp) | GFP_DMA)
  53. /* coherent mem. is cheap */
  54. static inline void *
  55. dma_alloc_noncoherent(struct device *dev, size_t size, dma_addr_t *dma_handle,
  56. gfp_t flag)
  57. {
  58. return dma_alloc_coherent(dev, size, dma_handle, flag);
  59. }
  60. #define dma_free_coherent platform_dma_free_coherent
  61. static inline void
  62. dma_free_noncoherent(struct device *dev, size_t size, void *cpu_addr,
  63. dma_addr_t dma_handle)
  64. {
  65. dma_free_coherent(dev, size, cpu_addr, dma_handle);
  66. }
  67. #define dma_map_single_attrs platform_dma_map_single_attrs
  68. static inline dma_addr_t dma_map_single(struct device *dev, void *cpu_addr,
  69. size_t size, int dir)
  70. {
  71. return dma_map_single_attrs(dev, cpu_addr, size, dir, NULL);
  72. }
  73. #define dma_map_sg_attrs platform_dma_map_sg_attrs
  74. static inline int dma_map_sg(struct device *dev, struct scatterlist *sgl,
  75. int nents, int dir)
  76. {
  77. return dma_map_sg_attrs(dev, sgl, nents, dir, NULL);
  78. }
  79. #define dma_unmap_single_attrs platform_dma_unmap_single_attrs
  80. static inline void dma_unmap_single(struct device *dev, dma_addr_t cpu_addr,
  81. size_t size, int dir)
  82. {
  83. return dma_unmap_single_attrs(dev, cpu_addr, size, dir, NULL);
  84. }
  85. #define dma_unmap_sg_attrs platform_dma_unmap_sg_attrs
  86. static inline void dma_unmap_sg(struct device *dev, struct scatterlist *sgl,
  87. int nents, int dir)
  88. {
  89. return dma_unmap_sg_attrs(dev, sgl, nents, dir, NULL);
  90. }
  91. #define dma_sync_single_for_cpu platform_dma_sync_single_for_cpu
  92. #define dma_sync_sg_for_cpu platform_dma_sync_sg_for_cpu
  93. #define dma_sync_single_for_device platform_dma_sync_single_for_device
  94. #define dma_sync_sg_for_device platform_dma_sync_sg_for_device
  95. #define dma_mapping_error platform_dma_mapping_error
  96. #define dma_map_page(dev, pg, off, size, dir) \
  97. dma_map_single(dev, page_address(pg) + (off), (size), (dir))
  98. #define dma_unmap_page(dev, dma_addr, size, dir) \
  99. dma_unmap_single(dev, dma_addr, size, dir)
  100. /*
  101. * Rest of this file is part of the "Advanced DMA API". Use at your own risk.
  102. * See Documentation/DMA-API.txt for details.
  103. */
  104. #define dma_sync_single_range_for_cpu(dev, dma_handle, offset, size, dir) \
  105. dma_sync_single_for_cpu(dev, dma_handle, size, dir)
  106. #define dma_sync_single_range_for_device(dev, dma_handle, offset, size, dir) \
  107. dma_sync_single_for_device(dev, dma_handle, size, dir)
  108. #define dma_supported platform_dma_supported
  109. static inline int
  110. dma_set_mask (struct device *dev, u64 mask)
  111. {
  112. if (!dev->dma_mask || !dma_supported(dev, mask))
  113. return -EIO;
  114. *dev->dma_mask = mask;
  115. return 0;
  116. }
  117. extern int dma_get_cache_alignment(void);
  118. static inline void
  119. dma_cache_sync (struct device *dev, void *vaddr, size_t size,
  120. enum dma_data_direction dir)
  121. {
  122. /*
  123. * IA-64 is cache-coherent, so this is mostly a no-op. However, we do need to
  124. * ensure that dma_cache_sync() enforces order, hence the mb().
  125. */
  126. mb();
  127. }
  128. #define dma_is_consistent(d, h) (1) /* all we do is coherent memory... */
  129. static inline struct dma_mapping_ops *get_dma_ops(struct device *dev)
  130. {
  131. return dma_ops;
  132. }
  133. #endif /* _ASM_IA64_DMA_MAPPING_H */