David Hu | 49ec08a | 2019-09-23 16:13:41 +0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2019, Arm Limited. All rights reserved. |
| 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | * |
| 6 | */ |
| 7 | |
| 8 | /* API definitions in NSPE mailbox library */ |
| 9 | |
| 10 | #ifndef __TFM_NS_MAILBOX_H__ |
| 11 | #define __TFM_NS_MAILBOX_H__ |
| 12 | |
| 13 | #include <stdbool.h> |
| 14 | #include "tfm_mailbox.h" |
| 15 | |
David Hu | dbafa3e | 2019-10-22 11:26:37 +0800 | [diff] [blame^] | 16 | #ifdef __cplusplus |
| 17 | extern "C" { |
| 18 | #endif |
| 19 | |
David Hu | 49ec08a | 2019-09-23 16:13:41 +0800 | [diff] [blame] | 20 | /** |
David Hu | dbafa3e | 2019-10-22 11:26:37 +0800 | [diff] [blame^] | 21 | * \brief Prepare and send PSA client request to SPE via mailbox. |
David Hu | 49ec08a | 2019-09-23 16:13:41 +0800 | [diff] [blame] | 22 | * |
| 23 | * \param[in] call_type PSA client call type |
| 24 | * \param[in] params Parmaters used for PSA client call |
| 25 | * \param[in] client_id Optional client ID of non-secure caller. |
| 26 | * It is required to identify the non-secure caller |
| 27 | * when NSPE OS enforces non-secure task isolation. |
| 28 | * |
| 29 | * \retval >= 0 The handle to the mailbox message assigned. |
| 30 | * \retval < 0 Operation failed with an error code. |
| 31 | */ |
David Hu | dbafa3e | 2019-10-22 11:26:37 +0800 | [diff] [blame^] | 32 | mailbox_msg_handle_t tfm_ns_mailbox_tx_client_req(uint32_t call_type, |
| 33 | const struct psa_client_params_t *params, |
| 34 | int32_t client_id); |
David Hu | 49ec08a | 2019-09-23 16:13:41 +0800 | [diff] [blame] | 35 | |
| 36 | /** |
David Hu | dbafa3e | 2019-10-22 11:26:37 +0800 | [diff] [blame^] | 37 | * \brief Fetch PSA client return result. |
David Hu | 49ec08a | 2019-09-23 16:13:41 +0800 | [diff] [blame] | 38 | * |
| 39 | * \param[in] handle The handle to the mailbox message |
| 40 | * \param[out] reply The address to be written with return result. |
| 41 | * |
| 42 | * \retval MAILBOX_SUCCESS Successfully get PSA client call return result. |
| 43 | * \retval Other return code Operation failed with an error code. |
| 44 | */ |
David Hu | dbafa3e | 2019-10-22 11:26:37 +0800 | [diff] [blame^] | 45 | int32_t tfm_ns_mailbox_rx_client_reply(mailbox_msg_handle_t handle, |
| 46 | int32_t *reply); |
David Hu | 49ec08a | 2019-09-23 16:13:41 +0800 | [diff] [blame] | 47 | |
| 48 | /** |
| 49 | * \brief Check whether a specific mailbox message has been replied. |
| 50 | * |
| 51 | * \param[in] handle The handle to the mailbox message |
| 52 | * |
| 53 | * \retval true The PSA client call return value is replied. |
| 54 | * \retval false The PSA client call return value is not |
| 55 | * replied yet. |
| 56 | */ |
David Hu | dbafa3e | 2019-10-22 11:26:37 +0800 | [diff] [blame^] | 57 | bool tfm_ns_mailbox_is_msg_replied(mailbox_msg_handle_t handle); |
David Hu | 49ec08a | 2019-09-23 16:13:41 +0800 | [diff] [blame] | 58 | |
| 59 | /** |
| 60 | * \brief NSPE mailbox initialization |
| 61 | * |
| 62 | * \param[in] queue The base address of NSPE mailbox queue to be |
| 63 | * initialized. |
| 64 | * |
| 65 | * \retval MAILBOX_SUCCESS Operation succeeded. |
| 66 | * \retval Other return code Operation failed with an error code. |
| 67 | */ |
David Hu | dbafa3e | 2019-10-22 11:26:37 +0800 | [diff] [blame^] | 68 | int32_t tfm_ns_mailbox_init(struct ns_mailbox_queue_t *queue); |
David Hu | 49ec08a | 2019-09-23 16:13:41 +0800 | [diff] [blame] | 69 | |
| 70 | /** |
| 71 | * \brief Platform specific NSPE mailbox initialization. |
David Hu | dbafa3e | 2019-10-22 11:26:37 +0800 | [diff] [blame^] | 72 | * Invoked by \ref tfm_ns_mailbox_init(). |
David Hu | 49ec08a | 2019-09-23 16:13:41 +0800 | [diff] [blame] | 73 | * |
| 74 | * \param[in] queue The base address of NSPE mailbox queue to be |
| 75 | * initialized. |
| 76 | * |
| 77 | * \retval MAILBOX_SUCCESS Operation succeeded. |
| 78 | * \retval Other return code Operation failed with an error code. |
| 79 | */ |
David Hu | dbafa3e | 2019-10-22 11:26:37 +0800 | [diff] [blame^] | 80 | int32_t tfm_ns_mailbox_hal_init(struct ns_mailbox_queue_t *queue); |
David Hu | 49ec08a | 2019-09-23 16:13:41 +0800 | [diff] [blame] | 81 | |
| 82 | /** |
David Hu | dbafa3e | 2019-10-22 11:26:37 +0800 | [diff] [blame^] | 83 | * \brief Notify SPE to deal with the PSA client call sent via mailbox |
| 84 | * |
| 85 | * \note The implementation depends on platform specific hardware and use case. |
| 86 | * |
| 87 | * \retval MAILBOX_SUCCESS Operation succeeded. |
| 88 | * \retval Other return code Operation failed with an error code. |
David Hu | 49ec08a | 2019-09-23 16:13:41 +0800 | [diff] [blame] | 89 | */ |
David Hu | dbafa3e | 2019-10-22 11:26:37 +0800 | [diff] [blame^] | 90 | int32_t tfm_ns_mailbox_hal_notify_peer(void); |
David Hu | 49ec08a | 2019-09-23 16:13:41 +0800 | [diff] [blame] | 91 | |
| 92 | /** |
David Hu | dbafa3e | 2019-10-22 11:26:37 +0800 | [diff] [blame^] | 93 | * \brief Enter critical section of NSPE mailbox. |
| 94 | * |
| 95 | * \note The implementation depends on platform specific hardware and use case. |
David Hu | 49ec08a | 2019-09-23 16:13:41 +0800 | [diff] [blame] | 96 | */ |
David Hu | dbafa3e | 2019-10-22 11:26:37 +0800 | [diff] [blame^] | 97 | void tfm_ns_mailbox_hal_enter_critical(void); |
| 98 | |
| 99 | /** |
| 100 | * \brief Exit critical section of NSPE mailbox. |
| 101 | * |
| 102 | * \note The implementation depends on platform specific hardware and use case. |
| 103 | */ |
| 104 | void tfm_ns_mailbox_hal_exit_critical(void); |
| 105 | |
| 106 | #ifdef __cplusplus |
| 107 | } |
| 108 | #endif |
David Hu | 49ec08a | 2019-09-23 16:13:41 +0800 | [diff] [blame] | 109 | |
| 110 | #endif /* __TFM_NS_MAILBOX_H__ */ |