1 /*
2  * Copyright (c) 2018-2022, Arm Limited. All rights reserved.
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  *
6  */
7 
8 #include <stdint.h>
9 #include "compiler_ext_defs.h"
10 #include "config_spm.h"
11 #include "svc_num.h"
12 #include "tfm_psa_call_pack.h"
13 #include "utilities.h"
14 #include "psa/client.h"
15 #include "psa/lifecycle.h"
16 #include "psa/service.h"
17 
psa_framework_version_svc(void)18 __naked uint32_t psa_framework_version_svc(void)
19 {
20     __asm volatile("svc     "M2S(TFM_SVC_PSA_FRAMEWORK_VERSION)"\n"
21                    "bx      lr                                  \n");
22 }
23 
psa_version_svc(uint32_t sid)24 __naked uint32_t psa_version_svc(uint32_t sid)
25 {
26     __asm volatile("svc     "M2S(TFM_SVC_PSA_VERSION)"         \n"
27                    "bx      lr                                 \n");
28 }
29 
tfm_psa_call_pack_svc(psa_handle_t handle,uint32_t ctrl_param,const psa_invec * in_vec,psa_outvec * out_vec)30 __naked psa_status_t tfm_psa_call_pack_svc(psa_handle_t handle,
31                                            uint32_t ctrl_param,
32                                            const psa_invec *in_vec,
33                                            psa_outvec *out_vec)
34 {
35     __asm volatile("svc     "M2S(TFM_SVC_PSA_CALL)"            \n"
36                    "bx      lr                                 \n");
37 }
38 
psa_wait_svc(psa_signal_t signal_mask,uint32_t timeout)39 __naked psa_signal_t psa_wait_svc(psa_signal_t signal_mask, uint32_t timeout)
40 {
41     __asm volatile("svc     "M2S(TFM_SVC_PSA_WAIT)"            \n"
42                    "bx      lr                                 \n");
43 }
44 
psa_get_svc(psa_signal_t signal,psa_msg_t * msg)45 __naked psa_status_t psa_get_svc(psa_signal_t signal, psa_msg_t *msg)
46 {
47     __asm volatile("svc     "M2S(TFM_SVC_PSA_GET)"             \n"
48                    "bx      lr                                 \n");
49 }
50 
psa_read_svc(psa_handle_t msg_handle,uint32_t invec_idx,void * buffer,size_t num_bytes)51 __naked size_t psa_read_svc(psa_handle_t msg_handle, uint32_t invec_idx,
52                             void *buffer, size_t num_bytes)
53 {
54     __asm volatile("svc     "M2S(TFM_SVC_PSA_READ)"            \n"
55                    "bx      lr                                 \n");
56 }
57 
psa_skip_svc(psa_handle_t msg_handle,uint32_t invec_idx,size_t num_bytes)58 __naked size_t psa_skip_svc(psa_handle_t msg_handle,
59                             uint32_t invec_idx, size_t num_bytes)
60 {
61     __asm volatile("svc     "M2S(TFM_SVC_PSA_SKIP)"            \n"
62                    "bx      lr                                 \n");
63 }
64 
psa_write_svc(psa_handle_t msg_handle,uint32_t outvec_idx,const void * buffer,size_t num_bytes)65 __naked void psa_write_svc(psa_handle_t msg_handle, uint32_t outvec_idx,
66                            const void *buffer, size_t num_bytes)
67 {
68     __asm volatile("svc     "M2S(TFM_SVC_PSA_WRITE)"           \n"
69                    "bx      lr                                 \n");
70 }
71 
psa_reply_svc(psa_handle_t msg_handle,psa_status_t retval)72 __naked void psa_reply_svc(psa_handle_t msg_handle, psa_status_t retval)
73 {
74     __asm volatile("svc     "M2S(TFM_SVC_PSA_REPLY)"           \n"
75                    "bx      lr                                 \n");
76 }
77 
78 #if CONFIG_TFM_DOORBELL_API == 1
psa_notify_svc(int32_t partition_id)79 __naked void psa_notify_svc(int32_t partition_id)
80 {
81     __asm volatile("svc     "M2S(TFM_SVC_PSA_NOTIFY)"          \n"
82                    "bx      lr                                 \n");
83 }
84 
psa_clear_svc(void)85 __naked void psa_clear_svc(void)
86 {
87     __asm volatile("svc     "M2S(TFM_SVC_PSA_CLEAR)"           \n"
88                    "bx      lr                                 \n");
89 }
90 #endif /* CONFIG_TFM_DOORBELL_API == 1 */
91 
psa_panic_svc(void)92 __naked void psa_panic_svc(void)
93 {
94     __asm volatile("svc     "M2S(TFM_SVC_PSA_PANIC)"           \n"
95                    "bx      lr                                 \n");
96 }
97 
psa_rot_lifecycle_state_svc(void)98 __naked uint32_t psa_rot_lifecycle_state_svc(void)
99 {
100     __asm volatile("svc     "M2S(TFM_SVC_PSA_LIFECYCLE)"       \n"
101                    "bx      lr                                 \n");
102 }
103 
104 /* Following PSA APIs are only needed by connection-based services */
105 #if CONFIG_TFM_CONNECTION_BASED_SERVICE_API == 1
106 
psa_connect_svc(uint32_t sid,uint32_t version)107 __naked psa_handle_t psa_connect_svc(uint32_t sid, uint32_t version)
108 {
109     __asm volatile("svc     "M2S(TFM_SVC_PSA_CONNECT)"         \n"
110                    "bx      lr                                 \n");
111 }
112 
psa_close_svc(psa_handle_t handle)113 __naked void psa_close_svc(psa_handle_t handle)
114 {
115     __asm volatile("svc     "M2S(TFM_SVC_PSA_CLOSE)"           \n"
116                    "bx      lr                                 \n");
117 }
118 
psa_set_rhandle_svc(psa_handle_t msg_handle,void * rhandle)119 __naked void psa_set_rhandle_svc(psa_handle_t msg_handle, void *rhandle)
120 {
121     __asm volatile("svc     "M2S(TFM_SVC_PSA_SET_RHANDLE)"     \n"
122                    "bx      lr                                 \n");
123 }
124 
125 #endif /* CONFIG_TFM_CONNECTION_BASED_SERVICE_API */
126 
127 #if CONFIG_TFM_FLIH_API == 1 || CONFIG_TFM_SLIH_API == 1
128 
psa_irq_enable_svc(psa_signal_t irq_signal)129 __naked void psa_irq_enable_svc(psa_signal_t irq_signal)
130 {
131     __asm volatile("svc     "M2S(TFM_SVC_PSA_IRQ_ENABLE)"      \n"
132                    "bx      lr                                 \n");
133 }
134 
psa_irq_disable_svc(psa_signal_t irq_signal)135 __naked psa_irq_status_t psa_irq_disable_svc(psa_signal_t irq_signal)
136 {
137     __asm volatile("svc     "M2S(TFM_SVC_PSA_IRQ_DISABLE)"     \n"
138                    "bx      lr                                 \n");
139 }
140 
141 /* This API is only used for FLIH. */
142 #if CONFIG_TFM_FLIH_API == 1
psa_reset_signal_svc(psa_signal_t irq_signal)143 __naked void psa_reset_signal_svc(psa_signal_t irq_signal)
144 {
145     __asm volatile("svc     "M2S(TFM_SVC_PSA_RESET_SIGNAL)"    \n"
146                    "bx      lr                                 \n");
147 }
148 #endif
149 
150 /* This API is only used for SLIH. */
151 #if CONFIG_TFM_SLIH_API == 1
psa_eoi_svc(psa_signal_t irq_signal)152 __naked void psa_eoi_svc(psa_signal_t irq_signal)
153 {
154     __asm volatile("svc     "M2S(TFM_SVC_PSA_EOI)"             \n"
155                    "bx      lr                                 \n");
156 }
157 #endif
158 
159 #endif /* CONFIG_TFM_FLIH_API == 1 || CONFIG_TFM_SLIH_API == 1 */
160