1 #ifndef _QSEECOM_H_ 2 #define _QSEECOM_H_ 3 4 #include <linux/types.h> 5 #include <linux/ioctl.h> 6 7 #define MAX_ION_FD 4 8 #define MAX_APP_NAME_SIZE 64 9 #define QSEECOM_HASH_SIZE 32 10 11 /* qseecom_ta_heap allocation retry delay (ms) and max attemp count */ 12 #define QSEECOM_TA_ION_ALLOCATE_DELAY 50 13 #define QSEECOM_TA_ION_ALLOCATE_MAX_ATTEMP 20 14 15 #define ICE_KEY_SIZE 32 16 #define ICE_SALT_SIZE 32 17 18 /* 19 * struct qseecom_register_listener_req - 20 * for register listener ioctl request 21 * @listener_id - service id (shared between userspace and QSE) 22 * @ifd_data_fd - ion handle 23 * @virt_sb_base - shared buffer base in user space 24 * @sb_size - shared buffer size 25 */ 26 struct qseecom_register_listener_req { 27 uint32_t listener_id; /* in */ 28 int32_t ifd_data_fd; /* in */ 29 void *virt_sb_base; /* in */ 30 uint32_t sb_size; /* in */ 31 }; 32 33 /* 34 * struct qseecom_send_cmd_req - for send command ioctl request 35 * @cmd_req_len - command buffer length 36 * @cmd_req_buf - command buffer 37 * @resp_len - response buffer length 38 * @resp_buf - response buffer 39 */ 40 struct qseecom_send_cmd_req { 41 void *cmd_req_buf; /* in */ 42 unsigned int cmd_req_len; /* in */ 43 void *resp_buf; /* in/out */ 44 unsigned int resp_len; /* in/out */ 45 }; 46 47 /* 48 * struct qseecom_ion_fd_info - ion fd handle data information 49 * @fd - ion handle to some memory allocated in user space 50 * @cmd_buf_offset - command buffer offset 51 */ 52 struct qseecom_ion_fd_info { 53 int32_t fd; 54 uint32_t cmd_buf_offset; 55 }; 56 /* 57 * struct qseecom_send_modfd_cmd_req - for send command ioctl request 58 * @cmd_req_len - command buffer length 59 * @cmd_req_buf - command buffer 60 * @resp_len - response buffer length 61 * @resp_buf - response buffer 62 * @ifd_data_fd - ion handle to memory allocated in user space 63 * @cmd_buf_offset - command buffer offset 64 */ 65 struct qseecom_send_modfd_cmd_req { 66 void *cmd_req_buf; /* in */ 67 unsigned int cmd_req_len; /* in */ 68 void *resp_buf; /* in/out */ 69 unsigned int resp_len; /* in/out */ 70 struct qseecom_ion_fd_info ifd_data[MAX_ION_FD]; 71 }; 72 73 /* 74 * struct qseecom_listener_send_resp_req - signal to continue the send_cmd req. 75 * Used as a trigger from HLOS service to notify QSEECOM that it's done with its 76 * operation and provide the response for QSEECOM can continue the incomplete 77 * command execution 78 * @resp_len - Length of the response 79 * @resp_buf - Response buffer where the response of the cmd should go. 80 */ 81 struct qseecom_send_resp_req { 82 void *resp_buf; /* in */ 83 unsigned int resp_len; /* in */ 84 }; 85 86 /* 87 * struct qseecom_load_img_data - for sending image length information and 88 * ion file descriptor to the qseecom driver. ion file descriptor is used 89 * for retrieving the ion file handle and in turn the physical address of 90 * the image location. 91 * @mdt_len - Length of the .mdt file in bytes. 92 * @img_len - Length of the .mdt + .b00 +..+.bxx images files in bytes 93 * @ion_fd - Ion file descriptor used when allocating memory. 94 * @img_name - Name of the image. 95 * @app_arch - Architecture of the image, i.e. 32bit or 64bit app 96 */ 97 struct qseecom_load_img_req { 98 uint32_t mdt_len; /* in */ 99 uint32_t img_len; /* in */ 100 int32_t ifd_data_fd; /* in */ 101 char img_name[MAX_APP_NAME_SIZE]; /* in */ 102 uint32_t app_arch; /* in */ 103 uint32_t app_id; /* out*/ 104 }; 105 106 struct qseecom_set_sb_mem_param_req { 107 int32_t ifd_data_fd; /* in */ 108 void *virt_sb_base; /* in */ 109 uint32_t sb_len; /* in */ 110 }; 111 112 /* 113 * struct qseecom_qseos_version_req - get qseos version 114 * @qseos_version - version number 115 */ 116 struct qseecom_qseos_version_req { 117 unsigned int qseos_version; /* in */ 118 }; 119 120 /* 121 * struct qseecom_qseos_app_load_query - verify if app is loaded in qsee 122 * @app_name[MAX_APP_NAME_SIZE]- name of the app. 123 * @app_id - app id. 124 */ 125 struct qseecom_qseos_app_load_query { 126 char app_name[MAX_APP_NAME_SIZE]; /* in */ 127 uint32_t app_id; /* out */ 128 uint32_t app_arch; 129 }; 130 131 struct qseecom_send_svc_cmd_req { 132 uint32_t cmd_id; 133 void *cmd_req_buf; /* in */ 134 unsigned int cmd_req_len; /* in */ 135 void *resp_buf; /* in/out */ 136 unsigned int resp_len; /* in/out */ 137 }; 138 139 enum qseecom_key_management_usage_type { 140 QSEOS_KM_USAGE_DISK_ENCRYPTION = 0x01, 141 QSEOS_KM_USAGE_FILE_ENCRYPTION = 0x02, 142 QSEOS_KM_USAGE_UFS_ICE_DISK_ENCRYPTION = 0x03, 143 QSEOS_KM_USAGE_SDCC_ICE_DISK_ENCRYPTION = 0x04, 144 QSEOS_KM_USAGE_MAX 145 }; 146 147 struct qseecom_create_key_req { 148 unsigned char hash32[QSEECOM_HASH_SIZE]; 149 enum qseecom_key_management_usage_type usage; 150 }; 151 152 struct qseecom_wipe_key_req { 153 enum qseecom_key_management_usage_type usage; 154 int wipe_key_flag;/* 1->remove key from storage(alone with clear key) */ 155 /* 0->do not remove from storage (clear key) */ 156 }; 157 158 struct qseecom_update_key_userinfo_req { 159 unsigned char current_hash32[QSEECOM_HASH_SIZE]; 160 unsigned char new_hash32[QSEECOM_HASH_SIZE]; 161 enum qseecom_key_management_usage_type usage; 162 }; 163 164 #define SHA256_DIGEST_LENGTH (256/8) 165 /* 166 * struct qseecom_save_partition_hash_req 167 * @partition_id - partition id. 168 * @hash[SHA256_DIGEST_LENGTH] - sha256 digest. 169 */ 170 struct qseecom_save_partition_hash_req { 171 int partition_id; /* in */ 172 char digest[SHA256_DIGEST_LENGTH]; /* in */ 173 }; 174 175 /* 176 * struct qseecom_is_es_activated_req 177 * @is_activated - 1=true , 0=false 178 */ 179 struct qseecom_is_es_activated_req { 180 int is_activated; /* out */ 181 }; 182 183 /* 184 * struct qseecom_mdtp_cipher_dip_req 185 * @in_buf - input buffer 186 * @in_buf_size - input buffer size 187 * @out_buf - output buffer 188 * @out_buf_size - output buffer size 189 * @direction - 0=encrypt, 1=decrypt 190 */ 191 struct qseecom_mdtp_cipher_dip_req { 192 uint8_t *in_buf; 193 uint32_t in_buf_size; 194 uint8_t *out_buf; 195 uint32_t out_buf_size; 196 uint32_t direction; 197 }; 198 199 enum qseecom_bandwidth_request_mode { 200 INACTIVE = 0, 201 LOW, 202 MEDIUM, 203 HIGH, 204 }; 205 206 /* 207 * struct qseecom_send_modfd_resp - for send command ioctl request 208 * @req_len - command buffer length 209 * @req_buf - command buffer 210 * @ifd_data_fd - ion handle to memory allocated in user space 211 * @cmd_buf_offset - command buffer offset 212 */ 213 struct qseecom_send_modfd_listener_resp { 214 void *resp_buf_ptr; /* in */ 215 unsigned int resp_len; /* in */ 216 struct qseecom_ion_fd_info ifd_data[MAX_ION_FD]; /* in */ 217 }; 218 219 struct qseecom_qteec_req { 220 void *req_ptr; 221 uint32_t req_len; 222 void *resp_ptr; 223 uint32_t resp_len; 224 }; 225 226 struct qseecom_qteec_modfd_req { 227 void *req_ptr; 228 uint32_t req_len; 229 void *resp_ptr; 230 uint32_t resp_len; 231 struct qseecom_ion_fd_info ifd_data[MAX_ION_FD]; 232 }; 233 234 struct qseecom_sg_entry { 235 uint32_t phys_addr; 236 uint32_t len; 237 }; 238 239 struct qseecom_sg_entry_64bit { 240 uint64_t phys_addr; 241 uint32_t len; 242 } __attribute__ ((packed)); 243 244 /* 245 * sg list buf format version 246 * 1: Legacy format to support only 512 SG list entries 247 * 2: new format to support > 512 entries 248 */ 249 #define QSEECOM_SG_LIST_BUF_FORMAT_VERSION_1 1 250 #define QSEECOM_SG_LIST_BUF_FORMAT_VERSION_2 2 251 252 struct qseecom_sg_list_buf_hdr_64bit { 253 struct qseecom_sg_entry_64bit blank_entry; /* must be all 0 */ 254 uint32_t version; /* sg list buf format version */ 255 uint64_t new_buf_phys_addr; /* PA of new buffer */ 256 uint32_t nents_total; /* Total number of SG entries */ 257 } __attribute__ ((packed)); 258 259 #define QSEECOM_SG_LIST_BUF_HDR_SZ_64BIT \ 260 sizeof(struct qseecom_sg_list_buf_hdr_64bit) 261 262 #define MAX_CE_PIPE_PAIR_PER_UNIT 3 263 #define INVALID_CE_INFO_UNIT_NUM 0xffffffff 264 265 #define CE_PIPE_PAIR_USE_TYPE_FDE 0 266 #define CE_PIPE_PAIR_USE_TYPE_PFE 1 267 268 struct qseecom_ce_pipe_entry { 269 int valid; 270 unsigned int ce_num; 271 unsigned int ce_pipe_pair; 272 }; 273 274 struct qseecom_ice_data_t { 275 int flag; 276 }; 277 278 #define MAX_CE_INFO_HANDLE_SIZE 32 279 struct qseecom_ce_info_req { 280 unsigned char handle[MAX_CE_INFO_HANDLE_SIZE]; 281 unsigned int usage; 282 unsigned int unit_num; 283 unsigned int num_ce_pipe_entries; 284 struct qseecom_ce_pipe_entry ce_pipe_entry[MAX_CE_PIPE_PAIR_PER_UNIT]; 285 }; 286 287 struct qseecom_ice_key_data_t { 288 uint8_t key[ICE_KEY_SIZE]; 289 uint32_t key_len; 290 uint8_t salt[ICE_SALT_SIZE]; 291 uint32_t salt_len; 292 }; 293 294 #define SG_ENTRY_SZ sizeof(struct qseecom_sg_entry) 295 #define SG_ENTRY_SZ_64BIT sizeof(struct qseecom_sg_entry_64bit) 296 297 struct file; 298 299 300 #define QSEECOM_IOC_MAGIC 0x97 301 302 303 #define QSEECOM_IOCTL_REGISTER_LISTENER_REQ \ 304 _IOWR(QSEECOM_IOC_MAGIC, 1, struct qseecom_register_listener_req) 305 306 #define QSEECOM_IOCTL_UNREGISTER_LISTENER_REQ \ 307 _IO(QSEECOM_IOC_MAGIC, 2) 308 309 #define QSEECOM_IOCTL_SEND_CMD_REQ \ 310 _IOWR(QSEECOM_IOC_MAGIC, 3, struct qseecom_send_cmd_req) 311 312 #define QSEECOM_IOCTL_SEND_MODFD_CMD_REQ \ 313 _IOWR(QSEECOM_IOC_MAGIC, 4, struct qseecom_send_modfd_cmd_req) 314 315 #define QSEECOM_IOCTL_RECEIVE_REQ \ 316 _IO(QSEECOM_IOC_MAGIC, 5) 317 318 #define QSEECOM_IOCTL_SEND_RESP_REQ \ 319 _IO(QSEECOM_IOC_MAGIC, 6) 320 321 #define QSEECOM_IOCTL_LOAD_APP_REQ \ 322 _IOWR(QSEECOM_IOC_MAGIC, 7, struct qseecom_load_img_req) 323 324 #define QSEECOM_IOCTL_SET_MEM_PARAM_REQ \ 325 _IOWR(QSEECOM_IOC_MAGIC, 8, struct qseecom_set_sb_mem_param_req) 326 327 #define QSEECOM_IOCTL_UNLOAD_APP_REQ \ 328 _IO(QSEECOM_IOC_MAGIC, 9) 329 330 #define QSEECOM_IOCTL_GET_QSEOS_VERSION_REQ \ 331 _IOWR(QSEECOM_IOC_MAGIC, 10, struct qseecom_qseos_version_req) 332 333 #define QSEECOM_IOCTL_PERF_ENABLE_REQ \ 334 _IO(QSEECOM_IOC_MAGIC, 11) 335 336 #define QSEECOM_IOCTL_PERF_DISABLE_REQ \ 337 _IO(QSEECOM_IOC_MAGIC, 12) 338 339 #define QSEECOM_IOCTL_LOAD_EXTERNAL_ELF_REQ \ 340 _IOWR(QSEECOM_IOC_MAGIC, 13, struct qseecom_load_img_req) 341 342 #define QSEECOM_IOCTL_UNLOAD_EXTERNAL_ELF_REQ \ 343 _IO(QSEECOM_IOC_MAGIC, 14) 344 345 #define QSEECOM_IOCTL_APP_LOADED_QUERY_REQ \ 346 _IOWR(QSEECOM_IOC_MAGIC, 15, struct qseecom_qseos_app_load_query) 347 348 #define QSEECOM_IOCTL_SEND_CMD_SERVICE_REQ \ 349 _IOWR(QSEECOM_IOC_MAGIC, 16, struct qseecom_send_svc_cmd_req) 350 351 #define QSEECOM_IOCTL_CREATE_KEY_REQ \ 352 _IOWR(QSEECOM_IOC_MAGIC, 17, struct qseecom_create_key_req) 353 354 #define QSEECOM_IOCTL_WIPE_KEY_REQ \ 355 _IOWR(QSEECOM_IOC_MAGIC, 18, struct qseecom_wipe_key_req) 356 357 #define QSEECOM_IOCTL_SAVE_PARTITION_HASH_REQ \ 358 _IOWR(QSEECOM_IOC_MAGIC, 19, struct qseecom_save_partition_hash_req) 359 360 #define QSEECOM_IOCTL_IS_ES_ACTIVATED_REQ \ 361 _IOWR(QSEECOM_IOC_MAGIC, 20, struct qseecom_is_es_activated_req) 362 363 #define QSEECOM_IOCTL_SEND_MODFD_RESP \ 364 _IOWR(QSEECOM_IOC_MAGIC, 21, struct qseecom_send_modfd_listener_resp) 365 366 #define QSEECOM_IOCTL_SET_BUS_SCALING_REQ \ 367 _IOWR(QSEECOM_IOC_MAGIC, 23, int) 368 369 #define QSEECOM_IOCTL_UPDATE_KEY_USER_INFO_REQ \ 370 _IOWR(QSEECOM_IOC_MAGIC, 24, struct qseecom_update_key_userinfo_req) 371 372 #define QSEECOM_QTEEC_IOCTL_OPEN_SESSION_REQ \ 373 _IOWR(QSEECOM_IOC_MAGIC, 30, struct qseecom_qteec_modfd_req) 374 375 #define QSEECOM_QTEEC_IOCTL_CLOSE_SESSION_REQ \ 376 _IOWR(QSEECOM_IOC_MAGIC, 31, struct qseecom_qteec_req) 377 378 #define QSEECOM_QTEEC_IOCTL_INVOKE_MODFD_CMD_REQ \ 379 _IOWR(QSEECOM_IOC_MAGIC, 32, struct qseecom_qteec_modfd_req) 380 381 #define QSEECOM_QTEEC_IOCTL_REQUEST_CANCELLATION_REQ \ 382 _IOWR(QSEECOM_IOC_MAGIC, 33, struct qseecom_qteec_modfd_req) 383 384 #define QSEECOM_IOCTL_MDTP_CIPHER_DIP_REQ \ 385 _IOWR(QSEECOM_IOC_MAGIC, 34, struct qseecom_mdtp_cipher_dip_req) 386 387 #define QSEECOM_IOCTL_SEND_MODFD_CMD_64_REQ \ 388 _IOWR(QSEECOM_IOC_MAGIC, 35, struct qseecom_send_modfd_cmd_req) 389 390 #define QSEECOM_IOCTL_SEND_MODFD_RESP_64 \ 391 _IOWR(QSEECOM_IOC_MAGIC, 36, struct qseecom_send_modfd_listener_resp) 392 393 #define QSEECOM_IOCTL_GET_CE_PIPE_INFO \ 394 _IOWR(QSEECOM_IOC_MAGIC, 40, struct qseecom_ce_info_req) 395 396 #define QSEECOM_IOCTL_FREE_CE_PIPE_INFO \ 397 _IOWR(QSEECOM_IOC_MAGIC, 41, struct qseecom_ce_info_req) 398 399 #define QSEECOM_IOCTL_QUERY_CE_PIPE_INFO \ 400 _IOWR(QSEECOM_IOC_MAGIC, 42, struct qseecom_ce_info_req) 401 402 #define QSEECOM_IOCTL_SET_ICE_INFO \ 403 _IOWR(QSEECOM_IOC_MAGIC, 43, struct qseecom_ice_data_t) 404 405 #define QSEECOM_IOCTL_FBE_CLEAR_KEY \ 406 _IOWR(QSEECOM_IOC_MAGIC, 44, struct qseecom_ice_key_data_t) 407 408 #endif /* _QSEECOM_H_ */ 409