From f29ae1c08da55d6465a4ed6576dfd4ee5681fe0c Mon Sep 17 00:00:00 2001 From: Joe Zhu Date: Fri, 19 May 2023 17:15:34 +0800 Subject: [PATCH] module: timer: add API to update timer status without alarm Some devices need overflow interrupt to update internal status. Add new driver API to handle this if there is no acitve alarm. Change-Id: I6a3106beb8dce8de7de29dfa5ff5742a9fd9692b Signed-off-by: Joe Zhu --- module/timer/include/mod_timer.h | 9 ++++++++- module/timer/src/mod_timer.c | 13 ++++++++++--- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/module/timer/include/mod_timer.h b/module/timer/include/mod_timer.h index c7b7f37d5..1d583a9a1 100644 --- a/module/timer/include/mod_timer.h +++ b/module/timer/include/mod_timer.h @@ -1,6 +1,6 @@ /* * Arm SCP/MCP Software - * Copyright (c) 2017-2022, Arm Limited and Contributors. All rights reserved. + * Copyright (c) 2017-2024, Arm Limited and Contributors. All rights reserved. * * SPDX-License-Identifier: BSD-3-Clause * @@ -120,6 +120,13 @@ struct mod_timer_driver_api { /*! Get counter frequency */ int (*get_frequency)(fwk_id_t dev_id, uint32_t *value); + + /*! + * Timer device may need to update internal status in alarm or overflow + * event. This handler is used to process overflow event when there is no + * active alarm. Optional + */ + void (*overflow_handler)(fwk_id_t dev_id); }; /*! diff --git a/module/timer/src/mod_timer.c b/module/timer/src/mod_timer.c index f65f27d35..c944798d2 100644 --- a/module/timer/src/mod_timer.c +++ b/module/timer/src/mod_timer.c @@ -1,6 +1,6 @@ /* * Arm SCP/MCP Software - * Copyright (c) 2017-2023, Arm Limited and Contributors. All rights reserved. + * Copyright (c) 2017-2024, Arm Limited and Contributors. All rights reserved. * * SPDX-License-Identifier: BSD-3-Clause * @@ -557,8 +557,15 @@ static void timer_isr(uintptr_t ctx_ptr) (struct alarm_sub_element_ctx *)fwk_list_pop_head(&ctx->alarms_active); if (alarm == NULL) { - /* Timer interrupt triggered without any alarm in the active queue */ - fwk_unexpected(); + if (ctx->driver->overflow_handler != NULL) { + ctx->driver->overflow_handler(ctx->driver_dev_id); + } else { + /* + * Timer interrupt triggered without any alarm in the active queue nor an + * overflow handler provided. + */ + fwk_unexpected(); + } return; }