TF-M Reference Manual  1.2.0
TrustedFirmware-M
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
tfm_rpc.c
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 #include "spm_ipc.h"
10 #include "tfm_rpc.h"
11 #include "utilities.h"
12 
13 static void default_handle_req(void)
14 {
15 }
16 
17 static void default_mailbox_reply(const void *owner, int32_t ret)
18 {
19  (void)owner;
20  (void)ret;
21 }
22 
23 static const void *default_get_caller_data(int32_t client_id)
24 {
25  (void)client_id;
26 
27  return NULL;
28 }
29 
30 static struct tfm_rpc_ops_t rpc_ops = {
31  .handle_req = default_handle_req,
32  .reply = default_mailbox_reply,
33  .get_caller_data = default_get_caller_data,
34 };
35 
37 {
39 }
40 
41 uint32_t tfm_rpc_psa_version(const struct client_call_params_t *params,
42  bool ns_caller)
43 {
44  TFM_CORE_ASSERT(params != NULL);
45 
46  return tfm_spm_client_psa_version(params->sid, ns_caller);
47 }
48 
49 psa_status_t tfm_rpc_psa_connect(const struct client_call_params_t *params,
50  bool ns_caller)
51 {
52  TFM_CORE_ASSERT(params != NULL);
53 
54  return tfm_spm_client_psa_connect(params->sid, params->version, ns_caller);
55 }
56 
57 psa_status_t tfm_rpc_psa_call(const struct client_call_params_t *params,
58  bool ns_caller)
59 {
60  TFM_CORE_ASSERT(params != NULL);
61 
62  return tfm_spm_client_psa_call(params->handle, params->type,
63  params->in_vec, params->in_len,
64  params->out_vec, params->out_len, ns_caller,
66 }
67 
68 void tfm_rpc_psa_close(const struct client_call_params_t *params,
69  bool ns_caller)
70 {
71  TFM_CORE_ASSERT(params != NULL);
72 
73  tfm_spm_client_psa_close(params->handle, ns_caller);
74 }
75 
76 int32_t tfm_rpc_register_ops(const struct tfm_rpc_ops_t *ops_ptr)
77 {
78  if (!ops_ptr) {
79  return TFM_RPC_INVAL_PARAM;
80  }
81 
82  if (!ops_ptr->handle_req || !ops_ptr->reply || !ops_ptr->get_caller_data) {
83  return TFM_RPC_INVAL_PARAM;
84  }
85 
86  /* Currently, one and only one mailbox implementation is supported. */
87  if ((rpc_ops.handle_req != default_handle_req) ||
88  (rpc_ops.reply != default_mailbox_reply) || \
89  (rpc_ops.get_caller_data != default_get_caller_data)) {
90  return TFM_RPC_CONFLICT_CALLBACK;
91  }
92 
93  rpc_ops.handle_req = ops_ptr->handle_req;
94  rpc_ops.reply = ops_ptr->reply;
95  rpc_ops.get_caller_data = ops_ptr->get_caller_data;
96 
97  return TFM_RPC_SUCCESS;
98 }
99 
101 {
102  rpc_ops.handle_req = default_handle_req;
103  rpc_ops.reply = default_mailbox_reply;
104  rpc_ops.get_caller_data = default_get_caller_data;
105 }
106 
108 {
109  rpc_ops.handle_req();
110 }
111 
112 void tfm_rpc_client_call_reply(const void *owner, int32_t ret)
113 {
114  const struct tfm_msg_body_t *msg = (const struct tfm_msg_body_t *)owner;
115 
116  rpc_ops.reply(msg->caller_data, ret);
117 }
118 
119 void tfm_rpc_set_caller_data(struct tfm_msg_body_t *msg, int32_t client_id)
120 {
121  msg->caller_data = rpc_ops.get_caller_data(client_id);
122 }
#define TFM_PARTITION_UNPRIVILEGED_MODE
Definition: spm_func.h:32
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
uint32_t tfm_spm_client_psa_framework_version(void)
handler for psa_framework_version.
void tfm_rpc_psa_close(const struct client_call_params_t *params, bool ns_caller)
Definition: tfm_rpc.c:68
psa_status_t tfm_spm_client_psa_call(psa_handle_t handle, int32_t type, const psa_invec *inptr, size_t in_num, psa_outvec *outptr, size_t out_num, bool ns_caller, uint32_t privileged)
handler for psa_call.
void tfm_spm_client_psa_close(psa_handle_t handle, bool ns_caller)
handler for psa_close.
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
#define TFM_CORE_ASSERT(cond)
Definition: utilities.h:21
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
#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
psa_status_t tfm_spm_client_psa_connect(uint32_t sid, uint32_t version, bool ns_caller)
handler for psa_connect.
uint32_t tfm_spm_client_psa_version(uint32_t sid, bool ns_caller)
handler for psa_version.
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