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 * @uctx: Generic user mode context 32 * @ctx: Generic TA context 33 */ 34 struct user_ta_ctx { 35 struct tee_ta_session_head open_sessions; 36 struct tee_cryp_state_head cryp_states; 37 struct tee_obj_head objects; 38 struct tee_storage_enum_head storage_enums; 39 struct user_mode_ctx uctx; 40 struct tee_ta_ctx ta_ctx; 41 }; 42 43 #ifdef CFG_WITH_USER_TA 44 bool is_user_ta_ctx(struct ts_ctx *ctx); 45 #else 46 static inline bool __noprof is_user_ta_ctx(struct ts_ctx *ctx __unused) 47 { 48 return false; 49 } 50 #endif 51 52 static inline struct user_ta_ctx *to_user_ta_ctx(struct ts_ctx *ctx) 53 { 54 assert(is_user_ta_ctx(ctx)); 55 return container_of(ctx, struct user_ta_ctx, ta_ctx.ts_ctx); 56 } 57 58 #ifdef CFG_WITH_USER_TA 59 /* 60 * Setup session context for a user TA 61 * @uuid: TA UUID 62 * @s: Session for which to setup a user TA context 63 * 64 * This function must be called with tee_ta_mutex locked. 65 */ 66 TEE_Result tee_ta_init_user_ta_session(const TEE_UUID *uuid, 67 struct tee_ta_session *s); 68 69 /* 70 * Finalize session context initialization for a user TA 71 * @sess: Session for which to finalize user TA context 72 */ 73 TEE_Result tee_ta_complete_user_ta_session(struct tee_ta_session *s); 74 #else 75 static inline TEE_Result 76 tee_ta_init_user_ta_session(const TEE_UUID *uuid __unused, 77 struct tee_ta_session *s __unused) 78 { 79 return TEE_ERROR_ITEM_NOT_FOUND; 80 } 81 82 static inline TEE_Result 83 tee_ta_complete_user_ta_session(struct tee_ta_session *s __unused) 84 { 85 return TEE_ERROR_GENERIC; 86 } 87 #endif /*CFG_WITH_USER_TA*/ 88 #endif /*__KERNEL_USER_TA_H*/ 89