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