]> git.proxmox.com Git - mirror_edk2.git/blobdiff - PcAtChipsetPkg/PcatRealTimeClockRuntimeDxe/PcRtc.c
BaseTools: Fixed an error reported during generating report.
[mirror_edk2.git] / PcAtChipsetPkg / PcatRealTimeClockRuntimeDxe / PcRtc.c
index 882f2ea8cd1ebbde69bdf54b60105a31e9449e65..23f8d3b56f591a5c8654317372f5b25d54dea266 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   RTC Architectural Protocol GUID as defined in DxeCis 0.96.\r
 \r
-Copyright (c) 2006 - 2010, 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
@@ -104,6 +104,8 @@ PcRtcInit (
   EFI_TIME        Time;\r
   UINTN           DataSize;\r
   UINT32          TimerVar;\r
+  BOOLEAN         Enabled;\r
+  BOOLEAN         Pending;\r
 \r
   //\r
   // Acquire RTC Lock to make access to RTC atomic\r
@@ -141,6 +143,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 +206,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,17 +220,104 @@ 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
   // Reset time value according to new RTC configuration\r
   //\r
   Status = PcRtcSetTime (&Time, Global);\r
-  if(!EFI_ERROR (Status)) {\r
+  if (EFI_ERROR (Status)) {\r
+    return EFI_DEVICE_ERROR;\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
+  // so we can use them to get and set wakeup time.\r
+  //\r
+  Status = PcRtcGetWakeupTime (&Enabled, &Pending, &Time, Global);\r
+  if ((Enabled) || (!EFI_ERROR (Status))) {\r
     return EFI_SUCCESS;\r
-  } else {\r
+  }\r
+  \r
+  //\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
+  Time.Minute = RTC_INIT_MINUTE;\r
+  Time.Hour   = RTC_INIT_HOUR;\r
+  Time.Day    = RTC_INIT_DAY;\r
+  Time.Month  = RTC_INIT_MONTH;\r
+  Time.Year   = RTC_INIT_YEAR;\r
+  Time.Nanosecond  = 0;\r
+  Time.TimeZone = Global->SavedTimeZone;\r
+  Time.Daylight = Global->Daylight;;\r
+\r
+  //\r
+  // Acquire RTC Lock to make access to RTC atomic\r
+  //\r
+  if (!EfiAtRuntime ()) {\r
+    EfiAcquireLock (&Global->RtcLock);\r
+  }\r
+  //\r
+  // Wait for up to 0.1 seconds for the RTC to be updated\r
+  //\r
+  Status = RtcWaitToUpdate (PcdGet32 (PcdRealTimeClockUpdateTimeout));\r
+  if (EFI_ERROR (Status)) {\r
+    if (!EfiAtRuntime ()) {\r
+    EfiReleaseLock (&Global->RtcLock);\r
+    }\r
     return EFI_DEVICE_ERROR;\r
   }\r
+  \r
+  ConvertEfiTimeToRtcTime (&Time, RegisterB, &Century);\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 (Time),\r
+              &Time\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
+  //\r
+  // Set RTC alarm time registers\r
+  //\r
+  RtcWrite (RTC_ADDRESS_SECONDS_ALARM, Time.Second);\r
+  RtcWrite (RTC_ADDRESS_MINUTES_ALARM, Time.Minute);\r
+  RtcWrite (RTC_ADDRESS_HOURS_ALARM, Time.Hour);\r
+\r
+  //\r
+  // Allow updates of the RTC registers\r
+  //\r
+  RegisterB.Bits.Set = 0;\r
+  RtcWrite (RTC_ADDRESS_REGISTER_B, RegisterB.Data);\r
\r
+  //\r
+  // Release RTC Lock.\r
+  //\r
+  if (!EfiAtRuntime ()) {\r
+    EfiReleaseLock (&Global->RtcLock);\r
+  }\r
+  return EFI_SUCCESS;\r
 }\r
 \r
 /**\r
@@ -378,6 +479,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 +534,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
@@ -507,6 +617,7 @@ PcRtcGetWakeupTime (
   //\r
   // Get the alarm info from variable\r
   //\r
+  DataSize = sizeof (EFI_TIME);\r
   Status = EfiGetVariable (\r
               L"RTCALARM",\r
               &gEfiCallerIdGuid,\r
@@ -620,27 +731,13 @@ 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
-\r
-  RegisterB.Bits.Set  = 1;\r
-  RtcWrite (RTC_ADDRESS_REGISTER_B, RegisterB.Data);\r
+  RegisterB.Data = RtcRead (RTC_ADDRESS_REGISTER_B);\r
 \r
   if (Enable) {\r
     ConvertEfiTimeToRtcTime (&RtcTime, RegisterB, &Century);\r
-\r
-    //\r
-    // Set RTC alarm time\r
-    //\r
-    RtcWrite (RTC_ADDRESS_SECONDS_ALARM, RtcTime.Second);\r
-    RtcWrite (RTC_ADDRESS_MINUTES_ALARM, RtcTime.Minute);\r
-    RtcWrite (RTC_ADDRESS_HOURS_ALARM, RtcTime.Hour);\r
-\r
-    RegisterB.Bits.Aie = 1;\r
-\r
   } else {\r
-    RegisterB.Bits.Aie = 0;\r
     //\r
     // if the alarm is disable, record the current setting.\r
     //\r
@@ -653,11 +750,6 @@ PcRtcSetWakeupTime (
     RtcTime.TimeZone = Global->SavedTimeZone;\r
     RtcTime.Daylight = Global->Daylight;\r
   }\r
-  //\r
-  // Allow updates of the RTC registers\r
-  //\r
-  RegisterB.Bits.Set = 0;\r
-  RtcWrite (RTC_ADDRESS_REGISTER_B, RegisterB.Data);\r
 \r
   //\r
   // Set the Y/M/D info to variable as it has no corresponding hw registers.\r
@@ -670,8 +762,36 @@ PcRtcSetWakeupTime (
               &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
+    //\r
+    // Set RTC alarm time\r
+    //\r
+    RtcWrite (RTC_ADDRESS_SECONDS_ALARM, RtcTime.Second);\r
+    RtcWrite (RTC_ADDRESS_MINUTES_ALARM, RtcTime.Minute);\r
+    RtcWrite (RTC_ADDRESS_HOURS_ALARM, RtcTime.Hour);\r
+\r
+    RegisterB.Bits.Aie = 1;\r
+\r
+  } else {\r
+    RegisterB.Bits.Aie = 0;\r
+  }\r
+  //\r
+  // Allow updates of the RTC registers\r
+  //\r
+  RegisterB.Bits.Set = 0;\r
+  RtcWrite (RTC_ADDRESS_REGISTER_B, RegisterB.Data);\r
 \r
   //\r
   // Release RTC Lock.\r
@@ -835,8 +955,8 @@ RtcTimeFieldsValid (
   IN EFI_TIME *Time\r
   )\r
 {\r
-  if (Time->Year < 1998 ||\r
-      Time->Year > 2099 ||\r
+  if (Time->Year < PcdGet16 (PcdMinimalValidYear) ||\r
+      Time->Year > PcdGet16 (PcdMaximalValidYear) ||\r
       Time->Month < 1 ||\r
       Time->Month > 12 ||\r
       (!DayValid (Time)) ||\r