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. |
Olav Haugan | 0a85251 | 2012-01-09 10:20:55 -0800 | [diff] [blame] | 5 | * Copyright (c) 2011-2012, Code Aurora Forum. 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_TYPE_IOMMU: IOMMU memory |
| 33 | * @ION_HEAP_TYPE_CP: memory allocated from a prereserved |
| 34 | * carveout heap, allocations are physically |
| 35 | * contiguous. Used for content protection. |
Benjamin Gaignard | 07b590e | 2012-08-15 10:55:10 -0700 | [diff] [blame] | 36 | * @ION_HEAP_TYPE_DMA: memory allocated via DMA API |
Olav Haugan | 0a85251 | 2012-01-09 10:20:55 -0800 | [diff] [blame] | 37 | * @ION_HEAP_END: helper for iterating over heaps |
Rebecca Schultz Zavin | c80005a | 2011-06-29 19:44:29 -0700 | [diff] [blame] | 38 | */ |
| 39 | enum ion_heap_type { |
| 40 | ION_HEAP_TYPE_SYSTEM, |
| 41 | ION_HEAP_TYPE_SYSTEM_CONTIG, |
| 42 | ION_HEAP_TYPE_CARVEOUT, |
Benjamin Gaignard | 07b590e | 2012-08-15 10:55:10 -0700 | [diff] [blame] | 43 | ION_HEAP_TYPE_DMA, |
Rebecca Schultz Zavin | c80005a | 2011-06-29 19:44:29 -0700 | [diff] [blame] | 44 | ION_HEAP_TYPE_CUSTOM, /* must be last so device specific heaps always |
| 45 | are at the end of this enum */ |
Rebecca Schultz Zavin | e6ee124 | 2011-06-30 12:19:55 -0700 | [diff] [blame] | 46 | ION_NUM_HEAPS, |
Rebecca Schultz Zavin | c80005a | 2011-06-29 19:44:29 -0700 | [diff] [blame] | 47 | }; |
| 48 | |
Iliyan Malchev | f2230156 | 2011-07-06 16:53:21 -0700 | [diff] [blame] | 49 | #define ION_HEAP_SYSTEM_MASK (1 << ION_HEAP_TYPE_SYSTEM) |
| 50 | #define ION_HEAP_SYSTEM_CONTIG_MASK (1 << ION_HEAP_TYPE_SYSTEM_CONTIG) |
| 51 | #define ION_HEAP_CARVEOUT_MASK (1 << ION_HEAP_TYPE_CARVEOUT) |
Benjamin Gaignard | 07b590e | 2012-08-15 10:55:10 -0700 | [diff] [blame] | 52 | #define ION_HEAP_TYPE_DMA_MASK (1 << ION_HEAP_TYPE_DMA) |
Rebecca Schultz Zavin | c80005a | 2011-06-29 19:44:29 -0700 | [diff] [blame] | 53 | |
Mitchel Humpherys | 227a658 | 2012-09-11 15:59:11 -0700 | [diff] [blame] | 54 | /** |
| 55 | * heap flags - the lower 16 bits are used by core ion, the upper 16 |
| 56 | * bits are reserved for use by the heaps themselves. |
| 57 | */ |
| 58 | #define ION_FLAG_CACHED 1 /* mappings of this buffer should be |
| 59 | cached, ion will do cache |
| 60 | maintenance when the buffer is |
| 61 | mapped for dma */ |
Laura Abbott | a2e9363 | 2011-08-19 13:36:32 -0700 | [diff] [blame] | 62 | |
Rebecca Schultz Zavin | c80005a | 2011-06-29 19:44:29 -0700 | [diff] [blame] | 63 | #ifdef __KERNEL__ |
Laura Abbott | 6557696 | 2011-10-31 12:13:25 -0700 | [diff] [blame] | 64 | #include <linux/err.h> |
Laura Abbott | cffdff5 | 2011-09-23 10:40:19 -0700 | [diff] [blame] | 65 | #include <mach/ion.h> |
Rebecca Schultz Zavin | c80005a | 2011-06-29 19:44:29 -0700 | [diff] [blame] | 66 | struct ion_device; |
| 67 | struct ion_heap; |
| 68 | struct ion_mapper; |
| 69 | struct ion_client; |
| 70 | struct ion_buffer; |
| 71 | |
| 72 | /* This should be removed some day when phys_addr_t's are fully |
| 73 | plumbed in the kernel, and all instances of ion_phys_addr_t should |
| 74 | be converted to phys_addr_t. For the time being many kernel interfaces |
| 75 | do not accept phys_addr_t's that would have to */ |
| 76 | #define ion_phys_addr_t unsigned long |
Laura Abbott | caafeea | 2011-12-13 11:43:10 -0800 | [diff] [blame] | 77 | #define ion_virt_addr_t unsigned long |
Rebecca Schultz Zavin | c80005a | 2011-06-29 19:44:29 -0700 | [diff] [blame] | 78 | |
Rebecca Schultz Zavin | c80005a | 2011-06-29 19:44:29 -0700 | [diff] [blame] | 79 | /** |
| 80 | * struct ion_platform_heap - defines a heap in the given platform |
| 81 | * @type: type of the heap from ion_heap_type enum |
Olav Haugan | ee0f780 | 2011-12-19 13:28:57 -0800 | [diff] [blame] | 82 | * @id: unique identifier for heap. When allocating (lower numbers |
Olav Haugan | b5be799 | 2011-11-18 14:29:02 -0800 | [diff] [blame] | 83 | * will be allocated from first) |
Rebecca Schultz Zavin | c80005a | 2011-06-29 19:44:29 -0700 | [diff] [blame] | 84 | * @name: used for debug purposes |
| 85 | * @base: base address of heap in physical memory if applicable |
| 86 | * @size: size of the heap in bytes if applicable |
Laura Abbott | caafeea | 2011-12-13 11:43:10 -0800 | [diff] [blame] | 87 | * @memory_type:Memory type used for the heap |
Olav Haugan | 85c9540 | 2012-05-30 17:32:37 -0700 | [diff] [blame] | 88 | * @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] | 89 | * @extra_data: Extra data specific to each heap type |
Benjamin Gaignard | 8dff0a6 | 2012-06-25 15:30:18 -0700 | [diff] [blame] | 90 | * @priv: heap private data |
Rebecca Schultz Zavin | c80005a | 2011-06-29 19:44:29 -0700 | [diff] [blame] | 91 | */ |
| 92 | struct ion_platform_heap { |
| 93 | enum ion_heap_type type; |
Rebecca Schultz Zavin | e6ee124 | 2011-06-30 12:19:55 -0700 | [diff] [blame] | 94 | unsigned int id; |
Rebecca Schultz Zavin | c80005a | 2011-06-29 19:44:29 -0700 | [diff] [blame] | 95 | const char *name; |
| 96 | ion_phys_addr_t base; |
| 97 | size_t size; |
Laura Abbott | a2e9363 | 2011-08-19 13:36:32 -0700 | [diff] [blame] | 98 | enum ion_memory_types memory_type; |
Olav Haugan | 85c9540 | 2012-05-30 17:32:37 -0700 | [diff] [blame] | 99 | unsigned int has_outer_cache; |
Olav Haugan | 0703dbf | 2011-12-19 17:53:38 -0800 | [diff] [blame] | 100 | void *extra_data; |
Benjamin Gaignard | 8dff0a6 | 2012-06-25 15:30:18 -0700 | [diff] [blame] | 101 | void *priv; |
Olav Haugan | 0703dbf | 2011-12-19 17:53:38 -0800 | [diff] [blame] | 102 | }; |
| 103 | |
Laura Abbott | caafeea | 2011-12-13 11:43:10 -0800 | [diff] [blame] | 104 | /** |
Rebecca Schultz Zavin | c80005a | 2011-06-29 19:44:29 -0700 | [diff] [blame] | 105 | * struct ion_platform_data - array of platform heaps passed from board file |
Olav Haugan | 85c9540 | 2012-05-30 17:32:37 -0700 | [diff] [blame] | 106 | * @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] | 107 | * @nr: number of structures in the array |
| 108 | * @request_region: function to be called when the number of allocations goes |
| 109 | * from 0 -> 1 |
| 110 | * @release_region: function to be called when the number of allocations goes |
| 111 | * from 1 -> 0 |
| 112 | * @setup_region: function to be called upon ion registration |
| 113 | * @heaps: array of platform_heap structions |
Rebecca Schultz Zavin | c80005a | 2011-06-29 19:44:29 -0700 | [diff] [blame] | 114 | * |
| 115 | * Provided by the board file in the form of platform data to a platform device. |
| 116 | */ |
| 117 | struct ion_platform_data { |
Olav Haugan | 85c9540 | 2012-05-30 17:32:37 -0700 | [diff] [blame] | 118 | unsigned int has_outer_cache; |
Rebecca Schultz Zavin | c80005a | 2011-06-29 19:44:29 -0700 | [diff] [blame] | 119 | int nr; |
Olav Haugan | ee0f780 | 2011-12-19 13:28:57 -0800 | [diff] [blame] | 120 | int (*request_region)(void *); |
| 121 | int (*release_region)(void *); |
Alex Bird | 27ca661 | 2011-11-01 14:40:06 -0700 | [diff] [blame] | 122 | void *(*setup_region)(void); |
Benjamin Gaignard | 63d8103 | 2012-06-25 15:27:30 -0700 | [diff] [blame] | 123 | struct ion_platform_heap *heaps; |
Rebecca Schultz Zavin | c80005a | 2011-06-29 19:44:29 -0700 | [diff] [blame] | 124 | }; |
| 125 | |
Jordan Crouse | 8cd4832 | 2011-10-12 17:05:19 -0600 | [diff] [blame] | 126 | #ifdef CONFIG_ION |
| 127 | |
Rebecca Schultz Zavin | c80005a | 2011-06-29 19:44:29 -0700 | [diff] [blame] | 128 | /** |
Laura Abbott | b14ed96 | 2012-01-30 14:18:08 -0800 | [diff] [blame] | 129 | * ion_reserve() - reserve memory for ion heaps if applicable |
| 130 | * @data: platform data specifying starting physical address and |
| 131 | * size |
| 132 | * |
| 133 | * Calls memblock reserve to set aside memory for heaps that are |
| 134 | * located at specific memory addresses or of specfic sizes not |
| 135 | * managed by the kernel |
| 136 | */ |
| 137 | void ion_reserve(struct ion_platform_data *data); |
| 138 | |
| 139 | /** |
Rebecca Schultz Zavin | c80005a | 2011-06-29 19:44:29 -0700 | [diff] [blame] | 140 | * ion_client_create() - allocate a client and returns it |
| 141 | * @dev: the global ion device |
| 142 | * @heap_mask: mask of heaps this client can allocate from |
| 143 | * @name: used for debugging |
| 144 | */ |
| 145 | struct ion_client *ion_client_create(struct ion_device *dev, |
| 146 | unsigned int heap_mask, const char *name); |
| 147 | |
| 148 | /** |
Laura Abbott | 302911d | 2011-08-15 17:12:57 -0700 | [diff] [blame] | 149 | * msm_ion_client_create - allocate a client using the ion_device specified in |
| 150 | * drivers/gpu/ion/msm/msm_ion.c |
| 151 | * |
| 152 | * heap_mask and name are the same as ion_client_create, return values |
| 153 | * are the same as ion_client_create. |
| 154 | */ |
| 155 | |
| 156 | struct ion_client *msm_ion_client_create(unsigned int heap_mask, |
| 157 | const char *name); |
| 158 | |
| 159 | /** |
Rebecca Schultz Zavin | c80005a | 2011-06-29 19:44:29 -0700 | [diff] [blame] | 160 | * ion_client_destroy() - free's a client and all it's handles |
| 161 | * @client: the client |
| 162 | * |
| 163 | * Free the provided client and all it's resources including |
| 164 | * any handles it is holding. |
| 165 | */ |
| 166 | void ion_client_destroy(struct ion_client *client); |
| 167 | |
| 168 | /** |
| 169 | * ion_alloc - allocate ion memory |
| 170 | * @client: the client |
| 171 | * @len: size of the allocation |
| 172 | * @align: requested allocation alignment, lots of hardware blocks have |
| 173 | * alignment requirements of some kind |
Hanumant Singh | 7d72bad | 2012-08-29 18:39:44 -0700 | [diff] [blame] | 174 | * @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] | 175 | * heaps will be tried in order from lowest to highest order bit |
Hanumant Singh | 7d72bad | 2012-08-29 18:39:44 -0700 | [diff] [blame] | 176 | * @flags: heap flags, the low 16 bits are consumed by ion, the high 16 |
| 177 | * bits are passed on to the respective heap and can be heap |
| 178 | * custom |
Rebecca Schultz Zavin | c80005a | 2011-06-29 19:44:29 -0700 | [diff] [blame] | 179 | * |
| 180 | * Allocate memory in one of the heaps provided in heap mask and return |
| 181 | * an opaque handle to it. |
| 182 | */ |
| 183 | struct ion_handle *ion_alloc(struct ion_client *client, size_t len, |
Hanumant Singh | 7d72bad | 2012-08-29 18:39:44 -0700 | [diff] [blame] | 184 | size_t align, unsigned int heap_mask, |
| 185 | unsigned int flags); |
Rebecca Schultz Zavin | c80005a | 2011-06-29 19:44:29 -0700 | [diff] [blame] | 186 | |
| 187 | /** |
| 188 | * ion_free - free a handle |
| 189 | * @client: the client |
| 190 | * @handle: the handle to free |
| 191 | * |
| 192 | * Free the provided handle. |
| 193 | */ |
| 194 | void ion_free(struct ion_client *client, struct ion_handle *handle); |
| 195 | |
| 196 | /** |
| 197 | * ion_phys - returns the physical address and len of a handle |
| 198 | * @client: the client |
| 199 | * @handle: the handle |
| 200 | * @addr: a pointer to put the address in |
| 201 | * @len: a pointer to put the length in |
| 202 | * |
| 203 | * This function queries the heap for a particular handle to get the |
| 204 | * handle's physical address. It't output is only correct if |
| 205 | * a heap returns physically contiguous memory -- in other cases |
Laura Abbott | b14ed96 | 2012-01-30 14:18:08 -0800 | [diff] [blame] | 206 | * 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] | 207 | * instead. Returns -EINVAL if the handle is invalid. This has |
| 208 | * no implications on the reference counting of the handle -- |
| 209 | * the returned value may not be valid if the caller is not |
| 210 | * holding a reference. |
| 211 | */ |
| 212 | int ion_phys(struct ion_client *client, struct ion_handle *handle, |
| 213 | ion_phys_addr_t *addr, size_t *len); |
| 214 | |
| 215 | /** |
Laura Abbott | b14ed96 | 2012-01-30 14:18:08 -0800 | [diff] [blame] | 216 | * ion_map_dma - return an sg_table describing a handle |
| 217 | * @client: the client |
| 218 | * @handle: the handle |
| 219 | * |
| 220 | * This function returns the sg_table describing |
| 221 | * a particular ion handle. |
| 222 | */ |
| 223 | struct sg_table *ion_sg_table(struct ion_client *client, |
| 224 | struct ion_handle *handle); |
| 225 | |
| 226 | /** |
Rebecca Schultz Zavin | c80005a | 2011-06-29 19:44:29 -0700 | [diff] [blame] | 227 | * ion_map_kernel - create mapping for the given handle |
| 228 | * @client: the client |
| 229 | * @handle: handle to map |
| 230 | * |
| 231 | * 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] | 232 | * can be used to access this address. |
Rebecca Schultz Zavin | c80005a | 2011-06-29 19:44:29 -0700 | [diff] [blame] | 233 | */ |
Mitchel Humpherys | 911b4b7 | 2012-09-12 14:42:50 -0700 | [diff] [blame] | 234 | 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] | 235 | |
| 236 | /** |
| 237 | * ion_unmap_kernel() - destroy a kernel mapping for a handle |
| 238 | * @client: the client |
| 239 | * @handle: handle to unmap |
| 240 | */ |
| 241 | void ion_unmap_kernel(struct ion_client *client, struct ion_handle *handle); |
| 242 | |
| 243 | /** |
Laura Abbott | b14ed96 | 2012-01-30 14:18:08 -0800 | [diff] [blame] | 244 | * 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] | 245 | * @client: the client |
Laura Abbott | b14ed96 | 2012-01-30 14:18:08 -0800 | [diff] [blame] | 246 | * @handle: the handle |
Rebecca Schultz Zavin | c80005a | 2011-06-29 19:44:29 -0700 | [diff] [blame] | 247 | */ |
Laura Abbott | b14ed96 | 2012-01-30 14:18:08 -0800 | [diff] [blame] | 248 | 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] | 249 | |
| 250 | /** |
Laura Abbott | b14ed96 | 2012-01-30 14:18:08 -0800 | [diff] [blame] | 251 | * 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] | 252 | * @client: the client |
Laura Abbott | b14ed96 | 2012-01-30 14:18:08 -0800 | [diff] [blame] | 253 | * @fd: the dma-buf fd |
Rebecca Schultz Zavin | c80005a | 2011-06-29 19:44:29 -0700 | [diff] [blame] | 254 | * |
Laura Abbott | b14ed96 | 2012-01-30 14:18:08 -0800 | [diff] [blame] | 255 | * Given an dma-buf fd that was allocated through ion via ion_share_dma_buf, |
| 256 | * import that fd and return a handle representing it. If a dma-buf from |
| 257 | * 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] | 258 | */ |
Laura Abbott | b14ed96 | 2012-01-30 14:18:08 -0800 | [diff] [blame] | 259 | 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] | 260 | |
Laura Abbott | 273dd8e | 2011-10-12 14:26:33 -0700 | [diff] [blame] | 261 | /** |
| 262 | * ion_handle_get_flags - get the flags for a given handle |
| 263 | * |
| 264 | * @client - client who allocated the handle |
| 265 | * @handle - handle to get the flags |
| 266 | * @flags - pointer to store the flags |
| 267 | * |
| 268 | * Gets the current flags for a handle. These flags indicate various options |
| 269 | * of the buffer (caching, security, etc.) |
| 270 | */ |
| 271 | int ion_handle_get_flags(struct ion_client *client, struct ion_handle *handle, |
| 272 | unsigned long *flags); |
| 273 | |
Laura Abbott | 8c01736 | 2011-09-22 20:59:12 -0700 | [diff] [blame] | 274 | |
| 275 | /** |
| 276 | * ion_map_iommu - map the given handle into an iommu |
| 277 | * |
| 278 | * @client - client who allocated the handle |
| 279 | * @handle - handle to map |
| 280 | * @domain_num - domain number to map to |
| 281 | * @partition_num - partition number to allocate iova from |
| 282 | * @align - alignment for the iova |
| 283 | * @iova_length - length of iova to map. If the iova length is |
| 284 | * greater than the handle length, the remaining |
| 285 | * address space will be mapped to a dummy buffer. |
| 286 | * @iova - pointer to store the iova address |
| 287 | * @buffer_size - pointer to store the size of the buffer |
Mitchel Humpherys | 362b52b | 2012-09-13 10:53:22 -0700 | [diff] [blame] | 288 | * @flags - flags for options to map |
Olav Haugan | b367659 | 2012-03-02 15:02:25 -0800 | [diff] [blame] | 289 | * @iommu_flags - flags specific to the iommu. |
Laura Abbott | 8c01736 | 2011-09-22 20:59:12 -0700 | [diff] [blame] | 290 | * |
| 291 | * Maps the handle into the iova space specified via domain number. Iova |
| 292 | * will be allocated from the partition specified via partition_num. |
| 293 | * Returns 0 on success, negative value on error. |
| 294 | */ |
| 295 | int ion_map_iommu(struct ion_client *client, struct ion_handle *handle, |
| 296 | int domain_num, int partition_num, unsigned long align, |
| 297 | unsigned long iova_length, unsigned long *iova, |
| 298 | unsigned long *buffer_size, |
Olav Haugan | b367659 | 2012-03-02 15:02:25 -0800 | [diff] [blame] | 299 | unsigned long flags, unsigned long iommu_flags); |
Laura Abbott | 8c01736 | 2011-09-22 20:59:12 -0700 | [diff] [blame] | 300 | |
| 301 | |
| 302 | /** |
| 303 | * ion_handle_get_size - get the allocated size of a given handle |
| 304 | * |
| 305 | * @client - client who allocated the handle |
| 306 | * @handle - handle to get the size |
| 307 | * @size - pointer to store the size |
| 308 | * |
| 309 | * gives the allocated size of a handle. returns 0 on success, negative |
| 310 | * value on error |
| 311 | * |
| 312 | * NOTE: This is intended to be used only to get a size to pass to map_iommu. |
| 313 | * You should *NOT* rely on this for any other usage. |
| 314 | */ |
| 315 | |
| 316 | int ion_handle_get_size(struct ion_client *client, struct ion_handle *handle, |
| 317 | unsigned long *size); |
| 318 | |
| 319 | /** |
| 320 | * ion_unmap_iommu - unmap the handle from an iommu |
| 321 | * |
| 322 | * @client - client who allocated the handle |
| 323 | * @handle - handle to unmap |
| 324 | * @domain_num - domain to unmap from |
| 325 | * @partition_num - partition to unmap from |
| 326 | * |
| 327 | * Decrement the reference count on the iommu mapping. If the count is |
| 328 | * 0, the mapping will be removed from the iommu. |
| 329 | */ |
| 330 | void ion_unmap_iommu(struct ion_client *client, struct ion_handle *handle, |
| 331 | int domain_num, int partition_num); |
| 332 | |
| 333 | |
Olav Haugan | 0a85251 | 2012-01-09 10:20:55 -0800 | [diff] [blame] | 334 | /** |
| 335 | * ion_secure_heap - secure a heap |
| 336 | * |
| 337 | * @client - a client that has allocated from the heap heap_id |
| 338 | * @heap_id - heap id to secure. |
Laura Abbott | 7e44648 | 2012-06-13 15:59:39 -0700 | [diff] [blame] | 339 | * @version - version of content protection |
| 340 | * @data - extra data needed for protection |
Olav Haugan | 0a85251 | 2012-01-09 10:20:55 -0800 | [diff] [blame] | 341 | * |
| 342 | * Secure a heap |
| 343 | * Returns 0 on success |
| 344 | */ |
Laura Abbott | 7e44648 | 2012-06-13 15:59:39 -0700 | [diff] [blame] | 345 | int ion_secure_heap(struct ion_device *dev, int heap_id, int version, |
| 346 | void *data); |
Olav Haugan | 0a85251 | 2012-01-09 10:20:55 -0800 | [diff] [blame] | 347 | |
| 348 | /** |
| 349 | * ion_unsecure_heap - un-secure a heap |
| 350 | * |
| 351 | * @client - a client that has allocated from the heap heap_id |
| 352 | * @heap_id - heap id to un-secure. |
Laura Abbott | 7e44648 | 2012-06-13 15:59:39 -0700 | [diff] [blame] | 353 | * @version - version of content protection |
| 354 | * @data - extra data needed for protection |
Olav Haugan | 0a85251 | 2012-01-09 10:20:55 -0800 | [diff] [blame] | 355 | * |
| 356 | * Un-secure a heap |
| 357 | * Returns 0 on success |
| 358 | */ |
Laura Abbott | 7e44648 | 2012-06-13 15:59:39 -0700 | [diff] [blame] | 359 | int ion_unsecure_heap(struct ion_device *dev, int heap_id, int version, |
| 360 | void *data); |
Olav Haugan | 0a85251 | 2012-01-09 10:20:55 -0800 | [diff] [blame] | 361 | |
| 362 | /** |
Olav Haugan | 41f8579 | 2012-02-08 15:28:05 -0800 | [diff] [blame] | 363 | * msm_ion_do_cache_op - do cache operations. |
| 364 | * |
| 365 | * @client - pointer to ION client. |
| 366 | * @handle - pointer to buffer handle. |
| 367 | * @vaddr - virtual address to operate on. |
| 368 | * @len - Length of data to do cache operation on. |
| 369 | * @cmd - Cache operation to perform: |
| 370 | * ION_IOC_CLEAN_CACHES |
| 371 | * ION_IOC_INV_CACHES |
| 372 | * ION_IOC_CLEAN_INV_CACHES |
| 373 | * |
| 374 | * Returns 0 on success |
| 375 | */ |
| 376 | int msm_ion_do_cache_op(struct ion_client *client, struct ion_handle *handle, |
| 377 | void *vaddr, unsigned long len, unsigned int cmd); |
| 378 | |
Jordan Crouse | 8cd4832 | 2011-10-12 17:05:19 -0600 | [diff] [blame] | 379 | #else |
Laura Abbott | b14ed96 | 2012-01-30 14:18:08 -0800 | [diff] [blame] | 380 | static inline void ion_reserve(struct ion_platform_data *data) |
| 381 | { |
| 382 | |
| 383 | } |
| 384 | |
Jordan Crouse | 8cd4832 | 2011-10-12 17:05:19 -0600 | [diff] [blame] | 385 | static inline struct ion_client *ion_client_create(struct ion_device *dev, |
| 386 | unsigned int heap_mask, const char *name) |
| 387 | { |
| 388 | return ERR_PTR(-ENODEV); |
| 389 | } |
Laura Abbott | 273dd8e | 2011-10-12 14:26:33 -0700 | [diff] [blame] | 390 | |
Jordan Crouse | 8cd4832 | 2011-10-12 17:05:19 -0600 | [diff] [blame] | 391 | static inline struct ion_client *msm_ion_client_create(unsigned int heap_mask, |
| 392 | const char *name) |
| 393 | { |
| 394 | return ERR_PTR(-ENODEV); |
| 395 | } |
| 396 | |
| 397 | static inline void ion_client_destroy(struct ion_client *client) { } |
| 398 | |
| 399 | static inline struct ion_handle *ion_alloc(struct ion_client *client, |
Hanumant Singh | 7d72bad | 2012-08-29 18:39:44 -0700 | [diff] [blame] | 400 | size_t len, size_t align, |
| 401 | unsigned int heap_mask, |
| 402 | unsigned int flags) |
Jordan Crouse | 8cd4832 | 2011-10-12 17:05:19 -0600 | [diff] [blame] | 403 | { |
| 404 | return ERR_PTR(-ENODEV); |
| 405 | } |
| 406 | |
| 407 | static inline void ion_free(struct ion_client *client, |
| 408 | struct ion_handle *handle) { } |
| 409 | |
| 410 | |
| 411 | static inline int ion_phys(struct ion_client *client, |
| 412 | struct ion_handle *handle, ion_phys_addr_t *addr, size_t *len) |
| 413 | { |
| 414 | return -ENODEV; |
| 415 | } |
| 416 | |
Laura Abbott | b14ed96 | 2012-01-30 14:18:08 -0800 | [diff] [blame] | 417 | static inline struct sg_table *ion_sg_table(struct ion_client *client, |
| 418 | struct ion_handle *handle) |
| 419 | { |
| 420 | return ERR_PTR(-ENODEV); |
| 421 | } |
| 422 | |
Jordan Crouse | 8cd4832 | 2011-10-12 17:05:19 -0600 | [diff] [blame] | 423 | static inline void *ion_map_kernel(struct ion_client *client, |
Mitchel Humpherys | baa8692 | 2012-11-02 16:35:39 -0700 | [diff] [blame] | 424 | struct ion_handle *handle) |
Jordan Crouse | 8cd4832 | 2011-10-12 17:05:19 -0600 | [diff] [blame] | 425 | { |
| 426 | return ERR_PTR(-ENODEV); |
| 427 | } |
| 428 | |
| 429 | static inline void ion_unmap_kernel(struct ion_client *client, |
| 430 | struct ion_handle *handle) { } |
| 431 | |
Laura Abbott | b14ed96 | 2012-01-30 14:18:08 -0800 | [diff] [blame] | 432 | 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] | 433 | { |
Laura Abbott | b14ed96 | 2012-01-30 14:18:08 -0800 | [diff] [blame] | 434 | return -ENODEV; |
Jordan Crouse | 8cd4832 | 2011-10-12 17:05:19 -0600 | [diff] [blame] | 435 | } |
| 436 | |
Laura Abbott | b14ed96 | 2012-01-30 14:18:08 -0800 | [diff] [blame] | 437 | 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] | 438 | { |
| 439 | return ERR_PTR(-ENODEV); |
| 440 | } |
| 441 | |
| 442 | static inline int ion_handle_get_flags(struct ion_client *client, |
| 443 | struct ion_handle *handle, unsigned long *flags) |
| 444 | { |
| 445 | return -ENODEV; |
| 446 | } |
Laura Abbott | 8c01736 | 2011-09-22 20:59:12 -0700 | [diff] [blame] | 447 | |
| 448 | static inline int ion_map_iommu(struct ion_client *client, |
| 449 | struct ion_handle *handle, int domain_num, |
| 450 | int partition_num, unsigned long align, |
| 451 | unsigned long iova_length, unsigned long *iova, |
Olav Haugan | 9a27d4c | 2012-02-23 09:35:16 -0800 | [diff] [blame] | 452 | unsigned long *buffer_size, |
Olav Haugan | b367659 | 2012-03-02 15:02:25 -0800 | [diff] [blame] | 453 | unsigned long flags, |
| 454 | unsigned long iommu_flags) |
Laura Abbott | 8c01736 | 2011-09-22 20:59:12 -0700 | [diff] [blame] | 455 | { |
| 456 | return -ENODEV; |
| 457 | } |
| 458 | |
Mitchel Humpherys | baa8692 | 2012-11-02 16:35:39 -0700 | [diff] [blame] | 459 | static inline int ion_handle_get_size(struct ion_client *client, |
| 460 | struct ion_handle *handle, unsigned long *size) |
| 461 | { |
| 462 | return -ENODEV; |
| 463 | } |
| 464 | |
Laura Abbott | 8c01736 | 2011-09-22 20:59:12 -0700 | [diff] [blame] | 465 | static inline void ion_unmap_iommu(struct ion_client *client, |
| 466 | struct ion_handle *handle, int domain_num, |
| 467 | int partition_num) |
| 468 | { |
| 469 | return; |
| 470 | } |
| 471 | |
Laura Abbott | 7e44648 | 2012-06-13 15:59:39 -0700 | [diff] [blame] | 472 | static inline int ion_secure_heap(struct ion_device *dev, int heap_id, |
| 473 | int version, void *data) |
Olav Haugan | 0a85251 | 2012-01-09 10:20:55 -0800 | [diff] [blame] | 474 | { |
| 475 | return -ENODEV; |
Laura Abbott | 8c01736 | 2011-09-22 20:59:12 -0700 | [diff] [blame] | 476 | |
Olav Haugan | 0a85251 | 2012-01-09 10:20:55 -0800 | [diff] [blame] | 477 | } |
| 478 | |
Laura Abbott | 7e44648 | 2012-06-13 15:59:39 -0700 | [diff] [blame] | 479 | static inline int ion_unsecure_heap(struct ion_device *dev, int heap_id, |
| 480 | int version, void *data) |
Olav Haugan | 0a85251 | 2012-01-09 10:20:55 -0800 | [diff] [blame] | 481 | { |
| 482 | return -ENODEV; |
| 483 | } |
| 484 | |
Olav Haugan | 41f8579 | 2012-02-08 15:28:05 -0800 | [diff] [blame] | 485 | static inline int msm_ion_do_cache_op(struct ion_client *client, |
| 486 | struct ion_handle *handle, void *vaddr, |
| 487 | unsigned long len, unsigned int cmd) |
| 488 | { |
| 489 | return -ENODEV; |
| 490 | } |
| 491 | |
Jordan Crouse | 8cd4832 | 2011-10-12 17:05:19 -0600 | [diff] [blame] | 492 | #endif /* CONFIG_ION */ |
Rebecca Schultz Zavin | c80005a | 2011-06-29 19:44:29 -0700 | [diff] [blame] | 493 | #endif /* __KERNEL__ */ |
| 494 | |
| 495 | /** |
| 496 | * DOC: Ion Userspace API |
| 497 | * |
| 498 | * create a client by opening /dev/ion |
| 499 | * most operations handled via following ioctls |
| 500 | * |
| 501 | */ |
| 502 | |
| 503 | /** |
| 504 | * struct ion_allocation_data - metadata passed from userspace for allocations |
| 505 | * @len: size of the allocation |
| 506 | * @align: required alignment of the allocation |
Hanumant Singh | 7d72bad | 2012-08-29 18:39:44 -0700 | [diff] [blame] | 507 | * @heap_mask: mask of heaps to allocate from |
Rebecca Schultz Zavin | c80005a | 2011-06-29 19:44:29 -0700 | [diff] [blame] | 508 | * @flags: flags passed to heap |
| 509 | * @handle: pointer that will be populated with a cookie to use to refer |
| 510 | * to this allocation |
| 511 | * |
| 512 | * Provided by userspace as an argument to the ioctl |
| 513 | */ |
| 514 | struct ion_allocation_data { |
| 515 | size_t len; |
| 516 | size_t align; |
Laura Abbott | 0eec151 | 2012-08-27 13:14:39 -0700 | [diff] [blame] | 517 | unsigned int heap_mask; |
Rebecca Schultz Zavin | c80005a | 2011-06-29 19:44:29 -0700 | [diff] [blame] | 518 | unsigned int flags; |
| 519 | struct ion_handle *handle; |
| 520 | }; |
| 521 | |
| 522 | /** |
| 523 | * struct ion_fd_data - metadata passed to/from userspace for a handle/fd pair |
| 524 | * @handle: a handle |
| 525 | * @fd: a file descriptor representing that handle |
| 526 | * |
| 527 | * For ION_IOC_SHARE or ION_IOC_MAP userspace populates the handle field with |
| 528 | * the handle returned from ion alloc, and the kernel returns the file |
| 529 | * descriptor to share or map in the fd field. For ION_IOC_IMPORT, userspace |
| 530 | * provides the file descriptor and the kernel returns the handle. |
| 531 | */ |
| 532 | struct ion_fd_data { |
| 533 | struct ion_handle *handle; |
| 534 | int fd; |
| 535 | }; |
| 536 | |
| 537 | /** |
| 538 | * struct ion_handle_data - a handle passed to/from the kernel |
| 539 | * @handle: a handle |
| 540 | */ |
| 541 | struct ion_handle_data { |
| 542 | struct ion_handle *handle; |
| 543 | }; |
| 544 | |
Rebecca Schultz Zavin | e6ee124 | 2011-06-30 12:19:55 -0700 | [diff] [blame] | 545 | /** |
| 546 | * struct ion_custom_data - metadata passed to/from userspace for a custom ioctl |
| 547 | * @cmd: the custom ioctl function to call |
| 548 | * @arg: additional data to pass to the custom ioctl, typically a user |
| 549 | * pointer to a predefined structure |
| 550 | * |
| 551 | * This works just like the regular cmd and arg fields of an ioctl. |
| 552 | */ |
Rebecca Schultz Zavin | c80005a | 2011-06-29 19:44:29 -0700 | [diff] [blame] | 553 | struct ion_custom_data { |
| 554 | unsigned int cmd; |
| 555 | unsigned long arg; |
| 556 | }; |
Rebecca Schultz Zavin | c80005a | 2011-06-29 19:44:29 -0700 | [diff] [blame] | 557 | #define ION_IOC_MAGIC 'I' |
| 558 | |
| 559 | /** |
| 560 | * DOC: ION_IOC_ALLOC - allocate memory |
| 561 | * |
| 562 | * Takes an ion_allocation_data struct and returns it with the handle field |
| 563 | * populated with the opaque handle for the allocation. |
| 564 | */ |
| 565 | #define ION_IOC_ALLOC _IOWR(ION_IOC_MAGIC, 0, \ |
| 566 | struct ion_allocation_data) |
| 567 | |
| 568 | /** |
| 569 | * DOC: ION_IOC_FREE - free memory |
| 570 | * |
| 571 | * Takes an ion_handle_data struct and frees the handle. |
| 572 | */ |
| 573 | #define ION_IOC_FREE _IOWR(ION_IOC_MAGIC, 1, struct ion_handle_data) |
| 574 | |
| 575 | /** |
| 576 | * DOC: ION_IOC_MAP - get a file descriptor to mmap |
| 577 | * |
| 578 | * Takes an ion_fd_data struct with the handle field populated with a valid |
| 579 | * opaque handle. Returns the struct with the fd field set to a file |
| 580 | * descriptor open in the current address space. This file descriptor |
| 581 | * can then be used as an argument to mmap. |
| 582 | */ |
| 583 | #define ION_IOC_MAP _IOWR(ION_IOC_MAGIC, 2, struct ion_fd_data) |
| 584 | |
| 585 | /** |
| 586 | * DOC: ION_IOC_SHARE - creates a file descriptor to use to share an allocation |
| 587 | * |
| 588 | * Takes an ion_fd_data struct with the handle field populated with a valid |
| 589 | * opaque handle. Returns the struct with the fd field set to a file |
| 590 | * descriptor open in the current address space. This file descriptor |
| 591 | * can then be passed to another process. The corresponding opaque handle can |
| 592 | * be retrieved via ION_IOC_IMPORT. |
| 593 | */ |
| 594 | #define ION_IOC_SHARE _IOWR(ION_IOC_MAGIC, 4, struct ion_fd_data) |
| 595 | |
| 596 | /** |
| 597 | * DOC: ION_IOC_IMPORT - imports a shared file descriptor |
| 598 | * |
| 599 | * Takes an ion_fd_data struct with the fd field populated with a valid file |
| 600 | * descriptor obtained from ION_IOC_SHARE and returns the struct with the handle |
| 601 | * filed set to the corresponding opaque handle. |
| 602 | */ |
Laura Abbott | 0eec151 | 2012-08-27 13:14:39 -0700 | [diff] [blame] | 603 | #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] | 604 | |
| 605 | /** |
| 606 | * DOC: ION_IOC_CUSTOM - call architecture specific ion ioctl |
| 607 | * |
| 608 | * Takes the argument of the architecture specific ioctl to call and |
| 609 | * passes appropriate userdata for that ioctl |
| 610 | */ |
| 611 | #define ION_IOC_CUSTOM _IOWR(ION_IOC_MAGIC, 6, struct ion_custom_data) |
| 612 | |
Laura Abbott | abcb6f7 | 2011-10-04 16:26:49 -0700 | [diff] [blame] | 613 | |
Rebecca Schultz Zavin | c80005a | 2011-06-29 19:44:29 -0700 | [diff] [blame] | 614 | #endif /* _LINUX_ION_H */ |