Rebecca Schultz Zavin | c80005a | 2011-06-29 19:44:29 -0700 | [diff] [blame] | 1 | /* |
| 2 | * include/linux/ion.h |
| 3 | * |
| 4 | * Copyright (C) 2011 Google, Inc. |
Mitchel Humpherys | a75e4eb | 2012-12-14 16:12:23 -0800 | [diff] [blame] | 5 | * Copyright (c) 2011-2013, The Linux Foundation. All rights reserved. |
Rebecca Schultz Zavin | c80005a | 2011-06-29 19:44:29 -0700 | [diff] [blame] | 6 | * |
| 7 | * This software is licensed under the terms of the GNU General Public |
| 8 | * License version 2, as published by the Free Software Foundation, and |
| 9 | * may be copied, distributed, and modified under those terms. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | */ |
| 17 | |
| 18 | #ifndef _LINUX_ION_H |
| 19 | #define _LINUX_ION_H |
| 20 | |
Laura Abbott | abcb6f7 | 2011-10-04 16:26:49 -0700 | [diff] [blame] | 21 | #include <linux/ioctl.h> |
Rebecca Schultz Zavin | c80005a | 2011-06-29 19:44:29 -0700 | [diff] [blame] | 22 | #include <linux/types.h> |
| 23 | |
| 24 | struct ion_handle; |
| 25 | /** |
| 26 | * enum ion_heap_types - list of all possible types of heaps |
Iliyan Malchev | f2230156 | 2011-07-06 16:53:21 -0700 | [diff] [blame] | 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 |
Olav Haugan | b5be799 | 2011-11-18 14:29:02 -0800 | [diff] [blame] | 30 | * carveout heap, allocations are physically |
| 31 | * contiguous |
Olav Haugan | 0a85251 | 2012-01-09 10:20:55 -0800 | [diff] [blame] | 32 | * @ION_HEAP_END: helper for iterating over heaps |
Rebecca Schultz Zavin | c80005a | 2011-06-29 19:44:29 -0700 | [diff] [blame] | 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_CUSTOM, /* must be last so device specific heaps always |
| 39 | are at the end of this enum */ |
Rebecca Schultz Zavin | e6ee124 | 2011-06-30 12:19:55 -0700 | [diff] [blame] | 40 | ION_NUM_HEAPS, |
Rebecca Schultz Zavin | c80005a | 2011-06-29 19:44:29 -0700 | [diff] [blame] | 41 | }; |
| 42 | |
Iliyan Malchev | f2230156 | 2011-07-06 16:53:21 -0700 | [diff] [blame] | 43 | #define ION_HEAP_SYSTEM_MASK (1 << ION_HEAP_TYPE_SYSTEM) |
| 44 | #define ION_HEAP_SYSTEM_CONTIG_MASK (1 << ION_HEAP_TYPE_SYSTEM_CONTIG) |
| 45 | #define ION_HEAP_CARVEOUT_MASK (1 << ION_HEAP_TYPE_CARVEOUT) |
Rebecca Schultz Zavin | c80005a | 2011-06-29 19:44:29 -0700 | [diff] [blame] | 46 | |
Mitchel Humpherys | 227a658 | 2012-09-11 15:59:11 -0700 | [diff] [blame] | 47 | /** |
| 48 | * heap flags - the lower 16 bits are used by core ion, the upper 16 |
| 49 | * bits are reserved for use by the heaps themselves. |
| 50 | */ |
| 51 | #define ION_FLAG_CACHED 1 /* mappings of this buffer should be |
| 52 | cached, ion will do cache |
| 53 | maintenance when the buffer is |
| 54 | mapped for dma */ |
Rebecca Schultz Zavin | 3edb900 | 2012-09-19 23:31:05 -0700 | [diff] [blame] | 55 | #define ION_FLAG_CACHED_NEEDS_SYNC 2 /* mappings of this buffer will created |
| 56 | at mmap time, if this is set |
| 57 | caches must be managed manually */ |
Laura Abbott | a2e9363 | 2011-08-19 13:36:32 -0700 | [diff] [blame] | 58 | |
Rebecca Schultz Zavin | c80005a | 2011-06-29 19:44:29 -0700 | [diff] [blame] | 59 | #ifdef __KERNEL__ |
Laura Abbott | 6557696 | 2011-10-31 12:13:25 -0700 | [diff] [blame] | 60 | #include <linux/err.h> |
Laura Abbott | cffdff5 | 2011-09-23 10:40:19 -0700 | [diff] [blame] | 61 | #include <mach/ion.h> |
Rebecca Schultz Zavin | c80005a | 2011-06-29 19:44:29 -0700 | [diff] [blame] | 62 | struct ion_device; |
| 63 | struct ion_heap; |
| 64 | struct ion_mapper; |
| 65 | struct ion_client; |
| 66 | struct ion_buffer; |
| 67 | |
| 68 | /* This should be removed some day when phys_addr_t's are fully |
| 69 | plumbed in the kernel, and all instances of ion_phys_addr_t should |
| 70 | be converted to phys_addr_t. For the time being many kernel interfaces |
| 71 | do not accept phys_addr_t's that would have to */ |
| 72 | #define ion_phys_addr_t unsigned long |
| 73 | |
Rebecca Schultz Zavin | c80005a | 2011-06-29 19:44:29 -0700 | [diff] [blame] | 74 | /** |
| 75 | * struct ion_platform_heap - defines a heap in the given platform |
| 76 | * @type: type of the heap from ion_heap_type enum |
Olav Haugan | ee0f780 | 2011-12-19 13:28:57 -0800 | [diff] [blame] | 77 | * @id: unique identifier for heap. When allocating (lower numbers |
Olav Haugan | b5be799 | 2011-11-18 14:29:02 -0800 | [diff] [blame] | 78 | * will be allocated from first) |
Rebecca Schultz Zavin | c80005a | 2011-06-29 19:44:29 -0700 | [diff] [blame] | 79 | * @name: used for debug purposes |
| 80 | * @base: base address of heap in physical memory if applicable |
| 81 | * @size: size of the heap in bytes if applicable |
Laura Abbott | caafeea | 2011-12-13 11:43:10 -0800 | [diff] [blame] | 82 | * @memory_type:Memory type used for the heap |
Olav Haugan | 85c9540 | 2012-05-30 17:32:37 -0700 | [diff] [blame] | 83 | * @has_outer_cache: set to 1 if outer cache is used, 0 otherwise. |
Laura Abbott | caafeea | 2011-12-13 11:43:10 -0800 | [diff] [blame] | 84 | * @extra_data: Extra data specific to each heap type |
Benjamin Gaignard | 8dff0a6 | 2012-06-25 15:30:18 -0700 | [diff] [blame] | 85 | * @priv: heap private data |
Rebecca Schultz Zavin | c80005a | 2011-06-29 19:44:29 -0700 | [diff] [blame] | 86 | */ |
| 87 | struct ion_platform_heap { |
| 88 | enum ion_heap_type type; |
Rebecca Schultz Zavin | e6ee124 | 2011-06-30 12:19:55 -0700 | [diff] [blame] | 89 | unsigned int id; |
Rebecca Schultz Zavin | c80005a | 2011-06-29 19:44:29 -0700 | [diff] [blame] | 90 | const char *name; |
| 91 | ion_phys_addr_t base; |
| 92 | size_t size; |
Laura Abbott | a2e9363 | 2011-08-19 13:36:32 -0700 | [diff] [blame] | 93 | enum ion_memory_types memory_type; |
Olav Haugan | 85c9540 | 2012-05-30 17:32:37 -0700 | [diff] [blame] | 94 | unsigned int has_outer_cache; |
Olav Haugan | 0703dbf | 2011-12-19 17:53:38 -0800 | [diff] [blame] | 95 | void *extra_data; |
Benjamin Gaignard | 8dff0a6 | 2012-06-25 15:30:18 -0700 | [diff] [blame] | 96 | void *priv; |
Olav Haugan | 0703dbf | 2011-12-19 17:53:38 -0800 | [diff] [blame] | 97 | }; |
| 98 | |
Laura Abbott | caafeea | 2011-12-13 11:43:10 -0800 | [diff] [blame] | 99 | /** |
Rebecca Schultz Zavin | c80005a | 2011-06-29 19:44:29 -0700 | [diff] [blame] | 100 | * struct ion_platform_data - array of platform heaps passed from board file |
Olav Haugan | 85c9540 | 2012-05-30 17:32:37 -0700 | [diff] [blame] | 101 | * @has_outer_cache: set to 1 if outer cache is used, 0 otherwise. |
Alex Bird | 27ca661 | 2011-11-01 14:40:06 -0700 | [diff] [blame] | 102 | * @nr: number of structures in the array |
Alex Bird | 27ca661 | 2011-11-01 14:40:06 -0700 | [diff] [blame] | 103 | * @heaps: array of platform_heap structions |
Rebecca Schultz Zavin | c80005a | 2011-06-29 19:44:29 -0700 | [diff] [blame] | 104 | * |
| 105 | * Provided by the board file in the form of platform data to a platform device. |
| 106 | */ |
| 107 | struct ion_platform_data { |
Olav Haugan | 85c9540 | 2012-05-30 17:32:37 -0700 | [diff] [blame] | 108 | unsigned int has_outer_cache; |
Rebecca Schultz Zavin | c80005a | 2011-06-29 19:44:29 -0700 | [diff] [blame] | 109 | int nr; |
Benjamin Gaignard | 63d8103 | 2012-06-25 15:27:30 -0700 | [diff] [blame] | 110 | struct ion_platform_heap *heaps; |
Rebecca Schultz Zavin | c80005a | 2011-06-29 19:44:29 -0700 | [diff] [blame] | 111 | }; |
| 112 | |
Jordan Crouse | 8cd4832 | 2011-10-12 17:05:19 -0600 | [diff] [blame] | 113 | #ifdef CONFIG_ION |
| 114 | |
Rebecca Schultz Zavin | c80005a | 2011-06-29 19:44:29 -0700 | [diff] [blame] | 115 | /** |
Laura Abbott | b14ed96 | 2012-01-30 14:18:08 -0800 | [diff] [blame] | 116 | * ion_reserve() - reserve memory for ion heaps if applicable |
| 117 | * @data: platform data specifying starting physical address and |
| 118 | * size |
| 119 | * |
| 120 | * Calls memblock reserve to set aside memory for heaps that are |
| 121 | * located at specific memory addresses or of specfic sizes not |
| 122 | * managed by the kernel |
| 123 | */ |
| 124 | void ion_reserve(struct ion_platform_data *data); |
| 125 | |
| 126 | /** |
Rebecca Schultz Zavin | c80005a | 2011-06-29 19:44:29 -0700 | [diff] [blame] | 127 | * ion_client_create() - allocate a client and returns it |
| 128 | * @dev: the global ion device |
| 129 | * @heap_mask: mask of heaps this client can allocate from |
| 130 | * @name: used for debugging |
| 131 | */ |
| 132 | struct ion_client *ion_client_create(struct ion_device *dev, |
| 133 | unsigned int heap_mask, const char *name); |
| 134 | |
| 135 | /** |
| 136 | * ion_client_destroy() - free's a client and all it's handles |
| 137 | * @client: the client |
| 138 | * |
| 139 | * Free the provided client and all it's resources including |
| 140 | * any handles it is holding. |
| 141 | */ |
| 142 | void ion_client_destroy(struct ion_client *client); |
| 143 | |
| 144 | /** |
| 145 | * ion_alloc - allocate ion memory |
| 146 | * @client: the client |
| 147 | * @len: size of the allocation |
| 148 | * @align: requested allocation alignment, lots of hardware blocks have |
| 149 | * alignment requirements of some kind |
Hanumant Singh | 7d72bad | 2012-08-29 18:39:44 -0700 | [diff] [blame] | 150 | * @heap_mask: mask of heaps to allocate from, if multiple bits are set |
Rebecca Schultz Zavin | e6ee124 | 2011-06-30 12:19:55 -0700 | [diff] [blame] | 151 | * heaps will be tried in order from lowest to highest order bit |
Hanumant Singh | 7d72bad | 2012-08-29 18:39:44 -0700 | [diff] [blame] | 152 | * @flags: heap flags, the low 16 bits are consumed by ion, the high 16 |
| 153 | * bits are passed on to the respective heap and can be heap |
| 154 | * custom |
Rebecca Schultz Zavin | c80005a | 2011-06-29 19:44:29 -0700 | [diff] [blame] | 155 | * |
| 156 | * Allocate memory in one of the heaps provided in heap mask and return |
| 157 | * an opaque handle to it. |
| 158 | */ |
| 159 | struct ion_handle *ion_alloc(struct ion_client *client, size_t len, |
Hanumant Singh | 7d72bad | 2012-08-29 18:39:44 -0700 | [diff] [blame] | 160 | size_t align, unsigned int heap_mask, |
| 161 | unsigned int flags); |
Rebecca Schultz Zavin | c80005a | 2011-06-29 19:44:29 -0700 | [diff] [blame] | 162 | |
| 163 | /** |
| 164 | * ion_free - free a handle |
| 165 | * @client: the client |
| 166 | * @handle: the handle to free |
| 167 | * |
| 168 | * Free the provided handle. |
| 169 | */ |
| 170 | void ion_free(struct ion_client *client, struct ion_handle *handle); |
| 171 | |
| 172 | /** |
| 173 | * ion_phys - returns the physical address and len of a handle |
| 174 | * @client: the client |
| 175 | * @handle: the handle |
| 176 | * @addr: a pointer to put the address in |
| 177 | * @len: a pointer to put the length in |
| 178 | * |
| 179 | * This function queries the heap for a particular handle to get the |
| 180 | * handle's physical address. It't output is only correct if |
| 181 | * a heap returns physically contiguous memory -- in other cases |
Laura Abbott | b14ed96 | 2012-01-30 14:18:08 -0800 | [diff] [blame] | 182 | * this api should not be implemented -- ion_sg_table should be used |
Rebecca Schultz Zavin | c80005a | 2011-06-29 19:44:29 -0700 | [diff] [blame] | 183 | * instead. Returns -EINVAL if the handle is invalid. This has |
| 184 | * no implications on the reference counting of the handle -- |
| 185 | * the returned value may not be valid if the caller is not |
| 186 | * holding a reference. |
| 187 | */ |
| 188 | int ion_phys(struct ion_client *client, struct ion_handle *handle, |
| 189 | ion_phys_addr_t *addr, size_t *len); |
| 190 | |
| 191 | /** |
Laura Abbott | b14ed96 | 2012-01-30 14:18:08 -0800 | [diff] [blame] | 192 | * ion_map_dma - return an sg_table describing a handle |
| 193 | * @client: the client |
| 194 | * @handle: the handle |
| 195 | * |
| 196 | * This function returns the sg_table describing |
| 197 | * a particular ion handle. |
| 198 | */ |
| 199 | struct sg_table *ion_sg_table(struct ion_client *client, |
| 200 | struct ion_handle *handle); |
| 201 | |
| 202 | /** |
Rebecca Schultz Zavin | c80005a | 2011-06-29 19:44:29 -0700 | [diff] [blame] | 203 | * ion_map_kernel - create mapping for the given handle |
| 204 | * @client: the client |
| 205 | * @handle: handle to map |
| 206 | * |
| 207 | * Map the given handle into the kernel and return a kernel address that |
Mitchel Humpherys | c4dba0a | 2012-11-05 14:06:18 -0800 | [diff] [blame] | 208 | * can be used to access this address. |
Rebecca Schultz Zavin | c80005a | 2011-06-29 19:44:29 -0700 | [diff] [blame] | 209 | */ |
Mitchel Humpherys | 911b4b7 | 2012-09-12 14:42:50 -0700 | [diff] [blame] | 210 | void *ion_map_kernel(struct ion_client *client, struct ion_handle *handle); |
Rebecca Schultz Zavin | c80005a | 2011-06-29 19:44:29 -0700 | [diff] [blame] | 211 | |
| 212 | /** |
| 213 | * ion_unmap_kernel() - destroy a kernel mapping for a handle |
| 214 | * @client: the client |
| 215 | * @handle: handle to unmap |
| 216 | */ |
| 217 | void ion_unmap_kernel(struct ion_client *client, struct ion_handle *handle); |
| 218 | |
| 219 | /** |
Laura Abbott | b14ed96 | 2012-01-30 14:18:08 -0800 | [diff] [blame] | 220 | * ion_share_dma_buf() - given an ion client, create a dma-buf fd |
Rebecca Schultz Zavin | c80005a | 2011-06-29 19:44:29 -0700 | [diff] [blame] | 221 | * @client: the client |
Laura Abbott | b14ed96 | 2012-01-30 14:18:08 -0800 | [diff] [blame] | 222 | * @handle: the handle |
Rebecca Schultz Zavin | c80005a | 2011-06-29 19:44:29 -0700 | [diff] [blame] | 223 | */ |
Laura Abbott | b14ed96 | 2012-01-30 14:18:08 -0800 | [diff] [blame] | 224 | int ion_share_dma_buf(struct ion_client *client, struct ion_handle *handle); |
Rebecca Schultz Zavin | c80005a | 2011-06-29 19:44:29 -0700 | [diff] [blame] | 225 | |
| 226 | /** |
Laura Abbott | b14ed96 | 2012-01-30 14:18:08 -0800 | [diff] [blame] | 227 | * ion_import_dma_buf() - given an dma-buf fd from the ion exporter get handle |
Rebecca Schultz Zavin | c80005a | 2011-06-29 19:44:29 -0700 | [diff] [blame] | 228 | * @client: the client |
Laura Abbott | b14ed96 | 2012-01-30 14:18:08 -0800 | [diff] [blame] | 229 | * @fd: the dma-buf fd |
Rebecca Schultz Zavin | c80005a | 2011-06-29 19:44:29 -0700 | [diff] [blame] | 230 | * |
Laura Abbott | b14ed96 | 2012-01-30 14:18:08 -0800 | [diff] [blame] | 231 | * Given an dma-buf fd that was allocated through ion via ion_share_dma_buf, |
| 232 | * import that fd and return a handle representing it. If a dma-buf from |
| 233 | * another exporter is passed in this function will return ERR_PTR(-EINVAL) |
Rebecca Schultz Zavin | c80005a | 2011-06-29 19:44:29 -0700 | [diff] [blame] | 234 | */ |
Laura Abbott | b14ed96 | 2012-01-30 14:18:08 -0800 | [diff] [blame] | 235 | struct ion_handle *ion_import_dma_buf(struct ion_client *client, int fd); |
Laura Abbott | 273dd8e | 2011-10-12 14:26:33 -0700 | [diff] [blame] | 236 | |
Jordan Crouse | 8cd4832 | 2011-10-12 17:05:19 -0600 | [diff] [blame] | 237 | #else |
Laura Abbott | b14ed96 | 2012-01-30 14:18:08 -0800 | [diff] [blame] | 238 | static inline void ion_reserve(struct ion_platform_data *data) |
| 239 | { |
| 240 | |
| 241 | } |
| 242 | |
Jordan Crouse | 8cd4832 | 2011-10-12 17:05:19 -0600 | [diff] [blame] | 243 | static inline struct ion_client *ion_client_create(struct ion_device *dev, |
| 244 | unsigned int heap_mask, const char *name) |
| 245 | { |
| 246 | return ERR_PTR(-ENODEV); |
| 247 | } |
Laura Abbott | 273dd8e | 2011-10-12 14:26:33 -0700 | [diff] [blame] | 248 | |
Jordan Crouse | 8cd4832 | 2011-10-12 17:05:19 -0600 | [diff] [blame] | 249 | static inline void ion_client_destroy(struct ion_client *client) { } |
| 250 | |
| 251 | static inline struct ion_handle *ion_alloc(struct ion_client *client, |
Hanumant Singh | 7d72bad | 2012-08-29 18:39:44 -0700 | [diff] [blame] | 252 | size_t len, size_t align, |
| 253 | unsigned int heap_mask, |
| 254 | unsigned int flags) |
Jordan Crouse | 8cd4832 | 2011-10-12 17:05:19 -0600 | [diff] [blame] | 255 | { |
| 256 | return ERR_PTR(-ENODEV); |
| 257 | } |
| 258 | |
| 259 | static inline void ion_free(struct ion_client *client, |
| 260 | struct ion_handle *handle) { } |
| 261 | |
| 262 | |
| 263 | static inline int ion_phys(struct ion_client *client, |
| 264 | struct ion_handle *handle, ion_phys_addr_t *addr, size_t *len) |
| 265 | { |
| 266 | return -ENODEV; |
| 267 | } |
| 268 | |
Laura Abbott | b14ed96 | 2012-01-30 14:18:08 -0800 | [diff] [blame] | 269 | static inline struct sg_table *ion_sg_table(struct ion_client *client, |
| 270 | struct ion_handle *handle) |
| 271 | { |
| 272 | return ERR_PTR(-ENODEV); |
| 273 | } |
| 274 | |
Jordan Crouse | 8cd4832 | 2011-10-12 17:05:19 -0600 | [diff] [blame] | 275 | static inline void *ion_map_kernel(struct ion_client *client, |
Mitchel Humpherys | baa8692 | 2012-11-02 16:35:39 -0700 | [diff] [blame] | 276 | struct ion_handle *handle) |
Jordan Crouse | 8cd4832 | 2011-10-12 17:05:19 -0600 | [diff] [blame] | 277 | { |
| 278 | return ERR_PTR(-ENODEV); |
| 279 | } |
| 280 | |
| 281 | static inline void ion_unmap_kernel(struct ion_client *client, |
| 282 | struct ion_handle *handle) { } |
| 283 | |
Laura Abbott | b14ed96 | 2012-01-30 14:18:08 -0800 | [diff] [blame] | 284 | static inline int ion_share_dma_buf(struct ion_client *client, struct ion_handle *handle) |
Jordan Crouse | 8cd4832 | 2011-10-12 17:05:19 -0600 | [diff] [blame] | 285 | { |
Laura Abbott | b14ed96 | 2012-01-30 14:18:08 -0800 | [diff] [blame] | 286 | return -ENODEV; |
Jordan Crouse | 8cd4832 | 2011-10-12 17:05:19 -0600 | [diff] [blame] | 287 | } |
| 288 | |
Laura Abbott | b14ed96 | 2012-01-30 14:18:08 -0800 | [diff] [blame] | 289 | static inline struct ion_handle *ion_import_dma_buf(struct ion_client *client, int fd) |
Jordan Crouse | 8cd4832 | 2011-10-12 17:05:19 -0600 | [diff] [blame] | 290 | { |
| 291 | return ERR_PTR(-ENODEV); |
| 292 | } |
| 293 | |
| 294 | static inline int ion_handle_get_flags(struct ion_client *client, |
| 295 | struct ion_handle *handle, unsigned long *flags) |
| 296 | { |
| 297 | return -ENODEV; |
| 298 | } |
Laura Abbott | 8c01736 | 2011-09-22 20:59:12 -0700 | [diff] [blame] | 299 | |
Jordan Crouse | 8cd4832 | 2011-10-12 17:05:19 -0600 | [diff] [blame] | 300 | #endif /* CONFIG_ION */ |
Rebecca Schultz Zavin | c80005a | 2011-06-29 19:44:29 -0700 | [diff] [blame] | 301 | #endif /* __KERNEL__ */ |
| 302 | |
| 303 | /** |
| 304 | * DOC: Ion Userspace API |
| 305 | * |
| 306 | * create a client by opening /dev/ion |
| 307 | * most operations handled via following ioctls |
| 308 | * |
| 309 | */ |
| 310 | |
| 311 | /** |
| 312 | * struct ion_allocation_data - metadata passed from userspace for allocations |
| 313 | * @len: size of the allocation |
| 314 | * @align: required alignment of the allocation |
Hanumant Singh | 7d72bad | 2012-08-29 18:39:44 -0700 | [diff] [blame] | 315 | * @heap_mask: mask of heaps to allocate from |
Rebecca Schultz Zavin | c80005a | 2011-06-29 19:44:29 -0700 | [diff] [blame] | 316 | * @flags: flags passed to heap |
| 317 | * @handle: pointer that will be populated with a cookie to use to refer |
| 318 | * to this allocation |
| 319 | * |
| 320 | * Provided by userspace as an argument to the ioctl |
| 321 | */ |
| 322 | struct ion_allocation_data { |
| 323 | size_t len; |
| 324 | size_t align; |
Laura Abbott | 0eec151 | 2012-08-27 13:14:39 -0700 | [diff] [blame] | 325 | unsigned int heap_mask; |
Rebecca Schultz Zavin | c80005a | 2011-06-29 19:44:29 -0700 | [diff] [blame] | 326 | unsigned int flags; |
| 327 | struct ion_handle *handle; |
| 328 | }; |
| 329 | |
| 330 | /** |
| 331 | * struct ion_fd_data - metadata passed to/from userspace for a handle/fd pair |
| 332 | * @handle: a handle |
| 333 | * @fd: a file descriptor representing that handle |
| 334 | * |
| 335 | * For ION_IOC_SHARE or ION_IOC_MAP userspace populates the handle field with |
| 336 | * the handle returned from ion alloc, and the kernel returns the file |
| 337 | * descriptor to share or map in the fd field. For ION_IOC_IMPORT, userspace |
| 338 | * provides the file descriptor and the kernel returns the handle. |
| 339 | */ |
| 340 | struct ion_fd_data { |
| 341 | struct ion_handle *handle; |
| 342 | int fd; |
| 343 | }; |
| 344 | |
| 345 | /** |
| 346 | * struct ion_handle_data - a handle passed to/from the kernel |
| 347 | * @handle: a handle |
| 348 | */ |
| 349 | struct ion_handle_data { |
| 350 | struct ion_handle *handle; |
| 351 | }; |
| 352 | |
Rebecca Schultz Zavin | e6ee124 | 2011-06-30 12:19:55 -0700 | [diff] [blame] | 353 | /** |
| 354 | * struct ion_custom_data - metadata passed to/from userspace for a custom ioctl |
| 355 | * @cmd: the custom ioctl function to call |
| 356 | * @arg: additional data to pass to the custom ioctl, typically a user |
| 357 | * pointer to a predefined structure |
| 358 | * |
| 359 | * This works just like the regular cmd and arg fields of an ioctl. |
| 360 | */ |
Rebecca Schultz Zavin | c80005a | 2011-06-29 19:44:29 -0700 | [diff] [blame] | 361 | struct ion_custom_data { |
| 362 | unsigned int cmd; |
| 363 | unsigned long arg; |
| 364 | }; |
Rebecca Schultz Zavin | c80005a | 2011-06-29 19:44:29 -0700 | [diff] [blame] | 365 | #define ION_IOC_MAGIC 'I' |
| 366 | |
| 367 | /** |
| 368 | * DOC: ION_IOC_ALLOC - allocate memory |
| 369 | * |
| 370 | * Takes an ion_allocation_data struct and returns it with the handle field |
| 371 | * populated with the opaque handle for the allocation. |
| 372 | */ |
| 373 | #define ION_IOC_ALLOC _IOWR(ION_IOC_MAGIC, 0, \ |
| 374 | struct ion_allocation_data) |
| 375 | |
| 376 | /** |
| 377 | * DOC: ION_IOC_FREE - free memory |
| 378 | * |
| 379 | * Takes an ion_handle_data struct and frees the handle. |
| 380 | */ |
| 381 | #define ION_IOC_FREE _IOWR(ION_IOC_MAGIC, 1, struct ion_handle_data) |
| 382 | |
| 383 | /** |
| 384 | * DOC: ION_IOC_MAP - get a file descriptor to mmap |
| 385 | * |
| 386 | * Takes an ion_fd_data struct with the handle field populated with a valid |
| 387 | * opaque handle. Returns the struct with the fd field set to a file |
| 388 | * descriptor open in the current address space. This file descriptor |
| 389 | * can then be used as an argument to mmap. |
| 390 | */ |
| 391 | #define ION_IOC_MAP _IOWR(ION_IOC_MAGIC, 2, struct ion_fd_data) |
| 392 | |
| 393 | /** |
| 394 | * DOC: ION_IOC_SHARE - creates a file descriptor to use to share an allocation |
| 395 | * |
| 396 | * Takes an ion_fd_data struct with the handle field populated with a valid |
| 397 | * opaque handle. Returns the struct with the fd field set to a file |
| 398 | * descriptor open in the current address space. This file descriptor |
| 399 | * can then be passed to another process. The corresponding opaque handle can |
| 400 | * be retrieved via ION_IOC_IMPORT. |
| 401 | */ |
| 402 | #define ION_IOC_SHARE _IOWR(ION_IOC_MAGIC, 4, struct ion_fd_data) |
| 403 | |
| 404 | /** |
| 405 | * DOC: ION_IOC_IMPORT - imports a shared file descriptor |
| 406 | * |
| 407 | * Takes an ion_fd_data struct with the fd field populated with a valid file |
| 408 | * descriptor obtained from ION_IOC_SHARE and returns the struct with the handle |
| 409 | * filed set to the corresponding opaque handle. |
| 410 | */ |
Laura Abbott | 0eec151 | 2012-08-27 13:14:39 -0700 | [diff] [blame] | 411 | #define ION_IOC_IMPORT _IOWR(ION_IOC_MAGIC, 5, struct ion_fd_data) |
Rebecca Schultz Zavin | c80005a | 2011-06-29 19:44:29 -0700 | [diff] [blame] | 412 | |
| 413 | /** |
Rebecca Schultz Zavin | f441922 | 2012-06-26 13:17:34 -0700 | [diff] [blame] | 414 | * DOC: ION_IOC_SYNC - syncs a shared file descriptors to memory |
| 415 | * |
| 416 | * Deprecated in favor of using the dma_buf api's correctly (syncing |
| 417 | * will happend automatically when the buffer is mapped to a device). |
| 418 | * If necessary should be used after touching a cached buffer from the cpu, |
| 419 | * this will make the buffer in memory coherent. |
| 420 | */ |
| 421 | #define ION_IOC_SYNC _IOWR(ION_IOC_MAGIC, 7, struct ion_fd_data) |
| 422 | |
| 423 | /** |
Rebecca Schultz Zavin | c80005a | 2011-06-29 19:44:29 -0700 | [diff] [blame] | 424 | * DOC: ION_IOC_CUSTOM - call architecture specific ion ioctl |
| 425 | * |
| 426 | * Takes the argument of the architecture specific ioctl to call and |
| 427 | * passes appropriate userdata for that ioctl |
| 428 | */ |
| 429 | #define ION_IOC_CUSTOM _IOWR(ION_IOC_MAGIC, 6, struct ion_custom_data) |
| 430 | |
Laura Abbott | abcb6f7 | 2011-10-04 16:26:49 -0700 | [diff] [blame] | 431 | |
Rebecca Schultz Zavin | c80005a | 2011-06-29 19:44:29 -0700 | [diff] [blame] | 432 | #endif /* _LINUX_ION_H */ |