xref: /optee_os/lib/libutee/include/user_ta_header.h (revision 10b907910d58334cc5b1486cb2f91a08f764566e)
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 #define TA_FLAG_DEVICE_ENUM		(1 << 9) /* device enumeration */
27 
28 #define TA_FLAGS_MASK			GENMASK_32(9, 0)
29 
30 struct ta_head {
31 	TEE_UUID uuid;
32 	uint32_t stack_size;
33 	uint32_t flags;
34 	uint64_t depr_entry;
35 };
36 
37 #if defined(CFG_FTRACE_SUPPORT)
38 #define FTRACE_RETFUNC_DEPTH		50
39 union compat_ptr {
40 	uint64_t ptr64;
41 	struct {
42 		uint32_t lo;
43 		uint32_t hi;
44 	} ptr32;
45 };
46 
47 struct __ftrace_info {
48 	union compat_ptr buf_start;
49 	union compat_ptr buf_end;
50 	union compat_ptr ret_ptr;
51 };
52 
53 struct ftrace_buf {
54 	uint64_t ret_func_ptr;	/* __ftrace_return pointer */
55 	uint64_t ret_stack[FTRACE_RETFUNC_DEPTH]; /* Return stack */
56 	uint32_t ret_idx;	/* Return stack index */
57 	uint32_t lr_idx;	/* lr index used for stack unwinding */
58 	uint64_t begin_time[FTRACE_RETFUNC_DEPTH]; /* Timestamp */
59 	uint64_t suspend_time;	/* Suspend timestamp */
60 	uint32_t curr_size;	/* Size of ftrace buffer */
61 	uint32_t max_size;	/* Max allowed size of ftrace buffer */
62 	uint32_t head_off;	/* Ftrace buffer header offset */
63 	uint32_t buf_off;	/* Ftrace buffer offset */
64 	bool syscall_trace_enabled; /* Some syscalls are never traced */
65 	bool syscall_trace_suspended; /* By foreign interrupt or RPC */
66 };
67 
68 /* Defined by the linker script */
69 extern struct ftrace_buf __ftrace_buf_start;
70 extern uint8_t __ftrace_buf_end[];
71 
72 unsigned long ftrace_return(void);
73 void __ftrace_return(void);
74 #endif
75 
76 /*
77  * Pointers to ELF initialization and finalization functions are extracted by
78  * ldelf and stored on the TA heap. They can be accessed via the TA global
79  * variable __init_fini_info::ifs, but the functions are meant to called via
80  * __utee_call_elf_init_fn() and __utee_call_elf_fini_fn().
81  */
82 
83 struct __init_fini {
84 	uint32_t flags;
85 	uint16_t init_size;
86 	uint16_t fini_size;
87 
88 	void (**init)(void); /* @init_size entries */
89 	void (**fini)(void); /* @fini_size entries */
90 };
91 
92 #define __IFS_VALID		BIT(0)
93 #define __IFS_INIT_HAS_RUN	BIT(1)
94 #define __IFS_FINI_HAS_RUN	BIT(2)
95 
96 struct __init_fini_info {
97 	uint32_t reserved;
98 	uint16_t size;
99 	uint16_t pad;
100 	struct __init_fini *ifs; /* @size entries */
101 };
102 
103 /* 32-bit variants for a 64-bit ldelf to access a 32-bit TA */
104 
105 struct __init_fini32 {
106 	uint32_t flags;
107 	uint16_t init_size;
108 	uint16_t fini_size;
109 	uint32_t init;
110 	uint32_t fini;
111 };
112 
113 struct __init_fini_info32 {
114 	uint32_t reserved;
115 	uint16_t size;
116 	uint16_t pad;
117 	uint32_t ifs;
118 };
119 
120 void __utee_call_elf_init_fn(void);
121 void __utee_call_elf_fini_fn(void);
122 
123 #define TA_PROP_STR_SINGLE_INSTANCE	"gpd.ta.singleInstance"
124 #define TA_PROP_STR_MULTI_SESSION	"gpd.ta.multiSession"
125 #define TA_PROP_STR_KEEP_ALIVE		"gpd.ta.instanceKeepAlive"
126 #define TA_PROP_STR_DATA_SIZE		"gpd.ta.dataSize"
127 #define TA_PROP_STR_STACK_SIZE		"gpd.ta.stackSize"
128 #define TA_PROP_STR_VERSION		"gpd.ta.version"
129 #define TA_PROP_STR_DESCRIPTION		"gpd.ta.description"
130 #define TA_PROP_STR_UNSAFE_PARAM	"op-tee.unsafe_param"
131 #define TA_PROP_STR_REMAP		"op-tee.remap"
132 #define TA_PROP_STR_CACHE_SYNC		"op-tee.cache_sync"
133 
134 enum user_ta_prop_type {
135 	USER_TA_PROP_TYPE_BOOL,	/* bool */
136 	USER_TA_PROP_TYPE_U32,	/* uint32_t */
137 	USER_TA_PROP_TYPE_UUID,	/* TEE_UUID */
138 	USER_TA_PROP_TYPE_IDENTITY,	/* TEE_Identity */
139 	USER_TA_PROP_TYPE_STRING,	/* zero terminated string of char */
140 	USER_TA_PROP_TYPE_BINARY_BLOCK,	/* zero terminated base64 coded string */
141 };
142 
143 enum user_ta_core_service_id {
144 	USER_TA_CORE_ENTRY_MATH_INIT = 0x00000010,
145 	USER_TA_CORE_ENTRY_GARBAGE = 0x00000011,
146 	USER_TA_CORE_ENTRY_CLOSESESSION = 0x00000012,
147 };
148 
149 struct user_ta_property {
150 	const char *name;
151 	enum user_ta_prop_type type;
152 	const void *value;
153 };
154 
155 extern const struct user_ta_property ta_props[];
156 extern const size_t ta_num_props;
157 
158 /* Needed by TEE_CheckMemoryAccessRights() */
159 extern uint32_t ta_param_types;
160 extern TEE_Param ta_params[TEE_NUM_PARAMS];
161 
162 /* Trusted Application Function header */
163 typedef struct ta_func_head {
164 	uint32_t cmd_id;	/* Trusted Application Function ID */
165 	uint32_t start;		/* offset to start func */
166 } ta_func_head_t;
167 
168 int tahead_get_trace_level(void);
169 
170 #endif /* USER_TA_HEADER_H */
171