[PATCH 3/4] lib: sbi: Add SBI watchdog framework
Rahul Pathak
rahul.pathak at oss.qualcomm.com
Mon Oct 5 02:16:52 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
>
> +
> +int sbi_watchdog_write_attribute(u32 attribute_id, u32 attribute_value)
> +{
> + int ret;
> +
> + spin_lock(&sbi_system_watchdog->wdt_lock);
> +
> + /* Check if the attribute is writable */
> + if (!(sbi_watchdog_attr_perm[attribute_id] & WDT_ATTR_PERM_W)) {
attribute_id must be validated here before it's used for any access.
> + ret = SBI_ERR_DENIED;
> + goto out;
> + }
> +
> + switch (attribute_id) {
> + case SBI_WDT_PERIOD:
> + /* Return error if wdt_period passed is less than wdt_min_period */
> + if (attribute_value < sbi_system_watchdog->wdt_attr.wdt_min_period) {
> + ret = SBI_ERR_FAILED;
> + goto out;
> + }
> + break;
> +
> + case SBI_WDT_NOTIF_TIME:
> + /* Ignore the write if the MSI capability is not enabled */
> + if (!CAP_GET(sbi_system_watchdog->wdt_attr.wdt_capability, WDT_CAP_MSI_MASK)) {
> + ret = SBI_SUCCESS;
> + goto out;
> + }
> +
> + /* Returen error if the notif time is greater than the timeout period*/
> + if (attribute_value >= sbi_system_watchdog->wdt_attr.wdt_period) {
> + ret = SBI_ERR_FAILED;
> + goto out;
> + }
> + break;
> +
> + case SBI_WDT_NOTIF_MSI_ADDR_LOW:
> + case SBI_WDT_NOTIF_MSI_ADDR_HIGH:
> + case SBI_WDT_NOTIF_MSI_DATA:
> + /* Ignore the write if the MSI capability is not enabled */
> + if (!CAP_GET(sbi_system_watchdog->wdt_attr.wdt_capability, WDT_CAP_MSI_MASK)) {
> + ret = SBI_SUCCESS;
> + goto out;
> + }
> +
> + /*
> + * The MSI address and data can be written only when
> + * the notifications are disabled
> + */
> + if (sbi_system_watchdog->wdt_attr.wdt_notif_time != 0) {
> + ret = SBI_ERR_FAILED;
> + goto out;
> + }
> + break;
> +
> + default:
> + /* Return error if the attribute index is out of bound*/
> + if (attribute_id >= SBI_WDT_ATTR_MAX) {
> + ret = SBI_ERR_INVALID_PARAM;
> + goto out;
> + }
> + break;
> + }
> +
> + u32 *wdt_attrs = (u32 *)&sbi_system_watchdog->wdt_attr;
> + wdt_attrs[attribute_id] = attribute_value;
> +
> + ret = SBI_SUCCESS;
> +
> +out:
> + spin_unlock(&sbi_system_watchdog->wdt_lock);
> + return ret;
> +}
> +
More information about the opensbi
mailing list