blob: c9919b2eb0701d8e082cfda971fd468f79952e39 [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"
David Hu5923bc22019-09-23 15:44:06 +080013
14static void default_handle_req(void)
15{
16}
17
18static void default_mailbox_reply(const void *owner, int32_t ret)
19{
20 (void)owner;
21 (void)ret;
22}
23
David Hua79c7c12019-12-11 18:47:06 +080024static const void *default_get_caller_data(int32_t client_id)
25{
26 (void)client_id;
27
28 return NULL;
29}
30
David Hu5923bc22019-09-23 15:44:06 +080031static struct tfm_rpc_ops_t rpc_ops = {
32 .handle_req = default_handle_req,
33 .reply = default_mailbox_reply,
David Hua79c7c12019-12-11 18:47:06 +080034 .get_caller_data = default_get_caller_data,
David Hu5923bc22019-09-23 15:44:06 +080035};
36
37uint32_t tfm_rpc_psa_framework_version(void)
38{
Mingyang Sund44522a2020-01-16 16:48:37 +080039 return tfm_spm_client_psa_framework_version();
David Hu5923bc22019-09-23 15:44:06 +080040}
41
42uint32_t tfm_rpc_psa_version(const struct client_call_params_t *params,
Summer Qin43c185d2019-10-10 15:44:42 +080043 bool ns_caller)
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 Sund44522a2020-01-16 16:48:37 +080047 return tfm_spm_client_psa_version(params->sid, ns_caller);
David Hu5923bc22019-09-23 15:44:06 +080048}
49
50psa_status_t tfm_rpc_psa_connect(const struct client_call_params_t *params,
Summer Qin43c185d2019-10-10 15:44:42 +080051 bool ns_caller)
David Hu5923bc22019-09-23 15:44:06 +080052{
Ken Liuf250b8b2019-12-27 16:31:24 +080053 TFM_CORE_ASSERT(params != NULL);
David Hu5923bc22019-09-23 15:44:06 +080054
Mingyang Sund44522a2020-01-16 16:48:37 +080055 return tfm_spm_client_psa_connect(params->sid, params->version, ns_caller);
David Hu5923bc22019-09-23 15:44:06 +080056}
57
58psa_status_t tfm_rpc_psa_call(const struct client_call_params_t *params,
Summer Qin43c185d2019-10-10 15:44:42 +080059 bool ns_caller)
David Hu5923bc22019-09-23 15:44:06 +080060{
Ken Liuf250b8b2019-12-27 16:31:24 +080061 TFM_CORE_ASSERT(params != NULL);
David Hu5923bc22019-09-23 15:44:06 +080062
Mingyang Sund44522a2020-01-16 16:48:37 +080063 return tfm_spm_client_psa_call(params->handle, params->type,
64 params->in_vec, params->in_len,
65 params->out_vec, params->out_len, ns_caller,
66 TFM_PARTITION_UNPRIVILEGED_MODE);
David Hu5923bc22019-09-23 15:44:06 +080067}
68
69void tfm_rpc_psa_close(const struct client_call_params_t *params,
Summer Qin43c185d2019-10-10 15:44:42 +080070 bool ns_caller)
David Hu5923bc22019-09-23 15:44:06 +080071{
Ken Liuf250b8b2019-12-27 16:31:24 +080072 TFM_CORE_ASSERT(params != NULL);
David Hu5923bc22019-09-23 15:44:06 +080073
Mingyang Sund44522a2020-01-16 16:48:37 +080074 tfm_spm_client_psa_close(params->handle, ns_caller);
David Hu5923bc22019-09-23 15:44:06 +080075}
76
77int32_t tfm_rpc_register_ops(const struct tfm_rpc_ops_t *ops_ptr)
78{
79 if (!ops_ptr) {
80 return TFM_RPC_INVAL_PARAM;
81 }
82
David Hua79c7c12019-12-11 18:47:06 +080083 if (!ops_ptr->handle_req || !ops_ptr->reply || !ops_ptr->get_caller_data) {
David Hu5923bc22019-09-23 15:44:06 +080084 return TFM_RPC_INVAL_PARAM;
85 }
86
87 /* Currently, one and only one mailbox implementation is supported. */
88 if ((rpc_ops.handle_req != default_handle_req) ||
Xinyu Zhang3a453242021-04-16 17:57:09 +080089 (rpc_ops.reply != default_mailbox_reply) ||
David Hua79c7c12019-12-11 18:47:06 +080090 (rpc_ops.get_caller_data != default_get_caller_data)) {
David Hu5923bc22019-09-23 15:44:06 +080091 return TFM_RPC_CONFLICT_CALLBACK;
92 }
93
94 rpc_ops.handle_req = ops_ptr->handle_req;
95 rpc_ops.reply = ops_ptr->reply;
David Hua79c7c12019-12-11 18:47:06 +080096 rpc_ops.get_caller_data = ops_ptr->get_caller_data;
David Hu5923bc22019-09-23 15:44:06 +080097
98 return TFM_RPC_SUCCESS;
99}
100
101void tfm_rpc_unregister_ops(void)
102{
103 rpc_ops.handle_req = default_handle_req;
104 rpc_ops.reply = default_mailbox_reply;
David Hua79c7c12019-12-11 18:47:06 +0800105 rpc_ops.get_caller_data = default_get_caller_data;
David Hu5923bc22019-09-23 15:44:06 +0800106}
107
108void tfm_rpc_client_call_handler(void)
109{
110 rpc_ops.handle_req();
111}
112
113void tfm_rpc_client_call_reply(const void *owner, int32_t ret)
114{
David Hu46603dd2019-12-11 18:05:16 +0800115 const struct tfm_msg_body_t *msg = (const struct tfm_msg_body_t *)owner;
116
117 rpc_ops.reply(msg->caller_data, ret);
118}
119
120void tfm_rpc_set_caller_data(struct tfm_msg_body_t *msg, int32_t client_id)
121{
David Hua79c7c12019-12-11 18:47:06 +0800122 msg->caller_data = rpc_ops.get_caller_data(client_id);
David Hu5923bc22019-09-23 15:44:06 +0800123}