11bb92983SJerome Forissier /* SPDX-License-Identifier: BSD-2-Clause */ 2b0104773SPascal Brand /* 3b0104773SPascal Brand * Copyright (c) 2014, STMicroelectronics International N.V. 4387b0ee3SEtienne Carriere * Copyright (c) 2018, Linaro Limited. 5b0104773SPascal Brand */ 6b0104773SPascal Brand 7b0104773SPascal Brand #ifndef USER_TA_HEADER_H 8b0104773SPascal Brand #define USER_TA_HEADER_H 9b0104773SPascal Brand 10b0104773SPascal Brand #include <tee_api_types.h> 11387b0ee3SEtienne Carriere #include <util.h> 12b0104773SPascal Brand 13*138c5102SJens Wiklander #define TA_FLAG_USER_MODE 0 /* Deprecated, was BIT32(0) */ 14*138c5102SJens Wiklander #define TA_FLAG_EXEC_DDR 0 /* Deprecated, was BIT32(1) */ 15*138c5102SJens Wiklander #define TA_FLAG_SINGLE_INSTANCE BIT32(2) 16*138c5102SJens Wiklander #define TA_FLAG_MULTI_SESSION BIT32(3) 17*138c5102SJens Wiklander #define TA_FLAG_INSTANCE_KEEP_ALIVE BIT32(4) /* remains after last close */ 18*138c5102SJens Wiklander #define TA_FLAG_SECURE_DATA_PATH BIT32(5) /* accesses SDP memory */ 19*138c5102SJens Wiklander #define TA_FLAG_REMAP_SUPPORT 0 /* Deprecated, was BIT32(6) */ 20*138c5102SJens Wiklander #define TA_FLAG_CACHE_MAINTENANCE BIT32(7) /* use cache flush syscall */ 21c7c4b6e3SJens Wiklander /* 22c7c4b6e3SJens Wiklander * TA instance can execute multiple sessions concurrently 23c7c4b6e3SJens Wiklander * (pseudo-TAs only). 24c7c4b6e3SJens Wiklander */ 25*138c5102SJens Wiklander #define TA_FLAG_CONCURRENT BIT32(8) 26bc5921cdSMaxim Uvarov /* 27bc5921cdSMaxim Uvarov * Device enumeration is done in two stages by the normal world, first 28bc5921cdSMaxim Uvarov * before the tee-supplicant has started and then once more when the 29bc5921cdSMaxim Uvarov * tee-supplicant is started. The flags below control if the TA should 30bc5921cdSMaxim Uvarov * be reported in the first or second or case. 31bc5921cdSMaxim Uvarov */ 32*138c5102SJens Wiklander #define TA_FLAG_DEVICE_ENUM BIT32(9) /* without tee-supplicant */ 33*138c5102SJens Wiklander #define TA_FLAG_DEVICE_ENUM_SUPP BIT32(10) /* with tee-supplicant */ 34*138c5102SJens Wiklander /* See also "gpd.ta.doesNotCloseHandleOnCorruptObject" */ 35*138c5102SJens Wiklander #define TA_FLAG_DONT_CLOSE_HANDLE_ON_CORRUPT_OBJECT \ 36*138c5102SJens Wiklander BIT32(11) 3755d3ebe9SPascal Brand 38bc5921cdSMaxim Uvarov #define TA_FLAGS_MASK GENMASK_32(10, 0) 39387b0ee3SEtienne Carriere 40bc420748SJens Wiklander struct ta_head { 41bc420748SJens Wiklander TEE_UUID uuid; 42bc420748SJens Wiklander uint32_t stack_size; 43bc420748SJens Wiklander uint32_t flags; 44a73b5878SJens Wiklander uint64_t depr_entry; 45bc420748SJens Wiklander }; 46bc420748SJens Wiklander 47099918f6SSumit Garg #if defined(CFG_FTRACE_SUPPORT) 48b02ae382SSumit Garg #define FTRACE_RETFUNC_DEPTH 50 49c96d7091SSumit Garg union compat_ptr { 50c96d7091SSumit Garg uint64_t ptr64; 51c96d7091SSumit Garg struct { 52c96d7091SSumit Garg uint32_t lo; 53c96d7091SSumit Garg uint32_t hi; 54c96d7091SSumit Garg } ptr32; 55c96d7091SSumit Garg }; 56c96d7091SSumit Garg 57b02ae382SSumit Garg struct __ftrace_info { 58c96d7091SSumit Garg union compat_ptr buf_start; 59c96d7091SSumit Garg union compat_ptr buf_end; 60c96d7091SSumit Garg union compat_ptr ret_ptr; 61b02ae382SSumit Garg }; 62b02ae382SSumit Garg 63b02ae382SSumit Garg struct ftrace_buf { 64b02ae382SSumit Garg uint64_t ret_func_ptr; /* __ftrace_return pointer */ 65b02ae382SSumit Garg uint64_t ret_stack[FTRACE_RETFUNC_DEPTH]; /* Return stack */ 66b02ae382SSumit Garg uint32_t ret_idx; /* Return stack index */ 67b02ae382SSumit Garg uint32_t lr_idx; /* lr index used for stack unwinding */ 68f5df167cSSumit Garg uint64_t begin_time[FTRACE_RETFUNC_DEPTH]; /* Timestamp */ 69f5df167cSSumit Garg uint64_t suspend_time; /* Suspend timestamp */ 70b02ae382SSumit Garg uint32_t curr_size; /* Size of ftrace buffer */ 71b02ae382SSumit Garg uint32_t max_size; /* Max allowed size of ftrace buffer */ 72b02ae382SSumit Garg uint32_t head_off; /* Ftrace buffer header offset */ 73b02ae382SSumit Garg uint32_t buf_off; /* Ftrace buffer offset */ 74099918f6SSumit Garg bool syscall_trace_enabled; /* Some syscalls are never traced */ 75099918f6SSumit Garg bool syscall_trace_suspended; /* By foreign interrupt or RPC */ 76b02ae382SSumit Garg }; 77b02ae382SSumit Garg 78b02ae382SSumit Garg /* Defined by the linker script */ 79b02ae382SSumit Garg extern struct ftrace_buf __ftrace_buf_start; 80b02ae382SSumit Garg extern uint8_t __ftrace_buf_end[]; 81b02ae382SSumit Garg 82b02ae382SSumit Garg unsigned long ftrace_return(void); 83b02ae382SSumit Garg void __ftrace_return(void); 84b02ae382SSumit Garg #endif 85b02ae382SSumit Garg 86dd655cb9SJerome Forissier void __utee_call_elf_init_fn(void); 87dd655cb9SJerome Forissier void __utee_call_elf_fini_fn(void); 88dd655cb9SJerome Forissier 899d224046SJerome Forissier void __utee_tcb_init(void); 909d224046SJerome Forissier 919d224046SJerome Forissier /* 929d224046SJerome Forissier * Information about the ELF objects loaded by the application 939d224046SJerome Forissier */ 949d224046SJerome Forissier 959d224046SJerome Forissier struct __elf_phdr_info { 969d224046SJerome Forissier uint32_t reserved; 979d224046SJerome Forissier uint16_t count; 989d224046SJerome Forissier uint8_t reserved2; 999d224046SJerome Forissier char zero; 1009d224046SJerome Forissier struct dl_phdr_info *dlpi; /* @count entries */ 1019d224046SJerome Forissier }; 1029d224046SJerome Forissier 1039d224046SJerome Forissier /* 32-bit variant for a 64-bit ldelf to access a 32-bit TA */ 1049d224046SJerome Forissier struct __elf_phdr_info32 { 1059d224046SJerome Forissier uint32_t reserved; 1069d224046SJerome Forissier uint16_t count; 1079d224046SJerome Forissier uint8_t reserved2; 1089d224046SJerome Forissier char zero; 1099d224046SJerome Forissier uint32_t dlpi; 1109d224046SJerome Forissier }; 1119d224046SJerome Forissier 1129d224046SJerome Forissier extern struct __elf_phdr_info __elf_phdr_info; 1139d224046SJerome Forissier 11455d3ebe9SPascal Brand #define TA_PROP_STR_SINGLE_INSTANCE "gpd.ta.singleInstance" 11555d3ebe9SPascal Brand #define TA_PROP_STR_MULTI_SESSION "gpd.ta.multiSession" 11655d3ebe9SPascal Brand #define TA_PROP_STR_KEEP_ALIVE "gpd.ta.instanceKeepAlive" 11755d3ebe9SPascal Brand #define TA_PROP_STR_DATA_SIZE "gpd.ta.dataSize" 11855d3ebe9SPascal Brand #define TA_PROP_STR_STACK_SIZE "gpd.ta.stackSize" 119d71d2857SCedric Chaumont #define TA_PROP_STR_VERSION "gpd.ta.version" 120d71d2857SCedric Chaumont #define TA_PROP_STR_DESCRIPTION "gpd.ta.description" 121d3efff0bSJens Wiklander #define TA_PROP_STR_ENDIAN "gpd.ta.endian" 122*138c5102SJens Wiklander #define TA_PROP_STR_DOES_NOT_CLOSE_HANDLE_ON_CORRUPT_OBJECT \ 123*138c5102SJens Wiklander "gpd.ta.doesNotCloseHandleOnCorruptObject" 124b0104773SPascal Brand 125b0104773SPascal Brand enum user_ta_prop_type { 126b0104773SPascal Brand USER_TA_PROP_TYPE_BOOL, /* bool */ 127b0104773SPascal Brand USER_TA_PROP_TYPE_U32, /* uint32_t */ 128b0104773SPascal Brand USER_TA_PROP_TYPE_UUID, /* TEE_UUID */ 129b0104773SPascal Brand USER_TA_PROP_TYPE_IDENTITY, /* TEE_Identity */ 130b0104773SPascal Brand USER_TA_PROP_TYPE_STRING, /* zero terminated string of char */ 131b0104773SPascal Brand USER_TA_PROP_TYPE_BINARY_BLOCK, /* zero terminated base64 coded string */ 1326551d565SJens Wiklander USER_TA_PROP_TYPE_U64, /* uint64_t */ 133b0104773SPascal Brand }; 134b0104773SPascal Brand 135b0104773SPascal Brand struct user_ta_property { 136b0104773SPascal Brand const char *name; 137b0104773SPascal Brand enum user_ta_prop_type type; 138b0104773SPascal Brand const void *value; 139b0104773SPascal Brand }; 140b0104773SPascal Brand 141b0104773SPascal Brand extern const struct user_ta_property ta_props[]; 142b0104773SPascal Brand extern const size_t ta_num_props; 143b0104773SPascal Brand 144e64b7b2eSJens Wiklander extern uint8_t __ta_no_share_heap[]; 145e64b7b2eSJens Wiklander extern const size_t __ta_no_share_heap_size; 146b0104773SPascal Brand /* Needed by TEE_CheckMemoryAccessRights() */ 147b0104773SPascal Brand extern uint32_t ta_param_types; 14868540524SIgor Opaniuk extern TEE_Param ta_params[TEE_NUM_PARAMS]; 149e64b7b2eSJens Wiklander extern struct malloc_ctx *__ta_no_share_malloc_ctx; 150b0104773SPascal Brand 151b0104773SPascal Brand int tahead_get_trace_level(void); 152b0104773SPascal Brand 153b0104773SPascal Brand #endif /* USER_TA_HEADER_H */ 154