1 /* SPDX-License-Identifier: BSD-2-Clause */
2 /*
3 * Copyright (c) 2015, Linaro Limited
4 */
5 #ifndef KERNEL_PSEUDO_TA_H
6 #define KERNEL_PSEUDO_TA_H
7
8 #include <assert.h>
9 #include <compiler.h>
10 #include <kernel/tee_ta_manager.h>
11 #include <scattered_array.h>
12 #include <tee_api_types.h>
13 #include <user_ta_header.h>
14 #include <util.h>
15
16 #define PTA_MANDATORY_FLAGS (TA_FLAG_SINGLE_INSTANCE | \
17 TA_FLAG_MULTI_SESSION | \
18 TA_FLAG_INSTANCE_KEEP_ALIVE)
19
20 #define PTA_ALLOWED_FLAGS (PTA_MANDATORY_FLAGS | \
21 TA_FLAG_SECURE_DATA_PATH | \
22 TA_FLAG_CONCURRENT | \
23 TA_FLAG_DEVICE_ENUM)
24
25 #define PTA_DEFAULT_FLAGS PTA_MANDATORY_FLAGS
26
27 struct pseudo_ta_head {
28 TEE_UUID uuid;
29 const char *name;
30 uint32_t flags;
31
32 TEE_Result (*create_entry_point)(void);
33 void (*destroy_entry_point)(void);
34 TEE_Result (*open_session_entry_point)(uint32_t nParamTypes,
35 TEE_Param pParams[TEE_NUM_PARAMS],
36 void **ppSessionContext);
37 void (*close_session_entry_point)(void *pSessionContext);
38 TEE_Result (*invoke_command_entry_point)(void *pSessionContext,
39 uint32_t nCommandID, uint32_t nParamTypes,
40 TEE_Param pParams[TEE_NUM_PARAMS]);
41 };
42
43 #define pseudo_ta_register(...) \
44 SCATTERED_ARRAY_DEFINE_PG_ITEM(pseudo_tas, struct pseudo_ta_head) = \
45 { __VA_ARGS__ }
46
47 struct pseudo_ta_ctx {
48 const struct pseudo_ta_head *pseudo_ta;
49 struct tee_ta_ctx ctx;
50 };
51
52 bool is_pseudo_ta_ctx(struct ts_ctx *ctx);
53
to_pseudo_ta_ctx(struct ts_ctx * ctx)54 static inline struct pseudo_ta_ctx *to_pseudo_ta_ctx(struct ts_ctx *ctx)
55 {
56 assert(is_pseudo_ta_ctx(ctx));
57 return container_of(ctx, struct pseudo_ta_ctx, ctx.ts_ctx);
58 }
59
60 TEE_Result tee_ta_init_pseudo_ta_session(const TEE_UUID *uuid,
61 struct tee_ta_session *s);
62
63 #endif /* KERNEL_PSEUDO_TA_H */
64
65