blob: d423b264b6f288fa49026b261272560f2ba698c2 [file] [log] [blame]
Laura Abbott6438e532012-07-20 10:10:41 -07001/*
Laura Abbott6438e532012-07-20 10:10:41 -07002 *
Neeti Desai9dc9db42012-10-18 17:53:51 -07003 * Copyright (c) 2012, 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,
25};
26
27/**
28 * These are the only ids that should be used for Ion heap ids.
29 * The ids listed are the order in which allocation will be attempted
30 * if specified. Don't swap the order of heap ids unless you know what
31 * you are doing!
32 * Id's are spaced by purpose to allow new Id's to be inserted in-between (for
33 * possible fallbacks)
34 */
35
36enum ion_heap_ids {
37 INVALID_HEAP_ID = -1,
38 ION_CP_MM_HEAP_ID = 8,
39 ION_CP_MFC_HEAP_ID = 12,
40 ION_CP_WB_HEAP_ID = 16, /* 8660 only */
41 ION_CAMERA_HEAP_ID = 20, /* 8660 only */
Neeti Desai9dc9db42012-10-18 17:53:51 -070042 ION_PIL1_HEAP_ID = 23, /* Currently used for other PIL images */
Mitchel Humpherys362b52b2012-09-13 10:53:22 -070043 ION_SF_HEAP_ID = 24,
44 ION_IOMMU_HEAP_ID = 25,
Neeti Desai9dc9db42012-10-18 17:53:51 -070045 ION_PIL2_HEAP_ID = 26, /* Currently used for modem firmware images */
Mitchel Humpherys362b52b2012-09-13 10:53:22 -070046 ION_QSECOM_HEAP_ID = 27,
47 ION_AUDIO_HEAP_ID = 28,
48
49 ION_MM_FIRMWARE_HEAP_ID = 29,
50 ION_SYSTEM_HEAP_ID = 30,
51
52 ION_HEAP_ID_RESERVED = 31 /** Bit reserved for ION_SECURE flag */
53};
54
55enum ion_fixed_position {
56 NOT_FIXED,
57 FIXED_LOW,
58 FIXED_MIDDLE,
59 FIXED_HIGH,
60};
61
62enum cp_mem_usage {
63 VIDEO_BITSTREAM = 0x1,
64 VIDEO_PIXEL = 0x2,
65 VIDEO_NONPIXEL = 0x3,
66 MAX_USAGE = 0x4,
67 UNKNOWN = 0x7FFFFFFF,
68};
69
70#define ION_HEAP_CP_MASK (1 << ION_HEAP_TYPE_CP)
71
72/**
73 * Flag to use when allocating to indicate that a heap is secure.
74 */
75#define ION_SECURE (1 << ION_HEAP_ID_RESERVED)
76
77/**
78 * Macro should be used with ion_heap_ids defined above.
79 */
80#define ION_HEAP(bit) (1 << (bit))
81
82#define ION_VMALLOC_HEAP_NAME "vmalloc"
83#define ION_AUDIO_HEAP_NAME "audio"
84#define ION_SF_HEAP_NAME "sf"
85#define ION_MM_HEAP_NAME "mm"
86#define ION_CAMERA_HEAP_NAME "camera_preview"
87#define ION_IOMMU_HEAP_NAME "iommu"
88#define ION_MFC_HEAP_NAME "mfc"
89#define ION_WB_HEAP_NAME "wb"
90#define ION_MM_FIRMWARE_HEAP_NAME "mm_fw"
Neeti Desai9dc9db42012-10-18 17:53:51 -070091#define ION_PIL1_HEAP_NAME "pil_1"
92#define ION_PIL2_HEAP_NAME "pil_2"
Mitchel Humpherys362b52b2012-09-13 10:53:22 -070093#define ION_QSECOM_HEAP_NAME "qsecom"
94#define ION_FMEM_HEAP_NAME "fmem"
95
96#define ION_SET_CACHED(__cache) (__cache | ION_FLAG_CACHED)
97#define ION_SET_UNCACHED(__cache) (__cache & ~ION_FLAG_CACHED)
98
99#define ION_IS_CACHED(__flags) ((__flags) & ION_FLAG_CACHED)
100
101#ifdef __KERNEL__
102
103/*
104 * This flag allows clients when mapping into the IOMMU to specify to
105 * defer un-mapping from the IOMMU until the buffer memory is freed.
106 */
107#define ION_IOMMU_UNMAP_DELAYED 1
108
Laura Abbott93619302012-10-11 11:51:40 -0700109/*
110 * This flag allows clients to defer unsecuring a buffer until the buffer
111 * is actually freed.
112 */
113#define ION_UNSECURE_DELAYED 1
114
Mitchel Humpherys362b52b2012-09-13 10:53:22 -0700115/**
116 * struct ion_cp_heap_pdata - defines a content protection heap in the given
117 * platform
118 * @permission_type: Memory ID used to identify the memory to TZ
119 * @align: Alignment requirement for the memory
120 * @secure_base: Base address for securing the heap.
121 * Note: This might be different from actual base address
122 * of this heap in the case of a shared heap.
123 * @secure_size: Memory size for securing the heap.
124 * Note: This might be different from actual size
125 * of this heap in the case of a shared heap.
126 * @reusable Flag indicating whether this heap is reusable of not.
127 * (see FMEM)
128 * @mem_is_fmem Flag indicating whether this memory is coming from fmem
129 * or not.
130 * @fixed_position If nonzero, position in the fixed area.
131 * @virt_addr: Virtual address used when using fmem.
132 * @iommu_map_all: Indicates whether we should map whole heap into IOMMU.
133 * @iommu_2x_map_domain: Indicates the domain to use for overmapping.
134 * @request_region: function to be called when the number of allocations
135 * goes from 0 -> 1
136 * @release_region: function to be called when the number of allocations
137 * goes from 1 -> 0
138 * @setup_region: function to be called upon ion registration
139 * @memory_type:Memory type used for the heap
Laura Abbottac963312012-12-11 15:09:03 -0800140 * @no_nonsecure_alloc: don't allow non-secure allocations from this heap
Mitchel Humpherys362b52b2012-09-13 10:53:22 -0700141 *
142 */
143struct ion_cp_heap_pdata {
144 enum ion_permission_type permission_type;
145 unsigned int align;
146 ion_phys_addr_t secure_base; /* Base addr used when heap is shared */
147 size_t secure_size; /* Size used for securing heap when heap is shared*/
148 int reusable;
149 int mem_is_fmem;
Laura Abbott3180a5f2012-08-03 17:31:03 -0700150 int is_cma;
Mitchel Humpherys362b52b2012-09-13 10:53:22 -0700151 enum ion_fixed_position fixed_position;
152 int iommu_map_all;
153 int iommu_2x_map_domain;
154 ion_virt_addr_t *virt_addr;
155 int (*request_region)(void *);
156 int (*release_region)(void *);
157 void *(*setup_region)(void);
158 enum ion_memory_types memory_type;
Laura Abbottac963312012-12-11 15:09:03 -0800159 int no_nonsecure_alloc;
Mitchel Humpherys362b52b2012-09-13 10:53:22 -0700160};
161
162/**
163 * struct ion_co_heap_pdata - defines a carveout heap in the given platform
164 * @adjacent_mem_id: Id of heap that this heap must be adjacent to.
165 * @align: Alignment requirement for the memory
166 * @mem_is_fmem Flag indicating whether this memory is coming from fmem
167 * or not.
168 * @fixed_position If nonzero, position in the fixed area.
169 * @request_region: function to be called when the number of allocations
170 * goes from 0 -> 1
171 * @release_region: function to be called when the number of allocations
172 * goes from 1 -> 0
173 * @setup_region: function to be called upon ion registration
174 * @memory_type:Memory type used for the heap
175 *
176 */
177struct ion_co_heap_pdata {
178 int adjacent_mem_id;
179 unsigned int align;
180 int mem_is_fmem;
181 enum ion_fixed_position fixed_position;
182 int (*request_region)(void *);
183 int (*release_region)(void *);
184 void *(*setup_region)(void);
185 enum ion_memory_types memory_type;
186};
187
188#ifdef CONFIG_ION
189/**
190 * msm_ion_secure_heap - secure a heap. Wrapper around ion_secure_heap.
191 *
192 * @heap_id - heap id to secure.
193 *
194 * Secure a heap
195 * Returns 0 on success
196 */
197int msm_ion_secure_heap(int heap_id);
198
199/**
200 * msm_ion_unsecure_heap - unsecure a heap. Wrapper around ion_unsecure_heap.
201 *
202 * @heap_id - heap id to secure.
203 *
204 * Un-secure a heap
205 * Returns 0 on success
206 */
207int msm_ion_unsecure_heap(int heap_id);
208
209/**
210 * msm_ion_secure_heap_2_0 - secure a heap using 2.0 APIs
211 * Wrapper around ion_secure_heap.
212 *
213 * @heap_id - heap id to secure.
214 * @usage - usage hint to TZ
215 *
216 * Secure a heap
217 * Returns 0 on success
218 */
219int msm_ion_secure_heap_2_0(int heap_id, enum cp_mem_usage usage);
220
221/**
222 * msm_ion_unsecure_heap - unsecure a heap secured with 3.0 APIs.
223 * Wrapper around ion_unsecure_heap.
224 *
225 * @heap_id - heap id to secure.
226 * @usage - usage hint to TZ
227 *
228 * Un-secure a heap
229 * Returns 0 on success
230 */
231int msm_ion_unsecure_heap_2_0(int heap_id, enum cp_mem_usage usage);
Laura Abbott93619302012-10-11 11:51:40 -0700232
233/**
234 * msm_ion_secure_buffer - secure an individual buffer
235 *
236 * @client - client who has access to the buffer
237 * @handle - buffer to secure
238 * @usage - usage hint to TZ
239 * @flags - flags for the securing
240 */
241int msm_ion_secure_buffer(struct ion_client *client, struct ion_handle *handle,
242 enum cp_mem_usage usage, int flags);
243
244/**
245 * msm_ion_unsecure_buffer - unsecure an individual buffer
246 *
247 * @client - client who has access to the buffer
248 * @handle - buffer to secure
249 */
250int msm_ion_unsecure_buffer(struct ion_client *client,
251 struct ion_handle *handle);
Mitchel Humpherys362b52b2012-09-13 10:53:22 -0700252#else
253static inline int msm_ion_secure_heap(int heap_id)
254{
255 return -ENODEV;
256
257}
258
259static inline int msm_ion_unsecure_heap(int heap_id)
260{
261 return -ENODEV;
262}
263
264static inline int msm_ion_secure_heap_2_0(int heap_id, enum cp_mem_usage usage)
265{
266 return -ENODEV;
267}
268
269static inline int msm_ion_unsecure_heap_2_0(int heap_id,
270 enum cp_mem_usage usage)
271{
272 return -ENODEV;
273}
274#endif /* CONFIG_ION */
275
276#endif /* __KERNEL */
277
278/* struct ion_flush_data - data passed to ion for flushing caches
279 *
280 * @handle: handle with data to flush
281 * @fd: fd to flush
282 * @vaddr: userspace virtual address mapped with mmap
283 * @offset: offset into the handle to flush
284 * @length: length of handle to flush
285 *
286 * Performs cache operations on the handle. If p is the start address
287 * of the handle, p + offset through p + offset + length will have
288 * the cache operations performed
289 */
290struct ion_flush_data {
291 struct ion_handle *handle;
292 int fd;
293 void *vaddr;
294 unsigned int offset;
295 unsigned int length;
296};
297
298/* struct ion_flag_data - information about flags for this buffer
299 *
300 * @handle: handle to get flags from
301 * @flags: flags of this handle
302 *
303 * Takes handle as an input and outputs the flags from the handle
304 * in the flag field.
305 */
306struct ion_flag_data {
307 struct ion_handle *handle;
308 unsigned long flags;
309};
310
311#define ION_IOC_MSM_MAGIC 'M'
312
313/**
314 * DOC: ION_IOC_CLEAN_CACHES - clean the caches
315 *
316 * Clean the caches of the handle specified.
317 */
318#define ION_IOC_CLEAN_CACHES _IOWR(ION_IOC_MSM_MAGIC, 0, \
319 struct ion_flush_data)
320/**
321 * DOC: ION_IOC_INV_CACHES - invalidate the caches
322 *
323 * Invalidate the caches of the handle specified.
324 */
325#define ION_IOC_INV_CACHES _IOWR(ION_IOC_MSM_MAGIC, 1, \
326 struct ion_flush_data)
327/**
328 * DOC: ION_IOC_CLEAN_INV_CACHES - clean and invalidate the caches
329 *
330 * Clean and invalidate the caches of the handle specified.
331 */
332#define ION_IOC_CLEAN_INV_CACHES _IOWR(ION_IOC_MSM_MAGIC, 2, \
333 struct ion_flush_data)
334
335/**
336 * DOC: ION_IOC_GET_FLAGS - get the flags of the handle
337 *
338 * Gets the flags of the current handle which indicate cachability,
339 * secure state etc.
340 */
341#define ION_IOC_GET_FLAGS _IOWR(ION_IOC_MSM_MAGIC, 3, \
342 struct ion_flag_data)
343
Laura Abbott6438e532012-07-20 10:10:41 -0700344#endif