blob: ccc2a7c153212e9d8600769f056755285b45237f [file] [log] [blame]
Colin Crossc3a2fe02013-12-13 14:24:57 -08001/*
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
23typedef 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
Seunghun Lee53d719f2014-04-17 00:39:44 +090030 * carveout heap, allocations are physically
31 * contiguous
Colin Crossc3a2fe02013-12-13 14:24:57 -080032 * @ION_HEAP_TYPE_DMA: memory allocated via DMA API
33 * @ION_NUM_HEAPS: helper for iterating over heaps, a bit mask
Seunghun Lee53d719f2014-04-17 00:39:44 +090034 * is used to identify the heaps, so only 32
35 * total heap types are supported
Colin Crossc3a2fe02013-12-13 14:24:57 -080036 */
37enum 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,
Sriram Raghunathan7e416172015-09-22 22:35:51 +053043 ION_HEAP_TYPE_CUSTOM, /*
44 * must be last so device specific heaps always
45 * are at the end of this enum
46 */
Patrick Daly7e8cbb42016-11-01 18:37:42 -070047 ION_NUM_HEAPS = 16,
Colin Crossc3a2fe02013-12-13 14:24:57 -080048};
49
Patrick Daly7e8cbb42016-11-01 18:37:42 -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))
53#define ION_HEAP_TYPE_DMA_MASK ((1 << ION_HEAP_TYPE_DMA))
54
Seunghun Lee53d719f2014-04-17 00:39:44 +090055#define ION_NUM_HEAP_IDS (sizeof(unsigned int) * 8)
Colin Crossc3a2fe02013-12-13 14:24:57 -080056
57/**
58 * allocation flags - the lower 16 bits are used by core ion, the upper 16
59 * bits are reserved for use by the heaps themselves.
60 */
Patrick Daly7e8cbb42016-11-01 18:37:42 -070061#define ION_FLAG_CACHED 1 /*
62 * mappings of this buffer should be
63 * cached, ion will do cache
64 * maintenance when the buffer is
65 * mapped for dma
66 */
67#define ION_FLAG_CACHED_NEEDS_SYNC 2 /*
68 * mappings of this buffer will created
69 * at mmap time, if this is set
70 * caches must be managed
71 * manually
72 */
Colin Crossc3a2fe02013-12-13 14:24:57 -080073
74/**
75 * DOC: Ion Userspace API
76 *
77 * create a client by opening /dev/ion
78 * most operations handled via following ioctls
79 *
80 */
81
82/**
83 * struct ion_allocation_data - metadata passed from userspace for allocations
84 * @len: size of the allocation
85 * @align: required alignment of the allocation
86 * @heap_id_mask: mask of heap ids to allocate from
87 * @flags: flags passed to heap
Seunghun Lee53d719f2014-04-17 00:39:44 +090088 * @handle: pointer that will be populated with a cookie to use to
Colin Crossc3a2fe02013-12-13 14:24:57 -080089 * refer to this allocation
90 *
91 * Provided by userspace as an argument to the ioctl
92 */
93struct ion_allocation_data {
94 size_t len;
95 size_t align;
96 unsigned int heap_id_mask;
97 unsigned int flags;
98 ion_user_handle_t handle;
99};
100
101/**
102 * struct ion_fd_data - metadata passed to/from userspace for a handle/fd pair
103 * @handle: a handle
104 * @fd: a file descriptor representing that handle
105 *
106 * For ION_IOC_SHARE or ION_IOC_MAP userspace populates the handle field with
107 * the handle returned from ion alloc, and the kernel returns the file
108 * descriptor to share or map in the fd field. For ION_IOC_IMPORT, userspace
109 * provides the file descriptor and the kernel returns the handle.
110 */
111struct ion_fd_data {
112 ion_user_handle_t handle;
113 int fd;
114};
115
116/**
117 * struct ion_handle_data - a handle passed to/from the kernel
118 * @handle: a handle
119 */
120struct ion_handle_data {
121 ion_user_handle_t handle;
122};
123
124/**
125 * struct ion_custom_data - metadata passed to/from userspace for a custom ioctl
126 * @cmd: the custom ioctl function to call
127 * @arg: additional data to pass to the custom ioctl, typically a user
128 * pointer to a predefined structure
129 *
130 * This works just like the regular cmd and arg fields of an ioctl.
131 */
132struct ion_custom_data {
133 unsigned int cmd;
134 unsigned long arg;
135};
136
137#define ION_IOC_MAGIC 'I'
138
139/**
140 * DOC: ION_IOC_ALLOC - allocate memory
141 *
142 * Takes an ion_allocation_data struct and returns it with the handle field
143 * populated with the opaque handle for the allocation.
144 */
145#define ION_IOC_ALLOC _IOWR(ION_IOC_MAGIC, 0, \
146 struct ion_allocation_data)
147
148/**
149 * DOC: ION_IOC_FREE - free memory
150 *
151 * Takes an ion_handle_data struct and frees the handle.
152 */
153#define ION_IOC_FREE _IOWR(ION_IOC_MAGIC, 1, struct ion_handle_data)
154
155/**
156 * DOC: ION_IOC_MAP - get a file descriptor to mmap
157 *
158 * Takes an ion_fd_data struct with the handle field populated with a valid
159 * opaque handle. Returns the struct with the fd field set to a file
160 * descriptor open in the current address space. This file descriptor
161 * can then be used as an argument to mmap.
162 */
163#define ION_IOC_MAP _IOWR(ION_IOC_MAGIC, 2, struct ion_fd_data)
164
165/**
166 * DOC: ION_IOC_SHARE - creates a file descriptor to use to share an allocation
167 *
168 * Takes an ion_fd_data struct with the handle field populated with a valid
169 * opaque handle. Returns the struct with the fd field set to a file
170 * descriptor open in the current address space. This file descriptor
171 * can then be passed to another process. The corresponding opaque handle can
172 * be retrieved via ION_IOC_IMPORT.
173 */
174#define ION_IOC_SHARE _IOWR(ION_IOC_MAGIC, 4, struct ion_fd_data)
175
176/**
177 * DOC: ION_IOC_IMPORT - imports a shared file descriptor
178 *
179 * Takes an ion_fd_data struct with the fd field populated with a valid file
180 * descriptor obtained from ION_IOC_SHARE and returns the struct with the handle
181 * filed set to the corresponding opaque handle.
182 */
183#define ION_IOC_IMPORT _IOWR(ION_IOC_MAGIC, 5, struct ion_fd_data)
184
185/**
186 * DOC: ION_IOC_SYNC - syncs a shared file descriptors to memory
187 *
188 * Deprecated in favor of using the dma_buf api's correctly (syncing
Carlos E. Garcia69e98df2015-04-24 09:40:42 -0400189 * will happen automatically when the buffer is mapped to a device).
Colin Crossc3a2fe02013-12-13 14:24:57 -0800190 * If necessary should be used after touching a cached buffer from the cpu,
191 * this will make the buffer in memory coherent.
192 */
193#define ION_IOC_SYNC _IOWR(ION_IOC_MAGIC, 7, struct ion_fd_data)
194
195/**
196 * DOC: ION_IOC_CUSTOM - call architecture specific ion ioctl
197 *
198 * Takes the argument of the architecture specific ioctl to call and
199 * passes appropriate userdata for that ioctl
200 */
201#define ION_IOC_CUSTOM _IOWR(ION_IOC_MAGIC, 6, struct ion_custom_data)
202
Colin Crossc3a2fe02013-12-13 14:24:57 -0800203#endif /* _UAPI_LINUX_ION_H */