]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ArmPkg/Drivers/GenericWatchdogDxe/GenericWatchdogDxe.c
ArmPkg: Fix bug in Generic Watchdog driver
[mirror_edk2.git] / ArmPkg / Drivers / GenericWatchdogDxe / GenericWatchdogDxe.c
index c5372056f3ea080c350ff67ce8f78f0a77663343..3180f011253639c408b7151c79c2106a352c7340 100644 (file)
@@ -1,6 +1,6 @@
 /** @file\r
 *\r
-*  Copyright (c) 2013-2017, ARM Limited. All rights reserved.\r
+*  Copyright (c) 2013-2018, ARM Limited. All rights reserved.\r
 *\r
 *  This program and the accompanying materials\r
 *  are licensed and made available under the terms and conditions of the BSD\r
@@ -24,8 +24,8 @@
 #include <Library/UefiLib.h>\r
 #include <Library/ArmGenericTimerCounterLib.h>\r
 \r
+#include <Protocol/HardwareInterrupt2.h>\r
 #include <Protocol/WatchdogTimer.h>\r
-#include <Protocol/HardwareInterrupt.h>\r
 \r
 #include "GenericWatchdog.h"\r
 \r
@@ -41,38 +41,38 @@ UINTN mTimerFrequencyHz = 0;
    It is therefore stored here. 0 means the timer is not running. */\r
 UINT64 mNumTimerTicks = 0;\r
 \r
-EFI_HARDWARE_INTERRUPT_PROTOCOL *mInterruptProtocol;\r
+EFI_HARDWARE_INTERRUPT2_PROTOCOL *mInterruptProtocol;\r
 \r
-EFI_STATUS\r
+VOID\r
 WatchdogWriteOffsetRegister (\r
   UINT32  Value\r
   )\r
 {\r
-  return MmioWrite32 (GENERIC_WDOG_OFFSET_REG, Value);\r
+  MmioWrite32 (GENERIC_WDOG_OFFSET_REG, Value);\r
 }\r
 \r
-EFI_STATUS\r
+VOID\r
 WatchdogWriteCompareRegister (\r
   UINT64  Value\r
   )\r
 {\r
-  return MmioWrite64 (GENERIC_WDOG_COMPARE_VALUE_REG, Value);\r
+  MmioWrite64 (GENERIC_WDOG_COMPARE_VALUE_REG, Value);\r
 }\r
 \r
-EFI_STATUS\r
+VOID\r
 WatchdogEnable (\r
   VOID\r
   )\r
 {\r
-  return MmioWrite32 (GENERIC_WDOG_CONTROL_STATUS_REG, GENERIC_WDOG_ENABLED);\r
+  MmioWrite32 (GENERIC_WDOG_CONTROL_STATUS_REG, GENERIC_WDOG_ENABLED);\r
 }\r
 \r
-EFI_STATUS\r
+VOID\r
 WatchdogDisable (\r
   VOID\r
   )\r
 {\r
-  return MmioWrite32 (GENERIC_WDOG_CONTROL_STATUS_REG, GENERIC_WDOG_DISABLED);\r
+  MmioWrite32 (GENERIC_WDOG_CONTROL_STATUS_REG, GENERIC_WDOG_DISABLED);\r
 }\r
 \r
 /** On exiting boot services we must make sure the Watchdog Timer\r
@@ -163,9 +163,7 @@ WatchdogRegisterHandler (
                            then the watchdog timer is disabled.\r
 \r
   @retval EFI_SUCCESS           The watchdog timer has been programmed to fire\r
-                                in Time  100ns units.\r
-  @retval EFI_DEVICE_ERROR      A watchdog timer could not be programmed due\r
-                                to a device error.\r
+                                in TimerPeriod 100ns units.\r
 \r
 **/\r
 EFI_STATUS\r
@@ -176,12 +174,12 @@ WatchdogSetTimerPeriod (
   )\r
 {\r
   UINTN       SystemCount;\r
-  EFI_STATUS  Status;\r
 \r
   // if TimerPeriod is 0, this is a request to stop the watchdog.\r
   if (TimerPeriod == 0) {\r
     mNumTimerTicks = 0;\r
-    return WatchdogDisable ();\r
+    WatchdogDisable ();\r
+    return EFI_SUCCESS;\r
   }\r
 \r
   // Work out how many timer ticks will equate to TimerPeriod\r
@@ -195,19 +193,16 @@ WatchdogSetTimerPeriod (
        because enabling the watchdog causes an "explicit refresh", which\r
        clobbers the compare register (WCV). In order to make sure this doesn't\r
        trigger an interrupt, set the offset to max. */\r
-    Status = WatchdogWriteOffsetRegister (MAX_UINT32);\r
-    if (EFI_ERROR (Status)) {\r
-      return Status;\r
-    }\r
+    WatchdogWriteOffsetRegister (MAX_UINT32);\r
     WatchdogEnable ();\r
     SystemCount = ArmGenericTimerGetSystemCount ();\r
-    Status      = WatchdogWriteCompareRegister (SystemCount + mNumTimerTicks);\r
+    WatchdogWriteCompareRegister (SystemCount + mNumTimerTicks);\r
   } else {\r
-    Status = WatchdogWriteOffsetRegister ((UINT32)mNumTimerTicks);\r
+    WatchdogWriteOffsetRegister ((UINT32)mNumTimerTicks);\r
     WatchdogEnable ();\r
   }\r
 \r
-  return Status;\r
+  return EFI_SUCCESS;\r
 }\r
 \r
 /**\r
@@ -311,7 +306,7 @@ GenericWatchdogEntry (
   if (!EFI_ERROR (Status)) {\r
     // Install interrupt handler\r
     Status = gBS->LocateProtocol (\r
-                    &gHardwareInterruptProtocolGuid,\r
+                    &gHardwareInterrupt2ProtocolGuid,\r
                     NULL,\r
                     (VOID **)&mInterruptProtocol\r
                     );\r
@@ -322,14 +317,21 @@ GenericWatchdogEntry (
                  WatchdogInterruptHandler\r
                  );\r
       if (!EFI_ERROR (Status)) {\r
-        // Install the Timer Architectural Protocol onto a new handle\r
-        Handle = NULL;\r
-        Status = gBS->InstallMultipleProtocolInterfaces (\r
-                        &Handle,\r
-                        &gEfiWatchdogTimerArchProtocolGuid,\r
-                        &gWatchdogTimer,\r
-                        NULL\r
-                        );\r
+        Status = mInterruptProtocol->SetTriggerType (\r
+                   mInterruptProtocol,\r
+                   FixedPcdGet32 (PcdGenericWatchdogEl2IntrNum),\r
+                   EFI_HARDWARE_INTERRUPT2_TRIGGER_EDGE_RISING\r
+                   );\r
+        if (!EFI_ERROR (Status)) {\r
+          // Install the Timer Architectural Protocol onto a new handle\r
+          Handle = NULL;\r
+          Status = gBS->InstallMultipleProtocolInterfaces (\r
+                          &Handle,\r
+                          &gEfiWatchdogTimerArchProtocolGuid,\r
+                          &gWatchdogTimer,\r
+                          NULL\r
+                          );\r
+        }\r
       }\r
     }\r
   }\r