blob: 2ba75880c171b18ad3802b082e9463113c67acaa [file] [log] [blame]
Laura Abbott6438e532012-07-20 10:10:41 -07001/*
Laura Abbott6438e532012-07-20 10:10:41 -07002 *
Laura Abbottc7cd2b02013-01-03 14:20:16 -08003 * Copyright (c) 2012-2013, Code Aurora Forum. 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
Ajay Dudanif572d262012-08-29 18:02:11 -070019#include <linux/ion.h>
Laura Abbott6438e532012-07-20 10:10:41 -070020
Mitchel Humpherysdc4d01d2012-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 */
Laura Abbott03e3cd72013-02-09 09:35:30 -080042 ION_ADSP_HEAP_ID = 22,
Mitchel Humpherysdc4d01d2012-09-13 10:53:22 -070043 ION_SF_HEAP_ID = 24,
44 ION_IOMMU_HEAP_ID = 25,
45 ION_QSECOM_HEAP_ID = 27,
46 ION_AUDIO_HEAP_ID = 28,
47
48 ION_MM_FIRMWARE_HEAP_ID = 29,
49 ION_SYSTEM_HEAP_ID = 30,
50
51 ION_HEAP_ID_RESERVED = 31 /** Bit reserved for ION_SECURE flag */
52};
53
54enum ion_fixed_position {
55 NOT_FIXED,
56 FIXED_LOW,
57 FIXED_MIDDLE,
58 FIXED_HIGH,
59};
60
61enum cp_mem_usage {
62 VIDEO_BITSTREAM = 0x1,
63 VIDEO_PIXEL = 0x2,
64 VIDEO_NONPIXEL = 0x3,
65 MAX_USAGE = 0x4,
66 UNKNOWN = 0x7FFFFFFF,
67};
68
69#define ION_HEAP_CP_MASK (1 << ION_HEAP_TYPE_CP)
70
71/**
72 * Flag to use when allocating to indicate that a heap is secure.
73 */
74#define ION_SECURE (1 << ION_HEAP_ID_RESERVED)
75
76/**
Laura Abbottc7cd2b02013-01-03 14:20:16 -080077 * Flag for clients to force contiguous memort allocation
78 *
79 * Use of this flag is carefully monitored!
80 */
81#define ION_FORCE_CONTIGUOUS (1 << 30)
82
83/**
Mitchel Humpherysdc4d01d2012-09-13 10:53:22 -070084 * Macro should be used with ion_heap_ids defined above.
85 */
86#define ION_HEAP(bit) (1 << (bit))
87
Laura Abbott03e3cd72013-02-09 09:35:30 -080088#define ION_ADSP_HEAP_NAME "adsp"
Mitchel Humpherysdc4d01d2012-09-13 10:53:22 -070089#define ION_VMALLOC_HEAP_NAME "vmalloc"
90#define ION_AUDIO_HEAP_NAME "audio"
91#define ION_SF_HEAP_NAME "sf"
92#define ION_MM_HEAP_NAME "mm"
93#define ION_CAMERA_HEAP_NAME "camera_preview"
94#define ION_IOMMU_HEAP_NAME "iommu"
95#define ION_MFC_HEAP_NAME "mfc"
96#define ION_WB_HEAP_NAME "wb"
97#define ION_MM_FIRMWARE_HEAP_NAME "mm_fw"
98#define ION_QSECOM_HEAP_NAME "qsecom"
99#define ION_FMEM_HEAP_NAME "fmem"
100
101#define ION_SET_CACHED(__cache) (__cache | ION_FLAG_CACHED)
102#define ION_SET_UNCACHED(__cache) (__cache & ~ION_FLAG_CACHED)
103
104#define ION_IS_CACHED(__flags) ((__flags) & ION_FLAG_CACHED)
105
106#ifdef __KERNEL__
107
108/*
109 * This flag allows clients when mapping into the IOMMU to specify to
110 * defer un-mapping from the IOMMU until the buffer memory is freed.
111 */
112#define ION_IOMMU_UNMAP_DELAYED 1
113
114/**
115 * struct ion_cp_heap_pdata - defines a content protection heap in the given
116 * platform
117 * @permission_type: Memory ID used to identify the memory to TZ
118 * @align: Alignment requirement for the memory
119 * @secure_base: Base address for securing the heap.
120 * Note: This might be different from actual base address
121 * of this heap in the case of a shared heap.
122 * @secure_size: Memory size for securing the heap.
123 * Note: This might be different from actual size
124 * of this heap in the case of a shared heap.
125 * @reusable Flag indicating whether this heap is reusable of not.
126 * (see FMEM)
127 * @mem_is_fmem Flag indicating whether this memory is coming from fmem
128 * or not.
129 * @fixed_position If nonzero, position in the fixed area.
130 * @virt_addr: Virtual address used when using fmem.
131 * @iommu_map_all: Indicates whether we should map whole heap into IOMMU.
132 * @iommu_2x_map_domain: Indicates the domain to use for overmapping.
133 * @request_region: function to be called when the number of allocations
134 * goes from 0 -> 1
135 * @release_region: function to be called when the number of allocations
136 * goes from 1 -> 0
137 * @setup_region: function to be called upon ion registration
138 * @memory_type:Memory type used for the heap
Laura Abbott5249a052012-12-11 15:09:03 -0800139 * @no_nonsecure_alloc: don't allow non-secure allocations from this heap
Mitchel Humpherysdc4d01d2012-09-13 10:53:22 -0700140 *
141 */
142struct ion_cp_heap_pdata {
143 enum ion_permission_type permission_type;
144 unsigned int align;
145 ion_phys_addr_t secure_base; /* Base addr used when heap is shared */
146 size_t secure_size; /* Size used for securing heap when heap is shared*/
147 int reusable;
148 int mem_is_fmem;
Laura Abbottd3142222012-08-03 17:31:03 -0700149 int is_cma;
Mitchel Humpherysdc4d01d2012-09-13 10:53:22 -0700150 enum ion_fixed_position fixed_position;
151 int iommu_map_all;
152 int iommu_2x_map_domain;
153 ion_virt_addr_t *virt_addr;
154 int (*request_region)(void *);
155 int (*release_region)(void *);
156 void *(*setup_region)(void);
157 enum ion_memory_types memory_type;
Laura Abbott5249a052012-12-11 15:09:03 -0800158 int no_nonsecure_alloc;
Mitchel Humpherysdc4d01d2012-09-13 10:53:22 -0700159};
160
161/**
162 * struct ion_co_heap_pdata - defines a carveout heap in the given platform
163 * @adjacent_mem_id: Id of heap that this heap must be adjacent to.
164 * @align: Alignment requirement for the memory
165 * @mem_is_fmem Flag indicating whether this memory is coming from fmem
166 * or not.
167 * @fixed_position If nonzero, position in the fixed area.
168 * @request_region: function to be called when the number of allocations
169 * goes from 0 -> 1
170 * @release_region: function to be called when the number of allocations
171 * goes from 1 -> 0
172 * @setup_region: function to be called upon ion registration
173 * @memory_type:Memory type used for the heap
174 *
175 */
176struct ion_co_heap_pdata {
177 int adjacent_mem_id;
178 unsigned int align;
179 int mem_is_fmem;
180 enum ion_fixed_position fixed_position;
181 int (*request_region)(void *);
182 int (*release_region)(void *);
183 void *(*setup_region)(void);
184 enum ion_memory_types memory_type;
185};
186
187#ifdef CONFIG_ION
188/**
189 * msm_ion_secure_heap - secure a heap. Wrapper around ion_secure_heap.
190 *
191 * @heap_id - heap id to secure.
192 *
193 * Secure a heap
194 * Returns 0 on success
195 */
196int msm_ion_secure_heap(int heap_id);
197
198/**
199 * msm_ion_unsecure_heap - unsecure a heap. Wrapper around ion_unsecure_heap.
200 *
201 * @heap_id - heap id to secure.
202 *
203 * Un-secure a heap
204 * Returns 0 on success
205 */
206int msm_ion_unsecure_heap(int heap_id);
207
208/**
209 * msm_ion_secure_heap_2_0 - secure a heap using 2.0 APIs
210 * Wrapper around ion_secure_heap.
211 *
212 * @heap_id - heap id to secure.
213 * @usage - usage hint to TZ
214 *
215 * Secure a heap
216 * Returns 0 on success
217 */
218int msm_ion_secure_heap_2_0(int heap_id, enum cp_mem_usage usage);
219
220/**
221 * msm_ion_unsecure_heap - unsecure a heap secured with 3.0 APIs.
222 * Wrapper around ion_unsecure_heap.
223 *
224 * @heap_id - heap id to secure.
225 * @usage - usage hint to TZ
226 *
227 * Un-secure a heap
228 * Returns 0 on success
229 */
230int msm_ion_unsecure_heap_2_0(int heap_id, enum cp_mem_usage usage);
231#else
232static inline int msm_ion_secure_heap(int heap_id)
233{
234 return -ENODEV;
235
236}
237
238static inline int msm_ion_unsecure_heap(int heap_id)
239{
240 return -ENODEV;
241}
242
243static inline int msm_ion_secure_heap_2_0(int heap_id, enum cp_mem_usage usage)
244{
245 return -ENODEV;
246}
247
248static inline int msm_ion_unsecure_heap_2_0(int heap_id,
249 enum cp_mem_usage usage)
250{
251 return -ENODEV;
252}
253#endif /* CONFIG_ION */
254
255#endif /* __KERNEL */
256
257/* struct ion_flush_data - data passed to ion for flushing caches
258 *
259 * @handle: handle with data to flush
260 * @fd: fd to flush
261 * @vaddr: userspace virtual address mapped with mmap
262 * @offset: offset into the handle to flush
263 * @length: length of handle to flush
264 *
265 * Performs cache operations on the handle. If p is the start address
266 * of the handle, p + offset through p + offset + length will have
267 * the cache operations performed
268 */
269struct ion_flush_data {
270 struct ion_handle *handle;
271 int fd;
272 void *vaddr;
273 unsigned int offset;
274 unsigned int length;
275};
276
277/* struct ion_flag_data - information about flags for this buffer
278 *
279 * @handle: handle to get flags from
280 * @flags: flags of this handle
281 *
282 * Takes handle as an input and outputs the flags from the handle
283 * in the flag field.
284 */
285struct ion_flag_data {
286 struct ion_handle *handle;
287 unsigned long flags;
288};
289
290#define ION_IOC_MSM_MAGIC 'M'
291
292/**
293 * DOC: ION_IOC_CLEAN_CACHES - clean the caches
294 *
295 * Clean the caches of the handle specified.
296 */
297#define ION_IOC_CLEAN_CACHES _IOWR(ION_IOC_MSM_MAGIC, 0, \
298 struct ion_flush_data)
299/**
300 * DOC: ION_IOC_INV_CACHES - invalidate the caches
301 *
302 * Invalidate the caches of the handle specified.
303 */
304#define ION_IOC_INV_CACHES _IOWR(ION_IOC_MSM_MAGIC, 1, \
305 struct ion_flush_data)
306/**
307 * DOC: ION_IOC_CLEAN_INV_CACHES - clean and invalidate the caches
308 *
309 * Clean and invalidate the caches of the handle specified.
310 */
311#define ION_IOC_CLEAN_INV_CACHES _IOWR(ION_IOC_MSM_MAGIC, 2, \
312 struct ion_flush_data)
313
314/**
315 * DOC: ION_IOC_GET_FLAGS - get the flags of the handle
316 *
317 * Gets the flags of the current handle which indicate cachability,
318 * secure state etc.
319 */
320#define ION_IOC_GET_FLAGS _IOWR(ION_IOC_MSM_MAGIC, 3, \
321 struct ion_flag_data)
322
Laura Abbott6438e532012-07-20 10:10:41 -0700323#endif