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 * struct teesmc64_arg - SMC argument for Trusted OS 211 * @cmd: OS Command, one of TEESMC_CMD_* 212 * @ta_func: Trusted Application function, specific to the Trusted Application 213 * @session: In parameter for all TEESMC_CMD_* but 214 * TEESMC_CMD_OPEN_SESSION 215 * @ret: return value 216 * @ret_origin: origin of the return value 217 * @num_params: number of parameters supplied to the OS Command 218 * @params: the parameters supplied to the OS Command 219 * 220 * See description of struct teesmc32_arg. 221 */ 222 struct teesmc64_arg { 223 uint64_t cmd; 224 uint64_t ta_func; 225 uint64_t session; 226 uint64_t ret; 227 uint64_t ret_origin; 228 uint64_t num_params; 229 /* 230 * Commented out element used to visualize the layout dynamic part 231 * of the struct. Note that this field is not available at all 232 * if num_params == 0. 233 * 234 * params is accessed through the macro TEESMC64_GET_PARAMS 235 * 236 * struct teesmc64_param params[num_params]; 237 */ 238 }; 239 240 /** 241 * TEESMC64_GET_PARAMS - return pointer to union teesmc64_param * 242 * 243 * @x: Pointer to a struct teesmc64_arg 244 * 245 * Returns a pointer to the params[] inside a struct teesmc64_arg. 246 */ 247 #define TEESMC64_GET_PARAMS(x) \ 248 (struct teesmc64_param *)(((struct teesmc64_arg *)(x)) + 1) 249 250 /** 251 * TEESMC64_GET_ARG_SIZE - return size of struct teesmc64_arg 252 * 253 * @num_params: Number of parameters embedded in the struct teesmc64_arg 254 * 255 * Returns the size of the struct teesmc64_arg together with the number 256 * of embedded paramters. 257 */ 258 #define TEESMC64_GET_ARG_SIZE(num_params) \ 259 (sizeof(struct teesmc64_arg) + \ 260 sizeof(struct teesmc64_param) * (num_params)) 261 262 #define TEESMC_UUID_LEN 16 263 264 /** 265 * struct teesmc_meta_open_session - additional parameters for 266 * TEESMC32_CMD_OPEN_SESSION and 267 * TEESMC64_CMD_OPEN_SESSION 268 * @uuid: UUID of the Trusted Application 269 * @clnt_uuid: UUID of client 270 * @clnt_login: Login class of client, TEE_LOGIN_* if being Global Platform 271 * compliant 272 * 273 * This struct is passed in the first parameter as an input memref tagged 274 * as meta on an TEESMC{32,64}_CMD_OPEN_SESSION cmd. It's important 275 * that it really is the first parameter to make it easy for an eventual 276 * hypervisor to inspect and possibly update clnt_* values. 277 */ 278 struct teesmc_meta_open_session { 279 uint8_t uuid[TEESMC_UUID_LEN]; 280 uint8_t clnt_uuid[TEESMC_UUID_LEN]; 281 uint32_t clnt_login; 282 }; 283 284 285 #endif /*!ASM*/ 286 287 /* 288 ******************************************************************************* 289 * Part 2 - low level SMC interaction 290 ******************************************************************************* 291 */ 292 293 #define TEESMC_32 0 294 #define TEESMC_64 0x40000000 295 #define TEESMC_FAST_CALL 0x80000000 296 #define TEESMC_STD_CALL 0 297 298 #define TEESMC_OWNER_MASK 0x3F 299 #define TEESMC_OWNER_SHIFT 24 300 301 #define TEESMC_FUNC_MASK 0xFFFF 302 303 #define TEESMC_IS_FAST_CALL(smc_val) ((smc_val) & TEESMC_FAST_CALL) 304 #define TEESMC_IS_64(smc_val) ((smc_val) & TEESMC_64) 305 #define TEESMC_FUNC_NUM(smc_val) ((smc_val) & TEESMC_FUNC_MASK) 306 #define TEESMC_OWNER_NUM(smc_val) (((smc_val) >> TEESMC_OWNER_SHIFT) & \ 307 TEESMC_OWNER_MASK) 308 309 #define TEESMC_CALL_VAL(type, calling_convention, owner, func_num) \ 310 ((type) | (calling_convention) | \ 311 (((owner) & TEESMC_OWNER_MASK) << TEESMC_OWNER_SHIFT) |\ 312 ((func_num) & TEESMC_FUNC_MASK)) 313 314 #define TEESMC_OWNER_ARCH 0 315 #define TEESMC_OWNER_CPU 1 316 #define TEESMC_OWNER_SIP 2 317 #define TEESMC_OWNER_OEM 3 318 #define TEESMC_OWNER_STANDARD 4 319 #define TEESMC_OWNER_TRUSTED_APP 48 320 #define TEESMC_OWNER_TRUSTED_OS 50 321 322 #define TEESMC_OWNER_TRUSTED_OS_OPTEED 62 323 #define TEESMC_OWNER_TRUSTED_OS_API 63 324 325 /* 326 * Function specified by SMC Calling convention. 327 */ 328 #define TEESMC32_FUNCID_CALLS_COUNT 0xFF00 329 #define TEESMC32_CALLS_COUNT \ 330 TEESMC_CALL_VAL(TEESMC_32, TEESMC_FAST_CALL, \ 331 TEESMC_OWNER_TRUSTED_OS_API, \ 332 TEESMC32_FUNCID_CALLS_COUNT) 333 334 /* 335 * Function specified by SMC Calling convention 336 * 337 * Return one of the following UIDs if using API specified in this file 338 * without further extentions: 339 * 65cb6b93-af0c-4617-8ed6-644a8d1140f8 : Only 32 bit calls are supported 340 * 65cb6b93-af0c-4617-8ed6-644a8d1140f9 : Both 32 and 64 bit calls are supported 341 */ 342 #define TEESMC_UID_R0 0x65cb6b93 343 #define TEESMC_UID_R1 0xaf0c4617 344 #define TEESMC_UID_R2 0x8ed6644a 345 #define TEESMC_UID32_R3 0x8d1140f8 346 #define TEESMC_UID64_R3 0x8d1140f9 347 #define TEESMC32_FUNCID_CALLS_UID 0xFF01 348 #define TEESMC32_CALLS_UID \ 349 TEESMC_CALL_VAL(TEESMC_32, TEESMC_FAST_CALL, \ 350 TEESMC_OWNER_TRUSTED_OS_API, \ 351 TEESMC32_FUNCID_CALLS_UID) 352 353 /* 354 * Function specified by SMC Calling convention 355 * 356 * Returns 1.0 if using API specified in this file without further extentions. 357 */ 358 #define TEESMC_REVISION_MAJOR 1 359 #define TEESMC_REVISION_MINOR 0 360 #define TEESMC32_FUNCID_CALLS_REVISION 0xFF03 361 #define TEESMC32_CALLS_REVISION \ 362 TEESMC_CALL_VAL(TEESMC_32, TEESMC_FAST_CALL, \ 363 TEESMC_OWNER_TRUSTED_OS_API, \ 364 TEESMC32_FUNCID_CALLS_REVISION) 365 366 /* 367 * Get UUID of Trusted OS. 368 * 369 * Used by non-secure world to figure out which Trusted OS is installed. 370 * Note that returned UUID is the UUID of the Trusted OS, not of the API. 371 * 372 * Returns UUID in r0-4/w0-4 in the same way as TEESMC32_CALLS_UID 373 * described above. 374 */ 375 #define TEESMC_FUNCID_GET_OS_UUID 0 376 #define TEESMC32_CALL_GET_OS_UUID \ 377 TEESMC_CALL_VAL(TEESMC_32, TEESMC_FAST_CALL, TEESMC_OWNER_TRUSTED_OS, \ 378 TEESMC_FUNCID_GET_OS_UUID) 379 380 /* 381 * Get revision of Trusted OS. 382 * 383 * Used by non-secure world to figure out which version of the Trusted OS 384 * is installed. Note that the returned revision is the revision of the 385 * Trusted OS, not of the API. 386 * 387 * Returns revision in r0-1/w0-1 in the same way as TEESMC32_CALLS_REVISION 388 * described above. 389 */ 390 #define TEESMC_FUNCID_GET_OS_REVISION 1 391 #define TEESMC32_CALL_GET_OS_REVISION \ 392 TEESMC_CALL_VAL(TEESMC_32, TEESMC_FAST_CALL, TEESMC_OWNER_TRUSTED_OS, \ 393 TEESMC_FUNCID_GET_OS_REVISION) 394 395 396 397 /* 398 * Call with struct teesmc32_arg as argument 399 * 400 * Call register usage: 401 * r0/x0 SMC Function ID, TEESMC32_CALL_WITH_ARG 402 * r1/x1 Physical pointer to a struct teesmc32_arg 403 * r2-6/x2-6 Not used 404 * r7/x7 Hypervisor Client ID register 405 * 406 * Normal return register usage: 407 * r0/x0 Return value, TEESMC_RETURN_* 408 * r1-3/x1-3 Not used 409 * r4-7/x4-7 Preserved 410 * 411 * Ebusy return register usage: 412 * r0/x0 Return value, TEESMC_RETURN_EBUSY 413 * r1-3/x1-3 Preserved 414 * r4-7/x4-7 Preserved 415 * 416 * RPC return register usage: 417 * r0/x0 Return value, TEESMC_RETURN_IS_RPC(val) 418 * r1-2/x1-2 RPC parameters 419 * r3-7/x3-7 Resume information, must be preserved 420 * 421 * Possible return values: 422 * TEESMC_RETURN_UNKNOWN_FUNCTION Trusted OS does not recognize this 423 * function. 424 * TEESMC_RETURN_OK Call completed, result updated in 425 * the previously supplied struct 426 * teesmc32_arg. 427 * TEESMC_RETURN_EBUSY Trusted OS busy, try again later. 428 * TEESMC_RETURN_EBADADDR Bad physcial pointer to struct 429 * teesmc32_arg. 430 * TEESMC_RETURN_EBADCMD Bad/unknown cmd in struct teesmc32_arg 431 * TEESMC_RETURN_IS_RPC() Call suspended by RPC call to normal 432 * world. 433 */ 434 #define TEESMC_FUNCID_CALL_WITH_ARG 2 435 #define TEESMC32_CALL_WITH_ARG \ 436 TEESMC_CALL_VAL(TEESMC_32, TEESMC_STD_CALL, TEESMC_OWNER_TRUSTED_OS, \ 437 TEESMC_FUNCID_CALL_WITH_ARG) 438 /* Same as TEESMC32_CALL_WITH_ARG but a "fast call". */ 439 #define TEESMC32_FASTCALL_WITH_ARG \ 440 TEESMC_CALL_VAL(TEESMC_32, TEESMC_FAST_CALL, TEESMC_OWNER_TRUSTED_OS, \ 441 TEESMC_FUNCID_CALL_WITH_ARG) 442 443 /* 444 * Call with struct teesmc64_arg as argument 445 * 446 * See description of TEESMC32_CALL_WITH_ARG above, uses struct 447 * teesmc64_arg in x1 instead. 448 */ 449 #define TEESMC64_CALL_WITH_ARG \ 450 TEESMC_CALL_VAL(TEESMC_64, TEESMC_STD_CALL, TEESMC_OWNER_TRUSTED_OS, \ 451 TEESMC_FUNCID_CALL_WITH_ARG) 452 /* Same as TEESMC64_CALL_WITH_ARG but a "fast call". */ 453 #define TEESMC64_FASTCALL_WITH_ARG \ 454 TEESMC_CALL_VAL(TEESMC_64, TEESMC_FAST_CALL, TEESMC_OWNER_TRUSTED_OS, \ 455 TEESMC_FUNCID_CALL_WITH_ARG) 456 457 /* 458 * Resume from RPC (for example after processing an IRQ) 459 * 460 * Call register usage: 461 * r0/x0 SMC Function ID, 462 * TEESMC32_CALL_RETURN_FROM_RPC or 463 * TEESMC32_FASTCALL_RETURN_FROM_RPC 464 * r1-3/x1-3 Value of r1-3/x1-3 when TEESMC32_CALL_WITH_ARG returned 465 * TEESMC_RETURN_RPC in r0/x0 466 * 467 * Return register usage is the same as for TEESMC32_CALL_WITH_ARG above. 468 * 469 * Possible return values 470 * TEESMC_RETURN_UNKNOWN_FUNCTION Trusted OS does not recognize this 471 * function. 472 * TEESMC_RETURN_OK Original call completed, result 473 * updated in the previously supplied. 474 * struct teesmc32_arg 475 * TEESMC_RETURN_RPC Call suspended by RPC call to normal 476 * world. 477 * TEESMC_RETURN_EBUSY Trusted OS busy, try again later. 478 * TEESMC_RETURN_ERESUME Resume failed, the opaque resume 479 * information was corrupt. 480 */ 481 #define TEESMC_FUNCID_RETURN_FROM_RPC 3 482 #define TEESMC32_CALL_RETURN_FROM_RPC \ 483 TEESMC_CALL_VAL(TEESMC_32, TEESMC_STD_CALL, TEESMC_OWNER_TRUSTED_OS, \ 484 TEESMC_FUNCID_RETURN_FROM_RPC) 485 /* Same as TEESMC32_CALL_RETURN_FROM_RPC but a "fast call". */ 486 #define TEESMC32_FASTCALL_RETURN_FROM_RPC \ 487 TEESMC_CALL_VAL(TEESMC_32, TEESMC_STD_CALL, TEESMC_OWNER_TRUSTED_OS, \ 488 TEESMC_FUNCID_RETURN_FROM_RPC) 489 490 /* 491 * Resume from RPC (for example after processing an IRQ) 492 * 493 * See description of TEESMC32_CALL_RETURN_FROM_RPC above, used when 494 * it's a 64bit call that has returned. 495 */ 496 #define TEESMC64_CALL_RETURN_FROM_RPC \ 497 TEESMC_CALL_VAL(TEESMC_64, TEESMC_STD_CALL, TEESMC_OWNER_TRUSTED_OS, \ 498 TEESMC_FUNCID_RETURN_FROM_RPC) 499 /* Same as TEESMC64_CALL_RETURN_FROM_RPC but a "fast call". */ 500 #define TEESMC64_FASTCALL_RETURN_FROM_RPC \ 501 TEESMC_CALL_VAL(TEESMC_64, TEESMC_STD_CALL, TEESMC_OWNER_TRUSTED_OS, \ 502 TEESMC_FUNCID_RETURN_FROM_RPC) 503 504 #define TEESMC_RETURN_RPC_PREFIX_MASK 0xFFFF0000 505 #define TEESMC_RETURN_RPC_PREFIX 0xFFFF0000 506 #define TEESMC_RETURN_RPC_FUNC_MASK 0x0000FFFF 507 508 #define TEESMC_RETURN_GET_RPC_FUNC(ret) ((ret) & TEESMC_RETURN_RPC_FUNC_MASK) 509 510 #define TEESMC_RPC_VAL(func) ((func) | TEESMC_RETURN_RPC_PREFIX) 511 512 /* 513 * Allocate argument memory for RPC parameter passing. 514 * Argument memory is used to hold a struct teesmc32_arg. 515 * 516 * "Call" register usage: 517 * r0/x0 This value, TEESMC_RETURN_RPC_ALLOC 518 * r1/x1 Size in bytes of required argument memory 519 * r2-7/x2-7 Resume information, must be preserved 520 * 521 * "Return" register usage: 522 * r0/x0 SMC Function ID, TEESMC32_CALL_RETURN_FROM_RPC if it was an 523 * AArch32 SMC return or TEESMC64_CALL_RETURN_FROM_RPC for 524 * AArch64 SMC return 525 * r1/x1 Physical pointer to allocated argument memory, 0 if size 526 * was 0 or if memory can't be allocated 527 * r2-7/x2-7 Preserved 528 */ 529 #define TEESMC_RPC_FUNC_ALLOC_ARG 0 530 #define TEESMC_RETURN_RPC_ALLOC_ARG \ 531 TEESMC_RPC_VAL(TEESMC_RPC_FUNC_ALLOC_ARG) 532 533 /* 534 * Allocate payload memory for RPC parameter passing. 535 * Payload memory is used to hold the memory referred to by struct 536 * teesmc32_param_memref. 537 * 538 * "Call" register usage: 539 * r0/x0 This value, TEESMC_RETURN_RPC_ALLOC 540 * r1/x1 Size in bytes of required payload 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 payload 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_PAYLOAD 1 552 #define TEESMC_RETURN_RPC_ALLOC_PAYLOAD \ 553 TEESMC_RPC_VAL(TEESMC_RPC_FUNC_ALLOC_PAYLOAD) 554 555 /* 556 * Free memory previously allocated by TEESMC_RETURN_RPC_ALLOC_ARG. 557 * 558 * "Call" register usage: 559 * r0/x0 This value, TEESMC_RETURN_RPC_FREE 560 * r1/x1 Physical pointer to previously allocated argument memory 561 * r2-7/x2-7 Resume information, must be preserved 562 * 563 * "Return" register usage: 564 * r0/x0 SMC Function ID, TEESMC32_CALL_RETURN_FROM_RPC if it was an 565 * AArch32 SMC return or TEESMC64_CALL_RETURN_FROM_RPC for 566 * AArch64 SMC return 567 * r1/x1 Not used 568 * r2-7/x2-7 Preserved 569 */ 570 #define TEESMC_RPC_FUNC_FREE_ARG 2 571 #define TEESMC_RETURN_RPC_FREE_ARG TEESMC_RPC_VAL(TEESMC_RPC_FUNC_FREE_ARG) 572 573 /* 574 * Free memory previously allocated by TEESMC_RETURN_RPC_ALLOC_PAYLOAD. 575 * 576 * "Call" register usage: 577 * r0/x0 This value, TEESMC_RETURN_RPC_FREE 578 * r1/x1 Physical pointer to previously allocated payload memory 579 * r3-7/x3-7 Resume information, must be preserved 580 * 581 * "Return" register usage: 582 * r0/x0 SMC Function ID, TEESMC32_CALL_RETURN_FROM_RPC if it was an 583 * AArch32 SMC return or TEESMC64_CALL_RETURN_FROM_RPC for 584 * AArch64 SMC return 585 * r1-2/x1-2 Not used 586 * r3-7/x3-7 Preserved 587 */ 588 #define TEESMC_RPC_FUNC_FREE_PAYLOAD 3 589 #define TEESMC_RETURN_RPC_FREE_PAYLOAD \ 590 TEESMC_RPC_VAL(TEESMC_RPC_FUNC_FREE_PAYLOAD) 591 592 /* 593 * Deliver an IRQ in normal world. 594 * 595 * "Call" register usage: 596 * r0/x0 TEESMC_RETURN_RPC_IRQ 597 * r1-7/x1-7 Resume information, must be preserved 598 * 599 * "Return" register usage: 600 * r0/x0 SMC Function ID, TEESMC32_CALL_RETURN_FROM_RPC if it was an 601 * AArch32 SMC return or TEESMC64_CALL_RETURN_FROM_RPC for 602 * AArch64 SMC return 603 * r1-7/x1-7 Preserved 604 */ 605 #define TEESMC_RPC_FUNC_IRQ 4 606 #define TEESMC_RETURN_RPC_IRQ TEESMC_RPC_VAL(TEESMC_RPC_FUNC_IRQ) 607 608 /* 609 * Do an RPC request. The supplied struct teesmc{32,64}_arg tells which 610 * request to do and the paramters for the request. The following fields 611 * are used (the rest are unused): 612 * - cmd the Request ID 613 * - ret return value of the request, filled in by normal world 614 * - num_params number of parameters for the request 615 * - params the parameters 616 * - param_attrs attributes of the parameters 617 * 618 * "Call" register usage: 619 * r0/x0 TEESMC_RETURN_RPC_CMD 620 * r1/x1 Physical pointer to a struct teesmc32_arg if returning from 621 * a AArch32 SMC or a struct teesmc64_arg if returning from a 622 * AArch64 SMC, must be preserved, only the data should 623 * be updated 624 * r2-7/x2-7 Resume information, must be preserved 625 * 626 * "Return" register usage: 627 * r0/x0 SMC Function ID, TEESMC32_CALL_RETURN_FROM_RPC if it was an 628 * AArch32 SMC return or TEESMC64_CALL_RETURN_FROM_RPC for 629 * AArch64 SMC return 630 * r1-7/x1-7 Preserved 631 */ 632 #define TEESMC_RPC_FUNC_CMD 5 633 #define TEESMC_RETURN_RPC_CMD TEESMC_RPC_VAL(TEESMC_RPC_FUNC_CMD) 634 635 636 /* Returned in r0 */ 637 #define TEESMC_RETURN_UNKNOWN_FUNCTION 0xFFFFFFFF 638 639 /* Returned in r0 only from Trusted OS functions */ 640 #define TEESMC_RETURN_OK 0x0 641 #define TEESMC_RETURN_EBUSY 0x1 642 #define TEESMC_RETURN_ERESUME 0x2 643 #define TEESMC_RETURN_EBADADDR 0x3 644 #define TEESMC_RETURN_EBADCMD 0x4 645 #define TEESMC_RETURN_IS_RPC(ret) \ 646 (((ret) & TEESMC_RETURN_RPC_PREFIX_MASK) == TEESMC_RETURN_RPC_PREFIX) 647 648 typedef struct teesmc_meta_open_session t_teesmc_meta_open_session; 649 650 void tee_smc_call(ARM_SMC_ARGS *param); 651 652 #endif /* TEESMC_H */ 653