xref: /rk3399_rockchip-uboot/include/optee_include/teesmc.h (revision 74eb6027432600de60ed1c8bf892f1f8243c2c8a)
1*abdd2437Shisping /*
2*abdd2437Shisping  * (C) Copyright 2017 Rockchip Electronics Co., Ltd
3*abdd2437Shisping  *
4*abdd2437Shisping  * SPDX-License-Identifier:     GPL-2.0+
5*abdd2437Shisping  */
6*abdd2437Shisping 
7*abdd2437Shisping #ifndef TEESMC_H
8*abdd2437Shisping #define TEESMC_H
9*abdd2437Shisping 
10*abdd2437Shisping #include <optee_include/tee_base_types.h>
11*abdd2437Shisping 
12*abdd2437Shisping #ifndef ASM
13*abdd2437Shisping /*
14*abdd2437Shisping  * This section depends on uint64_t, uint32_t uint8_t already being
15*abdd2437Shisping  * defined. Since this file is used in several different environments
16*abdd2437Shisping  * (secure world OS and normal world Linux kernel to start with) where
17*abdd2437Shisping  * stdint.h may not be available it's the responsibility of the one
18*abdd2437Shisping  * including this file to provide those types.
19*abdd2437Shisping  */
20*abdd2437Shisping 
21*abdd2437Shisping /*
22*abdd2437Shisping  * Trusted OS SMC interface.
23*abdd2437Shisping  *
24*abdd2437Shisping  * The SMC interface follows SMC Calling Convention
25*abdd2437Shisping  * (ARM_DEN0028A_SMC_Calling_Convention).
26*abdd2437Shisping  *
27*abdd2437Shisping  * The primary objective of this API is to provide a transport layer on
28*abdd2437Shisping  * which a Global Platform compliant TEE interfaces can be deployed. But the
29*abdd2437Shisping  * interface can also be used for other implementations.
30*abdd2437Shisping  *
31*abdd2437Shisping  * This file is divided in two parts.
32*abdd2437Shisping  * Part 1 deals with passing parameters to Trusted Applications running in
33*abdd2437Shisping  * a trusted OS in secure world.
34*abdd2437Shisping  * Part 2 deals with the lower level handling of the SMC.
35*abdd2437Shisping  */
36*abdd2437Shisping 
37*abdd2437Shisping /*
38*abdd2437Shisping  *******************************************************************************
39*abdd2437Shisping  * Part 1 - passing parameters to Trusted Applications
40*abdd2437Shisping  *******************************************************************************
41*abdd2437Shisping  */
42*abdd2437Shisping 
43*abdd2437Shisping /*
44*abdd2437Shisping  * Same values as TEE_PARAM_* from TEE Internal API
45*abdd2437Shisping  */
46*abdd2437Shisping #define TEESMC_ATTR_TYPE_NONE		0
47*abdd2437Shisping #define TEESMC_ATTR_TYPE_VALUE_INPUT	1
48*abdd2437Shisping #define TEESMC_ATTR_TYPE_VALUE_OUTPUT	2
49*abdd2437Shisping #define TEESMC_ATTR_TYPE_VALUE_INOUT	3
50*abdd2437Shisping #define TEESMC_ATTR_TYPE_MEMREF_INPUT	5
51*abdd2437Shisping #define TEESMC_ATTR_TYPE_MEMREF_OUTPUT	6
52*abdd2437Shisping #define TEESMC_ATTR_TYPE_MEMREF_INOUT	7
53*abdd2437Shisping 
54*abdd2437Shisping #define TEESMC_ATTR_TYPE_MASK		0x7
55*abdd2437Shisping 
56*abdd2437Shisping /*
57*abdd2437Shisping  * Meta parameter to be absorbed by the Secure OS and not passed
58*abdd2437Shisping  * to the Trusted Application.
59*abdd2437Shisping  *
60*abdd2437Shisping  * One example of this is a struct teesmc_meta_open_session which
61*abdd2437Shisping  * is added to TEESMC{32,64}_CMD_OPEN_SESSION.
62*abdd2437Shisping  */
63*abdd2437Shisping #define TEESMC_ATTR_META		0x8
64*abdd2437Shisping 
65*abdd2437Shisping /*
66*abdd2437Shisping  * Used as an indication from normal world of compatible cache usage.
67*abdd2437Shisping  * 'I' stands for inner cache and 'O' for outer cache.
68*abdd2437Shisping  */
69*abdd2437Shisping #define TEESMC_ATTR_CACHE_I_NONCACHE	0x0
70*abdd2437Shisping #define TEESMC_ATTR_CACHE_I_WRITE_THR	0x1
71*abdd2437Shisping #define TEESMC_ATTR_CACHE_I_WRITE_BACK	0x2
72*abdd2437Shisping #define TEESMC_ATTR_CACHE_O_NONCACHE	0x0
73*abdd2437Shisping #define TEESMC_ATTR_CACHE_O_WRITE_THR	0x4
74*abdd2437Shisping #define TEESMC_ATTR_CACHE_O_WRITE_BACK	0x8
75*abdd2437Shisping 
76*abdd2437Shisping #define TEESMC_ATTR_CACHE_NONCACHE	0x0
77*abdd2437Shisping #define TEESMC_ATTR_CACHE_DEFAULT	(TEESMC_ATTR_CACHE_I_WRITE_BACK | \
78*abdd2437Shisping 					 TEESMC_ATTR_CACHE_O_WRITE_BACK)
79*abdd2437Shisping 
80*abdd2437Shisping #define TEESMC_ATTR_CACHE_SHIFT		4
81*abdd2437Shisping #define TEESMC_ATTR_CACHE_MASK		0xf
82*abdd2437Shisping 
83*abdd2437Shisping #define TEESMC_CMD_OPEN_SESSION		0
84*abdd2437Shisping #define TEESMC_CMD_INVOKE_COMMAND	1
85*abdd2437Shisping #define TEESMC_CMD_CLOSE_SESSION	2
86*abdd2437Shisping #define TEESMC_CMD_CANCEL		3
87*abdd2437Shisping 
88*abdd2437Shisping /**
89*abdd2437Shisping  * struct teesmc32_param_memref - memory reference
90*abdd2437Shisping  * @buf_ptr: Address of the buffer
91*abdd2437Shisping  * @size: Size of the buffer
92*abdd2437Shisping  *
93*abdd2437Shisping  * Secure and normal world communicates pointer via physical address instead of
94*abdd2437Shisping  * the virtual address with is usually used for pointers. This is because
95*abdd2437Shisping  * Secure and normal world has completely independant memory mapping. Normal
96*abdd2437Shisping  * world can even have a hypervisor which need to translate the guest
97*abdd2437Shisping  * physical address (AKA IPA in ARM lingo) to a real physical address
98*abdd2437Shisping  * before passing the structure to secure world.
99*abdd2437Shisping  */
100*abdd2437Shisping struct teesmc32_param_memref {
101*abdd2437Shisping 	uint32_t buf_ptr;
102*abdd2437Shisping 	uint32_t size;
103*abdd2437Shisping };
104*abdd2437Shisping 
105*abdd2437Shisping /**
106*abdd2437Shisping  * struct teesmc32_param_memref - memory reference
107*abdd2437Shisping  * @buf_ptr: Address of the buffer
108*abdd2437Shisping  * @size: Size of the buffer
109*abdd2437Shisping  *
110*abdd2437Shisping  * See description of struct teesmc32_param_memref.
111*abdd2437Shisping  */
112*abdd2437Shisping struct teesmc64_param_memref {
113*abdd2437Shisping 	uint64_t buf_ptr;
114*abdd2437Shisping 	uint64_t size;
115*abdd2437Shisping };
116*abdd2437Shisping 
117*abdd2437Shisping /**
118*abdd2437Shisping  * struct teesmc32_param_value - values
119*abdd2437Shisping  * @a: first value
120*abdd2437Shisping  * @b: second value
121*abdd2437Shisping  */
122*abdd2437Shisping struct teesmc32_param_value {
123*abdd2437Shisping 	uint32_t a;
124*abdd2437Shisping 	uint32_t b;
125*abdd2437Shisping };
126*abdd2437Shisping 
127*abdd2437Shisping /**
128*abdd2437Shisping  * struct teesmc64_param_value - values
129*abdd2437Shisping  * @a: first value
130*abdd2437Shisping  * @b: second value
131*abdd2437Shisping  */
132*abdd2437Shisping struct teesmc64_param_value {
133*abdd2437Shisping 	uint64_t a;
134*abdd2437Shisping 	uint64_t b;
135*abdd2437Shisping };
136*abdd2437Shisping 
137*abdd2437Shisping /**
138*abdd2437Shisping  * struct teesmc32_param - parameter
139*abdd2437Shisping  * @attr: attributes
140*abdd2437Shisping  * @memref: a memory reference
141*abdd2437Shisping  * @value: a value
142*abdd2437Shisping  *
143*abdd2437Shisping  * attr & TEESMC_ATTR_TYPE_MASK indicates if memref or value is used in the
144*abdd2437Shisping  * union. TEESMC_ATTR_TYPE_VALUE_* indicates value and
145*abdd2437Shisping  * TEESMC_ATTR_TYPE_MEMREF_* indicates memref. TEESMC_ATTR_TYPE_NONE
146*abdd2437Shisping  * indicates that none of the members are used.
147*abdd2437Shisping  */
148*abdd2437Shisping struct teesmc32_param {
149*abdd2437Shisping 	uint32_t attr;
150*abdd2437Shisping 	union {
151*abdd2437Shisping 		struct teesmc32_param_memref memref;
152*abdd2437Shisping 		struct teesmc32_param_value value;
153*abdd2437Shisping 	} u;
154*abdd2437Shisping };
155*abdd2437Shisping 
156*abdd2437Shisping /**
157*abdd2437Shisping  * struct teesmc64_param - parameter
158*abdd2437Shisping  * @attr: attributes
159*abdd2437Shisping  * @memref: a memory reference
160*abdd2437Shisping  * @value: a value
161*abdd2437Shisping  *
162*abdd2437Shisping  * See description of union teesmc32_param.
163*abdd2437Shisping  */
164*abdd2437Shisping struct teesmc64_param {
165*abdd2437Shisping 	uint64_t attr;
166*abdd2437Shisping 	union {
167*abdd2437Shisping 		struct teesmc64_param_memref memref;
168*abdd2437Shisping 		struct teesmc64_param_value value;
169*abdd2437Shisping 	} u;
170*abdd2437Shisping };
171*abdd2437Shisping 
172*abdd2437Shisping /**
173*abdd2437Shisping  * struct teesmc32_arg - SMC argument for Trusted OS
174*abdd2437Shisping  * @cmd: Command, one of TEESMC_CMD_*
175*abdd2437Shisping  * @ta_func: Trusted Application function, specific to the Trusted Application,
176*abdd2437Shisping  *	     used if cmd == TEESMC_CMD_INVOKE_COMMAND
177*abdd2437Shisping  * @session: In parameter for all TEESMC_CMD_* except
178*abdd2437Shisping  *	     TEESMC_CMD_OPEN_SESSION where it's an output paramter instead
179*abdd2437Shisping  * @ret: return value
180*abdd2437Shisping  * @ret_origin: origin of the return value
181*abdd2437Shisping  * @num_params: number of parameters supplied to the OS Command
182*abdd2437Shisping  * @params: the parameters supplied to the OS Command
183*abdd2437Shisping  *
184*abdd2437Shisping  * All normal SMC calls to Trusted OS uses this struct. If cmd requires
185*abdd2437Shisping  * further information than what these field holds it can be passed as a
186*abdd2437Shisping  * parameter tagged as meta (setting the TEESMC_ATTR_META bit in
187*abdd2437Shisping  * corresponding param_attrs). This is used for TEESMC_CMD_OPEN_SESSION
188*abdd2437Shisping  * to pass a struct teesmc32_meta_open_session which is needed find the
189*abdd2437Shisping  * Trusted Application and to indicate the credentials of the client.
190*abdd2437Shisping  */
191*abdd2437Shisping struct teesmc32_arg {
192*abdd2437Shisping 	uint32_t cmd;
193*abdd2437Shisping 	uint32_t ta_func;
194*abdd2437Shisping 	uint32_t session;
195*abdd2437Shisping 	uint32_t ret;
196*abdd2437Shisping 	uint32_t ret_origin;
197*abdd2437Shisping 	uint32_t num_params;
198*abdd2437Shisping 	/*
199*abdd2437Shisping 	 * Commented out element used to visualize the layout dynamic part
200*abdd2437Shisping 	 * of the struct. Note that this field is not available at all
201*abdd2437Shisping 	 * if num_params == 0.
202*abdd2437Shisping 	 *
203*abdd2437Shisping 	 * params is accessed through the macro TEESMC32_GET_PARAMS
204*abdd2437Shisping 	 *
205*abdd2437Shisping 	 * struct teesmc32_param params[num_params];
206*abdd2437Shisping 	 */
207*abdd2437Shisping };
208*abdd2437Shisping 
209*abdd2437Shisping /**
210*abdd2437Shisping  * struct teesmc64_arg - SMC argument for Trusted OS
211*abdd2437Shisping  * @cmd: OS Command, one of TEESMC_CMD_*
212*abdd2437Shisping  * @ta_func: Trusted Application function, specific to the Trusted Application
213*abdd2437Shisping  * @session: In parameter for all TEESMC_CMD_* but
214*abdd2437Shisping  *	     TEESMC_CMD_OPEN_SESSION
215*abdd2437Shisping  * @ret: return value
216*abdd2437Shisping  * @ret_origin: origin of the return value
217*abdd2437Shisping  * @num_params: number of parameters supplied to the OS Command
218*abdd2437Shisping  * @params: the parameters supplied to the OS Command
219*abdd2437Shisping  *
220*abdd2437Shisping  * See description of struct teesmc32_arg.
221*abdd2437Shisping  */
222*abdd2437Shisping struct teesmc64_arg {
223*abdd2437Shisping 	uint64_t cmd;
224*abdd2437Shisping 	uint64_t ta_func;
225*abdd2437Shisping 	uint64_t session;
226*abdd2437Shisping 	uint64_t ret;
227*abdd2437Shisping 	uint64_t ret_origin;
228*abdd2437Shisping 	uint64_t num_params;
229*abdd2437Shisping 	/*
230*abdd2437Shisping 	 * Commented out element used to visualize the layout dynamic part
231*abdd2437Shisping 	 * of the struct. Note that this field is not available at all
232*abdd2437Shisping 	 * if num_params == 0.
233*abdd2437Shisping 	 *
234*abdd2437Shisping 	 * params is accessed through the macro TEESMC64_GET_PARAMS
235*abdd2437Shisping 	 *
236*abdd2437Shisping 	 * struct teesmc64_param params[num_params];
237*abdd2437Shisping 	 */
238*abdd2437Shisping };
239*abdd2437Shisping 
240*abdd2437Shisping /**
241*abdd2437Shisping  * TEESMC64_GET_PARAMS - return pointer to union teesmc64_param *
242*abdd2437Shisping  *
243*abdd2437Shisping  * @x: Pointer to a struct teesmc64_arg
244*abdd2437Shisping  *
245*abdd2437Shisping  * Returns a pointer to the params[] inside a struct teesmc64_arg.
246*abdd2437Shisping  */
247*abdd2437Shisping #define TEESMC64_GET_PARAMS(x) \
248*abdd2437Shisping 	(struct teesmc64_param *)(((struct teesmc64_arg *)(x)) + 1)
249*abdd2437Shisping 
250*abdd2437Shisping /**
251*abdd2437Shisping  * TEESMC64_GET_ARG_SIZE - return size of struct teesmc64_arg
252*abdd2437Shisping  *
253*abdd2437Shisping  * @num_params: Number of parameters embedded in the struct teesmc64_arg
254*abdd2437Shisping  *
255*abdd2437Shisping  * Returns the size of the struct teesmc64_arg together with the number
256*abdd2437Shisping  * of embedded paramters.
257*abdd2437Shisping  */
258*abdd2437Shisping #define TEESMC64_GET_ARG_SIZE(num_params) \
259*abdd2437Shisping 	(sizeof(struct teesmc64_arg) + \
260*abdd2437Shisping 	 sizeof(struct teesmc64_param) * (num_params))
261*abdd2437Shisping 
262*abdd2437Shisping #define TEESMC_UUID_LEN	16
263*abdd2437Shisping 
264*abdd2437Shisping /**
265*abdd2437Shisping  * struct teesmc_meta_open_session - additional parameters for
266*abdd2437Shisping  *				     TEESMC32_CMD_OPEN_SESSION and
267*abdd2437Shisping  *				     TEESMC64_CMD_OPEN_SESSION
268*abdd2437Shisping  * @uuid: UUID of the Trusted Application
269*abdd2437Shisping  * @clnt_uuid: UUID of client
270*abdd2437Shisping  * @clnt_login: Login class of client, TEE_LOGIN_* if being Global Platform
271*abdd2437Shisping  *		compliant
272*abdd2437Shisping  *
273*abdd2437Shisping  * This struct is passed in the first parameter as an input memref tagged
274*abdd2437Shisping  * as meta on an TEESMC{32,64}_CMD_OPEN_SESSION cmd. It's important
275*abdd2437Shisping  * that it really is the first parameter to make it easy for an eventual
276*abdd2437Shisping  * hypervisor to inspect and possibly update clnt_* values.
277*abdd2437Shisping  */
278*abdd2437Shisping struct teesmc_meta_open_session {
279*abdd2437Shisping 	uint8_t uuid[TEESMC_UUID_LEN];
280*abdd2437Shisping 	uint8_t clnt_uuid[TEESMC_UUID_LEN];
281*abdd2437Shisping 	uint32_t clnt_login;
282*abdd2437Shisping };
283*abdd2437Shisping 
284*abdd2437Shisping 
285*abdd2437Shisping #endif /*!ASM*/
286*abdd2437Shisping 
287*abdd2437Shisping /*
288*abdd2437Shisping  *******************************************************************************
289*abdd2437Shisping  * Part 2 - low level SMC interaction
290*abdd2437Shisping  *******************************************************************************
291*abdd2437Shisping  */
292*abdd2437Shisping 
293*abdd2437Shisping #define TEESMC_32			0
294*abdd2437Shisping #define TEESMC_64			0x40000000
295*abdd2437Shisping #define TEESMC_FAST_CALL		0x80000000
296*abdd2437Shisping #define TEESMC_STD_CALL			0
297*abdd2437Shisping 
298*abdd2437Shisping #define TEESMC_OWNER_MASK		0x3F
299*abdd2437Shisping #define TEESMC_OWNER_SHIFT		24
300*abdd2437Shisping 
301*abdd2437Shisping #define TEESMC_FUNC_MASK		0xFFFF
302*abdd2437Shisping 
303*abdd2437Shisping #define TEESMC_IS_FAST_CALL(smc_val)	((smc_val) & TEESMC_FAST_CALL)
304*abdd2437Shisping #define TEESMC_IS_64(smc_val)		((smc_val) & TEESMC_64)
305*abdd2437Shisping #define TEESMC_FUNC_NUM(smc_val)	((smc_val) & TEESMC_FUNC_MASK)
306*abdd2437Shisping #define TEESMC_OWNER_NUM(smc_val)	(((smc_val) >> TEESMC_OWNER_SHIFT) & \
307*abdd2437Shisping 					 TEESMC_OWNER_MASK)
308*abdd2437Shisping 
309*abdd2437Shisping #define TEESMC_CALL_VAL(type, calling_convention, owner, func_num) \
310*abdd2437Shisping 			((type) | (calling_convention) | \
311*abdd2437Shisping 			(((owner) & TEESMC_OWNER_MASK) << TEESMC_OWNER_SHIFT) |\
312*abdd2437Shisping 			((func_num) & TEESMC_FUNC_MASK))
313*abdd2437Shisping 
314*abdd2437Shisping #define TEESMC_OWNER_ARCH		0
315*abdd2437Shisping #define TEESMC_OWNER_CPU		1
316*abdd2437Shisping #define TEESMC_OWNER_SIP		2
317*abdd2437Shisping #define TEESMC_OWNER_OEM		3
318*abdd2437Shisping #define TEESMC_OWNER_STANDARD		4
319*abdd2437Shisping #define TEESMC_OWNER_TRUSTED_APP	48
320*abdd2437Shisping #define TEESMC_OWNER_TRUSTED_OS		50
321*abdd2437Shisping 
322*abdd2437Shisping #define TEESMC_OWNER_TRUSTED_OS_OPTEED	62
323*abdd2437Shisping #define TEESMC_OWNER_TRUSTED_OS_API	63
324*abdd2437Shisping 
325*abdd2437Shisping /*
326*abdd2437Shisping  * Function specified by SMC Calling convention.
327*abdd2437Shisping  */
328*abdd2437Shisping #define TEESMC32_FUNCID_CALLS_COUNT	0xFF00
329*abdd2437Shisping #define TEESMC32_CALLS_COUNT \
330*abdd2437Shisping 	TEESMC_CALL_VAL(TEESMC_32, TEESMC_FAST_CALL, \
331*abdd2437Shisping 			TEESMC_OWNER_TRUSTED_OS_API, \
332*abdd2437Shisping 			TEESMC32_FUNCID_CALLS_COUNT)
333*abdd2437Shisping 
334*abdd2437Shisping /*
335*abdd2437Shisping  * Function specified by SMC Calling convention
336*abdd2437Shisping  *
337*abdd2437Shisping  * Return one of the following UIDs if using API specified in this file
338*abdd2437Shisping  * without further extentions:
339*abdd2437Shisping  * 65cb6b93-af0c-4617-8ed6-644a8d1140f8 : Only 32 bit calls are supported
340*abdd2437Shisping  * 65cb6b93-af0c-4617-8ed6-644a8d1140f9 : Both 32 and 64 bit calls are supported
341*abdd2437Shisping  */
342*abdd2437Shisping #define TEESMC_UID_R0			0x65cb6b93
343*abdd2437Shisping #define TEESMC_UID_R1			0xaf0c4617
344*abdd2437Shisping #define TEESMC_UID_R2			0x8ed6644a
345*abdd2437Shisping #define TEESMC_UID32_R3			0x8d1140f8
346*abdd2437Shisping #define TEESMC_UID64_R3			0x8d1140f9
347*abdd2437Shisping #define TEESMC32_FUNCID_CALLS_UID	0xFF01
348*abdd2437Shisping #define TEESMC32_CALLS_UID \
349*abdd2437Shisping 	TEESMC_CALL_VAL(TEESMC_32, TEESMC_FAST_CALL, \
350*abdd2437Shisping 			TEESMC_OWNER_TRUSTED_OS_API, \
351*abdd2437Shisping 			TEESMC32_FUNCID_CALLS_UID)
352*abdd2437Shisping 
353*abdd2437Shisping /*
354*abdd2437Shisping  * Function specified by SMC Calling convention
355*abdd2437Shisping  *
356*abdd2437Shisping  * Returns 1.0 if using API specified in this file without further extentions.
357*abdd2437Shisping  */
358*abdd2437Shisping #define TEESMC_REVISION_MAJOR	1
359*abdd2437Shisping #define TEESMC_REVISION_MINOR	0
360*abdd2437Shisping #define TEESMC32_FUNCID_CALLS_REVISION	0xFF03
361*abdd2437Shisping #define TEESMC32_CALLS_REVISION \
362*abdd2437Shisping 	TEESMC_CALL_VAL(TEESMC_32, TEESMC_FAST_CALL, \
363*abdd2437Shisping 			TEESMC_OWNER_TRUSTED_OS_API, \
364*abdd2437Shisping 			TEESMC32_FUNCID_CALLS_REVISION)
365*abdd2437Shisping 
366*abdd2437Shisping /*
367*abdd2437Shisping  * Get UUID of Trusted OS.
368*abdd2437Shisping  *
369*abdd2437Shisping  * Used by non-secure world to figure out which Trusted OS is installed.
370*abdd2437Shisping  * Note that returned UUID is the UUID of the Trusted OS, not of the API.
371*abdd2437Shisping  *
372*abdd2437Shisping  * Returns UUID in r0-4/w0-4 in the same way as TEESMC32_CALLS_UID
373*abdd2437Shisping  * described above.
374*abdd2437Shisping  */
375*abdd2437Shisping #define TEESMC_FUNCID_GET_OS_UUID	0
376*abdd2437Shisping #define TEESMC32_CALL_GET_OS_UUID \
377*abdd2437Shisping 	TEESMC_CALL_VAL(TEESMC_32, TEESMC_FAST_CALL, TEESMC_OWNER_TRUSTED_OS, \
378*abdd2437Shisping 			TEESMC_FUNCID_GET_OS_UUID)
379*abdd2437Shisping 
380*abdd2437Shisping /*
381*abdd2437Shisping  * Get revision of Trusted OS.
382*abdd2437Shisping  *
383*abdd2437Shisping  * Used by non-secure world to figure out which version of the Trusted OS
384*abdd2437Shisping  * is installed. Note that the returned revision is the revision of the
385*abdd2437Shisping  * Trusted OS, not of the API.
386*abdd2437Shisping  *
387*abdd2437Shisping  * Returns revision in r0-1/w0-1 in the same way as TEESMC32_CALLS_REVISION
388*abdd2437Shisping  * described above.
389*abdd2437Shisping  */
390*abdd2437Shisping #define TEESMC_FUNCID_GET_OS_REVISION	1
391*abdd2437Shisping #define TEESMC32_CALL_GET_OS_REVISION \
392*abdd2437Shisping 	TEESMC_CALL_VAL(TEESMC_32, TEESMC_FAST_CALL, TEESMC_OWNER_TRUSTED_OS, \
393*abdd2437Shisping 			TEESMC_FUNCID_GET_OS_REVISION)
394*abdd2437Shisping 
395*abdd2437Shisping 
396*abdd2437Shisping 
397*abdd2437Shisping /*
398*abdd2437Shisping  * Call with struct teesmc32_arg as argument
399*abdd2437Shisping  *
400*abdd2437Shisping  * Call register usage:
401*abdd2437Shisping  * r0/x0	SMC Function ID, TEESMC32_CALL_WITH_ARG
402*abdd2437Shisping  * r1/x1	Physical pointer to a struct teesmc32_arg
403*abdd2437Shisping  * r2-6/x2-6	Not used
404*abdd2437Shisping  * r7/x7	Hypervisor Client ID register
405*abdd2437Shisping  *
406*abdd2437Shisping  * Normal return register usage:
407*abdd2437Shisping  * r0/x0	Return value, TEESMC_RETURN_*
408*abdd2437Shisping  * r1-3/x1-3	Not used
409*abdd2437Shisping  * r4-7/x4-7	Preserved
410*abdd2437Shisping  *
411*abdd2437Shisping  * Ebusy return register usage:
412*abdd2437Shisping  * r0/x0	Return value, TEESMC_RETURN_EBUSY
413*abdd2437Shisping  * r1-3/x1-3	Preserved
414*abdd2437Shisping  * r4-7/x4-7	Preserved
415*abdd2437Shisping  *
416*abdd2437Shisping  * RPC return register usage:
417*abdd2437Shisping  * r0/x0	Return value, TEESMC_RETURN_IS_RPC(val)
418*abdd2437Shisping  * r1-2/x1-2	RPC parameters
419*abdd2437Shisping  * r3-7/x3-7	Resume information, must be preserved
420*abdd2437Shisping  *
421*abdd2437Shisping  * Possible return values:
422*abdd2437Shisping  * TEESMC_RETURN_UNKNOWN_FUNCTION	Trusted OS does not recognize this
423*abdd2437Shisping  *					function.
424*abdd2437Shisping  * TEESMC_RETURN_OK			Call completed, result updated in
425*abdd2437Shisping  *					the previously supplied struct
426*abdd2437Shisping  *					teesmc32_arg.
427*abdd2437Shisping  * TEESMC_RETURN_EBUSY			Trusted OS busy, try again later.
428*abdd2437Shisping  * TEESMC_RETURN_EBADADDR		Bad physcial pointer to struct
429*abdd2437Shisping  *					teesmc32_arg.
430*abdd2437Shisping  * TEESMC_RETURN_EBADCMD		Bad/unknown cmd in struct teesmc32_arg
431*abdd2437Shisping  * TEESMC_RETURN_IS_RPC()		Call suspended by RPC call to normal
432*abdd2437Shisping  *					world.
433*abdd2437Shisping  */
434*abdd2437Shisping #define TEESMC_FUNCID_CALL_WITH_ARG	2
435*abdd2437Shisping #define TEESMC32_CALL_WITH_ARG \
436*abdd2437Shisping 	TEESMC_CALL_VAL(TEESMC_32, TEESMC_STD_CALL, TEESMC_OWNER_TRUSTED_OS, \
437*abdd2437Shisping 	TEESMC_FUNCID_CALL_WITH_ARG)
438*abdd2437Shisping /* Same as TEESMC32_CALL_WITH_ARG but a "fast call". */
439*abdd2437Shisping #define TEESMC32_FASTCALL_WITH_ARG \
440*abdd2437Shisping 	TEESMC_CALL_VAL(TEESMC_32, TEESMC_FAST_CALL, TEESMC_OWNER_TRUSTED_OS, \
441*abdd2437Shisping 	TEESMC_FUNCID_CALL_WITH_ARG)
442*abdd2437Shisping 
443*abdd2437Shisping /*
444*abdd2437Shisping  * Call with struct teesmc64_arg as argument
445*abdd2437Shisping  *
446*abdd2437Shisping  * See description of TEESMC32_CALL_WITH_ARG above, uses struct
447*abdd2437Shisping  * teesmc64_arg in x1 instead.
448*abdd2437Shisping  */
449*abdd2437Shisping #define TEESMC64_CALL_WITH_ARG \
450*abdd2437Shisping 	TEESMC_CALL_VAL(TEESMC_64, TEESMC_STD_CALL, TEESMC_OWNER_TRUSTED_OS, \
451*abdd2437Shisping 	TEESMC_FUNCID_CALL_WITH_ARG)
452*abdd2437Shisping /* Same as TEESMC64_CALL_WITH_ARG but a "fast call". */
453*abdd2437Shisping #define TEESMC64_FASTCALL_WITH_ARG \
454*abdd2437Shisping 	TEESMC_CALL_VAL(TEESMC_64, TEESMC_FAST_CALL, TEESMC_OWNER_TRUSTED_OS, \
455*abdd2437Shisping 	TEESMC_FUNCID_CALL_WITH_ARG)
456*abdd2437Shisping 
457*abdd2437Shisping /*
458*abdd2437Shisping  * Resume from RPC (for example after processing an IRQ)
459*abdd2437Shisping  *
460*abdd2437Shisping  * Call register usage:
461*abdd2437Shisping  * r0/x0	SMC Function ID,
462*abdd2437Shisping  *		TEESMC32_CALL_RETURN_FROM_RPC or
463*abdd2437Shisping  *		TEESMC32_FASTCALL_RETURN_FROM_RPC
464*abdd2437Shisping  * r1-3/x1-3	Value of r1-3/x1-3 when TEESMC32_CALL_WITH_ARG returned
465*abdd2437Shisping  *		TEESMC_RETURN_RPC in r0/x0
466*abdd2437Shisping  *
467*abdd2437Shisping  * Return register usage is the same as for TEESMC32_CALL_WITH_ARG above.
468*abdd2437Shisping  *
469*abdd2437Shisping  * Possible return values
470*abdd2437Shisping  * TEESMC_RETURN_UNKNOWN_FUNCTION	Trusted OS does not recognize this
471*abdd2437Shisping  *					function.
472*abdd2437Shisping  * TEESMC_RETURN_OK			Original call completed, result
473*abdd2437Shisping  *					updated in the previously supplied.
474*abdd2437Shisping  *					struct teesmc32_arg
475*abdd2437Shisping  * TEESMC_RETURN_RPC			Call suspended by RPC call to normal
476*abdd2437Shisping  *					world.
477*abdd2437Shisping  * TEESMC_RETURN_EBUSY			Trusted OS busy, try again later.
478*abdd2437Shisping  * TEESMC_RETURN_ERESUME		Resume failed, the opaque resume
479*abdd2437Shisping  *					information was corrupt.
480*abdd2437Shisping  */
481*abdd2437Shisping #define TEESMC_FUNCID_RETURN_FROM_RPC	3
482*abdd2437Shisping #define TEESMC32_CALL_RETURN_FROM_RPC \
483*abdd2437Shisping 	TEESMC_CALL_VAL(TEESMC_32, TEESMC_STD_CALL, TEESMC_OWNER_TRUSTED_OS, \
484*abdd2437Shisping 			TEESMC_FUNCID_RETURN_FROM_RPC)
485*abdd2437Shisping /* Same as TEESMC32_CALL_RETURN_FROM_RPC but a "fast call". */
486*abdd2437Shisping #define TEESMC32_FASTCALL_RETURN_FROM_RPC \
487*abdd2437Shisping 	TEESMC_CALL_VAL(TEESMC_32, TEESMC_STD_CALL, TEESMC_OWNER_TRUSTED_OS, \
488*abdd2437Shisping 			TEESMC_FUNCID_RETURN_FROM_RPC)
489*abdd2437Shisping 
490*abdd2437Shisping /*
491*abdd2437Shisping  * Resume from RPC (for example after processing an IRQ)
492*abdd2437Shisping  *
493*abdd2437Shisping  * See description of TEESMC32_CALL_RETURN_FROM_RPC above, used when
494*abdd2437Shisping  * it's a 64bit call that has returned.
495*abdd2437Shisping  */
496*abdd2437Shisping #define TEESMC64_CALL_RETURN_FROM_RPC \
497*abdd2437Shisping 	TEESMC_CALL_VAL(TEESMC_64, TEESMC_STD_CALL, TEESMC_OWNER_TRUSTED_OS, \
498*abdd2437Shisping 			TEESMC_FUNCID_RETURN_FROM_RPC)
499*abdd2437Shisping /* Same as TEESMC64_CALL_RETURN_FROM_RPC but a "fast call". */
500*abdd2437Shisping #define TEESMC64_FASTCALL_RETURN_FROM_RPC \
501*abdd2437Shisping 	TEESMC_CALL_VAL(TEESMC_64, TEESMC_STD_CALL, TEESMC_OWNER_TRUSTED_OS, \
502*abdd2437Shisping 			TEESMC_FUNCID_RETURN_FROM_RPC)
503*abdd2437Shisping 
504*abdd2437Shisping #define TEESMC_RETURN_RPC_PREFIX_MASK	0xFFFF0000
505*abdd2437Shisping #define TEESMC_RETURN_RPC_PREFIX	0xFFFF0000
506*abdd2437Shisping #define TEESMC_RETURN_RPC_FUNC_MASK	0x0000FFFF
507*abdd2437Shisping 
508*abdd2437Shisping #define TEESMC_RETURN_GET_RPC_FUNC(ret)	((ret) & TEESMC_RETURN_RPC_FUNC_MASK)
509*abdd2437Shisping 
510*abdd2437Shisping #define TEESMC_RPC_VAL(func)		((func) | TEESMC_RETURN_RPC_PREFIX)
511*abdd2437Shisping 
512*abdd2437Shisping /*
513*abdd2437Shisping  * Allocate argument memory for RPC parameter passing.
514*abdd2437Shisping  * Argument memory is used to hold a struct teesmc32_arg.
515*abdd2437Shisping  *
516*abdd2437Shisping  * "Call" register usage:
517*abdd2437Shisping  * r0/x0	This value, TEESMC_RETURN_RPC_ALLOC
518*abdd2437Shisping  * r1/x1	Size in bytes of required argument memory
519*abdd2437Shisping  * r2-7/x2-7	Resume information, must be preserved
520*abdd2437Shisping  *
521*abdd2437Shisping  * "Return" register usage:
522*abdd2437Shisping  * r0/x0	SMC Function ID, TEESMC32_CALL_RETURN_FROM_RPC if it was an
523*abdd2437Shisping  *		AArch32 SMC return or TEESMC64_CALL_RETURN_FROM_RPC for
524*abdd2437Shisping  *		AArch64 SMC return
525*abdd2437Shisping  * r1/x1	Physical pointer to allocated argument memory, 0 if size
526*abdd2437Shisping  *		was 0 or if memory can't be allocated
527*abdd2437Shisping  * r2-7/x2-7	Preserved
528*abdd2437Shisping  */
529*abdd2437Shisping #define TEESMC_RPC_FUNC_ALLOC_ARG	0
530*abdd2437Shisping #define TEESMC_RETURN_RPC_ALLOC_ARG	\
531*abdd2437Shisping 	TEESMC_RPC_VAL(TEESMC_RPC_FUNC_ALLOC_ARG)
532*abdd2437Shisping 
533*abdd2437Shisping /*
534*abdd2437Shisping  * Allocate payload memory for RPC parameter passing.
535*abdd2437Shisping  * Payload memory is used to hold the memory referred to by struct
536*abdd2437Shisping  * teesmc32_param_memref.
537*abdd2437Shisping  *
538*abdd2437Shisping  * "Call" register usage:
539*abdd2437Shisping  * r0/x0	This value, TEESMC_RETURN_RPC_ALLOC
540*abdd2437Shisping  * r1/x1	Size in bytes of required payload memory
541*abdd2437Shisping  * r2-7/x2-7	Resume information, must be preserved
542*abdd2437Shisping  *
543*abdd2437Shisping  * "Return" register usage:
544*abdd2437Shisping  * r0/x0	SMC Function ID, TEESMC32_CALL_RETURN_FROM_RPC if it was an
545*abdd2437Shisping  *		AArch32 SMC return or TEESMC64_CALL_RETURN_FROM_RPC for
546*abdd2437Shisping  *		AArch64 SMC return
547*abdd2437Shisping  * r1/x1	Physical pointer to allocated payload memory, 0 if size
548*abdd2437Shisping  *		was 0 or if memory can't be allocated
549*abdd2437Shisping  * r2-7/x2-7	Preserved
550*abdd2437Shisping  */
551*abdd2437Shisping #define TEESMC_RPC_FUNC_ALLOC_PAYLOAD	1
552*abdd2437Shisping #define TEESMC_RETURN_RPC_ALLOC_PAYLOAD	\
553*abdd2437Shisping 	TEESMC_RPC_VAL(TEESMC_RPC_FUNC_ALLOC_PAYLOAD)
554*abdd2437Shisping 
555*abdd2437Shisping /*
556*abdd2437Shisping  * Free memory previously allocated by TEESMC_RETURN_RPC_ALLOC_ARG.
557*abdd2437Shisping  *
558*abdd2437Shisping  * "Call" register usage:
559*abdd2437Shisping  * r0/x0	This value, TEESMC_RETURN_RPC_FREE
560*abdd2437Shisping  * r1/x1	Physical pointer to previously allocated argument memory
561*abdd2437Shisping  * r2-7/x2-7	Resume information, must be preserved
562*abdd2437Shisping  *
563*abdd2437Shisping  * "Return" register usage:
564*abdd2437Shisping  * r0/x0	SMC Function ID, TEESMC32_CALL_RETURN_FROM_RPC if it was an
565*abdd2437Shisping  *		AArch32 SMC return or TEESMC64_CALL_RETURN_FROM_RPC for
566*abdd2437Shisping  *		AArch64 SMC return
567*abdd2437Shisping  * r1/x1	Not used
568*abdd2437Shisping  * r2-7/x2-7	Preserved
569*abdd2437Shisping  */
570*abdd2437Shisping #define TEESMC_RPC_FUNC_FREE_ARG	2
571*abdd2437Shisping #define TEESMC_RETURN_RPC_FREE_ARG	TEESMC_RPC_VAL(TEESMC_RPC_FUNC_FREE_ARG)
572*abdd2437Shisping 
573*abdd2437Shisping /*
574*abdd2437Shisping  * Free memory previously allocated by TEESMC_RETURN_RPC_ALLOC_PAYLOAD.
575*abdd2437Shisping  *
576*abdd2437Shisping  * "Call" register usage:
577*abdd2437Shisping  * r0/x0	This value, TEESMC_RETURN_RPC_FREE
578*abdd2437Shisping  * r1/x1	Physical pointer to previously allocated payload memory
579*abdd2437Shisping  * r3-7/x3-7	Resume information, must be preserved
580*abdd2437Shisping  *
581*abdd2437Shisping  * "Return" register usage:
582*abdd2437Shisping  * r0/x0	SMC Function ID, TEESMC32_CALL_RETURN_FROM_RPC if it was an
583*abdd2437Shisping  *		AArch32 SMC return or TEESMC64_CALL_RETURN_FROM_RPC for
584*abdd2437Shisping  *		AArch64 SMC return
585*abdd2437Shisping  * r1-2/x1-2	Not used
586*abdd2437Shisping  * r3-7/x3-7	Preserved
587*abdd2437Shisping  */
588*abdd2437Shisping #define TEESMC_RPC_FUNC_FREE_PAYLOAD	3
589*abdd2437Shisping #define TEESMC_RETURN_RPC_FREE_PAYLOAD	\
590*abdd2437Shisping 	TEESMC_RPC_VAL(TEESMC_RPC_FUNC_FREE_PAYLOAD)
591*abdd2437Shisping 
592*abdd2437Shisping /*
593*abdd2437Shisping  * Deliver an IRQ in normal world.
594*abdd2437Shisping  *
595*abdd2437Shisping  * "Call" register usage:
596*abdd2437Shisping  * r0/x0	TEESMC_RETURN_RPC_IRQ
597*abdd2437Shisping  * r1-7/x1-7	Resume information, must be preserved
598*abdd2437Shisping  *
599*abdd2437Shisping  * "Return" register usage:
600*abdd2437Shisping  * r0/x0	SMC Function ID, TEESMC32_CALL_RETURN_FROM_RPC if it was an
601*abdd2437Shisping  *		AArch32 SMC return or TEESMC64_CALL_RETURN_FROM_RPC for
602*abdd2437Shisping  *		AArch64 SMC return
603*abdd2437Shisping  * r1-7/x1-7	Preserved
604*abdd2437Shisping  */
605*abdd2437Shisping #define TEESMC_RPC_FUNC_IRQ		4
606*abdd2437Shisping #define TEESMC_RETURN_RPC_IRQ		TEESMC_RPC_VAL(TEESMC_RPC_FUNC_IRQ)
607*abdd2437Shisping 
608*abdd2437Shisping /*
609*abdd2437Shisping  * Do an RPC request. The supplied struct teesmc{32,64}_arg tells which
610*abdd2437Shisping  * request to do and the paramters for the request. The following fields
611*abdd2437Shisping  * are used (the rest are unused):
612*abdd2437Shisping  * - cmd		the Request ID
613*abdd2437Shisping  * - ret		return value of the request, filled in by normal world
614*abdd2437Shisping  * - num_params		number of parameters for the request
615*abdd2437Shisping  * - params		the parameters
616*abdd2437Shisping  * - param_attrs	attributes of the parameters
617*abdd2437Shisping  *
618*abdd2437Shisping  * "Call" register usage:
619*abdd2437Shisping  * r0/x0	TEESMC_RETURN_RPC_CMD
620*abdd2437Shisping  * r1/x1	Physical pointer to a struct teesmc32_arg if returning from
621*abdd2437Shisping  *		a AArch32 SMC or a struct teesmc64_arg if returning from a
622*abdd2437Shisping  *		AArch64 SMC, must be preserved, only the data should
623*abdd2437Shisping  *		be updated
624*abdd2437Shisping  * r2-7/x2-7	Resume information, must be preserved
625*abdd2437Shisping  *
626*abdd2437Shisping  * "Return" register usage:
627*abdd2437Shisping  * r0/x0	SMC Function ID, TEESMC32_CALL_RETURN_FROM_RPC if it was an
628*abdd2437Shisping  *		AArch32 SMC return or TEESMC64_CALL_RETURN_FROM_RPC for
629*abdd2437Shisping  *		AArch64 SMC return
630*abdd2437Shisping  * r1-7/x1-7	Preserved
631*abdd2437Shisping  */
632*abdd2437Shisping #define TEESMC_RPC_FUNC_CMD		5
633*abdd2437Shisping #define TEESMC_RETURN_RPC_CMD		TEESMC_RPC_VAL(TEESMC_RPC_FUNC_CMD)
634*abdd2437Shisping 
635*abdd2437Shisping 
636*abdd2437Shisping /* Returned in r0 */
637*abdd2437Shisping #define TEESMC_RETURN_UNKNOWN_FUNCTION	0xFFFFFFFF
638*abdd2437Shisping 
639*abdd2437Shisping /* Returned in r0 only from Trusted OS functions */
640*abdd2437Shisping #define TEESMC_RETURN_OK		0x0
641*abdd2437Shisping #define TEESMC_RETURN_EBUSY		0x1
642*abdd2437Shisping #define TEESMC_RETURN_ERESUME		0x2
643*abdd2437Shisping #define TEESMC_RETURN_EBADADDR		0x3
644*abdd2437Shisping #define TEESMC_RETURN_EBADCMD		0x4
645*abdd2437Shisping #define TEESMC_RETURN_IS_RPC(ret) \
646*abdd2437Shisping 	(((ret) & TEESMC_RETURN_RPC_PREFIX_MASK) == TEESMC_RETURN_RPC_PREFIX)
647*abdd2437Shisping 
648*abdd2437Shisping typedef struct teesmc_meta_open_session t_teesmc_meta_open_session;
649*abdd2437Shisping 
650*abdd2437Shisping void tee_smc_call(ARM_SMC_ARGS *param);
651*abdd2437Shisping 
652*abdd2437Shisping #endif /* TEESMC_H */
653