xref: /optee_os/lib/libutee/include/user_ta_header.h (revision a1f2c4302d527853b44b3f33a76a1c2c341101f4)
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 
13138c5102SJens Wiklander #define TA_FLAG_USER_MODE		0	 /* Deprecated, was BIT32(0) */
14138c5102SJens Wiklander #define TA_FLAG_EXEC_DDR		0	 /* Deprecated, was BIT32(1) */
15138c5102SJens Wiklander #define TA_FLAG_SINGLE_INSTANCE		BIT32(2)
16138c5102SJens Wiklander #define TA_FLAG_MULTI_SESSION		BIT32(3)
17138c5102SJens Wiklander #define TA_FLAG_INSTANCE_KEEP_ALIVE	BIT32(4) /* remains after last close */
18138c5102SJens Wiklander #define TA_FLAG_SECURE_DATA_PATH	BIT32(5) /* accesses SDP memory */
19138c5102SJens Wiklander #define TA_FLAG_REMAP_SUPPORT		0	 /* Deprecated, was BIT32(6) */
20138c5102SJens 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 	 */
25138c5102SJens 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 	 */
32138c5102SJens Wiklander #define TA_FLAG_DEVICE_ENUM		BIT32(9)  /* without tee-supplicant */
33138c5102SJens Wiklander #define TA_FLAG_DEVICE_ENUM_SUPP	BIT32(10) /* with tee-supplicant */
34138c5102SJens Wiklander 	/* See also "gpd.ta.doesNotCloseHandleOnCorruptObject" */
35138c5102SJens Wiklander #define TA_FLAG_DONT_CLOSE_HANDLE_ON_CORRUPT_OBJECT \
36138c5102SJens 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 */
705c2c0fb3SJerome Forissier 	uint32_t curr_idx;	/* Current entry in the (circular) 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 */
765c2c0fb3SJerome Forissier 	bool overflow;		/* Circular buffer has wrapped */
77b02ae382SSumit Garg };
78b02ae382SSumit Garg 
79b02ae382SSumit Garg /* Defined by the linker script */
80b02ae382SSumit Garg extern struct ftrace_buf __ftrace_buf_start;
81b02ae382SSumit Garg extern uint8_t __ftrace_buf_end[];
82b02ae382SSumit Garg 
83b02ae382SSumit Garg unsigned long ftrace_return(void);
84b02ae382SSumit Garg void __ftrace_return(void);
85b02ae382SSumit Garg #endif
86b02ae382SSumit Garg 
87dd655cb9SJerome Forissier void __utee_call_elf_init_fn(void);
88dd655cb9SJerome Forissier void __utee_call_elf_fini_fn(void);
89dd655cb9SJerome Forissier 
909d224046SJerome Forissier void __utee_tcb_init(void);
919d224046SJerome Forissier 
929d224046SJerome Forissier /*
939d224046SJerome Forissier  * Information about the ELF objects loaded by the application
949d224046SJerome Forissier  */
959d224046SJerome Forissier 
969d224046SJerome Forissier struct __elf_phdr_info {
979d224046SJerome Forissier 	uint32_t reserved;
989d224046SJerome Forissier 	uint16_t count;
999d224046SJerome Forissier 	uint8_t reserved2;
1009d224046SJerome Forissier 	char zero;
1019d224046SJerome Forissier 	struct dl_phdr_info *dlpi; /* @count entries */
1029d224046SJerome Forissier };
1039d224046SJerome Forissier 
1049d224046SJerome Forissier /* 32-bit variant for a 64-bit ldelf to access a 32-bit TA */
1059d224046SJerome Forissier struct __elf_phdr_info32 {
1069d224046SJerome Forissier 	uint32_t reserved;
1079d224046SJerome Forissier 	uint16_t count;
1089d224046SJerome Forissier 	uint8_t reserved2;
1099d224046SJerome Forissier 	char zero;
1109d224046SJerome Forissier 	uint32_t dlpi;
1119d224046SJerome Forissier };
1129d224046SJerome Forissier 
1139d224046SJerome Forissier extern struct __elf_phdr_info __elf_phdr_info;
1149d224046SJerome Forissier 
11555d3ebe9SPascal Brand #define TA_PROP_STR_SINGLE_INSTANCE	"gpd.ta.singleInstance"
11655d3ebe9SPascal Brand #define TA_PROP_STR_MULTI_SESSION	"gpd.ta.multiSession"
11755d3ebe9SPascal Brand #define TA_PROP_STR_KEEP_ALIVE		"gpd.ta.instanceKeepAlive"
11855d3ebe9SPascal Brand #define TA_PROP_STR_DATA_SIZE		"gpd.ta.dataSize"
11955d3ebe9SPascal Brand #define TA_PROP_STR_STACK_SIZE		"gpd.ta.stackSize"
120d71d2857SCedric Chaumont #define TA_PROP_STR_VERSION		"gpd.ta.version"
121d71d2857SCedric Chaumont #define TA_PROP_STR_DESCRIPTION		"gpd.ta.description"
122d3efff0bSJens Wiklander #define TA_PROP_STR_ENDIAN		"gpd.ta.endian"
123138c5102SJens Wiklander #define TA_PROP_STR_DOES_NOT_CLOSE_HANDLE_ON_CORRUPT_OBJECT \
124138c5102SJens Wiklander 	"gpd.ta.doesNotCloseHandleOnCorruptObject"
125b0104773SPascal Brand 
126b0104773SPascal Brand enum user_ta_prop_type {
127b0104773SPascal Brand 	USER_TA_PROP_TYPE_BOOL,	/* bool */
128b0104773SPascal Brand 	USER_TA_PROP_TYPE_U32,	/* uint32_t */
129b0104773SPascal Brand 	USER_TA_PROP_TYPE_UUID,	/* TEE_UUID */
130b0104773SPascal Brand 	USER_TA_PROP_TYPE_IDENTITY,	/* TEE_Identity */
131b0104773SPascal Brand 	USER_TA_PROP_TYPE_STRING,	/* zero terminated string of char */
132b0104773SPascal Brand 	USER_TA_PROP_TYPE_BINARY_BLOCK,	/* zero terminated base64 coded string */
1336551d565SJens Wiklander 	USER_TA_PROP_TYPE_U64,	/* uint64_t */
134*a1f2c430SClement Faure 	USER_TA_PROP_TYPE_INVALID,	/* invalid value */
135b0104773SPascal Brand };
136b0104773SPascal Brand 
137b0104773SPascal Brand struct user_ta_property {
138b0104773SPascal Brand 	const char *name;
139b0104773SPascal Brand 	enum user_ta_prop_type type;
140b0104773SPascal Brand 	const void *value;
141b0104773SPascal Brand };
142b0104773SPascal Brand 
143b0104773SPascal Brand extern const struct user_ta_property ta_props[];
144b0104773SPascal Brand extern const size_t ta_num_props;
145b0104773SPascal Brand 
146e64b7b2eSJens Wiklander extern uint8_t __ta_no_share_heap[];
147e64b7b2eSJens Wiklander extern const size_t __ta_no_share_heap_size;
148b0104773SPascal Brand /* Needed by TEE_CheckMemoryAccessRights() */
149b0104773SPascal Brand extern uint32_t ta_param_types;
15068540524SIgor Opaniuk extern TEE_Param ta_params[TEE_NUM_PARAMS];
151e64b7b2eSJens Wiklander extern struct malloc_ctx *__ta_no_share_malloc_ctx;
152b0104773SPascal Brand 
153b0104773SPascal Brand int tahead_get_trace_level(void);
154b0104773SPascal Brand 
155b0104773SPascal Brand #endif /* USER_TA_HEADER_H */
156