public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "rajesh.ravi@broadcom.com" <rajesh.ravi@broadcom.com>
To: devel@edk2.groups.io
Cc: Rajesh Ravi <rajesh.ravi@broadcom.com>,
	Leif Lindholm <leif@nuviainc.com>,
	Ard Biesheuvel <ard.biesheuvel@arm.com>
Subject: [PATCH v1 1/1] ArmPkg/GenericWatchdogDxe: Add rev 1 support to ARM Generic Watchdog driver
Date: Thu,  8 Oct 2020 20:26:08 +0530	[thread overview]
Message-ID: <20201008145608.15737-2-rajesh.ravi@broadcom.com> (raw)
In-Reply-To: <20201008145608.15737-1-rajesh.ravi@broadcom.com>

From: Rajesh Ravi <rajesh.ravi@broadcom.com>

Add SBSA watchdog rev 1 support to ARM Generic Watchdog driver.

Signed-off-by: Rajesh Ravi <rajesh.ravi@broadcom.com>
Cc: Leif Lindholm <leif@nuviainc.com>
Cc: Ard Biesheuvel <ard.biesheuvel@arm.com>
---
 ArmPkg/Drivers/GenericWatchdogDxe/GenericWatchdog.h    |  8 ++-
 ArmPkg/Drivers/GenericWatchdogDxe/GenericWatchdogDxe.c | 53 ++++++++++++++++++--
 2 files changed, 56 insertions(+), 5 deletions(-)

diff --git a/ArmPkg/Drivers/GenericWatchdogDxe/GenericWatchdog.h b/ArmPkg/Drivers/GenericWatchdogDxe/GenericWatchdog.h
index c64bc5c4627d..ed74bcf95021 100644
--- a/ArmPkg/Drivers/GenericWatchdogDxe/GenericWatchdog.h
+++ b/ArmPkg/Drivers/GenericWatchdogDxe/GenericWatchdog.h
@@ -13,12 +13,18 @@
 
 // Control Frame:
 #define GENERIC_WDOG_CONTROL_STATUS_REG       ((UINTN)FixedPcdGet64 (PcdGenericWatchdogControlBase) + 0x000)
-#define GENERIC_WDOG_OFFSET_REG               ((UINTN)FixedPcdGet64 (PcdGenericWatchdogControlBase) + 0x008)
+#define GENERIC_WDOG_OFFSET_REG_LOW           ((UINTN)FixedPcdGet64 (PcdGenericWatchdogControlBase) + 0x008)
+#define GENERIC_WDOG_OFFSET_REG_HIGH          ((UINTN)FixedPcdGet64 (PcdGenericWatchdogControlBase) + 0x00C)
 #define GENERIC_WDOG_COMPARE_VALUE_REG_LOW    ((UINTN)FixedPcdGet64 (PcdGenericWatchdogControlBase) + 0x010)
 #define GENERIC_WDOG_COMPARE_VALUE_REG_HIGH   ((UINTN)FixedPcdGet64 (PcdGenericWatchdogControlBase) + 0x014)
+#define GENERIC_WDOG_IIDR_REG                 ((UINTN)FixedPcdGet64 (PcdGenericWatchdogControlBase) + 0xFCC)
 
 // Values of bit 0 of the Control/Status Register
 #define GENERIC_WDOG_ENABLED          1
 #define GENERIC_WDOG_DISABLED         0
+#define GENERIC_WDOG_ARCH_REV_OFFSET 16
+#define GENERIC_WDOG_ARCH_REV_MASK   0xF
+#define SBSA_WDOG_WOR_WIDTH          48
+#define MAX_OFFSET_REG_VAL           (((UINT64)1 << 48) - 1)
 
 #endif  // __GENERIC_WATCHDOG_H__
diff --git a/ArmPkg/Drivers/GenericWatchdogDxe/GenericWatchdogDxe.c b/ArmPkg/Drivers/GenericWatchdogDxe/GenericWatchdogDxe.c
index f79cc9170f8a..7ef9b1ff08ab 100644
--- a/ArmPkg/Drivers/GenericWatchdogDxe/GenericWatchdogDxe.c
+++ b/ArmPkg/Drivers/GenericWatchdogDxe/GenericWatchdogDxe.c
@@ -35,16 +35,53 @@ STATIC UINTN mTimerFrequencyHz = 0;
    It is therefore stored here. 0 means the timer is not running. */
 STATIC UINT64 mNumTimerTicks = 0;
 
