xref: /rk3399_rockchip-uboot/include/optee_include/teesmc.h (revision abdd24375050db7ce121b48477cc332d6c8c40f6)
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  * TEESMC32_GET_PARAMS - return pointer to union teesmc32_param *
211*abdd2437Shisping  *
212*abdd2437Shisping  * @x: Pointer to a struct teesmc32_arg
213*abdd2437Shisping  *
214*abdd2437Shisping  * Returns a pointer to the params[] inside a struct teesmc32_arg.
215*abdd2437Shisping  */
216*abdd2437Shisping #define TEESMC32_GET_PARAMS(x) \
217*abdd2437Shisping 	(struct teesmc32_param *)(((struct teesmc32_arg *)(x)) + 1)
218*abdd2437Shisping 
219*abdd2437Shisping /**
220*abdd2437Shisping  * TEESMC32_GET_ARG_SIZE - return size of struct teesmc32_arg
221*abdd2437Shisping  *
222*abdd2437Shisping  * @num_params: Number of parameters embedded in the struct teesmc32_arg
223*abdd2437Shisping  *
224*abdd2437Shisping  * Returns the size of the struct teesmc32_arg together with the number
225*abdd2437Shisping  * of embedded paramters.
226*abdd2437Shisping  */
227*abdd2437Shisping #define TEESMC32_GET_ARG_SIZE(num_params) \
228*abdd2437Shisping 	(sizeof(struct teesmc32_arg) + \
229*abdd2437Shisping 	 sizeof(struct teesmc32_param) * (num_params))
230*abdd2437Shisping 
231*abdd2437Shisping /**
232*abdd2437Shisping  * struct teesmc64_arg - SMC argument for Trusted OS
233*abdd2437Shisping  * @cmd: OS Command, one of TEESMC_CMD_*
234*abdd2437Shisping  * @ta_func: Trusted Application function, specific to the Trusted Application
235*abdd2437Shisping  * @session: In parameter for all TEESMC_CMD_* but
236*abdd2437Shisping  *	     TEESMC_CMD_OPEN_SESSION
237*abdd2437Shisping  * @ret: return value
238*abdd2437Shisping  * @ret_origin: origin of the return value
239*abdd2437Shisping  * @num_params: number of parameters supplied to the OS Command
240*abdd2437Shisping  * @params: the parameters supplied to the OS Command
241*abdd2437Shisping  *
242*abdd2437Shisping  * See description of struct teesmc32_arg.
243*abdd2437Shisping  */
244*abdd2437Shisping struct teesmc64_arg {
245*abdd2437Shisping 	uint64_t cmd;
246*abdd2437Shisping 	uint64_t ta_func;
247*abdd2437Shisping 	uint64_t session;
248*abdd2437Shisping 	uint64_t ret;
249*abdd2437Shisping 	uint64_t ret_origin;
250*abdd2437Shisping 	uint64_t num_params;
251*abdd2437Shisping 	/*
252*abdd2437Shisping 	 * Commented out element used to visualize the layout dynamic part
253*abdd2437Shisping 	 * of the struct. Note that this field is not available at all
254*abdd2437Shisping 	 * if num_params == 0.
255*abdd2437Shisping 	 *
256*abdd2437Shisping 	 * params is accessed through the macro TEESMC64_GET_PARAMS
257*abdd2437Shisping 	 *
258*abdd2437Shisping 	 * struct teesmc64_param params[num_params];
259*abdd2437Shisping 	 */
260*abdd2437Shisping };
261*abdd2437Shisping 
262*abdd2437Shisping /**
263*abdd2437Shisping  * TEESMC64_GET_PARAMS - return pointer to union teesmc64_param *
264*abdd2437Shisping  *
265*abdd2437Shisping  * @x: Pointer to a struct teesmc64_arg
266*abdd2437Shisping  *
267*abdd2437Shisping  * Returns a pointer to the params[] inside a struct teesmc64_arg.
268*abdd2437Shisping  */
269*abdd2437Shisping #define TEESMC64_GET_PARAMS(x) \
270*abdd2437Shisping 	(struct teesmc64_param *)(((struct teesmc64_arg *)(x)) + 1)
271*abdd2437Shisping 
272*abdd2437Shisping /**
273*abdd2437Shisping  * TEESMC64_GET_ARG_SIZE - return size of struct teesmc64_arg
274*abdd2437Shisping  *
275*abdd2437Shisping  * @num_params: Number of parameters embedded in the struct teesmc64_arg
276*abdd2437Shisping  *
277*abdd2437Shisping  * Returns the size of the struct teesmc64_arg together with the number
278*abdd2437Shisping  * of embedded paramters.
279*abdd2437Shisping  */
280*abdd2437Shisping #define TEESMC64_GET_ARG_SIZE(num_params) \
281*abdd2437Shisping 	(sizeof(struct teesmc64_arg) + \
282*abdd2437Shisping 	 sizeof(struct teesmc64_param) * (num_params))
283*abdd2437Shisping 
284*abdd2437Shisping #define TEESMC_UUID_LEN	16
285*abdd2437Shisping 
286*abdd2437Shisping /**
287*abdd2437Shisping  * struct teesmc_meta_open_session - additional parameters for
288*abdd2437Shisping  *				     TEESMC32_CMD_OPEN_SESSION and
289*abdd2437Shisping  *				     TEESMC64_CMD_OPEN_SESSION
290*abdd2437Shisping  * @uuid: UUID of the Trusted Application
291*abdd2437Shisping  * @clnt_uuid: UUID of client
292*abdd2437Shisping  * @clnt_login: Login class of client, TEE_LOGIN_* if being Global Platform
293*abdd2437Shisping  *		compliant
294*abdd2437Shisping  *
295*abdd2437Shisping  * This struct is passed in the first parameter as an input memref tagged
296*abdd2437Shisping  * as meta on an TEESMC{32,64}_CMD_OPEN_SESSION cmd. It's important
297*abdd2437Shisping  * that it really is the first parameter to make it easy for an eventual
298*abdd2437Shisping  * hypervisor to inspect and possibly update clnt_* values.
299*abdd2437Shisping  */
300*abdd2437Shisping struct teesmc_meta_open_session {
301*abdd2437Shisping 	uint8_t uuid[TEESMC_UUID_LEN];
302*abdd2437Shisping 	uint8_t clnt_uuid[TEESMC_UUID_LEN];
303*abdd2437Shisping 	uint32_t clnt_login;
304*abdd2437Shisping };
305*abdd2437Shisping 
306*abdd2437Shisping 
307*abdd2437Shisping #endif /*!ASM*/
308*abdd2437Shisping 
309*abdd2437Shisping /*
310*abdd2437Shisping  *******************************************************************************
311*abdd2437Shisping  * Part 2 - low level SMC interaction
312*abdd2437Shisping  *******************************************************************************
313*abdd2437Shisping  */
314*abdd2437Shisping 
315*abdd2437Shisping #define TEESMC_32			0
316*abdd2437Shisping #define TEESMC_64			0x40000000
317*abdd2437Shisping #define TEESMC_FAST_CALL		0x80000000
318*abdd2437Shisping #define TEESMC_STD_CALL			0
319*abdd2437Shisping 
320*abdd2437Shisping #define TEESMC_OWNER_MASK		0x3F
321*abdd2437Shisping #define TEESMC_OWNER_SHIFT		24
322*abdd2437Shisping 
323*abdd2437Shisping #define TEESMC_FUNC_MASK		0xFFFF
324*abdd2437Shisping 
325*abdd2437Shisping #define TEESMC_IS_FAST_CALL(smc_val)	((smc_val) & TEESMC_FAST_CALL)
326*abdd2437Shisping #define TEESMC_IS_64(smc_val)		((smc_val) & TEESMC_64)
327*abdd2437Shisping #define TEESMC_FUNC_NUM(smc_val)	((smc_val) & TEESMC_FUNC_MASK)
328*abdd2437Shisping #define TEESMC_OWNER_NUM(smc_val)	(((smc_val) >> TEESMC_OWNER_SHIFT) & \
329*abdd2437Shisping 					 TEESMC_OWNER_MASK)
330*abdd2437Shisping 
331*abdd2437Shisping #define TEESMC_CALL_VAL(type, calling_convention, owner, func_num) \
332*abdd2437Shisping 			((type) | (calling_convention) | \
333*abdd2437Shisping 			(((owner) & TEESMC_OWNER_MASK) << TEESMC_OWNER_SHIFT) |\
334*abdd2437Shisping 			((func_num) & TEESMC_FUNC_MASK))
335*abdd2437Shisping 
336*abdd2437Shisping #define TEESMC_OWNER_ARCH		0
337*abdd2437Shisping #define TEESMC_OWNER_CPU		1
338*abdd2437Shisping #define TEESMC_OWNER_SIP		2
339*abdd2437Shisping #define TEESMC_OWNER_OEM		3
340*abdd2437Shisping #define TEESMC_OWNER_STANDARD		4
341*abdd2437Shisping #define TEESMC_OWNER_TRUSTED_APP	48
342*abdd2437Shisping #define TEESMC_OWNER_TRUSTED_OS		50
343*abdd2437Shisping 
344*abdd2437Shisping #define TEESMC_OWNER_TRUSTED_OS_OPTEED	62
345*abdd2437Shisping #define TEESMC_OWNER_TRUSTED_OS_API	63
346*abdd2437Shisping 
347*abdd2437Shisping /*
348*abdd2437Shisping  * Function specified by SMC Calling convention.
349*abdd2437Shisping  */
350*abdd2437Shisping #define TEESMC32_FUNCID_CALLS_COUNT	0xFF00
351*abdd2437Shisping #define TEESMC32_CALLS_COUNT \
352*abdd2437Shisping 	TEESMC_CALL_VAL(TEESMC_32, TEESMC_FAST_CALL, \
353*abdd2437Shisping 			TEESMC_OWNER_TRUSTED_OS_API, \
354*abdd2437Shisping 			TEESMC32_FUNCID_CALLS_COUNT)
355*abdd2437Shisping 
356*abdd2437Shisping /*
357*abdd2437Shisping  * Function specified by SMC Calling convention
358*abdd2437Shisping  *
359*abdd2437Shisping  * Return one of the following UIDs if using API specified in this file
360*abdd2437Shisping  * without further extentions:
361*abdd2437Shisping  * 65cb6b93-af0c-4617-8ed6-644a8d1140f8 : Only 32 bit calls are supported
362*abdd2437Shisping  * 65cb6b93-af0c-4617-8ed6-644a8d1140f9 : Both 32 and 64 bit calls are supported
363*abdd2437Shisping  */
364*abdd2437Shisping #define TEESMC_UID_R0			0x65cb6b93
365*abdd2437Shisping #define TEESMC_UID_R1			0xaf0c4617
366*abdd2437Shisping #define TEESMC_UID_R2			0x8ed6644a
367*abdd2437Shisping #define TEESMC_UID32_R3			0x8d1140f8
368*abdd2437Shisping #define TEESMC_UID64_R3			0x8d1140f9
369*abdd2437Shisping #define TEESMC32_FUNCID_CALLS_UID	0xFF01
370*abdd2437Shisping #define TEESMC32_CALLS_UID \
371*abdd2437Shisping 	TEESMC_CALL_VAL(TEESMC_32, TEESMC_FAST_CALL, \
372*abdd2437Shisping 			TEESMC_OWNER_TRUSTED_OS_API, \
373*abdd2437Shisping 			TEESMC32_FUNCID_CALLS_UID)
374*abdd2437Shisping 
375*abdd2437Shisping /*
376*abdd2437Shisping  * Function specified by SMC Calling convention
377*abdd2437Shisping  *
378*abdd2437Shisping  * Returns 1.0 if using API specified in this file without further extentions.
379*abdd2437Shisping  */
380*abdd2437Shisping #define TEESMC_REVISION_MAJOR	1
381*abdd2437Shisping #define TEESMC_REVISION_MINOR	0
382*abdd2437Shisping #define TEESMC32_FUNCID_CALLS_REVISION	0xFF03
383*abdd2437Shisping #define TEESMC32_CALLS_REVISION \
384*abdd2437Shisping 	TEESMC_CALL_VAL(TEESMC_32, TEESMC_FAST_CALL, \
385*abdd2437Shisping 			TEESMC_OWNER_TRUSTED_OS_API, \
386*abdd2437Shisping 			TEESMC32_FUNCID_CALLS_REVISION)
387*abdd2437Shisping 
388*abdd2437Shisping /*
389*abdd2437Shisping  * Get UUID of Trusted OS.
390*abdd2437Shisping  *
391*abdd2437Shisping  * Used by non-secure world to figure out which Trusted OS is installed.
392*abdd2437Shisping  * Note that returned UUID is the UUID of the Trusted OS, not of the API.
393*abdd2437Shisping  *
394*abdd2437Shisping  * Returns UUID in r0-4/w0-4 in the same way as TEESMC32_CALLS_UID
395*abdd2437Shisping  * described above.
396*abdd2437Shisping  */
397*abdd2437Shisping #define TEESMC_FUNCID_GET_OS_UUID	0
398*abdd2437Shisping #define TEESMC32_CALL_GET_OS_UUID \
399*abdd2437Shisping 	TEESMC_CALL_VAL(TEESMC_32, TEESMC_FAST_CALL, TEESMC_OWNER_TRUSTED_OS, \
400*abdd2437Shisping 			TEESMC_FUNCID_GET_OS_UUID)
401*abdd2437Shisping 
402*abdd2437Shisping /*
403*abdd2437Shisping  * Get revision of Trusted OS.
404*abdd2437Shisping  *
405*abdd2437Shisping  * Used by non-secure world to figure out which version of the Trusted OS
406*abdd2437Shisping  * is installed. Note that the returned revision is the revision of the
407*abdd2437Shisping  * Trusted OS, not of the API.
408*abdd2437Shisping  *
409*abdd2437Shisping  * Returns revision in r0-1/w0-1 in the same way as TEESMC32_CALLS_REVISION
410*abdd2437Shisping  * described above.
411*abdd2437Shisping  */
412*abdd2437Shisping #define TEESMC_FUNCID_GET_OS_REVISION	1
413*abdd2437Shisping #define TEESMC32_CALL_GET_OS_REVISION \
414*abdd2437Shisping 	TEESMC_CALL_VAL(TEESMC_32, TEESMC_FAST_CALL, TEESMC_OWNER_TRUSTED_OS, \
415*abdd2437Shisping 			TEESMC_FUNCID_GET_OS_REVISION)
416*abdd2437Shisping 
417*abdd2437Shisping 
418*abdd2437Shisping 
419*abdd2437Shisping /*
420*abdd2437Shisping  * Call with struct teesmc32_arg as argument
421*abdd2437Shisping  *
422*abdd2437Shisping  * Call register usage:
423*abdd2437Shisping  * r0/x0	SMC Function ID, TEESMC32_CALL_WITH_ARG
424*abdd2437Shisping  * r1/x1	Physical pointer to a struct teesmc32_arg
425*abdd2437Shisping  * r2-6/x2-6	Not used
426*abdd2437Shisping  * r7/x7	Hypervisor Client ID register
427*abdd2437Shisping  *
428*abdd2437Shisping  * Normal return register usage:
429*abdd2437Shisping  * r0/x0	Return value, TEESMC_RETURN_*
430*abdd2437Shisping  * r1-3/x1-3	Not used
431*abdd2437Shisping  * r4-7/x4-7	Preserved
432*abdd2437Shisping  *
433*abdd2437Shisping  * Ebusy return register usage:
434*abdd2437Shisping  * r0/x0	Return value, TEESMC_RETURN_EBUSY
435*abdd2437Shisping  * r1-3/x1-3	Preserved
436*abdd2437Shisping  * r4-7/x4-7	Preserved
437*abdd2437Shisping  *
438*abdd2437Shisping  * RPC return register usage:
439*abdd2437Shisping  * r0/x0	Return value, TEESMC_RETURN_IS_RPC(val)
440*abdd2437Shisping  * r1-2/x1-2	RPC parameters
441*abdd2437Shisping  * r3-7/x3-7	Resume information, must be preserved
442*abdd2437Shisping  *
443*abdd2437Shisping  * Possible return values:
444*abdd2437Shisping  * TEESMC_RETURN_UNKNOWN_FUNCTION	Trusted OS does not recognize this
445*abdd2437Shisping  *					function.
446*abdd2437Shisping  * TEESMC_RETURN_OK			Call completed, result updated in
447*abdd2437Shisping  *					the previously supplied struct
448*abdd2437Shisping  *					teesmc32_arg.
449*abdd2437Shisping  * TEESMC_RETURN_EBUSY			Trusted OS busy, try again later.
450*abdd2437Shisping  * TEESMC_RETURN_EBADADDR		Bad physcial pointer to struct
451*abdd2437Shisping  *					teesmc32_arg.
452*abdd2437Shisping  * TEESMC_RETURN_EBADCMD		Bad/unknown cmd in struct teesmc32_arg
453*abdd2437Shisping  * TEESMC_RETURN_IS_RPC()		Call suspended by RPC call to normal
454*abdd2437Shisping  *					world.
455*abdd2437Shisping  */
456*abdd2437Shisping #define TEESMC_FUNCID_CALL_WITH_ARG	2
457*abdd2437Shisping #define TEESMC32_CALL_WITH_ARG \
458*abdd2437Shisping 	TEESMC_CALL_VAL(TEESMC_32, TEESMC_STD_CALL, TEESMC_OWNER_TRUSTED_OS, \
459*abdd2437Shisping 	TEESMC_FUNCID_CALL_WITH_ARG)
460*abdd2437Shisping /* Same as TEESMC32_CALL_WITH_ARG but a "fast call". */
461*abdd2437Shisping #define TEESMC32_FASTCALL_WITH_ARG \
462*abdd2437Shisping 	TEESMC_CALL_VAL(TEESMC_32, TEESMC_FAST_CALL, TEESMC_OWNER_TRUSTED_OS, \
463*abdd2437Shisping 	TEESMC_FUNCID_CALL_WITH_ARG)
464*abdd2437Shisping 
465*abdd2437Shisping /*
466*abdd2437Shisping  * Call with struct teesmc64_arg as argument
467*abdd2437Shisping  *
468*abdd2437Shisping  * See description of TEESMC32_CALL_WITH_ARG above, uses struct
469*abdd2437Shisping  * teesmc64_arg in x1 instead.
470*abdd2437Shisping  */
471*abdd2437Shisping #define TEESMC64_CALL_WITH_ARG \
472*abdd2437Shisping 	TEESMC_CALL_VAL(TEESMC_64, TEESMC_STD_CALL, TEESMC_OWNER_TRUSTED_OS, \
473*abdd2437Shisping 	TEESMC_FUNCID_CALL_WITH_ARG)
474*abdd2437Shisping /* Same as TEESMC64_CALL_WITH_ARG but a "fast call". */
475*abdd2437Shisping #define TEESMC64_FASTCALL_WITH_ARG \
476*abdd2437Shisping 	TEESMC_CALL_VAL(TEESMC_64, TEESMC_FAST_CALL, TEESMC_OWNER_TRUSTED_OS, \
477*abdd2437Shisping 	TEESMC_FUNCID_CALL_WITH_ARG)
478*abdd2437Shisping 
479*abdd2437Shisping /*
480*abdd2437Shisping  * Resume from RPC (for example after processing an IRQ)
481*abdd2437Shisping  *
482*abdd2437Shisping  * Call register usage:
483*abdd2437Shisping  * r0/x0	SMC Function ID,
484*abdd2437Shisping  *		TEESMC32_CALL_RETURN_FROM_RPC or
485*abdd2437Shisping  *		TEESMC32_FASTCALL_RETURN_FROM_RPC
486*abdd2437Shisping  * r1-3/x1-3	Value of r1-3/x1-3 when TEESMC32_CALL_WITH_ARG returned
487*abdd2437Shisping  *		TEESMC_RETURN_RPC in r0/x0
488*abdd2437Shisping  *
489*abdd2437Shisping  * Return register usage is the same as for TEESMC32_CALL_WITH_ARG above.
490*abdd2437Shisping  *
491*abdd2437Shisping  * Possible return values
492*abdd2437Shisping  * TEESMC_RETURN_UNKNOWN_FUNCTION	Trusted OS does not recognize this
493*abdd2437Shisping  *					function.
494*abdd2437Shisping  * TEESMC_RETURN_OK			Original call completed, result
495*abdd2437Shisping  *					updated in the previously supplied.
496*abdd2437Shisping  *					struct teesmc32_arg
497*abdd2437Shisping  * TEESMC_RETURN_RPC			Call suspended by RPC call to normal
498*abdd2437Shisping  *					world.
499*abdd2437Shisping  * TEESMC_RETURN_EBUSY			Trusted OS busy, try again later.
500*abdd2437Shisping  * TEESMC_RETURN_ERESUME		Resume failed, the opaque resume
501*abdd2437Shisping  *					information was corrupt.
502*abdd2437Shisping  */
503*abdd2437Shisping #define TEESMC_FUNCID_RETURN_FROM_RPC	3
504*abdd2437Shisping #define TEESMC32_CALL_RETURN_FROM_RPC \
505*abdd2437Shisping 	TEESMC_CALL_VAL(TEESMC_32, TEESMC_STD_CALL, TEESMC_OWNER_TRUSTED_OS, \
506*abdd2437Shisping 			TEESMC_FUNCID_RETURN_FROM_RPC)
507*abdd2437Shisping /* Same as TEESMC32_CALL_RETURN_FROM_RPC but a "fast call". */
508*abdd2437Shisping #define TEESMC32_FASTCALL_RETURN_FROM_RPC \
509*abdd2437Shisping 	TEESMC_CALL_VAL(TEESMC_32, TEESMC_STD_CALL, TEESMC_OWNER_TRUSTED_OS, \
510*abdd2437Shisping 			TEESMC_FUNCID_RETURN_FROM_RPC)
511*abdd2437Shisping 
512*abdd2437Shisping /*
513*abdd2437Shisping  * Resume from RPC (for example after processing an IRQ)
514*abdd2437Shisping  *
515*abdd2437Shisping  * See description of TEESMC32_CALL_RETURN_FROM_RPC above, used when
516*abdd2437Shisping  * it's a 64bit call that has returned.
517*abdd2437Shisping  */
518*abdd2437Shisping #define TEESMC64_CALL_RETURN_FROM_RPC \
519*abdd2437Shisping 	TEESMC_CALL_VAL(TEESMC_64, TEESMC_STD_CALL, TEESMC_OWNER_TRUSTED_OS, \
520*abdd2437Shisping 			TEESMC_FUNCID_RETURN_FROM_RPC)
521*abdd2437Shisping /* Same as TEESMC64_CALL_RETURN_FROM_RPC but a "fast call". */
522*abdd2437Shisping #define TEESMC64_FASTCALL_RETURN_FROM_RPC \
523*abdd2437Shisping 	TEESMC_CALL_VAL(TEESMC_64, TEESMC_STD_CALL, TEESMC_OWNER_TRUSTED_OS, \
524*abdd2437Shisping 			TEESMC_FUNCID_RETURN_FROM_RPC)
525*abdd2437Shisping 
526*abdd2437Shisping #define TEESMC_RETURN_RPC_PREFIX_MASK	0xFFFF0000
527*abdd2437Shisping #define TEESMC_RETURN_RPC_PREFIX	0xFFFF0000
528*abdd2437Shisping #define TEESMC_RETURN_RPC_FUNC_MASK	0x0000FFFF
529*abdd2437Shisping 
530*abdd2437Shisping #define TEESMC_RETURN_GET_RPC_FUNC(ret)	((ret) & TEESMC_RETURN_RPC_FUNC_MASK)
531*abdd2437Shisping 
532*abdd2437Shisping #define TEESMC_RPC_VAL(func)		((func) | TEESMC_RETURN_RPC_PREFIX)
533*abdd2437Shisping 
534*abdd2437Shisping /*
535*abdd2437Shisping  * Allocate argument memory for RPC parameter passing.
536*abdd2437Shisping  * Argument memory is used to hold a struct teesmc32_arg.
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 argument 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 argument 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_ARG	0
552*abdd2437Shisping #define TEESMC_RETURN_RPC_ALLOC_ARG	\
553*abdd2437Shisping 	TEESMC_RPC_VAL(TEESMC_RPC_FUNC_ALLOC_ARG)
554*abdd2437Shisping 
555*abdd2437Shisping /*
556*abdd2437Shisping  * Allocate payload memory for RPC parameter passing.
557*abdd2437Shisping  * Payload memory is used to hold the memory referred to by struct
558*abdd2437Shisping  * teesmc32_param_memref.
559*abdd2437Shisping  *
560*abdd2437Shisping  * "Call" register usage:
561*abdd2437Shisping  * r0/x0	This value, TEESMC_RETURN_RPC_ALLOC
562*abdd2437Shisping  * r1/x1	Size in bytes of required payload memory
563*abdd2437Shisping  * r2-7/x2-7	Resume information, must be preserved
564*abdd2437Shisping  *
565*abdd2437Shisping  * "Return" register usage:
566*abdd2437Shisping  * r0/x0	SMC Function ID, TEESMC32_CALL_RETURN_FROM_RPC if it was an
567*abdd2437Shisping  *		AArch32 SMC return or TEESMC64_CALL_RETURN_FROM_RPC for
568*abdd2437Shisping  *		AArch64 SMC return
569*abdd2437Shisping  * r1/x1	Physical pointer to allocated payload memory, 0 if size
570*abdd2437Shisping  *		was 0 or if memory can't be allocated
571*abdd2437Shisping  * r2-7/x2-7	Preserved
572*abdd2437Shisping  */
573*abdd2437Shisping #define TEESMC_RPC_FUNC_ALLOC_PAYLOAD	1
574*abdd2437Shisping #define TEESMC_RETURN_RPC_ALLOC_PAYLOAD	\
575*abdd2437Shisping 	TEESMC_RPC_VAL(TEESMC_RPC_FUNC_ALLOC_PAYLOAD)
576*abdd2437Shisping 
577*abdd2437Shisping /*
578*abdd2437Shisping  * Free memory previously allocated by TEESMC_RETURN_RPC_ALLOC_ARG.
579*abdd2437Shisping  *
580*abdd2437Shisping  * "Call" register usage:
581*abdd2437Shisping  * r0/x0	This value, TEESMC_RETURN_RPC_FREE
582*abdd2437Shisping  * r1/x1	Physical pointer to previously allocated argument memory
583*abdd2437Shisping  * r2-7/x2-7	Resume information, must be preserved
584*abdd2437Shisping  *
585*abdd2437Shisping  * "Return" register usage:
586*abdd2437Shisping  * r0/x0	SMC Function ID, TEESMC32_CALL_RETURN_FROM_RPC if it was an
587*abdd2437Shisping  *		AArch32 SMC return or TEESMC64_CALL_RETURN_FROM_RPC for
588*abdd2437Shisping  *		AArch64 SMC return
589*abdd2437Shisping  * r1/x1	Not used
590*abdd2437Shisping  * r2-7/x2-7	Preserved
591*abdd2437Shisping  */
592*abdd2437Shisping #define TEESMC_RPC_FUNC_FREE_ARG	2
593*abdd2437Shisping #define TEESMC_RETURN_RPC_FREE_ARG	TEESMC_RPC_VAL(TEESMC_RPC_FUNC_FREE_ARG)
594*abdd2437Shisping 
595*abdd2437Shisping /*
596*abdd2437Shisping  * Free memory previously allocated by TEESMC_RETURN_RPC_ALLOC_PAYLOAD.
597*abdd2437Shisping  *
598*abdd2437Shisping  * "Call" register usage:
599*abdd2437Shisping  * r0/x0	This value, TEESMC_RETURN_RPC_FREE
600*abdd2437Shisping  * r1/x1	Physical pointer to previously allocated payload memory
601*abdd2437Shisping  * r3-7/x3-7	Resume information, must be preserved
602*abdd2437Shisping  *
603*abdd2437Shisping  * "Return" register usage:
604*abdd2437Shisping  * r0/x0	SMC Function ID, TEESMC32_CALL_RETURN_FROM_RPC if it was an
605*abdd2437Shisping  *		AArch32 SMC return or TEESMC64_CALL_RETURN_FROM_RPC for
606*abdd2437Shisping  *		AArch64 SMC return
607*abdd2437Shisping  * r1-2/x1-2	Not used
608*abdd2437Shisping  * r3-7/x3-7	Preserved
609*abdd2437Shisping  */
610*abdd2437Shisping #define TEESMC_RPC_FUNC_FREE_PAYLOAD	3
611*abdd2437Shisping #define TEESMC_RETURN_RPC_FREE_PAYLOAD	\
612*abdd2437Shisping 	TEESMC_RPC_VAL(TEESMC_RPC_FUNC_FREE_PAYLOAD)
613*abdd2437Shisping 
614*abdd2437Shisping /*
615*abdd2437Shisping  * Deliver an IRQ in normal world.
616*abdd2437Shisping  *
617*abdd2437Shisping  * "Call" register usage:
618*abdd2437Shisping  * r0/x0	TEESMC_RETURN_RPC_IRQ
619*abdd2437Shisping  * r1-7/x1-7	Resume information, must be preserved
620*abdd2437Shisping  *
621*abdd2437Shisping  * "Return" register usage:
622*abdd2437Shisping  * r0/x0	SMC Function ID, TEESMC32_CALL_RETURN_FROM_RPC if it was an
623*abdd2437Shisping  *		AArch32 SMC return or TEESMC64_CALL_RETURN_FROM_RPC for
624*abdd2437Shisping  *		AArch64 SMC return
625*abdd2437Shisping  * r1-7/x1-7	Preserved
626*abdd2437Shisping  */
627*abdd2437Shisping #define TEESMC_RPC_FUNC_IRQ		4
628*abdd2437Shisping #define TEESMC_RETURN_RPC_IRQ		TEESMC_RPC_VAL(TEESMC_RPC_FUNC_IRQ)
629*abdd2437Shisping 
630*abdd2437Shisping /*
631*abdd2437Shisping  * Do an RPC request. The supplied struct teesmc{32,64}_arg tells which
632*abdd2437Shisping  * request to do and the paramters for the request. The following fields
633*abdd2437Shisping  * are used (the rest are unused):
634*abdd2437Shisping  * - cmd		the Request ID
635*abdd2437Shisping  * - ret		return value of the request, filled in by normal world
636*abdd2437Shisping  * - num_params		number of parameters for the request
637*abdd2437Shisping  * - params		the parameters
638*abdd2437Shisping  * - param_attrs	attributes of the parameters
639*abdd2437Shisping  *
640*abdd2437Shisping  * "Call" register usage:
641*abdd2437Shisping  * r0/x0	TEESMC_RETURN_RPC_CMD
642*abdd2437Shisping  * r1/x1	Physical pointer to a struct teesmc32_arg if returning from
643*abdd2437Shisping  *		a AArch32 SMC or a struct teesmc64_arg if returning from a
644*abdd2437Shisping  *		AArch64 SMC, must be preserved, only the data should
645*abdd2437Shisping  *		be updated
646*abdd2437Shisping  * r2-7/x2-7	Resume information, must be preserved
647*abdd2437Shisping  *
648*abdd2437Shisping  * "Return" register usage:
649*abdd2437Shisping  * r0/x0	SMC Function ID, TEESMC32_CALL_RETURN_FROM_RPC if it was an
650*abdd2437Shisping  *		AArch32 SMC return or TEESMC64_CALL_RETURN_FROM_RPC for
651*abdd2437Shisping  *		AArch64 SMC return
652*abdd2437Shisping  * r1-7/x1-7	Preserved
653*abdd2437Shisping  */
654*abdd2437Shisping #define TEESMC_RPC_FUNC_CMD		5
655*abdd2437Shisping #define TEESMC_RETURN_RPC_CMD		TEESMC_RPC_VAL(TEESMC_RPC_FUNC_CMD)
656*abdd2437Shisping 
657*abdd2437Shisping 
658*abdd2437Shisping /* Returned in r0 */
659*abdd2437Shisping #define TEESMC_RETURN_UNKNOWN_FUNCTION	0xFFFFFFFF
660*abdd2437Shisping 
661*abdd2437Shisping /* Returned in r0 only from Trusted OS functions */
662*abdd2437Shisping #define TEESMC_RETURN_OK		0x0
663*abdd2437Shisping #define TEESMC_RETURN_EBUSY		0x1
664*abdd2437Shisping #define TEESMC_RETURN_ERESUME		0x2
665*abdd2437Shisping #define TEESMC_RETURN_EBADADDR		0x3
666*abdd2437Shisping #define TEESMC_RETURN_EBADCMD		0x4
667*abdd2437Shisping #define TEESMC_RETURN_IS_RPC(ret) \
668*abdd2437Shisping 	(((ret) & TEESMC_RETURN_RPC_PREFIX_MASK) == TEESMC_RETURN_RPC_PREFIX)
669*abdd2437Shisping 
670*abdd2437Shisping typedef struct teesmc32_arg             t_teesmc32_arg;
671*abdd2437Shisping typedef struct teesmc32_param           t_teesmc32_param;
672*abdd2437Shisping typedef struct teesmc_meta_open_session t_teesmc_meta_open_session;
673*abdd2437Shisping 
674*abdd2437Shisping void tee_smc_call(ARM_SMC_ARGS *param);
675*abdd2437Shisping 
676*abdd2437Shisping #endif /* TEESMC_H */
677