1 /* SPDX-License-Identifier: BSD-2-Clause */
2 /*
3  * Copyright (c) 2015, Linaro Limited
4  * Copyright (c) 2020, Arm Limited
5  */
6 #ifndef KERNEL_USER_TA_H
7 #define KERNEL_USER_TA_H
8 
9 #include <assert.h>
10 #include <kernel/tee_ta_manager.h>
11 #include <kernel/user_mode_ctx_struct.h>
12 #include <kernel/thread.h>
13 #include <mm/file.h>
14 #include <mm/tee_mm.h>
15 #include <scattered_array.h>
16 #include <tee_api_types.h>
17 #include <types_ext.h>
18 #include <util.h>
19 
20 TAILQ_HEAD(tee_cryp_state_head, tee_cryp_state);
21 TAILQ_HEAD(tee_obj_head, tee_obj);
22 TAILQ_HEAD(tee_storage_enum_head, tee_storage_enum);
23 SLIST_HEAD(load_seg_head, load_seg);
24 
25 /*
26  * struct user_ta_ctx - user TA context
27  * @open_sessions:	List of sessions opened by this TA
28  * @cryp_states:	List of cryp states created by this TA
29  * @objects:		List of storage objects opened by this TA
30  * @storage_enums:	List of storage enumerators opened by this TA
31  * @ta_time_offs:	Time reference used by the TA
32  * @uctx:		Generic user mode context
33  * @ctx:		Generic TA context
34  */
35 struct user_ta_ctx {
36 	struct tee_ta_session_head open_sessions;
37 	struct tee_cryp_state_head cryp_states;
38 	struct tee_obj_head objects;
39 	struct tee_storage_enum_head storage_enums;
40 	void *ta_time_offs;
41 	struct user_mode_ctx uctx;
42 	struct tee_ta_ctx ta_ctx;
43 };
44 
45 #ifdef CFG_WITH_USER_TA
46 bool is_user_ta_ctx(struct ts_ctx *ctx);
47 #else
is_user_ta_ctx(struct ts_ctx * ctx __unused)48 static inline bool is_user_ta_ctx(struct ts_ctx *ctx __unused)
49 {
50 	return false;
51 }
52 #endif
53 
to_user_ta_ctx(struct ts_ctx * ctx)54 static inline struct user_ta_ctx *to_user_ta_ctx(struct ts_ctx *ctx)
55 {
56 	assert(is_user_ta_ctx(ctx));
57 	return container_of(ctx, struct user_ta_ctx, ta_ctx.ts_ctx);
58 }
59 
60 #ifdef CFG_WITH_USER_TA
61 TEE_Result tee_ta_init_user_ta_session(const TEE_UUID *uuid,
62 			struct tee_ta_session *s);
63 #else
tee_ta_init_user_ta_session(const TEE_UUID * uuid __unused,struct tee_ta_session * s __unused)64 static inline TEE_Result tee_ta_init_user_ta_session(
65 			const TEE_UUID *uuid __unused,
66 			struct tee_ta_session *s __unused)
67 {
68 	return TEE_ERROR_ITEM_NOT_FOUND;
69 }
70 #endif
71 
72 
73 #endif /*KERNEL_USER_TA_H*/
74