]> git.karo-electronics.de Git - karo-tx-linux.git/blob - include/linux/msm_iommu_domains.h
arm64: configs: add Ka-Ro txsd_defconfig
[karo-tx-linux.git] / include / linux / msm_iommu_domains.h
1 /*
2  * Copyright (c) 2011-2014, The Linux Foundation. All rights reserved.
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 and
6  * only version 2 as 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
14 #ifndef _LINUX_MSM_IOMMU_DOMAINS_H
15 #define _LINUX_MSM_IOMMU_DOMAINS_H
16
17 #include <linux/errno.h>
18 #include <linux/mutex.h>
19 #include <linux/genalloc.h>
20 #include <linux/rbtree.h>
21 #include <linux/dma-buf.h>
22
23 #define MSM_IOMMU_DOMAIN_SECURE         0x1
24
25 enum {
26         VIDEO_DOMAIN,
27         CAMERA_DOMAIN,
28         DISPLAY_READ_DOMAIN,
29         DISPLAY_WRITE_DOMAIN,
30         ROTATOR_SRC_DOMAIN,
31         ROTATOR_DST_DOMAIN,
32         MAX_DOMAINS
33 };
34
35 enum {
36         VIDEO_FIRMWARE_POOL,
37         VIDEO_MAIN_POOL,
38         GEN_POOL,
39 };
40
41 struct mem_pool {
42         struct mutex pool_mutex;
43         struct gen_pool *gpool;
44         phys_addr_t paddr;
45         unsigned long size;
46         unsigned long free;
47         unsigned int id;
48 };
49
50 struct msm_iommu_domain {
51         /* iommu domain to map in */
52         struct iommu_domain *domain;
53         /* total number of allocations from this domain */
54         atomic_t allocation_cnt;
55         /* number of iova pools */
56         int npools;
57         /*
58          * array of gen_pools for allocating iovas.
59          * behavior is undefined if these overlap
60          */
61         struct mem_pool *iova_pools;
62 };
63
64 struct msm_iommu_domain_name {
65         char *name;
66         int domain;
67 };
68
69 struct iommu_domains_pdata {
70         struct msm_iommu_domain *domains;
71         int ndomains;
72         struct msm_iommu_domain_name *domain_names;
73         int nnames;
74         unsigned int domain_alloc_flags;
75 };
76
77 struct msm_iova_partition {
78         unsigned long start;
79         unsigned long size;
80 };
81
82 struct msm_iova_layout {
83         struct msm_iova_partition *partitions;
84         int npartitions;
85         const char *client_name;
86         unsigned int domain_flags;
87         unsigned int is_secure;
88 };
89
90 #if defined(CONFIG_QCOM_IOMMU)
91 extern void msm_iommu_set_client_name(struct iommu_domain *domain,
92                                       char const *name);
93 extern struct iommu_domain *msm_get_iommu_domain(int domain_num);
94 extern int msm_allocate_iova_address(unsigned int iommu_domain,
95                                      unsigned int partition_no,
96                                      unsigned long size,
97                                      unsigned long align,
98                                      unsigned long *iova);
99
100 extern void msm_free_iova_address(unsigned long iova,
101                                   unsigned int iommu_domain,
102                                   unsigned int partition_no,
103                                   unsigned long size);
104
105 extern int msm_use_iommu(void);
106
107 extern int msm_iommu_map_extra(struct iommu_domain *domain,
108                                unsigned long start_iova,
109                                phys_addr_t phys_addr,
110                                unsigned long size,
111                                unsigned long page_size,
112                                int cached);
113
114 extern void msm_iommu_unmap_extra(struct iommu_domain *domain,
115                                   unsigned long start_iova,
116                                   unsigned long size,
117                                   unsigned long page_size);
118
119 extern int msm_iommu_map_contig_buffer(phys_addr_t phys,
120                                        unsigned int domain_no,
121                                        unsigned int partition_no,
122                                        unsigned long size,
123                                        unsigned long align,
124                                        unsigned long cached,
125                                        dma_addr_t *iova_val);
126
127 extern void msm_iommu_unmap_contig_buffer(dma_addr_t iova,
128                                           unsigned int domain_no,
129                                           unsigned int partition_no,
130                                           unsigned long size);
131
132 extern int msm_register_domain(struct msm_iova_layout *layout);
133 extern int msm_unregister_domain(struct iommu_domain *domain);
134
135 int msm_map_dma_buf(struct dma_buf *dma_buf, struct sg_table *table,
136                     int domain_num, int partition_num, unsigned long align,
137                     unsigned long iova_length, unsigned long *iova,
138                     unsigned long *buffer_size,
139                     unsigned long flags, unsigned long iommu_flags);
140
141 void msm_unmap_dma_buf(struct sg_table *table, int domain_num,
142                        int partition_num);
143 #else
144 static inline void msm_iommu_set_client_name(struct iommu_domain *domain,
145                                              char const *name)
146 {
147 }
148
149 static inline struct iommu_domain *msm_get_iommu_domain(int subsys_id)
150 {
151         return NULL;
152 }
153
154 static inline int msm_allocate_iova_address(unsigned int iommu_domain,
155                                             unsigned int partition_no,
156                                             unsigned long size,
157                                             unsigned long align,
158                                             unsigned long *iova)
159 {
160         return -ENOMEM;
161 }
162
163 static inline void msm_free_iova_address(unsigned long iova,
164                                          unsigned int iommu_domain,
165                                          unsigned int partition_no,
166                                          unsigned long size) { }
167
168 static inline int msm_use_iommu(void)
169 {
170         return 0;
171 }
172
173 static inline int msm_iommu_map_extra(struct iommu_domain *domain,
174                                       unsigned long start_iova,
175                                       phys_addr_t phys_addr,
176                                       unsigned long size,
177                                       unsigned long page_size,
178                                       int cached)
179 {
180         return -ENODEV;
181 }
182
183 static inline void msm_iommu_unmap_extra(struct iommu_domain *domain,
184                                          unsigned long start_iova,
185                                          unsigned long size,
186                                          unsigned long page_size)
187 {
188 }
189
190 static inline int msm_iommu_map_contig_buffer(phys_addr_t phys,
191                                               unsigned int domain_no,
192                                               unsigned int partition_no,
193                                               unsigned long size,
194                                               unsigned long align,
195                                               unsigned long cached,
196                                               dma_addr_t *iova_val)
197 {
198         *iova_val = phys;
199         return 0;
200 }
201
202 static inline void msm_iommu_unmap_contig_buffer(dma_addr_t iova,
203                                                  unsigned int domain_no,
204                                                  unsigned int partition_no,
205                                                  unsigned long size)
206 {
207 }
208
209 static inline int msm_register_domain(struct msm_iova_layout *layout)
210 {
211         return -ENODEV;
212 }
213
214 static inline int msm_unregister_domain(struct iommu_domain *domain)
215 {
216         return -ENODEV;
217 }
218
219 static inline int msm_map_dma_buf(struct dma_buf *dma_buf,
220                                   struct sg_table *table,
221                                   int domain_num, int partition_num,
222                                   unsigned long align,
223                                   unsigned long iova_length,
224                                   unsigned long *iova,
225                                   unsigned long *buffer_size,
226                                   unsigned long flags,
227                                   unsigned long iommu_flags)
228 {
229         return -ENODEV;
230 }
231
232 static inline void msm_unmap_dma_buf(struct sg_table *table, int domain_num,
233                                      int partition_num)
234 {
235
236 }
237
238 #endif /* CONFIG_QCOM_IOMMU */
239 #endif /* _LINUX_MSM_IOMMU_DOMAINS_H */