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