1 /* SPDX-License-Identifier: BSD-2-Clause */ 2 /* 3 * Copyright (c) 2015-2021, Linaro Limited 4 */ 5 #ifndef __SM_OPTEE_SMC_H 6 #define __SM_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 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 * a4-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 /* Secure world supports probing for RPMB device if needed */ 320 #define OPTEE_SMC_SEC_CAP_RPMB_PROBE BIT(7) 321 /* Secure world supports protected memory */ 322 #define OPTEE_SMC_SEC_CAP_PROTMEM BIT(8) 323 /* Secure world supports dynamic protected memory */ 324 #define OPTEE_SMC_SEC_CAP_DYNAMIC_PROTMEM BIT(9) 325 326 #define OPTEE_SMC_FUNCID_EXCHANGE_CAPABILITIES U(9) 327 #define OPTEE_SMC_EXCHANGE_CAPABILITIES \ 328 OPTEE_SMC_FAST_CALL_VAL(OPTEE_SMC_FUNCID_EXCHANGE_CAPABILITIES) 329 330 /* 331 * Disable and empties cache of shared memory objects 332 * 333 * Secure world can cache frequently used shared memory objects, for 334 * example objects used as RPC arguments. When secure world is idle this 335 * function returns one shared memory reference to free. To disable the 336 * cache and free all cached objects this function has to be called until 337 * it returns OPTEE_SMC_RETURN_ENOTAVAIL. 338 * 339 * Call register usage: 340 * a0 SMC Function ID, OPTEE_SMC_DISABLE_SHM_CACHE 341 * a1-6 Not used 342 * a7 Hypervisor Client ID register 343 * 344 * Normal return register usage: 345 * a0 OPTEE_SMC_RETURN_OK 346 * a1 Upper 32 bits of a 64-bit Shared memory cookie 347 * a2 Lower 32 bits of a 64-bit Shared memory cookie 348 * a3-7 Preserved 349 * 350 * Cache empty return register usage: 351 * a0 OPTEE_SMC_RETURN_ENOTAVAIL 352 * a1-7 Preserved 353 * 354 * Not idle return register usage: 355 * a0 OPTEE_SMC_RETURN_EBUSY 356 * a1-7 Preserved 357 */ 358 #define OPTEE_SMC_FUNCID_DISABLE_SHM_CACHE U(10) 359 #define OPTEE_SMC_DISABLE_SHM_CACHE \ 360 OPTEE_SMC_FAST_CALL_VAL(OPTEE_SMC_FUNCID_DISABLE_SHM_CACHE) 361 362 /* 363 * Enable cache of shared memory objects 364 * 365 * Secure world can cache frequently used shared memory objects, for 366 * example objects used as RPC arguments. When secure world is idle this 367 * function returns OPTEE_SMC_RETURN_OK and the cache is enabled. If 368 * secure world isn't idle OPTEE_SMC_RETURN_EBUSY is returned. 369 * 370 * Call register usage: 371 * a0 SMC Function ID, OPTEE_SMC_ENABLE_SHM_CACHE 372 * a1-6 Not used 373 * a7 Hypervisor Client ID register 374 * 375 * Normal return register usage: 376 * a0 OPTEE_SMC_RETURN_OK 377 * a1-7 Preserved 378 * 379 * Not idle return register usage: 380 * a0 OPTEE_SMC_RETURN_EBUSY 381 * a1-7 Preserved 382 */ 383 #define OPTEE_SMC_FUNCID_ENABLE_SHM_CACHE U(11) 384 #define OPTEE_SMC_ENABLE_SHM_CACHE \ 385 OPTEE_SMC_FAST_CALL_VAL(OPTEE_SMC_FUNCID_ENABLE_SHM_CACHE) 386 387 /* 388 * Release of secondary cores 389 * 390 * OP-TEE in secure world is in charge of the release process of secondary 391 * cores. The Rich OS issue the this request to ask OP-TEE to boot up the 392 * secondary cores, go through the OP-TEE per-core initialization, and then 393 * switch to the Non-seCure world with the Rich OS provided entry address. 394 * The secondary cores enter Non-Secure world in SVC mode, with Thumb, FIQ, 395 * IRQ and Abort bits disabled. 396 * 397 * Call register usage: 398 * a0 SMC Function ID, OPTEE_SMC_BOOT_SECONDARY 399 * a1 Index of secondary core to boot 400 * a2 Upper 32 bits of a 64-bit Non-Secure world entry physical address 401 * a3 Lower 32 bits of a 64-bit Non-Secure world entry physical address 402 * a4-7 Not used 403 * 404 * Normal return register usage: 405 * a0 OPTEE_SMC_RETURN_OK 406 * a1-7 Preserved 407 * 408 * Error return: 409 * a0 OPTEE_SMC_RETURN_EBADCMD Core index out of range 410 * a1-7 Preserved 411 * 412 * Not idle return register usage: 413 * a0 OPTEE_SMC_RETURN_EBUSY 414 * a1-7 Preserved 415 */ 416 #define OPTEE_SMC_FUNCID_BOOT_SECONDARY U(12) 417 #define OPTEE_SMC_BOOT_SECONDARY \ 418 OPTEE_SMC_FAST_CALL_VAL(OPTEE_SMC_FUNCID_BOOT_SECONDARY) 419 420 /* 421 * Inform OP-TEE about a new virtual machine 422 * 423 * Hypervisor issues this call during virtual machine (guest) creation. 424 * OP-TEE records client id of new virtual machine and prepares 425 * to receive requests from it. This call is available only if OP-TEE 426 * was built with virtualization support. 427 * 428 * Call requests usage: 429 * a0 SMC Function ID, OPTEE_SMC_VM_CREATED 430 * a1 Hypervisor Client ID of newly created virtual machine 431 * a2-6 Not used 432 * a7 Hypervisor Client ID register. Must be 0, because only hypervisor 433 * can issue this call 434 * 435 * Normal return register usage: 436 * a0 OPTEE_SMC_RETURN_OK 437 * a1-7 Preserved 438 * 439 * Error return: 440 * a0 OPTEE_SMC_RETURN_ENOTAVAIL OP-TEE have no resources for 441 * another VM 442 * a1-7 Preserved 443 * 444 */ 445 #define OPTEE_SMC_FUNCID_VM_CREATED U(13) 446 #define OPTEE_SMC_VM_CREATED \ 447 OPTEE_SMC_FAST_CALL_VAL(OPTEE_SMC_FUNCID_VM_CREATED) 448 449 /* 450 * Inform OP-TEE about shutdown of a virtual machine 451 * 452 * Hypervisor issues this call during virtual machine (guest) destruction. 453 * OP-TEE will clean up all resources associated with this VM. This call is 454 * available only if OP-TEE was built with virtualization support. 455 * 456 * Call requests usage: 457 * a0 SMC Function ID, OPTEE_SMC_VM_DESTROYED 458 * a1 Hypervisor Client ID of virtual machine being shut down 459 * a2-6 Not used 460 * a7 Hypervisor Client ID register. Must be 0, because only hypervisor 461 * can issue this call 462 * 463 * Normal return register usage: 464 * a0 OPTEE_SMC_RETURN_OK 465 * a1-7 Preserved 466 * 467 */ 468 #define OPTEE_SMC_FUNCID_VM_DESTROYED U(14) 469 #define OPTEE_SMC_VM_DESTROYED \ 470 OPTEE_SMC_FAST_CALL_VAL(OPTEE_SMC_FUNCID_VM_DESTROYED) 471 472 /* 473 * Query OP-TEE about number of supported threads 474 * 475 * Normal World OS or Hypervisor issues this call to find out how many 476 * threads OP-TEE supports. That is how many standard calls can be issued 477 * in parallel before OP-TEE will return OPTEE_SMC_RETURN_ETHREAD_LIMIT. 478 * 479 * Call requests usage: 480 * a0 SMC Function ID, OPTEE_SMC_GET_THREAD_COUNT 481 * a1-6 Not used 482 * a7 Hypervisor Client ID register 483 * 484 * Normal return register usage: 485 * a0 OPTEE_SMC_RETURN_OK 486 * a1 Number of threads 487 * a2-7 Preserved 488 * 489 * Error return: 490 * a0 OPTEE_SMC_RETURN_UNKNOWN_FUNCTION Requested call is not implemented 491 * a1-7 Preserved 492 */ 493 #define OPTEE_SMC_FUNCID_GET_THREAD_COUNT U(15) 494 #define OPTEE_SMC_GET_THREAD_COUNT \ 495 OPTEE_SMC_FAST_CALL_VAL(OPTEE_SMC_FUNCID_GET_THREAD_COUNT) 496 497 /* 498 * Inform OP-TEE that normal world is able to receive asynchronous 499 * notifications. 500 * 501 * Call requests usage: 502 * a0 SMC Function ID, OPTEE_SMC_ENABLE_ASYNC_NOTIF 503 * a1-6 Not used 504 * a7 Hypervisor Client ID register 505 * 506 * Normal return register usage: 507 * a0 OPTEE_SMC_RETURN_OK 508 * a1-7 Preserved 509 * 510 * Not supported return register usage: 511 * a0 OPTEE_SMC_RETURN_ENOTAVAIL 512 * a1-7 Preserved 513 */ 514 #define OPTEE_SMC_FUNCID_ENABLE_ASYNC_NOTIF 16 515 #define OPTEE_SMC_ENABLE_ASYNC_NOTIF \ 516 OPTEE_SMC_FAST_CALL_VAL(OPTEE_SMC_FUNCID_ENABLE_ASYNC_NOTIF) 517 518 /* 519 * Retrieve a value of notifications pending since the last call of this 520 * function. 521 * 522 * OP-TEE keeps a record of all posted values. When an interrupt is 523 * received which indicates that there are posted values this function 524 * should be called until all pended values have been retrieved. When a 525 * value is retrieved, it's cleared from the record in secure world. 526 * 527 * It is expected that this function is called from an interrupt handler 528 * in normal world. 529 * 530 * Call requests usage: 531 * a0 SMC Function ID, OPTEE_SMC_GET_ASYNC_NOTIF_VALUE 532 * a1-6 Not used 533 * a7 Hypervisor Client ID register 534 * 535 * Normal return register usage: 536 * a0 OPTEE_SMC_RETURN_OK 537 * a1 value 538 * a2 Bit[0]: OPTEE_SMC_ASYNC_NOTIF_VALUE_VALID if the value in a1 is 539 * valid, else 0 if no values where pending 540 * a2 Bit[1]: OPTEE_SMC_ASYNC_NOTIF_VALUE_PENDING if another value is 541 * pending, else 0. 542 * Bit[31:2]: MBZ 543 * a3-7 Preserved 544 * 545 * Not supported return register usage: 546 * a0 OPTEE_SMC_RETURN_ENOTAVAIL 547 * a1-7 Preserved 548 */ 549 #define OPTEE_SMC_ASYNC_NOTIF_VALID BIT(0) 550 #define OPTEE_SMC_ASYNC_NOTIF_PENDING BIT(1) 551 552 /* 553 * Notification that OP-TEE expects a yielding call to do some bottom half 554 * work in a driver. 555 */ 556 #define OPTEE_SMC_ASYNC_NOTIF_VALUE_DO_BOTTOM_HALF 0 557 558 #define OPTEE_SMC_FUNCID_GET_ASYNC_NOTIF_VALUE 17 559 #define OPTEE_SMC_GET_ASYNC_NOTIF_VALUE \ 560 OPTEE_SMC_FAST_CALL_VAL(OPTEE_SMC_FUNCID_GET_ASYNC_NOTIF_VALUE) 561 562 /* See OPTEE_SMC_CALL_WITH_RPC_ARG above */ 563 #define OPTEE_SMC_FUNCID_CALL_WITH_RPC_ARG U(18) 564 565 /* See OPTEE_SMC_CALL_WITH_REGD_ARG above */ 566 #define OPTEE_SMC_FUNCID_CALL_WITH_REGD_ARG U(19) 567 568 /* 569 * Get protected memory config 570 * 571 * Returns the protected memory config. 572 * 573 * Call register usage: 574 * a0 SMC Function ID, OPTEE_SMC_GET_PROTMEM_CONFIG 575 * a2-6 Not used, must be zero 576 * a7 Hypervisor Client ID register 577 * 578 * Have config return register usage: 579 * a0 OPTEE_SMC_RETURN_OK 580 * a1 Physical address of start of protected memory 581 * a2 Size of protected memory 582 * a3 PA width, max 64 583 * a4-7 Preserved 584 * 585 * Not available register usage: 586 * a0 OPTEE_SMC_RETURN_ENOTAVAIL 587 * a1-3 Not used 588 * a4-7 Preserved 589 */ 590 #define OPTEE_SMC_FUNCID_GET_PROTMEM_CONFIG U(20) 591 #define OPTEE_SMC_GET_PROTMEM_CONFIG \ 592 OPTEE_SMC_FAST_CALL_VAL(OPTEE_SMC_FUNCID_GET_PROTMEM_CONFIG) 593 594 /* 595 * Resume from RPC (for example after processing a foreign interrupt) 596 * 597 * Call register usage: 598 * a0 SMC Function ID, OPTEE_SMC_CALL_RETURN_FROM_RPC 599 * a1-3 Value of a1-3 when OPTEE_SMC_CALL_WITH_ARG returned 600 * OPTEE_SMC_RETURN_RPC in a0 601 * 602 * Return register usage is the same as for OPTEE_SMC_*CALL_WITH_ARG above. 603 * 604 * Possible return values 605 * OPTEE_SMC_RETURN_UNKNOWN_FUNCTION Trusted OS does not recognize this 606 * function. 607 * OPTEE_SMC_RETURN_OK Original call completed, result 608 * updated in the previously supplied. 609 * struct optee_msg_arg 610 * OPTEE_SMC_RETURN_RPC Call suspended by RPC call to normal 611 * world. 612 * OPTEE_SMC_RETURN_ERESUME Resume failed, the opaque resume 613 * information was corrupt. 614 */ 615 #define OPTEE_SMC_FUNCID_RETURN_FROM_RPC U(3) 616 #define OPTEE_SMC_CALL_RETURN_FROM_RPC \ 617 OPTEE_SMC_STD_CALL_VAL(OPTEE_SMC_FUNCID_RETURN_FROM_RPC) 618 619 #define OPTEE_SMC_RETURN_RPC_PREFIX_MASK U(0xFFFF0000) 620 #define OPTEE_SMC_RETURN_RPC_PREFIX U(0xFFFF0000) 621 #define OPTEE_SMC_RETURN_RPC_FUNC_MASK U(0x0000FFFF) 622 623 #define OPTEE_SMC_RETURN_GET_RPC_FUNC(ret) \ 624 ((ret) & OPTEE_SMC_RETURN_RPC_FUNC_MASK) 625 626 #define OPTEE_SMC_RPC_VAL(func) ((func) | OPTEE_SMC_RETURN_RPC_PREFIX) 627 628 /* 629 * Allocate memory for RPC parameter passing. The memory is used to hold a 630 * struct optee_msg_arg. 631 * 632 * "Call" register usage: 633 * a0 This value, OPTEE_SMC_RETURN_RPC_ALLOC 634 * a1 Size in bytes of required argument memory 635 * a2 Not used 636 * a3 Resume information, must be preserved 637 * a4-5 Not used 638 * a6-7 Resume information, must be preserved 639 * 640 * "Return" register usage: 641 * a0 SMC Function ID, OPTEE_SMC_CALL_RETURN_FROM_RPC. 642 * a1 Upper 32 bits of 64-bit physical pointer to allocated 643 * memory, (a1 == 0 && a2 == 0) if size was 0 or if memory can't 644 * be allocated. 645 * a2 Lower 32 bits of 64-bit physical pointer to allocated 646 * memory, (a1 == 0 && a2 == 0) if size was 0 or if memory can't 647 * be allocated 648 * a3 Preserved 649 * a4 Upper 32 bits of 64-bit Shared memory cookie used when freeing 650 * the memory or doing an RPC 651 * a5 Lower 32 bits of 64-bit Shared memory cookie used when freeing 652 * the memory or doing an RPC 653 * a6-7 Preserved 654 */ 655 #define OPTEE_SMC_RPC_FUNC_ALLOC U(0) 656 #define OPTEE_SMC_RETURN_RPC_ALLOC \ 657 OPTEE_SMC_RPC_VAL(OPTEE_SMC_RPC_FUNC_ALLOC) 658 659 /* 660 * Free memory previously allocated by OPTEE_SMC_RETURN_RPC_ALLOC 661 * 662 * "Call" register usage: 663 * a0 This value, OPTEE_SMC_RETURN_RPC_FREE 664 * a1 Upper 32 bits of 64-bit shared memory cookie belonging to this 665 * argument memory 666 * a2 Lower 32 bits of 64-bit shared memory cookie belonging to this 667 * argument memory 668 * a3-7 Resume information, must be preserved 669 * 670 * "Return" register usage: 671 * a0 SMC Function ID, OPTEE_SMC_CALL_RETURN_FROM_RPC. 672 * a1-2 Not used 673 * a3-7 Preserved 674 */ 675 #define OPTEE_SMC_RPC_FUNC_FREE U(2) 676 #define OPTEE_SMC_RETURN_RPC_FREE \ 677 OPTEE_SMC_RPC_VAL(OPTEE_SMC_RPC_FUNC_FREE) 678 679 /* 680 * Deliver a foreign interrupt in normal world. 681 * 682 * "Call" register usage: 683 * a0 OPTEE_SMC_RETURN_RPC_FOREIGN_INTR 684 * a1-7 Resume information, must be preserved 685 * 686 * "Return" register usage: 687 * a0 SMC Function ID, OPTEE_SMC_CALL_RETURN_FROM_RPC. 688 * a1-7 Preserved 689 */ 690 #define OPTEE_SMC_RPC_FUNC_FOREIGN_INTR U(4) 691 #define OPTEE_SMC_RETURN_RPC_FOREIGN_INTR \ 692 OPTEE_SMC_RPC_VAL(OPTEE_SMC_RPC_FUNC_FOREIGN_INTR) 693 694 /* 695 * Do an RPC request. The supplied struct optee_msg_arg tells which 696 * request to do and the parameters for the request. The following fields 697 * are used (the rest are unused): 698 * - cmd the Request ID 699 * - ret return value of the request, filled in by normal world 700 * - num_params number of parameters for the request 701 * - params the parameters 702 * - param_attrs attributes of the parameters 703 * 704 * "Call" register usage: 705 * a0 OPTEE_SMC_RETURN_RPC_CMD 706 * a1 Upper 32 bits of a 64-bit Shared memory cookie holding a 707 * struct optee_msg_arg, must be preserved, only the data should 708 * be updated 709 * a2 Lower 32 bits of a 64-bit Shared memory cookie holding a 710 * struct optee_msg_arg, must be preserved, only the data should 711 * be updated 712 * a3-7 Resume information, must be preserved 713 * 714 * "Return" register usage: 715 * a0 SMC Function ID, OPTEE_SMC_CALL_RETURN_FROM_RPC. 716 * a1-2 Not used 717 * a3-7 Preserved 718 */ 719 #define OPTEE_SMC_RPC_FUNC_CMD U(5) 720 #define OPTEE_SMC_RETURN_RPC_CMD \ 721 OPTEE_SMC_RPC_VAL(OPTEE_SMC_RPC_FUNC_CMD) 722 723 /* Returned in a0 */ 724 #define OPTEE_SMC_RETURN_UNKNOWN_FUNCTION U(0xFFFFFFFF) 725 726 /* Returned in a0 only from Trusted OS functions */ 727 #define OPTEE_SMC_RETURN_OK U(0x0) 728 #define OPTEE_SMC_RETURN_ETHREAD_LIMIT U(0x1) 729 #define OPTEE_SMC_RETURN_EBUSY U(0x2) 730 #define OPTEE_SMC_RETURN_ERESUME U(0x3) 731 #define OPTEE_SMC_RETURN_EBADADDR U(0x4) 732 #define OPTEE_SMC_RETURN_EBADCMD U(0x5) 733 #define OPTEE_SMC_RETURN_ENOMEM U(0x6) 734 #define OPTEE_SMC_RETURN_ENOTAVAIL U(0x7) 735 #define OPTEE_SMC_RETURN_IS_RPC(ret) \ 736 (((ret) != OPTEE_SMC_RETURN_UNKNOWN_FUNCTION) && \ 737 ((((ret) & OPTEE_SMC_RETURN_RPC_PREFIX_MASK) == \ 738 OPTEE_SMC_RETURN_RPC_PREFIX))) 739 740 #endif /* __SM_OPTEE_SMC_H */ 741