/* * Copyright (c) 2014, STMicroelectronics International N.V. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * 1. Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ #ifndef TEE_TA_MANAGER_H #define TEE_TA_MANAGER_H #include #include #include #include #include #include #include #include #include /* Magic TEE identity pointer: set when teecore requests a TA close */ #define KERN_IDENTITY ((TEE_Identity *)-1) /* Operation is initiated by a client (non-secure) app */ #define NSAPP_IDENTITY (NULL) TAILQ_HEAD(tee_ta_session_head, tee_ta_session); TAILQ_HEAD(tee_ta_ctx_head, tee_ta_ctx); struct tee_ta_param { uint32_t types; TEE_Param params[4]; uint32_t param_attr[4]; }; struct tee_ta_ctx; struct user_ta_ctx; struct static_ta_ctx; struct tee_ta_ops { TEE_Result (*enter_open_session)(struct tee_ta_session *s, struct tee_ta_param *param, TEE_ErrorOrigin *eo); TEE_Result (*enter_invoke_cmd)(struct tee_ta_session *s, uint32_t cmd, struct tee_ta_param *param, TEE_ErrorOrigin *eo); void (*enter_close_session)(struct tee_ta_session *s); void (*dump_state)(struct tee_ta_ctx *ctx); void (*destroy)(struct tee_ta_ctx *ctx); }; /* Context of a loaded TA */ struct tee_ta_ctx { TEE_UUID uuid; const struct tee_ta_ops *ops; uint32_t flags; /* TA_FLAGS from TA header */ TAILQ_ENTRY(tee_ta_ctx) link; uint32_t panicked; /* True if TA has panicked, written from asm */ uint32_t panic_code; /* Code supplied for panic */ uint32_t ref_count; /* Reference counter for multi session TA */ bool busy; /* context is busy and cannot be entered */ struct condvar busy_cv; /* CV used when context is busy */ }; struct tee_ta_session { TAILQ_ENTRY(tee_ta_session) link; struct tee_ta_ctx *ctx; /* TA context */ /* session of calling TA if != NULL */ struct tee_ta_session *calling_sess; TEE_Identity clnt_id; /* Identify of client */ bool cancel; /* True if TAF is cancelled */ bool cancel_mask; /* True if cancel is masked */ TEE_Time cancel_time; /* Time when to cancel the TAF */ void *user_ctx; /* ??? */ uint32_t ref_count; /* reference counter */ struct condvar refc_cv; /* CV used to wait for ref_count to be 0 */ struct condvar lock_cv; /* CV used to wait for lock */ int lock_thread; /* Id of thread holding the lock */ bool unlink; /* True if session is to be unlinked */ }; /* Registered contexts */ extern struct tee_ta_ctx_head tee_ctxes; TEE_Result tee_ta_open_session(TEE_ErrorOrigin *err, struct tee_ta_session **sess, struct tee_ta_session_head *open_sessions, const TEE_UUID *uuid, const TEE_Identity *clnt_id, uint32_t cancel_req_to, struct tee_ta_param *param); TEE_Result tee_ta_invoke_command(TEE_ErrorOrigin *err, struct tee_ta_session *sess, const TEE_Identity *clnt_id, uint32_t cancel_req_to, uint32_t cmd, struct tee_ta_param *param); TEE_Result tee_ta_cancel_command(TEE_ErrorOrigin *err, struct tee_ta_session *sess, const TEE_Identity *clnt_id); /*----------------------------------------------------------------------------- * Function called to close a TA. * Parameters: * id - The session id (in) * Returns: * TEE_Result *---------------------------------------------------------------------------*/ TEE_Result tee_ta_close_session(struct tee_ta_session *sess, struct tee_ta_session_head *open_sessions, const TEE_Identity *clnt_id); TEE_Result tee_ta_get_current_session(struct tee_ta_session **sess); void tee_ta_set_current_session(struct tee_ta_session *sess); TEE_Result tee_ta_get_client_id(TEE_Identity *id); struct tee_ta_session *tee_ta_get_session(uint32_t id, bool exclusive, struct tee_ta_session_head *open_sessions); void tee_ta_put_session(struct tee_ta_session *sess); void tee_ta_dump_current(void); #endif