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