xref: /rk3399_rockchip-uboot/include/optee_include/tee_client_api.h (revision abdd24375050db7ce121b48477cc332d6c8c40f6)
1*abdd2437Shisping /*
2*abdd2437Shisping  * Copyright 2017, Rockchip Electronics Co., Ltd
3*abdd2437Shisping  * hisping lin, <hisping.lin@rock-chips.com>
4*abdd2437Shisping  *
5*abdd2437Shisping  * SPDX-License-Identifier:	GPL-2.0+
6*abdd2437Shisping  */
7*abdd2437Shisping #ifndef TEE_CLIENT_API_H
8*abdd2437Shisping #define TEE_CLIENT_API_H
9*abdd2437Shisping 
10*abdd2437Shisping #include <optee_include/tee_base_types.h>
11*abdd2437Shisping /*
12*abdd2437Shisping  * Defines the number of available memory references in an open session or
13*abdd2437Shisping  * invoke command operation payload.
14*abdd2437Shisping  */
15*abdd2437Shisping #define TEEC_CONFIG_PAYLOAD_REF_COUNT 4
16*abdd2437Shisping 
17*abdd2437Shisping /**
18*abdd2437Shisping  * Defines the maximum size of a single shared memory block, in bytes, of both
19*abdd2437Shisping  * API allocated and API registered memory. The size is currently set to
20*abdd2437Shisping  * 512 * kB (512 * 1024).
21*abdd2437Shisping  */
22*abdd2437Shisping #define TEEC_CONFIG_SHAREDMEM_MAX_SIZE 0x8000
23*abdd2437Shisping 
24*abdd2437Shisping /**
25*abdd2437Shisping  * Flag constants indicating the type of parameters encoded inside the
26*abdd2437Shisping  * operation payload (TEEC_Operation), Type is uint32_t.
27*abdd2437Shisping  *
28*abdd2437Shisping  * TEEC_NONE                   The Parameter is not used
29*abdd2437Shisping  *
30*abdd2437Shisping  * TEEC_VALUE_INPUT            The Parameter is a TEEC_Value tagged as input.
31*abdd2437Shisping  *
32*abdd2437Shisping  * TEEC_VALUE_OUTPUT           The Parameter is a TEEC_Value tagged as output.
33*abdd2437Shisping  *
34*abdd2437Shisping  * TEEC_VALUE_INOUT            The Parameter is a TEEC_Value tagged as both as
35*abdd2437Shisping  *                             input and output, i.e., for which both the
36*abdd2437Shisping  *                             behaviors of TEEC_VALUE_INPUT and
37*abdd2437Shisping  *                             TEEC_VALUE_OUTPUT apply.
38*abdd2437Shisping  *
39*abdd2437Shisping  * TEEC_MEMREF_TEMP_INPUT      The Parameter is a TEEC_TempMemoryReference
40*abdd2437Shisping  *                             describing a region of memory which needs to be
41*abdd2437Shisping  *                             temporarily registered for the duration of the
42*abdd2437Shisping  *                             Operation and is tagged as input.
43*abdd2437Shisping  *
44*abdd2437Shisping  * TEEC_MEMREF_TEMP_OUTPUT     Same as TEEC_MEMREF_TEMP_INPUT, but the Memory
45*abdd2437Shisping  *                             Reference is tagged as output. The
46*abdd2437Shisping  *                             Implementation may update the size field to
47*abdd2437Shisping  *                             reflect the required output size in some use
48*abdd2437Shisping  *                             cases.
49*abdd2437Shisping  *
50*abdd2437Shisping  * TEEC_MEMREF_TEMP_INOUT      A Temporary Memory Reference tagged as both
51*abdd2437Shisping  *                             input and output, i.e., for which both the
52*abdd2437Shisping  *                             behaviors of TEEC_MEMREF_TEMP_INPUT and
53*abdd2437Shisping  *                             TEEC_MEMREF_TEMP_OUTPUT apply.
54*abdd2437Shisping  *
55*abdd2437Shisping  * TEEC_MEMREF_WHOLE           The Parameter is a Registered Memory Reference
56*abdd2437Shisping  *                             that refers to the entirety of its parent Shared
57*abdd2437Shisping  *                             Memory block. The parameter structure is a
58*abdd2437Shisping  *                             TEEC_MemoryReference. In this structure, the
59*abdd2437Shisping  *                             Implementation MUST read only the parent field
60*abdd2437Shisping  *                             and MAY update the size field when the operation
61*abdd2437Shisping  *                             completes.
62*abdd2437Shisping  *
63*abdd2437Shisping  * TEEC_MEMREF_PARTIAL_INPUT   A Registered Memory Reference structure that
64*abdd2437Shisping  *                             refers to a partial region of its parent Shared
65*abdd2437Shisping  *                             Memory block and is tagged as input.
66*abdd2437Shisping  *
67*abdd2437Shisping  * TEEC_MEMREF_PARTIAL_OUTPUT  Registered Memory Reference structure that
68*abdd2437Shisping  *                             refers to a partial region of its parent Shared
69*abdd2437Shisping  *                             Memory block and is tagged as output.
70*abdd2437Shisping  *
71*abdd2437Shisping  * TEEC_MEMREF_PARTIAL_INOUT   The Registered Memory Reference structure that
72*abdd2437Shisping  *                             refers to a partial region of its parent Shared
73*abdd2437Shisping  *                             Memory block and is tagged as both input and
74*abdd2437Shisping  *                             output, i.e., for which both the behaviors of
75*abdd2437Shisping  *                             TEEC_MEMREF_PARTIAL_INPUT and
76*abdd2437Shisping  *                             TEEC_MEMREF_PARTIAL_OUTPUT apply.
77*abdd2437Shisping  */
78*abdd2437Shisping #define TEEC_NONE                   0x00000000
79*abdd2437Shisping #define TEEC_VALUE_INPUT            0x00000001
80*abdd2437Shisping #define TEEC_VALUE_OUTPUT           0x00000002
81*abdd2437Shisping #define TEEC_VALUE_INOUT            0x00000003
82*abdd2437Shisping #define TEEC_MEMREF_TEMP_INPUT      0x00000005
83*abdd2437Shisping #define TEEC_MEMREF_TEMP_OUTPUT     0x00000006
84*abdd2437Shisping #define TEEC_MEMREF_TEMP_INOUT      0x00000007
85*abdd2437Shisping #define TEEC_MEMREF_WHOLE           0x0000000C
86*abdd2437Shisping #define TEEC_MEMREF_PARTIAL_INPUT   0x0000000D
87*abdd2437Shisping #define TEEC_MEMREF_PARTIAL_OUTPUT  0x0000000E
88*abdd2437Shisping #define TEEC_MEMREF_PARTIAL_INOUT   0x0000000F
89*abdd2437Shisping 
90*abdd2437Shisping /**
91*abdd2437Shisping  * Flag constants indicating the data transfer direction of memory in
92*abdd2437Shisping  * TEEC_Parameter. TEEC_MEM_INPUT signifies data transfer direction from the
93*abdd2437Shisping  * client application to the TEE. TEEC_MEM_OUTPUT signifies data transfer
94*abdd2437Shisping  * direction from the TEE to the client application. Type is uint32_t.
95*abdd2437Shisping  *
96*abdd2437Shisping  * TEEC_MEM_INPUT   The Shared Memory can carry data from the client
97*abdd2437Shisping  *                  application to the Trusted Application.
98*abdd2437Shisping  * TEEC_MEM_OUTPUT  The Shared Memory can carry data from the Trusted
99*abdd2437Shisping  *                  Application to the client application.
100*abdd2437Shisping  */
101*abdd2437Shisping #define TEEC_MEM_INPUT   0x00000001
102*abdd2437Shisping #define TEEC_MEM_OUTPUT  0x00000002
103*abdd2437Shisping 
104*abdd2437Shisping /**
105*abdd2437Shisping  * Return values. Type is TEEC_Result
106*abdd2437Shisping  *
107*abdd2437Shisping  * TEEC_SUCCESS                 The operation was successful.
108*abdd2437Shisping  * TEEC_ERROR_GENERIC           Non-specific cause.
109*abdd2437Shisping  * TEEC_ERROR_ACCESS_DENIED     Access privileges are not sufficient.
110*abdd2437Shisping  * TEEC_ERROR_CANCEL            The operation was canceled.
111*abdd2437Shisping  * TEEC_ERROR_ACCESS_CONFLICT   Concurrent accesses caused conflict.
112*abdd2437Shisping  * TEEC_ERROR_EXCESS_DATA       Too much data for the requested operation was
113*abdd2437Shisping  *                              passed.
114*abdd2437Shisping  * TEEC_ERROR_BAD_FORMAT        Input data was of invalid format.
115*abdd2437Shisping  * TEEC_ERROR_BAD_PARAMETERS    Input parameters were invalid.
116*abdd2437Shisping  * TEEC_ERROR_BAD_STATE         Operation is not valid in the current state.
117*abdd2437Shisping  * TEEC_ERROR_ITEM_NOT_FOUND    The requested data item is not found.
118*abdd2437Shisping  * TEEC_ERROR_NOT_IMPLEMENTED   The requested operation should exist but is not
119*abdd2437Shisping  *                              yet implemented.
120*abdd2437Shisping  * TEEC_ERROR_NOT_SUPPORTED     The requested operation is valid but is not
121*abdd2437Shisping  *                              supported in this implementation.
122*abdd2437Shisping  * TEEC_ERROR_NO_DATA           Expected data was missing.
123*abdd2437Shisping  * TEEC_ERROR_OUT_OF_MEMORY     System ran out of resources.
124*abdd2437Shisping  * TEEC_ERROR_BUSY              The system is busy working on something else.
125*abdd2437Shisping  * TEEC_ERROR_COMMUNICATION     Communication with a remote party failed.
126*abdd2437Shisping  * TEEC_ERROR_SECURITY          A security fault was detected.
127*abdd2437Shisping  * TEEC_ERROR_SHORT_BUFFER      The supplied buffer is too short for the
128*abdd2437Shisping  *                              generated output.
129*abdd2437Shisping  * TEEC_ERROR_TARGET_DEAD       Trusted Application has panicked
130*abdd2437Shisping  *                              during the operation.
131*abdd2437Shisping  */
132*abdd2437Shisping 
133*abdd2437Shisping /**
134*abdd2437Shisping  *  Standard defined error codes.
135*abdd2437Shisping  */
136*abdd2437Shisping #define TEEC_SUCCESS                0x00000000
137*abdd2437Shisping #define TEEC_ERROR_GENERIC          0xFFFF0000
138*abdd2437Shisping #define TEEC_ERROR_ACCESS_DENIED    0xFFFF0001
139*abdd2437Shisping #define TEEC_ERROR_CANCEL           0xFFFF0002
140*abdd2437Shisping #define TEEC_ERROR_ACCESS_CONFLICT  0xFFFF0003
141*abdd2437Shisping #define TEEC_ERROR_EXCESS_DATA      0xFFFF0004
142*abdd2437Shisping #define TEEC_ERROR_BAD_FORMAT       0xFFFF0005
143*abdd2437Shisping #define TEEC_ERROR_BAD_PARAMETERS   0xFFFF0006
144*abdd2437Shisping #define TEEC_ERROR_BAD_STATE        0xFFFF0007
145*abdd2437Shisping #define TEEC_ERROR_ITEM_NOT_FOUND   0xFFFF0008
146*abdd2437Shisping #define TEEC_ERROR_NOT_IMPLEMENTED  0xFFFF0009
147*abdd2437Shisping #define TEEC_ERROR_NOT_SUPPORTED    0xFFFF000A
148*abdd2437Shisping #define TEEC_ERROR_NO_DATA          0xFFFF000B
149*abdd2437Shisping #define TEEC_ERROR_OUT_OF_MEMORY    0xFFFF000C
150*abdd2437Shisping #define TEEC_ERROR_BUSY             0xFFFF000D
151*abdd2437Shisping #define TEEC_ERROR_COMMUNICATION    0xFFFF000E
152*abdd2437Shisping #define TEEC_ERROR_SECURITY         0xFFFF000F
153*abdd2437Shisping #define TEEC_ERROR_SHORT_BUFFER     0xFFFF0010
154*abdd2437Shisping #define TEEC_ERROR_TARGET_DEAD      0xFFFF3024
155*abdd2437Shisping 
156*abdd2437Shisping /**
157*abdd2437Shisping  * Function error origins, of type TEEC_ErrorOrigin. These indicate where in
158*abdd2437Shisping  * the software stack a particular return value originates from.
159*abdd2437Shisping  *
160*abdd2437Shisping  * TEEC_ORIGIN_API          The error originated within the TEE Client API
161*abdd2437Shisping  *                          implementation.
162*abdd2437Shisping  * TEEC_ORIGIN_COMMS        The error originated within the underlying
163*abdd2437Shisping  *                          communications stack linking the rich OS with
164*abdd2437Shisping  *                          the TEE.
165*abdd2437Shisping  * TEEC_ORIGIN_TEE          The error originated within the common TEE code.
166*abdd2437Shisping  * TEEC_ORIGIN_TRUSTED_APP  The error originated within the Trusted Application
167*abdd2437Shisping  *                          code.
168*abdd2437Shisping  */
169*abdd2437Shisping #define TEEC_ORIGIN_API          0x00000001
170*abdd2437Shisping #define TEEC_ORIGIN_COMMS        0x00000002
171*abdd2437Shisping #define TEEC_ORIGIN_TEE          0x00000003
172*abdd2437Shisping #define TEEC_ORIGIN_TRUSTED_APP  0x00000004
173*abdd2437Shisping 
174*abdd2437Shisping /**
175*abdd2437Shisping  * Session login methods, for use in TEEC_OpenSession() as parameter
176*abdd2437Shisping  * connectionMethod. Type is uint32_t.
177*abdd2437Shisping  *
178*abdd2437Shisping  * TEEC_LOGIN_PUBLIC       No login data is provided.
179*abdd2437Shisping  * TEEC_LOGIN_USER         Login data about the user running the Client
180*abdd2437Shisping  *                         Application process is provided.
181*abdd2437Shisping  * TEEC_LOGIN_GROUP        Login data about the group running the Client
182*abdd2437Shisping  *                         Application process is provided.
183*abdd2437Shisping  * TEEC_LOGIN_APPLICATION  Login data about the running Client Application
184*abdd2437Shisping  *                         itself is provided.
185*abdd2437Shisping  */
186*abdd2437Shisping #define TEEC_LOGIN_PUBLIC       0x00000000
187*abdd2437Shisping #define TEEC_LOGIN_USER         0x00000001
188*abdd2437Shisping #define TEEC_LOGIN_GROUP        0x00000002
189*abdd2437Shisping #define TEEC_LOGIN_APPLICATION  0x00000004
190*abdd2437Shisping 
191*abdd2437Shisping /**
192*abdd2437Shisping  * Encode the paramTypes according to the supplied types.
193*abdd2437Shisping  *
194*abdd2437Shisping  * @param p0 The first param type.
195*abdd2437Shisping  * @param p1 The second param type.
196*abdd2437Shisping  * @param p2 The third param type.
197*abdd2437Shisping  * @param p3 The fourth param type.
198*abdd2437Shisping  */
199*abdd2437Shisping #define TEEC_PARAM_TYPES(p0, p1, p2, p3) \
200*abdd2437Shisping 	((p0) | ((p1) << 4) | ((p2) << 8) | ((p3) << 12))
201*abdd2437Shisping 
202*abdd2437Shisping /**
203*abdd2437Shisping  * Get the i_th param type from the paramType.
204*abdd2437Shisping  *
205*abdd2437Shisping  * @param p The paramType.
206*abdd2437Shisping  * @param i The i-th parameter to get the type for.
207*abdd2437Shisping  */
208*abdd2437Shisping #define TEEC_PARAM_TYPE_GET(p, i) (((p) >> (i * 4)) & 0xF)
209*abdd2437Shisping 
210*abdd2437Shisping typedef uint32_t TEEC_Result;
211*abdd2437Shisping 
212*abdd2437Shisping /**
213*abdd2437Shisping  * struct TEEC_Context - Represents a connection between a client application
214*abdd2437Shisping  * and a TEE.
215*abdd2437Shisping  */
216*abdd2437Shisping typedef struct {
217*abdd2437Shisping 	char devname[256];
218*abdd2437Shisping 	int fd;
219*abdd2437Shisping } TEEC_Context;
220*abdd2437Shisping 
221*abdd2437Shisping /**
222*abdd2437Shisping  * This type contains a Universally Unique Resource Identifier (UUID) type as
223*abdd2437Shisping  * defined in RFC4122. These UUID values are used to identify Trusted
224*abdd2437Shisping  * Applications.
225*abdd2437Shisping  */
226*abdd2437Shisping typedef struct {
227*abdd2437Shisping 	uint32_t timeLow;
228*abdd2437Shisping 	uint16_t timeMid;
229*abdd2437Shisping 	uint16_t timeHiAndVersion;
230*abdd2437Shisping 	uint8_t clockSeqAndNode[8];
231*abdd2437Shisping } TEEC_UUID;
232*abdd2437Shisping 
233*abdd2437Shisping /**
234*abdd2437Shisping  * struct TEEC_SharedMemory - Memory to transfer data between a client
235*abdd2437Shisping  * application and trusted code.
236*abdd2437Shisping  *
237*abdd2437Shisping  * @param buffer      The memory buffer which is to be, or has been, shared
238*abdd2437Shisping  *                    with the TEE.
239*abdd2437Shisping  * @param size        The size, in bytes, of the memory buffer.
240*abdd2437Shisping  * @param flags       Bit-vector which holds properties of buffer.
241*abdd2437Shisping  *                    The bit-vector can contain either or both of the
242*abdd2437Shisping  *                    TEEC_MEM_INPUT and TEEC_MEM_OUTPUT flags.
243*abdd2437Shisping  *
244*abdd2437Shisping  * A shared memory block is a region of memory allocated in the context of the
245*abdd2437Shisping  * client application memory space that can be used to transfer data between
246*abdd2437Shisping  * that client application and a trusted application. The user of this struct
247*abdd2437Shisping  * is responsible to populate the buffer pointer.
248*abdd2437Shisping  */
249*abdd2437Shisping typedef struct {
250*abdd2437Shisping 	void *buffer;
251*abdd2437Shisping 	size_t size;
252*abdd2437Shisping 	uint32_t flags;
253*abdd2437Shisping 	/*
254*abdd2437Shisping 	 * Implementation-Defined
255*abdd2437Shisping 	 *
256*abdd2437Shisping 	 * These represent a pointer to an allocated buffer.
257*abdd2437Shisping 	 * This can be different from the
258*abdd2437Shisping 	 * "buffer" above if the caller tried to register
259*abdd2437Shisping 	 * a buffer rather than allocate one.
260*abdd2437Shisping 	 */
261*abdd2437Shisping 	void   *alloc_buffer;
262*abdd2437Shisping } TEEC_SharedMemory;
263*abdd2437Shisping 
264*abdd2437Shisping /**
265*abdd2437Shisping  * struct TEEC_TempMemoryReference - Temporary memory to transfer data between
266*abdd2437Shisping  * a client application and trusted code, only used for the duration of the
267*abdd2437Shisping  * operation.
268*abdd2437Shisping  *
269*abdd2437Shisping  * @param buffer  The memory buffer which is to be, or has been shared with
270*abdd2437Shisping  *                the TEE.
271*abdd2437Shisping  * @param size    The size, in bytes, of the memory buffer.
272*abdd2437Shisping  *
273*abdd2437Shisping  * A memory buffer that is registered temporarily for the duration of the
274*abdd2437Shisping  * operation to be called.
275*abdd2437Shisping  */
276*abdd2437Shisping typedef struct {
277*abdd2437Shisping 	void *buffer;
278*abdd2437Shisping 	size_t size;
279*abdd2437Shisping } TEEC_TempMemoryReference;
280*abdd2437Shisping 
281*abdd2437Shisping /**
282*abdd2437Shisping  * struct TEEC_RegisteredMemoryReference - use a pre-registered or
283*abdd2437Shisping  * pre-allocated shared memory block of memory to transfer data between
284*abdd2437Shisping  * a client application and trusted code.
285*abdd2437Shisping  *
286*abdd2437Shisping  * @param parent  Points to a shared memory structure. The memory reference
287*abdd2437Shisping  *                may utilize the whole shared memory or only a part of it.
288*abdd2437Shisping  *                Must not be NULL
289*abdd2437Shisping  *
290*abdd2437Shisping  * @param size    The size, in bytes, of the memory buffer.
291*abdd2437Shisping  *
292*abdd2437Shisping  * @param offset  The offset, in bytes, of the referenced memory region from
293*abdd2437Shisping  *                the start of the shared memory block.
294*abdd2437Shisping  *
295*abdd2437Shisping  */
296*abdd2437Shisping typedef struct {
297*abdd2437Shisping 	TEEC_SharedMemory *parent;
298*abdd2437Shisping 	size_t size;
299*abdd2437Shisping 	size_t offset;
300*abdd2437Shisping } TEEC_RegisteredMemoryReference;
301*abdd2437Shisping 
302*abdd2437Shisping /**
303*abdd2437Shisping  * struct TEEC_Value - Small raw data container
304*abdd2437Shisping  *
305*abdd2437Shisping  * Instead of allocating a shared memory buffer this structure can be used
306*abdd2437Shisping  * to pass small raw data between a client application and trusted code.
307*abdd2437Shisping  *
308*abdd2437Shisping  * @param a  The first integer value.
309*abdd2437Shisping  *
310*abdd2437Shisping  * @param b  The second second value.
311*abdd2437Shisping  */
312*abdd2437Shisping typedef struct {
313*abdd2437Shisping 	uint32_t a;
314*abdd2437Shisping 	uint32_t b;
315*abdd2437Shisping } TEEC_Value;
316*abdd2437Shisping 
317*abdd2437Shisping /**
318*abdd2437Shisping  * union TEEC_Parameter - Memory container to be used when passing data between
319*abdd2437Shisping  *                        client application and trusted code.
320*abdd2437Shisping  *
321*abdd2437Shisping  * Either the client uses a shared memory reference, parts of it or a small raw
322*abdd2437Shisping  * data container.
323*abdd2437Shisping  *
324*abdd2437Shisping  * @param tmpref  A temporary memory reference only valid for the duration
325*abdd2437Shisping  *                of the operation.
326*abdd2437Shisping  *
327*abdd2437Shisping  * @param memref  The entire shared memory or parts of it.
328*abdd2437Shisping  *
329*abdd2437Shisping  * @param value   The small raw data container to use
330*abdd2437Shisping  */
331*abdd2437Shisping typedef union {
332*abdd2437Shisping 	TEEC_TempMemoryReference tmpref;
333*abdd2437Shisping 	TEEC_RegisteredMemoryReference memref;
334*abdd2437Shisping 	TEEC_Value value;
335*abdd2437Shisping } TEEC_Parameter;
336*abdd2437Shisping 
337*abdd2437Shisping /**
338*abdd2437Shisping  * struct TEEC_Session - Represents a connection between a client application
339*abdd2437Shisping  * and a trusted application.
340*abdd2437Shisping  */
341*abdd2437Shisping typedef struct {
342*abdd2437Shisping 	uint32_t id;
343*abdd2437Shisping } TEEC_Session;
344*abdd2437Shisping 
345*abdd2437Shisping /**
346*abdd2437Shisping  * struct TEEC_Operation - Holds information and memory references used in
347*abdd2437Shisping  * TEEC_InvokeCommand().
348*abdd2437Shisping  *
349*abdd2437Shisping  * @param   started     Client must initialize to zero if it needs to cancel
350*abdd2437Shisping  *                      an operation about to be performed.
351*abdd2437Shisping  * @param   paramTypes  Type of data passed. Use TEEC_PARAMS_TYPE macro to
352*abdd2437Shisping  *                      create the correct flags.
353*abdd2437Shisping  *                      0 means TEEC_NONE is passed for all params.
354*abdd2437Shisping  * @param   params      Array of parameters of type TEEC_Parameter.
355*abdd2437Shisping  * @param   session     Internal pointer to the last session used by
356*abdd2437Shisping  *                      TEEC_InvokeCommand with this operation.
357*abdd2437Shisping  *
358*abdd2437Shisping  */
359*abdd2437Shisping typedef struct {
360*abdd2437Shisping 	uint32_t started;
361*abdd2437Shisping 	uint32_t paramTypes;
362*abdd2437Shisping 	TEEC_Parameter params[TEEC_CONFIG_PAYLOAD_REF_COUNT];
363*abdd2437Shisping 	/* Implementation-Defined */
364*abdd2437Shisping 	TEEC_Session *session;
365*abdd2437Shisping 	TEEC_SharedMemory memRefs[TEEC_CONFIG_PAYLOAD_REF_COUNT];
366*abdd2437Shisping 	uint32_t flags;
367*abdd2437Shisping } TEEC_Operation;
368*abdd2437Shisping 
369*abdd2437Shisping /**
370*abdd2437Shisping  * TEEC_InitializeContext() - Initializes a context holding connection
371*abdd2437Shisping  * information on the specific TEE, designated by the name string.
372*abdd2437Shisping 
373*abdd2437Shisping  * @param name    A zero-terminated string identifying the TEE to connect to.
374*abdd2437Shisping  *                If name is set to NULL, the default TEE is connected to. NULL
375*abdd2437Shisping  *                is the only supported value in this version of the API
376*abdd2437Shisping  *                implementation.
377*abdd2437Shisping  *
378*abdd2437Shisping  * @param context The context structure which is to be initialized.
379*abdd2437Shisping  *
380*abdd2437Shisping  * @return TEEC_SUCCESS  The initialization was successful.
381*abdd2437Shisping  * @return TEEC_Result   Something failed.
382*abdd2437Shisping  */
383*abdd2437Shisping TEEC_Result TEEC_InitializeContext(const char *name, TEEC_Context *context);
384*abdd2437Shisping 
385*abdd2437Shisping /**
386*abdd2437Shisping  * TEEC_FinalizeContext() - Destroys a context holding connection information
387*abdd2437Shisping  * on the specific TEE.
388*abdd2437Shisping  *
389*abdd2437Shisping  * This function destroys an initialized TEE context, closing the connection
390*abdd2437Shisping  * between the client application and the TEE. This function must only be
391*abdd2437Shisping  * called when all sessions related to this TEE context have been closed and
392*abdd2437Shisping  * all shared memory blocks have been released, otherwise an error will be
393*abdd2437Shisping  * returned.
394*abdd2437Shisping  *
395*abdd2437Shisping  * @param context       The context to be destroyed.
396*abdd2437Shisping  *
397*abdd2437Shisping  * @return TEEC_SUCCESS The function call was successful.
398*abdd2437Shisping  * @return TEEC_Result  Something failed.
399*abdd2437Shisping  */
400*abdd2437Shisping TEEC_Result TEEC_FinalizeContext(TEEC_Context *context);
401*abdd2437Shisping 
402*abdd2437Shisping /**
403*abdd2437Shisping  * TEEC_OpenSession() - Opens a new session with the specified trusted
404*abdd2437Shisping  *                      application.
405*abdd2437Shisping  *
406*abdd2437Shisping  * @param context            The initialized TEE context structure in which
407*abdd2437Shisping  *                           scope to open the session.
408*abdd2437Shisping  * @param session            The session to initialize.
409*abdd2437Shisping  * @param destination        A structure identifying the trusted application
410*abdd2437Shisping  *                           with which to open a session.
411*abdd2437Shisping  *
412*abdd2437Shisping  * @param connectionMethod   The connection method to use.
413*abdd2437Shisping  * @param connectionData     Any data necessary to connect with the chosen
414*abdd2437Shisping  *                           connection method. Not supported, should be set to
415*abdd2437Shisping  *                           NULL.
416*abdd2437Shisping  * @param operation          An operation structure to use in the session. May
417*abdd2437Shisping  *                           be set to NULL to signify no operation structure
418*abdd2437Shisping  *                           needed.
419*abdd2437Shisping  *
420*abdd2437Shisping  * @param returnOrigin       A parameter which will hold the error origin if
421*abdd2437Shisping  *                           this function returns any value other than
422*abdd2437Shisping  *                           TEEC_SUCCESS.
423*abdd2437Shisping  *
424*abdd2437Shisping  * @return TEEC_SUCCESS      OpenSession successfully opened a new session.
425*abdd2437Shisping  * @return TEEC_Result       Something failed.
426*abdd2437Shisping  *
427*abdd2437Shisping  */
428*abdd2437Shisping TEEC_Result TEEC_OpenSession(TEEC_Context *context,
429*abdd2437Shisping 			     TEEC_Session *session,
430*abdd2437Shisping 			     const TEEC_UUID *destination,
431*abdd2437Shisping 			     uint32_t connectionMethod,
432*abdd2437Shisping 			     const void *connectionData,
433*abdd2437Shisping 			     TEEC_Operation *operation,
434*abdd2437Shisping 			     uint32_t *returnOrigin);
435*abdd2437Shisping 
436*abdd2437Shisping /**
437*abdd2437Shisping  * TEEC_CloseSession() - Closes the session which has been opened with the
438*abdd2437Shisping  * specific trusted application.
439*abdd2437Shisping  *
440*abdd2437Shisping  * @param session The opened session to close.
441*abdd2437Shisping  */
442*abdd2437Shisping void TEEC_CloseSession(TEEC_Session *session);
443*abdd2437Shisping 
444*abdd2437Shisping /**
445*abdd2437Shisping  * TEEC_InvokeCommand() - Executes a command in the specified trusted
446*abdd2437Shisping  * application.
447*abdd2437Shisping  *
448*abdd2437Shisping  * @param session        A handle to an open connection to the trusted
449*abdd2437Shisping  *                       application.
450*abdd2437Shisping  * @param commandID      Identifier of the command in the trusted application
451*abdd2437Shisping  *                       to invoke.
452*abdd2437Shisping  * @param operation      An operation structure to use in the invoke command.
453*abdd2437Shisping  *                       May be set to NULL to signify no operation structure
454*abdd2437Shisping  *                       needed.
455*abdd2437Shisping  * @param returnOrigin   A parameter which will hold the error origin if this
456*abdd2437Shisping  *                       function returns any value other than TEEC_SUCCESS.
457*abdd2437Shisping  *
458*abdd2437Shisping  * @return TEEC_SUCCESS  OpenSession successfully opened a new session.
459*abdd2437Shisping  * @return TEEC_Result   Something failed.
460*abdd2437Shisping  */
461*abdd2437Shisping TEEC_Result TEEC_InvokeCommand(TEEC_Session *session,
462*abdd2437Shisping 			       uint32_t commandID,
463*abdd2437Shisping 			       TEEC_Operation *operation,
464*abdd2437Shisping 			       uint32_t *returnOrigin);
465*abdd2437Shisping 
466*abdd2437Shisping /**
467*abdd2437Shisping  * TEEC_RegisterSharedMemory() - Register a block of existing memory as a
468*abdd2437Shisping  * shared block within the scope of the specified context.
469*abdd2437Shisping  *
470*abdd2437Shisping  * @param context    The initialized TEE context structure in which scope to
471*abdd2437Shisping  *                   open the session.
472*abdd2437Shisping  * @param sharedMem  pointer to the shared memory structure to register.
473*abdd2437Shisping  *
474*abdd2437Shisping  * @return TEEC_SUCCESS              The registration was successful.
475*abdd2437Shisping  * @return TEEC_ERROR_OUT_OF_MEMORY  Memory exhaustion.
476*abdd2437Shisping  * @return TEEC_Result               Something failed.
477*abdd2437Shisping  */
478*abdd2437Shisping TEEC_Result TEEC_RegisterSharedMemory(TEEC_Context *context,
479*abdd2437Shisping 				      TEEC_SharedMemory *sharedMem);
480*abdd2437Shisping 
481*abdd2437Shisping /**
482*abdd2437Shisping  * TEEC_AllocateSharedMemory() - Allocate shared memory for TEE.
483*abdd2437Shisping  *
484*abdd2437Shisping  * @param context     The initialized TEE context structure in which scope to
485*abdd2437Shisping  *                    open the session.
486*abdd2437Shisping  * @param sharedMem   Pointer to the allocated shared memory.
487*abdd2437Shisping  *
488*abdd2437Shisping  * @return TEEC_SUCCESS              The registration was successful.
489*abdd2437Shisping  * @return TEEC_ERROR_OUT_OF_MEMORY  Memory exhaustion.
490*abdd2437Shisping  * @return TEEC_Result               Something failed.
491*abdd2437Shisping  */
492*abdd2437Shisping TEEC_Result TEEC_AllocateSharedMemory(TEEC_Context *context,
493*abdd2437Shisping 				      TEEC_SharedMemory *sharedMem);
494*abdd2437Shisping 
495*abdd2437Shisping /**
496*abdd2437Shisping  * TEEC_ReleaseSharedMemory() - Free or deregister the shared memory.
497*abdd2437Shisping  *
498*abdd2437Shisping  * @param sharedMem  Pointer to the shared memory to be freed.
499*abdd2437Shisping  */
500*abdd2437Shisping void TEEC_ReleaseSharedMemory(TEEC_SharedMemory *sharedMemory);
501*abdd2437Shisping 
502*abdd2437Shisping /**
503*abdd2437Shisping  * TEEC_RequestCancellation() - Request the cancellation of a pending open
504*abdd2437Shisping  *                              session or command invocation.
505*abdd2437Shisping  *
506*abdd2437Shisping  * @param operation Pointer to an operation previously passed to open session
507*abdd2437Shisping  *                  or invoke.
508*abdd2437Shisping  */
509*abdd2437Shisping void TEEC_RequestCancellation(TEEC_Operation *operation);
510*abdd2437Shisping 
511*abdd2437Shisping /**
512*abdd2437Shisping  * Register a pre-allocated Trusted Application This is mainly intended for
513*abdd2437Shisping  * OS-FREE contexts or when a filesystem is not available.
514*abdd2437Shisping  *
515*abdd2437Shisping  * @param ta   Pointer to the trusted application binary
516*abdd2437Shisping  * @param size The size of the TA binary
517*abdd2437Shisping  *
518*abdd2437Shisping  * @return TEEC_SUCCESS if successful.
519*abdd2437Shisping  * @return TEEC_Result something failed.
520*abdd2437Shisping  */
521*abdd2437Shisping TEEC_Result TEEC_RegisterTA(const void *ta, const size_t size);
522*abdd2437Shisping 
523*abdd2437Shisping /**
524*abdd2437Shisping  * Unregister a pre-allocated Trusted Application This is mainly intended for
525*abdd2437Shisping  * OS-FREE contexts or when a filesystem is not available.
526*abdd2437Shisping  *
527*abdd2437Shisping  * @param ta Pointer to the trusted application binary
528*abdd2437Shisping  */
529*abdd2437Shisping void TEEC_UnregisterTA(const void *ta);
530*abdd2437Shisping 
531*abdd2437Shisping #endif
532