xref: /optee_os/lib/libutee/include/user_ta_header.h (revision 4edd96e6d7a7228e907cf498b23e5b5fbdaf39a0)
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_idx;	/* Current entry in the (circular) 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 	bool overflow;		/* Circular buffer has wrapped */
77 };
78 
79 /* Defined by the linker script */
80 extern struct ftrace_buf __ftrace_buf_start;
81 extern uint8_t __ftrace_buf_end[];
82 
83 unsigned long ftrace_return(void);
84 void __ftrace_return(void);
85 #endif
86 
87 void __utee_call_elf_init_fn(void);
88 void __utee_call_elf_fini_fn(void);
89 
90 void __utee_tcb_init(void);
91 
92 /*
93  * Information about the ELF objects loaded by the application
94  */
95 
96 struct __elf_phdr_info {
97 	uint32_t reserved;
98 	uint16_t count;
99 	uint8_t reserved2;
100 	char zero;
101 	struct dl_phdr_info *dlpi; /* @count entries */
102 };
103 
104 /* 32-bit variant for a 64-bit ldelf to access a 32-bit TA */
105 struct __elf_phdr_info32 {
106 	uint32_t reserved;
107 	uint16_t count;
108 	uint8_t reserved2;
109 	char zero;
110 	uint32_t dlpi;
111 };
112 
113 extern struct __elf_phdr_info __elf_phdr_info;
114 
115 #define TA_PROP_STR_SINGLE_INSTANCE	"gpd.ta.singleInstance"
116 #define TA_PROP_STR_MULTI_SESSION	"gpd.ta.multiSession"
117 #define TA_PROP_STR_KEEP_ALIVE		"gpd.ta.instanceKeepAlive"
118 #define TA_PROP_STR_DATA_SIZE		"gpd.ta.dataSize"
119 #define TA_PROP_STR_STACK_SIZE		"gpd.ta.stackSize"
120 #define TA_PROP_STR_VERSION		"gpd.ta.version"
121 #define TA_PROP_STR_DESCRIPTION		"gpd.ta.description"
122 #define TA_PROP_STR_ENDIAN		"gpd.ta.endian"
123 #define TA_PROP_STR_DOES_NOT_CLOSE_HANDLE_ON_CORRUPT_OBJECT \
124 	"gpd.ta.doesNotCloseHandleOnCorruptObject"
125 
126 enum user_ta_prop_type {
127 	USER_TA_PROP_TYPE_BOOL,	/* bool */
128 	USER_TA_PROP_TYPE_U32,	/* uint32_t */
129 	USER_TA_PROP_TYPE_UUID,	/* TEE_UUID */
130 	USER_TA_PROP_TYPE_IDENTITY,	/* TEE_Identity */
131 	USER_TA_PROP_TYPE_STRING,	/* zero terminated string of char */
132 	USER_TA_PROP_TYPE_BINARY_BLOCK,	/* zero terminated base64 coded string */
133 	USER_TA_PROP_TYPE_U64,	/* uint64_t */
134 	USER_TA_PROP_TYPE_INVALID,	/* invalid value */
135 };
136 
137 struct user_ta_property {
138 	const char *name;
139 	enum user_ta_prop_type type;
140 	const void *value;
141 };
142 
143 extern const struct user_ta_property ta_props[];
144 extern const size_t ta_num_props;
145 
146 extern uint8_t __ta_no_share_heap[];
147 extern const size_t __ta_no_share_heap_size;
148 /* Needed by TEE_CheckMemoryAccessRights() */
149 extern uint32_t ta_param_types;
150 extern TEE_Param ta_params[TEE_NUM_PARAMS];
151 extern struct malloc_ctx *__ta_no_share_malloc_ctx;
152 
153 int tahead_get_trace_level(void);
154 
155 #endif /* USER_TA_HEADER_H */
156