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. |
| 36 | * @ION_HEAP_END: helper for iterating over heaps |
Rebecca Schultz Zavin | c80005a | 2011-06-29 19:44:29 -0700 | [diff] [blame] | 37 | */ |
| 38 | enum ion_heap_type { |
| 39 | ION_HEAP_TYPE_SYSTEM, |
| 40 | ION_HEAP_TYPE_SYSTEM_CONTIG, |
| 41 | ION_HEAP_TYPE_CARVEOUT, |
Laura Abbott | 8c01736 | 2011-09-22 20:59:12 -0700 | [diff] [blame] | 42 | ION_HEAP_TYPE_IOMMU, |
Olav Haugan | 0a85251 | 2012-01-09 10:20:55 -0800 | [diff] [blame] | 43 | ION_HEAP_TYPE_CP, |
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) |
Olav Haugan | 0a85251 | 2012-01-09 10:20:55 -0800 | [diff] [blame] | 52 | #define ION_HEAP_CP_MASK (1 << ION_HEAP_TYPE_CP) |
Rebecca Schultz Zavin | c80005a | 2011-06-29 19:44:29 -0700 | [diff] [blame] | 53 | |
Mitchel Humpherys | 97e2123 | 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 | |
| 63 | /** |
| 64 | * These are the only ids that should be used for Ion heap ids. |
| 65 | * The ids listed are the order in which allocation will be attempted |
| 66 | * if specified. Don't swap the order of heap ids unless you know what |
| 67 | * you are doing! |
Olav Haugan | b5be799 | 2011-11-18 14:29:02 -0800 | [diff] [blame] | 68 | * Id's are spaced by purpose to allow new Id's to be inserted in-between (for |
| 69 | * possible fallbacks) |
Laura Abbott | a2e9363 | 2011-08-19 13:36:32 -0700 | [diff] [blame] | 70 | */ |
| 71 | |
| 72 | enum ion_heap_ids { |
Olav Haugan | 42ebe71 | 2012-01-10 16:30:58 -0800 | [diff] [blame] | 73 | INVALID_HEAP_ID = -1, |
Olav Haugan | b5be799 | 2011-11-18 14:29:02 -0800 | [diff] [blame] | 74 | ION_CP_MM_HEAP_ID = 8, |
| 75 | ION_CP_MFC_HEAP_ID = 12, |
| 76 | ION_CP_WB_HEAP_ID = 16, /* 8660 only */ |
| 77 | ION_CAMERA_HEAP_ID = 20, /* 8660 only */ |
| 78 | ION_SF_HEAP_ID = 24, |
Olav Haugan | 9e123f9 | 2012-02-15 15:41:48 -0800 | [diff] [blame] | 79 | ION_IOMMU_HEAP_ID = 25, |
Olav Haugan | 80854eb | 2012-01-12 12:00:23 -0800 | [diff] [blame] | 80 | ION_QSECOM_HEAP_ID = 27, |
Olav Haugan | b5be799 | 2011-11-18 14:29:02 -0800 | [diff] [blame] | 81 | ION_AUDIO_HEAP_ID = 28, |
| 82 | |
Olav Haugan | 42ebe71 | 2012-01-10 16:30:58 -0800 | [diff] [blame] | 83 | ION_MM_FIRMWARE_HEAP_ID = 29, |
Olav Haugan | b5be799 | 2011-11-18 14:29:02 -0800 | [diff] [blame] | 84 | ION_SYSTEM_HEAP_ID = 30, |
| 85 | |
| 86 | ION_HEAP_ID_RESERVED = 31 /** Bit reserved for ION_SECURE flag */ |
Laura Abbott | a2e9363 | 2011-08-19 13:36:32 -0700 | [diff] [blame] | 87 | }; |
| 88 | |
Larry Bassel | 2d8b42d | 2012-03-12 10:41:26 -0700 | [diff] [blame] | 89 | enum ion_fixed_position { |
| 90 | NOT_FIXED, |
| 91 | FIXED_LOW, |
| 92 | FIXED_MIDDLE, |
| 93 | FIXED_HIGH, |
| 94 | }; |
| 95 | |
Laura Abbott | d0c83de | 2012-06-12 18:49:57 -0700 | [diff] [blame] | 96 | enum cp_mem_usage { |
| 97 | VIDEO_BITSTREAM = 0x1, |
| 98 | VIDEO_PIXEL = 0x2, |
| 99 | VIDEO_NONPIXEL = 0x3, |
| 100 | MAX_USAGE = 0x4, |
| 101 | UNKNOWN = 0x7FFFFFFF, |
| 102 | }; |
| 103 | |
Olav Haugan | b5be799 | 2011-11-18 14:29:02 -0800 | [diff] [blame] | 104 | /** |
| 105 | * Flag to use when allocating to indicate that a heap is secure. |
| 106 | */ |
| 107 | #define ION_SECURE (1 << ION_HEAP_ID_RESERVED) |
| 108 | |
| 109 | /** |
| 110 | * Macro should be used with ion_heap_ids defined above. |
| 111 | */ |
| 112 | #define ION_HEAP(bit) (1 << (bit)) |
| 113 | |
Laura Abbott | a2e9363 | 2011-08-19 13:36:32 -0700 | [diff] [blame] | 114 | #define ION_VMALLOC_HEAP_NAME "vmalloc" |
Olav Haugan | b5be799 | 2011-11-18 14:29:02 -0800 | [diff] [blame] | 115 | #define ION_AUDIO_HEAP_NAME "audio" |
| 116 | #define ION_SF_HEAP_NAME "sf" |
| 117 | #define ION_MM_HEAP_NAME "mm" |
| 118 | #define ION_CAMERA_HEAP_NAME "camera_preview" |
Laura Abbott | 8c01736 | 2011-09-22 20:59:12 -0700 | [diff] [blame] | 119 | #define ION_IOMMU_HEAP_NAME "iommu" |
Olav Haugan | b5be799 | 2011-11-18 14:29:02 -0800 | [diff] [blame] | 120 | #define ION_MFC_HEAP_NAME "mfc" |
| 121 | #define ION_WB_HEAP_NAME "wb" |
Olav Haugan | 42ebe71 | 2012-01-10 16:30:58 -0800 | [diff] [blame] | 122 | #define ION_MM_FIRMWARE_HEAP_NAME "mm_fw" |
Olav Haugan | 80854eb | 2012-01-12 12:00:23 -0800 | [diff] [blame] | 123 | #define ION_QSECOM_HEAP_NAME "qsecom" |
Laura Abbott | caafeea | 2011-12-13 11:43:10 -0800 | [diff] [blame] | 124 | #define ION_FMEM_HEAP_NAME "fmem" |
Laura Abbott | a2e9363 | 2011-08-19 13:36:32 -0700 | [diff] [blame] | 125 | |
Mitchel Humpherys | 97e2123 | 2012-09-11 15:59:11 -0700 | [diff] [blame] | 126 | #define ION_SET_CACHED(__cache) (__cache | ION_FLAG_CACHED) |
| 127 | #define ION_SET_UNCACHED(__cache) (__cache & ~ION_FLAG_CACHED) |
Laura Abbott | 894fd58 | 2011-08-19 13:33:56 -0700 | [diff] [blame] | 128 | |
Mitchel Humpherys | 97e2123 | 2012-09-11 15:59:11 -0700 | [diff] [blame] | 129 | #define ION_IS_CACHED(__flags) ((__flags) & ION_FLAG_CACHED) |
Laura Abbott | 894fd58 | 2011-08-19 13:33:56 -0700 | [diff] [blame] | 130 | |
Laura Abbott | 3541203 | 2011-09-29 09:50:06 -0700 | [diff] [blame] | 131 | |
Olav Haugan | b367659 | 2012-03-02 15:02:25 -0800 | [diff] [blame] | 132 | /* |
| 133 | * This flag allows clients when mapping into the IOMMU to specify to |
| 134 | * defer un-mapping from the IOMMU until the buffer memory is freed. |
| 135 | */ |
| 136 | #define ION_IOMMU_UNMAP_DELAYED 1 |
| 137 | |
Rebecca Schultz Zavin | c80005a | 2011-06-29 19:44:29 -0700 | [diff] [blame] | 138 | #ifdef __KERNEL__ |
Laura Abbott | 6557696 | 2011-10-31 12:13:25 -0700 | [diff] [blame] | 139 | #include <linux/err.h> |
Laura Abbott | cffdff5 | 2011-09-23 10:40:19 -0700 | [diff] [blame] | 140 | #include <mach/ion.h> |
Rebecca Schultz Zavin | c80005a | 2011-06-29 19:44:29 -0700 | [diff] [blame] | 141 | struct ion_device; |
| 142 | struct ion_heap; |
| 143 | struct ion_mapper; |
| 144 | struct ion_client; |
| 145 | struct ion_buffer; |
| 146 | |
| 147 | /* This should be removed some day when phys_addr_t's are fully |
| 148 | plumbed in the kernel, and all instances of ion_phys_addr_t should |
| 149 | be converted to phys_addr_t. For the time being many kernel interfaces |
| 150 | do not accept phys_addr_t's that would have to */ |
| 151 | #define ion_phys_addr_t unsigned long |
Laura Abbott | caafeea | 2011-12-13 11:43:10 -0800 | [diff] [blame] | 152 | #define ion_virt_addr_t unsigned long |
Rebecca Schultz Zavin | c80005a | 2011-06-29 19:44:29 -0700 | [diff] [blame] | 153 | |
Rebecca Schultz Zavin | c80005a | 2011-06-29 19:44:29 -0700 | [diff] [blame] | 154 | /** |
| 155 | * struct ion_platform_heap - defines a heap in the given platform |
| 156 | * @type: type of the heap from ion_heap_type enum |
Olav Haugan | ee0f780 | 2011-12-19 13:28:57 -0800 | [diff] [blame] | 157 | * @id: unique identifier for heap. When allocating (lower numbers |
Olav Haugan | b5be799 | 2011-11-18 14:29:02 -0800 | [diff] [blame] | 158 | * will be allocated from first) |
Rebecca Schultz Zavin | c80005a | 2011-06-29 19:44:29 -0700 | [diff] [blame] | 159 | * @name: used for debug purposes |
| 160 | * @base: base address of heap in physical memory if applicable |
| 161 | * @size: size of the heap in bytes if applicable |
Laura Abbott | caafeea | 2011-12-13 11:43:10 -0800 | [diff] [blame] | 162 | * @memory_type:Memory type used for the heap |
Olav Haugan | 85c9540 | 2012-05-30 17:32:37 -0700 | [diff] [blame] | 163 | * @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] | 164 | * @extra_data: Extra data specific to each heap type |
Rebecca Schultz Zavin | c80005a | 2011-06-29 19:44:29 -0700 | [diff] [blame] | 165 | */ |
| 166 | struct ion_platform_heap { |
| 167 | enum ion_heap_type type; |
Rebecca Schultz Zavin | e6ee124 | 2011-06-30 12:19:55 -0700 | [diff] [blame] | 168 | unsigned int id; |
Rebecca Schultz Zavin | c80005a | 2011-06-29 19:44:29 -0700 | [diff] [blame] | 169 | const char *name; |
| 170 | ion_phys_addr_t base; |
| 171 | size_t size; |
Laura Abbott | a2e9363 | 2011-08-19 13:36:32 -0700 | [diff] [blame] | 172 | enum ion_memory_types memory_type; |
Olav Haugan | 85c9540 | 2012-05-30 17:32:37 -0700 | [diff] [blame] | 173 | unsigned int has_outer_cache; |
Olav Haugan | 0703dbf | 2011-12-19 17:53:38 -0800 | [diff] [blame] | 174 | void *extra_data; |
| 175 | }; |
| 176 | |
Laura Abbott | caafeea | 2011-12-13 11:43:10 -0800 | [diff] [blame] | 177 | /** |
| 178 | * struct ion_cp_heap_pdata - defines a content protection heap in the given |
| 179 | * platform |
| 180 | * @permission_type: Memory ID used to identify the memory to TZ |
| 181 | * @align: Alignment requirement for the memory |
| 182 | * @secure_base: Base address for securing the heap. |
| 183 | * Note: This might be different from actual base address |
| 184 | * of this heap in the case of a shared heap. |
| 185 | * @secure_size: Memory size for securing the heap. |
| 186 | * Note: This might be different from actual size |
| 187 | * of this heap in the case of a shared heap. |
| 188 | * @reusable Flag indicating whether this heap is reusable of not. |
| 189 | * (see FMEM) |
Olav Haugan | f6dc774 | 2012-02-15 09:11:55 -0800 | [diff] [blame] | 190 | * @mem_is_fmem Flag indicating whether this memory is coming from fmem |
| 191 | * or not. |
Larry Bassel | 2d8b42d | 2012-03-12 10:41:26 -0700 | [diff] [blame] | 192 | * @fixed_position If nonzero, position in the fixed area. |
Laura Abbott | caafeea | 2011-12-13 11:43:10 -0800 | [diff] [blame] | 193 | * @virt_addr: Virtual address used when using fmem. |
Olav Haugan | 8726caf | 2012-05-10 15:11:35 -0700 | [diff] [blame] | 194 | * @iommu_map_all: Indicates whether we should map whole heap into IOMMU. |
| 195 | * @iommu_2x_map_domain: Indicates the domain to use for overmapping. |
Laura Abbott | caafeea | 2011-12-13 11:43:10 -0800 | [diff] [blame] | 196 | * @request_region: function to be called when the number of allocations |
| 197 | * goes from 0 -> 1 |
| 198 | * @release_region: function to be called when the number of allocations |
| 199 | * goes from 1 -> 0 |
| 200 | * @setup_region: function to be called upon ion registration |
| 201 | * |
| 202 | */ |
Olav Haugan | 0703dbf | 2011-12-19 17:53:38 -0800 | [diff] [blame] | 203 | struct ion_cp_heap_pdata { |
Olav Haugan | 0a85251 | 2012-01-09 10:20:55 -0800 | [diff] [blame] | 204 | enum ion_permission_type permission_type; |
Olav Haugan | 42ebe71 | 2012-01-10 16:30:58 -0800 | [diff] [blame] | 205 | unsigned int align; |
| 206 | ion_phys_addr_t secure_base; /* Base addr used when heap is shared */ |
| 207 | size_t secure_size; /* Size used for securing heap when heap is shared*/ |
Laura Abbott | caafeea | 2011-12-13 11:43:10 -0800 | [diff] [blame] | 208 | int reusable; |
Olav Haugan | f6dc774 | 2012-02-15 09:11:55 -0800 | [diff] [blame] | 209 | int mem_is_fmem; |
Larry Bassel | 2d8b42d | 2012-03-12 10:41:26 -0700 | [diff] [blame] | 210 | enum ion_fixed_position fixed_position; |
Olav Haugan | 8726caf | 2012-05-10 15:11:35 -0700 | [diff] [blame] | 211 | int iommu_map_all; |
| 212 | int iommu_2x_map_domain; |
Laura Abbott | caafeea | 2011-12-13 11:43:10 -0800 | [diff] [blame] | 213 | ion_virt_addr_t *virt_addr; |
Olav Haugan | ee0f780 | 2011-12-19 13:28:57 -0800 | [diff] [blame] | 214 | int (*request_region)(void *); |
| 215 | int (*release_region)(void *); |
Alex Bird | 8a3ede3 | 2011-11-07 12:33:42 -0800 | [diff] [blame] | 216 | void *(*setup_region)(void); |
Rebecca Schultz Zavin | c80005a | 2011-06-29 19:44:29 -0700 | [diff] [blame] | 217 | }; |
| 218 | |
Laura Abbott | caafeea | 2011-12-13 11:43:10 -0800 | [diff] [blame] | 219 | /** |
| 220 | * struct ion_co_heap_pdata - defines a carveout heap in the given platform |
| 221 | * @adjacent_mem_id: Id of heap that this heap must be adjacent to. |
| 222 | * @align: Alignment requirement for the memory |
Olav Haugan | f6dc774 | 2012-02-15 09:11:55 -0800 | [diff] [blame] | 223 | * @mem_is_fmem Flag indicating whether this memory is coming from fmem |
| 224 | * or not. |
Larry Bassel | 2d8b42d | 2012-03-12 10:41:26 -0700 | [diff] [blame] | 225 | * @fixed_position If nonzero, position in the fixed area. |
Laura Abbott | caafeea | 2011-12-13 11:43:10 -0800 | [diff] [blame] | 226 | * @request_region: function to be called when the number of allocations |
| 227 | * goes from 0 -> 1 |
| 228 | * @release_region: function to be called when the number of allocations |
| 229 | * goes from 1 -> 0 |
| 230 | * @setup_region: function to be called upon ion registration |
| 231 | * |
| 232 | */ |
Olav Haugan | 0703dbf | 2011-12-19 17:53:38 -0800 | [diff] [blame] | 233 | struct ion_co_heap_pdata { |
Olav Haugan | 42ebe71 | 2012-01-10 16:30:58 -0800 | [diff] [blame] | 234 | int adjacent_mem_id; |
| 235 | unsigned int align; |
Olav Haugan | f6dc774 | 2012-02-15 09:11:55 -0800 | [diff] [blame] | 236 | int mem_is_fmem; |
Larry Bassel | 2d8b42d | 2012-03-12 10:41:26 -0700 | [diff] [blame] | 237 | enum ion_fixed_position fixed_position; |
Olav Haugan | 0703dbf | 2011-12-19 17:53:38 -0800 | [diff] [blame] | 238 | int (*request_region)(void *); |
| 239 | int (*release_region)(void *); |
| 240 | void *(*setup_region)(void); |
| 241 | }; |
| 242 | |
Rebecca Schultz Zavin | c80005a | 2011-06-29 19:44:29 -0700 | [diff] [blame] | 243 | /** |
| 244 | * struct ion_platform_data - array of platform heaps passed from board file |
Olav Haugan | 85c9540 | 2012-05-30 17:32:37 -0700 | [diff] [blame] | 245 | * @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] | 246 | * @nr: number of structures in the array |
| 247 | * @request_region: function to be called when the number of allocations goes |
| 248 | * from 0 -> 1 |
| 249 | * @release_region: function to be called when the number of allocations goes |
| 250 | * from 1 -> 0 |
| 251 | * @setup_region: function to be called upon ion registration |
| 252 | * @heaps: array of platform_heap structions |
Rebecca Schultz Zavin | c80005a | 2011-06-29 19:44:29 -0700 | [diff] [blame] | 253 | * |
| 254 | * Provided by the board file in the form of platform data to a platform device. |
| 255 | */ |
| 256 | struct ion_platform_data { |
Olav Haugan | 85c9540 | 2012-05-30 17:32:37 -0700 | [diff] [blame] | 257 | unsigned int has_outer_cache; |
Rebecca Schultz Zavin | c80005a | 2011-06-29 19:44:29 -0700 | [diff] [blame] | 258 | int nr; |
Olav Haugan | ee0f780 | 2011-12-19 13:28:57 -0800 | [diff] [blame] | 259 | int (*request_region)(void *); |
| 260 | int (*release_region)(void *); |
Alex Bird | 27ca661 | 2011-11-01 14:40:06 -0700 | [diff] [blame] | 261 | void *(*setup_region)(void); |
Rebecca Schultz Zavin | c80005a | 2011-06-29 19:44:29 -0700 | [diff] [blame] | 262 | struct ion_platform_heap heaps[]; |
| 263 | }; |
| 264 | |
Jordan Crouse | 8cd4832 | 2011-10-12 17:05:19 -0600 | [diff] [blame] | 265 | #ifdef CONFIG_ION |
| 266 | |
Rebecca Schultz Zavin | c80005a | 2011-06-29 19:44:29 -0700 | [diff] [blame] | 267 | /** |
Laura Abbott | b14ed96 | 2012-01-30 14:18:08 -0800 | [diff] [blame] | 268 | * ion_reserve() - reserve memory for ion heaps if applicable |
| 269 | * @data: platform data specifying starting physical address and |
| 270 | * size |
| 271 | * |
| 272 | * Calls memblock reserve to set aside memory for heaps that are |
| 273 | * located at specific memory addresses or of specfic sizes not |
| 274 | * managed by the kernel |
| 275 | */ |
| 276 | void ion_reserve(struct ion_platform_data *data); |
| 277 | |
| 278 | /** |
Rebecca Schultz Zavin | c80005a | 2011-06-29 19:44:29 -0700 | [diff] [blame] | 279 | * ion_client_create() - allocate a client and returns it |
| 280 | * @dev: the global ion device |
| 281 | * @heap_mask: mask of heaps this client can allocate from |
| 282 | * @name: used for debugging |
| 283 | */ |
| 284 | struct ion_client *ion_client_create(struct ion_device *dev, |
| 285 | unsigned int heap_mask, const char *name); |
| 286 | |
| 287 | /** |
Laura Abbott | 302911d | 2011-08-15 17:12:57 -0700 | [diff] [blame] | 288 | * msm_ion_client_create - allocate a client using the ion_device specified in |
| 289 | * drivers/gpu/ion/msm/msm_ion.c |
| 290 | * |
| 291 | * heap_mask and name are the same as ion_client_create, return values |
| 292 | * are the same as ion_client_create. |
| 293 | */ |
| 294 | |
| 295 | struct ion_client *msm_ion_client_create(unsigned int heap_mask, |
| 296 | const char *name); |
| 297 | |
| 298 | /** |
Rebecca Schultz Zavin | c80005a | 2011-06-29 19:44:29 -0700 | [diff] [blame] | 299 | * ion_client_destroy() - free's a client and all it's handles |
| 300 | * @client: the client |
| 301 | * |
| 302 | * Free the provided client and all it's resources including |
| 303 | * any handles it is holding. |
| 304 | */ |
| 305 | void ion_client_destroy(struct ion_client *client); |
| 306 | |
| 307 | /** |
| 308 | * ion_alloc - allocate ion memory |
| 309 | * @client: the client |
| 310 | * @len: size of the allocation |
| 311 | * @align: requested allocation alignment, lots of hardware blocks have |
| 312 | * alignment requirements of some kind |
Hanumant Singh | 2ac41c9 | 2012-08-29 18:39:44 -0700 | [diff] [blame] | 313 | * @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] | 314 | * heaps will be tried in order from lowest to highest order bit |
Hanumant Singh | 2ac41c9 | 2012-08-29 18:39:44 -0700 | [diff] [blame] | 315 | * @flags: heap flags, the low 16 bits are consumed by ion, the high 16 |
| 316 | * bits are passed on to the respective heap and can be heap |
| 317 | * custom |
Rebecca Schultz Zavin | c80005a | 2011-06-29 19:44:29 -0700 | [diff] [blame] | 318 | * |
| 319 | * Allocate memory in one of the heaps provided in heap mask and return |
| 320 | * an opaque handle to it. |
| 321 | */ |
| 322 | struct ion_handle *ion_alloc(struct ion_client *client, size_t len, |
Hanumant Singh | 2ac41c9 | 2012-08-29 18:39:44 -0700 | [diff] [blame] | 323 | size_t align, unsigned int heap_mask, |
| 324 | unsigned int flags); |
Rebecca Schultz Zavin | c80005a | 2011-06-29 19:44:29 -0700 | [diff] [blame] | 325 | |
| 326 | /** |
| 327 | * ion_free - free a handle |
| 328 | * @client: the client |
| 329 | * @handle: the handle to free |
| 330 | * |
| 331 | * Free the provided handle. |
| 332 | */ |
| 333 | void ion_free(struct ion_client *client, struct ion_handle *handle); |
| 334 | |
| 335 | /** |
| 336 | * ion_phys - returns the physical address and len of a handle |
| 337 | * @client: the client |
| 338 | * @handle: the handle |
| 339 | * @addr: a pointer to put the address in |
| 340 | * @len: a pointer to put the length in |
| 341 | * |
| 342 | * This function queries the heap for a particular handle to get the |
| 343 | * handle's physical address. It't output is only correct if |
| 344 | * a heap returns physically contiguous memory -- in other cases |
Laura Abbott | b14ed96 | 2012-01-30 14:18:08 -0800 | [diff] [blame] | 345 | * 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] | 346 | * instead. Returns -EINVAL if the handle is invalid. This has |
| 347 | * no implications on the reference counting of the handle -- |
| 348 | * the returned value may not be valid if the caller is not |
| 349 | * holding a reference. |
| 350 | */ |
| 351 | int ion_phys(struct ion_client *client, struct ion_handle *handle, |
| 352 | ion_phys_addr_t *addr, size_t *len); |
| 353 | |
| 354 | /** |
Laura Abbott | b14ed96 | 2012-01-30 14:18:08 -0800 | [diff] [blame] | 355 | * ion_map_dma - return an sg_table describing a handle |
| 356 | * @client: the client |
| 357 | * @handle: the handle |
| 358 | * |
| 359 | * This function returns the sg_table describing |
| 360 | * a particular ion handle. |
| 361 | */ |
| 362 | struct sg_table *ion_sg_table(struct ion_client *client, |
| 363 | struct ion_handle *handle); |
| 364 | |
| 365 | /** |
Rebecca Schultz Zavin | c80005a | 2011-06-29 19:44:29 -0700 | [diff] [blame] | 366 | * ion_map_kernel - create mapping for the given handle |
| 367 | * @client: the client |
| 368 | * @handle: handle to map |
Laura Abbott | 894fd58 | 2011-08-19 13:33:56 -0700 | [diff] [blame] | 369 | * @flags: flags for this mapping |
Rebecca Schultz Zavin | c80005a | 2011-06-29 19:44:29 -0700 | [diff] [blame] | 370 | * |
| 371 | * 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] | 372 | * can be used to access this address. If no flags are specified, this |
| 373 | * will return a non-secure uncached mapping. |
Rebecca Schultz Zavin | c80005a | 2011-06-29 19:44:29 -0700 | [diff] [blame] | 374 | */ |
Mitchel Humpherys | 456e268 | 2012-09-12 14:42:50 -0700 | [diff] [blame^] | 375 | 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] | 376 | |
| 377 | /** |
| 378 | * ion_unmap_kernel() - destroy a kernel mapping for a handle |
| 379 | * @client: the client |
| 380 | * @handle: handle to unmap |
| 381 | */ |
| 382 | void ion_unmap_kernel(struct ion_client *client, struct ion_handle *handle); |
| 383 | |
| 384 | /** |
Laura Abbott | b14ed96 | 2012-01-30 14:18:08 -0800 | [diff] [blame] | 385 | * 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] | 386 | * @client: the client |
Laura Abbott | b14ed96 | 2012-01-30 14:18:08 -0800 | [diff] [blame] | 387 | * @handle: the handle |
Rebecca Schultz Zavin | c80005a | 2011-06-29 19:44:29 -0700 | [diff] [blame] | 388 | */ |
Laura Abbott | b14ed96 | 2012-01-30 14:18:08 -0800 | [diff] [blame] | 389 | 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] | 390 | |
| 391 | /** |
Laura Abbott | b14ed96 | 2012-01-30 14:18:08 -0800 | [diff] [blame] | 392 | * 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] | 393 | * @client: the client |
Laura Abbott | b14ed96 | 2012-01-30 14:18:08 -0800 | [diff] [blame] | 394 | * @fd: the dma-buf fd |
Rebecca Schultz Zavin | c80005a | 2011-06-29 19:44:29 -0700 | [diff] [blame] | 395 | * |
Laura Abbott | b14ed96 | 2012-01-30 14:18:08 -0800 | [diff] [blame] | 396 | * Given an dma-buf fd that was allocated through ion via ion_share_dma_buf, |
| 397 | * import that fd and return a handle representing it. If a dma-buf from |
| 398 | * 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] | 399 | */ |
Laura Abbott | b14ed96 | 2012-01-30 14:18:08 -0800 | [diff] [blame] | 400 | 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] | 401 | |
Laura Abbott | 273dd8e | 2011-10-12 14:26:33 -0700 | [diff] [blame] | 402 | /** |
| 403 | * ion_handle_get_flags - get the flags for a given handle |
| 404 | * |
| 405 | * @client - client who allocated the handle |
| 406 | * @handle - handle to get the flags |
| 407 | * @flags - pointer to store the flags |
| 408 | * |
| 409 | * Gets the current flags for a handle. These flags indicate various options |
| 410 | * of the buffer (caching, security, etc.) |
| 411 | */ |
| 412 | int ion_handle_get_flags(struct ion_client *client, struct ion_handle *handle, |
| 413 | unsigned long *flags); |
| 414 | |
Laura Abbott | 8c01736 | 2011-09-22 20:59:12 -0700 | [diff] [blame] | 415 | |
| 416 | /** |
| 417 | * ion_map_iommu - map the given handle into an iommu |
| 418 | * |
| 419 | * @client - client who allocated the handle |
| 420 | * @handle - handle to map |
| 421 | * @domain_num - domain number to map to |
| 422 | * @partition_num - partition number to allocate iova from |
| 423 | * @align - alignment for the iova |
| 424 | * @iova_length - length of iova to map. If the iova length is |
| 425 | * greater than the handle length, the remaining |
| 426 | * address space will be mapped to a dummy buffer. |
| 427 | * @iova - pointer to store the iova address |
| 428 | * @buffer_size - pointer to store the size of the buffer |
Olav Haugan | b367659 | 2012-03-02 15:02:25 -0800 | [diff] [blame] | 429 | * @iommu_flags - flags specific to the iommu. |
Laura Abbott | 8c01736 | 2011-09-22 20:59:12 -0700 | [diff] [blame] | 430 | * |
| 431 | * Maps the handle into the iova space specified via domain number. Iova |
| 432 | * will be allocated from the partition specified via partition_num. |
| 433 | * Returns 0 on success, negative value on error. |
| 434 | */ |
| 435 | int ion_map_iommu(struct ion_client *client, struct ion_handle *handle, |
| 436 | int domain_num, int partition_num, unsigned long align, |
| 437 | unsigned long iova_length, unsigned long *iova, |
| 438 | unsigned long *buffer_size, |
Olav Haugan | b367659 | 2012-03-02 15:02:25 -0800 | [diff] [blame] | 439 | unsigned long flags, unsigned long iommu_flags); |
Laura Abbott | 8c01736 | 2011-09-22 20:59:12 -0700 | [diff] [blame] | 440 | |
| 441 | |
| 442 | /** |
| 443 | * ion_handle_get_size - get the allocated size of a given handle |
| 444 | * |
| 445 | * @client - client who allocated the handle |
| 446 | * @handle - handle to get the size |
| 447 | * @size - pointer to store the size |
| 448 | * |
| 449 | * gives the allocated size of a handle. returns 0 on success, negative |
| 450 | * value on error |
| 451 | * |
| 452 | * NOTE: This is intended to be used only to get a size to pass to map_iommu. |
| 453 | * You should *NOT* rely on this for any other usage. |
| 454 | */ |
| 455 | |
| 456 | int ion_handle_get_size(struct ion_client *client, struct ion_handle *handle, |
| 457 | unsigned long *size); |
| 458 | |
| 459 | /** |
| 460 | * ion_unmap_iommu - unmap the handle from an iommu |
| 461 | * |
| 462 | * @client - client who allocated the handle |
| 463 | * @handle - handle to unmap |
| 464 | * @domain_num - domain to unmap from |
| 465 | * @partition_num - partition to unmap from |
| 466 | * |
| 467 | * Decrement the reference count on the iommu mapping. If the count is |
| 468 | * 0, the mapping will be removed from the iommu. |
| 469 | */ |
| 470 | void ion_unmap_iommu(struct ion_client *client, struct ion_handle *handle, |
| 471 | int domain_num, int partition_num); |
| 472 | |
| 473 | |
Olav Haugan | 0a85251 | 2012-01-09 10:20:55 -0800 | [diff] [blame] | 474 | /** |
| 475 | * ion_secure_heap - secure a heap |
| 476 | * |
| 477 | * @client - a client that has allocated from the heap heap_id |
| 478 | * @heap_id - heap id to secure. |
Laura Abbott | 7e44648 | 2012-06-13 15:59:39 -0700 | [diff] [blame] | 479 | * @version - version of content protection |
| 480 | * @data - extra data needed for protection |
Olav Haugan | 0a85251 | 2012-01-09 10:20:55 -0800 | [diff] [blame] | 481 | * |
| 482 | * Secure a heap |
| 483 | * Returns 0 on success |
| 484 | */ |
Laura Abbott | 7e44648 | 2012-06-13 15:59:39 -0700 | [diff] [blame] | 485 | int ion_secure_heap(struct ion_device *dev, int heap_id, int version, |
| 486 | void *data); |
Olav Haugan | 0a85251 | 2012-01-09 10:20:55 -0800 | [diff] [blame] | 487 | |
| 488 | /** |
| 489 | * ion_unsecure_heap - un-secure a heap |
| 490 | * |
| 491 | * @client - a client that has allocated from the heap heap_id |
| 492 | * @heap_id - heap id to un-secure. |
Laura Abbott | 7e44648 | 2012-06-13 15:59:39 -0700 | [diff] [blame] | 493 | * @version - version of content protection |
| 494 | * @data - extra data needed for protection |
Olav Haugan | 0a85251 | 2012-01-09 10:20:55 -0800 | [diff] [blame] | 495 | * |
| 496 | * Un-secure a heap |
| 497 | * Returns 0 on success |
| 498 | */ |
Laura Abbott | 7e44648 | 2012-06-13 15:59:39 -0700 | [diff] [blame] | 499 | int ion_unsecure_heap(struct ion_device *dev, int heap_id, int version, |
| 500 | void *data); |
Olav Haugan | 0a85251 | 2012-01-09 10:20:55 -0800 | [diff] [blame] | 501 | |
| 502 | /** |
| 503 | * msm_ion_secure_heap - secure a heap. Wrapper around ion_secure_heap. |
| 504 | * |
| 505 | * @heap_id - heap id to secure. |
| 506 | * |
| 507 | * Secure a heap |
| 508 | * Returns 0 on success |
| 509 | */ |
| 510 | int msm_ion_secure_heap(int heap_id); |
| 511 | |
| 512 | /** |
| 513 | * msm_ion_unsecure_heap - unsecure a heap. Wrapper around ion_unsecure_heap. |
| 514 | * |
| 515 | * @heap_id - heap id to secure. |
| 516 | * |
| 517 | * Un-secure a heap |
| 518 | * Returns 0 on success |
| 519 | */ |
| 520 | int msm_ion_unsecure_heap(int heap_id); |
| 521 | |
Olav Haugan | 41f8579 | 2012-02-08 15:28:05 -0800 | [diff] [blame] | 522 | /** |
Laura Abbott | 7e44648 | 2012-06-13 15:59:39 -0700 | [diff] [blame] | 523 | * msm_ion_secure_heap_2_0 - secure a heap using 2.0 APIs |
| 524 | * Wrapper around ion_secure_heap. |
| 525 | * |
| 526 | * @heap_id - heap id to secure. |
| 527 | * @usage - usage hint to TZ |
| 528 | * |
| 529 | * Secure a heap |
| 530 | * Returns 0 on success |
| 531 | */ |
| 532 | int msm_ion_secure_heap_2_0(int heap_id, enum cp_mem_usage usage); |
| 533 | |
| 534 | /** |
| 535 | * msm_ion_unsecure_heap - unsecure a heap secured with 3.0 APIs. |
| 536 | * Wrapper around ion_unsecure_heap. |
| 537 | * |
| 538 | * @heap_id - heap id to secure. |
| 539 | * @usage - usage hint to TZ |
| 540 | * |
| 541 | * Un-secure a heap |
| 542 | * Returns 0 on success |
| 543 | */ |
| 544 | int msm_ion_unsecure_heap_2_0(int heap_id, enum cp_mem_usage usage); |
| 545 | |
| 546 | /** |
Olav Haugan | 41f8579 | 2012-02-08 15:28:05 -0800 | [diff] [blame] | 547 | * msm_ion_do_cache_op - do cache operations. |
| 548 | * |
| 549 | * @client - pointer to ION client. |
| 550 | * @handle - pointer to buffer handle. |
| 551 | * @vaddr - virtual address to operate on. |
| 552 | * @len - Length of data to do cache operation on. |
| 553 | * @cmd - Cache operation to perform: |
| 554 | * ION_IOC_CLEAN_CACHES |
| 555 | * ION_IOC_INV_CACHES |
| 556 | * ION_IOC_CLEAN_INV_CACHES |
| 557 | * |
| 558 | * Returns 0 on success |
| 559 | */ |
| 560 | int msm_ion_do_cache_op(struct ion_client *client, struct ion_handle *handle, |
| 561 | void *vaddr, unsigned long len, unsigned int cmd); |
| 562 | |
Jordan Crouse | 8cd4832 | 2011-10-12 17:05:19 -0600 | [diff] [blame] | 563 | #else |
Laura Abbott | b14ed96 | 2012-01-30 14:18:08 -0800 | [diff] [blame] | 564 | static inline void ion_reserve(struct ion_platform_data *data) |
| 565 | { |
| 566 | |
| 567 | } |
| 568 | |
Jordan Crouse | 8cd4832 | 2011-10-12 17:05:19 -0600 | [diff] [blame] | 569 | static inline struct ion_client *ion_client_create(struct ion_device *dev, |
| 570 | unsigned int heap_mask, const char *name) |
| 571 | { |
| 572 | return ERR_PTR(-ENODEV); |
| 573 | } |
Laura Abbott | 273dd8e | 2011-10-12 14:26:33 -0700 | [diff] [blame] | 574 | |
Jordan Crouse | 8cd4832 | 2011-10-12 17:05:19 -0600 | [diff] [blame] | 575 | static inline struct ion_client *msm_ion_client_create(unsigned int heap_mask, |
| 576 | const char *name) |
| 577 | { |
| 578 | return ERR_PTR(-ENODEV); |
| 579 | } |
| 580 | |
| 581 | static inline void ion_client_destroy(struct ion_client *client) { } |
| 582 | |
| 583 | static inline struct ion_handle *ion_alloc(struct ion_client *client, |
Hanumant Singh | 2ac41c9 | 2012-08-29 18:39:44 -0700 | [diff] [blame] | 584 | size_t len, size_t align, |
| 585 | unsigned int heap_mask, |
| 586 | unsigned int flags) |
Jordan Crouse | 8cd4832 | 2011-10-12 17:05:19 -0600 | [diff] [blame] | 587 | { |
| 588 | return ERR_PTR(-ENODEV); |
| 589 | } |
| 590 | |
| 591 | static inline void ion_free(struct ion_client *client, |
| 592 | struct ion_handle *handle) { } |
| 593 | |
| 594 | |
| 595 | static inline int ion_phys(struct ion_client *client, |
| 596 | struct ion_handle *handle, ion_phys_addr_t *addr, size_t *len) |
| 597 | { |
| 598 | return -ENODEV; |
| 599 | } |
| 600 | |
Laura Abbott | b14ed96 | 2012-01-30 14:18:08 -0800 | [diff] [blame] | 601 | static inline struct sg_table *ion_sg_table(struct ion_client *client, |
| 602 | struct ion_handle *handle) |
| 603 | { |
| 604 | return ERR_PTR(-ENODEV); |
| 605 | } |
| 606 | |
Jordan Crouse | 8cd4832 | 2011-10-12 17:05:19 -0600 | [diff] [blame] | 607 | static inline void *ion_map_kernel(struct ion_client *client, |
| 608 | struct ion_handle *handle, unsigned long flags) |
| 609 | { |
| 610 | return ERR_PTR(-ENODEV); |
| 611 | } |
| 612 | |
| 613 | static inline void ion_unmap_kernel(struct ion_client *client, |
| 614 | struct ion_handle *handle) { } |
| 615 | |
Laura Abbott | b14ed96 | 2012-01-30 14:18:08 -0800 | [diff] [blame] | 616 | 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] | 617 | { |
Laura Abbott | b14ed96 | 2012-01-30 14:18:08 -0800 | [diff] [blame] | 618 | return -ENODEV; |
Jordan Crouse | 8cd4832 | 2011-10-12 17:05:19 -0600 | [diff] [blame] | 619 | } |
| 620 | |
Laura Abbott | b14ed96 | 2012-01-30 14:18:08 -0800 | [diff] [blame] | 621 | 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] | 622 | { |
| 623 | return ERR_PTR(-ENODEV); |
| 624 | } |
| 625 | |
| 626 | static inline int ion_handle_get_flags(struct ion_client *client, |
| 627 | struct ion_handle *handle, unsigned long *flags) |
| 628 | { |
| 629 | return -ENODEV; |
| 630 | } |
Laura Abbott | 8c01736 | 2011-09-22 20:59:12 -0700 | [diff] [blame] | 631 | |
| 632 | static inline int ion_map_iommu(struct ion_client *client, |
| 633 | struct ion_handle *handle, int domain_num, |
| 634 | int partition_num, unsigned long align, |
| 635 | unsigned long iova_length, unsigned long *iova, |
Olav Haugan | 9a27d4c | 2012-02-23 09:35:16 -0800 | [diff] [blame] | 636 | unsigned long *buffer_size, |
Olav Haugan | b367659 | 2012-03-02 15:02:25 -0800 | [diff] [blame] | 637 | unsigned long flags, |
| 638 | unsigned long iommu_flags) |
Laura Abbott | 8c01736 | 2011-09-22 20:59:12 -0700 | [diff] [blame] | 639 | { |
| 640 | return -ENODEV; |
| 641 | } |
| 642 | |
| 643 | static inline void ion_unmap_iommu(struct ion_client *client, |
| 644 | struct ion_handle *handle, int domain_num, |
| 645 | int partition_num) |
| 646 | { |
| 647 | return; |
| 648 | } |
| 649 | |
Laura Abbott | 7e44648 | 2012-06-13 15:59:39 -0700 | [diff] [blame] | 650 | static inline int ion_secure_heap(struct ion_device *dev, int heap_id, |
| 651 | int version, void *data) |
Olav Haugan | 0a85251 | 2012-01-09 10:20:55 -0800 | [diff] [blame] | 652 | { |
| 653 | return -ENODEV; |
Laura Abbott | 8c01736 | 2011-09-22 20:59:12 -0700 | [diff] [blame] | 654 | |
Olav Haugan | 0a85251 | 2012-01-09 10:20:55 -0800 | [diff] [blame] | 655 | } |
| 656 | |
Laura Abbott | 7e44648 | 2012-06-13 15:59:39 -0700 | [diff] [blame] | 657 | static inline int ion_unsecure_heap(struct ion_device *dev, int heap_id, |
| 658 | int version, void *data) |
Olav Haugan | 0a85251 | 2012-01-09 10:20:55 -0800 | [diff] [blame] | 659 | { |
| 660 | return -ENODEV; |
| 661 | } |
| 662 | |
| 663 | static inline int msm_ion_secure_heap(int heap_id) |
| 664 | { |
| 665 | return -ENODEV; |
| 666 | |
| 667 | } |
| 668 | |
| 669 | static inline int msm_ion_unsecure_heap(int heap_id) |
| 670 | { |
| 671 | return -ENODEV; |
| 672 | } |
Olav Haugan | 41f8579 | 2012-02-08 15:28:05 -0800 | [diff] [blame] | 673 | |
Laura Abbott | 7e44648 | 2012-06-13 15:59:39 -0700 | [diff] [blame] | 674 | static inline int msm_ion_secure_heap_2_0(int heap_id, enum cp_mem_usage usage) |
| 675 | { |
| 676 | return -ENODEV; |
| 677 | } |
| 678 | |
| 679 | static inline int msm_ion_unsecure_heap_2_0(int heap_id, |
| 680 | enum cp_mem_usage usage) |
| 681 | { |
| 682 | return -ENODEV; |
| 683 | } |
| 684 | |
Olav Haugan | 41f8579 | 2012-02-08 15:28:05 -0800 | [diff] [blame] | 685 | static inline int msm_ion_do_cache_op(struct ion_client *client, |
| 686 | struct ion_handle *handle, void *vaddr, |
| 687 | unsigned long len, unsigned int cmd) |
| 688 | { |
| 689 | return -ENODEV; |
| 690 | } |
| 691 | |
Jordan Crouse | 8cd4832 | 2011-10-12 17:05:19 -0600 | [diff] [blame] | 692 | #endif /* CONFIG_ION */ |
Rebecca Schultz Zavin | c80005a | 2011-06-29 19:44:29 -0700 | [diff] [blame] | 693 | #endif /* __KERNEL__ */ |
| 694 | |
| 695 | /** |
| 696 | * DOC: Ion Userspace API |
| 697 | * |
| 698 | * create a client by opening /dev/ion |
| 699 | * most operations handled via following ioctls |
| 700 | * |
| 701 | */ |
| 702 | |
| 703 | /** |
| 704 | * struct ion_allocation_data - metadata passed from userspace for allocations |
| 705 | * @len: size of the allocation |
| 706 | * @align: required alignment of the allocation |
Brian Muramatsu | b6b0b65 | 2012-07-30 22:54:08 -0700 | [diff] [blame] | 707 | * @heap_mask: mask of heaps to allocate from |
Rebecca Schultz Zavin | c80005a | 2011-06-29 19:44:29 -0700 | [diff] [blame] | 708 | * @flags: flags passed to heap |
| 709 | * @handle: pointer that will be populated with a cookie to use to refer |
| 710 | * to this allocation |
| 711 | * |
| 712 | * Provided by userspace as an argument to the ioctl |
| 713 | */ |
| 714 | struct ion_allocation_data { |
| 715 | size_t len; |
| 716 | size_t align; |
Brian Muramatsu | b6b0b65 | 2012-07-30 22:54:08 -0700 | [diff] [blame] | 717 | unsigned int heap_mask; |
Rebecca Schultz Zavin | c80005a | 2011-06-29 19:44:29 -0700 | [diff] [blame] | 718 | unsigned int flags; |
| 719 | struct ion_handle *handle; |
| 720 | }; |
| 721 | |
| 722 | /** |
| 723 | * struct ion_fd_data - metadata passed to/from userspace for a handle/fd pair |
| 724 | * @handle: a handle |
| 725 | * @fd: a file descriptor representing that handle |
| 726 | * |
| 727 | * For ION_IOC_SHARE or ION_IOC_MAP userspace populates the handle field with |
| 728 | * the handle returned from ion alloc, and the kernel returns the file |
| 729 | * descriptor to share or map in the fd field. For ION_IOC_IMPORT, userspace |
| 730 | * provides the file descriptor and the kernel returns the handle. |
| 731 | */ |
| 732 | struct ion_fd_data { |
| 733 | struct ion_handle *handle; |
| 734 | int fd; |
| 735 | }; |
| 736 | |
| 737 | /** |
| 738 | * struct ion_handle_data - a handle passed to/from the kernel |
| 739 | * @handle: a handle |
| 740 | */ |
| 741 | struct ion_handle_data { |
| 742 | struct ion_handle *handle; |
| 743 | }; |
| 744 | |
Rebecca Schultz Zavin | e6ee124 | 2011-06-30 12:19:55 -0700 | [diff] [blame] | 745 | /** |
| 746 | * struct ion_custom_data - metadata passed to/from userspace for a custom ioctl |
| 747 | * @cmd: the custom ioctl function to call |
| 748 | * @arg: additional data to pass to the custom ioctl, typically a user |
| 749 | * pointer to a predefined structure |
| 750 | * |
| 751 | * This works just like the regular cmd and arg fields of an ioctl. |
| 752 | */ |
Rebecca Schultz Zavin | c80005a | 2011-06-29 19:44:29 -0700 | [diff] [blame] | 753 | struct ion_custom_data { |
| 754 | unsigned int cmd; |
| 755 | unsigned long arg; |
| 756 | }; |
| 757 | |
Laura Abbott | abcb6f7 | 2011-10-04 16:26:49 -0700 | [diff] [blame] | 758 | |
| 759 | /* struct ion_flush_data - data passed to ion for flushing caches |
| 760 | * |
| 761 | * @handle: handle with data to flush |
Laura Abbott | e80ea01 | 2011-11-18 18:36:47 -0800 | [diff] [blame] | 762 | * @fd: fd to flush |
Laura Abbott | abcb6f7 | 2011-10-04 16:26:49 -0700 | [diff] [blame] | 763 | * @vaddr: userspace virtual address mapped with mmap |
| 764 | * @offset: offset into the handle to flush |
| 765 | * @length: length of handle to flush |
| 766 | * |
| 767 | * Performs cache operations on the handle. If p is the start address |
| 768 | * of the handle, p + offset through p + offset + length will have |
| 769 | * the cache operations performed |
| 770 | */ |
| 771 | struct ion_flush_data { |
| 772 | struct ion_handle *handle; |
Laura Abbott | e80ea01 | 2011-11-18 18:36:47 -0800 | [diff] [blame] | 773 | int fd; |
Laura Abbott | abcb6f7 | 2011-10-04 16:26:49 -0700 | [diff] [blame] | 774 | void *vaddr; |
| 775 | unsigned int offset; |
| 776 | unsigned int length; |
| 777 | }; |
Laura Abbott | 273dd8e | 2011-10-12 14:26:33 -0700 | [diff] [blame] | 778 | |
| 779 | /* struct ion_flag_data - information about flags for this buffer |
| 780 | * |
| 781 | * @handle: handle to get flags from |
| 782 | * @flags: flags of this handle |
| 783 | * |
| 784 | * Takes handle as an input and outputs the flags from the handle |
| 785 | * in the flag field. |
| 786 | */ |
| 787 | struct ion_flag_data { |
| 788 | struct ion_handle *handle; |
| 789 | unsigned long flags; |
| 790 | }; |
| 791 | |
Rebecca Schultz Zavin | c80005a | 2011-06-29 19:44:29 -0700 | [diff] [blame] | 792 | #define ION_IOC_MAGIC 'I' |
| 793 | |
| 794 | /** |
| 795 | * DOC: ION_IOC_ALLOC - allocate memory |
| 796 | * |
| 797 | * Takes an ion_allocation_data struct and returns it with the handle field |
| 798 | * populated with the opaque handle for the allocation. |
| 799 | */ |
| 800 | #define ION_IOC_ALLOC _IOWR(ION_IOC_MAGIC, 0, \ |
| 801 | struct ion_allocation_data) |
| 802 | |
| 803 | /** |
| 804 | * DOC: ION_IOC_FREE - free memory |
| 805 | * |
| 806 | * Takes an ion_handle_data struct and frees the handle. |
| 807 | */ |
| 808 | #define ION_IOC_FREE _IOWR(ION_IOC_MAGIC, 1, struct ion_handle_data) |
| 809 | |
| 810 | /** |
| 811 | * DOC: ION_IOC_MAP - get a file descriptor to mmap |
| 812 | * |
| 813 | * Takes an ion_fd_data struct with the handle field populated with a valid |
| 814 | * opaque handle. Returns the struct with the fd field set to a file |
| 815 | * descriptor open in the current address space. This file descriptor |
| 816 | * can then be used as an argument to mmap. |
| 817 | */ |
| 818 | #define ION_IOC_MAP _IOWR(ION_IOC_MAGIC, 2, struct ion_fd_data) |
| 819 | |
| 820 | /** |
| 821 | * DOC: ION_IOC_SHARE - creates a file descriptor to use to share an allocation |
| 822 | * |
| 823 | * Takes an ion_fd_data struct with the handle field populated with a valid |
| 824 | * opaque handle. Returns the struct with the fd field set to a file |
| 825 | * descriptor open in the current address space. This file descriptor |
| 826 | * can then be passed to another process. The corresponding opaque handle can |
| 827 | * be retrieved via ION_IOC_IMPORT. |
| 828 | */ |
| 829 | #define ION_IOC_SHARE _IOWR(ION_IOC_MAGIC, 4, struct ion_fd_data) |
| 830 | |
| 831 | /** |
| 832 | * DOC: ION_IOC_IMPORT - imports a shared file descriptor |
| 833 | * |
| 834 | * Takes an ion_fd_data struct with the fd field populated with a valid file |
| 835 | * descriptor obtained from ION_IOC_SHARE and returns the struct with the handle |
| 836 | * filed set to the corresponding opaque handle. |
| 837 | */ |
Ajay Dudani | f572d26 | 2012-08-29 18:02:11 -0700 | [diff] [blame] | 838 | #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] | 839 | |
| 840 | /** |
| 841 | * DOC: ION_IOC_CUSTOM - call architecture specific ion ioctl |
| 842 | * |
| 843 | * Takes the argument of the architecture specific ioctl to call and |
| 844 | * passes appropriate userdata for that ioctl |
| 845 | */ |
| 846 | #define ION_IOC_CUSTOM _IOWR(ION_IOC_MAGIC, 6, struct ion_custom_data) |
| 847 | |
Laura Abbott | abcb6f7 | 2011-10-04 16:26:49 -0700 | [diff] [blame] | 848 | |
| 849 | /** |
| 850 | * DOC: ION_IOC_CLEAN_CACHES - clean the caches |
| 851 | * |
| 852 | * Clean the caches of the handle specified. |
| 853 | */ |
Ajay Dudani | f572d26 | 2012-08-29 18:02:11 -0700 | [diff] [blame] | 854 | #define ION_IOC_CLEAN_CACHES _IOWR(ION_IOC_MAGIC, 20, \ |
Laura Abbott | abcb6f7 | 2011-10-04 16:26:49 -0700 | [diff] [blame] | 855 | struct ion_flush_data) |
| 856 | /** |
| 857 | * DOC: ION_MSM_IOC_INV_CACHES - invalidate the caches |
| 858 | * |
| 859 | * Invalidate the caches of the handle specified. |
| 860 | */ |
Ajay Dudani | f572d26 | 2012-08-29 18:02:11 -0700 | [diff] [blame] | 861 | #define ION_IOC_INV_CACHES _IOWR(ION_IOC_MAGIC, 21, \ |
Laura Abbott | abcb6f7 | 2011-10-04 16:26:49 -0700 | [diff] [blame] | 862 | struct ion_flush_data) |
| 863 | /** |
| 864 | * DOC: ION_MSM_IOC_CLEAN_CACHES - clean and invalidate the caches |
| 865 | * |
| 866 | * Clean and invalidate the caches of the handle specified. |
| 867 | */ |
Ajay Dudani | f572d26 | 2012-08-29 18:02:11 -0700 | [diff] [blame] | 868 | #define ION_IOC_CLEAN_INV_CACHES _IOWR(ION_IOC_MAGIC, 22, \ |
Laura Abbott | abcb6f7 | 2011-10-04 16:26:49 -0700 | [diff] [blame] | 869 | struct ion_flush_data) |
Laura Abbott | 273dd8e | 2011-10-12 14:26:33 -0700 | [diff] [blame] | 870 | |
| 871 | /** |
| 872 | * DOC: ION_IOC_GET_FLAGS - get the flags of the handle |
| 873 | * |
| 874 | * Gets the flags of the current handle which indicate cachability, |
| 875 | * secure state etc. |
| 876 | */ |
Ajay Dudani | f572d26 | 2012-08-29 18:02:11 -0700 | [diff] [blame] | 877 | #define ION_IOC_GET_FLAGS _IOWR(ION_IOC_MAGIC, 23, \ |
Laura Abbott | 273dd8e | 2011-10-12 14:26:33 -0700 | [diff] [blame] | 878 | struct ion_flag_data) |
Rebecca Schultz Zavin | c80005a | 2011-06-29 19:44:29 -0700 | [diff] [blame] | 879 | #endif /* _LINUX_ION_H */ |