xref: /optee_os/core/include/kernel/tee_ta_manager.h (revision 03c42787bbb0d574300fdc79ef82316837aef3a3)
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 TEE_Identity *clnt_id,
67 			       uint32_t cancel_req_to,
68 			       struct tee_ta_param *param);
69 
70 TEE_Result tee_ta_invoke_command(TEE_ErrorOrigin *err,
71 				 struct tee_ta_session *sess,
72 				 uint32_t cancel_req_to, uint32_t cmd,
73 				 struct tee_ta_param *param);
74 
75 TEE_Result tee_ta_cancel_command(TEE_ErrorOrigin *err,
76 				 struct tee_ta_session *sess);
77 
78 /*-----------------------------------------------------------------------------
79  * Function called to close a TA.
80  * Parameters:
81  * id   - The session id (in)
82  * Returns:
83  *        TEE_Result
84  *---------------------------------------------------------------------------*/
85 TEE_Result tee_ta_close_session(uint32_t id,
86 				struct tee_ta_session_head *open_sessions);
87 
88 TEE_Result tee_ta_get_current_session(struct tee_ta_session **sess);
89 
90 void tee_ta_set_current_session(struct tee_ta_session *sess);
91 
92 TEE_Result tee_ta_get_client_id(TEE_Identity *id);
93 
94 /*
95  * Get pointer of executable part of the TA located in virtual kernel memory
96  */
97 uintptr_t tee_ta_get_exec(const struct tee_ta_ctx *const ctx);
98 
99 /* Returns OK is sess is a valid session pointer or static TA */
100 TEE_Result tee_ta_verify_session_pointer(struct tee_ta_session *sess,
101 					 struct tee_ta_session_head
102 					 *open_sessions);
103 
104 int tee_ta_set_trace_level(int level);
105 
106 #endif
107