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