xref: /optee_os/lib/libutee/include/user_ta_header.h (revision bc5921cdab538c8ae48422f5ffd600f1cbdd95b2)
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 /*
84  * Pointers to ELF initialization and finalization functions are extracted by
85  * ldelf and stored on the TA heap. They can be accessed via the TA global
86  * variable __init_fini_info::ifs, but the functions are meant to called via
87  * __utee_call_elf_init_fn() and __utee_call_elf_fini_fn().
88  */
89 
90 struct __init_fini {
91 	uint32_t flags;
92 	uint16_t init_size;
93 	uint16_t fini_size;
94 
95 	void (**init)(void); /* @init_size entries */
96 	void (**fini)(void); /* @fini_size entries */
97 };
98 
99 #define __IFS_VALID		BIT(0)
100 #define __IFS_INIT_HAS_RUN	BIT(1)
101 #define __IFS_FINI_HAS_RUN	BIT(2)
102 
103 struct __init_fini_info {
104 	uint32_t reserved;
105 	uint16_t size;
106 	uint16_t pad;
107 	struct __init_fini *ifs; /* @size entries */
108 };
109 
110 /* 32-bit variants for a 64-bit ldelf to access a 32-bit TA */
111 
112 struct __init_fini32 {
113 	uint32_t flags;
114 	uint16_t init_size;
115 	uint16_t fini_size;
116 	uint32_t init;
117 	uint32_t fini;
118 };
119 
120 struct __init_fini_info32 {
121 	uint32_t reserved;
122 	uint16_t size;
123 	uint16_t pad;
124 	uint32_t ifs;
125 };
126 
127 void __utee_call_elf_init_fn(void);
128 void __utee_call_elf_fini_fn(void);
129 
130 #define TA_PROP_STR_SINGLE_INSTANCE	"gpd.ta.singleInstance"
131 #define TA_PROP_STR_MULTI_SESSION	"gpd.ta.multiSession"
132 #define TA_PROP_STR_KEEP_ALIVE		"gpd.ta.instanceKeepAlive"
133 #define TA_PROP_STR_DATA_SIZE		"gpd.ta.dataSize"
134 #define TA_PROP_STR_STACK_SIZE		"gpd.ta.stackSize"
135 #define TA_PROP_STR_VERSION		"gpd.ta.version"
136 #define TA_PROP_STR_DESCRIPTION		"gpd.ta.description"
137 #define TA_PROP_STR_UNSAFE_PARAM	"op-tee.unsafe_param"
138 #define TA_PROP_STR_REMAP		"op-tee.remap"
139 #define TA_PROP_STR_CACHE_SYNC		"op-tee.cache_sync"
140 
141 enum user_ta_prop_type {
142 	USER_TA_PROP_TYPE_BOOL,	/* bool */
143 	USER_TA_PROP_TYPE_U32,	/* uint32_t */
144 	USER_TA_PROP_TYPE_UUID,	/* TEE_UUID */
145 	USER_TA_PROP_TYPE_IDENTITY,	/* TEE_Identity */
146 	USER_TA_PROP_TYPE_STRING,	/* zero terminated string of char */
147 	USER_TA_PROP_TYPE_BINARY_BLOCK,	/* zero terminated base64 coded string */
148 };
149 
150 enum user_ta_core_service_id {
151 	USER_TA_CORE_ENTRY_MATH_INIT = 0x00000010,
152 	USER_TA_CORE_ENTRY_GARBAGE = 0x00000011,
153 	USER_TA_CORE_ENTRY_CLOSESESSION = 0x00000012,
154 };
155 
156 struct user_ta_property {
157 	const char *name;
158 	enum user_ta_prop_type type;
159 	const void *value;
160 };
161 
162 extern const struct user_ta_property ta_props[];
163 extern const size_t ta_num_props;
164 
165 /* Needed by TEE_CheckMemoryAccessRights() */
166 extern uint32_t ta_param_types;
167 extern TEE_Param ta_params[TEE_NUM_PARAMS];
168 
169 /* Trusted Application Function header */
170 typedef struct ta_func_head {
171 	uint32_t cmd_id;	/* Trusted Application Function ID */
172 	uint32_t start;		/* offset to start func */
173 } ta_func_head_t;
174 
175 int tahead_get_trace_level(void);
176 
177 #endif /* USER_TA_HEADER_H */
178