dma-iommu.h 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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 <asm/errno.h>
  20. #ifdef CONFIG_IOMMU_DMA
  21. #include <linux/iommu.h>
  22. int iommu_dma_init(void);
  23. /* Domain management interface for IOMMU drivers */
  24. int iommu_get_dma_cookie(struct iommu_domain *domain);
  25. void iommu_put_dma_cookie(struct iommu_domain *domain);
  26. /* Setup call for arch DMA mapping code */
  27. int iommu_dma_init_domain(struct iommu_domain *domain, dma_addr_t base, u64 size);
  28. /* General helpers for DMA-API <-> IOMMU-API interaction */
  29. int dma_direction_to_prot(enum dma_data_direction dir, bool coherent);
  30. /*
  31. * These implement the bulk of the relevant DMA mapping callbacks, but require
  32. * the arch code to take care of attributes and cache maintenance
  33. */
  34. struct page **iommu_dma_alloc(struct device *dev, size_t size,
  35. gfp_t gfp, int prot, dma_addr_t *handle,
  36. void (*flush_page)(struct device *, const void *, phys_addr_t));
  37. void iommu_dma_free(struct device *dev, struct page **pages, size_t size,
  38. dma_addr_t *handle);
  39. int iommu_dma_mmap(struct page **pages, size_t size, struct vm_area_struct *vma);
  40. dma_addr_t iommu_dma_map_page(struct device *dev, struct page *page,
  41. unsigned long offset, size_t size, int prot);
  42. int iommu_dma_map_sg(struct device *dev, struct scatterlist *sg,
  43. int nents, int prot);
  44. /*
  45. * Arch code with no special attribute handling may use these
  46. * directly as DMA mapping callbacks for simplicity
  47. */
  48. void iommu_dma_unmap_page(struct device *dev, dma_addr_t handle, size_t size,
  49. enum dma_data_direction dir, struct dma_attrs *attrs);
  50. void iommu_dma_unmap_sg(struct device *dev, struct scatterlist *sg, int nents,
  51. enum dma_data_direction dir, struct dma_attrs *attrs);
  52. int iommu_dma_supported(struct device *dev, u64 mask);
  53. int iommu_dma_mapping_error(struct device *dev, dma_addr_t dma_addr);
  54. #else
  55. struct iommu_domain;
  56. static inline int iommu_dma_init(void)
  57. {
  58. return 0;
  59. }
  60. static inline int iommu_get_dma_cookie(struct iommu_domain *domain)
  61. {
  62. return -ENODEV;
  63. }
  64. static inline void iommu_put_dma_cookie(struct iommu_domain *domain)
  65. {
  66. }
  67. #endif /* CONFIG_IOMMU_DMA */
  68. #endif /* __KERNEL__ */
  69. #endif /* __DMA_IOMMU_H */