mTower
tee_ta_manager.h
1 /* SPDX-License-Identifier: BSD-2-Clause */
2 /*
3  * Copyright (c) 2014, STMicroelectronics International N.V.
4  * Copyright (c) 2017, Linaro Limited
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions are met:
9  *
10  * 1. Redistributions of source code must retain the above copyright notice,
11  * this list of conditions and the following disclaimer.
12  *
13  * 2. Redistributions in binary form must reproduce the above copyright notice,
14  * this list of conditions and the following disclaimer in the documentation
15  * and/or other materials provided with the distribution.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
21  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27  * POSSIBILITY OF SUCH DAMAGE.
28  */
29 
30 #ifndef TEE_TA_MANAGER_H
31 #define TEE_TA_MANAGER_H
32 
33 //#include <types_ext.h>
34 #include "queue.h"
35 #include <tee_api_types.h>
36 //#include <utee_types.h>
37 //#include <kernel/tee_common.h>
38 //#include <kernel/mutex.h>
39 //#include <tee_api_types.h>
40 //#include <user_ta_header.h>
41 
42 
43 /* Magic TEE identity pointer: set when teecore requests a TA close */
44 //#define KERN_IDENTITY ((TEE_Identity *)-1)
46 //#define NSAPP_IDENTITY (NULL)
47 
48 TAILQ_HEAD(tee_ta_session_head, tee_ta_session);
49 TAILQ_HEAD(tee_ta_ctx_head, tee_ta_ctx);
50 
51 struct mobj;
52 
53 struct param_val {
54  uint32_t a;
55  uint32_t b;
56 };
57 
58 struct param_mem {
59  struct mobj *mobj;
60  size_t size;
61  size_t offs;
62 };
63 
64 struct tee_ta_param {
65  uint32_t types;
66  union {
67  struct param_val val;
68  struct param_mem mem;
69  } u[TEE_NUM_PARAMS];
70 };
71 
72 struct tee_ta_ctx;
73 struct user_ta_ctx;
74 struct pseudo_ta_ctx;
75 
76 struct tee_ta_ops {
77  TEE_Result (*enter_open_session)(struct tee_ta_session *s,
78  struct tee_ta_param *param, TEE_ErrorOrigin *eo);
79 // TEE_Result (*enter_invoke_cmd)(struct tee_ta_session *s, uint32_t cmd,
80 // uint32_t param_types, TEE_Param params[4]);
81 
82  TEE_Result (*enter_invoke_cmd)(struct tee_ta_session *s, uint32_t cmd,
83  struct tee_ta_param *param, TEE_ErrorOrigin *eo);
84  void (*enter_close_session)(struct tee_ta_session *s);
85  void (*dump_state)(struct tee_ta_ctx *ctx);
86  void (*destroy)(struct tee_ta_ctx *ctx);
87  uint32_t (*get_instance_id)(struct tee_ta_ctx *ctx);
88 };
89 
90 //#if defined(CFG_TA_GPROF_SUPPORT)
91 //struct sample_buf {
92 // uint32_t nsamples; /* Size of @samples array in uint16_t */
93 // uint32_t offset; /* Passed from user mode */
94 // uint32_t scale; /* Passed from user mode */
95 // uint32_t count; /* Number of samples taken */
96 // bool enabled; /* Sampling enabled? */
97 // uint16_t *samples;
98 // uint64_t usr; /* Total user CPU time for this session */
99 // uint64_t usr_entered; /* When this session last entered user mode */
100 // uint32_t freq; /* @usr divided by @freq is in seconds */
101 //};
102 //#endif
103 
104 /* Context of a loaded TA */
105 struct tee_ta_ctx {
106  TEE_UUID uuid;
107  const struct tee_ta_ops *ops;
108  uint32_t flags; /* TA_FLAGS from TA header */
109  TAILQ_ENTRY(tee_ta_ctx) link;
110 // uint32_t panicked; /* True if TA has panicked, written from asm */
111 // uint32_t panic_code; /* Code supplied for panic */
112 // uint32_t ref_count; /* Reference counter for multi session TA */
113 // bool busy; /* context is busy and cannot be entered */
114 // struct condvar busy_cv; /* CV used when context is busy */
115 };
116 
118  TAILQ_ENTRY(tee_ta_session) link;
119  TAILQ_ENTRY(tee_ta_session) link_tsd;
120  struct tee_ta_ctx *ctx; /* TA context */
121 // TEE_Identity clnt_id; /* Identify of client */
122 // bool cancel; /* True if TAF is cancelled */
123 // bool cancel_mask; /* True if cancel is masked */
124 // TEE_Time cancel_time; /* Time when to cancel the TAF */
125  void *user_ctx; /* ??? */
126 // uint32_t ref_count; /* reference counter */
127 // struct condvar refc_cv; /* CV used to wait for ref_count to be 0 */
128 // struct condvar lock_cv; /* CV used to wait for lock */
129 // int lock_thread; /* Id of thread holding the lock */
130 // bool unlink; /* True if session is to be unlinked */
131 //#if defined(CFG_TA_GPROF_SUPPORT)
132 // struct sample_buf *sbuf; /* Profiling data (PC sampling) */
133 //#endif
134 };
135 
136 /* Registered contexts */
137 extern struct tee_ta_ctx_head tee_ctxes;
138 
139 //extern struct mutex tee_ta_mutex;
140 
141 //TEE_Result tee_ta_open_session(TEE_ErrorOrigin *err,
142 // struct tee_ta_session **sess,
143 // struct tee_ta_session_head *open_sessions,
144 // const TEE_UUID *uuid,
145 // const TEE_Identity *clnt_id,
146 // uint32_t cancel_req_to,
147 // struct tee_ta_param *param);
148 //
149 //TEE_Result tee_ta_invoke_command(TEE_ErrorOrigin *err,
150 // struct tee_ta_session *sess,
151 // const TEE_Identity *clnt_id,
152 // uint32_t cancel_req_to, uint32_t cmd,
153 // struct tee_ta_param *param);
154 //
155 //TEE_Result tee_ta_cancel_command(TEE_ErrorOrigin *err,
156 // struct tee_ta_session *sess,
157 // const TEE_Identity *clnt_id);
158 //
159 //bool tee_ta_session_is_cancelled(struct tee_ta_session *s, TEE_Time *curr_time);
160 
161 /*-----------------------------------------------------------------------------
162  * Function called to close a TA.
163  * Parameters:
164  * id - The session id (in)
165  * Returns:
166  * TEE_Result
167  *---------------------------------------------------------------------------*/
168 //TEE_Result tee_ta_close_session(struct tee_ta_session *sess,
169 // struct tee_ta_session_head *open_sessions,
170 // const TEE_Identity *clnt_id);
171 //
172 //TEE_Result tee_ta_get_current_session(struct tee_ta_session **sess);
173 //
174 //void tee_ta_push_current_session(struct tee_ta_session *sess);
175 //struct tee_ta_session *tee_ta_pop_current_session(void);
176 //
177 //struct tee_ta_session *tee_ta_get_calling_session(void);
178 //
179 //TEE_Result tee_ta_get_client_id(TEE_Identity *id);
180 //
181 //struct tee_ta_session *tee_ta_get_session(uint32_t id, bool exclusive,
182 // struct tee_ta_session_head *open_sessions);
183 
184 //void tee_ta_put_session(struct tee_ta_session *sess);
185 //
186 //void tee_ta_dump_current(void);
187 
188 //#if defined(CFG_TA_GPROF_SUPPORT)
189 //void tee_ta_gprof_sample_pc(vaddr_t pc);
190 //void tee_ta_update_session_utime_suspend(void);
191 //void tee_ta_update_session_utime_resume(void);
192 //#else
193 //static inline void tee_ta_gprof_sample_pc(vaddr_t pc __unused) {}
194 //static inline void tee_ta_update_session_utime_suspend(void) {}
195 //static inline void tee_ta_update_session_utime_resume(void) {}
196 //#endif
197 
198 #endif
Definition: tee_ta_manager.h:53
Definition: tee_ta_manager.h:64
Definition: tee_ta_manager.h:76
Definition: pseudo_ta.h:45
Definition: tee_ta_manager.h:117
Definition: tee_api_types.h:45
Definition: tee_ta_manager.h:58
Definition: tee_ta_manager.h:105