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