blob: fa5017aef728242c9559e800da8911d1be848ce2 [file] [log] [blame]
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -07001/*
2 * include/linux/ion.h
3 *
4 * Copyright (C) 2011 Google, Inc.
Olav Haugan0a852512012-01-09 10:20:55 -08005 * Copyright (c) 2011-2012, Code Aurora Forum. All rights reserved.
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -07006 *
7 * This software is licensed under the terms of the GNU General Public
8 * License version 2, as published by the Free Software Foundation, and
9 * may be copied, distributed, and modified under those terms.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 */
17
18#ifndef _LINUX_ION_H
19#define _LINUX_ION_H
20
Laura Abbottabcb6f72011-10-04 16:26:49 -070021#include <linux/ioctl.h>
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -070022#include <linux/types.h>
23
Laura Abbottabcb6f72011-10-04 16:26:49 -070024
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -070025struct ion_handle;
26/**
27 * enum ion_heap_types - list of all possible types of heaps
Iliyan Malchevf22301562011-07-06 16:53:21 -070028 * @ION_HEAP_TYPE_SYSTEM: memory allocated via vmalloc
29 * @ION_HEAP_TYPE_SYSTEM_CONTIG: memory allocated via kmalloc
30 * @ION_HEAP_TYPE_CARVEOUT: memory allocated from a prereserved
Olav Hauganb5be7992011-11-18 14:29:02 -080031 * carveout heap, allocations are physically
32 * contiguous
Olav Haugan0a852512012-01-09 10:20:55 -080033 * @ION_HEAP_TYPE_IOMMU: IOMMU memory
34 * @ION_HEAP_TYPE_CP: memory allocated from a prereserved
35 * carveout heap, allocations are physically
36 * contiguous. Used for content protection.
37 * @ION_HEAP_END: helper for iterating over heaps
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -070038 */
39enum ion_heap_type {
40 ION_HEAP_TYPE_SYSTEM,
41 ION_HEAP_TYPE_SYSTEM_CONTIG,
42 ION_HEAP_TYPE_CARVEOUT,
Laura Abbott8c017362011-09-22 20:59:12 -070043 ION_HEAP_TYPE_IOMMU,
Olav Haugan0a852512012-01-09 10:20:55 -080044 ION_HEAP_TYPE_CP,
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -070045 ION_HEAP_TYPE_CUSTOM, /* must be last so device specific heaps always
46 are at the end of this enum */
Rebecca Schultz Zavine6ee1242011-06-30 12:19:55 -070047 ION_NUM_HEAPS,
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -070048};
49
Iliyan Malchevf22301562011-07-06 16:53:21 -070050#define ION_HEAP_SYSTEM_MASK (1 << ION_HEAP_TYPE_SYSTEM)
51#define ION_HEAP_SYSTEM_CONTIG_MASK (1 << ION_HEAP_TYPE_SYSTEM_CONTIG)
52#define ION_HEAP_CARVEOUT_MASK (1 << ION_HEAP_TYPE_CARVEOUT)
Olav Haugan0a852512012-01-09 10:20:55 -080053#define ION_HEAP_CP_MASK (1 << ION_HEAP_TYPE_CP)
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -070054
Laura Abbotta2e93632011-08-19 13:36:32 -070055
56/**
57 * These are the only ids that should be used for Ion heap ids.
58 * The ids listed are the order in which allocation will be attempted
59 * if specified. Don't swap the order of heap ids unless you know what
60 * you are doing!
Olav Hauganb5be7992011-11-18 14:29:02 -080061 * Id's are spaced by purpose to allow new Id's to be inserted in-between (for
62 * possible fallbacks)
Laura Abbotta2e93632011-08-19 13:36:32 -070063 */
64
65enum ion_heap_ids {
Olav Hauganb5be7992011-11-18 14:29:02 -080066 ION_IOMMU_HEAP_ID = 4,
67 ION_CP_MM_HEAP_ID = 8,
68 ION_CP_MFC_HEAP_ID = 12,
69 ION_CP_WB_HEAP_ID = 16, /* 8660 only */
70 ION_CAMERA_HEAP_ID = 20, /* 8660 only */
71 ION_SF_HEAP_ID = 24,
72 ION_AUDIO_HEAP_ID = 28,
73
74 ION_SYSTEM_HEAP_ID = 30,
75
76 ION_HEAP_ID_RESERVED = 31 /** Bit reserved for ION_SECURE flag */
Laura Abbotta2e93632011-08-19 13:36:32 -070077};
78
Olav Hauganb5be7992011-11-18 14:29:02 -080079/**
80 * Flag to use when allocating to indicate that a heap is secure.
81 */
82#define ION_SECURE (1 << ION_HEAP_ID_RESERVED)
83
84/**
85 * Macro should be used with ion_heap_ids defined above.
86 */
87#define ION_HEAP(bit) (1 << (bit))
88
Laura Abbotta2e93632011-08-19 13:36:32 -070089#define ION_VMALLOC_HEAP_NAME "vmalloc"
Olav Hauganb5be7992011-11-18 14:29:02 -080090#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"
Laura Abbott8c017362011-09-22 20:59:12 -070094#define ION_IOMMU_HEAP_NAME "iommu"
Olav Hauganb5be7992011-11-18 14:29:02 -080095#define ION_MFC_HEAP_NAME "mfc"
96#define ION_WB_HEAP_NAME "wb"
Laura Abbotta2e93632011-08-19 13:36:32 -070097
Laura Abbott894fd582011-08-19 13:33:56 -070098#define CACHED 1
99#define UNCACHED 0
100
101#define ION_CACHE_SHIFT 0
102
103#define ION_SET_CACHE(__cache) ((__cache) << ION_CACHE_SHIFT)
104
Laura Abbott35412032011-09-29 09:50:06 -0700105#define ION_IS_CACHED(__flags) ((__flags) & (1 << ION_CACHE_SHIFT))
106
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700107#ifdef __KERNEL__
Laura Abbott65576962011-10-31 12:13:25 -0700108#include <linux/err.h>
Laura Abbottcffdff52011-09-23 10:40:19 -0700109#include <mach/ion.h>
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700110struct ion_device;
111struct ion_heap;
112struct ion_mapper;
113struct ion_client;
114struct ion_buffer;
115
116/* This should be removed some day when phys_addr_t's are fully
117 plumbed in the kernel, and all instances of ion_phys_addr_t should
118 be converted to phys_addr_t. For the time being many kernel interfaces
119 do not accept phys_addr_t's that would have to */
120#define ion_phys_addr_t unsigned long
121
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700122/**
123 * struct ion_platform_heap - defines a heap in the given platform
124 * @type: type of the heap from ion_heap_type enum
Olav Hauganee0f7802011-12-19 13:28:57 -0800125 * @id: unique identifier for heap. When allocating (lower numbers
Olav Hauganb5be7992011-11-18 14:29:02 -0800126 * will be allocated from first)
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700127 * @name: used for debug purposes
128 * @base: base address of heap in physical memory if applicable
129 * @size: size of the heap in bytes if applicable
Olav Haugan0a852512012-01-09 10:20:55 -0800130 * @memory_type: Memory type used for the heap
131 * @ion_memory_id: Memory ID used to identify the memory to TZ
Alex Bird8a3ede32011-11-07 12:33:42 -0800132 * @request_region: function to be called when the number of allocations goes
133 * from 0 -> 1
134 * @release_region: function to be called when the number of allocations goes
135 * from 1 -> 0
136 * @setup_region: function to be called upon ion registration
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700137 *
138 * Provided by the board file.
139 */
140struct ion_platform_heap {
141 enum ion_heap_type type;
Rebecca Schultz Zavine6ee1242011-06-30 12:19:55 -0700142 unsigned int id;
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700143 const char *name;
144 ion_phys_addr_t base;
145 size_t size;
Laura Abbotta2e93632011-08-19 13:36:32 -0700146 enum ion_memory_types memory_type;
Olav Haugan0703dbf2011-12-19 17:53:38 -0800147 void *extra_data;
148};
149
150struct ion_cp_heap_pdata {
Olav Haugan0a852512012-01-09 10:20:55 -0800151 enum ion_permission_type permission_type;
Olav Hauganee0f7802011-12-19 13:28:57 -0800152 int (*request_region)(void *);
153 int (*release_region)(void *);
Alex Bird8a3ede32011-11-07 12:33:42 -0800154 void *(*setup_region)(void);
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700155};
156
Olav Haugan0703dbf2011-12-19 17:53:38 -0800157struct ion_co_heap_pdata {
158 int (*request_region)(void *);
159 int (*release_region)(void *);
160 void *(*setup_region)(void);
161};
162
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700163/**
164 * struct ion_platform_data - array of platform heaps passed from board file
Alex Bird27ca6612011-11-01 14:40:06 -0700165 * @nr: number of structures in the array
166 * @request_region: function to be called when the number of allocations goes
167 * from 0 -> 1
168 * @release_region: function to be called when the number of allocations goes
169 * from 1 -> 0
170 * @setup_region: function to be called upon ion registration
171 * @heaps: array of platform_heap structions
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700172 *
173 * Provided by the board file in the form of platform data to a platform device.
174 */
175struct ion_platform_data {
176 int nr;
Olav Hauganee0f7802011-12-19 13:28:57 -0800177 int (*request_region)(void *);
178 int (*release_region)(void *);
Alex Bird27ca6612011-11-01 14:40:06 -0700179 void *(*setup_region)(void);
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700180 struct ion_platform_heap heaps[];
181};
182
Jordan Crouse8cd48322011-10-12 17:05:19 -0600183#ifdef CONFIG_ION
184
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700185/**
186 * ion_client_create() - allocate a client and returns it
187 * @dev: the global ion device
188 * @heap_mask: mask of heaps this client can allocate from
189 * @name: used for debugging
190 */
191struct ion_client *ion_client_create(struct ion_device *dev,
192 unsigned int heap_mask, const char *name);
193
194/**
Laura Abbott302911d2011-08-15 17:12:57 -0700195 * msm_ion_client_create - allocate a client using the ion_device specified in
196 * drivers/gpu/ion/msm/msm_ion.c
197 *
198 * heap_mask and name are the same as ion_client_create, return values
199 * are the same as ion_client_create.
200 */
201
202struct ion_client *msm_ion_client_create(unsigned int heap_mask,
203 const char *name);
204
205/**
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700206 * ion_client_destroy() - free's a client and all it's handles
207 * @client: the client
208 *
209 * Free the provided client and all it's resources including
210 * any handles it is holding.
211 */
212void ion_client_destroy(struct ion_client *client);
213
214/**
215 * ion_alloc - allocate ion memory
216 * @client: the client
217 * @len: size of the allocation
218 * @align: requested allocation alignment, lots of hardware blocks have
219 * alignment requirements of some kind
Rebecca Schultz Zavine6ee1242011-06-30 12:19:55 -0700220 * @flags: mask of heaps to allocate from, if multiple bits are set
221 * heaps will be tried in order from lowest to highest order bit
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700222 *
223 * Allocate memory in one of the heaps provided in heap mask and return
224 * an opaque handle to it.
225 */
226struct ion_handle *ion_alloc(struct ion_client *client, size_t len,
227 size_t align, unsigned int flags);
228
229/**
230 * ion_free - free a handle
231 * @client: the client
232 * @handle: the handle to free
233 *
234 * Free the provided handle.
235 */
236void ion_free(struct ion_client *client, struct ion_handle *handle);
237
238/**
239 * ion_phys - returns the physical address and len of a handle
240 * @client: the client
241 * @handle: the handle
242 * @addr: a pointer to put the address in
243 * @len: a pointer to put the length in
244 *
245 * This function queries the heap for a particular handle to get the
246 * handle's physical address. It't output is only correct if
247 * a heap returns physically contiguous memory -- in other cases
248 * this api should not be implemented -- ion_map_dma should be used
249 * instead. Returns -EINVAL if the handle is invalid. This has
250 * no implications on the reference counting of the handle --
251 * the returned value may not be valid if the caller is not
252 * holding a reference.
253 */
254int ion_phys(struct ion_client *client, struct ion_handle *handle,
255 ion_phys_addr_t *addr, size_t *len);
256
257/**
258 * ion_map_kernel - create mapping for the given handle
259 * @client: the client
260 * @handle: handle to map
Laura Abbott894fd582011-08-19 13:33:56 -0700261 * @flags: flags for this mapping
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700262 *
263 * Map the given handle into the kernel and return a kernel address that
Laura Abbott894fd582011-08-19 13:33:56 -0700264 * can be used to access this address. If no flags are specified, this
265 * will return a non-secure uncached mapping.
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700266 */
Laura Abbott894fd582011-08-19 13:33:56 -0700267void *ion_map_kernel(struct ion_client *client, struct ion_handle *handle,
268 unsigned long flags);
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700269
270/**
271 * ion_unmap_kernel() - destroy a kernel mapping for a handle
272 * @client: the client
273 * @handle: handle to unmap
274 */
275void ion_unmap_kernel(struct ion_client *client, struct ion_handle *handle);
276
277/**
278 * ion_map_dma - create a dma mapping for a given handle
279 * @client: the client
280 * @handle: handle to map
281 *
282 * Return an sglist describing the given handle
283 */
284struct scatterlist *ion_map_dma(struct ion_client *client,
Laura Abbott894fd582011-08-19 13:33:56 -0700285 struct ion_handle *handle,
286 unsigned long flags);
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700287
288/**
289 * ion_unmap_dma() - destroy a dma mapping for a handle
290 * @client: the client
291 * @handle: handle to unmap
292 */
293void ion_unmap_dma(struct ion_client *client, struct ion_handle *handle);
294
295/**
296 * ion_share() - given a handle, obtain a buffer to pass to other clients
297 * @client: the client
298 * @handle: the handle to share
299 *
Iliyan Malchev3fe24362011-08-09 14:42:08 -0700300 * Given a handle, return a buffer, which exists in a global name
301 * space, and can be passed to other clients. Should be passed into ion_import
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700302 * to obtain a new handle for this buffer.
Iliyan Malchev3fe24362011-08-09 14:42:08 -0700303 *
304 * NOTE: This function does do not an extra reference. The burden is on the
305 * caller to make sure the buffer doesn't go away while it's being passed to
306 * another client. That is, ion_free should not be called on this handle until
307 * the buffer has been imported into the other client.
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700308 */
309struct ion_buffer *ion_share(struct ion_client *client,
310 struct ion_handle *handle);
311
312/**
313 * ion_import() - given an buffer in another client, import it
314 * @client: this blocks client
315 * @buffer: the buffer to import (as obtained from ion_share)
316 *
317 * Given a buffer, add it to the client and return the handle to use to refer
318 * to it further. This is called to share a handle from one kernel client to
319 * another.
320 */
321struct ion_handle *ion_import(struct ion_client *client,
322 struct ion_buffer *buffer);
323
324/**
325 * ion_import_fd() - given an fd obtained via ION_IOC_SHARE ioctl, import it
326 * @client: this blocks client
327 * @fd: the fd
328 *
329 * A helper function for drivers that will be recieving ion buffers shared
330 * with them from userspace. These buffers are represented by a file
331 * descriptor obtained as the return from the ION_IOC_SHARE ioctl.
332 * This function coverts that fd into the underlying buffer, and returns
333 * the handle to use to refer to it further.
334 */
335struct ion_handle *ion_import_fd(struct ion_client *client, int fd);
Laura Abbott273dd8e2011-10-12 14:26:33 -0700336
Laura Abbott273dd8e2011-10-12 14:26:33 -0700337/**
338 * ion_handle_get_flags - get the flags for a given handle
339 *
340 * @client - client who allocated the handle
341 * @handle - handle to get the flags
342 * @flags - pointer to store the flags
343 *
344 * Gets the current flags for a handle. These flags indicate various options
345 * of the buffer (caching, security, etc.)
346 */
347int ion_handle_get_flags(struct ion_client *client, struct ion_handle *handle,
348 unsigned long *flags);
349
Laura Abbott8c017362011-09-22 20:59:12 -0700350
351/**
352 * ion_map_iommu - map the given handle into an iommu
353 *
354 * @client - client who allocated the handle
355 * @handle - handle to map
356 * @domain_num - domain number to map to
357 * @partition_num - partition number to allocate iova from
358 * @align - alignment for the iova
359 * @iova_length - length of iova to map. If the iova length is
360 * greater than the handle length, the remaining
361 * address space will be mapped to a dummy buffer.
362 * @iova - pointer to store the iova address
363 * @buffer_size - pointer to store the size of the buffer
364 * @flags - flags for options to map
365 *
366 * Maps the handle into the iova space specified via domain number. Iova
367 * will be allocated from the partition specified via partition_num.
368 * Returns 0 on success, negative value on error.
369 */
370int ion_map_iommu(struct ion_client *client, struct ion_handle *handle,
371 int domain_num, int partition_num, unsigned long align,
372 unsigned long iova_length, unsigned long *iova,
373 unsigned long *buffer_size,
374 unsigned long flags);
375
376
377/**
378 * ion_handle_get_size - get the allocated size of a given handle
379 *
380 * @client - client who allocated the handle
381 * @handle - handle to get the size
382 * @size - pointer to store the size
383 *
384 * gives the allocated size of a handle. returns 0 on success, negative
385 * value on error
386 *
387 * NOTE: This is intended to be used only to get a size to pass to map_iommu.
388 * You should *NOT* rely on this for any other usage.
389 */
390
391int ion_handle_get_size(struct ion_client *client, struct ion_handle *handle,
392 unsigned long *size);
393
394/**
395 * ion_unmap_iommu - unmap the handle from an iommu
396 *
397 * @client - client who allocated the handle
398 * @handle - handle to unmap
399 * @domain_num - domain to unmap from
400 * @partition_num - partition to unmap from
401 *
402 * Decrement the reference count on the iommu mapping. If the count is
403 * 0, the mapping will be removed from the iommu.
404 */
405void ion_unmap_iommu(struct ion_client *client, struct ion_handle *handle,
406 int domain_num, int partition_num);
407
408
Olav Haugan0a852512012-01-09 10:20:55 -0800409/**
410 * ion_secure_heap - secure a heap
411 *
412 * @client - a client that has allocated from the heap heap_id
413 * @heap_id - heap id to secure.
414 *
415 * Secure a heap
416 * Returns 0 on success
417 */
418int ion_secure_heap(struct ion_device *dev, int heap_id);
419
420/**
421 * ion_unsecure_heap - un-secure a heap
422 *
423 * @client - a client that has allocated from the heap heap_id
424 * @heap_id - heap id to un-secure.
425 *
426 * Un-secure a heap
427 * Returns 0 on success
428 */
429int ion_unsecure_heap(struct ion_device *dev, int heap_id);
430
431/**
432 * msm_ion_secure_heap - secure a heap. Wrapper around ion_secure_heap.
433 *
434 * @heap_id - heap id to secure.
435 *
436 * Secure a heap
437 * Returns 0 on success
438 */
439int msm_ion_secure_heap(int heap_id);
440
441/**
442 * msm_ion_unsecure_heap - unsecure a heap. Wrapper around ion_unsecure_heap.
443 *
444 * @heap_id - heap id to secure.
445 *
446 * Un-secure a heap
447 * Returns 0 on success
448 */
449int msm_ion_unsecure_heap(int heap_id);
450
Jordan Crouse8cd48322011-10-12 17:05:19 -0600451#else
452static inline struct ion_client *ion_client_create(struct ion_device *dev,
453 unsigned int heap_mask, const char *name)
454{
455 return ERR_PTR(-ENODEV);
456}
Laura Abbott273dd8e2011-10-12 14:26:33 -0700457
Jordan Crouse8cd48322011-10-12 17:05:19 -0600458static inline struct ion_client *msm_ion_client_create(unsigned int heap_mask,
459 const char *name)
460{
461 return ERR_PTR(-ENODEV);
462}
463
464static inline void ion_client_destroy(struct ion_client *client) { }
465
466static inline struct ion_handle *ion_alloc(struct ion_client *client,
467 size_t len, size_t align, unsigned int flags)
468{
469 return ERR_PTR(-ENODEV);
470}
471
472static inline void ion_free(struct ion_client *client,
473 struct ion_handle *handle) { }
474
475
476static inline int ion_phys(struct ion_client *client,
477 struct ion_handle *handle, ion_phys_addr_t *addr, size_t *len)
478{
479 return -ENODEV;
480}
481
482static inline void *ion_map_kernel(struct ion_client *client,
483 struct ion_handle *handle, unsigned long flags)
484{
485 return ERR_PTR(-ENODEV);
486}
487
488static inline void ion_unmap_kernel(struct ion_client *client,
489 struct ion_handle *handle) { }
490
491static inline struct scatterlist *ion_map_dma(struct ion_client *client,
492 struct ion_handle *handle, unsigned long flags)
493{
494 return ERR_PTR(-ENODEV);
495}
496
497static inline void ion_unmap_dma(struct ion_client *client,
498 struct ion_handle *handle) { }
499
500static inline struct ion_buffer *ion_share(struct ion_client *client,
501 struct ion_handle *handle)
502{
503 return ERR_PTR(-ENODEV);
504}
505
506static inline struct ion_handle *ion_import(struct ion_client *client,
507 struct ion_buffer *buffer)
508{
509 return ERR_PTR(-ENODEV);
510}
511
512static inline struct ion_handle *ion_import_fd(struct ion_client *client,
513 int fd)
514{
515 return ERR_PTR(-ENODEV);
516}
517
518static inline int ion_handle_get_flags(struct ion_client *client,
519 struct ion_handle *handle, unsigned long *flags)
520{
521 return -ENODEV;
522}
Laura Abbott8c017362011-09-22 20:59:12 -0700523
524static inline int ion_map_iommu(struct ion_client *client,
525 struct ion_handle *handle, int domain_num,
526 int partition_num, unsigned long align,
527 unsigned long iova_length, unsigned long *iova,
528 unsigned long flags)
529{
530 return -ENODEV;
531}
532
533static inline void ion_unmap_iommu(struct ion_client *client,
534 struct ion_handle *handle, int domain_num,
535 int partition_num)
536{
537 return;
538}
539
Olav Haugan0a852512012-01-09 10:20:55 -0800540static inline int ion_secure_heap(struct ion_device *dev, int heap_id)
541{
542 return -ENODEV;
Laura Abbott8c017362011-09-22 20:59:12 -0700543
Olav Haugan0a852512012-01-09 10:20:55 -0800544}
545
546static inline int ion_unsecure_heap(struct ion_device *dev, int heap_id)
547{
548 return -ENODEV;
549}
550
551static inline int msm_ion_secure_heap(int heap_id)
552{
553 return -ENODEV;
554
555}
556
557static inline int msm_ion_unsecure_heap(int heap_id)
558{
559 return -ENODEV;
560}
Jordan Crouse8cd48322011-10-12 17:05:19 -0600561#endif /* CONFIG_ION */
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700562#endif /* __KERNEL__ */
563
564/**
565 * DOC: Ion Userspace API
566 *
567 * create a client by opening /dev/ion
568 * most operations handled via following ioctls
569 *
570 */
571
572/**
573 * struct ion_allocation_data - metadata passed from userspace for allocations
574 * @len: size of the allocation
575 * @align: required alignment of the allocation
576 * @flags: flags passed to heap
577 * @handle: pointer that will be populated with a cookie to use to refer
578 * to this allocation
579 *
580 * Provided by userspace as an argument to the ioctl
581 */
582struct ion_allocation_data {
583 size_t len;
584 size_t align;
585 unsigned int flags;
586 struct ion_handle *handle;
587};
588
589/**
590 * struct ion_fd_data - metadata passed to/from userspace for a handle/fd pair
591 * @handle: a handle
592 * @fd: a file descriptor representing that handle
593 *
594 * For ION_IOC_SHARE or ION_IOC_MAP userspace populates the handle field with
595 * the handle returned from ion alloc, and the kernel returns the file
596 * descriptor to share or map in the fd field. For ION_IOC_IMPORT, userspace
597 * provides the file descriptor and the kernel returns the handle.
598 */
599struct ion_fd_data {
600 struct ion_handle *handle;
601 int fd;
602};
603
604/**
605 * struct ion_handle_data - a handle passed to/from the kernel
606 * @handle: a handle
607 */
608struct ion_handle_data {
609 struct ion_handle *handle;
610};
611
Rebecca Schultz Zavine6ee1242011-06-30 12:19:55 -0700612/**
613 * struct ion_custom_data - metadata passed to/from userspace for a custom ioctl
614 * @cmd: the custom ioctl function to call
615 * @arg: additional data to pass to the custom ioctl, typically a user
616 * pointer to a predefined structure
617 *
618 * This works just like the regular cmd and arg fields of an ioctl.
619 */
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700620struct ion_custom_data {
621 unsigned int cmd;
622 unsigned long arg;
623};
624
Laura Abbottabcb6f72011-10-04 16:26:49 -0700625
626/* struct ion_flush_data - data passed to ion for flushing caches
627 *
628 * @handle: handle with data to flush
Laura Abbotte80ea012011-11-18 18:36:47 -0800629 * @fd: fd to flush
Laura Abbottabcb6f72011-10-04 16:26:49 -0700630 * @vaddr: userspace virtual address mapped with mmap
631 * @offset: offset into the handle to flush
632 * @length: length of handle to flush
633 *
634 * Performs cache operations on the handle. If p is the start address
635 * of the handle, p + offset through p + offset + length will have
636 * the cache operations performed
637 */
638struct ion_flush_data {
639 struct ion_handle *handle;
Laura Abbotte80ea012011-11-18 18:36:47 -0800640 int fd;
Laura Abbottabcb6f72011-10-04 16:26:49 -0700641 void *vaddr;
642 unsigned int offset;
643 unsigned int length;
644};
Laura Abbott273dd8e2011-10-12 14:26:33 -0700645
646/* struct ion_flag_data - information about flags for this buffer
647 *
648 * @handle: handle to get flags from
649 * @flags: flags of this handle
650 *
651 * Takes handle as an input and outputs the flags from the handle
652 * in the flag field.
653 */
654struct ion_flag_data {
655 struct ion_handle *handle;
656 unsigned long flags;
657};
658
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700659#define ION_IOC_MAGIC 'I'
660
661/**
662 * DOC: ION_IOC_ALLOC - allocate memory
663 *
664 * Takes an ion_allocation_data struct and returns it with the handle field
665 * populated with the opaque handle for the allocation.
666 */
667#define ION_IOC_ALLOC _IOWR(ION_IOC_MAGIC, 0, \
668 struct ion_allocation_data)
669
670/**
671 * DOC: ION_IOC_FREE - free memory
672 *
673 * Takes an ion_handle_data struct and frees the handle.
674 */
675#define ION_IOC_FREE _IOWR(ION_IOC_MAGIC, 1, struct ion_handle_data)
676
677/**
678 * DOC: ION_IOC_MAP - get a file descriptor to mmap
679 *
680 * Takes an ion_fd_data struct with the handle field populated with a valid
681 * opaque handle. Returns the struct with the fd field set to a file
682 * descriptor open in the current address space. This file descriptor
683 * can then be used as an argument to mmap.
684 */
685#define ION_IOC_MAP _IOWR(ION_IOC_MAGIC, 2, struct ion_fd_data)
686
687/**
688 * DOC: ION_IOC_SHARE - creates a file descriptor to use to share an allocation
689 *
690 * Takes an ion_fd_data struct with the handle field populated with a valid
691 * opaque handle. Returns the struct with the fd field set to a file
692 * descriptor open in the current address space. This file descriptor
693 * can then be passed to another process. The corresponding opaque handle can
694 * be retrieved via ION_IOC_IMPORT.
695 */
696#define ION_IOC_SHARE _IOWR(ION_IOC_MAGIC, 4, struct ion_fd_data)
697
698/**
699 * DOC: ION_IOC_IMPORT - imports a shared file descriptor
700 *
701 * Takes an ion_fd_data struct with the fd field populated with a valid file
702 * descriptor obtained from ION_IOC_SHARE and returns the struct with the handle
703 * filed set to the corresponding opaque handle.
704 */
705#define ION_IOC_IMPORT _IOWR(ION_IOC_MAGIC, 5, int)
706
707/**
708 * DOC: ION_IOC_CUSTOM - call architecture specific ion ioctl
709 *
710 * Takes the argument of the architecture specific ioctl to call and
711 * passes appropriate userdata for that ioctl
712 */
713#define ION_IOC_CUSTOM _IOWR(ION_IOC_MAGIC, 6, struct ion_custom_data)
714
Laura Abbottabcb6f72011-10-04 16:26:49 -0700715
716/**
717 * DOC: ION_IOC_CLEAN_CACHES - clean the caches
718 *
719 * Clean the caches of the handle specified.
720 */
721#define ION_IOC_CLEAN_CACHES _IOWR(ION_IOC_MAGIC, 7, \
722 struct ion_flush_data)
723/**
724 * DOC: ION_MSM_IOC_INV_CACHES - invalidate the caches
725 *
726 * Invalidate the caches of the handle specified.
727 */
728#define ION_IOC_INV_CACHES _IOWR(ION_IOC_MAGIC, 8, \
729 struct ion_flush_data)
730/**
731 * DOC: ION_MSM_IOC_CLEAN_CACHES - clean and invalidate the caches
732 *
733 * Clean and invalidate the caches of the handle specified.
734 */
735#define ION_IOC_CLEAN_INV_CACHES _IOWR(ION_IOC_MAGIC, 9, \
736 struct ion_flush_data)
Laura Abbott273dd8e2011-10-12 14:26:33 -0700737
738/**
739 * DOC: ION_IOC_GET_FLAGS - get the flags of the handle
740 *
741 * Gets the flags of the current handle which indicate cachability,
742 * secure state etc.
743 */
744#define ION_IOC_GET_FLAGS _IOWR(ION_IOC_MAGIC, 10, \
745 struct ion_flag_data)
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700746#endif /* _LINUX_ION_H */