1 /* SPDX-License-Identifier: BSD-2-Clause */
2 /*
3  * Copyright (c) 2015, Linaro Limited
4  * Copyright (c) 2014, STMicroelectronics International N.V.
5  */
6 #ifndef UTEE_SYSCALLS_H
7 #define UTEE_SYSCALLS_H
8 
9 #include <compiler.h>
10 #include <stddef.h>
11 #include <stdint.h>
12 
13 #include <utee_types.h>
14 #include <tee_api_types.h>
15 #include <trace.h>
16 
17 /*
18  * Arguments must use the native register width, unless it's a signed
19  * argument then it must be a 32-bit value instead to avoid problems with
20  * sign extension. To keep it simple, only use pointers, int32_t, unsigned
21  * long and size_t. Pointers may only point structures or types based on
22  * fixed width integer types. Only exception are buffers with opaque data.
23  *
24  * Return values should not use a fixed width larger than 32 bits, unsigned
25  * long and pointers are OK though.
26  *
27  * Members in structs on the other hand should only use fixed width integer
28  * types; uint32_t, uint64_t etc. To keep it simple, use uint64_t for all
29  * length fields.
30  */
31 
32 void _utee_return(unsigned long ret) __noreturn;
33 
34 void _utee_log(const void *buf, size_t len);
35 
36 /* This is not __noreturn because AArch32 stack unwinding fails otherwise */
37 void _utee_panic(unsigned long code);
38 
39 /* prop_set is TEE_PROPSET_xxx*/
40 TEE_Result _utee_get_property(unsigned long prop_set, unsigned long index,
41 			      void *name, uint32_t *name_len, void *buf,
42 			      uint32_t *blen, uint32_t *prop_type);
43 
44 TEE_Result _utee_get_property_name_to_index(unsigned long prop_set,
45 					    const void *name,
46 					    unsigned long name_len,
47 					    uint32_t *index);
48 
49 /* sess has type TEE_TASessionHandle */
50 TEE_Result _utee_open_ta_session(const TEE_UUID *dest,
51 				 unsigned long cancel_req_to,
52 				 struct utee_params *params, uint32_t *sess,
53 				 uint32_t *ret_orig);
54 
55 /* sess has type TEE_TASessionHandle */
56 TEE_Result _utee_close_ta_session(unsigned long sess);
57 
58 /* sess has type TEE_TASessionHandle */
59 TEE_Result _utee_invoke_ta_command(unsigned long sess,
60 				   unsigned long cancel_req_to,
61 				   unsigned long cmd_id,
62 				   struct utee_params *params,
63 				   uint32_t *ret_orig);
64 
65 TEE_Result _utee_check_access_rights(uint32_t flags, const void *buf,
66 				     size_t len);
67 
68 /* cancel has type bool */
69 TEE_Result _utee_get_cancellation_flag(uint32_t *cancel);
70 
71 /* old_mask has type bool */
72 TEE_Result _utee_unmask_cancellation(uint32_t *old_mask);
73 
74 /* old_mask has type bool */
75 TEE_Result _utee_mask_cancellation(uint32_t *old_mask);
76 
77 TEE_Result _utee_wait(unsigned long timeout);
78 
79 /* cat has type enum _utee_time_category */
80 TEE_Result _utee_get_time(unsigned long cat, TEE_Time *time);
81 
82 TEE_Result _utee_set_ta_time(const TEE_Time *time);
83 
84 TEE_Result _utee_cryp_state_alloc(unsigned long algo, unsigned long op_mode,
85 				  unsigned long key1, unsigned long key2,
86 				  uint32_t *state);
87 TEE_Result _utee_cryp_state_copy(unsigned long dst, unsigned long src);
88 TEE_Result _utee_cryp_state_free(unsigned long state);
89 
90 /* iv and iv_len are ignored for some algorithms */
91 TEE_Result _utee_hash_init(unsigned long state, const void *iv, size_t iv_len);
92 TEE_Result _utee_hash_update(unsigned long state, const void *chunk,
93 			     size_t chunk_size);
94 TEE_Result _utee_hash_final(unsigned long state, const void *chunk,
95 			    size_t chunk_size, void *hash, uint64_t *hash_len);
96 
97 TEE_Result _utee_cipher_init(unsigned long state, const void *iv,
98 			     size_t iv_len);
99 TEE_Result _utee_cipher_update(unsigned long state, const void *src,
100 			       size_t src_len, void *dest, uint64_t *dest_len);
101 TEE_Result _utee_cipher_final(unsigned long state, const void *src,
102 			      size_t src_len, void *dest, uint64_t *dest_len);
103 
104 /* Generic Object Functions */
105 TEE_Result _utee_cryp_obj_get_info(unsigned long obj,
106 				   struct utee_object_info *info);
107 TEE_Result _utee_cryp_obj_restrict_usage(unsigned long obj,
108 					 unsigned long usage);
109 TEE_Result _utee_cryp_obj_get_attr(unsigned long obj, unsigned long attr_id,
110 				   void *buffer, uint64_t *size);
111 
112 /* Transient Object Functions */
113 /* type has type TEE_ObjectType */
114 TEE_Result _utee_cryp_obj_alloc(unsigned long type, unsigned long max_size,
115 				uint32_t *obj);
116 TEE_Result _utee_cryp_obj_close(unsigned long obj);
117 TEE_Result _utee_cryp_obj_reset(unsigned long obj);
118 TEE_Result _utee_cryp_obj_populate(unsigned long obj,
119 				   struct utee_attribute *attrs,
120 				   unsigned long attr_count);
121 TEE_Result _utee_cryp_obj_copy(unsigned long dst_obj, unsigned long src_obj);
122 
123 TEE_Result _utee_cryp_obj_generate_key(unsigned long obj,
124 				       unsigned long key_size,
125 				       const struct utee_attribute *params,
126 				       unsigned long param_count);
127 
128 TEE_Result _utee_cryp_derive_key(unsigned long state,
129 				 const struct utee_attribute *params,
130 				 unsigned long param_count,
131 				 unsigned long derived_key);
132 
133 TEE_Result _utee_cryp_random_number_generate(void *buf, size_t blen);
134 
135 TEE_Result _utee_authenc_init(unsigned long state, const void *nonce,
136 			      size_t nonce_len, size_t tag_len, size_t aad_len,
137 			      size_t payload_len);
138 TEE_Result _utee_authenc_update_aad(unsigned long state, const void *aad_data,
139 				    size_t aad_data_len);
140 TEE_Result _utee_authenc_update_payload(unsigned long state,
141 					const void *src_data, size_t src_len,
142 					void *dest_data, uint64_t *dest_len);
143 TEE_Result _utee_authenc_enc_final(unsigned long state, const void *src_data,
144 				   size_t src_len, void *dest_data,
145 				   uint64_t *dest_len, void *tag,
146 				   uint64_t *tag_len);
147 TEE_Result _utee_authenc_dec_final(unsigned long state, const void *src_data,
148 				   size_t src_len, void *dest_data,
149 				   uint64_t *dest_len, const void *tag,
150 				   size_t tag_len);
151 
152 TEE_Result _utee_asymm_operate(unsigned long state,
153 			       const struct utee_attribute *params,
154 			       unsigned long num_params, const void *src_data,
155 			       size_t src_len, void *dest_data,
156 			       uint64_t *dest_len);
157 
158 TEE_Result _utee_asymm_verify(unsigned long state,
159 			      const struct utee_attribute *params,
160 			      unsigned long num_params, const void *data,
161 			      size_t data_len, const void *sig, size_t sig_len);
162 
163 /* Persistant Object Functions */
164 /* obj is of type TEE_ObjectHandle */
165 TEE_Result _utee_storage_obj_open(unsigned long storage_id,
166 				  const void *object_id, size_t object_id_len,
167 				  unsigned long flags, uint32_t *obj);
168 
169 /*
170  * attr is of type TEE_ObjectHandle
171  * obj is of type TEE_ObjectHandle
172  */
173 TEE_Result _utee_storage_obj_create(unsigned long storage_id,
174 				    const void *object_id,
175 				    size_t object_id_len, unsigned long flags,
176 				    unsigned long attr, const void *data,
177 				    size_t len, uint32_t *obj);
178 
179 /* obj is of type TEE_ObjectHandle */
180 TEE_Result _utee_storage_obj_del(unsigned long obj);
181 
182 /* obj is of type TEE_ObjectHandle */
183 TEE_Result _utee_storage_obj_rename(unsigned long obj, const void *new_obj_id,
184 				    size_t new_obj_id_len);
185 
186 /* Persistent Object Enumeration Functions */
187 /* obj_enum is of type TEE_ObjectEnumHandle */
188 TEE_Result _utee_storage_alloc_enum(uint32_t *obj_enum);
189 
190 
191 /* obj_enum is of type TEE_ObjectEnumHandle */
192 TEE_Result _utee_storage_free_enum(unsigned long obj_enum);
193 
194 /* obj_enum is of type TEE_ObjectEnumHandle */
195 TEE_Result _utee_storage_reset_enum(unsigned long obj_enum);
196 
197 /* obj_enum is of type TEE_ObjectEnumHandle */
198 TEE_Result _utee_storage_start_enum(unsigned long obj_enum,
199 				    unsigned long storage_id);
200 
201 /* obj_enum is of type TEE_ObjectEnumHandle */
202 TEE_Result _utee_storage_next_enum(unsigned long obj_enum,
203 				   struct utee_object_info *info,
204 				   void *obj_id, uint64_t *len);
205 
206 /* Data Stream Access Functions */
207 /* obj is of type TEE_ObjectHandle */
208 TEE_Result _utee_storage_obj_read(unsigned long obj, void *data, size_t len,
209 				  uint64_t *count);
210 
211 /* obj is of type TEE_ObjectHandle */
212 TEE_Result _utee_storage_obj_write(unsigned long obj, const void *data,
213 				   size_t len);
214 
215 /* obj is of type TEE_ObjectHandle */
216 TEE_Result _utee_storage_obj_trunc(unsigned long obj, size_t len);
217 
218 /* obj is of type TEE_ObjectHandle */
219 /* whence is of type TEE_Whence */
220 TEE_Result _utee_storage_obj_seek(unsigned long obj, int32_t offset,
221 				  unsigned long whence);
222 
223 /* op is of type enum _utee_cache_operation */
224 TEE_Result _utee_cache_operation(void *va, size_t l, unsigned long op);
225 
226 TEE_Result _utee_gprof_send(void *buf, size_t size, uint32_t *id);
227 
228 #endif /* UTEE_SYSCALLS_H */
229