TF-M Reference Manual  1.2.0
TrustedFirmware-M
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
tfm_rpc.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2019-2020, Arm Limited. All rights reserved.
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  *
6  */
7 
8 /*
9  * Definitions of Remote Procedure Call (RPC) functionalities in TF-M, which
10  * sits between upper TF-M SPM and underlying mailbox implementation.
11  */
12 
13 #ifndef __TFM_RPC_H__
14 #define __TFM_RPC_H__
15 
16 #ifdef TFM_MULTI_CORE_TOPOLOGY
17 
18 #include <stdbool.h>
19 #include <stdint.h>
20 #include "cmsis_compiler.h"
21 #include "psa/client.h"
22 #include "psa/service.h"
23 #include "tfm_thread.h"
24 #include "tfm_wait.h"
25 #include "spm_ipc.h"
26 
27 #define TFM_RPC_SUCCESS (0)
28 #define TFM_RPC_INVAL_PARAM (INT32_MIN + 1)
29 #define TFM_RPC_CONFLICT_CALLBACK (INT32_MIN + 2)
30 
31 /*
32  * This structure holds the parameters used in a PSA client call.
33  * The parameters are passed from non-secure core to secure core.
34  */
35 struct client_call_params_t {
36  uint32_t sid;
37  psa_handle_t handle;
38  int32_t type;
39  const psa_invec *in_vec;
40  size_t in_len;
41  psa_outvec *out_vec;
42  size_t out_len;
43  uint32_t version;
44 };
45 
46 /*
47  * The underlying mailbox communication implementation should provide
48  * the specific operations to complete the RPC functionalities.
49  *
50  * It includes the following operations:
51  * handle_req() - Handle PSA client call request from NSPE
52  * reply() - Reply PSA client call return result to NSPE. The parameter
53  * owner identifies the owner of the PSA client call.
54  * get_caller_data() - Get the private data of NSPE client from mailbox to
55  * identify the PSA client call.
56  */
57 struct tfm_rpc_ops_t {
58  void (*handle_req)(void);
59  void (*reply)(const void *owner, int32_t ret);
60  const void * (*get_caller_data)(int32_t client_id);
61 };
62 
69 uint32_t tfm_rpc_psa_framework_version(void);
70 
81 uint32_t tfm_rpc_psa_version(const struct client_call_params_t *params,
82  bool ns_caller);
83 
97 psa_status_t tfm_rpc_psa_connect(const struct client_call_params_t *params,
98  bool ns_caller);
99 
116 psa_status_t tfm_rpc_psa_call(const struct client_call_params_t *params,
117  bool ns_caller);
118 
131 void tfm_rpc_psa_close(const struct client_call_params_t *params,
132  bool ns_caller);
133 
142 int32_t tfm_rpc_register_ops(const struct tfm_rpc_ops_t *ops_ptr);
143 
153 void tfm_rpc_unregister_ops(void);
154 
160 void tfm_rpc_client_call_handler(void);
161 
169 void tfm_rpc_client_call_reply(const void *owner, int32_t ret);
170 
171 /*
172  * Check if the message was allocated for a non-secure request via RPC
173  *
174  * \param[in] msg The message body context pointer
175  * \ref msg_body_t structures
176  *
177  * \retval true The message was allocated for a NS request via RPC.
178  * \retval false Otherwise.
179  */
180 __STATIC_INLINE bool is_tfm_rpc_msg(const struct tfm_msg_body_t *msg)
181 {
182  /*
183  * FIXME
184  * The ID should be smaller than 0 if the message is allocated by a
185  * non-secure caller.
186  * However, current TF-M implementation use 0 as the default non-secure
187  * caller ID. Therefore, treat the caller as non-secure when client_id == 0.
188  *
189  * This condition check should be improved after TF-M non-secure client ID
190  * management is implemented.
191  */
192  if (msg && (msg->msg.client_id <= 0) && !msg->ack_evnt.owner) {
193  return true;
194  }
195 
196  return false;
197 }
198 
199 /*
200  * \brief Set the private data of the NS caller in \ref msg_body_t, to identify
201  * the caller after PSA client call is compeleted.
202  *
203  * \param[in] msg The address of \ref msg_body_t structure
204  * \param[in] client_id The client ID of the NS caller.
205  */
206 void tfm_rpc_set_caller_data(struct tfm_msg_body_t *msg, int32_t client_id);
207 
208 #else /* TFM_MULTI_CORE_TOPOLOGY */
209 
210 /* RPC is only available in multi-core scenario */
211 #define is_tfm_rpc_msg(x) (false)
212 
213 #define tfm_rpc_client_call_handler() do {} while (0)
214 
215 #define tfm_rpc_client_call_reply(owner, ret) do {} while (0)
216 
217 #define tfm_rpc_set_caller_data(msg, client_id) do {} while (0)
218 
219 #endif /* TFM_MULTI_CORE_TOPOLOGY */
220 #endif /* __TFM_RPC_H__ */
psa_status_t tfm_rpc_psa_connect(const struct client_call_params_t *params, bool ns_caller)
Definition: tfm_rpc.c:49
psa_status_t tfm_rpc_psa_call(const struct client_call_params_t *params, bool ns_caller)
Definition: tfm_rpc.c:57
void tfm_rpc_psa_close(const struct client_call_params_t *params, bool ns_caller)
Definition: tfm_rpc.c:68
int32_t client_id
Definition: service.h:64
#define is_tfm_rpc_msg(x)
Definition: tfm_rpc.h:211
uint32_t tfm_rpc_psa_framework_version(void)
Definition: tfm_rpc.c:36
#define tfm_rpc_client_call_handler()
Definition: tfm_rpc.h:213
psa_msg_t msg
Definition: spm_ipc.h:63
struct tfm_core_thread_t * owner
Definition: tfm_wait.h:19
void tfm_rpc_unregister_ops(void)
Definition: tfm_rpc.c:100
int32_t tfm_rpc_register_ops(const struct tfm_rpc_ops_t *ops_ptr)
Definition: tfm_rpc.c:76
int32_t psa_handle_t
Definition: client.h:61
#define tfm_rpc_set_caller_data(msg, client_id)
Definition: tfm_rpc.h:217
uint32_t tfm_rpc_psa_version(const struct client_call_params_t *params, bool ns_caller)
Definition: tfm_rpc.c:41
struct tfm_event_t ack_evnt
Definition: spm_ipc.h:62
int32_t psa_status_t
Function return status.
Definition: crypto_types.h:43
#define tfm_rpc_client_call_reply(owner, ret)
Definition: tfm_rpc.h:215