diff options
-rw-r--r-- | spm/cactus/cactus_tests/cactus_test_interrupts.c | 41 |
1 files changed, 38 insertions, 3 deletions
diff --git a/spm/cactus/cactus_tests/cactus_test_interrupts.c b/spm/cactus/cactus_tests/cactus_test_interrupts.c index 2d37f8a..3fa5f23 100644 --- a/spm/cactus/cactus_tests/cactus_test_interrupts.c +++ b/spm/cactus/cactus_tests/cactus_test_interrupts.c @@ -14,6 +14,14 @@ #include <platform.h> +static int flag_set; + +static void sec_wdog_interrupt_handled(void) +{ + expect(flag_set, 0); + flag_set = 1; +} + CACTUS_CMD_HANDLER(sleep_cmd, CACTUS_SLEEP_CMD) { uint64_t time_lapsed; @@ -102,16 +110,35 @@ CACTUS_CMD_HANDLER(twdog_cmd, CACTUS_TWDOG_START_CMD) return cactus_success_resp(vm_id, source, time_ms); } +bool handle_twdog_interrupt_sp_sleep(uint32_t sleep_time, uint64_t *time_lapsed) +{ + sp_register_interrupt_tail_end_handler(sec_wdog_interrupt_handled, + IRQ_TWDOG_INTID); + *time_lapsed += sp_sleep_elapsed_time(sleep_time); + + if (flag_set == 0) { + return false; + } + + /* Reset the flag and unregister the handler. */ + flag_set = 0; + sp_unregister_interrupt_tail_end_handler(IRQ_TWDOG_INTID); + + return true; +} + CACTUS_CMD_HANDLER(sleep_twdog_cmd, CACTUS_SLEEP_TRIGGER_TWDOG_CMD) { - uint64_t time_lapsed; + uint64_t time_lapsed = 0; uint32_t sleep_time = cactus_get_sleep_time(*args) / 2; uint64_t time_ms = cactus_get_wdog_trigger_duration(*args); VERBOSE("Request to sleep %x for %ums.\n", ffa_dir_msg_dest(*args), sleep_time); - time_lapsed = sp_sleep_elapsed_time(sleep_time); + if (!handle_twdog_interrupt_sp_sleep(sleep_time, &time_lapsed)) { + goto fail; + } /* Lapsed time should be at least equal to sleep time. */ VERBOSE("Sleep complete: %llu\n", time_lapsed); @@ -123,7 +150,9 @@ CACTUS_CMD_HANDLER(sleep_twdog_cmd, CACTUS_SLEEP_TRIGGER_TWDOG_CMD) VERBOSE("2nd Request to sleep %x for %ums.\n", ffa_dir_msg_dest(*args), sleep_time); - time_lapsed += sp_sleep_elapsed_time(sleep_time); + if (!handle_twdog_interrupt_sp_sleep(sleep_time, &time_lapsed)) { + goto fail; + } /* Lapsed time should be at least equal to sleep time. */ VERBOSE("2nd Sleep complete: %llu\n", time_lapsed); @@ -131,4 +160,10 @@ CACTUS_CMD_HANDLER(sleep_twdog_cmd, CACTUS_SLEEP_TRIGGER_TWDOG_CMD) return cactus_response(ffa_dir_msg_dest(*args), ffa_dir_msg_source(*args), time_lapsed); +fail: + /* Test failed. */ + ERROR("Watchdog interrupt not handled\n"); + return cactus_error_resp(ffa_dir_msg_dest(*args), + ffa_dir_msg_source(*args), + CACTUS_ERROR_TEST); } |