]> git.proxmox.com Git - mirror_edk2.git/blobdiff - PcAtChipsetPkg/PcatRealTimeClockRuntimeDxe/PcRtc.c
BaseTools: Library hashing fix and optimization for --hash feature
[mirror_edk2.git] / PcAtChipsetPkg / PcatRealTimeClockRuntimeDxe / PcRtc.c
index 5143575e311f9e4d11d222e83e8c45f96afee4cf..8b68b0f19252fecd171fc4b71fc24b6b6a67c4c5 100644 (file)
@@ -1,14 +1,10 @@
 /** @file\r
   RTC Architectural Protocol GUID as defined in DxeCis 0.96.\r
 \r
-Copyright (c) 2006 - 2016, 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
-http://opensource.org/licenses/bsd-license.php\r
+Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2017, AMD Inc. All rights reserved.<BR>\r
 \r
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
 **/\r
 \r
@@ -26,7 +22,7 @@ CHAR16 mTimeZoneVariableName[] = L"RTC";
 \r
 /**\r
   Compare the Hour, Minute and Second of the From time and the To time.\r
-  \r
+\r
   Only compare H/M/S in EFI_TIME and ignore other fields here.\r
 \r
   @param From   the first time\r
@@ -70,8 +66,8 @@ RtcRead (
   IN  UINT8 Address\r
   )\r
 {\r
-  IoWrite8 (PCAT_RTC_ADDRESS_REGISTER, (UINT8) (Address | (UINT8) (IoRead8 (PCAT_RTC_ADDRESS_REGISTER) & 0x80)));\r
-  return IoRead8 (PCAT_RTC_DATA_REGISTER);\r
+  IoWrite8 (PcdGet8 (PcdRtcIndexRegister), (UINT8) (Address | (UINT8) (IoRead8 (PcdGet8 (PcdRtcIndexRegister)) & 0x80)));\r
+  return IoRead8 (PcdGet8 (PcdRtcTargetRegister));\r
 }\r
 \r
 /**\r
@@ -88,8 +84,8 @@ RtcWrite (
   IN  UINT8   Data\r
   )\r
 {\r
-  IoWrite8 (PCAT_RTC_ADDRESS_REGISTER, (UINT8) (Address | (UINT8) (IoRead8 (PCAT_RTC_ADDRESS_REGISTER) & 0x80)));\r
-  IoWrite8 (PCAT_RTC_DATA_REGISTER, Data);\r
+  IoWrite8 (PcdGet8 (PcdRtcIndexRegister), (UINT8) (Address | (UINT8) (IoRead8 (PcdGet8 (PcdRtcIndexRegister)) & 0x80)));\r
+  IoWrite8 (PcdGet8 (PcdRtcTargetRegister), Data);\r
 }\r
 \r
 /**\r
@@ -128,7 +124,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 +140,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 +172,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
@@ -185,7 +181,7 @@ PcRtcInit (
   if (!EfiAtRuntime ()) {\r
     EfiReleaseLock (&Global->RtcLock);\r
   }\r
\r
+\r
   //\r
   // Get the data of Daylight saving and time zone, if they have been\r
   // stored in NV variable during previous boot.\r
@@ -203,7 +199,7 @@ PcRtcInit (
     Time.Daylight = (UINT8) (TimerVar >> 16);\r
   } else {\r
     Time.TimeZone = EFI_UNSPECIFIED_TIMEZONE;\r
-    Time.Daylight = 0;  \r
+    Time.Daylight = 0;\r
   }\r
 \r
   //\r
@@ -239,7 +235,7 @@ PcRtcInit (
   if (EFI_ERROR (Status)) {\r
     return EFI_DEVICE_ERROR;\r
   }\r
-  \r
+\r
   //\r
   // Reset wakeup time value to valid state when wakeup alarm is disabled and wakeup time is invalid.\r
   // Global variable has already had valid SavedTimeZone and Daylight,\r
@@ -249,9 +245,9 @@ PcRtcInit (
   if ((Enabled) || (!EFI_ERROR (Status))) {\r
     return EFI_SUCCESS;\r
   }\r
-  \r
+\r
   //\r
-  // When wakeup time is disabled and invalid, reset wakeup time register to valid state \r
+  // When wakeup time is disabled and invalid, reset wakeup time register to valid state\r
   // but keep wakeup alarm disabled.\r
   //\r
   Time.Second = RTC_INIT_SECOND;\r
@@ -299,13 +295,13 @@ PcRtcInit (
     }\r
     return EFI_DEVICE_ERROR;\r
   }\r
-  \r
+\r
   //\r
   // Inhibit updates of the RTC\r
   //\r
   RegisterB.Bits.Set  = 1;\r
   RtcWrite (RTC_ADDRESS_REGISTER_B, RegisterB.Data);\r
\r
+\r
   //\r
   // Set RTC alarm time registers\r
   //\r
@@ -318,7 +314,7 @@ PcRtcInit (
   //\r
   RegisterB.Bits.Set = 0;\r
   RtcWrite (RTC_ADDRESS_REGISTER_B, RegisterB.Data);\r
\r
+\r
   //\r
   // Release RTC Lock.\r
   //\r
@@ -483,7 +479,7 @@ PcRtcSetTime (
      }\r
     return Status;\r
   }\r
-  \r
+\r
   //\r
   // Write timezone and daylight to RTC variable\r
   //\r
@@ -787,7 +783,7 @@ PcRtcSetWakeupTime (
     }\r
     return EFI_DEVICE_ERROR;\r
   }\r
-  \r
+\r
   //\r
   // Inhibit updates of the RTC\r
   //\r
@@ -930,7 +926,7 @@ ConvertRtcTimeToEfiTime (
   @param    Timeout  Tell how long it should take to wait.\r
 \r
   @retval   EFI_DEVICE_ERROR   RTC device error.\r
-  @retval   EFI_SUCCESS        RTC is updated and ready.  \r
+  @retval   EFI_SUCCESS        RTC is updated and ready.\r
 **/\r
 EFI_STATUS\r
 RtcWaitToUpdate (\r
@@ -1111,7 +1107,7 @@ ConvertEfiTimeToRtcTime (
 \r
 /**\r
   Compare the Hour, Minute and Second of the From time and the To time.\r
-  \r
+\r
   Only compare H/M/S in EFI_TIME and ignore other fields here.\r
 \r
   @param From   the first time\r
@@ -1162,7 +1158,7 @@ IsWithinOneDay (
   //\r
   ASSERT (From->Month >=1);\r
   ASSERT (From->Month <=12);\r
-  \r
+\r
   if (From->Year == To->Year) {\r
     if (From->Month == To->Month) {\r
       if ((From->Day + 1) == To->Day) {\r
@@ -1201,41 +1197,28 @@ IsWithinOneDay (
 }\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
+  Get the century RTC address from the ACPI FADT table.\r
 \r
-  @return ACPI table or NULL if not found.\r
+  @return  The century RTC address or 0 if not found.\r
 **/\r
-VOID *\r
-ScanTableInSDT (\r
-  IN EFI_ACPI_DESCRIPTION_HEADER    *Sdt,\r
-  IN UINT32                         Signature,\r
-  IN UINTN                          TablePointerSize\r
+UINT8\r
+GetCenturyRtcAddress (\r
+  VOID\r
   )\r
 {\r
-  UINTN                          Index;\r
-  UINTN                          EntryCount;\r
-  UINTN                          EntryBase;\r
-  EFI_ACPI_DESCRIPTION_HEADER    *Table;\r
+  EFI_ACPI_2_0_FIXED_ACPI_DESCRIPTION_TABLE     *Fadt;\r
 \r
-  EntryCount = (Sdt->Length - sizeof (EFI_ACPI_DESCRIPTION_HEADER)) / TablePointerSize;\r
+  Fadt = (EFI_ACPI_2_0_FIXED_ACPI_DESCRIPTION_TABLE *) EfiLocateFirstAcpiTable (\r
+                                                         EFI_ACPI_2_0_FIXED_ACPI_DESCRIPTION_TABLE_SIGNATURE\r
+                                                         );\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
+  if ((Fadt != NULL) &&\r
+      (Fadt->Century > RTC_ADDRESS_REGISTER_D) && (Fadt->Century < 0x80)\r
+      ) {\r
+    return Fadt->Century;\r
+  } else {\r
+    return 0;\r
   }\r
-\r
-  return NULL;\r
 }\r
 \r
 /**\r
@@ -1255,47 +1238,14 @@ PcRtcAcpiTableChangeCallback (
   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
-  ASSERT (Rsdp != 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
-  }\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
+  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