import PULS_20160108
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / drivers / staging / android / uapi / ion.h
1 /*
2 * drivers/staging/android/uapi/ion.h
3 *
4 * Copyright (C) 2011 Google, Inc.
5 *
6 * This software is licensed under the terms of the GNU General Public
7 * License version 2, as published by the Free Software Foundation, and
8 * may be copied, distributed, and modified under those terms.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 */
16
17 #ifndef _UAPI_LINUX_ION_H
18 #define _UAPI_LINUX_ION_H
19
20 #include <linux/ioctl.h>
21 #include <linux/types.h>
22
23 typedef int ion_user_handle_t;
24
25 /**
26 * enum ion_heap_types - list of all possible types of heaps
27 * @ION_HEAP_TYPE_SYSTEM: memory allocated via vmalloc
28 * @ION_HEAP_TYPE_SYSTEM_CONTIG: memory allocated via kmalloc
29 * @ION_HEAP_TYPE_CARVEOUT: memory allocated from a prereserved
30 * carveout heap, allocations are physically
31 * contiguous
32 * @ION_HEAP_TYPE_DMA: memory allocated via DMA API
33 * @ION_NUM_HEAPS: helper for iterating over heaps, a bit mask
34 * is used to identify the heaps, so only 32
35 * total heap types are supported
36 */
37 enum ion_heap_type {
38 ION_HEAP_TYPE_SYSTEM,
39 ION_HEAP_TYPE_SYSTEM_CONTIG,
40 ION_HEAP_TYPE_CARVEOUT,
41 ION_HEAP_TYPE_CHUNK,
42 ION_HEAP_TYPE_DMA,
43 ION_HEAP_TYPE_CUSTOM, /* must be last so device specific heaps always
44 are at the end of this enum */
45 ION_NUM_HEAPS = 16,
46 };
47
48 #define ION_HEAP_SYSTEM_MASK (1 << ION_HEAP_TYPE_SYSTEM)
49 #define ION_HEAP_SYSTEM_CONTIG_MASK (1 << ION_HEAP_TYPE_SYSTEM_CONTIG)
50 #define ION_HEAP_CARVEOUT_MASK (1 << ION_HEAP_TYPE_CARVEOUT)
51 #define ION_HEAP_TYPE_DMA_MASK (1 << ION_HEAP_TYPE_DMA)
52
53 /**
54 * allocation flags - the lower 16 bits are used by core ion, the upper 16
55 * bits are reserved for use by the heaps themselves.
56 */
57 #define ION_FLAG_CACHED 1 /* mappings of this buffer should be
58 cached, ion will do cache
59 maintenance when the buffer is
60 mapped for dma */
61 #define ION_FLAG_CACHED_NEEDS_SYNC 2 /* mappings of this buffer will created
62 at mmap time, if this is set
63 caches must be managed manually */
64
65 /**
66 * DOC: Ion Userspace API
67 *
68 * create a client by opening /dev/ion
69 * most operations handled via following ioctls
70 *
71 */
72
73 /**
74 * struct ion_allocation_data - metadata passed from userspace for allocations
75 * @len: size of the allocation
76 * @align: required alignment of the allocation
77 * @heap_id_mask: mask of heap ids to allocate from
78 * @flags: flags passed to heap
79 * @handle: pointer that will be populated with a cookie to use to
80 * refer to this allocation
81 *
82 * Provided by userspace as an argument to the ioctl
83 */
84 struct ion_allocation_data {
85 size_t len;
86 size_t align;
87 unsigned int heap_id_mask;
88 unsigned int flags;
89 ion_user_handle_t handle;
90 };
91
92 /**
93 * struct ion_fd_data - metadata passed to/from userspace for a handle/fd pair
94 * @handle: a handle
95 * @fd: a file descriptor representing that handle
96 *
97 * For ION_IOC_SHARE or ION_IOC_MAP userspace populates the handle field with
98 * the handle returned from ion alloc, and the kernel returns the file
99 * descriptor to share or map in the fd field. For ION_IOC_IMPORT, userspace
100 * provides the file descriptor and the kernel returns the handle.
101 */
102 struct ion_fd_data {
103 ion_user_handle_t handle;
104 int fd;
105 };
106
107 /**
108 * struct ion_handle_data - a handle passed to/from the kernel
109 * @handle: a handle
110 */
111 struct ion_handle_data {
112 ion_user_handle_t handle;
113 };
114
115 /**
116 * struct ion_custom_data - metadata passed to/from userspace for a custom ioctl
117 * @cmd: the custom ioctl function to call
118 * @arg: additional data to pass to the custom ioctl, typically a user
119 * pointer to a predefined structure
120 *
121 * This works just like the regular cmd and arg fields of an ioctl.
122 */
123 struct ion_custom_data {
124 unsigned int cmd;
125 unsigned long arg;
126 };
127
128 #define ION_IOC_MAGIC 'I'
129
130 /**
131 * DOC: ION_IOC_ALLOC - allocate memory
132 *
133 * Takes an ion_allocation_data struct and returns it with the handle field
134 * populated with the opaque handle for the allocation.
135 */
136 #define ION_IOC_ALLOC _IOWR(ION_IOC_MAGIC, 0, \
137 struct ion_allocation_data)
138
139 /**
140 * DOC: ION_IOC_FREE - free memory
141 *
142 * Takes an ion_handle_data struct and frees the handle.
143 */
144 #define ION_IOC_FREE _IOWR(ION_IOC_MAGIC, 1, struct ion_handle_data)
145
146 /**
147 * DOC: ION_IOC_MAP - get a file descriptor to mmap
148 *
149 * Takes an ion_fd_data struct with the handle field populated with a valid
150 * opaque handle. Returns the struct with the fd field set to a file
151 * descriptor open in the current address space. This file descriptor
152 * can then be used as an argument to mmap.
153 */
154 #define ION_IOC_MAP _IOWR(ION_IOC_MAGIC, 2, struct ion_fd_data)
155
156 /**
157 * DOC: ION_IOC_SHARE - creates a file descriptor to use to share an allocation
158 *
159 * Takes an ion_fd_data struct with the handle field populated with a valid
160 * opaque handle. Returns the struct with the fd field set to a file
161 * descriptor open in the current address space. This file descriptor
162 * can then be passed to another process. The corresponding opaque handle can
163 * be retrieved via ION_IOC_IMPORT.
164 */
165 #define ION_IOC_SHARE _IOWR(ION_IOC_MAGIC, 4, struct ion_fd_data)
166
167 /**
168 * DOC: ION_IOC_IMPORT - imports a shared file descriptor
169 *
170 * Takes an ion_fd_data struct with the fd field populated with a valid file
171 * descriptor obtained from ION_IOC_SHARE and returns the struct with the handle
172 * filed set to the corresponding opaque handle.
173 */
174 #define ION_IOC_IMPORT _IOWR(ION_IOC_MAGIC, 5, struct ion_fd_data)
175
176 /**
177 * DOC: ION_IOC_SYNC - syncs a shared file descriptors to memory
178 *
179 * Deprecated in favor of using the dma_buf api's correctly (syncing
180 * will happend automatically when the buffer is mapped to a device).
181 * If necessary should be used after touching a cached buffer from the cpu,
182 * this will make the buffer in memory coherent.
183 */
184 #define ION_IOC_SYNC _IOWR(ION_IOC_MAGIC, 7, struct ion_fd_data)
185
186 /**
187 * DOC: ION_IOC_CUSTOM - call architecture specific ion ioctl
188 *
189 * Takes the argument of the architecture specific ioctl to call and
190 * passes appropriate userdata for that ioctl
191 */
192 #define ION_IOC_CUSTOM _IOWR(ION_IOC_MAGIC, 6, struct ion_custom_data)
193
194 #endif /* _UAPI_LINUX_ION_H */