blob: 09c584b22ead19084f1bfcddd117c0cf2c8868f6 [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
Laura Abbott5249a052012-12-11 15:09:03 -0800130 * @no_nonsecure_alloc: don't allow non-secure allocations from this heap
Mitchel Humpherysdc4d01d2012-09-13 10:53:22 -0700131 *
132 */
133struct ion_cp_heap_pdata {
134 enum ion_permission_type permission_type;
135 unsigned int align;
136 ion_phys_addr_t secure_base; /* Base addr used when heap is shared */
137 size_t secure_size; /* Size used for securing heap when heap is shared*/
138 int reusable;
139 int mem_is_fmem;
Laura Abbottd3142222012-08-03 17:31:03 -0700140 int is_cma;
Mitchel Humpherysdc4d01d2012-09-13 10:53:22 -0700141 enum ion_fixed_position fixed_position;
142 int iommu_map_all;
143 int iommu_2x_map_domain;
144 ion_virt_addr_t *virt_addr;
145 int (*request_region)(void *);
146 int (*release_region)(void *);
147 void *(*setup_region)(void);
148 enum ion_memory_types memory_type;
Laura Abbott5249a052012-12-11 15:09:03 -0800149 int no_nonsecure_alloc;
Mitchel Humpherysdc4d01d2012-09-13 10:53:22 -0700150};
151
152/**
153 * struct ion_co_heap_pdata - defines a carveout heap in the given platform
154 * @adjacent_mem_id: Id of heap that this heap must be adjacent to.
155 * @align: Alignment requirement for the memory
156 * @mem_is_fmem Flag indicating whether this memory is coming from fmem
157 * or not.
158 * @fixed_position If nonzero, position in the fixed area.
159 * @request_region: function to be called when the number of allocations
160 * goes from 0 -> 1
161 * @release_region: function to be called when the number of allocations
162 * goes from 1 -> 0
163 * @setup_region: function to be called upon ion registration
164 * @memory_type:Memory type used for the heap
165 *
166 */
167struct ion_co_heap_pdata {
168 int adjacent_mem_id;
169 unsigned int align;
170 int mem_is_fmem;
171 enum ion_fixed_position fixed_position;
172 int (*request_region)(void *);
173 int (*release_region)(void *);
174 void *(*setup_region)(void);
175 enum ion_memory_types memory_type;
176};
177
178#ifdef CONFIG_ION
179/**
180 * msm_ion_secure_heap - secure a heap. Wrapper around ion_secure_heap.
181 *
182 * @heap_id - heap id to secure.
183 *
184 * Secure a heap
185 * Returns 0 on success
186 */
187int msm_ion_secure_heap(int heap_id);
188
189/**
190 * msm_ion_unsecure_heap - unsecure a heap. Wrapper around ion_unsecure_heap.
191 *
192 * @heap_id - heap id to secure.
193 *
194 * Un-secure a heap
195 * Returns 0 on success
196 */
197int msm_ion_unsecure_heap(int heap_id);
198
199/**
200 * msm_ion_secure_heap_2_0 - secure a heap using 2.0 APIs
201 * Wrapper around ion_secure_heap.
202 *
203 * @heap_id - heap id to secure.
204 * @usage - usage hint to TZ
205 *
206 * Secure a heap
207 * Returns 0 on success
208 */
209int msm_ion_secure_heap_2_0(int heap_id, enum cp_mem_usage usage);
210
211/**
212 * msm_ion_unsecure_heap - unsecure a heap secured with 3.0 APIs.
213 * Wrapper around ion_unsecure_heap.
214 *
215 * @heap_id - heap id to secure.
216 * @usage - usage hint to TZ
217 *
218 * Un-secure a heap
219 * Returns 0 on success
220 */
221int msm_ion_unsecure_heap_2_0(int heap_id, enum cp_mem_usage usage);
222#else
223static inline int msm_ion_secure_heap(int heap_id)
224{
225 return -ENODEV;
226
227}
228
229static inline int msm_ion_unsecure_heap(int heap_id)
230{
231 return -ENODEV;
232}
233
234static inline int msm_ion_secure_heap_2_0(int heap_id, enum cp_mem_usage usage)
235{
236 return -ENODEV;
237}
238
239static inline int msm_ion_unsecure_heap_2_0(int heap_id,
240 enum cp_mem_usage usage)
241{
242 return -ENODEV;
243}
244#endif /* CONFIG_ION */
245
246#endif /* __KERNEL */
247
248/* struct ion_flush_data - data passed to ion for flushing caches
249 *
250 * @handle: handle with data to flush
251 * @fd: fd to flush
252 * @vaddr: userspace virtual address mapped with mmap
253 * @offset: offset into the handle to flush
254 * @length: length of handle to flush
255 *
256 * Performs cache operations on the handle. If p is the start address
257 * of the handle, p + offset through p + offset + length will have
258 * the cache operations performed
259 */
260struct ion_flush_data {
261 struct ion_handle *handle;
262 int fd;
263 void *vaddr;
264 unsigned int offset;
265 unsigned int length;
266};
267
268/* struct ion_flag_data - information about flags for this buffer
269 *
270 * @handle: handle to get flags from
271 * @flags: flags of this handle
272 *
273 * Takes handle as an input and outputs the flags from the handle
274 * in the flag field.
275 */
276struct ion_flag_data {
277 struct ion_handle *handle;
278 unsigned long flags;
279};
280
281#define ION_IOC_MSM_MAGIC 'M'
282
283/**
284 * DOC: ION_IOC_CLEAN_CACHES - clean the caches
285 *
286 * Clean the caches of the handle specified.
287 */
288#define ION_IOC_CLEAN_CACHES _IOWR(ION_IOC_MSM_MAGIC, 0, \
289 struct ion_flush_data)
290/**
291 * DOC: ION_IOC_INV_CACHES - invalidate the caches
292 *
293 * Invalidate the caches of the handle specified.
294 */
295#define ION_IOC_INV_CACHES _IOWR(ION_IOC_MSM_MAGIC, 1, \
296 struct ion_flush_data)
297/**
298 * DOC: ION_IOC_CLEAN_INV_CACHES - clean and invalidate the caches
299 *
300 * Clean and invalidate the caches of the handle specified.
301 */
302#define ION_IOC_CLEAN_INV_CACHES _IOWR(ION_IOC_MSM_MAGIC, 2, \
303 struct ion_flush_data)
304
305/**
306 * DOC: ION_IOC_GET_FLAGS - get the flags of the handle
307 *
308 * Gets the flags of the current handle which indicate cachability,
309 * secure state etc.
310 */
311#define ION_IOC_GET_FLAGS _IOWR(ION_IOC_MSM_MAGIC, 3, \
312 struct ion_flag_data)
313
Laura Abbott6438e532012-07-20 10:10:41 -0700314#endif