blob: a683ed4fe4ed06b40b368c0787750b9b9a1fc5b0 [file] [log] [blame]
Laura Abbott6438e532012-07-20 10:10:41 -07001/*
Laura Abbott6438e532012-07-20 10:10:41 -07002 *
Laura Abbott7db4e0b2013-01-03 14:20:16 -08003 * Copyright (c) 2012-2013, The Linux Foundation. All rights reserved.
Laura Abbott6438e532012-07-20 10:10:41 -07004 *
5 * This software is licensed under the terms of the GNU General Public
6 * License version 2, as published by the Free Software Foundation, and
7 * may be copied, distributed, and modified under those terms.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 */
15
16#ifndef _LINUX_MSM_ION_H
17#define _LINUX_MSM_ION_H
18
19#include <linux/ion.h>
20
Mitchel Humpherys362b52b2012-09-13 10:53:22 -070021enum msm_ion_heap_types {
22 ION_HEAP_TYPE_MSM_START = ION_HEAP_TYPE_CUSTOM + 1,
23 ION_HEAP_TYPE_IOMMU = ION_HEAP_TYPE_MSM_START,
24 ION_HEAP_TYPE_CP,
Laura Abbotta8c373f2013-02-15 09:25:35 -080025 ION_HEAP_TYPE_SECURE_DMA,
Mitchel Humpherys362b52b2012-09-13 10:53:22 -070026};
27
28/**
29 * These are the only ids that should be used for Ion heap ids.
30 * The ids listed are the order in which allocation will be attempted
31 * if specified. Don't swap the order of heap ids unless you know what
32 * you are doing!
33 * Id's are spaced by purpose to allow new Id's to be inserted in-between (for
34 * possible fallbacks)
35 */
36
37enum ion_heap_ids {
38 INVALID_HEAP_ID = -1,
39 ION_CP_MM_HEAP_ID = 8,
40 ION_CP_MFC_HEAP_ID = 12,
41 ION_CP_WB_HEAP_ID = 16, /* 8660 only */
42 ION_CAMERA_HEAP_ID = 20, /* 8660 only */
Laura Abbott98e8ddc2013-02-09 09:35:30 -080043 ION_ADSP_HEAP_ID = 22,
Neeti Desai9dc9db42012-10-18 17:53:51 -070044 ION_PIL1_HEAP_ID = 23, /* Currently used for other PIL images */
Mitchel Humpherys362b52b2012-09-13 10:53:22 -070045 ION_SF_HEAP_ID = 24,
46 ION_IOMMU_HEAP_ID = 25,
Neeti Desai9dc9db42012-10-18 17:53:51 -070047 ION_PIL2_HEAP_ID = 26, /* Currently used for modem firmware images */
Mitchel Humpherys362b52b2012-09-13 10:53:22 -070048 ION_QSECOM_HEAP_ID = 27,
49 ION_AUDIO_HEAP_ID = 28,
50
51 ION_MM_FIRMWARE_HEAP_ID = 29,
52 ION_SYSTEM_HEAP_ID = 30,
53
54 ION_HEAP_ID_RESERVED = 31 /** Bit reserved for ION_SECURE flag */
55};
56
57enum ion_fixed_position {
58 NOT_FIXED,
59 FIXED_LOW,
60 FIXED_MIDDLE,
61 FIXED_HIGH,
62};
63
64enum cp_mem_usage {
65 VIDEO_BITSTREAM = 0x1,
66 VIDEO_PIXEL = 0x2,
67 VIDEO_NONPIXEL = 0x3,
68 MAX_USAGE = 0x4,
69 UNKNOWN = 0x7FFFFFFF,
70};
71
72#define ION_HEAP_CP_MASK (1 << ION_HEAP_TYPE_CP)
73
74/**
75 * Flag to use when allocating to indicate that a heap is secure.
76 */
77#define ION_SECURE (1 << ION_HEAP_ID_RESERVED)
78
79/**
Laura Abbott7db4e0b2013-01-03 14:20:16 -080080 * Flag for clients to force contiguous memort allocation
81 *
82 * Use of this flag is carefully monitored!
83 */
84#define ION_FORCE_CONTIGUOUS (1 << 30)
85
86/**
Mitchel Humpherys362b52b2012-09-13 10:53:22 -070087 * Macro should be used with ion_heap_ids defined above.
88 */
89#define ION_HEAP(bit) (1 << (bit))
90
Laura Abbott98e8ddc2013-02-09 09:35:30 -080091#define ION_ADSP_HEAP_NAME "adsp"
Mitchel Humpherys362b52b2012-09-13 10:53:22 -070092#define ION_VMALLOC_HEAP_NAME "vmalloc"
93#define ION_AUDIO_HEAP_NAME "audio"
94#define ION_SF_HEAP_NAME "sf"
95#define ION_MM_HEAP_NAME "mm"
96#define ION_CAMERA_HEAP_NAME "camera_preview"
97#define ION_IOMMU_HEAP_NAME "iommu"
98#define ION_MFC_HEAP_NAME "mfc"
99#define ION_WB_HEAP_NAME "wb"
100#define ION_MM_FIRMWARE_HEAP_NAME "mm_fw"
Neeti Desai9dc9db42012-10-18 17:53:51 -0700101#define ION_PIL1_HEAP_NAME "pil_1"
102#define ION_PIL2_HEAP_NAME "pil_2"
Mitchel Humpherys362b52b2012-09-13 10:53:22 -0700103#define ION_QSECOM_HEAP_NAME "qsecom"
104#define ION_FMEM_HEAP_NAME "fmem"
105
106#define ION_SET_CACHED(__cache) (__cache | ION_FLAG_CACHED)
107#define ION_SET_UNCACHED(__cache) (__cache & ~ION_FLAG_CACHED)
108
109#define ION_IS_CACHED(__flags) ((__flags) & ION_FLAG_CACHED)
110
111#ifdef __KERNEL__
112
113/*
114 * This flag allows clients when mapping into the IOMMU to specify to
115 * defer un-mapping from the IOMMU until the buffer memory is freed.
116 */
117#define ION_IOMMU_UNMAP_DELAYED 1
118
Laura Abbott93619302012-10-11 11:51:40 -0700119/*
120 * This flag allows clients to defer unsecuring a buffer until the buffer
121 * is actually freed.
122 */
123#define ION_UNSECURE_DELAYED 1
124
Mitchel Humpherys362b52b2012-09-13 10:53:22 -0700125/**
126 * struct ion_cp_heap_pdata - defines a content protection heap in the given
127 * platform
128 * @permission_type: Memory ID used to identify the memory to TZ
129 * @align: Alignment requirement for the memory
130 * @secure_base: Base address for securing the heap.
131 * Note: This might be different from actual base address
132 * of this heap in the case of a shared heap.
133 * @secure_size: Memory size for securing the heap.
134 * Note: This might be different from actual size
135 * of this heap in the case of a shared heap.
136 * @reusable Flag indicating whether this heap is reusable of not.
137 * (see FMEM)
138 * @mem_is_fmem Flag indicating whether this memory is coming from fmem
139 * or not.
140 * @fixed_position If nonzero, position in the fixed area.
141 * @virt_addr: Virtual address used when using fmem.
142 * @iommu_map_all: Indicates whether we should map whole heap into IOMMU.
143 * @iommu_2x_map_domain: Indicates the domain to use for overmapping.
144 * @request_region: function to be called when the number of allocations
145 * goes from 0 -> 1
146 * @release_region: function to be called when the number of allocations
147 * goes from 1 -> 0
148 * @setup_region: function to be called upon ion registration
149 * @memory_type:Memory type used for the heap
Mitchel Humpherys345f0232013-01-11 10:55:25 -0800150 * @allow_nonsecure_alloc: allow non-secure allocations from this heap. For
151 * secure heaps, this flag must be set so allow non-secure
152 * allocations. For non-secure heaps, this flag is ignored.
Mitchel Humpherys362b52b2012-09-13 10:53:22 -0700153 *
154 */
155struct ion_cp_heap_pdata {
156 enum ion_permission_type permission_type;
157 unsigned int align;
158 ion_phys_addr_t secure_base; /* Base addr used when heap is shared */
159 size_t secure_size; /* Size used for securing heap when heap is shared*/
160 int reusable;
161 int mem_is_fmem;
Laura Abbott3180a5f2012-08-03 17:31:03 -0700162 int is_cma;
Mitchel Humpherys362b52b2012-09-13 10:53:22 -0700163 enum ion_fixed_position fixed_position;
164 int iommu_map_all;
165 int iommu_2x_map_domain;
Laura Abbott871ad422013-03-13 14:28:19 -0700166 void *virt_addr;
Mitchel Humpherys362b52b2012-09-13 10:53:22 -0700167 int (*request_region)(void *);
168 int (*release_region)(void *);
169 void *(*setup_region)(void);
170 enum ion_memory_types memory_type;
Mitchel Humpherys345f0232013-01-11 10:55:25 -0800171 int allow_nonsecure_alloc;
Mitchel Humpherys362b52b2012-09-13 10:53:22 -0700172};
173
174/**
175 * struct ion_co_heap_pdata - defines a carveout heap in the given platform
176 * @adjacent_mem_id: Id of heap that this heap must be adjacent to.
177 * @align: Alignment requirement for the memory
178 * @mem_is_fmem Flag indicating whether this memory is coming from fmem
179 * or not.
180 * @fixed_position If nonzero, position in the fixed area.
181 * @request_region: function to be called when the number of allocations
182 * goes from 0 -> 1
183 * @release_region: function to be called when the number of allocations
184 * goes from 1 -> 0
185 * @setup_region: function to be called upon ion registration
186 * @memory_type:Memory type used for the heap
187 *
188 */
189struct ion_co_heap_pdata {
190 int adjacent_mem_id;
191 unsigned int align;
192 int mem_is_fmem;
193 enum ion_fixed_position fixed_position;
194 int (*request_region)(void *);
195 int (*release_region)(void *);
196 void *(*setup_region)(void);
197 enum ion_memory_types memory_type;
198};
199
200#ifdef CONFIG_ION
201/**
202 * msm_ion_secure_heap - secure a heap. Wrapper around ion_secure_heap.
203 *
204 * @heap_id - heap id to secure.
205 *
206 * Secure a heap
207 * Returns 0 on success
208 */
209int msm_ion_secure_heap(int heap_id);
210
211/**
212 * msm_ion_unsecure_heap - unsecure a heap. Wrapper around ion_unsecure_heap.
213 *
214 * @heap_id - heap id to secure.
215 *
216 * Un-secure a heap
217 * Returns 0 on success
218 */
219int msm_ion_unsecure_heap(int heap_id);
220
221/**
222 * msm_ion_secure_heap_2_0 - secure a heap using 2.0 APIs
223 * Wrapper around ion_secure_heap.
224 *
225 * @heap_id - heap id to secure.
226 * @usage - usage hint to TZ
227 *
228 * Secure a heap
229 * Returns 0 on success
230 */
231int msm_ion_secure_heap_2_0(int heap_id, enum cp_mem_usage usage);
232
233/**
234 * msm_ion_unsecure_heap - unsecure a heap secured with 3.0 APIs.
235 * Wrapper around ion_unsecure_heap.
236 *
237 * @heap_id - heap id to secure.
238 * @usage - usage hint to TZ
239 *
240 * Un-secure a heap
241 * Returns 0 on success
242 */
243int msm_ion_unsecure_heap_2_0(int heap_id, enum cp_mem_usage usage);
Laura Abbott93619302012-10-11 11:51:40 -0700244
245/**
246 * msm_ion_secure_buffer - secure an individual buffer
247 *
248 * @client - client who has access to the buffer
249 * @handle - buffer to secure
250 * @usage - usage hint to TZ
251 * @flags - flags for the securing
252 */
253int msm_ion_secure_buffer(struct ion_client *client, struct ion_handle *handle,
254 enum cp_mem_usage usage, int flags);
255
256/**
257 * msm_ion_unsecure_buffer - unsecure an individual buffer
258 *
259 * @client - client who has access to the buffer
260 * @handle - buffer to secure
261 */
262int msm_ion_unsecure_buffer(struct ion_client *client,
263 struct ion_handle *handle);
Mitchel Humpherys362b52b2012-09-13 10:53:22 -0700264#else
265static inline int msm_ion_secure_heap(int heap_id)
266{
267 return -ENODEV;
268
269}
270
271static inline int msm_ion_unsecure_heap(int heap_id)
272{
273 return -ENODEV;
274}
275
276static inline int msm_ion_secure_heap_2_0(int heap_id, enum cp_mem_usage usage)
277{
278 return -ENODEV;
279}
280
281static inline int msm_ion_unsecure_heap_2_0(int heap_id,
282 enum cp_mem_usage usage)
283{
284 return -ENODEV;
285}
Mitchel Humpherys782653e2013-02-25 18:54:53 -0800286
287static inline int msm_ion_secure_buffer(struct ion_client *client,
288 struct ion_handle *handle,
289 enum cp_mem_usage usage,
290 int flags)
291{
292 return -ENODEV;
293}
294
295static inline int msm_ion_unsecure_buffer(struct ion_client *client,
296 struct ion_handle *handle)
297{
298 return -ENODEV;
299}
Mitchel Humpherys362b52b2012-09-13 10:53:22 -0700300#endif /* CONFIG_ION */
301
302#endif /* __KERNEL */
303
304/* struct ion_flush_data - data passed to ion for flushing caches
305 *
306 * @handle: handle with data to flush
307 * @fd: fd to flush
308 * @vaddr: userspace virtual address mapped with mmap
309 * @offset: offset into the handle to flush
310 * @length: length of handle to flush
311 *
312 * Performs cache operations on the handle. If p is the start address
313 * of the handle, p + offset through p + offset + length will have
314 * the cache operations performed
315 */
316struct ion_flush_data {
317 struct ion_handle *handle;
318 int fd;
319 void *vaddr;
320 unsigned int offset;
321 unsigned int length;
322};
323
Mitchel Humpherys362b52b2012-09-13 10:53:22 -0700324#define ION_IOC_MSM_MAGIC 'M'
325
326/**
327 * DOC: ION_IOC_CLEAN_CACHES - clean the caches
328 *
329 * Clean the caches of the handle specified.
330 */
331#define ION_IOC_CLEAN_CACHES _IOWR(ION_IOC_MSM_MAGIC, 0, \
332 struct ion_flush_data)
333/**
334 * DOC: ION_IOC_INV_CACHES - invalidate the caches
335 *
336 * Invalidate the caches of the handle specified.
337 */
338#define ION_IOC_INV_CACHES _IOWR(ION_IOC_MSM_MAGIC, 1, \
339 struct ion_flush_data)
340/**
341 * DOC: ION_IOC_CLEAN_INV_CACHES - clean and invalidate the caches
342 *
343 * Clean and invalidate the caches of the handle specified.
344 */
345#define ION_IOC_CLEAN_INV_CACHES _IOWR(ION_IOC_MSM_MAGIC, 2, \
346 struct ion_flush_data)
347
Laura Abbott6438e532012-07-20 10:10:41 -0700348#endif