.. | .. |
---|
| 1 | +/* SPDX-License-Identifier: GPL-2.0-only */ |
---|
1 | 2 | /* |
---|
2 | 3 | * 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 | 4 | */ |
---|
16 | 5 | #ifndef __DMA_IOMMU_H |
---|
17 | 6 | #define __DMA_IOMMU_H |
---|
18 | 7 | |
---|
19 | | -#ifdef __KERNEL__ |
---|
| 8 | +#include <linux/errno.h> |
---|
20 | 9 | #include <linux/types.h> |
---|
21 | | -#include <asm/errno.h> |
---|
22 | 10 | |
---|
23 | 11 | #ifdef CONFIG_IOMMU_DMA |
---|
24 | 12 | #include <linux/dma-mapping.h> |
---|
25 | 13 | #include <linux/iommu.h> |
---|
26 | 14 | #include <linux/msi.h> |
---|
27 | | - |
---|
28 | | -struct iova_domain; |
---|
29 | | - |
---|
30 | | -int iommu_dma_init(void); |
---|
31 | 15 | |
---|
32 | 16 | /* Domain management interface for IOMMU drivers */ |
---|
33 | 17 | int iommu_get_dma_cookie(struct iommu_domain *domain); |
---|
.. | .. |
---|
35 | 19 | void iommu_put_dma_cookie(struct iommu_domain *domain); |
---|
36 | 20 | |
---|
37 | 21 | /* 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); |
---|
80 | 23 | |
---|
81 | 24 | /* 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 | + |
---|
83 | 38 | void iommu_dma_get_resv_regions(struct device *dev, struct list_head *list); |
---|
84 | 39 | |
---|
85 | 40 | int iommu_dma_reserve_iova(struct device *dev, dma_addr_t base, |
---|
.. | .. |
---|
87 | 42 | |
---|
88 | 43 | int iommu_dma_enable_best_fit_algo(struct device *dev); |
---|
89 | 44 | |
---|
90 | | -#else |
---|
| 45 | +#else /* CONFIG_IOMMU_DMA */ |
---|
91 | 46 | |
---|
92 | 47 | struct iommu_domain; |
---|
| 48 | +struct msi_desc; |
---|
93 | 49 | struct msi_msg; |
---|
94 | 50 | struct device; |
---|
95 | 51 | |
---|
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) |
---|
97 | 54 | { |
---|
98 | | - return 0; |
---|
99 | 55 | } |
---|
100 | 56 | |
---|
101 | 57 | static inline int iommu_get_dma_cookie(struct iommu_domain *domain) |
---|
.. | .. |
---|
112 | 68 | { |
---|
113 | 69 | } |
---|
114 | 70 | |
---|
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) |
---|
116 | 79 | { |
---|
117 | 80 | } |
---|
118 | 81 | |
---|
.. | .. |
---|
132 | 95 | } |
---|
133 | 96 | |
---|
134 | 97 | #endif /* CONFIG_IOMMU_DMA */ |
---|
135 | | -#endif /* __KERNEL__ */ |
---|
136 | 98 | #endif /* __DMA_IOMMU_H */ |
---|