]> git.proxmox.com Git - mirror_edk2.git/blobdiff - PcAtChipsetPkg/PcatRealTimeClockRuntimeDxe/PcRtc.c
ShellPkg: Add extended USB decoding for consistent device names
[mirror_edk2.git] / PcAtChipsetPkg / PcatRealTimeClockRuntimeDxe / PcRtc.c
index 6c7e0ca6d77517f33efaa4d9f233ae99766fa7c4..a77009a21765299e6e9160ed7993367652a21071 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   RTC Architectural Protocol GUID as defined in DxeCis 0.96.\r
 \r
-Copyright (c) 2006 - 2007, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2006 - 2014, 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
@@ -141,6 +141,11 @@ PcRtcInit (
   //\r
   Status = RtcWaitToUpdate (PcdGet32 (PcdRealTimeClockUpdateTimeout));\r
   if (EFI_ERROR (Status)) {\r
+    //\r
+    // Set the variable with default value if the RTC is functioning incorrectly.\r
+    //\r
+    Global->SavedTimeZone = EFI_UNSPECIFIED_TIMEZONE;\r
+    Global->Daylight      = 0;\r
     if (!EfiAtRuntime ()) {\r
       EfiReleaseLock (&Global->RtcLock);\r
     }\r
@@ -199,6 +204,13 @@ PcRtcInit (
     Status = RtcTimeFieldsValid (&Time);\r
   }\r
   if (EFI_ERROR (Status)) {\r
+    //\r
+    // Report Status Code to indicate that the RTC has bad date and time\r
+    //\r
+    REPORT_STATUS_CODE (\r
+      EFI_ERROR_CODE | EFI_ERROR_MINOR,\r
+      (EFI_SOFTWARE_DXE_RT_DRIVER | EFI_SW_EC_BAD_DATE_TIME)\r
+      );\r
     Time.Second = RTC_INIT_SECOND;\r
     Time.Minute = RTC_INIT_MINUTE;\r
     Time.Hour   = RTC_INIT_HOUR;\r
@@ -206,6 +218,8 @@ PcRtcInit (
     Time.Month  = RTC_INIT_MONTH;\r
     Time.Year   = RTC_INIT_YEAR;\r
     Time.Nanosecond  = 0;\r
+    Time.TimeZone = EFI_UNSPECIFIED_TIMEZONE;\r
+    Time.Daylight = 0;\r
   }\r
 \r
   //\r
@@ -378,6 +392,26 @@ PcRtcSetTime (
      }\r
     return Status;\r
   }\r
+  \r
+  //\r
+  // Write timezone and daylight to RTC variable\r
+  //\r
+  TimerVar = Time->Daylight;\r
+  TimerVar = (UINT32) ((TimerVar << 16) | (UINT16)(Time->TimeZone));\r
+  Status =  EfiSetVariable (\r
+              L"RTC",\r
+              &gEfiCallerIdGuid,\r
+              EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,\r
+              sizeof (TimerVar),\r
+              &TimerVar\r
+              );\r
+  if (EFI_ERROR (Status)) {\r
+    if (!EfiAtRuntime ()) {\r
+      EfiReleaseLock (&Global->RtcLock);\r
+    }\r
+    return EFI_DEVICE_ERROR;\r
+  }\r
+\r
   //\r
   // Read Register B, and inhibit updates of the RTC\r
   //\r
@@ -413,17 +447,6 @@ PcRtcSetTime (
   Global->SavedTimeZone = Time->TimeZone;\r
   Global->Daylight      = Time->Daylight;\r
 \r
-  TimerVar = Time->Daylight;\r
-  TimerVar = (UINT32) ((TimerVar << 16) | Time->TimeZone);\r
-  Status =  EfiSetVariable (\r
-              L"RTC",\r
-              &gEfiCallerIdGuid,\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
@@ -455,6 +478,8 @@ PcRtcGetWakeupTime (
   RTC_REGISTER_B  RegisterB;\r
   RTC_REGISTER_C  RegisterC;\r
   UINT8           Century;\r
+  EFI_TIME        RtcTime;\r
+  UINTN           DataSize;\r
 \r
   //\r
   // Check parameters for null pointers\r
@@ -489,36 +514,45 @@ PcRtcGetWakeupTime (
   // Get the Time/Date/Daylight Savings values.\r
   //\r
   *Enabled = RegisterB.Bits.Aie;\r
-  if (*Enabled) {\r
-    Time->Second  = RtcRead (RTC_ADDRESS_SECONDS_ALARM);\r
-    Time->Minute  = RtcRead (RTC_ADDRESS_MINUTES_ALARM);\r
-    Time->Hour    = RtcRead (RTC_ADDRESS_HOURS_ALARM);\r
-    Time->Day     = RtcRead (RTC_ADDRESS_DAY_OF_THE_MONTH);\r
-    Time->Month   = RtcRead (RTC_ADDRESS_MONTH);\r
-    Time->Year    = RtcRead (RTC_ADDRESS_YEAR);\r
-  } else {\r
-    Time->Second  = 0;\r
-    Time->Minute  = 0;\r
-    Time->Hour    = 0;\r
-    Time->Day     = RtcRead (RTC_ADDRESS_DAY_OF_THE_MONTH);\r
-    Time->Month   = RtcRead (RTC_ADDRESS_MONTH);\r
-    Time->Year    = RtcRead (RTC_ADDRESS_YEAR);\r
-  }\r
+  *Pending = RegisterC.Bits.Af;\r
+\r
+  Time->Second = RtcRead (RTC_ADDRESS_SECONDS_ALARM);\r
+  Time->Minute = RtcRead (RTC_ADDRESS_MINUTES_ALARM);\r
+  Time->Hour   = RtcRead (RTC_ADDRESS_HOURS_ALARM);\r
+  Time->Day    = RtcRead (RTC_ADDRESS_DAY_OF_THE_MONTH);\r
+  Time->Month  = RtcRead (RTC_ADDRESS_MONTH);\r
+  Time->Year   = RtcRead (RTC_ADDRESS_YEAR);\r
+  Time->TimeZone = Global->SavedTimeZone;\r
+  Time->Daylight = Global->Daylight;\r
 \r
   Century = RtcRead (RTC_ADDRESS_CENTURY);\r
-  \r
+\r
   //\r
-  // Release RTC Lock.\r
+  // Get the alarm info from variable\r
   //\r
-  if (!EfiAtRuntime ()) {\r
-    EfiReleaseLock (&Global->RtcLock);\r
+  DataSize = sizeof (EFI_TIME);\r
+  Status = EfiGetVariable (\r
+              L"RTCALARM",\r
+              &gEfiCallerIdGuid,\r
+              NULL,\r
+              &DataSize,\r
+              &RtcTime\r
+              );\r
+  if (!EFI_ERROR (Status)) {\r
+    //\r
+    // The alarm variable exists. In this case, we read variable to get info.\r
+    //\r
+    Time->Day   = RtcTime.Day;\r
+    Time->Month = RtcTime.Month;\r
+    Time->Year  = RtcTime.Year;\r
   }\r
 \r
   //\r
-  // Get the variable that contains the TimeZone and Daylight fields\r
+  // Release RTC Lock.\r
   //\r
-  Time->TimeZone  = Global->SavedTimeZone;\r
-  Time->Daylight  = Global->Daylight;\r
+  if (!EfiAtRuntime ()) {\r
+    EfiReleaseLock (&Global->RtcLock);\r
+  }\r
 \r
   //\r
   // Make sure all field values are in correct range\r
@@ -531,8 +565,6 @@ PcRtcGetWakeupTime (
     return EFI_DEVICE_ERROR;\r
   }\r
 \r
-  *Pending = RegisterC.Bits.Af;\r
-\r
   return EFI_SUCCESS;\r
 }\r
 \r
@@ -564,6 +596,8 @@ PcRtcSetWakeupTime (
   UINT8                 Century;\r
   EFI_TIME_CAPABILITIES Capabilities;\r
 \r
+  ZeroMem (&RtcTime, sizeof (RtcTime));\r
+\r
   if (Enable) {\r
 \r
     if (Time == NULL) {\r
@@ -610,16 +644,50 @@ PcRtcSetWakeupTime (
     return EFI_DEVICE_ERROR;\r
   }\r
   //\r
-  // Read Register B, and inhibit updates of the RTC\r
+  // Read Register B\r
   //\r
-  RegisterB.Data      = RtcRead (RTC_ADDRESS_REGISTER_B);\r
+  RegisterB.Data = RtcRead (RTC_ADDRESS_REGISTER_B);\r
 \r
+  if (Enable) {\r
+    ConvertEfiTimeToRtcTime (&RtcTime, RegisterB, &Century);\r
+  } else {\r
+    //\r
+    // if the alarm is disable, record the current setting.\r
+    //\r
+    RtcTime.Second  = RtcRead (RTC_ADDRESS_SECONDS_ALARM);\r
+    RtcTime.Minute  = RtcRead (RTC_ADDRESS_MINUTES_ALARM);\r
+    RtcTime.Hour    = RtcRead (RTC_ADDRESS_HOURS_ALARM);\r
+    RtcTime.Day     = RtcRead (RTC_ADDRESS_DAY_OF_THE_MONTH);\r
+    RtcTime.Month   = RtcRead (RTC_ADDRESS_MONTH);\r
+    RtcTime.Year    = RtcRead (RTC_ADDRESS_YEAR);\r
+    RtcTime.TimeZone = Global->SavedTimeZone;\r
+    RtcTime.Daylight = Global->Daylight;\r
+  }\r
+\r
+  //\r
+  // Set the Y/M/D info to variable as it has no corresponding hw registers.\r
+  //\r
+  Status =  EfiSetVariable (\r
+              L"RTCALARM",\r
+              &gEfiCallerIdGuid,\r
+              EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,\r
+              sizeof (RtcTime),\r
+              &RtcTime\r
+              );\r
+  if (EFI_ERROR (Status)) {\r
+    if (!EfiAtRuntime ()) {\r
+      EfiReleaseLock (&Global->RtcLock);\r
+    }\r
+    return EFI_DEVICE_ERROR;\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
   if (Enable) {\r
-    ConvertEfiTimeToRtcTime (&RtcTime, RegisterB, &Century);\r
-\r
     //\r
     // Set RTC alarm time\r
     //\r