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. |
| 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 _LINUX_ION_H |
| 18 | #define _LINUX_ION_H |
| 19 | |
Laura Abbott | abcb6f7 | 2011-10-04 16:26:49 -0700 | [diff] [blame] | 20 | #include <linux/ioctl.h> |
Rebecca Schultz Zavin | c80005a | 2011-06-29 19:44:29 -0700 | [diff] [blame] | 21 | #include <linux/types.h> |
| 22 | |
Laura Abbott | abcb6f7 | 2011-10-04 16:26:49 -0700 | [diff] [blame] | 23 | |
Rebecca Schultz Zavin | c80005a | 2011-06-29 19:44:29 -0700 | [diff] [blame] | 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 |
Iliyan Malchev | f2230156 | 2011-07-06 16:53:21 -0700 | [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, |
Laura Abbott | 8c01736 | 2011-09-22 20:59:12 -0700 | [diff] [blame] | 38 | ION_HEAP_TYPE_IOMMU, |
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 | |
Laura Abbott | a2e9363 | 2011-08-19 13:36:32 -0700 | [diff] [blame] | 48 | |
| 49 | /** |
| 50 | * These are the only ids that should be used for Ion heap ids. |
| 51 | * The ids listed are the order in which allocation will be attempted |
| 52 | * if specified. Don't swap the order of heap ids unless you know what |
| 53 | * you are doing! |
Olav Haugan | b5be799 | 2011-11-18 14:29:02 -0800 | [diff] [blame^] | 54 | * Id's are spaced by purpose to allow new Id's to be inserted in-between (for |
| 55 | * possible fallbacks) |
Laura Abbott | a2e9363 | 2011-08-19 13:36:32 -0700 | [diff] [blame] | 56 | */ |
| 57 | |
| 58 | enum ion_heap_ids { |
Olav Haugan | b5be799 | 2011-11-18 14:29:02 -0800 | [diff] [blame^] | 59 | ION_IOMMU_HEAP_ID = 4, |
| 60 | ION_CP_MM_HEAP_ID = 8, |
| 61 | ION_CP_MFC_HEAP_ID = 12, |
| 62 | ION_CP_WB_HEAP_ID = 16, /* 8660 only */ |
| 63 | ION_CAMERA_HEAP_ID = 20, /* 8660 only */ |
| 64 | ION_SF_HEAP_ID = 24, |
| 65 | ION_AUDIO_HEAP_ID = 28, |
| 66 | |
| 67 | ION_SYSTEM_HEAP_ID = 30, |
| 68 | |
| 69 | ION_HEAP_ID_RESERVED = 31 /** Bit reserved for ION_SECURE flag */ |
Laura Abbott | a2e9363 | 2011-08-19 13:36:32 -0700 | [diff] [blame] | 70 | }; |
| 71 | |
Olav Haugan | b5be799 | 2011-11-18 14:29:02 -0800 | [diff] [blame^] | 72 | /** |
| 73 | * Flag to use when allocating to indicate that a heap is secure. |
| 74 | */ |
| 75 | #define ION_SECURE (1 << ION_HEAP_ID_RESERVED) |
| 76 | |
| 77 | /** |
| 78 | * Macro should be used with ion_heap_ids defined above. |
| 79 | */ |
| 80 | #define ION_HEAP(bit) (1 << (bit)) |
| 81 | |
Laura Abbott | a2e9363 | 2011-08-19 13:36:32 -0700 | [diff] [blame] | 82 | #define ION_VMALLOC_HEAP_NAME "vmalloc" |
Olav Haugan | b5be799 | 2011-11-18 14:29:02 -0800 | [diff] [blame^] | 83 | #define ION_AUDIO_HEAP_NAME "audio" |
| 84 | #define ION_SF_HEAP_NAME "sf" |
| 85 | #define ION_MM_HEAP_NAME "mm" |
| 86 | #define ION_CAMERA_HEAP_NAME "camera_preview" |
Laura Abbott | 8c01736 | 2011-09-22 20:59:12 -0700 | [diff] [blame] | 87 | #define ION_IOMMU_HEAP_NAME "iommu" |
Olav Haugan | b5be799 | 2011-11-18 14:29:02 -0800 | [diff] [blame^] | 88 | #define ION_MFC_HEAP_NAME "mfc" |
| 89 | #define ION_WB_HEAP_NAME "wb" |
Laura Abbott | a2e9363 | 2011-08-19 13:36:32 -0700 | [diff] [blame] | 90 | |
Laura Abbott | 894fd58 | 2011-08-19 13:33:56 -0700 | [diff] [blame] | 91 | #define CACHED 1 |
| 92 | #define UNCACHED 0 |
| 93 | |
| 94 | #define ION_CACHE_SHIFT 0 |
| 95 | |
| 96 | #define ION_SET_CACHE(__cache) ((__cache) << ION_CACHE_SHIFT) |
| 97 | |
Laura Abbott | 3541203 | 2011-09-29 09:50:06 -0700 | [diff] [blame] | 98 | #define ION_IS_CACHED(__flags) ((__flags) & (1 << ION_CACHE_SHIFT)) |
| 99 | |
Rebecca Schultz Zavin | c80005a | 2011-06-29 19:44:29 -0700 | [diff] [blame] | 100 | #ifdef __KERNEL__ |
Laura Abbott | 6557696 | 2011-10-31 12:13:25 -0700 | [diff] [blame] | 101 | #include <linux/err.h> |
Laura Abbott | cffdff5 | 2011-09-23 10:40:19 -0700 | [diff] [blame] | 102 | #include <mach/ion.h> |
Rebecca Schultz Zavin | c80005a | 2011-06-29 19:44:29 -0700 | [diff] [blame] | 103 | struct ion_device; |
| 104 | struct ion_heap; |
| 105 | struct ion_mapper; |
| 106 | struct ion_client; |
| 107 | struct ion_buffer; |
| 108 | |
| 109 | /* This should be removed some day when phys_addr_t's are fully |
| 110 | plumbed in the kernel, and all instances of ion_phys_addr_t should |
| 111 | be converted to phys_addr_t. For the time being many kernel interfaces |
| 112 | do not accept phys_addr_t's that would have to */ |
| 113 | #define ion_phys_addr_t unsigned long |
| 114 | |
Rebecca Schultz Zavin | c80005a | 2011-06-29 19:44:29 -0700 | [diff] [blame] | 115 | /** |
| 116 | * struct ion_platform_heap - defines a heap in the given platform |
| 117 | * @type: type of the heap from ion_heap_type enum |
Olav Haugan | ee0f780 | 2011-12-19 13:28:57 -0800 | [diff] [blame] | 118 | * @id: unique identifier for heap. When allocating (lower numbers |
Olav Haugan | b5be799 | 2011-11-18 14:29:02 -0800 | [diff] [blame^] | 119 | * will be allocated from first) |
Rebecca Schultz Zavin | c80005a | 2011-06-29 19:44:29 -0700 | [diff] [blame] | 120 | * @name: used for debug purposes |
| 121 | * @base: base address of heap in physical memory if applicable |
| 122 | * @size: size of the heap in bytes if applicable |
Alex Bird | 8a3ede3 | 2011-11-07 12:33:42 -0800 | [diff] [blame] | 123 | * @request_region: function to be called when the number of allocations goes |
| 124 | * from 0 -> 1 |
| 125 | * @release_region: function to be called when the number of allocations goes |
| 126 | * from 1 -> 0 |
| 127 | * @setup_region: function to be called upon ion registration |
Rebecca Schultz Zavin | c80005a | 2011-06-29 19:44:29 -0700 | [diff] [blame] | 128 | * |
| 129 | * Provided by the board file. |
| 130 | */ |
| 131 | struct ion_platform_heap { |
| 132 | enum ion_heap_type type; |
Rebecca Schultz Zavin | e6ee124 | 2011-06-30 12:19:55 -0700 | [diff] [blame] | 133 | unsigned int id; |
Rebecca Schultz Zavin | c80005a | 2011-06-29 19:44:29 -0700 | [diff] [blame] | 134 | const char *name; |
| 135 | ion_phys_addr_t base; |
| 136 | size_t size; |
Laura Abbott | a2e9363 | 2011-08-19 13:36:32 -0700 | [diff] [blame] | 137 | enum ion_memory_types memory_type; |
Olav Haugan | ee0f780 | 2011-12-19 13:28:57 -0800 | [diff] [blame] | 138 | int (*request_region)(void *); |
| 139 | int (*release_region)(void *); |
Alex Bird | 8a3ede3 | 2011-11-07 12:33:42 -0800 | [diff] [blame] | 140 | void *(*setup_region)(void); |
Rebecca Schultz Zavin | c80005a | 2011-06-29 19:44:29 -0700 | [diff] [blame] | 141 | }; |
| 142 | |
| 143 | /** |
| 144 | * struct ion_platform_data - array of platform heaps passed from board file |
Alex Bird | 27ca661 | 2011-11-01 14:40:06 -0700 | [diff] [blame] | 145 | * @nr: number of structures in the array |
| 146 | * @request_region: function to be called when the number of allocations goes |
| 147 | * from 0 -> 1 |
| 148 | * @release_region: function to be called when the number of allocations goes |
| 149 | * from 1 -> 0 |
| 150 | * @setup_region: function to be called upon ion registration |
| 151 | * @heaps: array of platform_heap structions |
Rebecca Schultz Zavin | c80005a | 2011-06-29 19:44:29 -0700 | [diff] [blame] | 152 | * |
| 153 | * Provided by the board file in the form of platform data to a platform device. |
| 154 | */ |
| 155 | struct ion_platform_data { |
| 156 | int nr; |
Olav Haugan | ee0f780 | 2011-12-19 13:28:57 -0800 | [diff] [blame] | 157 | int (*request_region)(void *); |
| 158 | int (*release_region)(void *); |
Alex Bird | 27ca661 | 2011-11-01 14:40:06 -0700 | [diff] [blame] | 159 | void *(*setup_region)(void); |
Rebecca Schultz Zavin | c80005a | 2011-06-29 19:44:29 -0700 | [diff] [blame] | 160 | struct ion_platform_heap heaps[]; |
| 161 | }; |
| 162 | |
Jordan Crouse | 8cd4832 | 2011-10-12 17:05:19 -0600 | [diff] [blame] | 163 | #ifdef CONFIG_ION |
| 164 | |
Rebecca Schultz Zavin | c80005a | 2011-06-29 19:44:29 -0700 | [diff] [blame] | 165 | /** |
| 166 | * ion_client_create() - allocate a client and returns it |
| 167 | * @dev: the global ion device |
| 168 | * @heap_mask: mask of heaps this client can allocate from |
| 169 | * @name: used for debugging |
| 170 | */ |
| 171 | struct ion_client *ion_client_create(struct ion_device *dev, |
| 172 | unsigned int heap_mask, const char *name); |
| 173 | |
| 174 | /** |
Laura Abbott | 302911d | 2011-08-15 17:12:57 -0700 | [diff] [blame] | 175 | * msm_ion_client_create - allocate a client using the ion_device specified in |
| 176 | * drivers/gpu/ion/msm/msm_ion.c |
| 177 | * |
| 178 | * heap_mask and name are the same as ion_client_create, return values |
| 179 | * are the same as ion_client_create. |
| 180 | */ |
| 181 | |
| 182 | struct ion_client *msm_ion_client_create(unsigned int heap_mask, |
| 183 | const char *name); |
| 184 | |
| 185 | /** |
Rebecca Schultz Zavin | c80005a | 2011-06-29 19:44:29 -0700 | [diff] [blame] | 186 | * ion_client_destroy() - free's a client and all it's handles |
| 187 | * @client: the client |
| 188 | * |
| 189 | * Free the provided client and all it's resources including |
| 190 | * any handles it is holding. |
| 191 | */ |
| 192 | void ion_client_destroy(struct ion_client *client); |
| 193 | |
| 194 | /** |
| 195 | * ion_alloc - allocate ion memory |
| 196 | * @client: the client |
| 197 | * @len: size of the allocation |
| 198 | * @align: requested allocation alignment, lots of hardware blocks have |
| 199 | * alignment requirements of some kind |
Rebecca Schultz Zavin | e6ee124 | 2011-06-30 12:19:55 -0700 | [diff] [blame] | 200 | * @flags: mask of heaps to allocate from, if multiple bits are set |
| 201 | * heaps will be tried in order from lowest to highest order bit |
Rebecca Schultz Zavin | c80005a | 2011-06-29 19:44:29 -0700 | [diff] [blame] | 202 | * |
| 203 | * Allocate memory in one of the heaps provided in heap mask and return |
| 204 | * an opaque handle to it. |
| 205 | */ |
| 206 | struct ion_handle *ion_alloc(struct ion_client *client, size_t len, |
| 207 | size_t align, unsigned int flags); |
| 208 | |
| 209 | /** |
| 210 | * ion_free - free a handle |
| 211 | * @client: the client |
| 212 | * @handle: the handle to free |
| 213 | * |
| 214 | * Free the provided handle. |
| 215 | */ |
| 216 | void ion_free(struct ion_client *client, struct ion_handle *handle); |
| 217 | |
| 218 | /** |
| 219 | * ion_phys - returns the physical address and len of a handle |
| 220 | * @client: the client |
| 221 | * @handle: the handle |
| 222 | * @addr: a pointer to put the address in |
| 223 | * @len: a pointer to put the length in |
| 224 | * |
| 225 | * This function queries the heap for a particular handle to get the |
| 226 | * handle's physical address. It't output is only correct if |
| 227 | * a heap returns physically contiguous memory -- in other cases |
| 228 | * this api should not be implemented -- ion_map_dma should be used |
| 229 | * instead. Returns -EINVAL if the handle is invalid. This has |
| 230 | * no implications on the reference counting of the handle -- |
| 231 | * the returned value may not be valid if the caller is not |
| 232 | * holding a reference. |
| 233 | */ |
| 234 | int ion_phys(struct ion_client *client, struct ion_handle *handle, |
| 235 | ion_phys_addr_t *addr, size_t *len); |
| 236 | |
| 237 | /** |
| 238 | * ion_map_kernel - create mapping for the given handle |
| 239 | * @client: the client |
| 240 | * @handle: handle to map |
Laura Abbott | 894fd58 | 2011-08-19 13:33:56 -0700 | [diff] [blame] | 241 | * @flags: flags for this mapping |
Rebecca Schultz Zavin | c80005a | 2011-06-29 19:44:29 -0700 | [diff] [blame] | 242 | * |
| 243 | * Map the given handle into the kernel and return a kernel address that |
Laura Abbott | 894fd58 | 2011-08-19 13:33:56 -0700 | [diff] [blame] | 244 | * can be used to access this address. If no flags are specified, this |
| 245 | * will return a non-secure uncached mapping. |
Rebecca Schultz Zavin | c80005a | 2011-06-29 19:44:29 -0700 | [diff] [blame] | 246 | */ |
Laura Abbott | 894fd58 | 2011-08-19 13:33:56 -0700 | [diff] [blame] | 247 | void *ion_map_kernel(struct ion_client *client, struct ion_handle *handle, |
| 248 | unsigned long flags); |
Rebecca Schultz Zavin | c80005a | 2011-06-29 19:44:29 -0700 | [diff] [blame] | 249 | |
| 250 | /** |
| 251 | * ion_unmap_kernel() - destroy a kernel mapping for a handle |
| 252 | * @client: the client |
| 253 | * @handle: handle to unmap |
| 254 | */ |
| 255 | void ion_unmap_kernel(struct ion_client *client, struct ion_handle *handle); |
| 256 | |
| 257 | /** |
| 258 | * ion_map_dma - create a dma mapping for a given handle |
| 259 | * @client: the client |
| 260 | * @handle: handle to map |
| 261 | * |
| 262 | * Return an sglist describing the given handle |
| 263 | */ |
| 264 | struct scatterlist *ion_map_dma(struct ion_client *client, |
Laura Abbott | 894fd58 | 2011-08-19 13:33:56 -0700 | [diff] [blame] | 265 | struct ion_handle *handle, |
| 266 | unsigned long flags); |
Rebecca Schultz Zavin | c80005a | 2011-06-29 19:44:29 -0700 | [diff] [blame] | 267 | |
| 268 | /** |
| 269 | * ion_unmap_dma() - destroy a dma mapping for a handle |
| 270 | * @client: the client |
| 271 | * @handle: handle to unmap |
| 272 | */ |
| 273 | void ion_unmap_dma(struct ion_client *client, struct ion_handle *handle); |
| 274 | |
| 275 | /** |
| 276 | * ion_share() - given a handle, obtain a buffer to pass to other clients |
| 277 | * @client: the client |
| 278 | * @handle: the handle to share |
| 279 | * |
Iliyan Malchev | 3fe2436 | 2011-08-09 14:42:08 -0700 | [diff] [blame] | 280 | * Given a handle, return a buffer, which exists in a global name |
| 281 | * space, and can be passed to other clients. Should be passed into ion_import |
Rebecca Schultz Zavin | c80005a | 2011-06-29 19:44:29 -0700 | [diff] [blame] | 282 | * to obtain a new handle for this buffer. |
Iliyan Malchev | 3fe2436 | 2011-08-09 14:42:08 -0700 | [diff] [blame] | 283 | * |
| 284 | * NOTE: This function does do not an extra reference. The burden is on the |
| 285 | * caller to make sure the buffer doesn't go away while it's being passed to |
| 286 | * another client. That is, ion_free should not be called on this handle until |
| 287 | * the buffer has been imported into the other client. |
Rebecca Schultz Zavin | c80005a | 2011-06-29 19:44:29 -0700 | [diff] [blame] | 288 | */ |
| 289 | struct ion_buffer *ion_share(struct ion_client *client, |
| 290 | struct ion_handle *handle); |
| 291 | |
| 292 | /** |
| 293 | * ion_import() - given an buffer in another client, import it |
| 294 | * @client: this blocks client |
| 295 | * @buffer: the buffer to import (as obtained from ion_share) |
| 296 | * |
| 297 | * Given a buffer, add it to the client and return the handle to use to refer |
| 298 | * to it further. This is called to share a handle from one kernel client to |
| 299 | * another. |
| 300 | */ |
| 301 | struct ion_handle *ion_import(struct ion_client *client, |
| 302 | struct ion_buffer *buffer); |
| 303 | |
| 304 | /** |
| 305 | * ion_import_fd() - given an fd obtained via ION_IOC_SHARE ioctl, import it |
| 306 | * @client: this blocks client |
| 307 | * @fd: the fd |
| 308 | * |
| 309 | * A helper function for drivers that will be recieving ion buffers shared |
| 310 | * with them from userspace. These buffers are represented by a file |
| 311 | * descriptor obtained as the return from the ION_IOC_SHARE ioctl. |
| 312 | * This function coverts that fd into the underlying buffer, and returns |
| 313 | * the handle to use to refer to it further. |
| 314 | */ |
| 315 | struct ion_handle *ion_import_fd(struct ion_client *client, int fd); |
Laura Abbott | 273dd8e | 2011-10-12 14:26:33 -0700 | [diff] [blame] | 316 | |
Laura Abbott | 273dd8e | 2011-10-12 14:26:33 -0700 | [diff] [blame] | 317 | /** |
| 318 | * ion_handle_get_flags - get the flags for a given handle |
| 319 | * |
| 320 | * @client - client who allocated the handle |
| 321 | * @handle - handle to get the flags |
| 322 | * @flags - pointer to store the flags |
| 323 | * |
| 324 | * Gets the current flags for a handle. These flags indicate various options |
| 325 | * of the buffer (caching, security, etc.) |
| 326 | */ |
| 327 | int ion_handle_get_flags(struct ion_client *client, struct ion_handle *handle, |
| 328 | unsigned long *flags); |
| 329 | |
Laura Abbott | 8c01736 | 2011-09-22 20:59:12 -0700 | [diff] [blame] | 330 | |
| 331 | /** |
| 332 | * ion_map_iommu - map the given handle into an iommu |
| 333 | * |
| 334 | * @client - client who allocated the handle |
| 335 | * @handle - handle to map |
| 336 | * @domain_num - domain number to map to |
| 337 | * @partition_num - partition number to allocate iova from |
| 338 | * @align - alignment for the iova |
| 339 | * @iova_length - length of iova to map. If the iova length is |
| 340 | * greater than the handle length, the remaining |
| 341 | * address space will be mapped to a dummy buffer. |
| 342 | * @iova - pointer to store the iova address |
| 343 | * @buffer_size - pointer to store the size of the buffer |
| 344 | * @flags - flags for options to map |
| 345 | * |
| 346 | * Maps the handle into the iova space specified via domain number. Iova |
| 347 | * will be allocated from the partition specified via partition_num. |
| 348 | * Returns 0 on success, negative value on error. |
| 349 | */ |
| 350 | int ion_map_iommu(struct ion_client *client, struct ion_handle *handle, |
| 351 | int domain_num, int partition_num, unsigned long align, |
| 352 | unsigned long iova_length, unsigned long *iova, |
| 353 | unsigned long *buffer_size, |
| 354 | unsigned long flags); |
| 355 | |
| 356 | |
| 357 | /** |
| 358 | * ion_handle_get_size - get the allocated size of a given handle |
| 359 | * |
| 360 | * @client - client who allocated the handle |
| 361 | * @handle - handle to get the size |
| 362 | * @size - pointer to store the size |
| 363 | * |
| 364 | * gives the allocated size of a handle. returns 0 on success, negative |
| 365 | * value on error |
| 366 | * |
| 367 | * NOTE: This is intended to be used only to get a size to pass to map_iommu. |
| 368 | * You should *NOT* rely on this for any other usage. |
| 369 | */ |
| 370 | |
| 371 | int ion_handle_get_size(struct ion_client *client, struct ion_handle *handle, |
| 372 | unsigned long *size); |
| 373 | |
| 374 | /** |
| 375 | * ion_unmap_iommu - unmap the handle from an iommu |
| 376 | * |
| 377 | * @client - client who allocated the handle |
| 378 | * @handle - handle to unmap |
| 379 | * @domain_num - domain to unmap from |
| 380 | * @partition_num - partition to unmap from |
| 381 | * |
| 382 | * Decrement the reference count on the iommu mapping. If the count is |
| 383 | * 0, the mapping will be removed from the iommu. |
| 384 | */ |
| 385 | void ion_unmap_iommu(struct ion_client *client, struct ion_handle *handle, |
| 386 | int domain_num, int partition_num); |
| 387 | |
| 388 | |
Jordan Crouse | 8cd4832 | 2011-10-12 17:05:19 -0600 | [diff] [blame] | 389 | #else |
| 390 | static inline struct ion_client *ion_client_create(struct ion_device *dev, |
| 391 | unsigned int heap_mask, const char *name) |
| 392 | { |
| 393 | return ERR_PTR(-ENODEV); |
| 394 | } |
Laura Abbott | 273dd8e | 2011-10-12 14:26:33 -0700 | [diff] [blame] | 395 | |
Jordan Crouse | 8cd4832 | 2011-10-12 17:05:19 -0600 | [diff] [blame] | 396 | static inline struct ion_client *msm_ion_client_create(unsigned int heap_mask, |
| 397 | const char *name) |
| 398 | { |
| 399 | return ERR_PTR(-ENODEV); |
| 400 | } |
| 401 | |
| 402 | static inline void ion_client_destroy(struct ion_client *client) { } |
| 403 | |
| 404 | static inline struct ion_handle *ion_alloc(struct ion_client *client, |
| 405 | size_t len, size_t align, unsigned int flags) |
| 406 | { |
| 407 | return ERR_PTR(-ENODEV); |
| 408 | } |
| 409 | |
| 410 | static inline void ion_free(struct ion_client *client, |
| 411 | struct ion_handle *handle) { } |
| 412 | |
| 413 | |
| 414 | static inline int ion_phys(struct ion_client *client, |
| 415 | struct ion_handle *handle, ion_phys_addr_t *addr, size_t *len) |
| 416 | { |
| 417 | return -ENODEV; |
| 418 | } |
| 419 | |
| 420 | static inline void *ion_map_kernel(struct ion_client *client, |
| 421 | struct ion_handle *handle, unsigned long flags) |
| 422 | { |
| 423 | return ERR_PTR(-ENODEV); |
| 424 | } |
| 425 | |
| 426 | static inline void ion_unmap_kernel(struct ion_client *client, |
| 427 | struct ion_handle *handle) { } |
| 428 | |
| 429 | static inline struct scatterlist *ion_map_dma(struct ion_client *client, |
| 430 | struct ion_handle *handle, unsigned long flags) |
| 431 | { |
| 432 | return ERR_PTR(-ENODEV); |
| 433 | } |
| 434 | |
| 435 | static inline void ion_unmap_dma(struct ion_client *client, |
| 436 | struct ion_handle *handle) { } |
| 437 | |
| 438 | static inline struct ion_buffer *ion_share(struct ion_client *client, |
| 439 | struct ion_handle *handle) |
| 440 | { |
| 441 | return ERR_PTR(-ENODEV); |
| 442 | } |
| 443 | |
| 444 | static inline struct ion_handle *ion_import(struct ion_client *client, |
| 445 | struct ion_buffer *buffer) |
| 446 | { |
| 447 | return ERR_PTR(-ENODEV); |
| 448 | } |
| 449 | |
| 450 | static inline struct ion_handle *ion_import_fd(struct ion_client *client, |
| 451 | int fd) |
| 452 | { |
| 453 | return ERR_PTR(-ENODEV); |
| 454 | } |
| 455 | |
| 456 | static inline int ion_handle_get_flags(struct ion_client *client, |
| 457 | struct ion_handle *handle, unsigned long *flags) |
| 458 | { |
| 459 | return -ENODEV; |
| 460 | } |
Laura Abbott | 8c01736 | 2011-09-22 20:59:12 -0700 | [diff] [blame] | 461 | |
| 462 | static inline int ion_map_iommu(struct ion_client *client, |
| 463 | struct ion_handle *handle, int domain_num, |
| 464 | int partition_num, unsigned long align, |
| 465 | unsigned long iova_length, unsigned long *iova, |
| 466 | unsigned long flags) |
| 467 | { |
| 468 | return -ENODEV; |
| 469 | } |
| 470 | |
| 471 | static inline void ion_unmap_iommu(struct ion_client *client, |
| 472 | struct ion_handle *handle, int domain_num, |
| 473 | int partition_num) |
| 474 | { |
| 475 | return; |
| 476 | } |
| 477 | |
| 478 | |
Jordan Crouse | 8cd4832 | 2011-10-12 17:05:19 -0600 | [diff] [blame] | 479 | #endif /* CONFIG_ION */ |
Rebecca Schultz Zavin | c80005a | 2011-06-29 19:44:29 -0700 | [diff] [blame] | 480 | #endif /* __KERNEL__ */ |
| 481 | |
| 482 | /** |
| 483 | * DOC: Ion Userspace API |
| 484 | * |
| 485 | * create a client by opening /dev/ion |
| 486 | * most operations handled via following ioctls |
| 487 | * |
| 488 | */ |
| 489 | |
| 490 | /** |
| 491 | * struct ion_allocation_data - metadata passed from userspace for allocations |
| 492 | * @len: size of the allocation |
| 493 | * @align: required alignment of the allocation |
| 494 | * @flags: flags passed to heap |
| 495 | * @handle: pointer that will be populated with a cookie to use to refer |
| 496 | * to this allocation |
| 497 | * |
| 498 | * Provided by userspace as an argument to the ioctl |
| 499 | */ |
| 500 | struct ion_allocation_data { |
| 501 | size_t len; |
| 502 | size_t align; |
| 503 | unsigned int flags; |
| 504 | struct ion_handle *handle; |
| 505 | }; |
| 506 | |
| 507 | /** |
| 508 | * struct ion_fd_data - metadata passed to/from userspace for a handle/fd pair |
| 509 | * @handle: a handle |
| 510 | * @fd: a file descriptor representing that handle |
| 511 | * |
| 512 | * For ION_IOC_SHARE or ION_IOC_MAP userspace populates the handle field with |
| 513 | * the handle returned from ion alloc, and the kernel returns the file |
| 514 | * descriptor to share or map in the fd field. For ION_IOC_IMPORT, userspace |
| 515 | * provides the file descriptor and the kernel returns the handle. |
| 516 | */ |
| 517 | struct ion_fd_data { |
| 518 | struct ion_handle *handle; |
| 519 | int fd; |
| 520 | }; |
| 521 | |
| 522 | /** |
| 523 | * struct ion_handle_data - a handle passed to/from the kernel |
| 524 | * @handle: a handle |
| 525 | */ |
| 526 | struct ion_handle_data { |
| 527 | struct ion_handle *handle; |
| 528 | }; |
| 529 | |
Rebecca Schultz Zavin | e6ee124 | 2011-06-30 12:19:55 -0700 | [diff] [blame] | 530 | /** |
| 531 | * struct ion_custom_data - metadata passed to/from userspace for a custom ioctl |
| 532 | * @cmd: the custom ioctl function to call |
| 533 | * @arg: additional data to pass to the custom ioctl, typically a user |
| 534 | * pointer to a predefined structure |
| 535 | * |
| 536 | * This works just like the regular cmd and arg fields of an ioctl. |
| 537 | */ |
Rebecca Schultz Zavin | c80005a | 2011-06-29 19:44:29 -0700 | [diff] [blame] | 538 | struct ion_custom_data { |
| 539 | unsigned int cmd; |
| 540 | unsigned long arg; |
| 541 | }; |
| 542 | |
Laura Abbott | abcb6f7 | 2011-10-04 16:26:49 -0700 | [diff] [blame] | 543 | |
| 544 | /* struct ion_flush_data - data passed to ion for flushing caches |
| 545 | * |
| 546 | * @handle: handle with data to flush |
Laura Abbott | e80ea01 | 2011-11-18 18:36:47 -0800 | [diff] [blame] | 547 | * @fd: fd to flush |
Laura Abbott | abcb6f7 | 2011-10-04 16:26:49 -0700 | [diff] [blame] | 548 | * @vaddr: userspace virtual address mapped with mmap |
| 549 | * @offset: offset into the handle to flush |
| 550 | * @length: length of handle to flush |
| 551 | * |
| 552 | * Performs cache operations on the handle. If p is the start address |
| 553 | * of the handle, p + offset through p + offset + length will have |
| 554 | * the cache operations performed |
| 555 | */ |
| 556 | struct ion_flush_data { |
| 557 | struct ion_handle *handle; |
Laura Abbott | e80ea01 | 2011-11-18 18:36:47 -0800 | [diff] [blame] | 558 | int fd; |
Laura Abbott | abcb6f7 | 2011-10-04 16:26:49 -0700 | [diff] [blame] | 559 | void *vaddr; |
| 560 | unsigned int offset; |
| 561 | unsigned int length; |
| 562 | }; |
Laura Abbott | 273dd8e | 2011-10-12 14:26:33 -0700 | [diff] [blame] | 563 | |
| 564 | /* struct ion_flag_data - information about flags for this buffer |
| 565 | * |
| 566 | * @handle: handle to get flags from |
| 567 | * @flags: flags of this handle |
| 568 | * |
| 569 | * Takes handle as an input and outputs the flags from the handle |
| 570 | * in the flag field. |
| 571 | */ |
| 572 | struct ion_flag_data { |
| 573 | struct ion_handle *handle; |
| 574 | unsigned long flags; |
| 575 | }; |
| 576 | |
Rebecca Schultz Zavin | c80005a | 2011-06-29 19:44:29 -0700 | [diff] [blame] | 577 | #define ION_IOC_MAGIC 'I' |
| 578 | |
| 579 | /** |
| 580 | * DOC: ION_IOC_ALLOC - allocate memory |
| 581 | * |
| 582 | * Takes an ion_allocation_data struct and returns it with the handle field |
| 583 | * populated with the opaque handle for the allocation. |
| 584 | */ |
| 585 | #define ION_IOC_ALLOC _IOWR(ION_IOC_MAGIC, 0, \ |
| 586 | struct ion_allocation_data) |
| 587 | |
| 588 | /** |
| 589 | * DOC: ION_IOC_FREE - free memory |
| 590 | * |
| 591 | * Takes an ion_handle_data struct and frees the handle. |
| 592 | */ |
| 593 | #define ION_IOC_FREE _IOWR(ION_IOC_MAGIC, 1, struct ion_handle_data) |
| 594 | |
| 595 | /** |
| 596 | * DOC: ION_IOC_MAP - get a file descriptor to mmap |
| 597 | * |
| 598 | * Takes an ion_fd_data struct with the handle field populated with a valid |
| 599 | * opaque handle. Returns the struct with the fd field set to a file |
| 600 | * descriptor open in the current address space. This file descriptor |
| 601 | * can then be used as an argument to mmap. |
| 602 | */ |
| 603 | #define ION_IOC_MAP _IOWR(ION_IOC_MAGIC, 2, struct ion_fd_data) |
| 604 | |
| 605 | /** |
| 606 | * DOC: ION_IOC_SHARE - creates a file descriptor to use to share an allocation |
| 607 | * |
| 608 | * Takes an ion_fd_data struct with the handle field populated with a valid |
| 609 | * opaque handle. Returns the struct with the fd field set to a file |
| 610 | * descriptor open in the current address space. This file descriptor |
| 611 | * can then be passed to another process. The corresponding opaque handle can |
| 612 | * be retrieved via ION_IOC_IMPORT. |
| 613 | */ |
| 614 | #define ION_IOC_SHARE _IOWR(ION_IOC_MAGIC, 4, struct ion_fd_data) |
| 615 | |
| 616 | /** |
| 617 | * DOC: ION_IOC_IMPORT - imports a shared file descriptor |
| 618 | * |
| 619 | * Takes an ion_fd_data struct with the fd field populated with a valid file |
| 620 | * descriptor obtained from ION_IOC_SHARE and returns the struct with the handle |
| 621 | * filed set to the corresponding opaque handle. |
| 622 | */ |
| 623 | #define ION_IOC_IMPORT _IOWR(ION_IOC_MAGIC, 5, int) |
| 624 | |
| 625 | /** |
| 626 | * DOC: ION_IOC_CUSTOM - call architecture specific ion ioctl |
| 627 | * |
| 628 | * Takes the argument of the architecture specific ioctl to call and |
| 629 | * passes appropriate userdata for that ioctl |
| 630 | */ |
| 631 | #define ION_IOC_CUSTOM _IOWR(ION_IOC_MAGIC, 6, struct ion_custom_data) |
| 632 | |
Laura Abbott | abcb6f7 | 2011-10-04 16:26:49 -0700 | [diff] [blame] | 633 | |
| 634 | /** |
| 635 | * DOC: ION_IOC_CLEAN_CACHES - clean the caches |
| 636 | * |
| 637 | * Clean the caches of the handle specified. |
| 638 | */ |
| 639 | #define ION_IOC_CLEAN_CACHES _IOWR(ION_IOC_MAGIC, 7, \ |
| 640 | struct ion_flush_data) |
| 641 | /** |
| 642 | * DOC: ION_MSM_IOC_INV_CACHES - invalidate the caches |
| 643 | * |
| 644 | * Invalidate the caches of the handle specified. |
| 645 | */ |
| 646 | #define ION_IOC_INV_CACHES _IOWR(ION_IOC_MAGIC, 8, \ |
| 647 | struct ion_flush_data) |
| 648 | /** |
| 649 | * DOC: ION_MSM_IOC_CLEAN_CACHES - clean and invalidate the caches |
| 650 | * |
| 651 | * Clean and invalidate the caches of the handle specified. |
| 652 | */ |
| 653 | #define ION_IOC_CLEAN_INV_CACHES _IOWR(ION_IOC_MAGIC, 9, \ |
| 654 | struct ion_flush_data) |
Laura Abbott | 273dd8e | 2011-10-12 14:26:33 -0700 | [diff] [blame] | 655 | |
| 656 | /** |
| 657 | * DOC: ION_IOC_GET_FLAGS - get the flags of the handle |
| 658 | * |
| 659 | * Gets the flags of the current handle which indicate cachability, |
| 660 | * secure state etc. |
| 661 | */ |
| 662 | #define ION_IOC_GET_FLAGS _IOWR(ION_IOC_MAGIC, 10, \ |
| 663 | struct ion_flag_data) |
Rebecca Schultz Zavin | c80005a | 2011-06-29 19:44:29 -0700 | [diff] [blame] | 664 | #endif /* _LINUX_ION_H */ |