1 /* 2 * Copyright (c) 2014, STMicroelectronics International N.V. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are met: 7 * 8 * 1. Redistributions of source code must retain the above copyright notice, 9 * this list of conditions and the following disclaimer. 10 * 11 * 2. Redistributions in binary form must reproduce the above copyright notice, 12 * this list of conditions and the following disclaimer in the documentation 13 * and/or other materials provided with the distribution. 14 * 15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 19 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 21 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 24 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25 * POSSIBILITY OF SUCH DAMAGE. 26 */ 27 28 #ifndef TEE_TA_MANAGER_H 29 #define TEE_TA_MANAGER_H 30 31 #include <kernel/tee_common.h> 32 33 #include "tee_api_types.h" 34 #include "tee_api_types.h" 35 #include "tee_ta.h" 36 #include <kernel/kta_types.h> 37 #include "tee_ta_manager_unpg.h" 38 #include "tee_trace.h" 39 40 /*----------------------------------------------------------------------------- 41 * Initializes virtual memory management by reserving virtual memory for 42 * memory areas not available TA virtual memroy allocation. 43 * 44 * Spare physical pages are passed in the memory range between ta_start and 45 * ta_spare_end. Spare physical pages are supposed to be mapped with "no 46 * access" attribute. 47 * 48 * All addresses will be rounded up the the next page. 49 * 50 * Parameters: 51 * ro_start - start of read only section for paging, 52 * ro_end - end of read only section for paging, 53 * ta_start - start of section used for TA virtual memory 54 * ta_spare_end - end of spare pages used for paging 55 * 56 * Returns: 57 * void 58 *---------------------------------------------------------------------------*/ 59 void tee_ta_vmem_init(tee_vaddr_t ro_start, tee_vaddr_t ro_end, 60 tee_vaddr_t ta_start, tee_vaddr_t ta_spare_end); 61 62 TEE_Result tee_ta_open_session(TEE_ErrorOrigin *err, 63 struct tee_ta_session **sess, 64 struct tee_ta_session_head *open_sessions, 65 const TEE_UUID *uuid, 66 const kta_signed_header_t *ta, 67 const TEE_Identity *clnt_id, 68 uint32_t cancel_req_to, 69 struct tee_ta_param *param); 70 71 TEE_Result tee_ta_invoke_command(TEE_ErrorOrigin *err, 72 struct tee_ta_session *sess, 73 const TEE_Identity *clnt_id, 74 uint32_t cancel_req_to, uint32_t cmd, 75 struct tee_ta_param *param); 76 77 TEE_Result tee_ta_cancel_command(TEE_ErrorOrigin *err, 78 struct tee_ta_session *sess, 79 const TEE_Identity *clnt_id); 80 81 /* 82 * Load a TA via RPC with UUID defined by input param uuid. The virtual 83 * address of the TA is recieved in out parameter ta 84 * 85 * Function is not thread safe 86 */ 87 TEE_Result tee_ta_rpc_load(const TEE_UUID *uuid, kta_signed_header_t **ta, 88 struct tee_ta_nwumap *map, uint32_t *ret_orig); 89 90 /*----------------------------------------------------------------------------- 91 * Function called to close a TA. 92 * Parameters: 93 * id - The session id (in) 94 * Returns: 95 * TEE_Result 96 *---------------------------------------------------------------------------*/ 97 TEE_Result tee_ta_close_session(uint32_t id, 98 struct tee_ta_session_head *open_sessions); 99 100 TEE_Result tee_ta_get_current_session(struct tee_ta_session **sess); 101 102 void tee_ta_set_current_session(struct tee_ta_session *sess); 103 104 TEE_Result tee_ta_make_current_session_resident(void); 105 void tee_ta_unlock_current_session(void); 106 107 TEE_Result tee_ta_get_client_id(TEE_Identity *id); 108 109 /* 110 * Get pointer of executable part of the TA located in virtual kernel memory 111 */ 112 uintptr_t tee_ta_get_exec(const struct tee_ta_ctx *const ctx); 113 114 /* Returns OK is sess is a valid session pointer or static TA */ 115 TEE_Result tee_ta_verify_session_pointer(struct tee_ta_session *sess, 116 struct tee_ta_session_head 117 *open_sessions); 118 119 int tee_ta_set_trace_level(int level); 120 121 #endif 122