1 /* 2 * Copyright (c) 2022, Arm Limited. All rights reserved. 3 * Copyright (c) 2023-2024 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 <stdint.h> 12 13 #include "runtime_defs.h" 14 #include "sprt_partition_metadata_indicator.h" 15 #include "tfm_sp_log.h" 16 17 #include "psa/error.h" 18 #include "psa/service.h" 19 common_sfn_thread(void * param)20void common_sfn_thread(void *param) 21 { 22 psa_signal_t sig_asserted, signal_mask, sig; 23 psa_msg_t msg; 24 struct runtime_metadata_t *meta; 25 service_fn_t *p_sfn_table; 26 sfn_init_fn_t sfn_init; 27 28 meta = PART_METADATA(); 29 sfn_init = (sfn_init_fn_t)meta->entry; 30 p_sfn_table = (service_fn_t *)meta->sfn_table; 31 signal_mask = (1UL << meta->n_sfn) - 1; 32 33 if (sfn_init && sfn_init(param) != PSA_SUCCESS) { 34 LOG_ERRFMT("Partition initialization FAILED in 0x%x\r\n", sfn_init); 35 psa_panic(); 36 } 37 38 while (1) { 39 sig_asserted = psa_wait(signal_mask, PSA_BLOCK); 40 /* Handle signals */ 41 for (int i = 0; sig_asserted != 0 && i < meta->n_sfn; i++) { 42 sig = 1UL << i; 43 if (sig_asserted & sig) { 44 /* The i bit signal asserted, index of SFN is i as well */ 45 if (!p_sfn_table[i]) { 46 /* No corresponding SFN */ 47 psa_panic(); 48 } 49 50 psa_get(sig, &msg); 51 psa_reply(msg.handle, ((service_fn_t)p_sfn_table[i])(&msg)); 52 sig_asserted &= ~sig; 53 } 54 } 55 56 if (sig_asserted != 0) { 57 /* Wrong signal asserted */ 58 psa_panic(); 59 } 60 } 61 } 62