xref: /optee_os/core/include/kernel/tee_ta_manager.h (revision bc420748bfc44a9e09000a3966fc59e9e0219df4)
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 <tee_api_types.h>
32 #include <utee_types.h>
33 #include <kernel/tee_common.h>
34 #include <kernel/tee_ta_manager_unpg.h>
35 
36 /* Magic TEE identity pointer: set when teecore requests a TA close */
37 #define KERN_IDENTITY	((TEE_Identity *)-1)
38 /* Operation is initiated by a client (non-secure) app */
39 #define NSAPP_IDENTITY	(NULL)
40 
41 /*-----------------------------------------------------------------------------
42  * Initializes virtual memory management by reserving virtual memory for
43  * memory areas not available TA virtual memroy allocation.
44  *
45  * Spare physical pages are passed in the memory range between ta_start and
46  * ta_spare_end.  Spare physical pages are supposed to be mapped with "no
47  * access" attribute.
48  *
49  * All addresses will be rounded up the the next page.
50  *
51  * Parameters:
52  * ro_start - start of read only section for paging,
53  * ro_end   - end of read only section for paging,
54  * ta_start - start of section used for TA virtual memory
55  * ta_spare_end - end of spare pages used for paging
56  *
57  * Returns:
58  *        void
59  *---------------------------------------------------------------------------*/
60 void tee_ta_vmem_init(tee_vaddr_t ro_start, tee_vaddr_t ro_end,
61 		      tee_vaddr_t ta_start, tee_vaddr_t ta_spare_end);
62 
63 TEE_Result tee_ta_open_session(TEE_ErrorOrigin *err,
64 			       struct tee_ta_session **sess,
65 			       struct tee_ta_session_head *open_sessions,
66 			       const TEE_UUID *uuid,
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  * Function called to close a TA.
83  * Parameters:
84  * id   - The session id (in)
85  * Returns:
86  *        TEE_Result
87  *---------------------------------------------------------------------------*/
88 TEE_Result tee_ta_close_session(struct tee_ta_session *sess,
89 				struct tee_ta_session_head *open_sessions,
90 				const TEE_Identity *clnt_id);
91 
92 TEE_Result tee_ta_get_current_session(struct tee_ta_session **sess);
93 
94 void tee_ta_set_current_session(struct tee_ta_session *sess);
95 
96 TEE_Result tee_ta_get_client_id(TEE_Identity *id);
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 void tee_ta_dump_current(void);
105 void tee_ta_dump_all(void);
106 
107 #ifdef CFG_CACHE_API
108 TEE_Result tee_uta_cache_operation(struct tee_ta_session *s,
109 				   enum utee_cache_operation op,
110 				   void *va, size_t len);
111 #endif
112 
113 #endif
114