xref: /openbmc/linux/drivers/tee/optee/optee_smc.h (revision 1ac731c529cd4d6adbce134754b51ff7d822b145)
132356d30SJerome Forissier /* SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) */
24fb0a5ebSJens Wiklander /*
3617d8e8bSJens Wiklander  * Copyright (c) 2015-2021, Linaro Limited
44fb0a5ebSJens Wiklander  */
54fb0a5ebSJens Wiklander #ifndef OPTEE_SMC_H
64fb0a5ebSJens Wiklander #define OPTEE_SMC_H
74fb0a5ebSJens Wiklander 
84fb0a5ebSJens Wiklander #include <linux/arm-smccc.h>
94fb0a5ebSJens Wiklander #include <linux/bitops.h>
104fb0a5ebSJens Wiklander 
114fb0a5ebSJens Wiklander #define OPTEE_SMC_STD_CALL_VAL(func_num) \
124fb0a5ebSJens Wiklander 	ARM_SMCCC_CALL_VAL(ARM_SMCCC_STD_CALL, ARM_SMCCC_SMC_32, \
134fb0a5ebSJens Wiklander 			   ARM_SMCCC_OWNER_TRUSTED_OS, (func_num))
144fb0a5ebSJens Wiklander #define OPTEE_SMC_FAST_CALL_VAL(func_num) \
154fb0a5ebSJens Wiklander 	ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL, ARM_SMCCC_SMC_32, \
164fb0a5ebSJens Wiklander 			   ARM_SMCCC_OWNER_TRUSTED_OS, (func_num))
174fb0a5ebSJens Wiklander 
184fb0a5ebSJens Wiklander /*
194fb0a5ebSJens Wiklander  * Function specified by SMC Calling convention.
204fb0a5ebSJens Wiklander  */
214fb0a5ebSJens Wiklander #define OPTEE_SMC_FUNCID_CALLS_COUNT	0xFF00
224fb0a5ebSJens Wiklander #define OPTEE_SMC_CALLS_COUNT \
234fb0a5ebSJens Wiklander 	ARM_SMCCC_CALL_VAL(OPTEE_SMC_FAST_CALL, SMCCC_SMC_32, \
244fb0a5ebSJens Wiklander 			   SMCCC_OWNER_TRUSTED_OS_END, \
254fb0a5ebSJens Wiklander 			   OPTEE_SMC_FUNCID_CALLS_COUNT)
264fb0a5ebSJens Wiklander 
274fb0a5ebSJens Wiklander /*
284fb0a5ebSJens Wiklander  * Normal cached memory (write-back), shareable for SMP systems and not
294fb0a5ebSJens Wiklander  * shareable for UP systems.
304fb0a5ebSJens Wiklander  */
314fb0a5ebSJens Wiklander #define OPTEE_SMC_SHM_CACHED		1
324fb0a5ebSJens Wiklander 
334fb0a5ebSJens Wiklander /*
344fb0a5ebSJens Wiklander  * a0..a7 is used as register names in the descriptions below, on arm32
354fb0a5ebSJens Wiklander  * that translates to r0..r7 and on arm64 to w0..w7. In both cases it's
364fb0a5ebSJens Wiklander  * 32-bit registers.
374fb0a5ebSJens Wiklander  */
384fb0a5ebSJens Wiklander 
394fb0a5ebSJens Wiklander /*
404fb0a5ebSJens Wiklander  * Function specified by SMC Calling convention
414fb0a5ebSJens Wiklander  *
42617d8e8bSJens Wiklander  * Return the following UID if using API specified in this file
43617d8e8bSJens Wiklander  * without further extensions:
44617d8e8bSJens Wiklander  * 384fb3e0-e7f8-11e3-af63-0002a5d5c51b.
45617d8e8bSJens Wiklander  * see also OPTEE_MSG_UID_* in optee_msg.h
464fb0a5ebSJens Wiklander  */
474fb0a5ebSJens Wiklander #define OPTEE_SMC_FUNCID_CALLS_UID OPTEE_MSG_FUNCID_CALLS_UID
484fb0a5ebSJens Wiklander #define OPTEE_SMC_CALLS_UID \
494fb0a5ebSJens Wiklander 	ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL, ARM_SMCCC_SMC_32, \
504fb0a5ebSJens Wiklander 			   ARM_SMCCC_OWNER_TRUSTED_OS_END, \
514fb0a5ebSJens Wiklander 			   OPTEE_SMC_FUNCID_CALLS_UID)
524fb0a5ebSJens Wiklander 
534fb0a5ebSJens Wiklander /*
544fb0a5ebSJens Wiklander  * Function specified by SMC Calling convention
554fb0a5ebSJens Wiklander  *
56617d8e8bSJens Wiklander  * Returns 2.0 if using API specified in this file without further extensions.
574fb0a5ebSJens Wiklander  * see also OPTEE_MSG_REVISION_* in optee_msg.h
584fb0a5ebSJens Wiklander  */
594fb0a5ebSJens Wiklander #define OPTEE_SMC_FUNCID_CALLS_REVISION OPTEE_MSG_FUNCID_CALLS_REVISION
604fb0a5ebSJens Wiklander #define OPTEE_SMC_CALLS_REVISION \
614fb0a5ebSJens Wiklander 	ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL, ARM_SMCCC_SMC_32, \
624fb0a5ebSJens Wiklander 			   ARM_SMCCC_OWNER_TRUSTED_OS_END, \
634fb0a5ebSJens Wiklander 			   OPTEE_SMC_FUNCID_CALLS_REVISION)
644fb0a5ebSJens Wiklander 
654fb0a5ebSJens Wiklander struct optee_smc_calls_revision_result {
664fb0a5ebSJens Wiklander 	unsigned long major;
674fb0a5ebSJens Wiklander 	unsigned long minor;
684fb0a5ebSJens Wiklander 	unsigned long reserved0;
694fb0a5ebSJens Wiklander 	unsigned long reserved1;
704fb0a5ebSJens Wiklander };
714fb0a5ebSJens Wiklander 
724fb0a5ebSJens Wiklander /*
734fb0a5ebSJens Wiklander  * Get UUID of Trusted OS.
744fb0a5ebSJens Wiklander  *
754fb0a5ebSJens Wiklander  * Used by non-secure world to figure out which Trusted OS is installed.
764fb0a5ebSJens Wiklander  * Note that returned UUID is the UUID of the Trusted OS, not of the API.
774fb0a5ebSJens Wiklander  *
784fb0a5ebSJens Wiklander  * Returns UUID in a0-4 in the same way as OPTEE_SMC_CALLS_UID
794fb0a5ebSJens Wiklander  * described above.
804fb0a5ebSJens Wiklander  */
814fb0a5ebSJens Wiklander #define OPTEE_SMC_FUNCID_GET_OS_UUID OPTEE_MSG_FUNCID_GET_OS_UUID
824fb0a5ebSJens Wiklander #define OPTEE_SMC_CALL_GET_OS_UUID \
834fb0a5ebSJens Wiklander 	OPTEE_SMC_FAST_CALL_VAL(OPTEE_SMC_FUNCID_GET_OS_UUID)
844fb0a5ebSJens Wiklander 
854fb0a5ebSJens Wiklander /*
864fb0a5ebSJens Wiklander  * Get revision of Trusted OS.
874fb0a5ebSJens Wiklander  *
884fb0a5ebSJens Wiklander  * Used by non-secure world to figure out which version of the Trusted OS
894fb0a5ebSJens Wiklander  * is installed. Note that the returned revision is the revision of the
904fb0a5ebSJens Wiklander  * Trusted OS, not of the API.
914fb0a5ebSJens Wiklander  *
924fb0a5ebSJens Wiklander  * Returns revision in a0-1 in the same way as OPTEE_SMC_CALLS_REVISION
936e112de0SJérôme Forissier  * described above. May optionally return a 32-bit build identifier in a2,
946e112de0SJérôme Forissier  * with zero meaning unspecified.
954fb0a5ebSJens Wiklander  */
964fb0a5ebSJens Wiklander #define OPTEE_SMC_FUNCID_GET_OS_REVISION OPTEE_MSG_FUNCID_GET_OS_REVISION
974fb0a5ebSJens Wiklander #define OPTEE_SMC_CALL_GET_OS_REVISION \
984fb0a5ebSJens Wiklander 	OPTEE_SMC_FAST_CALL_VAL(OPTEE_SMC_FUNCID_GET_OS_REVISION)
994fb0a5ebSJens Wiklander 
1006e112de0SJérôme Forissier struct optee_smc_call_get_os_revision_result {
1016e112de0SJérôme Forissier 	unsigned long major;
1026e112de0SJérôme Forissier 	unsigned long minor;
1036e112de0SJérôme Forissier 	unsigned long build_id;
1046e112de0SJérôme Forissier 	unsigned long reserved1;
1056e112de0SJérôme Forissier };
1066e112de0SJérôme Forissier 
1074fb0a5ebSJens Wiklander /*
108*f3040daaSJeffrey Kardatzke  * Load Trusted OS from optee/tee.bin in the Linux firmware.
109*f3040daaSJeffrey Kardatzke  *
110*f3040daaSJeffrey Kardatzke  * WARNING: Use this cautiously as it could lead to insecure loading of the
111*f3040daaSJeffrey Kardatzke  * Trusted OS.
112*f3040daaSJeffrey Kardatzke  * This SMC instructs EL3 to load a binary and execute it as the Trusted OS.
113*f3040daaSJeffrey Kardatzke  *
114*f3040daaSJeffrey Kardatzke  * Call register usage:
115*f3040daaSJeffrey Kardatzke  * a0 SMC Function ID, OPTEE_SMC_CALL_LOAD_IMAGE
116*f3040daaSJeffrey Kardatzke  * a1 Upper 32bit of a 64bit size for the payload
117*f3040daaSJeffrey Kardatzke  * a2 Lower 32bit of a 64bit size for the payload
118*f3040daaSJeffrey Kardatzke  * a3 Upper 32bit of the physical address for the payload
119*f3040daaSJeffrey Kardatzke  * a4 Lower 32bit of the physical address for the payload
120*f3040daaSJeffrey Kardatzke  *
121*f3040daaSJeffrey Kardatzke  * The payload is in the OP-TEE image format.
122*f3040daaSJeffrey Kardatzke  *
123*f3040daaSJeffrey Kardatzke  * Returns result in a0, 0 on success and an error code otherwise.
124*f3040daaSJeffrey Kardatzke  */
125*f3040daaSJeffrey Kardatzke #define OPTEE_SMC_FUNCID_LOAD_IMAGE 2
126*f3040daaSJeffrey Kardatzke #define OPTEE_SMC_CALL_LOAD_IMAGE \
127*f3040daaSJeffrey Kardatzke 	ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL, ARM_SMCCC_SMC_32, \
128*f3040daaSJeffrey Kardatzke 			   ARM_SMCCC_OWNER_TRUSTED_OS_END, \
129*f3040daaSJeffrey Kardatzke 			   OPTEE_SMC_FUNCID_LOAD_IMAGE)
130*f3040daaSJeffrey Kardatzke 
131*f3040daaSJeffrey Kardatzke /*
1324fb0a5ebSJens Wiklander  * Call with struct optee_msg_arg as argument
1334fb0a5ebSJens Wiklander  *
134ed8faf6cSJens Wiklander  * When called with OPTEE_SMC_CALL_WITH_RPC_ARG or
135ed8faf6cSJens Wiklander  * OPTEE_SMC_CALL_WITH_REGD_ARG in a0 there is one RPC struct optee_msg_arg
136ed8faf6cSJens Wiklander  * following after the first struct optee_msg_arg. The RPC struct
137ed8faf6cSJens Wiklander  * optee_msg_arg has reserved space for the number of RPC parameters as
138ed8faf6cSJens Wiklander  * returned by OPTEE_SMC_EXCHANGE_CAPABILITIES.
139ed8faf6cSJens Wiklander  *
140ed8faf6cSJens Wiklander  * When calling these functions, normal world has a few responsibilities:
1416749e69cSJens Wiklander  * 1. It must be able to handle eventual RPCs
1426749e69cSJens Wiklander  * 2. Non-secure interrupts should not be masked
1436749e69cSJens Wiklander  * 3. If asynchronous notifications has been negotiated successfully, then
144ed8faf6cSJens Wiklander  *    the interrupt for asynchronous notifications should be unmasked
145ed8faf6cSJens Wiklander  *    during this call.
1466749e69cSJens Wiklander  *
147ed8faf6cSJens Wiklander  * Call register usage, OPTEE_SMC_CALL_WITH_ARG and
148ed8faf6cSJens Wiklander  * OPTEE_SMC_CALL_WITH_RPC_ARG:
149ed8faf6cSJens Wiklander  * a0	SMC Function ID, OPTEE_SMC_CALL_WITH_ARG or OPTEE_SMC_CALL_WITH_RPC_ARG
150617d8e8bSJens Wiklander  * a1	Upper 32 bits of a 64-bit physical pointer to a struct optee_msg_arg
151617d8e8bSJens Wiklander  * a2	Lower 32 bits of a 64-bit physical pointer to a struct optee_msg_arg
1524fb0a5ebSJens Wiklander  * a3	Cache settings, not used if physical pointer is in a predefined shared
1534fb0a5ebSJens Wiklander  *	memory area else per OPTEE_SMC_SHM_*
1544fb0a5ebSJens Wiklander  * a4-6	Not used
1554fb0a5ebSJens Wiklander  * a7	Hypervisor Client ID register
1564fb0a5ebSJens Wiklander  *
157ed8faf6cSJens Wiklander  * Call register usage, OPTEE_SMC_CALL_WITH_REGD_ARG:
158ed8faf6cSJens Wiklander  * a0	SMC Function ID, OPTEE_SMC_CALL_WITH_REGD_ARG
159ed8faf6cSJens Wiklander  * a1	Upper 32 bits of a 64-bit shared memory cookie
160ed8faf6cSJens Wiklander  * a2	Lower 32 bits of a 64-bit shared memory cookie
161ed8faf6cSJens Wiklander  * a3	Offset of the struct optee_msg_arg in the shared memory with the
162ed8faf6cSJens Wiklander  *	supplied cookie
163ed8faf6cSJens Wiklander  * a4-6	Not used
164ed8faf6cSJens Wiklander  * a7	Hypervisor Client ID register
165ed8faf6cSJens Wiklander  *
1664fb0a5ebSJens Wiklander  * Normal return register usage:
1674fb0a5ebSJens Wiklander  * a0	Return value, OPTEE_SMC_RETURN_*
1684fb0a5ebSJens Wiklander  * a1-3	Not used
1694fb0a5ebSJens Wiklander  * a4-7	Preserved
1704fb0a5ebSJens Wiklander  *
1714fb0a5ebSJens Wiklander  * OPTEE_SMC_RETURN_ETHREAD_LIMIT return register usage:
1724fb0a5ebSJens Wiklander  * a0	Return value, OPTEE_SMC_RETURN_ETHREAD_LIMIT
1734fb0a5ebSJens Wiklander  * a1-3	Preserved
1744fb0a5ebSJens Wiklander  * a4-7	Preserved
1754fb0a5ebSJens Wiklander  *
1764fb0a5ebSJens Wiklander  * RPC return register usage:
1774fb0a5ebSJens Wiklander  * a0	Return value, OPTEE_SMC_RETURN_IS_RPC(val)
1784fb0a5ebSJens Wiklander  * a1-2	RPC parameters
1794fb0a5ebSJens Wiklander  * a3-7	Resume information, must be preserved
1804fb0a5ebSJens Wiklander  *
1814fb0a5ebSJens Wiklander  * Possible return values:
1824fb0a5ebSJens Wiklander  * OPTEE_SMC_RETURN_UNKNOWN_FUNCTION	Trusted OS does not recognize this
1834fb0a5ebSJens Wiklander  *					function.
1844fb0a5ebSJens Wiklander  * OPTEE_SMC_RETURN_OK			Call completed, result updated in
1854fb0a5ebSJens Wiklander  *					the previously supplied struct
1864fb0a5ebSJens Wiklander  *					optee_msg_arg.
1874fb0a5ebSJens Wiklander  * OPTEE_SMC_RETURN_ETHREAD_LIMIT	Number of Trusted OS threads exceeded,
1884fb0a5ebSJens Wiklander  *					try again later.
189bed13b5fSBjorn Helgaas  * OPTEE_SMC_RETURN_EBADADDR		Bad physical pointer to struct
1904fb0a5ebSJens Wiklander  *					optee_msg_arg.
1914fb0a5ebSJens Wiklander  * OPTEE_SMC_RETURN_EBADCMD		Bad/unknown cmd in struct optee_msg_arg
1924fb0a5ebSJens Wiklander  * OPTEE_SMC_RETURN_IS_RPC()		Call suspended by RPC call to normal
1934fb0a5ebSJens Wiklander  *					world.
1944fb0a5ebSJens Wiklander  */
1954fb0a5ebSJens Wiklander #define OPTEE_SMC_FUNCID_CALL_WITH_ARG OPTEE_MSG_FUNCID_CALL_WITH_ARG
1964fb0a5ebSJens Wiklander #define OPTEE_SMC_CALL_WITH_ARG \
1974fb0a5ebSJens Wiklander 	OPTEE_SMC_STD_CALL_VAL(OPTEE_SMC_FUNCID_CALL_WITH_ARG)
198ed8faf6cSJens Wiklander #define OPTEE_SMC_CALL_WITH_RPC_ARG \
199ed8faf6cSJens Wiklander 	OPTEE_SMC_STD_CALL_VAL(OPTEE_SMC_FUNCID_CALL_WITH_RPC_ARG)
200ed8faf6cSJens Wiklander #define OPTEE_SMC_CALL_WITH_REGD_ARG \
201ed8faf6cSJens Wiklander 	OPTEE_SMC_STD_CALL_VAL(OPTEE_SMC_FUNCID_CALL_WITH_REGD_ARG)
2024fb0a5ebSJens Wiklander 
2034fb0a5ebSJens Wiklander /*
2044fb0a5ebSJens Wiklander  * Get Shared Memory Config
2054fb0a5ebSJens Wiklander  *
2064fb0a5ebSJens Wiklander  * Returns the Secure/Non-secure shared memory config.
2074fb0a5ebSJens Wiklander  *
2084fb0a5ebSJens Wiklander  * Call register usage:
2094fb0a5ebSJens Wiklander  * a0	SMC Function ID, OPTEE_SMC_GET_SHM_CONFIG
2104fb0a5ebSJens Wiklander  * a1-6	Not used
2114fb0a5ebSJens Wiklander  * a7	Hypervisor Client ID register
2124fb0a5ebSJens Wiklander  *
2134fb0a5ebSJens Wiklander  * Have config return register usage:
2144fb0a5ebSJens Wiklander  * a0	OPTEE_SMC_RETURN_OK
2154fb0a5ebSJens Wiklander  * a1	Physical address of start of SHM
216b66527eeSJiang Jian  * a2	Size of SHM
2174fb0a5ebSJens Wiklander  * a3	Cache settings of memory, as defined by the
2184fb0a5ebSJens Wiklander  *	OPTEE_SMC_SHM_* values above
2194fb0a5ebSJens Wiklander  * a4-7	Preserved
2204fb0a5ebSJens Wiklander  *
2214fb0a5ebSJens Wiklander  * Not available register usage:
2224fb0a5ebSJens Wiklander  * a0	OPTEE_SMC_RETURN_ENOTAVAIL
2234fb0a5ebSJens Wiklander  * a1-3 Not used
2244fb0a5ebSJens Wiklander  * a4-7	Preserved
2254fb0a5ebSJens Wiklander  */
2264fb0a5ebSJens Wiklander #define OPTEE_SMC_FUNCID_GET_SHM_CONFIG	7
2274fb0a5ebSJens Wiklander #define OPTEE_SMC_GET_SHM_CONFIG \
2284fb0a5ebSJens Wiklander 	OPTEE_SMC_FAST_CALL_VAL(OPTEE_SMC_FUNCID_GET_SHM_CONFIG)
2294fb0a5ebSJens Wiklander 
2304fb0a5ebSJens Wiklander struct optee_smc_get_shm_config_result {
2314fb0a5ebSJens Wiklander 	unsigned long status;
2324fb0a5ebSJens Wiklander 	unsigned long start;
2334fb0a5ebSJens Wiklander 	unsigned long size;
2344fb0a5ebSJens Wiklander 	unsigned long settings;
2354fb0a5ebSJens Wiklander };
2364fb0a5ebSJens Wiklander 
2374fb0a5ebSJens Wiklander /*
2384fb0a5ebSJens Wiklander  * Exchanges capabilities between normal world and secure world
2394fb0a5ebSJens Wiklander  *
2404fb0a5ebSJens Wiklander  * Call register usage:
2414fb0a5ebSJens Wiklander  * a0	SMC Function ID, OPTEE_SMC_EXCHANGE_CAPABILITIES
2424fb0a5ebSJens Wiklander  * a1	bitfield of normal world capabilities OPTEE_SMC_NSEC_CAP_*
2434fb0a5ebSJens Wiklander  * a2-6	Not used
2444fb0a5ebSJens Wiklander  * a7	Hypervisor Client ID register
2454fb0a5ebSJens Wiklander  *
2464fb0a5ebSJens Wiklander  * Normal return register usage:
2474fb0a5ebSJens Wiklander  * a0	OPTEE_SMC_RETURN_OK
2484fb0a5ebSJens Wiklander  * a1	bitfield of secure world capabilities OPTEE_SMC_SEC_CAP_*
2496749e69cSJens Wiklander  * a2	The maximum secure world notification number
250ed8faf6cSJens Wiklander  * a3	Bit[7:0]: Number of parameters needed for RPC to be supplied
251ed8faf6cSJens Wiklander  *		  as the second MSG arg struct for
252ed8faf6cSJens Wiklander  *		  OPTEE_SMC_CALL_WITH_ARG
253ed8faf6cSJens Wiklander  *	Bit[31:8]: Reserved (MBZ)
254ed8faf6cSJens Wiklander  * a4-7	Preserved
2554fb0a5ebSJens Wiklander  *
2564fb0a5ebSJens Wiklander  * Error return register usage:
2574fb0a5ebSJens Wiklander  * a0	OPTEE_SMC_RETURN_ENOTAVAIL, can't use the capabilities from normal world
2584fb0a5ebSJens Wiklander  * a1	bitfield of secure world capabilities OPTEE_SMC_SEC_CAP_*
2594fb0a5ebSJens Wiklander  * a2-7 Preserved
2604fb0a5ebSJens Wiklander  */
2614fb0a5ebSJens Wiklander /* Normal world works as a uniprocessor system */
2624fb0a5ebSJens Wiklander #define OPTEE_SMC_NSEC_CAP_UNIPROCESSOR		BIT(0)
2634fb0a5ebSJens Wiklander /* Secure world has reserved shared memory for normal world to use */
2644fb0a5ebSJens Wiklander #define OPTEE_SMC_SEC_CAP_HAVE_RESERVED_SHM	BIT(0)
2654fb0a5ebSJens Wiklander /* Secure world can communicate via previously unregistered shared memory */
2664fb0a5ebSJens Wiklander #define OPTEE_SMC_SEC_CAP_UNREGISTERED_SHM	BIT(1)
267de5c6dfcSVolodymyr Babchuk 
268de5c6dfcSVolodymyr Babchuk /*
269de5c6dfcSVolodymyr Babchuk  * Secure world supports commands "register/unregister shared memory",
270de5c6dfcSVolodymyr Babchuk  * secure world accepts command buffers located in any parts of non-secure RAM
271de5c6dfcSVolodymyr Babchuk  */
272de5c6dfcSVolodymyr Babchuk #define OPTEE_SMC_SEC_CAP_DYNAMIC_SHM		BIT(2)
273617d8e8bSJens Wiklander /* Secure world is built with virtualization support */
274617d8e8bSJens Wiklander #define OPTEE_SMC_SEC_CAP_VIRTUALIZATION	BIT(3)
275617d8e8bSJens Wiklander /* Secure world supports Shared Memory with a NULL reference */
276ba171d3fSCedric Neveux #define OPTEE_SMC_SEC_CAP_MEMREF_NULL		BIT(4)
2776749e69cSJens Wiklander /* Secure world supports asynchronous notification of normal world */
2786749e69cSJens Wiklander #define OPTEE_SMC_SEC_CAP_ASYNC_NOTIF		BIT(5)
279ed8faf6cSJens Wiklander /* Secure world supports pre-allocating RPC arg struct */
280ed8faf6cSJens Wiklander #define OPTEE_SMC_SEC_CAP_RPC_ARG		BIT(6)
281ba171d3fSCedric Neveux 
2824fb0a5ebSJens Wiklander #define OPTEE_SMC_FUNCID_EXCHANGE_CAPABILITIES	9
2834fb0a5ebSJens Wiklander #define OPTEE_SMC_EXCHANGE_CAPABILITIES \
2844fb0a5ebSJens Wiklander 	OPTEE_SMC_FAST_CALL_VAL(OPTEE_SMC_FUNCID_EXCHANGE_CAPABILITIES)
2854fb0a5ebSJens Wiklander 
2864fb0a5ebSJens Wiklander struct optee_smc_exchange_capabilities_result {
2874fb0a5ebSJens Wiklander 	unsigned long status;
2884fb0a5ebSJens Wiklander 	unsigned long capabilities;
2896749e69cSJens Wiklander 	unsigned long max_notif_value;
290ed8faf6cSJens Wiklander 	unsigned long data;
2914fb0a5ebSJens Wiklander };
2924fb0a5ebSJens Wiklander 
2934fb0a5ebSJens Wiklander /*
2944fb0a5ebSJens Wiklander  * Disable and empties cache of shared memory objects
2954fb0a5ebSJens Wiklander  *
2964fb0a5ebSJens Wiklander  * Secure world can cache frequently used shared memory objects, for
2974fb0a5ebSJens Wiklander  * example objects used as RPC arguments. When secure world is idle this
2984fb0a5ebSJens Wiklander  * function returns one shared memory reference to free. To disable the
2994fb0a5ebSJens Wiklander  * cache and free all cached objects this function has to be called until
3004fb0a5ebSJens Wiklander  * it returns OPTEE_SMC_RETURN_ENOTAVAIL.
3014fb0a5ebSJens Wiklander  *
3024fb0a5ebSJens Wiklander  * Call register usage:
3034fb0a5ebSJens Wiklander  * a0	SMC Function ID, OPTEE_SMC_DISABLE_SHM_CACHE
3044fb0a5ebSJens Wiklander  * a1-6	Not used
3054fb0a5ebSJens Wiklander  * a7	Hypervisor Client ID register
3064fb0a5ebSJens Wiklander  *
3074fb0a5ebSJens Wiklander  * Normal return register usage:
3084fb0a5ebSJens Wiklander  * a0	OPTEE_SMC_RETURN_OK
309617d8e8bSJens Wiklander  * a1	Upper 32 bits of a 64-bit Shared memory cookie
310617d8e8bSJens Wiklander  * a2	Lower 32 bits of a 64-bit Shared memory cookie
3114fb0a5ebSJens Wiklander  * a3-7	Preserved
3124fb0a5ebSJens Wiklander  *
3134fb0a5ebSJens Wiklander  * Cache empty return register usage:
3144fb0a5ebSJens Wiklander  * a0	OPTEE_SMC_RETURN_ENOTAVAIL
3154fb0a5ebSJens Wiklander  * a1-7	Preserved
3164fb0a5ebSJens Wiklander  *
3174fb0a5ebSJens Wiklander  * Not idle return register usage:
3184fb0a5ebSJens Wiklander  * a0	OPTEE_SMC_RETURN_EBUSY
3194fb0a5ebSJens Wiklander  * a1-7	Preserved
3204fb0a5ebSJens Wiklander  */
3214fb0a5ebSJens Wiklander #define OPTEE_SMC_FUNCID_DISABLE_SHM_CACHE	10
3224fb0a5ebSJens Wiklander #define OPTEE_SMC_DISABLE_SHM_CACHE \
3234fb0a5ebSJens Wiklander 	OPTEE_SMC_FAST_CALL_VAL(OPTEE_SMC_FUNCID_DISABLE_SHM_CACHE)
3244fb0a5ebSJens Wiklander 
3254fb0a5ebSJens Wiklander struct optee_smc_disable_shm_cache_result {
3264fb0a5ebSJens Wiklander 	unsigned long status;
3274fb0a5ebSJens Wiklander 	unsigned long shm_upper32;
3284fb0a5ebSJens Wiklander 	unsigned long shm_lower32;
3294fb0a5ebSJens Wiklander 	unsigned long reserved0;
3304fb0a5ebSJens Wiklander };
3314fb0a5ebSJens Wiklander 
3324fb0a5ebSJens Wiklander /*
3334fb0a5ebSJens Wiklander  * Enable cache of shared memory objects
3344fb0a5ebSJens Wiklander  *
3354fb0a5ebSJens Wiklander  * Secure world can cache frequently used shared memory objects, for
3364fb0a5ebSJens Wiklander  * example objects used as RPC arguments. When secure world is idle this
3374fb0a5ebSJens Wiklander  * function returns OPTEE_SMC_RETURN_OK and the cache is enabled. If
3384fb0a5ebSJens Wiklander  * secure world isn't idle OPTEE_SMC_RETURN_EBUSY is returned.
3394fb0a5ebSJens Wiklander  *
3404fb0a5ebSJens Wiklander  * Call register usage:
3414fb0a5ebSJens Wiklander  * a0	SMC Function ID, OPTEE_SMC_ENABLE_SHM_CACHE
3424fb0a5ebSJens Wiklander  * a1-6	Not used
3434fb0a5ebSJens Wiklander  * a7	Hypervisor Client ID register
3444fb0a5ebSJens Wiklander  *
3454fb0a5ebSJens Wiklander  * Normal return register usage:
3464fb0a5ebSJens Wiklander  * a0	OPTEE_SMC_RETURN_OK
3474fb0a5ebSJens Wiklander  * a1-7	Preserved
3484fb0a5ebSJens Wiklander  *
3494fb0a5ebSJens Wiklander  * Not idle return register usage:
3504fb0a5ebSJens Wiklander  * a0	OPTEE_SMC_RETURN_EBUSY
3514fb0a5ebSJens Wiklander  * a1-7	Preserved
3524fb0a5ebSJens Wiklander  */
3534fb0a5ebSJens Wiklander #define OPTEE_SMC_FUNCID_ENABLE_SHM_CACHE	11
3544fb0a5ebSJens Wiklander #define OPTEE_SMC_ENABLE_SHM_CACHE \
3554fb0a5ebSJens Wiklander 	OPTEE_SMC_FAST_CALL_VAL(OPTEE_SMC_FUNCID_ENABLE_SHM_CACHE)
3564fb0a5ebSJens Wiklander 
3574fb0a5ebSJens Wiklander /*
358617d8e8bSJens Wiklander  * Query OP-TEE about number of supported threads
359617d8e8bSJens Wiklander  *
360617d8e8bSJens Wiklander  * Normal World OS or Hypervisor issues this call to find out how many
361617d8e8bSJens Wiklander  * threads OP-TEE supports. That is how many standard calls can be issued
362617d8e8bSJens Wiklander  * in parallel before OP-TEE will return OPTEE_SMC_RETURN_ETHREAD_LIMIT.
363617d8e8bSJens Wiklander  *
364617d8e8bSJens Wiklander  * Call requests usage:
365617d8e8bSJens Wiklander  * a0	SMC Function ID, OPTEE_SMC_GET_THREAD_COUNT
366617d8e8bSJens Wiklander  * a1-6 Not used
367617d8e8bSJens Wiklander  * a7	Hypervisor Client ID register
368617d8e8bSJens Wiklander  *
369617d8e8bSJens Wiklander  * Normal return register usage:
370617d8e8bSJens Wiklander  * a0	OPTEE_SMC_RETURN_OK
371617d8e8bSJens Wiklander  * a1	Number of threads
372617d8e8bSJens Wiklander  * a2-7 Preserved
373617d8e8bSJens Wiklander  *
374617d8e8bSJens Wiklander  * Error return:
375617d8e8bSJens Wiklander  * a0	OPTEE_SMC_RETURN_UNKNOWN_FUNCTION   Requested call is not implemented
376617d8e8bSJens Wiklander  * a1-7	Preserved
377617d8e8bSJens Wiklander  */
378617d8e8bSJens Wiklander #define OPTEE_SMC_FUNCID_GET_THREAD_COUNT	15
379617d8e8bSJens Wiklander #define OPTEE_SMC_GET_THREAD_COUNT \
380617d8e8bSJens Wiklander 	OPTEE_SMC_FAST_CALL_VAL(OPTEE_SMC_FUNCID_GET_THREAD_COUNT)
381617d8e8bSJens Wiklander 
382617d8e8bSJens Wiklander /*
3836749e69cSJens Wiklander  * Inform OP-TEE that normal world is able to receive asynchronous
3846749e69cSJens Wiklander  * notifications.
3856749e69cSJens Wiklander  *
3866749e69cSJens Wiklander  * Call requests usage:
3876749e69cSJens Wiklander  * a0	SMC Function ID, OPTEE_SMC_ENABLE_ASYNC_NOTIF
3886749e69cSJens Wiklander  * a1-6	Not used
3896749e69cSJens Wiklander  * a7	Hypervisor Client ID register
3906749e69cSJens Wiklander  *
3916749e69cSJens Wiklander  * Normal return register usage:
3926749e69cSJens Wiklander  * a0	OPTEE_SMC_RETURN_OK
3936749e69cSJens Wiklander  * a1-7	Preserved
3946749e69cSJens Wiklander  *
3956749e69cSJens Wiklander  * Not supported return register usage:
3966749e69cSJens Wiklander  * a0	OPTEE_SMC_RETURN_ENOTAVAIL
3976749e69cSJens Wiklander  * a1-7	Preserved
3986749e69cSJens Wiklander  */
3996749e69cSJens Wiklander #define OPTEE_SMC_FUNCID_ENABLE_ASYNC_NOTIF	16
4006749e69cSJens Wiklander #define OPTEE_SMC_ENABLE_ASYNC_NOTIF \
4016749e69cSJens Wiklander 	OPTEE_SMC_FAST_CALL_VAL(OPTEE_SMC_FUNCID_ENABLE_ASYNC_NOTIF)
4026749e69cSJens Wiklander 
4036749e69cSJens Wiklander /*
4046749e69cSJens Wiklander  * Retrieve a value of notifications pending since the last call of this
4056749e69cSJens Wiklander  * function.
4066749e69cSJens Wiklander  *
4076749e69cSJens Wiklander  * OP-TEE keeps a record of all posted values. When an interrupt is
4086749e69cSJens Wiklander  * received which indicates that there are posted values this function
4096749e69cSJens Wiklander  * should be called until all pended values have been retrieved. When a
4106749e69cSJens Wiklander  * value is retrieved, it's cleared from the record in secure world.
4116749e69cSJens Wiklander  *
412ed8faf6cSJens Wiklander  * It is expected that this function is called from an interrupt handler
413ed8faf6cSJens Wiklander  * in normal world.
414ed8faf6cSJens Wiklander  *
4156749e69cSJens Wiklander  * Call requests usage:
4166749e69cSJens Wiklander  * a0	SMC Function ID, OPTEE_SMC_GET_ASYNC_NOTIF_VALUE
4176749e69cSJens Wiklander  * a1-6	Not used
4186749e69cSJens Wiklander  * a7	Hypervisor Client ID register
4196749e69cSJens Wiklander  *
4206749e69cSJens Wiklander  * Normal return register usage:
4216749e69cSJens Wiklander  * a0	OPTEE_SMC_RETURN_OK
4226749e69cSJens Wiklander  * a1	value
4236749e69cSJens Wiklander  * a2	Bit[0]: OPTEE_SMC_ASYNC_NOTIF_VALUE_VALID if the value in a1 is
4246749e69cSJens Wiklander  *		valid, else 0 if no values where pending
4256749e69cSJens Wiklander  * a2	Bit[1]: OPTEE_SMC_ASYNC_NOTIF_VALUE_PENDING if another value is
4266749e69cSJens Wiklander  *		pending, else 0.
4276749e69cSJens Wiklander  *	Bit[31:2]: MBZ
4286749e69cSJens Wiklander  * a3-7	Preserved
4296749e69cSJens Wiklander  *
4306749e69cSJens Wiklander  * Not supported return register usage:
4316749e69cSJens Wiklander  * a0	OPTEE_SMC_RETURN_ENOTAVAIL
4326749e69cSJens Wiklander  * a1-7	Preserved
4336749e69cSJens Wiklander  */
4346749e69cSJens Wiklander #define OPTEE_SMC_ASYNC_NOTIF_VALUE_VALID	BIT(0)
4356749e69cSJens Wiklander #define OPTEE_SMC_ASYNC_NOTIF_VALUE_PENDING	BIT(1)
4366749e69cSJens Wiklander 
4376749e69cSJens Wiklander /*
4386749e69cSJens Wiklander  * Notification that OP-TEE expects a yielding call to do some bottom half
4396749e69cSJens Wiklander  * work in a driver.
4406749e69cSJens Wiklander  */
4416749e69cSJens Wiklander #define OPTEE_SMC_ASYNC_NOTIF_VALUE_DO_BOTTOM_HALF	0
4426749e69cSJens Wiklander 
4436749e69cSJens Wiklander #define OPTEE_SMC_FUNCID_GET_ASYNC_NOTIF_VALUE	17
4446749e69cSJens Wiklander #define OPTEE_SMC_GET_ASYNC_NOTIF_VALUE \
4456749e69cSJens Wiklander 	OPTEE_SMC_FAST_CALL_VAL(OPTEE_SMC_FUNCID_GET_ASYNC_NOTIF_VALUE)
4466749e69cSJens Wiklander 
447ed8faf6cSJens Wiklander /* See OPTEE_SMC_CALL_WITH_RPC_ARG above */
448ed8faf6cSJens Wiklander #define OPTEE_SMC_FUNCID_CALL_WITH_RPC_ARG	18
449ed8faf6cSJens Wiklander 
450ed8faf6cSJens Wiklander /* See OPTEE_SMC_CALL_WITH_REGD_ARG above */
451ed8faf6cSJens Wiklander #define OPTEE_SMC_FUNCID_CALL_WITH_REGD_ARG	19
452ed8faf6cSJens Wiklander 
4536749e69cSJens Wiklander /*
45439e6519aSDavid Wang  * Resume from RPC (for example after processing a foreign interrupt)
4554fb0a5ebSJens Wiklander  *
4564fb0a5ebSJens Wiklander  * Call register usage:
4574fb0a5ebSJens Wiklander  * a0	SMC Function ID, OPTEE_SMC_CALL_RETURN_FROM_RPC
4584fb0a5ebSJens Wiklander  * a1-3	Value of a1-3 when OPTEE_SMC_CALL_WITH_ARG returned
4594fb0a5ebSJens Wiklander  *	OPTEE_SMC_RETURN_RPC in a0
4604fb0a5ebSJens Wiklander  *
4614fb0a5ebSJens Wiklander  * Return register usage is the same as for OPTEE_SMC_*CALL_WITH_ARG above.
4624fb0a5ebSJens Wiklander  *
4634fb0a5ebSJens Wiklander  * Possible return values
4644fb0a5ebSJens Wiklander  * OPTEE_SMC_RETURN_UNKNOWN_FUNCTION	Trusted OS does not recognize this
4654fb0a5ebSJens Wiklander  *					function.
4664fb0a5ebSJens Wiklander  * OPTEE_SMC_RETURN_OK			Original call completed, result
4674fb0a5ebSJens Wiklander  *					updated in the previously supplied.
4684fb0a5ebSJens Wiklander  *					struct optee_msg_arg
4694fb0a5ebSJens Wiklander  * OPTEE_SMC_RETURN_RPC			Call suspended by RPC call to normal
4704fb0a5ebSJens Wiklander  *					world.
4714fb0a5ebSJens Wiklander  * OPTEE_SMC_RETURN_ERESUME		Resume failed, the opaque resume
4724fb0a5ebSJens Wiklander  *					information was corrupt.
4734fb0a5ebSJens Wiklander  */
4744fb0a5ebSJens Wiklander #define OPTEE_SMC_FUNCID_RETURN_FROM_RPC	3
4754fb0a5ebSJens Wiklander #define OPTEE_SMC_CALL_RETURN_FROM_RPC \
4764fb0a5ebSJens Wiklander 	OPTEE_SMC_STD_CALL_VAL(OPTEE_SMC_FUNCID_RETURN_FROM_RPC)
4774fb0a5ebSJens Wiklander 
4784fb0a5ebSJens Wiklander #define OPTEE_SMC_RETURN_RPC_PREFIX_MASK	0xFFFF0000
4794fb0a5ebSJens Wiklander #define OPTEE_SMC_RETURN_RPC_PREFIX		0xFFFF0000
4804fb0a5ebSJens Wiklander #define OPTEE_SMC_RETURN_RPC_FUNC_MASK		0x0000FFFF
4814fb0a5ebSJens Wiklander 
4824fb0a5ebSJens Wiklander #define OPTEE_SMC_RETURN_GET_RPC_FUNC(ret) \
4834fb0a5ebSJens Wiklander 	((ret) & OPTEE_SMC_RETURN_RPC_FUNC_MASK)
4844fb0a5ebSJens Wiklander 
4854fb0a5ebSJens Wiklander #define OPTEE_SMC_RPC_VAL(func)		((func) | OPTEE_SMC_RETURN_RPC_PREFIX)
4864fb0a5ebSJens Wiklander 
4874fb0a5ebSJens Wiklander /*
4884fb0a5ebSJens Wiklander  * Allocate memory for RPC parameter passing. The memory is used to hold a
4894fb0a5ebSJens Wiklander  * struct optee_msg_arg.
4904fb0a5ebSJens Wiklander  *
4914fb0a5ebSJens Wiklander  * "Call" register usage:
4924fb0a5ebSJens Wiklander  * a0	This value, OPTEE_SMC_RETURN_RPC_ALLOC
4934fb0a5ebSJens Wiklander  * a1	Size in bytes of required argument memory
4944fb0a5ebSJens Wiklander  * a2	Not used
4954fb0a5ebSJens Wiklander  * a3	Resume information, must be preserved
4964fb0a5ebSJens Wiklander  * a4-5	Not used
4974fb0a5ebSJens Wiklander  * a6-7	Resume information, must be preserved
4984fb0a5ebSJens Wiklander  *
4994fb0a5ebSJens Wiklander  * "Return" register usage:
5004fb0a5ebSJens Wiklander  * a0	SMC Function ID, OPTEE_SMC_CALL_RETURN_FROM_RPC.
501617d8e8bSJens Wiklander  * a1	Upper 32 bits of 64-bit physical pointer to allocated
5024fb0a5ebSJens Wiklander  *	memory, (a1 == 0 && a2 == 0) if size was 0 or if memory can't
5034fb0a5ebSJens Wiklander  *	be allocated.
504617d8e8bSJens Wiklander  * a2	Lower 32 bits of 64-bit physical pointer to allocated
5054fb0a5ebSJens Wiklander  *	memory, (a1 == 0 && a2 == 0) if size was 0 or if memory can't
5064fb0a5ebSJens Wiklander  *	be allocated
5074fb0a5ebSJens Wiklander  * a3	Preserved
508617d8e8bSJens Wiklander  * a4	Upper 32 bits of 64-bit Shared memory cookie used when freeing
5094fb0a5ebSJens Wiklander  *	the memory or doing an RPC
510617d8e8bSJens Wiklander  * a5	Lower 32 bits of 64-bit Shared memory cookie used when freeing
5114fb0a5ebSJens Wiklander  *	the memory or doing an RPC
5124fb0a5ebSJens Wiklander  * a6-7	Preserved
5134fb0a5ebSJens Wiklander  */
5144fb0a5ebSJens Wiklander #define OPTEE_SMC_RPC_FUNC_ALLOC	0
5154fb0a5ebSJens Wiklander #define OPTEE_SMC_RETURN_RPC_ALLOC \
5164fb0a5ebSJens Wiklander 	OPTEE_SMC_RPC_VAL(OPTEE_SMC_RPC_FUNC_ALLOC)
5174fb0a5ebSJens Wiklander 
5184fb0a5ebSJens Wiklander /*
5194fb0a5ebSJens Wiklander  * Free memory previously allocated by OPTEE_SMC_RETURN_RPC_ALLOC
5204fb0a5ebSJens Wiklander  *
5214fb0a5ebSJens Wiklander  * "Call" register usage:
5224fb0a5ebSJens Wiklander  * a0	This value, OPTEE_SMC_RETURN_RPC_FREE
523617d8e8bSJens Wiklander  * a1	Upper 32 bits of 64-bit shared memory cookie belonging to this
5244fb0a5ebSJens Wiklander  *	argument memory
525617d8e8bSJens Wiklander  * a2	Lower 32 bits of 64-bit shared memory cookie belonging to this
5264fb0a5ebSJens Wiklander  *	argument memory
5274fb0a5ebSJens Wiklander  * a3-7	Resume information, must be preserved
5284fb0a5ebSJens Wiklander  *
5294fb0a5ebSJens Wiklander  * "Return" register usage:
5304fb0a5ebSJens Wiklander  * a0	SMC Function ID, OPTEE_SMC_CALL_RETURN_FROM_RPC.
5314fb0a5ebSJens Wiklander  * a1-2	Not used
5324fb0a5ebSJens Wiklander  * a3-7	Preserved
5334fb0a5ebSJens Wiklander  */
5344fb0a5ebSJens Wiklander #define OPTEE_SMC_RPC_FUNC_FREE		2
5354fb0a5ebSJens Wiklander #define OPTEE_SMC_RETURN_RPC_FREE \
5364fb0a5ebSJens Wiklander 	OPTEE_SMC_RPC_VAL(OPTEE_SMC_RPC_FUNC_FREE)
5374fb0a5ebSJens Wiklander 
5384fb0a5ebSJens Wiklander /*
539617d8e8bSJens Wiklander  * Deliver a foreign interrupt in normal world.
5404fb0a5ebSJens Wiklander  *
5414fb0a5ebSJens Wiklander  * "Call" register usage:
54239e6519aSDavid Wang  * a0	OPTEE_SMC_RETURN_RPC_FOREIGN_INTR
5434fb0a5ebSJens Wiklander  * a1-7	Resume information, must be preserved
5444fb0a5ebSJens Wiklander  *
5454fb0a5ebSJens Wiklander  * "Return" register usage:
5464fb0a5ebSJens Wiklander  * a0	SMC Function ID, OPTEE_SMC_CALL_RETURN_FROM_RPC.
5474fb0a5ebSJens Wiklander  * a1-7	Preserved
5484fb0a5ebSJens Wiklander  */
54939e6519aSDavid Wang #define OPTEE_SMC_RPC_FUNC_FOREIGN_INTR	4
55039e6519aSDavid Wang #define OPTEE_SMC_RETURN_RPC_FOREIGN_INTR \
55139e6519aSDavid Wang 	OPTEE_SMC_RPC_VAL(OPTEE_SMC_RPC_FUNC_FOREIGN_INTR)
5524fb0a5ebSJens Wiklander 
5534fb0a5ebSJens Wiklander /*
5544fb0a5ebSJens Wiklander  * Do an RPC request. The supplied struct optee_msg_arg tells which
5554fb0a5ebSJens Wiklander  * request to do and the parameters for the request. The following fields
5564fb0a5ebSJens Wiklander  * are used (the rest are unused):
5574fb0a5ebSJens Wiklander  * - cmd		the Request ID
5584fb0a5ebSJens Wiklander  * - ret		return value of the request, filled in by normal world
5594fb0a5ebSJens Wiklander  * - num_params		number of parameters for the request
5604fb0a5ebSJens Wiklander  * - params		the parameters
5614fb0a5ebSJens Wiklander  * - param_attrs	attributes of the parameters
5624fb0a5ebSJens Wiklander  *
5634fb0a5ebSJens Wiklander  * "Call" register usage:
5644fb0a5ebSJens Wiklander  * a0	OPTEE_SMC_RETURN_RPC_CMD
565617d8e8bSJens Wiklander  * a1	Upper 32 bits of a 64-bit Shared memory cookie holding a
5664fb0a5ebSJens Wiklander  *	struct optee_msg_arg, must be preserved, only the data should
5674fb0a5ebSJens Wiklander  *	be updated
568617d8e8bSJens Wiklander  * a2	Lower 32 bits of a 64-bit Shared memory cookie holding a
5694fb0a5ebSJens Wiklander  *	struct optee_msg_arg, must be preserved, only the data should
5704fb0a5ebSJens Wiklander  *	be updated
5714fb0a5ebSJens Wiklander  * a3-7	Resume information, must be preserved
5724fb0a5ebSJens Wiklander  *
5734fb0a5ebSJens Wiklander  * "Return" register usage:
5744fb0a5ebSJens Wiklander  * a0	SMC Function ID, OPTEE_SMC_CALL_RETURN_FROM_RPC.
5754fb0a5ebSJens Wiklander  * a1-2	Not used
5764fb0a5ebSJens Wiklander  * a3-7	Preserved
5774fb0a5ebSJens Wiklander  */
5784fb0a5ebSJens Wiklander #define OPTEE_SMC_RPC_FUNC_CMD		5
5794fb0a5ebSJens Wiklander #define OPTEE_SMC_RETURN_RPC_CMD \
5804fb0a5ebSJens Wiklander 	OPTEE_SMC_RPC_VAL(OPTEE_SMC_RPC_FUNC_CMD)
5814fb0a5ebSJens Wiklander 
5824fb0a5ebSJens Wiklander /* Returned in a0 */
5834fb0a5ebSJens Wiklander #define OPTEE_SMC_RETURN_UNKNOWN_FUNCTION 0xFFFFFFFF
5844fb0a5ebSJens Wiklander 
5854fb0a5ebSJens Wiklander /* Returned in a0 only from Trusted OS functions */
5864fb0a5ebSJens Wiklander #define OPTEE_SMC_RETURN_OK		0x0
5874fb0a5ebSJens Wiklander #define OPTEE_SMC_RETURN_ETHREAD_LIMIT	0x1
5884fb0a5ebSJens Wiklander #define OPTEE_SMC_RETURN_EBUSY		0x2
5894fb0a5ebSJens Wiklander #define OPTEE_SMC_RETURN_ERESUME	0x3
5904fb0a5ebSJens Wiklander #define OPTEE_SMC_RETURN_EBADADDR	0x4
5914fb0a5ebSJens Wiklander #define OPTEE_SMC_RETURN_EBADCMD	0x5
5924fb0a5ebSJens Wiklander #define OPTEE_SMC_RETURN_ENOMEM		0x6
5934fb0a5ebSJens Wiklander #define OPTEE_SMC_RETURN_ENOTAVAIL	0x7
5944fb0a5ebSJens Wiklander #define OPTEE_SMC_RETURN_IS_RPC(ret)	__optee_smc_return_is_rpc((ret))
5954fb0a5ebSJens Wiklander 
__optee_smc_return_is_rpc(u32 ret)5964fb0a5ebSJens Wiklander static inline bool __optee_smc_return_is_rpc(u32 ret)
5974fb0a5ebSJens Wiklander {
5984fb0a5ebSJens Wiklander 	return ret != OPTEE_SMC_RETURN_UNKNOWN_FUNCTION &&
5994fb0a5ebSJens Wiklander 	       (ret & OPTEE_SMC_RETURN_RPC_PREFIX_MASK) ==
6004fb0a5ebSJens Wiklander 			OPTEE_SMC_RETURN_RPC_PREFIX;
6014fb0a5ebSJens Wiklander }
6024fb0a5ebSJens Wiklander 
6034fb0a5ebSJens Wiklander #endif /* OPTEE_SMC_H */
604