1 /*
2  * Copyright (c) 2021-2024, Arm Limited. All rights reserved.
3  * Copyright (c) 2021-2023 Cypress Semiconductor Corporation (an Infineon company)
4  * or an affiliate of Cypress Semiconductor Corporation. All rights reserved.
5  *
6  * SPDX-License-Identifier: BSD-3-Clause
7  *
8  */
9 
10 #include "async.h"
11 #include "config_tfm.h"
12 #include "psa/service.h"
13 #include "psa_manifest/ns_agent_mailbox.h"
14 #include "tfm_hal_mailbox.h"
15 #include "tfm_hal_multi_core.h"
16 #include "tfm_hal_platform.h"
17 #include "tfm_multi_core.h"
18 #include "tfm_rpc.h"
19 #include "tfm_sp_log.h"
20 
boot_ns_core(void)21 static void boot_ns_core(void)
22 {
23     /* Boot up non-secure core */
24     LOG_DBGFMT("Enabling non-secure core...\r\n");
25 
26     tfm_hal_boot_ns_cpu(tfm_hal_get_ns_VTOR());
27     tfm_hal_wait_for_ns_cpu_ready();
28 }
29 
ns_agent_mailbox_entry(void)30 void ns_agent_mailbox_entry(void)
31 {
32     psa_signal_t signals = 0;
33 
34     boot_ns_core();
35 
36     if (tfm_inter_core_comm_init()) {
37         LOG_ERRFMT("Inter-core communication init failed\r\n");
38         psa_panic();
39     }
40 
41     MAILBOX_ENABLE_INTERRUPTS();
42 
43     while (1) {
44         signals = psa_wait(PSA_WAIT_ANY, PSA_BLOCK);
45         if (MAILBOX_SIGNAL_IS_ACTIVE(signals)) {
46             psa_eoi(MAILBOX_SIGNAL_GET_ACTIVE(signals));
47             tfm_rpc_client_call_handler();
48 #if CONFIG_TFM_SPM_BACKEND_IPC == 1
49         } else if (signals & ASYNC_MSG_REPLY) {
50             tfm_rpc_client_call_reply();
51 #endif
52         } else {
53             psa_panic();
54         }
55     }
56 }
57