1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * Copyright (C) 2014-2015 ARM Ltd.
9 #include <linux/types.h>
10 #include <asm/errno.h>
12 #ifdef CONFIG_IOMMU_DMA
13 #include <linux/dma-mapping.h>
14 #include <linux/iommu.h>
15 #include <linux/msi.h>
17 int iommu_dma_init(void);
19 /* Domain management interface for IOMMU drivers */
20 int iommu_get_dma_cookie(struct iommu_domain *domain);
21 int iommu_get_msi_cookie(struct iommu_domain *domain, dma_addr_t base);
22 void iommu_put_dma_cookie(struct iommu_domain *domain);
24 /* Setup call for arch DMA mapping code */
25 int iommu_dma_init_domain(struct iommu_domain *domain, dma_addr_t base,
26 u64 size, struct device *dev);
28 /* General helpers for DMA-API <-> IOMMU-API interaction */
29 int dma_info_to_prot(enum dma_data_direction dir, bool coherent,
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
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,
42 int iommu_dma_mmap(struct page **pages, size_t size, struct vm_area_struct *vma);
44 dma_addr_t iommu_dma_map_page(struct device *dev, struct page *page,
45 unsigned long offset, size_t size, int prot);
46 int iommu_dma_map_sg(struct device *dev, struct scatterlist *sg,
50 * Arch code with no special attribute handling may use these
51 * directly as DMA mapping callbacks for simplicity
53 void iommu_dma_unmap_page(struct device *dev, dma_addr_t handle, size_t size,
54 enum dma_data_direction dir, unsigned long attrs);
55 void iommu_dma_unmap_sg(struct device *dev, struct scatterlist *sg, int nents,
56 enum dma_data_direction dir, unsigned long attrs);
57 dma_addr_t iommu_dma_map_resource(struct device *dev, phys_addr_t phys,
58 size_t size, enum dma_data_direction dir, unsigned long attrs);
59 void iommu_dma_unmap_resource(struct device *dev, dma_addr_t handle,
60 size_t size, enum dma_data_direction dir, unsigned long attrs);
62 /* The DMA API isn't _quite_ the whole story, though... */
64 * iommu_dma_prepare_msi() - Map the MSI page in the IOMMU device
66 * The MSI page will be stored in @desc.
68 * Return: 0 on success otherwise an error describing the failure.
70 int iommu_dma_prepare_msi(struct msi_desc *desc, phys_addr_t msi_addr);
72 /* Update the MSI message if required. */
73 void iommu_dma_compose_msi_msg(struct msi_desc *desc,
76 void iommu_dma_get_resv_regions(struct device *dev, struct list_head *list);
85 static inline int iommu_dma_init(void)
90 static inline int iommu_get_dma_cookie(struct iommu_domain *domain)
95 static inline int iommu_get_msi_cookie(struct iommu_domain *domain, dma_addr_t base)
100 static inline void iommu_put_dma_cookie(struct iommu_domain *domain)
104 static inline int iommu_dma_prepare_msi(struct msi_desc *desc,
105 phys_addr_t msi_addr)
110 static inline void iommu_dma_compose_msi_msg(struct msi_desc *desc,
115 static inline void iommu_dma_get_resv_regions(struct device *dev, struct list_head *list)
119 #endif /* CONFIG_IOMMU_DMA */
120 #endif /* __KERNEL__ */
121 #endif /* __DMA_IOMMU_H */