David Hu | 49ec08a | 2019-09-23 16:13:41 +0800 | [diff] [blame] | 1 | /* |
David Hu | de3f79f | 2019-11-14 16:56:51 +0800 | [diff] [blame] | 2 | * Copyright (c) 2019-2020, 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) |
| 76 | |
| 77 | /* |
| 78 | * This structure holds the parameters used in a PSA client call. |
| 79 | */ |
| 80 | struct psa_client_params_t { |
| 81 | union { |
| 82 | struct { |
| 83 | uint32_t sid; |
| 84 | } psa_version_params; |
| 85 | |
| 86 | struct { |
| 87 | uint32_t sid; |
Jaykumar Pitambarbhai Patel | 3a98602 | 2019-10-08 17:37:15 +0530 | [diff] [blame] | 88 | uint32_t version; |
David Hu | 49ec08a | 2019-09-23 16:13:41 +0800 | [diff] [blame] | 89 | } psa_connect_params; |
| 90 | |
| 91 | struct { |
| 92 | psa_handle_t handle; |
| 93 | int32_t type; |
| 94 | const psa_invec *in_vec; |
| 95 | size_t in_len; |
| 96 | psa_outvec *out_vec; |
| 97 | size_t out_len; |
| 98 | } psa_call_params; |
| 99 | |
| 100 | struct { |
| 101 | psa_handle_t handle; |
| 102 | } psa_close_params; |
| 103 | }; |
| 104 | }; |
| 105 | |
| 106 | /* Mailbox message passed from NSPE to SPE to deliver a PSA client call */ |
| 107 | struct mailbox_msg_t { |
| 108 | uint32_t call_type; /* PSA client call type */ |
| 109 | struct psa_client_params_t params; /* Contain parameters used in PSA |
| 110 | * client call |
| 111 | */ |
| 112 | |
| 113 | int32_t client_id; /* Optional client ID of the |
| 114 | * non-secure caller. |
| 115 | * It is required to identify the |
| 116 | * non-secure task when NSPE OS |
| 117 | * enforces non-secure task isolation |
| 118 | */ |
| 119 | }; |
| 120 | |
| 121 | /* A handle to a mailbox message in use */ |
| 122 | typedef int32_t mailbox_msg_handle_t; |
| 123 | |
| 124 | #define MAILBOX_MSG_NULL_HANDLE ((mailbox_msg_handle_t)0) |
| 125 | |
| 126 | /* |
| 127 | * Mailbox reply structure in non-secure memory |
| 128 | * to hold the PSA client call return result from SPE |
| 129 | */ |
| 130 | struct mailbox_reply_t { |
| 131 | int32_t return_val; |
| 132 | }; |
| 133 | |
| 134 | /* A single slot structure in NSPE mailbox queue */ |
| 135 | struct ns_mailbox_slot_t { |
| 136 | struct mailbox_msg_t msg; |
| 137 | struct mailbox_reply_t reply; |
David Hu | 3684ee7 | 2019-11-12 18:43:34 +0800 | [diff] [blame] | 138 | const void *owner; /* Handle of the owner task of this |
| 139 | * slot |
| 140 | */ |
| 141 | bool is_woken; /* Indicate that owner task has been |
| 142 | * or should be woken up, after the |
| 143 | * replied is received. |
| 144 | */ |
David Hu | 49ec08a | 2019-09-23 16:13:41 +0800 | [diff] [blame] | 145 | }; |
| 146 | |
| 147 | typedef uint32_t mailbox_queue_status_t; |
| 148 | |
| 149 | /* NSPE mailbox queue */ |
| 150 | struct ns_mailbox_queue_t { |
| 151 | mailbox_queue_status_t empty_slots; /* Bitmask of empty slots */ |
| 152 | mailbox_queue_status_t pend_slots; /* Bitmask of slots pending |
| 153 | * for SPE handling |
| 154 | */ |
| 155 | mailbox_queue_status_t replied_slots; /* Bitmask of active slots |
| 156 | * containing PSA client call |
| 157 | * return result |
| 158 | */ |
| 159 | |
| 160 | struct ns_mailbox_slot_t queue[NUM_MAILBOX_QUEUE_SLOT]; |
David Hu | 65cbfb8 | 2019-11-15 17:18:12 +0800 | [diff] [blame] | 161 | |
| 162 | #ifdef TFM_MULTI_CORE_TEST |
| 163 | uint32_t nr_tx; /* The total number of |
| 164 | * submission of NS PSA Client |
| 165 | * calls from NS task via |
| 166 | * mailbox. |
| 167 | */ |
| 168 | uint32_t nr_used_slots; /* The total number of used |
| 169 | * mailbox queue slots each time |
| 170 | * NS thread requests a mailbox |
| 171 | * queue slot. |
| 172 | */ |
| 173 | #endif |
David Hu | 49ec08a | 2019-09-23 16:13:41 +0800 | [diff] [blame] | 174 | }; |
| 175 | |
David Hu | 4904152 | 2019-11-18 13:48:09 +0800 | [diff] [blame] | 176 | #ifdef __cplusplus |
| 177 | } |
| 178 | #endif |
| 179 | |
David Hu | 49ec08a | 2019-09-23 16:13:41 +0800 | [diff] [blame] | 180 | #endif /* __TFM_MAILBOX_H__ */ |