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 bool syscall_trace_enabled; /* Some syscalls are never traced */ 98 bool syscall_trace_suspended; /* By foreign interrupt or RPC */ 99 bool overflow; /* Circular buffer has wrapped */ 100 }; 101 102 /* Defined by the linker script */ 103 extern struct ftrace_buf __ftrace_buf_start; 104 extern uint8_t __ftrace_buf_end[]; 105 106 unsigned long ftrace_return(void); 107 void __ftrace_return(void); 108 #endif 109 110 void __utee_call_elf_init_fn(void); 111 void __utee_call_elf_fini_fn(void); 112 113 void __utee_tcb_init(void); 114 115 /* 116 * Information about the ELF objects loaded by the application 117 */ 118 119 struct __elf_phdr_info { 120 uint32_t reserved; 121 uint16_t count; 122 uint8_t reserved2; 123 char zero; 124 struct dl_phdr_info *dlpi; /* @count entries */ 125 }; 126 127 /* 32-bit variant for a 64-bit ldelf to access a 32-bit TA */ 128 struct __elf_phdr_info32 { 129 uint32_t reserved; 130 uint16_t count; 131 uint8_t reserved2; 132 char zero; 133 uint32_t dlpi; 134 }; 135 136 extern struct __elf_phdr_info __elf_phdr_info; 137 138 #define TA_PROP_STR_SINGLE_INSTANCE "gpd.ta.singleInstance" 139 #define TA_PROP_STR_MULTI_SESSION "gpd.ta.multiSession" 140 #define TA_PROP_STR_KEEP_ALIVE "gpd.ta.instanceKeepAlive" 141 #define TA_PROP_STR_KEEP_CRASHED "optee.ta.instanceKeepCrashed" 142 #define TA_PROP_STR_DATA_SIZE "gpd.ta.dataSize" 143 #define TA_PROP_STR_STACK_SIZE "gpd.ta.stackSize" 144 #define TA_PROP_STR_VERSION "gpd.ta.version" 145 #define TA_PROP_STR_DESCRIPTION "gpd.ta.description" 146 #define TA_PROP_STR_ENDIAN "gpd.ta.endian" 147 #define TA_PROP_STR_DOES_NOT_CLOSE_HANDLE_ON_CORRUPT_OBJECT \ 148 "gpd.ta.doesNotCloseHandleOnCorruptObject" 149 150 enum user_ta_prop_type { 151 USER_TA_PROP_TYPE_BOOL, /* bool */ 152 USER_TA_PROP_TYPE_U32, /* uint32_t */ 153 USER_TA_PROP_TYPE_UUID, /* TEE_UUID */ 154 USER_TA_PROP_TYPE_IDENTITY, /* TEE_Identity */ 155 USER_TA_PROP_TYPE_STRING, /* zero terminated string of char */ 156 USER_TA_PROP_TYPE_BINARY_BLOCK, /* zero terminated base64 coded string */ 157 USER_TA_PROP_TYPE_U64, /* uint64_t */ 158 USER_TA_PROP_TYPE_INVALID, /* invalid value */ 159 }; 160 161 struct user_ta_property { 162 const char *name; 163 enum user_ta_prop_type type; 164 const void *value; 165 }; 166 167 extern const struct user_ta_property ta_props[]; 168 extern const size_t ta_num_props; 169 170 extern uint8_t __ta_no_share_heap[]; 171 extern const size_t __ta_no_share_heap_size; 172 /* Needed by TEE_CheckMemoryAccessRights() */ 173 extern uint32_t ta_param_types; 174 extern TEE_Param ta_params[TEE_NUM_PARAMS]; 175 extern struct malloc_ctx *__ta_no_share_malloc_ctx; 176 177 int tahead_get_trace_level(void); 178 179 #endif /* USER_TA_HEADER_H */ 180