From 1728e1bc15d124f6d080d867a40d2428327c831e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20=C5=BBygowski?= Date: Thu, 31 Aug 2023 10:40:39 +0200 Subject: [PATCH] intelblocks/oc_wdt: Consolidate the API MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Reduce the OC WDT integration code footprint by consolidating multiple API calls into a single function to be called by SoC. Change-Id: Iba031cd8e0b72cabc4d0d8a216273d763231c889 Signed-off-by: Michał Żygowski Reviewed-on: https://review.coreboot.org/c/coreboot/+/77574 Reviewed-by: Krystian Hebel Tested-by: build bot (Jenkins) --- .../common/block/include/intelblocks/oc_wdt.h | 14 ++------- src/soc/intel/common/block/oc_wdt/oc_wdt.c | 30 ++++++++++++++----- 2 files changed, 24 insertions(+), 20 deletions(-) diff --git a/src/soc/intel/common/block/include/intelblocks/oc_wdt.h b/src/soc/intel/common/block/include/intelblocks/oc_wdt.h index 8a03a18732..bc0f0b1a27 100644 --- a/src/soc/intel/common/block/include/intelblocks/oc_wdt.h +++ b/src/soc/intel/common/block/include/intelblocks/oc_wdt.h @@ -5,22 +5,12 @@ #include -/* - * Starts and reloads the OC watchdog with given timeout. - * - * timeout - Time in seconds before OC watchdog times out. Supported range = 70 - 1024 - */ -void oc_wdt_start(unsigned int timeout); +/* Starts and reloads the OC watchdog if enabled in Kconfig */ +void setup_oc_wdt(void); /* Reloads the OC watchdog (if enabled) preserving the current settings. */ void oc_wdt_reload(void); -/* Disables the OC WDT */ -void oc_wdt_disable(void); - -/* Checks if OC WDT is enabled and returns true if so, otherwise false */ -bool is_oc_wdt_enabled(void); - /* Returns currently programmed OC watchdog timeout in seconds */ unsigned int oc_wdt_get_current_timeout(void); diff --git a/src/soc/intel/common/block/oc_wdt/oc_wdt.c b/src/soc/intel/common/block/oc_wdt/oc_wdt.c index 012621bb90..d0f054a074 100644 --- a/src/soc/intel/common/block/oc_wdt/oc_wdt.c +++ b/src/soc/intel/common/block/oc_wdt/oc_wdt.c @@ -22,7 +22,7 @@ * * timeout - Time in seconds before OC watchdog times out. Supported range = 70 - 1024 */ -void oc_wdt_start(unsigned int timeout) +static void oc_wdt_start(unsigned int timeout) { uint32_t oc_wdt_ctrl; @@ -48,6 +48,12 @@ void oc_wdt_start(unsigned int timeout) outl(oc_wdt_ctrl, PCH_OC_WDT_CTL); } +/* Checks if OC WDT is enabled and returns true if so, otherwise false. */ +static bool is_oc_wdt_enabled(void) +{ + return (inl(PCH_OC_WDT_CTL) & PCH_OC_WDT_CTL_EN) ? true : false; +} + /* Reloads the OC watchdog (if enabled) preserving the current settings. */ void oc_wdt_reload(void) { @@ -65,7 +71,7 @@ void oc_wdt_reload(void) } /* Disables the OC WDT. */ -void oc_wdt_disable(void) +static void oc_wdt_disable(void) { uint32_t oc_wdt_ctrl; @@ -76,14 +82,22 @@ void oc_wdt_disable(void) outl(oc_wdt_ctrl, PCH_OC_WDT_CTL); } -/* Checks if OC WDT is enabled and returns true if so, otherwise false. */ -bool is_oc_wdt_enabled(void) -{ - return (inl(PCH_OC_WDT_CTL) & PCH_OC_WDT_CTL_EN) ? true : false; -} - /* Returns currently programmed OC watchdog timeout in seconds */ unsigned int oc_wdt_get_current_timeout(void) { return (inl(PCH_OC_WDT_CTL) & PCH_OC_WDT_CTL_TOV_MASK) + 1; } + +/* Starts and reloads the OC watchdog if enabled in Kconfig */ +void setup_oc_wdt(void) +{ + if (CONFIG(SOC_INTEL_COMMON_OC_WDT_ENABLE)) { + oc_wdt_start(CONFIG_SOC_INTEL_COMMON_OC_WDT_TIMEOUT_SECONDS); + if (is_oc_wdt_enabled()) + printk(BIOS_DEBUG, "OC Watchdog enabled\n"); + else + printk(BIOS_ERR, "Failed to enable OC watchdog\n"); + } else { + oc_wdt_disable(); + } +}