1 /* SPDX-License-Identifier: BSD-2-Clause */ 2 /* 3 * Copyright (c) 2014, STMicroelectronics International N.V. 4 * Copyright (c) 2018, Linaro Limited. 5 */ 6 7 #ifndef USER_TA_HEADER_H 8 #define USER_TA_HEADER_H 9 10 #include <tee_api_types.h> 11 #include <util.h> 12 13 #define TA_FLAG_USER_MODE 0 /* Deprecated, was BIT32(0) */ 14 #define TA_FLAG_EXEC_DDR 0 /* Deprecated, was BIT32(1) */ 15 #define TA_FLAG_SINGLE_INSTANCE BIT32(2) 16 #define TA_FLAG_MULTI_SESSION BIT32(3) 17 #define TA_FLAG_INSTANCE_KEEP_ALIVE BIT32(4) /* remains after last close */ 18 #define TA_FLAG_SECURE_DATA_PATH BIT32(5) /* accesses SDP memory */ 19 #define TA_FLAG_REMAP_SUPPORT 0 /* Deprecated, was BIT32(6) */ 20 #define TA_FLAG_CACHE_MAINTENANCE BIT32(7) /* use cache flush syscall */ 21 /* 22 * TA instance can execute multiple sessions concurrently 23 * (pseudo-TAs only). 24 */ 25 #define TA_FLAG_CONCURRENT BIT32(8) 26 /* 27 * Device enumeration is initiated at multiple stages by the normal 28 * world: 29 * 1. First when the kernel driver has initialized 30 * 2. When RPMB is available via inkernel RPMB routing 31 * 3. When the tee-supplicant is started 32 * 33 * The flags below control at which stage a TA will be enumerated: 34 * TA_FLAG_DEVICE_ENUM - at stage 1 35 * TA_FLAG_DEVICE_ENUM_TEE_STORAGE_PRIVATE - 36 * when secure storage is available, at stage 2 or 3 depending 37 * on whether TEE_STORAGE_PRIVATE is using RPMB FS 38 * (CFG_REE_FS=n CFG_RPMB_FS=y) or REE FS (CFG_REE_FS=y). The 39 * former utilizes in kernel RPMB routing, and the latter 40 * depends on tee-supplicant to access secure storage. 41 * TA_FLAG_DEVICE_ENUM_SUPP - at stage 3 42 * 43 * The TA is enumerated at stage 2 if 44 * TA_FLAG_DEVICE_ENUM_TEE_STORAGE_PRIVATE is set and 45 * TEE_STORAGE_PRIVATE is using RPMB FS, or if it's using REE FS it 46 * will be enumerated at stage 3. 47 */ 48 #define TA_FLAG_DEVICE_ENUM BIT32(9) /* without tee-supplicant */ 49 #define TA_FLAG_DEVICE_ENUM_SUPP BIT32(10) /* with tee-supplicant */ 50 /* See also "gpd.ta.doesNotCloseHandleOnCorruptObject" */ 51 #define TA_FLAG_DONT_CLOSE_HANDLE_ON_CORRUPT_OBJECT \ 52 BIT32(11) 53 #define TA_FLAG_DEVICE_ENUM_TEE_STORAGE_PRIVATE \ 54 BIT32(12) /* with TEE_STORAGE_PRIVATE */ 55 /* 56 * Don't restart a TA with TA_FLAG_INSTANCE_KEEP_ALIVE set if it has 57 * crashed. 58 */ 59 #define TA_FLAG_INSTANCE_KEEP_CRASHED BIT32(13) 60 61 #define TA_FLAGS_MASK GENMASK_32(13, 0) 62 63 struct ta_head { 64 TEE_UUID uuid; 65 uint32_t stack_size; 66 uint32_t flags; 67 uint64_t depr_entry; 68 }; 69 70 #if defined(CFG_FTRACE_SUPPORT) 71 #define FTRACE_RETFUNC_DEPTH 50 72 union compat_ptr { 73 uint64_t ptr64; 74 struct { 75 uint32_t lo; 76 uint32_t hi; 77 } ptr32; 78 }; 79 80 struct __ftrace_info { 81 union compat_ptr buf_start; 82 union compat_ptr buf_end; 83 union compat_ptr ret_ptr; 84 }; 85 86 struct ftrace_buf { 87 uint64_t ret_func_ptr; /* __ftrace_return pointer */ 88 uint64_t ret_stack[FTRACE_RETFUNC_DEPTH]; /* Return stack */ 89 uint32_t ret_idx; /* Return stack index */ 90 uint32_t lr_idx; /* lr index used for stack unwinding */ 91 uint64_t begin_time[FTRACE_RETFUNC_DEPTH]; /* Timestamp */ 92 uint64_t suspend_time; /* Suspend timestamp */ 93 uint32_t curr_idx; /* Current entry in the (circular) buffer */ 94 uint32_t max_size; /* Max allowed size of ftrace buffer */ 95 uint32_t head_off; /* Ftrace buffer header offset */ 96 uint32_t buf_off; /* Ftrace buffer offset */ 97 uint32_t dump_id; /* Dump ID returned by the supplicant */ 98 bool syscall_trace_enabled; /* Some syscalls are never traced */ 99 bool syscall_trace_suspended; /* By foreign interrupt or RPC */ 100 bool overflow; /* Circular buffer has wrapped */ 101 }; 102 103 /* Defined by the linker script */ 104 extern struct ftrace_buf __ftrace_buf_start; 105 extern uint8_t __ftrace_buf_end[]; 106 107 unsigned long ftrace_return(void); 108 void __ftrace_return(void); 109 #endif 110 111 void __utee_call_elf_init_fn(void); 112 void __utee_call_elf_fini_fn(void); 113 114 void __utee_tcb_init(void); 115 116 /* 117 * Information about the ELF objects loaded by the application 118 */ 119 120 struct __elf_phdr_info { 121 uint32_t reserved; 122 uint16_t count; 123 uint8_t reserved2; 124 char zero; 125 struct dl_phdr_info *dlpi; /* @count entries */ 126 }; 127 128 /* 32-bit variant for a 64-bit ldelf to access a 32-bit TA */ 129 struct __elf_phdr_info32 { 130 uint32_t reserved; 131 uint16_t count; 132 uint8_t reserved2; 133 char zero; 134 uint32_t dlpi; 135 }; 136 137 extern struct __elf_phdr_info __elf_phdr_info; 138 139 #define TA_PROP_STR_SINGLE_INSTANCE "gpd.ta.singleInstance" 140 #define TA_PROP_STR_MULTI_SESSION "gpd.ta.multiSession" 141 #define TA_PROP_STR_KEEP_ALIVE "gpd.ta.instanceKeepAlive" 142 #define TA_PROP_STR_KEEP_CRASHED "optee.ta.instanceKeepCrashed" 143 #define TA_PROP_STR_DATA_SIZE "gpd.ta.dataSize" 144 #define TA_PROP_STR_STACK_SIZE "gpd.ta.stackSize" 145 #define TA_PROP_STR_VERSION "gpd.ta.version" 146 #define TA_PROP_STR_DESCRIPTION "gpd.ta.description" 147 #define TA_PROP_STR_ENDIAN "gpd.ta.endian" 148 #define TA_PROP_STR_DOES_NOT_CLOSE_HANDLE_ON_CORRUPT_OBJECT \ 149 "gpd.ta.doesNotCloseHandleOnCorruptObject" 150 151 enum user_ta_prop_type { 152 USER_TA_PROP_TYPE_BOOL, /* bool */ 153 USER_TA_PROP_TYPE_U32, /* uint32_t */ 154 USER_TA_PROP_TYPE_UUID, /* TEE_UUID */ 155 USER_TA_PROP_TYPE_IDENTITY, /* TEE_Identity */ 156 USER_TA_PROP_TYPE_STRING, /* zero terminated string of char */ 157 USER_TA_PROP_TYPE_BINARY_BLOCK, /* zero terminated base64 coded string */ 158 USER_TA_PROP_TYPE_U64, /* uint64_t */ 159 USER_TA_PROP_TYPE_INVALID, /* invalid value */ 160 }; 161 162 struct user_ta_property { 163 const char *name; 164 enum user_ta_prop_type type; 165 const void *value; 166 }; 167 168 extern const struct user_ta_property ta_props[]; 169 extern const size_t ta_num_props; 170 171 extern uint8_t __ta_no_share_heap[]; 172 extern const size_t __ta_no_share_heap_size; 173 /* Needed by TEE_CheckMemoryAccessRights() */ 174 extern uint32_t ta_param_types; 175 extern TEE_Param ta_params[TEE_NUM_PARAMS]; 176 extern struct malloc_ctx *__ta_no_share_malloc_ctx; 177 178 int tahead_get_trace_level(void); 179 180 #endif /* USER_TA_HEADER_H */ 181