xref: /optee_os/lib/libutee/include/utee_syscalls.h (revision 8e81e2f5366a971afdd2ac47fb8529d1def5feb0)
1 /*
2  * Copyright (c) 2015, Linaro Limited
3  * Copyright (c) 2014, STMicroelectronics International N.V.
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are met:
8  *
9  * 1. Redistributions of source code must retain the above copyright notice,
10  * this list of conditions and the following disclaimer.
11  *
12  * 2. Redistributions in binary form must reproduce the above copyright notice,
13  * this list of conditions and the following disclaimer in the documentation
14  * and/or other materials provided with the distribution.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
20  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26  * POSSIBILITY OF SUCH DAMAGE.
27  */
28 #ifndef UTEE_SYSCALLS_H
29 #define UTEE_SYSCALLS_H
30 
31 #include <compiler.h>
32 #include <stddef.h>
33 #include <stdint.h>
34 
35 #include <utee_types.h>
36 #include <tee_api_types.h>
37 #include <trace.h>
38 
39 /*
40  * Arguments must use the native register width, unless it's a signed
41  * argument then it must be a 32-bit value instead to avoid problems with
42  * sign extension. To keep it simple, only use pointers, int32_t, unsigned
43  * long and size_t. Pointers may only point structures or types based on
44  * fixed width integer types. Only exception are buffers with opaque data.
45  *
46  * Return values should not use a fixed width larger than 32 bits, unsigned
47  * long and pointers are OK though.
48  *
49  * Members in structs on the other hand should only use fixed width integer
50  * types; uint32_t, uint64_t etc. To keep it simple, use uint64_t for all
51  * length fields.
52  */
53 
54 void utee_return(unsigned long ret) __noreturn;
55 
56 void utee_log(const void *buf, size_t len);
57 
58 /* This is not __noreturn because AArch32 stack unwinding fails otherwise */
59 void utee_panic(unsigned long code);
60 
61 /* prop_set is TEE_PROPSET_xxx*/
62 TEE_Result utee_get_property(unsigned long prop_set, unsigned long index,
63 			     void *name, uint32_t *name_len,
64 			     void *buf, uint32_t *blen,
65 				uint32_t *prop_type);
66 TEE_Result utee_get_property_name_to_index(unsigned long prop_set,
67 					   const void *name,
68 					   unsigned long name_len,
69 					   uint32_t *index);
70 
71 
72 /* sess has type TEE_TASessionHandle */
73 TEE_Result utee_open_ta_session(const TEE_UUID *dest,
74 			unsigned long cancel_req_to, struct utee_params *params,
75 			uint32_t *sess, uint32_t *ret_orig);
76 
77 /* sess has type TEE_TASessionHandle */
78 TEE_Result utee_close_ta_session(unsigned long sess);
79 
80 /* sess has type TEE_TASessionHandle */
81 TEE_Result utee_invoke_ta_command(unsigned long sess,
82 			unsigned long cancel_req_to, unsigned long cmd_id,
83 			struct utee_params *params, uint32_t *ret_orig);
84 
85 TEE_Result utee_check_access_rights(uint32_t flags, const void *buf,
86 				    size_t len);
87 
88 /* cancel has type bool */
89 TEE_Result utee_get_cancellation_flag(uint32_t *cancel);
90 
91 /* old_mask has type bool */
92 TEE_Result utee_unmask_cancellation(uint32_t *old_mask);
93 
94 /* old_mask has type bool */
95 TEE_Result utee_mask_cancellation(uint32_t *old_mask);
96 
97 TEE_Result utee_wait(unsigned long timeout);
98 
99 /* cat has type enum utee_time_category */
100 TEE_Result utee_get_time(unsigned long cat, TEE_Time *time);
101 
102 TEE_Result utee_set_ta_time(const TEE_Time *time);
103 
104 TEE_Result utee_cryp_state_alloc(unsigned long algo, unsigned long op_mode,
105 				 unsigned long key1, unsigned long key2,
106 				 uint32_t *state);
107 TEE_Result utee_cryp_state_copy(unsigned long dst, unsigned long src);
108 TEE_Result utee_cryp_state_free(unsigned long state);
109 
110 /* iv and iv_len are ignored for some algorithms */
111 TEE_Result utee_hash_init(unsigned long state, const void *iv, size_t iv_len);
112 TEE_Result utee_hash_update(unsigned long state, const void *chunk,
113 			    size_t chunk_size);
114 TEE_Result utee_hash_final(unsigned long state, const void *chunk,
115 			   size_t chunk_size, void *hash, uint64_t *hash_len);
116 
117 TEE_Result utee_cipher_init(unsigned long state, const void *iv, size_t iv_len);
118 TEE_Result utee_cipher_update(unsigned long state, const void *src,
119 			size_t src_len, void *dest, uint64_t *dest_len);
120 TEE_Result utee_cipher_final(unsigned long state, const void *src,
121 			size_t src_len, void *dest, uint64_t *dest_len);
122 
123 /* Generic Object Functions */
124 TEE_Result utee_cryp_obj_get_info(unsigned long obj, TEE_ObjectInfo *info);
125 TEE_Result utee_cryp_obj_restrict_usage(unsigned long obj, unsigned long usage);
126 TEE_Result utee_cryp_obj_get_attr(unsigned long obj, unsigned long attr_id,
127 			void *buffer, uint64_t *size);
128 
129 /* Transient Object Functions */
130 /* type has type TEE_ObjectType */
131 TEE_Result utee_cryp_obj_alloc(unsigned long type, unsigned long max_size,
132 			uint32_t *obj);
133 TEE_Result utee_cryp_obj_close(unsigned long obj);
134 TEE_Result utee_cryp_obj_reset(unsigned long obj);
135 TEE_Result utee_cryp_obj_populate(unsigned long obj,
136 			struct utee_attribute *attrs, unsigned long attr_count);
137 TEE_Result utee_cryp_obj_copy(unsigned long dst_obj, unsigned long src_obj);
138 
139 TEE_Result utee_cryp_obj_generate_key(unsigned long obj, unsigned long key_size,
140 			const struct utee_attribute *params,
141 			unsigned long param_count);
142 
143 TEE_Result utee_cryp_derive_key(unsigned long state,
144 			const struct utee_attribute *params,
145 			unsigned long param_count, unsigned long derived_key);
146 
147 TEE_Result utee_cryp_random_number_generate(void *buf, size_t blen);
148 
149 TEE_Result utee_authenc_init(unsigned long state, const void *nonce,
150 			size_t nonce_len, size_t tag_len, size_t aad_len,
151 			size_t payload_len);
152 TEE_Result utee_authenc_update_aad(unsigned long state, const void *aad_data,
153 			size_t aad_data_len);
154 TEE_Result utee_authenc_update_payload(unsigned long state,
155 			const void *src_data, size_t src_len, void *dest_data,
156 			uint64_t *dest_len);
157 TEE_Result utee_authenc_enc_final(unsigned long state, const void *src_data,
158 			size_t src_len, void *dest_data, uint64_t *dest_len,
159 			void *tag, uint64_t *tag_len);
160 TEE_Result utee_authenc_dec_final(unsigned long state, const void *src_data,
161 			size_t src_len, void *dest_data, uint64_t *dest_len,
162 			const void *tag, size_t tag_len);
163 
164 TEE_Result utee_asymm_operate(unsigned long state,
165 			const struct utee_attribute *params,
166 			unsigned long num_params, const void *src_data,
167 			size_t src_len, void *dest_data, uint64_t *dest_len);
168 
169 TEE_Result utee_asymm_verify(unsigned long state,
170 			const struct utee_attribute *params,
171 			unsigned long num_params, const void *data,
172 			size_t data_len, const void *sig, size_t sig_len);
173 
174 /* Persistant Object Functions */
175 /* obj is of type TEE_ObjectHandle */
176 TEE_Result utee_storage_obj_open(unsigned long storage_id,
177 				 const void *object_id,
178 				 size_t object_id_len, unsigned long flags,
179 				 uint32_t *obj);
180 
181 /*
182  * attr is of type TEE_ObjectHandle
183  * obj is of type TEE_ObjectHandle
184  */
185 TEE_Result utee_storage_obj_create(unsigned long storage_id,
186 				   const void *object_id,
187 				   size_t object_id_len, unsigned long flags,
188 				   unsigned long attr, const void *data,
189 				   size_t len, uint32_t *obj);
190 
191 /* obj is of type TEE_ObjectHandle */
192 TEE_Result utee_storage_obj_del(unsigned long obj);
193 
194 /* obj is of type TEE_ObjectHandle */
195 TEE_Result utee_storage_obj_rename(unsigned long obj, const void *new_obj_id,
196 				size_t new_obj_id_len);
197 
198 /* Persistent Object Enumeration Functions */
199 /* obj_enum is of type TEE_ObjectEnumHandle */
200 TEE_Result utee_storage_alloc_enum(uint32_t *obj_enum);
201 
202 
203 /* obj_enum is of type TEE_ObjectEnumHandle */
204 TEE_Result utee_storage_free_enum(unsigned long obj_enum);
205 
206 /* obj_enum is of type TEE_ObjectEnumHandle */
207 TEE_Result utee_storage_reset_enum(unsigned long obj_enum);
208 
209 /* obj_enum is of type TEE_ObjectEnumHandle */
210 TEE_Result utee_storage_start_enum(unsigned long obj_enum,
211 			unsigned long storage_id);
212 
213 /* obj_enum is of type TEE_ObjectEnumHandle */
214 TEE_Result utee_storage_next_enum(unsigned long obj_enum, TEE_ObjectInfo *info,
215 			void *obj_id, uint64_t *len);
216 
217 /* Data Stream Access Functions */
218 /* obj is of type TEE_ObjectHandle */
219 TEE_Result utee_storage_obj_read(unsigned long obj, void *data, size_t len,
220 			uint64_t *count);
221 
222 /* obj is of type TEE_ObjectHandle */
223 TEE_Result utee_storage_obj_write(unsigned long obj, const void *data,
224 			size_t len);
225 
226 /* obj is of type TEE_ObjectHandle */
227 TEE_Result utee_storage_obj_trunc(unsigned long obj, size_t len);
228 
229 /* obj is of type TEE_ObjectHandle */
230 /* whence is of type TEE_Whence */
231 TEE_Result utee_storage_obj_seek(unsigned long obj, int32_t offset,
232 				 unsigned long whence);
233 
234 /* seServiceHandle is of type TEE_SEServiceHandle */
235 TEE_Result utee_se_service_open(uint32_t *seServiceHandle);
236 
237 /* seServiceHandle is of type TEE_SEServiceHandle */
238 TEE_Result utee_se_service_close(unsigned long seServiceHandle);
239 
240 /*
241  * seServiceHandle is of type TEE_SEServiceHandle
242  * r is of type TEE_SEReaderHandle
243  */
244 TEE_Result utee_se_service_get_readers(unsigned long seServiceHandle,
245 			uint32_t *r, uint64_t *len);
246 
247 /*
248  * r is of type TEE_SEReaderHandle
249  * p is defined with defines UTEE_SE_READER_*
250  */
251 TEE_Result utee_se_reader_get_prop(unsigned long r, uint32_t *p);
252 
253 /* r is of type TEE_SEReaderHandle */
254 TEE_Result utee_se_reader_get_name(unsigned long r,
255 			char *name, uint64_t *name_len);
256 
257 /*
258  * r is of type TEE_SEReaderHandle
259  * s if of type TEE_SESessionHandle
260  */
261 TEE_Result utee_se_reader_open_session(unsigned long r, uint32_t *s);
262 
263 /* r is of type TEE_SEReaderHandle */
264 TEE_Result utee_se_reader_close_sessions(unsigned long r);
265 
266 /* s is of type TEE_SESessionHandle */
267 TEE_Result utee_se_session_is_closed(unsigned long s);
268 
269 /* s is of type TEE_SESessionHandle */
270 TEE_Result utee_se_session_get_atr(unsigned long s, void *atr,
271 			uint64_t *atr_len);
272 
273 /*
274  * s is of type TEE_SESessionHandle
275  * c is of type TEE_SEChannelHandle
276  */
277 TEE_Result utee_se_session_open_channel(unsigned long s,
278 			unsigned long is_logical, const void *aid_buffer,
279 			size_t aid_buffer_len, uint32_t *c);
280 
281 /* s is of type TEE_SESessionHandle */
282 TEE_Result utee_se_session_close(unsigned long s);
283 
284 /* c is of type TEE_SEChannelHandle */
285 TEE_Result utee_se_channel_select_next(unsigned long c);
286 
287 /* c is of type TEE_SEChannelHandle */
288 TEE_Result utee_se_channel_get_select_resp(unsigned long c, void *resp,
289 			uint64_t *resp_len);
290 
291 /* c is of type TEE_SEChannelHandle */
292 TEE_Result utee_se_channel_transmit(unsigned long c, void *cmd,
293 			size_t cmd_len, void *resp, uint64_t *resp_len);
294 
295 /* c is of type TEE_SEChannelHandle */
296 TEE_Result utee_se_channel_close(unsigned long c);
297 
298 /* op is of type enum utee_cache_operation */
299 TEE_Result utee_cache_operation(void *va, size_t l, unsigned long op);
300 
301 TEE_Result utee_gprof_send(void *buf, size_t size, uint32_t *id);
302 
303 #endif /* UTEE_SYSCALLS_H */
304