dma-iommu.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /*
  2. * Copyright (C) 2014-2015 ARM Ltd.
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License version 2 as
  6. * published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #ifndef __DMA_IOMMU_H
  17. #define __DMA_IOMMU_H
  18. #ifdef __KERNEL__
  19. #include <linux/types.h>
  20. #include <asm/errno.h>
  21. #ifdef CONFIG_IOMMU_DMA
  22. #include <linux/dma-mapping.h>
  23. #include <linux/iommu.h>
  24. #include <linux/msi.h>
  25. int iommu_dma_init(void);
  26. /* Domain management interface for IOMMU drivers */
  27. int iommu_get_dma_cookie(struct iommu_domain *domain);
  28. int iommu_get_msi_cookie(struct iommu_domain *domain, dma_addr_t base);
  29. void iommu_put_dma_cookie(struct iommu_domain *domain);
  30. /* Setup call for arch DMA mapping code */
  31. int iommu_dma_init_domain(struct iommu_domain *domain, dma_addr_t base,
  32. u64 size, struct device *dev);
  33. /* General helpers for DMA-API <-> IOMMU-API interaction */
  34. int dma_info_to_prot(enum dma_data_direction dir, bool coherent,
  35. unsigned long attrs);
  36. /*
  37. * These implement the bulk of the relevant DMA mapping callbacks, but require
  38. * the arch code to take care of attributes and cache maintenance
  39. */
  40. struct page **iommu_dma_alloc(struct device *dev, size_t size, gfp_t gfp,
  41. unsigned long attrs, int prot, dma_addr_t *handle,
  42. void (*flush_page)(struct device *, const void *, phys_addr_t));
  43. void iommu_dma_free(struct device *dev, struct page **pages, size_t size,
  44. dma_addr_t *handle);
  45. int iommu_dma_mmap(struct page **pages, size_t size, struct vm_area_struct *vma);
  46. dma_addr_t iommu_dma_map_page(struct device *dev, struct page *page,
  47. unsigned long offset, size_t size, int prot);
  48. int iommu_dma_map_sg(struct device *dev, struct scatterlist *sg,
  49. int nents, int prot);
  50. /*
  51. * Arch code with no special attribute handling may use these
  52. * directly as DMA mapping callbacks for simplicity
  53. */
  54. void iommu_dma_unmap_page(struct device *dev, dma_addr_t handle, size_t size,
  55. enum dma_data_direction dir, unsigned long attrs);
  56. void iommu_dma_unmap_sg(struct device *dev, struct scatterlist *sg, int nents,
  57. enum dma_data_direction dir, unsigned long attrs);
  58. dma_addr_t iommu_dma_map_resource(struct device *dev, phys_addr_t phys,
  59. size_t size, enum dma_data_direction dir, unsigned long attrs);
  60. void iommu_dma_unmap_resource(struct device *dev, dma_addr_t handle,
  61. size_t size, enum dma_data_direction dir, unsigned long attrs);
  62. int iommu_dma_mapping_error(struct device *dev, dma_addr_t dma_addr);
  63. /* The DMA API isn't _quite_ the whole story, though... */
  64. void iommu_dma_map_msi_msg(int irq, struct msi_msg *msg);
  65. void iommu_dma_get_resv_regions(struct device *dev, struct list_head *list);
  66. #else
  67. struct iommu_domain;
  68. struct msi_msg;
  69. struct device;
  70. static inline int iommu_dma_init(void)
  71. {
  72. return 0;
  73. }
  74. static inline int iommu_get_dma_cookie(struct iommu_domain *domain)
  75. {
  76. return -ENODEV;
  77. }
  78. static inline int iommu_get_msi_cookie(struct iommu_domain *domain, dma_addr_t base)
  79. {
  80. return -ENODEV;
  81. }
  82. static inline void iommu_put_dma_cookie(struct iommu_domain *domain)
  83. {
  84. }
  85. static inline void iommu_dma_map_msi_msg(int irq, struct msi_msg *msg)
  86. {
  87. }
  88. static inline void iommu_dma_get_resv_regions(struct device *dev, struct list_head *list)
  89. {
  90. }
  91. #endif /* CONFIG_IOMMU_DMA */
  92. #endif /* __KERNEL__ */
  93. #endif /* __DMA_IOMMU_H */