1 /* 2 * include/linux/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_ION_H 18 #define _UAPI_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_END: helper for iterating over heaps 33 */ 34 enum ion_heap_type { 35 ION_HEAP_TYPE_SYSTEM, 36 ION_HEAP_TYPE_SYSTEM_CONTIG, 37 ION_HEAP_TYPE_CARVEOUT, 38 ION_HEAP_TYPE_CHUNK, 39 ION_HEAP_TYPE_CUSTOM, /* must be last so device specific heaps always 40 are at the end of this enum */ 41 ION_NUM_HEAPS, 42 }; 43 44 #define ION_HEAP_SYSTEM_MASK (1 << ION_HEAP_TYPE_SYSTEM) 45 #define ION_HEAP_SYSTEM_CONTIG_MASK (1 << ION_HEAP_TYPE_SYSTEM_CONTIG) 46 #define ION_HEAP_CARVEOUT_MASK (1 << ION_HEAP_TYPE_CARVEOUT) 47 48 #define ION_NUM_HEAP_IDS sizeof(unsigned int) * 8 49 50 /** 51 * allocation flags - the lower 16 bits are used by core ion, the upper 16 52 * bits are reserved for use by the heaps themselves. 53 */ 54 #define ION_FLAG_CACHED 1 /* mappings of this buffer should be 55 cached, ion will do cache 56 maintenance when the buffer is 57 mapped for dma */ 58 #define ION_FLAG_CACHED_NEEDS_SYNC 2 /* mappings of this buffer will created 59 at mmap time, if this is set 60 caches must be managed manually */ 61 #define ION_FLAG_FREED_FROM_SHRINKER 4 /* Skip any possible 62 heap-specific caching 63 mechanism (e.g. page 64 pools). Guarantees that any 65 buffer storage that came 66 from the system allocator 67 will be returned to the 68 system allocator. */ 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_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 #define ION_IOC_MAGIC 'I' 133 134 /** 135 * DOC: ION_IOC_ALLOC - allocate memory 136 * 137 * Takes an ion_allocation_data struct and returns it with the handle field 138 * populated with the opaque handle for the allocation. 139 */ 140 #define ION_IOC_ALLOC _IOWR(ION_IOC_MAGIC, 0, \ 141 struct ion_allocation_data) 142 143 /** 144 * DOC: ION_IOC_FREE - free memory 145 * 146 * Takes an ion_handle_data struct and frees the handle. 147 */ 148 #define ION_IOC_FREE _IOWR(ION_IOC_MAGIC, 1, struct ion_handle_data) 149 150 /** 151 * DOC: ION_IOC_MAP - get a file descriptor to mmap 152 * 153 * Takes an ion_fd_data struct with the handle field populated with a valid 154 * opaque handle. Returns the struct with the fd field set to a file 155 * descriptor open in the current address space. This file descriptor 156 * can then be used as an argument to mmap. 157 */ 158 #define ION_IOC_MAP _IOWR(ION_IOC_MAGIC, 2, struct ion_fd_data) 159 160 /** 161 * DOC: ION_IOC_SHARE - creates a file descriptor to use to share an allocation 162 * 163 * Takes an ion_fd_data struct with the handle field populated with a valid 164 * opaque handle. Returns the struct with the fd field set to a file 165 * descriptor open in the current address space. This file descriptor 166 * can then be passed to another process. The corresponding opaque handle can 167 * be retrieved via ION_IOC_IMPORT. 168 */ 169 #define ION_IOC_SHARE _IOWR(ION_IOC_MAGIC, 4, struct ion_fd_data) 170 171 /** 172 * DOC: ION_IOC_IMPORT - imports a shared file descriptor 173 * 174 * Takes an ion_fd_data struct with the fd field populated with a valid file 175 * descriptor obtained from ION_IOC_SHARE and returns the struct with the handle 176 * filed set to the corresponding opaque handle. 177 */ 178 #define ION_IOC_IMPORT _IOWR(ION_IOC_MAGIC, 5, struct ion_fd_data) 179 180 /** 181 * DOC: ION_IOC_SYNC - syncs a shared file descriptors to memory 182 * 183 * Deprecated in favor of using the dma_buf api's correctly (syncing 184 * will happend automatically when the buffer is mapped to a device). 185 * If necessary should be used after touching a cached buffer from the cpu, 186 * this will make the buffer in memory coherent. 187 */ 188 #define ION_IOC_SYNC _IOWR(ION_IOC_MAGIC, 7, struct ion_fd_data) 189 190 /** 191 * DOC: ION_IOC_CUSTOM - call architecture specific ion ioctl 192 * 193 * Takes the argument of the architecture specific ioctl to call and 194 * passes appropriate userdata for that ioctl 195 */ 196 #define ION_IOC_CUSTOM _IOWR(ION_IOC_MAGIC, 6, struct ion_custom_data) 197 198 #endif /* _UAPI_ION_H */ 199