1 /* 2 * (C) Copyright 2017 Rockchip Electronics Co., Ltd 3 * 4 * SPDX-License-Identifier: GPL-2.0+ 5 */ 6 7 #ifndef TEESMC_H 8 #define TEESMC_H 9 10 #include <optee_include/tee_base_types.h> 11 12 #ifndef ASM 13 /* 14 * This section depends on uint64_t, uint32_t uint8_t already being 15 * defined. Since this file is used in several different environments 16 * (secure world OS and normal world Linux kernel to start with) where 17 * stdint.h may not be available it's the responsibility of the one 18 * including this file to provide those types. 19 */ 20 21 /* 22 * Trusted OS SMC interface. 23 * 24 * The SMC interface follows SMC Calling Convention 25 * (ARM_DEN0028A_SMC_Calling_Convention). 26 * 27 * The primary objective of this API is to provide a transport layer on 28 * which a Global Platform compliant TEE interfaces can be deployed. But the 29 * interface can also be used for other implementations. 30 * 31 * This file is divided in two parts. 32 * Part 1 deals with passing parameters to Trusted Applications running in 33 * a trusted OS in secure world. 34 * Part 2 deals with the lower level handling of the SMC. 35 */ 36 37 /* 38 ******************************************************************************* 39 * Part 1 - passing parameters to Trusted Applications 40 ******************************************************************************* 41 */ 42 43 /* 44 * Same values as TEE_PARAM_* from TEE Internal API 45 */ 46 #define TEESMC_ATTR_TYPE_NONE 0 47 #define TEESMC_ATTR_TYPE_VALUE_INPUT 1 48 #define TEESMC_ATTR_TYPE_VALUE_OUTPUT 2 49 #define TEESMC_ATTR_TYPE_VALUE_INOUT 3 50 #define TEESMC_ATTR_TYPE_MEMREF_INPUT 5 51 #define TEESMC_ATTR_TYPE_MEMREF_OUTPUT 6 52 #define TEESMC_ATTR_TYPE_MEMREF_INOUT 7 53 54 #define TEESMC_ATTR_TYPE_MASK 0x7 55 56 /* 57 * Meta parameter to be absorbed by the Secure OS and not passed 58 * to the Trusted Application. 59 * 60 * One example of this is a struct teesmc_meta_open_session which 61 * is added to TEESMC{32,64}_CMD_OPEN_SESSION. 62 */ 63 #define TEESMC_ATTR_META 0x8 64 65 /* 66 * Used as an indication from normal world of compatible cache usage. 67 * 'I' stands for inner cache and 'O' for outer cache. 68 */ 69 #define TEESMC_ATTR_CACHE_I_NONCACHE 0x0 70 #define TEESMC_ATTR_CACHE_I_WRITE_THR 0x1 71 #define TEESMC_ATTR_CACHE_I_WRITE_BACK 0x2 72 #define TEESMC_ATTR_CACHE_O_NONCACHE 0x0 73 #define TEESMC_ATTR_CACHE_O_WRITE_THR 0x4 74 #define TEESMC_ATTR_CACHE_O_WRITE_BACK 0x8 75 76 #define TEESMC_ATTR_CACHE_NONCACHE 0x0 77 #define TEESMC_ATTR_CACHE_DEFAULT (TEESMC_ATTR_CACHE_I_WRITE_BACK | \ 78 TEESMC_ATTR_CACHE_O_WRITE_BACK) 79 80 #define TEESMC_ATTR_CACHE_SHIFT 4 81 #define TEESMC_ATTR_CACHE_MASK 0xf 82 83 #define TEESMC_CMD_OPEN_SESSION 0 84 #define TEESMC_CMD_INVOKE_COMMAND 1 85 #define TEESMC_CMD_CLOSE_SESSION 2 86 #define TEESMC_CMD_CANCEL 3 87 88 /** 89 * struct teesmc32_param_memref - memory reference 90 * @buf_ptr: Address of the buffer 91 * @size: Size of the buffer 92 * 93 * Secure and normal world communicates pointer via physical address instead of 94 * the virtual address with is usually used for pointers. This is because 95 * Secure and normal world has completely independant memory mapping. Normal 96 * world can even have a hypervisor which need to translate the guest 97 * physical address (AKA IPA in ARM lingo) to a real physical address 98 * before passing the structure to secure world. 99 */ 100 struct teesmc32_param_memref { 101 uint32_t buf_ptr; 102 uint32_t size; 103 }; 104 105 /** 106 * struct teesmc32_param_memref - memory reference 107 * @buf_ptr: Address of the buffer 108 * @size: Size of the buffer 109 * 110 * See description of struct teesmc32_param_memref. 111 */ 112 struct teesmc64_param_memref { 113 uint64_t buf_ptr; 114 uint64_t size; 115 }; 116 117 /** 118 * struct teesmc32_param_value - values 119 * @a: first value 120 * @b: second value 121 */ 122 struct teesmc32_param_value { 123 uint32_t a; 124 uint32_t b; 125 }; 126 127 /** 128 * struct teesmc64_param_value - values 129 * @a: first value 130 * @b: second value 131 */ 132 struct teesmc64_param_value { 133 uint64_t a; 134 uint64_t b; 135 }; 136 137 /** 138 * struct teesmc32_param - parameter 139 * @attr: attributes 140 * @memref: a memory reference 141 * @value: a value 142 * 143 * attr & TEESMC_ATTR_TYPE_MASK indicates if memref or value is used in the 144 * union. TEESMC_ATTR_TYPE_VALUE_* indicates value and 145 * TEESMC_ATTR_TYPE_MEMREF_* indicates memref. TEESMC_ATTR_TYPE_NONE 146 * indicates that none of the members are used. 147 */ 148 struct teesmc32_param { 149 uint32_t attr; 150 union { 151 struct teesmc32_param_memref memref; 152 struct teesmc32_param_value value; 153 } u; 154 }; 155 156 /** 157 * struct teesmc64_param - parameter 158 * @attr: attributes 159 * @memref: a memory reference 160 * @value: a value 161 * 162 * See description of union teesmc32_param. 163 */ 164 struct teesmc64_param { 165 uint64_t attr; 166 union { 167 struct teesmc64_param_memref memref; 168 struct teesmc64_param_value value; 169 } u; 170 }; 171 172 /** 173 * struct teesmc32_arg - SMC argument for Trusted OS 174 * @cmd: Command, one of TEESMC_CMD_* 175 * @ta_func: Trusted Application function, specific to the Trusted Application, 176 * used if cmd == TEESMC_CMD_INVOKE_COMMAND 177 * @session: In parameter for all TEESMC_CMD_* except 178 * TEESMC_CMD_OPEN_SESSION where it's an output paramter instead 179 * @ret: return value 180 * @ret_origin: origin of the return value 181 * @num_params: number of parameters supplied to the OS Command 182 * @params: the parameters supplied to the OS Command 183 * 184 * All normal SMC calls to Trusted OS uses this struct. If cmd requires 185 * further information than what these field holds it can be passed as a 186 * parameter tagged as meta (setting the TEESMC_ATTR_META bit in 187 * corresponding param_attrs). This is used for TEESMC_CMD_OPEN_SESSION 188 * to pass a struct teesmc32_meta_open_session which is needed find the 189 * Trusted Application and to indicate the credentials of the client. 190 */ 191 struct teesmc32_arg { 192 uint32_t cmd; 193 uint32_t ta_func; 194 uint32_t session; 195 uint32_t ret; 196 uint32_t ret_origin; 197 uint32_t num_params; 198 /* 199 * Commented out element used to visualize the layout dynamic part 200 * of the struct. Note that this field is not available at all 201 * if num_params == 0. 202 * 203 * params is accessed through the macro TEESMC32_GET_PARAMS 204 * 205 * struct teesmc32_param params[num_params]; 206 */ 207 }; 208 209 /** 210 * TEESMC32_GET_PARAMS - return pointer to union teesmc32_param * 211 * 212 * @x: Pointer to a struct teesmc32_arg 213 * 214 * Returns a pointer to the params[] inside a struct teesmc32_arg. 215 */ 216 #define TEESMC32_GET_PARAMS(x) \ 217 (struct teesmc32_param *)(((struct teesmc32_arg *)(x)) + 1) 218 219 /** 220 * TEESMC32_GET_ARG_SIZE - return size of struct teesmc32_arg 221 * 222 * @num_params: Number of parameters embedded in the struct teesmc32_arg 223 * 224 * Returns the size of the struct teesmc32_arg together with the number 225 * of embedded paramters. 226 */ 227 #define TEESMC32_GET_ARG_SIZE(num_params) \ 228 (sizeof(struct teesmc32_arg) + \ 229 sizeof(struct teesmc32_param) * (num_params)) 230 231 /** 232 * struct teesmc64_arg - SMC argument for Trusted OS 233 * @cmd: OS Command, one of TEESMC_CMD_* 234 * @ta_func: Trusted Application function, specific to the Trusted Application 235 * @session: In parameter for all TEESMC_CMD_* but 236 * TEESMC_CMD_OPEN_SESSION 237 * @ret: return value 238 * @ret_origin: origin of the return value 239 * @num_params: number of parameters supplied to the OS Command 240 * @params: the parameters supplied to the OS Command 241 * 242 * See description of struct teesmc32_arg. 243 */ 244 struct teesmc64_arg { 245 uint64_t cmd; 246 uint64_t ta_func; 247 uint64_t session; 248 uint64_t ret; 249 uint64_t ret_origin; 250 uint64_t num_params; 251 /* 252 * Commented out element used to visualize the layout dynamic part 253 * of the struct. Note that this field is not available at all 254 * if num_params == 0. 255 * 256 * params is accessed through the macro TEESMC64_GET_PARAMS 257 * 258 * struct teesmc64_param params[num_params]; 259 */ 260 }; 261 262 /** 263 * TEESMC64_GET_PARAMS - return pointer to union teesmc64_param * 264 * 265 * @x: Pointer to a struct teesmc64_arg 266 * 267 * Returns a pointer to the params[] inside a struct teesmc64_arg. 268 */ 269 #define TEESMC64_GET_PARAMS(x) \ 270 (struct teesmc64_param *)(((struct teesmc64_arg *)(x)) + 1) 271 272 /** 273 * TEESMC64_GET_ARG_SIZE - return size of struct teesmc64_arg 274 * 275 * @num_params: Number of parameters embedded in the struct teesmc64_arg 276 * 277 * Returns the size of the struct teesmc64_arg together with the number 278 * of embedded paramters. 279 */ 280 #define TEESMC64_GET_ARG_SIZE(num_params) \ 281 (sizeof(struct teesmc64_arg) + \ 282 sizeof(struct teesmc64_param) * (num_params)) 283 284 #define TEESMC_UUID_LEN 16 285 286 /** 287 * struct teesmc_meta_open_session - additional parameters for 288 * TEESMC32_CMD_OPEN_SESSION and 289 * TEESMC64_CMD_OPEN_SESSION 290 * @uuid: UUID of the Trusted Application 291 * @clnt_uuid: UUID of client 292 * @clnt_login: Login class of client, TEE_LOGIN_* if being Global Platform 293 * compliant 294 * 295 * This struct is passed in the first parameter as an input memref tagged 296 * as meta on an TEESMC{32,64}_CMD_OPEN_SESSION cmd. It's important 297 * that it really is the first parameter to make it easy for an eventual 298 * hypervisor to inspect and possibly update clnt_* values. 299 */ 300 struct teesmc_meta_open_session { 301 uint8_t uuid[TEESMC_UUID_LEN]; 302 uint8_t clnt_uuid[TEESMC_UUID_LEN]; 303 uint32_t clnt_login; 304 }; 305 306 307 #endif /*!ASM*/ 308 309 /* 310 ******************************************************************************* 311 * Part 2 - low level SMC interaction 312 ******************************************************************************* 313 */ 314 315 #define TEESMC_32 0 316 #define TEESMC_64 0x40000000 317 #define TEESMC_FAST_CALL 0x80000000 318 #define TEESMC_STD_CALL 0 319 320 #define TEESMC_OWNER_MASK 0x3F 321 #define TEESMC_OWNER_SHIFT 24 322 323 #define TEESMC_FUNC_MASK 0xFFFF 324 325 #define TEESMC_IS_FAST_CALL(smc_val) ((smc_val) & TEESMC_FAST_CALL) 326 #define TEESMC_IS_64(smc_val) ((smc_val) & TEESMC_64) 327 #define TEESMC_FUNC_NUM(smc_val) ((smc_val) & TEESMC_FUNC_MASK) 328 #define TEESMC_OWNER_NUM(smc_val) (((smc_val) >> TEESMC_OWNER_SHIFT) & \ 329 TEESMC_OWNER_MASK) 330 331 #define TEESMC_CALL_VAL(type, calling_convention, owner, func_num) \ 332 ((type) | (calling_convention) | \ 333 (((owner) & TEESMC_OWNER_MASK) << TEESMC_OWNER_SHIFT) |\ 334 ((func_num) & TEESMC_FUNC_MASK)) 335 336 #define TEESMC_OWNER_ARCH 0 337 #define TEESMC_OWNER_CPU 1 338 #define TEESMC_OWNER_SIP 2 339 #define TEESMC_OWNER_OEM 3 340 #define TEESMC_OWNER_STANDARD 4 341 #define TEESMC_OWNER_TRUSTED_APP 48 342 #define TEESMC_OWNER_TRUSTED_OS 50 343 344 #define TEESMC_OWNER_TRUSTED_OS_OPTEED 62 345 #define TEESMC_OWNER_TRUSTED_OS_API 63 346 347 /* 348 * Function specified by SMC Calling convention. 349 */ 350 #define TEESMC32_FUNCID_CALLS_COUNT 0xFF00 351 #define TEESMC32_CALLS_COUNT \ 352 TEESMC_CALL_VAL(TEESMC_32, TEESMC_FAST_CALL, \ 353 TEESMC_OWNER_TRUSTED_OS_API, \ 354 TEESMC32_FUNCID_CALLS_COUNT) 355 356 /* 357 * Function specified by SMC Calling convention 358 * 359 * Return one of the following UIDs if using API specified in this file 360 * without further extentions: 361 * 65cb6b93-af0c-4617-8ed6-644a8d1140f8 : Only 32 bit calls are supported 362 * 65cb6b93-af0c-4617-8ed6-644a8d1140f9 : Both 32 and 64 bit calls are supported 363 */ 364 #define TEESMC_UID_R0 0x65cb6b93 365 #define TEESMC_UID_R1 0xaf0c4617 366 #define TEESMC_UID_R2 0x8ed6644a 367 #define TEESMC_UID32_R3 0x8d1140f8 368 #define TEESMC_UID64_R3 0x8d1140f9 369 #define TEESMC32_FUNCID_CALLS_UID 0xFF01 370 #define TEESMC32_CALLS_UID \ 371 TEESMC_CALL_VAL(TEESMC_32, TEESMC_FAST_CALL, \ 372 TEESMC_OWNER_TRUSTED_OS_API, \ 373 TEESMC32_FUNCID_CALLS_UID) 374 375 /* 376 * Function specified by SMC Calling convention 377 * 378 * Returns 1.0 if using API specified in this file without further extentions. 379 */ 380 #define TEESMC_REVISION_MAJOR 1 381 #define TEESMC_REVISION_MINOR 0 382 #define TEESMC32_FUNCID_CALLS_REVISION 0xFF03 383 #define TEESMC32_CALLS_REVISION \ 384 TEESMC_CALL_VAL(TEESMC_32, TEESMC_FAST_CALL, \ 385 TEESMC_OWNER_TRUSTED_OS_API, \ 386 TEESMC32_FUNCID_CALLS_REVISION) 387 388 /* 389 * Get UUID of Trusted OS. 390 * 391 * Used by non-secure world to figure out which Trusted OS is installed. 392 * Note that returned UUID is the UUID of the Trusted OS, not of the API. 393 * 394 * Returns UUID in r0-4/w0-4 in the same way as TEESMC32_CALLS_UID 395 * described above. 396 */ 397 #define TEESMC_FUNCID_GET_OS_UUID 0 398 #define TEESMC32_CALL_GET_OS_UUID \ 399 TEESMC_CALL_VAL(TEESMC_32, TEESMC_FAST_CALL, TEESMC_OWNER_TRUSTED_OS, \ 400 TEESMC_FUNCID_GET_OS_UUID) 401 402 /* 403 * Get revision of Trusted OS. 404 * 405 * Used by non-secure world to figure out which version of the Trusted OS 406 * is installed. Note that the returned revision is the revision of the 407 * Trusted OS, not of the API. 408 * 409 * Returns revision in r0-1/w0-1 in the same way as TEESMC32_CALLS_REVISION 410 * described above. 411 */ 412 #define TEESMC_FUNCID_GET_OS_REVISION 1 413 #define TEESMC32_CALL_GET_OS_REVISION \ 414 TEESMC_CALL_VAL(TEESMC_32, TEESMC_FAST_CALL, TEESMC_OWNER_TRUSTED_OS, \ 415 TEESMC_FUNCID_GET_OS_REVISION) 416 417 418 419 /* 420 * Call with struct teesmc32_arg as argument 421 * 422 * Call register usage: 423 * r0/x0 SMC Function ID, TEESMC32_CALL_WITH_ARG 424 * r1/x1 Physical pointer to a struct teesmc32_arg 425 * r2-6/x2-6 Not used 426 * r7/x7 Hypervisor Client ID register 427 * 428 * Normal return register usage: 429 * r0/x0 Return value, TEESMC_RETURN_* 430 * r1-3/x1-3 Not used 431 * r4-7/x4-7 Preserved 432 * 433 * Ebusy return register usage: 434 * r0/x0 Return value, TEESMC_RETURN_EBUSY 435 * r1-3/x1-3 Preserved 436 * r4-7/x4-7 Preserved 437 * 438 * RPC return register usage: 439 * r0/x0 Return value, TEESMC_RETURN_IS_RPC(val) 440 * r1-2/x1-2 RPC parameters 441 * r3-7/x3-7 Resume information, must be preserved 442 * 443 * Possible return values: 444 * TEESMC_RETURN_UNKNOWN_FUNCTION Trusted OS does not recognize this 445 * function. 446 * TEESMC_RETURN_OK Call completed, result updated in 447 * the previously supplied struct 448 * teesmc32_arg. 449 * TEESMC_RETURN_EBUSY Trusted OS busy, try again later. 450 * TEESMC_RETURN_EBADADDR Bad physcial pointer to struct 451 * teesmc32_arg. 452 * TEESMC_RETURN_EBADCMD Bad/unknown cmd in struct teesmc32_arg 453 * TEESMC_RETURN_IS_RPC() Call suspended by RPC call to normal 454 * world. 455 */ 456 #define TEESMC_FUNCID_CALL_WITH_ARG 2 457 #define TEESMC32_CALL_WITH_ARG \ 458 TEESMC_CALL_VAL(TEESMC_32, TEESMC_STD_CALL, TEESMC_OWNER_TRUSTED_OS, \ 459 TEESMC_FUNCID_CALL_WITH_ARG) 460 /* Same as TEESMC32_CALL_WITH_ARG but a "fast call". */ 461 #define TEESMC32_FASTCALL_WITH_ARG \ 462 TEESMC_CALL_VAL(TEESMC_32, TEESMC_FAST_CALL, TEESMC_OWNER_TRUSTED_OS, \ 463 TEESMC_FUNCID_CALL_WITH_ARG) 464 465 /* 466 * Call with struct teesmc64_arg as argument 467 * 468 * See description of TEESMC32_CALL_WITH_ARG above, uses struct 469 * teesmc64_arg in x1 instead. 470 */ 471 #define TEESMC64_CALL_WITH_ARG \ 472 TEESMC_CALL_VAL(TEESMC_64, TEESMC_STD_CALL, TEESMC_OWNER_TRUSTED_OS, \ 473 TEESMC_FUNCID_CALL_WITH_ARG) 474 /* Same as TEESMC64_CALL_WITH_ARG but a "fast call". */ 475 #define TEESMC64_FASTCALL_WITH_ARG \ 476 TEESMC_CALL_VAL(TEESMC_64, TEESMC_FAST_CALL, TEESMC_OWNER_TRUSTED_OS, \ 477 TEESMC_FUNCID_CALL_WITH_ARG) 478 479 /* 480 * Resume from RPC (for example after processing an IRQ) 481 * 482 * Call register usage: 483 * r0/x0 SMC Function ID, 484 * TEESMC32_CALL_RETURN_FROM_RPC or 485 * TEESMC32_FASTCALL_RETURN_FROM_RPC 486 * r1-3/x1-3 Value of r1-3/x1-3 when TEESMC32_CALL_WITH_ARG returned 487 * TEESMC_RETURN_RPC in r0/x0 488 * 489 * Return register usage is the same as for TEESMC32_CALL_WITH_ARG above. 490 * 491 * Possible return values 492 * TEESMC_RETURN_UNKNOWN_FUNCTION Trusted OS does not recognize this 493 * function. 494 * TEESMC_RETURN_OK Original call completed, result 495 * updated in the previously supplied. 496 * struct teesmc32_arg 497 * TEESMC_RETURN_RPC Call suspended by RPC call to normal 498 * world. 499 * TEESMC_RETURN_EBUSY Trusted OS busy, try again later. 500 * TEESMC_RETURN_ERESUME Resume failed, the opaque resume 501 * information was corrupt. 502 */ 503 #define TEESMC_FUNCID_RETURN_FROM_RPC 3 504 #define TEESMC32_CALL_RETURN_FROM_RPC \ 505 TEESMC_CALL_VAL(TEESMC_32, TEESMC_STD_CALL, TEESMC_OWNER_TRUSTED_OS, \ 506 TEESMC_FUNCID_RETURN_FROM_RPC) 507 /* Same as TEESMC32_CALL_RETURN_FROM_RPC but a "fast call". */ 508 #define TEESMC32_FASTCALL_RETURN_FROM_RPC \ 509 TEESMC_CALL_VAL(TEESMC_32, TEESMC_STD_CALL, TEESMC_OWNER_TRUSTED_OS, \ 510 TEESMC_FUNCID_RETURN_FROM_RPC) 511 512 /* 513 * Resume from RPC (for example after processing an IRQ) 514 * 515 * See description of TEESMC32_CALL_RETURN_FROM_RPC above, used when 516 * it's a 64bit call that has returned. 517 */ 518 #define TEESMC64_CALL_RETURN_FROM_RPC \ 519 TEESMC_CALL_VAL(TEESMC_64, TEESMC_STD_CALL, TEESMC_OWNER_TRUSTED_OS, \ 520 TEESMC_FUNCID_RETURN_FROM_RPC) 521 /* Same as TEESMC64_CALL_RETURN_FROM_RPC but a "fast call". */ 522 #define TEESMC64_FASTCALL_RETURN_FROM_RPC \ 523 TEESMC_CALL_VAL(TEESMC_64, TEESMC_STD_CALL, TEESMC_OWNER_TRUSTED_OS, \ 524 TEESMC_FUNCID_RETURN_FROM_RPC) 525 526 #define TEESMC_RETURN_RPC_PREFIX_MASK 0xFFFF0000 527 #define TEESMC_RETURN_RPC_PREFIX 0xFFFF0000 528 #define TEESMC_RETURN_RPC_FUNC_MASK 0x0000FFFF 529 530 #define TEESMC_RETURN_GET_RPC_FUNC(ret) ((ret) & TEESMC_RETURN_RPC_FUNC_MASK) 531 532 #define TEESMC_RPC_VAL(func) ((func) | TEESMC_RETURN_RPC_PREFIX) 533 534 /* 535 * Allocate argument memory for RPC parameter passing. 536 * Argument memory is used to hold a struct teesmc32_arg. 537 * 538 * "Call" register usage: 539 * r0/x0 This value, TEESMC_RETURN_RPC_ALLOC 540 * r1/x1 Size in bytes of required argument memory 541 * r2-7/x2-7 Resume information, must be preserved 542 * 543 * "Return" register usage: 544 * r0/x0 SMC Function ID, TEESMC32_CALL_RETURN_FROM_RPC if it was an 545 * AArch32 SMC return or TEESMC64_CALL_RETURN_FROM_RPC for 546 * AArch64 SMC return 547 * r1/x1 Physical pointer to allocated argument memory, 0 if size 548 * was 0 or if memory can't be allocated 549 * r2-7/x2-7 Preserved 550 */ 551 #define TEESMC_RPC_FUNC_ALLOC_ARG 0 552 #define TEESMC_RETURN_RPC_ALLOC_ARG \ 553 TEESMC_RPC_VAL(TEESMC_RPC_FUNC_ALLOC_ARG) 554 555 /* 556 * Allocate payload memory for RPC parameter passing. 557 * Payload memory is used to hold the memory referred to by struct 558 * teesmc32_param_memref. 559 * 560 * "Call" register usage: 561 * r0/x0 This value, TEESMC_RETURN_RPC_ALLOC 562 * r1/x1 Size in bytes of required payload memory 563 * r2-7/x2-7 Resume information, must be preserved 564 * 565 * "Return" register usage: 566 * r0/x0 SMC Function ID, TEESMC32_CALL_RETURN_FROM_RPC if it was an 567 * AArch32 SMC return or TEESMC64_CALL_RETURN_FROM_RPC for 568 * AArch64 SMC return 569 * r1/x1 Physical pointer to allocated payload memory, 0 if size 570 * was 0 or if memory can't be allocated 571 * r2-7/x2-7 Preserved 572 */ 573 #define TEESMC_RPC_FUNC_ALLOC_PAYLOAD 1 574 #define TEESMC_RETURN_RPC_ALLOC_PAYLOAD \ 575 TEESMC_RPC_VAL(TEESMC_RPC_FUNC_ALLOC_PAYLOAD) 576 577 /* 578 * Free memory previously allocated by TEESMC_RETURN_RPC_ALLOC_ARG. 579 * 580 * "Call" register usage: 581 * r0/x0 This value, TEESMC_RETURN_RPC_FREE 582 * r1/x1 Physical pointer to previously allocated argument memory 583 * r2-7/x2-7 Resume information, must be preserved 584 * 585 * "Return" register usage: 586 * r0/x0 SMC Function ID, TEESMC32_CALL_RETURN_FROM_RPC if it was an 587 * AArch32 SMC return or TEESMC64_CALL_RETURN_FROM_RPC for 588 * AArch64 SMC return 589 * r1/x1 Not used 590 * r2-7/x2-7 Preserved 591 */ 592 #define TEESMC_RPC_FUNC_FREE_ARG 2 593 #define TEESMC_RETURN_RPC_FREE_ARG TEESMC_RPC_VAL(TEESMC_RPC_FUNC_FREE_ARG) 594 595 /* 596 * Free memory previously allocated by TEESMC_RETURN_RPC_ALLOC_PAYLOAD. 597 * 598 * "Call" register usage: 599 * r0/x0 This value, TEESMC_RETURN_RPC_FREE 600 * r1/x1 Physical pointer to previously allocated payload memory 601 * r3-7/x3-7 Resume information, must be preserved 602 * 603 * "Return" register usage: 604 * r0/x0 SMC Function ID, TEESMC32_CALL_RETURN_FROM_RPC if it was an 605 * AArch32 SMC return or TEESMC64_CALL_RETURN_FROM_RPC for 606 * AArch64 SMC return 607 * r1-2/x1-2 Not used 608 * r3-7/x3-7 Preserved 609 */ 610 #define TEESMC_RPC_FUNC_FREE_PAYLOAD 3 611 #define TEESMC_RETURN_RPC_FREE_PAYLOAD \ 612 TEESMC_RPC_VAL(TEESMC_RPC_FUNC_FREE_PAYLOAD) 613 614 /* 615 * Deliver an IRQ in normal world. 616 * 617 * "Call" register usage: 618 * r0/x0 TEESMC_RETURN_RPC_IRQ 619 * r1-7/x1-7 Resume information, must be preserved 620 * 621 * "Return" register usage: 622 * r0/x0 SMC Function ID, TEESMC32_CALL_RETURN_FROM_RPC if it was an 623 * AArch32 SMC return or TEESMC64_CALL_RETURN_FROM_RPC for 624 * AArch64 SMC return 625 * r1-7/x1-7 Preserved 626 */ 627 #define TEESMC_RPC_FUNC_IRQ 4 628 #define TEESMC_RETURN_RPC_IRQ TEESMC_RPC_VAL(TEESMC_RPC_FUNC_IRQ) 629 630 /* 631 * Do an RPC request. The supplied struct teesmc{32,64}_arg tells which 632 * request to do and the paramters for the request. The following fields 633 * are used (the rest are unused): 634 * - cmd the Request ID 635 * - ret return value of the request, filled in by normal world 636 * - num_params number of parameters for the request 637 * - params the parameters 638 * - param_attrs attributes of the parameters 639 * 640 * "Call" register usage: 641 * r0/x0 TEESMC_RETURN_RPC_CMD 642 * r1/x1 Physical pointer to a struct teesmc32_arg if returning from 643 * a AArch32 SMC or a struct teesmc64_arg if returning from a 644 * AArch64 SMC, must be preserved, only the data should 645 * be updated 646 * r2-7/x2-7 Resume information, must be preserved 647 * 648 * "Return" register usage: 649 * r0/x0 SMC Function ID, TEESMC32_CALL_RETURN_FROM_RPC if it was an 650 * AArch32 SMC return or TEESMC64_CALL_RETURN_FROM_RPC for 651 * AArch64 SMC return 652 * r1-7/x1-7 Preserved 653 */ 654 #define TEESMC_RPC_FUNC_CMD 5 655 #define TEESMC_RETURN_RPC_CMD TEESMC_RPC_VAL(TEESMC_RPC_FUNC_CMD) 656 657 658 /* Returned in r0 */ 659 #define TEESMC_RETURN_UNKNOWN_FUNCTION 0xFFFFFFFF 660 661 /* Returned in r0 only from Trusted OS functions */ 662 #define TEESMC_RETURN_OK 0x0 663 #define TEESMC_RETURN_EBUSY 0x1 664 #define TEESMC_RETURN_ERESUME 0x2 665 #define TEESMC_RETURN_EBADADDR 0x3 666 #define TEESMC_RETURN_EBADCMD 0x4 667 #define TEESMC_RETURN_IS_RPC(ret) \ 668 (((ret) & TEESMC_RETURN_RPC_PREFIX_MASK) == TEESMC_RETURN_RPC_PREFIX) 669 670 typedef struct teesmc32_arg t_teesmc32_arg; 671 typedef struct teesmc32_param t_teesmc32_param; 672 typedef struct teesmc_meta_open_session t_teesmc_meta_open_session; 673 674 void tee_smc_call(ARM_SMC_ARGS *param); 675 676 #endif /* TEESMC_H */ 677