xref: /OK3568_Linux_fs/kernel/include/uapi/linux/tee.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun  * Copyright (c) 2015-2016, Linaro Limited
3*4882a593Smuzhiyun  * All rights reserved.
4*4882a593Smuzhiyun  *
5*4882a593Smuzhiyun  * Redistribution and use in source and binary forms, with or without
6*4882a593Smuzhiyun  * modification, are permitted provided that the following conditions are met:
7*4882a593Smuzhiyun  *
8*4882a593Smuzhiyun  * 1. Redistributions of source code must retain the above copyright notice,
9*4882a593Smuzhiyun  * this list of conditions and the following disclaimer.
10*4882a593Smuzhiyun  *
11*4882a593Smuzhiyun  * 2. Redistributions in binary form must reproduce the above copyright notice,
12*4882a593Smuzhiyun  * this list of conditions and the following disclaimer in the documentation
13*4882a593Smuzhiyun  * and/or other materials provided with the distribution.
14*4882a593Smuzhiyun  *
15*4882a593Smuzhiyun  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16*4882a593Smuzhiyun  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17*4882a593Smuzhiyun  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18*4882a593Smuzhiyun  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
19*4882a593Smuzhiyun  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20*4882a593Smuzhiyun  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21*4882a593Smuzhiyun  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22*4882a593Smuzhiyun  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23*4882a593Smuzhiyun  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24*4882a593Smuzhiyun  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25*4882a593Smuzhiyun  * POSSIBILITY OF SUCH DAMAGE.
26*4882a593Smuzhiyun  */
27*4882a593Smuzhiyun 
28*4882a593Smuzhiyun #ifndef __TEE_H
29*4882a593Smuzhiyun #define __TEE_H
30*4882a593Smuzhiyun 
31*4882a593Smuzhiyun #include <linux/ioctl.h>
32*4882a593Smuzhiyun #include <linux/types.h>
33*4882a593Smuzhiyun 
34*4882a593Smuzhiyun /*
35*4882a593Smuzhiyun  * This file describes the API provided by a TEE driver to user space.
36*4882a593Smuzhiyun  *
37*4882a593Smuzhiyun  * Each TEE driver defines a TEE specific protocol which is used for the
38*4882a593Smuzhiyun  * data passed back and forth using TEE_IOC_CMD.
39*4882a593Smuzhiyun  */
40*4882a593Smuzhiyun 
41*4882a593Smuzhiyun /* Helpers to make the ioctl defines */
42*4882a593Smuzhiyun #define TEE_IOC_MAGIC	0xa4
43*4882a593Smuzhiyun #define TEE_IOC_BASE	0
44*4882a593Smuzhiyun 
45*4882a593Smuzhiyun /* Flags relating to shared memory */
46*4882a593Smuzhiyun #define TEE_IOCTL_SHM_MAPPED	0x1	/* memory mapped in normal world */
47*4882a593Smuzhiyun #define TEE_IOCTL_SHM_DMA_BUF	0x2	/* dma-buf handle on shared memory */
48*4882a593Smuzhiyun 
49*4882a593Smuzhiyun #define TEE_MAX_ARG_SIZE	1024
50*4882a593Smuzhiyun 
51*4882a593Smuzhiyun #define TEE_GEN_CAP_GP		(1 << 0)/* GlobalPlatform compliant TEE */
52*4882a593Smuzhiyun #define TEE_GEN_CAP_PRIVILEGED	(1 << 1)/* Privileged device (for supplicant) */
53*4882a593Smuzhiyun #define TEE_GEN_CAP_REG_MEM	(1 << 2)/* Supports registering shared memory */
54*4882a593Smuzhiyun #define TEE_GEN_CAP_MEMREF_NULL	(1 << 3)/* NULL MemRef support */
55*4882a593Smuzhiyun 
56*4882a593Smuzhiyun #define TEE_MEMREF_NULL		(__u64)(-1) /* NULL MemRef Buffer */
57*4882a593Smuzhiyun 
58*4882a593Smuzhiyun /*
59*4882a593Smuzhiyun  * TEE Implementation ID
60*4882a593Smuzhiyun  */
61*4882a593Smuzhiyun #define TEE_IMPL_ID_OPTEE	1
62*4882a593Smuzhiyun #define TEE_IMPL_ID_AMDTEE	2
63*4882a593Smuzhiyun 
64*4882a593Smuzhiyun /*
65*4882a593Smuzhiyun  * OP-TEE specific capabilities
66*4882a593Smuzhiyun  */
67*4882a593Smuzhiyun #define TEE_OPTEE_CAP_TZ	(1 << 0)
68*4882a593Smuzhiyun 
69*4882a593Smuzhiyun /**
70*4882a593Smuzhiyun  * struct tee_ioctl_version_data - TEE version
71*4882a593Smuzhiyun  * @impl_id:	[out] TEE implementation id
72*4882a593Smuzhiyun  * @impl_caps:	[out] Implementation specific capabilities
73*4882a593Smuzhiyun  * @gen_caps:	[out] Generic capabilities, defined by TEE_GEN_CAPS_* above
74*4882a593Smuzhiyun  *
75*4882a593Smuzhiyun  * Identifies the TEE implementation, @impl_id is one of TEE_IMPL_ID_* above.
76*4882a593Smuzhiyun  * @impl_caps is implementation specific, for example TEE_OPTEE_CAP_*
77*4882a593Smuzhiyun  * is valid when @impl_id == TEE_IMPL_ID_OPTEE.
78*4882a593Smuzhiyun  */
79*4882a593Smuzhiyun struct tee_ioctl_version_data {
80*4882a593Smuzhiyun 	__u32 impl_id;
81*4882a593Smuzhiyun 	__u32 impl_caps;
82*4882a593Smuzhiyun 	__u32 gen_caps;
83*4882a593Smuzhiyun };
84*4882a593Smuzhiyun 
85*4882a593Smuzhiyun /**
86*4882a593Smuzhiyun  * TEE_IOC_VERSION - query version of TEE
87*4882a593Smuzhiyun  *
88*4882a593Smuzhiyun  * Takes a tee_ioctl_version_data struct and returns with the TEE version
89*4882a593Smuzhiyun  * data filled in.
90*4882a593Smuzhiyun  */
91*4882a593Smuzhiyun #define TEE_IOC_VERSION		_IOR(TEE_IOC_MAGIC, TEE_IOC_BASE + 0, \
92*4882a593Smuzhiyun 				     struct tee_ioctl_version_data)
93*4882a593Smuzhiyun 
94*4882a593Smuzhiyun /**
95*4882a593Smuzhiyun  * struct tee_ioctl_shm_alloc_data - Shared memory allocate argument
96*4882a593Smuzhiyun  * @size:	[in/out] Size of shared memory to allocate
97*4882a593Smuzhiyun  * @flags:	[in/out] Flags to/from allocation.
98*4882a593Smuzhiyun  * @id:		[out] Identifier of the shared memory
99*4882a593Smuzhiyun  *
100*4882a593Smuzhiyun  * The flags field should currently be zero as input. Updated by the call
101*4882a593Smuzhiyun  * with actual flags as defined by TEE_IOCTL_SHM_* above.
102*4882a593Smuzhiyun  * This structure is used as argument for TEE_IOC_SHM_ALLOC below.
103*4882a593Smuzhiyun  */
104*4882a593Smuzhiyun struct tee_ioctl_shm_alloc_data {
105*4882a593Smuzhiyun 	__u64 size;
106*4882a593Smuzhiyun 	__u32 flags;
107*4882a593Smuzhiyun 	__s32 id;
108*4882a593Smuzhiyun };
109*4882a593Smuzhiyun 
110*4882a593Smuzhiyun /**
111*4882a593Smuzhiyun  * TEE_IOC_SHM_ALLOC - allocate shared memory
112*4882a593Smuzhiyun  *
113*4882a593Smuzhiyun  * Allocates shared memory between the user space process and secure OS.
114*4882a593Smuzhiyun  *
115*4882a593Smuzhiyun  * Returns a file descriptor on success or < 0 on failure
116*4882a593Smuzhiyun  *
117*4882a593Smuzhiyun  * The returned file descriptor is used to map the shared memory into user
118*4882a593Smuzhiyun  * space. The shared memory is freed when the descriptor is closed and the
119*4882a593Smuzhiyun  * memory is unmapped.
120*4882a593Smuzhiyun  */
121*4882a593Smuzhiyun #define TEE_IOC_SHM_ALLOC	_IOWR(TEE_IOC_MAGIC, TEE_IOC_BASE + 1, \
122*4882a593Smuzhiyun 				     struct tee_ioctl_shm_alloc_data)
123*4882a593Smuzhiyun 
124*4882a593Smuzhiyun /**
125*4882a593Smuzhiyun  * struct tee_ioctl_buf_data - Variable sized buffer
126*4882a593Smuzhiyun  * @buf_ptr:	[in] A __user pointer to a buffer
127*4882a593Smuzhiyun  * @buf_len:	[in] Length of the buffer above
128*4882a593Smuzhiyun  *
129*4882a593Smuzhiyun  * Used as argument for TEE_IOC_OPEN_SESSION, TEE_IOC_INVOKE,
130*4882a593Smuzhiyun  * TEE_IOC_SUPPL_RECV, and TEE_IOC_SUPPL_SEND below.
131*4882a593Smuzhiyun  */
132*4882a593Smuzhiyun struct tee_ioctl_buf_data {
133*4882a593Smuzhiyun 	__u64 buf_ptr;
134*4882a593Smuzhiyun 	__u64 buf_len;
135*4882a593Smuzhiyun };
136*4882a593Smuzhiyun 
137*4882a593Smuzhiyun /*
138*4882a593Smuzhiyun  * Attributes for struct tee_ioctl_param, selects field in the union
139*4882a593Smuzhiyun  */
140*4882a593Smuzhiyun #define TEE_IOCTL_PARAM_ATTR_TYPE_NONE		0	/* parameter not used */
141*4882a593Smuzhiyun 
142*4882a593Smuzhiyun /*
143*4882a593Smuzhiyun  * These defines value parameters (struct tee_ioctl_param_value)
144*4882a593Smuzhiyun  */
145*4882a593Smuzhiyun #define TEE_IOCTL_PARAM_ATTR_TYPE_VALUE_INPUT	1
146*4882a593Smuzhiyun #define TEE_IOCTL_PARAM_ATTR_TYPE_VALUE_OUTPUT	2
147*4882a593Smuzhiyun #define TEE_IOCTL_PARAM_ATTR_TYPE_VALUE_INOUT	3	/* input and output */
148*4882a593Smuzhiyun 
149*4882a593Smuzhiyun /*
150*4882a593Smuzhiyun  * These defines shared memory reference parameters (struct
151*4882a593Smuzhiyun  * tee_ioctl_param_memref)
152*4882a593Smuzhiyun  */
153*4882a593Smuzhiyun #define TEE_IOCTL_PARAM_ATTR_TYPE_MEMREF_INPUT	5
154*4882a593Smuzhiyun #define TEE_IOCTL_PARAM_ATTR_TYPE_MEMREF_OUTPUT	6
155*4882a593Smuzhiyun #define TEE_IOCTL_PARAM_ATTR_TYPE_MEMREF_INOUT	7	/* input and output */
156*4882a593Smuzhiyun 
157*4882a593Smuzhiyun /*
158*4882a593Smuzhiyun  * Mask for the type part of the attribute, leaves room for more types
159*4882a593Smuzhiyun  */
160*4882a593Smuzhiyun #define TEE_IOCTL_PARAM_ATTR_TYPE_MASK		0xff
161*4882a593Smuzhiyun 
162*4882a593Smuzhiyun /* Meta parameter carrying extra information about the message. */
163*4882a593Smuzhiyun #define TEE_IOCTL_PARAM_ATTR_META		0x100
164*4882a593Smuzhiyun 
165*4882a593Smuzhiyun /* Mask of all known attr bits */
166*4882a593Smuzhiyun #define TEE_IOCTL_PARAM_ATTR_MASK \
167*4882a593Smuzhiyun 	(TEE_IOCTL_PARAM_ATTR_TYPE_MASK | TEE_IOCTL_PARAM_ATTR_META)
168*4882a593Smuzhiyun 
169*4882a593Smuzhiyun /*
170*4882a593Smuzhiyun  * Matches TEEC_LOGIN_* in GP TEE Client API
171*4882a593Smuzhiyun  * Are only defined for GP compliant TEEs
172*4882a593Smuzhiyun  */
173*4882a593Smuzhiyun #define TEE_IOCTL_LOGIN_PUBLIC			0
174*4882a593Smuzhiyun #define TEE_IOCTL_LOGIN_USER			1
175*4882a593Smuzhiyun #define TEE_IOCTL_LOGIN_GROUP			2
176*4882a593Smuzhiyun #define TEE_IOCTL_LOGIN_APPLICATION		4
177*4882a593Smuzhiyun #define TEE_IOCTL_LOGIN_USER_APPLICATION	5
178*4882a593Smuzhiyun #define TEE_IOCTL_LOGIN_GROUP_APPLICATION	6
179*4882a593Smuzhiyun /*
180*4882a593Smuzhiyun  * Disallow user-space to use GP implementation specific login
181*4882a593Smuzhiyun  * method range (0x80000000 - 0xBFFFFFFF). This range is rather
182*4882a593Smuzhiyun  * being reserved for REE kernel clients or TEE implementation.
183*4882a593Smuzhiyun  */
184*4882a593Smuzhiyun #define TEE_IOCTL_LOGIN_REE_KERNEL_MIN		0x80000000
185*4882a593Smuzhiyun #define TEE_IOCTL_LOGIN_REE_KERNEL_MAX		0xBFFFFFFF
186*4882a593Smuzhiyun /* Private login method for REE kernel clients */
187*4882a593Smuzhiyun #define TEE_IOCTL_LOGIN_REE_KERNEL		0x80000000
188*4882a593Smuzhiyun 
189*4882a593Smuzhiyun /**
190*4882a593Smuzhiyun  * struct tee_ioctl_param - parameter
191*4882a593Smuzhiyun  * @attr: attributes
192*4882a593Smuzhiyun  * @a: if a memref, offset into the shared memory object, else a value parameter
193*4882a593Smuzhiyun  * @b: if a memref, size of the buffer, else a value parameter
194*4882a593Smuzhiyun  * @c: if a memref, shared memory identifier, else a value parameter
195*4882a593Smuzhiyun  *
196*4882a593Smuzhiyun  * @attr & TEE_PARAM_ATTR_TYPE_MASK indicates if memref or value is used in
197*4882a593Smuzhiyun  * the union. TEE_PARAM_ATTR_TYPE_VALUE_* indicates value and
198*4882a593Smuzhiyun  * TEE_PARAM_ATTR_TYPE_MEMREF_* indicates memref. TEE_PARAM_ATTR_TYPE_NONE
199*4882a593Smuzhiyun  * indicates that none of the members are used.
200*4882a593Smuzhiyun  *
201*4882a593Smuzhiyun  * Shared memory is allocated with TEE_IOC_SHM_ALLOC which returns an
202*4882a593Smuzhiyun  * identifier representing the shared memory object. A memref can reference
203*4882a593Smuzhiyun  * a part of a shared memory by specifying an offset (@a) and size (@b) of
204*4882a593Smuzhiyun  * the object. To supply the entire shared memory object set the offset
205*4882a593Smuzhiyun  * (@a) to 0 and size (@b) to the previously returned size of the object.
206*4882a593Smuzhiyun  *
207*4882a593Smuzhiyun  * A client may need to present a NULL pointer in the argument
208*4882a593Smuzhiyun  * passed to a trusted application in the TEE.
209*4882a593Smuzhiyun  * This is also a requirement in GlobalPlatform Client API v1.0c
210*4882a593Smuzhiyun  * (section 3.2.5 memory references), which can be found at
211*4882a593Smuzhiyun  * http://www.globalplatform.org/specificationsdevice.asp
212*4882a593Smuzhiyun  *
213*4882a593Smuzhiyun  * If a NULL pointer is passed to a TA in the TEE, the (@c)
214*4882a593Smuzhiyun  * IOCTL parameters value must be set to TEE_MEMREF_NULL indicating a NULL
215*4882a593Smuzhiyun  * memory reference.
216*4882a593Smuzhiyun  */
217*4882a593Smuzhiyun struct tee_ioctl_param {
218*4882a593Smuzhiyun 	__u64 attr;
219*4882a593Smuzhiyun 	__u64 a;
220*4882a593Smuzhiyun 	__u64 b;
221*4882a593Smuzhiyun 	__u64 c;
222*4882a593Smuzhiyun };
223*4882a593Smuzhiyun 
224*4882a593Smuzhiyun #define TEE_IOCTL_UUID_LEN		16
225*4882a593Smuzhiyun 
226*4882a593Smuzhiyun /**
227*4882a593Smuzhiyun  * struct tee_ioctl_open_session_arg - Open session argument
228*4882a593Smuzhiyun  * @uuid:	[in] UUID of the Trusted Application
229*4882a593Smuzhiyun  * @clnt_uuid:	[in] UUID of client
230*4882a593Smuzhiyun  * @clnt_login:	[in] Login class of client, TEE_IOCTL_LOGIN_* above
231*4882a593Smuzhiyun  * @cancel_id:	[in] Cancellation id, a unique value to identify this request
232*4882a593Smuzhiyun  * @session:	[out] Session id
233*4882a593Smuzhiyun  * @ret:	[out] return value
234*4882a593Smuzhiyun  * @ret_origin	[out] origin of the return value
235*4882a593Smuzhiyun  * @num_params	[in] number of parameters following this struct
236*4882a593Smuzhiyun  */
237*4882a593Smuzhiyun struct tee_ioctl_open_session_arg {
238*4882a593Smuzhiyun 	__u8 uuid[TEE_IOCTL_UUID_LEN];
239*4882a593Smuzhiyun 	__u8 clnt_uuid[TEE_IOCTL_UUID_LEN];
240*4882a593Smuzhiyun 	__u32 clnt_login;
241*4882a593Smuzhiyun 	__u32 cancel_id;
242*4882a593Smuzhiyun 	__u32 session;
243*4882a593Smuzhiyun 	__u32 ret;
244*4882a593Smuzhiyun 	__u32 ret_origin;
245*4882a593Smuzhiyun 	__u32 num_params;
246*4882a593Smuzhiyun 	/* num_params tells the actual number of element in params */
247*4882a593Smuzhiyun 	struct tee_ioctl_param params[];
248*4882a593Smuzhiyun };
249*4882a593Smuzhiyun 
250*4882a593Smuzhiyun /**
251*4882a593Smuzhiyun  * TEE_IOC_OPEN_SESSION - opens a session to a Trusted Application
252*4882a593Smuzhiyun  *
253*4882a593Smuzhiyun  * Takes a struct tee_ioctl_buf_data which contains a struct
254*4882a593Smuzhiyun  * tee_ioctl_open_session_arg followed by any array of struct
255*4882a593Smuzhiyun  * tee_ioctl_param
256*4882a593Smuzhiyun  */
257*4882a593Smuzhiyun #define TEE_IOC_OPEN_SESSION	_IOR(TEE_IOC_MAGIC, TEE_IOC_BASE + 2, \
258*4882a593Smuzhiyun 				     struct tee_ioctl_buf_data)
259*4882a593Smuzhiyun 
260*4882a593Smuzhiyun /**
261*4882a593Smuzhiyun  * struct tee_ioctl_invoke_func_arg - Invokes a function in a Trusted
262*4882a593Smuzhiyun  * Application
263*4882a593Smuzhiyun  * @func:	[in] Trusted Application function, specific to the TA
264*4882a593Smuzhiyun  * @session:	[in] Session id
265*4882a593Smuzhiyun  * @cancel_id:	[in] Cancellation id, a unique value to identify this request
266*4882a593Smuzhiyun  * @ret:	[out] return value
267*4882a593Smuzhiyun  * @ret_origin	[out] origin of the return value
268*4882a593Smuzhiyun  * @num_params	[in] number of parameters following this struct
269*4882a593Smuzhiyun  */
270*4882a593Smuzhiyun struct tee_ioctl_invoke_arg {
271*4882a593Smuzhiyun 	__u32 func;
272*4882a593Smuzhiyun 	__u32 session;
273*4882a593Smuzhiyun 	__u32 cancel_id;
274*4882a593Smuzhiyun 	__u32 ret;
275*4882a593Smuzhiyun 	__u32 ret_origin;
276*4882a593Smuzhiyun 	__u32 num_params;
277*4882a593Smuzhiyun 	/* num_params tells the actual number of element in params */
278*4882a593Smuzhiyun 	struct tee_ioctl_param params[];
279*4882a593Smuzhiyun };
280*4882a593Smuzhiyun 
281*4882a593Smuzhiyun /**
282*4882a593Smuzhiyun  * TEE_IOC_INVOKE - Invokes a function in a Trusted Application
283*4882a593Smuzhiyun  *
284*4882a593Smuzhiyun  * Takes a struct tee_ioctl_buf_data which contains a struct
285*4882a593Smuzhiyun  * tee_invoke_func_arg followed by any array of struct tee_param
286*4882a593Smuzhiyun  */
287*4882a593Smuzhiyun #define TEE_IOC_INVOKE		_IOR(TEE_IOC_MAGIC, TEE_IOC_BASE + 3, \
288*4882a593Smuzhiyun 				     struct tee_ioctl_buf_data)
289*4882a593Smuzhiyun 
290*4882a593Smuzhiyun /**
291*4882a593Smuzhiyun  * struct tee_ioctl_cancel_arg - Cancels an open session or invoke ioctl
292*4882a593Smuzhiyun  * @cancel_id:	[in] Cancellation id, a unique value to identify this request
293*4882a593Smuzhiyun  * @session:	[in] Session id, if the session is opened, else set to 0
294*4882a593Smuzhiyun  */
295*4882a593Smuzhiyun struct tee_ioctl_cancel_arg {
296*4882a593Smuzhiyun 	__u32 cancel_id;
297*4882a593Smuzhiyun 	__u32 session;
298*4882a593Smuzhiyun };
299*4882a593Smuzhiyun 
300*4882a593Smuzhiyun /**
301*4882a593Smuzhiyun  * TEE_IOC_CANCEL - Cancels an open session or invoke
302*4882a593Smuzhiyun  */
303*4882a593Smuzhiyun #define TEE_IOC_CANCEL		_IOR(TEE_IOC_MAGIC, TEE_IOC_BASE + 4, \
304*4882a593Smuzhiyun 				     struct tee_ioctl_cancel_arg)
305*4882a593Smuzhiyun 
306*4882a593Smuzhiyun /**
307*4882a593Smuzhiyun  * struct tee_ioctl_close_session_arg - Closes an open session
308*4882a593Smuzhiyun  * @session:	[in] Session id
309*4882a593Smuzhiyun  */
310*4882a593Smuzhiyun struct tee_ioctl_close_session_arg {
311*4882a593Smuzhiyun 	__u32 session;
312*4882a593Smuzhiyun };
313*4882a593Smuzhiyun 
314*4882a593Smuzhiyun /**
315*4882a593Smuzhiyun  * TEE_IOC_CLOSE_SESSION - Closes a session
316*4882a593Smuzhiyun  */
317*4882a593Smuzhiyun #define TEE_IOC_CLOSE_SESSION	_IOR(TEE_IOC_MAGIC, TEE_IOC_BASE + 5, \
318*4882a593Smuzhiyun 				     struct tee_ioctl_close_session_arg)
319*4882a593Smuzhiyun 
320*4882a593Smuzhiyun /**
321*4882a593Smuzhiyun  * struct tee_iocl_supp_recv_arg - Receive a request for a supplicant function
322*4882a593Smuzhiyun  * @func:	[in] supplicant function
323*4882a593Smuzhiyun  * @num_params	[in/out] number of parameters following this struct
324*4882a593Smuzhiyun  *
325*4882a593Smuzhiyun  * @num_params is the number of params that tee-supplicant has room to
326*4882a593Smuzhiyun  * receive when input, @num_params is the number of actual params
327*4882a593Smuzhiyun  * tee-supplicant receives when output.
328*4882a593Smuzhiyun  */
329*4882a593Smuzhiyun struct tee_iocl_supp_recv_arg {
330*4882a593Smuzhiyun 	__u32 func;
331*4882a593Smuzhiyun 	__u32 num_params;
332*4882a593Smuzhiyun 	/* num_params tells the actual number of element in params */
333*4882a593Smuzhiyun 	struct tee_ioctl_param params[];
334*4882a593Smuzhiyun };
335*4882a593Smuzhiyun 
336*4882a593Smuzhiyun /**
337*4882a593Smuzhiyun  * TEE_IOC_SUPPL_RECV - Receive a request for a supplicant function
338*4882a593Smuzhiyun  *
339*4882a593Smuzhiyun  * Takes a struct tee_ioctl_buf_data which contains a struct
340*4882a593Smuzhiyun  * tee_iocl_supp_recv_arg followed by any array of struct tee_param
341*4882a593Smuzhiyun  */
342*4882a593Smuzhiyun #define TEE_IOC_SUPPL_RECV	_IOR(TEE_IOC_MAGIC, TEE_IOC_BASE + 6, \
343*4882a593Smuzhiyun 				     struct tee_ioctl_buf_data)
344*4882a593Smuzhiyun 
345*4882a593Smuzhiyun /**
346*4882a593Smuzhiyun  * struct tee_iocl_supp_send_arg - Send a response to a received request
347*4882a593Smuzhiyun  * @ret:	[out] return value
348*4882a593Smuzhiyun  * @num_params	[in] number of parameters following this struct
349*4882a593Smuzhiyun  */
350*4882a593Smuzhiyun struct tee_iocl_supp_send_arg {
351*4882a593Smuzhiyun 	__u32 ret;
352*4882a593Smuzhiyun 	__u32 num_params;
353*4882a593Smuzhiyun 	/* num_params tells the actual number of element in params */
354*4882a593Smuzhiyun 	struct tee_ioctl_param params[];
355*4882a593Smuzhiyun };
356*4882a593Smuzhiyun 
357*4882a593Smuzhiyun /**
358*4882a593Smuzhiyun  * TEE_IOC_SUPPL_SEND - Receive a request for a supplicant function
359*4882a593Smuzhiyun  *
360*4882a593Smuzhiyun  * Takes a struct tee_ioctl_buf_data which contains a struct
361*4882a593Smuzhiyun  * tee_iocl_supp_send_arg followed by any array of struct tee_param
362*4882a593Smuzhiyun  */
363*4882a593Smuzhiyun #define TEE_IOC_SUPPL_SEND	_IOR(TEE_IOC_MAGIC, TEE_IOC_BASE + 7, \
364*4882a593Smuzhiyun 				     struct tee_ioctl_buf_data)
365*4882a593Smuzhiyun 
366*4882a593Smuzhiyun /**
367*4882a593Smuzhiyun  * struct tee_ioctl_shm_register_data - Shared memory register argument
368*4882a593Smuzhiyun  * @addr:      [in] Start address of shared memory to register
369*4882a593Smuzhiyun  * @length:    [in/out] Length of shared memory to register
370*4882a593Smuzhiyun  * @flags:     [in/out] Flags to/from registration.
371*4882a593Smuzhiyun  * @id:                [out] Identifier of the shared memory
372*4882a593Smuzhiyun  *
373*4882a593Smuzhiyun  * The flags field should currently be zero as input. Updated by the call
374*4882a593Smuzhiyun  * with actual flags as defined by TEE_IOCTL_SHM_* above.
375*4882a593Smuzhiyun  * This structure is used as argument for TEE_IOC_SHM_REGISTER below.
376*4882a593Smuzhiyun  */
377*4882a593Smuzhiyun struct tee_ioctl_shm_register_data {
378*4882a593Smuzhiyun 	__u64 addr;
379*4882a593Smuzhiyun 	__u64 length;
380*4882a593Smuzhiyun 	__u32 flags;
381*4882a593Smuzhiyun 	__s32 id;
382*4882a593Smuzhiyun };
383*4882a593Smuzhiyun 
384*4882a593Smuzhiyun /**
385*4882a593Smuzhiyun  * TEE_IOC_SHM_REGISTER - Register shared memory argument
386*4882a593Smuzhiyun  *
387*4882a593Smuzhiyun  * Registers shared memory between the user space process and secure OS.
388*4882a593Smuzhiyun  *
389*4882a593Smuzhiyun  * Returns a file descriptor on success or < 0 on failure
390*4882a593Smuzhiyun  *
391*4882a593Smuzhiyun  * The shared memory is unregisterred when the descriptor is closed.
392*4882a593Smuzhiyun  */
393*4882a593Smuzhiyun #define TEE_IOC_SHM_REGISTER   _IOWR(TEE_IOC_MAGIC, TEE_IOC_BASE + 9, \
394*4882a593Smuzhiyun 				     struct tee_ioctl_shm_register_data)
395*4882a593Smuzhiyun /*
396*4882a593Smuzhiyun  * Five syscalls are used when communicating with the TEE driver.
397*4882a593Smuzhiyun  * open(): opens the device associated with the driver
398*4882a593Smuzhiyun  * ioctl(): as described above operating on the file descriptor from open()
399*4882a593Smuzhiyun  * close(): two cases
400*4882a593Smuzhiyun  *   - closes the device file descriptor
401*4882a593Smuzhiyun  *   - closes a file descriptor connected to allocated shared memory
402*4882a593Smuzhiyun  * mmap(): maps shared memory into user space using information from struct
403*4882a593Smuzhiyun  *	   tee_ioctl_shm_alloc_data
404*4882a593Smuzhiyun  * munmap(): unmaps previously shared memory
405*4882a593Smuzhiyun  */
406*4882a593Smuzhiyun 
407*4882a593Smuzhiyun #endif /*__TEE_H*/
408