1 /*
2  * Copyright (c) 2021-2023, Arm Limited. All rights reserved.
3  * Copyright (c) 2023 Cypress Semiconductor Corporation (an Infineon
4  * company) or an affiliate of Cypress Semiconductor Corporation. All rights
5  * reserved.
6  *
7  * SPDX-License-Identifier: BSD-3-Clause
8  *
9  */
10 
11 #include "tfm_nspm.h"
12 #include "tfm_ns_ctx.h"
13 #include "tfm_ns_client_ext.h"
14 #include "utilities.h"
15 #include "tfm_arch.h"
16 #include "tfm_hal_platform.h"
17 
18 #define DEFAULT_NS_CLIENT_ID ((int32_t)-1)
19 
tfm_nspm_get_current_client_id(void)20 int32_t tfm_nspm_get_current_client_id(void)
21 {
22 #ifdef TFM_NS_MANAGE_NSID
23     int32_t client_id;
24     client_id = get_nsid_from_active_ns_ctx();
25     return (client_id < 0 ? client_id:TFM_NS_CLIENT_INVALID_ID);
26 #else
27     return DEFAULT_NS_CLIENT_ID;
28 #endif
29 }
30 
tfm_nspm_ctx_init(void)31 void tfm_nspm_ctx_init(void)
32 {
33 #ifdef TFM_PARTITION_NS_AGENT_TZ
34     /* SCB_NS.VTOR points to the Non-secure vector table base address */
35     SCB_NS->VTOR = tfm_hal_get_ns_VTOR();
36 
37     /* Setups Main stack pointer of the non-secure code */
38     __TZ_set_MSP_NS(tfm_hal_get_ns_MSP());
39 #endif
40 
41 #ifdef TFM_NS_MANAGE_NSID
42     if (!init_ns_ctx()) {
43         tfm_core_panic();
44     }
45 #endif
46 }
47