9 #include "cmsis_compiler.h"
11 #include "tfm_spm_hal.h"
18 #ifndef TFM_MAX_NS_THREAD_COUNT
19 #define TFM_MAX_NS_THREAD_COUNT 8
21 #define INVALID_CLIENT_ID 0
23 #define DEFAULT_NS_CLIENT_ID ((int32_t)-1)
25 #define INVALID_NS_CLIENT_IDX (-1)
26 #define DEFAULT_NS_CLIENT_IDX 0
28 #ifdef TFM_NS_CLIENT_IDENTIFICATION
29 static struct ns_client_list_t {
31 int32_t next_free_index;
34 static int32_t free_index = 0U;
37 static int get_next_ns_client_id()
41 if (next_ns_client_id > 0) {
44 return next_ns_client_id--;
50 #ifdef TFM_NS_CLIENT_IDENTIFICATION
55 NsClientIdList[0].ns_client_id = get_next_ns_client_id();
65 #ifdef TFM_NS_CLIENT_IDENTIFICATION
69 return NsClientIdList[active_ns_client_idx].ns_client_id;
87 #ifdef CONFIG_TFM_ENABLE_CTX_MGMT
88 #ifdef TFM_NS_CLIENT_IDENTIFICATION
99 NsClientIdList[i].next_free_index = i + 1;
122 #ifdef CONFIG_TFM_ENABLE_CTX_MGMT
123 #ifdef TFM_NS_CLIENT_IDENTIFICATION
129 if (free_index < 0) {
136 NsClientIdList[free_index].ns_client_id = get_next_ns_client_id();
137 free_index = NsClientIdList[free_index].next_free_index;
151 #ifdef CONFIG_TFM_ENABLE_CTX_MGMT
152 #ifdef TFM_NS_CLIENT_IDENTIFICATION
172 if (active_ns_client_idx == index) {
176 NsClientIdList[index].next_free_index = free_index;
196 #ifdef CONFIG_TFM_ENABLE_CTX_MGMT
197 #ifdef TFM_NS_CLIENT_IDENTIFICATION
217 active_ns_client_idx = index;
235 #ifdef CONFIG_TFM_ENABLE_CTX_MGMT
236 #ifdef TFM_NS_CLIENT_IDENTIFICATION
257 if (active_ns_client_idx != index) {
272 #ifdef TFM_NS_CLIENT_IDENTIFICATION
276 int current_client_id;
283 if (ns_client_id >= 0) {
288 if (active_ns_client_idx < 0) {
293 current_client_id = NsClientIdList[active_ns_client_idx].ns_client_id;
294 if (current_client_id >= 0 ) {
299 NsClientIdList[active_ns_client_idx].ns_client_id = ns_client_id;
308 SCB_NS->VTOR = tfm_spm_hal_get_ns_VTOR();
311 uint32_t ns_msp = tfm_spm_hal_get_ns_MSP();
313 __TZ_set_MSP_NS(ns_msp);
316 uint32_t entry_ptr = tfm_spm_hal_get_ns_entry_point();
#define INVALID_NS_CLIENT_IDX
#define TFM_MAX_NS_THREAD_COUNT
#define DEFAULT_NS_CLIENT_ID
#define __tfm_nspm_secure_gateway_attributes__
Attributes for secure gateway functions for NSPM.
void configure_ns_code(void)
#define cmse_nsfptr_create(p)
__STATIC_INLINE uint32_t __get_active_exc_num(void)
int32_t tfm_nspm_get_current_client_id(void)
Get the client ID of the current NS client.
__tfm_nspm_secure_gateway_attributes__ uint32_t TZ_StoreContext_S(TZ_MemoryId_t id)
__tfm_nspm_secure_gateway_attributes__ uint32_t TZ_FreeModuleContext_S(TZ_MemoryId_t id)
__tfm_nspm_secure_gateway_attributes__ uint32_t TZ_LoadContext_S(TZ_MemoryId_t id)
__tfm_nspm_secure_gateway_attributes__ uint32_t TZ_InitContextSystem_S(void)
#define EXC_NUM_THREAD_MODE
void tfm_nspm_configure_clients(void)
initialise the NS context database
__tfm_nspm_secure_gateway_attributes__ TZ_MemoryId_t TZ_AllocModuleContext_S(TZ_ModuleId_t module)
#define INVALID_CLIENT_ID
#define DEFAULT_NS_CLIENT_IDX
enum tfm_status_e tfm_register_client_id(int32_t ns_client_id)
Assign client ID to the current TZ context.