xref: /optee_os/lib/libutee/include/user_ta_header.h (revision e86f1266afb6871795921b1eeb2bcbe5b1928cb5)
1b0104773SPascal Brand /*
2b0104773SPascal Brand  * Copyright (c) 2014, STMicroelectronics International N.V.
3b0104773SPascal Brand  * All rights reserved.
4b0104773SPascal Brand  *
5b0104773SPascal Brand  * Redistribution and use in source and binary forms, with or without
6b0104773SPascal Brand  * modification, are permitted provided that the following conditions are met:
7b0104773SPascal Brand  *
8b0104773SPascal Brand  * 1. Redistributions of source code must retain the above copyright notice,
9b0104773SPascal Brand  * this list of conditions and the following disclaimer.
10b0104773SPascal Brand  *
11b0104773SPascal Brand  * 2. Redistributions in binary form must reproduce the above copyright notice,
12b0104773SPascal Brand  * this list of conditions and the following disclaimer in the documentation
13b0104773SPascal Brand  * and/or other materials provided with the distribution.
14b0104773SPascal Brand  *
15b0104773SPascal Brand  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16b0104773SPascal Brand  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17b0104773SPascal Brand  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18b0104773SPascal Brand  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
19b0104773SPascal Brand  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20b0104773SPascal Brand  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21b0104773SPascal Brand  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22b0104773SPascal Brand  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23b0104773SPascal Brand  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24b0104773SPascal Brand  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25b0104773SPascal Brand  * POSSIBILITY OF SUCH DAMAGE.
26b0104773SPascal Brand  */
27b0104773SPascal Brand 
28b0104773SPascal Brand #ifndef USER_TA_HEADER_H
29b0104773SPascal Brand #define USER_TA_HEADER_H
30b0104773SPascal Brand 
31b0104773SPascal Brand #include <tee_api_types.h>
32b0104773SPascal Brand 
33b0104773SPascal Brand 
34b0104773SPascal Brand #define TA_FLAG_USER_MODE		(1 << 0)
35b0104773SPascal Brand #define TA_FLAG_EXEC_DDR		(1 << 1)
36b0104773SPascal Brand #define TA_FLAG_SINGLE_INSTANCE		(1 << 2)
37b0104773SPascal Brand #define TA_FLAG_MULTI_SESSION		(1 << 3)
3855d3ebe9SPascal Brand #define TA_FLAG_INSTANCE_KEEP_ALIVE	(1 << 4) /* remains after last close */
39b0104773SPascal Brand /*
4055d3ebe9SPascal Brand  * TA_FLAG_UNSAFE_NW_PARAMS: May manipulate some secure memory based on
4155d3ebe9SPascal Brand  * physical pointers from non-secure world
42b0104773SPascal Brand  */
43b0104773SPascal Brand #define TA_FLAG_UNSAFE_NW_PARAMS	(1 << 5)
4455d3ebe9SPascal Brand #define TA_FLAG_REMAP_SUPPORT		(1 << 6) /* use map/unmap syscalls */
4555d3ebe9SPascal Brand #define TA_FLAG_CACHE_MAINTENANCE	(1 << 7) /* use cache flush syscall */
4655d3ebe9SPascal Brand 
47*e86f1266SJens Wiklander union ta_head_func_ptr {
48*e86f1266SJens Wiklander 	uint64_t ptr64;
49*e86f1266SJens Wiklander 	struct ta_head_func_ptr32 {
50*e86f1266SJens Wiklander 		uint32_t lo;
51*e86f1266SJens Wiklander 		uint32_t hi;
52*e86f1266SJens Wiklander 	} ptr32;
53*e86f1266SJens Wiklander };
54*e86f1266SJens Wiklander 
55bc420748SJens Wiklander struct ta_head {
56bc420748SJens Wiklander 	TEE_UUID uuid;
57bc420748SJens Wiklander 	uint32_t stack_size;
58bc420748SJens Wiklander 	uint32_t flags;
59*e86f1266SJens Wiklander 	union ta_head_func_ptr open_session;
60*e86f1266SJens Wiklander 	union ta_head_func_ptr close_session;
61*e86f1266SJens Wiklander 	union ta_head_func_ptr invoke_command;
62bc420748SJens Wiklander };
63bc420748SJens Wiklander 
6455d3ebe9SPascal Brand #define TA_PROP_STR_SINGLE_INSTANCE	"gpd.ta.singleInstance"
6555d3ebe9SPascal Brand #define TA_PROP_STR_MULTI_SESSION	"gpd.ta.multiSession"
6655d3ebe9SPascal Brand #define TA_PROP_STR_KEEP_ALIVE		"gpd.ta.instanceKeepAlive"
6755d3ebe9SPascal Brand #define TA_PROP_STR_DATA_SIZE		"gpd.ta.dataSize"
6855d3ebe9SPascal Brand #define TA_PROP_STR_STACK_SIZE		"gpd.ta.stackSize"
69d71d2857SCedric Chaumont #define TA_PROP_STR_VERSION		"gpd.ta.version"
70d71d2857SCedric Chaumont #define TA_PROP_STR_DESCRIPTION		"gpd.ta.description"
7155d3ebe9SPascal Brand #define TA_PROP_STR_UNSAFE_PARAM	"op-tee.unsafe_param"
7255d3ebe9SPascal Brand #define TA_PROP_STR_REMAP		"op-tee.remap"
7355d3ebe9SPascal Brand #define TA_PROP_STR_CACHE_SYNC		"op-tee.cache_sync"
74b0104773SPascal Brand 
75b0104773SPascal Brand enum user_ta_prop_type {
76b0104773SPascal Brand 	USER_TA_PROP_TYPE_BOOL,	/* bool */
77b0104773SPascal Brand 	USER_TA_PROP_TYPE_U32,	/* uint32_t */
78b0104773SPascal Brand 	USER_TA_PROP_TYPE_UUID,	/* TEE_UUID */
79b0104773SPascal Brand 	USER_TA_PROP_TYPE_IDENTITY,	/* TEE_Identity */
80b0104773SPascal Brand 	USER_TA_PROP_TYPE_STRING,	/* zero terminated string of char */
81b0104773SPascal Brand 	USER_TA_PROP_TYPE_BINARY_BLOCK,	/* zero terminated base64 coded string */
82b0104773SPascal Brand };
83b0104773SPascal Brand 
84b0104773SPascal Brand enum user_ta_core_service_id {
85b0104773SPascal Brand 	USER_TA_CORE_ENTRY_MATH_INIT = 0x00000010,
86b0104773SPascal Brand 	USER_TA_CORE_ENTRY_GARBAGE = 0x00000011,
87b0104773SPascal Brand 	USER_TA_CORE_ENTRY_CLOSESESSION = 0x00000012,
88b0104773SPascal Brand };
89b0104773SPascal Brand 
90b0104773SPascal Brand struct user_ta_property {
91b0104773SPascal Brand 	const char *name;
92b0104773SPascal Brand 	enum user_ta_prop_type type;
93b0104773SPascal Brand 	const void *value;
94b0104773SPascal Brand };
95b0104773SPascal Brand 
96b0104773SPascal Brand extern const struct user_ta_property ta_props[];
97b0104773SPascal Brand extern const size_t ta_num_props;
98b0104773SPascal Brand 
99b0104773SPascal Brand /* Needed by TEE_CheckMemoryAccessRights() */
100b0104773SPascal Brand extern uint32_t ta_param_types;
101b0104773SPascal Brand extern TEE_Param ta_params[4];
102b0104773SPascal Brand 
103b0104773SPascal Brand /* Trusted Application Function header */
104b0104773SPascal Brand typedef struct ta_func_head {
105b0104773SPascal Brand 	uint32_t cmd_id;	/* Trusted Application Function ID */
106b0104773SPascal Brand 	uint32_t start;		/* offset to start func */
107b0104773SPascal Brand } ta_func_head_t;
108b0104773SPascal Brand 
109b0104773SPascal Brand typedef struct {
110b0104773SPascal Brand 	/* Same Prefix as ta_head_t */
111b0104773SPascal Brand 	TEE_UUID uuid;
112b0104773SPascal Brand 	const char *name;
113b0104773SPascal Brand 	uint32_t flags;
114b0104773SPascal Brand 
115b0104773SPascal Brand 	/* properties */
116b0104773SPascal Brand 	uint32_t prop_datasize;
117b0104773SPascal Brand 	uint32_t prop_stacksize;
118b0104773SPascal Brand 	uint32_t prop_tracelevel;
119b0104773SPascal Brand 
120b0104773SPascal Brand 	const ta_func_head_t *funcs;
121b0104773SPascal Brand 	uint32_t nbr_func;
122b0104773SPascal Brand 	 TEE_Result(*create_entry_point) (void);
123b0104773SPascal Brand 	void (*destroy_entry_point) (void);
124b0104773SPascal Brand 	 TEE_Result(*open_session_entry_point) (uint32_t nParamTypes,
125b0104773SPascal Brand 					     TEE_Param pParams[4],
126b0104773SPascal Brand 					     void **ppSessionContext);
127b0104773SPascal Brand 	void (*close_session_entry_point) (void *pSessionContext);
128b0104773SPascal Brand 	 TEE_Result(*invoke_command_entry_point) (void *pSessionContext,
129b0104773SPascal Brand 					       uint32_t nCommandID,
130b0104773SPascal Brand 					       uint32_t nParamTypes,
131b0104773SPascal Brand 					       TEE_Param pParams[4]);
132b0104773SPascal Brand 	 TEE_Result(*core_entries) (uint32_t nServiceId, uint32_t nParamTypes,
133b0104773SPascal Brand 				   TEE_Param pParam[4]);
134b0104773SPascal Brand } ta_static_head_t;
135b0104773SPascal Brand 
136b0104773SPascal Brand int tahead_get_trace_level(void);
137b0104773SPascal Brand 
138b0104773SPascal Brand #endif /* USER_TA_HEADER_H */
139