David Hu | 733d8f9 | 2019-09-23 15:32:40 +0800 | [diff] [blame] | 1 | /* |
Xinyu Zhang | 669744c | 2023-02-06 15:24:26 +0800 | [diff] [blame] | 2 | * Copyright (c) 2019-2023, Arm Limited. All rights reserved. |
BohdanHunko | 628109f | 2023-01-31 17:23:35 +0200 | [diff] [blame] | 3 | * Copyright (c) 2022-2023 Cypress Semiconductor Corporation (an Infineon |
Chris Brand | 10a2acb | 2022-10-18 17:12:27 -0700 | [diff] [blame] | 4 | * company) or an affiliate of Cypress Semiconductor Corporation. All rights |
| 5 | * reserved. |
David Hu | 733d8f9 | 2019-09-23 15:32:40 +0800 | [diff] [blame] | 6 | * |
| 7 | * SPDX-License-Identifier: BSD-3-Clause |
| 8 | * |
| 9 | */ |
| 10 | |
Mingyang Sun | eeca465 | 2021-07-15 15:19:16 +0800 | [diff] [blame] | 11 | #include <stdint.h> |
Mingyang Sun | b26b280 | 2021-07-07 11:25:00 +0800 | [diff] [blame] | 12 | #include "bitops.h" |
Mingyang Sun | 4609ac7 | 2022-02-08 18:56:35 +0800 | [diff] [blame] | 13 | #include "config_impl.h" |
Xinyu Zhang | cdbe362 | 2022-10-31 14:34:25 +0800 | [diff] [blame] | 14 | #include "config_spm.h" |
Ken Liu | 92ede9f | 2021-10-20 09:35:00 +0800 | [diff] [blame] | 15 | #include "critical_section.h" |
Mingyang Sun | eeca465 | 2021-07-15 15:19:16 +0800 | [diff] [blame] | 16 | #include "psa/lifecycle.h" |
David Hu | 733d8f9 | 2019-09-23 15:32:40 +0800 | [diff] [blame] | 17 | #include "psa/service.h" |
Kevin Peng | 3f67b2e | 2021-10-18 17:47:27 +0800 | [diff] [blame] | 18 | #include "interrupt.h" |
Sherry Zhang | c714702 | 2023-02-03 11:21:10 +0800 | [diff] [blame] | 19 | #include "spm.h" |
Mingyang Sun | 22a3faf | 2021-07-09 15:32:47 +0800 | [diff] [blame] | 20 | #include "tfm_arch.h" |
Mingyang Sun | b26b280 | 2021-07-07 11:25:00 +0800 | [diff] [blame] | 21 | #include "load/partition_defs.h" |
Mingyang Sun | 2b35266 | 2021-04-21 11:35:43 +0800 | [diff] [blame] | 22 | #include "load/service_defs.h" |
Ken Liu | 3dd9256 | 2021-08-17 16:22:54 +0800 | [diff] [blame] | 23 | #include "load/interrupt_defs.h" |
Summer Qin | 5fdcf63 | 2020-06-22 16:49:24 +0800 | [diff] [blame] | 24 | #include "utilities.h" |
Mingyang Sun | deae45d | 2021-09-06 15:31:07 +0800 | [diff] [blame] | 25 | #include "ffm/backend.h" |
Ken Liu | e07c3b7 | 2021-10-14 16:19:13 +0800 | [diff] [blame] | 26 | #include "ffm/psa_api.h" |
Mingyang Sun | b26b280 | 2021-07-07 11:25:00 +0800 | [diff] [blame] | 27 | #include "tfm_rpc.h" |
Kevin Peng | b42ed86 | 2022-08-08 14:44:02 +0800 | [diff] [blame] | 28 | #include "tfm_api.h" |
Kevin Peng | d399a1f | 2021-09-08 15:33:14 +0800 | [diff] [blame] | 29 | #include "tfm_hal_interrupt.h" |
Mingyang Sun | b26b280 | 2021-07-07 11:25:00 +0800 | [diff] [blame] | 30 | #include "tfm_hal_platform.h" |
Ken Liu | 82e3eac | 2021-10-14 16:19:13 +0800 | [diff] [blame] | 31 | #include "tfm_psa_call_pack.h" |
Summer Qin | 56725eb | 2022-05-06 15:23:40 +0800 | [diff] [blame] | 32 | #include "tfm_hal_isolation.h" |
David Hu | 733d8f9 | 2019-09-23 15:32:40 +0800 | [diff] [blame] | 33 | |
Shawn Shan | 038348e | 2021-09-08 17:11:04 +0800 | [diff] [blame] | 34 | #if PSA_FRAMEWORK_HAS_MM_IOVEC |
| 35 | |
| 36 | /* |
| 37 | * The MM-IOVEC status |
| 38 | * The max total number of invec and outvec is 8. |
| 39 | * Each invec/outvec takes 4 bit, 32 bits in total. |
| 40 | * |
| 41 | * The encoding format of the MM-IOVEC status: |
| 42 | *-------------------------------------------------------------- |
| 43 | *| Bit | 31 - 28 | 27 - 24 | ... | 7 - 4 | 3 - 0 | |
| 44 | *-------------------------------------------------------------- |
| 45 | *| Vector | outvec[3] | outvec[2] | ... | invec[1] | invec[0] | |
| 46 | *-------------------------------------------------------------- |
| 47 | * |
| 48 | * Take invec[0] as an example: |
| 49 | * |
| 50 | * bit 0: whether invec[0] has been mapped. |
| 51 | * bit 1: whether invec[0] has been unmapped. |
| 52 | * bit 2: whether invec[0] has been accessed using psa_read(), psa_skip() or |
| 53 | * psa_write(). |
| 54 | * bit 3: reserved for invec[0]. |
| 55 | */ |
| 56 | |
| 57 | #define IOVEC_STATUS_BITS 4 /* Each vector occupies 4 bits. */ |
| 58 | #define OUTVEC_IDX_BASE 4 /* |
| 59 | * Base index of outvec. |
| 60 | * There are four invecs in front of |
| 61 | * outvec. |
| 62 | */ |
| 63 | #define INVEC_IDX_BASE 0 /* Base index of invec. */ |
| 64 | |
| 65 | #define IOVEC_MAPPED_BIT (1U << 0) |
| 66 | #define IOVEC_UNMAPPED_BIT (1U << 1) |
| 67 | #define IOVEC_ACCESSED_BIT (1U << 2) |
| 68 | |
Mingyang Sun | a09adda | 2022-02-16 18:11:33 +0800 | [diff] [blame] | 69 | #define IOVEC_IS_MAPPED(handle, iovec_idx) \ |
| 70 | ((((handle)->iovec_status) >> ((iovec_idx) * IOVEC_STATUS_BITS)) & \ |
Shawn Shan | 038348e | 2021-09-08 17:11:04 +0800 | [diff] [blame] | 71 | IOVEC_MAPPED_BIT) |
Mingyang Sun | a09adda | 2022-02-16 18:11:33 +0800 | [diff] [blame] | 72 | #define IOVEC_IS_UNMAPPED(handle, iovec_idx) \ |
| 73 | ((((handle)->iovec_status) >> ((iovec_idx) * IOVEC_STATUS_BITS)) & \ |
Shawn Shan | 038348e | 2021-09-08 17:11:04 +0800 | [diff] [blame] | 74 | IOVEC_UNMAPPED_BIT) |
Mingyang Sun | a09adda | 2022-02-16 18:11:33 +0800 | [diff] [blame] | 75 | #define IOVEC_IS_ACCESSED(handle, iovec_idx) \ |
| 76 | ((((handle)->iovec_status) >> ((iovec_idx) * IOVEC_STATUS_BITS)) & \ |
Shawn Shan | 038348e | 2021-09-08 17:11:04 +0800 | [diff] [blame] | 77 | IOVEC_ACCESSED_BIT) |
Mingyang Sun | a09adda | 2022-02-16 18:11:33 +0800 | [diff] [blame] | 78 | #define SET_IOVEC_MAPPED(handle, iovec_idx) \ |
| 79 | (((handle)->iovec_status) |= (IOVEC_MAPPED_BIT << \ |
Shawn Shan | 038348e | 2021-09-08 17:11:04 +0800 | [diff] [blame] | 80 | ((iovec_idx) * IOVEC_STATUS_BITS))) |
Mingyang Sun | a09adda | 2022-02-16 18:11:33 +0800 | [diff] [blame] | 81 | #define SET_IOVEC_UNMAPPED(handle, iovec_idx) \ |
| 82 | (((handle)->iovec_status) |= (IOVEC_UNMAPPED_BIT << \ |
Shawn Shan | 038348e | 2021-09-08 17:11:04 +0800 | [diff] [blame] | 83 | ((iovec_idx) * IOVEC_STATUS_BITS))) |
Mingyang Sun | a09adda | 2022-02-16 18:11:33 +0800 | [diff] [blame] | 84 | #define SET_IOVEC_ACCESSED(handle, iovec_idx) \ |
| 85 | (((handle)->iovec_status) |= (IOVEC_ACCESSED_BIT << \ |
Shawn Shan | 038348e | 2021-09-08 17:11:04 +0800 | [diff] [blame] | 86 | ((iovec_idx) * IOVEC_STATUS_BITS))) |
| 87 | |
| 88 | #endif /* PSA_FRAMEWORK_HAS_MM_IOVEC */ |
| 89 | |
Xinyu Zhang | b287ef8 | 2021-11-03 18:38:50 +0800 | [diff] [blame] | 90 | void spm_handle_programmer_errors(psa_status_t status) |
| 91 | { |
Summer Qin | d9d497b | 2022-04-14 14:39:26 +0800 | [diff] [blame] | 92 | if (status == PSA_ERROR_PROGRAMMER_ERROR || |
| 93 | status == PSA_ERROR_CONNECTION_REFUSED) { |
| 94 | if (!tfm_spm_is_ns_caller()) { |
Xinyu Zhang | b287ef8 | 2021-11-03 18:38:50 +0800 | [diff] [blame] | 95 | tfm_core_panic(); |
Summer Qin | d9d497b | 2022-04-14 14:39:26 +0800 | [diff] [blame] | 96 | } |
Xinyu Zhang | b287ef8 | 2021-11-03 18:38:50 +0800 | [diff] [blame] | 97 | } |
| 98 | } |
| 99 | |
Mingyang Sun | eeca465 | 2021-07-15 15:19:16 +0800 | [diff] [blame] | 100 | uint32_t tfm_spm_get_lifecycle_state(void) |
| 101 | { |
| 102 | /* |
| 103 | * FixMe: return PSA_LIFECYCLE_UNKNOWN to the caller directly. It will be |
| 104 | * implemented in the future. |
| 105 | */ |
| 106 | return PSA_LIFECYCLE_UNKNOWN; |
| 107 | } |
| 108 | |
Mingyang Sun | eeca465 | 2021-07-15 15:19:16 +0800 | [diff] [blame] | 109 | /* PSA Partition API function body */ |
| 110 | |
Kevin Peng | def92de | 2021-11-10 16:14:48 +0800 | [diff] [blame] | 111 | #if CONFIG_TFM_SPM_BACKEND_IPC == 1 \ |
| 112 | || CONFIG_TFM_FLIH_API == 1 || CONFIG_TFM_SLIH_API == 1 |
Mingyang Sun | b26b280 | 2021-07-07 11:25:00 +0800 | [diff] [blame] | 113 | psa_signal_t tfm_spm_partition_psa_wait(psa_signal_t signal_mask, |
| 114 | uint32_t timeout) |
| 115 | { |
| 116 | struct partition_t *partition = NULL; |
| 117 | |
| 118 | /* |
| 119 | * Timeout[30:0] are reserved for future use. |
| 120 | * SPM must ignore the value of RES. |
| 121 | */ |
| 122 | timeout &= PSA_TIMEOUT_MASK; |
| 123 | |
Kevin Peng | cdf3ae2 | 2022-01-19 14:53:52 +0800 | [diff] [blame] | 124 | partition = GET_CURRENT_COMPONENT(); |
Mingyang Sun | b26b280 | 2021-07-07 11:25:00 +0800 | [diff] [blame] | 125 | |
| 126 | /* |
Ruchika Gupta | d183417 | 2022-06-15 12:03:08 +0530 | [diff] [blame] | 127 | * signals_allowed can be 0 for TF-M internal partitions for special usages. |
| 128 | * Regular Secure Partitions should have at least one signal. |
| 129 | * This is gauranteed by the manifest tool. |
Mingyang Sun | b26b280 | 2021-07-07 11:25:00 +0800 | [diff] [blame] | 130 | * It is a PROGRAMMER ERROR if the signal_mask does not include any assigned |
| 131 | * signals. |
| 132 | */ |
Ruchika Gupta | d183417 | 2022-06-15 12:03:08 +0530 | [diff] [blame] | 133 | if ((partition->signals_allowed) && |
| 134 | (partition->signals_allowed & signal_mask) == 0) { |
Mingyang Sun | b26b280 | 2021-07-07 11:25:00 +0800 | [diff] [blame] | 135 | tfm_core_panic(); |
| 136 | } |
| 137 | |
| 138 | /* |
shejia01 | 95a88bc | 2023-01-16 15:44:46 +0800 | [diff] [blame] | 139 | * After new signal(s) are available, the return value will be updated in |
| 140 | * PendSV and blocked thread gets to run. |
Mingyang Sun | b26b280 | 2021-07-07 11:25:00 +0800 | [diff] [blame] | 141 | */ |
Mingyang Sun | 5c9529f | 2022-03-15 17:51:56 +0800 | [diff] [blame] | 142 | if (timeout == PSA_BLOCK) { |
shejia01 | 95a88bc | 2023-01-16 15:44:46 +0800 | [diff] [blame] | 143 | return backend_wait_signals(partition, signal_mask); |
| 144 | } else { |
| 145 | return partition->signals_asserted & signal_mask; |
Mingyang Sun | b26b280 | 2021-07-07 11:25:00 +0800 | [diff] [blame] | 146 | } |
Mingyang Sun | b26b280 | 2021-07-07 11:25:00 +0800 | [diff] [blame] | 147 | } |
Kevin Peng | def92de | 2021-11-10 16:14:48 +0800 | [diff] [blame] | 148 | #endif |
Mingyang Sun | b26b280 | 2021-07-07 11:25:00 +0800 | [diff] [blame] | 149 | |
Kevin Peng | def92de | 2021-11-10 16:14:48 +0800 | [diff] [blame] | 150 | #if CONFIG_TFM_SPM_BACKEND_IPC == 1 |
Mingyang Sun | b26b280 | 2021-07-07 11:25:00 +0800 | [diff] [blame] | 151 | psa_status_t tfm_spm_partition_psa_get(psa_signal_t signal, psa_msg_t *msg) |
| 152 | { |
Ken Liu | c9313eb | 2023-02-22 15:45:54 +0800 | [diff] [blame] | 153 | struct connection_t *handle = NULL; |
Mingyang Sun | b26b280 | 2021-07-07 11:25:00 +0800 | [diff] [blame] | 154 | struct partition_t *partition = NULL; |
Xinyu Zhang | 6ad0703 | 2022-08-10 14:45:56 +0800 | [diff] [blame] | 155 | fih_int fih_rc = FIH_FAILURE; |
Mingyang Sun | b26b280 | 2021-07-07 11:25:00 +0800 | [diff] [blame] | 156 | |
| 157 | /* |
| 158 | * Only one message could be retrieved every time for psa_get(). It is a |
| 159 | * fatal error if the input signal has more than a signal bit set. |
| 160 | */ |
| 161 | if (!IS_ONLY_ONE_BIT_IN_UINT32(signal)) { |
| 162 | tfm_core_panic(); |
| 163 | } |
| 164 | |
Kevin Peng | cdf3ae2 | 2022-01-19 14:53:52 +0800 | [diff] [blame] | 165 | partition = GET_CURRENT_COMPONENT(); |
| 166 | |
Mingyang Sun | b26b280 | 2021-07-07 11:25:00 +0800 | [diff] [blame] | 167 | /* |
| 168 | * Write the message to the service buffer. It is a fatal error if the |
| 169 | * input msg pointer is not a valid memory reference or not read-write. |
| 170 | */ |
Xinyu Zhang | 6ad0703 | 2022-08-10 14:45:56 +0800 | [diff] [blame] | 171 | FIH_CALL(tfm_hal_memory_check, fih_rc, |
| 172 | partition->boundary, (uintptr_t)msg, |
| 173 | sizeof(psa_msg_t), TFM_HAL_ACCESS_READWRITE); |
| 174 | if (fih_not_eq(fih_rc, fih_int_encode(PSA_SUCCESS))) { |
Mingyang Sun | b26b280 | 2021-07-07 11:25:00 +0800 | [diff] [blame] | 175 | tfm_core_panic(); |
| 176 | } |
| 177 | |
| 178 | /* |
| 179 | * It is a fatal error if the caller call psa_get() when no message has |
| 180 | * been set. The caller must call this function after an RoT Service signal |
| 181 | * is returned by psa_wait(). |
| 182 | */ |
| 183 | if (partition->signals_asserted == 0) { |
| 184 | tfm_core_panic(); |
| 185 | } |
| 186 | |
| 187 | /* |
| 188 | * It is a fatal error if the RoT Service signal is not currently asserted. |
| 189 | */ |
| 190 | if ((partition->signals_asserted & signal) == 0) { |
| 191 | tfm_core_panic(); |
| 192 | } |
| 193 | |
| 194 | /* |
| 195 | * Get message by signal from partition. It is a fatal error if getting |
| 196 | * failed, which means the input signal is not correspond to an RoT service. |
| 197 | */ |
Mingyang Sun | a09adda | 2022-02-16 18:11:33 +0800 | [diff] [blame] | 198 | handle = spm_get_handle_by_signal(partition, signal); |
| 199 | if (!handle) { |
Mingyang Sun | b26b280 | 2021-07-07 11:25:00 +0800 | [diff] [blame] | 200 | return PSA_ERROR_DOES_NOT_EXIST; |
| 201 | } |
| 202 | |
Mingyang Sun | a09adda | 2022-02-16 18:11:33 +0800 | [diff] [blame] | 203 | spm_memcpy(msg, &handle->msg, sizeof(psa_msg_t)); |
Mingyang Sun | b26b280 | 2021-07-07 11:25:00 +0800 | [diff] [blame] | 204 | |
| 205 | return PSA_SUCCESS; |
| 206 | } |
Mingyang Sun | 4609ac7 | 2022-02-08 18:56:35 +0800 | [diff] [blame] | 207 | #endif |
Mingyang Sun | b26b280 | 2021-07-07 11:25:00 +0800 | [diff] [blame] | 208 | |
Mingyang Sun | b26b280 | 2021-07-07 11:25:00 +0800 | [diff] [blame] | 209 | size_t tfm_spm_partition_psa_read(psa_handle_t msg_handle, uint32_t invec_idx, |
| 210 | void *buffer, size_t num_bytes) |
| 211 | { |
| 212 | size_t bytes; |
Ken Liu | c9313eb | 2023-02-22 15:45:54 +0800 | [diff] [blame] | 213 | struct connection_t *handle = NULL; |
Summer Qin | 56725eb | 2022-05-06 15:23:40 +0800 | [diff] [blame] | 214 | struct partition_t *curr_partition = GET_CURRENT_COMPONENT(); |
Xinyu Zhang | 6ad0703 | 2022-08-10 14:45:56 +0800 | [diff] [blame] | 215 | fih_int fih_rc = FIH_FAILURE; |
Mingyang Sun | b26b280 | 2021-07-07 11:25:00 +0800 | [diff] [blame] | 216 | |
| 217 | /* It is a fatal error if message handle is invalid */ |
Ken Liu | c9313eb | 2023-02-22 15:45:54 +0800 | [diff] [blame] | 218 | handle = spm_msg_handle_to_connection(msg_handle); |
Mingyang Sun | a09adda | 2022-02-16 18:11:33 +0800 | [diff] [blame] | 219 | if (!handle) { |
Mingyang Sun | b26b280 | 2021-07-07 11:25:00 +0800 | [diff] [blame] | 220 | tfm_core_panic(); |
| 221 | } |
| 222 | |
Mingyang Sun | b26b280 | 2021-07-07 11:25:00 +0800 | [diff] [blame] | 223 | /* |
| 224 | * It is a fatal error if message handle does not refer to a request |
| 225 | * message |
| 226 | */ |
Mingyang Sun | a09adda | 2022-02-16 18:11:33 +0800 | [diff] [blame] | 227 | if (handle->msg.type < PSA_IPC_CALL) { |
Mingyang Sun | b26b280 | 2021-07-07 11:25:00 +0800 | [diff] [blame] | 228 | tfm_core_panic(); |
| 229 | } |
| 230 | |
| 231 | /* |
| 232 | * It is a fatal error if invec_idx is equal to or greater than |
| 233 | * PSA_MAX_IOVEC |
| 234 | */ |
| 235 | if (invec_idx >= PSA_MAX_IOVEC) { |
| 236 | tfm_core_panic(); |
| 237 | } |
| 238 | |
Shawn Shan | 038348e | 2021-09-08 17:11:04 +0800 | [diff] [blame] | 239 | #if PSA_FRAMEWORK_HAS_MM_IOVEC |
| 240 | /* |
| 241 | * It is a fatal error if the input vector has already been mapped using |
| 242 | * psa_map_invec(). |
| 243 | */ |
Mingyang Sun | a09adda | 2022-02-16 18:11:33 +0800 | [diff] [blame] | 244 | if (IOVEC_IS_MAPPED(handle, (invec_idx + INVEC_IDX_BASE))) { |
Shawn Shan | 038348e | 2021-09-08 17:11:04 +0800 | [diff] [blame] | 245 | tfm_core_panic(); |
| 246 | } |
| 247 | |
Mingyang Sun | a09adda | 2022-02-16 18:11:33 +0800 | [diff] [blame] | 248 | SET_IOVEC_ACCESSED(handle, (invec_idx + INVEC_IDX_BASE)); |
Shawn Shan | 038348e | 2021-09-08 17:11:04 +0800 | [diff] [blame] | 249 | #endif |
| 250 | |
Kevin Peng | 016b0e4 | 2022-04-15 11:28:48 +0800 | [diff] [blame] | 251 | /* There was no remaining data in this input vector */ |
| 252 | if (handle->msg.in_size[invec_idx] == 0) { |
| 253 | return 0; |
| 254 | } |
| 255 | |
Mingyang Sun | b26b280 | 2021-07-07 11:25:00 +0800 | [diff] [blame] | 256 | /* |
| 257 | * Copy the client data to the service buffer. It is a fatal error |
| 258 | * if the memory reference for buffer is invalid or not read-write. |
| 259 | */ |
Xinyu Zhang | 6ad0703 | 2022-08-10 14:45:56 +0800 | [diff] [blame] | 260 | FIH_CALL(tfm_hal_memory_check, fih_rc, |
| 261 | curr_partition->boundary, (uintptr_t)buffer, |
| 262 | num_bytes, TFM_HAL_ACCESS_READWRITE); |
| 263 | if (fih_not_eq(fih_rc, fih_int_encode(PSA_SUCCESS))) { |
Mingyang Sun | b26b280 | 2021-07-07 11:25:00 +0800 | [diff] [blame] | 264 | tfm_core_panic(); |
| 265 | } |
| 266 | |
Mingyang Sun | a09adda | 2022-02-16 18:11:33 +0800 | [diff] [blame] | 267 | bytes = num_bytes > handle->msg.in_size[invec_idx] ? |
| 268 | handle->msg.in_size[invec_idx] : num_bytes; |
Mingyang Sun | b26b280 | 2021-07-07 11:25:00 +0800 | [diff] [blame] | 269 | |
Mingyang Sun | a09adda | 2022-02-16 18:11:33 +0800 | [diff] [blame] | 270 | spm_memcpy(buffer, handle->invec[invec_idx].base, bytes); |
Mingyang Sun | b26b280 | 2021-07-07 11:25:00 +0800 | [diff] [blame] | 271 | |
| 272 | /* There maybe some remaining data */ |
Mingyang Sun | a09adda | 2022-02-16 18:11:33 +0800 | [diff] [blame] | 273 | handle->invec[invec_idx].base = |
| 274 | (char *)handle->invec[invec_idx].base + bytes; |
| 275 | handle->msg.in_size[invec_idx] -= bytes; |
Mingyang Sun | b26b280 | 2021-07-07 11:25:00 +0800 | [diff] [blame] | 276 | |
| 277 | return bytes; |
| 278 | } |
| 279 | |
| 280 | size_t tfm_spm_partition_psa_skip(psa_handle_t msg_handle, uint32_t invec_idx, |
| 281 | size_t num_bytes) |
| 282 | { |
Ken Liu | c9313eb | 2023-02-22 15:45:54 +0800 | [diff] [blame] | 283 | struct connection_t *handle = NULL; |
Mingyang Sun | b26b280 | 2021-07-07 11:25:00 +0800 | [diff] [blame] | 284 | |
| 285 | /* It is a fatal error if message handle is invalid */ |
Ken Liu | c9313eb | 2023-02-22 15:45:54 +0800 | [diff] [blame] | 286 | handle = spm_msg_handle_to_connection(msg_handle); |
Mingyang Sun | a09adda | 2022-02-16 18:11:33 +0800 | [diff] [blame] | 287 | if (!handle) { |
Mingyang Sun | b26b280 | 2021-07-07 11:25:00 +0800 | [diff] [blame] | 288 | tfm_core_panic(); |
| 289 | } |
| 290 | |
| 291 | /* |
| 292 | * It is a fatal error if message handle does not refer to a request |
| 293 | * message |
| 294 | */ |
Mingyang Sun | a09adda | 2022-02-16 18:11:33 +0800 | [diff] [blame] | 295 | if (handle->msg.type < PSA_IPC_CALL) { |
Mingyang Sun | b26b280 | 2021-07-07 11:25:00 +0800 | [diff] [blame] | 296 | tfm_core_panic(); |
| 297 | } |
| 298 | |
| 299 | /* |
| 300 | * It is a fatal error if invec_idx is equal to or greater than |
| 301 | * PSA_MAX_IOVEC |
| 302 | */ |
| 303 | if (invec_idx >= PSA_MAX_IOVEC) { |
| 304 | tfm_core_panic(); |
| 305 | } |
| 306 | |
Shawn Shan | 038348e | 2021-09-08 17:11:04 +0800 | [diff] [blame] | 307 | #if PSA_FRAMEWORK_HAS_MM_IOVEC |
| 308 | /* |
| 309 | * It is a fatal error if the input vector has already been mapped using |
| 310 | * psa_map_invec(). |
| 311 | */ |
Mingyang Sun | a09adda | 2022-02-16 18:11:33 +0800 | [diff] [blame] | 312 | if (IOVEC_IS_MAPPED(handle, (invec_idx + INVEC_IDX_BASE))) { |
Shawn Shan | 038348e | 2021-09-08 17:11:04 +0800 | [diff] [blame] | 313 | tfm_core_panic(); |
| 314 | } |
| 315 | |
Mingyang Sun | a09adda | 2022-02-16 18:11:33 +0800 | [diff] [blame] | 316 | SET_IOVEC_ACCESSED(handle, (invec_idx + INVEC_IDX_BASE)); |
Shawn Shan | 038348e | 2021-09-08 17:11:04 +0800 | [diff] [blame] | 317 | #endif |
| 318 | |
Kevin Peng | 016b0e4 | 2022-04-15 11:28:48 +0800 | [diff] [blame] | 319 | /* There was no remaining data in this input vector */ |
| 320 | if (handle->msg.in_size[invec_idx] == 0) { |
| 321 | return 0; |
| 322 | } |
| 323 | |
Mingyang Sun | b26b280 | 2021-07-07 11:25:00 +0800 | [diff] [blame] | 324 | /* |
| 325 | * If num_bytes is greater than the remaining size of the input vector then |
| 326 | * the remaining size of the input vector is used. |
| 327 | */ |
Mingyang Sun | a09adda | 2022-02-16 18:11:33 +0800 | [diff] [blame] | 328 | if (num_bytes > handle->msg.in_size[invec_idx]) { |
| 329 | num_bytes = handle->msg.in_size[invec_idx]; |
Mingyang Sun | b26b280 | 2021-07-07 11:25:00 +0800 | [diff] [blame] | 330 | } |
| 331 | |
| 332 | /* There maybe some remaining data */ |
Mingyang Sun | a09adda | 2022-02-16 18:11:33 +0800 | [diff] [blame] | 333 | handle->invec[invec_idx].base = |
| 334 | (char *)handle->invec[invec_idx].base + num_bytes; |
| 335 | handle->msg.in_size[invec_idx] -= num_bytes; |
Mingyang Sun | b26b280 | 2021-07-07 11:25:00 +0800 | [diff] [blame] | 336 | |
| 337 | return num_bytes; |
| 338 | } |
| 339 | |
| 340 | void tfm_spm_partition_psa_write(psa_handle_t msg_handle, uint32_t outvec_idx, |
| 341 | const void *buffer, size_t num_bytes) |
| 342 | { |
Ken Liu | c9313eb | 2023-02-22 15:45:54 +0800 | [diff] [blame] | 343 | struct connection_t *handle = NULL; |
Summer Qin | 56725eb | 2022-05-06 15:23:40 +0800 | [diff] [blame] | 344 | struct partition_t *curr_partition = GET_CURRENT_COMPONENT(); |
Xinyu Zhang | 6ad0703 | 2022-08-10 14:45:56 +0800 | [diff] [blame] | 345 | fih_int fih_rc = FIH_FAILURE; |
Mingyang Sun | b26b280 | 2021-07-07 11:25:00 +0800 | [diff] [blame] | 346 | |
| 347 | /* It is a fatal error if message handle is invalid */ |
Ken Liu | c9313eb | 2023-02-22 15:45:54 +0800 | [diff] [blame] | 348 | handle = spm_msg_handle_to_connection(msg_handle); |
Mingyang Sun | a09adda | 2022-02-16 18:11:33 +0800 | [diff] [blame] | 349 | if (!handle) { |
Mingyang Sun | b26b280 | 2021-07-07 11:25:00 +0800 | [diff] [blame] | 350 | tfm_core_panic(); |
| 351 | } |
| 352 | |
Mingyang Sun | b26b280 | 2021-07-07 11:25:00 +0800 | [diff] [blame] | 353 | /* |
| 354 | * It is a fatal error if message handle does not refer to a request |
| 355 | * message |
| 356 | */ |
Mingyang Sun | a09adda | 2022-02-16 18:11:33 +0800 | [diff] [blame] | 357 | if (handle->msg.type < PSA_IPC_CALL) { |
Mingyang Sun | b26b280 | 2021-07-07 11:25:00 +0800 | [diff] [blame] | 358 | tfm_core_panic(); |
| 359 | } |
| 360 | |
| 361 | /* |
| 362 | * It is a fatal error if outvec_idx is equal to or greater than |
| 363 | * PSA_MAX_IOVEC |
| 364 | */ |
| 365 | if (outvec_idx >= PSA_MAX_IOVEC) { |
| 366 | tfm_core_panic(); |
| 367 | } |
| 368 | |
| 369 | /* |
| 370 | * It is a fatal error if the call attempts to write data past the end of |
| 371 | * the client output vector |
| 372 | */ |
Mingyang Sun | a09adda | 2022-02-16 18:11:33 +0800 | [diff] [blame] | 373 | if (num_bytes > handle->msg.out_size[outvec_idx] - |
| 374 | handle->outvec[outvec_idx].len) { |
Mingyang Sun | b26b280 | 2021-07-07 11:25:00 +0800 | [diff] [blame] | 375 | tfm_core_panic(); |
| 376 | } |
| 377 | |
Shawn Shan | 038348e | 2021-09-08 17:11:04 +0800 | [diff] [blame] | 378 | #if PSA_FRAMEWORK_HAS_MM_IOVEC |
| 379 | /* |
| 380 | * It is a fatal error if the output vector has already been mapped using |
| 381 | * psa_map_outvec(). |
| 382 | */ |
Mingyang Sun | a09adda | 2022-02-16 18:11:33 +0800 | [diff] [blame] | 383 | if (IOVEC_IS_MAPPED(handle, (outvec_idx + OUTVEC_IDX_BASE))) { |
Shawn Shan | 038348e | 2021-09-08 17:11:04 +0800 | [diff] [blame] | 384 | tfm_core_panic(); |
| 385 | } |
| 386 | |
Mingyang Sun | a09adda | 2022-02-16 18:11:33 +0800 | [diff] [blame] | 387 | SET_IOVEC_ACCESSED(handle, (outvec_idx + OUTVEC_IDX_BASE)); |
Shawn Shan | 038348e | 2021-09-08 17:11:04 +0800 | [diff] [blame] | 388 | #endif |
| 389 | |
Mingyang Sun | b26b280 | 2021-07-07 11:25:00 +0800 | [diff] [blame] | 390 | /* |
| 391 | * Copy the service buffer to client outvecs. It is a fatal error |
| 392 | * if the memory reference for buffer is invalid or not readable. |
| 393 | */ |
Xinyu Zhang | 6ad0703 | 2022-08-10 14:45:56 +0800 | [diff] [blame] | 394 | FIH_CALL(tfm_hal_memory_check, fih_rc, |
| 395 | curr_partition->boundary, (uintptr_t)buffer, |
| 396 | num_bytes, TFM_HAL_ACCESS_READABLE); |
| 397 | if (fih_not_eq(fih_rc, fih_int_encode(PSA_SUCCESS))) { |
Mingyang Sun | b26b280 | 2021-07-07 11:25:00 +0800 | [diff] [blame] | 398 | tfm_core_panic(); |
| 399 | } |
| 400 | |
Mingyang Sun | a09adda | 2022-02-16 18:11:33 +0800 | [diff] [blame] | 401 | spm_memcpy((char *)handle->outvec[outvec_idx].base + |
| 402 | handle->outvec[outvec_idx].len, buffer, num_bytes); |
Mingyang Sun | b26b280 | 2021-07-07 11:25:00 +0800 | [diff] [blame] | 403 | |
| 404 | /* Update the write number */ |
Mingyang Sun | a09adda | 2022-02-16 18:11:33 +0800 | [diff] [blame] | 405 | handle->outvec[outvec_idx].len += num_bytes; |
Mingyang Sun | b26b280 | 2021-07-07 11:25:00 +0800 | [diff] [blame] | 406 | } |
| 407 | |
Ken Liu | f8c7e53 | 2022-02-10 15:03:04 +0800 | [diff] [blame] | 408 | psa_status_t tfm_spm_partition_psa_reply(psa_handle_t msg_handle, |
| 409 | psa_status_t status) |
Mingyang Sun | b26b280 | 2021-07-07 11:25:00 +0800 | [diff] [blame] | 410 | { |
Ken Liu | 0bed7e0 | 2022-02-10 12:38:07 +0800 | [diff] [blame] | 411 | struct service_t *service; |
Ken Liu | c9313eb | 2023-02-22 15:45:54 +0800 | [diff] [blame] | 412 | struct connection_t *handle; |
Ken Liu | f8c7e53 | 2022-02-10 15:03:04 +0800 | [diff] [blame] | 413 | psa_status_t ret = PSA_SUCCESS; |
Mingyang Sun | 620c856 | 2021-11-10 11:44:58 +0800 | [diff] [blame] | 414 | struct critical_section_t cs_assert = CRITICAL_SECTION_STATIC_INIT; |
Mingyang Sun | b26b280 | 2021-07-07 11:25:00 +0800 | [diff] [blame] | 415 | |
| 416 | /* It is a fatal error if message handle is invalid */ |
Ken Liu | c9313eb | 2023-02-22 15:45:54 +0800 | [diff] [blame] | 417 | handle = spm_msg_handle_to_connection(msg_handle); |
Mingyang Sun | a09adda | 2022-02-16 18:11:33 +0800 | [diff] [blame] | 418 | if (!handle) { |
Mingyang Sun | b26b280 | 2021-07-07 11:25:00 +0800 | [diff] [blame] | 419 | tfm_core_panic(); |
| 420 | } |
| 421 | |
| 422 | /* |
| 423 | * RoT Service information is needed in this function, stored it in message |
| 424 | * body structure. Only two parameters are passed in this function: handle |
| 425 | * and status, so it is useful and simply to do like this. |
| 426 | */ |
Mingyang Sun | a09adda | 2022-02-16 18:11:33 +0800 | [diff] [blame] | 427 | service = handle->service; |
Mingyang Sun | b26b280 | 2021-07-07 11:25:00 +0800 | [diff] [blame] | 428 | if (!service) { |
| 429 | tfm_core_panic(); |
| 430 | } |
| 431 | |
Mingyang Sun | a09adda | 2022-02-16 18:11:33 +0800 | [diff] [blame] | 432 | switch (handle->msg.type) { |
Mingyang Sun | b26b280 | 2021-07-07 11:25:00 +0800 | [diff] [blame] | 433 | case PSA_IPC_CONNECT: |
| 434 | /* |
| 435 | * Reply to PSA_IPC_CONNECT message. Connect handle is returned if the |
| 436 | * input status is PSA_SUCCESS. Others return values are based on the |
| 437 | * input status. |
| 438 | */ |
| 439 | if (status == PSA_SUCCESS) { |
| 440 | ret = msg_handle; |
| 441 | } else if (status == PSA_ERROR_CONNECTION_REFUSED) { |
| 442 | /* Refuse the client connection, indicating a permanent error. */ |
Mingyang Sun | b26b280 | 2021-07-07 11:25:00 +0800 | [diff] [blame] | 443 | ret = PSA_ERROR_CONNECTION_REFUSED; |
Mingyang Sun | aeca8e0 | 2022-02-24 14:47:56 +0800 | [diff] [blame] | 444 | handle->status = TFM_HANDLE_STATUS_TO_FREE; |
Mingyang Sun | b26b280 | 2021-07-07 11:25:00 +0800 | [diff] [blame] | 445 | } else if (status == PSA_ERROR_CONNECTION_BUSY) { |
| 446 | /* Fail the client connection, indicating a transient error. */ |
| 447 | ret = PSA_ERROR_CONNECTION_BUSY; |
| 448 | } else { |
| 449 | tfm_core_panic(); |
| 450 | } |
| 451 | break; |
| 452 | case PSA_IPC_DISCONNECT: |
| 453 | /* Service handle is not used anymore */ |
Mingyang Sun | aeca8e0 | 2022-02-24 14:47:56 +0800 | [diff] [blame] | 454 | handle->status = TFM_HANDLE_STATUS_TO_FREE; |
Mingyang Sun | b26b280 | 2021-07-07 11:25:00 +0800 | [diff] [blame] | 455 | |
| 456 | /* |
| 457 | * If the message type is PSA_IPC_DISCONNECT, then the status code is |
| 458 | * ignored |
| 459 | */ |
| 460 | break; |
| 461 | default: |
Mingyang Sun | a09adda | 2022-02-16 18:11:33 +0800 | [diff] [blame] | 462 | if (handle->msg.type >= PSA_IPC_CALL) { |
Shawn Shan | 038348e | 2021-09-08 17:11:04 +0800 | [diff] [blame] | 463 | |
| 464 | #if PSA_FRAMEWORK_HAS_MM_IOVEC |
| 465 | |
| 466 | /* |
| 467 | * If the unmapped function is not called for an input/output vector |
| 468 | * that has been mapped, the framework will remove the mapping. |
| 469 | */ |
| 470 | int i; |
| 471 | |
| 472 | for (i = 0; i < PSA_MAX_IOVEC * 2; i++) { |
Mingyang Sun | a09adda | 2022-02-16 18:11:33 +0800 | [diff] [blame] | 473 | if (IOVEC_IS_MAPPED(handle, i) && |
| 474 | (!IOVEC_IS_UNMAPPED(handle, i))) { |
| 475 | SET_IOVEC_UNMAPPED(handle, i); |
Shawn Shan | 038348e | 2021-09-08 17:11:04 +0800 | [diff] [blame] | 476 | /* |
| 477 | * Any output vectors that are still mapped will report that |
| 478 | * zero bytes have been written. |
| 479 | */ |
| 480 | if (i >= OUTVEC_IDX_BASE) { |
Mingyang Sun | a09adda | 2022-02-16 18:11:33 +0800 | [diff] [blame] | 481 | handle->outvec[i - OUTVEC_IDX_BASE].len = 0; |
Shawn Shan | 038348e | 2021-09-08 17:11:04 +0800 | [diff] [blame] | 482 | } |
| 483 | } |
| 484 | } |
| 485 | |
| 486 | #endif |
Mingyang Sun | b26b280 | 2021-07-07 11:25:00 +0800 | [diff] [blame] | 487 | /* Reply to a request message. Return values are based on status */ |
| 488 | ret = status; |
| 489 | /* |
| 490 | * The total number of bytes written to a single parameter must be |
| 491 | * reported to the client by updating the len member of the |
| 492 | * psa_outvec structure for the parameter before returning from |
| 493 | * psa_call(). |
| 494 | */ |
Mingyang Sun | a09adda | 2022-02-16 18:11:33 +0800 | [diff] [blame] | 495 | update_caller_outvec_len(handle); |
Mingyang Sun | b26b280 | 2021-07-07 11:25:00 +0800 | [diff] [blame] | 496 | if (SERVICE_IS_STATELESS(service->p_ldinf->flags)) { |
Mingyang Sun | aeca8e0 | 2022-02-24 14:47:56 +0800 | [diff] [blame] | 497 | handle->status = TFM_HANDLE_STATUS_TO_FREE; |
Mingyang Sun | b26b280 | 2021-07-07 11:25:00 +0800 | [diff] [blame] | 498 | } |
| 499 | } else { |
| 500 | tfm_core_panic(); |
| 501 | } |
| 502 | } |
| 503 | |
| 504 | if (ret == PSA_ERROR_PROGRAMMER_ERROR) { |
| 505 | /* |
| 506 | * If the source of the programmer error is a Secure Partition, the SPM |
| 507 | * must panic the Secure Partition in response to a PROGRAMMER ERROR. |
| 508 | */ |
Mingyang Sun | aeca8e0 | 2022-02-24 14:47:56 +0800 | [diff] [blame] | 509 | if (!TFM_CLIENT_ID_IS_NS(handle->msg.client_id)) { |
Mingyang Sun | b26b280 | 2021-07-07 11:25:00 +0800 | [diff] [blame] | 510 | tfm_core_panic(); |
| 511 | } |
Mingyang Sun | b26b280 | 2021-07-07 11:25:00 +0800 | [diff] [blame] | 512 | } |
| 513 | |
Mingyang Sun | 620c856 | 2021-11-10 11:44:58 +0800 | [diff] [blame] | 514 | /* |
| 515 | * TODO: It can be optimized further by moving critical section protection |
| 516 | * to mailbox. Also need to check implementation when secure context is |
| 517 | * involved. |
| 518 | */ |
| 519 | CRITICAL_SECTION_ENTER(cs_assert); |
Ken Liu | 995a974 | 2022-05-18 19:28:30 +0800 | [diff] [blame] | 520 | ret = backend_replying(handle, ret); |
Mingyang Sun | 620c856 | 2021-11-10 11:44:58 +0800 | [diff] [blame] | 521 | CRITICAL_SECTION_LEAVE(cs_assert); |
| 522 | |
Mingyang Sun | aeca8e0 | 2022-02-24 14:47:56 +0800 | [diff] [blame] | 523 | if (handle->status == TFM_HANDLE_STATUS_TO_FREE) { |
Ken Liu | c9313eb | 2023-02-22 15:45:54 +0800 | [diff] [blame] | 524 | spm_free_connection(handle); |
Mingyang Sun | aeca8e0 | 2022-02-24 14:47:56 +0800 | [diff] [blame] | 525 | } else { |
| 526 | handle->status = TFM_HANDLE_STATUS_IDLE; |
| 527 | } |
| 528 | |
Mingyang Sun | 620c856 | 2021-11-10 11:44:58 +0800 | [diff] [blame] | 529 | return ret; |
Mingyang Sun | b26b280 | 2021-07-07 11:25:00 +0800 | [diff] [blame] | 530 | } |
| 531 | |
Kevin Peng | 613b417 | 2022-02-15 14:41:44 +0800 | [diff] [blame] | 532 | #if CONFIG_TFM_DOORBELL_API == 1 |
Jianliang Shen | bd8c7c9 | 2023-03-03 16:07:42 +0100 | [diff] [blame^] | 533 | void tfm_spm_partition_psa_notify(int32_t partition_id) |
Mingyang Sun | b26b280 | 2021-07-07 11:25:00 +0800 | [diff] [blame] | 534 | { |
Ken Liu | 5d73c87 | 2021-08-19 19:23:17 +0800 | [diff] [blame] | 535 | struct partition_t *p_pt = tfm_spm_get_partition_by_id(partition_id); |
| 536 | |
Jianliang Shen | bd8c7c9 | 2023-03-03 16:07:42 +0100 | [diff] [blame^] | 537 | backend_assert_signal(p_pt, PSA_DOORBELL); |
Mingyang Sun | b26b280 | 2021-07-07 11:25:00 +0800 | [diff] [blame] | 538 | } |
| 539 | |
| 540 | void tfm_spm_partition_psa_clear(void) |
| 541 | { |
Ken Liu | 92ede9f | 2021-10-20 09:35:00 +0800 | [diff] [blame] | 542 | struct critical_section_t cs_assert = CRITICAL_SECTION_STATIC_INIT; |
Mingyang Sun | b26b280 | 2021-07-07 11:25:00 +0800 | [diff] [blame] | 543 | struct partition_t *partition = NULL; |
| 544 | |
Kevin Peng | cdf3ae2 | 2022-01-19 14:53:52 +0800 | [diff] [blame] | 545 | partition = GET_CURRENT_COMPONENT(); |
Mingyang Sun | b26b280 | 2021-07-07 11:25:00 +0800 | [diff] [blame] | 546 | |
| 547 | /* |
| 548 | * It is a fatal error if the Secure Partition's doorbell signal is not |
| 549 | * currently asserted. |
| 550 | */ |
| 551 | if ((partition->signals_asserted & PSA_DOORBELL) == 0) { |
| 552 | tfm_core_panic(); |
| 553 | } |
Ken Liu | 92ede9f | 2021-10-20 09:35:00 +0800 | [diff] [blame] | 554 | |
| 555 | CRITICAL_SECTION_ENTER(cs_assert); |
Mingyang Sun | b26b280 | 2021-07-07 11:25:00 +0800 | [diff] [blame] | 556 | partition->signals_asserted &= ~PSA_DOORBELL; |
Ken Liu | 92ede9f | 2021-10-20 09:35:00 +0800 | [diff] [blame] | 557 | CRITICAL_SECTION_LEAVE(cs_assert); |
Mingyang Sun | b26b280 | 2021-07-07 11:25:00 +0800 | [diff] [blame] | 558 | } |
Kevin Peng | 613b417 | 2022-02-15 14:41:44 +0800 | [diff] [blame] | 559 | #endif /* CONFIG_TFM_DOORBELL_API == 1 */ |
Mingyang Sun | b26b280 | 2021-07-07 11:25:00 +0800 | [diff] [blame] | 560 | |
Mingyang Sun | b26b280 | 2021-07-07 11:25:00 +0800 | [diff] [blame] | 561 | void tfm_spm_partition_psa_panic(void) |
| 562 | { |
Joakim Andersson | 97cef7e | 2022-03-18 10:22:00 +0100 | [diff] [blame] | 563 | #ifdef CONFIG_TFM_HALT_ON_CORE_PANIC |
| 564 | tfm_hal_system_halt(); |
| 565 | #else |
Mingyang Sun | b26b280 | 2021-07-07 11:25:00 +0800 | [diff] [blame] | 566 | /* |
| 567 | * PSA FF recommends that the SPM causes the system to restart when a secure |
| 568 | * partition panics. |
| 569 | */ |
| 570 | tfm_hal_system_reset(); |
Joakim Andersson | 97cef7e | 2022-03-18 10:22:00 +0100 | [diff] [blame] | 571 | #endif |
Mingyang Sun | b26b280 | 2021-07-07 11:25:00 +0800 | [diff] [blame] | 572 | } |
| 573 | |
Mingyang Sun | ed5fe7b | 2022-02-10 17:33:21 +0800 | [diff] [blame] | 574 | #if CONFIG_TFM_FLIH_API == 1 || CONFIG_TFM_SLIH_API == 1 |
Kevin Peng | 67a89fd | 2021-11-25 11:22:02 +0800 | [diff] [blame] | 575 | void tfm_spm_partition_psa_irq_enable(psa_signal_t irq_signal) |
Mingyang Sun | b26b280 | 2021-07-07 11:25:00 +0800 | [diff] [blame] | 576 | { |
| 577 | struct partition_t *partition; |
Chris Brand | 10a2acb | 2022-10-18 17:12:27 -0700 | [diff] [blame] | 578 | const struct irq_load_info_t *irq_info; |
Mingyang Sun | b26b280 | 2021-07-07 11:25:00 +0800 | [diff] [blame] | 579 | |
Kevin Peng | cdf3ae2 | 2022-01-19 14:53:52 +0800 | [diff] [blame] | 580 | partition = GET_CURRENT_COMPONENT(); |
Mingyang Sun | b26b280 | 2021-07-07 11:25:00 +0800 | [diff] [blame] | 581 | |
| 582 | irq_info = get_irq_info_for_signal(partition->p_ldinf, irq_signal); |
| 583 | if (!irq_info) { |
| 584 | tfm_core_panic(); |
| 585 | } |
| 586 | |
Kevin Peng | d399a1f | 2021-09-08 15:33:14 +0800 | [diff] [blame] | 587 | tfm_hal_irq_enable(irq_info->source); |
Mingyang Sun | b26b280 | 2021-07-07 11:25:00 +0800 | [diff] [blame] | 588 | } |
| 589 | |
Kevin Peng | 67a89fd | 2021-11-25 11:22:02 +0800 | [diff] [blame] | 590 | psa_irq_status_t tfm_spm_partition_psa_irq_disable(psa_signal_t irq_signal) |
Mingyang Sun | b26b280 | 2021-07-07 11:25:00 +0800 | [diff] [blame] | 591 | { |
| 592 | struct partition_t *partition; |
Chris Brand | 10a2acb | 2022-10-18 17:12:27 -0700 | [diff] [blame] | 593 | const struct irq_load_info_t *irq_info; |
Mingyang Sun | b26b280 | 2021-07-07 11:25:00 +0800 | [diff] [blame] | 594 | |
Kevin Peng | cdf3ae2 | 2022-01-19 14:53:52 +0800 | [diff] [blame] | 595 | partition = GET_CURRENT_COMPONENT(); |
Mingyang Sun | b26b280 | 2021-07-07 11:25:00 +0800 | [diff] [blame] | 596 | |
| 597 | irq_info = get_irq_info_for_signal(partition->p_ldinf, irq_signal); |
| 598 | if (!irq_info) { |
| 599 | tfm_core_panic(); |
| 600 | } |
| 601 | |
Kevin Peng | d399a1f | 2021-09-08 15:33:14 +0800 | [diff] [blame] | 602 | tfm_hal_irq_disable(irq_info->source); |
Mingyang Sun | b26b280 | 2021-07-07 11:25:00 +0800 | [diff] [blame] | 603 | |
| 604 | return 1; |
| 605 | } |
| 606 | |
Mingyang Sun | ed5fe7b | 2022-02-10 17:33:21 +0800 | [diff] [blame] | 607 | /* This API is only used for FLIH. */ |
| 608 | #if CONFIG_TFM_FLIH_API == 1 |
Mingyang Sun | b26b280 | 2021-07-07 11:25:00 +0800 | [diff] [blame] | 609 | void tfm_spm_partition_psa_reset_signal(psa_signal_t irq_signal) |
| 610 | { |
Ken Liu | 92ede9f | 2021-10-20 09:35:00 +0800 | [diff] [blame] | 611 | struct critical_section_t cs_assert = CRITICAL_SECTION_STATIC_INIT; |
Chris Brand | 10a2acb | 2022-10-18 17:12:27 -0700 | [diff] [blame] | 612 | const struct irq_load_info_t *irq_info; |
Mingyang Sun | b26b280 | 2021-07-07 11:25:00 +0800 | [diff] [blame] | 613 | struct partition_t *partition; |
| 614 | |
Kevin Peng | cdf3ae2 | 2022-01-19 14:53:52 +0800 | [diff] [blame] | 615 | partition = GET_CURRENT_COMPONENT(); |
Mingyang Sun | b26b280 | 2021-07-07 11:25:00 +0800 | [diff] [blame] | 616 | |
| 617 | irq_info = get_irq_info_for_signal(partition->p_ldinf, irq_signal); |
| 618 | if (!irq_info) { |
| 619 | tfm_core_panic(); |
| 620 | } |
| 621 | |
| 622 | if (!irq_info->flih_func) { |
| 623 | /* This API is for FLIH IRQs only */ |
| 624 | tfm_core_panic(); |
| 625 | } |
| 626 | |
| 627 | if ((partition->signals_asserted & irq_signal) == 0) { |
| 628 | /* The signal is not asserted */ |
| 629 | tfm_core_panic(); |
| 630 | } |
| 631 | |
Ken Liu | 92ede9f | 2021-10-20 09:35:00 +0800 | [diff] [blame] | 632 | CRITICAL_SECTION_ENTER(cs_assert); |
Mingyang Sun | b26b280 | 2021-07-07 11:25:00 +0800 | [diff] [blame] | 633 | partition->signals_asserted &= ~irq_signal; |
Ken Liu | 92ede9f | 2021-10-20 09:35:00 +0800 | [diff] [blame] | 634 | CRITICAL_SECTION_LEAVE(cs_assert); |
Mingyang Sun | b26b280 | 2021-07-07 11:25:00 +0800 | [diff] [blame] | 635 | } |
Mingyang Sun | ed5fe7b | 2022-02-10 17:33:21 +0800 | [diff] [blame] | 636 | #endif |
Shawn Shan | 038348e | 2021-09-08 17:11:04 +0800 | [diff] [blame] | 637 | |
Mingyang Sun | ed5fe7b | 2022-02-10 17:33:21 +0800 | [diff] [blame] | 638 | /* This API is only used for SLIH. */ |
| 639 | #if CONFIG_TFM_SLIH_API == 1 |
| 640 | void tfm_spm_partition_psa_eoi(psa_signal_t irq_signal) |
Xinyu Zhang | 2bc4d57 | 2021-12-27 16:37:46 +0800 | [diff] [blame] | 641 | { |
Mingyang Sun | ed5fe7b | 2022-02-10 17:33:21 +0800 | [diff] [blame] | 642 | struct critical_section_t cs_assert = CRITICAL_SECTION_STATIC_INIT; |
Chris Brand | 10a2acb | 2022-10-18 17:12:27 -0700 | [diff] [blame] | 643 | const struct irq_load_info_t *irq_info = NULL; |
Mingyang Sun | ed5fe7b | 2022-02-10 17:33:21 +0800 | [diff] [blame] | 644 | struct partition_t *partition = NULL; |
Xinyu Zhang | 2bc4d57 | 2021-12-27 16:37:46 +0800 | [diff] [blame] | 645 | |
Mingyang Sun | ed5fe7b | 2022-02-10 17:33:21 +0800 | [diff] [blame] | 646 | partition = GET_CURRENT_COMPONENT(); |
| 647 | |
| 648 | irq_info = get_irq_info_for_signal(partition->p_ldinf, irq_signal); |
| 649 | /* It is a fatal error if passed signal is not an interrupt signal. */ |
| 650 | if (!irq_info) { |
Xinyu Zhang | 2bc4d57 | 2021-12-27 16:37:46 +0800 | [diff] [blame] | 651 | tfm_core_panic(); |
| 652 | } |
| 653 | |
Mingyang Sun | ed5fe7b | 2022-02-10 17:33:21 +0800 | [diff] [blame] | 654 | if (irq_info->flih_func) { |
| 655 | /* This API is for SLIH IRQs only */ |
Xinyu Zhang | 2bc4d57 | 2021-12-27 16:37:46 +0800 | [diff] [blame] | 656 | tfm_core_panic(); |
| 657 | } |
| 658 | |
Mingyang Sun | ed5fe7b | 2022-02-10 17:33:21 +0800 | [diff] [blame] | 659 | /* It is a fatal error if passed signal is not currently asserted */ |
| 660 | if ((partition->signals_asserted & irq_signal) == 0) { |
| 661 | tfm_core_panic(); |
| 662 | } |
| 663 | |
| 664 | CRITICAL_SECTION_ENTER(cs_assert); |
| 665 | partition->signals_asserted &= ~irq_signal; |
| 666 | CRITICAL_SECTION_LEAVE(cs_assert); |
| 667 | |
| 668 | tfm_hal_irq_clear_pending(irq_info->source); |
| 669 | tfm_hal_irq_enable(irq_info->source); |
Xinyu Zhang | 2bc4d57 | 2021-12-27 16:37:46 +0800 | [diff] [blame] | 670 | } |
Mingyang Sun | ed5fe7b | 2022-02-10 17:33:21 +0800 | [diff] [blame] | 671 | #endif |
| 672 | #endif /* CONFIG_TFM_FLIH_API == 1 || CONFIG_TFM_SLIH_API == 1 */ |
Xinyu Zhang | 2bc4d57 | 2021-12-27 16:37:46 +0800 | [diff] [blame] | 673 | |
Shawn Shan | 038348e | 2021-09-08 17:11:04 +0800 | [diff] [blame] | 674 | #if PSA_FRAMEWORK_HAS_MM_IOVEC |
| 675 | |
| 676 | const void *tfm_spm_partition_psa_map_invec(psa_handle_t msg_handle, |
| 677 | uint32_t invec_idx) |
| 678 | { |
Ken Liu | c9313eb | 2023-02-22 15:45:54 +0800 | [diff] [blame] | 679 | struct connection_t *handle; |
Shawn Shan | 038348e | 2021-09-08 17:11:04 +0800 | [diff] [blame] | 680 | struct partition_t *partition = NULL; |
Xinyu Zhang | 6ad0703 | 2022-08-10 14:45:56 +0800 | [diff] [blame] | 681 | fih_int fih_rc = FIH_FAILURE; |
Shawn Shan | 038348e | 2021-09-08 17:11:04 +0800 | [diff] [blame] | 682 | |
| 683 | /* It is a fatal error if message handle is invalid */ |
Ken Liu | c9313eb | 2023-02-22 15:45:54 +0800 | [diff] [blame] | 684 | handle = spm_msg_handle_to_connection(msg_handle); |
Mingyang Sun | a09adda | 2022-02-16 18:11:33 +0800 | [diff] [blame] | 685 | if (!handle) { |
Shawn Shan | 038348e | 2021-09-08 17:11:04 +0800 | [diff] [blame] | 686 | tfm_core_panic(); |
| 687 | } |
| 688 | |
Mingyang Sun | a09adda | 2022-02-16 18:11:33 +0800 | [diff] [blame] | 689 | partition = handle->service->partition; |
Shawn Shan | 038348e | 2021-09-08 17:11:04 +0800 | [diff] [blame] | 690 | |
| 691 | /* |
| 692 | * It is a fatal error if MM-IOVEC has not been enabled for the RoT |
| 693 | * Service that received the message. |
| 694 | */ |
Mingyang Sun | a09adda | 2022-02-16 18:11:33 +0800 | [diff] [blame] | 695 | if (!SERVICE_ENABLED_MM_IOVEC(handle->service->p_ldinf->flags)) { |
Shawn Shan | 038348e | 2021-09-08 17:11:04 +0800 | [diff] [blame] | 696 | tfm_core_panic(); |
| 697 | } |
| 698 | |
| 699 | /* |
| 700 | * It is a fatal error if message handle does not refer to a request |
| 701 | * message. |
| 702 | */ |
Mingyang Sun | a09adda | 2022-02-16 18:11:33 +0800 | [diff] [blame] | 703 | if (handle->msg.type < PSA_IPC_CALL) { |
Shawn Shan | 038348e | 2021-09-08 17:11:04 +0800 | [diff] [blame] | 704 | tfm_core_panic(); |
| 705 | } |
| 706 | |
| 707 | /* |
| 708 | * It is a fatal error if invec_idx is equal to or greater than |
| 709 | * PSA_MAX_IOVEC. |
| 710 | */ |
| 711 | if (invec_idx >= PSA_MAX_IOVEC) { |
| 712 | tfm_core_panic(); |
| 713 | } |
| 714 | |
| 715 | /* It is a fatal error if the input vector has length zero. */ |
Mingyang Sun | a09adda | 2022-02-16 18:11:33 +0800 | [diff] [blame] | 716 | if (handle->msg.in_size[invec_idx] == 0) { |
Shawn Shan | 038348e | 2021-09-08 17:11:04 +0800 | [diff] [blame] | 717 | tfm_core_panic(); |
| 718 | } |
| 719 | |
| 720 | /* |
| 721 | * It is a fatal error if the input vector has already been mapped using |
| 722 | * psa_map_invec(). |
| 723 | */ |
Mingyang Sun | a09adda | 2022-02-16 18:11:33 +0800 | [diff] [blame] | 724 | if (IOVEC_IS_MAPPED(handle, (invec_idx + INVEC_IDX_BASE))) { |
Shawn Shan | 038348e | 2021-09-08 17:11:04 +0800 | [diff] [blame] | 725 | tfm_core_panic(); |
| 726 | } |
| 727 | |
| 728 | /* |
| 729 | * It is a fatal error if the input vector has already been accessed |
| 730 | * using psa_read() or psa_skip(). |
| 731 | */ |
Mingyang Sun | a09adda | 2022-02-16 18:11:33 +0800 | [diff] [blame] | 732 | if (IOVEC_IS_ACCESSED(handle, (invec_idx + INVEC_IDX_BASE))) { |
Shawn Shan | 038348e | 2021-09-08 17:11:04 +0800 | [diff] [blame] | 733 | tfm_core_panic(); |
| 734 | } |
| 735 | |
| 736 | /* |
| 737 | * It is a fatal error if the memory reference for the wrap input vector is |
| 738 | * invalid or not readable. |
| 739 | */ |
Xinyu Zhang | 6ad0703 | 2022-08-10 14:45:56 +0800 | [diff] [blame] | 740 | FIH_CALL(tfm_hal_memory_check, fih_rc, |
| 741 | partition->boundary, (uintptr_t)handle->invec[invec_idx].base, |
| 742 | handle->invec[invec_idx].len, TFM_HAL_ACCESS_READABLE); |
| 743 | if (fih_not_eq(fih_rc, fih_int_encode(PSA_SUCCESS))) { |
Shawn Shan | 038348e | 2021-09-08 17:11:04 +0800 | [diff] [blame] | 744 | tfm_core_panic(); |
| 745 | } |
| 746 | |
Mingyang Sun | a09adda | 2022-02-16 18:11:33 +0800 | [diff] [blame] | 747 | SET_IOVEC_MAPPED(handle, (invec_idx + INVEC_IDX_BASE)); |
Shawn Shan | 038348e | 2021-09-08 17:11:04 +0800 | [diff] [blame] | 748 | |
Mingyang Sun | a09adda | 2022-02-16 18:11:33 +0800 | [diff] [blame] | 749 | return handle->invec[invec_idx].base; |
Shawn Shan | 038348e | 2021-09-08 17:11:04 +0800 | [diff] [blame] | 750 | } |
| 751 | |
| 752 | void tfm_spm_partition_psa_unmap_invec(psa_handle_t msg_handle, |
| 753 | uint32_t invec_idx) |
| 754 | { |
Ken Liu | c9313eb | 2023-02-22 15:45:54 +0800 | [diff] [blame] | 755 | struct connection_t *handle; |
Shawn Shan | 038348e | 2021-09-08 17:11:04 +0800 | [diff] [blame] | 756 | |
| 757 | /* It is a fatal error if message handle is invalid */ |
Ken Liu | c9313eb | 2023-02-22 15:45:54 +0800 | [diff] [blame] | 758 | handle = spm_msg_handle_to_connection(msg_handle); |
Mingyang Sun | a09adda | 2022-02-16 18:11:33 +0800 | [diff] [blame] | 759 | if (!handle) { |
Shawn Shan | 038348e | 2021-09-08 17:11:04 +0800 | [diff] [blame] | 760 | tfm_core_panic(); |
| 761 | } |
| 762 | |
| 763 | /* |
| 764 | * It is a fatal error if MM-IOVEC has not been enabled for the RoT |
| 765 | * Service that received the message. |
| 766 | */ |
Mingyang Sun | a09adda | 2022-02-16 18:11:33 +0800 | [diff] [blame] | 767 | if (!SERVICE_ENABLED_MM_IOVEC(handle->service->p_ldinf->flags)) { |
Shawn Shan | 038348e | 2021-09-08 17:11:04 +0800 | [diff] [blame] | 768 | tfm_core_panic(); |
| 769 | } |
| 770 | |
| 771 | /* |
| 772 | * It is a fatal error if message handle does not refer to a request |
| 773 | * message. |
| 774 | */ |
Mingyang Sun | a09adda | 2022-02-16 18:11:33 +0800 | [diff] [blame] | 775 | if (handle->msg.type < PSA_IPC_CALL) { |
Shawn Shan | 038348e | 2021-09-08 17:11:04 +0800 | [diff] [blame] | 776 | tfm_core_panic(); |
| 777 | } |
| 778 | |
| 779 | /* |
| 780 | * It is a fatal error if invec_idx is equal to or greater than |
| 781 | * PSA_MAX_IOVEC. |
| 782 | */ |
| 783 | if (invec_idx >= PSA_MAX_IOVEC) { |
| 784 | tfm_core_panic(); |
| 785 | } |
| 786 | |
| 787 | /* |
| 788 | * It is a fatal error if The input vector has not been mapped by a call to |
| 789 | * psa_map_invec(). |
| 790 | */ |
Mingyang Sun | a09adda | 2022-02-16 18:11:33 +0800 | [diff] [blame] | 791 | if (!IOVEC_IS_MAPPED(handle, (invec_idx + INVEC_IDX_BASE))) { |
Shawn Shan | 038348e | 2021-09-08 17:11:04 +0800 | [diff] [blame] | 792 | tfm_core_panic(); |
| 793 | } |
| 794 | |
| 795 | /* |
| 796 | * It is a fatal error if the input vector has already been unmapped by a |
| 797 | * call to psa_unmap_invec(). |
| 798 | */ |
Mingyang Sun | a09adda | 2022-02-16 18:11:33 +0800 | [diff] [blame] | 799 | if (IOVEC_IS_UNMAPPED(handle, (invec_idx + INVEC_IDX_BASE))) { |
Shawn Shan | 038348e | 2021-09-08 17:11:04 +0800 | [diff] [blame] | 800 | tfm_core_panic(); |
| 801 | } |
| 802 | |
Mingyang Sun | a09adda | 2022-02-16 18:11:33 +0800 | [diff] [blame] | 803 | SET_IOVEC_UNMAPPED(handle, (invec_idx + INVEC_IDX_BASE)); |
Shawn Shan | 038348e | 2021-09-08 17:11:04 +0800 | [diff] [blame] | 804 | } |
| 805 | |
| 806 | void *tfm_spm_partition_psa_map_outvec(psa_handle_t msg_handle, |
| 807 | uint32_t outvec_idx) |
| 808 | { |
Ken Liu | c9313eb | 2023-02-22 15:45:54 +0800 | [diff] [blame] | 809 | struct connection_t *handle; |
Shawn Shan | 038348e | 2021-09-08 17:11:04 +0800 | [diff] [blame] | 810 | struct partition_t *partition = NULL; |
Xinyu Zhang | 6ad0703 | 2022-08-10 14:45:56 +0800 | [diff] [blame] | 811 | fih_int fih_rc = FIH_FAILURE; |
Shawn Shan | 038348e | 2021-09-08 17:11:04 +0800 | [diff] [blame] | 812 | |
| 813 | /* It is a fatal error if message handle is invalid */ |
Ken Liu | c9313eb | 2023-02-22 15:45:54 +0800 | [diff] [blame] | 814 | handle = spm_msg_handle_to_connection(msg_handle); |
Mingyang Sun | a09adda | 2022-02-16 18:11:33 +0800 | [diff] [blame] | 815 | if (!handle) { |
Shawn Shan | 038348e | 2021-09-08 17:11:04 +0800 | [diff] [blame] | 816 | tfm_core_panic(); |
| 817 | } |
| 818 | |
Mingyang Sun | a09adda | 2022-02-16 18:11:33 +0800 | [diff] [blame] | 819 | partition = handle->service->partition; |
Shawn Shan | 038348e | 2021-09-08 17:11:04 +0800 | [diff] [blame] | 820 | |
| 821 | /* |
| 822 | * It is a fatal error if MM-IOVEC has not been enabled for the RoT |
| 823 | * Service that received the message. |
| 824 | */ |
Mingyang Sun | a09adda | 2022-02-16 18:11:33 +0800 | [diff] [blame] | 825 | if (!SERVICE_ENABLED_MM_IOVEC(handle->service->p_ldinf->flags)) { |
Shawn Shan | 038348e | 2021-09-08 17:11:04 +0800 | [diff] [blame] | 826 | tfm_core_panic(); |
| 827 | } |
| 828 | |
| 829 | /* |
| 830 | * It is a fatal error if message handle does not refer to a request |
| 831 | * message. |
| 832 | */ |
Mingyang Sun | a09adda | 2022-02-16 18:11:33 +0800 | [diff] [blame] | 833 | if (handle->msg.type < PSA_IPC_CALL) { |
Shawn Shan | 038348e | 2021-09-08 17:11:04 +0800 | [diff] [blame] | 834 | tfm_core_panic(); |
| 835 | } |
| 836 | |
| 837 | /* |
| 838 | * It is a fatal error if outvec_idx is equal to or greater than |
| 839 | * PSA_MAX_IOVEC. |
| 840 | */ |
| 841 | if (outvec_idx >= PSA_MAX_IOVEC) { |
| 842 | tfm_core_panic(); |
| 843 | } |
| 844 | |
| 845 | /* It is a fatal error if the output vector has length zero. */ |
Mingyang Sun | a09adda | 2022-02-16 18:11:33 +0800 | [diff] [blame] | 846 | if (handle->msg.out_size[outvec_idx] == 0) { |
Shawn Shan | 038348e | 2021-09-08 17:11:04 +0800 | [diff] [blame] | 847 | tfm_core_panic(); |
| 848 | } |
| 849 | |
| 850 | /* |
| 851 | * It is a fatal error if the output vector has already been mapped using |
| 852 | * psa_map_outvec(). |
| 853 | */ |
Mingyang Sun | a09adda | 2022-02-16 18:11:33 +0800 | [diff] [blame] | 854 | if (IOVEC_IS_MAPPED(handle, (outvec_idx + OUTVEC_IDX_BASE))) { |
Shawn Shan | 038348e | 2021-09-08 17:11:04 +0800 | [diff] [blame] | 855 | tfm_core_panic(); |
| 856 | } |
| 857 | |
| 858 | /* |
| 859 | * It is a fatal error if the output vector has already been accessed |
| 860 | * using psa_write(). |
| 861 | */ |
Mingyang Sun | a09adda | 2022-02-16 18:11:33 +0800 | [diff] [blame] | 862 | if (IOVEC_IS_ACCESSED(handle, (outvec_idx + OUTVEC_IDX_BASE))) { |
Shawn Shan | 038348e | 2021-09-08 17:11:04 +0800 | [diff] [blame] | 863 | tfm_core_panic(); |
| 864 | } |
| 865 | |
| 866 | /* |
| 867 | * It is a fatal error if the output vector is invalid or not read-write. |
| 868 | */ |
Xinyu Zhang | 6ad0703 | 2022-08-10 14:45:56 +0800 | [diff] [blame] | 869 | FIH_CALL(tfm_hal_memory_check, fih_rc, |
| 870 | partition->boundary, (uintptr_t)handle->outvec[outvec_idx].base, |
| 871 | handle->outvec[outvec_idx].len, TFM_HAL_ACCESS_READWRITE); |
| 872 | if (fih_not_eq(fih_rc, fih_int_encode(PSA_SUCCESS))) { |
Shawn Shan | 038348e | 2021-09-08 17:11:04 +0800 | [diff] [blame] | 873 | tfm_core_panic(); |
| 874 | } |
Mingyang Sun | a09adda | 2022-02-16 18:11:33 +0800 | [diff] [blame] | 875 | SET_IOVEC_MAPPED(handle, (outvec_idx + OUTVEC_IDX_BASE)); |
Shawn Shan | 038348e | 2021-09-08 17:11:04 +0800 | [diff] [blame] | 876 | |
Mingyang Sun | a09adda | 2022-02-16 18:11:33 +0800 | [diff] [blame] | 877 | return handle->outvec[outvec_idx].base; |
Shawn Shan | 038348e | 2021-09-08 17:11:04 +0800 | [diff] [blame] | 878 | } |
| 879 | |
| 880 | void tfm_spm_partition_psa_unmap_outvec(psa_handle_t msg_handle, |
| 881 | uint32_t outvec_idx, size_t len) |
| 882 | { |
Ken Liu | c9313eb | 2023-02-22 15:45:54 +0800 | [diff] [blame] | 883 | struct connection_t *handle; |
Shawn Shan | 038348e | 2021-09-08 17:11:04 +0800 | [diff] [blame] | 884 | |
| 885 | /* It is a fatal error if message handle is invalid */ |
Ken Liu | c9313eb | 2023-02-22 15:45:54 +0800 | [diff] [blame] | 886 | handle = spm_msg_handle_to_connection(msg_handle); |
Mingyang Sun | a09adda | 2022-02-16 18:11:33 +0800 | [diff] [blame] | 887 | if (!handle) { |
Shawn Shan | 038348e | 2021-09-08 17:11:04 +0800 | [diff] [blame] | 888 | tfm_core_panic(); |
| 889 | } |
| 890 | |
| 891 | /* |
| 892 | * It is a fatal error if MM-IOVEC has not been enabled for the RoT |
| 893 | * Service that received the message. |
| 894 | */ |
Mingyang Sun | a09adda | 2022-02-16 18:11:33 +0800 | [diff] [blame] | 895 | if (!SERVICE_ENABLED_MM_IOVEC(handle->service->p_ldinf->flags)) { |
Shawn Shan | 038348e | 2021-09-08 17:11:04 +0800 | [diff] [blame] | 896 | tfm_core_panic(); |
| 897 | } |
| 898 | |
| 899 | /* |
| 900 | * It is a fatal error if message handle does not refer to a request |
| 901 | * message. |
| 902 | */ |
Mingyang Sun | a09adda | 2022-02-16 18:11:33 +0800 | [diff] [blame] | 903 | if (handle->msg.type < PSA_IPC_CALL) { |
Shawn Shan | 038348e | 2021-09-08 17:11:04 +0800 | [diff] [blame] | 904 | tfm_core_panic(); |
| 905 | } |
| 906 | |
| 907 | /* |
| 908 | * It is a fatal error if outvec_idx is equal to or greater than |
| 909 | * PSA_MAX_IOVEC. |
| 910 | */ |
| 911 | if (outvec_idx >= PSA_MAX_IOVEC) { |
| 912 | tfm_core_panic(); |
| 913 | } |
| 914 | |
| 915 | /* |
| 916 | * It is a fatal error if len is greater than the output vector size. |
| 917 | */ |
Mingyang Sun | a09adda | 2022-02-16 18:11:33 +0800 | [diff] [blame] | 918 | if (len > handle->msg.out_size[outvec_idx]) { |
Shawn Shan | 038348e | 2021-09-08 17:11:04 +0800 | [diff] [blame] | 919 | tfm_core_panic(); |
| 920 | } |
| 921 | |
| 922 | /* |
| 923 | * It is a fatal error if The output vector has not been mapped by a call to |
| 924 | * psa_map_outvec(). |
| 925 | */ |
Mingyang Sun | a09adda | 2022-02-16 18:11:33 +0800 | [diff] [blame] | 926 | if (!IOVEC_IS_MAPPED(handle, (outvec_idx + OUTVEC_IDX_BASE))) { |
Shawn Shan | 038348e | 2021-09-08 17:11:04 +0800 | [diff] [blame] | 927 | tfm_core_panic(); |
| 928 | } |
| 929 | |
| 930 | /* |
| 931 | * It is a fatal error if the output vector has already been unmapped by a |
| 932 | * call to psa_unmap_outvec(). |
| 933 | */ |
Mingyang Sun | a09adda | 2022-02-16 18:11:33 +0800 | [diff] [blame] | 934 | if (IOVEC_IS_UNMAPPED(handle, (outvec_idx + OUTVEC_IDX_BASE))) { |
Shawn Shan | 038348e | 2021-09-08 17:11:04 +0800 | [diff] [blame] | 935 | tfm_core_panic(); |
| 936 | } |
| 937 | |
Mingyang Sun | a09adda | 2022-02-16 18:11:33 +0800 | [diff] [blame] | 938 | SET_IOVEC_UNMAPPED(handle, (outvec_idx + OUTVEC_IDX_BASE)); |
Shawn Shan | 038348e | 2021-09-08 17:11:04 +0800 | [diff] [blame] | 939 | |
| 940 | /* Update the write number */ |
Mingyang Sun | a09adda | 2022-02-16 18:11:33 +0800 | [diff] [blame] | 941 | handle->outvec[outvec_idx].len = len; |
Shawn Shan | 038348e | 2021-09-08 17:11:04 +0800 | [diff] [blame] | 942 | } |
| 943 | |
| 944 | #endif /* PSA_FRAMEWORK_HAS_MM_IOVEC */ |