hc
2024-05-10 61598093bbdd283a7edc367d900f223070ead8d2
kernel/include/linux/dma-iommu.h
....@@ -1,33 +1,17 @@
1
+/* SPDX-License-Identifier: GPL-2.0-only */
12 /*
23 * 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/>.
154 */
165 #ifndef __DMA_IOMMU_H
176 #define __DMA_IOMMU_H
187
19
-#ifdef __KERNEL__
8
+#include <linux/errno.h>
209 #include <linux/types.h>
21
-#include <asm/errno.h>
2210
2311 #ifdef CONFIG_IOMMU_DMA
2412 #include <linux/dma-mapping.h>
2513 #include <linux/iommu.h>
2614 #include <linux/msi.h>
27
-
28
-struct iova_domain;
29
-
30
-int iommu_dma_init(void);
3115
3216 /* Domain management interface for IOMMU drivers */
3317 int iommu_get_dma_cookie(struct iommu_domain *domain);
....@@ -35,51 +19,22 @@
3519 void iommu_put_dma_cookie(struct iommu_domain *domain);
3620
3721 /* Setup call for arch DMA mapping code */
38
-int iommu_dma_init_domain(struct iommu_domain *domain, dma_addr_t base,
39
- u64 size, struct device *dev);
40
-
41
-/* General helpers for DMA-API <-> IOMMU-API interaction */
42
-int dma_info_to_prot(enum dma_data_direction dir, bool coherent,
43
- unsigned long attrs);
44
-
45
-/*
46
- * These implement the bulk of the relevant DMA mapping callbacks, but require
47
- * the arch code to take care of attributes and cache maintenance
48
- */
49
-struct page **iommu_dma_alloc(struct device *dev, size_t size, gfp_t gfp,
50
- unsigned long attrs, int prot, dma_addr_t *handle,
51
- void (*flush_page)(struct device *, const void *, phys_addr_t));
52
-void iommu_dma_free(struct device *dev, struct page **pages, size_t size,
53
- dma_addr_t *handle);
54
-
55
-int iommu_dma_mmap(struct page **pages, size_t size, struct vm_area_struct *vma);
56
-
57
-dma_addr_t iommu_dma_map_page(struct device *dev, struct page *page,
58
- unsigned long offset, size_t size, int prot);
59
-int iommu_dma_map_sg(struct device *dev, struct scatterlist *sg,
60
- int nents, int prot);
61
-size_t iommu_dma_prepare_map_sg(struct device *dev, struct iova_domain *iovad,
62
- struct scatterlist *sg, int nents);
63
-int iommu_dma_finalise_sg(struct device *dev, struct scatterlist *sg,
64
- int nents, dma_addr_t dma_addr);
65
-void iommu_dma_invalidate_sg(struct scatterlist *sg, int nents);
66
-
67
-/*
68
- * Arch code with no special attribute handling may use these
69
- * directly as DMA mapping callbacks for simplicity
70
- */
71
-void iommu_dma_unmap_page(struct device *dev, dma_addr_t handle, size_t size,
72
- enum dma_data_direction dir, unsigned long attrs);
73
-void iommu_dma_unmap_sg(struct device *dev, struct scatterlist *sg, int nents,
74
- enum dma_data_direction dir, unsigned long attrs);
75
-dma_addr_t iommu_dma_map_resource(struct device *dev, phys_addr_t phys,
76
- size_t size, enum dma_data_direction dir, unsigned long attrs);
77
-void iommu_dma_unmap_resource(struct device *dev, dma_addr_t handle,
78
- size_t size, enum dma_data_direction dir, unsigned long attrs);
79
-int iommu_dma_mapping_error(struct device *dev, dma_addr_t dma_addr);
22
+void iommu_setup_dma_ops(struct device *dev, u64 dma_base, u64 size);
8023
8124 /* The DMA API isn't _quite_ the whole story, though... */
82
-void iommu_dma_map_msi_msg(int irq, struct msi_msg *msg);
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,
36
+ struct msi_msg *msg);
37
+
8338 void iommu_dma_get_resv_regions(struct device *dev, struct list_head *list);
8439
8540 int iommu_dma_reserve_iova(struct device *dev, dma_addr_t base,
....@@ -87,15 +42,16 @@
8742
8843 int iommu_dma_enable_best_fit_algo(struct device *dev);
8944
90
-#else
45
+#else /* CONFIG_IOMMU_DMA */
9146
9247 struct iommu_domain;
48
+struct msi_desc;
9349 struct msi_msg;
9450 struct device;
9551
96
-static inline int iommu_dma_init(void)
52
+static inline void iommu_setup_dma_ops(struct device *dev, u64 dma_base,
53
+ u64 size)
9754 {
98
- return 0;
9955 }
10056
10157 static inline int iommu_get_dma_cookie(struct iommu_domain *domain)
....@@ -112,7 +68,14 @@
11268 {
11369 }
11470
115
-static inline void iommu_dma_map_msi_msg(int irq, struct msi_msg *msg)
71
+static inline int iommu_dma_prepare_msi(struct msi_desc *desc,
72
+ phys_addr_t msi_addr)
73
+{
74
+ return 0;
75
+}
76
+
77
+static inline void iommu_dma_compose_msi_msg(struct msi_desc *desc,
78
+ struct msi_msg *msg)
11679 {
11780 }
11881
....@@ -132,5 +95,4 @@
13295 }
13396
13497 #endif /* CONFIG_IOMMU_DMA */
135
-#endif /* __KERNEL__ */
13698 #endif /* __DMA_IOMMU_H */