Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 1 | /* |
Sherry Zhang | dcab286 | 2022-01-10 10:43:31 +0800 | [diff] [blame] | 2 | * Copyright (c) 2018-2022, Arm Limited. All rights reserved. |
Chris Brand | b4c2b00 | 2022-07-21 12:54:00 -0700 | [diff] [blame] | 3 | * Copyright (c) 2021-2022 Cypress Semiconductor Corporation (an Infineon |
| 4 | * company) or an affiliate of Cypress Semiconductor Corporation. All rights |
| 5 | * reserved. |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 6 | * |
| 7 | * SPDX-License-Identifier: BSD-3-Clause |
| 8 | * |
| 9 | */ |
Mingyang Sun | da01a97 | 2019-07-12 17:32:59 +0800 | [diff] [blame] | 10 | |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 11 | #include <inttypes.h> |
| 12 | #include <stdbool.h> |
Summer Qin | 22c301a | 2022-04-27 17:36:00 +0800 | [diff] [blame] | 13 | #include <stdint.h> |
Ken Liu | 24dffb2 | 2021-02-10 11:03:58 +0800 | [diff] [blame] | 14 | #include "bitops.h" |
Mingyang Sun | 4609ac7 | 2022-02-08 18:56:35 +0800 | [diff] [blame] | 15 | #include "config_impl.h" |
Xinyu Zhang | cdbe362 | 2022-10-31 14:34:25 +0800 | [diff] [blame^] | 16 | #include "config_spm.h" |
Ken Liu | 92ede9f | 2021-10-20 09:35:00 +0800 | [diff] [blame] | 17 | #include "critical_section.h" |
Ken Liu | f39d8eb | 2021-10-07 12:55:33 +0800 | [diff] [blame] | 18 | #include "current.h" |
David Hu | f07e97d | 2021-02-15 22:05:40 +0800 | [diff] [blame] | 19 | #include "fih.h" |
Jamie Fox | cc31d40 | 2019-01-28 17:13:52 +0000 | [diff] [blame] | 20 | #include "psa/client.h" |
| 21 | #include "psa/service.h" |
Ken Liu | 5d73c87 | 2021-08-19 19:23:17 +0800 | [diff] [blame] | 22 | #include "thread.h" |
Ken Liu | bcae38b | 2021-01-20 15:47:44 +0800 | [diff] [blame] | 23 | #include "internal_errors.h" |
Mingyang Sun | d44522a | 2020-01-16 16:48:37 +0800 | [diff] [blame] | 24 | #include "tfm_api.h" |
Kevin Peng | b20b032 | 2022-02-09 16:47:19 +0800 | [diff] [blame] | 25 | #include "tfm_arch.h" |
Mingyang Sun | d1ed673 | 2020-08-26 15:52:21 +0800 | [diff] [blame] | 26 | #include "tfm_hal_defs.h" |
Kevin Peng | d399a1f | 2021-09-08 15:33:14 +0800 | [diff] [blame] | 27 | #include "tfm_hal_interrupt.h" |
Mingyang Sun | d1ed673 | 2020-08-26 15:52:21 +0800 | [diff] [blame] | 28 | #include "tfm_hal_isolation.h" |
Mingyang Sun | 7397b4f | 2020-06-17 15:07:45 +0800 | [diff] [blame] | 29 | #include "spm_ipc.h" |
Mingyang Sun | d44522a | 2020-01-16 16:48:37 +0800 | [diff] [blame] | 30 | #include "tfm_peripherals_def.h" |
Kevin Peng | 385fda8 | 2021-08-18 10:41:19 +0800 | [diff] [blame] | 31 | #include "tfm_nspm.h" |
Mingyang Sun | d44522a | 2020-01-16 16:48:37 +0800 | [diff] [blame] | 32 | #include "tfm_rpc.h" |
Mingyang Sun | d44522a | 2020-01-16 16:48:37 +0800 | [diff] [blame] | 33 | #include "tfm_core_trustzone.h" |
Ken Liu | 24dffb2 | 2021-02-10 11:03:58 +0800 | [diff] [blame] | 34 | #include "lists.h" |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 35 | #include "tfm_pools.h" |
Mingyang Sun | 22a3faf | 2021-07-09 15:32:47 +0800 | [diff] [blame] | 36 | #include "region.h" |
Mingyang Sun | 7397b4f | 2020-06-17 15:07:45 +0800 | [diff] [blame] | 37 | #include "psa_manifest/pid.h" |
Mingyang Sun | deae45d | 2021-09-06 15:31:07 +0800 | [diff] [blame] | 38 | #include "ffm/backend.h" |
Mingyang Sun | 00df235 | 2021-04-15 15:46:08 +0800 | [diff] [blame] | 39 | #include "load/partition_defs.h" |
| 40 | #include "load/service_defs.h" |
Ken Liu | 8668628 | 2021-04-27 11:11:15 +0800 | [diff] [blame] | 41 | #include "load/asset_defs.h" |
Ken Liu | acd2a57 | 2021-05-12 16:19:04 +0800 | [diff] [blame] | 42 | #include "load/spm_load_api.h" |
Sherry Zhnag | 482b88b | 2021-08-19 17:51:47 +0800 | [diff] [blame] | 43 | #include "tfm_nspm.h" |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 44 | |
Sherry Zhang | 86a71c6 | 2022-01-12 18:19:02 +0800 | [diff] [blame] | 45 | #if !(defined CONFIG_TFM_CONN_HANDLE_MAX_NUM) || (CONFIG_TFM_CONN_HANDLE_MAX_NUM == 0) |
| 46 | #error "CONFIG_TFM_CONN_HANDLE_MAX_NUM must be defined and not zero." |
| 47 | #endif |
| 48 | |
Ken Liu | ea45b0d | 2021-05-22 17:41:25 +0800 | [diff] [blame] | 49 | /* Partition and service runtime data list head/runtime data table */ |
Ken Liu | ea45b0d | 2021-05-22 17:41:25 +0800 | [diff] [blame] | 50 | static struct service_head_t services_listhead; |
Ken Liu | b3b2cb6 | 2021-05-22 00:39:28 +0800 | [diff] [blame] | 51 | struct service_t *stateless_services_ref_tbl[STATIC_HANDLE_NUM_LIMIT]; |
Summer Qin | d99509f | 2019-08-02 17:36:58 +0800 | [diff] [blame] | 52 | |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 53 | /* Pools */ |
Ken Liu | 0bed7e0 | 2022-02-10 12:38:07 +0800 | [diff] [blame] | 54 | TFM_POOL_DECLARE(conn_handle_pool, sizeof(struct conn_handle_t), |
Sherry Zhang | 86a71c6 | 2022-01-12 18:19:02 +0800 | [diff] [blame] | 55 | CONFIG_TFM_CONN_HANDLE_MAX_NUM); |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 56 | |
Summer Qin | 373feb1 | 2020-03-27 15:35:33 +0800 | [diff] [blame] | 57 | /*********************** Connection handle conversion APIs *******************/ |
| 58 | |
Summer Qin | 373feb1 | 2020-03-27 15:35:33 +0800 | [diff] [blame] | 59 | #define CONVERSION_FACTOR_BITOFFSET 3 |
| 60 | #define CONVERSION_FACTOR_VALUE (1 << CONVERSION_FACTOR_BITOFFSET) |
| 61 | /* Set 32 as the maximum */ |
| 62 | #define CONVERSION_FACTOR_VALUE_MAX 0x20 |
| 63 | |
| 64 | #if CONVERSION_FACTOR_VALUE > CONVERSION_FACTOR_VALUE_MAX |
| 65 | #error "CONVERSION FACTOR OUT OF RANGE" |
| 66 | #endif |
| 67 | |
| 68 | static uint32_t loop_index; |
| 69 | |
| 70 | /* |
| 71 | * A handle instance psa_handle_t allocated inside SPM is actually a memory |
| 72 | * address among the handle pool. Return this handle to the client directly |
| 73 | * exposes information of secure memory address. In this case, converting the |
| 74 | * handle into another value does not represent the memory address to avoid |
| 75 | * exposing secure memory directly to clients. |
| 76 | * |
| 77 | * This function converts the handle instance into another value by scaling the |
| 78 | * handle in pool offset, the converted value is named as a user handle. |
| 79 | * |
| 80 | * The formula: |
| 81 | * user_handle = (handle_instance - POOL_START) * CONVERSION_FACTOR_VALUE + |
| 82 | * CLIENT_HANDLE_VALUE_MIN + loop_index |
| 83 | * where: |
| 84 | * CONVERSION_FACTOR_VALUE = 1 << CONVERSION_FACTOR_BITOFFSET, and should not |
| 85 | * exceed CONVERSION_FACTOR_VALUE_MAX. |
| 86 | * |
| 87 | * handle_instance in RANGE[POOL_START, POOL_END] |
| 88 | * user_handle in RANGE[CLIENT_HANDLE_VALUE_MIN, 0x3FFFFFFF] |
| 89 | * loop_index in RANGE[0, CONVERSION_FACTOR_VALUE - 1] |
| 90 | * |
| 91 | * note: |
| 92 | * loop_index is used to promise same handle instance is converted into |
| 93 | * different user handles in short time. |
| 94 | */ |
Ken Liu | 0bed7e0 | 2022-02-10 12:38:07 +0800 | [diff] [blame] | 95 | psa_handle_t tfm_spm_to_user_handle(struct conn_handle_t *handle_instance) |
Summer Qin | 373feb1 | 2020-03-27 15:35:33 +0800 | [diff] [blame] | 96 | { |
| 97 | psa_handle_t user_handle; |
| 98 | |
| 99 | loop_index = (loop_index + 1) % CONVERSION_FACTOR_VALUE; |
| 100 | user_handle = (psa_handle_t)((((uintptr_t)handle_instance - |
| 101 | (uintptr_t)conn_handle_pool) << CONVERSION_FACTOR_BITOFFSET) + |
| 102 | CLIENT_HANDLE_VALUE_MIN + loop_index); |
| 103 | |
| 104 | return user_handle; |
| 105 | } |
| 106 | |
| 107 | /* |
| 108 | * This function converts a user handle into a corresponded handle instance. |
| 109 | * The converted value is validated before returning, an invalid handle instance |
| 110 | * is returned as NULL. |
| 111 | * |
| 112 | * The formula: |
| 113 | * handle_instance = ((user_handle - CLIENT_HANDLE_VALUE_MIN) / |
| 114 | * CONVERSION_FACTOR_VALUE) + POOL_START |
| 115 | * where: |
| 116 | * CONVERSION_FACTOR_VALUE = 1 << CONVERSION_FACTOR_BITOFFSET, and should not |
| 117 | * exceed CONVERSION_FACTOR_VALUE_MAX. |
| 118 | * |
| 119 | * handle_instance in RANGE[POOL_START, POOL_END] |
| 120 | * user_handle in RANGE[CLIENT_HANDLE_VALUE_MIN, 0x3FFFFFFF] |
| 121 | * loop_index in RANGE[0, CONVERSION_FACTOR_VALUE - 1] |
| 122 | */ |
Ken Liu | 0bed7e0 | 2022-02-10 12:38:07 +0800 | [diff] [blame] | 123 | struct conn_handle_t *tfm_spm_to_handle_instance(psa_handle_t user_handle) |
Summer Qin | 373feb1 | 2020-03-27 15:35:33 +0800 | [diff] [blame] | 124 | { |
Ken Liu | 0bed7e0 | 2022-02-10 12:38:07 +0800 | [diff] [blame] | 125 | struct conn_handle_t *handle_instance; |
Summer Qin | 373feb1 | 2020-03-27 15:35:33 +0800 | [diff] [blame] | 126 | |
| 127 | if (user_handle == PSA_NULL_HANDLE) { |
| 128 | return NULL; |
| 129 | } |
| 130 | |
Ken Liu | 0bed7e0 | 2022-02-10 12:38:07 +0800 | [diff] [blame] | 131 | handle_instance = (struct conn_handle_t *)((((uintptr_t)user_handle - |
Summer Qin | 373feb1 | 2020-03-27 15:35:33 +0800 | [diff] [blame] | 132 | CLIENT_HANDLE_VALUE_MIN) >> CONVERSION_FACTOR_BITOFFSET) + |
| 133 | (uintptr_t)conn_handle_pool); |
| 134 | |
| 135 | return handle_instance; |
| 136 | } |
| 137 | |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 138 | /* Service handle management functions */ |
Kevin Peng | e61e705 | 2022-01-27 14:57:06 +0800 | [diff] [blame] | 139 | struct conn_handle_t *tfm_spm_create_conn_handle(void) |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 140 | { |
Ken Liu | 0bed7e0 | 2022-02-10 12:38:07 +0800 | [diff] [blame] | 141 | struct conn_handle_t *p_handle; |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 142 | |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 143 | /* Get buffer for handle list structure from handle pool */ |
Ken Liu | 0bed7e0 | 2022-02-10 12:38:07 +0800 | [diff] [blame] | 144 | p_handle = (struct conn_handle_t *)tfm_pool_alloc(conn_handle_pool); |
Edison Ai | 9cc2624 | 2019-08-06 11:28:04 +0800 | [diff] [blame] | 145 | if (!p_handle) { |
Summer Qin | 630c76b | 2020-05-20 10:32:58 +0800 | [diff] [blame] | 146 | return NULL; |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 147 | } |
| 148 | |
Kevin Peng | 2cc2572 | 2021-11-18 11:46:02 +0800 | [diff] [blame] | 149 | spm_memset(p_handle, 0, sizeof(*p_handle)); |
| 150 | |
Shawn Shan | cc39fcb | 2019-11-13 15:38:16 +0800 | [diff] [blame] | 151 | p_handle->status = TFM_HANDLE_STATUS_IDLE; |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 152 | |
Summer Qin | 630c76b | 2020-05-20 10:32:58 +0800 | [diff] [blame] | 153 | return p_handle; |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 154 | } |
| 155 | |
Ken Liu | ad3f3e6 | 2022-03-04 22:23:52 +0800 | [diff] [blame] | 156 | psa_status_t tfm_spm_validate_conn_handle(const struct conn_handle_t *handle) |
Summer Qin | 1ce712a | 2019-10-14 18:04:05 +0800 | [diff] [blame] | 157 | { |
Kevin Peng | e61e705 | 2022-01-27 14:57:06 +0800 | [diff] [blame] | 158 | /* Check the handle address is valid */ |
Summer Qin | 1ce712a | 2019-10-14 18:04:05 +0800 | [diff] [blame] | 159 | if (is_valid_chunk_data_in_pool(conn_handle_pool, |
Ken Liu | ad3f3e6 | 2022-03-04 22:23:52 +0800 | [diff] [blame] | 160 | (uint8_t *)handle) != true) { |
Ken Liu | bcae38b | 2021-01-20 15:47:44 +0800 | [diff] [blame] | 161 | return SPM_ERROR_GENERIC; |
Summer Qin | 1ce712a | 2019-10-14 18:04:05 +0800 | [diff] [blame] | 162 | } |
| 163 | |
Ken Liu | ad3f3e6 | 2022-03-04 22:23:52 +0800 | [diff] [blame] | 164 | return PSA_SUCCESS; |
Summer Qin | 1ce712a | 2019-10-14 18:04:05 +0800 | [diff] [blame] | 165 | } |
| 166 | |
Ken Liu | ad3f3e6 | 2022-03-04 22:23:52 +0800 | [diff] [blame] | 167 | void tfm_spm_free_conn_handle(struct conn_handle_t *conn_handle) |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 168 | { |
Mingyang Sun | 620c856 | 2021-11-10 11:44:58 +0800 | [diff] [blame] | 169 | struct critical_section_t cs_assert = CRITICAL_SECTION_STATIC_INIT; |
| 170 | |
Summer Qin | 1056d1c | 2022-10-19 16:07:15 +0800 | [diff] [blame] | 171 | SPM_ASSERT(conn_handle != NULL); |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 172 | |
Mingyang Sun | 620c856 | 2021-11-10 11:44:58 +0800 | [diff] [blame] | 173 | CRITICAL_SECTION_ENTER(cs_assert); |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 174 | /* Back handle buffer to pool */ |
Ken Liu | 66ca613 | 2021-02-24 08:49:51 +0800 | [diff] [blame] | 175 | tfm_pool_free(conn_handle_pool, conn_handle); |
Mingyang Sun | 620c856 | 2021-11-10 11:44:58 +0800 | [diff] [blame] | 176 | CRITICAL_SECTION_LEAVE(cs_assert); |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 177 | } |
| 178 | |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 179 | /* Partition management functions */ |
Mingyang Sun | d44522a | 2020-01-16 16:48:37 +0800 | [diff] [blame] | 180 | |
Mingyang Sun | 4609ac7 | 2022-02-08 18:56:35 +0800 | [diff] [blame] | 181 | /* This API is only used in IPC backend. */ |
| 182 | #if CONFIG_TFM_SPM_BACKEND_IPC == 1 |
Ken Liu | 0bed7e0 | 2022-02-10 12:38:07 +0800 | [diff] [blame] | 183 | struct conn_handle_t *spm_get_handle_by_signal(struct partition_t *p_ptn, |
Ken Liu | 5a28da3 | 2022-01-19 14:37:05 +0800 | [diff] [blame] | 184 | psa_signal_t signal) |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 185 | { |
Mingyang Sun | a09adda | 2022-02-16 18:11:33 +0800 | [diff] [blame] | 186 | struct conn_handle_t *p_handle_iter; |
| 187 | struct conn_handle_t **pr_handle_iter, **last_found_handle_holder = NULL; |
Ken Liu | 92ede9f | 2021-10-20 09:35:00 +0800 | [diff] [blame] | 188 | struct critical_section_t cs_assert = CRITICAL_SECTION_STATIC_INIT; |
Ken Liu | 5a28da3 | 2022-01-19 14:37:05 +0800 | [diff] [blame] | 189 | uint32_t nr_found_msgs = 0; |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 190 | |
Mingyang Sun | 620c856 | 2021-11-10 11:44:58 +0800 | [diff] [blame] | 191 | CRITICAL_SECTION_ENTER(cs_assert); |
Ken Liu | 5a28da3 | 2022-01-19 14:37:05 +0800 | [diff] [blame] | 192 | |
| 193 | /* Return the last found message which applies a FIFO mechanism. */ |
Mingyang Sun | a09adda | 2022-02-16 18:11:33 +0800 | [diff] [blame] | 194 | UNI_LIST_FOREACH_NODE_PNODE(pr_handle_iter, p_handle_iter, |
| 195 | p_ptn, p_handles) { |
| 196 | if (p_handle_iter->service->p_ldinf->signal == signal) { |
| 197 | last_found_handle_holder = pr_handle_iter; |
Ken Liu | 5a28da3 | 2022-01-19 14:37:05 +0800 | [diff] [blame] | 198 | nr_found_msgs++; |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 199 | } |
| 200 | } |
Mingyang Sun | 73056b6 | 2020-07-03 15:18:46 +0800 | [diff] [blame] | 201 | |
Mingyang Sun | a09adda | 2022-02-16 18:11:33 +0800 | [diff] [blame] | 202 | if (last_found_handle_holder) { |
| 203 | p_handle_iter = *last_found_handle_holder; |
| 204 | UNI_LIST_REMOVE_NODE_BY_PNODE(last_found_handle_holder, p_handles); |
Ken Liu | 5a28da3 | 2022-01-19 14:37:05 +0800 | [diff] [blame] | 205 | |
Ken Liu | 5a28da3 | 2022-01-19 14:37:05 +0800 | [diff] [blame] | 206 | if (nr_found_msgs == 1) { |
| 207 | p_ptn->signals_asserted &= ~signal; |
| 208 | } |
| 209 | } |
| 210 | |
Ken Liu | 92ede9f | 2021-10-20 09:35:00 +0800 | [diff] [blame] | 211 | CRITICAL_SECTION_LEAVE(cs_assert); |
Mingyang Sun | 73056b6 | 2020-07-03 15:18:46 +0800 | [diff] [blame] | 212 | |
Mingyang Sun | a09adda | 2022-02-16 18:11:33 +0800 | [diff] [blame] | 213 | return p_handle_iter; |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 214 | } |
Mingyang Sun | a09adda | 2022-02-16 18:11:33 +0800 | [diff] [blame] | 215 | #endif /* CONFIG_TFM_SPM_BACKEND_IPC == 1 */ |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 216 | |
Mingyang Sun | 783a59b | 2021-04-20 15:52:18 +0800 | [diff] [blame] | 217 | struct service_t *tfm_spm_get_service_by_sid(uint32_t sid) |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 218 | { |
Feder.Liang | aeb5a79 | 2021-08-10 16:12:56 +0800 | [diff] [blame] | 219 | struct service_t *p_prev, *p_curr; |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 220 | |
Ken Liu | 5a28da3 | 2022-01-19 14:37:05 +0800 | [diff] [blame] | 221 | UNI_LIST_FOREACH_NODE_PREV(p_prev, p_curr, &services_listhead, next) { |
Feder.Liang | aeb5a79 | 2021-08-10 16:12:56 +0800 | [diff] [blame] | 222 | if (p_curr->p_ldinf->sid == sid) { |
Ken Liu | 5a28da3 | 2022-01-19 14:37:05 +0800 | [diff] [blame] | 223 | UNI_LIST_MOVE_AFTER(&services_listhead, p_prev, p_curr, next); |
Feder.Liang | aeb5a79 | 2021-08-10 16:12:56 +0800 | [diff] [blame] | 224 | return p_curr; |
Mingyang Sun | ef42f44 | 2021-06-11 15:07:58 +0800 | [diff] [blame] | 225 | } |
| 226 | } |
| 227 | |
Ken Liu | ea45b0d | 2021-05-22 17:41:25 +0800 | [diff] [blame] | 228 | return NULL; |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 229 | } |
| 230 | |
Kevin Peng | 613b417 | 2022-02-15 14:41:44 +0800 | [diff] [blame] | 231 | #if CONFIG_TFM_DOORBELL_API == 1 |
Mingyang Sun | d44522a | 2020-01-16 16:48:37 +0800 | [diff] [blame] | 232 | /** |
| 233 | * \brief Get the partition context by partition ID. |
| 234 | * |
| 235 | * \param[in] partition_id Partition identity |
| 236 | * |
| 237 | * \retval NULL Failed |
| 238 | * \retval "Not NULL" Target partition context pointer, |
Mingyang Sun | ae70d8d | 2020-06-30 15:56:05 +0800 | [diff] [blame] | 239 | * \ref partition_t structures |
Mingyang Sun | d44522a | 2020-01-16 16:48:37 +0800 | [diff] [blame] | 240 | */ |
Kevin Peng | eca45b9 | 2021-02-09 14:46:50 +0800 | [diff] [blame] | 241 | struct partition_t *tfm_spm_get_partition_by_id(int32_t partition_id) |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 242 | { |
Ken Liu | ea45b0d | 2021-05-22 17:41:25 +0800 | [diff] [blame] | 243 | struct partition_t *p_part; |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 244 | |
Ken Liu | 5a28da3 | 2022-01-19 14:37:05 +0800 | [diff] [blame] | 245 | UNI_LIST_FOREACH(p_part, PARTITION_LIST_ADDR, next) { |
Ken Liu | ea45b0d | 2021-05-22 17:41:25 +0800 | [diff] [blame] | 246 | if (p_part->p_ldinf->pid == partition_id) { |
| 247 | return p_part; |
| 248 | } |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 249 | } |
Ken Liu | ea45b0d | 2021-05-22 17:41:25 +0800 | [diff] [blame] | 250 | |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 251 | return NULL; |
| 252 | } |
Kevin Peng | 613b417 | 2022-02-15 14:41:44 +0800 | [diff] [blame] | 253 | #endif /* CONFIG_TFM_DOORBELL_API == 1 */ |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 254 | |
Mingyang Sun | 783a59b | 2021-04-20 15:52:18 +0800 | [diff] [blame] | 255 | int32_t tfm_spm_check_client_version(struct service_t *service, |
Jaykumar Pitambarbhai Patel | 3a98602 | 2019-10-08 17:37:15 +0530 | [diff] [blame] | 256 | uint32_t version) |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 257 | { |
Summer Qin | 1056d1c | 2022-10-19 16:07:15 +0800 | [diff] [blame] | 258 | SPM_ASSERT(service); |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 259 | |
Ken Liu | acd2a57 | 2021-05-12 16:19:04 +0800 | [diff] [blame] | 260 | switch (SERVICE_GET_VERSION_POLICY(service->p_ldinf->flags)) { |
Ken Liu | b3b2cb6 | 2021-05-22 00:39:28 +0800 | [diff] [blame] | 261 | case SERVICE_VERSION_POLICY_RELAXED: |
Ken Liu | acd2a57 | 2021-05-12 16:19:04 +0800 | [diff] [blame] | 262 | if (version > service->p_ldinf->version) { |
Ken Liu | bcae38b | 2021-01-20 15:47:44 +0800 | [diff] [blame] | 263 | return SPM_ERROR_VERSION; |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 264 | } |
| 265 | break; |
Ken Liu | b3b2cb6 | 2021-05-22 00:39:28 +0800 | [diff] [blame] | 266 | case SERVICE_VERSION_POLICY_STRICT: |
Ken Liu | acd2a57 | 2021-05-12 16:19:04 +0800 | [diff] [blame] | 267 | if (version != service->p_ldinf->version) { |
Ken Liu | bcae38b | 2021-01-20 15:47:44 +0800 | [diff] [blame] | 268 | return SPM_ERROR_VERSION; |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 269 | } |
| 270 | break; |
| 271 | default: |
Ken Liu | bcae38b | 2021-01-20 15:47:44 +0800 | [diff] [blame] | 272 | return SPM_ERROR_VERSION; |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 273 | } |
Ken Liu | ad3f3e6 | 2022-03-04 22:23:52 +0800 | [diff] [blame] | 274 | return PSA_SUCCESS; |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 275 | } |
| 276 | |
Edison Ai | e728fbf | 2019-11-13 09:37:12 +0800 | [diff] [blame] | 277 | int32_t tfm_spm_check_authorization(uint32_t sid, |
Mingyang Sun | 783a59b | 2021-04-20 15:52:18 +0800 | [diff] [blame] | 278 | struct service_t *service, |
Summer Qin | 618e8c3 | 2019-12-09 10:47:20 +0800 | [diff] [blame] | 279 | bool ns_caller) |
Edison Ai | e728fbf | 2019-11-13 09:37:12 +0800 | [diff] [blame] | 280 | { |
Mingyang Sun | ae70d8d | 2020-06-30 15:56:05 +0800 | [diff] [blame] | 281 | struct partition_t *partition = NULL; |
Chris Brand | 1fb796d | 2022-10-18 16:54:25 -0700 | [diff] [blame] | 282 | const uint32_t *dep; |
Edison Ai | e728fbf | 2019-11-13 09:37:12 +0800 | [diff] [blame] | 283 | int32_t i; |
| 284 | |
Summer Qin | 1056d1c | 2022-10-19 16:07:15 +0800 | [diff] [blame] | 285 | SPM_ASSERT(service); |
Edison Ai | e728fbf | 2019-11-13 09:37:12 +0800 | [diff] [blame] | 286 | |
| 287 | if (ns_caller) { |
Ken Liu | acd2a57 | 2021-05-12 16:19:04 +0800 | [diff] [blame] | 288 | if (!SERVICE_IS_NS_ACCESSIBLE(service->p_ldinf->flags)) { |
Ken Liu | bcae38b | 2021-01-20 15:47:44 +0800 | [diff] [blame] | 289 | return SPM_ERROR_GENERIC; |
Edison Ai | e728fbf | 2019-11-13 09:37:12 +0800 | [diff] [blame] | 290 | } |
| 291 | } else { |
Kevin Peng | cdf3ae2 | 2022-01-19 14:53:52 +0800 | [diff] [blame] | 292 | partition = GET_CURRENT_COMPONENT(); |
Edison Ai | e728fbf | 2019-11-13 09:37:12 +0800 | [diff] [blame] | 293 | if (!partition) { |
Edison Ai | 9059ea0 | 2019-11-28 13:46:14 +0800 | [diff] [blame] | 294 | tfm_core_panic(); |
Edison Ai | e728fbf | 2019-11-13 09:37:12 +0800 | [diff] [blame] | 295 | } |
| 296 | |
Chris Brand | 1fb796d | 2022-10-18 16:54:25 -0700 | [diff] [blame] | 297 | dep = LOAD_INFO_DEPS(partition->p_ldinf); |
Ken Liu | acd2a57 | 2021-05-12 16:19:04 +0800 | [diff] [blame] | 298 | for (i = 0; i < partition->p_ldinf->ndeps; i++) { |
Mingyang Sun | 2b35266 | 2021-04-21 11:35:43 +0800 | [diff] [blame] | 299 | if (dep[i] == sid) { |
Edison Ai | e728fbf | 2019-11-13 09:37:12 +0800 | [diff] [blame] | 300 | break; |
| 301 | } |
| 302 | } |
| 303 | |
Ken Liu | acd2a57 | 2021-05-12 16:19:04 +0800 | [diff] [blame] | 304 | if (i == partition->p_ldinf->ndeps) { |
Ken Liu | bcae38b | 2021-01-20 15:47:44 +0800 | [diff] [blame] | 305 | return SPM_ERROR_GENERIC; |
Edison Ai | e728fbf | 2019-11-13 09:37:12 +0800 | [diff] [blame] | 306 | } |
| 307 | } |
Ken Liu | ad3f3e6 | 2022-03-04 22:23:52 +0800 | [diff] [blame] | 308 | return PSA_SUCCESS; |
Edison Ai | e728fbf | 2019-11-13 09:37:12 +0800 | [diff] [blame] | 309 | } |
| 310 | |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 311 | /* Message functions */ |
Summer Qin | 401cf81 | 2022-04-02 09:46:34 +0800 | [diff] [blame] | 312 | #if CONFIG_TFM_CONNECTION_BASED_SERVICE_API == 1 |
Kevin Peng | e61e705 | 2022-01-27 14:57:06 +0800 | [diff] [blame] | 313 | struct conn_handle_t *spm_get_handle_by_client_handle(psa_handle_t handle, |
| 314 | int32_t client_id) |
| 315 | { |
| 316 | struct conn_handle_t *p_conn_handle = tfm_spm_to_handle_instance(handle); |
| 317 | |
Ken Liu | ad3f3e6 | 2022-03-04 22:23:52 +0800 | [diff] [blame] | 318 | if (tfm_spm_validate_conn_handle(p_conn_handle) != PSA_SUCCESS) { |
Kevin Peng | e61e705 | 2022-01-27 14:57:06 +0800 | [diff] [blame] | 319 | return NULL; |
| 320 | } |
| 321 | |
| 322 | /* Validate the caller id in the connection handle equals client_id. */ |
| 323 | if (p_conn_handle->msg.client_id != client_id) { |
| 324 | return NULL; |
| 325 | } |
| 326 | |
| 327 | return p_conn_handle; |
| 328 | } |
Summer Qin | 401cf81 | 2022-04-02 09:46:34 +0800 | [diff] [blame] | 329 | #endif |
Kevin Peng | e61e705 | 2022-01-27 14:57:06 +0800 | [diff] [blame] | 330 | |
| 331 | struct conn_handle_t *spm_get_handle_by_msg_handle(psa_handle_t msg_handle) |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 332 | { |
| 333 | /* |
Mate Toth-Pal | a4b5d24 | 2019-09-23 09:14:47 +0200 | [diff] [blame] | 334 | * The message handler passed by the caller is considered invalid in the |
| 335 | * following cases: |
| 336 | * 1. Not a valid message handle. (The address of a message is not the |
| 337 | * address of a possible handle from the pool |
| 338 | * 2. Handle not belongs to the caller partition (The handle is either |
Mingyang Sun | a09adda | 2022-02-16 18:11:33 +0800 | [diff] [blame] | 339 | * unused, or owned by another partition) |
Mate Toth-Pal | a4b5d24 | 2019-09-23 09:14:47 +0200 | [diff] [blame] | 340 | * Check the conditions above |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 341 | */ |
Kevin Peng | eec41a8 | 2021-08-18 13:56:23 +0800 | [diff] [blame] | 342 | int32_t partition_id; |
Ken Liu | 0bed7e0 | 2022-02-10 12:38:07 +0800 | [diff] [blame] | 343 | struct conn_handle_t *p_conn_handle = |
Ken Liu | 5d73c87 | 2021-08-19 19:23:17 +0800 | [diff] [blame] | 344 | tfm_spm_to_handle_instance(msg_handle); |
Mate Toth-Pal | a4b5d24 | 2019-09-23 09:14:47 +0200 | [diff] [blame] | 345 | |
Ken Liu | ad3f3e6 | 2022-03-04 22:23:52 +0800 | [diff] [blame] | 346 | if (tfm_spm_validate_conn_handle(p_conn_handle) != PSA_SUCCESS) { |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 347 | return NULL; |
| 348 | } |
| 349 | |
Mate Toth-Pal | a4b5d24 | 2019-09-23 09:14:47 +0200 | [diff] [blame] | 350 | /* Check that the running partition owns the message */ |
Mingyang Sun | f3d2989 | 2019-07-10 17:50:23 +0800 | [diff] [blame] | 351 | partition_id = tfm_spm_partition_get_running_partition_id(); |
Ken Liu | 0bed7e0 | 2022-02-10 12:38:07 +0800 | [diff] [blame] | 352 | if (partition_id != p_conn_handle->service->partition->p_ldinf->pid) { |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 353 | return NULL; |
| 354 | } |
| 355 | |
Ken Liu | 0bed7e0 | 2022-02-10 12:38:07 +0800 | [diff] [blame] | 356 | return p_conn_handle; |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 357 | } |
| 358 | |
Mingyang Sun | a09adda | 2022-02-16 18:11:33 +0800 | [diff] [blame] | 359 | void spm_fill_message(struct conn_handle_t *conn_handle, |
Mingyang Sun | 783a59b | 2021-04-20 15:52:18 +0800 | [diff] [blame] | 360 | struct service_t *service, |
Ken Liu | 505b170 | 2020-05-29 13:19:58 +0800 | [diff] [blame] | 361 | psa_handle_t handle, |
Summer Qin | 1ce712a | 2019-10-14 18:04:05 +0800 | [diff] [blame] | 362 | int32_t type, int32_t client_id, |
Edison Ai | 9711582 | 2019-08-01 14:22:19 +0800 | [diff] [blame] | 363 | psa_invec *invec, size_t in_len, |
| 364 | psa_outvec *outvec, size_t out_len, |
| 365 | psa_outvec *caller_outvec) |
| 366 | { |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 367 | uint32_t i; |
| 368 | |
Summer Qin | 1056d1c | 2022-10-19 16:07:15 +0800 | [diff] [blame] | 369 | SPM_ASSERT(conn_handle); |
| 370 | SPM_ASSERT(service); |
| 371 | SPM_ASSERT(!(invec == NULL && in_len != 0)); |
| 372 | SPM_ASSERT(!(outvec == NULL && out_len != 0)); |
| 373 | SPM_ASSERT(in_len <= SIZE_MAX - out_len); |
| 374 | SPM_ASSERT(in_len + out_len <= PSA_MAX_IOVEC); |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 375 | |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 376 | /* Clear message buffer before using it */ |
Mingyang Sun | a09adda | 2022-02-16 18:11:33 +0800 | [diff] [blame] | 377 | spm_memset(&conn_handle->msg, 0, sizeof(psa_msg_t)); |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 378 | |
Mingyang Sun | a09adda | 2022-02-16 18:11:33 +0800 | [diff] [blame] | 379 | THRD_SYNC_INIT(&conn_handle->ack_evnt); |
Mingyang Sun | a09adda | 2022-02-16 18:11:33 +0800 | [diff] [blame] | 380 | conn_handle->service = service; |
| 381 | conn_handle->p_client = GET_CURRENT_COMPONENT(); |
| 382 | conn_handle->caller_outvec = caller_outvec; |
| 383 | conn_handle->msg.client_id = client_id; |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 384 | |
| 385 | /* Copy contents */ |
Mingyang Sun | a09adda | 2022-02-16 18:11:33 +0800 | [diff] [blame] | 386 | conn_handle->msg.type = type; |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 387 | |
| 388 | for (i = 0; i < in_len; i++) { |
Mingyang Sun | a09adda | 2022-02-16 18:11:33 +0800 | [diff] [blame] | 389 | conn_handle->msg.in_size[i] = invec[i].len; |
| 390 | conn_handle->invec[i].base = invec[i].base; |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 391 | } |
| 392 | |
| 393 | for (i = 0; i < out_len; i++) { |
Mingyang Sun | a09adda | 2022-02-16 18:11:33 +0800 | [diff] [blame] | 394 | conn_handle->msg.out_size[i] = outvec[i].len; |
| 395 | conn_handle->outvec[i].base = outvec[i].base; |
Ken Liu | 0bed7e0 | 2022-02-10 12:38:07 +0800 | [diff] [blame] | 396 | /* Out len is used to record the wrote number, set 0 here again */ |
Mingyang Sun | a09adda | 2022-02-16 18:11:33 +0800 | [diff] [blame] | 397 | conn_handle->outvec[i].len = 0; |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 398 | } |
| 399 | |
Ken Liu | 505b170 | 2020-05-29 13:19:58 +0800 | [diff] [blame] | 400 | /* Use the user connect handle as the message handle */ |
Mingyang Sun | a09adda | 2022-02-16 18:11:33 +0800 | [diff] [blame] | 401 | conn_handle->msg.handle = handle; |
| 402 | conn_handle->msg.rhandle = conn_handle->rhandle; |
David Hu | 46603dd | 2019-12-11 18:05:16 +0800 | [diff] [blame] | 403 | |
| 404 | /* Set the private data of NSPE client caller in multi-core topology */ |
| 405 | if (TFM_CLIENT_ID_IS_NS(client_id)) { |
Mingyang Sun | a09adda | 2022-02-16 18:11:33 +0800 | [diff] [blame] | 406 | tfm_rpc_set_caller_data(conn_handle, client_id); |
David Hu | 46603dd | 2019-12-11 18:05:16 +0800 | [diff] [blame] | 407 | } |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 408 | } |
| 409 | |
Kevin Peng | eec41a8 | 2021-08-18 13:56:23 +0800 | [diff] [blame] | 410 | int32_t tfm_spm_partition_get_running_partition_id(void) |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 411 | { |
Mingyang Sun | ae70d8d | 2020-06-30 15:56:05 +0800 | [diff] [blame] | 412 | struct partition_t *partition; |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 413 | |
Kevin Peng | cdf3ae2 | 2022-01-19 14:53:52 +0800 | [diff] [blame] | 414 | partition = GET_CURRENT_COMPONENT(); |
Ken Liu | acd2a57 | 2021-05-12 16:19:04 +0800 | [diff] [blame] | 415 | if (partition && partition->p_ldinf) { |
| 416 | return partition->p_ldinf->pid; |
Kevin Peng | 79c2bda | 2020-07-24 16:31:12 +0800 | [diff] [blame] | 417 | } else { |
| 418 | return INVALID_PARTITION_ID; |
| 419 | } |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 420 | } |
| 421 | |
Mingyang Sun | 22a3faf | 2021-07-09 15:32:47 +0800 | [diff] [blame] | 422 | bool tfm_spm_is_ns_caller(void) |
| 423 | { |
Kevin Peng | cdf3ae2 | 2022-01-19 14:53:52 +0800 | [diff] [blame] | 424 | struct partition_t *partition = GET_CURRENT_COMPONENT(); |
Ken Liu | 897e8f1 | 2022-02-10 03:21:17 +0100 | [diff] [blame] | 425 | |
| 426 | if (!partition) { |
| 427 | tfm_core_panic(); |
| 428 | } |
| 429 | |
Chris Brand | b4c2b00 | 2022-07-21 12:54:00 -0700 | [diff] [blame] | 430 | return IS_PARTITION_NS_AGENT(partition->p_ldinf); |
Mingyang Sun | 22a3faf | 2021-07-09 15:32:47 +0800 | [diff] [blame] | 431 | } |
| 432 | |
Kevin Peng | 385fda8 | 2021-08-18 10:41:19 +0800 | [diff] [blame] | 433 | int32_t tfm_spm_get_client_id(bool ns_caller) |
| 434 | { |
| 435 | int32_t client_id; |
| 436 | |
| 437 | if (ns_caller) { |
| 438 | client_id = tfm_nspm_get_current_client_id(); |
| 439 | } else { |
| 440 | client_id = tfm_spm_partition_get_running_partition_id(); |
| 441 | } |
| 442 | |
| 443 | if (ns_caller != (client_id < 0)) { |
| 444 | /* NS client ID must be negative and Secure ID must >= 0 */ |
| 445 | tfm_core_panic(); |
| 446 | } |
| 447 | |
| 448 | return client_id; |
| 449 | } |
| 450 | |
Ken Liu | ce2692d | 2020-02-11 12:39:36 +0800 | [diff] [blame] | 451 | uint32_t tfm_spm_init(void) |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 452 | { |
Mingyang Sun | ae70d8d | 2020-06-30 15:56:05 +0800 | [diff] [blame] | 453 | struct partition_t *partition; |
Ruchika Gupta | 0b70b06 | 2022-06-15 12:03:43 +0530 | [diff] [blame] | 454 | uint32_t service_setting; |
David Hu | f07e97d | 2021-02-15 22:05:40 +0800 | [diff] [blame] | 455 | fih_int fih_rc = FIH_FAILURE; |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 456 | |
| 457 | tfm_pool_init(conn_handle_pool, |
| 458 | POOL_BUFFER_SIZE(conn_handle_pool), |
Ken Liu | 0bed7e0 | 2022-02-10 12:38:07 +0800 | [diff] [blame] | 459 | sizeof(struct conn_handle_t), |
Sherry Zhang | 86a71c6 | 2022-01-12 18:19:02 +0800 | [diff] [blame] | 460 | CONFIG_TFM_CONN_HANDLE_MAX_NUM); |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 461 | |
Ken Liu | 5a28da3 | 2022-01-19 14:37:05 +0800 | [diff] [blame] | 462 | UNI_LISI_INIT_NODE(PARTITION_LIST_ADDR, next); |
| 463 | UNI_LISI_INIT_NODE(&services_listhead, next); |
Ken Liu | ea45b0d | 2021-05-22 17:41:25 +0800 | [diff] [blame] | 464 | |
Sherry Zhnag | 482b88b | 2021-08-19 17:51:47 +0800 | [diff] [blame] | 465 | /* Init the nonsecure context. */ |
Chris Brand | 56b4d0c | 2021-12-17 16:15:58 -0800 | [diff] [blame] | 466 | tfm_nspm_ctx_init(); |
Sherry Zhnag | 482b88b | 2021-08-19 17:51:47 +0800 | [diff] [blame] | 467 | |
Ken Liu | acd2a57 | 2021-05-12 16:19:04 +0800 | [diff] [blame] | 468 | while (1) { |
Mingyang Sun | deae45d | 2021-09-06 15:31:07 +0800 | [diff] [blame] | 469 | partition = load_a_partition_assuredly(PARTITION_LIST_ADDR); |
Shawn Shan | 2333106 | 2021-09-01 14:58:21 +0800 | [diff] [blame] | 470 | if (partition == NO_MORE_PARTITION) { |
Ken Liu | acd2a57 | 2021-05-12 16:19:04 +0800 | [diff] [blame] | 471 | break; |
Kevin Peng | 79c2bda | 2020-07-24 16:31:12 +0800 | [diff] [blame] | 472 | } |
| 473 | |
Ruchika Gupta | 0b70b06 | 2022-06-15 12:03:43 +0530 | [diff] [blame] | 474 | service_setting = load_services_assuredly( |
Mingyang Sun | deae45d | 2021-09-06 15:31:07 +0800 | [diff] [blame] | 475 | partition, |
| 476 | &services_listhead, |
| 477 | stateless_services_ref_tbl, |
| 478 | sizeof(stateless_services_ref_tbl)); |
Kevin Peng | 27e4227 | 2021-05-24 17:58:53 +0800 | [diff] [blame] | 479 | |
Ruchika Gupta | 0b70b06 | 2022-06-15 12:03:43 +0530 | [diff] [blame] | 480 | load_irqs_assuredly(partition); |
Kevin Peng | 27e4227 | 2021-05-24 17:58:53 +0800 | [diff] [blame] | 481 | |
Mingyang Sun | deae45d | 2021-09-06 15:31:07 +0800 | [diff] [blame] | 482 | /* Bind the partition with platform. */ |
Ken Liu | 967ffa9 | 2022-05-25 15:13:34 +0800 | [diff] [blame] | 483 | FIH_CALL(tfm_hal_bind_boundary, fih_rc, partition->p_ldinf, |
| 484 | &partition->boundary); |
Ken Liu | ce58bfc | 2021-05-12 17:54:48 +0800 | [diff] [blame] | 485 | if (fih_not_eq(fih_rc, fih_int_encode(TFM_HAL_SUCCESS))) { |
| 486 | tfm_core_panic(); |
Mingyang Sun | 61f8fbc | 2021-06-04 17:49:56 +0800 | [diff] [blame] | 487 | } |
Mate Toth-Pal | 8ac98a7 | 2019-11-21 17:30:10 +0100 | [diff] [blame] | 488 | |
Ken Liu | 995a974 | 2022-05-18 19:28:30 +0800 | [diff] [blame] | 489 | backend_init_comp_assuredly(partition, service_setting); |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 490 | } |
| 491 | |
Ken Liu | 995a974 | 2022-05-18 19:28:30 +0800 | [diff] [blame] | 492 | return backend_system_run(); |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 493 | } |
Ken Liu | 2d17517 | 2019-03-21 17:08:41 +0800 | [diff] [blame] | 494 | |
Mingyang Sun | a09adda | 2022-02-16 18:11:33 +0800 | [diff] [blame] | 495 | void update_caller_outvec_len(struct conn_handle_t *handle) |
Mingyang Sun | d44522a | 2020-01-16 16:48:37 +0800 | [diff] [blame] | 496 | { |
| 497 | uint32_t i; |
| 498 | |
| 499 | /* |
| 500 | * FixeMe: abstract these part into dedicated functions to avoid |
| 501 | * accessing thread context in psa layer |
| 502 | */ |
Ken Liu | f39d8eb | 2021-10-07 12:55:33 +0800 | [diff] [blame] | 503 | /* |
| 504 | * If it is a NS request via RPC, the owner of this message is not set. |
| 505 | * Or if it is a SFN message, it does not have owner thread state either. |
| 506 | */ |
Mingyang Sun | a09adda | 2022-02-16 18:11:33 +0800 | [diff] [blame] | 507 | if ((!is_tfm_rpc_msg(handle)) && (handle->sfn_magic != TFM_MSG_MAGIC_SFN)) { |
Summer Qin | 1056d1c | 2022-10-19 16:07:15 +0800 | [diff] [blame] | 508 | SPM_ASSERT(handle->ack_evnt.owner->state == THRD_STATE_BLOCK); |
Mingyang Sun | d44522a | 2020-01-16 16:48:37 +0800 | [diff] [blame] | 509 | } |
| 510 | |
| 511 | for (i = 0; i < PSA_MAX_IOVEC; i++) { |
Mingyang Sun | a09adda | 2022-02-16 18:11:33 +0800 | [diff] [blame] | 512 | if (handle->msg.out_size[i] == 0) { |
Mingyang Sun | d44522a | 2020-01-16 16:48:37 +0800 | [diff] [blame] | 513 | continue; |
| 514 | } |
| 515 | |
Summer Qin | 1056d1c | 2022-10-19 16:07:15 +0800 | [diff] [blame] | 516 | SPM_ASSERT(handle->caller_outvec[i].base == handle->outvec[i].base); |
Mingyang Sun | d44522a | 2020-01-16 16:48:37 +0800 | [diff] [blame] | 517 | |
Mingyang Sun | a09adda | 2022-02-16 18:11:33 +0800 | [diff] [blame] | 518 | handle->caller_outvec[i].len = handle->outvec[i].len; |
Mingyang Sun | d44522a | 2020-01-16 16:48:37 +0800 | [diff] [blame] | 519 | } |
| 520 | } |
| 521 | |
Ken Liu | 5d73c87 | 2021-08-19 19:23:17 +0800 | [diff] [blame] | 522 | void spm_assert_signal(void *p_pt, psa_signal_t signal) |
Mingyang Sun | d44522a | 2020-01-16 16:48:37 +0800 | [diff] [blame] | 523 | { |
Ken Liu | 92ede9f | 2021-10-20 09:35:00 +0800 | [diff] [blame] | 524 | struct critical_section_t cs_assert = CRITICAL_SECTION_STATIC_INIT; |
Ken Liu | 5d73c87 | 2021-08-19 19:23:17 +0800 | [diff] [blame] | 525 | struct partition_t *partition = (struct partition_t *)p_pt; |
Mingyang Sun | d44522a | 2020-01-16 16:48:37 +0800 | [diff] [blame] | 526 | |
Mingyang Sun | d44522a | 2020-01-16 16:48:37 +0800 | [diff] [blame] | 527 | if (!partition) { |
| 528 | tfm_core_panic(); |
| 529 | } |
| 530 | |
Ken Liu | 92ede9f | 2021-10-20 09:35:00 +0800 | [diff] [blame] | 531 | CRITICAL_SECTION_ENTER(cs_assert); |
| 532 | |
Mingyang Sun | af22ffa | 2020-07-09 17:48:37 +0800 | [diff] [blame] | 533 | partition->signals_asserted |= signal; |
Mingyang Sun | d44522a | 2020-01-16 16:48:37 +0800 | [diff] [blame] | 534 | |
Kevin Peng | 8dac610 | 2021-03-09 16:44:00 +0800 | [diff] [blame] | 535 | if (partition->signals_waiting & signal) { |
Ken Liu | 995a974 | 2022-05-18 19:28:30 +0800 | [diff] [blame] | 536 | backend_wake_up(partition); |
Kevin Peng | 8dac610 | 2021-03-09 16:44:00 +0800 | [diff] [blame] | 537 | } |
Ken Liu | 92ede9f | 2021-10-20 09:35:00 +0800 | [diff] [blame] | 538 | |
| 539 | CRITICAL_SECTION_LEAVE(cs_assert); |
Mingyang Sun | d44522a | 2020-01-16 16:48:37 +0800 | [diff] [blame] | 540 | } |