Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) */
0002 /*
0003  * Copyright (c) 2015-2021, Linaro Limited
0004  */
0005 #ifndef OPTEE_SMC_H
0006 #define OPTEE_SMC_H
0007 
0008 #include <linux/arm-smccc.h>
0009 #include <linux/bitops.h>
0010 
0011 #define OPTEE_SMC_STD_CALL_VAL(func_num) \
0012     ARM_SMCCC_CALL_VAL(ARM_SMCCC_STD_CALL, ARM_SMCCC_SMC_32, \
0013                ARM_SMCCC_OWNER_TRUSTED_OS, (func_num))
0014 #define OPTEE_SMC_FAST_CALL_VAL(func_num) \
0015     ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL, ARM_SMCCC_SMC_32, \
0016                ARM_SMCCC_OWNER_TRUSTED_OS, (func_num))
0017 
0018 /*
0019  * Function specified by SMC Calling convention.
0020  */
0021 #define OPTEE_SMC_FUNCID_CALLS_COUNT    0xFF00
0022 #define OPTEE_SMC_CALLS_COUNT \
0023     ARM_SMCCC_CALL_VAL(OPTEE_SMC_FAST_CALL, SMCCC_SMC_32, \
0024                SMCCC_OWNER_TRUSTED_OS_END, \
0025                OPTEE_SMC_FUNCID_CALLS_COUNT)
0026 
0027 /*
0028  * Normal cached memory (write-back), shareable for SMP systems and not
0029  * shareable for UP systems.
0030  */
0031 #define OPTEE_SMC_SHM_CACHED        1
0032 
0033 /*
0034  * a0..a7 is used as register names in the descriptions below, on arm32
0035  * that translates to r0..r7 and on arm64 to w0..w7. In both cases it's
0036  * 32-bit registers.
0037  */
0038 
0039 /*
0040  * Function specified by SMC Calling convention
0041  *
0042  * Return the following UID if using API specified in this file
0043  * without further extensions:
0044  * 384fb3e0-e7f8-11e3-af63-0002a5d5c51b.
0045  * see also OPTEE_MSG_UID_* in optee_msg.h
0046  */
0047 #define OPTEE_SMC_FUNCID_CALLS_UID OPTEE_MSG_FUNCID_CALLS_UID
0048 #define OPTEE_SMC_CALLS_UID \
0049     ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL, ARM_SMCCC_SMC_32, \
0050                ARM_SMCCC_OWNER_TRUSTED_OS_END, \
0051                OPTEE_SMC_FUNCID_CALLS_UID)
0052 
0053 /*
0054  * Function specified by SMC Calling convention
0055  *
0056  * Returns 2.0 if using API specified in this file without further extensions.
0057  * see also OPTEE_MSG_REVISION_* in optee_msg.h
0058  */
0059 #define OPTEE_SMC_FUNCID_CALLS_REVISION OPTEE_MSG_FUNCID_CALLS_REVISION
0060 #define OPTEE_SMC_CALLS_REVISION \
0061     ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL, ARM_SMCCC_SMC_32, \
0062                ARM_SMCCC_OWNER_TRUSTED_OS_END, \
0063                OPTEE_SMC_FUNCID_CALLS_REVISION)
0064 
0065 struct optee_smc_calls_revision_result {
0066     unsigned long major;
0067     unsigned long minor;
0068     unsigned long reserved0;
0069     unsigned long reserved1;
0070 };
0071 
0072 /*
0073  * Get UUID of Trusted OS.
0074  *
0075  * Used by non-secure world to figure out which Trusted OS is installed.
0076  * Note that returned UUID is the UUID of the Trusted OS, not of the API.
0077  *
0078  * Returns UUID in a0-4 in the same way as OPTEE_SMC_CALLS_UID
0079  * described above.
0080  */
0081 #define OPTEE_SMC_FUNCID_GET_OS_UUID OPTEE_MSG_FUNCID_GET_OS_UUID
0082 #define OPTEE_SMC_CALL_GET_OS_UUID \
0083     OPTEE_SMC_FAST_CALL_VAL(OPTEE_SMC_FUNCID_GET_OS_UUID)
0084 
0085 /*
0086  * Get revision of Trusted OS.
0087  *
0088  * Used by non-secure world to figure out which version of the Trusted OS
0089  * is installed. Note that the returned revision is the revision of the
0090  * Trusted OS, not of the API.
0091  *
0092  * Returns revision in a0-1 in the same way as OPTEE_SMC_CALLS_REVISION
0093  * described above. May optionally return a 32-bit build identifier in a2,
0094  * with zero meaning unspecified.
0095  */
0096 #define OPTEE_SMC_FUNCID_GET_OS_REVISION OPTEE_MSG_FUNCID_GET_OS_REVISION
0097 #define OPTEE_SMC_CALL_GET_OS_REVISION \
0098     OPTEE_SMC_FAST_CALL_VAL(OPTEE_SMC_FUNCID_GET_OS_REVISION)
0099 
0100 struct optee_smc_call_get_os_revision_result {
0101     unsigned long major;
0102     unsigned long minor;
0103     unsigned long build_id;
0104     unsigned long reserved1;
0105 };
0106 
0107 /*
0108  * Call with struct optee_msg_arg as argument
0109  *
0110  * When called with OPTEE_SMC_CALL_WITH_RPC_ARG or
0111  * OPTEE_SMC_CALL_WITH_REGD_ARG in a0 there is one RPC struct optee_msg_arg
0112  * following after the first struct optee_msg_arg. The RPC struct
0113  * optee_msg_arg has reserved space for the number of RPC parameters as
0114  * returned by OPTEE_SMC_EXCHANGE_CAPABILITIES.
0115  *
0116  * When calling these functions, normal world has a few responsibilities:
0117  * 1. It must be able to handle eventual RPCs
0118  * 2. Non-secure interrupts should not be masked
0119  * 3. If asynchronous notifications has been negotiated successfully, then
0120  *    the interrupt for asynchronous notifications should be unmasked
0121  *    during this call.
0122  *
0123  * Call register usage, OPTEE_SMC_CALL_WITH_ARG and
0124  * OPTEE_SMC_CALL_WITH_RPC_ARG:
0125  * a0   SMC Function ID, OPTEE_SMC_CALL_WITH_ARG or OPTEE_SMC_CALL_WITH_RPC_ARG
0126  * a1   Upper 32 bits of a 64-bit physical pointer to a struct optee_msg_arg
0127  * a2   Lower 32 bits of a 64-bit physical pointer to a struct optee_msg_arg
0128  * a3   Cache settings, not used if physical pointer is in a predefined shared
0129  *  memory area else per OPTEE_SMC_SHM_*
0130  * a4-6 Not used
0131  * a7   Hypervisor Client ID register
0132  *
0133  * Call register usage, OPTEE_SMC_CALL_WITH_REGD_ARG:
0134  * a0   SMC Function ID, OPTEE_SMC_CALL_WITH_REGD_ARG
0135  * a1   Upper 32 bits of a 64-bit shared memory cookie
0136  * a2   Lower 32 bits of a 64-bit shared memory cookie
0137  * a3   Offset of the struct optee_msg_arg in the shared memory with the
0138  *  supplied cookie
0139  * a4-6 Not used
0140  * a7   Hypervisor Client ID register
0141  *
0142  * Normal return register usage:
0143  * a0   Return value, OPTEE_SMC_RETURN_*
0144  * a1-3 Not used
0145  * a4-7 Preserved
0146  *
0147  * OPTEE_SMC_RETURN_ETHREAD_LIMIT return register usage:
0148  * a0   Return value, OPTEE_SMC_RETURN_ETHREAD_LIMIT
0149  * a1-3 Preserved
0150  * a4-7 Preserved
0151  *
0152  * RPC return register usage:
0153  * a0   Return value, OPTEE_SMC_RETURN_IS_RPC(val)
0154  * a1-2 RPC parameters
0155  * a3-7 Resume information, must be preserved
0156  *
0157  * Possible return values:
0158  * OPTEE_SMC_RETURN_UNKNOWN_FUNCTION    Trusted OS does not recognize this
0159  *                  function.
0160  * OPTEE_SMC_RETURN_OK          Call completed, result updated in
0161  *                  the previously supplied struct
0162  *                  optee_msg_arg.
0163  * OPTEE_SMC_RETURN_ETHREAD_LIMIT   Number of Trusted OS threads exceeded,
0164  *                  try again later.
0165  * OPTEE_SMC_RETURN_EBADADDR        Bad physical pointer to struct
0166  *                  optee_msg_arg.
0167  * OPTEE_SMC_RETURN_EBADCMD     Bad/unknown cmd in struct optee_msg_arg
0168  * OPTEE_SMC_RETURN_IS_RPC()        Call suspended by RPC call to normal
0169  *                  world.
0170  */
0171 #define OPTEE_SMC_FUNCID_CALL_WITH_ARG OPTEE_MSG_FUNCID_CALL_WITH_ARG
0172 #define OPTEE_SMC_CALL_WITH_ARG \
0173     OPTEE_SMC_STD_CALL_VAL(OPTEE_SMC_FUNCID_CALL_WITH_ARG)
0174 #define OPTEE_SMC_CALL_WITH_RPC_ARG \
0175     OPTEE_SMC_STD_CALL_VAL(OPTEE_SMC_FUNCID_CALL_WITH_RPC_ARG)
0176 #define OPTEE_SMC_CALL_WITH_REGD_ARG \
0177     OPTEE_SMC_STD_CALL_VAL(OPTEE_SMC_FUNCID_CALL_WITH_REGD_ARG)
0178 
0179 /*
0180  * Get Shared Memory Config
0181  *
0182  * Returns the Secure/Non-secure shared memory config.
0183  *
0184  * Call register usage:
0185  * a0   SMC Function ID, OPTEE_SMC_GET_SHM_CONFIG
0186  * a1-6 Not used
0187  * a7   Hypervisor Client ID register
0188  *
0189  * Have config return register usage:
0190  * a0   OPTEE_SMC_RETURN_OK
0191  * a1   Physical address of start of SHM
0192  * a2   Size of SHM
0193  * a3   Cache settings of memory, as defined by the
0194  *  OPTEE_SMC_SHM_* values above
0195  * a4-7 Preserved
0196  *
0197  * Not available register usage:
0198  * a0   OPTEE_SMC_RETURN_ENOTAVAIL
0199  * a1-3 Not used
0200  * a4-7 Preserved
0201  */
0202 #define OPTEE_SMC_FUNCID_GET_SHM_CONFIG 7
0203 #define OPTEE_SMC_GET_SHM_CONFIG \
0204     OPTEE_SMC_FAST_CALL_VAL(OPTEE_SMC_FUNCID_GET_SHM_CONFIG)
0205 
0206 struct optee_smc_get_shm_config_result {
0207     unsigned long status;
0208     unsigned long start;
0209     unsigned long size;
0210     unsigned long settings;
0211 };
0212 
0213 /*
0214  * Exchanges capabilities between normal world and secure world
0215  *
0216  * Call register usage:
0217  * a0   SMC Function ID, OPTEE_SMC_EXCHANGE_CAPABILITIES
0218  * a1   bitfield of normal world capabilities OPTEE_SMC_NSEC_CAP_*
0219  * a2-6 Not used
0220  * a7   Hypervisor Client ID register
0221  *
0222  * Normal return register usage:
0223  * a0   OPTEE_SMC_RETURN_OK
0224  * a1   bitfield of secure world capabilities OPTEE_SMC_SEC_CAP_*
0225  * a2   The maximum secure world notification number
0226  * a3   Bit[7:0]: Number of parameters needed for RPC to be supplied
0227  *        as the second MSG arg struct for
0228  *        OPTEE_SMC_CALL_WITH_ARG
0229  *  Bit[31:8]: Reserved (MBZ)
0230  * a4-7 Preserved
0231  *
0232  * Error return register usage:
0233  * a0   OPTEE_SMC_RETURN_ENOTAVAIL, can't use the capabilities from normal world
0234  * a1   bitfield of secure world capabilities OPTEE_SMC_SEC_CAP_*
0235  * a2-7 Preserved
0236  */
0237 /* Normal world works as a uniprocessor system */
0238 #define OPTEE_SMC_NSEC_CAP_UNIPROCESSOR     BIT(0)
0239 /* Secure world has reserved shared memory for normal world to use */
0240 #define OPTEE_SMC_SEC_CAP_HAVE_RESERVED_SHM BIT(0)
0241 /* Secure world can communicate via previously unregistered shared memory */
0242 #define OPTEE_SMC_SEC_CAP_UNREGISTERED_SHM  BIT(1)
0243 
0244 /*
0245  * Secure world supports commands "register/unregister shared memory",
0246  * secure world accepts command buffers located in any parts of non-secure RAM
0247  */
0248 #define OPTEE_SMC_SEC_CAP_DYNAMIC_SHM       BIT(2)
0249 /* Secure world is built with virtualization support */
0250 #define OPTEE_SMC_SEC_CAP_VIRTUALIZATION    BIT(3)
0251 /* Secure world supports Shared Memory with a NULL reference */
0252 #define OPTEE_SMC_SEC_CAP_MEMREF_NULL       BIT(4)
0253 /* Secure world supports asynchronous notification of normal world */
0254 #define OPTEE_SMC_SEC_CAP_ASYNC_NOTIF       BIT(5)
0255 /* Secure world supports pre-allocating RPC arg struct */
0256 #define OPTEE_SMC_SEC_CAP_RPC_ARG       BIT(6)
0257 
0258 #define OPTEE_SMC_FUNCID_EXCHANGE_CAPABILITIES  9
0259 #define OPTEE_SMC_EXCHANGE_CAPABILITIES \
0260     OPTEE_SMC_FAST_CALL_VAL(OPTEE_SMC_FUNCID_EXCHANGE_CAPABILITIES)
0261 
0262 struct optee_smc_exchange_capabilities_result {
0263     unsigned long status;
0264     unsigned long capabilities;
0265     unsigned long max_notif_value;
0266     unsigned long data;
0267 };
0268 
0269 /*
0270  * Disable and empties cache of shared memory objects
0271  *
0272  * Secure world can cache frequently used shared memory objects, for
0273  * example objects used as RPC arguments. When secure world is idle this
0274  * function returns one shared memory reference to free. To disable the
0275  * cache and free all cached objects this function has to be called until
0276  * it returns OPTEE_SMC_RETURN_ENOTAVAIL.
0277  *
0278  * Call register usage:
0279  * a0   SMC Function ID, OPTEE_SMC_DISABLE_SHM_CACHE
0280  * a1-6 Not used
0281  * a7   Hypervisor Client ID register
0282  *
0283  * Normal return register usage:
0284  * a0   OPTEE_SMC_RETURN_OK
0285  * a1   Upper 32 bits of a 64-bit Shared memory cookie
0286  * a2   Lower 32 bits of a 64-bit Shared memory cookie
0287  * a3-7 Preserved
0288  *
0289  * Cache empty return register usage:
0290  * a0   OPTEE_SMC_RETURN_ENOTAVAIL
0291  * a1-7 Preserved
0292  *
0293  * Not idle return register usage:
0294  * a0   OPTEE_SMC_RETURN_EBUSY
0295  * a1-7 Preserved
0296  */
0297 #define OPTEE_SMC_FUNCID_DISABLE_SHM_CACHE  10
0298 #define OPTEE_SMC_DISABLE_SHM_CACHE \
0299     OPTEE_SMC_FAST_CALL_VAL(OPTEE_SMC_FUNCID_DISABLE_SHM_CACHE)
0300 
0301 struct optee_smc_disable_shm_cache_result {
0302     unsigned long status;
0303     unsigned long shm_upper32;
0304     unsigned long shm_lower32;
0305     unsigned long reserved0;
0306 };
0307 
0308 /*
0309  * Enable cache of shared memory objects
0310  *
0311  * Secure world can cache frequently used shared memory objects, for
0312  * example objects used as RPC arguments. When secure world is idle this
0313  * function returns OPTEE_SMC_RETURN_OK and the cache is enabled. If
0314  * secure world isn't idle OPTEE_SMC_RETURN_EBUSY is returned.
0315  *
0316  * Call register usage:
0317  * a0   SMC Function ID, OPTEE_SMC_ENABLE_SHM_CACHE
0318  * a1-6 Not used
0319  * a7   Hypervisor Client ID register
0320  *
0321  * Normal return register usage:
0322  * a0   OPTEE_SMC_RETURN_OK
0323  * a1-7 Preserved
0324  *
0325  * Not idle return register usage:
0326  * a0   OPTEE_SMC_RETURN_EBUSY
0327  * a1-7 Preserved
0328  */
0329 #define OPTEE_SMC_FUNCID_ENABLE_SHM_CACHE   11
0330 #define OPTEE_SMC_ENABLE_SHM_CACHE \
0331     OPTEE_SMC_FAST_CALL_VAL(OPTEE_SMC_FUNCID_ENABLE_SHM_CACHE)
0332 
0333 /*
0334  * Query OP-TEE about number of supported threads
0335  *
0336  * Normal World OS or Hypervisor issues this call to find out how many
0337  * threads OP-TEE supports. That is how many standard calls can be issued
0338  * in parallel before OP-TEE will return OPTEE_SMC_RETURN_ETHREAD_LIMIT.
0339  *
0340  * Call requests usage:
0341  * a0   SMC Function ID, OPTEE_SMC_GET_THREAD_COUNT
0342  * a1-6 Not used
0343  * a7   Hypervisor Client ID register
0344  *
0345  * Normal return register usage:
0346  * a0   OPTEE_SMC_RETURN_OK
0347  * a1   Number of threads
0348  * a2-7 Preserved
0349  *
0350  * Error return:
0351  * a0   OPTEE_SMC_RETURN_UNKNOWN_FUNCTION   Requested call is not implemented
0352  * a1-7 Preserved
0353  */
0354 #define OPTEE_SMC_FUNCID_GET_THREAD_COUNT   15
0355 #define OPTEE_SMC_GET_THREAD_COUNT \
0356     OPTEE_SMC_FAST_CALL_VAL(OPTEE_SMC_FUNCID_GET_THREAD_COUNT)
0357 
0358 /*
0359  * Inform OP-TEE that normal world is able to receive asynchronous
0360  * notifications.
0361  *
0362  * Call requests usage:
0363  * a0   SMC Function ID, OPTEE_SMC_ENABLE_ASYNC_NOTIF
0364  * a1-6 Not used
0365  * a7   Hypervisor Client ID register
0366  *
0367  * Normal return register usage:
0368  * a0   OPTEE_SMC_RETURN_OK
0369  * a1-7 Preserved
0370  *
0371  * Not supported return register usage:
0372  * a0   OPTEE_SMC_RETURN_ENOTAVAIL
0373  * a1-7 Preserved
0374  */
0375 #define OPTEE_SMC_FUNCID_ENABLE_ASYNC_NOTIF 16
0376 #define OPTEE_SMC_ENABLE_ASYNC_NOTIF \
0377     OPTEE_SMC_FAST_CALL_VAL(OPTEE_SMC_FUNCID_ENABLE_ASYNC_NOTIF)
0378 
0379 /*
0380  * Retrieve a value of notifications pending since the last call of this
0381  * function.
0382  *
0383  * OP-TEE keeps a record of all posted values. When an interrupt is
0384  * received which indicates that there are posted values this function
0385  * should be called until all pended values have been retrieved. When a
0386  * value is retrieved, it's cleared from the record in secure world.
0387  *
0388  * It is expected that this function is called from an interrupt handler
0389  * in normal world.
0390  *
0391  * Call requests usage:
0392  * a0   SMC Function ID, OPTEE_SMC_GET_ASYNC_NOTIF_VALUE
0393  * a1-6 Not used
0394  * a7   Hypervisor Client ID register
0395  *
0396  * Normal return register usage:
0397  * a0   OPTEE_SMC_RETURN_OK
0398  * a1   value
0399  * a2   Bit[0]: OPTEE_SMC_ASYNC_NOTIF_VALUE_VALID if the value in a1 is
0400  *      valid, else 0 if no values where pending
0401  * a2   Bit[1]: OPTEE_SMC_ASYNC_NOTIF_VALUE_PENDING if another value is
0402  *      pending, else 0.
0403  *  Bit[31:2]: MBZ
0404  * a3-7 Preserved
0405  *
0406  * Not supported return register usage:
0407  * a0   OPTEE_SMC_RETURN_ENOTAVAIL
0408  * a1-7 Preserved
0409  */
0410 #define OPTEE_SMC_ASYNC_NOTIF_VALUE_VALID   BIT(0)
0411 #define OPTEE_SMC_ASYNC_NOTIF_VALUE_PENDING BIT(1)
0412 
0413 /*
0414  * Notification that OP-TEE expects a yielding call to do some bottom half
0415  * work in a driver.
0416  */
0417 #define OPTEE_SMC_ASYNC_NOTIF_VALUE_DO_BOTTOM_HALF  0
0418 
0419 #define OPTEE_SMC_FUNCID_GET_ASYNC_NOTIF_VALUE  17
0420 #define OPTEE_SMC_GET_ASYNC_NOTIF_VALUE \
0421     OPTEE_SMC_FAST_CALL_VAL(OPTEE_SMC_FUNCID_GET_ASYNC_NOTIF_VALUE)
0422 
0423 /* See OPTEE_SMC_CALL_WITH_RPC_ARG above */
0424 #define OPTEE_SMC_FUNCID_CALL_WITH_RPC_ARG  18
0425 
0426 /* See OPTEE_SMC_CALL_WITH_REGD_ARG above */
0427 #define OPTEE_SMC_FUNCID_CALL_WITH_REGD_ARG 19
0428 
0429 /*
0430  * Resume from RPC (for example after processing a foreign interrupt)
0431  *
0432  * Call register usage:
0433  * a0   SMC Function ID, OPTEE_SMC_CALL_RETURN_FROM_RPC
0434  * a1-3 Value of a1-3 when OPTEE_SMC_CALL_WITH_ARG returned
0435  *  OPTEE_SMC_RETURN_RPC in a0
0436  *
0437  * Return register usage is the same as for OPTEE_SMC_*CALL_WITH_ARG above.
0438  *
0439  * Possible return values
0440  * OPTEE_SMC_RETURN_UNKNOWN_FUNCTION    Trusted OS does not recognize this
0441  *                  function.
0442  * OPTEE_SMC_RETURN_OK          Original call completed, result
0443  *                  updated in the previously supplied.
0444  *                  struct optee_msg_arg
0445  * OPTEE_SMC_RETURN_RPC         Call suspended by RPC call to normal
0446  *                  world.
0447  * OPTEE_SMC_RETURN_ERESUME     Resume failed, the opaque resume
0448  *                  information was corrupt.
0449  */
0450 #define OPTEE_SMC_FUNCID_RETURN_FROM_RPC    3
0451 #define OPTEE_SMC_CALL_RETURN_FROM_RPC \
0452     OPTEE_SMC_STD_CALL_VAL(OPTEE_SMC_FUNCID_RETURN_FROM_RPC)
0453 
0454 #define OPTEE_SMC_RETURN_RPC_PREFIX_MASK    0xFFFF0000
0455 #define OPTEE_SMC_RETURN_RPC_PREFIX     0xFFFF0000
0456 #define OPTEE_SMC_RETURN_RPC_FUNC_MASK      0x0000FFFF
0457 
0458 #define OPTEE_SMC_RETURN_GET_RPC_FUNC(ret) \
0459     ((ret) & OPTEE_SMC_RETURN_RPC_FUNC_MASK)
0460 
0461 #define OPTEE_SMC_RPC_VAL(func)     ((func) | OPTEE_SMC_RETURN_RPC_PREFIX)
0462 
0463 /*
0464  * Allocate memory for RPC parameter passing. The memory is used to hold a
0465  * struct optee_msg_arg.
0466  *
0467  * "Call" register usage:
0468  * a0   This value, OPTEE_SMC_RETURN_RPC_ALLOC
0469  * a1   Size in bytes of required argument memory
0470  * a2   Not used
0471  * a3   Resume information, must be preserved
0472  * a4-5 Not used
0473  * a6-7 Resume information, must be preserved
0474  *
0475  * "Return" register usage:
0476  * a0   SMC Function ID, OPTEE_SMC_CALL_RETURN_FROM_RPC.
0477  * a1   Upper 32 bits of 64-bit physical pointer to allocated
0478  *  memory, (a1 == 0 && a2 == 0) if size was 0 or if memory can't
0479  *  be allocated.
0480  * a2   Lower 32 bits of 64-bit physical pointer to allocated
0481  *  memory, (a1 == 0 && a2 == 0) if size was 0 or if memory can't
0482  *  be allocated
0483  * a3   Preserved
0484  * a4   Upper 32 bits of 64-bit Shared memory cookie used when freeing
0485  *  the memory or doing an RPC
0486  * a5   Lower 32 bits of 64-bit Shared memory cookie used when freeing
0487  *  the memory or doing an RPC
0488  * a6-7 Preserved
0489  */
0490 #define OPTEE_SMC_RPC_FUNC_ALLOC    0
0491 #define OPTEE_SMC_RETURN_RPC_ALLOC \
0492     OPTEE_SMC_RPC_VAL(OPTEE_SMC_RPC_FUNC_ALLOC)
0493 
0494 /*
0495  * Free memory previously allocated by OPTEE_SMC_RETURN_RPC_ALLOC
0496  *
0497  * "Call" register usage:
0498  * a0   This value, OPTEE_SMC_RETURN_RPC_FREE
0499  * a1   Upper 32 bits of 64-bit shared memory cookie belonging to this
0500  *  argument memory
0501  * a2   Lower 32 bits of 64-bit shared memory cookie belonging to this
0502  *  argument memory
0503  * a3-7 Resume information, must be preserved
0504  *
0505  * "Return" register usage:
0506  * a0   SMC Function ID, OPTEE_SMC_CALL_RETURN_FROM_RPC.
0507  * a1-2 Not used
0508  * a3-7 Preserved
0509  */
0510 #define OPTEE_SMC_RPC_FUNC_FREE     2
0511 #define OPTEE_SMC_RETURN_RPC_FREE \
0512     OPTEE_SMC_RPC_VAL(OPTEE_SMC_RPC_FUNC_FREE)
0513 
0514 /*
0515  * Deliver a foreign interrupt in normal world.
0516  *
0517  * "Call" register usage:
0518  * a0   OPTEE_SMC_RETURN_RPC_FOREIGN_INTR
0519  * a1-7 Resume information, must be preserved
0520  *
0521  * "Return" register usage:
0522  * a0   SMC Function ID, OPTEE_SMC_CALL_RETURN_FROM_RPC.
0523  * a1-7 Preserved
0524  */
0525 #define OPTEE_SMC_RPC_FUNC_FOREIGN_INTR 4
0526 #define OPTEE_SMC_RETURN_RPC_FOREIGN_INTR \
0527     OPTEE_SMC_RPC_VAL(OPTEE_SMC_RPC_FUNC_FOREIGN_INTR)
0528 
0529 /*
0530  * Do an RPC request. The supplied struct optee_msg_arg tells which
0531  * request to do and the parameters for the request. The following fields
0532  * are used (the rest are unused):
0533  * - cmd        the Request ID
0534  * - ret        return value of the request, filled in by normal world
0535  * - num_params     number of parameters for the request
0536  * - params     the parameters
0537  * - param_attrs    attributes of the parameters
0538  *
0539  * "Call" register usage:
0540  * a0   OPTEE_SMC_RETURN_RPC_CMD
0541  * a1   Upper 32 bits of a 64-bit Shared memory cookie holding a
0542  *  struct optee_msg_arg, must be preserved, only the data should
0543  *  be updated
0544  * a2   Lower 32 bits of a 64-bit Shared memory cookie holding a
0545  *  struct optee_msg_arg, must be preserved, only the data should
0546  *  be updated
0547  * a3-7 Resume information, must be preserved
0548  *
0549  * "Return" register usage:
0550  * a0   SMC Function ID, OPTEE_SMC_CALL_RETURN_FROM_RPC.
0551  * a1-2 Not used
0552  * a3-7 Preserved
0553  */
0554 #define OPTEE_SMC_RPC_FUNC_CMD      5
0555 #define OPTEE_SMC_RETURN_RPC_CMD \
0556     OPTEE_SMC_RPC_VAL(OPTEE_SMC_RPC_FUNC_CMD)
0557 
0558 /* Returned in a0 */
0559 #define OPTEE_SMC_RETURN_UNKNOWN_FUNCTION 0xFFFFFFFF
0560 
0561 /* Returned in a0 only from Trusted OS functions */
0562 #define OPTEE_SMC_RETURN_OK     0x0
0563 #define OPTEE_SMC_RETURN_ETHREAD_LIMIT  0x1
0564 #define OPTEE_SMC_RETURN_EBUSY      0x2
0565 #define OPTEE_SMC_RETURN_ERESUME    0x3
0566 #define OPTEE_SMC_RETURN_EBADADDR   0x4
0567 #define OPTEE_SMC_RETURN_EBADCMD    0x5
0568 #define OPTEE_SMC_RETURN_ENOMEM     0x6
0569 #define OPTEE_SMC_RETURN_ENOTAVAIL  0x7
0570 #define OPTEE_SMC_RETURN_IS_RPC(ret)    __optee_smc_return_is_rpc((ret))
0571 
0572 static inline bool __optee_smc_return_is_rpc(u32 ret)
0573 {
0574     return ret != OPTEE_SMC_RETURN_UNKNOWN_FUNCTION &&
0575            (ret & OPTEE_SMC_RETURN_RPC_PREFIX_MASK) ==
0576             OPTEE_SMC_RETURN_RPC_PREFIX;
0577 }
0578 
0579 #endif /* OPTEE_SMC_H */