blob: 8303009e4b0e1fda2a4cad40f24f566df6849e35 [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
Mingyang Sun22a3faf2021-07-09 15:32:47 +080042uint32_t tfm_rpc_psa_version(const struct client_call_params_t *params)
David Hu5923bc22019-09-23 15:44:06 +080043{
Ken Liuf250b8b2019-12-27 16:31:24 +080044 TFM_CORE_ASSERT(params != NULL);
David Hu5923bc22019-09-23 15:44:06 +080045
Mingyang Sun22a3faf2021-07-09 15:32:47 +080046 return tfm_spm_client_psa_version(params->sid);
David Hu5923bc22019-09-23 15:44:06 +080047}
48
Mingyang Sun22a3faf2021-07-09 15:32:47 +080049psa_status_t tfm_rpc_psa_connect(const struct client_call_params_t *params)
David Hu5923bc22019-09-23 15:44:06 +080050{
Ken Liuf250b8b2019-12-27 16:31:24 +080051 TFM_CORE_ASSERT(params != NULL);
David Hu5923bc22019-09-23 15:44:06 +080052
Mingyang Sun22a3faf2021-07-09 15:32:47 +080053 return tfm_spm_client_psa_connect(params->sid, params->version);
David Hu5923bc22019-09-23 15:44:06 +080054}
55
Mingyang Sun22a3faf2021-07-09 15:32:47 +080056psa_status_t tfm_rpc_psa_call(const struct client_call_params_t *params)
David Hu5923bc22019-09-23 15:44:06 +080057{
Ken Liuf250b8b2019-12-27 16:31:24 +080058 TFM_CORE_ASSERT(params != NULL);
David Hu5923bc22019-09-23 15:44:06 +080059
Mingyang Sund44522a2020-01-16 16:48:37 +080060 return tfm_spm_client_psa_call(params->handle, params->type,
61 params->in_vec, params->in_len,
Mingyang Sun22a3faf2021-07-09 15:32:47 +080062 params->out_vec, params->out_len,
Mingyang Sund44522a2020-01-16 16:48:37 +080063 TFM_PARTITION_UNPRIVILEGED_MODE);
David Hu5923bc22019-09-23 15:44:06 +080064}
65
Mingyang Sun22a3faf2021-07-09 15:32:47 +080066void tfm_rpc_psa_close(const struct client_call_params_t *params)
David Hu5923bc22019-09-23 15:44:06 +080067{
Ken Liuf250b8b2019-12-27 16:31:24 +080068 TFM_CORE_ASSERT(params != NULL);
David Hu5923bc22019-09-23 15:44:06 +080069
Mingyang Sun22a3faf2021-07-09 15:32:47 +080070 tfm_spm_client_psa_close(params->handle);
David Hu5923bc22019-09-23 15:44:06 +080071}
72
73int32_t tfm_rpc_register_ops(const struct tfm_rpc_ops_t *ops_ptr)
74{
75 if (!ops_ptr) {
76 return TFM_RPC_INVAL_PARAM;
77 }
78
David Hua79c7c12019-12-11 18:47:06 +080079 if (!ops_ptr->handle_req || !ops_ptr->reply || !ops_ptr->get_caller_data) {
David Hu5923bc22019-09-23 15:44:06 +080080 return TFM_RPC_INVAL_PARAM;
81 }
82
83 /* Currently, one and only one mailbox implementation is supported. */
84 if ((rpc_ops.handle_req != default_handle_req) ||
Xinyu Zhang3a453242021-04-16 17:57:09 +080085 (rpc_ops.reply != default_mailbox_reply) ||
David Hua79c7c12019-12-11 18:47:06 +080086 (rpc_ops.get_caller_data != default_get_caller_data)) {
David Hu5923bc22019-09-23 15:44:06 +080087 return TFM_RPC_CONFLICT_CALLBACK;
88 }
89
90 rpc_ops.handle_req = ops_ptr->handle_req;
91 rpc_ops.reply = ops_ptr->reply;
David Hua79c7c12019-12-11 18:47:06 +080092 rpc_ops.get_caller_data = ops_ptr->get_caller_data;
David Hu5923bc22019-09-23 15:44:06 +080093
94 return TFM_RPC_SUCCESS;
95}
96
97void tfm_rpc_unregister_ops(void)
98{
99 rpc_ops.handle_req = default_handle_req;
100 rpc_ops.reply = default_mailbox_reply;
David Hua79c7c12019-12-11 18:47:06 +0800101 rpc_ops.get_caller_data = default_get_caller_data;
David Hu5923bc22019-09-23 15:44:06 +0800102}
103
104void tfm_rpc_client_call_handler(void)
105{
106 rpc_ops.handle_req();
107}
108
109void tfm_rpc_client_call_reply(const void *owner, int32_t ret)
110{
David Hu46603dd2019-12-11 18:05:16 +0800111 const struct tfm_msg_body_t *msg = (const struct tfm_msg_body_t *)owner;
112
113 rpc_ops.reply(msg->caller_data, ret);
114}
115
116void tfm_rpc_set_caller_data(struct tfm_msg_body_t *msg, int32_t client_id)
117{
David Hua79c7c12019-12-11 18:47:06 +0800118 msg->caller_data = rpc_ops.get_caller_data(client_id);
David Hu5923bc22019-09-23 15:44:06 +0800119}