David Hu | 5923bc2 | 2019-09-23 15:44:06 +0800 | [diff] [blame] | 1 | /* |
Mingyang Sun | 00df235 | 2021-04-15 15:46:08 +0800 | [diff] [blame] | 2 | * Copyright (c) 2019-2021, Arm Limited. All rights reserved. |
David Hu | 5923bc2 | 2019-09-23 15:44:06 +0800 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | * |
| 6 | */ |
| 7 | |
Mingyang Sun | 7397b4f | 2020-06-17 15:07:45 +0800 | [diff] [blame] | 8 | #include "spm_ipc.h" |
Mingyang Sun | 133a792 | 2021-07-08 16:01:26 +0800 | [diff] [blame] | 9 | #include "ffm/psa_api.h" |
David Hu | 5923bc2 | 2019-09-23 15:44:06 +0800 | [diff] [blame] | 10 | #include "tfm_rpc.h" |
Summer Qin | 5fdcf63 | 2020-06-22 16:49:24 +0800 | [diff] [blame] | 11 | #include "utilities.h" |
Mingyang Sun | 00df235 | 2021-04-15 15:46:08 +0800 | [diff] [blame] | 12 | #include "load/partition_defs.h" |
David Hu | 5923bc2 | 2019-09-23 15:44:06 +0800 | [diff] [blame] | 13 | |
| 14 | static void default_handle_req(void) |
| 15 | { |
| 16 | } |
| 17 | |
| 18 | static void default_mailbox_reply(const void *owner, int32_t ret) |
| 19 | { |
| 20 | (void)owner; |
| 21 | (void)ret; |
| 22 | } |
| 23 | |
David Hu | a79c7c1 | 2019-12-11 18:47:06 +0800 | [diff] [blame] | 24 | static const void *default_get_caller_data(int32_t client_id) |
| 25 | { |
| 26 | (void)client_id; |
| 27 | |
| 28 | return NULL; |
| 29 | } |
| 30 | |
David Hu | 5923bc2 | 2019-09-23 15:44:06 +0800 | [diff] [blame] | 31 | static struct tfm_rpc_ops_t rpc_ops = { |
| 32 | .handle_req = default_handle_req, |
| 33 | .reply = default_mailbox_reply, |
David Hu | a79c7c1 | 2019-12-11 18:47:06 +0800 | [diff] [blame] | 34 | .get_caller_data = default_get_caller_data, |
David Hu | 5923bc2 | 2019-09-23 15:44:06 +0800 | [diff] [blame] | 35 | }; |
| 36 | |
| 37 | uint32_t tfm_rpc_psa_framework_version(void) |
| 38 | { |
Mingyang Sun | d44522a | 2020-01-16 16:48:37 +0800 | [diff] [blame] | 39 | return tfm_spm_client_psa_framework_version(); |
David Hu | 5923bc2 | 2019-09-23 15:44:06 +0800 | [diff] [blame] | 40 | } |
| 41 | |
Mingyang Sun | 22a3faf | 2021-07-09 15:32:47 +0800 | [diff] [blame] | 42 | uint32_t tfm_rpc_psa_version(const struct client_call_params_t *params) |
David Hu | 5923bc2 | 2019-09-23 15:44:06 +0800 | [diff] [blame] | 43 | { |
Ken Liu | f250b8b | 2019-12-27 16:31:24 +0800 | [diff] [blame] | 44 | TFM_CORE_ASSERT(params != NULL); |
David Hu | 5923bc2 | 2019-09-23 15:44:06 +0800 | [diff] [blame] | 45 | |
Mingyang Sun | 22a3faf | 2021-07-09 15:32:47 +0800 | [diff] [blame] | 46 | return tfm_spm_client_psa_version(params->sid); |
David Hu | 5923bc2 | 2019-09-23 15:44:06 +0800 | [diff] [blame] | 47 | } |
| 48 | |
Mingyang Sun | 22a3faf | 2021-07-09 15:32:47 +0800 | [diff] [blame] | 49 | psa_status_t tfm_rpc_psa_connect(const struct client_call_params_t *params) |
David Hu | 5923bc2 | 2019-09-23 15:44:06 +0800 | [diff] [blame] | 50 | { |
Ken Liu | f250b8b | 2019-12-27 16:31:24 +0800 | [diff] [blame] | 51 | TFM_CORE_ASSERT(params != NULL); |
David Hu | 5923bc2 | 2019-09-23 15:44:06 +0800 | [diff] [blame] | 52 | |
Mingyang Sun | 22a3faf | 2021-07-09 15:32:47 +0800 | [diff] [blame] | 53 | return tfm_spm_client_psa_connect(params->sid, params->version); |
David Hu | 5923bc2 | 2019-09-23 15:44:06 +0800 | [diff] [blame] | 54 | } |
| 55 | |
Mingyang Sun | 22a3faf | 2021-07-09 15:32:47 +0800 | [diff] [blame] | 56 | psa_status_t tfm_rpc_psa_call(const struct client_call_params_t *params) |
David Hu | 5923bc2 | 2019-09-23 15:44:06 +0800 | [diff] [blame] | 57 | { |
Ken Liu | f250b8b | 2019-12-27 16:31:24 +0800 | [diff] [blame] | 58 | TFM_CORE_ASSERT(params != NULL); |
David Hu | 5923bc2 | 2019-09-23 15:44:06 +0800 | [diff] [blame] | 59 | |
Mingyang Sun | d44522a | 2020-01-16 16:48:37 +0800 | [diff] [blame] | 60 | return tfm_spm_client_psa_call(params->handle, params->type, |
| 61 | params->in_vec, params->in_len, |
Mingyang Sun | e529e3b | 2021-07-12 14:46:30 +0800 | [diff] [blame^] | 62 | params->out_vec, params->out_len); |
David Hu | 5923bc2 | 2019-09-23 15:44:06 +0800 | [diff] [blame] | 63 | } |
| 64 | |
Mingyang Sun | 22a3faf | 2021-07-09 15:32:47 +0800 | [diff] [blame] | 65 | void tfm_rpc_psa_close(const struct client_call_params_t *params) |
David Hu | 5923bc2 | 2019-09-23 15:44:06 +0800 | [diff] [blame] | 66 | { |
Ken Liu | f250b8b | 2019-12-27 16:31:24 +0800 | [diff] [blame] | 67 | TFM_CORE_ASSERT(params != NULL); |
David Hu | 5923bc2 | 2019-09-23 15:44:06 +0800 | [diff] [blame] | 68 | |
Mingyang Sun | 22a3faf | 2021-07-09 15:32:47 +0800 | [diff] [blame] | 69 | tfm_spm_client_psa_close(params->handle); |
David Hu | 5923bc2 | 2019-09-23 15:44:06 +0800 | [diff] [blame] | 70 | } |
| 71 | |
| 72 | int32_t tfm_rpc_register_ops(const struct tfm_rpc_ops_t *ops_ptr) |
| 73 | { |
| 74 | if (!ops_ptr) { |
| 75 | return TFM_RPC_INVAL_PARAM; |
| 76 | } |
| 77 | |
David Hu | a79c7c1 | 2019-12-11 18:47:06 +0800 | [diff] [blame] | 78 | if (!ops_ptr->handle_req || !ops_ptr->reply || !ops_ptr->get_caller_data) { |
David Hu | 5923bc2 | 2019-09-23 15:44:06 +0800 | [diff] [blame] | 79 | return TFM_RPC_INVAL_PARAM; |
| 80 | } |
| 81 | |
| 82 | /* Currently, one and only one mailbox implementation is supported. */ |
| 83 | if ((rpc_ops.handle_req != default_handle_req) || |
Xinyu Zhang | 3a45324 | 2021-04-16 17:57:09 +0800 | [diff] [blame] | 84 | (rpc_ops.reply != default_mailbox_reply) || |
David Hu | a79c7c1 | 2019-12-11 18:47:06 +0800 | [diff] [blame] | 85 | (rpc_ops.get_caller_data != default_get_caller_data)) { |
David Hu | 5923bc2 | 2019-09-23 15:44:06 +0800 | [diff] [blame] | 86 | return TFM_RPC_CONFLICT_CALLBACK; |
| 87 | } |
| 88 | |
| 89 | rpc_ops.handle_req = ops_ptr->handle_req; |
| 90 | rpc_ops.reply = ops_ptr->reply; |
David Hu | a79c7c1 | 2019-12-11 18:47:06 +0800 | [diff] [blame] | 91 | rpc_ops.get_caller_data = ops_ptr->get_caller_data; |
David Hu | 5923bc2 | 2019-09-23 15:44:06 +0800 | [diff] [blame] | 92 | |
| 93 | return TFM_RPC_SUCCESS; |
| 94 | } |
| 95 | |
| 96 | void tfm_rpc_unregister_ops(void) |
| 97 | { |
| 98 | rpc_ops.handle_req = default_handle_req; |
| 99 | rpc_ops.reply = default_mailbox_reply; |
David Hu | a79c7c1 | 2019-12-11 18:47:06 +0800 | [diff] [blame] | 100 | rpc_ops.get_caller_data = default_get_caller_data; |
David Hu | 5923bc2 | 2019-09-23 15:44:06 +0800 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | void tfm_rpc_client_call_handler(void) |
| 104 | { |
| 105 | rpc_ops.handle_req(); |
| 106 | } |
| 107 | |
| 108 | void tfm_rpc_client_call_reply(const void *owner, int32_t ret) |
| 109 | { |
David Hu | 46603dd | 2019-12-11 18:05:16 +0800 | [diff] [blame] | 110 | const struct tfm_msg_body_t *msg = (const struct tfm_msg_body_t *)owner; |
| 111 | |
| 112 | rpc_ops.reply(msg->caller_data, ret); |
| 113 | } |
| 114 | |
| 115 | void tfm_rpc_set_caller_data(struct tfm_msg_body_t *msg, int32_t client_id) |
| 116 | { |
David Hu | a79c7c1 | 2019-12-11 18:47:06 +0800 | [diff] [blame] | 117 | msg->caller_data = rpc_ops.get_caller_data(client_id); |
David Hu | 5923bc2 | 2019-09-23 15:44:06 +0800 | [diff] [blame] | 118 | } |