OSDN Git Service

mm/vmalloc.c: fix align value calculation error
[sagit-ice-cold/kernel_xiaomi_msm8998.git] / include / linux / msm_iommu_domains.h
1 /* Copyright (c) 2011-2015, The Linux Foundation. All rights reserved.
2  *
3  * This program is free software; you can redistribute it and/or modify
4  * it under the terms of the GNU General Public License version 2 and
5  * only version 2 as published by the Free Software Foundation.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10  * GNU General Public License for more details.
11  */
12
13 #ifndef _LINUX_MSM_IOMMU_DOMAINS_H
14 #define _LINUX_MSM_IOMMU_DOMAINS_H
15
16 #include <linux/errno.h>
17 #include <linux/mutex.h>
18 #include <linux/rbtree.h>
19 #include <linux/msm_ion.h>
20
21 #define MSM_IOMMU_DOMAIN_SECURE 0x1
22
23 struct mem_pool {
24         struct mutex pool_mutex;
25         unsigned long *bitmap;
26         unsigned long nr_pages;
27         phys_addr_t paddr;
28         unsigned long size;
29         unsigned long free;
30         unsigned int id;
31 };
32
33 enum {
34         VIDEO_DOMAIN,
35         CAMERA_DOMAIN,
36         DISPLAY_READ_DOMAIN,
37         DISPLAY_WRITE_DOMAIN,
38         ROTATOR_SRC_DOMAIN,
39         ROTATOR_DST_DOMAIN,
40         MAX_DOMAINS
41 };
42
43 enum {
44         VIDEO_FIRMWARE_POOL,
45         VIDEO_MAIN_POOL,
46         GEN_POOL,
47 };
48
49 struct msm_iommu_domain_name {
50         char *name;
51         int domain;
52 };
53
54 struct msm_iommu_domain {
55         /* iommu domain to map in */
56         struct iommu_domain *domain;
57         /* total number of allocations from this domain */
58         atomic_t allocation_cnt;
59         /* number of iova pools */
60         int npools;
61         /*
62          * array of gen_pools for allocating iovas.
63          * behavior is undefined if these overlap
64          */
65         struct mem_pool *iova_pools;
66 };
67
68 struct iommu_domains_pdata {
69         struct msm_iommu_domain *domains;
70         int ndomains;
71         struct msm_iommu_domain_name *domain_names;
72         int nnames;
73         unsigned int domain_alloc_flags;
74 };
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_MSM_IOMMU)
91 /**
92  * ion_map_iommu - map the given handle into an iommu
93  *
94  * @client - client who allocated the handle
95  * @handle - handle to map
96  * @domain_num - domain number to map to
97  * @partition_num - partition number to allocate iova from
98  * @align - alignment for the iova
99  * @iova_length - length of iova to map. If the iova length is
100  *              greater than the handle length, the remaining
101  *              address space will be mapped to a dummy buffer.
102  * @iova - pointer to store the iova address
103  * @buffer_size - pointer to store the size of the buffer
104  * @flags - flags for options to map
105  * @iommu_flags - flags specific to the iommu.
106  *
107  * Maps the handle into the iova space specified via domain number. Iova
108  * will be allocated from the partition specified via partition_num.
109  * Returns 0 on success, negative value on error.
110  */
111 int ion_map_iommu(struct ion_client *client, struct ion_handle *handle,
112                         int domain_num, int partition_num, unsigned long align,
113                         unsigned long iova_length, ion_phys_addr_t *iova,
114                         unsigned long *buffer_size,
115                         unsigned long flags, unsigned long iommu_flags);
116
117 /**
118  * ion_unmap_iommu - unmap the handle from an iommu
119  *
120  * @client - client who allocated the handle
121  * @handle - handle to unmap
122  * @domain_num - domain to unmap from
123  * @partition_num - partition to unmap from
124  *
125  * Decrement the reference count on the iommu mapping. If the count is
126  * 0, the mapping will be removed from the iommu.
127  */
128 void ion_unmap_iommu(struct ion_client *client, struct ion_handle *handle,
129                         int domain_num, int partition_num);
130
131 extern void msm_iommu_set_client_name(struct iommu_domain *domain,
132                                       char const *name);
133 extern struct iommu_domain *msm_get_iommu_domain(int domain_num);
134 extern int msm_find_domain_no(const struct iommu_domain *domain);
135 extern struct iommu_domain *msm_iommu_domain_find(const char *name);
136 extern int msm_iommu_domain_no_find(const char *name);
137
138
139 extern int msm_allocate_iova_address(unsigned int iommu_domain,
140                                         unsigned int partition_no,
141                                         unsigned long size,
142                                         unsigned long align,
143                                         unsigned long *iova);
144
145 extern void msm_free_iova_address(unsigned long iova,
146                         unsigned int iommu_domain,
147                         unsigned int partition_no,
148                         unsigned long size);
149
150 extern int msm_use_iommu(void);
151
152 extern int msm_iommu_map_extra(struct iommu_domain *domain,
153                                                 unsigned long start_iova,
154                                                 phys_addr_t phys_addr,
155                                                 unsigned long size,
156                                                 unsigned long page_size,
157                                                 int cached);
158
159 extern void msm_iommu_unmap_extra(struct iommu_domain *domain,
160                                                 unsigned long start_iova,
161                                                 unsigned long size,
162                                                 unsigned long page_size);
163
164 extern int msm_iommu_map_contig_buffer(phys_addr_t phys,
165                                 unsigned int domain_no,
166                                 unsigned int partition_no,
167                                 unsigned long size,
168                                 unsigned long align,
169                                 unsigned long cached,
170                                 dma_addr_t *iova_val);
171
172
173 extern void msm_iommu_unmap_contig_buffer(dma_addr_t iova,
174                                         unsigned int domain_no,
175                                         unsigned int partition_no,
176                                         unsigned long size);
177
178 extern int msm_register_domain(struct msm_iova_layout *layout);
179 extern int msm_unregister_domain(struct iommu_domain *domain);
180
181 int msm_map_dma_buf(struct dma_buf *dma_buf, struct sg_table *table,
182                         int domain_num, int partition_num, unsigned long align,
183                         unsigned long iova_length, ion_phys_addr_t *iova,
184                         unsigned long *buffer_size,
185                         unsigned long flags, unsigned long iommu_flags);
186
187 void msm_unmap_dma_buf(struct sg_table *table, int domain_num,
188                         int partition_num);
189 #else
190 static inline int ion_map_iommu(struct ion_client *client,
191                         struct ion_handle *handle, int domain_num,
192                         int partition_num, unsigned long align,
193                         unsigned long iova_length, ion_phys_addr_t *iova,
194                         unsigned long *buffer_size,
195                         unsigned long flags,
196                         unsigned long iommu_flags)
197 {
198         return -ENODEV;
199 }
200
201 static inline void ion_unmap_iommu(struct ion_client *client,
202                         struct ion_handle *handle, int domain_num,
203                         int partition_num)
204 {
205 }
206
207 static inline void msm_iommu_set_client_name(struct iommu_domain *domain,
208                                              char const *name)
209 {
210 }
211
212 static inline struct iommu_domain
213         *msm_get_iommu_domain(int subsys_id) { return NULL; }
214
215
216 static inline int msm_find_domain_no(const struct iommu_domain *domain)
217 {
218         return -EINVAL;
219 }
220
221 static inline int msm_allocate_iova_address(unsigned int iommu_domain,
222                                         unsigned int partition_no,
223                                         unsigned long size,
224                                         unsigned long align,
225                                         unsigned long *iova) { return -ENOMEM; }
226
227 static inline void msm_free_iova_address(unsigned long iova,
228                         unsigned int iommu_domain,
229                         unsigned int partition_no,
230                         unsigned long size) { }
231
232 static inline int msm_use_iommu(void)
233 {
234         return 0;
235 }
236
237 static inline int msm_iommu_map_extra(struct iommu_domain *domain,
238                                                 unsigned long start_iova,
239                                                 phys_addr_t phys_addr,
240                                                 unsigned long size,
241                                                 unsigned long page_size,
242                                                 int cached)
243 {
244         return -ENODEV;
245 }
246
247 static inline void msm_iommu_unmap_extra(struct iommu_domain *domain,
248                                                 unsigned long start_iova,
249                                                 unsigned long size,
250                                                 unsigned long page_size)
251 {
252 }
253
254 static inline int msm_iommu_map_contig_buffer(phys_addr_t phys,
255                                 unsigned int domain_no,
256                                 unsigned int partition_no,
257                                 unsigned long size,
258                                 unsigned long align,
259                                 unsigned long cached,
260                                 dma_addr_t *iova_val)
261 {
262         *iova_val = phys;
263         return 0;
264 }
265
266 static inline void msm_iommu_unmap_contig_buffer(dma_addr_t iova,
267                                         unsigned int domain_no,
268                                         unsigned int partition_no,
269                                         unsigned long size)
270 {
271 }
272
273 static inline int msm_register_domain(struct msm_iova_layout *layout)
274 {
275         return -ENODEV;
276 }
277
278 static inline int msm_unregister_domain(struct iommu_domain *domain)
279 {
280         return -ENODEV;
281 }
282
283 static inline struct iommu_domain *msm_iommu_domain_find(const char *name)
284 {
285         return NULL;
286 }
287
288 static inline int msm_iommu_domain_no_find(const char *name)
289 {
290         return -ENODEV;
291 }
292
293 static inline int msm_map_dma_buf(struct dma_buf *dma_buf,
294                         struct sg_table *table,
295                         int domain_num, int partition_num, unsigned long align,
296                         unsigned long iova_length, ion_phys_addr_t *iova,
297                         unsigned long *buffer_size,
298                         unsigned long flags, unsigned long iommu_flags)
299 {
300         return -ENODEV;
301 }
302
303 static inline void msm_unmap_dma_buf(struct sg_table *table, int domain_num,
304                         int partition_num)
305 {
306 }
307
308 #endif
309
310 #endif