dma-iommu.h 3.0 KB

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