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