1 /*
2  * Copyright (c) 2023, Arm Limited. All rights reserved.
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  *
6  */
7 
8 #include <stdint.h>
9 #include "psa/client.h"
10 #include "config_impl.h"
11 #include "tfm_psa_call_pack.h"
12 #include "sprt_partition_metadata_indicator.h"
13 #include "runtime_defs.h"
14 
psa_framework_version(void)15 uint32_t psa_framework_version(void)
16 {
17     return PART_METADATA()->psa_fns->psa_framework_version();
18 }
19 
psa_version(uint32_t sid)20 uint32_t psa_version(uint32_t sid)
21 {
22     return PART_METADATA()->psa_fns->psa_version(sid);
23 }
24 
tfm_psa_call_pack(psa_handle_t handle,uint32_t ctrl_param,const psa_invec * in_vec,psa_outvec * out_vec)25 psa_status_t tfm_psa_call_pack(psa_handle_t handle,
26                                uint32_t ctrl_param,
27                                const psa_invec *in_vec,
28                                psa_outvec *out_vec)
29 {
30     return PART_METADATA()->psa_fns->psa_call(handle, ctrl_param,
31                                               in_vec, out_vec);
32 }
33 
psa_wait(psa_signal_t signal_mask,uint32_t timeout)34 psa_signal_t psa_wait(psa_signal_t signal_mask, uint32_t timeout)
35 {
36     return PART_METADATA()->psa_fns->psa_wait(signal_mask, timeout);
37 }
38 
psa_get(psa_signal_t signal,psa_msg_t * msg)39 psa_status_t psa_get(psa_signal_t signal, psa_msg_t *msg)
40 {
41     return PART_METADATA()->psa_fns->psa_get(signal, msg);
42 }
43 
psa_read(psa_handle_t msg_handle,uint32_t invec_idx,void * buffer,size_t num_bytes)44 size_t psa_read(psa_handle_t msg_handle, uint32_t invec_idx,
45                 void *buffer, size_t num_bytes)
46 {
47     return PART_METADATA()->psa_fns->psa_read(msg_handle, invec_idx, buffer, num_bytes);
48 }
49 
psa_skip(psa_handle_t msg_handle,uint32_t invec_idx,size_t num_bytes)50 size_t psa_skip(psa_handle_t msg_handle, uint32_t invec_idx, size_t num_bytes)
51 {
52     return PART_METADATA()->psa_fns->psa_skip(msg_handle, invec_idx, num_bytes);
53 }
54 
psa_write(psa_handle_t msg_handle,uint32_t outvec_idx,const void * buffer,size_t num_bytes)55 void psa_write(psa_handle_t msg_handle, uint32_t outvec_idx,
56                const void *buffer, size_t num_bytes)
57 {
58     PART_METADATA()->psa_fns->psa_write(msg_handle, outvec_idx, buffer, num_bytes);
59 }
60 
psa_reply(psa_handle_t msg_handle,psa_status_t retval)61 void psa_reply(psa_handle_t msg_handle, psa_status_t retval)
62 {
63     PART_METADATA()->psa_fns->psa_reply(msg_handle, retval);
64 }
65 
psa_panic(void)66 void psa_panic(void)
67 {
68     PART_METADATA()->psa_fns->psa_panic();
69 }
70 
psa_rot_lifecycle_state(void)71 uint32_t psa_rot_lifecycle_state(void)
72 {
73     return PART_METADATA()->psa_fns->psa_rot_lifecycle_state();
74 }
75 
76 #if CONFIG_TFM_CONNECTION_BASED_SERVICE_API == 1
psa_connect(uint32_t sid,uint32_t version)77 psa_handle_t psa_connect(uint32_t sid, uint32_t version)
78 {
79     return PART_METADATA()->psa_fns->psa_connect(sid, version);
80 }
81 
psa_close(psa_handle_t handle)82 void psa_close(psa_handle_t handle)
83 {
84    PART_METADATA()->psa_fns->psa_close(handle);
85 }
86 
psa_set_rhandle(psa_handle_t msg_handle,void * rhandle)87 void psa_set_rhandle(psa_handle_t msg_handle, void *rhandle)
88 {
89     PART_METADATA()->psa_fns->psa_set_rhandle(msg_handle, rhandle);
90 }
91 #endif /* CONFIG_TFM_CONNECTION_BASED_SERVICE_API == 1 */
92 
93 #if CONFIG_TFM_DOORBELL_API == 1
psa_notify(int32_t partition_id)94 void psa_notify(int32_t partition_id)
95 {
96     PART_METADATA()->psa_fns->psa_notify(partition_id);
97 }
98 
psa_clear(void)99 void psa_clear(void)
100 {
101     PART_METADATA()->psa_fns->psa_clear();
102 }
103 #endif /* CONFIG_TFM_DOORBELL_API == 1 */
104 
105 #if CONFIG_TFM_FLIH_API == 1 || CONFIG_TFM_SLIH_API == 1
psa_irq_enable(psa_signal_t irq_signal)106 void psa_irq_enable(psa_signal_t irq_signal)
107 {
108     PART_METADATA()->psa_fns->psa_irq_enable(irq_signal);
109 }
110 
psa_irq_disable(psa_signal_t irq_signal)111 psa_irq_status_t psa_irq_disable(psa_signal_t irq_signal)
112 {
113     return PART_METADATA()->psa_fns->psa_irq_disable(irq_signal);
114 }
115 
116 #if CONFIG_TFM_FLIH_API == 1
psa_reset_signal(psa_signal_t irq_signal)117 void psa_reset_signal(psa_signal_t irq_signal)
118 {
119    PART_METADATA()->psa_fns->psa_reset_signal(irq_signal);
120 }
121 #endif /* CONFIG_TFM_FLIH_API == 1 */
122 
123 #if CONFIG_TFM_SLIH_API == 1
psa_eoi(psa_signal_t irq_signal)124 void psa_eoi(psa_signal_t irq_signal)
125 {
126     PART_METADATA()->psa_fns->psa_eoi(irq_signal);
127 }
128 #endif /* CONFIG_TFM_SLIH_API == 1 */
129 #endif /* CONFIG_TFM_FLIH_API == 1 || CONFIG_TFM_SLIH_API == 1 */
130 
131 #if PSA_FRAMEWORK_HAS_MM_IOVEC
psa_map_invec(psa_handle_t msg_handle,uint32_t invec_idx)132 const void *psa_map_invec(psa_handle_t msg_handle, uint32_t invec_idx)
133 {
134     return PART_METADATA()->psa_fns->psa_map_invec(msg_handle, invec_idx);
135 }
136 
psa_unmap_invec(psa_handle_t msg_handle,uint32_t invec_idx)137 void psa_unmap_invec(psa_handle_t msg_handle, uint32_t invec_idx)
138 {
139     PART_METADATA()->psa_fns->psa_unmap_invec(msg_handle, invec_idx);
140 }
141 
psa_map_outvec(psa_handle_t msg_handle,uint32_t outvec_idx)142 void *psa_map_outvec(psa_handle_t msg_handle, uint32_t outvec_idx)
143 {
144     PART_METADATA()->psa_fns->psa_map_outvec(msg_handle, outvec_idx);
145 }
146 
psa_unmap_outvec(psa_handle_t msg_handle,uint32_t outvec_idx,size_t len)147 void psa_unmap_outvec(psa_handle_t msg_handle, uint32_t outvec_idx, size_t len)
148 {
149     PART_METADATA()->psa_fns->psa_unmap_outvec(msg_handle, outvec_idx, len);
150 }
151 #endif /* PSA_FRAMEWORK_HAS_MM_IOVEC */
152 
153 #ifdef TFM_PARTITION_NS_AGENT_MAILBOX
agent_psa_call(psa_handle_t handle,uint32_t control,const struct client_params_t * params,const void * client_data_stateless)154 psa_status_t agent_psa_call(psa_handle_t handle,
155                             uint32_t control,
156                             const struct client_params_t *params,
157                             const void *client_data_stateless)
158 {
159     return PART_METADATA()->psa_fns->agent_psa_call(handle, control, params,
160                                                     client_data_stateless);
161 }
162 
163 #if CONFIG_TFM_CONNECTION_BASED_SERVICE_API == 1
agent_psa_connect(uint32_t sid,uint32_t version,int32_t ns_client_id,const void * client_data)164 psa_handle_t agent_psa_connect(uint32_t sid, uint32_t version,
165                                int32_t ns_client_id, const void *client_data)
166 {
167     return PART_METADATA()->psa_fns->agent_psa_connect(sid, version,
168                                                        ns_client_id,
169                                                        client_data);
170 }
171 #endif /* CONFIG_TFM_CONNECTION_BASED_SERVICE_API == 1 */
172 #endif /* TFM_PARTITION_NS_AGENT_MAILBOX */
173