David Hu | 49ec08a | 2019-09-23 16:13:41 +0800 | [diff] [blame] | 1 | /* |
David Hu | 1bd1c7b | 2020-05-09 14:13:20 +0800 | [diff] [blame] | 2 | * Copyright (c) 2019-2021, Arm Limited. All rights reserved. |
David Hu | 49ec08a | 2019-09-23 16:13:41 +0800 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | * |
| 6 | */ |
| 7 | |
| 8 | /* |
| 9 | * This is header file of common mailbox objects shared by NSPE and SPE. |
| 10 | * Please refer to tfm_ns_mailbox.h for the definitions only used in NSPE |
| 11 | * mailbox library. |
| 12 | * Please refer to tfm_spe_mailbox.h for the SPE specific definitions and APIs. |
| 13 | */ |
| 14 | |
| 15 | #ifndef __TFM_MAILBOX_H__ |
| 16 | #define __TFM_MAILBOX_H__ |
| 17 | |
David Hu | 3684ee7 | 2019-11-12 18:43:34 +0800 | [diff] [blame] | 18 | #include <stdbool.h> |
David Hu | 49ec08a | 2019-09-23 16:13:41 +0800 | [diff] [blame] | 19 | #include <stdint.h> |
| 20 | #include <stddef.h> |
David Hu | de3f79f | 2019-11-14 16:56:51 +0800 | [diff] [blame] | 21 | #ifdef TFM_MULTI_CORE_MULTI_CLIENT_CALL |
| 22 | #include "device_cfg.h" |
| 23 | #endif |
David Hu | 49ec08a | 2019-09-23 16:13:41 +0800 | [diff] [blame] | 24 | #include "psa/client.h" |
| 25 | |
David Hu | 4904152 | 2019-11-18 13:48:09 +0800 | [diff] [blame] | 26 | #ifdef __cplusplus |
| 27 | extern "C" { |
| 28 | #endif |
| 29 | |
David Hu | 49ec08a | 2019-09-23 16:13:41 +0800 | [diff] [blame] | 30 | /* |
David Hu | de3f79f | 2019-11-14 16:56:51 +0800 | [diff] [blame] | 31 | * If multiple outstanding NS PSA Client calls is enabled, multi-core platform |
| 32 | * should define the number of mailbox queue slots NUM_MAILBOX_QUEUE_SLOT in |
| 33 | * platform device_cfg.h. |
| 34 | * Otherwise, NUM_MAILBOX_QUEUE_SLOT is defined as 1. |
David Hu | 49ec08a | 2019-09-23 16:13:41 +0800 | [diff] [blame] | 35 | */ |
David Hu | de3f79f | 2019-11-14 16:56:51 +0800 | [diff] [blame] | 36 | #ifdef TFM_MULTI_CORE_MULTI_CLIENT_CALL |
| 37 | #ifndef NUM_MAILBOX_QUEUE_SLOT |
| 38 | #error "Error: Platform doesn't define NUM_MAILBOX_QUEUE_SLOT for mailbox queue" |
| 39 | #endif |
| 40 | |
| 41 | #if (NUM_MAILBOX_QUEUE_SLOT < 2) |
| 42 | #error "Error: Invalid NUM_MAILBOX_QUEUE_SLOT. The value should be more than 1" |
| 43 | #endif |
| 44 | |
| 45 | /* |
| 46 | * The number of slots should be no more than the number of bits in |
| 47 | * mailbox_queue_status_t. |
| 48 | * Here the value is hardcoded. A better way is to define a sizeof() to |
| 49 | * calculate the bits in mailbox_queue_status_t and dump it with pragma message. |
| 50 | */ |
| 51 | #if (NUM_MAILBOX_QUEUE_SLOT > 32) |
| 52 | #error "Error: Invalid NUM_MAILBOX_QUEUE_SLOT. The value should be no more than 32" |
| 53 | #endif |
| 54 | #else /* TFM_MULTI_CORE_MULTI_CLIENT_CALL */ |
| 55 | /* Force the number of mailbox queue slots as 1. */ |
| 56 | #undef NUM_MAILBOX_QUEUE_SLOT |
David Hu | 49ec08a | 2019-09-23 16:13:41 +0800 | [diff] [blame] | 57 | #define NUM_MAILBOX_QUEUE_SLOT (1) |
David Hu | de3f79f | 2019-11-14 16:56:51 +0800 | [diff] [blame] | 58 | #endif /* TFM_MULTI_CORE_MULTI_CLIENT_CALL */ |
David Hu | 49ec08a | 2019-09-23 16:13:41 +0800 | [diff] [blame] | 59 | |
| 60 | /* PSA client call type value */ |
| 61 | #define MAILBOX_PSA_FRAMEWORK_VERSION (0x1) |
| 62 | #define MAILBOX_PSA_VERSION (0x2) |
| 63 | #define MAILBOX_PSA_CONNECT (0x3) |
| 64 | #define MAILBOX_PSA_CALL (0x4) |
| 65 | #define MAILBOX_PSA_CLOSE (0x5) |
| 66 | |
| 67 | /* Return code of mailbox APIs */ |
| 68 | #define MAILBOX_SUCCESS (0) |
| 69 | #define MAILBOX_QUEUE_FULL (INT32_MIN + 1) |
| 70 | #define MAILBOX_INVAL_PARAMS (INT32_MIN + 2) |
| 71 | #define MAILBOX_NO_PERMS (INT32_MIN + 3) |
| 72 | #define MAILBOX_NO_PEND_EVENT (INT32_MIN + 4) |
| 73 | #define MAILBOX_CHAN_BUSY (INT32_MIN + 5) |
| 74 | #define MAILBOX_CALLBACK_REG_ERROR (INT32_MIN + 6) |
| 75 | #define MAILBOX_INIT_ERROR (INT32_MIN + 7) |
David Hu | 1bd1c7b | 2020-05-09 14:13:20 +0800 | [diff] [blame] | 76 | #define MAILBOX_GENERIC_ERROR (INT32_MIN + 8) |
David Hu | 49ec08a | 2019-09-23 16:13:41 +0800 | [diff] [blame] | 77 | |
| 78 | /* |
| 79 | * This structure holds the parameters used in a PSA client call. |
| 80 | */ |
| 81 | struct psa_client_params_t { |
| 82 | union { |
| 83 | struct { |
| 84 | uint32_t sid; |
| 85 | } psa_version_params; |
| 86 | |
| 87 | struct { |
| 88 | uint32_t sid; |
Jaykumar Pitambarbhai Patel | 3a98602 | 2019-10-08 17:37:15 +0530 | [diff] [blame] | 89 | uint32_t version; |
David Hu | 49ec08a | 2019-09-23 16:13:41 +0800 | [diff] [blame] | 90 | } psa_connect_params; |
| 91 | |
| 92 | struct { |
| 93 | psa_handle_t handle; |
| 94 | int32_t type; |
| 95 | const psa_invec *in_vec; |
| 96 | size_t in_len; |
| 97 | psa_outvec *out_vec; |
| 98 | size_t out_len; |
| 99 | } psa_call_params; |
| 100 | |
| 101 | struct { |
| 102 | psa_handle_t handle; |
| 103 | } psa_close_params; |
| 104 | }; |
| 105 | }; |
| 106 | |
| 107 | /* Mailbox message passed from NSPE to SPE to deliver a PSA client call */ |
| 108 | struct mailbox_msg_t { |
| 109 | uint32_t call_type; /* PSA client call type */ |
| 110 | struct psa_client_params_t params; /* Contain parameters used in PSA |
| 111 | * client call |
| 112 | */ |
| 113 | |
| 114 | int32_t client_id; /* Optional client ID of the |
| 115 | * non-secure caller. |
| 116 | * It is required to identify the |
| 117 | * non-secure task when NSPE OS |
| 118 | * enforces non-secure task isolation |
| 119 | */ |
| 120 | }; |
| 121 | |
David Hu | 49ec08a | 2019-09-23 16:13:41 +0800 | [diff] [blame] | 122 | /* |
| 123 | * Mailbox reply structure in non-secure memory |
| 124 | * to hold the PSA client call return result from SPE |
| 125 | */ |
| 126 | struct mailbox_reply_t { |
| 127 | int32_t return_val; |
| 128 | }; |
| 129 | |
| 130 | /* A single slot structure in NSPE mailbox queue */ |
| 131 | struct ns_mailbox_slot_t { |
| 132 | struct mailbox_msg_t msg; |
| 133 | struct mailbox_reply_t reply; |
David Hu | 3684ee7 | 2019-11-12 18:43:34 +0800 | [diff] [blame] | 134 | const void *owner; /* Handle of the owner task of this |
| 135 | * slot |
| 136 | */ |
| 137 | bool is_woken; /* Indicate that owner task has been |
| 138 | * or should be woken up, after the |
| 139 | * replied is received. |
| 140 | */ |
David Hu | 49ec08a | 2019-09-23 16:13:41 +0800 | [diff] [blame] | 141 | }; |
| 142 | |
| 143 | typedef uint32_t mailbox_queue_status_t; |
| 144 | |
| 145 | /* NSPE mailbox queue */ |
| 146 | struct ns_mailbox_queue_t { |
| 147 | mailbox_queue_status_t empty_slots; /* Bitmask of empty slots */ |
| 148 | mailbox_queue_status_t pend_slots; /* Bitmask of slots pending |
| 149 | * for SPE handling |
| 150 | */ |
| 151 | mailbox_queue_status_t replied_slots; /* Bitmask of active slots |
| 152 | * containing PSA client call |
| 153 | * return result |
| 154 | */ |
| 155 | |
| 156 | struct ns_mailbox_slot_t queue[NUM_MAILBOX_QUEUE_SLOT]; |
David Hu | 65cbfb8 | 2019-11-15 17:18:12 +0800 | [diff] [blame] | 157 | |
| 158 | #ifdef TFM_MULTI_CORE_TEST |
| 159 | uint32_t nr_tx; /* The total number of |
| 160 | * submission of NS PSA Client |
| 161 | * calls from NS task via |
| 162 | * mailbox. |
| 163 | */ |
| 164 | uint32_t nr_used_slots; /* The total number of used |
| 165 | * mailbox queue slots each time |
| 166 | * NS thread requests a mailbox |
| 167 | * queue slot. |
| 168 | */ |
| 169 | #endif |
David Hu | 49ec08a | 2019-09-23 16:13:41 +0800 | [diff] [blame] | 170 | }; |
| 171 | |
David Hu | 4904152 | 2019-11-18 13:48:09 +0800 | [diff] [blame] | 172 | #ifdef __cplusplus |
| 173 | } |
| 174 | #endif |
| 175 | |
David Hu | 49ec08a | 2019-09-23 16:13:41 +0800 | [diff] [blame] | 176 | #endif /* __TFM_MAILBOX_H__ */ |