xref: /optee_os/lib/libutee/include/utee_syscalls.h (revision f17691b3f6b27866f66636a53685bd3a6f7daa8a)
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. To keep it simple, only
41  * use pointers, long, unsigned long and size_t. Pointers may only point
42  * structures or types based on fixed width integer types. Only exception
43  * are buffers with opaque data.
44  *
45  * Return values should not use a fixed width larger than 32 bits, unsigned
46  * long and pointers are OK though.
47  *
48  * Members in structs on the other hand should only use fixed width integer
49  * types; uint32_t, uint64_t etc. To keep it simple, use uint64_t for all
50  * length fields.
51  */
52 
53 void utee_return(unsigned long ret) __noreturn;
54 
55 void utee_log(const void *buf, size_t len);
56 
57 void utee_panic(unsigned long code) __noreturn;
58 
59 uint32_t utee_dummy(uint32_t *a);
60 
61 uint32_t utee_dummy_7args(unsigned long a1, unsigned long a2, unsigned long a3,
62 			unsigned long a4, unsigned long a5, unsigned long a6,
63 			unsigned long a7);
64 
65 uint32_t utee_nocall(void);
66 
67 /* prop defined by enum utee_property */
68 TEE_Result utee_get_property(unsigned long prop, void *buf, size_t len);
69 
70 /* sess has type TEE_TASessionHandle */
71 TEE_Result utee_open_ta_session(const TEE_UUID *dest,
72 			unsigned long cancel_req_to, struct utee_params *params,
73 			uint32_t *sess, uint32_t *ret_orig);
74 
75 /* sess has type TEE_TASessionHandle */
76 TEE_Result utee_close_ta_session(unsigned long sess);
77 
78 /* sess has type TEE_TASessionHandle */
79 TEE_Result utee_invoke_ta_command(unsigned long sess,
80 			unsigned long cancel_req_to, unsigned long cmd_id,
81 			struct utee_params *params, uint32_t *ret_orig);
82 
83 TEE_Result utee_check_access_rights(uint32_t flags, const void *buf,
84 				    size_t len);
85 
86 /* cancel has type bool */
87 TEE_Result utee_get_cancellation_flag(uint32_t *cancel);
88 
89 /* old_mask has type bool */
90 TEE_Result utee_unmask_cancellation(uint32_t *old_mask);
91 
92 /* old_mask has type bool */
93 TEE_Result utee_mask_cancellation(uint32_t *old_mask);
94 
95 TEE_Result utee_wait(unsigned long timeout);
96 
97 /* cat has type enum utee_time_category */
98 TEE_Result utee_get_time(unsigned long cat, TEE_Time *time);
99 
100 TEE_Result utee_set_ta_time(const TEE_Time *time);
101 
102 TEE_Result utee_cryp_state_alloc(unsigned long algo, unsigned long op_mode,
103 				 unsigned long key1, unsigned long key2,
104 				 uint32_t *state);
105 TEE_Result utee_cryp_state_copy(unsigned long dst, unsigned long src);
106 TEE_Result utee_cryp_state_free(unsigned long state);
107 
108 /* iv and iv_len are ignored for some algorithms */
109 TEE_Result utee_hash_init(unsigned long state, const void *iv, size_t iv_len);
110 TEE_Result utee_hash_update(unsigned long state, const void *chunk,
111 			    size_t chunk_size);
112 TEE_Result utee_hash_final(unsigned long state, const void *chunk,
113 			   size_t chunk_size, void *hash, uint64_t *hash_len);
114 
115 TEE_Result utee_cipher_init(unsigned long state, const void *iv, size_t iv_len);
116 TEE_Result utee_cipher_update(unsigned long state, const void *src,
117 			size_t src_len, void *dest, uint64_t *dest_len);
118 TEE_Result utee_cipher_final(unsigned long state, const void *src,
119 			size_t src_len, void *dest, uint64_t *dest_len);
120 
121 /* Generic Object Functions */
122 TEE_Result utee_cryp_obj_get_info(unsigned long obj, TEE_ObjectInfo *info);
123 TEE_Result utee_cryp_obj_restrict_usage(unsigned long obj, unsigned long usage);
124 TEE_Result utee_cryp_obj_get_attr(unsigned long obj, unsigned long attr_id,
125 			void *buffer, uint64_t *size);
126 
127 /* Transient Object Functions */
128 /* type has type TEE_ObjectType */
129 TEE_Result utee_cryp_obj_alloc(unsigned long type, unsigned long max_size,
130 			uint32_t *obj);
131 TEE_Result utee_cryp_obj_close(unsigned long obj);
132 TEE_Result utee_cryp_obj_reset(unsigned long obj);
133 TEE_Result utee_cryp_obj_populate(unsigned long obj,
134 			struct utee_attribute *attrs, unsigned long attr_count);
135 TEE_Result utee_cryp_obj_copy(unsigned long dst_obj, unsigned long src_obj);
136 
137 TEE_Result utee_cryp_obj_generate_key(unsigned long obj, unsigned long key_size,
138 			const struct utee_attribute *params,
139 			unsigned long param_count);
140 
141 TEE_Result utee_cryp_derive_key(unsigned long state,
142 			const struct utee_attribute *params,
143 			unsigned long param_count, unsigned long derived_key);
144 
145 TEE_Result utee_cryp_random_number_generate(void *buf, size_t blen);
146 
147 TEE_Result utee_authenc_init(unsigned long state, const void *nonce,
148 			size_t nonce_len, size_t tag_len, size_t aad_len,
149 			size_t payload_len);
150 TEE_Result utee_authenc_update_aad(unsigned long state, const void *aad_data,
151 			size_t aad_data_len);
152 TEE_Result utee_authenc_update_payload(unsigned long state,
153 			const void *src_data, size_t src_len, void *dest_data,
154 			uint64_t *dest_len);
155 TEE_Result utee_authenc_enc_final(unsigned long state, const void *src_data,
156 			size_t src_len, void *dest_data, uint64_t *dest_len,
157 			void *tag, uint64_t *tag_len);
158 TEE_Result utee_authenc_dec_final(unsigned long state, const void *src_data,
159 			size_t src_len, void *dest_data, uint64_t *dest_len,
160 			const void *tag, size_t tag_len);
161 
162 TEE_Result utee_asymm_operate(unsigned long state,
163 			const struct utee_attribute *params,
164 			unsigned long num_params, const void *src_data,
165 			size_t src_len, void *dest_data, uint64_t *dest_len);
166 
167 TEE_Result utee_asymm_verify(unsigned long state,
168 			const struct utee_attribute *params,
169 			unsigned long num_params, const void *data,
170 			size_t data_len, const void *sig, size_t sig_len);
171 
172 /* Persistant Object Functions */
173 /* obj is of type TEE_ObjectHandle */
174 TEE_Result utee_storage_obj_open(unsigned long storage_id, void *object_id,
175 				 size_t object_id_len, unsigned long flags,
176 				 uint32_t *obj);
177 
178 /*
179  * attr is of type TEE_ObjectHandle
180  * obj is of type TEE_ObjectHandle
181  */
182 TEE_Result utee_storage_obj_create(unsigned long storage_id, void *object_id,
183 				size_t object_id_len, unsigned long flags,
184 				unsigned long attr, const void *data,
185 				size_t len, uint32_t *obj);
186 
187 /* obj is of type TEE_ObjectHandle */
188 TEE_Result utee_storage_obj_del(unsigned long obj);
189 
190 /* obj is of type TEE_ObjectHandle */
191 TEE_Result utee_storage_obj_rename(unsigned long obj, const void *new_obj_id,
192 				size_t new_obj_id_len);
193 
194 /* Persistent Object Enumeration Functions */
195 /* obj_enum is of type TEE_ObjectEnumHandle */
196 TEE_Result utee_storage_alloc_enum(uint32_t *obj_enum);
197 
198 
199 /* obj_enum is of type TEE_ObjectEnumHandle */
200 TEE_Result utee_storage_free_enum(unsigned long obj_enum);
201 
202 /* obj_enum is of type TEE_ObjectEnumHandle */
203 TEE_Result utee_storage_reset_enum(unsigned long obj_enum);
204 
205 /* obj_enum is of type TEE_ObjectEnumHandle */
206 TEE_Result utee_storage_start_enum(unsigned long obj_enum,
207 			unsigned long storage_id);
208 
209 /* obj_enum is of type TEE_ObjectEnumHandle */
210 TEE_Result utee_storage_next_enum(unsigned long obj_enum, TEE_ObjectInfo *info,
211 			void *obj_id, uint64_t *len);
212 
213 /* Data Stream Access Functions */
214 /* obj is of type TEE_ObjectHandle */
215 TEE_Result utee_storage_obj_read(unsigned long obj, void *data, size_t len,
216 			uint64_t *count);
217 
218 /* obj is of type TEE_ObjectHandle */
219 TEE_Result utee_storage_obj_write(unsigned long obj, const void *data,
220 			size_t len);
221 
222 /* obj is of type TEE_ObjectHandle */
223 TEE_Result utee_storage_obj_trunc(unsigned long obj, size_t len);
224 
225 /* obj is of type TEE_ObjectHandle */
226 /* whence is of type TEE_Whence */
227 TEE_Result utee_storage_obj_seek(unsigned long obj, long offset,
228 				 unsigned long whence);
229 
230 /* seServiceHandle is of type TEE_SEServiceHandle */
231 TEE_Result utee_se_service_open(uint32_t *seServiceHandle);
232 
233 /* seServiceHandle is of type TEE_SEServiceHandle */
234 TEE_Result utee_se_service_close(unsigned long seServiceHandle);
235 
236 /*
237  * seServiceHandle is of type TEE_SEServiceHandle
238  * r is of type TEE_SEReaderHandle
239  */
240 TEE_Result utee_se_service_get_readers(unsigned long seServiceHandle,
241 			uint32_t *r, uint64_t *len);
242 
243 /*
244  * r is of type TEE_SEReaderHandle
245  * p is defined with defines UTEE_SE_READER_*
246  */
247 TEE_Result utee_se_reader_get_prop(unsigned long r, uint32_t *p);
248 
249 /* r is of type TEE_SEReaderHandle */
250 TEE_Result utee_se_reader_get_name(unsigned long r,
251 			char *name, uint64_t *name_len);
252 
253 /*
254  * r is of type TEE_SEReaderHandle
255  * s if of type TEE_SESessionHandle
256  */
257 TEE_Result utee_se_reader_open_session(unsigned long r, uint32_t *s);
258 
259 /* r is of type TEE_SEReaderHandle */
260 TEE_Result utee_se_reader_close_sessions(unsigned long r);
261 
262 /* s is of type TEE_SESessionHandle */
263 TEE_Result utee_se_session_is_closed(unsigned long s);
264 
265 /* s is of type TEE_SESessionHandle */
266 TEE_Result utee_se_session_get_atr(unsigned long s, void *atr,
267 			uint64_t *atr_len);
268 
269 /*
270  * s is of type TEE_SESessionHandle
271  * c is of type TEE_SEChannelHandle
272  */
273 TEE_Result utee_se_session_open_channel(unsigned long s,
274 			unsigned long is_logical, const void *aid_buffer,
275 			size_t aid_buffer_len, uint32_t *c);
276 
277 /* s is of type TEE_SESessionHandle */
278 TEE_Result utee_se_session_close(unsigned long s);
279 
280 /* c is of type TEE_SEChannelHandle */
281 TEE_Result utee_se_channel_select_next(unsigned long c);
282 
283 /* c is of type TEE_SEChannelHandle */
284 TEE_Result utee_se_channel_get_select_resp(unsigned long c, void *resp,
285 			uint64_t *resp_len);
286 
287 /* c is of type TEE_SEChannelHandle */
288 TEE_Result utee_se_channel_transmit(unsigned long c, void *cmd,
289 			size_t cmd_len, void *resp, uint64_t *resp_len);
290 
291 /* c is of type TEE_SEChannelHandle */
292 TEE_Result utee_se_channel_close(unsigned long c);
293 
294 /* op is of type enum utee_cache_operation */
295 TEE_Result utee_cache_operation(void *va, size_t l, unsigned long op);
296 
297 #endif /* UTEE_SYSCALLS_H */
298