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 (1 << 0) */ 14 #define TA_FLAG_EXEC_DDR 0 /* Deprecated, was (1 << 1) */ 15 #define TA_FLAG_SINGLE_INSTANCE (1 << 2) 16 #define TA_FLAG_MULTI_SESSION (1 << 3) 17 #define TA_FLAG_INSTANCE_KEEP_ALIVE (1 << 4) /* remains after last close */ 18 #define TA_FLAG_SECURE_DATA_PATH (1 << 5) /* accesses SDP memory */ 19 #define TA_FLAG_REMAP_SUPPORT 0 /* Deprecated, was (1 << 6) */ 20 #define TA_FLAG_CACHE_MAINTENANCE (1 << 7) /* use cache flush syscall */ 21 /* 22 * TA instance can execute multiple sessions concurrently 23 * (pseudo-TAs only). 24 */ 25 #define TA_FLAG_CONCURRENT (1 << 8) 26 /* 27 * Device enumeration is done in two stages by the normal world, first 28 * before the tee-supplicant has started and then once more when the 29 * tee-supplicant is started. The flags below control if the TA should 30 * be reported in the first or second or case. 31 */ 32 #define TA_FLAG_DEVICE_ENUM (1 << 9) /* without tee-supplicant */ 33 #define TA_FLAG_DEVICE_ENUM_SUPP (1 << 10) /* with tee-supplicant */ 34 35 #define TA_FLAGS_MASK GENMASK_32(10, 0) 36 37 struct ta_head { 38 TEE_UUID uuid; 39 uint32_t stack_size; 40 uint32_t flags; 41 uint64_t depr_entry; 42 }; 43 44 #if defined(CFG_FTRACE_SUPPORT) 45 #define FTRACE_RETFUNC_DEPTH 50 46 union compat_ptr { 47 uint64_t ptr64; 48 struct { 49 uint32_t lo; 50 uint32_t hi; 51 } ptr32; 52 }; 53 54 struct __ftrace_info { 55 union compat_ptr buf_start; 56 union compat_ptr buf_end; 57 union compat_ptr ret_ptr; 58 }; 59 60 struct ftrace_buf { 61 uint64_t ret_func_ptr; /* __ftrace_return pointer */ 62 uint64_t ret_stack[FTRACE_RETFUNC_DEPTH]; /* Return stack */ 63 uint32_t ret_idx; /* Return stack index */ 64 uint32_t lr_idx; /* lr index used for stack unwinding */ 65 uint64_t begin_time[FTRACE_RETFUNC_DEPTH]; /* Timestamp */ 66 uint64_t suspend_time; /* Suspend timestamp */ 67 uint32_t curr_size; /* Size of ftrace buffer */ 68 uint32_t max_size; /* Max allowed size of ftrace buffer */ 69 uint32_t head_off; /* Ftrace buffer header offset */ 70 uint32_t buf_off; /* Ftrace buffer offset */ 71 bool syscall_trace_enabled; /* Some syscalls are never traced */ 72 bool syscall_trace_suspended; /* By foreign interrupt or RPC */ 73 }; 74 75 /* Defined by the linker script */ 76 extern struct ftrace_buf __ftrace_buf_start; 77 extern uint8_t __ftrace_buf_end[]; 78 79 unsigned long ftrace_return(void); 80 void __ftrace_return(void); 81 #endif 82 83 void __utee_call_elf_init_fn(void); 84 void __utee_call_elf_fini_fn(void); 85 86 void __utee_tcb_init(void); 87 88 /* 89 * Information about the ELF objects loaded by the application 90 */ 91 92 struct __elf_phdr_info { 93 uint32_t reserved; 94 uint16_t count; 95 uint8_t reserved2; 96 char zero; 97 struct dl_phdr_info *dlpi; /* @count entries */ 98 }; 99 100 /* 32-bit variant for a 64-bit ldelf to access a 32-bit TA */ 101 struct __elf_phdr_info32 { 102 uint32_t reserved; 103 uint16_t count; 104 uint8_t reserved2; 105 char zero; 106 uint32_t dlpi; 107 }; 108 109 extern struct __elf_phdr_info __elf_phdr_info; 110 111 #define TA_PROP_STR_SINGLE_INSTANCE "gpd.ta.singleInstance" 112 #define TA_PROP_STR_MULTI_SESSION "gpd.ta.multiSession" 113 #define TA_PROP_STR_KEEP_ALIVE "gpd.ta.instanceKeepAlive" 114 #define TA_PROP_STR_DATA_SIZE "gpd.ta.dataSize" 115 #define TA_PROP_STR_STACK_SIZE "gpd.ta.stackSize" 116 #define TA_PROP_STR_VERSION "gpd.ta.version" 117 #define TA_PROP_STR_DESCRIPTION "gpd.ta.description" 118 119 enum user_ta_prop_type { 120 USER_TA_PROP_TYPE_BOOL, /* bool */ 121 USER_TA_PROP_TYPE_U32, /* uint32_t */ 122 USER_TA_PROP_TYPE_UUID, /* TEE_UUID */ 123 USER_TA_PROP_TYPE_IDENTITY, /* TEE_Identity */ 124 USER_TA_PROP_TYPE_STRING, /* zero terminated string of char */ 125 USER_TA_PROP_TYPE_BINARY_BLOCK, /* zero terminated base64 coded string */ 126 }; 127 128 struct user_ta_property { 129 const char *name; 130 enum user_ta_prop_type type; 131 const void *value; 132 }; 133 134 extern const struct user_ta_property ta_props[]; 135 extern const size_t ta_num_props; 136 137 /* Needed by TEE_CheckMemoryAccessRights() */ 138 extern uint32_t ta_param_types; 139 extern TEE_Param ta_params[TEE_NUM_PARAMS]; 140 141 int tahead_get_trace_level(void); 142 143 #endif /* USER_TA_HEADER_H */ 144