Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2018-2019, Arm Limited. All rights reserved. |
| 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | * |
| 6 | */ |
Mingyang Sun | da01a97 | 2019-07-12 17:32:59 +0800 | [diff] [blame] | 7 | |
| 8 | /* All the APIs defined in this file are used for IPC model. */ |
| 9 | |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 10 | #include <inttypes.h> |
Summer Qin | 2bfd2a0 | 2018-09-26 17:10:41 +0800 | [diff] [blame] | 11 | #include <limits.h> |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 12 | #include <stdbool.h> |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 13 | #include <stdlib.h> |
Jamie Fox | cc31d40 | 2019-01-28 17:13:52 +0000 | [diff] [blame] | 14 | #include "psa/client.h" |
| 15 | #include "psa/service.h" |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 16 | #include "tfm_utils.h" |
Mingyang Sun | f3d2989 | 2019-07-10 17:50:23 +0800 | [diff] [blame] | 17 | #include "tfm_spm_hal.h" |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 18 | #include "spm_api.h" |
| 19 | #include "spm_db.h" |
David Hu | 326f397 | 2019-08-06 14:16:51 +0800 | [diff] [blame] | 20 | #include "tfm_core_mem_check.h" |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 21 | #include "tfm_internal_defines.h" |
| 22 | #include "tfm_wait.h" |
| 23 | #include "tfm_message_queue.h" |
| 24 | #include "tfm_list.h" |
| 25 | #include "tfm_pools.h" |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 26 | #include "tfm_thread.h" |
Summer Qin | 2bfd2a0 | 2018-09-26 17:10:41 +0800 | [diff] [blame] | 27 | #include "region_defs.h" |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 28 | #include "tfm_nspm.h" |
Edison Ai | 807fedb | 2019-03-07 11:22:03 +0800 | [diff] [blame] | 29 | #include "tfm_memory_utils.h" |
Mingyang Sun | 94b1b41 | 2019-09-20 15:11:14 +0800 | [diff] [blame] | 30 | #include "tfm_core_utils.h" |
David Hu | fb38d56 | 2019-09-23 15:58:34 +0800 | [diff] [blame] | 31 | #include "tfm_rpc.h" |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 32 | |
Summer Qin | d99509f | 2019-08-02 17:36:58 +0800 | [diff] [blame] | 33 | #include "secure_fw/services/tfm_service_list.inc" |
| 34 | |
| 35 | /* Extern service variable */ |
| 36 | extern struct tfm_spm_service_t service[]; |
Summer Qin | e578c5b | 2019-08-16 16:42:16 +0800 | [diff] [blame] | 37 | extern const struct tfm_spm_service_db_t service_db[]; |
Summer Qin | d99509f | 2019-08-02 17:36:58 +0800 | [diff] [blame] | 38 | |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 39 | /* Extern SPM variable */ |
| 40 | extern struct spm_partition_db_t g_spm_partition_db; |
| 41 | |
Mate Toth-Pal | c430b99 | 2019-05-09 21:01:14 +0200 | [diff] [blame] | 42 | /* Extern secure lock variable */ |
| 43 | extern int32_t tfm_secure_lock; |
Mingyang Sun | f3d2989 | 2019-07-10 17:50:23 +0800 | [diff] [blame] | 44 | |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 45 | /* Pools */ |
| 46 | TFM_POOL_DECLARE(conn_handle_pool, sizeof(struct tfm_conn_handle_t), |
| 47 | TFM_CONN_HANDLE_MAX_NUM); |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 48 | |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 49 | /********************** SPM functions for handler mode ***********************/ |
| 50 | |
| 51 | /* Service handle management functions */ |
| 52 | psa_handle_t tfm_spm_create_conn_handle(struct tfm_spm_service_t *service) |
| 53 | { |
Edison Ai | 9cc2624 | 2019-08-06 11:28:04 +0800 | [diff] [blame] | 54 | struct tfm_conn_handle_t *p_handle; |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 55 | |
| 56 | TFM_ASSERT(service); |
| 57 | |
| 58 | /* Get buffer for handle list structure from handle pool */ |
Edison Ai | 9cc2624 | 2019-08-06 11:28:04 +0800 | [diff] [blame] | 59 | p_handle = (struct tfm_conn_handle_t *)tfm_pool_alloc(conn_handle_pool); |
| 60 | if (!p_handle) { |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 61 | return PSA_NULL_HANDLE; |
| 62 | } |
| 63 | |
Edison Ai | 9cc2624 | 2019-08-06 11:28:04 +0800 | [diff] [blame] | 64 | p_handle->service = service; |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 65 | |
| 66 | /* Add handle node to list for next psa functions */ |
Edison Ai | 9cc2624 | 2019-08-06 11:28:04 +0800 | [diff] [blame] | 67 | tfm_list_add_tail(&service->handle_list, &p_handle->list); |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 68 | |
Edison Ai | 9cc2624 | 2019-08-06 11:28:04 +0800 | [diff] [blame] | 69 | return (psa_handle_t)p_handle; |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 70 | } |
| 71 | |
| 72 | static struct tfm_conn_handle_t * |
Mingyang Sun | 5e13aa7 | 2019-07-10 10:30:16 +0800 | [diff] [blame] | 73 | tfm_spm_find_conn_handle_node(struct tfm_spm_service_t *service, |
| 74 | psa_handle_t conn_handle) |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 75 | { |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 76 | TFM_ASSERT(service); |
| 77 | |
Edison Ai | 9cc2624 | 2019-08-06 11:28:04 +0800 | [diff] [blame] | 78 | return (struct tfm_conn_handle_t *)conn_handle; |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | int32_t tfm_spm_free_conn_handle(struct tfm_spm_service_t *service, |
| 82 | psa_handle_t conn_handle) |
| 83 | { |
Edison Ai | 9cc2624 | 2019-08-06 11:28:04 +0800 | [diff] [blame] | 84 | struct tfm_conn_handle_t *p_handle; |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 85 | |
| 86 | TFM_ASSERT(service); |
| 87 | |
| 88 | /* There are many handles for each RoT Service */ |
Edison Ai | 9cc2624 | 2019-08-06 11:28:04 +0800 | [diff] [blame] | 89 | p_handle = tfm_spm_find_conn_handle_node(service, conn_handle); |
| 90 | if (!p_handle) { |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 91 | tfm_panic(); |
| 92 | } |
| 93 | |
Mate Toth-Pal | a4b5d24 | 2019-09-23 09:14:47 +0200 | [diff] [blame] | 94 | /* Clear magic as the handler is not used anymore */ |
| 95 | p_handle->internal_msg.magic = 0; |
| 96 | |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 97 | /* Remove node from handle list */ |
Edison Ai | 9cc2624 | 2019-08-06 11:28:04 +0800 | [diff] [blame] | 98 | tfm_list_del_node(&p_handle->list); |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 99 | |
| 100 | /* Back handle buffer to pool */ |
Edison Ai | 9cc2624 | 2019-08-06 11:28:04 +0800 | [diff] [blame] | 101 | tfm_pool_free(p_handle); |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 102 | return IPC_SUCCESS; |
| 103 | } |
| 104 | |
| 105 | int32_t tfm_spm_set_rhandle(struct tfm_spm_service_t *service, |
| 106 | psa_handle_t conn_handle, |
| 107 | void *rhandle) |
| 108 | { |
Edison Ai | 9cc2624 | 2019-08-06 11:28:04 +0800 | [diff] [blame] | 109 | struct tfm_conn_handle_t *p_handle; |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 110 | |
| 111 | TFM_ASSERT(service); |
| 112 | /* Set reverse handle value only be allowed for a connected handle */ |
| 113 | TFM_ASSERT(conn_handle != PSA_NULL_HANDLE); |
| 114 | |
| 115 | /* There are many handles for each RoT Service */ |
Edison Ai | 9cc2624 | 2019-08-06 11:28:04 +0800 | [diff] [blame] | 116 | p_handle = tfm_spm_find_conn_handle_node(service, conn_handle); |
| 117 | if (!p_handle) { |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 118 | tfm_panic(); |
| 119 | } |
| 120 | |
Edison Ai | 9cc2624 | 2019-08-06 11:28:04 +0800 | [diff] [blame] | 121 | p_handle->rhandle = rhandle; |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 122 | return IPC_SUCCESS; |
| 123 | } |
| 124 | |
| 125 | void *tfm_spm_get_rhandle(struct tfm_spm_service_t *service, |
| 126 | psa_handle_t conn_handle) |
| 127 | { |
Edison Ai | 9cc2624 | 2019-08-06 11:28:04 +0800 | [diff] [blame] | 128 | struct tfm_conn_handle_t *p_handle; |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 129 | |
| 130 | TFM_ASSERT(service); |
| 131 | /* Get reverse handle value only be allowed for a connected handle */ |
| 132 | TFM_ASSERT(conn_handle != PSA_NULL_HANDLE); |
| 133 | |
| 134 | /* There are many handles for each RoT Service */ |
Edison Ai | 9cc2624 | 2019-08-06 11:28:04 +0800 | [diff] [blame] | 135 | p_handle = tfm_spm_find_conn_handle_node(service, conn_handle); |
| 136 | if (!p_handle) { |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 137 | tfm_panic(); |
| 138 | } |
| 139 | |
Edison Ai | 9cc2624 | 2019-08-06 11:28:04 +0800 | [diff] [blame] | 140 | return p_handle->rhandle; |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 141 | } |
| 142 | |
| 143 | /* Partition management functions */ |
| 144 | struct tfm_spm_service_t * |
Mingyang Sun | f3d2989 | 2019-07-10 17:50:23 +0800 | [diff] [blame] | 145 | tfm_spm_get_service_by_signal(struct spm_partition_desc_t *partition, |
| 146 | psa_signal_t signal) |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 147 | { |
| 148 | struct tfm_list_node_t *node, *head; |
| 149 | struct tfm_spm_service_t *service; |
| 150 | |
| 151 | TFM_ASSERT(partition); |
| 152 | |
Mingyang Sun | 5e13aa7 | 2019-07-10 10:30:16 +0800 | [diff] [blame] | 153 | if (tfm_list_is_empty(&partition->runtime_data.service_list)) { |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 154 | tfm_panic(); |
| 155 | } |
| 156 | |
Mingyang Sun | 5e13aa7 | 2019-07-10 10:30:16 +0800 | [diff] [blame] | 157 | head = &partition->runtime_data.service_list; |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 158 | TFM_LIST_FOR_EACH(node, head) { |
| 159 | service = TFM_GET_CONTAINER_PTR(node, struct tfm_spm_service_t, list); |
Summer Qin | e578c5b | 2019-08-16 16:42:16 +0800 | [diff] [blame] | 160 | if (service->service_db->signal == signal) { |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 161 | return service; |
| 162 | } |
| 163 | } |
| 164 | return NULL; |
| 165 | } |
| 166 | |
| 167 | struct tfm_spm_service_t *tfm_spm_get_service_by_sid(uint32_t sid) |
| 168 | { |
| 169 | uint32_t i; |
| 170 | struct tfm_list_node_t *node, *head; |
| 171 | struct tfm_spm_service_t *service; |
Mingyang Sun | 5e13aa7 | 2019-07-10 10:30:16 +0800 | [diff] [blame] | 172 | struct spm_partition_desc_t *partition; |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 173 | |
Mate Toth-Pal | 3ad2e3e | 2019-07-11 21:43:37 +0200 | [diff] [blame] | 174 | for (i = 0; i < g_spm_partition_db.partition_count; i++) { |
Mingyang Sun | 5e13aa7 | 2019-07-10 10:30:16 +0800 | [diff] [blame] | 175 | partition = &g_spm_partition_db.partitions[i]; |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 176 | /* Skip partition without IPC flag */ |
Mingyang Sun | f3d2989 | 2019-07-10 17:50:23 +0800 | [diff] [blame] | 177 | if ((tfm_spm_partition_get_flags(i) & SPM_PART_FLAG_IPC) == 0) { |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 178 | continue; |
| 179 | } |
| 180 | |
Mingyang Sun | 5e13aa7 | 2019-07-10 10:30:16 +0800 | [diff] [blame] | 181 | if (tfm_list_is_empty(&partition->runtime_data.service_list)) { |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 182 | continue; |
| 183 | } |
| 184 | |
Mingyang Sun | 5e13aa7 | 2019-07-10 10:30:16 +0800 | [diff] [blame] | 185 | head = &partition->runtime_data.service_list; |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 186 | TFM_LIST_FOR_EACH(node, head) { |
| 187 | service = TFM_GET_CONTAINER_PTR(node, struct tfm_spm_service_t, |
| 188 | list); |
Summer Qin | e578c5b | 2019-08-16 16:42:16 +0800 | [diff] [blame] | 189 | if (service->service_db->sid == sid) { |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 190 | return service; |
| 191 | } |
| 192 | } |
| 193 | } |
| 194 | return NULL; |
| 195 | } |
| 196 | |
| 197 | struct tfm_spm_service_t * |
| 198 | tfm_spm_get_service_by_handle(psa_handle_t conn_handle) |
| 199 | { |
Edison Ai | 9cc2624 | 2019-08-06 11:28:04 +0800 | [diff] [blame] | 200 | return ((struct tfm_conn_handle_t *)conn_handle)->service; |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 201 | } |
| 202 | |
Mingyang Sun | 5e13aa7 | 2019-07-10 10:30:16 +0800 | [diff] [blame] | 203 | struct spm_partition_desc_t *tfm_spm_get_partition_by_id(int32_t partition_id) |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 204 | { |
Mingyang Sun | 5e13aa7 | 2019-07-10 10:30:16 +0800 | [diff] [blame] | 205 | uint32_t idx = get_partition_idx(partition_id); |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 206 | |
Mingyang Sun | 5e13aa7 | 2019-07-10 10:30:16 +0800 | [diff] [blame] | 207 | if (idx != SPM_INVALID_PARTITION_IDX) { |
| 208 | return &(g_spm_partition_db.partitions[idx]); |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 209 | } |
| 210 | return NULL; |
| 211 | } |
| 212 | |
Mingyang Sun | 5e13aa7 | 2019-07-10 10:30:16 +0800 | [diff] [blame] | 213 | struct spm_partition_desc_t *tfm_spm_get_running_partition(void) |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 214 | { |
| 215 | uint32_t spid; |
| 216 | |
Mingyang Sun | f3d2989 | 2019-07-10 17:50:23 +0800 | [diff] [blame] | 217 | spid = tfm_spm_partition_get_running_partition_id(); |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 218 | |
| 219 | return tfm_spm_get_partition_by_id(spid); |
| 220 | } |
| 221 | |
| 222 | int32_t tfm_spm_check_client_version(struct tfm_spm_service_t *service, |
Jaykumar Pitambarbhai Patel | 3a98602 | 2019-10-08 17:37:15 +0530 | [diff] [blame^] | 223 | uint32_t version) |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 224 | { |
| 225 | TFM_ASSERT(service); |
| 226 | |
Jaykumar Pitambarbhai Patel | 3a98602 | 2019-10-08 17:37:15 +0530 | [diff] [blame^] | 227 | switch (service->service_db->version_policy) { |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 228 | case TFM_VERSION_POLICY_RELAXED: |
Jaykumar Pitambarbhai Patel | 3a98602 | 2019-10-08 17:37:15 +0530 | [diff] [blame^] | 229 | if (version > service->service_db->version) { |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 230 | return IPC_ERROR_VERSION; |
| 231 | } |
| 232 | break; |
| 233 | case TFM_VERSION_POLICY_STRICT: |
Jaykumar Pitambarbhai Patel | 3a98602 | 2019-10-08 17:37:15 +0530 | [diff] [blame^] | 234 | if (version != service->service_db->version) { |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 235 | return IPC_ERROR_VERSION; |
| 236 | } |
| 237 | break; |
| 238 | default: |
| 239 | return IPC_ERROR_VERSION; |
| 240 | } |
| 241 | return IPC_SUCCESS; |
| 242 | } |
| 243 | |
| 244 | /* Message functions */ |
| 245 | struct tfm_msg_body_t *tfm_spm_get_msg_from_handle(psa_handle_t msg_handle) |
| 246 | { |
| 247 | /* |
Mate Toth-Pal | a4b5d24 | 2019-09-23 09:14:47 +0200 | [diff] [blame] | 248 | * The message handler passed by the caller is considered invalid in the |
| 249 | * following cases: |
| 250 | * 1. Not a valid message handle. (The address of a message is not the |
| 251 | * address of a possible handle from the pool |
| 252 | * 2. Handle not belongs to the caller partition (The handle is either |
| 253 | * unused, or owned by anither partition) |
| 254 | * Check the conditions above |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 255 | */ |
Mate Toth-Pal | a4b5d24 | 2019-09-23 09:14:47 +0200 | [diff] [blame] | 256 | struct tfm_conn_handle_t *connection_handle_address; |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 257 | struct tfm_msg_body_t *msg; |
| 258 | uint32_t partition_id; |
| 259 | |
| 260 | msg = (struct tfm_msg_body_t *)msg_handle; |
Mate Toth-Pal | a4b5d24 | 2019-09-23 09:14:47 +0200 | [diff] [blame] | 261 | |
| 262 | connection_handle_address = |
| 263 | TFM_GET_CONTAINER_PTR(msg, struct tfm_conn_handle_t, internal_msg); |
| 264 | |
| 265 | if (is_valid_chunk_data_in_pool( |
| 266 | conn_handle_pool, (uint8_t *)connection_handle_address) != 1) { |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 267 | return NULL; |
| 268 | } |
| 269 | |
| 270 | /* |
Mate Toth-Pal | a4b5d24 | 2019-09-23 09:14:47 +0200 | [diff] [blame] | 271 | * Check that the magic number is correct. This proves that the message |
| 272 | * structure contains an active message. |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 273 | */ |
| 274 | if (msg->magic != TFM_MSG_MAGIC) { |
| 275 | return NULL; |
| 276 | } |
| 277 | |
Mate Toth-Pal | a4b5d24 | 2019-09-23 09:14:47 +0200 | [diff] [blame] | 278 | /* Check that the running partition owns the message */ |
Mingyang Sun | f3d2989 | 2019-07-10 17:50:23 +0800 | [diff] [blame] | 279 | partition_id = tfm_spm_partition_get_running_partition_id(); |
Summer Qin | 423dbef | 2019-08-22 15:59:35 +0800 | [diff] [blame] | 280 | if (partition_id != msg->service->partition->static_data->partition_id) { |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 281 | return NULL; |
| 282 | } |
| 283 | |
Mate Toth-Pal | a4b5d24 | 2019-09-23 09:14:47 +0200 | [diff] [blame] | 284 | /* |
| 285 | * FixMe: For condition 1 it should be checked whether the message belongs |
| 286 | * to the service. Skipping this check isn't a security risk as even if the |
| 287 | * message belongs to another service, the handle belongs to the calling |
| 288 | * partition. |
| 289 | */ |
| 290 | |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 291 | return msg; |
| 292 | } |
| 293 | |
Edison Ai | 9711582 | 2019-08-01 14:22:19 +0800 | [diff] [blame] | 294 | struct tfm_msg_body_t * |
| 295 | tfm_spm_get_msg_buffer_from_conn_handle(psa_handle_t conn_handle) |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 296 | { |
Edison Ai | 9711582 | 2019-08-01 14:22:19 +0800 | [diff] [blame] | 297 | TFM_ASSERT(conn_handle != PSA_NULL_HANDLE); |
| 298 | |
| 299 | return &(((struct tfm_conn_handle_t *)conn_handle)->internal_msg); |
| 300 | } |
| 301 | |
| 302 | void tfm_spm_fill_msg(struct tfm_msg_body_t *msg, |
| 303 | struct tfm_spm_service_t *service, |
| 304 | psa_handle_t handle, |
| 305 | int32_t type, int32_t ns_caller, |
| 306 | psa_invec *invec, size_t in_len, |
| 307 | psa_outvec *outvec, size_t out_len, |
| 308 | psa_outvec *caller_outvec) |
| 309 | { |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 310 | uint32_t i; |
| 311 | |
Edison Ai | 9711582 | 2019-08-01 14:22:19 +0800 | [diff] [blame] | 312 | TFM_ASSERT(msg); |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 313 | TFM_ASSERT(service); |
| 314 | TFM_ASSERT(!(invec == NULL && in_len != 0)); |
| 315 | TFM_ASSERT(!(outvec == NULL && out_len != 0)); |
| 316 | TFM_ASSERT(in_len <= PSA_MAX_IOVEC); |
| 317 | TFM_ASSERT(out_len <= PSA_MAX_IOVEC); |
| 318 | TFM_ASSERT(in_len + out_len <= PSA_MAX_IOVEC); |
| 319 | |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 320 | /* Clear message buffer before using it */ |
Mingyang Sun | 94b1b41 | 2019-09-20 15:11:14 +0800 | [diff] [blame] | 321 | tfm_core_util_memset(msg, 0, sizeof(struct tfm_msg_body_t)); |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 322 | |
Ken Liu | 35f8939 | 2019-03-14 14:51:05 +0800 | [diff] [blame] | 323 | tfm_event_init(&msg->ack_evnt); |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 324 | msg->magic = TFM_MSG_MAGIC; |
| 325 | msg->service = service; |
| 326 | msg->handle = handle; |
| 327 | msg->caller_outvec = caller_outvec; |
| 328 | /* Get current partition id */ |
| 329 | if (ns_caller) { |
| 330 | msg->msg.client_id = tfm_nspm_get_current_client_id(); |
| 331 | } else { |
Mingyang Sun | f3d2989 | 2019-07-10 17:50:23 +0800 | [diff] [blame] | 332 | msg->msg.client_id = tfm_spm_partition_get_running_partition_id(); |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 333 | } |
| 334 | |
| 335 | /* Copy contents */ |
| 336 | msg->msg.type = type; |
| 337 | |
| 338 | for (i = 0; i < in_len; i++) { |
| 339 | msg->msg.in_size[i] = invec[i].len; |
| 340 | msg->invec[i].base = invec[i].base; |
| 341 | } |
| 342 | |
| 343 | for (i = 0; i < out_len; i++) { |
| 344 | msg->msg.out_size[i] = outvec[i].len; |
| 345 | msg->outvec[i].base = outvec[i].base; |
| 346 | /* Out len is used to record the writed number, set 0 here again */ |
| 347 | msg->outvec[i].len = 0; |
| 348 | } |
| 349 | |
| 350 | /* Use message address as handle */ |
| 351 | msg->msg.handle = (psa_handle_t)msg; |
| 352 | |
| 353 | /* For connected handle, set rhandle to every message */ |
| 354 | if (handle != PSA_NULL_HANDLE) { |
| 355 | msg->msg.rhandle = tfm_spm_get_rhandle(service, handle); |
| 356 | } |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 357 | } |
| 358 | |
| 359 | int32_t tfm_spm_send_event(struct tfm_spm_service_t *service, |
| 360 | struct tfm_msg_body_t *msg) |
| 361 | { |
Mingyang Sun | 5e13aa7 | 2019-07-10 10:30:16 +0800 | [diff] [blame] | 362 | struct spm_partition_runtime_data_t *p_runtime_data = |
| 363 | &service->partition->runtime_data; |
| 364 | |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 365 | TFM_ASSERT(service); |
| 366 | TFM_ASSERT(msg); |
| 367 | |
| 368 | /* Enqueue message to service message queue */ |
| 369 | if (tfm_msg_enqueue(&service->msg_queue, msg) != IPC_SUCCESS) { |
| 370 | return IPC_ERROR_GENERIC; |
| 371 | } |
| 372 | |
| 373 | /* Messages put. Update signals */ |
Summer Qin | e578c5b | 2019-08-16 16:42:16 +0800 | [diff] [blame] | 374 | p_runtime_data->signals |= service->service_db->signal; |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 375 | |
Mingyang Sun | 5e13aa7 | 2019-07-10 10:30:16 +0800 | [diff] [blame] | 376 | tfm_event_wake(&p_runtime_data->signal_evnt, (p_runtime_data->signals & |
| 377 | p_runtime_data->signal_mask)); |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 378 | |
David Hu | fb38d56 | 2019-09-23 15:58:34 +0800 | [diff] [blame] | 379 | /* |
| 380 | * If it is a NS request via RPC, it is unnecessary to block current |
| 381 | * thread. |
| 382 | */ |
| 383 | if (!is_tfm_rpc_msg(msg)) { |
| 384 | tfm_event_wait(&msg->ack_evnt); |
| 385 | } |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 386 | |
| 387 | return IPC_SUCCESS; |
| 388 | } |
| 389 | |
Edison Ai | 7aff9e8 | 2019-07-11 14:56:46 +0800 | [diff] [blame] | 390 | uint32_t tfm_spm_partition_get_stack_bottom(uint32_t partition_idx) |
| 391 | { |
| 392 | return g_spm_partition_db.partitions[partition_idx]. |
Summer Qin | 423dbef | 2019-08-22 15:59:35 +0800 | [diff] [blame] | 393 | memory_data->stack_bottom; |
Edison Ai | 7aff9e8 | 2019-07-11 14:56:46 +0800 | [diff] [blame] | 394 | } |
| 395 | |
| 396 | uint32_t tfm_spm_partition_get_stack_top(uint32_t partition_idx) |
| 397 | { |
Summer Qin | 423dbef | 2019-08-22 15:59:35 +0800 | [diff] [blame] | 398 | return g_spm_partition_db.partitions[partition_idx].memory_data->stack_top; |
Edison Ai | 7aff9e8 | 2019-07-11 14:56:46 +0800 | [diff] [blame] | 399 | } |
| 400 | |
Mingyang Sun | f3d2989 | 2019-07-10 17:50:23 +0800 | [diff] [blame] | 401 | uint32_t tfm_spm_partition_get_running_partition_id(void) |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 402 | { |
| 403 | struct tfm_thrd_ctx *pth = tfm_thrd_curr_thread(); |
| 404 | struct spm_partition_desc_t *partition; |
Summer Qin | b5da9cc | 2019-08-26 15:19:45 +0800 | [diff] [blame] | 405 | struct spm_partition_runtime_data_t *r_data; |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 406 | |
Summer Qin | b5da9cc | 2019-08-26 15:19:45 +0800 | [diff] [blame] | 407 | r_data = TFM_GET_CONTAINER_PTR(pth, struct spm_partition_runtime_data_t, |
| 408 | sp_thrd); |
| 409 | partition = TFM_GET_CONTAINER_PTR(r_data, struct spm_partition_desc_t, |
| 410 | runtime_data); |
Summer Qin | 423dbef | 2019-08-22 15:59:35 +0800 | [diff] [blame] | 411 | return partition->static_data->partition_id; |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 412 | } |
| 413 | |
| 414 | static struct tfm_thrd_ctx * |
Mingyang Sun | f3d2989 | 2019-07-10 17:50:23 +0800 | [diff] [blame] | 415 | tfm_spm_partition_get_thread_info(uint32_t partition_idx) |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 416 | { |
Summer Qin | b5da9cc | 2019-08-26 15:19:45 +0800 | [diff] [blame] | 417 | return &g_spm_partition_db.partitions[partition_idx].runtime_data.sp_thrd; |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 418 | } |
| 419 | |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 420 | static tfm_thrd_func_t |
Mingyang Sun | f3d2989 | 2019-07-10 17:50:23 +0800 | [diff] [blame] | 421 | tfm_spm_partition_get_init_func(uint32_t partition_idx) |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 422 | { |
| 423 | return (tfm_thrd_func_t)(g_spm_partition_db.partitions[partition_idx]. |
Summer Qin | 423dbef | 2019-08-22 15:59:35 +0800 | [diff] [blame] | 424 | static_data->partition_init); |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 425 | } |
| 426 | |
Mingyang Sun | f3d2989 | 2019-07-10 17:50:23 +0800 | [diff] [blame] | 427 | static uint32_t tfm_spm_partition_get_priority(uint32_t partition_idx) |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 428 | { |
Summer Qin | 423dbef | 2019-08-22 15:59:35 +0800 | [diff] [blame] | 429 | return g_spm_partition_db.partitions[partition_idx].static_data-> |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 430 | partition_priority; |
| 431 | } |
| 432 | |
David Hu | cb05d97 | 2019-08-06 18:10:11 +0800 | [diff] [blame] | 433 | int32_t tfm_memory_check(const void *buffer, size_t len, int32_t ns_caller, |
Summer Qin | eb537e5 | 2019-03-29 09:57:10 +0800 | [diff] [blame] | 434 | enum tfm_memory_access_e access, |
| 435 | uint32_t privileged) |
Summer Qin | 2bfd2a0 | 2018-09-26 17:10:41 +0800 | [diff] [blame] | 436 | { |
Hugues de Valon | 9957856 | 2019-06-18 16:08:51 +0100 | [diff] [blame] | 437 | enum tfm_status_e err; |
Summer Qin | 2bfd2a0 | 2018-09-26 17:10:41 +0800 | [diff] [blame] | 438 | |
| 439 | /* If len is zero, this indicates an empty buffer and base is ignored */ |
| 440 | if (len == 0) { |
| 441 | return IPC_SUCCESS; |
| 442 | } |
| 443 | |
| 444 | if (!buffer) { |
| 445 | return IPC_ERROR_BAD_PARAMETERS; |
| 446 | } |
| 447 | |
| 448 | if ((uintptr_t)buffer > (UINTPTR_MAX - len)) { |
| 449 | return IPC_ERROR_MEMORY_CHECK; |
| 450 | } |
| 451 | |
Summer Qin | 424d4db | 2019-03-25 14:09:51 +0800 | [diff] [blame] | 452 | if (access == TFM_MEMORY_ACCESS_RW) { |
Summer Qin | eb537e5 | 2019-03-29 09:57:10 +0800 | [diff] [blame] | 453 | err = tfm_core_has_write_access_to_region(buffer, len, ns_caller, |
| 454 | privileged); |
Summer Qin | 2bfd2a0 | 2018-09-26 17:10:41 +0800 | [diff] [blame] | 455 | } else { |
Summer Qin | eb537e5 | 2019-03-29 09:57:10 +0800 | [diff] [blame] | 456 | err = tfm_core_has_read_access_to_region(buffer, len, ns_caller, |
| 457 | privileged); |
Summer Qin | 424d4db | 2019-03-25 14:09:51 +0800 | [diff] [blame] | 458 | } |
Summer Qin | 0fc3f59 | 2019-04-11 16:00:10 +0800 | [diff] [blame] | 459 | if (err == TFM_SUCCESS) { |
Summer Qin | 424d4db | 2019-03-25 14:09:51 +0800 | [diff] [blame] | 460 | return IPC_SUCCESS; |
Summer Qin | 2bfd2a0 | 2018-09-26 17:10:41 +0800 | [diff] [blame] | 461 | } |
| 462 | |
| 463 | return IPC_ERROR_MEMORY_CHECK; |
| 464 | } |
| 465 | |
Summer Qin | 75f0d75 | 2019-08-27 14:38:20 +0800 | [diff] [blame] | 466 | uint32_t tfm_spm_partition_get_privileged_mode(uint32_t partition_flags) |
Summer Qin | eb537e5 | 2019-03-29 09:57:10 +0800 | [diff] [blame] | 467 | { |
Summer Qin | 75f0d75 | 2019-08-27 14:38:20 +0800 | [diff] [blame] | 468 | if (partition_flags & SPM_PART_FLAG_PSA_ROT) { |
Summer Qin | eb537e5 | 2019-03-29 09:57:10 +0800 | [diff] [blame] | 469 | return TFM_PARTITION_PRIVILEGED_MODE; |
| 470 | } else { |
| 471 | return TFM_PARTITION_UNPRIVILEGED_MODE; |
| 472 | } |
| 473 | } |
| 474 | |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 475 | /********************** SPM functions for thread mode ************************/ |
| 476 | |
| 477 | void tfm_spm_init(void) |
| 478 | { |
| 479 | uint32_t i, num; |
Mingyang Sun | 5e13aa7 | 2019-07-10 10:30:16 +0800 | [diff] [blame] | 480 | struct spm_partition_desc_t *partition; |
Ken Liu | 483f5da | 2019-04-24 10:45:21 +0800 | [diff] [blame] | 481 | struct tfm_thrd_ctx *pth, this_thrd; |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 482 | |
| 483 | tfm_pool_init(conn_handle_pool, |
| 484 | POOL_BUFFER_SIZE(conn_handle_pool), |
| 485 | sizeof(struct tfm_conn_handle_t), |
| 486 | TFM_CONN_HANDLE_MAX_NUM); |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 487 | |
| 488 | /* Init partition first for it will be used when init service */ |
Mate Toth-Pal | 3ad2e3e | 2019-07-11 21:43:37 +0200 | [diff] [blame] | 489 | for (i = 0; i < g_spm_partition_db.partition_count; i++) { |
Mingyang Sun | 5e13aa7 | 2019-07-10 10:30:16 +0800 | [diff] [blame] | 490 | partition = &g_spm_partition_db.partitions[i]; |
| 491 | tfm_spm_hal_configure_default_isolation(partition->platform_data); |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 492 | if ((tfm_spm_partition_get_flags(i) & SPM_PART_FLAG_IPC) == 0) { |
| 493 | continue; |
| 494 | } |
Ken Liu | 35f8939 | 2019-03-14 14:51:05 +0800 | [diff] [blame] | 495 | |
Mingyang Sun | 5e13aa7 | 2019-07-10 10:30:16 +0800 | [diff] [blame] | 496 | tfm_event_init(&partition->runtime_data.signal_evnt); |
| 497 | tfm_list_init(&partition->runtime_data.service_list); |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 498 | |
Mingyang Sun | f3d2989 | 2019-07-10 17:50:23 +0800 | [diff] [blame] | 499 | pth = tfm_spm_partition_get_thread_info(i); |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 500 | if (!pth) { |
| 501 | tfm_panic(); |
| 502 | } |
| 503 | |
| 504 | tfm_thrd_init(pth, |
Mingyang Sun | f3d2989 | 2019-07-10 17:50:23 +0800 | [diff] [blame] | 505 | tfm_spm_partition_get_init_func(i), |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 506 | NULL, |
Ken Liu | 5a2b905 | 2019-08-15 19:03:29 +0800 | [diff] [blame] | 507 | (uintptr_t)tfm_spm_partition_get_stack_top(i), |
| 508 | (uintptr_t)tfm_spm_partition_get_stack_bottom(i)); |
Edison Ai | 788bae2 | 2019-02-18 17:38:59 +0800 | [diff] [blame] | 509 | |
Mingyang Sun | f3d2989 | 2019-07-10 17:50:23 +0800 | [diff] [blame] | 510 | pth->prior = tfm_spm_partition_get_priority(i); |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 511 | |
| 512 | /* Kick off */ |
| 513 | if (tfm_thrd_start(pth) != THRD_SUCCESS) { |
| 514 | tfm_panic(); |
| 515 | } |
| 516 | } |
| 517 | |
| 518 | /* Init Service */ |
Summer Qin | d99509f | 2019-08-02 17:36:58 +0800 | [diff] [blame] | 519 | num = sizeof(service) / sizeof(struct tfm_spm_service_t); |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 520 | for (i = 0; i < num; i++) { |
Summer Qin | e578c5b | 2019-08-16 16:42:16 +0800 | [diff] [blame] | 521 | service[i].service_db = &service_db[i]; |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 522 | partition = |
Summer Qin | e578c5b | 2019-08-16 16:42:16 +0800 | [diff] [blame] | 523 | tfm_spm_get_partition_by_id(service[i].service_db->partition_id); |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 524 | if (!partition) { |
| 525 | tfm_panic(); |
| 526 | } |
Summer Qin | d99509f | 2019-08-02 17:36:58 +0800 | [diff] [blame] | 527 | service[i].partition = partition; |
| 528 | tfm_list_init(&service[i].handle_list); |
Mingyang Sun | 5e13aa7 | 2019-07-10 10:30:16 +0800 | [diff] [blame] | 529 | tfm_list_add_tail(&partition->runtime_data.service_list, |
Summer Qin | d99509f | 2019-08-02 17:36:58 +0800 | [diff] [blame] | 530 | &service[i].list); |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 531 | } |
| 532 | |
Ken Liu | 483f5da | 2019-04-24 10:45:21 +0800 | [diff] [blame] | 533 | /* |
| 534 | * All threads initialized, start the scheduler. |
| 535 | * |
| 536 | * NOTE: |
| 537 | * Here is the booting privileged thread mode, and will never |
| 538 | * return to this place after scheduler is started. The start |
| 539 | * function has to save current runtime context to act as a |
| 540 | * 'current thread' to avoid repeating NULL 'current thread' |
| 541 | * checking while context switching. This saved context is worthy |
| 542 | * of being saved somewhere if there are potential usage purpose. |
| 543 | * Let's save this context in a local variable 'this_thrd' at |
| 544 | * current since there is no usage for it. |
Mate Toth-Pal | c430b99 | 2019-05-09 21:01:14 +0200 | [diff] [blame] | 545 | * Also set tfm_nspm_thread_entry as pfn for this thread to |
| 546 | * use in detecting NS/S thread scheduling changes. |
Ken Liu | 483f5da | 2019-04-24 10:45:21 +0800 | [diff] [blame] | 547 | */ |
Mate Toth-Pal | c430b99 | 2019-05-09 21:01:14 +0200 | [diff] [blame] | 548 | this_thrd.pfn = (tfm_thrd_func_t)tfm_nspm_thread_entry; |
Ken Liu | 483f5da | 2019-04-24 10:45:21 +0800 | [diff] [blame] | 549 | tfm_thrd_start_scheduler(&this_thrd); |
Edison Ai | 764d41f | 2018-09-21 15:56:36 +0800 | [diff] [blame] | 550 | } |
Ken Liu | 2d17517 | 2019-03-21 17:08:41 +0800 | [diff] [blame] | 551 | |
| 552 | void tfm_pendsv_do_schedule(struct tfm_state_context_ext *ctxb) |
| 553 | { |
| 554 | #if TFM_LVL == 2 |
| 555 | struct spm_partition_desc_t *p_next_partition; |
Summer Qin | b5da9cc | 2019-08-26 15:19:45 +0800 | [diff] [blame] | 556 | struct spm_partition_runtime_data_t *r_data; |
Ken Liu | 2d17517 | 2019-03-21 17:08:41 +0800 | [diff] [blame] | 557 | uint32_t is_privileged; |
| 558 | #endif |
| 559 | struct tfm_thrd_ctx *pth_next = tfm_thrd_next_thread(); |
| 560 | struct tfm_thrd_ctx *pth_curr = tfm_thrd_curr_thread(); |
| 561 | |
Mate Toth-Pal | 32b2ccd | 2019-04-26 10:00:16 +0200 | [diff] [blame] | 562 | if (pth_next != NULL && pth_curr != pth_next) { |
Ken Liu | 2d17517 | 2019-03-21 17:08:41 +0800 | [diff] [blame] | 563 | #if TFM_LVL == 2 |
Summer Qin | b5da9cc | 2019-08-26 15:19:45 +0800 | [diff] [blame] | 564 | r_data = TFM_GET_CONTAINER_PTR(pth_next, |
| 565 | struct spm_partition_runtime_data_t, |
| 566 | sp_thrd); |
| 567 | p_next_partition = TFM_GET_CONTAINER_PTR(r_data, |
Ken Liu | 2d17517 | 2019-03-21 17:08:41 +0800 | [diff] [blame] | 568 | struct spm_partition_desc_t, |
Summer Qin | b5da9cc | 2019-08-26 15:19:45 +0800 | [diff] [blame] | 569 | runtime_data); |
Ken Liu | 2d17517 | 2019-03-21 17:08:41 +0800 | [diff] [blame] | 570 | |
Summer Qin | 423dbef | 2019-08-22 15:59:35 +0800 | [diff] [blame] | 571 | if (p_next_partition->static_data->partition_flags & |
Ken Liu | 2d17517 | 2019-03-21 17:08:41 +0800 | [diff] [blame] | 572 | SPM_PART_FLAG_PSA_ROT) { |
| 573 | is_privileged = TFM_PARTITION_PRIVILEGED_MODE; |
| 574 | } else { |
| 575 | is_privileged = TFM_PARTITION_UNPRIVILEGED_MODE; |
| 576 | } |
| 577 | |
| 578 | tfm_spm_partition_change_privilege(is_privileged); |
| 579 | #endif |
Mate Toth-Pal | c430b99 | 2019-05-09 21:01:14 +0200 | [diff] [blame] | 580 | /* Increase the secure lock, if we enter secure from non-secure */ |
| 581 | if ((void *)pth_curr->pfn == (void *)tfm_nspm_thread_entry) { |
| 582 | ++tfm_secure_lock; |
| 583 | } |
| 584 | /* Decrease the secure lock, if we return from secure to non-secure */ |
| 585 | if ((void *)pth_next->pfn == (void *)tfm_nspm_thread_entry) { |
| 586 | --tfm_secure_lock; |
| 587 | } |
| 588 | |
Ken Liu | 2d17517 | 2019-03-21 17:08:41 +0800 | [diff] [blame] | 589 | tfm_thrd_context_switch(ctxb, pth_curr, pth_next); |
| 590 | } |
David Hu | fb38d56 | 2019-09-23 15:58:34 +0800 | [diff] [blame] | 591 | |
| 592 | /* |
| 593 | * Handle pending mailbox message from NS in multi-core topology. |
| 594 | * Empty operation on single Armv8-M platform. |
| 595 | */ |
| 596 | tfm_rpc_client_call_handler(); |
Ken Liu | 2d17517 | 2019-03-21 17:08:41 +0800 | [diff] [blame] | 597 | } |