xref: /optee_os/lib/libutee/include/user_ta_header.h (revision c96d7091b566e1c37410bfddb5b3c5280ddcc13a)
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 
13fe8db355SJerome Forissier #define TA_FLAG_USER_MODE		0	 /* Deprecated, was (1 << 0) */
14fe8db355SJerome Forissier #define TA_FLAG_EXEC_DDR		0	 /* Deprecated, was (1 << 1) */
15b0104773SPascal Brand #define TA_FLAG_SINGLE_INSTANCE		(1 << 2)
16b0104773SPascal Brand #define TA_FLAG_MULTI_SESSION		(1 << 3)
1755d3ebe9SPascal Brand #define TA_FLAG_INSTANCE_KEEP_ALIVE	(1 << 4) /* remains after last close */
18c04e5c1dSEtienne Carriere #define TA_FLAG_SECURE_DATA_PATH	(1 << 5) /* accesses SDP memory */
1980c4fb79SEtienne Carriere #define TA_FLAG_REMAP_SUPPORT		0	 /* Deprecated, was (1 << 6) */
2055d3ebe9SPascal Brand #define TA_FLAG_CACHE_MAINTENANCE	(1 << 7) /* use cache flush syscall */
21c7c4b6e3SJens Wiklander 	/*
22c7c4b6e3SJens Wiklander 	 * TA instance can execute multiple sessions concurrently
23c7c4b6e3SJens Wiklander 	 * (pseudo-TAs only).
24c7c4b6e3SJens Wiklander 	 */
25c7c4b6e3SJens Wiklander #define TA_FLAG_CONCURRENT		(1 << 8)
260b611081SSumit Garg #define TA_FLAG_DEVICE_ENUM		(1 << 9) /* device enumeration */
2755d3ebe9SPascal Brand 
28fe8db355SJerome Forissier #define TA_FLAGS_MASK			GENMASK_32(9, 0)
29387b0ee3SEtienne Carriere 
30bc420748SJens Wiklander struct ta_head {
31bc420748SJens Wiklander 	TEE_UUID uuid;
32bc420748SJens Wiklander 	uint32_t stack_size;
33bc420748SJens Wiklander 	uint32_t flags;
34a73b5878SJens Wiklander 	uint64_t depr_entry;
35bc420748SJens Wiklander };
36bc420748SJens Wiklander 
37b02ae382SSumit Garg #if defined(CFG_TA_FTRACE_SUPPORT)
38b02ae382SSumit Garg #define FTRACE_RETFUNC_DEPTH		50
39*c96d7091SSumit Garg union compat_ptr {
40*c96d7091SSumit Garg 	uint64_t ptr64;
41*c96d7091SSumit Garg 	struct {
42*c96d7091SSumit Garg 		uint32_t lo;
43*c96d7091SSumit Garg 		uint32_t hi;
44*c96d7091SSumit Garg 	} ptr32;
45*c96d7091SSumit Garg };
46*c96d7091SSumit Garg 
47b02ae382SSumit Garg struct __ftrace_info {
48*c96d7091SSumit Garg 	union compat_ptr buf_start;
49*c96d7091SSumit Garg 	union compat_ptr buf_end;
50*c96d7091SSumit Garg 	union compat_ptr ret_ptr;
51b02ae382SSumit Garg };
52b02ae382SSumit Garg 
53b02ae382SSumit Garg struct ftrace_buf {
54b02ae382SSumit Garg 	uint64_t ret_func_ptr;	/* __ftrace_return pointer */
55b02ae382SSumit Garg 	uint64_t ret_stack[FTRACE_RETFUNC_DEPTH]; /* Return stack */
56b02ae382SSumit Garg 	uint32_t ret_idx;	/* Return stack index */
57b02ae382SSumit Garg 	uint32_t lr_idx;	/* lr index used for stack unwinding */
58b02ae382SSumit Garg 	uint32_t curr_size;	/* Size of ftrace buffer */
59b02ae382SSumit Garg 	uint32_t max_size;	/* Max allowed size of ftrace buffer */
60b02ae382SSumit Garg 	uint32_t head_off;	/* Ftrace buffer header offset */
61b02ae382SSumit Garg 	uint32_t buf_off;	/* Ftrace buffer offset */
62b02ae382SSumit Garg };
63b02ae382SSumit Garg 
64b02ae382SSumit Garg /* Defined by the linker script */
65b02ae382SSumit Garg extern struct ftrace_buf __ftrace_buf_start;
66b02ae382SSumit Garg extern uint8_t __ftrace_buf_end[];
67b02ae382SSumit Garg 
68b02ae382SSumit Garg unsigned long ftrace_return(void);
69b02ae382SSumit Garg void __ftrace_return(void);
70b02ae382SSumit Garg #endif
71b02ae382SSumit Garg 
7255d3ebe9SPascal Brand #define TA_PROP_STR_SINGLE_INSTANCE	"gpd.ta.singleInstance"
7355d3ebe9SPascal Brand #define TA_PROP_STR_MULTI_SESSION	"gpd.ta.multiSession"
7455d3ebe9SPascal Brand #define TA_PROP_STR_KEEP_ALIVE		"gpd.ta.instanceKeepAlive"
7555d3ebe9SPascal Brand #define TA_PROP_STR_DATA_SIZE		"gpd.ta.dataSize"
7655d3ebe9SPascal Brand #define TA_PROP_STR_STACK_SIZE		"gpd.ta.stackSize"
77d71d2857SCedric Chaumont #define TA_PROP_STR_VERSION		"gpd.ta.version"
78d71d2857SCedric Chaumont #define TA_PROP_STR_DESCRIPTION		"gpd.ta.description"
7955d3ebe9SPascal Brand #define TA_PROP_STR_UNSAFE_PARAM	"op-tee.unsafe_param"
8055d3ebe9SPascal Brand #define TA_PROP_STR_REMAP		"op-tee.remap"
8155d3ebe9SPascal Brand #define TA_PROP_STR_CACHE_SYNC		"op-tee.cache_sync"
82b0104773SPascal Brand 
83b0104773SPascal Brand enum user_ta_prop_type {
84b0104773SPascal Brand 	USER_TA_PROP_TYPE_BOOL,	/* bool */
85b0104773SPascal Brand 	USER_TA_PROP_TYPE_U32,	/* uint32_t */
86b0104773SPascal Brand 	USER_TA_PROP_TYPE_UUID,	/* TEE_UUID */
87b0104773SPascal Brand 	USER_TA_PROP_TYPE_IDENTITY,	/* TEE_Identity */
88b0104773SPascal Brand 	USER_TA_PROP_TYPE_STRING,	/* zero terminated string of char */
89b0104773SPascal Brand 	USER_TA_PROP_TYPE_BINARY_BLOCK,	/* zero terminated base64 coded string */
90b0104773SPascal Brand };
91b0104773SPascal Brand 
92b0104773SPascal Brand enum user_ta_core_service_id {
93b0104773SPascal Brand 	USER_TA_CORE_ENTRY_MATH_INIT = 0x00000010,
94b0104773SPascal Brand 	USER_TA_CORE_ENTRY_GARBAGE = 0x00000011,
95b0104773SPascal Brand 	USER_TA_CORE_ENTRY_CLOSESESSION = 0x00000012,
96b0104773SPascal Brand };
97b0104773SPascal Brand 
98b0104773SPascal Brand struct user_ta_property {
99b0104773SPascal Brand 	const char *name;
100b0104773SPascal Brand 	enum user_ta_prop_type type;
101b0104773SPascal Brand 	const void *value;
102b0104773SPascal Brand };
103b0104773SPascal Brand 
104b0104773SPascal Brand extern const struct user_ta_property ta_props[];
105b0104773SPascal Brand extern const size_t ta_num_props;
106b0104773SPascal Brand 
107b0104773SPascal Brand /* Needed by TEE_CheckMemoryAccessRights() */
108b0104773SPascal Brand extern uint32_t ta_param_types;
10968540524SIgor Opaniuk extern TEE_Param ta_params[TEE_NUM_PARAMS];
110b0104773SPascal Brand 
111b0104773SPascal Brand /* Trusted Application Function header */
112b0104773SPascal Brand typedef struct ta_func_head {
113b0104773SPascal Brand 	uint32_t cmd_id;	/* Trusted Application Function ID */
114b0104773SPascal Brand 	uint32_t start;		/* offset to start func */
115b0104773SPascal Brand } ta_func_head_t;
116b0104773SPascal Brand 
117b0104773SPascal Brand int tahead_get_trace_level(void);
118b0104773SPascal Brand 
119b0104773SPascal Brand #endif /* USER_TA_HEADER_H */
120