]> git.proxmox.com Git - mirror_edk2.git/commitdiff
PcAtChipsetPkg/Rtc: Fix a UEFI Win7 boot hang issue
authorRuiyu Ni <ruiyu.ni@intel.com>
Tue, 22 Dec 2015 13:52:47 +0000 (13:52 +0000)
committerniruiyu <niruiyu@Edk2>
Tue, 22 Dec 2015 13:52:47 +0000 (13:52 +0000)
The patch updates the Century value in CMOS location specified
by FADT.Century to avoid UEFI Win7 hang during booting.
Per the ACPI spec if the FADT.Century is zero, it's not needed
to store the century value in CMOS. But UEFI Win7 treats the
Century storage is optional only when FADT.Century is 0x80.
While Linux strictly follows the ACPI spec and treats Century
storage is optional when FADT.Century is 0.
So if a platform wants to support both UEFI Win7 and Linux,
it needs to report FADT.Century to a traditional value which
doesn't equal to 0 or 0x80 (0x32 mostly). And RTC driver is
enhanced to save the century value to the location specified
by FADT.Century.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com>
Reviewed-by: Star Zeng <star.zeng@intel.com>
git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@19442 6f19259b-4bc3-4df7-8a09-765794883524

PcAtChipsetPkg/PcatRealTimeClockRuntimeDxe/PcRtc.c
PcAtChipsetPkg/PcatRealTimeClockRuntimeDxe/PcRtc.h
PcAtChipsetPkg/PcatRealTimeClockRuntimeDxe/PcRtcEntry.c
PcAtChipsetPkg/PcatRealTimeClockRuntimeDxe/PcatRealTimeClockRuntimeDxe.inf

