]>
Commit | Line | Data |
---|---|---|
0db2e5d1 RM |
1 | /* |
2 | * 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 | */ | |
16 | #ifndef __DMA_IOMMU_H | |
17 | #define __DMA_IOMMU_H | |
18 | ||
19 | #ifdef __KERNEL__ | |
20 | #include <asm/errno.h> | |
21 | ||
22 | #ifdef CONFIG_IOMMU_DMA | |
23 | #include <linux/iommu.h> | |
44bb7e24 | 24 | #include <linux/msi.h> |
0db2e5d1 RM |
25 | |
26 | int iommu_dma_init(void); | |
27 | ||
28 | /* Domain management interface for IOMMU drivers */ | |
29 | int iommu_get_dma_cookie(struct iommu_domain *domain); | |
fdbe574e | 30 | int iommu_get_msi_cookie(struct iommu_domain *domain, dma_addr_t base); |
0db2e5d1 RM |
31 | void iommu_put_dma_cookie(struct iommu_domain *domain); |
32 | ||
33 | /* Setup call for arch DMA mapping code */ | |
fade1ec0 RM |
34 | int iommu_dma_init_domain(struct iommu_domain *domain, dma_addr_t base, |
35 | u64 size, struct device *dev); | |
0db2e5d1 RM |
36 | |
37 | /* General helpers for DMA-API <-> IOMMU-API interaction */ | |
737c85ca MH |
38 | int dma_info_to_prot(enum dma_data_direction dir, bool coherent, |
39 | unsigned long attrs); | |
0db2e5d1 RM |
40 | |
41 | /* | |
42 | * These implement the bulk of the relevant DMA mapping callbacks, but require | |
43 | * the arch code to take care of attributes and cache maintenance | |
44 | */ | |
3b6b7e19 | 45 | struct page **iommu_dma_alloc(struct device *dev, size_t size, gfp_t gfp, |
00085f1e | 46 | unsigned long attrs, int prot, dma_addr_t *handle, |
0db2e5d1 RM |
47 | void (*flush_page)(struct device *, const void *, phys_addr_t)); |
48 | void iommu_dma_free(struct device *dev, struct page **pages, size_t size, | |
49 | dma_addr_t *handle); | |
50 | ||
51 | int iommu_dma_mmap(struct page **pages, size_t size, struct vm_area_struct *vma); | |
52 | ||
53 | dma_addr_t iommu_dma_map_page(struct device *dev, struct page *page, | |
54 | unsigned long offset, size_t size, int prot); | |
55 | int iommu_dma_map_sg(struct device *dev, struct scatterlist *sg, | |
56 | int nents, int prot); | |
57 | ||
58 | /* | |
59 | * Arch code with no special attribute handling may use these | |
60 | * directly as DMA mapping callbacks for simplicity | |
61 | */ | |
62 | void iommu_dma_unmap_page(struct device *dev, dma_addr_t handle, size_t size, | |
00085f1e | 63 | enum dma_data_direction dir, unsigned long attrs); |
0db2e5d1 | 64 | void iommu_dma_unmap_sg(struct device *dev, struct scatterlist *sg, int nents, |
00085f1e | 65 | enum dma_data_direction dir, unsigned long attrs); |
51f8cc9e RM |
66 | dma_addr_t iommu_dma_map_resource(struct device *dev, phys_addr_t phys, |
67 | size_t size, enum dma_data_direction dir, unsigned long attrs); | |
68 | void iommu_dma_unmap_resource(struct device *dev, dma_addr_t handle, | |
69 | size_t size, enum dma_data_direction dir, unsigned long attrs); | |
0db2e5d1 RM |
70 | int iommu_dma_mapping_error(struct device *dev, dma_addr_t dma_addr); |
71 | ||
44bb7e24 RM |
72 | /* The DMA API isn't _quite_ the whole story, though... */ |
73 | void iommu_dma_map_msi_msg(int irq, struct msi_msg *msg); | |
74 | ||
0db2e5d1 RM |
75 | #else |
76 | ||
77 | struct iommu_domain; | |
44bb7e24 | 78 | struct msi_msg; |
0db2e5d1 RM |
79 | |
80 | static inline int iommu_dma_init(void) | |
81 | { | |
82 | return 0; | |
83 | } | |
84 | ||
85 | static inline int iommu_get_dma_cookie(struct iommu_domain *domain) | |
86 | { | |
87 | return -ENODEV; | |
88 | } | |
89 | ||
fdbe574e RM |
90 | static inline int iommu_get_msi_cookie(struct iommu_domain *domain, dma_addr_t base) |
91 | { | |
92 | return -ENODEV; | |
93 | } | |
94 | ||
0db2e5d1 RM |
95 | static inline void iommu_put_dma_cookie(struct iommu_domain *domain) |
96 | { | |
97 | } | |
98 | ||
44bb7e24 RM |
99 | static inline void iommu_dma_map_msi_msg(int irq, struct msi_msg *msg) |
100 | { | |
101 | } | |
102 | ||
0db2e5d1 RM |
103 | #endif /* CONFIG_IOMMU_DMA */ |
104 | #endif /* __KERNEL__ */ | |
105 | #endif /* __DMA_IOMMU_H */ |