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