+STATIC UINT32 mWatchDogRev = 0;
+
+STATIC UINT64 mWatchdogMaxOffsetVal = MAX_UINT32;
+
 STATIC EFI_HARDWARE_INTERRUPT2_PROTOCOL *mInterruptProtocol;
 STATIC EFI_WATCHDOG_TIMER_NOTIFY        mWatchdogNotify;
 
+STATIC
+inline
+UINT32
+WatchdogReadRevisionRegister (
+  VOID
+  )
+{
+  return MmioRead32 (GENERIC_WDOG_IIDR_REG);
+}
+
+STATIC
+inline
+UINT32
+WatchdogGetRevision (
+  VOID
+  )
+{
+  UINT32 IidrRegVal;
+
+  IidrRegVal = WatchdogReadRevisionRegister();
+
+  return ((IidrRegVal >> GENERIC_WDOG_ARCH_REV_OFFSET) & GENERIC_WDOG_ARCH_REV_MASK);
+}
+
 STATIC
 VOID
 WatchdogWriteOffsetRegister (
-  UINT32  Value
+  UINT64  Value
   )
 {
-  MmioWrite32 (GENERIC_WDOG_OFFSET_REG, Value);
+  if(Value >> SBSA_WDOG_WOR_WIDTH) {
+    return;
+  }
+
+  MmioWrite32 (GENERIC_WDOG_OFFSET_REG_LOW, ((UINT32)Value & MAX_UINT32));
+  if (mWatchDogRev) {
+    MmioWrite32 (GENERIC_WDOG_OFFSET_REG_HIGH, (Value >> 32) & MAX_UINT32);
+  } else {
+    MmioWrite32 (GENERIC_WDOG_OFFSET_REG_HIGH, 0);
+  }
 }
 
 STATIC
@@ -207,12 +244,12 @@ WatchdogSetTimerPeriod (
   /* If the number of required ticks is greater than the max the watchdog's
      offset register (WOR) can hold, we need to manually compute and set
      the compare register (WCV) */
-  if (mNumTimerTicks > MAX_UINT32) {
+  if (mNumTimerTicks > mWatchdogMaxOffsetVal) {
     /* We need to enable the watchdog *before* writing to the compare register,
        because enabling the watchdog causes an "explicit refresh", which
        clobbers the compare register (WCV). In order to make sure this doesn't
        trigger an interrupt, set the offset to max. */
-    WatchdogWriteOffsetRegister (MAX_UINT32);
+    WatchdogWriteOffsetRegister (MAX_OFFSET_REG_VAL);
     WatchdogEnable ();
     SystemCount = ArmGenericTimerGetSystemCount ();
     WatchdogWriteCompareRegister (SystemCount + mNumTimerTicks);
@@ -319,6 +356,14 @@ GenericWatchdogEntry (
   mTimerFrequencyHz = ArmGenericTimerGetTimerFreq ();
   ASSERT (mTimerFrequencyHz != 0);
 
+  mWatchDogRev = WatchdogGetRevision();
+
+  if (mWatchDogRev) {
+    mWatchdogMaxOffsetVal = MAX_OFFSET_REG_VAL;
+  } else {
+    mWatchdogMaxOffsetVal = MAX_UINT32;
+  }
+
   // Install interrupt handler
   Status = mInterruptProtocol->RegisterInterruptSource (mInterruptProtocol,
                                  FixedPcdGet32 (PcdGenericWatchdogEl2IntrNum),
-- 
2.17.1


  reply	other threads:[~2020-10-08 14:56 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-08 14:56 [PATCH v1 0/1] Add SBSA watchdog rev 1 support to ARM Generic Watchdog driver rajesh.ravi
2020-10-08 14:56 ` rajesh.ravi [this message]
2020-10-08 17:24   ` [edk2-devel] [PATCH v1 1/1] ArmPkg/GenericWatchdogDxe: Add " Sami Mujawar
  -- strict thread matches above, loose matches on Subject: below --
2020-10-08  8:46 [PATCH v1 0/1] Add SBSA watchdog " rajesh.ravi
2020-10-08  8:46 ` [PATCH v1 1/1] ArmPkg/GenericWatchdogDxe: Add " rajesh.ravi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201008145608.15737-2-rajesh.ravi@broadcom.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox