| Laura Abbott | 6438e53 | 2012-07-20 10:10:41 -0700 | [diff] [blame] | 1 | /* | 
| Laura Abbott | 6438e53 | 2012-07-20 10:10:41 -0700 | [diff] [blame] | 2 | * | 
| Duy Truong | e833aca | 2013-02-12 13:35:08 -0800 | [diff] [blame] | 3 | * Copyright (c) 2012-2013, The Linux Foundation. All rights reserved. | 
| Laura Abbott | 6438e53 | 2012-07-20 10:10:41 -0700 | [diff] [blame] | 4 | * | 
|  | 5 | * This software is licensed under the terms of the GNU General Public | 
|  | 6 | * License version 2, as published by the Free Software Foundation, and | 
|  | 7 | * may be copied, distributed, and modified under those terms. | 
|  | 8 | * | 
|  | 9 | * This program is distributed in the hope that it will be useful, | 
|  | 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
|  | 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
|  | 12 | * GNU General Public License for more details. | 
|  | 13 | * | 
|  | 14 | */ | 
|  | 15 |  | 
|  | 16 | #ifndef _LINUX_MSM_ION_H | 
|  | 17 | #define _LINUX_MSM_ION_H | 
|  | 18 |  | 
| Ajay Dudani | f572d26 | 2012-08-29 18:02:11 -0700 | [diff] [blame] | 19 | #include <linux/ion.h> | 
| Laura Abbott | 6438e53 | 2012-07-20 10:10:41 -0700 | [diff] [blame] | 20 |  | 
| Mitchel Humpherys | dc4d01d | 2012-09-13 10:53:22 -0700 | [diff] [blame] | 21 | enum msm_ion_heap_types { | 
|  | 22 | ION_HEAP_TYPE_MSM_START = ION_HEAP_TYPE_CUSTOM + 1, | 
|  | 23 | ION_HEAP_TYPE_IOMMU = ION_HEAP_TYPE_MSM_START, | 
|  | 24 | ION_HEAP_TYPE_CP, | 
|  | 25 | }; | 
|  | 26 |  | 
|  | 27 | /** | 
|  | 28 | * These are the only ids that should be used for Ion heap ids. | 
|  | 29 | * The ids listed are the order in which allocation will be attempted | 
|  | 30 | * if specified. Don't swap the order of heap ids unless you know what | 
|  | 31 | * you are doing! | 
|  | 32 | * Id's are spaced by purpose to allow new Id's to be inserted in-between (for | 
|  | 33 | * possible fallbacks) | 
|  | 34 | */ | 
|  | 35 |  | 
|  | 36 | enum ion_heap_ids { | 
|  | 37 | INVALID_HEAP_ID = -1, | 
|  | 38 | ION_CP_MM_HEAP_ID = 8, | 
|  | 39 | ION_CP_MFC_HEAP_ID = 12, | 
|  | 40 | ION_CP_WB_HEAP_ID = 16, /* 8660 only */ | 
|  | 41 | ION_CAMERA_HEAP_ID = 20, /* 8660 only */ | 
| Mitchel Humpherys | 7b93740 | 2013-03-19 17:16:58 -0700 | [diff] [blame] | 42 | ION_SYSTEM_CONTIG_HEAP_ID = 21, | 
| Laura Abbott | 03e3cd7 | 2013-02-09 09:35:30 -0800 | [diff] [blame] | 43 | ION_ADSP_HEAP_ID = 22, | 
| Mitchel Humpherys | dc4d01d | 2012-09-13 10:53:22 -0700 | [diff] [blame] | 44 | ION_SF_HEAP_ID = 24, | 
|  | 45 | ION_IOMMU_HEAP_ID = 25, | 
|  | 46 | ION_QSECOM_HEAP_ID = 27, | 
|  | 47 | ION_AUDIO_HEAP_ID = 28, | 
|  | 48 |  | 
|  | 49 | ION_MM_FIRMWARE_HEAP_ID = 29, | 
|  | 50 | ION_SYSTEM_HEAP_ID = 30, | 
|  | 51 |  | 
|  | 52 | ION_HEAP_ID_RESERVED = 31 /** Bit reserved for ION_SECURE flag */ | 
|  | 53 | }; | 
|  | 54 |  | 
|  | 55 | enum ion_fixed_position { | 
|  | 56 | NOT_FIXED, | 
|  | 57 | FIXED_LOW, | 
|  | 58 | FIXED_MIDDLE, | 
|  | 59 | FIXED_HIGH, | 
|  | 60 | }; | 
|  | 61 |  | 
|  | 62 | enum cp_mem_usage { | 
|  | 63 | VIDEO_BITSTREAM = 0x1, | 
|  | 64 | VIDEO_PIXEL = 0x2, | 
|  | 65 | VIDEO_NONPIXEL = 0x3, | 
|  | 66 | MAX_USAGE = 0x4, | 
|  | 67 | UNKNOWN = 0x7FFFFFFF, | 
|  | 68 | }; | 
|  | 69 |  | 
|  | 70 | #define ION_HEAP_CP_MASK		(1 << ION_HEAP_TYPE_CP) | 
|  | 71 |  | 
|  | 72 | /** | 
|  | 73 | * Flag to use when allocating to indicate that a heap is secure. | 
|  | 74 | */ | 
| Adrian Alexei | 416c251 | 2013-04-04 16:18:51 -0700 | [diff] [blame] | 75 | #define ION_FLAG_SECURE (1 << ION_HEAP_ID_RESERVED) | 
| Mitchel Humpherys | dc4d01d | 2012-09-13 10:53:22 -0700 | [diff] [blame] | 76 |  | 
|  | 77 | /** | 
| Laura Abbott | c7cd2b0 | 2013-01-03 14:20:16 -0800 | [diff] [blame] | 78 | * Flag for clients to force contiguous memort allocation | 
|  | 79 | * | 
|  | 80 | * Use of this flag is carefully monitored! | 
|  | 81 | */ | 
| Adrian Alexei | 416c251 | 2013-04-04 16:18:51 -0700 | [diff] [blame] | 82 | #define ION_FLAG_FORCE_CONTIGUOUS (1 << 30) | 
|  | 83 |  | 
|  | 84 | /** | 
|  | 85 | * Deprecated! Please use the corresponding ION_FLAG_* | 
|  | 86 | */ | 
|  | 87 | #define ION_SECURE ION_FLAG_SECURE | 
|  | 88 | #define ION_FORCE_CONTIGUOUS ION_FLAG_FORCE_CONTIGUOUS | 
| Laura Abbott | c7cd2b0 | 2013-01-03 14:20:16 -0800 | [diff] [blame] | 89 |  | 
|  | 90 | /** | 
| Mitchel Humpherys | dc4d01d | 2012-09-13 10:53:22 -0700 | [diff] [blame] | 91 | * Macro should be used with ion_heap_ids defined above. | 
|  | 92 | */ | 
|  | 93 | #define ION_HEAP(bit) (1 << (bit)) | 
| detule | a392904 | 2013-05-05 13:56:50 +0200 | [diff] [blame] | 94 | #define ion_full_heap_mask (ION_HEAP(ION_CP_MM_HEAP_ID) | \ | 
|  | 95 | ION_HEAP(ION_CP_MFC_HEAP_ID) | \ | 
|  | 96 | ION_HEAP(ION_CP_WB_HEAP_ID) | \ | 
|  | 97 | ION_HEAP(ION_CAMERA_HEAP_ID) | \ | 
|  | 98 | ION_HEAP(ION_SF_HEAP_ID) | \ | 
|  | 99 | ION_HEAP(ION_IOMMU_HEAP_ID) | \ | 
|  | 100 | ION_HEAP(ION_QSECOM_HEAP_ID) | \ | 
|  | 101 | ION_HEAP(ION_AUDIO_HEAP_ID) | \ | 
|  | 102 | ION_HEAP(ION_MM_FIRMWARE_HEAP_ID) | \ | 
|  | 103 | ION_HEAP(ION_SYSTEM_HEAP_ID) ) | 
|  | 104 |  | 
| Mitchel Humpherys | dc4d01d | 2012-09-13 10:53:22 -0700 | [diff] [blame] | 105 |  | 
| Laura Abbott | 03e3cd7 | 2013-02-09 09:35:30 -0800 | [diff] [blame] | 106 | #define ION_ADSP_HEAP_NAME	"adsp" | 
| Mitchel Humpherys | dc4d01d | 2012-09-13 10:53:22 -0700 | [diff] [blame] | 107 | #define ION_VMALLOC_HEAP_NAME	"vmalloc" | 
| Mitchel Humpherys | 7b93740 | 2013-03-19 17:16:58 -0700 | [diff] [blame] | 108 | #define ION_KMALLOC_HEAP_NAME	"kmalloc" | 
| Mitchel Humpherys | dc4d01d | 2012-09-13 10:53:22 -0700 | [diff] [blame] | 109 | #define ION_AUDIO_HEAP_NAME	"audio" | 
|  | 110 | #define ION_SF_HEAP_NAME	"sf" | 
|  | 111 | #define ION_MM_HEAP_NAME	"mm" | 
|  | 112 | #define ION_CAMERA_HEAP_NAME	"camera_preview" | 
|  | 113 | #define ION_IOMMU_HEAP_NAME	"iommu" | 
|  | 114 | #define ION_MFC_HEAP_NAME	"mfc" | 
|  | 115 | #define ION_WB_HEAP_NAME	"wb" | 
|  | 116 | #define ION_MM_FIRMWARE_HEAP_NAME	"mm_fw" | 
|  | 117 | #define ION_QSECOM_HEAP_NAME	"qsecom" | 
|  | 118 | #define ION_FMEM_HEAP_NAME	"fmem" | 
|  | 119 |  | 
|  | 120 | #define ION_SET_CACHED(__cache)		(__cache | ION_FLAG_CACHED) | 
|  | 121 | #define ION_SET_UNCACHED(__cache)	(__cache & ~ION_FLAG_CACHED) | 
|  | 122 |  | 
|  | 123 | #define ION_IS_CACHED(__flags)	((__flags) & ION_FLAG_CACHED) | 
|  | 124 |  | 
|  | 125 | #ifdef __KERNEL__ | 
|  | 126 |  | 
|  | 127 | /* | 
|  | 128 | * This flag allows clients when mapping into the IOMMU to specify to | 
|  | 129 | * defer un-mapping from the IOMMU until the buffer memory is freed. | 
|  | 130 | */ | 
|  | 131 | #define ION_IOMMU_UNMAP_DELAYED 1 | 
|  | 132 |  | 
|  | 133 | /** | 
|  | 134 | * struct ion_cp_heap_pdata - defines a content protection heap in the given | 
|  | 135 | * platform | 
|  | 136 | * @permission_type:	Memory ID used to identify the memory to TZ | 
|  | 137 | * @align:		Alignment requirement for the memory | 
|  | 138 | * @secure_base:	Base address for securing the heap. | 
|  | 139 | *			Note: This might be different from actual base address | 
|  | 140 | *			of this heap in the case of a shared heap. | 
|  | 141 | * @secure_size:	Memory size for securing the heap. | 
|  | 142 | *			Note: This might be different from actual size | 
|  | 143 | *			of this heap in the case of a shared heap. | 
|  | 144 | * @reusable		Flag indicating whether this heap is reusable of not. | 
|  | 145 | *			(see FMEM) | 
|  | 146 | * @mem_is_fmem		Flag indicating whether this memory is coming from fmem | 
|  | 147 | *			or not. | 
|  | 148 | * @fixed_position	If nonzero, position in the fixed area. | 
|  | 149 | * @virt_addr:		Virtual address used when using fmem. | 
|  | 150 | * @iommu_map_all:	Indicates whether we should map whole heap into IOMMU. | 
|  | 151 | * @iommu_2x_map_domain: Indicates the domain to use for overmapping. | 
|  | 152 | * @request_region:	function to be called when the number of allocations | 
|  | 153 | *			goes from 0 -> 1 | 
|  | 154 | * @release_region:	function to be called when the number of allocations | 
|  | 155 | *			goes from 1 -> 0 | 
|  | 156 | * @setup_region:	function to be called upon ion registration | 
|  | 157 | * @memory_type:Memory type used for the heap | 
| Laura Abbott | 5249a05 | 2012-12-11 15:09:03 -0800 | [diff] [blame] | 158 | * @no_nonsecure_alloc: don't allow non-secure allocations from this heap | 
| Mitchel Humpherys | dc4d01d | 2012-09-13 10:53:22 -0700 | [diff] [blame] | 159 | * | 
|  | 160 | */ | 
|  | 161 | struct ion_cp_heap_pdata { | 
|  | 162 | enum ion_permission_type permission_type; | 
|  | 163 | unsigned int align; | 
|  | 164 | ion_phys_addr_t secure_base; /* Base addr used when heap is shared */ | 
|  | 165 | size_t secure_size; /* Size used for securing heap when heap is shared*/ | 
|  | 166 | int reusable; | 
|  | 167 | int mem_is_fmem; | 
| Laura Abbott | d314222 | 2012-08-03 17:31:03 -0700 | [diff] [blame] | 168 | int is_cma; | 
| Mitchel Humpherys | dc4d01d | 2012-09-13 10:53:22 -0700 | [diff] [blame] | 169 | enum ion_fixed_position fixed_position; | 
|  | 170 | int iommu_map_all; | 
|  | 171 | int iommu_2x_map_domain; | 
|  | 172 | ion_virt_addr_t *virt_addr; | 
|  | 173 | int (*request_region)(void *); | 
|  | 174 | int (*release_region)(void *); | 
|  | 175 | void *(*setup_region)(void); | 
|  | 176 | enum ion_memory_types memory_type; | 
| Laura Abbott | 5249a05 | 2012-12-11 15:09:03 -0800 | [diff] [blame] | 177 | int no_nonsecure_alloc; | 
| Mitchel Humpherys | dc4d01d | 2012-09-13 10:53:22 -0700 | [diff] [blame] | 178 | }; | 
|  | 179 |  | 
|  | 180 | /** | 
|  | 181 | * struct ion_co_heap_pdata - defines a carveout heap in the given platform | 
|  | 182 | * @adjacent_mem_id:	Id of heap that this heap must be adjacent to. | 
|  | 183 | * @align:		Alignment requirement for the memory | 
|  | 184 | * @mem_is_fmem		Flag indicating whether this memory is coming from fmem | 
|  | 185 | *			or not. | 
|  | 186 | * @fixed_position	If nonzero, position in the fixed area. | 
|  | 187 | * @request_region:	function to be called when the number of allocations | 
|  | 188 | *			goes from 0 -> 1 | 
|  | 189 | * @release_region:	function to be called when the number of allocations | 
|  | 190 | *			goes from 1 -> 0 | 
|  | 191 | * @setup_region:	function to be called upon ion registration | 
|  | 192 | * @memory_type:Memory type used for the heap | 
|  | 193 | * | 
|  | 194 | */ | 
|  | 195 | struct ion_co_heap_pdata { | 
|  | 196 | int adjacent_mem_id; | 
|  | 197 | unsigned int align; | 
|  | 198 | int mem_is_fmem; | 
|  | 199 | enum ion_fixed_position fixed_position; | 
|  | 200 | int (*request_region)(void *); | 
|  | 201 | int (*release_region)(void *); | 
|  | 202 | void *(*setup_region)(void); | 
|  | 203 | enum ion_memory_types memory_type; | 
|  | 204 | }; | 
|  | 205 |  | 
|  | 206 | #ifdef CONFIG_ION | 
|  | 207 | /** | 
|  | 208 | * msm_ion_secure_heap - secure a heap. Wrapper around ion_secure_heap. | 
|  | 209 | * | 
|  | 210 | * @heap_id - heap id to secure. | 
|  | 211 | * | 
|  | 212 | * Secure a heap | 
|  | 213 | * Returns 0 on success | 
|  | 214 | */ | 
|  | 215 | int msm_ion_secure_heap(int heap_id); | 
|  | 216 |  | 
|  | 217 | /** | 
|  | 218 | * msm_ion_unsecure_heap - unsecure a heap. Wrapper around ion_unsecure_heap. | 
|  | 219 | * | 
|  | 220 | * @heap_id - heap id to secure. | 
|  | 221 | * | 
|  | 222 | * Un-secure a heap | 
|  | 223 | * Returns 0 on success | 
|  | 224 | */ | 
|  | 225 | int msm_ion_unsecure_heap(int heap_id); | 
|  | 226 |  | 
|  | 227 | /** | 
|  | 228 | * msm_ion_secure_heap_2_0 - secure a heap using 2.0 APIs | 
|  | 229 | *  Wrapper around ion_secure_heap. | 
|  | 230 | * | 
|  | 231 | * @heap_id - heap id to secure. | 
|  | 232 | * @usage - usage hint to TZ | 
|  | 233 | * | 
|  | 234 | * Secure a heap | 
|  | 235 | * Returns 0 on success | 
|  | 236 | */ | 
|  | 237 | int msm_ion_secure_heap_2_0(int heap_id, enum cp_mem_usage usage); | 
|  | 238 |  | 
|  | 239 | /** | 
|  | 240 | * msm_ion_unsecure_heap - unsecure a heap secured with 3.0 APIs. | 
|  | 241 | * Wrapper around ion_unsecure_heap. | 
|  | 242 | * | 
|  | 243 | * @heap_id - heap id to secure. | 
|  | 244 | * @usage - usage hint to TZ | 
|  | 245 | * | 
|  | 246 | * Un-secure a heap | 
|  | 247 | * Returns 0 on success | 
|  | 248 | */ | 
|  | 249 | int msm_ion_unsecure_heap_2_0(int heap_id, enum cp_mem_usage usage); | 
|  | 250 | #else | 
|  | 251 | static inline int msm_ion_secure_heap(int heap_id) | 
|  | 252 | { | 
|  | 253 | return -ENODEV; | 
|  | 254 |  | 
|  | 255 | } | 
|  | 256 |  | 
|  | 257 | static inline int msm_ion_unsecure_heap(int heap_id) | 
|  | 258 | { | 
|  | 259 | return -ENODEV; | 
|  | 260 | } | 
|  | 261 |  | 
|  | 262 | static inline int msm_ion_secure_heap_2_0(int heap_id, enum cp_mem_usage usage) | 
|  | 263 | { | 
|  | 264 | return -ENODEV; | 
|  | 265 | } | 
|  | 266 |  | 
|  | 267 | static inline int msm_ion_unsecure_heap_2_0(int heap_id, | 
|  | 268 | enum cp_mem_usage usage) | 
|  | 269 | { | 
|  | 270 | return -ENODEV; | 
|  | 271 | } | 
|  | 272 | #endif /* CONFIG_ION */ | 
|  | 273 |  | 
|  | 274 | #endif /* __KERNEL */ | 
|  | 275 |  | 
|  | 276 | /* struct ion_flush_data - data passed to ion for flushing caches | 
|  | 277 | * | 
|  | 278 | * @handle:	handle with data to flush | 
|  | 279 | * @fd:		fd to flush | 
|  | 280 | * @vaddr:	userspace virtual address mapped with mmap | 
|  | 281 | * @offset:	offset into the handle to flush | 
|  | 282 | * @length:	length of handle to flush | 
|  | 283 | * | 
|  | 284 | * Performs cache operations on the handle. If p is the start address | 
|  | 285 | * of the handle, p + offset through p + offset + length will have | 
|  | 286 | * the cache operations performed | 
|  | 287 | */ | 
| detule | a392904 | 2013-05-05 13:56:50 +0200 | [diff] [blame] | 288 | /* | 
| Mitchel Humpherys | dc4d01d | 2012-09-13 10:53:22 -0700 | [diff] [blame] | 289 | struct ion_flush_data { | 
|  | 290 | struct ion_handle *handle; | 
|  | 291 | int fd; | 
|  | 292 | void *vaddr; | 
|  | 293 | unsigned int offset; | 
|  | 294 | unsigned int length; | 
|  | 295 | }; | 
| detule | a392904 | 2013-05-05 13:56:50 +0200 | [diff] [blame] | 296 | */ | 
| Mitchel Humpherys | dc4d01d | 2012-09-13 10:53:22 -0700 | [diff] [blame] | 297 | /* struct ion_flag_data - information about flags for this buffer | 
|  | 298 | * | 
|  | 299 | * @handle:	handle to get flags from | 
|  | 300 | * @flags:	flags of this handle | 
|  | 301 | * | 
|  | 302 | * Takes handle as an input and outputs the flags from the handle | 
|  | 303 | * in the flag field. | 
|  | 304 | */ | 
| detule | a392904 | 2013-05-05 13:56:50 +0200 | [diff] [blame] | 305 | /* | 
| Mitchel Humpherys | dc4d01d | 2012-09-13 10:53:22 -0700 | [diff] [blame] | 306 | struct ion_flag_data { | 
|  | 307 | struct ion_handle *handle; | 
|  | 308 | unsigned long flags; | 
|  | 309 | }; | 
| detule | a392904 | 2013-05-05 13:56:50 +0200 | [diff] [blame] | 310 | */ | 
| Mitchel Humpherys | dc4d01d | 2012-09-13 10:53:22 -0700 | [diff] [blame] | 311 | #define ION_IOC_MSM_MAGIC 'M' | 
|  | 312 |  | 
|  | 313 | /** | 
|  | 314 | * DOC: ION_IOC_CLEAN_CACHES - clean the caches | 
|  | 315 | * | 
|  | 316 | * Clean the caches of the handle specified. | 
|  | 317 | */ | 
|  | 318 | #define ION_IOC_CLEAN_CACHES	_IOWR(ION_IOC_MSM_MAGIC, 0, \ | 
|  | 319 | struct ion_flush_data) | 
| detule | a392904 | 2013-05-05 13:56:50 +0200 | [diff] [blame] | 320 |  | 
| Mitchel Humpherys | dc4d01d | 2012-09-13 10:53:22 -0700 | [diff] [blame] | 321 | /** | 
|  | 322 | * DOC: ION_IOC_INV_CACHES - invalidate the caches | 
|  | 323 | * | 
|  | 324 | * Invalidate the caches of the handle specified. | 
|  | 325 | */ | 
|  | 326 | #define ION_IOC_INV_CACHES	_IOWR(ION_IOC_MSM_MAGIC, 1, \ | 
|  | 327 | struct ion_flush_data) | 
|  | 328 | /** | 
|  | 329 | * DOC: ION_IOC_CLEAN_INV_CACHES - clean and invalidate the caches | 
|  | 330 | * | 
|  | 331 | * Clean and invalidate the caches of the handle specified. | 
|  | 332 | */ | 
|  | 333 | #define ION_IOC_CLEAN_INV_CACHES	_IOWR(ION_IOC_MSM_MAGIC, 2, \ | 
|  | 334 | struct ion_flush_data) | 
|  | 335 |  | 
|  | 336 | /** | 
|  | 337 | * DOC: ION_IOC_GET_FLAGS - get the flags of the handle | 
|  | 338 | * | 
|  | 339 | * Gets the flags of the current handle which indicate cachability, | 
|  | 340 | * secure state etc. | 
|  | 341 | */ | 
|  | 342 | #define ION_IOC_GET_FLAGS		_IOWR(ION_IOC_MSM_MAGIC, 3, \ | 
|  | 343 | struct ion_flag_data) | 
| Laura Abbott | 6438e53 | 2012-07-20 10:10:41 -0700 | [diff] [blame] | 344 | #endif |