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 thread_svc_regs; 20 struct ts_session { 21 TAILQ_ENTRY(ts_session) link_tsd; 22 struct ts_ctx *ctx; /* Generic TS context */ 23 #if defined(CFG_TA_GPROF_SUPPORT) 24 struct sample_buf *sbuf; /* Profiling data (PC sampling) */ 25 #endif 26 #if defined(CFG_FTRACE_SUPPORT) 27 struct ftrace_buf *fbuf; /* ftrace buffer */ 28 #endif 29 /* 30 * Used by PTAs to store session specific information, or used by ldelf 31 * syscalls to store handlers of opened TA/SP binaries. 32 */ 33 void *user_ctx; 34 bool (*handle_svc)(struct thread_svc_regs *regs); 35 }; 36 37 enum ts_gprof_status { 38 TS_GPROF_SUSPEND, 39 TS_GPROF_RESUME, 40 }; 41 42 struct ts_ops { 43 TEE_Result (*enter_open_session)(struct ts_session *s); 44 TEE_Result (*enter_invoke_cmd)(struct ts_session *s, uint32_t cmd); 45 void (*enter_close_session)(struct ts_session *s); 46 #if defined(CFG_TA_STATS) 47 TEE_Result (*dump_mem_stats)(struct ts_session *s); 48 #endif 49 void (*dump_state)(struct ts_ctx *ctx); 50 void (*dump_ftrace)(struct ts_ctx *ctx); 51 void (*destroy)(struct ts_ctx *ctx); 52 uint32_t (*get_instance_id)(struct ts_ctx *ctx); 53 bool (*handle_svc)(struct thread_svc_regs *regs); 54 #ifdef CFG_TA_GPROF_SUPPORT 55 void (*gprof_set_status)(enum ts_gprof_status status); 56 #endif 57 }; 58 59 struct ts_session *ts_get_current_session(void); 60 struct ts_session *ts_get_current_session_may_fail(void); 61 62 void ts_push_current_session(struct ts_session *sess); 63 struct ts_session *ts_pop_current_session(void); 64 struct ts_session *ts_get_calling_session(void); 65 66 #endif /*__KERNEL_TS_MANAGER_H*/ 67