1 /* SPDX-License-Identifier: (GPL-2.0 OR 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 <linux/arm-smccc.h> 9 #include <linux/bitops.h> 10 11 #define OPTEE_SMC_STD_CALL_VAL(func_num) \ 12 ARM_SMCCC_CALL_VAL(ARM_SMCCC_STD_CALL, ARM_SMCCC_SMC_32, \ 13 ARM_SMCCC_OWNER_TRUSTED_OS, (func_num)) 14 #define OPTEE_SMC_FAST_CALL_VAL(func_num) \ 15 ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL, ARM_SMCCC_SMC_32, \ 16 ARM_SMCCC_OWNER_TRUSTED_OS, (func_num)) 17 18 /* 19 * Function specified by SMC Calling convention. 20 */ 21 #define OPTEE_SMC_FUNCID_CALLS_COUNT 0xFF00 22 #define OPTEE_SMC_CALLS_COUNT \ 23 ARM_SMCCC_CALL_VAL(OPTEE_SMC_FAST_CALL, SMCCC_SMC_32, \ 24 SMCCC_OWNER_TRUSTED_OS_END, \ 25 OPTEE_SMC_FUNCID_CALLS_COUNT) 26 27 /* 28 * Normal cached memory (write-back), shareable for SMP systems and not 29 * shareable for UP systems. 30 */ 31 #define OPTEE_SMC_SHM_CACHED 1 32 33 /* 34 * a0..a7 is used as register names in the descriptions below, on arm32 35 * that translates to r0..r7 and on arm64 to w0..w7. In both cases it's 36 * 32-bit registers. 37 */ 38 39 /* 40 * Function specified by SMC Calling convention 41 * 42 * Return the following UID if using API specified in this file 43 * without further extensions: 44 * 384fb3e0-e7f8-11e3-af63-0002a5d5c51b. 45 * see also OPTEE_MSG_UID_* in optee_msg.h 46 */ 47 #define OPTEE_SMC_FUNCID_CALLS_UID OPTEE_MSG_FUNCID_CALLS_UID 48 #define OPTEE_SMC_CALLS_UID \ 49 ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL, ARM_SMCCC_SMC_32, \ 50 ARM_SMCCC_OWNER_TRUSTED_OS_END, \ 51 OPTEE_SMC_FUNCID_CALLS_UID) 52 53 /* 54 * Function specified by SMC Calling convention 55 * 56 * Returns 2.0 if using API specified in this file without further extensions. 57 * see also OPTEE_MSG_REVISION_* in optee_msg.h 58 */ 59 #define OPTEE_SMC_FUNCID_CALLS_REVISION OPTEE_MSG_FUNCID_CALLS_REVISION 60 #define OPTEE_SMC_CALLS_REVISION \ 61 ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL, ARM_SMCCC_SMC_32, \ 62 ARM_SMCCC_OWNER_TRUSTED_OS_END, \ 63 OPTEE_SMC_FUNCID_CALLS_REVISION) 64 65 struct optee_smc_calls_revision_result { 66 unsigned long major; 67 unsigned long minor; 68 unsigned long reserved0; 69 unsigned long reserved1; 70 }; 71 72 /* 73 * Get UUID of Trusted OS. 74 * 75 * Used by non-secure world to figure out which Trusted OS is installed. 76 * Note that returned UUID is the UUID of the Trusted OS, not of the API. 77 * 78 * Returns UUID in a0-4 in the same way as OPTEE_SMC_CALLS_UID 79 * described above. 80 */ 81 #define OPTEE_SMC_FUNCID_GET_OS_UUID OPTEE_MSG_FUNCID_GET_OS_UUID 82 #define OPTEE_SMC_CALL_GET_OS_UUID \ 83 OPTEE_SMC_FAST_CALL_VAL(OPTEE_SMC_FUNCID_GET_OS_UUID) 84 85 /* 86 * Get revision of Trusted OS. 87 * 88 * Used by non-secure world to figure out which version of the Trusted OS 89 * is installed. Note that the returned revision is the revision of the 90 * Trusted OS, not of the API. 91 * 92 * Returns revision in a0-1 in the same way as OPTEE_SMC_CALLS_REVISION 93 * described above. May optionally return a 32-bit build identifier in a2, 94 * with zero meaning unspecified. 95 */ 96 #define OPTEE_SMC_FUNCID_GET_OS_REVISION OPTEE_MSG_FUNCID_GET_OS_REVISION 97 #define OPTEE_SMC_CALL_GET_OS_REVISION \ 98 OPTEE_SMC_FAST_CALL_VAL(OPTEE_SMC_FUNCID_GET_OS_REVISION) 99 100 struct optee_smc_call_get_os_revision_result { 101 unsigned long major; 102 unsigned long minor; 103 unsigned long build_id; 104 unsigned long reserved1; 105 }; 106 107 /* 108 * Load Trusted OS from optee/tee.bin in the Linux firmware. 109 * 110 * WARNING: Use this cautiously as it could lead to insecure loading of the 111 * Trusted OS. 112 * This SMC instructs EL3 to load a binary and execute it as the Trusted OS. 113 * 114 * Call register usage: 115 * a0 SMC Function ID, OPTEE_SMC_CALL_LOAD_IMAGE 116 * a1 Upper 32bit of a 64bit size for the payload 117 * a2 Lower 32bit of a 64bit size for the payload 118 * a3 Upper 32bit of the physical address for the payload 119 * a4 Lower 32bit of the physical address for the payload 120 * 121 * The payload is in the OP-TEE image format. 122 * 123 * Returns result in a0, 0 on success and an error code otherwise. 124 */ 125 #define OPTEE_SMC_FUNCID_LOAD_IMAGE 2 126 #define OPTEE_SMC_CALL_LOAD_IMAGE \ 127 ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL, ARM_SMCCC_SMC_32, \ 128 ARM_SMCCC_OWNER_TRUSTED_OS_END, \ 129 OPTEE_SMC_FUNCID_LOAD_IMAGE) 130 131 /* 132 * Call with struct optee_msg_arg as argument 133 * 134 * When called with OPTEE_SMC_CALL_WITH_RPC_ARG or 135 * OPTEE_SMC_CALL_WITH_REGD_ARG in a0 there is one RPC struct optee_msg_arg 136 * following after the first struct optee_msg_arg. The RPC struct 137 * optee_msg_arg has reserved space for the number of RPC parameters as 138 * returned by OPTEE_SMC_EXCHANGE_CAPABILITIES. 139 * 140 * When calling these functions, normal world has a few responsibilities: 141 * 1. It must be able to handle eventual RPCs 142 * 2. Non-secure interrupts should not be masked 143 * 3. If asynchronous notifications has been negotiated successfully, then 144 * the interrupt for asynchronous notifications should be unmasked 145 * during this call. 146 * 147 * Call register usage, OPTEE_SMC_CALL_WITH_ARG and 148 * OPTEE_SMC_CALL_WITH_RPC_ARG: 149 * a0 SMC Function ID, OPTEE_SMC_CALL_WITH_ARG or OPTEE_SMC_CALL_WITH_RPC_ARG 150 * a1 Upper 32 bits of a 64-bit physical pointer to a struct optee_msg_arg 151 * a2 Lower 32 bits of a 64-bit physical pointer to a struct optee_msg_arg 152 * a3 Cache settings, not used if physical pointer is in a predefined shared 153 * memory area else per OPTEE_SMC_SHM_* 154 * a4-6 Not used 155 * a7 Hypervisor Client ID register 156 * 157 * Call register usage, OPTEE_SMC_CALL_WITH_REGD_ARG: 158 * a0 SMC Function ID, OPTEE_SMC_CALL_WITH_REGD_ARG 159 * a1 Upper 32 bits of a 64-bit shared memory cookie 160 * a2 Lower 32 bits of a 64-bit shared memory cookie 161 * a3 Offset of the struct optee_msg_arg in the shared memory with the 162 * supplied cookie 163 * a4-6 Not used 164 * a7 Hypervisor Client ID register 165 * 166 * Normal return register usage: 167 * a0 Return value, OPTEE_SMC_RETURN_* 168 * a1-3 Not used 169 * a4-7 Preserved 170 * 171 * OPTEE_SMC_RETURN_ETHREAD_LIMIT return register usage: 172 * a0 Return value, OPTEE_SMC_RETURN_ETHREAD_LIMIT 173 * a1-3 Preserved 174 * a4-7 Preserved 175 * 176 * RPC return register usage: 177 * a0 Return value, OPTEE_SMC_RETURN_IS_RPC(val) 178 * a1-2 RPC parameters 179 * a3-7 Resume information, must be preserved 180 * 181 * Possible return values: 182 * OPTEE_SMC_RETURN_UNKNOWN_FUNCTION Trusted OS does not recognize this 183 * function. 184 * OPTEE_SMC_RETURN_OK Call completed, result updated in 185 * the previously supplied struct 186 * optee_msg_arg. 187 * OPTEE_SMC_RETURN_ETHREAD_LIMIT Number of Trusted OS threads exceeded, 188 * try again later. 189 * OPTEE_SMC_RETURN_EBADADDR Bad physical pointer to struct 190 * optee_msg_arg. 191 * OPTEE_SMC_RETURN_EBADCMD Bad/unknown cmd in struct optee_msg_arg 192 * OPTEE_SMC_RETURN_IS_RPC() Call suspended by RPC call to normal 193 * world. 194 */ 195 #define OPTEE_SMC_FUNCID_CALL_WITH_ARG OPTEE_MSG_FUNCID_CALL_WITH_ARG 196 #define OPTEE_SMC_CALL_WITH_ARG \ 197 OPTEE_SMC_STD_CALL_VAL(OPTEE_SMC_FUNCID_CALL_WITH_ARG) 198 #define OPTEE_SMC_CALL_WITH_RPC_ARG \ 199 OPTEE_SMC_STD_CALL_VAL(OPTEE_SMC_FUNCID_CALL_WITH_RPC_ARG) 200 #define OPTEE_SMC_CALL_WITH_REGD_ARG \ 201 OPTEE_SMC_STD_CALL_VAL(OPTEE_SMC_FUNCID_CALL_WITH_REGD_ARG) 202 203 /* 204 * Get Shared Memory Config 205 * 206 * Returns the Secure/Non-secure shared memory config. 207 * 208 * Call register usage: 209 * a0 SMC Function ID, OPTEE_SMC_GET_SHM_CONFIG 210 * a1-6 Not used 211 * a7 Hypervisor Client ID register 212 * 213 * Have config return register usage: 214 * a0 OPTEE_SMC_RETURN_OK 215 * a1 Physical address of start of SHM 216 * a2 Size of SHM 217 * a3 Cache settings of memory, as defined by the 218 * OPTEE_SMC_SHM_* values above 219 * a4-7 Preserved 220 * 221 * Not available register usage: 222 * a0 OPTEE_SMC_RETURN_ENOTAVAIL 223 * a1-3 Not used 224 * a4-7 Preserved 225 */ 226 #define OPTEE_SMC_FUNCID_GET_SHM_CONFIG 7 227 #define OPTEE_SMC_GET_SHM_CONFIG \ 228 OPTEE_SMC_FAST_CALL_VAL(OPTEE_SMC_FUNCID_GET_SHM_CONFIG) 229 230 struct optee_smc_get_shm_config_result { 231 unsigned long status; 232 unsigned long start; 233 unsigned long size; 234 unsigned long settings; 235 }; 236 237 /* 238 * Exchanges capabilities between normal world and secure world 239 * 240 * Call register usage: 241 * a0 SMC Function ID, OPTEE_SMC_EXCHANGE_CAPABILITIES 242 * a1 bitfield of normal world capabilities OPTEE_SMC_NSEC_CAP_* 243 * a2-6 Not used 244 * a7 Hypervisor Client ID register 245 * 246 * Normal return register usage: 247 * a0 OPTEE_SMC_RETURN_OK 248 * a1 bitfield of secure world capabilities OPTEE_SMC_SEC_CAP_* 249 * a2 The maximum secure world notification number 250 * a3 Bit[7:0]: Number of parameters needed for RPC to be supplied 251 * as the second MSG arg struct for 252 * OPTEE_SMC_CALL_WITH_ARG 253 * Bit[31:8]: Reserved (MBZ) 254 * a4-7 Preserved 255 * 256 * Error return register usage: 257 * a0 OPTEE_SMC_RETURN_ENOTAVAIL, can't use the capabilities from normal world 258 * a1 bitfield of secure world capabilities OPTEE_SMC_SEC_CAP_* 259 * a2-7 Preserved 260 */ 261 /* Normal world works as a uniprocessor system */ 262 #define OPTEE_SMC_NSEC_CAP_UNIPROCESSOR BIT(0) 263 /* Secure world has reserved shared memory for normal world to use */ 264 #define OPTEE_SMC_SEC_CAP_HAVE_RESERVED_SHM BIT(0) 265 /* Secure world can communicate via previously unregistered shared memory */ 266 #define OPTEE_SMC_SEC_CAP_UNREGISTERED_SHM BIT(1) 267 268 /* 269 * Secure world supports commands "register/unregister shared memory", 270 * secure world accepts command buffers located in any parts of non-secure RAM 271 */ 272 #define OPTEE_SMC_SEC_CAP_DYNAMIC_SHM BIT(2) 273 /* Secure world is built with virtualization support */ 274 #define OPTEE_SMC_SEC_CAP_VIRTUALIZATION BIT(3) 275 /* Secure world supports Shared Memory with a NULL reference */ 276 #define OPTEE_SMC_SEC_CAP_MEMREF_NULL BIT(4) 277 /* Secure world supports asynchronous notification of normal world */ 278 #define OPTEE_SMC_SEC_CAP_ASYNC_NOTIF BIT(5) 279 /* Secure world supports pre-allocating RPC arg struct */ 280 #define OPTEE_SMC_SEC_CAP_RPC_ARG BIT(6) 281 /* Secure world supports probing for RPMB device if needed */ 282 #define OPTEE_SMC_SEC_CAP_RPMB_PROBE BIT(7) 283 284 #define OPTEE_SMC_FUNCID_EXCHANGE_CAPABILITIES 9 285 #define OPTEE_SMC_EXCHANGE_CAPABILITIES \ 286 OPTEE_SMC_FAST_CALL_VAL(OPTEE_SMC_FUNCID_EXCHANGE_CAPABILITIES) 287 288 struct optee_smc_exchange_capabilities_result { 289 unsigned long status; 290 unsigned long capabilities; 291 unsigned long max_notif_value; 292 unsigned long data; 293 }; 294 295 /* 296 * Disable and empties cache of shared memory objects 297 * 298 * Secure world can cache frequently used shared memory objects, for 299 * example objects used as RPC arguments. When secure world is idle this 300 * function returns one shared memory reference to free. To disable the 301 * cache and free all cached objects this function has to be called until 302 * it returns OPTEE_SMC_RETURN_ENOTAVAIL. 303 * 304 * Call register usage: 305 * a0 SMC Function ID, OPTEE_SMC_DISABLE_SHM_CACHE 306 * a1-6 Not used 307 * a7 Hypervisor Client ID register 308 * 309 * Normal return register usage: 310 * a0 OPTEE_SMC_RETURN_OK 311 * a1 Upper 32 bits of a 64-bit Shared memory cookie 312 * a2 Lower 32 bits of a 64-bit Shared memory cookie 313 * a3-7 Preserved 314 * 315 * Cache empty return register usage: 316 * a0 OPTEE_SMC_RETURN_ENOTAVAIL 317 * a1-7 Preserved 318 * 319 * Not idle return register usage: 320 * a0 OPTEE_SMC_RETURN_EBUSY 321 * a1-7 Preserved 322 */ 323 #define OPTEE_SMC_FUNCID_DISABLE_SHM_CACHE 10 324 #define OPTEE_SMC_DISABLE_SHM_CACHE \ 325 OPTEE_SMC_FAST_CALL_VAL(OPTEE_SMC_FUNCID_DISABLE_SHM_CACHE) 326 327 struct optee_smc_disable_shm_cache_result { 328 unsigned long status; 329 unsigned long shm_upper32; 330 unsigned long shm_lower32; 331 unsigned long reserved0; 332 }; 333 334 /* 335 * Enable cache of shared memory objects 336 * 337 * Secure world can cache frequently used shared memory objects, for 338 * example objects used as RPC arguments. When secure world is idle this 339 * function returns OPTEE_SMC_RETURN_OK and the cache is enabled. If 340 * secure world isn't idle OPTEE_SMC_RETURN_EBUSY is returned. 341 * 342 * Call register usage: 343 * a0 SMC Function ID, OPTEE_SMC_ENABLE_SHM_CACHE 344 * a1-6 Not used 345 * a7 Hypervisor Client ID register 346 * 347 * Normal return register usage: 348 * a0 OPTEE_SMC_RETURN_OK 349 * a1-7 Preserved 350 * 351 * Not idle return register usage: 352 * a0 OPTEE_SMC_RETURN_EBUSY 353 * a1-7 Preserved 354 */ 355 #define OPTEE_SMC_FUNCID_ENABLE_SHM_CACHE 11 356 #define OPTEE_SMC_ENABLE_SHM_CACHE \ 357 OPTEE_SMC_FAST_CALL_VAL(OPTEE_SMC_FUNCID_ENABLE_SHM_CACHE) 358 359 /* 360 * Query OP-TEE about number of supported threads 361 * 362 * Normal World OS or Hypervisor issues this call to find out how many 363 * threads OP-TEE supports. That is how many standard calls can be issued 364 * in parallel before OP-TEE will return OPTEE_SMC_RETURN_ETHREAD_LIMIT. 365 * 366 * Call requests usage: 367 * a0 SMC Function ID, OPTEE_SMC_GET_THREAD_COUNT 368 * a1-6 Not used 369 * a7 Hypervisor Client ID register 370 * 371 * Normal return register usage: 372 * a0 OPTEE_SMC_RETURN_OK 373 * a1 Number of threads 374 * a2-7 Preserved 375 * 376 * Error return: 377 * a0 OPTEE_SMC_RETURN_UNKNOWN_FUNCTION Requested call is not implemented 378 * a1-7 Preserved 379 */ 380 #define OPTEE_SMC_FUNCID_GET_THREAD_COUNT 15 381 #define OPTEE_SMC_GET_THREAD_COUNT \ 382 OPTEE_SMC_FAST_CALL_VAL(OPTEE_SMC_FUNCID_GET_THREAD_COUNT) 383 384 /* 385 * Inform OP-TEE that normal world is able to receive asynchronous 386 * notifications. 387 * 388 * Call requests usage: 389 * a0 SMC Function ID, OPTEE_SMC_ENABLE_ASYNC_NOTIF 390 * a1-6 Not used 391 * a7 Hypervisor Client ID register 392 * 393 * Normal return register usage: 394 * a0 OPTEE_SMC_RETURN_OK 395 * a1-7 Preserved 396 * 397 * Not supported return register usage: 398 * a0 OPTEE_SMC_RETURN_ENOTAVAIL 399 * a1-7 Preserved 400 */ 401 #define OPTEE_SMC_FUNCID_ENABLE_ASYNC_NOTIF 16 402 #define OPTEE_SMC_ENABLE_ASYNC_NOTIF \ 403 OPTEE_SMC_FAST_CALL_VAL(OPTEE_SMC_FUNCID_ENABLE_ASYNC_NOTIF) 404 405 /* 406 * Retrieve a value of notifications pending since the last call of this 407 * function. 408 * 409 * OP-TEE keeps a record of all posted values. When an interrupt is 410 * received which indicates that there are posted values this function 411 * should be called until all pended values have been retrieved. When a 412 * value is retrieved, it's cleared from the record in secure world. 413 * 414 * It is expected that this function is called from an interrupt handler 415 * in normal world. 416 * 417 * Call requests usage: 418 * a0 SMC Function ID, OPTEE_SMC_GET_ASYNC_NOTIF_VALUE 419 * a1-6 Not used 420 * a7 Hypervisor Client ID register 421 * 422 * Normal return register usage: 423 * a0 OPTEE_SMC_RETURN_OK 424 * a1 value 425 * a2 Bit[0]: OPTEE_SMC_ASYNC_NOTIF_VALUE_VALID if the value in a1 is 426 * valid, else 0 if no values where pending 427 * a2 Bit[1]: OPTEE_SMC_ASYNC_NOTIF_VALUE_PENDING if another value is 428 * pending, else 0. 429 * Bit[31:2]: MBZ 430 * a3-7 Preserved 431 * 432 * Not supported return register usage: 433 * a0 OPTEE_SMC_RETURN_ENOTAVAIL 434 * a1-7 Preserved 435 */ 436 #define OPTEE_SMC_ASYNC_NOTIF_VALUE_VALID BIT(0) 437 #define OPTEE_SMC_ASYNC_NOTIF_VALUE_PENDING BIT(1) 438 439 /* 440 * Notification that OP-TEE expects a yielding call to do some bottom half 441 * work in a driver. 442 */ 443 #define OPTEE_SMC_ASYNC_NOTIF_VALUE_DO_BOTTOM_HALF 0 444 445 #define OPTEE_SMC_FUNCID_GET_ASYNC_NOTIF_VALUE 17 446 #define OPTEE_SMC_GET_ASYNC_NOTIF_VALUE \ 447 OPTEE_SMC_FAST_CALL_VAL(OPTEE_SMC_FUNCID_GET_ASYNC_NOTIF_VALUE) 448 449 /* See OPTEE_SMC_CALL_WITH_RPC_ARG above */ 450 #define OPTEE_SMC_FUNCID_CALL_WITH_RPC_ARG 18 451 452 /* See OPTEE_SMC_CALL_WITH_REGD_ARG above */ 453 #define OPTEE_SMC_FUNCID_CALL_WITH_REGD_ARG 19 454 455 /* 456 * Resume from RPC (for example after processing a foreign interrupt) 457 * 458 * Call register usage: 459 * a0 SMC Function ID, OPTEE_SMC_CALL_RETURN_FROM_RPC 460 * a1-3 Value of a1-3 when OPTEE_SMC_CALL_WITH_ARG returned 461 * OPTEE_SMC_RETURN_RPC in a0 462 * 463 * Return register usage is the same as for OPTEE_SMC_*CALL_WITH_ARG above. 464 * 465 * Possible return values 466 * OPTEE_SMC_RETURN_UNKNOWN_FUNCTION Trusted OS does not recognize this 467 * function. 468 * OPTEE_SMC_RETURN_OK Original call completed, result 469 * updated in the previously supplied. 470 * struct optee_msg_arg 471 * OPTEE_SMC_RETURN_RPC Call suspended by RPC call to normal 472 * world. 473 * OPTEE_SMC_RETURN_ERESUME Resume failed, the opaque resume 474 * information was corrupt. 475 */ 476 #define OPTEE_SMC_FUNCID_RETURN_FROM_RPC 3 477 #define OPTEE_SMC_CALL_RETURN_FROM_RPC \ 478 OPTEE_SMC_STD_CALL_VAL(OPTEE_SMC_FUNCID_RETURN_FROM_RPC) 479 480 #define OPTEE_SMC_RETURN_RPC_PREFIX_MASK 0xFFFF0000 481 #define OPTEE_SMC_RETURN_RPC_PREFIX 0xFFFF0000 482 #define OPTEE_SMC_RETURN_RPC_FUNC_MASK 0x0000FFFF 483 484 #define OPTEE_SMC_RETURN_GET_RPC_FUNC(ret) \ 485 ((ret) & OPTEE_SMC_RETURN_RPC_FUNC_MASK) 486 487 #define OPTEE_SMC_RPC_VAL(func) ((func) | OPTEE_SMC_RETURN_RPC_PREFIX) 488 489 /* 490 * Allocate memory for RPC parameter passing. The memory is used to hold a 491 * struct optee_msg_arg. 492 * 493 * "Call" register usage: 494 * a0 This value, OPTEE_SMC_RETURN_RPC_ALLOC 495 * a1 Size in bytes of required argument memory 496 * a2 Not used 497 * a3 Resume information, must be preserved 498 * a4-5 Not used 499 * a6-7 Resume information, must be preserved 500 * 501 * "Return" register usage: 502 * a0 SMC Function ID, OPTEE_SMC_CALL_RETURN_FROM_RPC. 503 * a1 Upper 32 bits of 64-bit physical pointer to allocated 504 * memory, (a1 == 0 && a2 == 0) if size was 0 or if memory can't 505 * be allocated. 506 * a2 Lower 32 bits of 64-bit physical pointer to allocated 507 * memory, (a1 == 0 && a2 == 0) if size was 0 or if memory can't 508 * be allocated 509 * a3 Preserved 510 * a4 Upper 32 bits of 64-bit Shared memory cookie used when freeing 511 * the memory or doing an RPC 512 * a5 Lower 32 bits of 64-bit Shared memory cookie used when freeing 513 * the memory or doing an RPC 514 * a6-7 Preserved 515 */ 516 #define OPTEE_SMC_RPC_FUNC_ALLOC 0 517 #define OPTEE_SMC_RETURN_RPC_ALLOC \ 518 OPTEE_SMC_RPC_VAL(OPTEE_SMC_RPC_FUNC_ALLOC) 519 520 /* 521 * Free memory previously allocated by OPTEE_SMC_RETURN_RPC_ALLOC 522 * 523 * "Call" register usage: 524 * a0 This value, OPTEE_SMC_RETURN_RPC_FREE 525 * a1 Upper 32 bits of 64-bit shared memory cookie belonging to this 526 * argument memory 527 * a2 Lower 32 bits of 64-bit shared memory cookie belonging to this 528 * argument memory 529 * a3-7 Resume information, must be preserved 530 * 531 * "Return" register usage: 532 * a0 SMC Function ID, OPTEE_SMC_CALL_RETURN_FROM_RPC. 533 * a1-2 Not used 534 * a3-7 Preserved 535 */ 536 #define OPTEE_SMC_RPC_FUNC_FREE 2 537 #define OPTEE_SMC_RETURN_RPC_FREE \ 538 OPTEE_SMC_RPC_VAL(OPTEE_SMC_RPC_FUNC_FREE) 539 540 /* 541 * Deliver a foreign interrupt in normal world. 542 * 543 * "Call" register usage: 544 * a0 OPTEE_SMC_RETURN_RPC_FOREIGN_INTR 545 * a1-7 Resume information, must be preserved 546 * 547 * "Return" register usage: 548 * a0 SMC Function ID, OPTEE_SMC_CALL_RETURN_FROM_RPC. 549 * a1-7 Preserved 550 */ 551 #define OPTEE_SMC_RPC_FUNC_FOREIGN_INTR 4 552 #define OPTEE_SMC_RETURN_RPC_FOREIGN_INTR \ 553 OPTEE_SMC_RPC_VAL(OPTEE_SMC_RPC_FUNC_FOREIGN_INTR) 554 555 /* 556 * Do an RPC request. The supplied struct optee_msg_arg tells which 557 * request to do and the parameters for the request. The following fields 558 * are used (the rest are unused): 559 * - cmd the Request ID 560 * - ret return value of the request, filled in by normal world 561 * - num_params number of parameters for the request 562 * - params the parameters 563 * - param_attrs attributes of the parameters 564 * 565 * "Call" register usage: 566 * a0 OPTEE_SMC_RETURN_RPC_CMD 567 * a1 Upper 32 bits of a 64-bit Shared memory cookie holding a 568 * struct optee_msg_arg, must be preserved, only the data should 569 * be updated 570 * a2 Lower 32 bits of a 64-bit Shared memory cookie holding a 571 * struct optee_msg_arg, must be preserved, only the data should 572 * be updated 573 * a3-7 Resume information, must be preserved 574 * 575 * "Return" register usage: 576 * a0 SMC Function ID, OPTEE_SMC_CALL_RETURN_FROM_RPC. 577 * a1-2 Not used 578 * a3-7 Preserved 579 */ 580 #define OPTEE_SMC_RPC_FUNC_CMD 5 581 #define OPTEE_SMC_RETURN_RPC_CMD \ 582 OPTEE_SMC_RPC_VAL(OPTEE_SMC_RPC_FUNC_CMD) 583 584 /* Returned in a0 */ 585 #define OPTEE_SMC_RETURN_UNKNOWN_FUNCTION 0xFFFFFFFF 586 587 /* Returned in a0 only from Trusted OS functions */ 588 #define OPTEE_SMC_RETURN_OK 0x0 589 #define OPTEE_SMC_RETURN_ETHREAD_LIMIT 0x1 590 #define OPTEE_SMC_RETURN_EBUSY 0x2 591 #define OPTEE_SMC_RETURN_ERESUME 0x3 592 #define OPTEE_SMC_RETURN_EBADADDR 0x4 593 #define OPTEE_SMC_RETURN_EBADCMD 0x5 594 #define OPTEE_SMC_RETURN_ENOMEM 0x6 595 #define OPTEE_SMC_RETURN_ENOTAVAIL 0x7 596 #define OPTEE_SMC_RETURN_IS_RPC(ret) __optee_smc_return_is_rpc((ret)) 597 598 static inline bool __optee_smc_return_is_rpc(u32 ret) 599 { 600 return ret != OPTEE_SMC_RETURN_UNKNOWN_FUNCTION && 601 (ret & OPTEE_SMC_RETURN_RPC_PREFIX_MASK) == 602 OPTEE_SMC_RETURN_RPC_PREFIX; 603 } 604 605 #endif /* OPTEE_SMC_H */ 606