dma-mapping.h 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. #ifndef _ASM_DMA_MAPPING_H_
  2. #define _ASM_DMA_MAPPING_H_
  3. /*
  4. * IOMMU interface. See Documentation/DMA-mapping.txt and DMA-API.txt for
  5. * documentation.
  6. */
  7. #include <linux/scatterlist.h>
  8. #include <asm/io.h>
  9. #include <asm/swiotlb.h>
  10. struct dma_mapping_ops {
  11. int (*mapping_error)(dma_addr_t dma_addr);
  12. void* (*alloc_coherent)(struct device *dev, size_t size,
  13. dma_addr_t *dma_handle, gfp_t gfp);
  14. void (*free_coherent)(struct device *dev, size_t size,
  15. void *vaddr, dma_addr_t dma_handle);
  16. dma_addr_t (*map_single)(struct device *hwdev, void *ptr,
  17. size_t size, int direction);
  18. /* like map_single, but doesn't check the device mask */
  19. dma_addr_t (*map_simple)(struct device *hwdev, char *ptr,
  20. size_t size, int direction);
  21. void (*unmap_single)(struct device *dev, dma_addr_t addr,
  22. size_t size, int direction);
  23. void (*sync_single_for_cpu)(struct device *hwdev,
  24. dma_addr_t dma_handle, size_t size,
  25. int direction);
  26. void (*sync_single_for_device)(struct device *hwdev,
  27. dma_addr_t dma_handle, size_t size,
  28. int direction);
  29. void (*sync_single_range_for_cpu)(struct device *hwdev,
  30. dma_addr_t dma_handle, unsigned long offset,
  31. size_t size, int direction);
  32. void (*sync_single_range_for_device)(struct device *hwdev,
  33. dma_addr_t dma_handle, unsigned long offset,
  34. size_t size, int direction);
  35. void (*sync_sg_for_cpu)(struct device *hwdev,
  36. struct scatterlist *sg, int nelems,
  37. int direction);
  38. void (*sync_sg_for_device)(struct device *hwdev,
  39. struct scatterlist *sg, int nelems,
  40. int direction);
  41. int (*map_sg)(struct device *hwdev, struct scatterlist *sg,
  42. int nents, int direction);
  43. void (*unmap_sg)(struct device *hwdev,
  44. struct scatterlist *sg, int nents,
  45. int direction);
  46. int (*dma_supported)(struct device *hwdev, u64 mask);
  47. int is_phys;
  48. };
  49. extern const struct dma_mapping_ops *dma_ops;
  50. #ifdef CONFIG_X86_32
  51. # include "dma-mapping_32.h"
  52. #else
  53. # include "dma-mapping_64.h"
  54. #endif
  55. static inline dma_addr_t
  56. dma_map_single(struct device *hwdev, void *ptr, size_t size,
  57. int direction)
  58. {
  59. BUG_ON(!valid_dma_direction(direction));
  60. return dma_ops->map_single(hwdev, ptr, size, direction);
  61. }
  62. static inline void
  63. dma_unmap_single(struct device *dev, dma_addr_t addr, size_t size,
  64. int direction)
  65. {
  66. BUG_ON(!valid_dma_direction(direction));
  67. if (dma_ops->unmap_single)
  68. dma_ops->unmap_single(dev, addr, size, direction);
  69. }
  70. static inline int
  71. dma_map_sg(struct device *hwdev, struct scatterlist *sg,
  72. int nents, int direction)
  73. {
  74. BUG_ON(!valid_dma_direction(direction));
  75. return dma_ops->map_sg(hwdev, sg, nents, direction);
  76. }
  77. static inline void
  78. dma_unmap_sg(struct device *hwdev, struct scatterlist *sg, int nents,
  79. int direction)
  80. {
  81. BUG_ON(!valid_dma_direction(direction));
  82. if (dma_ops->unmap_sg)
  83. dma_ops->unmap_sg(hwdev, sg, nents, direction);
  84. }
  85. #endif