blob: 4062073a9a42065b462e94a2a2c7a51137369593 [file] [log] [blame]
Edison Ai764d41f2018-09-21 15:56:36 +08001/*
Sherry Zhangdcab2862022-01-10 10:43:31 +08002 * Copyright (c) 2018-2022, Arm Limited. All rights reserved.
Chris Brand56b4d0c2021-12-17 16:15:58 -08003 * Copyright (c) 2021, Cypress Semiconductor Corporation. All rights reserved.
Edison Ai764d41f2018-09-21 15:56:36 +08004 *
5 * SPDX-License-Identifier: BSD-3-Clause
6 *
7 */
Mingyang Sunda01a972019-07-12 17:32:59 +08008
Edison Ai764d41f2018-09-21 15:56:36 +08009#include <inttypes.h>
10#include <stdbool.h>
Ken Liu086b32c2021-12-27 14:44:52 +080011#include "aapcs_local.h"
Ken Liu24dffb22021-02-10 11:03:58 +080012#include "bitops.h"
Mingyang Sun4609ac72022-02-08 18:56:35 +080013#include "config_impl.h"
Ken Liu92ede9f2021-10-20 09:35:00 +080014#include "critical_section.h"
Ken Liuf39d8eb2021-10-07 12:55:33 +080015#include "current.h"
David Huf07e97d2021-02-15 22:05:40 +080016#include "fih.h"
Jamie Foxcc31d402019-01-28 17:13:52 +000017#include "psa/client.h"
18#include "psa/service.h"
Ken Liu5d73c872021-08-19 19:23:17 +080019#include "thread.h"
Ken Liubcae38b2021-01-20 15:47:44 +080020#include "internal_errors.h"
Mingyang Sund44522a2020-01-16 16:48:37 +080021#include "tfm_spm_hal.h"
Mingyang Sund44522a2020-01-16 16:48:37 +080022#include "tfm_api.h"
Kevin Pengb20b0322022-02-09 16:47:19 +080023#include "tfm_arch.h"
Mingyang Sund44522a2020-01-16 16:48:37 +080024#include "tfm_secure_api.h"
25#include "tfm_memory_utils.h"
Mingyang Sund1ed6732020-08-26 15:52:21 +080026#include "tfm_hal_defs.h"
Kevin Pengd399a1f2021-09-08 15:33:14 +080027#include "tfm_hal_interrupt.h"
Mingyang Sund1ed6732020-08-26 15:52:21 +080028#include "tfm_hal_isolation.h"
Mingyang Sun7397b4f2020-06-17 15:07:45 +080029#include "spm_ipc.h"
Mingyang Sund44522a2020-01-16 16:48:37 +080030#include "tfm_peripherals_def.h"
Mingyang Sund44522a2020-01-16 16:48:37 +080031#include "tfm_core_utils.h"
Kevin Peng385fda82021-08-18 10:41:19 +080032#include "tfm_nspm.h"
Mingyang Sund44522a2020-01-16 16:48:37 +080033#include "tfm_rpc.h"
Mingyang Sund44522a2020-01-16 16:48:37 +080034#include "tfm_core_trustzone.h"
Ken Liu24dffb22021-02-10 11:03:58 +080035#include "lists.h"
Edison Ai764d41f2018-09-21 15:56:36 +080036#include "tfm_pools.h"
Mingyang Sun22a3faf2021-07-09 15:32:47 +080037#include "region.h"
Mingyang Sun7397b4f2020-06-17 15:07:45 +080038#include "psa_manifest/pid.h"
Mingyang Sundeae45d2021-09-06 15:31:07 +080039#include "ffm/backend.h"
Mingyang Sun00df2352021-04-15 15:46:08 +080040#include "load/partition_defs.h"
41#include "load/service_defs.h"
Ken Liu86686282021-04-27 11:11:15 +080042#include "load/asset_defs.h"
Ken Liuacd2a572021-05-12 16:19:04 +080043#include "load/spm_load_api.h"
Sherry Zhnag482b88b2021-08-19 17:51:47 +080044#include "tfm_nspm.h"
Summer Qin596f5552022-01-27 18:04:06 +080045#if defined(CONFIG_TFM_PARTITION_META)
46#include "tfm_hal_memory_symbols.h"
47#endif
Edison Ai764d41f2018-09-21 15:56:36 +080048
Sherry Zhang86a71c62022-01-12 18:19:02 +080049#if !(defined CONFIG_TFM_CONN_HANDLE_MAX_NUM) || (CONFIG_TFM_CONN_HANDLE_MAX_NUM == 0)
50#error "CONFIG_TFM_CONN_HANDLE_MAX_NUM must be defined and not zero."
51#endif
52
Ken Liuea45b0d2021-05-22 17:41:25 +080053/* Partition and service runtime data list head/runtime data table */
Ken Liuea45b0d2021-05-22 17:41:25 +080054static struct service_head_t services_listhead;
Ken Liub3b2cb62021-05-22 00:39:28 +080055struct service_t *stateless_services_ref_tbl[STATIC_HANDLE_NUM_LIMIT];
Summer Qind99509f2019-08-02 17:36:58 +080056
Summer Qin596f5552022-01-27 18:04:06 +080057#if defined(CONFIG_TFM_PARTITION_META)
58/* Indicator point to the partition meta */
59static uintptr_t *partition_meta_indicator_pos = NULL;
60#endif
61
Edison Ai764d41f2018-09-21 15:56:36 +080062/* Pools */
Ken Liu0bed7e02022-02-10 12:38:07 +080063TFM_POOL_DECLARE(conn_handle_pool, sizeof(struct conn_handle_t),
Sherry Zhang86a71c62022-01-12 18:19:02 +080064 CONFIG_TFM_CONN_HANDLE_MAX_NUM);
Edison Ai764d41f2018-09-21 15:56:36 +080065
Mingyang Sun620c8562021-11-10 11:44:58 +080066extern uint32_t scheduler_lock;
67
Summer Qin373feb12020-03-27 15:35:33 +080068/*********************** Connection handle conversion APIs *******************/
69
Summer Qin373feb12020-03-27 15:35:33 +080070#define CONVERSION_FACTOR_BITOFFSET 3
71#define CONVERSION_FACTOR_VALUE (1 << CONVERSION_FACTOR_BITOFFSET)
72/* Set 32 as the maximum */
73#define CONVERSION_FACTOR_VALUE_MAX 0x20
74
75#if CONVERSION_FACTOR_VALUE > CONVERSION_FACTOR_VALUE_MAX
76#error "CONVERSION FACTOR OUT OF RANGE"
77#endif
78
79static uint32_t loop_index;
80
81/*
82 * A handle instance psa_handle_t allocated inside SPM is actually a memory
83 * address among the handle pool. Return this handle to the client directly
84 * exposes information of secure memory address. In this case, converting the
85 * handle into another value does not represent the memory address to avoid
86 * exposing secure memory directly to clients.
87 *
88 * This function converts the handle instance into another value by scaling the
89 * handle in pool offset, the converted value is named as a user handle.
90 *
91 * The formula:
92 * user_handle = (handle_instance - POOL_START) * CONVERSION_FACTOR_VALUE +
93 * CLIENT_HANDLE_VALUE_MIN + loop_index
94 * where:
95 * CONVERSION_FACTOR_VALUE = 1 << CONVERSION_FACTOR_BITOFFSET, and should not
96 * exceed CONVERSION_FACTOR_VALUE_MAX.
97 *
98 * handle_instance in RANGE[POOL_START, POOL_END]
99 * user_handle in RANGE[CLIENT_HANDLE_VALUE_MIN, 0x3FFFFFFF]
100 * loop_index in RANGE[0, CONVERSION_FACTOR_VALUE - 1]
101 *
102 * note:
103 * loop_index is used to promise same handle instance is converted into
104 * different user handles in short time.
105 */
Ken Liu0bed7e02022-02-10 12:38:07 +0800106psa_handle_t tfm_spm_to_user_handle(struct conn_handle_t *handle_instance)
Summer Qin373feb12020-03-27 15:35:33 +0800107{
108 psa_handle_t user_handle;
109
110 loop_index = (loop_index + 1) % CONVERSION_FACTOR_VALUE;
111 user_handle = (psa_handle_t)((((uintptr_t)handle_instance -
112 (uintptr_t)conn_handle_pool) << CONVERSION_FACTOR_BITOFFSET) +
113 CLIENT_HANDLE_VALUE_MIN + loop_index);
114
115 return user_handle;
116}
117
118/*
119 * This function converts a user handle into a corresponded handle instance.
120 * The converted value is validated before returning, an invalid handle instance
121 * is returned as NULL.
122 *
123 * The formula:
124 * handle_instance = ((user_handle - CLIENT_HANDLE_VALUE_MIN) /
125 * CONVERSION_FACTOR_VALUE) + POOL_START
126 * where:
127 * CONVERSION_FACTOR_VALUE = 1 << CONVERSION_FACTOR_BITOFFSET, and should not
128 * exceed CONVERSION_FACTOR_VALUE_MAX.
129 *
130 * handle_instance in RANGE[POOL_START, POOL_END]
131 * user_handle in RANGE[CLIENT_HANDLE_VALUE_MIN, 0x3FFFFFFF]
132 * loop_index in RANGE[0, CONVERSION_FACTOR_VALUE - 1]
133 */
Ken Liu0bed7e02022-02-10 12:38:07 +0800134struct conn_handle_t *tfm_spm_to_handle_instance(psa_handle_t user_handle)
Summer Qin373feb12020-03-27 15:35:33 +0800135{
Ken Liu0bed7e02022-02-10 12:38:07 +0800136 struct conn_handle_t *handle_instance;
Summer Qin373feb12020-03-27 15:35:33 +0800137
138 if (user_handle == PSA_NULL_HANDLE) {
139 return NULL;
140 }
141
Ken Liu0bed7e02022-02-10 12:38:07 +0800142 handle_instance = (struct conn_handle_t *)((((uintptr_t)user_handle -
Summer Qin373feb12020-03-27 15:35:33 +0800143 CLIENT_HANDLE_VALUE_MIN) >> CONVERSION_FACTOR_BITOFFSET) +
144 (uintptr_t)conn_handle_pool);
145
146 return handle_instance;
147}
148
Edison Ai764d41f2018-09-21 15:56:36 +0800149/* Service handle management functions */
Ken Liu0bed7e02022-02-10 12:38:07 +0800150struct conn_handle_t *tfm_spm_create_conn_handle(struct service_t *service,
151 int32_t client_id)
Edison Ai764d41f2018-09-21 15:56:36 +0800152{
Ken Liu0bed7e02022-02-10 12:38:07 +0800153 struct conn_handle_t *p_handle;
Edison Ai764d41f2018-09-21 15:56:36 +0800154
Ken Liuf250b8b2019-12-27 16:31:24 +0800155 TFM_CORE_ASSERT(service);
Edison Ai764d41f2018-09-21 15:56:36 +0800156
157 /* Get buffer for handle list structure from handle pool */
Ken Liu0bed7e02022-02-10 12:38:07 +0800158 p_handle = (struct conn_handle_t *)tfm_pool_alloc(conn_handle_pool);
Edison Ai9cc26242019-08-06 11:28:04 +0800159 if (!p_handle) {
Summer Qin630c76b2020-05-20 10:32:58 +0800160 return NULL;
Edison Ai764d41f2018-09-21 15:56:36 +0800161 }
162
Kevin Peng2cc25722021-11-18 11:46:02 +0800163 spm_memset(p_handle, 0, sizeof(*p_handle));
164
Ken Liu0bed7e02022-02-10 12:38:07 +0800165 p_handle->service = service;
Shawn Shancc39fcb2019-11-13 15:38:16 +0800166 p_handle->status = TFM_HANDLE_STATUS_IDLE;
Summer Qin1ce712a2019-10-14 18:04:05 +0800167 p_handle->client_id = client_id;
Edison Ai764d41f2018-09-21 15:56:36 +0800168
Summer Qin630c76b2020-05-20 10:32:58 +0800169 return p_handle;
Edison Ai764d41f2018-09-21 15:56:36 +0800170}
171
Sherry Zhanga4575f32022-02-23 15:45:51 +0800172#if CONFIG_TFM_CONNECTION_BASED_SERVICE_API == 1
Ken Liu0bed7e02022-02-10 12:38:07 +0800173int32_t tfm_spm_validate_conn_handle(const struct conn_handle_t *conn_handle,
174 int32_t client_id)
Summer Qin1ce712a2019-10-14 18:04:05 +0800175{
176 /* Check the handle address is validated */
177 if (is_valid_chunk_data_in_pool(conn_handle_pool,
178 (uint8_t *)conn_handle) != true) {
Ken Liubcae38b2021-01-20 15:47:44 +0800179 return SPM_ERROR_GENERIC;
Summer Qin1ce712a2019-10-14 18:04:05 +0800180 }
181
182 /* Check the handle caller is correct */
Summer Qin630c76b2020-05-20 10:32:58 +0800183 if (conn_handle->client_id != client_id) {
Ken Liubcae38b2021-01-20 15:47:44 +0800184 return SPM_ERROR_GENERIC;
Summer Qin1ce712a2019-10-14 18:04:05 +0800185 }
186
Ken Liubcae38b2021-01-20 15:47:44 +0800187 return SPM_SUCCESS;
Summer Qin1ce712a2019-10-14 18:04:05 +0800188}
Sherry Zhanga4575f32022-02-23 15:45:51 +0800189#endif
Summer Qin1ce712a2019-10-14 18:04:05 +0800190
Mingyang Sun783a59b2021-04-20 15:52:18 +0800191int32_t tfm_spm_free_conn_handle(struct service_t *service,
Ken Liu0bed7e02022-02-10 12:38:07 +0800192 struct conn_handle_t *conn_handle)
Edison Ai764d41f2018-09-21 15:56:36 +0800193{
Mingyang Sun620c8562021-11-10 11:44:58 +0800194 struct critical_section_t cs_assert = CRITICAL_SECTION_STATIC_INIT;
195
Ken Liuf250b8b2019-12-27 16:31:24 +0800196 TFM_CORE_ASSERT(service);
Summer Qin630c76b2020-05-20 10:32:58 +0800197 TFM_CORE_ASSERT(conn_handle != NULL);
Edison Ai764d41f2018-09-21 15:56:36 +0800198
Mate Toth-Pala4b5d242019-09-23 09:14:47 +0200199 /* Clear magic as the handler is not used anymore */
Ken Liu0bed7e02022-02-10 12:38:07 +0800200 conn_handle->magic = 0;
Mate Toth-Pala4b5d242019-09-23 09:14:47 +0200201
Mingyang Sun620c8562021-11-10 11:44:58 +0800202 CRITICAL_SECTION_ENTER(cs_assert);
Edison Ai764d41f2018-09-21 15:56:36 +0800203
204 /* Back handle buffer to pool */
Ken Liu66ca6132021-02-24 08:49:51 +0800205 tfm_pool_free(conn_handle_pool, conn_handle);
Mingyang Sun620c8562021-11-10 11:44:58 +0800206 CRITICAL_SECTION_LEAVE(cs_assert);
207
Ken Liubcae38b2021-01-20 15:47:44 +0800208 return SPM_SUCCESS;
Edison Ai764d41f2018-09-21 15:56:36 +0800209}
210
Edison Ai764d41f2018-09-21 15:56:36 +0800211/* Partition management functions */
Mingyang Sund44522a2020-01-16 16:48:37 +0800212
Mingyang Sun4609ac72022-02-08 18:56:35 +0800213/* This API is only used in IPC backend. */
214#if CONFIG_TFM_SPM_BACKEND_IPC == 1
Ken Liu0bed7e02022-02-10 12:38:07 +0800215struct conn_handle_t *spm_get_handle_by_signal(struct partition_t *p_ptn,
Ken Liu5a28da32022-01-19 14:37:05 +0800216 psa_signal_t signal)
Edison Ai764d41f2018-09-21 15:56:36 +0800217{
Mingyang Suna09adda2022-02-16 18:11:33 +0800218 struct conn_handle_t *p_handle_iter;
219 struct conn_handle_t **pr_handle_iter, **last_found_handle_holder = NULL;
Ken Liu92ede9f2021-10-20 09:35:00 +0800220 struct critical_section_t cs_assert = CRITICAL_SECTION_STATIC_INIT;
Ken Liu5a28da32022-01-19 14:37:05 +0800221 uint32_t nr_found_msgs = 0;
Edison Ai764d41f2018-09-21 15:56:36 +0800222
Mingyang Sun620c8562021-11-10 11:44:58 +0800223 CRITICAL_SECTION_ENTER(cs_assert);
Ken Liu5a28da32022-01-19 14:37:05 +0800224
225 /* Return the last found message which applies a FIFO mechanism. */
Mingyang Suna09adda2022-02-16 18:11:33 +0800226 UNI_LIST_FOREACH_NODE_PNODE(pr_handle_iter, p_handle_iter,
227 p_ptn, p_handles) {
228 if (p_handle_iter->service->p_ldinf->signal == signal) {
229 last_found_handle_holder = pr_handle_iter;
Ken Liu5a28da32022-01-19 14:37:05 +0800230 nr_found_msgs++;
Edison Ai764d41f2018-09-21 15:56:36 +0800231 }
232 }
Mingyang Sun73056b62020-07-03 15:18:46 +0800233
Mingyang Suna09adda2022-02-16 18:11:33 +0800234 if (last_found_handle_holder) {
235 p_handle_iter = *last_found_handle_holder;
236 UNI_LIST_REMOVE_NODE_BY_PNODE(last_found_handle_holder, p_handles);
Ken Liu5a28da32022-01-19 14:37:05 +0800237
Ken Liu5a28da32022-01-19 14:37:05 +0800238 if (nr_found_msgs == 1) {
239 p_ptn->signals_asserted &= ~signal;
240 }
241 }
242
Ken Liu92ede9f2021-10-20 09:35:00 +0800243 CRITICAL_SECTION_LEAVE(cs_assert);
Mingyang Sun73056b62020-07-03 15:18:46 +0800244
Mingyang Suna09adda2022-02-16 18:11:33 +0800245 return p_handle_iter;
Edison Ai764d41f2018-09-21 15:56:36 +0800246}
Mingyang Suna09adda2022-02-16 18:11:33 +0800247#endif /* CONFIG_TFM_SPM_BACKEND_IPC == 1 */
Edison Ai764d41f2018-09-21 15:56:36 +0800248
Mingyang Sun783a59b2021-04-20 15:52:18 +0800249struct service_t *tfm_spm_get_service_by_sid(uint32_t sid)
Edison Ai764d41f2018-09-21 15:56:36 +0800250{
Feder.Liangaeb5a792021-08-10 16:12:56 +0800251 struct service_t *p_prev, *p_curr;
Edison Ai764d41f2018-09-21 15:56:36 +0800252
Ken Liu5a28da32022-01-19 14:37:05 +0800253 UNI_LIST_FOREACH_NODE_PREV(p_prev, p_curr, &services_listhead, next) {
Feder.Liangaeb5a792021-08-10 16:12:56 +0800254 if (p_curr->p_ldinf->sid == sid) {
Ken Liu5a28da32022-01-19 14:37:05 +0800255 UNI_LIST_MOVE_AFTER(&services_listhead, p_prev, p_curr, next);
Feder.Liangaeb5a792021-08-10 16:12:56 +0800256 return p_curr;
Mingyang Sunef42f442021-06-11 15:07:58 +0800257 }
258 }
259
Ken Liuea45b0d2021-05-22 17:41:25 +0800260 return NULL;
Edison Ai764d41f2018-09-21 15:56:36 +0800261}
262
Kevin Peng613b4172022-02-15 14:41:44 +0800263#if CONFIG_TFM_DOORBELL_API == 1
Mingyang Sund44522a2020-01-16 16:48:37 +0800264/**
265 * \brief Get the partition context by partition ID.
266 *
267 * \param[in] partition_id Partition identity
268 *
269 * \retval NULL Failed
270 * \retval "Not NULL" Target partition context pointer,
Mingyang Sunae70d8d2020-06-30 15:56:05 +0800271 * \ref partition_t structures
Mingyang Sund44522a2020-01-16 16:48:37 +0800272 */
Kevin Pengeca45b92021-02-09 14:46:50 +0800273struct partition_t *tfm_spm_get_partition_by_id(int32_t partition_id)
Edison Ai764d41f2018-09-21 15:56:36 +0800274{
Ken Liuea45b0d2021-05-22 17:41:25 +0800275 struct partition_t *p_part;
Edison Ai764d41f2018-09-21 15:56:36 +0800276
Ken Liu5a28da32022-01-19 14:37:05 +0800277 UNI_LIST_FOREACH(p_part, PARTITION_LIST_ADDR, next) {
Ken Liuea45b0d2021-05-22 17:41:25 +0800278 if (p_part->p_ldinf->pid == partition_id) {
279 return p_part;
280 }
Edison Ai764d41f2018-09-21 15:56:36 +0800281 }
Ken Liuea45b0d2021-05-22 17:41:25 +0800282
Edison Ai764d41f2018-09-21 15:56:36 +0800283 return NULL;
284}
Kevin Peng613b4172022-02-15 14:41:44 +0800285#endif /* CONFIG_TFM_DOORBELL_API == 1 */
Edison Ai764d41f2018-09-21 15:56:36 +0800286
Mingyang Sun783a59b2021-04-20 15:52:18 +0800287int32_t tfm_spm_check_client_version(struct service_t *service,
Jaykumar Pitambarbhai Patel3a986022019-10-08 17:37:15 +0530288 uint32_t version)
Edison Ai764d41f2018-09-21 15:56:36 +0800289{
Ken Liuf250b8b2019-12-27 16:31:24 +0800290 TFM_CORE_ASSERT(service);
Edison Ai764d41f2018-09-21 15:56:36 +0800291
Ken Liuacd2a572021-05-12 16:19:04 +0800292 switch (SERVICE_GET_VERSION_POLICY(service->p_ldinf->flags)) {
Ken Liub3b2cb62021-05-22 00:39:28 +0800293 case SERVICE_VERSION_POLICY_RELAXED:
Ken Liuacd2a572021-05-12 16:19:04 +0800294 if (version > service->p_ldinf->version) {
Ken Liubcae38b2021-01-20 15:47:44 +0800295 return SPM_ERROR_VERSION;
Edison Ai764d41f2018-09-21 15:56:36 +0800296 }
297 break;
Ken Liub3b2cb62021-05-22 00:39:28 +0800298 case SERVICE_VERSION_POLICY_STRICT:
Ken Liuacd2a572021-05-12 16:19:04 +0800299 if (version != service->p_ldinf->version) {
Ken Liubcae38b2021-01-20 15:47:44 +0800300 return SPM_ERROR_VERSION;
Edison Ai764d41f2018-09-21 15:56:36 +0800301 }
302 break;
303 default:
Ken Liubcae38b2021-01-20 15:47:44 +0800304 return SPM_ERROR_VERSION;
Edison Ai764d41f2018-09-21 15:56:36 +0800305 }
Ken Liubcae38b2021-01-20 15:47:44 +0800306 return SPM_SUCCESS;
Edison Ai764d41f2018-09-21 15:56:36 +0800307}
308
Edison Aie728fbf2019-11-13 09:37:12 +0800309int32_t tfm_spm_check_authorization(uint32_t sid,
Mingyang Sun783a59b2021-04-20 15:52:18 +0800310 struct service_t *service,
Summer Qin618e8c32019-12-09 10:47:20 +0800311 bool ns_caller)
Edison Aie728fbf2019-11-13 09:37:12 +0800312{
Mingyang Sunae70d8d2020-06-30 15:56:05 +0800313 struct partition_t *partition = NULL;
Mingyang Sun2b352662021-04-21 11:35:43 +0800314 uint32_t *dep;
Edison Aie728fbf2019-11-13 09:37:12 +0800315 int32_t i;
316
Ken Liuf250b8b2019-12-27 16:31:24 +0800317 TFM_CORE_ASSERT(service);
Edison Aie728fbf2019-11-13 09:37:12 +0800318
319 if (ns_caller) {
Ken Liuacd2a572021-05-12 16:19:04 +0800320 if (!SERVICE_IS_NS_ACCESSIBLE(service->p_ldinf->flags)) {
Ken Liubcae38b2021-01-20 15:47:44 +0800321 return SPM_ERROR_GENERIC;
Edison Aie728fbf2019-11-13 09:37:12 +0800322 }
323 } else {
Kevin Pengcdf3ae22022-01-19 14:53:52 +0800324 partition = GET_CURRENT_COMPONENT();
Edison Aie728fbf2019-11-13 09:37:12 +0800325 if (!partition) {
Edison Ai9059ea02019-11-28 13:46:14 +0800326 tfm_core_panic();
Edison Aie728fbf2019-11-13 09:37:12 +0800327 }
328
Ken Liuacd2a572021-05-12 16:19:04 +0800329 dep = (uint32_t *)LOAD_INFO_DEPS(partition->p_ldinf);
330 for (i = 0; i < partition->p_ldinf->ndeps; i++) {
Mingyang Sun2b352662021-04-21 11:35:43 +0800331 if (dep[i] == sid) {
Edison Aie728fbf2019-11-13 09:37:12 +0800332 break;
333 }
334 }
335
Ken Liuacd2a572021-05-12 16:19:04 +0800336 if (i == partition->p_ldinf->ndeps) {
Ken Liubcae38b2021-01-20 15:47:44 +0800337 return SPM_ERROR_GENERIC;
Edison Aie728fbf2019-11-13 09:37:12 +0800338 }
339 }
Ken Liubcae38b2021-01-20 15:47:44 +0800340 return SPM_SUCCESS;
Edison Aie728fbf2019-11-13 09:37:12 +0800341}
342
Edison Ai764d41f2018-09-21 15:56:36 +0800343/* Message functions */
Mingyang Sund44522a2020-01-16 16:48:37 +0800344
Ken Liu0bed7e02022-02-10 12:38:07 +0800345struct conn_handle_t *spm_get_handle_by_user_handle(psa_handle_t msg_handle)
Edison Ai764d41f2018-09-21 15:56:36 +0800346{
347 /*
Mate Toth-Pala4b5d242019-09-23 09:14:47 +0200348 * The message handler passed by the caller is considered invalid in the
349 * following cases:
350 * 1. Not a valid message handle. (The address of a message is not the
351 * address of a possible handle from the pool
352 * 2. Handle not belongs to the caller partition (The handle is either
Mingyang Suna09adda2022-02-16 18:11:33 +0800353 * unused, or owned by another partition)
Mate Toth-Pala4b5d242019-09-23 09:14:47 +0200354 * Check the conditions above
Edison Ai764d41f2018-09-21 15:56:36 +0800355 */
Kevin Pengeec41a82021-08-18 13:56:23 +0800356 int32_t partition_id;
Ken Liu0bed7e02022-02-10 12:38:07 +0800357 struct conn_handle_t *p_conn_handle =
Ken Liu5d73c872021-08-19 19:23:17 +0800358 tfm_spm_to_handle_instance(msg_handle);
Mate Toth-Pala4b5d242019-09-23 09:14:47 +0200359
360 if (is_valid_chunk_data_in_pool(
Ken Liu0bed7e02022-02-10 12:38:07 +0800361 conn_handle_pool, (uint8_t *)p_conn_handle) != true) {
Edison Ai764d41f2018-09-21 15:56:36 +0800362 return NULL;
363 }
364
365 /*
Mate Toth-Pala4b5d242019-09-23 09:14:47 +0200366 * Check that the magic number is correct. This proves that the message
367 * structure contains an active message.
Edison Ai764d41f2018-09-21 15:56:36 +0800368 */
Ken Liu0bed7e02022-02-10 12:38:07 +0800369 if (p_conn_handle->magic != TFM_MSG_MAGIC) {
Edison Ai764d41f2018-09-21 15:56:36 +0800370 return NULL;
371 }
372
Mate Toth-Pala4b5d242019-09-23 09:14:47 +0200373 /* Check that the running partition owns the message */
Mingyang Sunf3d29892019-07-10 17:50:23 +0800374 partition_id = tfm_spm_partition_get_running_partition_id();
Ken Liu0bed7e02022-02-10 12:38:07 +0800375 if (partition_id != p_conn_handle->service->partition->p_ldinf->pid) {
Edison Ai764d41f2018-09-21 15:56:36 +0800376 return NULL;
377 }
378
Ken Liu0bed7e02022-02-10 12:38:07 +0800379 return p_conn_handle;
Edison Ai764d41f2018-09-21 15:56:36 +0800380}
381
Mingyang Suna09adda2022-02-16 18:11:33 +0800382void spm_fill_message(struct conn_handle_t *conn_handle,
Mingyang Sun783a59b2021-04-20 15:52:18 +0800383 struct service_t *service,
Ken Liu505b1702020-05-29 13:19:58 +0800384 psa_handle_t handle,
Summer Qin1ce712a2019-10-14 18:04:05 +0800385 int32_t type, int32_t client_id,
Edison Ai97115822019-08-01 14:22:19 +0800386 psa_invec *invec, size_t in_len,
387 psa_outvec *outvec, size_t out_len,
388 psa_outvec *caller_outvec)
389{
Edison Ai764d41f2018-09-21 15:56:36 +0800390 uint32_t i;
391
Mingyang Suna09adda2022-02-16 18:11:33 +0800392 TFM_CORE_ASSERT(conn_handle);
Ken Liuf250b8b2019-12-27 16:31:24 +0800393 TFM_CORE_ASSERT(service);
394 TFM_CORE_ASSERT(!(invec == NULL && in_len != 0));
395 TFM_CORE_ASSERT(!(outvec == NULL && out_len != 0));
396 TFM_CORE_ASSERT(in_len <= PSA_MAX_IOVEC);
397 TFM_CORE_ASSERT(out_len <= PSA_MAX_IOVEC);
398 TFM_CORE_ASSERT(in_len + out_len <= PSA_MAX_IOVEC);
Edison Ai764d41f2018-09-21 15:56:36 +0800399
Edison Ai764d41f2018-09-21 15:56:36 +0800400 /* Clear message buffer before using it */
Mingyang Suna09adda2022-02-16 18:11:33 +0800401 spm_memset(&conn_handle->msg, 0, sizeof(psa_msg_t));
Edison Ai764d41f2018-09-21 15:56:36 +0800402
Mingyang Suna09adda2022-02-16 18:11:33 +0800403 THRD_SYNC_INIT(&conn_handle->ack_evnt);
404 conn_handle->magic = TFM_MSG_MAGIC;
405 conn_handle->service = service;
406 conn_handle->p_client = GET_CURRENT_COMPONENT();
407 conn_handle->caller_outvec = caller_outvec;
408 conn_handle->msg.client_id = client_id;
Edison Ai764d41f2018-09-21 15:56:36 +0800409
410 /* Copy contents */
Mingyang Suna09adda2022-02-16 18:11:33 +0800411 conn_handle->msg.type = type;
Edison Ai764d41f2018-09-21 15:56:36 +0800412
413 for (i = 0; i < in_len; i++) {
Mingyang Suna09adda2022-02-16 18:11:33 +0800414 conn_handle->msg.in_size[i] = invec[i].len;
415 conn_handle->invec[i].base = invec[i].base;
Edison Ai764d41f2018-09-21 15:56:36 +0800416 }
417
418 for (i = 0; i < out_len; i++) {
Mingyang Suna09adda2022-02-16 18:11:33 +0800419 conn_handle->msg.out_size[i] = outvec[i].len;
420 conn_handle->outvec[i].base = outvec[i].base;
Ken Liu0bed7e02022-02-10 12:38:07 +0800421 /* Out len is used to record the wrote number, set 0 here again */
Mingyang Suna09adda2022-02-16 18:11:33 +0800422 conn_handle->outvec[i].len = 0;
Edison Ai764d41f2018-09-21 15:56:36 +0800423 }
424
Ken Liu505b1702020-05-29 13:19:58 +0800425 /* Use the user connect handle as the message handle */
Mingyang Suna09adda2022-02-16 18:11:33 +0800426 conn_handle->msg.handle = handle;
427 conn_handle->msg.rhandle = conn_handle->rhandle;
David Hu46603dd2019-12-11 18:05:16 +0800428
429 /* Set the private data of NSPE client caller in multi-core topology */
430 if (TFM_CLIENT_ID_IS_NS(client_id)) {
Mingyang Suna09adda2022-02-16 18:11:33 +0800431 tfm_rpc_set_caller_data(conn_handle, client_id);
David Hu46603dd2019-12-11 18:05:16 +0800432 }
Edison Ai764d41f2018-09-21 15:56:36 +0800433}
434
Kevin Pengeec41a82021-08-18 13:56:23 +0800435int32_t tfm_spm_partition_get_running_partition_id(void)
Edison Ai764d41f2018-09-21 15:56:36 +0800436{
Mingyang Sunae70d8d2020-06-30 15:56:05 +0800437 struct partition_t *partition;
Edison Ai764d41f2018-09-21 15:56:36 +0800438
Kevin Pengcdf3ae22022-01-19 14:53:52 +0800439 partition = GET_CURRENT_COMPONENT();
Ken Liuacd2a572021-05-12 16:19:04 +0800440 if (partition && partition->p_ldinf) {
441 return partition->p_ldinf->pid;
Kevin Peng79c2bda2020-07-24 16:31:12 +0800442 } else {
443 return INVALID_PARTITION_ID;
444 }
Edison Ai764d41f2018-09-21 15:56:36 +0800445}
446
Summer Qin43c185d2019-10-10 15:44:42 +0800447int32_t tfm_memory_check(const void *buffer, size_t len, bool ns_caller,
Summer Qineb537e52019-03-29 09:57:10 +0800448 enum tfm_memory_access_e access,
449 uint32_t privileged)
Summer Qin2bfd2a02018-09-26 17:10:41 +0800450{
Mingyang Sund1ed6732020-08-26 15:52:21 +0800451 enum tfm_hal_status_t err;
452 uint32_t attr = 0;
Summer Qin2bfd2a02018-09-26 17:10:41 +0800453
454 /* If len is zero, this indicates an empty buffer and base is ignored */
455 if (len == 0) {
Ken Liubcae38b2021-01-20 15:47:44 +0800456 return SPM_SUCCESS;
Summer Qin2bfd2a02018-09-26 17:10:41 +0800457 }
458
459 if (!buffer) {
Ken Liubcae38b2021-01-20 15:47:44 +0800460 return SPM_ERROR_BAD_PARAMETERS;
Summer Qin2bfd2a02018-09-26 17:10:41 +0800461 }
462
463 if ((uintptr_t)buffer > (UINTPTR_MAX - len)) {
Ken Liubcae38b2021-01-20 15:47:44 +0800464 return SPM_ERROR_MEMORY_CHECK;
Summer Qin2bfd2a02018-09-26 17:10:41 +0800465 }
466
Summer Qin424d4db2019-03-25 14:09:51 +0800467 if (access == TFM_MEMORY_ACCESS_RW) {
Mingyang Sund1ed6732020-08-26 15:52:21 +0800468 attr |= (TFM_HAL_ACCESS_READABLE | TFM_HAL_ACCESS_WRITABLE);
Summer Qin2bfd2a02018-09-26 17:10:41 +0800469 } else {
Mingyang Sund1ed6732020-08-26 15:52:21 +0800470 attr |= TFM_HAL_ACCESS_READABLE;
Summer Qin424d4db2019-03-25 14:09:51 +0800471 }
Mingyang Sund1ed6732020-08-26 15:52:21 +0800472
473 if (privileged == TFM_PARTITION_UNPRIVILEGED_MODE) {
474 attr |= TFM_HAL_ACCESS_UNPRIVILEGED;
475 } else {
476 attr &= ~TFM_HAL_ACCESS_UNPRIVILEGED;
477 }
478
479 if (ns_caller) {
480 attr |= TFM_HAL_ACCESS_NS;
481 }
482
483 err = tfm_hal_memory_has_access((uintptr_t)buffer, len, attr);
484
485 if (err == TFM_HAL_SUCCESS) {
Ken Liubcae38b2021-01-20 15:47:44 +0800486 return SPM_SUCCESS;
Summer Qin2bfd2a02018-09-26 17:10:41 +0800487 }
488
Ken Liubcae38b2021-01-20 15:47:44 +0800489 return SPM_ERROR_MEMORY_CHECK;
Summer Qin2bfd2a02018-09-26 17:10:41 +0800490}
491
Mingyang Sun22a3faf2021-07-09 15:32:47 +0800492bool tfm_spm_is_ns_caller(void)
493{
Kevin Pengcdf3ae22022-01-19 14:53:52 +0800494 struct partition_t *partition = GET_CURRENT_COMPONENT();
Ken Liu897e8f12022-02-10 03:21:17 +0100495
496 if (!partition) {
497 tfm_core_panic();
498 }
499
500 return (partition->p_ldinf->pid == TFM_SP_NON_SECURE_ID);
Mingyang Sun22a3faf2021-07-09 15:32:47 +0800501}
502
Kevin Peng385fda82021-08-18 10:41:19 +0800503int32_t tfm_spm_get_client_id(bool ns_caller)
504{
505 int32_t client_id;
506
507 if (ns_caller) {
508 client_id = tfm_nspm_get_current_client_id();
509 } else {
510 client_id = tfm_spm_partition_get_running_partition_id();
511 }
512
513 if (ns_caller != (client_id < 0)) {
514 /* NS client ID must be negative and Secure ID must >= 0 */
515 tfm_core_panic();
516 }
517
518 return client_id;
519}
520
Ken Liuce2692d2020-02-11 12:39:36 +0800521uint32_t tfm_spm_init(void)
Edison Ai764d41f2018-09-21 15:56:36 +0800522{
Mingyang Sunae70d8d2020-06-30 15:56:05 +0800523 struct partition_t *partition;
Mingyang Sundeae45d2021-09-06 15:31:07 +0800524 const struct partition_load_info_t *p_pldi;
525 uint32_t service_setting = 0;
Ken Liuce58bfc2021-05-12 17:54:48 +0800526
David Huf07e97d2021-02-15 22:05:40 +0800527#ifdef TFM_FIH_PROFILE_ON
528 fih_int fih_rc = FIH_FAILURE;
529#endif
Edison Ai764d41f2018-09-21 15:56:36 +0800530
531 tfm_pool_init(conn_handle_pool,
532 POOL_BUFFER_SIZE(conn_handle_pool),
Ken Liu0bed7e02022-02-10 12:38:07 +0800533 sizeof(struct conn_handle_t),
Sherry Zhang86a71c62022-01-12 18:19:02 +0800534 CONFIG_TFM_CONN_HANDLE_MAX_NUM);
Edison Ai764d41f2018-09-21 15:56:36 +0800535
Ken Liu5a28da32022-01-19 14:37:05 +0800536 UNI_LISI_INIT_NODE(PARTITION_LIST_ADDR, next);
537 UNI_LISI_INIT_NODE(&services_listhead, next);
Ken Liuea45b0d2021-05-22 17:41:25 +0800538
Sherry Zhnag482b88b2021-08-19 17:51:47 +0800539 /* Init the nonsecure context. */
Chris Brand56b4d0c2021-12-17 16:15:58 -0800540 tfm_nspm_ctx_init();
Sherry Zhnag482b88b2021-08-19 17:51:47 +0800541
Ken Liuacd2a572021-05-12 16:19:04 +0800542 while (1) {
Mingyang Sundeae45d2021-09-06 15:31:07 +0800543 partition = load_a_partition_assuredly(PARTITION_LIST_ADDR);
Shawn Shan23331062021-09-01 14:58:21 +0800544 if (partition == NO_MORE_PARTITION) {
Ken Liuacd2a572021-05-12 16:19:04 +0800545 break;
Kevin Peng79c2bda2020-07-24 16:31:12 +0800546 }
547
Mingyang Sundeae45d2021-09-06 15:31:07 +0800548 p_pldi = partition->p_ldinf;
Mingyang Sun2b352662021-04-21 11:35:43 +0800549
Mingyang Sundeae45d2021-09-06 15:31:07 +0800550 if (p_pldi->nservices) {
551 service_setting = load_services_assuredly(
552 partition,
553 &services_listhead,
554 stateless_services_ref_tbl,
555 sizeof(stateless_services_ref_tbl));
Kevin Peng27e42272021-05-24 17:58:53 +0800556 }
557
Mingyang Sundeae45d2021-09-06 15:31:07 +0800558 if (p_pldi->nirqs) {
Kevin Peng27e42272021-05-24 17:58:53 +0800559 load_irqs_assuredly(partition);
560 }
561
Mingyang Sundeae45d2021-09-06 15:31:07 +0800562 /* Bind the partition with platform. */
Ken Liuce58bfc2021-05-12 17:54:48 +0800563#if TFM_FIH_PROFILE_ON
564 FIH_CALL(tfm_hal_bind_boundaries, fih_rc, partition->p_ldinf,
Mingyang Sundeae45d2021-09-06 15:31:07 +0800565 &partition->p_boundaries);
Ken Liuce58bfc2021-05-12 17:54:48 +0800566 if (fih_not_eq(fih_rc, fih_int_encode(TFM_HAL_SUCCESS))) {
567 tfm_core_panic();
Mingyang Sun61f8fbc2021-06-04 17:49:56 +0800568 }
Ken Liu86686282021-04-27 11:11:15 +0800569#else /* TFM_FIH_PROFILE_ON */
Ken Liuce58bfc2021-05-12 17:54:48 +0800570 if (tfm_hal_bind_boundaries(partition->p_ldinf,
Mingyang Sundeae45d2021-09-06 15:31:07 +0800571 &partition->p_boundaries)
572 != TFM_HAL_SUCCESS) {
Ken Liuce58bfc2021-05-12 17:54:48 +0800573 tfm_core_panic();
Mate Toth-Pal8ac98a72019-11-21 17:30:10 +0100574 }
Ken Liuce58bfc2021-05-12 17:54:48 +0800575#endif /* TFM_FIH_PROFILE_ON */
Mate Toth-Pal8ac98a72019-11-21 17:30:10 +0100576
Mingyang Sundeae45d2021-09-06 15:31:07 +0800577 backend_instance.comp_init_assuredly(partition, service_setting);
Edison Ai764d41f2018-09-21 15:56:36 +0800578 }
579
Summer Qin596f5552022-01-27 18:04:06 +0800580#if defined(CONFIG_TFM_PARTITION_META)
581 partition_meta_indicator_pos = (uintptr_t *)hal_mem_sp_meta_start;
582#endif
583
Mingyang Sundeae45d2021-09-06 15:31:07 +0800584 return backend_instance.system_run();
Edison Ai764d41f2018-09-21 15:56:36 +0800585}
Ken Liu2d175172019-03-21 17:08:41 +0800586
Ken Liu5d73c872021-08-19 19:23:17 +0800587uint64_t do_schedule(void)
588{
Ken Liu086b32c2021-12-27 14:44:52 +0800589 AAPCS_DUAL_U32_T ctx_ctrls;
Ken Liu5d73c872021-08-19 19:23:17 +0800590 struct partition_t *p_part_curr, *p_part_next;
Kevin Pengb20b0322022-02-09 16:47:19 +0800591 struct context_ctrl_t *p_curr_ctx;
Ken Liu5d73c872021-08-19 19:23:17 +0800592 struct thread_t *pth_next = thrd_next();
Kevin Pengca59ec02021-12-09 14:35:50 +0800593 struct critical_section_t cs = CRITICAL_SECTION_STATIC_INIT;
Ken Liu5d73c872021-08-19 19:23:17 +0800594
Kevin Pengb20b0322022-02-09 16:47:19 +0800595 p_curr_ctx = (struct context_ctrl_t *)(CURRENT_THREAD->p_context_ctrl);
Ken Liu086b32c2021-12-27 14:44:52 +0800596
Kevin Pengb20b0322022-02-09 16:47:19 +0800597 AAPCS_DUAL_U32_SET(ctx_ctrls, (uint32_t)p_curr_ctx, (uint32_t)p_curr_ctx);
598
599 p_part_curr = GET_CURRENT_COMPONENT();
Mingyang Sun4f08f4d2021-09-10 17:41:28 +0800600 p_part_next = GET_THRD_OWNER(pth_next);
Ken Liu5d73c872021-08-19 19:23:17 +0800601
Mingyang Sun620c8562021-11-10 11:44:58 +0800602 if (scheduler_lock != SCHEDULER_LOCKED && pth_next != NULL &&
603 p_part_curr != p_part_next) {
Ken Liu5d73c872021-08-19 19:23:17 +0800604 /* Check if there is enough room on stack to save more context */
Kevin Pengb20b0322022-02-09 16:47:19 +0800605 if ((p_curr_ctx->sp_limit +
606 sizeof(struct tfm_additional_context_t)) > __get_PSP()) {
Ken Liu5d73c872021-08-19 19:23:17 +0800607 tfm_core_panic();
608 }
Mate Toth-Palc430b992019-05-09 21:01:14 +0200609
Kevin Pengca59ec02021-12-09 14:35:50 +0800610 CRITICAL_SECTION_ENTER(cs);
Ken Liuce58bfc2021-05-12 17:54:48 +0800611 /*
612 * If required, let the platform update boundary based on its
613 * implementation. Change privilege, MPU or other configurations.
614 */
615 if (p_part_curr->p_boundaries != p_part_next->p_boundaries) {
616 if (tfm_hal_update_boundaries(p_part_next->p_ldinf,
617 p_part_next->p_boundaries)
618 != TFM_HAL_SUCCESS) {
619 tfm_core_panic();
620 }
621 }
Feder Liang42f5b562021-09-10 17:38:36 +0800622 ARCH_FLUSH_FP_CONTEXT();
Mingyang Sun620c8562021-11-10 11:44:58 +0800623
Ken Liu086b32c2021-12-27 14:44:52 +0800624 AAPCS_DUAL_U32_SET_A1(ctx_ctrls, (uint32_t)pth_next->p_context_ctrl);
625
Mingyang Sun620c8562021-11-10 11:44:58 +0800626 CURRENT_THREAD = pth_next;
Kevin Pengca59ec02021-12-09 14:35:50 +0800627 CRITICAL_SECTION_LEAVE(cs);
Ken Liu2d175172019-03-21 17:08:41 +0800628 }
David Hufb38d562019-09-23 15:58:34 +0800629
Summer Qin596f5552022-01-27 18:04:06 +0800630#if defined(CONFIG_TFM_PARTITION_META)
631 /* Update meta indicator */
632 if (partition_meta_indicator_pos && (p_part_next->p_metadata)) {
633 *partition_meta_indicator_pos = (uintptr_t)(p_part_next->p_metadata);
634 }
635#endif
636
Ken Liu086b32c2021-12-27 14:44:52 +0800637 return AAPCS_DUAL_U32_AS_U64(ctx_ctrls);
Ken Liu2d175172019-03-21 17:08:41 +0800638}
Mingyang Sund44522a2020-01-16 16:48:37 +0800639
Mingyang Suna09adda2022-02-16 18:11:33 +0800640void update_caller_outvec_len(struct conn_handle_t *handle)
Mingyang Sund44522a2020-01-16 16:48:37 +0800641{
642 uint32_t i;
643
644 /*
645 * FixeMe: abstract these part into dedicated functions to avoid
646 * accessing thread context in psa layer
647 */
Ken Liuf39d8eb2021-10-07 12:55:33 +0800648 /*
649 * If it is a NS request via RPC, the owner of this message is not set.
650 * Or if it is a SFN message, it does not have owner thread state either.
651 */
Mingyang Suna09adda2022-02-16 18:11:33 +0800652 if ((!is_tfm_rpc_msg(handle)) && (handle->sfn_magic != TFM_MSG_MAGIC_SFN)) {
653 TFM_CORE_ASSERT(handle->ack_evnt.owner->state == THRD_STATE_BLOCK);
Mingyang Sund44522a2020-01-16 16:48:37 +0800654 }
655
656 for (i = 0; i < PSA_MAX_IOVEC; i++) {
Mingyang Suna09adda2022-02-16 18:11:33 +0800657 if (handle->msg.out_size[i] == 0) {
Mingyang Sund44522a2020-01-16 16:48:37 +0800658 continue;
659 }
660
Mingyang Suna09adda2022-02-16 18:11:33 +0800661 TFM_CORE_ASSERT(
662 handle->caller_outvec[i].base == handle->outvec[i].base);
Mingyang Sund44522a2020-01-16 16:48:37 +0800663
Mingyang Suna09adda2022-02-16 18:11:33 +0800664 handle->caller_outvec[i].len = handle->outvec[i].len;
Mingyang Sund44522a2020-01-16 16:48:37 +0800665 }
666}
667
Ken Liu5d73c872021-08-19 19:23:17 +0800668void spm_assert_signal(void *p_pt, psa_signal_t signal)
Mingyang Sund44522a2020-01-16 16:48:37 +0800669{
Ken Liu92ede9f2021-10-20 09:35:00 +0800670 struct critical_section_t cs_assert = CRITICAL_SECTION_STATIC_INIT;
Ken Liu5d73c872021-08-19 19:23:17 +0800671 struct partition_t *partition = (struct partition_t *)p_pt;
Mingyang Sund44522a2020-01-16 16:48:37 +0800672
Mingyang Sund44522a2020-01-16 16:48:37 +0800673 if (!partition) {
674 tfm_core_panic();
675 }
676
Ken Liu92ede9f2021-10-20 09:35:00 +0800677 CRITICAL_SECTION_ENTER(cs_assert);
678
Mingyang Sunaf22ffa2020-07-09 17:48:37 +0800679 partition->signals_asserted |= signal;
Mingyang Sund44522a2020-01-16 16:48:37 +0800680
Kevin Peng8dac6102021-03-09 16:44:00 +0800681 if (partition->signals_waiting & signal) {
Mingyang Sun09328bd2022-03-25 11:55:13 +0800682 backend_instance.wake_up(partition);
Kevin Peng8dac6102021-03-09 16:44:00 +0800683 }
Ken Liu92ede9f2021-10-20 09:35:00 +0800684
685 CRITICAL_SECTION_LEAVE(cs_assert);
Mingyang Sund44522a2020-01-16 16:48:37 +0800686}