xref: /optee_os/core/include/kernel/tee_ta_manager.h (revision d1d226a5264ce5654695edc656ef759fc48f675f)
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 
39 /*-----------------------------------------------------------------------------
40  * Initializes virtual memory management by reserving virtual memory for
41  * memory areas not available TA virtual memroy allocation.
42  *
43  * Spare physical pages are passed in the memory range between ta_start and
44  * ta_spare_end.  Spare physical pages are supposed to be mapped with "no
45  * access" attribute.
46  *
47  * All addresses will be rounded up the the next page.
48  *
49  * Parameters:
50  * ro_start - start of read only section for paging,
51  * ro_end   - end of read only section for paging,
52  * ta_start - start of section used for TA virtual memory
53  * ta_spare_end - end of spare pages used for paging
54  *
55  * Returns:
56  *        void
57  *---------------------------------------------------------------------------*/
58 void tee_ta_vmem_init(tee_vaddr_t ro_start, tee_vaddr_t ro_end,
59 		      tee_vaddr_t ta_start, tee_vaddr_t ta_spare_end);
60 
61 TEE_Result tee_ta_open_session(TEE_ErrorOrigin *err,
62 			       struct tee_ta_session **sess,
63 			       struct tee_ta_session_head *open_sessions,
64 			       const TEE_UUID *uuid,
65 			       const TEE_Identity *clnt_id,
66 			       uint32_t cancel_req_to,
67 			       struct tee_ta_param *param);
68 
69 TEE_Result tee_ta_invoke_command(TEE_ErrorOrigin *err,
70 				 struct tee_ta_session *sess,
71 				 uint32_t cancel_req_to, uint32_t cmd,
72 				 struct tee_ta_param *param);
73 
74 TEE_Result tee_ta_cancel_command(TEE_ErrorOrigin *err,
75 				 struct tee_ta_session *sess);
76 
77 /*-----------------------------------------------------------------------------
78  * Function called to close a TA.
79  * Parameters:
80  * id   - The session id (in)
81  * Returns:
82  *        TEE_Result
83  *---------------------------------------------------------------------------*/
84 TEE_Result tee_ta_close_session(uint32_t id,
85 				struct tee_ta_session_head *open_sessions);
86 
87 TEE_Result tee_ta_get_current_session(struct tee_ta_session **sess);
88 
89 void tee_ta_set_current_session(struct tee_ta_session *sess);
90 
91 TEE_Result tee_ta_get_client_id(TEE_Identity *id);
92 
93 /*
94  * Get pointer of executable part of the TA located in virtual kernel memory
95  */
96 uintptr_t tee_ta_get_exec(const struct tee_ta_ctx *const ctx);
97 
98 /* Returns OK is sess is a valid session pointer or static TA */
99 TEE_Result tee_ta_verify_session_pointer(struct tee_ta_session *sess,
100 					 struct tee_ta_session_head
101 					 *open_sessions);
102 
103 int tee_ta_set_trace_level(int level);
104 
105 #endif
106