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, TEE_ObjectInfo *info); 106 TEE_Result _utee_cryp_obj_restrict_usage(unsigned long obj, 107 unsigned long usage); 108 TEE_Result _utee_cryp_obj_get_attr(unsigned long obj, unsigned long attr_id, 109 void *buffer, uint64_t *size); 110 111 /* Transient Object Functions */ 112 /* type has type TEE_ObjectType */ 113 TEE_Result _utee_cryp_obj_alloc(unsigned long type, unsigned long max_size, 114 uint32_t *obj); 115 TEE_Result _utee_cryp_obj_close(unsigned long obj); 116 TEE_Result _utee_cryp_obj_reset(unsigned long obj); 117 TEE_Result _utee_cryp_obj_populate(unsigned long obj, 118 struct utee_attribute *attrs, 119 unsigned long attr_count); 120 TEE_Result _utee_cryp_obj_copy(unsigned long dst_obj, unsigned long src_obj); 121 122 TEE_Result _utee_cryp_obj_generate_key(unsigned long obj, 123 unsigned long key_size, 124 const struct utee_attribute *params, 125 unsigned long param_count); 126 127 TEE_Result _utee_cryp_derive_key(unsigned long state, 128 const struct utee_attribute *params, 129 unsigned long param_count, 130 unsigned long derived_key); 131 132 TEE_Result _utee_cryp_random_number_generate(void *buf, size_t blen); 133 134 TEE_Result _utee_authenc_init(unsigned long state, const void *nonce, 135 size_t nonce_len, size_t tag_len, size_t aad_len, 136 size_t payload_len); 137 TEE_Result _utee_authenc_update_aad(unsigned long state, const void *aad_data, 138 size_t aad_data_len); 139 TEE_Result _utee_authenc_update_payload(unsigned long state, 140 const void *src_data, size_t src_len, 141 void *dest_data, uint64_t *dest_len); 142 TEE_Result _utee_authenc_enc_final(unsigned long state, const void *src_data, 143 size_t src_len, void *dest_data, 144 uint64_t *dest_len, void *tag, 145 uint64_t *tag_len); 146 TEE_Result _utee_authenc_dec_final(unsigned long state, const void *src_data, 147 size_t src_len, void *dest_data, 148 uint64_t *dest_len, const void *tag, 149 size_t tag_len); 150 151 TEE_Result _utee_asymm_operate(unsigned long state, 152 const struct utee_attribute *params, 153 unsigned long num_params, const void *src_data, 154 size_t src_len, void *dest_data, 155 uint64_t *dest_len); 156 157 TEE_Result _utee_asymm_verify(unsigned long state, 158 const struct utee_attribute *params, 159 unsigned long num_params, const void *data, 160 size_t data_len, const void *sig, size_t sig_len); 161 162 /* Persistant Object Functions */ 163 /* obj is of type TEE_ObjectHandle */ 164 TEE_Result _utee_storage_obj_open(unsigned long storage_id, 165 const void *object_id, size_t object_id_len, 166 unsigned long flags, uint32_t *obj); 167 168 /* 169 * attr is of type TEE_ObjectHandle 170 * obj is of type TEE_ObjectHandle 171 */ 172 TEE_Result _utee_storage_obj_create(unsigned long storage_id, 173 const void *object_id, 174 size_t object_id_len, unsigned long flags, 175 unsigned long attr, const void *data, 176 size_t len, uint32_t *obj); 177 178 /* obj is of type TEE_ObjectHandle */ 179 TEE_Result _utee_storage_obj_del(unsigned long obj); 180 181 /* obj is of type TEE_ObjectHandle */ 182 TEE_Result _utee_storage_obj_rename(unsigned long obj, const void *new_obj_id, 183 size_t new_obj_id_len); 184 185 /* Persistent Object Enumeration Functions */ 186 /* obj_enum is of type TEE_ObjectEnumHandle */ 187 TEE_Result _utee_storage_alloc_enum(uint32_t *obj_enum); 188 189 190 /* obj_enum is of type TEE_ObjectEnumHandle */ 191 TEE_Result _utee_storage_free_enum(unsigned long obj_enum); 192 193 /* obj_enum is of type TEE_ObjectEnumHandle */ 194 TEE_Result _utee_storage_reset_enum(unsigned long obj_enum); 195 196 /* obj_enum is of type TEE_ObjectEnumHandle */ 197 TEE_Result _utee_storage_start_enum(unsigned long obj_enum, 198 unsigned long storage_id); 199 200 /* obj_enum is of type TEE_ObjectEnumHandle */ 201 TEE_Result _utee_storage_next_enum(unsigned long obj_enum, TEE_ObjectInfo *info, 202 void *obj_id, uint64_t *len); 203 204 /* Data Stream Access Functions */ 205 /* obj is of type TEE_ObjectHandle */ 206 TEE_Result _utee_storage_obj_read(unsigned long obj, void *data, size_t len, 207 uint64_t *count); 208 209 /* obj is of type TEE_ObjectHandle */ 210 TEE_Result _utee_storage_obj_write(unsigned long obj, const void *data, 211 size_t len); 212 213 /* obj is of type TEE_ObjectHandle */ 214 TEE_Result _utee_storage_obj_trunc(unsigned long obj, size_t len); 215 216 /* obj is of type TEE_ObjectHandle */ 217 /* whence is of type TEE_Whence */ 218 TEE_Result _utee_storage_obj_seek(unsigned long obj, int32_t offset, 219 unsigned long whence); 220 221 /* seServiceHandle is of type TEE_SEServiceHandle */ 222 TEE_Result _utee_se_service_open(uint32_t *seServiceHandle); 223 224 /* seServiceHandle is of type TEE_SEServiceHandle */ 225 TEE_Result _utee_se_service_close(unsigned long seServiceHandle); 226 227 /* 228 * seServiceHandle is of type TEE_SEServiceHandle 229 * r is of type TEE_SEReaderHandle 230 */ 231 TEE_Result _utee_se_service_get_readers(unsigned long seServiceHandle, 232 uint32_t *r, uint64_t *len); 233 234 /* 235 * r is of type TEE_SEReaderHandle 236 * p is defined with defines UTEE_SE_READER_* 237 */ 238 TEE_Result _utee_se_reader_get_prop(unsigned long r, uint32_t *p); 239 240 /* r is of type TEE_SEReaderHandle */ 241 TEE_Result _utee_se_reader_get_name(unsigned long r, char *name, 242 uint64_t *name_len); 243 244 /* 245 * r is of type TEE_SEReaderHandle 246 * s if of type TEE_SESessionHandle 247 */ 248 TEE_Result _utee_se_reader_open_session(unsigned long r, uint32_t *s); 249 250 /* r is of type TEE_SEReaderHandle */ 251 TEE_Result _utee_se_reader_close_sessions(unsigned long r); 252 253 /* s is of type TEE_SESessionHandle */ 254 TEE_Result _utee_se_session_is_closed(unsigned long s); 255 256 /* s is of type TEE_SESessionHandle */ 257 TEE_Result _utee_se_session_get_atr(unsigned long s, void *atr, 258 uint64_t *atr_len); 259 260 /* 261 * s is of type TEE_SESessionHandle 262 * c is of type TEE_SEChannelHandle 263 */ 264 TEE_Result _utee_se_session_open_channel(unsigned long s, 265 unsigned long is_logical, 266 const void *aid_buffer, 267 size_t aid_buffer_len, uint32_t *c); 268 269 /* s is of type TEE_SESessionHandle */ 270 TEE_Result _utee_se_session_close(unsigned long s); 271 272 /* c is of type TEE_SEChannelHandle */ 273 TEE_Result _utee_se_channel_select_next(unsigned long c); 274 275 /* c is of type TEE_SEChannelHandle */ 276 TEE_Result _utee_se_channel_get_select_resp(unsigned long c, void *resp, 277 uint64_t *resp_len); 278 279 /* c is of type TEE_SEChannelHandle */ 280 TEE_Result _utee_se_channel_transmit(unsigned long c, void *cmd, size_t cmd_len, 281 void *resp, uint64_t *resp_len); 282 283 /* c is of type TEE_SEChannelHandle */ 284 TEE_Result _utee_se_channel_close(unsigned long c); 285 286 /* op is of type enum _utee_cache_operation */ 287 TEE_Result _utee_cache_operation(void *va, size_t l, unsigned long op); 288 289 TEE_Result _utee_gprof_send(void *buf, size_t size, uint32_t *id); 290 291 #endif /* UTEE_SYSCALLS_H */ 292