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