xref: /optee_os/core/include/tee/tee_svc.h (revision 9403c583381528e7fb391e3769644cc9653cfbb6)
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 #ifndef TEE_SVC_H
28 #define TEE_SVC_H
29 
30 #include <stdint.h>
31 #include <kernel/tee_common_unpg.h>	/* tee_uaddr_t */
32 #include <kernel/tee_ta_manager_unpg.h>
33 #include <tee_api_types.h>
34 #include <utee_types.h>
35 #include <assert.h>
36 
37 extern vaddr_t tee_svc_uref_base;
38 
39 struct tee_ta_session;
40 
41 void syscall_sys_return(unsigned long ret);
42 
43 void syscall_log(const void *buf, size_t len);
44 
45 void syscall_panic(unsigned long code);
46 
47 TEE_Result syscall_reserved(void);
48 
49 TEE_Result syscall_not_supported(void);
50 
51 uint32_t syscall_dummy(uint32_t *a);
52 uint32_t syscall_dummy_7args(unsigned long a1, unsigned long a2,
53 			unsigned long a3, unsigned long a4, unsigned long a5,
54 			unsigned long a6, unsigned long a7);
55 
56 uint32_t syscall_nocall(void);
57 
58 TEE_Result syscall_get_property(unsigned long prop, void *buf, size_t blen);
59 
60 TEE_Result syscall_open_ta_session(const TEE_UUID *dest,
61 			unsigned long cancel_req_to, struct utee_params *params,
62 			uint32_t *sess, uint32_t *ret_orig);
63 
64 TEE_Result syscall_close_ta_session(unsigned long sess);
65 
66 TEE_Result syscall_invoke_ta_command(unsigned long sess,
67 			unsigned long cancel_req_to, unsigned long cmd_id,
68 			struct utee_params *params, uint32_t *ret_orig);
69 
70 TEE_Result syscall_check_access_rights(unsigned long flags, const void *buf,
71 				       size_t len);
72 
73 TEE_Result tee_svc_copy_from_user(struct tee_ta_session *sess, void *kaddr,
74 				  const void *uaddr, size_t len);
75 TEE_Result tee_svc_copy_to_user(struct tee_ta_session *sess, void *uaddr,
76 				const void *kaddr, size_t len);
77 
78 TEE_Result tee_svc_copy_kaddr_to_uref(struct tee_ta_session *sess,
79 			uint32_t *uref, void *kaddr);
80 
81 static inline uint32_t tee_svc_kaddr_to_uref(void *kaddr)
82 {
83 	assert(((vaddr_t)kaddr - tee_svc_uref_base) < UINT32_MAX);
84 	return (vaddr_t)kaddr - tee_svc_uref_base;
85 }
86 
87 static inline vaddr_t tee_svc_uref_to_vaddr(uint32_t uref)
88 {
89 	return tee_svc_uref_base + uref;
90 }
91 
92 static inline void *tee_svc_uref_to_kaddr(uint32_t uref)
93 {
94 	return (void *)tee_svc_uref_to_vaddr(uref);
95 }
96 
97 TEE_Result syscall_get_cancellation_flag(uint32_t *cancel);
98 
99 TEE_Result syscall_unmask_cancellation(uint32_t *old_mask);
100 
101 TEE_Result syscall_mask_cancellation(uint32_t *old_mask);
102 
103 TEE_Result syscall_wait(unsigned long timeout);
104 
105 TEE_Result syscall_get_time(unsigned long cat, TEE_Time *time);
106 TEE_Result syscall_set_ta_time(const TEE_Time *time);
107 
108 #ifdef CFG_CACHE_API
109 TEE_Result syscall_cache_operation(void *va, size_t len, unsigned long op);
110 #else
111 #define  syscall_cache_operation syscall_not_supported
112 #endif
113 
114 void tee_svc_trace_syscall(int num);
115 
116 
117 #endif /* TEE_SVC_H */
118