Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 1 | /* |
Kevin Peng | a20b5af | 2021-01-11 11:20:52 +0800 | [diff] [blame] | 2 | * Copyright (c) 2018-2021, Arm Limited. All rights reserved. |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | * |
| 6 | */ |
Mingyang Sun | da01a97 | 2019-07-12 17:32:59 +0800 | [diff] [blame] | 7 | |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 8 | #include <inttypes.h> |
| 9 | #include <stdbool.h> |
Ken Liu | 24dffb2 | 2021-02-10 11:03:58 +0800 | [diff] [blame] | 10 | #include "bitops.h" |
David Hu | f07e97d | 2021-02-15 22:05:40 +0800 | [diff] [blame] | 11 | #include "fih.h" |
Jamie Fox | cc31d40 | 2019-01-28 17:13:52 +0000 | [diff] [blame] | 12 | #include "psa/client.h" |
| 13 | #include "psa/service.h" |
Ken Liu | 5d73c87 | 2021-08-19 19:23:17 +0800 | [diff] [blame] | 14 | #include "thread.h" |
Ken Liu | bcae38b | 2021-01-20 15:47:44 +0800 | [diff] [blame] | 15 | #include "internal_errors.h" |
Mingyang Sun | d44522a | 2020-01-16 16:48:37 +0800 | [diff] [blame] | 16 | #include "tfm_spm_hal.h" |
Mingyang Sun | d44522a | 2020-01-16 16:48:37 +0800 | [diff] [blame] | 17 | #include "tfm_api.h" |
| 18 | #include "tfm_secure_api.h" |
| 19 | #include "tfm_memory_utils.h" |
Mingyang Sun | d1ed673 | 2020-08-26 15:52:21 +0800 | [diff] [blame] | 20 | #include "tfm_hal_defs.h" |
Kevin Peng | d399a1f | 2021-09-08 15:33:14 +0800 | [diff] [blame] | 21 | #include "tfm_hal_interrupt.h" |
Mingyang Sun | d1ed673 | 2020-08-26 15:52:21 +0800 | [diff] [blame] | 22 | #include "tfm_hal_isolation.h" |
Mingyang Sun | 7397b4f | 2020-06-17 15:07:45 +0800 | [diff] [blame] | 23 | #include "spm_ipc.h" |
Mingyang Sun | d44522a | 2020-01-16 16:48:37 +0800 | [diff] [blame] | 24 | #include "tfm_peripherals_def.h" |
Mingyang Sun | d44522a | 2020-01-16 16:48:37 +0800 | [diff] [blame] | 25 | #include "tfm_core_utils.h" |
Kevin Peng | 385fda8 | 2021-08-18 10:41:19 +0800 | [diff] [blame] | 26 | #include "tfm_nspm.h" |
Mingyang Sun | d44522a | 2020-01-16 16:48:37 +0800 | [diff] [blame] | 27 | #include "tfm_rpc.h" |
Mingyang Sun | d44522a | 2020-01-16 16:48:37 +0800 | [diff] [blame] | 28 | #include "tfm_core_trustzone.h" |
Ken Liu | 24dffb2 | 2021-02-10 11:03:58 +0800 | [diff] [blame] | 29 | #include "lists.h" |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 30 | #include "tfm_pools.h" |
Mingyang Sun | 22a3faf | 2021-07-09 15:32:47 +0800 | [diff] [blame] | 31 | #include "region.h" |
Mingyang Sun | 7397b4f | 2020-06-17 15:07:45 +0800 | [diff] [blame] | 32 | #include "psa_manifest/pid.h" |
Mingyang Sun | deae45d | 2021-09-06 15:31:07 +0800 | [diff] [blame] | 33 | #include "ffm/backend.h" |
Mingyang Sun | 00df235 | 2021-04-15 15:46:08 +0800 | [diff] [blame] | 34 | #include "load/partition_defs.h" |
| 35 | #include "load/service_defs.h" |
Ken Liu | 8668628 | 2021-04-27 11:11:15 +0800 | [diff] [blame] | 36 | #include "load/asset_defs.h" |
Ken Liu | acd2a57 | 2021-05-12 16:19:04 +0800 | [diff] [blame] | 37 | #include "load/spm_load_api.h" |
Sherry Zhnag | 482b88b | 2021-08-19 17:51:47 +0800 | [diff] [blame^] | 38 | #include "tfm_nspm.h" |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 39 | |
Ken Liu | ea45b0d | 2021-05-22 17:41:25 +0800 | [diff] [blame] | 40 | /* Partition and service runtime data list head/runtime data table */ |
Ken Liu | ea45b0d | 2021-05-22 17:41:25 +0800 | [diff] [blame] | 41 | static struct service_head_t services_listhead; |
Ken Liu | b3b2cb6 | 2021-05-22 00:39:28 +0800 | [diff] [blame] | 42 | struct service_t *stateless_services_ref_tbl[STATIC_HANDLE_NUM_LIMIT]; |
Summer Qin | d99509f | 2019-08-02 17:36:58 +0800 | [diff] [blame] | 43 | |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 44 | /* Pools */ |
| 45 | TFM_POOL_DECLARE(conn_handle_pool, sizeof(struct tfm_conn_handle_t), |
| 46 | TFM_CONN_HANDLE_MAX_NUM); |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 47 | |
Summer Qin | 373feb1 | 2020-03-27 15:35:33 +0800 | [diff] [blame] | 48 | /*********************** Connection handle conversion APIs *******************/ |
| 49 | |
Summer Qin | 373feb1 | 2020-03-27 15:35:33 +0800 | [diff] [blame] | 50 | #define CONVERSION_FACTOR_BITOFFSET 3 |
| 51 | #define CONVERSION_FACTOR_VALUE (1 << CONVERSION_FACTOR_BITOFFSET) |
| 52 | /* Set 32 as the maximum */ |
| 53 | #define CONVERSION_FACTOR_VALUE_MAX 0x20 |
| 54 | |
| 55 | #if CONVERSION_FACTOR_VALUE > CONVERSION_FACTOR_VALUE_MAX |
| 56 | #error "CONVERSION FACTOR OUT OF RANGE" |
| 57 | #endif |
| 58 | |
| 59 | static uint32_t loop_index; |
| 60 | |
| 61 | /* |
| 62 | * A handle instance psa_handle_t allocated inside SPM is actually a memory |
| 63 | * address among the handle pool. Return this handle to the client directly |
| 64 | * exposes information of secure memory address. In this case, converting the |
| 65 | * handle into another value does not represent the memory address to avoid |
| 66 | * exposing secure memory directly to clients. |
| 67 | * |
| 68 | * This function converts the handle instance into another value by scaling the |
| 69 | * handle in pool offset, the converted value is named as a user handle. |
| 70 | * |
| 71 | * The formula: |
| 72 | * user_handle = (handle_instance - POOL_START) * CONVERSION_FACTOR_VALUE + |
| 73 | * CLIENT_HANDLE_VALUE_MIN + loop_index |
| 74 | * where: |
| 75 | * CONVERSION_FACTOR_VALUE = 1 << CONVERSION_FACTOR_BITOFFSET, and should not |
| 76 | * exceed CONVERSION_FACTOR_VALUE_MAX. |
| 77 | * |
| 78 | * handle_instance in RANGE[POOL_START, POOL_END] |
| 79 | * user_handle in RANGE[CLIENT_HANDLE_VALUE_MIN, 0x3FFFFFFF] |
| 80 | * loop_index in RANGE[0, CONVERSION_FACTOR_VALUE - 1] |
| 81 | * |
| 82 | * note: |
| 83 | * loop_index is used to promise same handle instance is converted into |
| 84 | * different user handles in short time. |
| 85 | */ |
Ken Liu | 505b170 | 2020-05-29 13:19:58 +0800 | [diff] [blame] | 86 | psa_handle_t tfm_spm_to_user_handle(struct tfm_conn_handle_t *handle_instance) |
Summer Qin | 373feb1 | 2020-03-27 15:35:33 +0800 | [diff] [blame] | 87 | { |
| 88 | psa_handle_t user_handle; |
| 89 | |
| 90 | loop_index = (loop_index + 1) % CONVERSION_FACTOR_VALUE; |
| 91 | user_handle = (psa_handle_t)((((uintptr_t)handle_instance - |
| 92 | (uintptr_t)conn_handle_pool) << CONVERSION_FACTOR_BITOFFSET) + |
| 93 | CLIENT_HANDLE_VALUE_MIN + loop_index); |
| 94 | |
| 95 | return user_handle; |
| 96 | } |
| 97 | |
| 98 | /* |
| 99 | * This function converts a user handle into a corresponded handle instance. |
| 100 | * The converted value is validated before returning, an invalid handle instance |
| 101 | * is returned as NULL. |
| 102 | * |
| 103 | * The formula: |
| 104 | * handle_instance = ((user_handle - CLIENT_HANDLE_VALUE_MIN) / |
| 105 | * CONVERSION_FACTOR_VALUE) + POOL_START |
| 106 | * where: |
| 107 | * CONVERSION_FACTOR_VALUE = 1 << CONVERSION_FACTOR_BITOFFSET, and should not |
| 108 | * exceed CONVERSION_FACTOR_VALUE_MAX. |
| 109 | * |
| 110 | * handle_instance in RANGE[POOL_START, POOL_END] |
| 111 | * user_handle in RANGE[CLIENT_HANDLE_VALUE_MIN, 0x3FFFFFFF] |
| 112 | * loop_index in RANGE[0, CONVERSION_FACTOR_VALUE - 1] |
| 113 | */ |
| 114 | struct tfm_conn_handle_t *tfm_spm_to_handle_instance(psa_handle_t user_handle) |
| 115 | { |
| 116 | struct tfm_conn_handle_t *handle_instance; |
| 117 | |
| 118 | if (user_handle == PSA_NULL_HANDLE) { |
| 119 | return NULL; |
| 120 | } |
| 121 | |
| 122 | handle_instance = (struct tfm_conn_handle_t *)((((uintptr_t)user_handle - |
| 123 | CLIENT_HANDLE_VALUE_MIN) >> CONVERSION_FACTOR_BITOFFSET) + |
| 124 | (uintptr_t)conn_handle_pool); |
| 125 | |
| 126 | return handle_instance; |
| 127 | } |
| 128 | |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 129 | /* Service handle management functions */ |
Mingyang Sun | 783a59b | 2021-04-20 15:52:18 +0800 | [diff] [blame] | 130 | struct tfm_conn_handle_t *tfm_spm_create_conn_handle(struct service_t *service, |
| 131 | int32_t client_id) |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 132 | { |
Edison Ai | 9cc2624 | 2019-08-06 11:28:04 +0800 | [diff] [blame] | 133 | struct tfm_conn_handle_t *p_handle; |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 134 | |
Ken Liu | f250b8b | 2019-12-27 16:31:24 +0800 | [diff] [blame] | 135 | TFM_CORE_ASSERT(service); |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 136 | |
| 137 | /* Get buffer for handle list structure from handle pool */ |
Edison Ai | 9cc2624 | 2019-08-06 11:28:04 +0800 | [diff] [blame] | 138 | p_handle = (struct tfm_conn_handle_t *)tfm_pool_alloc(conn_handle_pool); |
| 139 | if (!p_handle) { |
Summer Qin | 630c76b | 2020-05-20 10:32:58 +0800 | [diff] [blame] | 140 | return NULL; |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 141 | } |
| 142 | |
Edison Ai | 9cc2624 | 2019-08-06 11:28:04 +0800 | [diff] [blame] | 143 | p_handle->service = service; |
Shawn Shan | cc39fcb | 2019-11-13 15:38:16 +0800 | [diff] [blame] | 144 | p_handle->status = TFM_HANDLE_STATUS_IDLE; |
Summer Qin | 1ce712a | 2019-10-14 18:04:05 +0800 | [diff] [blame] | 145 | p_handle->client_id = client_id; |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 146 | |
| 147 | /* Add handle node to list for next psa functions */ |
Ken Liu | 2c47f7f | 2021-01-22 11:06:04 +0800 | [diff] [blame] | 148 | BI_LIST_INSERT_BEFORE(&service->handle_list, &p_handle->list); |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 149 | |
Summer Qin | 630c76b | 2020-05-20 10:32:58 +0800 | [diff] [blame] | 150 | return p_handle; |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 151 | } |
| 152 | |
Summer Qin | 630c76b | 2020-05-20 10:32:58 +0800 | [diff] [blame] | 153 | int32_t tfm_spm_validate_conn_handle( |
| 154 | const struct tfm_conn_handle_t *conn_handle, |
| 155 | int32_t client_id) |
Summer Qin | 1ce712a | 2019-10-14 18:04:05 +0800 | [diff] [blame] | 156 | { |
| 157 | /* Check the handle address is validated */ |
| 158 | if (is_valid_chunk_data_in_pool(conn_handle_pool, |
| 159 | (uint8_t *)conn_handle) != true) { |
Ken Liu | bcae38b | 2021-01-20 15:47:44 +0800 | [diff] [blame] | 160 | return SPM_ERROR_GENERIC; |
Summer Qin | 1ce712a | 2019-10-14 18:04:05 +0800 | [diff] [blame] | 161 | } |
| 162 | |
| 163 | /* Check the handle caller is correct */ |
Summer Qin | 630c76b | 2020-05-20 10:32:58 +0800 | [diff] [blame] | 164 | if (conn_handle->client_id != client_id) { |
Ken Liu | bcae38b | 2021-01-20 15:47:44 +0800 | [diff] [blame] | 165 | return SPM_ERROR_GENERIC; |
Summer Qin | 1ce712a | 2019-10-14 18:04:05 +0800 | [diff] [blame] | 166 | } |
| 167 | |
Ken Liu | bcae38b | 2021-01-20 15:47:44 +0800 | [diff] [blame] | 168 | return SPM_SUCCESS; |
Summer Qin | 1ce712a | 2019-10-14 18:04:05 +0800 | [diff] [blame] | 169 | } |
| 170 | |
Mingyang Sun | 783a59b | 2021-04-20 15:52:18 +0800 | [diff] [blame] | 171 | int32_t tfm_spm_free_conn_handle(struct service_t *service, |
Summer Qin | 02f7f07 | 2020-08-24 16:02:54 +0800 | [diff] [blame] | 172 | struct tfm_conn_handle_t *conn_handle) |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 173 | { |
Ken Liu | f250b8b | 2019-12-27 16:31:24 +0800 | [diff] [blame] | 174 | TFM_CORE_ASSERT(service); |
Summer Qin | 630c76b | 2020-05-20 10:32:58 +0800 | [diff] [blame] | 175 | TFM_CORE_ASSERT(conn_handle != NULL); |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 176 | |
Mate Toth-Pal | a4b5d24 | 2019-09-23 09:14:47 +0200 | [diff] [blame] | 177 | /* Clear magic as the handler is not used anymore */ |
Summer Qin | 630c76b | 2020-05-20 10:32:58 +0800 | [diff] [blame] | 178 | conn_handle->internal_msg.magic = 0; |
Mate Toth-Pal | a4b5d24 | 2019-09-23 09:14:47 +0200 | [diff] [blame] | 179 | |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 180 | /* Remove node from handle list */ |
Ken Liu | 2c47f7f | 2021-01-22 11:06:04 +0800 | [diff] [blame] | 181 | BI_LIST_REMOVE_NODE(&conn_handle->list); |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 182 | |
| 183 | /* Back handle buffer to pool */ |
Ken Liu | 66ca613 | 2021-02-24 08:49:51 +0800 | [diff] [blame] | 184 | tfm_pool_free(conn_handle_pool, conn_handle); |
Ken Liu | bcae38b | 2021-01-20 15:47:44 +0800 | [diff] [blame] | 185 | return SPM_SUCCESS; |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 186 | } |
| 187 | |
Mingyang Sun | 783a59b | 2021-04-20 15:52:18 +0800 | [diff] [blame] | 188 | int32_t tfm_spm_set_rhandle(struct service_t *service, |
Summer Qin | 02f7f07 | 2020-08-24 16:02:54 +0800 | [diff] [blame] | 189 | struct tfm_conn_handle_t *conn_handle, |
| 190 | void *rhandle) |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 191 | { |
Ken Liu | f250b8b | 2019-12-27 16:31:24 +0800 | [diff] [blame] | 192 | TFM_CORE_ASSERT(service); |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 193 | /* Set reverse handle value only be allowed for a connected handle */ |
Summer Qin | 630c76b | 2020-05-20 10:32:58 +0800 | [diff] [blame] | 194 | TFM_CORE_ASSERT(conn_handle != NULL); |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 195 | |
Summer Qin | 630c76b | 2020-05-20 10:32:58 +0800 | [diff] [blame] | 196 | conn_handle->rhandle = rhandle; |
Ken Liu | bcae38b | 2021-01-20 15:47:44 +0800 | [diff] [blame] | 197 | return SPM_SUCCESS; |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 198 | } |
| 199 | |
Mingyang Sun | d44522a | 2020-01-16 16:48:37 +0800 | [diff] [blame] | 200 | /** |
Xinyu Zhang | 3a45324 | 2021-04-16 17:57:09 +0800 | [diff] [blame] | 201 | * \brief Get reverse handle value from connection handle. |
Mingyang Sun | d44522a | 2020-01-16 16:48:37 +0800 | [diff] [blame] | 202 | * |
| 203 | * \param[in] service Target service context pointer |
| 204 | * \param[in] conn_handle Connection handle created by |
Summer Qin | 630c76b | 2020-05-20 10:32:58 +0800 | [diff] [blame] | 205 | * tfm_spm_create_conn_handle() |
Mingyang Sun | d44522a | 2020-01-16 16:48:37 +0800 | [diff] [blame] | 206 | * |
| 207 | * \retval void * Success |
| 208 | * \retval "Does not return" Panic for those: |
| 209 | * service pointer are NULL |
Xinyu Zhang | 3a45324 | 2021-04-16 17:57:09 +0800 | [diff] [blame] | 210 | * handle is \ref PSA_NULL_HANDLE |
Mingyang Sun | d44522a | 2020-01-16 16:48:37 +0800 | [diff] [blame] | 211 | * handle node does not be found |
| 212 | */ |
Mingyang Sun | 783a59b | 2021-04-20 15:52:18 +0800 | [diff] [blame] | 213 | static void *tfm_spm_get_rhandle(struct service_t *service, |
Summer Qin | 630c76b | 2020-05-20 10:32:58 +0800 | [diff] [blame] | 214 | struct tfm_conn_handle_t *conn_handle) |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 215 | { |
Ken Liu | f250b8b | 2019-12-27 16:31:24 +0800 | [diff] [blame] | 216 | TFM_CORE_ASSERT(service); |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 217 | /* Get reverse handle value only be allowed for a connected handle */ |
Summer Qin | 630c76b | 2020-05-20 10:32:58 +0800 | [diff] [blame] | 218 | TFM_CORE_ASSERT(conn_handle != NULL); |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 219 | |
Summer Qin | 630c76b | 2020-05-20 10:32:58 +0800 | [diff] [blame] | 220 | return conn_handle->rhandle; |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 221 | } |
| 222 | |
| 223 | /* Partition management functions */ |
Mingyang Sun | d44522a | 2020-01-16 16:48:37 +0800 | [diff] [blame] | 224 | |
Summer Qin | 02f7f07 | 2020-08-24 16:02:54 +0800 | [diff] [blame] | 225 | struct tfm_msg_body_t *tfm_spm_get_msg_by_signal(struct partition_t *partition, |
| 226 | psa_signal_t signal) |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 227 | { |
Ken Liu | 2c47f7f | 2021-01-22 11:06:04 +0800 | [diff] [blame] | 228 | struct bi_list_node_t *node, *head; |
Mingyang Sun | 73056b6 | 2020-07-03 15:18:46 +0800 | [diff] [blame] | 229 | struct tfm_msg_body_t *tmp_msg, *msg = NULL; |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 230 | |
Ken Liu | f250b8b | 2019-12-27 16:31:24 +0800 | [diff] [blame] | 231 | TFM_CORE_ASSERT(partition); |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 232 | |
Mingyang Sun | af22ffa | 2020-07-09 17:48:37 +0800 | [diff] [blame] | 233 | head = &partition->msg_list; |
Mingyang Sun | 73056b6 | 2020-07-03 15:18:46 +0800 | [diff] [blame] | 234 | |
Ken Liu | 2c47f7f | 2021-01-22 11:06:04 +0800 | [diff] [blame] | 235 | if (BI_LIST_IS_EMPTY(head)) { |
Mingyang Sun | 73056b6 | 2020-07-03 15:18:46 +0800 | [diff] [blame] | 236 | return NULL; |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 237 | } |
| 238 | |
Mingyang Sun | 73056b6 | 2020-07-03 15:18:46 +0800 | [diff] [blame] | 239 | /* |
| 240 | * There may be multiple messages for this RoT Service signal, do not clear |
| 241 | * partition mask until no remaining message. Search may be optimized. |
| 242 | */ |
Ken Liu | 2c47f7f | 2021-01-22 11:06:04 +0800 | [diff] [blame] | 243 | BI_LIST_FOR_EACH(node, head) { |
Ken Liu | c25558c | 2021-05-20 15:31:28 +0800 | [diff] [blame] | 244 | tmp_msg = TO_CONTAINER(node, struct tfm_msg_body_t, msg_node); |
Ken Liu | acd2a57 | 2021-05-12 16:19:04 +0800 | [diff] [blame] | 245 | if (tmp_msg->service->p_ldinf->signal == signal && msg) { |
Mingyang Sun | 73056b6 | 2020-07-03 15:18:46 +0800 | [diff] [blame] | 246 | return msg; |
Ken Liu | acd2a57 | 2021-05-12 16:19:04 +0800 | [diff] [blame] | 247 | } else if (tmp_msg->service->p_ldinf->signal == signal) { |
Mingyang Sun | 73056b6 | 2020-07-03 15:18:46 +0800 | [diff] [blame] | 248 | msg = tmp_msg; |
Ken Liu | 2c47f7f | 2021-01-22 11:06:04 +0800 | [diff] [blame] | 249 | BI_LIST_REMOVE_NODE(node); |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 250 | } |
| 251 | } |
Mingyang Sun | 73056b6 | 2020-07-03 15:18:46 +0800 | [diff] [blame] | 252 | |
Mingyang Sun | af22ffa | 2020-07-09 17:48:37 +0800 | [diff] [blame] | 253 | partition->signals_asserted &= ~signal; |
Mingyang Sun | 73056b6 | 2020-07-03 15:18:46 +0800 | [diff] [blame] | 254 | |
| 255 | return msg; |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 256 | } |
| 257 | |
Mingyang Sun | da30f1e | 2020-07-13 17:20:32 +0800 | [diff] [blame] | 258 | uint32_t tfm_spm_partition_get_privileged_mode(uint32_t partition_flags) |
| 259 | { |
Kevin Peng | bf9a97e | 2021-06-18 16:34:12 +0800 | [diff] [blame] | 260 | #if TFM_LVL == 1 |
| 261 | return TFM_PARTITION_PRIVILEGED_MODE; |
| 262 | #else /* TFM_LVL == 1 */ |
Shawn Shan | a3657e8 | 2021-10-18 14:37:09 +0800 | [diff] [blame] | 263 | if (partition_flags & PARTITION_MODEL_PSA_ROT) { |
Mingyang Sun | da30f1e | 2020-07-13 17:20:32 +0800 | [diff] [blame] | 264 | return TFM_PARTITION_PRIVILEGED_MODE; |
| 265 | } else { |
| 266 | return TFM_PARTITION_UNPRIVILEGED_MODE; |
| 267 | } |
Kevin Peng | bf9a97e | 2021-06-18 16:34:12 +0800 | [diff] [blame] | 268 | #endif /* TFM_LVL == 1 */ |
Mingyang Sun | da30f1e | 2020-07-13 17:20:32 +0800 | [diff] [blame] | 269 | } |
| 270 | |
Mingyang Sun | 783a59b | 2021-04-20 15:52:18 +0800 | [diff] [blame] | 271 | struct service_t *tfm_spm_get_service_by_sid(uint32_t sid) |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 272 | { |
Feder.Liang | aeb5a79 | 2021-08-10 16:12:56 +0800 | [diff] [blame] | 273 | struct service_t *p_prev, *p_curr; |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 274 | |
Feder.Liang | aeb5a79 | 2021-08-10 16:12:56 +0800 | [diff] [blame] | 275 | UNI_LIST_FOR_EACH_PREV(p_prev, p_curr, &services_listhead) { |
| 276 | if (p_curr->p_ldinf->sid == sid) { |
| 277 | UNI_LIST_MOVE_AFTER(&services_listhead, p_prev, p_curr); |
| 278 | return p_curr; |
Mingyang Sun | ef42f44 | 2021-06-11 15:07:58 +0800 | [diff] [blame] | 279 | } |
| 280 | } |
| 281 | |
Ken Liu | ea45b0d | 2021-05-22 17:41:25 +0800 | [diff] [blame] | 282 | return NULL; |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 283 | } |
| 284 | |
Mingyang Sun | d44522a | 2020-01-16 16:48:37 +0800 | [diff] [blame] | 285 | /** |
| 286 | * \brief Get the partition context by partition ID. |
| 287 | * |
| 288 | * \param[in] partition_id Partition identity |
| 289 | * |
| 290 | * \retval NULL Failed |
| 291 | * \retval "Not NULL" Target partition context pointer, |
Mingyang Sun | ae70d8d | 2020-06-30 15:56:05 +0800 | [diff] [blame] | 292 | * \ref partition_t structures |
Mingyang Sun | d44522a | 2020-01-16 16:48:37 +0800 | [diff] [blame] | 293 | */ |
Kevin Peng | eca45b9 | 2021-02-09 14:46:50 +0800 | [diff] [blame] | 294 | 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] | 295 | { |
Ken Liu | ea45b0d | 2021-05-22 17:41:25 +0800 | [diff] [blame] | 296 | struct partition_t *p_part; |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 297 | |
Mingyang Sun | deae45d | 2021-09-06 15:31:07 +0800 | [diff] [blame] | 298 | UNI_LIST_FOR_EACH(p_part, PARTITION_LIST_ADDR) { |
Ken Liu | ea45b0d | 2021-05-22 17:41:25 +0800 | [diff] [blame] | 299 | if (p_part->p_ldinf->pid == partition_id) { |
| 300 | return p_part; |
| 301 | } |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 302 | } |
Ken Liu | ea45b0d | 2021-05-22 17:41:25 +0800 | [diff] [blame] | 303 | |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 304 | return NULL; |
| 305 | } |
| 306 | |
Mingyang Sun | ae70d8d | 2020-06-30 15:56:05 +0800 | [diff] [blame] | 307 | struct partition_t *tfm_spm_get_running_partition(void) |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 308 | { |
Mingyang Sun | 4f08f4d | 2021-09-10 17:41:28 +0800 | [diff] [blame] | 309 | return GET_THRD_OWNER(CURRENT_THREAD); |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 310 | } |
| 311 | |
Mingyang Sun | 783a59b | 2021-04-20 15:52:18 +0800 | [diff] [blame] | 312 | int32_t tfm_spm_check_client_version(struct service_t *service, |
Jaykumar Pitambarbhai Patel | 3a98602 | 2019-10-08 17:37:15 +0530 | [diff] [blame] | 313 | uint32_t version) |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 314 | { |
Ken Liu | f250b8b | 2019-12-27 16:31:24 +0800 | [diff] [blame] | 315 | TFM_CORE_ASSERT(service); |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 316 | |
Ken Liu | acd2a57 | 2021-05-12 16:19:04 +0800 | [diff] [blame] | 317 | switch (SERVICE_GET_VERSION_POLICY(service->p_ldinf->flags)) { |
Ken Liu | b3b2cb6 | 2021-05-22 00:39:28 +0800 | [diff] [blame] | 318 | case SERVICE_VERSION_POLICY_RELAXED: |
Ken Liu | acd2a57 | 2021-05-12 16:19:04 +0800 | [diff] [blame] | 319 | if (version > service->p_ldinf->version) { |
Ken Liu | bcae38b | 2021-01-20 15:47:44 +0800 | [diff] [blame] | 320 | return SPM_ERROR_VERSION; |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 321 | } |
| 322 | break; |
Ken Liu | b3b2cb6 | 2021-05-22 00:39:28 +0800 | [diff] [blame] | 323 | case SERVICE_VERSION_POLICY_STRICT: |
Ken Liu | acd2a57 | 2021-05-12 16:19:04 +0800 | [diff] [blame] | 324 | if (version != service->p_ldinf->version) { |
Ken Liu | bcae38b | 2021-01-20 15:47:44 +0800 | [diff] [blame] | 325 | return SPM_ERROR_VERSION; |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 326 | } |
| 327 | break; |
| 328 | default: |
Ken Liu | bcae38b | 2021-01-20 15:47:44 +0800 | [diff] [blame] | 329 | return SPM_ERROR_VERSION; |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 330 | } |
Ken Liu | bcae38b | 2021-01-20 15:47:44 +0800 | [diff] [blame] | 331 | return SPM_SUCCESS; |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 332 | } |
| 333 | |
Edison Ai | e728fbf | 2019-11-13 09:37:12 +0800 | [diff] [blame] | 334 | int32_t tfm_spm_check_authorization(uint32_t sid, |
Mingyang Sun | 783a59b | 2021-04-20 15:52:18 +0800 | [diff] [blame] | 335 | struct service_t *service, |
Summer Qin | 618e8c3 | 2019-12-09 10:47:20 +0800 | [diff] [blame] | 336 | bool ns_caller) |
Edison Ai | e728fbf | 2019-11-13 09:37:12 +0800 | [diff] [blame] | 337 | { |
Mingyang Sun | ae70d8d | 2020-06-30 15:56:05 +0800 | [diff] [blame] | 338 | struct partition_t *partition = NULL; |
Mingyang Sun | 2b35266 | 2021-04-21 11:35:43 +0800 | [diff] [blame] | 339 | uint32_t *dep; |
Edison Ai | e728fbf | 2019-11-13 09:37:12 +0800 | [diff] [blame] | 340 | int32_t i; |
| 341 | |
Ken Liu | f250b8b | 2019-12-27 16:31:24 +0800 | [diff] [blame] | 342 | TFM_CORE_ASSERT(service); |
Edison Ai | e728fbf | 2019-11-13 09:37:12 +0800 | [diff] [blame] | 343 | |
| 344 | if (ns_caller) { |
Ken Liu | acd2a57 | 2021-05-12 16:19:04 +0800 | [diff] [blame] | 345 | if (!SERVICE_IS_NS_ACCESSIBLE(service->p_ldinf->flags)) { |
Ken Liu | bcae38b | 2021-01-20 15:47:44 +0800 | [diff] [blame] | 346 | return SPM_ERROR_GENERIC; |
Edison Ai | e728fbf | 2019-11-13 09:37:12 +0800 | [diff] [blame] | 347 | } |
| 348 | } else { |
| 349 | partition = tfm_spm_get_running_partition(); |
| 350 | if (!partition) { |
Edison Ai | 9059ea0 | 2019-11-28 13:46:14 +0800 | [diff] [blame] | 351 | tfm_core_panic(); |
Edison Ai | e728fbf | 2019-11-13 09:37:12 +0800 | [diff] [blame] | 352 | } |
| 353 | |
Ken Liu | acd2a57 | 2021-05-12 16:19:04 +0800 | [diff] [blame] | 354 | dep = (uint32_t *)LOAD_INFO_DEPS(partition->p_ldinf); |
| 355 | for (i = 0; i < partition->p_ldinf->ndeps; i++) { |
Mingyang Sun | 2b35266 | 2021-04-21 11:35:43 +0800 | [diff] [blame] | 356 | if (dep[i] == sid) { |
Edison Ai | e728fbf | 2019-11-13 09:37:12 +0800 | [diff] [blame] | 357 | break; |
| 358 | } |
| 359 | } |
| 360 | |
Ken Liu | acd2a57 | 2021-05-12 16:19:04 +0800 | [diff] [blame] | 361 | if (i == partition->p_ldinf->ndeps) { |
Ken Liu | bcae38b | 2021-01-20 15:47:44 +0800 | [diff] [blame] | 362 | return SPM_ERROR_GENERIC; |
Edison Ai | e728fbf | 2019-11-13 09:37:12 +0800 | [diff] [blame] | 363 | } |
| 364 | } |
Ken Liu | bcae38b | 2021-01-20 15:47:44 +0800 | [diff] [blame] | 365 | return SPM_SUCCESS; |
Edison Ai | e728fbf | 2019-11-13 09:37:12 +0800 | [diff] [blame] | 366 | } |
| 367 | |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 368 | /* Message functions */ |
Mingyang Sun | d44522a | 2020-01-16 16:48:37 +0800 | [diff] [blame] | 369 | |
Summer Qin | 02f7f07 | 2020-08-24 16:02:54 +0800 | [diff] [blame] | 370 | struct tfm_msg_body_t *tfm_spm_get_msg_from_handle(psa_handle_t msg_handle) |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 371 | { |
| 372 | /* |
Mate Toth-Pal | a4b5d24 | 2019-09-23 09:14:47 +0200 | [diff] [blame] | 373 | * The message handler passed by the caller is considered invalid in the |
| 374 | * following cases: |
| 375 | * 1. Not a valid message handle. (The address of a message is not the |
| 376 | * address of a possible handle from the pool |
| 377 | * 2. Handle not belongs to the caller partition (The handle is either |
| 378 | * unused, or owned by anither partition) |
| 379 | * Check the conditions above |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 380 | */ |
Ken Liu | 505b170 | 2020-05-29 13:19:58 +0800 | [diff] [blame] | 381 | struct tfm_msg_body_t *p_msg; |
Kevin Peng | eec41a8 | 2021-08-18 13:56:23 +0800 | [diff] [blame] | 382 | int32_t partition_id; |
Ken Liu | 505b170 | 2020-05-29 13:19:58 +0800 | [diff] [blame] | 383 | struct tfm_conn_handle_t *p_conn_handle = |
Ken Liu | 5d73c87 | 2021-08-19 19:23:17 +0800 | [diff] [blame] | 384 | tfm_spm_to_handle_instance(msg_handle); |
Mate Toth-Pal | a4b5d24 | 2019-09-23 09:14:47 +0200 | [diff] [blame] | 385 | |
| 386 | if (is_valid_chunk_data_in_pool( |
Ken Liu | 505b170 | 2020-05-29 13:19:58 +0800 | [diff] [blame] | 387 | conn_handle_pool, (uint8_t *)p_conn_handle) != 1) { |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 388 | return NULL; |
| 389 | } |
| 390 | |
Ken Liu | 505b170 | 2020-05-29 13:19:58 +0800 | [diff] [blame] | 391 | p_msg = &p_conn_handle->internal_msg; |
| 392 | |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 393 | /* |
Mate Toth-Pal | a4b5d24 | 2019-09-23 09:14:47 +0200 | [diff] [blame] | 394 | * Check that the magic number is correct. This proves that the message |
| 395 | * structure contains an active message. |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 396 | */ |
Ken Liu | 505b170 | 2020-05-29 13:19:58 +0800 | [diff] [blame] | 397 | if (p_msg->magic != TFM_MSG_MAGIC) { |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 398 | return NULL; |
| 399 | } |
| 400 | |
Mate Toth-Pal | a4b5d24 | 2019-09-23 09:14:47 +0200 | [diff] [blame] | 401 | /* Check that the running partition owns the message */ |
Mingyang Sun | f3d2989 | 2019-07-10 17:50:23 +0800 | [diff] [blame] | 402 | partition_id = tfm_spm_partition_get_running_partition_id(); |
Ken Liu | acd2a57 | 2021-05-12 16:19:04 +0800 | [diff] [blame] | 403 | if (partition_id != p_msg->service->partition->p_ldinf->pid) { |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 404 | return NULL; |
| 405 | } |
| 406 | |
Ken Liu | 505b170 | 2020-05-29 13:19:58 +0800 | [diff] [blame] | 407 | return p_msg; |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 408 | } |
| 409 | |
Kevin Peng | df6aa29 | 2021-03-11 17:58:50 +0800 | [diff] [blame] | 410 | struct tfm_msg_body_t * |
| 411 | tfm_spm_get_msg_buffer_from_conn_handle(struct tfm_conn_handle_t *conn_handle) |
| 412 | { |
| 413 | TFM_CORE_ASSERT(conn_handle != NULL); |
| 414 | |
| 415 | return &(conn_handle->internal_msg); |
| 416 | } |
| 417 | |
Edison Ai | 9711582 | 2019-08-01 14:22:19 +0800 | [diff] [blame] | 418 | void tfm_spm_fill_msg(struct tfm_msg_body_t *msg, |
Mingyang Sun | 783a59b | 2021-04-20 15:52:18 +0800 | [diff] [blame] | 419 | struct service_t *service, |
Ken Liu | 505b170 | 2020-05-29 13:19:58 +0800 | [diff] [blame] | 420 | psa_handle_t handle, |
Summer Qin | 1ce712a | 2019-10-14 18:04:05 +0800 | [diff] [blame] | 421 | int32_t type, int32_t client_id, |
Edison Ai | 9711582 | 2019-08-01 14:22:19 +0800 | [diff] [blame] | 422 | psa_invec *invec, size_t in_len, |
| 423 | psa_outvec *outvec, size_t out_len, |
| 424 | psa_outvec *caller_outvec) |
| 425 | { |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 426 | uint32_t i; |
Ken Liu | 505b170 | 2020-05-29 13:19:58 +0800 | [diff] [blame] | 427 | struct tfm_conn_handle_t *conn_handle; |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 428 | |
Ken Liu | f250b8b | 2019-12-27 16:31:24 +0800 | [diff] [blame] | 429 | TFM_CORE_ASSERT(msg); |
| 430 | TFM_CORE_ASSERT(service); |
| 431 | TFM_CORE_ASSERT(!(invec == NULL && in_len != 0)); |
| 432 | TFM_CORE_ASSERT(!(outvec == NULL && out_len != 0)); |
| 433 | TFM_CORE_ASSERT(in_len <= PSA_MAX_IOVEC); |
| 434 | TFM_CORE_ASSERT(out_len <= PSA_MAX_IOVEC); |
| 435 | TFM_CORE_ASSERT(in_len + out_len <= PSA_MAX_IOVEC); |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 436 | |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 437 | /* Clear message buffer before using it */ |
Summer Qin | f24dbb5 | 2020-07-23 14:53:54 +0800 | [diff] [blame] | 438 | spm_memset(msg, 0, sizeof(struct tfm_msg_body_t)); |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 439 | |
Ken Liu | 5d73c87 | 2021-08-19 19:23:17 +0800 | [diff] [blame] | 440 | THRD_SYNC_INIT(&msg->ack_evnt); |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 441 | msg->magic = TFM_MSG_MAGIC; |
| 442 | msg->service = service; |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 443 | msg->caller_outvec = caller_outvec; |
Summer Qin | 1ce712a | 2019-10-14 18:04:05 +0800 | [diff] [blame] | 444 | msg->msg.client_id = client_id; |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 445 | |
| 446 | /* Copy contents */ |
| 447 | msg->msg.type = type; |
| 448 | |
| 449 | for (i = 0; i < in_len; i++) { |
| 450 | msg->msg.in_size[i] = invec[i].len; |
| 451 | msg->invec[i].base = invec[i].base; |
| 452 | } |
| 453 | |
| 454 | for (i = 0; i < out_len; i++) { |
| 455 | msg->msg.out_size[i] = outvec[i].len; |
| 456 | msg->outvec[i].base = outvec[i].base; |
| 457 | /* Out len is used to record the writed number, set 0 here again */ |
| 458 | msg->outvec[i].len = 0; |
| 459 | } |
| 460 | |
Ken Liu | 505b170 | 2020-05-29 13:19:58 +0800 | [diff] [blame] | 461 | /* Use the user connect handle as the message handle */ |
| 462 | msg->msg.handle = handle; |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 463 | |
Ken Liu | 505b170 | 2020-05-29 13:19:58 +0800 | [diff] [blame] | 464 | conn_handle = tfm_spm_to_handle_instance(handle); |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 465 | /* For connected handle, set rhandle to every message */ |
Ken Liu | 505b170 | 2020-05-29 13:19:58 +0800 | [diff] [blame] | 466 | if (conn_handle) { |
| 467 | msg->msg.rhandle = tfm_spm_get_rhandle(service, conn_handle); |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 468 | } |
David Hu | 46603dd | 2019-12-11 18:05:16 +0800 | [diff] [blame] | 469 | |
| 470 | /* Set the private data of NSPE client caller in multi-core topology */ |
| 471 | if (TFM_CLIENT_ID_IS_NS(client_id)) { |
| 472 | tfm_rpc_set_caller_data(msg, client_id); |
| 473 | } |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 474 | } |
| 475 | |
Kevin Peng | eec41a8 | 2021-08-18 13:56:23 +0800 | [diff] [blame] | 476 | int32_t tfm_spm_partition_get_running_partition_id(void) |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 477 | { |
Mingyang Sun | ae70d8d | 2020-06-30 15:56:05 +0800 | [diff] [blame] | 478 | struct partition_t *partition; |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 479 | |
Kevin Peng | 79c2bda | 2020-07-24 16:31:12 +0800 | [diff] [blame] | 480 | partition = tfm_spm_get_running_partition(); |
Ken Liu | acd2a57 | 2021-05-12 16:19:04 +0800 | [diff] [blame] | 481 | if (partition && partition->p_ldinf) { |
| 482 | return partition->p_ldinf->pid; |
Kevin Peng | 79c2bda | 2020-07-24 16:31:12 +0800 | [diff] [blame] | 483 | } else { |
| 484 | return INVALID_PARTITION_ID; |
| 485 | } |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 486 | } |
| 487 | |
Summer Qin | 43c185d | 2019-10-10 15:44:42 +0800 | [diff] [blame] | 488 | int32_t tfm_memory_check(const void *buffer, size_t len, bool ns_caller, |
Summer Qin | eb537e5 | 2019-03-29 09:57:10 +0800 | [diff] [blame] | 489 | enum tfm_memory_access_e access, |
| 490 | uint32_t privileged) |
Summer Qin | 2bfd2a0 | 2018-09-26 17:10:41 +0800 | [diff] [blame] | 491 | { |
Mingyang Sun | d1ed673 | 2020-08-26 15:52:21 +0800 | [diff] [blame] | 492 | enum tfm_hal_status_t err; |
| 493 | uint32_t attr = 0; |
Summer Qin | 2bfd2a0 | 2018-09-26 17:10:41 +0800 | [diff] [blame] | 494 | |
| 495 | /* If len is zero, this indicates an empty buffer and base is ignored */ |
| 496 | if (len == 0) { |
Ken Liu | bcae38b | 2021-01-20 15:47:44 +0800 | [diff] [blame] | 497 | return SPM_SUCCESS; |
Summer Qin | 2bfd2a0 | 2018-09-26 17:10:41 +0800 | [diff] [blame] | 498 | } |
| 499 | |
| 500 | if (!buffer) { |
Ken Liu | bcae38b | 2021-01-20 15:47:44 +0800 | [diff] [blame] | 501 | return SPM_ERROR_BAD_PARAMETERS; |
Summer Qin | 2bfd2a0 | 2018-09-26 17:10:41 +0800 | [diff] [blame] | 502 | } |
| 503 | |
| 504 | if ((uintptr_t)buffer > (UINTPTR_MAX - len)) { |
Ken Liu | bcae38b | 2021-01-20 15:47:44 +0800 | [diff] [blame] | 505 | return SPM_ERROR_MEMORY_CHECK; |
Summer Qin | 2bfd2a0 | 2018-09-26 17:10:41 +0800 | [diff] [blame] | 506 | } |
| 507 | |
Summer Qin | 424d4db | 2019-03-25 14:09:51 +0800 | [diff] [blame] | 508 | if (access == TFM_MEMORY_ACCESS_RW) { |
Mingyang Sun | d1ed673 | 2020-08-26 15:52:21 +0800 | [diff] [blame] | 509 | attr |= (TFM_HAL_ACCESS_READABLE | TFM_HAL_ACCESS_WRITABLE); |
Summer Qin | 2bfd2a0 | 2018-09-26 17:10:41 +0800 | [diff] [blame] | 510 | } else { |
Mingyang Sun | d1ed673 | 2020-08-26 15:52:21 +0800 | [diff] [blame] | 511 | attr |= TFM_HAL_ACCESS_READABLE; |
Summer Qin | 424d4db | 2019-03-25 14:09:51 +0800 | [diff] [blame] | 512 | } |
Mingyang Sun | d1ed673 | 2020-08-26 15:52:21 +0800 | [diff] [blame] | 513 | |
| 514 | if (privileged == TFM_PARTITION_UNPRIVILEGED_MODE) { |
| 515 | attr |= TFM_HAL_ACCESS_UNPRIVILEGED; |
| 516 | } else { |
| 517 | attr &= ~TFM_HAL_ACCESS_UNPRIVILEGED; |
| 518 | } |
| 519 | |
| 520 | if (ns_caller) { |
| 521 | attr |= TFM_HAL_ACCESS_NS; |
| 522 | } |
| 523 | |
| 524 | err = tfm_hal_memory_has_access((uintptr_t)buffer, len, attr); |
| 525 | |
| 526 | if (err == TFM_HAL_SUCCESS) { |
Ken Liu | bcae38b | 2021-01-20 15:47:44 +0800 | [diff] [blame] | 527 | return SPM_SUCCESS; |
Summer Qin | 2bfd2a0 | 2018-09-26 17:10:41 +0800 | [diff] [blame] | 528 | } |
| 529 | |
Ken Liu | bcae38b | 2021-01-20 15:47:44 +0800 | [diff] [blame] | 530 | return SPM_ERROR_MEMORY_CHECK; |
Summer Qin | 2bfd2a0 | 2018-09-26 17:10:41 +0800 | [diff] [blame] | 531 | } |
| 532 | |
Mingyang Sun | 22a3faf | 2021-07-09 15:32:47 +0800 | [diff] [blame] | 533 | bool tfm_spm_is_ns_caller(void) |
| 534 | { |
| 535 | #if defined(TFM_MULTI_CORE_TOPOLOGY) || defined(FORWARD_PROT_MSG) |
| 536 | /* Multi-core NS PSA API request is processed by pendSV. */ |
| 537 | return (__get_active_exc_num() == EXC_NUM_PENDSV); |
| 538 | #else |
| 539 | struct partition_t *partition = tfm_spm_get_running_partition(); |
Mingyang Sun | e529e3b | 2021-07-12 14:46:30 +0800 | [diff] [blame] | 540 | |
Mingyang Sun | 22a3faf | 2021-07-09 15:32:47 +0800 | [diff] [blame] | 541 | if (!partition) { |
| 542 | tfm_core_panic(); |
| 543 | } |
| 544 | |
| 545 | return (partition->p_ldinf->pid == TFM_SP_NON_SECURE_ID); |
| 546 | #endif |
| 547 | } |
| 548 | |
Mingyang Sun | e529e3b | 2021-07-12 14:46:30 +0800 | [diff] [blame] | 549 | uint32_t tfm_spm_get_caller_privilege_mode(void) |
| 550 | { |
| 551 | struct partition_t *partition; |
| 552 | |
| 553 | #if defined(TFM_MULTI_CORE_TOPOLOGY) || defined(FORWARD_PROT_MSG) |
| 554 | /* |
| 555 | * In multi-core topology, if PSA request is from mailbox, the client |
| 556 | * is unprivileged. |
| 557 | */ |
| 558 | if (__get_active_exc_num() == EXC_NUM_PENDSV) { |
| 559 | return TFM_PARTITION_UNPRIVILEGED_MODE; |
| 560 | } |
| 561 | #endif |
| 562 | partition = tfm_spm_get_running_partition(); |
| 563 | if (!partition) { |
| 564 | tfm_core_panic(); |
| 565 | } |
| 566 | |
| 567 | return tfm_spm_partition_get_privileged_mode(partition->p_ldinf->flags); |
| 568 | } |
| 569 | |
Kevin Peng | 385fda8 | 2021-08-18 10:41:19 +0800 | [diff] [blame] | 570 | int32_t tfm_spm_get_client_id(bool ns_caller) |
| 571 | { |
| 572 | int32_t client_id; |
| 573 | |
| 574 | if (ns_caller) { |
| 575 | client_id = tfm_nspm_get_current_client_id(); |
| 576 | } else { |
| 577 | client_id = tfm_spm_partition_get_running_partition_id(); |
| 578 | } |
| 579 | |
| 580 | if (ns_caller != (client_id < 0)) { |
| 581 | /* NS client ID must be negative and Secure ID must >= 0 */ |
| 582 | tfm_core_panic(); |
| 583 | } |
| 584 | |
| 585 | return client_id; |
| 586 | } |
| 587 | |
Ken Liu | ce2692d | 2020-02-11 12:39:36 +0800 | [diff] [blame] | 588 | uint32_t tfm_spm_init(void) |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 589 | { |
Mingyang Sun | ae70d8d | 2020-06-30 15:56:05 +0800 | [diff] [blame] | 590 | struct partition_t *partition; |
Mingyang Sun | deae45d | 2021-09-06 15:31:07 +0800 | [diff] [blame] | 591 | const struct partition_load_info_t *p_pldi; |
| 592 | uint32_t service_setting = 0; |
Ken Liu | ce58bfc | 2021-05-12 17:54:48 +0800 | [diff] [blame] | 593 | |
David Hu | f07e97d | 2021-02-15 22:05:40 +0800 | [diff] [blame] | 594 | #ifdef TFM_FIH_PROFILE_ON |
| 595 | fih_int fih_rc = FIH_FAILURE; |
| 596 | #endif |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 597 | |
| 598 | tfm_pool_init(conn_handle_pool, |
| 599 | POOL_BUFFER_SIZE(conn_handle_pool), |
| 600 | sizeof(struct tfm_conn_handle_t), |
| 601 | TFM_CONN_HANDLE_MAX_NUM); |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 602 | |
Mingyang Sun | deae45d | 2021-09-06 15:31:07 +0800 | [diff] [blame] | 603 | UNI_LISI_INIT_HEAD(PARTITION_LIST_ADDR); |
Ken Liu | ea45b0d | 2021-05-22 17:41:25 +0800 | [diff] [blame] | 604 | UNI_LISI_INIT_HEAD(&services_listhead); |
| 605 | |
Sherry Zhnag | 482b88b | 2021-08-19 17:51:47 +0800 | [diff] [blame^] | 606 | /* Init the nonsecure context. */ |
| 607 | #ifndef TFM_MULTI_CORE_TOPOLOGY |
| 608 | tfm_nspm_ctx_init(); |
| 609 | #endif |
| 610 | |
Ken Liu | acd2a57 | 2021-05-12 16:19:04 +0800 | [diff] [blame] | 611 | while (1) { |
Mingyang Sun | deae45d | 2021-09-06 15:31:07 +0800 | [diff] [blame] | 612 | partition = load_a_partition_assuredly(PARTITION_LIST_ADDR); |
Shawn Shan | 2333106 | 2021-09-01 14:58:21 +0800 | [diff] [blame] | 613 | if (partition == NO_MORE_PARTITION) { |
Ken Liu | acd2a57 | 2021-05-12 16:19:04 +0800 | [diff] [blame] | 614 | break; |
Kevin Peng | 79c2bda | 2020-07-24 16:31:12 +0800 | [diff] [blame] | 615 | } |
| 616 | |
Mingyang Sun | deae45d | 2021-09-06 15:31:07 +0800 | [diff] [blame] | 617 | p_pldi = partition->p_ldinf; |
Mingyang Sun | 2b35266 | 2021-04-21 11:35:43 +0800 | [diff] [blame] | 618 | |
Mingyang Sun | deae45d | 2021-09-06 15:31:07 +0800 | [diff] [blame] | 619 | if (p_pldi->nservices) { |
| 620 | service_setting = load_services_assuredly( |
| 621 | partition, |
| 622 | &services_listhead, |
| 623 | stateless_services_ref_tbl, |
| 624 | sizeof(stateless_services_ref_tbl)); |
Kevin Peng | 27e4227 | 2021-05-24 17:58:53 +0800 | [diff] [blame] | 625 | } |
| 626 | |
Mingyang Sun | deae45d | 2021-09-06 15:31:07 +0800 | [diff] [blame] | 627 | if (p_pldi->nirqs) { |
Kevin Peng | 27e4227 | 2021-05-24 17:58:53 +0800 | [diff] [blame] | 628 | load_irqs_assuredly(partition); |
| 629 | } |
| 630 | |
Mingyang Sun | deae45d | 2021-09-06 15:31:07 +0800 | [diff] [blame] | 631 | /* Bind the partition with platform. */ |
Ken Liu | ce58bfc | 2021-05-12 17:54:48 +0800 | [diff] [blame] | 632 | #if TFM_FIH_PROFILE_ON |
| 633 | FIH_CALL(tfm_hal_bind_boundaries, fih_rc, partition->p_ldinf, |
Mingyang Sun | deae45d | 2021-09-06 15:31:07 +0800 | [diff] [blame] | 634 | &partition->p_boundaries); |
Ken Liu | ce58bfc | 2021-05-12 17:54:48 +0800 | [diff] [blame] | 635 | if (fih_not_eq(fih_rc, fih_int_encode(TFM_HAL_SUCCESS))) { |
| 636 | tfm_core_panic(); |
Mingyang Sun | 61f8fbc | 2021-06-04 17:49:56 +0800 | [diff] [blame] | 637 | } |
Ken Liu | 8668628 | 2021-04-27 11:11:15 +0800 | [diff] [blame] | 638 | #else /* TFM_FIH_PROFILE_ON */ |
Ken Liu | ce58bfc | 2021-05-12 17:54:48 +0800 | [diff] [blame] | 639 | if (tfm_hal_bind_boundaries(partition->p_ldinf, |
Mingyang Sun | deae45d | 2021-09-06 15:31:07 +0800 | [diff] [blame] | 640 | &partition->p_boundaries) |
| 641 | != TFM_HAL_SUCCESS) { |
Ken Liu | ce58bfc | 2021-05-12 17:54:48 +0800 | [diff] [blame] | 642 | tfm_core_panic(); |
Mate Toth-Pal | 8ac98a7 | 2019-11-21 17:30:10 +0100 | [diff] [blame] | 643 | } |
Ken Liu | ce58bfc | 2021-05-12 17:54:48 +0800 | [diff] [blame] | 644 | #endif /* TFM_FIH_PROFILE_ON */ |
Mate Toth-Pal | 8ac98a7 | 2019-11-21 17:30:10 +0100 | [diff] [blame] | 645 | |
Mingyang Sun | deae45d | 2021-09-06 15:31:07 +0800 | [diff] [blame] | 646 | /* TODO: Replace this 'BACKEND_IPC' after SFN get involved. */ |
| 647 | backend_instance.comp_init_assuredly(partition, service_setting); |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 648 | } |
| 649 | |
Mingyang Sun | deae45d | 2021-09-06 15:31:07 +0800 | [diff] [blame] | 650 | return backend_instance.system_run(); |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 651 | } |
Ken Liu | 2d17517 | 2019-03-21 17:08:41 +0800 | [diff] [blame] | 652 | |
Ken Liu | 5d73c87 | 2021-08-19 19:23:17 +0800 | [diff] [blame] | 653 | /* |
| 654 | * Return both current and next context to assembly via AAPCS trick: |
| 655 | * - Returning a 64 bit integer by 32-bit R0 and R1. |
| 656 | * |
| 657 | * This is architecture-specific, hence the scheduler entry and this |
| 658 | * 'do_schedule' MAY be different on another architecture. |
| 659 | */ |
| 660 | union returning_contexts_t { |
| 661 | struct { |
| 662 | uint32_t curr; |
| 663 | uint32_t next; |
| 664 | } ctx; |
Ken Liu | 2d17517 | 2019-03-21 17:08:41 +0800 | [diff] [blame] | 665 | |
Ken Liu | 5d73c87 | 2021-08-19 19:23:17 +0800 | [diff] [blame] | 666 | uint64_t curr_next_ctxs; |
| 667 | }; |
| 668 | |
| 669 | uint64_t do_schedule(void) |
| 670 | { |
| 671 | union returning_contexts_t ret; |
| 672 | struct partition_t *p_part_curr, *p_part_next; |
| 673 | struct thread_t *pth_next = thrd_next(); |
| 674 | |
Mingyang Sun | 4f08f4d | 2021-09-10 17:41:28 +0800 | [diff] [blame] | 675 | p_part_curr = GET_THRD_OWNER(CURRENT_THREAD); |
| 676 | p_part_next = GET_THRD_OWNER(pth_next); |
Ken Liu | 5d73c87 | 2021-08-19 19:23:17 +0800 | [diff] [blame] | 677 | |
| 678 | if (pth_next != NULL && p_part_curr != p_part_next) { |
| 679 | /* Check if there is enough room on stack to save more context */ |
| 680 | if ((p_part_curr->ctx_ctrl.sp_limit + |
| 681 | sizeof(struct tfm_additional_context_t)) > __get_PSP()) { |
| 682 | tfm_core_panic(); |
| 683 | } |
Mate Toth-Pal | c430b99 | 2019-05-09 21:01:14 +0200 | [diff] [blame] | 684 | |
Ken Liu | ce58bfc | 2021-05-12 17:54:48 +0800 | [diff] [blame] | 685 | /* |
| 686 | * If required, let the platform update boundary based on its |
| 687 | * implementation. Change privilege, MPU or other configurations. |
| 688 | */ |
| 689 | if (p_part_curr->p_boundaries != p_part_next->p_boundaries) { |
| 690 | if (tfm_hal_update_boundaries(p_part_next->p_ldinf, |
| 691 | p_part_next->p_boundaries) |
| 692 | != TFM_HAL_SUCCESS) { |
| 693 | tfm_core_panic(); |
| 694 | } |
| 695 | } |
Ken Liu | 2d17517 | 2019-03-21 17:08:41 +0800 | [diff] [blame] | 696 | } |
David Hu | fb38d56 | 2019-09-23 15:58:34 +0800 | [diff] [blame] | 697 | |
| 698 | /* |
| 699 | * Handle pending mailbox message from NS in multi-core topology. |
| 700 | * Empty operation on single Armv8-M platform. |
| 701 | */ |
| 702 | tfm_rpc_client_call_handler(); |
Ken Liu | 5d73c87 | 2021-08-19 19:23:17 +0800 | [diff] [blame] | 703 | |
Mingyang Sun | 4f08f4d | 2021-09-10 17:41:28 +0800 | [diff] [blame] | 704 | ret.ctx.curr = (uint32_t)CURRENT_THREAD->p_context_ctrl; |
Ken Liu | 5d73c87 | 2021-08-19 19:23:17 +0800 | [diff] [blame] | 705 | ret.ctx.next = (uint32_t)pth_next->p_context_ctrl; |
| 706 | |
Mingyang Sun | 4f08f4d | 2021-09-10 17:41:28 +0800 | [diff] [blame] | 707 | CURRENT_THREAD = pth_next; |
Ken Liu | 5d73c87 | 2021-08-19 19:23:17 +0800 | [diff] [blame] | 708 | |
| 709 | return ret.curr_next_ctxs; |
Ken Liu | 2d17517 | 2019-03-21 17:08:41 +0800 | [diff] [blame] | 710 | } |
Mingyang Sun | d44522a | 2020-01-16 16:48:37 +0800 | [diff] [blame] | 711 | |
Summer Qin | 02f7f07 | 2020-08-24 16:02:54 +0800 | [diff] [blame] | 712 | void update_caller_outvec_len(struct tfm_msg_body_t *msg) |
Mingyang Sun | d44522a | 2020-01-16 16:48:37 +0800 | [diff] [blame] | 713 | { |
| 714 | uint32_t i; |
| 715 | |
| 716 | /* |
| 717 | * FixeMe: abstract these part into dedicated functions to avoid |
| 718 | * accessing thread context in psa layer |
| 719 | */ |
| 720 | /* If it is a NS request via RPC, the owner of this message is not set */ |
| 721 | if (!is_tfm_rpc_msg(msg)) { |
| 722 | TFM_CORE_ASSERT(msg->ack_evnt.owner->state == THRD_STATE_BLOCK); |
| 723 | } |
| 724 | |
| 725 | for (i = 0; i < PSA_MAX_IOVEC; i++) { |
| 726 | if (msg->msg.out_size[i] == 0) { |
| 727 | continue; |
| 728 | } |
| 729 | |
| 730 | TFM_CORE_ASSERT(msg->caller_outvec[i].base == msg->outvec[i].base); |
| 731 | |
| 732 | msg->caller_outvec[i].len = msg->outvec[i].len; |
| 733 | } |
| 734 | } |
| 735 | |
Ken Liu | 5d73c87 | 2021-08-19 19:23:17 +0800 | [diff] [blame] | 736 | void spm_assert_signal(void *p_pt, psa_signal_t signal) |
Mingyang Sun | d44522a | 2020-01-16 16:48:37 +0800 | [diff] [blame] | 737 | { |
Ken Liu | 5d73c87 | 2021-08-19 19:23:17 +0800 | [diff] [blame] | 738 | struct partition_t *partition = (struct partition_t *)p_pt; |
Mingyang Sun | d44522a | 2020-01-16 16:48:37 +0800 | [diff] [blame] | 739 | |
Mingyang Sun | d44522a | 2020-01-16 16:48:37 +0800 | [diff] [blame] | 740 | if (!partition) { |
| 741 | tfm_core_panic(); |
| 742 | } |
| 743 | |
Mingyang Sun | af22ffa | 2020-07-09 17:48:37 +0800 | [diff] [blame] | 744 | partition->signals_asserted |= signal; |
Mingyang Sun | d44522a | 2020-01-16 16:48:37 +0800 | [diff] [blame] | 745 | |
Kevin Peng | 8dac610 | 2021-03-09 16:44:00 +0800 | [diff] [blame] | 746 | if (partition->signals_waiting & signal) { |
Ken Liu | 5d73c87 | 2021-08-19 19:23:17 +0800 | [diff] [blame] | 747 | thrd_wake_up(&partition->waitobj, |
| 748 | partition->signals_asserted & partition->signals_waiting); |
Kevin Peng | 8dac610 | 2021-03-09 16:44:00 +0800 | [diff] [blame] | 749 | partition->signals_waiting &= ~signal; |
| 750 | } |
Mingyang Sun | d44522a | 2020-01-16 16:48:37 +0800 | [diff] [blame] | 751 | } |
| 752 | |
Kevin Peng | eca45b9 | 2021-02-09 14:46:50 +0800 | [diff] [blame] | 753 | __attribute__((naked)) |
Ken Liu | 5d73c87 | 2021-08-19 19:23:17 +0800 | [diff] [blame] | 754 | static psa_flih_result_t tfm_flih_deprivileged_handling(void *p_pt, |
Kevin Peng | ec239bb | 2021-09-03 15:40:27 +0800 | [diff] [blame] | 755 | uintptr_t fn_flih, |
Ken Liu | 5d73c87 | 2021-08-19 19:23:17 +0800 | [diff] [blame] | 756 | void *p_context_ctrl) |
Mingyang Sun | d44522a | 2020-01-16 16:48:37 +0800 | [diff] [blame] | 757 | { |
Kevin Peng | eca45b9 | 2021-02-09 14:46:50 +0800 | [diff] [blame] | 758 | __ASM volatile("SVC %0 \n" |
| 759 | "BX LR \n" |
| 760 | : : "I" (TFM_SVC_PREPARE_DEPRIV_FLIH)); |
| 761 | } |
Kevin Peng | dc79188 | 2021-03-12 10:57:12 +0800 | [diff] [blame] | 762 | |
Kevin Peng | ec239bb | 2021-09-03 15:40:27 +0800 | [diff] [blame] | 763 | void spm_handle_interrupt(void *p_pt, struct irq_load_info_t *p_ildi) |
Kevin Peng | eca45b9 | 2021-02-09 14:46:50 +0800 | [diff] [blame] | 764 | { |
Kevin Peng | eca45b9 | 2021-02-09 14:46:50 +0800 | [diff] [blame] | 765 | psa_flih_result_t flih_result; |
Kevin Peng | ec239bb | 2021-09-03 15:40:27 +0800 | [diff] [blame] | 766 | struct partition_t *p_part; |
Kevin Peng | dc79188 | 2021-03-12 10:57:12 +0800 | [diff] [blame] | 767 | |
Kevin Peng | ec239bb | 2021-09-03 15:40:27 +0800 | [diff] [blame] | 768 | if (!p_pt || !p_ildi) { |
Ken Liu | 5d73c87 | 2021-08-19 19:23:17 +0800 | [diff] [blame] | 769 | tfm_core_panic(); |
| 770 | } |
Kevin Peng | eca45b9 | 2021-02-09 14:46:50 +0800 | [diff] [blame] | 771 | |
Kevin Peng | ec239bb | 2021-09-03 15:40:27 +0800 | [diff] [blame] | 772 | p_part = (struct partition_t *)p_pt; |
| 773 | |
| 774 | if (p_ildi->pid != p_part->p_ldinf->pid) { |
| 775 | tfm_core_panic(); |
| 776 | } |
| 777 | |
| 778 | if (p_ildi->flih_func == NULL) { |
Kevin Peng | eca45b9 | 2021-02-09 14:46:50 +0800 | [diff] [blame] | 779 | /* SLIH Model Handling */ |
Kevin Peng | ec239bb | 2021-09-03 15:40:27 +0800 | [diff] [blame] | 780 | tfm_hal_irq_disable(p_ildi->source); |
Ken Liu | 5d73c87 | 2021-08-19 19:23:17 +0800 | [diff] [blame] | 781 | flih_result = PSA_FLIH_SIGNAL; |
| 782 | } else { |
| 783 | /* FLIH Model Handling */ |
Kevin Peng | ec239bb | 2021-09-03 15:40:27 +0800 | [diff] [blame] | 784 | if (tfm_spm_partition_get_privileged_mode(p_part->p_ldinf->flags) == |
Ken Liu | 5d73c87 | 2021-08-19 19:23:17 +0800 | [diff] [blame] | 785 | TFM_PARTITION_PRIVILEGED_MODE) { |
Kevin Peng | ec239bb | 2021-09-03 15:40:27 +0800 | [diff] [blame] | 786 | flih_result = p_ildi->flih_func(); |
Ken Liu | 5d73c87 | 2021-08-19 19:23:17 +0800 | [diff] [blame] | 787 | } else { |
| 788 | flih_result = tfm_flih_deprivileged_handling( |
Mingyang Sun | 4f08f4d | 2021-09-10 17:41:28 +0800 | [diff] [blame] | 789 | p_part, |
| 790 | (uintptr_t)p_ildi->flih_func, |
| 791 | CURRENT_THREAD->p_context_ctrl); |
Ken Liu | 5d73c87 | 2021-08-19 19:23:17 +0800 | [diff] [blame] | 792 | } |
Kevin Peng | eca45b9 | 2021-02-09 14:46:50 +0800 | [diff] [blame] | 793 | } |
| 794 | |
Ken Liu | 5d73c87 | 2021-08-19 19:23:17 +0800 | [diff] [blame] | 795 | if (flih_result == PSA_FLIH_SIGNAL) { |
| 796 | __disable_irq(); |
Kevin Peng | ec239bb | 2021-09-03 15:40:27 +0800 | [diff] [blame] | 797 | spm_assert_signal(p_pt, p_ildi->signal); |
Ken Liu | 5d73c87 | 2021-08-19 19:23:17 +0800 | [diff] [blame] | 798 | __enable_irq(); |
Kevin Peng | eca45b9 | 2021-02-09 14:46:50 +0800 | [diff] [blame] | 799 | } |
Mingyang Sun | d44522a | 2020-01-16 16:48:37 +0800 | [diff] [blame] | 800 | } |
| 801 | |
Kevin Peng | 27e4227 | 2021-05-24 17:58:53 +0800 | [diff] [blame] | 802 | struct irq_load_info_t *get_irq_info_for_signal( |
| 803 | const struct partition_load_info_t *p_ldinf, |
| 804 | psa_signal_t signal) |
Mingyang Sun | d44522a | 2020-01-16 16:48:37 +0800 | [diff] [blame] | 805 | { |
| 806 | size_t i; |
Kevin Peng | 27e4227 | 2021-05-24 17:58:53 +0800 | [diff] [blame] | 807 | struct irq_load_info_t *irq_info; |
Mingyang Sun | d44522a | 2020-01-16 16:48:37 +0800 | [diff] [blame] | 808 | |
Ken Liu | 24dffb2 | 2021-02-10 11:03:58 +0800 | [diff] [blame] | 809 | if (!IS_ONLY_ONE_BIT_IN_UINT32(signal)) { |
Kevin Peng | 27e4227 | 2021-05-24 17:58:53 +0800 | [diff] [blame] | 810 | return NULL; |
Kevin Peng | 410bee5 | 2021-01-13 16:27:17 +0800 | [diff] [blame] | 811 | } |
| 812 | |
Kevin Peng | 27e4227 | 2021-05-24 17:58:53 +0800 | [diff] [blame] | 813 | irq_info = (struct irq_load_info_t *)LOAD_INFO_IRQ(p_ldinf); |
| 814 | for (i = 0; i < p_ldinf->nirqs; i++) { |
| 815 | if (irq_info[i].signal == signal) { |
| 816 | return &irq_info[i]; |
Mingyang Sun | d44522a | 2020-01-16 16:48:37 +0800 | [diff] [blame] | 817 | } |
| 818 | } |
Kevin Peng | a20b5af | 2021-01-11 11:20:52 +0800 | [diff] [blame] | 819 | |
Kevin Peng | 27e4227 | 2021-05-24 17:58:53 +0800 | [diff] [blame] | 820 | return NULL; |
Mingyang Sun | d44522a | 2020-01-16 16:48:37 +0800 | [diff] [blame] | 821 | } |