]> git.proxmox.com Git - mirror_edk2.git/blobdiff - PcAtChipsetPkg/PcatRealTimeClockRuntimeDxe/PcRtc.c
PcAtChipsetPkg/PcatRealTimeClockRuntimeDxe: Replace RTC macros
[mirror_edk2.git] / PcAtChipsetPkg / PcatRealTimeClockRuntimeDxe / PcRtc.c
index acc70a67b71c72d759536ebd41061d2fbf56535c..c032e16217c3d858b93186a5cf49eae8bd21833e 100644 (file)
@@ -2,6 +2,8 @@
   RTC Architectural Protocol GUID as defined in DxeCis 0.96.\r
 \r
 Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2017, AMD Inc. All rights reserved.<BR>\r
+\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
@@ -128,7 +130,7 @@ PcRtcInit (
   // Make sure Division Chain is properly configured,\r
   // or RTC clock won't "tick" -- time won't increment\r
   //\r
-  RegisterA.Data = RTC_INIT_REGISTER_A;\r
+  RegisterA.Data = FixedPcdGet8 (PcdInitialValueRtcRegisterA);\r
   RtcWrite (RTC_ADDRESS_REGISTER_A, RegisterA.Data);\r
 \r
   //\r
@@ -144,7 +146,7 @@ PcRtcInit (
   //\r
   // Clear RTC register D\r
   //\r
-  RegisterD.Data = RTC_INIT_REGISTER_D;\r
+  RegisterD.Data = FixedPcdGet8 (PcdInitialValueRtcRegisterD);\r
   RtcWrite (RTC_ADDRESS_REGISTER_D, RegisterD.Data);\r
 \r
   //\r
@@ -176,7 +178,7 @@ PcRtcInit (
   // Set RTC configuration after get original time\r
   // The value of bit AIE should be reserved.\r
   //\r
-  RegisterB.Data = RTC_INIT_REGISTER_B | (RegisterB.Data & BIT5);\r
+  RegisterB.Data = FixedPcdGet8 (PcdInitialValueRtcRegisterB) | (RegisterB.Data & BIT5);\r
   RtcWrite (RTC_ADDRESS_REGISTER_B, RegisterB.Data);\r
 \r
   //\r
@@ -487,7 +489,7 @@ PcRtcSetTime (
   //\r
   // Write timezone and daylight to RTC variable\r
   //\r
-  if (Time->TimeZone == EFI_UNSPECIFIED_TIMEZONE) {\r
+  if ((Time->TimeZone == EFI_UNSPECIFIED_TIMEZONE) && (Time->Daylight == 0)) {\r
     Status = EfiSetVariable (\r
                mTimeZoneVariableName,\r
                &gEfiCallerIdGuid,\r
@@ -1230,6 +1232,11 @@ ScanTableInSDT (
     //\r
     Table = 0;\r
     CopyMem (&Table, (VOID *) (EntryBase + Index * TablePointerSize), TablePointerSize);\r
+\r
+    if (Table == NULL) {\r
+      continue;\r
+    }\r
+\r
     if (Table->Signature == Signature) {\r
       return Table;\r
     }\r
@@ -1239,63 +1246,86 @@ ScanTableInSDT (
 }\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
+  Get the century RTC address from the ACPI FADT table.\r
 \r
+  @return  The century RTC address or 0 if not found.\r
 **/\r
-VOID\r
-EFIAPI\r
-PcRtcAcpiTableChangeCallback (\r
-  IN EFI_EVENT        Event,\r
-  IN VOID             *Context\r
+UINT8\r
+GetCenturyRtcAddress (\r
+  VOID\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
+  if (EFI_ERROR (Status) || (Rsdp == NULL)) {\r
+    return 0;\r
   }\r
 \r
-  ASSERT (Rsdp != NULL);\r
+  Fadt = NULL;\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
+  if (Rsdp->Revision >= EFI_ACPI_2_0_ROOT_SYSTEM_DESCRIPTION_POINTER_REVISION && Rsdp->XsdtAddress != 0) {\r
+    Fadt = ScanTableInSDT (\r
+             (EFI_ACPI_DESCRIPTION_HEADER *) (UINTN) Rsdp->XsdtAddress,\r
+             EFI_ACPI_2_0_FIXED_ACPI_DESCRIPTION_TABLE_SIGNATURE,\r
+             sizeof (UINTN)\r
+             );\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
+  // Find FADT in RSDT\r
+  //\r
+  if (Fadt == NULL && Rsdp->RsdtAddress != 0) {\r
+    Fadt = ScanTableInSDT (\r
+             (EFI_ACPI_DESCRIPTION_HEADER *) (UINTN) Rsdp->RsdtAddress,\r
+             EFI_ACPI_2_0_FIXED_ACPI_DESCRIPTION_TABLE_SIGNATURE,\r
+             sizeof (UINT32)\r
+             );\r
   }\r
 \r
   if ((Fadt != NULL) &&\r
-      (Fadt->Century > RTC_ADDRESS_REGISTER_D) && (Fadt->Century < 0x80) &&\r
-      (mModuleGlobal.CenturyRtcAddress != Fadt->Century)\r
+      (Fadt->Century > RTC_ADDRESS_REGISTER_D) && (Fadt->Century < 0x80)\r
       ) {\r
-    mModuleGlobal.CenturyRtcAddress = Fadt->Century;\r
+    return Fadt->Century;\r
+  } else {\r
+    return 0;\r
+  }\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_TIME            Time;\r
+  UINT8               CenturyRtcAddress;\r
+  UINT8               Century;\r
+\r
+  CenturyRtcAddress = GetCenturyRtcAddress ();\r
+  if ((CenturyRtcAddress != 0) && (mModuleGlobal.CenturyRtcAddress != CenturyRtcAddress)) {\r
+    mModuleGlobal.CenturyRtcAddress = CenturyRtcAddress;\r
     Status = PcRtcGetTime (&Time, NULL, &mModuleGlobal);\r
     if (!EFI_ERROR (Status)) {\r
       Century = (UINT8) (Time.Year / 100);\r