index 5abb71c032b4d949f8ea467239db699360e5f73c..e122ae16990a51324e13935441de6b9a5d5efb32 100644 (file)
@@ -500,6 +500,13 @@ PcRtcSetTime (
   RegisterB.Bits.Set  = 1;\r
   RtcWrite (RTC_ADDRESS_REGISTER_B, RegisterB.Data);\r
 \r
+  //\r
+  // Store the century value to RTC before converting to BCD format.\r
+  //\r
+  if (Global->CenturyRtcAddress != 0) {\r
+    RtcWrite (Global->CenturyRtcAddress, DecimalToBcd8 ((UINT8) (RtcTime.Year / 100)));\r
+  }\r
+\r
   ConvertEfiTimeToRtcTime (&RtcTime, RegisterB);\r
 \r
   RtcWrite (RTC_ADDRESS_SECONDS, RtcTime.Second);\r
@@ -1198,3 +1205,106 @@ IsWithinOneDay (
   return Adjacent;\r
 }\r
 \r
+/**\r
+  This function find ACPI table with the specified signature in RSDT or XSDT.\r
+\r
+  @param Sdt              ACPI RSDT or XSDT.\r
+  @param Signature        ACPI table signature.\r
+  @param TablePointerSize Size of table pointer: 4 or 8.\r
+\r
+  @return ACPI table or NULL if not found.\r
+**/\r
+VOID *\r
+ScanTableInSDT (\r
+  IN EFI_ACPI_DESCRIPTION_HEADER    *Sdt,\r
+  IN UINT32                         Signature,\r
+  IN UINTN                          TablePointerSize\r
+  )\r
+{\r
+  UINTN                          Index;\r
+  UINTN                          EntryCount;\r
+  UINTN                          EntryBase;\r
+  EFI_ACPI_DESCRIPTION_HEADER    *Table;\r
+\r
+  EntryCount = (Sdt->Length - sizeof (EFI_ACPI_DESCRIPTION_HEADER)) / TablePointerSize;\r
+\r
+  EntryBase = (UINTN) (Sdt + 1);\r
+  for (Index = 0; Index < EntryCount; Index++) {\r
+    //\r
+    // When TablePointerSize is 4 while sizeof (VOID *) is 8, make sure the upper 4 bytes are zero.\r
+    //\r
+    Table = 0;\r
+    CopyMem (&Table, (VOID *) (EntryBase + Index * TablePointerSize), TablePointerSize);\r
+    if (Table->Signature == Signature) {\r
+      return Table;\r
+    }\r
+  }\r
+\r
+  return NULL;\r
+}\r
+\r
+/**\r
+  Notification function of ACPI Table change.\r
+\r
+  This is a notification function registered on ACPI Table change event.\r
+  It saves the Century address stored in ACPI FADT table.\r
+\r
+  @param  Event        Event whose notification function is being invoked.\r
+  @param  Context      Pointer to the notification function's context.\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+PcRtcAcpiTableChangeCallback (\r
+  IN EFI_EVENT        Event,\r
+  IN VOID             *Context\r
+  )\r
+{\r
+  EFI_STATUS                                    Status;\r
+  EFI_ACPI_2_0_ROOT_SYSTEM_DESCRIPTION_POINTER  *Rsdp;\r
+  EFI_ACPI_DESCRIPTION_HEADER                   *Rsdt;\r
+  EFI_ACPI_DESCRIPTION_HEADER                   *Xsdt;\r
+  EFI_ACPI_2_0_FIXED_ACPI_DESCRIPTION_TABLE     *Fadt;\r
+  EFI_TIME                                      Time;\r
+  UINT8                                         Century;\r
+\r
+  Status = EfiGetSystemConfigurationTable (&gEfiAcpiTableGuid, (VOID **) &Rsdp);\r
+  if (EFI_ERROR (Status)) {\r
+    Status = EfiGetSystemConfigurationTable (&gEfiAcpi10TableGuid, (VOID **) &Rsdp);\r
+  }\r
+\r
+  if (EFI_ERROR (Status)) {\r
+    return;\r
+  }\r
+\r
+  //\r
+  // Find FADT in XSDT\r
+  //\r
+  Fadt = NULL;\r
+  if (Rsdp->Revision >= EFI_ACPI_2_0_ROOT_SYSTEM_DESCRIPTION_POINTER_REVISION) {\r
+    Xsdt = (EFI_ACPI_DESCRIPTION_HEADER *) (UINTN) Rsdp->XsdtAddress;\r
+    Fadt = ScanTableInSDT (Xsdt, EFI_ACPI_2_0_FIXED_ACPI_DESCRIPTION_TABLE_SIGNATURE, sizeof (UINT64));\r
+  }\r
+\r
+  if (Fadt == NULL) {\r
+    //\r
+    // Find FADT in RSDT\r
+    //\r
+    Rsdt = (EFI_ACPI_DESCRIPTION_HEADER *) (UINTN) Rsdp->RsdtAddress;\r
+    Fadt = ScanTableInSDT (Rsdt, EFI_ACPI_2_0_FIXED_ACPI_DESCRIPTION_TABLE_SIGNATURE, sizeof (UINT32));\r
+  }\r
+\r
+  if ((Fadt != NULL) &&\r
+      (Fadt->Century > RTC_ADDRESS_REGISTER_D) && (Fadt->Century < 0x80) &&\r
+      (mModuleGlobal.CenturyRtcAddress != Fadt->Century)\r
+      ) {\r
+    mModuleGlobal.CenturyRtcAddress = Fadt->Century;\r
+    Status = PcRtcGetTime (&Time, NULL, &mModuleGlobal);\r
+    if (!EFI_ERROR (Status)) {\r
+      Century = (UINT8) (Time.Year / 100);\r
+      Century = DecimalToBcd8 (Century);\r
+      DEBUG ((EFI_D_INFO, "PcRtc: Write 0x%x to CMOS location 0x%x\n", Century, mModuleGlobal.CenturyRtcAddress));\r
+      RtcWrite (mModuleGlobal.CenturyRtcAddress, Century);\r
+    }\r
+  }\r
+}\r
index 026c1086b2fe826522c7017a0973e0c180d3d373..7fc19f90434efb71e6f72822c602d663cdb1c2cb 100644 (file)
@@ -19,6 +19,8 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 \r
 #include <Uefi.h>\r
 \r
+#include <Guid/Acpi.h>\r
+\r
 #include <Protocol/RealTimeClock.h>\r
 \r
 #include <Library/BaseLib.h>\r
@@ -34,13 +36,15 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 #include <Library/PcdLib.h>\r
 #include <Library/ReportStatusCodeLib.h>\r
 \r
-\r
 typedef struct {\r
   EFI_LOCK  RtcLock;\r
   INT16     SavedTimeZone;\r
   UINT8     Daylight;\r
+  UINT8     CenturyRtcAddress;\r
 } PC_RTC_MODULE_GLOBALS;\r
 \r
+extern PC_RTC_MODULE_GLOBALS  mModuleGlobal;\r
+\r
 #define PCAT_RTC_ADDRESS_REGISTER 0x70\r
 #define PCAT_RTC_DATA_REGISTER    0x71\r
 \r
@@ -355,4 +359,20 @@ IsLeapYear (
   IN EFI_TIME   *Time\r
   );\r
 \r
+/**\r
+  Notification function of ACPI Table change.\r
+\r
+  This is a notification function registered on ACPI Table change event.\r
+  It saves the Century address stored in ACPI FADT table.\r
+\r
+  @param  Event        Event whose notification function is being invoked.\r
+  @param  Context      Pointer to the notification function's context.\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+PcRtcAcpiTableChangeCallback (\r
+  IN EFI_EVENT        Event,\r
+  IN VOID             *Context\r
+  );\r
 #endif\r
index 9cf3988705503dfe9188dd932ee581f8caa7c4ec..6f2a987f22043715df96b359f948c89ec7907047 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Provides Set/Get time operations.\r
 \r
-Copyright (c) 2006 - 2008, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2006 - 2015, Intel Corporation. All rights reserved.<BR>\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
@@ -14,11 +14,10 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 \r
 #include "PcRtc.h"\r
 \r
-PC_RTC_MODULE_GLOBALS  mModuleGlobal;\r
+PC_RTC_MODULE_GLOBALS  mModuleGlobal = { 0 };\r
 \r
 EFI_HANDLE             mHandle = NULL;\r
 \r
-\r
 /**\r
   Returns the current time and date information, and the time-keeping capabilities\r
   of the hardware platform.\r
@@ -133,11 +132,32 @@ InitializePcRtc (
   )\r
 {\r
   EFI_STATUS  Status;\r
+  EFI_EVENT   Event;\r
 \r
   EfiInitializeLock (&mModuleGlobal.RtcLock, TPL_CALLBACK);\r
 \r
   Status = PcRtcInit (&mModuleGlobal);\r
   ASSERT_EFI_ERROR (Status);\r
+  \r
+  Status = gBS->CreateEventEx (\r
+                  EVT_NOTIFY_SIGNAL,\r
+                  TPL_CALLBACK,\r
+                  PcRtcAcpiTableChangeCallback,\r
+                  NULL,\r
+                  &gEfiAcpi10TableGuid,\r
+                  &Event\r
+                  );\r
+  ASSERT_EFI_ERROR (Status);\r
+  \r
+  Status = gBS->CreateEventEx (\r
+                  EVT_NOTIFY_SIGNAL,\r
+                  TPL_CALLBACK,\r
+                  PcRtcAcpiTableChangeCallback,\r
+                  NULL,\r
+                  &gEfiAcpiTableGuid,\r
+                  &Event\r
+                  );\r
+  ASSERT_EFI_ERROR (Status);\r
 \r
   gRT->GetTime       = PcRtcEfiGetTime;\r
   gRT->SetTime       = PcRtcEfiSetTime;\r
index 9e5faf75d6b70f7ee4184746ab857d7fca7813de..94596cef78455b2ad20729949cc419df9d0461ec 100644 (file)
 [Protocols]\r
   gEfiRealTimeClockArchProtocolGuid             ## PRODUCES\r
 \r
+[Guids]\r
+  gEfiAcpi10TableGuid                           ## CONSUMES\r
+  gEfiAcpiTableGuid                             ## CONSUMES\r
+\r
 [Depex]\r
   gEfiVariableArchProtocolGuid AND gEfiVariableWriteArchProtocolGuid\r
   \r