According to spec[1]

 "The compare value can either be loaded directly or indirectly on an
  explicit refresh or timeout refresh"

while QEMU does allow to write WCV, it doesn't act on
new value, which it should do according to pseudo code in spec:

 "TimeoutRefresh = ( SystemCounter [63:0] > CompareValue [63:0])"

fix it by updating timer on WCV write.

Fixes Windows watchdog reboots, since it sets
  WOR to ~4sec && never triggers WRR refresh
it however writes insane lage value into WCV
right after WOR & WCS enable, which effectively
cancels too small WOR value and missing WRR.

1) ArmĀ® Server Base System Architecture 6.0
   Platform Design Document
   DEN0029D 6.0
   "A.2 Watchdog Operation"

Signed-off-by: Igor Mammedov <[email protected]>
---
 hw/watchdog/sbsa_gwdt.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/hw/watchdog/sbsa_gwdt.c b/hw/watchdog/sbsa_gwdt.c
index c2d6f672f9..7fec61b7b0 100644
--- a/hw/watchdog/sbsa_gwdt.c
+++ b/hw/watchdog/sbsa_gwdt.c
@@ -44,6 +44,7 @@ static const VMStateDescription vmstate_sbsa_gwdt = {
 typedef enum WdtRefreshType {
     EXPLICIT_REFRESH = 0,
     TIMEOUT_REFRESH = 1,
+    WCV_LOAD = 2,
 } WdtRefreshType;
 
 static uint64_t sbsa_gwdt_rread(void *opaque, hwaddr addr, unsigned int size)
@@ -118,8 +119,6 @@ static void sbsa_gwdt_update_timer(SBSA_GWDTState *s, 
WdtRefreshType rtype)
         /* store (now + offset)ns in WCV */
         s->wcvu = timeout >> 32;
         s->wcvl = timeout;
-    } else {
-        g_assert_not_reached();
     }
 
     timeout = (uint64_t)s->wcvu << 32 | s->wcvl;
@@ -169,10 +168,16 @@ static void sbsa_gwdt_write(void *opaque, hwaddr offset, 
uint64_t data,
 
     case SBSA_GWDT_WCV:
         s->wcvl = data;
+        if (s->wcs & SBSA_GWDT_WCS_EN) {
+            sbsa_gwdt_update_timer(s, WCV_LOAD);
+        }
         break;
 
     case SBSA_GWDT_WCVU:
         s->wcvu = data;
+        if (s->wcs & SBSA_GWDT_WCS_EN) {
+            sbsa_gwdt_update_timer(s, WCV_LOAD);
+        }
         break;
 
     default:
-- 
2.47.3


Reply via email to