1 /*
2  * Copyright (c) 2022-2024, Arm Limited. All rights reserved.
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  *
6  */
7 
8 #include <stdint.h>
9 
10 #include "config_impl.h"
11 #include "security_defs.h"
12 #include "tfm_arch.h"
13 #include "tfm_psa_call_pack.h"
14 
15 #include "psa/client.h"
16 
17 /*
18  * This is the veneers of FF-M Client APIs, except for Armv8.0-m.
19  * The interfaces are written in C unlike Armv8.0-m because reentrant detection
20  * is done by the architecture.
21  *
22  * As NS Agent is also a Secure Partition, it can call the client APIs directly.
23  *
24  */
25 
26 __tz_c_veneer
tfm_psa_framework_version_veneer(void)27 uint32_t tfm_psa_framework_version_veneer(void)
28 {
29     uint32_t ret;
30 #if CONFIG_TFM_SECURE_THREAD_MASK_NS_INTERRUPT == 1
31     __set_BASEPRI(SECURE_THREAD_EXECUTION_PRIORITY);
32 #endif
33     ret = psa_framework_version();
34 #if CONFIG_TFM_SECURE_THREAD_MASK_NS_INTERRUPT == 1
35     __set_BASEPRI(0);
36 #endif
37     return ret;
38 }
39 
40 __tz_c_veneer
tfm_psa_version_veneer(uint32_t sid)41 uint32_t tfm_psa_version_veneer(uint32_t sid)
42 {
43     uint32_t ret;
44 #if CONFIG_TFM_SECURE_THREAD_MASK_NS_INTERRUPT == 1
45     __set_BASEPRI(SECURE_THREAD_EXECUTION_PRIORITY);
46 #endif
47     ret = psa_version(sid);
48 #if CONFIG_TFM_SECURE_THREAD_MASK_NS_INTERRUPT == 1
49     __set_BASEPRI(0);
50 #endif
51     return ret;
52 }
53 
54 __tz_c_veneer
tfm_psa_call_veneer(psa_handle_t handle,uint32_t ctrl_param,const psa_invec * in_vec,psa_outvec * out_vec)55 psa_status_t tfm_psa_call_veneer(psa_handle_t handle,
56                                  uint32_t ctrl_param,
57                                  const psa_invec *in_vec,
58                                  psa_outvec *out_vec)
59 {
60     psa_status_t ret;
61 #if CONFIG_TFM_SECURE_THREAD_MASK_NS_INTERRUPT == 1
62     __set_BASEPRI(SECURE_THREAD_EXECUTION_PRIORITY);
63 #endif
64     ret = tfm_psa_call_pack(handle,
65                             PARAM_SET_NS_VEC(ctrl_param),
66                             in_vec, out_vec);
67 #if CONFIG_TFM_SECURE_THREAD_MASK_NS_INTERRUPT == 1
68     __set_BASEPRI(0);
69 #endif
70     return ret;
71 }
72 
73 /* Following veneers are only needed by connection-based services */
74 #if CONFIG_TFM_CONNECTION_BASED_SERVICE_API == 1
75 __tz_c_veneer
tfm_psa_connect_veneer(uint32_t sid,uint32_t version)76 psa_handle_t tfm_psa_connect_veneer(uint32_t sid, uint32_t version)
77 {
78     psa_handle_t ret;
79 #if CONFIG_TFM_SECURE_THREAD_MASK_NS_INTERRUPT == 1
80     __set_BASEPRI(SECURE_THREAD_EXECUTION_PRIORITY);
81 #endif
82     ret = psa_connect(sid, version);
83 #if CONFIG_TFM_SECURE_THREAD_MASK_NS_INTERRUPT == 1
84     __set_BASEPRI(0);
85 #endif
86     return ret;
87 }
88 
89 __tz_c_veneer
tfm_psa_close_veneer(psa_handle_t handle)90 void tfm_psa_close_veneer(psa_handle_t handle)
91 {
92 #if CONFIG_TFM_SECURE_THREAD_MASK_NS_INTERRUPT == 1
93     __set_BASEPRI(SECURE_THREAD_EXECUTION_PRIORITY);
94 #endif
95     psa_close(handle);
96 #if CONFIG_TFM_SECURE_THREAD_MASK_NS_INTERRUPT == 1
97     __set_BASEPRI(0);
98 #endif
99 }
100 #else /* CONFIG_TFM_CONNECTION_BASED_SERVICE_API */
101 __tz_c_veneer
tfm_psa_connect_veneer(uint32_t sid,uint32_t version)102 psa_handle_t tfm_psa_connect_veneer(uint32_t sid, uint32_t version)
103 {
104     (void)sid;
105     (void)version;
106 
107     return PSA_ERROR_NOT_SUPPORTED;
108 }
109 
110 __tz_c_veneer
tfm_psa_close_veneer(psa_handle_t handle)111 void tfm_psa_close_veneer(psa_handle_t handle)
112 {
113     (void)handle;
114 
115     return;
116 }
117 #endif /* CONFIG_TFM_CONNECTION_BASED_SERVICE_API */
118