Etienne Carriere | 41343db | 2017-03-17 15:38:52 +0100 | [diff] [blame^] | 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_HEAP_TYPE_UNMAPPED: memory not mappable into linux address space |
| 34 | * @ION_NUM_HEAPS: helper for iterating over heaps, a bit mask |
| 35 | * is used to identify the heaps, so only 32 |
| 36 | * total heap types are supported |
| 37 | */ |
| 38 | enum ion_heap_type { |
| 39 | ION_HEAP_TYPE_SYSTEM, |
| 40 | ION_HEAP_TYPE_SYSTEM_CONTIG, |
| 41 | ION_HEAP_TYPE_CARVEOUT, |
| 42 | ION_HEAP_TYPE_CHUNK, |
| 43 | ION_HEAP_TYPE_DMA, |
| 44 | ION_HEAP_TYPE_UNMAPPED, |
| 45 | ION_HEAP_TYPE_CUSTOM, /* |
| 46 | * must be last so device specific heaps always |
| 47 | * are at the end of this enum |
| 48 | */ |
| 49 | }; |
| 50 | |
| 51 | #define ION_NUM_HEAP_IDS (sizeof(unsigned int) * 8) |
| 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 | |
| 58 | /* |
| 59 | * mappings of this buffer should be cached, ion will do cache maintenance |
| 60 | * when the buffer is mapped for dma |
| 61 | */ |
| 62 | #define ION_FLAG_CACHED 1 |
| 63 | |
| 64 | /* |
| 65 | * mappings of this buffer will created at mmap time, if this is set |
| 66 | * caches must be managed manually |
| 67 | */ |
| 68 | #define ION_FLAG_CACHED_NEEDS_SYNC 2 |
| 69 | |
| 70 | /** |
| 71 | * DOC: Ion Userspace API |
| 72 | * |
| 73 | * create a client by opening /dev/ion |
| 74 | * most operations handled via following ioctls |
| 75 | * |
| 76 | */ |
| 77 | |
| 78 | /** |
| 79 | * struct ion_allocation_data - metadata passed from userspace for allocations |
| 80 | * @len: size of the allocation |
| 81 | * @align: required alignment of the allocation |
| 82 | * @heap_id_mask: mask of heap ids to allocate from |
| 83 | * @flags: flags passed to heap |
| 84 | * @handle: pointer that will be populated with a cookie to use to |
| 85 | * refer to this allocation |
| 86 | * |
| 87 | * Provided by userspace as an argument to the ioctl |
| 88 | */ |
| 89 | struct ion_allocation_data { |
| 90 | size_t len; |
| 91 | size_t align; |
| 92 | unsigned int heap_id_mask; |
| 93 | unsigned int flags; |
| 94 | ion_user_handle_t handle; |
| 95 | }; |
| 96 | |
| 97 | /** |
| 98 | * struct ion_fd_data - metadata passed to/from userspace for a handle/fd pair |
| 99 | * @handle: a handle |
| 100 | * @fd: a file descriptor representing that handle |
| 101 | * |
| 102 | * For ION_IOC_SHARE or ION_IOC_MAP userspace populates the handle field with |
| 103 | * the handle returned from ion alloc, and the kernel returns the file |
| 104 | * descriptor to share or map in the fd field. For ION_IOC_IMPORT, userspace |
| 105 | * provides the file descriptor and the kernel returns the handle. |
| 106 | */ |
| 107 | struct ion_fd_data { |
| 108 | ion_user_handle_t handle; |
| 109 | int fd; |
| 110 | }; |
| 111 | |
| 112 | /** |
| 113 | * struct ion_handle_data - a handle passed to/from the kernel |
| 114 | * @handle: a handle |
| 115 | */ |
| 116 | struct ion_handle_data { |
| 117 | ion_user_handle_t handle; |
| 118 | }; |
| 119 | |
| 120 | /** |
| 121 | * struct ion_custom_data - metadata passed to/from userspace for a custom ioctl |
| 122 | * @cmd: the custom ioctl function to call |
| 123 | * @arg: additional data to pass to the custom ioctl, typically a user |
| 124 | * pointer to a predefined structure |
| 125 | * |
| 126 | * This works just like the regular cmd and arg fields of an ioctl. |
| 127 | */ |
| 128 | struct ion_custom_data { |
| 129 | unsigned int cmd; |
| 130 | unsigned long arg; |
| 131 | }; |
| 132 | |
| 133 | #define MAX_HEAP_NAME 32 |
| 134 | |
| 135 | /** |
| 136 | * struct ion_heap_data - data about a heap |
| 137 | * @name - first 32 characters of the heap name |
| 138 | * @type - heap type |
| 139 | * @heap_id - heap id for the heap |
| 140 | */ |
| 141 | struct ion_heap_data { |
| 142 | char name[MAX_HEAP_NAME]; |
| 143 | __u32 type; |
| 144 | __u32 heap_id; |
| 145 | __u32 reserved0; |
| 146 | __u32 reserved1; |
| 147 | __u32 reserved2; |
| 148 | }; |
| 149 | |
| 150 | /** |
| 151 | * struct ion_heap_query - collection of data about all heaps |
| 152 | * @cnt - total number of heaps to be copied |
| 153 | * @heaps - buffer to copy heap data |
| 154 | */ |
| 155 | struct ion_heap_query { |
| 156 | __u32 cnt; /* Total number of heaps to be copied */ |
| 157 | __u32 reserved0; /* align to 64bits */ |
| 158 | __u64 heaps; /* buffer to be populated */ |
| 159 | __u32 reserved1; |
| 160 | __u32 reserved2; |
| 161 | }; |
| 162 | |
| 163 | #define ION_IOC_MAGIC 'I' |
| 164 | |
| 165 | /** |
| 166 | * DOC: ION_IOC_ALLOC - allocate memory |
| 167 | * |
| 168 | * Takes an ion_allocation_data struct and returns it with the handle field |
| 169 | * populated with the opaque handle for the allocation. |
| 170 | */ |
| 171 | #define ION_IOC_ALLOC _IOWR(ION_IOC_MAGIC, 0, \ |
| 172 | struct ion_allocation_data) |
| 173 | |
| 174 | /** |
| 175 | * DOC: ION_IOC_FREE - free memory |
| 176 | * |
| 177 | * Takes an ion_handle_data struct and frees the handle. |
| 178 | */ |
| 179 | #define ION_IOC_FREE _IOWR(ION_IOC_MAGIC, 1, struct ion_handle_data) |
| 180 | |
| 181 | /** |
| 182 | * DOC: ION_IOC_MAP - get a file descriptor to mmap |
| 183 | * |
| 184 | * Takes an ion_fd_data struct with the handle field populated with a valid |
| 185 | * opaque handle. Returns the struct with the fd field set to a file |
| 186 | * descriptor open in the current address space. This file descriptor |
| 187 | * can then be used as an argument to mmap. |
| 188 | */ |
| 189 | #define ION_IOC_MAP _IOWR(ION_IOC_MAGIC, 2, struct ion_fd_data) |
| 190 | |
| 191 | /** |
| 192 | * DOC: ION_IOC_SHARE - creates a file descriptor to use to share an allocation |
| 193 | * |
| 194 | * Takes an ion_fd_data struct with the handle field populated with a valid |
| 195 | * opaque handle. Returns the struct with the fd field set to a file |
| 196 | * descriptor open in the current address space. This file descriptor |
| 197 | * can then be passed to another process. The corresponding opaque handle can |
| 198 | * be retrieved via ION_IOC_IMPORT. |
| 199 | */ |
| 200 | #define ION_IOC_SHARE _IOWR(ION_IOC_MAGIC, 4, struct ion_fd_data) |
| 201 | |
| 202 | /** |
| 203 | * DOC: ION_IOC_IMPORT - imports a shared file descriptor |
| 204 | * |
| 205 | * Takes an ion_fd_data struct with the fd field populated with a valid file |
| 206 | * descriptor obtained from ION_IOC_SHARE and returns the struct with the handle |
| 207 | * filed set to the corresponding opaque handle. |
| 208 | */ |
| 209 | #define ION_IOC_IMPORT _IOWR(ION_IOC_MAGIC, 5, struct ion_fd_data) |
| 210 | |
| 211 | /** |
| 212 | * DOC: ION_IOC_SYNC - syncs a shared file descriptors to memory |
| 213 | * |
| 214 | * Deprecated in favor of using the dma_buf api's correctly (syncing |
| 215 | * will happen automatically when the buffer is mapped to a device). |
| 216 | * If necessary should be used after touching a cached buffer from the cpu, |
| 217 | * this will make the buffer in memory coherent. |
| 218 | */ |
| 219 | #define ION_IOC_SYNC _IOWR(ION_IOC_MAGIC, 7, struct ion_fd_data) |
| 220 | |
| 221 | /** |
| 222 | * DOC: ION_IOC_CUSTOM - call architecture specific ion ioctl |
| 223 | * |
| 224 | * Takes the argument of the architecture specific ioctl to call and |
| 225 | * passes appropriate userdata for that ioctl |
| 226 | */ |
| 227 | #define ION_IOC_CUSTOM _IOWR(ION_IOC_MAGIC, 6, struct ion_custom_data) |
| 228 | |
| 229 | /** |
| 230 | * DOC: ION_IOC_HEAP_QUERY - information about available heaps |
| 231 | * |
| 232 | * Takes an ion_heap_query structure and populates information about |
| 233 | * available Ion heaps. |
| 234 | */ |
| 235 | #define ION_IOC_HEAP_QUERY _IOWR(ION_IOC_MAGIC, 8, \ |
| 236 | struct ion_heap_query) |
| 237 | |
| 238 | #endif /* _UAPI_LINUX_ION_H */ |