1 /* SPDX-License-Identifier: BSD-2-Clause */ 2 /* 3 * Copyright (c) 2015-2021, Linaro Limited 4 */ 5 #ifndef OPTEE_SMC_H 6 #define OPTEE_SMC_H 7 8 #include <stdint.h> 9 10 /* 11 * This file is exported by OP-TEE and is in kept in sync between secure 12 * world and normal world kernel driver. We're following ARM SMC Calling 13 * Convention as specified in 14 * http://infocenter.arm.com/help/topic/com.arm.doc.den0028a/index.html 15 * 16 * This file depends on optee_msg.h being included to expand the SMC id 17 * macros below. 18 */ 19 20 #define OPTEE_SMC_32 U(0) 21 #define OPTEE_SMC_64 U(0x40000000) 22 #define OPTEE_SMC_FAST_CALL U(0x80000000) 23 #define OPTEE_SMC_STD_CALL U(0) 24 25 #define OPTEE_SMC_OWNER_MASK U(0x3F) 26 #define OPTEE_SMC_OWNER_SHIFT U(24) 27 28 #define OPTEE_SMC_FUNC_MASK U(0xFFFF) 29 30 #define OPTEE_SMC_IS_FAST_CALL(smc_val) ((smc_val) & OPTEE_SMC_FAST_CALL) 31 #define OPTEE_SMC_IS_64(smc_val) ((smc_val) & OPTEE_SMC_64) 32 #define OPTEE_SMC_FUNC_NUM(smc_val) ((smc_val) & OPTEE_SMC_FUNC_MASK) 33 #define OPTEE_SMC_OWNER_NUM(smc_val) \ 34 (((smc_val) >> OPTEE_SMC_OWNER_SHIFT) & OPTEE_SMC_OWNER_MASK) 35 36 #define OPTEE_SMC_CALL_VAL(type, calling_convention, owner, func_num) \ 37 ((type) | (calling_convention) | \ 38 (((owner) & OPTEE_SMC_OWNER_MASK) << \ 39 OPTEE_SMC_OWNER_SHIFT) |\ 40 ((func_num) & OPTEE_SMC_FUNC_MASK)) 41 42 #define OPTEE_SMC_STD_CALL_VAL(func_num) \ 43 OPTEE_SMC_CALL_VAL(OPTEE_SMC_32, OPTEE_SMC_STD_CALL, \ 44 OPTEE_SMC_OWNER_TRUSTED_OS, (func_num)) 45 #define OPTEE_SMC_FAST_CALL_VAL(func_num) \ 46 OPTEE_SMC_CALL_VAL(OPTEE_SMC_32, OPTEE_SMC_FAST_CALL, \ 47 OPTEE_SMC_OWNER_TRUSTED_OS, (func_num)) 48 49 #define OPTEE_SMC_OWNER_ARCH U(0) 50 #define OPTEE_SMC_OWNER_CPU U(1) 51 #define OPTEE_SMC_OWNER_SIP U(2) 52 #define OPTEE_SMC_OWNER_OEM U(3) 53 #define OPTEE_SMC_OWNER_STANDARD U(4) 54 #define OPTEE_SMC_OWNER_TRUSTED_APP U(48) 55 #define OPTEE_SMC_OWNER_TRUSTED_OS U(50) 56 57 #define OPTEE_SMC_OWNER_TRUSTED_OS_OPTEED U(62) 58 #define OPTEE_SMC_OWNER_TRUSTED_OS_API U(63) 59 60 /* 61 * Function specified by SMC Calling convention. 62 */ 63 #define OPTEE_SMC_FUNCID_CALLS_COUNT U(0xFF00) 64 #define OPTEE_SMC_CALLS_COUNT \ 65 OPTEE_SMC_CALL_VAL(OPTEE_SMC_32, OPTEE_SMC_FAST_CALL, \ 66 OPTEE_SMC_OWNER_TRUSTED_OS_API, \ 67 OPTEE_SMC_FUNCID_CALLS_COUNT) 68 69 /* 70 * Normal cached memory (write-back), shareable for SMP systems and not 71 * shareable for UP systems. 72 */ 73 #define OPTEE_SMC_SHM_CACHED U(1) 74 75 /* 76 * a0..a7 is used as register names in the descriptions below, on arm32 77 * that translates to r0..r7 and on arm64 to w0..w7. In both cases it's 78 * 32-bit registers. 79 */ 80 81 /* 82 * Function specified by SMC Calling convention 83 * 84 * Return the following UID if using API specified in this file 85 * without further extensions: 86 * 384fb3e0-e7f8-11e3-af63-0002a5d5c51b. 87 * see also OPTEE_MSG_UID_* in optee_msg.h 88 */ 89 #define OPTEE_SMC_FUNCID_CALLS_UID OPTEE_MSG_FUNCID_CALLS_UID 90 #define OPTEE_SMC_CALLS_UID \ 91 OPTEE_SMC_CALL_VAL(OPTEE_SMC_32, OPTEE_SMC_FAST_CALL, \ 92 OPTEE_SMC_OWNER_TRUSTED_OS_API, \ 93 OPTEE_SMC_FUNCID_CALLS_UID) 94 95 /* 96 * Function specified by SMC Calling convention 97 * 98 * Returns 2.0 if using API specified in this file without further extensions. 99 * see also OPTEE_MSG_REVISION_* in optee_msg.h 100 */ 101 #define OPTEE_SMC_FUNCID_CALLS_REVISION OPTEE_MSG_FUNCID_CALLS_REVISION 102 #define OPTEE_SMC_CALLS_REVISION \ 103 OPTEE_SMC_CALL_VAL(OPTEE_SMC_32, OPTEE_SMC_FAST_CALL, \ 104 OPTEE_SMC_OWNER_TRUSTED_OS_API, \ 105 OPTEE_SMC_FUNCID_CALLS_REVISION) 106 107 /* 108 * Get UUID of Trusted OS. 109 * 110 * Used by non-secure world to figure out which Trusted OS is installed. 111 * Note that returned UUID is the UUID of the Trusted OS, not of the API. 112 * 113 * Returns UUID in a0-4 in the same way as OPTEE_SMC_CALLS_UID 114 * described above. 115 */ 116 #define OPTEE_SMC_FUNCID_GET_OS_UUID OPTEE_MSG_FUNCID_GET_OS_UUID 117 #define OPTEE_SMC_CALL_GET_OS_UUID \ 118 OPTEE_SMC_FAST_CALL_VAL(OPTEE_SMC_FUNCID_GET_OS_UUID) 119 120 /* 121 * Get revision of Trusted OS. 122 * 123 * Used by non-secure world to figure out which version of the Trusted OS 124 * is installed. Note that the returned revision is the revision of the 125 * Trusted OS, not of the API. 126 * 127 * Returns revision in a0-1 in the same way as OPTEE_SMC_CALLS_REVISION 128 * described above. May optionally return a 32-bit build identifier in a2, 129 * with zero meaning unspecified. 130 */ 131 #define OPTEE_SMC_FUNCID_GET_OS_REVISION OPTEE_MSG_FUNCID_GET_OS_REVISION 132 #define OPTEE_SMC_CALL_GET_OS_REVISION \ 133 OPTEE_SMC_FAST_CALL_VAL(OPTEE_SMC_FUNCID_GET_OS_REVISION) 134 135 /* 136 * Call with struct optee_msg_arg as argument 137 * 138 * When called with OPTEE_SMC_CALL_WITH_RPC_ARG or 139 * OPTEE_SMC_CALL_WITH_REGD_ARG in a0 there is one RPC struct optee_msg_arg 140 * following after the first struct optee_msg_arg. The RPC struct 141 * optee_msg_arg has reserved space for the number of RPC parameters as 142 * returned by OPTEE_SMC_EXCHANGE_CAPABILITIES. 143 * 144 * When calling these functions normal world has a few responsibilities: 145 * 1. It must be able to handle eventual RPCs 146 * 2. Non-secure interrupts should not be masked 147 * 3. If asynchronous notifications has been negotiated successfully, then 148 * the interrupt for asynchronous notifications should be unmasked 149 * during this call. 150 * 151 * Call register usage, OPTEE_SMC_CALL_WITH_ARG and 152 * OPTEE_SMC_CALL_WITH_RPC_ARG: 153 * a0 SMC Function ID, OPTEE_SMC_CALL_WITH_ARG or OPTEE_SMC_CALL_WITH_RPC_ARG 154 * a1 Upper 32 bits of a 64-bit physical pointer to a struct optee_msg_arg 155 * a2 Lower 32 bits of a 64-bit physical pointer to a struct optee_msg_arg 156 * a3 Cache settings, not used if physical pointer is in a predefined shared 157 * memory area else per OPTEE_SMC_SHM_* 158 * a4-6 Not used 159 * a7 Hypervisor Client ID register 160 * 161 * Call register usage, OPTEE_SMC_CALL_WITH_REGD_ARG: 162 * a0 SMC Function ID, OPTEE_SMC_CALL_WITH_REGD_ARG 163 * a1 Upper 32 bits of a 64-bit shared memory cookie 164 * a2 Lower 32 bits of a 64-bit shared memory cookie 165 * a3 Offset of the struct optee_msg_arg in the shared memory with the 166 * supplied cookie 167 * a4-6 Not used 168 * a7 Hypervisor Client ID register 169 * 170 * Normal return register usage: 171 * a0 Return value, OPTEE_SMC_RETURN_* 172 * a1-3 Not used 173 * a4-7 Preserved 174 * 175 * OPTEE_SMC_RETURN_ETHREAD_LIMIT return register usage: 176 * a0 Return value, OPTEE_SMC_RETURN_ETHREAD_LIMIT 177 * a1-3 Preserved 178 * a4-7 Preserved 179 * 180 * RPC return register usage: 181 * a0 Return value, OPTEE_SMC_RETURN_IS_RPC(val) 182 * a1-2 RPC parameters 183 * a3-7 Resume information, must be preserved 184 * 185 * Possible return values: 186 * OPTEE_SMC_RETURN_UNKNOWN_FUNCTION Trusted OS does not recognize this 187 * function. 188 * OPTEE_SMC_RETURN_OK Call completed, result updated in 189 * the previously supplied struct 190 * optee_msg_arg. 191 * OPTEE_SMC_RETURN_ETHREAD_LIMIT Number of Trusted OS threads exceeded, 192 * try again later. 193 * OPTEE_SMC_RETURN_EBADADDR Bad physical pointer to struct 194 * optee_msg_arg. 195 * OPTEE_SMC_RETURN_EBADCMD Bad/unknown cmd in struct optee_msg_arg 196 * OPTEE_SMC_RETURN_IS_RPC() Call suspended by RPC call to normal 197 * world. 198 */ 199 #define OPTEE_SMC_FUNCID_CALL_WITH_ARG OPTEE_MSG_FUNCID_CALL_WITH_ARG 200 #define OPTEE_SMC_CALL_WITH_ARG \ 201 OPTEE_SMC_STD_CALL_VAL(OPTEE_SMC_FUNCID_CALL_WITH_ARG) 202 #define OPTEE_SMC_CALL_WITH_RPC_ARG \ 203 OPTEE_SMC_STD_CALL_VAL(OPTEE_SMC_FUNCID_CALL_WITH_RPC_ARG) 204 #define OPTEE_SMC_CALL_WITH_REGD_ARG \ 205 OPTEE_SMC_STD_CALL_VAL(OPTEE_SMC_FUNCID_CALL_WITH_REGD_ARG) 206 207 /* 208 * Get Shared Memory Config 209 * 210 * Returns the Secure/Non-secure shared memory config. 211 * 212 * Call register usage: 213 * a0 SMC Function ID, OPTEE_SMC_GET_SHM_CONFIG 214 * a1-6 Not used 215 * a7 Hypervisor Client ID register 216 * 217 * Have config return register usage: 218 * a0 OPTEE_SMC_RETURN_OK 219 * a1 Physical address of start of SHM 220 * a2 Size of of SHM 221 * a3 Cache settings of memory, as defined by the 222 * OPTEE_SMC_SHM_* values above 223 * a4-7 Preserved 224 * 225 * Not available register usage: 226 * a0 OPTEE_SMC_RETURN_ENOTAVAIL 227 * a1-3 Not used 228 * a4-7 Preserved 229 */ 230 #define OPTEE_SMC_FUNCID_GET_SHM_CONFIG 7 231 #define OPTEE_SMC_GET_SHM_CONFIG \ 232 OPTEE_SMC_FAST_CALL_VAL(OPTEE_SMC_FUNCID_GET_SHM_CONFIG) 233 234 /* 235 * Configures L2CC mutex 236 * 237 * Disables, enables usage of L2CC mutex. Returns or sets physical address 238 * of L2CC mutex. 239 * 240 * Call register usage: 241 * a0 SMC Function ID, OPTEE_SMC_L2CC_MUTEX 242 * a1 OPTEE_SMC_L2CC_MUTEX_GET_ADDR Get physical address of mutex 243 * OPTEE_SMC_L2CC_MUTEX_SET_ADDR Set physical address of mutex 244 * OPTEE_SMC_L2CC_MUTEX_ENABLE Enable usage of mutex 245 * OPTEE_SMC_L2CC_MUTEX_DISABLE Disable usage of mutex 246 * a2 if a1 == OPTEE_SMC_L2CC_MUTEX_SET_ADDR, upper 32bit of a 64bit 247 * physical address of mutex 248 * a3 if a1 == OPTEE_SMC_L2CC_MUTEX_SET_ADDR, lower 32bit of a 64bit 249 * physical address of mutex 250 * a3-6 Not used 251 * a7 Hypervisor Client ID register 252 * 253 * Have config return register usage: 254 * a0 OPTEE_SMC_RETURN_OK 255 * a1 Preserved 256 * a2 if a1 == OPTEE_SMC_L2CC_MUTEX_GET_ADDR, upper 32bit of a 64bit 257 * physical address of mutex 258 * a3 if a1 == OPTEE_SMC_L2CC_MUTEX_GET_ADDR, lower 32bit of a 64bit 259 * physical address of mutex 260 * a3-7 Preserved 261 * 262 * Error return register usage: 263 * a0 OPTEE_SMC_RETURN_ENOTAVAIL Physical address not available 264 * OPTEE_SMC_RETURN_EBADADDR Bad supplied physical address 265 * OPTEE_SMC_RETURN_EBADCMD Unsupported value in a1 266 * a1-7 Preserved 267 */ 268 #define OPTEE_SMC_L2CC_MUTEX_GET_ADDR U(0) 269 #define OPTEE_SMC_L2CC_MUTEX_SET_ADDR U(1) 270 #define OPTEE_SMC_L2CC_MUTEX_ENABLE U(2) 271 #define OPTEE_SMC_L2CC_MUTEX_DISABLE U(3) 272 #define OPTEE_SMC_FUNCID_L2CC_MUTEX U(8) 273 #define OPTEE_SMC_L2CC_MUTEX \ 274 OPTEE_SMC_FAST_CALL_VAL(OPTEE_SMC_FUNCID_L2CC_MUTEX) 275 276 /* 277 * Exchanges capabilities between normal world and secure world 278 * 279 * Call register usage: 280 * a0 SMC Function ID, OPTEE_SMC_EXCHANGE_CAPABILITIES 281 * a1 bitfield of normal world capabilities OPTEE_SMC_NSEC_CAP_* 282 * a2-6 Not used 283 * a7 Hypervisor Client ID register 284 * 285 * Normal return register usage: 286 * a0 OPTEE_SMC_RETURN_OK 287 * a1 bitfield of secure world capabilities OPTEE_SMC_SEC_CAP_* 288 * a2 The maximum secure world notification number 289 * a3 Bit[7:0]: Number of parameters needed for RPC to be supplied 290 * as the second MSG arg struct for 291 * OPTEE_SMC_CALL_WITH_ARG 292 * Bit[31:8]: Reserved (MBZ) 293 * a3-7 Preserved 294 * 295 * Error return register usage: 296 * a0 OPTEE_SMC_RETURN_ENOTAVAIL, can't use the capabilities from normal world 297 * a1 bitfield of secure world capabilities OPTEE_SMC_SEC_CAP_* 298 * a2-7 Preserved 299 */ 300 /* Normal world works as a uniprocessor system */ 301 #define OPTEE_SMC_NSEC_CAP_UNIPROCESSOR BIT(0) 302 /* Secure world has reserved shared memory for normal world to use */ 303 #define OPTEE_SMC_SEC_CAP_HAVE_RESERVED_SHM BIT(0) 304 /* Secure world can communicate via previously unregistered shared memory */ 305 #define OPTEE_SMC_SEC_CAP_UNREGISTERED_SHM BIT(1) 306 /* 307 * Secure world supports commands "register/unregister shared memory", 308 * secure world accepts command buffers located in any parts of non-secure RAM 309 */ 310 #define OPTEE_SMC_SEC_CAP_DYNAMIC_SHM BIT(2) 311 /* Secure world is built with virtualization support */ 312 #define OPTEE_SMC_SEC_CAP_VIRTUALIZATION BIT(3) 313 /* Secure world supports Shared Memory with a NULL reference */ 314 #define OPTEE_SMC_SEC_CAP_MEMREF_NULL BIT(4) 315 /* Secure world supports asynchronous notification of normal world */ 316 #define OPTEE_SMC_SEC_CAP_ASYNC_NOTIF BIT(5) 317 /* Secure world supports pre-allocating RPC arg struct */ 318 #define OPTEE_SMC_SEC_CAP_RPC_ARG BIT(6) 319 320 #define OPTEE_SMC_FUNCID_EXCHANGE_CAPABILITIES U(9) 321 #define OPTEE_SMC_EXCHANGE_CAPABILITIES \ 322 OPTEE_SMC_FAST_CALL_VAL(OPTEE_SMC_FUNCID_EXCHANGE_CAPABILITIES) 323 324 /* 325 * Disable and empties cache of shared memory objects 326 * 327 * Secure world can cache frequently used shared memory objects, for 328 * example objects used as RPC arguments. When secure world is idle this 329 * function returns one shared memory reference to free. To disable the 330 * cache and free all cached objects this function has to be called until 331 * it returns OPTEE_SMC_RETURN_ENOTAVAIL. 332 * 333 * Call register usage: 334 * a0 SMC Function ID, OPTEE_SMC_DISABLE_SHM_CACHE 335 * a1-6 Not used 336 * a7 Hypervisor Client ID register 337 * 338 * Normal return register usage: 339 * a0 OPTEE_SMC_RETURN_OK 340 * a1 Upper 32 bits of a 64-bit Shared memory cookie 341 * a2 Lower 32 bits of a 64-bit Shared memory cookie 342 * a3-7 Preserved 343 * 344 * Cache empty return register usage: 345 * a0 OPTEE_SMC_RETURN_ENOTAVAIL 346 * a1-7 Preserved 347 * 348 * Not idle return register usage: 349 * a0 OPTEE_SMC_RETURN_EBUSY 350 * a1-7 Preserved 351 */ 352 #define OPTEE_SMC_FUNCID_DISABLE_SHM_CACHE U(10) 353 #define OPTEE_SMC_DISABLE_SHM_CACHE \ 354 OPTEE_SMC_FAST_CALL_VAL(OPTEE_SMC_FUNCID_DISABLE_SHM_CACHE) 355 356 /* 357 * Enable cache of shared memory objects 358 * 359 * Secure world can cache frequently used shared memory objects, for 360 * example objects used as RPC arguments. When secure world is idle this 361 * function returns OPTEE_SMC_RETURN_OK and the cache is enabled. If 362 * secure world isn't idle OPTEE_SMC_RETURN_EBUSY is returned. 363 * 364 * Call register usage: 365 * a0 SMC Function ID, OPTEE_SMC_ENABLE_SHM_CACHE 366 * a1-6 Not used 367 * a7 Hypervisor Client ID register 368 * 369 * Normal return register usage: 370 * a0 OPTEE_SMC_RETURN_OK 371 * a1-7 Preserved 372 * 373 * Not idle return register usage: 374 * a0 OPTEE_SMC_RETURN_EBUSY 375 * a1-7 Preserved 376 */ 377 #define OPTEE_SMC_FUNCID_ENABLE_SHM_CACHE U(11) 378 #define OPTEE_SMC_ENABLE_SHM_CACHE \ 379 OPTEE_SMC_FAST_CALL_VAL(OPTEE_SMC_FUNCID_ENABLE_SHM_CACHE) 380 381 /* 382 * Release of secondary cores 383 * 384 * OP-TEE in secure world is in charge of the release process of secondary 385 * cores. The Rich OS issue the this request to ask OP-TEE to boot up the 386 * secondary cores, go through the OP-TEE per-core initialization, and then 387 * switch to the Non-seCure world with the Rich OS provided entry address. 388 * The secondary cores enter Non-Secure world in SVC mode, with Thumb, FIQ, 389 * IRQ and Abort bits disabled. 390 * 391 * Call register usage: 392 * a0 SMC Function ID, OPTEE_SMC_BOOT_SECONDARY 393 * a1 Index of secondary core to boot 394 * a2 Upper 32 bits of a 64-bit Non-Secure world entry physical address 395 * a3 Lower 32 bits of a 64-bit Non-Secure world entry physical address 396 * a4-7 Not used 397 * 398 * Normal return register usage: 399 * a0 OPTEE_SMC_RETURN_OK 400 * a1-7 Preserved 401 * 402 * Error return: 403 * a0 OPTEE_SMC_RETURN_EBADCMD Core index out of range 404 * a1-7 Preserved 405 * 406 * Not idle return register usage: 407 * a0 OPTEE_SMC_RETURN_EBUSY 408 * a1-7 Preserved 409 */ 410 #define OPTEE_SMC_FUNCID_BOOT_SECONDARY U(12) 411 #define OPTEE_SMC_BOOT_SECONDARY \ 412 OPTEE_SMC_FAST_CALL_VAL(OPTEE_SMC_FUNCID_BOOT_SECONDARY) 413 414 /* 415 * Inform OP-TEE about a new virtual machine 416 * 417 * Hypervisor issues this call during virtual machine (guest) creation. 418 * OP-TEE records client id of new virtual machine and prepares 419 * to receive requests from it. This call is available only if OP-TEE 420 * was built with virtualization support. 421 * 422 * Call requests usage: 423 * a0 SMC Function ID, OPTEE_SMC_VM_CREATED 424 * a1 Hypervisor Client ID of newly created virtual machine 425 * a2-6 Not used 426 * a7 Hypervisor Client ID register. Must be 0, because only hypervisor 427 * can issue this call 428 * 429 * Normal return register usage: 430 * a0 OPTEE_SMC_RETURN_OK 431 * a1-7 Preserved 432 * 433 * Error return: 434 * a0 OPTEE_SMC_RETURN_ENOTAVAIL OP-TEE have no resources for 435 * another VM 436 * a1-7 Preserved 437 * 438 */ 439 #define OPTEE_SMC_FUNCID_VM_CREATED U(13) 440 #define OPTEE_SMC_VM_CREATED \ 441 OPTEE_SMC_FAST_CALL_VAL(OPTEE_SMC_FUNCID_VM_CREATED) 442 443 /* 444 * Inform OP-TEE about shutdown of a virtual machine 445 * 446 * Hypervisor issues this call during virtual machine (guest) destruction. 447 * OP-TEE will clean up all resources associated with this VM. This call is 448 * available only if OP-TEE was built with virtualization support. 449 * 450 * Call requests usage: 451 * a0 SMC Function ID, OPTEE_SMC_VM_DESTROYED 452 * a1 Hypervisor Client ID of virtual machine being shut down 453 * a2-6 Not used 454 * a7 Hypervisor Client ID register. Must be 0, because only hypervisor 455 * can issue this call 456 * 457 * Normal return register usage: 458 * a0 OPTEE_SMC_RETURN_OK 459 * a1-7 Preserved 460 * 461 */ 462 #define OPTEE_SMC_FUNCID_VM_DESTROYED U(14) 463 #define OPTEE_SMC_VM_DESTROYED \ 464 OPTEE_SMC_FAST_CALL_VAL(OPTEE_SMC_FUNCID_VM_DESTROYED) 465 466 /* 467 * Query OP-TEE about number of supported threads 468 * 469 * Normal World OS or Hypervisor issues this call to find out how many 470 * threads OP-TEE supports. That is how many standard calls can be issued 471 * in parallel before OP-TEE will return OPTEE_SMC_RETURN_ETHREAD_LIMIT. 472 * 473 * Call requests usage: 474 * a0 SMC Function ID, OPTEE_SMC_GET_THREAD_COUNT 475 * a1-6 Not used 476 * a7 Hypervisor Client ID register 477 * 478 * Normal return register usage: 479 * a0 OPTEE_SMC_RETURN_OK 480 * a1 Number of threads 481 * a2-7 Preserved 482 * 483 * Error return: 484 * a0 OPTEE_SMC_RETURN_UNKNOWN_FUNCTION Requested call is not implemented 485 * a1-7 Preserved 486 */ 487 #define OPTEE_SMC_FUNCID_GET_THREAD_COUNT U(15) 488 #define OPTEE_SMC_GET_THREAD_COUNT \ 489 OPTEE_SMC_FAST_CALL_VAL(OPTEE_SMC_FUNCID_GET_THREAD_COUNT) 490 491 /* 492 * Inform OP-TEE that normal world is able to receive asynchronous 493 * notifications. 494 * 495 * Call requests usage: 496 * a0 SMC Function ID, OPTEE_SMC_ENABLE_ASYNC_NOTIF 497 * a1-6 Not used 498 * a7 Hypervisor Client ID register 499 * 500 * Normal return register usage: 501 * a0 OPTEE_SMC_RETURN_OK 502 * a1-7 Preserved 503 * 504 * Not supported return register usage: 505 * a0 OPTEE_SMC_RETURN_ENOTAVAIL 506 * a1-7 Preserved 507 */ 508 #define OPTEE_SMC_FUNCID_ENABLE_ASYNC_NOTIF 16 509 #define OPTEE_SMC_ENABLE_ASYNC_NOTIF \ 510 OPTEE_SMC_FAST_CALL_VAL(OPTEE_SMC_FUNCID_ENABLE_ASYNC_NOTIF) 511 512 /* 513 * Retrieve a value of notifications pending since the last call of this 514 * function. 515 * 516 * OP-TEE keeps a record of all posted values. When an interrupt is 517 * received which indicates that there are posted values this function 518 * should be called until all pended values have been retrieved. When a 519 * value is retrieved, it's cleared from the record in secure world. 520 * 521 * It is expected that this function is called from an interrupt handler 522 * in normal world. 523 * 524 * Call requests usage: 525 * a0 SMC Function ID, OPTEE_SMC_GET_ASYNC_NOTIF_VALUE 526 * a1-6 Not used 527 * a7 Hypervisor Client ID register 528 * 529 * Normal return register usage: 530 * a0 OPTEE_SMC_RETURN_OK 531 * a1 value 532 * a2 Bit[0]: OPTEE_SMC_ASYNC_NOTIF_VALUE_VALID if the value in a1 is 533 * valid, else 0 if no values were pending 534 * a2 Bit[1]: OPTEE_SMC_ASYNC_NOTIF_VALUE_PENDING if another value is 535 * pending, else 0. 536 * Bit[31:2]: MBZ 537 * a3-7 Preserved 538 * 539 * Not supported return register usage: 540 * a0 OPTEE_SMC_RETURN_ENOTAVAIL 541 * a1-7 Preserved 542 */ 543 #define OPTEE_SMC_ASYNC_NOTIF_VALID BIT(0) 544 #define OPTEE_SMC_ASYNC_NOTIF_PENDING BIT(1) 545 546 /* 547 * Notification that OP-TEE expects a yielding call to do some bottom half 548 * work in a driver. 549 */ 550 #define OPTEE_SMC_ASYNC_NOTIF_VALUE_DO_BOTTOM_HALF 0 551 552 #define OPTEE_SMC_FUNCID_GET_ASYNC_NOTIF_VALUE 17 553 #define OPTEE_SMC_GET_ASYNC_NOTIF_VALUE \ 554 OPTEE_SMC_FAST_CALL_VAL(OPTEE_SMC_FUNCID_GET_ASYNC_NOTIF_VALUE) 555 556 /* See OPTEE_SMC_CALL_WITH_RPC_ARG above */ 557 #define OPTEE_SMC_FUNCID_CALL_WITH_RPC_ARG U(18) 558 559 /* See OPTEE_SMC_CALL_WITH_REGD_ARG above */ 560 #define OPTEE_SMC_FUNCID_CALL_WITH_REGD_ARG U(19) 561 562 /* 563 * Resume from RPC (for example after processing a foreign interrupt) 564 * 565 * Call register usage: 566 * a0 SMC Function ID, OPTEE_SMC_CALL_RETURN_FROM_RPC 567 * a1-3 Value of a1-3 when OPTEE_SMC_CALL_WITH_ARG returned 568 * OPTEE_SMC_RETURN_RPC in a0 569 * 570 * Return register usage is the same as for OPTEE_SMC_*CALL_WITH_ARG above. 571 * 572 * Possible return values 573 * OPTEE_SMC_RETURN_UNKNOWN_FUNCTION Trusted OS does not recognize this 574 * function. 575 * OPTEE_SMC_RETURN_OK Original call completed, result 576 * updated in the previously supplied. 577 * struct optee_msg_arg 578 * OPTEE_SMC_RETURN_RPC Call suspended by RPC call to normal 579 * world. 580 * OPTEE_SMC_RETURN_ERESUME Resume failed, the opaque resume 581 * information was corrupt. 582 */ 583 #define OPTEE_SMC_FUNCID_RETURN_FROM_RPC U(3) 584 #define OPTEE_SMC_CALL_RETURN_FROM_RPC \ 585 OPTEE_SMC_STD_CALL_VAL(OPTEE_SMC_FUNCID_RETURN_FROM_RPC) 586 587 #define OPTEE_SMC_RETURN_RPC_PREFIX_MASK U(0xFFFF0000) 588 #define OPTEE_SMC_RETURN_RPC_PREFIX U(0xFFFF0000) 589 #define OPTEE_SMC_RETURN_RPC_FUNC_MASK U(0x0000FFFF) 590 591 #define OPTEE_SMC_RETURN_GET_RPC_FUNC(ret) \ 592 ((ret) & OPTEE_SMC_RETURN_RPC_FUNC_MASK) 593 594 #define OPTEE_SMC_RPC_VAL(func) ((func) | OPTEE_SMC_RETURN_RPC_PREFIX) 595 596 /* 597 * Allocate memory for RPC parameter passing. The memory is used to hold a 598 * struct optee_msg_arg. 599 * 600 * "Call" register usage: 601 * a0 This value, OPTEE_SMC_RETURN_RPC_ALLOC 602 * a1 Size in bytes of required argument memory 603 * a2 Not used 604 * a3 Resume information, must be preserved 605 * a4-5 Not used 606 * a6-7 Resume information, must be preserved 607 * 608 * "Return" register usage: 609 * a0 SMC Function ID, OPTEE_SMC_CALL_RETURN_FROM_RPC. 610 * a1 Upper 32 bits of 64-bit physical pointer to allocated 611 * memory, (a1 == 0 && a2 == 0) if size was 0 or if memory can't 612 * be allocated. 613 * a2 Lower 32 bits of 64-bit physical pointer to allocated 614 * memory, (a1 == 0 && a2 == 0) if size was 0 or if memory can't 615 * be allocated 616 * a3 Preserved 617 * a4 Upper 32 bits of 64-bit Shared memory cookie used when freeing 618 * the memory or doing an RPC 619 * a5 Lower 32 bits of 64-bit Shared memory cookie used when freeing 620 * the memory or doing an RPC 621 * a6-7 Preserved 622 */ 623 #define OPTEE_SMC_RPC_FUNC_ALLOC U(0) 624 #define OPTEE_SMC_RETURN_RPC_ALLOC \ 625 OPTEE_SMC_RPC_VAL(OPTEE_SMC_RPC_FUNC_ALLOC) 626 627 /* 628 * Free memory previously allocated by OPTEE_SMC_RETURN_RPC_ALLOC 629 * 630 * "Call" register usage: 631 * a0 This value, OPTEE_SMC_RETURN_RPC_FREE 632 * a1 Upper 32 bits of 64-bit shared memory cookie belonging to this 633 * argument memory 634 * a2 Lower 32 bits of 64-bit shared memory cookie belonging to this 635 * argument memory 636 * a3-7 Resume information, must be preserved 637 * 638 * "Return" register usage: 639 * a0 SMC Function ID, OPTEE_SMC_CALL_RETURN_FROM_RPC. 640 * a1-2 Not used 641 * a3-7 Preserved 642 */ 643 #define OPTEE_SMC_RPC_FUNC_FREE U(2) 644 #define OPTEE_SMC_RETURN_RPC_FREE \ 645 OPTEE_SMC_RPC_VAL(OPTEE_SMC_RPC_FUNC_FREE) 646 647 /* 648 * Deliver a foreign interrupt in normal world. 649 * 650 * "Call" register usage: 651 * a0 OPTEE_SMC_RETURN_RPC_FOREIGN_INTR 652 * a1-7 Resume information, must be preserved 653 * 654 * "Return" register usage: 655 * a0 SMC Function ID, OPTEE_SMC_CALL_RETURN_FROM_RPC. 656 * a1-7 Preserved 657 */ 658 #define OPTEE_SMC_RPC_FUNC_FOREIGN_INTR U(4) 659 #define OPTEE_SMC_RETURN_RPC_FOREIGN_INTR \ 660 OPTEE_SMC_RPC_VAL(OPTEE_SMC_RPC_FUNC_FOREIGN_INTR) 661 662 /* 663 * Do an RPC request. The supplied struct optee_msg_arg tells which 664 * request to do and the parameters for the request. The following fields 665 * are used (the rest are unused): 666 * - cmd the Request ID 667 * - ret return value of the request, filled in by normal world 668 * - num_params number of parameters for the request 669 * - params the parameters 670 * - param_attrs attributes of the parameters 671 * 672 * "Call" register usage: 673 * a0 OPTEE_SMC_RETURN_RPC_CMD 674 * a1 Upper 32 bits of a 64-bit Shared memory cookie holding a 675 * struct optee_msg_arg, must be preserved, only the data should 676 * be updated 677 * a2 Lower 32 bits of a 64-bit Shared memory cookie holding a 678 * struct optee_msg_arg, must be preserved, only the data should 679 * be updated 680 * a3-7 Resume information, must be preserved 681 * 682 * "Return" register usage: 683 * a0 SMC Function ID, OPTEE_SMC_CALL_RETURN_FROM_RPC. 684 * a1-2 Not used 685 * a3-7 Preserved 686 */ 687 #define OPTEE_SMC_RPC_FUNC_CMD U(5) 688 #define OPTEE_SMC_RETURN_RPC_CMD \ 689 OPTEE_SMC_RPC_VAL(OPTEE_SMC_RPC_FUNC_CMD) 690 691 /* Returned in a0 */ 692 #define OPTEE_SMC_RETURN_UNKNOWN_FUNCTION U(0xFFFFFFFF) 693 694 /* Returned in a0 only from Trusted OS functions */ 695 #define OPTEE_SMC_RETURN_OK U(0x0) 696 #define OPTEE_SMC_RETURN_ETHREAD_LIMIT U(0x1) 697 #define OPTEE_SMC_RETURN_EBUSY U(0x2) 698 #define OPTEE_SMC_RETURN_ERESUME U(0x3) 699 #define OPTEE_SMC_RETURN_EBADADDR U(0x4) 700 #define OPTEE_SMC_RETURN_EBADCMD U(0x5) 701 #define OPTEE_SMC_RETURN_ENOMEM U(0x6) 702 #define OPTEE_SMC_RETURN_ENOTAVAIL U(0x7) 703 #define OPTEE_SMC_RETURN_IS_RPC(ret) \ 704 (((ret) != OPTEE_SMC_RETURN_UNKNOWN_FUNCTION) && \ 705 ((((ret) & OPTEE_SMC_RETURN_RPC_PREFIX_MASK) == \ 706 OPTEE_SMC_RETURN_RPC_PREFIX))) 707 708 #endif /* OPTEE_SMC_H */ 709