xref: /optee_os/lib/libutee/include/user_ta_header.h (revision 27cbcc57098afcb97cfdcd01647c61180e0e849f)
1b0104773SPascal Brand /*
2b0104773SPascal Brand  * Copyright (c) 2014, STMicroelectronics International N.V.
3b0104773SPascal Brand  * All rights reserved.
4b0104773SPascal Brand  *
5b0104773SPascal Brand  * Redistribution and use in source and binary forms, with or without
6b0104773SPascal Brand  * modification, are permitted provided that the following conditions are met:
7b0104773SPascal Brand  *
8b0104773SPascal Brand  * 1. Redistributions of source code must retain the above copyright notice,
9b0104773SPascal Brand  * this list of conditions and the following disclaimer.
10b0104773SPascal Brand  *
11b0104773SPascal Brand  * 2. Redistributions in binary form must reproduce the above copyright notice,
12b0104773SPascal Brand  * this list of conditions and the following disclaimer in the documentation
13b0104773SPascal Brand  * and/or other materials provided with the distribution.
14b0104773SPascal Brand  *
15b0104773SPascal Brand  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16b0104773SPascal Brand  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17b0104773SPascal Brand  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18b0104773SPascal Brand  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
19b0104773SPascal Brand  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20b0104773SPascal Brand  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21b0104773SPascal Brand  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22b0104773SPascal Brand  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23b0104773SPascal Brand  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24b0104773SPascal Brand  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25b0104773SPascal Brand  * POSSIBILITY OF SUCH DAMAGE.
26b0104773SPascal Brand  */
27b0104773SPascal Brand 
28b0104773SPascal Brand #ifndef USER_TA_HEADER_H
29b0104773SPascal Brand #define USER_TA_HEADER_H
30b0104773SPascal Brand 
31b0104773SPascal Brand #include <tee_api_types.h>
32b0104773SPascal Brand 
33b0104773SPascal Brand /*
34*27cbcc57SJens Wiklander  * The generic format of a TA header.
35*27cbcc57SJens Wiklander  *
36*27cbcc57SJens Wiklander  * signed_header
37*27cbcc57SJens Wiklander  * ta_head_t
38*27cbcc57SJens Wiklander  * ta_func_head_t (1)
39*27cbcc57SJens Wiklander  * ta_func_head_t (2)
40*27cbcc57SJens Wiklander  * ...
41*27cbcc57SJens Wiklander  * ta_func_head_t (N) N = ta_head(_t).nbr_func
42*27cbcc57SJens Wiklander  * func_1
43*27cbcc57SJens Wiklander  * func_1
44*27cbcc57SJens Wiklander  * ...
45*27cbcc57SJens Wiklander  * func_N
46*27cbcc57SJens Wiklander  * hash_1
47*27cbcc57SJens Wiklander  * hash_2
48*27cbcc57SJens Wiklander  * ...
49*27cbcc57SJens Wiklander  * hash_M
50*27cbcc57SJens Wiklander  *
51*27cbcc57SJens Wiklander  * The currently this format is limited to N = 5, resulting in a TA header as
52*27cbcc57SJens Wiklander  *
53*27cbcc57SJens Wiklander  * signed_header
54*27cbcc57SJens Wiklander  * struct user_ta_head
55*27cbcc57SJens Wiklander  * struct user_ta_func_head (1)
56*27cbcc57SJens Wiklander  * struct user_ta_func_head (2)
57*27cbcc57SJens Wiklander  * struct user_ta_func_head (3)
58*27cbcc57SJens Wiklander  * struct user_ta_sub_head
59*27cbcc57SJens Wiklander  *
60*27cbcc57SJens Wiklander  * Note that the last two func heads are replaced by struct user_ta_sub_head.
61b0104773SPascal Brand  */
62b0104773SPascal Brand 
63b0104773SPascal Brand struct user_ta_head {
64b0104773SPascal Brand 	TEE_UUID uuid;
65b0104773SPascal Brand 	uint32_t nbr_func;
66b0104773SPascal Brand 	uint32_t ro_size;
67b0104773SPascal Brand 	uint32_t rw_size;
68b0104773SPascal Brand 	uint32_t zi_size;
69b0104773SPascal Brand 	uint32_t got_size;
70b0104773SPascal Brand 	uint32_t hash_type;
71b0104773SPascal Brand };
72b0104773SPascal Brand 
73b0104773SPascal Brand #define USER_TA_HEAD_FLAG_USER_MODE 0x80000000UL
74b0104773SPascal Brand #define USER_TA_HEAD_FLAG_DDR_EXEC  0x40000000UL
75b0104773SPascal Brand 
76b0104773SPascal Brand struct user_ta_func_head {
77b0104773SPascal Brand 	uint32_t cmd_id;
78b0104773SPascal Brand 	uint32_t start;		/* offset to start func */
79b0104773SPascal Brand };
80b0104773SPascal Brand 
81b0104773SPascal Brand struct user_ta_sub_head {
82b0104773SPascal Brand 	uint32_t flags;
83b0104773SPascal Brand 	uint32_t spare;
84b0104773SPascal Brand 	uint32_t heap_size;
85b0104773SPascal Brand 	uint32_t stack_size;
86b0104773SPascal Brand };
87b0104773SPascal Brand 
88b0104773SPascal Brand #define TA_FLAG_USER_MODE           (1 << 0)
89b0104773SPascal Brand #define TA_FLAG_EXEC_DDR            (1 << 1)
90b0104773SPascal Brand #define TA_FLAG_SINGLE_INSTANCE     (1 << 2)
91b0104773SPascal Brand #define TA_FLAG_MULTI_SESSION       (1 << 3)
92b0104773SPascal Brand #define TA_FLAG_INSTANCE_KEEP_ALIVE (1 << 4)
93b0104773SPascal Brand /*
94b0104773SPascal Brand  * TEE Core will allow memrefs in some firewalled memory if this flag is
95b0104773SPascal Brand  * set for a User TA.
96b0104773SPascal Brand  */
97b0104773SPascal Brand #define TA_FLAG_UNSAFE_NW_PARAMS    (1 << 5)
98b0104773SPascal Brand 
99b0104773SPascal Brand enum user_ta_prop_type {
100b0104773SPascal Brand 	USER_TA_PROP_TYPE_BOOL,	/* bool */
101b0104773SPascal Brand 	USER_TA_PROP_TYPE_U32,	/* uint32_t */
102b0104773SPascal Brand 	USER_TA_PROP_TYPE_UUID,	/* TEE_UUID */
103b0104773SPascal Brand 	USER_TA_PROP_TYPE_IDENTITY,	/* TEE_Identity */
104b0104773SPascal Brand 	USER_TA_PROP_TYPE_STRING,	/* zero terminated string of char */
105b0104773SPascal Brand 	USER_TA_PROP_TYPE_BINARY_BLOCK,	/* zero terminated base64 coded string */
106b0104773SPascal Brand };
107b0104773SPascal Brand 
108b0104773SPascal Brand enum user_ta_core_service_id {
109b0104773SPascal Brand 	USER_TA_CORE_ENTRY_MATH_INIT = 0x00000010,
110b0104773SPascal Brand 	USER_TA_CORE_ENTRY_GARBAGE = 0x00000011,
111b0104773SPascal Brand 	USER_TA_CORE_ENTRY_CLOSESESSION = 0x00000012,
112b0104773SPascal Brand };
113b0104773SPascal Brand 
114b0104773SPascal Brand struct user_ta_property {
115b0104773SPascal Brand 	const char *name;
116b0104773SPascal Brand 	enum user_ta_prop_type type;
117b0104773SPascal Brand 	const void *value;
118b0104773SPascal Brand };
119b0104773SPascal Brand 
120b0104773SPascal Brand extern const struct user_ta_property ta_props[];
121b0104773SPascal Brand extern const size_t ta_num_props;
122b0104773SPascal Brand 
123b0104773SPascal Brand /* Needed by TEE_CheckMemoryAccessRights() */
124b0104773SPascal Brand extern uint32_t ta_param_types;
125b0104773SPascal Brand extern TEE_Param ta_params[4];
126b0104773SPascal Brand 
127b0104773SPascal Brand /* Trusted Application Function header */
128b0104773SPascal Brand typedef struct ta_func_head {
129b0104773SPascal Brand 	uint32_t cmd_id;	/* Trusted Application Function ID */
130b0104773SPascal Brand 	uint32_t start;		/* offset to start func */
131b0104773SPascal Brand } ta_func_head_t;
132b0104773SPascal Brand 
133b0104773SPascal Brand typedef struct {
134b0104773SPascal Brand 	/* Same Prefix as ta_head_t */
135b0104773SPascal Brand 	TEE_UUID uuid;
136b0104773SPascal Brand 	const char *name;
137b0104773SPascal Brand 	uint32_t flags;
138b0104773SPascal Brand 
139b0104773SPascal Brand 	/* properties */
140b0104773SPascal Brand 	uint32_t prop_datasize;
141b0104773SPascal Brand 	uint32_t prop_stacksize;
142b0104773SPascal Brand 	uint32_t prop_tracelevel;
143b0104773SPascal Brand 
144b0104773SPascal Brand 	const ta_func_head_t *funcs;
145b0104773SPascal Brand 	uint32_t nbr_func;
146b0104773SPascal Brand 	 TEE_Result(*create_entry_point) (void);
147b0104773SPascal Brand 	void (*destroy_entry_point) (void);
148b0104773SPascal Brand 	 TEE_Result(*open_session_entry_point) (uint32_t nParamTypes,
149b0104773SPascal Brand 					     TEE_Param pParams[4],
150b0104773SPascal Brand 					     void **ppSessionContext);
151b0104773SPascal Brand 	void (*close_session_entry_point) (void *pSessionContext);
152b0104773SPascal Brand 	 TEE_Result(*invoke_command_entry_point) (void *pSessionContext,
153b0104773SPascal Brand 					       uint32_t nCommandID,
154b0104773SPascal Brand 					       uint32_t nParamTypes,
155b0104773SPascal Brand 					       TEE_Param pParams[4]);
156b0104773SPascal Brand 	 TEE_Result(*core_entries) (uint32_t nServiceId, uint32_t nParamTypes,
157b0104773SPascal Brand 				   TEE_Param pParam[4]);
158b0104773SPascal Brand } ta_static_head_t;
159b0104773SPascal Brand 
160b0104773SPascal Brand int tahead_get_trace_level(void);
161b0104773SPascal Brand 
162b0104773SPascal Brand #endif /* USER_TA_HEADER_H */
163