[PATCH 3/4] lib: sbi: Add SBI watchdog framework

Rahul Pathak rahul.pathak at oss.qualcomm.com
Sun Oct 4 20:33:04 PDT 2026


On Fri, Oct 2, 2026 at 2:01 PM Prajwal N <prajwal.n at oss.qualcomm.com> wrote:
>
> Update the build infrastructure to include the SBI
> watchdog compilation.
>
> Implement the SBI watchdog functionality including
> start, stop, pat, read and write attributes,
> pretimeout and timeout handlers.
>
> Signed-off-by: Prajwal N <prajwal.n at oss.qualcomm.com>
> ---
>  include/sbi/sbi_wdt.h |  72 +++++++
>  lib/sbi/objects.mk    |   1 +
>  lib/sbi/sbi_init.c    |   8 +
>  lib/sbi/sbi_wdt.c     | 455 ++++++++++++++++++++++++++++++++++++++++++
>  4 files changed, 536 insertions(+)
>  create mode 100644 include/sbi/sbi_wdt.h
>  create mode 100644 lib/sbi/sbi_wdt.c
>
> +
> +
> +static void sbi_watchdog_expired_callback(struct sbi_timer_event *ev,
> +                                         struct sbi_timer_event_restart *restart)
> +{
> +       spin_lock(&sbi_system_watchdog->wdt_lock);
> +
> +       sbi_system_watchdog->wdt_attr.wdt_state = SBI_WDT_EXPIRED;
> +       /* Trigger the system reboot*/
> +       sbi_system_reset(SBI_SRST_RESET_TYPE_WARM_REBOOT, SBI_SRST_RESET_REASON_NONE);

Better to call the sbi_system_reset after the spinlock unlock

> +
> +       spin_unlock(&sbi_system_watchdog->wdt_lock);
> +}
> +
> +static void sbi_watchdog_enable_timer_events()
> +{
> +       u64 timeout, pretimeout;
> +       u32 pretimeout_us;
> +
> +       /* Restart the pretimeout event only if the wdt_notif_time is non zero*/
> +       if (sbi_system_watchdog->wdt_attr.wdt_notif_time != 0) {
> +               pretimeout_us = sbi_system_watchdog->wdt_attr.wdt_period -
> +                               sbi_system_watchdog->wdt_attr.wdt_notif_time;
> +               pretimeout = sbi_timer_value() + sbi_timer_compute_udelta(pretimeout_us);
> +
> +               sbi_timer_event_start(&sbi_system_watchdog->wdt_pretimeout_ev, pretimeout);
> +       }
> +
> +       /* Restart the Watchdog timeout event only if the wdt_period is non zero*/
> +       if (sbi_system_watchdog->wdt_attr.wdt_period != 0) {
> +               timeout = sbi_timer_value() +
> +                         sbi_timer_compute_udelta(sbi_system_watchdog->wdt_attr.wdt_period);
> +               sbi_timer_event_start(&sbi_system_watchdog->wdt_timer_ev, timeout);
> +       }
> +}
> +



More information about the opensbi mailing list