Merge branch 'acpica'
[linux-2.6-microblaze.git] / include / linux / dma-iommu.h
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 #ifdef __KERNEL__
9 #include <linux/types.h>
10 #include <asm/errno.h>
11
12 #ifdef CONFIG_IOMMU_DMA
13 #include <linux/dma-mapping.h>
14 #include <linux/iommu.h>
15 #include <linux/msi.h>
16
17 int iommu_dma_init(void);
18
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);
23
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);
27
28 /* General helpers for DMA-API <-> IOMMU-API interaction */
29 int dma_info_to_prot(enum dma_data_direction dir, bool coherent,
30                      unsigned long attrs);
31
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
42 int iommu_dma_mmap(struct page **pages, size_t size, struct vm_area_struct *vma);
43
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,
47                 int nents, int prot);
48
49 /*
50  * Arch code with no special attribute handling may use these
51  * directly as DMA mapping callbacks for simplicity
52  */
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);
61
62 /* The DMA API isn't _quite_ the whole story, though... */
63 /*
64  * iommu_dma_prepare_msi() - Map the MSI page in the IOMMU device
65  *
66  * The MSI page will be stored in @desc.
67  *
68  * Return: 0 on success otherwise an error describing the failure.
69  */
70 int iommu_dma_prepare_msi(struct msi_desc *desc, phys_addr_t msi_addr);
71
72 /* Update the MSI message if required. */
73 void iommu_dma_compose_msi_msg(struct msi_desc *desc,
74                                struct msi_msg *msg);
75
76 void iommu_dma_get_resv_regions(struct device *dev, struct list_head *list);
77
78 #else
79
80 struct iommu_domain;
81 struct msi_desc;
82 struct msi_msg;
83 struct device;
84
85 static inline int iommu_dma_init(void)
86 {
87         return 0;
88 }
89
90 static inline int iommu_get_dma_cookie(struct iommu_domain *domain)
91 {
92         return -ENODEV;
93 }
94
95 static inline int iommu_get_msi_cookie(struct iommu_domain *domain, dma_addr_t base)
96 {
97         return -ENODEV;
98 }
99
100 static inline void iommu_put_dma_cookie(struct iommu_domain *domain)
101 {
102 }
103
104 static inline int iommu_dma_prepare_msi(struct msi_desc *desc,
105                                         phys_addr_t msi_addr)
106 {
107         return 0;
108 }
109
110 static inline void iommu_dma_compose_msi_msg(struct msi_desc *desc,
111                                              struct msi_msg *msg)
112 {
113 }
114
115 static inline void iommu_dma_get_resv_regions(struct device *dev, struct list_head *list)
116 {
117 }
118
119 #endif  /* CONFIG_IOMMU_DMA */
120 #endif  /* __KERNEL__ */
121 #endif  /* __DMA_IOMMU_H */