blob: 9fc1ced41688f62633c49d07af2bccf2afdfb8f1 [file] [log] [blame]
David Hu5923bc22019-09-23 15:44:06 +08001/*
Mingyang Sun00df2352021-04-15 15:46:08 +08002 * Copyright (c) 2019-2021, Arm Limited. All rights reserved.
David Hu5923bc22019-09-23 15:44:06 +08003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 *
6 */
7
Mingyang Sun7397b4f2020-06-17 15:07:45 +08008#include "spm_ipc.h"
Mingyang Sun133a7922021-07-08 16:01:26 +08009#include "ffm/psa_api.h"
David Hu5923bc22019-09-23 15:44:06 +080010#include "tfm_rpc.h"
Summer Qin5fdcf632020-06-22 16:49:24 +080011#include "utilities.h"
Mingyang Sun00df2352021-04-15 15:46:08 +080012#include "load/partition_defs.h"
Mingyang Suneeca4652021-07-15 15:19:16 +080013#include "tfm_psa_call_param.h"
David Hu5923bc22019-09-23 15:44:06 +080014
15static void default_handle_req(void)
16{
17}
18
19static void default_mailbox_reply(const void *owner, int32_t ret)
20{
21 (void)owner;
22 (void)ret;
23}
24
David Hua79c7c12019-12-11 18:47:06 +080025static const void *default_get_caller_data(int32_t client_id)
26{
27 (void)client_id;
28
29 return NULL;
30}
31
David Hu5923bc22019-09-23 15:44:06 +080032static struct tfm_rpc_ops_t rpc_ops = {
33 .handle_req = default_handle_req,
34 .reply = default_mailbox_reply,
David Hua79c7c12019-12-11 18:47:06 +080035 .get_caller_data = default_get_caller_data,
David Hu5923bc22019-09-23 15:44:06 +080036};
37
38uint32_t tfm_rpc_psa_framework_version(void)
39{
Mingyang Sund44522a2020-01-16 16:48:37 +080040 return tfm_spm_client_psa_framework_version();
David Hu5923bc22019-09-23 15:44:06 +080041}
42
Mingyang Sun22a3faf2021-07-09 15:32:47 +080043uint32_t tfm_rpc_psa_version(const struct client_call_params_t *params)
David Hu5923bc22019-09-23 15:44:06 +080044{
Ken Liuf250b8b2019-12-27 16:31:24 +080045 TFM_CORE_ASSERT(params != NULL);
David Hu5923bc22019-09-23 15:44:06 +080046
Mingyang Sun22a3faf2021-07-09 15:32:47 +080047 return tfm_spm_client_psa_version(params->sid);
David Hu5923bc22019-09-23 15:44:06 +080048}
49
Mingyang Sun22a3faf2021-07-09 15:32:47 +080050psa_status_t tfm_rpc_psa_connect(const struct client_call_params_t *params)
David Hu5923bc22019-09-23 15:44:06 +080051{
Ken Liuf250b8b2019-12-27 16:31:24 +080052 TFM_CORE_ASSERT(params != NULL);
David Hu5923bc22019-09-23 15:44:06 +080053
Mingyang Sun22a3faf2021-07-09 15:32:47 +080054 return tfm_spm_client_psa_connect(params->sid, params->version);
David Hu5923bc22019-09-23 15:44:06 +080055}
56
Mingyang Sun22a3faf2021-07-09 15:32:47 +080057psa_status_t tfm_rpc_psa_call(const struct client_call_params_t *params)
David Hu5923bc22019-09-23 15:44:06 +080058{
Ken Liuf250b8b2019-12-27 16:31:24 +080059 TFM_CORE_ASSERT(params != NULL);
David Hu5923bc22019-09-23 15:44:06 +080060
Mingyang Suneeca4652021-07-15 15:19:16 +080061 return tfm_spm_client_psa_call(params->handle,
62 PARAM_PACK(params->type,
63 params->in_len,
64 params->out_len),
65 params->in_vec, params->out_vec);
David Hu5923bc22019-09-23 15:44:06 +080066}
67
Mingyang Sun22a3faf2021-07-09 15:32:47 +080068void tfm_rpc_psa_close(const struct client_call_params_t *params)
David Hu5923bc22019-09-23 15:44:06 +080069{
Ken Liuf250b8b2019-12-27 16:31:24 +080070 TFM_CORE_ASSERT(params != NULL);
David Hu5923bc22019-09-23 15:44:06 +080071
Mingyang Sun22a3faf2021-07-09 15:32:47 +080072 tfm_spm_client_psa_close(params->handle);
David Hu5923bc22019-09-23 15:44:06 +080073}
74
75int32_t tfm_rpc_register_ops(const struct tfm_rpc_ops_t *ops_ptr)
76{
77 if (!ops_ptr) {
78 return TFM_RPC_INVAL_PARAM;
79 }
80
David Hua79c7c12019-12-11 18:47:06 +080081 if (!ops_ptr->handle_req || !ops_ptr->reply || !ops_ptr->get_caller_data) {
David Hu5923bc22019-09-23 15:44:06 +080082 return TFM_RPC_INVAL_PARAM;
83 }
84
85 /* Currently, one and only one mailbox implementation is supported. */
86 if ((rpc_ops.handle_req != default_handle_req) ||
Xinyu Zhang3a453242021-04-16 17:57:09 +080087 (rpc_ops.reply != default_mailbox_reply) ||
David Hua79c7c12019-12-11 18:47:06 +080088 (rpc_ops.get_caller_data != default_get_caller_data)) {
David Hu5923bc22019-09-23 15:44:06 +080089 return TFM_RPC_CONFLICT_CALLBACK;
90 }
91
92 rpc_ops.handle_req = ops_ptr->handle_req;
93 rpc_ops.reply = ops_ptr->reply;
David Hua79c7c12019-12-11 18:47:06 +080094 rpc_ops.get_caller_data = ops_ptr->get_caller_data;
David Hu5923bc22019-09-23 15:44:06 +080095
96 return TFM_RPC_SUCCESS;
97}
98
99void tfm_rpc_unregister_ops(void)
100{
101 rpc_ops.handle_req = default_handle_req;
102 rpc_ops.reply = default_mailbox_reply;
David Hua79c7c12019-12-11 18:47:06 +0800103 rpc_ops.get_caller_data = default_get_caller_data;
David Hu5923bc22019-09-23 15:44:06 +0800104}
105
106void tfm_rpc_client_call_handler(void)
107{
108 rpc_ops.handle_req();
109}
110
111void tfm_rpc_client_call_reply(const void *owner, int32_t ret)
112{
David Hu46603dd2019-12-11 18:05:16 +0800113 const struct tfm_msg_body_t *msg = (const struct tfm_msg_body_t *)owner;
114
115 rpc_ops.reply(msg->caller_data, ret);
116}
117
118void tfm_rpc_set_caller_data(struct tfm_msg_body_t *msg, int32_t client_id)
119{
David Hua79c7c12019-12-11 18:47:06 +0800120 msg->caller_data = rpc_ops.get_caller_data(client_id);
David Hu5923bc22019-09-23 15:44:06 +0800121}