]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/PcatRealTimeClockRuntimeDxe/PcRtc.c
edk2/EdkCompatibilityPkg/Foundation/Library/EdkIIGlueLib/Library/PeiMemoryAllocationL...
[mirror_edk2.git] / MdeModulePkg / Universal / PcatRealTimeClockRuntimeDxe / PcRtc.c
index e9bd801baaeb40f8d4f03c56a5d0d84e54c2ec91..c9bf401e1c214270fd4f35e335ffc9375468ab5d 100644 (file)
@@ -1,6 +1,7 @@
-/*++\r
+/** @file\r
+  RTC Architectural Protocol GUID as defined in DxeCis 0.96.\r
 \r
-Copyright (c) 2006 - 2007 Intel Corporation. <BR>\r
+Copyright (c) 2006 - 2007, Intel Corporation\r
 All rights reserved. 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
@@ -9,17 +10,7 @@ http://opensource.org/licenses/bsd-license.php
 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
 \r
-\r
-\r
-Module Name:\r
-\r
-  PcRtc.c\r
-\r
-Abstract:\r
-\r
-  RTC Architectural Protocol GUID as defined in DxeCis 0.96\r
-\r
---*/\r
+**/\r
 \r
 #include "PcRtc.h"\r
 \r
@@ -116,6 +107,8 @@ Returns:
   RTC_REGISTER_D  RegisterD;\r
   UINT8           Century;\r
   EFI_TIME        Time;\r
+  UINTN           DataSize;\r
+  UINT32          TimerVar;\r
 \r
   //\r
   // Acquire RTC Lock to make access to RTC atomic\r
@@ -184,8 +177,9 @@ Returns:
 \r
   //\r
   // Set RTC configuration after get original time\r
+  // The value of bit AIE should be reserved.\r
   //\r
-  RtcWrite (RTC_ADDRESS_REGISTER_B, RTC_INIT_REGISTER_B);\r
+  RtcWrite (RTC_ADDRESS_REGISTER_B, (UINT8)(RTC_INIT_REGISTER_B | (RegisterB.Data & BIT5)));\r
 \r
   //\r
   // Release RTC Lock.\r
@@ -208,6 +202,25 @@ Returns:
     Time.Year   = RTC_INIT_YEAR;\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
+  //\r
+  DataSize = sizeof (UINT32);\r
+  Status = EfiGetVariable (\r
+             L"TimerVar",\r
+             &gEfiGenericPlatformVariableGuid,\r
+             NULL,\r
+             &DataSize,\r
+             (VOID *) &TimerVar\r
+             );\r
+  if (!EFI_ERROR (Status)) {\r
+    Global->SavedTimeZone = (INT16) TimerVar;\r
+    Global->Daylight      = (UINT8) (TimerVar >> 16);\r
+\r
+    Time.TimeZone = Global->SavedTimeZone;\r
+    Time.Daylight = Global->Daylight;\r
+  }\r
+  //\r
   // Reset time value according to new RTC configuration\r
   //\r
   PcRtcSetTime (&Time, Global);\r
@@ -352,6 +365,7 @@ Routine Description:
   EFI_TIME        RtcTime;\r
   RTC_REGISTER_B  RegisterB;\r
   UINT8           Century;\r
+  UINT32          TimerVar;\r
 \r
   if (Time == NULL) {\r
     return EFI_INVALID_PARAMETER;\r
@@ -426,7 +440,19 @@ Routine Description:
   //\r
   Global->SavedTimeZone = Time->TimeZone;\r
   Global->Daylight      = Time->Daylight;\r
-  return Status;\r
+\r
+  TimerVar = Time->Daylight;\r
+  TimerVar = (UINT32) ((TimerVar << 16) | Time->TimeZone);\r
+  Status =  EfiSetVariable (\r
+              L"TimerVar",\r
+              &gEfiGenericPlatformVariableGuid,\r
+              EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,\r
+              sizeof (TimerVar),\r
+              &TimerVar\r
+              );\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  return EFI_SUCCESS;\r
 }\r
 \r
 EFI_STATUS\r
@@ -1029,8 +1055,23 @@ Returns:
 \r
 --*/\r
 {\r
-  UINT8   DayOfMonth[12] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};\r
-  BOOLEAN Adjacent = FALSE;\r
+  UINT8   DayOfMonth[12];\r
+  BOOLEAN Adjacent;\r
+\r
+  DayOfMonth[0] = 31;\r
+  DayOfMonth[1] = 29;\r
+  DayOfMonth[2] = 31;\r
+  DayOfMonth[3] = 30;\r
+  DayOfMonth[4] = 31;\r
+  DayOfMonth[5] = 30;\r
+  DayOfMonth[6] = 31;\r
+  DayOfMonth[7] = 31;\r
+  DayOfMonth[8] = 30;\r
+  DayOfMonth[9] = 31;\r
+  DayOfMonth[10] = 30;\r
+  DayOfMonth[11] = 31;\r
+\r
+  Adjacent = FALSE;\r
 \r
   if (From->Year == To->Year) {\r
     if (From->Month == To->Month) {\r