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