Patrick Daly | eeeb940 | 2016-11-01 20:54:41 -0700 | [diff] [blame] | 1 | #ifndef _UAPI_MSM_ION_H |
| 2 | #define _UAPI_MSM_ION_H |
| 3 | |
| 4 | #include "ion.h" |
| 5 | |
Liam Mark | d9a5085 | 2016-09-22 11:30:51 -0700 | [diff] [blame] | 6 | #define ION_BIT(nr) (1UL << (nr)) |
| 7 | |
Patrick Daly | eeeb940 | 2016-11-01 20:54:41 -0700 | [diff] [blame] | 8 | enum msm_ion_heap_types { |
| 9 | ION_HEAP_TYPE_MSM_START = ION_HEAP_TYPE_CUSTOM + 1, |
| 10 | ION_HEAP_TYPE_SECURE_DMA = ION_HEAP_TYPE_MSM_START, |
Patrick Daly | c1005d8 | 2016-09-22 17:43:26 -0700 | [diff] [blame] | 11 | ION_HEAP_TYPE_SYSTEM_SECURE, |
Laura Abbott | 29defcc | 2014-08-01 16:13:40 -0700 | [diff] [blame] | 12 | ION_HEAP_TYPE_HYP_CMA, |
Patrick Daly | eeeb940 | 2016-11-01 20:54:41 -0700 | [diff] [blame] | 13 | /* |
| 14 | * if you add a heap type here you should also add it to |
| 15 | * heap_types_info[] in msm_ion.c |
| 16 | */ |
| 17 | }; |
| 18 | |
| 19 | /** |
| 20 | * These are the only ids that should be used for Ion heap ids. |
| 21 | * The ids listed are the order in which allocation will be attempted |
| 22 | * if specified. Don't swap the order of heap ids unless you know what |
| 23 | * you are doing! |
| 24 | * Id's are spaced by purpose to allow new Id's to be inserted in-between (for |
| 25 | * possible fallbacks) |
| 26 | */ |
| 27 | |
| 28 | enum ion_heap_ids { |
| 29 | INVALID_HEAP_ID = -1, |
| 30 | ION_CP_MM_HEAP_ID = 8, |
Patrick Daly | c1005d8 | 2016-09-22 17:43:26 -0700 | [diff] [blame] | 31 | ION_SECURE_HEAP_ID = 9, |
Laura Abbott | 29defcc | 2014-08-01 16:13:40 -0700 | [diff] [blame] | 32 | ION_SECURE_DISPLAY_HEAP_ID = 10, |
Patrick Daly | eeeb940 | 2016-11-01 20:54:41 -0700 | [diff] [blame] | 33 | ION_CP_MFC_HEAP_ID = 12, |
Laura Abbott | 29defcc | 2014-08-01 16:13:40 -0700 | [diff] [blame] | 34 | ION_SPSS_HEAP_ID = 13, /* Secure Processor ION heap */ |
Patrick Daly | eeeb940 | 2016-11-01 20:54:41 -0700 | [diff] [blame] | 35 | ION_CP_WB_HEAP_ID = 16, /* 8660 only */ |
Patrick Daly | 05be205 | 2017-12-06 17:43:49 -0800 | [diff] [blame] | 36 | ION_QSECOM_TA_HEAP_ID = 19, |
Patrick Daly | eeeb940 | 2016-11-01 20:54:41 -0700 | [diff] [blame] | 37 | ION_CAMERA_HEAP_ID = 20, /* 8660 only */ |
| 38 | ION_SYSTEM_CONTIG_HEAP_ID = 21, |
| 39 | ION_ADSP_HEAP_ID = 22, |
| 40 | ION_PIL1_HEAP_ID = 23, /* Currently used for other PIL images */ |
| 41 | ION_SF_HEAP_ID = 24, |
| 42 | ION_SYSTEM_HEAP_ID = 25, |
| 43 | ION_PIL2_HEAP_ID = 26, /* Currently used for modem firmware images */ |
| 44 | ION_QSECOM_HEAP_ID = 27, |
| 45 | ION_AUDIO_HEAP_ID = 28, |
| 46 | |
| 47 | ION_MM_FIRMWARE_HEAP_ID = 29, |
| 48 | |
| 49 | ION_HEAP_ID_RESERVED = 31 /** Bit reserved for ION_FLAG_SECURE flag */ |
| 50 | }; |
| 51 | |
| 52 | /* |
| 53 | * The IOMMU heap is deprecated! Here are some aliases for backwards |
| 54 | * compatibility: |
| 55 | */ |
| 56 | #define ION_IOMMU_HEAP_ID ION_SYSTEM_HEAP_ID |
| 57 | #define ION_HEAP_TYPE_IOMMU ION_HEAP_TYPE_SYSTEM |
| 58 | |
Laura Abbott | 29defcc | 2014-08-01 16:13:40 -0700 | [diff] [blame] | 59 | #define ION_SPSS_HEAP_ID ION_SPSS_HEAP_ID |
| 60 | |
Patrick Daly | eeeb940 | 2016-11-01 20:54:41 -0700 | [diff] [blame] | 61 | enum ion_fixed_position { |
| 62 | NOT_FIXED, |
| 63 | FIXED_LOW, |
| 64 | FIXED_MIDDLE, |
| 65 | FIXED_HIGH, |
| 66 | }; |
| 67 | |
| 68 | enum cp_mem_usage { |
| 69 | VIDEO_BITSTREAM = 0x1, |
| 70 | VIDEO_PIXEL = 0x2, |
| 71 | VIDEO_NONPIXEL = 0x3, |
| 72 | DISPLAY_SECURE_CP_USAGE = 0x4, |
| 73 | CAMERA_SECURE_CP_USAGE = 0x5, |
| 74 | MAX_USAGE = 0x6, |
| 75 | UNKNOWN = 0x7FFFFFFF, |
| 76 | }; |
| 77 | |
| 78 | /** |
Patrick Daly | c1005d8 | 2016-09-22 17:43:26 -0700 | [diff] [blame] | 79 | * Flags to be used when allocating from the secure heap for |
| 80 | * content protection |
| 81 | */ |
Liam Mark | d9a5085 | 2016-09-22 11:30:51 -0700 | [diff] [blame] | 82 | #define ION_FLAG_CP_TOUCH ION_BIT(17) |
| 83 | #define ION_FLAG_CP_BITSTREAM ION_BIT(18) |
| 84 | #define ION_FLAG_CP_PIXEL ION_BIT(19) |
| 85 | #define ION_FLAG_CP_NON_PIXEL ION_BIT(20) |
| 86 | #define ION_FLAG_CP_CAMERA ION_BIT(21) |
| 87 | #define ION_FLAG_CP_HLOS ION_BIT(22) |
Sudarshan Rajagopalan | c934228 | 2017-05-18 00:11:06 -0700 | [diff] [blame] | 88 | #define ION_FLAG_CP_SPSS_SP ION_BIT(23) |
Sudarshan Rajagopalan | 8e20679 | 2017-06-28 17:45:57 -0700 | [diff] [blame] | 89 | #define ION_FLAG_CP_SPSS_SP_SHARED ION_BIT(24) |
Liam Mark | d9a5085 | 2016-09-22 11:30:51 -0700 | [diff] [blame] | 90 | #define ION_FLAG_CP_SEC_DISPLAY ION_BIT(25) |
| 91 | #define ION_FLAG_CP_APP ION_BIT(26) |
| 92 | #define ION_FLAG_CP_CAMERA_PREVIEW ION_BIT(27) |
Sudarshan Rajagopalan | e08afb6 | 2017-07-13 11:19:46 -0700 | [diff] [blame] | 93 | #define ION_FLAG_CP_SPSS_HLOS_SHARED ION_BIT(30) |
Liam Mark | d9a5085 | 2016-09-22 11:30:51 -0700 | [diff] [blame] | 94 | |
Patrick Daly | c1005d8 | 2016-09-22 17:43:26 -0700 | [diff] [blame] | 95 | |
| 96 | /** |
Patrick Daly | eeeb940 | 2016-11-01 20:54:41 -0700 | [diff] [blame] | 97 | * Flag to use when allocating to indicate that a heap is secure. |
| 98 | * Do NOT use BIT macro since it is defined in #ifdef __KERNEL__ |
| 99 | */ |
Liam Mark | d9a5085 | 2016-09-22 11:30:51 -0700 | [diff] [blame] | 100 | #define ION_FLAG_SECURE ION_BIT(ION_HEAP_ID_RESERVED) |
Patrick Daly | eeeb940 | 2016-11-01 20:54:41 -0700 | [diff] [blame] | 101 | |
Patrick Daly | eeeb940 | 2016-11-01 20:54:41 -0700 | [diff] [blame] | 102 | /* |
| 103 | * Used in conjunction with heap which pool memory to force an allocation |
| 104 | * to come from the page allocator directly instead of from the pool allocation |
| 105 | */ |
Liam Mark | d9a5085 | 2016-09-22 11:30:51 -0700 | [diff] [blame] | 106 | #define ION_FLAG_POOL_FORCE_ALLOC ION_BIT(16) |
Patrick Daly | eeeb940 | 2016-11-01 20:54:41 -0700 | [diff] [blame] | 107 | |
| 108 | /** |
| 109 | * Deprecated! Please use the corresponding ION_FLAG_* |
| 110 | */ |
| 111 | #define ION_SECURE ION_FLAG_SECURE |
Patrick Daly | eeeb940 | 2016-11-01 20:54:41 -0700 | [diff] [blame] | 112 | |
| 113 | /** |
| 114 | * Macro should be used with ion_heap_ids defined above. |
| 115 | */ |
Liam Mark | d9a5085 | 2016-09-22 11:30:51 -0700 | [diff] [blame] | 116 | #define ION_HEAP(bit) ION_BIT(bit) |
Patrick Daly | eeeb940 | 2016-11-01 20:54:41 -0700 | [diff] [blame] | 117 | |
| 118 | #define ION_ADSP_HEAP_NAME "adsp" |
| 119 | #define ION_SYSTEM_HEAP_NAME "system" |
| 120 | #define ION_VMALLOC_HEAP_NAME ION_SYSTEM_HEAP_NAME |
| 121 | #define ION_KMALLOC_HEAP_NAME "kmalloc" |
| 122 | #define ION_AUDIO_HEAP_NAME "audio" |
| 123 | #define ION_SF_HEAP_NAME "sf" |
| 124 | #define ION_MM_HEAP_NAME "mm" |
| 125 | #define ION_CAMERA_HEAP_NAME "camera_preview" |
| 126 | #define ION_IOMMU_HEAP_NAME "iommu" |
| 127 | #define ION_MFC_HEAP_NAME "mfc" |
Laura Abbott | 29defcc | 2014-08-01 16:13:40 -0700 | [diff] [blame] | 128 | #define ION_SPSS_HEAP_NAME "spss" |
Patrick Daly | eeeb940 | 2016-11-01 20:54:41 -0700 | [diff] [blame] | 129 | #define ION_WB_HEAP_NAME "wb" |
| 130 | #define ION_MM_FIRMWARE_HEAP_NAME "mm_fw" |
| 131 | #define ION_PIL1_HEAP_NAME "pil_1" |
| 132 | #define ION_PIL2_HEAP_NAME "pil_2" |
| 133 | #define ION_QSECOM_HEAP_NAME "qsecom" |
Patrick Daly | 05be205 | 2017-12-06 17:43:49 -0800 | [diff] [blame] | 134 | #define ION_QSECOM_TA_HEAP_NAME "qsecom_ta" |
Patrick Daly | c1005d8 | 2016-09-22 17:43:26 -0700 | [diff] [blame] | 135 | #define ION_SECURE_HEAP_NAME "secure_heap" |
Laura Abbott | 29defcc | 2014-08-01 16:13:40 -0700 | [diff] [blame] | 136 | #define ION_SECURE_DISPLAY_HEAP_NAME "secure_display" |
Patrick Daly | eeeb940 | 2016-11-01 20:54:41 -0700 | [diff] [blame] | 137 | |
| 138 | #define ION_SET_CACHED(__cache) ((__cache) | ION_FLAG_CACHED) |
| 139 | #define ION_SET_UNCACHED(__cache) ((__cache) & ~ION_FLAG_CACHED) |
| 140 | |
| 141 | #define ION_IS_CACHED(__flags) ((__flags) & ION_FLAG_CACHED) |
| 142 | |
| 143 | /* struct ion_flush_data - data passed to ion for flushing caches |
| 144 | * |
| 145 | * @handle: handle with data to flush |
| 146 | * @fd: fd to flush |
| 147 | * @vaddr: userspace virtual address mapped with mmap |
| 148 | * @offset: offset into the handle to flush |
| 149 | * @length: length of handle to flush |
| 150 | * |
| 151 | * Performs cache operations on the handle. If p is the start address |
| 152 | * of the handle, p + offset through p + offset + length will have |
| 153 | * the cache operations performed |
| 154 | */ |
| 155 | struct ion_flush_data { |
| 156 | ion_user_handle_t handle; |
| 157 | int fd; |
| 158 | void *vaddr; |
| 159 | unsigned int offset; |
| 160 | unsigned int length; |
| 161 | }; |
| 162 | |
Laura Abbott | 29defcc | 2014-08-01 16:13:40 -0700 | [diff] [blame] | 163 | struct ion_prefetch_regions { |
| 164 | unsigned int vmid; |
| 165 | size_t __user *sizes; |
| 166 | unsigned int nr_sizes; |
| 167 | }; |
| 168 | |
Patrick Daly | eeeb940 | 2016-11-01 20:54:41 -0700 | [diff] [blame] | 169 | struct ion_prefetch_data { |
| 170 | int heap_id; |
| 171 | unsigned long len; |
Laura Abbott | 29defcc | 2014-08-01 16:13:40 -0700 | [diff] [blame] | 172 | struct ion_prefetch_regions __user *regions; |
| 173 | unsigned int nr_regions; |
Patrick Daly | eeeb940 | 2016-11-01 20:54:41 -0700 | [diff] [blame] | 174 | }; |
| 175 | |
| 176 | #define ION_IOC_MSM_MAGIC 'M' |
| 177 | |
| 178 | /** |
| 179 | * DOC: ION_IOC_CLEAN_CACHES - clean the caches |
| 180 | * |
| 181 | * Clean the caches of the handle specified. |
| 182 | */ |
| 183 | #define ION_IOC_CLEAN_CACHES _IOWR(ION_IOC_MSM_MAGIC, 0, \ |
| 184 | struct ion_flush_data) |
| 185 | /** |
| 186 | * DOC: ION_IOC_INV_CACHES - invalidate the caches |
| 187 | * |
| 188 | * Invalidate the caches of the handle specified. |
| 189 | */ |
| 190 | #define ION_IOC_INV_CACHES _IOWR(ION_IOC_MSM_MAGIC, 1, \ |
| 191 | struct ion_flush_data) |
| 192 | /** |
| 193 | * DOC: ION_IOC_CLEAN_INV_CACHES - clean and invalidate the caches |
| 194 | * |
| 195 | * Clean and invalidate the caches of the handle specified. |
| 196 | */ |
| 197 | #define ION_IOC_CLEAN_INV_CACHES _IOWR(ION_IOC_MSM_MAGIC, 2, \ |
| 198 | struct ion_flush_data) |
| 199 | |
| 200 | #define ION_IOC_PREFETCH _IOWR(ION_IOC_MSM_MAGIC, 3, \ |
| 201 | struct ion_prefetch_data) |
| 202 | |
| 203 | #define ION_IOC_DRAIN _IOWR(ION_IOC_MSM_MAGIC, 4, \ |
| 204 | struct ion_prefetch_data) |
| 205 | |
| 206 | #endif |