xref: /optee_os/core/include/kernel/ts_manager.h (revision 36bb435f5be571b4b4c0792de1cea85013afa728)
1 /* SPDX-License-Identifier: BSD-2-Clause */
2 /*
3  * Copyright (c) 2014, STMicroelectronics International N.V.
4  * Copyright (c) 2017-2020, Linaro Limited
5  * Copyright (c) 2020, Arm Limited
6  */
7 
8 #ifndef __KERNEL_TS_MANAGER_H
9 #define __KERNEL_TS_MANAGER_H
10 
11 #include <sys/queue.h>
12 #include <tee_api_types.h>
13 
14 struct ts_ctx {
15 	TEE_UUID uuid;
16 	const struct ts_ops *ops;
17 };
18 
19 struct ts_session {
20 	TAILQ_ENTRY(ts_session) link_tsd;
21 	struct ts_ctx *ctx;	/* Generic TS context */
22 #if defined(CFG_TA_GPROF_SUPPORT)
23 	struct sample_buf *sbuf; /* Profiling data (PC sampling) */
24 #endif
25 #if defined(CFG_FTRACE_SUPPORT)
26 	struct ftrace_buf *fbuf; /* ftrace buffer */
27 #endif
28 	/*
29 	 * Used by PTAs to store session specific information, or used by ldelf
30 	 * syscalls to store handlers of opened TA/SP binaries.
31 	 */
32 	void *user_ctx;
33 };
34 
35 enum ts_gprof_status {
36 	TS_GPROF_SUSPEND,
37 	TS_GPROF_RESUME,
38 };
39 
40 struct thread_svc_regs;
41 struct ts_ops {
42 	TEE_Result (*enter_open_session)(struct ts_session *s);
43 	TEE_Result (*enter_invoke_cmd)(struct ts_session *s, uint32_t cmd);
44 	void (*enter_close_session)(struct ts_session *s);
45 	void (*dump_state)(struct ts_ctx *ctx);
46 	void (*dump_ftrace)(struct ts_ctx *ctx);
47 	void (*destroy)(struct ts_ctx *ctx);
48 	uint32_t (*get_instance_id)(struct ts_ctx *ctx);
49 	bool (*handle_svc)(struct thread_svc_regs *regs);
50 #ifdef CFG_TA_GPROF_SUPPORT
51 	void (*gprof_set_status)(enum ts_gprof_status status);
52 #endif
53 };
54 
55 struct ts_session *ts_get_current_session(void);
56 struct ts_session *ts_get_current_session_may_fail(void);
57 
58 void ts_push_current_session(struct ts_session *sess);
59 struct ts_session *ts_pop_current_session(void);
60 struct ts_session *ts_get_calling_session(void);
61 
62 #endif /*__KERNEL_TS_MANAGER_H*/
63