diff options
author | David Hu <david.hu@arm.com> | 2019-12-11 18:47:06 +0800 |
---|---|---|
committer | David Hu <david.hu@arm.com> | 2020-02-14 10:57:13 +0800 |
commit | a79c7c14afe1262b8fbe6a7870923d9ad9032afc (patch) | |
tree | 5c5d8d07500ff64d3431f134877418dcfb07fc23 | |
parent | 46603dd150eb2addd4ae328841829dd7fb960211 (diff) | |
download | trusted-firmware-m-a79c7c14afe1262b8fbe6a7870923d9ad9032afc.tar.gz |
Dualcpu: Implement tfm_rpc_set_caller_data()
Add a callback get_caller_data() in structure tfm_rpc_ops_t for
SPE mailbox to return the pointer to the private data of NSPE
client.
Implement get_caller_data() callback in SPE mailbox to return the
address of Secure mailbox message handle as the private data.
Add a field cur_proc_slot_idx in SPE mailbox queue to record the
mailbox queue slot index under processing. That field can be used
in get_caller_data() callback to identify the slot and acquire the
private data handle of the NSPE client.
Change-Id: Ia5fc9b6f8df66bf6d9ca626b8b0496eb762baa0c
Signed-off-by: David Hu <david.hu@arm.com>
-rw-r--r-- | secure_fw/core/ipc/include/tfm_rpc.h | 3 | ||||
-rw-r--r-- | secure_fw/core/ipc/include/tfm_spe_mailbox.h | 7 | ||||
-rw-r--r-- | secure_fw/core/ipc/tfm_rpc.c | 19 | ||||
-rw-r--r-- | secure_fw/core/ipc/tfm_spe_mailbox.c | 32 |
4 files changed, 50 insertions, 11 deletions
diff --git a/secure_fw/core/ipc/include/tfm_rpc.h b/secure_fw/core/ipc/include/tfm_rpc.h index a0ff27d26c..cf573f8799 100644 --- a/secure_fw/core/ipc/include/tfm_rpc.h +++ b/secure_fw/core/ipc/include/tfm_rpc.h @@ -51,10 +51,13 @@ struct client_call_params_t { * handle_req() - Handle PSA client call request from NSPE * reply() - Reply PSA client call return result to NSPE. The parameter * owner identifies the owner of the PSA client call. + * get_caller_data() - Get the private data of NSPE client from mailbox to + * identify the PSA client call. */ struct tfm_rpc_ops_t { void (*handle_req)(void); void (*reply)(const void *owner, int32_t ret); + const void * (*get_caller_data)(int32_t client_id); }; /** diff --git a/secure_fw/core/ipc/include/tfm_spe_mailbox.h b/secure_fw/core/ipc/include/tfm_spe_mailbox.h index 2a1fe0f684..fd07907117 100644 --- a/secure_fw/core/ipc/include/tfm_spe_mailbox.h +++ b/secure_fw/core/ipc/include/tfm_spe_mailbox.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, Arm Limited. All rights reserved. + * Copyright (c) 2019-2020, Arm Limited. All rights reserved. * * SPDX-License-Identifier: BSD-3-Clause * @@ -23,6 +23,11 @@ struct secure_mailbox_queue_t { struct secure_mailbox_slot_t queue[NUM_MAILBOX_QUEUE_SLOT]; struct ns_mailbox_queue_t *ns_queue; + uint8_t cur_proc_slot_idx; /* + * The index of mailbox + * queue slot currently + * under processing. + */ }; /** diff --git a/secure_fw/core/ipc/tfm_rpc.c b/secure_fw/core/ipc/tfm_rpc.c index 3d48b9024f..0af6775a43 100644 --- a/secure_fw/core/ipc/tfm_rpc.c +++ b/secure_fw/core/ipc/tfm_rpc.c @@ -20,9 +20,17 @@ static void default_mailbox_reply(const void *owner, int32_t ret) (void)ret; } +static const void *default_get_caller_data(int32_t client_id) +{ + (void)client_id; + + return NULL; +} + static struct tfm_rpc_ops_t rpc_ops = { .handle_req = default_handle_req, .reply = default_mailbox_reply, + .get_caller_data = default_get_caller_data, }; uint32_t tfm_rpc_psa_framework_version(void) @@ -71,18 +79,20 @@ int32_t tfm_rpc_register_ops(const struct tfm_rpc_ops_t *ops_ptr) return TFM_RPC_INVAL_PARAM; } - if (!ops_ptr->handle_req || !ops_ptr->reply) { + if (!ops_ptr->handle_req || !ops_ptr->reply || !ops_ptr->get_caller_data) { return TFM_RPC_INVAL_PARAM; } /* Currently, one and only one mailbox implementation is supported. */ if ((rpc_ops.handle_req != default_handle_req) || - (rpc_ops.reply != default_mailbox_reply)) { + (rpc_ops.reply != default_mailbox_reply) || \ + (rpc_ops.get_caller_data != default_get_caller_data)) { return TFM_RPC_CONFLICT_CALLBACK; } rpc_ops.handle_req = ops_ptr->handle_req; rpc_ops.reply = ops_ptr->reply; + rpc_ops.get_caller_data = ops_ptr->get_caller_data; return TFM_RPC_SUCCESS; } @@ -91,6 +101,7 @@ void tfm_rpc_unregister_ops(void) { rpc_ops.handle_req = default_handle_req; rpc_ops.reply = default_mailbox_reply; + rpc_ops.get_caller_data = default_get_caller_data; } void tfm_rpc_client_call_handler(void) @@ -107,7 +118,5 @@ void tfm_rpc_client_call_reply(const void *owner, int32_t ret) void tfm_rpc_set_caller_data(struct tfm_msg_body_t *msg, int32_t client_id) { - (void)client_id; - - msg->caller_data = NULL; + msg->caller_data = rpc_ops.get_caller_data(client_id); } diff --git a/secure_fw/core/ipc/tfm_spe_mailbox.c b/secure_fw/core/ipc/tfm_spe_mailbox.c index 758b73507a..87f8995a6a 100644 --- a/secure_fw/core/ipc/tfm_spe_mailbox.c +++ b/secure_fw/core/ipc/tfm_spe_mailbox.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, Arm Limited. All rights reserved. + * Copyright (c) 2019-2020, Arm Limited. All rights reserved. * * SPDX-License-Identifier: BSD-3-Clause * @@ -228,13 +228,16 @@ int32_t tfm_mailbox_handle_msg(void) continue; } - /* - * Although SPE mailbox message handle is set, it is not used currently - * since multiple ongoing NSPE PSA client calls are not supported yet. - */ get_spe_mailbox_msg_handle(idx, &spe_mailbox_queue.queue[idx].msg_handle); + /* + * Set the current slot index under processing. + * The value is used in mailbox_get_caller_data() to identify the + * mailbox queue slot. + */ + spe_mailbox_queue.cur_proc_slot_idx = idx; + result = tfm_mailbox_dispatch(msg_ptr->call_type, &msg_ptr->params, msg_ptr->client_id, &psa_ret); if (result != MAILBOX_SUCCESS) { @@ -242,6 +245,9 @@ int32_t tfm_mailbox_handle_msg(void) continue; } + /* Clean up the current slot index under processing */ + spe_mailbox_queue.cur_proc_slot_idx = NUM_MAILBOX_QUEUE_SLOT; + if ((msg_ptr->call_type == MAILBOX_PSA_FRAMEWORK_VERSION) || (msg_ptr->call_type == MAILBOX_PSA_VERSION)) { /* @@ -345,10 +351,26 @@ static void mailbox_reply(const void *owner, int32_t ret) (void)tfm_mailbox_reply_msg(handle, ret); } +/* RPC get_caller_data() callback */ +static const void *mailbox_get_caller_data(int32_t client_id) +{ + uint8_t idx; + + (void)client_id; + + idx = spe_mailbox_queue.cur_proc_slot_idx; + if (idx < NUM_MAILBOX_QUEUE_SLOT) { + return (const void *)&spe_mailbox_queue.queue[idx].msg_handle; + } + + return NULL; +} + /* Mailbox specific operations callback for TF-M RPC */ static const struct tfm_rpc_ops_t mailbox_rpc_ops = { .handle_req = mailbox_handle_req, .reply = mailbox_reply, + .get_caller_data = mailbox_get_caller_data, }; int32_t tfm_mailbox_init(void) |