dma-mapping.h 5.0 KB

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