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 "utee_types.h" 39 40 /* Magic TEE identity pointer: set when teecore requests a TA close */ 41 #define KERN_IDENTITY ((TEE_Identity *)-1) 42 /* Operation is initiated by a client (non-secure) app */ 43 #define NSAPP_IDENTITY (NULL) 44 45 /*----------------------------------------------------------------------------- 46 * Initializes virtual memory management by reserving virtual memory for 47 * memory areas not available TA virtual memroy allocation. 48 * 49 * Spare physical pages are passed in the memory range between ta_start and 50 * ta_spare_end. Spare physical pages are supposed to be mapped with "no 51 * access" attribute. 52 * 53 * All addresses will be rounded up the the next page. 54 * 55 * Parameters: 56 * ro_start - start of read only section for paging, 57 * ro_end - end of read only section for paging, 58 * ta_start - start of section used for TA virtual memory 59 * ta_spare_end - end of spare pages used for paging 60 * 61 * Returns: 62 * void 63 *---------------------------------------------------------------------------*/ 64 void tee_ta_vmem_init(tee_vaddr_t ro_start, tee_vaddr_t ro_end, 65 tee_vaddr_t ta_start, tee_vaddr_t ta_spare_end); 66 67 TEE_Result tee_ta_open_session(TEE_ErrorOrigin *err, 68 struct tee_ta_session **sess, 69 struct tee_ta_session_head *open_sessions, 70 const TEE_UUID *uuid, 71 const TEE_Identity *clnt_id, 72 uint32_t cancel_req_to, 73 struct tee_ta_param *param); 74 75 TEE_Result tee_ta_invoke_command(TEE_ErrorOrigin *err, 76 struct tee_ta_session *sess, 77 const TEE_Identity *clnt_id, 78 uint32_t cancel_req_to, uint32_t cmd, 79 struct tee_ta_param *param); 80 81 TEE_Result tee_ta_cancel_command(TEE_ErrorOrigin *err, 82 struct tee_ta_session *sess, 83 const TEE_Identity *clnt_id); 84 85 /*----------------------------------------------------------------------------- 86 * Function called to close a TA. 87 * Parameters: 88 * id - The session id (in) 89 * Returns: 90 * TEE_Result 91 *---------------------------------------------------------------------------*/ 92 TEE_Result tee_ta_close_session(uint32_t id, 93 struct tee_ta_session_head *open_sessions, 94 const TEE_Identity *clnt_id); 95 96 TEE_Result tee_ta_get_current_session(struct tee_ta_session **sess); 97 98 void tee_ta_set_current_session(struct tee_ta_session *sess); 99 100 TEE_Result tee_ta_get_client_id(TEE_Identity *id); 101 102 /* 103 * Get pointer of executable part of the TA located in virtual kernel memory 104 */ 105 uintptr_t tee_ta_get_exec(const struct tee_ta_ctx *const ctx); 106 107 /* Returns OK is sess is a valid session pointer or static TA */ 108 TEE_Result tee_ta_verify_session_pointer(struct tee_ta_session *sess, 109 struct tee_ta_session_head 110 *open_sessions); 111 112 int tee_ta_set_trace_level(int level); 113 void tee_ta_dump_current(void); 114 void tee_ta_dump_all(void); 115 116 #ifdef CFG_CACHE_API 117 TEE_Result tee_uta_cache_operation(struct tee_ta_session *s, 118 enum utee_cache_operation op, 119 void *va, size_t len); 120 #endif 121 122 #endif 123