blob: 14cd8738ecfc3a34933085db9c1395f6ae4d889a [file] [log] [blame]
Christopher Ferris6ea19f62013-11-20 19:48:48 -08001/*
Christopher Ferrise0845012014-07-09 14:58:51 -07002 * drivers/staging/android/uapi/ion.h
Christopher Ferris6ea19f62013-11-20 19:48:48 -08003 *
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
Christopher Ferrise0845012014-07-09 14:58:51 -070017#ifndef _UAPI_LINUX_ION_H
18#define _UAPI_LINUX_ION_H
Christopher Ferris6ea19f62013-11-20 19:48:48 -080019
Christopher Ferrise0845012014-07-09 14:58:51 -070020#include <linux/ioctl.h>
Christopher Ferris6ea19f62013-11-20 19:48:48 -080021#include <linux/types.h>
22
Christopher Ferrise0845012014-07-09 14:58:51 -070023typedef int ion_user_handle_t;
24
Christopher Ferris6ea19f62013-11-20 19:48:48 -080025/**
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
Christopher Ferris31475242014-09-02 17:43:51 -070030 * carveout heap, allocations are physically
31 * contiguous
Christopher Ferrise0845012014-07-09 14:58:51 -070032 * @ION_HEAP_TYPE_DMA: memory allocated via DMA API
Christopher Ferris6ea19f62013-11-20 19:48:48 -080033 * @ION_NUM_HEAPS: helper for iterating over heaps, a bit mask
Christopher Ferris31475242014-09-02 17:43:51 -070034 * is used to identify the heaps, so only 32
35 * total heap types are supported
Christopher Ferris6ea19f62013-11-20 19:48:48 -080036 */
37enum ion_heap_type {
38 ION_HEAP_TYPE_SYSTEM,
39 ION_HEAP_TYPE_SYSTEM_CONTIG,
40 ION_HEAP_TYPE_CARVEOUT,
Christopher Ferrise0845012014-07-09 14:58:51 -070041 ION_HEAP_TYPE_CHUNK,
42 ION_HEAP_TYPE_DMA,
Christopher Ferris12e1f282016-02-04 12:35:07 -080043 ION_HEAP_TYPE_CUSTOM, /*
44 * must be last so device specific heaps always
45 * are at the end of this enum
46 */
Christopher Ferris6ea19f62013-11-20 19:48:48 -080047};
48
Christopher Ferris31475242014-09-02 17:43:51 -070049#define ION_NUM_HEAP_IDS (sizeof(unsigned int) * 8)
Christopher Ferris6ea19f62013-11-20 19:48:48 -080050
51/**
Christopher Ferrise0845012014-07-09 14:58:51 -070052 * allocation flags - the lower 16 bits are used by core ion, the upper 16
Christopher Ferris6ea19f62013-11-20 19:48:48 -080053 * bits are reserved for use by the heaps themselves.
54 */
Christopher Ferris33185402017-01-13 13:28:52 -080055
56/*
57 * mappings of this buffer should be cached, ion will do cache maintenance
58 * when the buffer is mapped for dma
59 */
60#define ION_FLAG_CACHED 1
61
62/*
63 * mappings of this buffer will created at mmap time, if this is set
64 * caches must be managed manually
65 */
66#define ION_FLAG_CACHED_NEEDS_SYNC 2
Christopher Ferris6ea19f62013-11-20 19:48:48 -080067
68/**
69 * DOC: Ion Userspace API
70 *
71 * create a client by opening /dev/ion
72 * most operations handled via following ioctls
73 *
74 */
75
76/**
77 * struct ion_allocation_data - metadata passed from userspace for allocations
Christopher Ferrise0845012014-07-09 14:58:51 -070078 * @len: size of the allocation
79 * @align: required alignment of the allocation
80 * @heap_id_mask: mask of heap ids to allocate from
81 * @flags: flags passed to heap
Christopher Ferris31475242014-09-02 17:43:51 -070082 * @handle: pointer that will be populated with a cookie to use to
Christopher Ferrise0845012014-07-09 14:58:51 -070083 * refer to this allocation
Christopher Ferris6ea19f62013-11-20 19:48:48 -080084 *
85 * Provided by userspace as an argument to the ioctl
86 */
87struct ion_allocation_data {
88 size_t len;
89 size_t align;
Christopher Ferrise0845012014-07-09 14:58:51 -070090 unsigned int heap_id_mask;
Christopher Ferris6ea19f62013-11-20 19:48:48 -080091 unsigned int flags;
Christopher Ferrise0845012014-07-09 14:58:51 -070092 ion_user_handle_t handle;
Christopher Ferris6ea19f62013-11-20 19:48:48 -080093};
94
95/**
96 * struct ion_fd_data - metadata passed to/from userspace for a handle/fd pair
97 * @handle: a handle
98 * @fd: a file descriptor representing that handle
99 *
100 * For ION_IOC_SHARE or ION_IOC_MAP userspace populates the handle field with
101 * the handle returned from ion alloc, and the kernel returns the file
102 * descriptor to share or map in the fd field. For ION_IOC_IMPORT, userspace
103 * provides the file descriptor and the kernel returns the handle.
104 */
105struct ion_fd_data {
Christopher Ferrise0845012014-07-09 14:58:51 -0700106 ion_user_handle_t handle;
Christopher Ferris6ea19f62013-11-20 19:48:48 -0800107 int fd;
108};
109
110/**
111 * struct ion_handle_data - a handle passed to/from the kernel
112 * @handle: a handle
113 */
114struct ion_handle_data {
Christopher Ferrise0845012014-07-09 14:58:51 -0700115 ion_user_handle_t handle;
Christopher Ferris6ea19f62013-11-20 19:48:48 -0800116};
117
118/**
119 * struct ion_custom_data - metadata passed to/from userspace for a custom ioctl
120 * @cmd: the custom ioctl function to call
121 * @arg: additional data to pass to the custom ioctl, typically a user
122 * pointer to a predefined structure
123 *
124 * This works just like the regular cmd and arg fields of an ioctl.
125 */
126struct ion_custom_data {
127 unsigned int cmd;
128 unsigned long arg;
129};
130
Christopher Ferris33185402017-01-13 13:28:52 -0800131#define MAX_HEAP_NAME 32
132
133/**
134 * struct ion_heap_data - data about a heap
135 * @name - first 32 characters of the heap name
136 * @type - heap type
137 * @heap_id - heap id for the heap
138 */
139struct ion_heap_data {
140 char name[MAX_HEAP_NAME];
141 __u32 type;
142 __u32 heap_id;
143 __u32 reserved0;
144 __u32 reserved1;
145 __u32 reserved2;
146};
147
148/**
149 * struct ion_heap_query - collection of data about all heaps
150 * @cnt - total number of heaps to be copied
151 * @heaps - buffer to copy heap data
152 */
153struct ion_heap_query {
154 __u32 cnt; /* Total number of heaps to be copied */
155 __u32 reserved0; /* align to 64bits */
156 __u64 heaps; /* buffer to be populated */
157 __u32 reserved1;
158 __u32 reserved2;
159};
160
Christopher Ferris6ea19f62013-11-20 19:48:48 -0800161#define ION_IOC_MAGIC 'I'
162
163/**
164 * DOC: ION_IOC_ALLOC - allocate memory
165 *
166 * Takes an ion_allocation_data struct and returns it with the handle field
167 * populated with the opaque handle for the allocation.
168 */
169#define ION_IOC_ALLOC _IOWR(ION_IOC_MAGIC, 0, \
170 struct ion_allocation_data)
171
172/**
173 * DOC: ION_IOC_FREE - free memory
174 *
175 * Takes an ion_handle_data struct and frees the handle.
176 */
177#define ION_IOC_FREE _IOWR(ION_IOC_MAGIC, 1, struct ion_handle_data)
178
179/**
180 * DOC: ION_IOC_MAP - get a file descriptor to mmap
181 *
182 * Takes an ion_fd_data struct with the handle field populated with a valid
183 * opaque handle. Returns the struct with the fd field set to a file
184 * descriptor open in the current address space. This file descriptor
185 * can then be used as an argument to mmap.
186 */
187#define ION_IOC_MAP _IOWR(ION_IOC_MAGIC, 2, struct ion_fd_data)
188
189/**
190 * DOC: ION_IOC_SHARE - creates a file descriptor to use to share an allocation
191 *
192 * Takes an ion_fd_data struct with the handle field populated with a valid
193 * opaque handle. Returns the struct with the fd field set to a file
194 * descriptor open in the current address space. This file descriptor
195 * can then be passed to another process. The corresponding opaque handle can
196 * be retrieved via ION_IOC_IMPORT.
197 */
198#define ION_IOC_SHARE _IOWR(ION_IOC_MAGIC, 4, struct ion_fd_data)
199
200/**
201 * DOC: ION_IOC_IMPORT - imports a shared file descriptor
202 *
203 * Takes an ion_fd_data struct with the fd field populated with a valid file
204 * descriptor obtained from ION_IOC_SHARE and returns the struct with the handle
205 * filed set to the corresponding opaque handle.
206 */
207#define ION_IOC_IMPORT _IOWR(ION_IOC_MAGIC, 5, struct ion_fd_data)
208
209/**
210 * DOC: ION_IOC_SYNC - syncs a shared file descriptors to memory
211 *
212 * Deprecated in favor of using the dma_buf api's correctly (syncing
Christopher Ferris12e1f282016-02-04 12:35:07 -0800213 * will happen automatically when the buffer is mapped to a device).
Christopher Ferris6ea19f62013-11-20 19:48:48 -0800214 * If necessary should be used after touching a cached buffer from the cpu,
215 * this will make the buffer in memory coherent.
216 */
217#define ION_IOC_SYNC _IOWR(ION_IOC_MAGIC, 7, struct ion_fd_data)
218
219/**
220 * DOC: ION_IOC_CUSTOM - call architecture specific ion ioctl
221 *
222 * Takes the argument of the architecture specific ioctl to call and
223 * passes appropriate userdata for that ioctl
224 */
225#define ION_IOC_CUSTOM _IOWR(ION_IOC_MAGIC, 6, struct ion_custom_data)
226
Christopher Ferris33185402017-01-13 13:28:52 -0800227/**
228 * DOC: ION_IOC_HEAP_QUERY - information about available heaps
229 *
230 * Takes an ion_heap_query structure and populates information about
231 * available Ion heaps.
232 */
233#define ION_IOC_HEAP_QUERY _IOWR(ION_IOC_MAGIC, 8, \
234 struct ion_heap_query)
235
Christopher Ferrise0845012014-07-09 14:58:51 -0700236#endif /* _UAPI_LINUX_ION_H */