1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3 * Copyright (C) 2014-2015 ARM Ltd.
4 */
5 #ifndef __DMA_IOMMU_H
6 #define __DMA_IOMMU_H
7
8 #include <linux/errno.h>
9 #include <linux/types.h>
10
11 #ifdef CONFIG_IOMMU_DMA
12 #include <linux/dma-mapping.h>
13 #include <linux/iommu.h>
14 #include <linux/msi.h>
15
16 /* Domain management interface for IOMMU drivers */
17 int iommu_get_dma_cookie(struct iommu_domain *domain);
18 int iommu_get_msi_cookie(struct iommu_domain *domain, dma_addr_t base);
19 void iommu_put_dma_cookie(struct iommu_domain *domain);
20
21 /* Setup call for arch DMA mapping code */
22 void iommu_setup_dma_ops(struct device *dev, u64 dma_base, u64 size);
23
24 /* The DMA API isn't _quite_ the whole story, though... */
25 /*
26 * iommu_dma_prepare_msi() - Map the MSI page in the IOMMU device
27 *
28 * The MSI page will be stored in @desc.
29 *
30 * Return: 0 on success otherwise an error describing the failure.
31 */
32 int iommu_dma_prepare_msi(struct msi_desc *desc, phys_addr_t msi_addr);
33
34 /* Update the MSI message if required. */
35 void iommu_dma_compose_msi_msg(struct msi_desc *desc, struct msi_msg *msg);
36
37 void iommu_dma_get_resv_regions(struct device *dev, struct list_head *list);
38
39 int iommu_dma_reserve_iova(struct device *dev, dma_addr_t base, u64 size);
40
41 int iommu_dma_enable_best_fit_algo(struct device *dev);
42
43 #else /* CONFIG_IOMMU_DMA */
44
45 struct iommu_domain;
46 struct msi_desc;
47 struct msi_msg;
48 struct device;
49
iommu_setup_dma_ops(struct device * dev,u64 dma_base,u64 size)50 static inline void iommu_setup_dma_ops(struct device *dev, u64 dma_base, u64 size)
51 {
52 }
53
iommu_get_dma_cookie(struct iommu_domain * domain)54 static inline int iommu_get_dma_cookie(struct iommu_domain *domain)
55 {
56 return -ENODEV;
57 }
58
iommu_get_msi_cookie(struct iommu_domain * domain,dma_addr_t base)59 static inline int iommu_get_msi_cookie(struct iommu_domain *domain, dma_addr_t base)
60 {
61 return -ENODEV;
62 }
63
iommu_put_dma_cookie(struct iommu_domain * domain)64 static inline void iommu_put_dma_cookie(struct iommu_domain *domain)
65 {
66 }
67
iommu_dma_prepare_msi(struct msi_desc * desc,phys_addr_t msi_addr)68 static inline int iommu_dma_prepare_msi(struct msi_desc *desc, phys_addr_t msi_addr)
69 {
70 return 0;
71 }
72
iommu_dma_compose_msi_msg(struct msi_desc * desc,struct msi_msg * msg)73 static inline void iommu_dma_compose_msi_msg(struct msi_desc *desc, struct msi_msg *msg)
74 {
75 }
76
iommu_dma_get_resv_regions(struct device * dev,struct list_head * list)77 static inline void iommu_dma_get_resv_regions(struct device *dev, struct list_head *list)
78 {
79 }
80
iommu_dma_reserve_iova(struct device * dev,dma_addr_t base,u64 size)81 static inline int iommu_dma_reserve_iova(struct device *dev, dma_addr_t base, u64 size)
82 {
83 return -ENODEV;
84 }
85
iommu_dma_enable_best_fit_algo(struct device * dev)86 static inline int iommu_dma_enable_best_fit_algo(struct device *dev)
87 {
88 return -ENODEV;
89 }
90
91 #endif /* CONFIG_IOMMU_DMA */
92 #endif /* __DMA_IOMMU_H */
93