xref: /OK3568_Linux_fs/kernel/drivers/tee/optee/optee_msg.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /* SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) */
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun  * Copyright (c) 2015-2019, Linaro Limited
4*4882a593Smuzhiyun  */
5*4882a593Smuzhiyun #ifndef _OPTEE_MSG_H
6*4882a593Smuzhiyun #define _OPTEE_MSG_H
7*4882a593Smuzhiyun 
8*4882a593Smuzhiyun #include <linux/bitops.h>
9*4882a593Smuzhiyun #include <linux/types.h>
10*4882a593Smuzhiyun 
11*4882a593Smuzhiyun /*
12*4882a593Smuzhiyun  * This file defines the OP-TEE message protocol (ABI) used to communicate
13*4882a593Smuzhiyun  * with an instance of OP-TEE running in secure world.
14*4882a593Smuzhiyun  *
15*4882a593Smuzhiyun  * This file is divided into three sections.
16*4882a593Smuzhiyun  * 1. Formatting of messages.
17*4882a593Smuzhiyun  * 2. Requests from normal world
18*4882a593Smuzhiyun  * 3. Requests from secure world, Remote Procedure Call (RPC), handled by
19*4882a593Smuzhiyun  *    tee-supplicant.
20*4882a593Smuzhiyun  */
21*4882a593Smuzhiyun 
22*4882a593Smuzhiyun /*****************************************************************************
23*4882a593Smuzhiyun  * Part 1 - formatting of messages
24*4882a593Smuzhiyun  *****************************************************************************/
25*4882a593Smuzhiyun 
26*4882a593Smuzhiyun #define OPTEE_MSG_ATTR_TYPE_NONE		0x0
27*4882a593Smuzhiyun #define OPTEE_MSG_ATTR_TYPE_VALUE_INPUT		0x1
28*4882a593Smuzhiyun #define OPTEE_MSG_ATTR_TYPE_VALUE_OUTPUT	0x2
29*4882a593Smuzhiyun #define OPTEE_MSG_ATTR_TYPE_VALUE_INOUT		0x3
30*4882a593Smuzhiyun #define OPTEE_MSG_ATTR_TYPE_RMEM_INPUT		0x5
31*4882a593Smuzhiyun #define OPTEE_MSG_ATTR_TYPE_RMEM_OUTPUT		0x6
32*4882a593Smuzhiyun #define OPTEE_MSG_ATTR_TYPE_RMEM_INOUT		0x7
33*4882a593Smuzhiyun #define OPTEE_MSG_ATTR_TYPE_TMEM_INPUT		0x9
34*4882a593Smuzhiyun #define OPTEE_MSG_ATTR_TYPE_TMEM_OUTPUT		0xa
35*4882a593Smuzhiyun #define OPTEE_MSG_ATTR_TYPE_TMEM_INOUT		0xb
36*4882a593Smuzhiyun 
37*4882a593Smuzhiyun #define OPTEE_MSG_ATTR_TYPE_MASK		GENMASK(7, 0)
38*4882a593Smuzhiyun 
39*4882a593Smuzhiyun /*
40*4882a593Smuzhiyun  * Meta parameter to be absorbed by the Secure OS and not passed
41*4882a593Smuzhiyun  * to the Trusted Application.
42*4882a593Smuzhiyun  *
43*4882a593Smuzhiyun  * Currently only used with OPTEE_MSG_CMD_OPEN_SESSION.
44*4882a593Smuzhiyun  */
45*4882a593Smuzhiyun #define OPTEE_MSG_ATTR_META			BIT(8)
46*4882a593Smuzhiyun 
47*4882a593Smuzhiyun /*
48*4882a593Smuzhiyun  * Pointer to a list of pages used to register user-defined SHM buffer.
49*4882a593Smuzhiyun  * Used with OPTEE_MSG_ATTR_TYPE_TMEM_*.
50*4882a593Smuzhiyun  * buf_ptr should point to the beginning of the buffer. Buffer will contain
51*4882a593Smuzhiyun  * list of page addresses. OP-TEE core can reconstruct contiguous buffer from
52*4882a593Smuzhiyun  * that page addresses list. Page addresses are stored as 64 bit values.
53*4882a593Smuzhiyun  * Last entry on a page should point to the next page of buffer.
54*4882a593Smuzhiyun  * Every entry in buffer should point to a 4k page beginning (12 least
55*4882a593Smuzhiyun  * significant bits must be equal to zero).
56*4882a593Smuzhiyun  *
57*4882a593Smuzhiyun  * 12 least significant bints of optee_msg_param.u.tmem.buf_ptr should hold page
58*4882a593Smuzhiyun  * offset of the user buffer.
59*4882a593Smuzhiyun  *
60*4882a593Smuzhiyun  * So, entries should be placed like members of this structure:
61*4882a593Smuzhiyun  *
62*4882a593Smuzhiyun  * struct page_data {
63*4882a593Smuzhiyun  *   uint64_t pages_array[OPTEE_MSG_NONCONTIG_PAGE_SIZE/sizeof(uint64_t) - 1];
64*4882a593Smuzhiyun  *   uint64_t next_page_data;
65*4882a593Smuzhiyun  * };
66*4882a593Smuzhiyun  *
67*4882a593Smuzhiyun  * Structure is designed to exactly fit into the page size
68*4882a593Smuzhiyun  * OPTEE_MSG_NONCONTIG_PAGE_SIZE which is a standard 4KB page.
69*4882a593Smuzhiyun  *
70*4882a593Smuzhiyun  * The size of 4KB is chosen because this is the smallest page size for ARM
71*4882a593Smuzhiyun  * architectures. If REE uses larger pages, it should divide them to 4KB ones.
72*4882a593Smuzhiyun  */
73*4882a593Smuzhiyun #define OPTEE_MSG_ATTR_NONCONTIG		BIT(9)
74*4882a593Smuzhiyun 
75*4882a593Smuzhiyun /*
76*4882a593Smuzhiyun  * Memory attributes for caching passed with temp memrefs. The actual value
77*4882a593Smuzhiyun  * used is defined outside the message protocol with the exception of
78*4882a593Smuzhiyun  * OPTEE_MSG_ATTR_CACHE_PREDEFINED which means the attributes already
79*4882a593Smuzhiyun  * defined for the memory range should be used. If optee_smc.h is used as
80*4882a593Smuzhiyun  * bearer of this protocol OPTEE_SMC_SHM_* is used for values.
81*4882a593Smuzhiyun  */
82*4882a593Smuzhiyun #define OPTEE_MSG_ATTR_CACHE_SHIFT		16
83*4882a593Smuzhiyun #define OPTEE_MSG_ATTR_CACHE_MASK		GENMASK(2, 0)
84*4882a593Smuzhiyun #define OPTEE_MSG_ATTR_CACHE_PREDEFINED		0
85*4882a593Smuzhiyun 
86*4882a593Smuzhiyun /*
87*4882a593Smuzhiyun  * Same values as TEE_LOGIN_* from TEE Internal API
88*4882a593Smuzhiyun  */
89*4882a593Smuzhiyun #define OPTEE_MSG_LOGIN_PUBLIC			0x00000000
90*4882a593Smuzhiyun #define OPTEE_MSG_LOGIN_USER			0x00000001
91*4882a593Smuzhiyun #define OPTEE_MSG_LOGIN_GROUP			0x00000002
92*4882a593Smuzhiyun #define OPTEE_MSG_LOGIN_APPLICATION		0x00000004
93*4882a593Smuzhiyun #define OPTEE_MSG_LOGIN_APPLICATION_USER	0x00000005
94*4882a593Smuzhiyun #define OPTEE_MSG_LOGIN_APPLICATION_GROUP	0x00000006
95*4882a593Smuzhiyun 
96*4882a593Smuzhiyun /*
97*4882a593Smuzhiyun  * Page size used in non-contiguous buffer entries
98*4882a593Smuzhiyun  */
99*4882a593Smuzhiyun #define OPTEE_MSG_NONCONTIG_PAGE_SIZE		4096
100*4882a593Smuzhiyun 
101*4882a593Smuzhiyun /**
102*4882a593Smuzhiyun  * struct optee_msg_param_tmem - temporary memory reference parameter
103*4882a593Smuzhiyun  * @buf_ptr:	Address of the buffer
104*4882a593Smuzhiyun  * @size:	Size of the buffer
105*4882a593Smuzhiyun  * @shm_ref:	Temporary shared memory reference, pointer to a struct tee_shm
106*4882a593Smuzhiyun  *
107*4882a593Smuzhiyun  * Secure and normal world communicates pointers as physical address
108*4882a593Smuzhiyun  * instead of the virtual address. This is because secure and normal world
109*4882a593Smuzhiyun  * have completely independent memory mapping. Normal world can even have a
110*4882a593Smuzhiyun  * hypervisor which need to translate the guest physical address (AKA IPA
111*4882a593Smuzhiyun  * in ARM documentation) to a real physical address before passing the
112*4882a593Smuzhiyun  * structure to secure world.
113*4882a593Smuzhiyun  */
114*4882a593Smuzhiyun struct optee_msg_param_tmem {
115*4882a593Smuzhiyun 	u64 buf_ptr;
116*4882a593Smuzhiyun 	u64 size;
117*4882a593Smuzhiyun 	u64 shm_ref;
118*4882a593Smuzhiyun };
119*4882a593Smuzhiyun 
120*4882a593Smuzhiyun /**
121*4882a593Smuzhiyun  * struct optee_msg_param_rmem - registered memory reference parameter
122*4882a593Smuzhiyun  * @offs:	Offset into shared memory reference
123*4882a593Smuzhiyun  * @size:	Size of the buffer
124*4882a593Smuzhiyun  * @shm_ref:	Shared memory reference, pointer to a struct tee_shm
125*4882a593Smuzhiyun  */
126*4882a593Smuzhiyun struct optee_msg_param_rmem {
127*4882a593Smuzhiyun 	u64 offs;
128*4882a593Smuzhiyun 	u64 size;
129*4882a593Smuzhiyun 	u64 shm_ref;
130*4882a593Smuzhiyun };
131*4882a593Smuzhiyun 
132*4882a593Smuzhiyun /**
133*4882a593Smuzhiyun  * struct optee_msg_param_value - opaque value parameter
134*4882a593Smuzhiyun  *
135*4882a593Smuzhiyun  * Value parameters are passed unchecked between normal and secure world.
136*4882a593Smuzhiyun  */
137*4882a593Smuzhiyun struct optee_msg_param_value {
138*4882a593Smuzhiyun 	u64 a;
139*4882a593Smuzhiyun 	u64 b;
140*4882a593Smuzhiyun 	u64 c;
141*4882a593Smuzhiyun };
142*4882a593Smuzhiyun 
143*4882a593Smuzhiyun /**
144*4882a593Smuzhiyun  * struct optee_msg_param - parameter used together with struct optee_msg_arg
145*4882a593Smuzhiyun  * @attr:	attributes
146*4882a593Smuzhiyun  * @tmem:	parameter by temporary memory reference
147*4882a593Smuzhiyun  * @rmem:	parameter by registered memory reference
148*4882a593Smuzhiyun  * @value:	parameter by opaque value
149*4882a593Smuzhiyun  * @octets:	parameter by octet string
150*4882a593Smuzhiyun  *
151*4882a593Smuzhiyun  * @attr & OPTEE_MSG_ATTR_TYPE_MASK indicates if tmem, rmem or value is used in
152*4882a593Smuzhiyun  * the union. OPTEE_MSG_ATTR_TYPE_VALUE_* indicates value or octets,
153*4882a593Smuzhiyun  * OPTEE_MSG_ATTR_TYPE_TMEM_* indicates @tmem and
154*4882a593Smuzhiyun  * OPTEE_MSG_ATTR_TYPE_RMEM_* indicates @rmem,
155*4882a593Smuzhiyun  * OPTEE_MSG_ATTR_TYPE_NONE indicates that none of the members are used.
156*4882a593Smuzhiyun  */
157*4882a593Smuzhiyun struct optee_msg_param {
158*4882a593Smuzhiyun 	u64 attr;
159*4882a593Smuzhiyun 	union {
160*4882a593Smuzhiyun 		struct optee_msg_param_tmem tmem;
161*4882a593Smuzhiyun 		struct optee_msg_param_rmem rmem;
162*4882a593Smuzhiyun 		struct optee_msg_param_value value;
163*4882a593Smuzhiyun 		u8 octets[24];
164*4882a593Smuzhiyun 	} u;
165*4882a593Smuzhiyun };
166*4882a593Smuzhiyun 
167*4882a593Smuzhiyun /**
168*4882a593Smuzhiyun  * struct optee_msg_arg - call argument
169*4882a593Smuzhiyun  * @cmd: Command, one of OPTEE_MSG_CMD_* or OPTEE_MSG_RPC_CMD_*
170*4882a593Smuzhiyun  * @func: Trusted Application function, specific to the Trusted Application,
171*4882a593Smuzhiyun  *	     used if cmd == OPTEE_MSG_CMD_INVOKE_COMMAND
172*4882a593Smuzhiyun  * @session: In parameter for all OPTEE_MSG_CMD_* except
173*4882a593Smuzhiyun  *	     OPTEE_MSG_CMD_OPEN_SESSION where it's an output parameter instead
174*4882a593Smuzhiyun  * @cancel_id: Cancellation id, a unique value to identify this request
175*4882a593Smuzhiyun  * @ret: return value
176*4882a593Smuzhiyun  * @ret_origin: origin of the return value
177*4882a593Smuzhiyun  * @num_params: number of parameters supplied to the OS Command
178*4882a593Smuzhiyun  * @params: the parameters supplied to the OS Command
179*4882a593Smuzhiyun  *
180*4882a593Smuzhiyun  * All normal calls to Trusted OS uses this struct. If cmd requires further
181*4882a593Smuzhiyun  * information than what these field holds it can be passed as a parameter
182*4882a593Smuzhiyun  * tagged as meta (setting the OPTEE_MSG_ATTR_META bit in corresponding
183*4882a593Smuzhiyun  * attrs field). All parameters tagged as meta has to come first.
184*4882a593Smuzhiyun  *
185*4882a593Smuzhiyun  * Temp memref parameters can be fragmented if supported by the Trusted OS
186*4882a593Smuzhiyun  * (when optee_smc.h is bearer of this protocol this is indicated with
187*4882a593Smuzhiyun  * OPTEE_SMC_SEC_CAP_UNREGISTERED_SHM). If a logical memref parameter is
188*4882a593Smuzhiyun  * fragmented then has all but the last fragment the
189*4882a593Smuzhiyun  * OPTEE_MSG_ATTR_FRAGMENT bit set in attrs. Even if a memref is fragmented
190*4882a593Smuzhiyun  * it will still be presented as a single logical memref to the Trusted
191*4882a593Smuzhiyun  * Application.
192*4882a593Smuzhiyun  */
193*4882a593Smuzhiyun struct optee_msg_arg {
194*4882a593Smuzhiyun 	u32 cmd;
195*4882a593Smuzhiyun 	u32 func;
196*4882a593Smuzhiyun 	u32 session;
197*4882a593Smuzhiyun 	u32 cancel_id;
198*4882a593Smuzhiyun 	u32 pad;
199*4882a593Smuzhiyun 	u32 ret;
200*4882a593Smuzhiyun 	u32 ret_origin;
201*4882a593Smuzhiyun 	u32 num_params;
202*4882a593Smuzhiyun 
203*4882a593Smuzhiyun 	/* num_params tells the actual number of element in params */
204*4882a593Smuzhiyun 	struct optee_msg_param params[0];
205*4882a593Smuzhiyun };
206*4882a593Smuzhiyun 
207*4882a593Smuzhiyun /**
208*4882a593Smuzhiyun  * OPTEE_MSG_GET_ARG_SIZE - return size of struct optee_msg_arg
209*4882a593Smuzhiyun  *
210*4882a593Smuzhiyun  * @num_params: Number of parameters embedded in the struct optee_msg_arg
211*4882a593Smuzhiyun  *
212*4882a593Smuzhiyun  * Returns the size of the struct optee_msg_arg together with the number
213*4882a593Smuzhiyun  * of embedded parameters.
214*4882a593Smuzhiyun  */
215*4882a593Smuzhiyun #define OPTEE_MSG_GET_ARG_SIZE(num_params) \
216*4882a593Smuzhiyun 	(sizeof(struct optee_msg_arg) + \
217*4882a593Smuzhiyun 	 sizeof(struct optee_msg_param) * (num_params))
218*4882a593Smuzhiyun 
219*4882a593Smuzhiyun /*****************************************************************************
220*4882a593Smuzhiyun  * Part 2 - requests from normal world
221*4882a593Smuzhiyun  *****************************************************************************/
222*4882a593Smuzhiyun 
223*4882a593Smuzhiyun /*
224*4882a593Smuzhiyun  * Return the following UID if using API specified in this file without
225*4882a593Smuzhiyun  * further extensions:
226*4882a593Smuzhiyun  * 384fb3e0-e7f8-11e3-af63-0002a5d5c51b.
227*4882a593Smuzhiyun  * Represented in 4 32-bit words in OPTEE_MSG_UID_0, OPTEE_MSG_UID_1,
228*4882a593Smuzhiyun  * OPTEE_MSG_UID_2, OPTEE_MSG_UID_3.
229*4882a593Smuzhiyun  */
230*4882a593Smuzhiyun #define OPTEE_MSG_UID_0			0x384fb3e0
231*4882a593Smuzhiyun #define OPTEE_MSG_UID_1			0xe7f811e3
232*4882a593Smuzhiyun #define OPTEE_MSG_UID_2			0xaf630002
233*4882a593Smuzhiyun #define OPTEE_MSG_UID_3			0xa5d5c51b
234*4882a593Smuzhiyun #define OPTEE_MSG_FUNCID_CALLS_UID	0xFF01
235*4882a593Smuzhiyun 
236*4882a593Smuzhiyun /*
237*4882a593Smuzhiyun  * Returns 2.0 if using API specified in this file without further
238*4882a593Smuzhiyun  * extensions. Represented in 2 32-bit words in OPTEE_MSG_REVISION_MAJOR
239*4882a593Smuzhiyun  * and OPTEE_MSG_REVISION_MINOR
240*4882a593Smuzhiyun  */
241*4882a593Smuzhiyun #define OPTEE_MSG_REVISION_MAJOR	2
242*4882a593Smuzhiyun #define OPTEE_MSG_REVISION_MINOR	0
243*4882a593Smuzhiyun #define OPTEE_MSG_FUNCID_CALLS_REVISION	0xFF03
244*4882a593Smuzhiyun 
245*4882a593Smuzhiyun /*
246*4882a593Smuzhiyun  * Get UUID of Trusted OS.
247*4882a593Smuzhiyun  *
248*4882a593Smuzhiyun  * Used by non-secure world to figure out which Trusted OS is installed.
249*4882a593Smuzhiyun  * Note that returned UUID is the UUID of the Trusted OS, not of the API.
250*4882a593Smuzhiyun  *
251*4882a593Smuzhiyun  * Returns UUID in 4 32-bit words in the same way as
252*4882a593Smuzhiyun  * OPTEE_MSG_FUNCID_CALLS_UID described above.
253*4882a593Smuzhiyun  */
254*4882a593Smuzhiyun #define OPTEE_MSG_OS_OPTEE_UUID_0	0x486178e0
255*4882a593Smuzhiyun #define OPTEE_MSG_OS_OPTEE_UUID_1	0xe7f811e3
256*4882a593Smuzhiyun #define OPTEE_MSG_OS_OPTEE_UUID_2	0xbc5e0002
257*4882a593Smuzhiyun #define OPTEE_MSG_OS_OPTEE_UUID_3	0xa5d5c51b
258*4882a593Smuzhiyun #define OPTEE_MSG_FUNCID_GET_OS_UUID	0x0000
259*4882a593Smuzhiyun 
260*4882a593Smuzhiyun /*
261*4882a593Smuzhiyun  * Get revision of Trusted OS.
262*4882a593Smuzhiyun  *
263*4882a593Smuzhiyun  * Used by non-secure world to figure out which version of the Trusted OS
264*4882a593Smuzhiyun  * is installed. Note that the returned revision is the revision of the
265*4882a593Smuzhiyun  * Trusted OS, not of the API.
266*4882a593Smuzhiyun  *
267*4882a593Smuzhiyun  * Returns revision in 2 32-bit words in the same way as
268*4882a593Smuzhiyun  * OPTEE_MSG_CALLS_REVISION described above.
269*4882a593Smuzhiyun  */
270*4882a593Smuzhiyun #define OPTEE_MSG_FUNCID_GET_OS_REVISION	0x0001
271*4882a593Smuzhiyun 
272*4882a593Smuzhiyun /*
273*4882a593Smuzhiyun  * Do a secure call with struct optee_msg_arg as argument
274*4882a593Smuzhiyun  * The OPTEE_MSG_CMD_* below defines what goes in struct optee_msg_arg::cmd
275*4882a593Smuzhiyun  *
276*4882a593Smuzhiyun  * OPTEE_MSG_CMD_OPEN_SESSION opens a session to a Trusted Application.
277*4882a593Smuzhiyun  * The first two parameters are tagged as meta, holding two value
278*4882a593Smuzhiyun  * parameters to pass the following information:
279*4882a593Smuzhiyun  * param[0].u.value.a-b uuid of Trusted Application
280*4882a593Smuzhiyun  * param[1].u.value.a-b uuid of Client
281*4882a593Smuzhiyun  * param[1].u.value.c Login class of client OPTEE_MSG_LOGIN_*
282*4882a593Smuzhiyun  *
283*4882a593Smuzhiyun  * OPTEE_MSG_CMD_INVOKE_COMMAND invokes a command a previously opened
284*4882a593Smuzhiyun  * session to a Trusted Application.  struct optee_msg_arg::func is Trusted
285*4882a593Smuzhiyun  * Application function, specific to the Trusted Application.
286*4882a593Smuzhiyun  *
287*4882a593Smuzhiyun  * OPTEE_MSG_CMD_CLOSE_SESSION closes a previously opened session to
288*4882a593Smuzhiyun  * Trusted Application.
289*4882a593Smuzhiyun  *
290*4882a593Smuzhiyun  * OPTEE_MSG_CMD_CANCEL cancels a currently invoked command.
291*4882a593Smuzhiyun  *
292*4882a593Smuzhiyun  * OPTEE_MSG_CMD_REGISTER_SHM registers a shared memory reference. The
293*4882a593Smuzhiyun  * information is passed as:
294*4882a593Smuzhiyun  * [in] param[0].attr			OPTEE_MSG_ATTR_TYPE_TMEM_INPUT
295*4882a593Smuzhiyun  *					[| OPTEE_MSG_ATTR_FRAGMENT]
296*4882a593Smuzhiyun  * [in] param[0].u.tmem.buf_ptr		physical address (of first fragment)
297*4882a593Smuzhiyun  * [in] param[0].u.tmem.size		size (of first fragment)
298*4882a593Smuzhiyun  * [in] param[0].u.tmem.shm_ref		holds shared memory reference
299*4882a593Smuzhiyun  * ...
300*4882a593Smuzhiyun  * The shared memory can optionally be fragmented, temp memrefs can follow
301*4882a593Smuzhiyun  * each other with all but the last with the OPTEE_MSG_ATTR_FRAGMENT bit set.
302*4882a593Smuzhiyun  *
303*4882a593Smuzhiyun  * OPTEE_MSG_CMD_UNREGISTER_SHM unregisteres a previously registered shared
304*4882a593Smuzhiyun  * memory reference. The information is passed as:
305*4882a593Smuzhiyun  * [in] param[0].attr			OPTEE_MSG_ATTR_TYPE_RMEM_INPUT
306*4882a593Smuzhiyun  * [in] param[0].u.rmem.shm_ref		holds shared memory reference
307*4882a593Smuzhiyun  * [in] param[0].u.rmem.offs		0
308*4882a593Smuzhiyun  * [in] param[0].u.rmem.size		0
309*4882a593Smuzhiyun  */
310*4882a593Smuzhiyun #define OPTEE_MSG_CMD_OPEN_SESSION	0
311*4882a593Smuzhiyun #define OPTEE_MSG_CMD_INVOKE_COMMAND	1
312*4882a593Smuzhiyun #define OPTEE_MSG_CMD_CLOSE_SESSION	2
313*4882a593Smuzhiyun #define OPTEE_MSG_CMD_CANCEL		3
314*4882a593Smuzhiyun #define OPTEE_MSG_CMD_REGISTER_SHM	4
315*4882a593Smuzhiyun #define OPTEE_MSG_CMD_UNREGISTER_SHM	5
316*4882a593Smuzhiyun #define OPTEE_MSG_FUNCID_CALL_WITH_ARG	0x0004
317*4882a593Smuzhiyun 
318*4882a593Smuzhiyun /*****************************************************************************
319*4882a593Smuzhiyun  * Part 3 - Requests from secure world, RPC
320*4882a593Smuzhiyun  *****************************************************************************/
321*4882a593Smuzhiyun 
322*4882a593Smuzhiyun /*
323*4882a593Smuzhiyun  * All RPC is done with a struct optee_msg_arg as bearer of information,
324*4882a593Smuzhiyun  * struct optee_msg_arg::arg holds values defined by OPTEE_MSG_RPC_CMD_* below
325*4882a593Smuzhiyun  *
326*4882a593Smuzhiyun  * RPC communication with tee-supplicant is reversed compared to normal
327*4882a593Smuzhiyun  * client communication desribed above. The supplicant receives requests
328*4882a593Smuzhiyun  * and sends responses.
329*4882a593Smuzhiyun  */
330*4882a593Smuzhiyun 
331*4882a593Smuzhiyun /*
332*4882a593Smuzhiyun  * Load a TA into memory, defined in tee-supplicant
333*4882a593Smuzhiyun  */
334*4882a593Smuzhiyun #define OPTEE_MSG_RPC_CMD_LOAD_TA	0
335*4882a593Smuzhiyun 
336*4882a593Smuzhiyun /*
337*4882a593Smuzhiyun  * Reserved
338*4882a593Smuzhiyun  */
339*4882a593Smuzhiyun #define OPTEE_MSG_RPC_CMD_RPMB		1
340*4882a593Smuzhiyun 
341*4882a593Smuzhiyun /*
342*4882a593Smuzhiyun  * File system access, defined in tee-supplicant
343*4882a593Smuzhiyun  */
344*4882a593Smuzhiyun #define OPTEE_MSG_RPC_CMD_FS		2
345*4882a593Smuzhiyun 
346*4882a593Smuzhiyun /*
347*4882a593Smuzhiyun  * Get time
348*4882a593Smuzhiyun  *
349*4882a593Smuzhiyun  * Returns number of seconds and nano seconds since the Epoch,
350*4882a593Smuzhiyun  * 1970-01-01 00:00:00 +0000 (UTC).
351*4882a593Smuzhiyun  *
352*4882a593Smuzhiyun  * [out] param[0].u.value.a	Number of seconds
353*4882a593Smuzhiyun  * [out] param[0].u.value.b	Number of nano seconds.
354*4882a593Smuzhiyun  */
355*4882a593Smuzhiyun #define OPTEE_MSG_RPC_CMD_GET_TIME	3
356*4882a593Smuzhiyun 
357*4882a593Smuzhiyun /*
358*4882a593Smuzhiyun  * Wait queue primitive, helper for secure world to implement a wait queue.
359*4882a593Smuzhiyun  *
360*4882a593Smuzhiyun  * If secure world need to wait for a secure world mutex it issues a sleep
361*4882a593Smuzhiyun  * request instead of spinning in secure world. Conversely is a wakeup
362*4882a593Smuzhiyun  * request issued when a secure world mutex with a thread waiting thread is
363*4882a593Smuzhiyun  * unlocked.
364*4882a593Smuzhiyun  *
365*4882a593Smuzhiyun  * Waiting on a key
366*4882a593Smuzhiyun  * [in] param[0].u.value.a OPTEE_MSG_RPC_WAIT_QUEUE_SLEEP
367*4882a593Smuzhiyun  * [in] param[0].u.value.b wait key
368*4882a593Smuzhiyun  *
369*4882a593Smuzhiyun  * Waking up a key
370*4882a593Smuzhiyun  * [in] param[0].u.value.a OPTEE_MSG_RPC_WAIT_QUEUE_WAKEUP
371*4882a593Smuzhiyun  * [in] param[0].u.value.b wakeup key
372*4882a593Smuzhiyun  */
373*4882a593Smuzhiyun #define OPTEE_MSG_RPC_CMD_WAIT_QUEUE	4
374*4882a593Smuzhiyun #define OPTEE_MSG_RPC_WAIT_QUEUE_SLEEP	0
375*4882a593Smuzhiyun #define OPTEE_MSG_RPC_WAIT_QUEUE_WAKEUP	1
376*4882a593Smuzhiyun 
377*4882a593Smuzhiyun /*
378*4882a593Smuzhiyun  * Suspend execution
379*4882a593Smuzhiyun  *
380*4882a593Smuzhiyun  * [in] param[0].value	.a number of milliseconds to suspend
381*4882a593Smuzhiyun  */
382*4882a593Smuzhiyun #define OPTEE_MSG_RPC_CMD_SUSPEND	5
383*4882a593Smuzhiyun 
384*4882a593Smuzhiyun /*
385*4882a593Smuzhiyun  * Allocate a piece of shared memory
386*4882a593Smuzhiyun  *
387*4882a593Smuzhiyun  * Shared memory can optionally be fragmented, to support that additional
388*4882a593Smuzhiyun  * spare param entries are allocated to make room for eventual fragments.
389*4882a593Smuzhiyun  * The spare param entries has .attr = OPTEE_MSG_ATTR_TYPE_NONE when
390*4882a593Smuzhiyun  * unused. All returned temp memrefs except the last should have the
391*4882a593Smuzhiyun  * OPTEE_MSG_ATTR_FRAGMENT bit set in the attr field.
392*4882a593Smuzhiyun  *
393*4882a593Smuzhiyun  * [in]  param[0].u.value.a		type of memory one of
394*4882a593Smuzhiyun  *					OPTEE_MSG_RPC_SHM_TYPE_* below
395*4882a593Smuzhiyun  * [in]  param[0].u.value.b		requested size
396*4882a593Smuzhiyun  * [in]  param[0].u.value.c		required alignment
397*4882a593Smuzhiyun  *
398*4882a593Smuzhiyun  * [out] param[0].u.tmem.buf_ptr	physical address (of first fragment)
399*4882a593Smuzhiyun  * [out] param[0].u.tmem.size		size (of first fragment)
400*4882a593Smuzhiyun  * [out] param[0].u.tmem.shm_ref	shared memory reference
401*4882a593Smuzhiyun  * ...
402*4882a593Smuzhiyun  * [out] param[n].u.tmem.buf_ptr	physical address
403*4882a593Smuzhiyun  * [out] param[n].u.tmem.size		size
404*4882a593Smuzhiyun  * [out] param[n].u.tmem.shm_ref	shared memory reference (same value
405*4882a593Smuzhiyun  *					as in param[n-1].u.tmem.shm_ref)
406*4882a593Smuzhiyun  */
407*4882a593Smuzhiyun #define OPTEE_MSG_RPC_CMD_SHM_ALLOC	6
408*4882a593Smuzhiyun /* Memory that can be shared with a non-secure user space application */
409*4882a593Smuzhiyun #define OPTEE_MSG_RPC_SHM_TYPE_APPL	0
410*4882a593Smuzhiyun /* Memory only shared with non-secure kernel */
411*4882a593Smuzhiyun #define OPTEE_MSG_RPC_SHM_TYPE_KERNEL	1
412*4882a593Smuzhiyun 
413*4882a593Smuzhiyun /*
414*4882a593Smuzhiyun  * Free shared memory previously allocated with OPTEE_MSG_RPC_CMD_SHM_ALLOC
415*4882a593Smuzhiyun  *
416*4882a593Smuzhiyun  * [in]  param[0].u.value.a		type of memory one of
417*4882a593Smuzhiyun  *					OPTEE_MSG_RPC_SHM_TYPE_* above
418*4882a593Smuzhiyun  * [in]  param[0].u.value.b		value of shared memory reference
419*4882a593Smuzhiyun  *					returned in param[0].u.tmem.shm_ref
420*4882a593Smuzhiyun  *					above
421*4882a593Smuzhiyun  */
422*4882a593Smuzhiyun #define OPTEE_MSG_RPC_CMD_SHM_FREE	7
423*4882a593Smuzhiyun 
424*4882a593Smuzhiyun /*
425*4882a593Smuzhiyun  * Access a device on an i2c bus
426*4882a593Smuzhiyun  *
427*4882a593Smuzhiyun  * [in]  param[0].u.value.a		mode: RD(0), WR(1)
428*4882a593Smuzhiyun  * [in]  param[0].u.value.b		i2c adapter
429*4882a593Smuzhiyun  * [in]  param[0].u.value.c		i2c chip
430*4882a593Smuzhiyun  *
431*4882a593Smuzhiyun  * [in]  param[1].u.value.a		i2c control flags
432*4882a593Smuzhiyun  *
433*4882a593Smuzhiyun  * [in/out] memref[2]			buffer to exchange the transfer data
434*4882a593Smuzhiyun  *					with the secure world
435*4882a593Smuzhiyun  *
436*4882a593Smuzhiyun  * [out]  param[3].u.value.a		bytes transferred by the driver
437*4882a593Smuzhiyun  */
438*4882a593Smuzhiyun #define OPTEE_MSG_RPC_CMD_I2C_TRANSFER 21
439*4882a593Smuzhiyun /* I2C master transfer modes */
440*4882a593Smuzhiyun #define OPTEE_MSG_RPC_CMD_I2C_TRANSFER_RD 0
441*4882a593Smuzhiyun #define OPTEE_MSG_RPC_CMD_I2C_TRANSFER_WR 1
442*4882a593Smuzhiyun /* I2C master control flags */
443*4882a593Smuzhiyun #define OPTEE_MSG_RPC_CMD_I2C_FLAGS_TEN_BIT  BIT(0)
444*4882a593Smuzhiyun 
445*4882a593Smuzhiyun #endif /* _OPTEE_MSG_H */
446