]> git.proxmox.com Git - mirror_edk2.git/blobdiff - PcAtChipsetPkg/PcatRealTimeClockRuntimeDxe/PcRtc.c
Program SD Cards into 4-bit mode (support for this is required in the spec). This...
[mirror_edk2.git] / PcAtChipsetPkg / PcatRealTimeClockRuntimeDxe / PcRtc.c
index d26e92360584ed3ecb4058eaa1b2e7e8c12e955c..659c01e57a7f0a464c2e872c81812e5d81bd7da9 100644 (file)
@@ -1,8 +1,8 @@
 /** @file\r
   RTC Architectural Protocol GUID as defined in DxeCis 0.96.\r
 \r
 /** @file\r
   RTC Architectural Protocol GUID as defined in DxeCis 0.96.\r
 \r
-Copyright (c) 2006 - 2007, Intel Corporation\r
-All rights reserved. This program and the accompanying materials\r
+Copyright (c) 2006 - 2007, 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
 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
@@ -108,7 +108,6 @@ PcRtcInit (
   //\r
   // Acquire RTC Lock to make access to RTC atomic\r
   //\r
   //\r
   // Acquire RTC Lock to make access to RTC atomic\r
   //\r
-  //Code here doesn't consider the runtime environment.\r
   if (!EfiAtRuntime ()) {\r
     EfiAcquireLock (&Global->RtcLock);\r
   }\r
   if (!EfiAtRuntime ()) {\r
     EfiAcquireLock (&Global->RtcLock);\r
   }\r
@@ -142,7 +141,6 @@ PcRtcInit (
   //\r
   Status = RtcWaitToUpdate (PcdGet32 (PcdRealTimeClockUpdateTimeout));\r
   if (EFI_ERROR (Status)) {\r
   //\r
   Status = RtcWaitToUpdate (PcdGet32 (PcdRealTimeClockUpdateTimeout));\r
   if (EFI_ERROR (Status)) {\r
-    //Code here doesn't consider the runtime environment.\r
     if (!EfiAtRuntime ()) {\r
       EfiReleaseLock (&Global->RtcLock);\r
     }\r
     if (!EfiAtRuntime ()) {\r
       EfiReleaseLock (&Global->RtcLock);\r
     }\r
@@ -169,11 +167,30 @@ PcRtcInit (
   //\r
   // Release RTC Lock.\r
   //\r
   //\r
   // Release RTC Lock.\r
   //\r
-  //Code here doesn't consider the runtime environment.\r
   if (!EfiAtRuntime ()) {\r
     EfiReleaseLock (&Global->RtcLock);\r
   }\r
  \r
   if (!EfiAtRuntime ()) {\r
     EfiReleaseLock (&Global->RtcLock);\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
+  //\r
+  DataSize = sizeof (UINT32);\r
+  Status = EfiGetVariable (\r
+             L"RTC",\r
+             &gEfiCallerIdGuid,\r
+             NULL,\r
+             &DataSize,\r
+             (VOID *) &TimerVar\r
+             );\r
+  if (!EFI_ERROR (Status)) {\r
+    Time.TimeZone = (INT16) TimerVar;\r
+    Time.Daylight = (UINT8) (TimerVar >> 16);\r
+  } else {\r
+    Time.TimeZone = EFI_UNSPECIFIED_TIMEZONE;\r
+    Time.Daylight = 0;  \r
+  }\r
+\r
   //\r
   // Validate time fields\r
   //\r
   //\r
   // Validate time fields\r
   //\r
@@ -188,32 +205,18 @@ PcRtcInit (
     Time.Day    = RTC_INIT_DAY;\r
     Time.Month  = RTC_INIT_MONTH;\r
     Time.Year   = RTC_INIT_YEAR;\r
     Time.Day    = RTC_INIT_DAY;\r
     Time.Month  = RTC_INIT_MONTH;\r
     Time.Year   = RTC_INIT_YEAR;\r
+    Time.Nanosecond  = 0;\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
-  //\r
-  DataSize = sizeof (UINT32);\r
-  Status = EfiGetVariable (\r
-             L"RTC",\r
-             &gEfiCallerIdGuid,\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
 \r
-    Time.TimeZone = Global->SavedTimeZone;\r
-    Time.Daylight = Global->Daylight;\r
-  }\r
   //\r
   // Reset time value according to new RTC configuration\r
   //\r
   //\r
   // Reset time value according to new RTC configuration\r
   //\r
-  PcRtcSetTime (&Time, Global);\r
-\r
-  return EFI_SUCCESS;\r
+  Status = PcRtcSetTime (&Time, Global);\r
+  if(!EFI_ERROR (Status)) {\r
+    return EFI_SUCCESS;\r
+  } else {\r
+    return EFI_DEVICE_ERROR;\r
+  }\r
 }\r
 \r
 /**\r
 }\r
 \r
 /**\r
@@ -251,7 +254,6 @@ PcRtcGetTime (
   //\r
   // Acquire RTC Lock to make access to RTC atomic\r
   //\r
   //\r
   // Acquire RTC Lock to make access to RTC atomic\r
   //\r
-  //Code here doesn't consider the runtime environment.\r
   if (!EfiAtRuntime ()) {\r
     EfiAcquireLock (&Global->RtcLock);\r
   }\r
   if (!EfiAtRuntime ()) {\r
     EfiAcquireLock (&Global->RtcLock);\r
   }\r
@@ -260,7 +262,6 @@ PcRtcGetTime (
   //\r
   Status = RtcWaitToUpdate (PcdGet32 (PcdRealTimeClockUpdateTimeout));\r
   if (EFI_ERROR (Status)) {\r
   //\r
   Status = RtcWaitToUpdate (PcdGet32 (PcdRealTimeClockUpdateTimeout));\r
   if (EFI_ERROR (Status)) {\r
-      //Code here doesn't consider the runtime environment.\r
       if (!EfiAtRuntime ()) {\r
         EfiReleaseLock (&Global->RtcLock);\r
       }\r
       if (!EfiAtRuntime ()) {\r
         EfiReleaseLock (&Global->RtcLock);\r
       }\r
@@ -286,10 +287,10 @@ PcRtcGetTime (
   //\r
   // Release RTC Lock.\r
   //\r
   //\r
   // Release RTC Lock.\r
   //\r
-  //Code here doesn't consider the runtime environment.\r
   if (!EfiAtRuntime ()) {\r
     EfiReleaseLock (&Global->RtcLock);\r
   }\r
   if (!EfiAtRuntime ()) {\r
     EfiReleaseLock (&Global->RtcLock);\r
   }\r
+\r
   //\r
   // Get the variable that contains the TimeZone and Daylight fields\r
   //\r
   //\r
   // Get the variable that contains the TimeZone and Daylight fields\r
   //\r
@@ -306,6 +307,7 @@ PcRtcGetTime (
   if (EFI_ERROR (Status)) {\r
     return EFI_DEVICE_ERROR;\r
   }\r
   if (EFI_ERROR (Status)) {\r
     return EFI_DEVICE_ERROR;\r
   }\r
+\r
   //\r
   //  Fill in Capabilities if it was passed in\r
   //\r
   //\r
   //  Fill in Capabilities if it was passed in\r
   //\r
@@ -363,7 +365,6 @@ PcRtcSetTime (
   //\r
   // Acquire RTC Lock to make access to RTC atomic\r
   //\r
   //\r
   // Acquire RTC Lock to make access to RTC atomic\r
   //\r
-  //Code here doesn't consider the runtime environment.\r
   if (!EfiAtRuntime ()) {\r
     EfiAcquireLock (&Global->RtcLock);\r
   }\r
   if (!EfiAtRuntime ()) {\r
     EfiAcquireLock (&Global->RtcLock);\r
   }\r
@@ -372,7 +373,6 @@ PcRtcSetTime (
   //\r
   Status = RtcWaitToUpdate (PcdGet32 (PcdRealTimeClockUpdateTimeout));\r
   if (EFI_ERROR (Status)) {\r
   //\r
   Status = RtcWaitToUpdate (PcdGet32 (PcdRealTimeClockUpdateTimeout));\r
   if (EFI_ERROR (Status)) {\r
-     //Code here doesn't consider the runtime environment.\r
      if (!EfiAtRuntime ()) {\r
        EfiReleaseLock (&Global->RtcLock);\r
      }\r
      if (!EfiAtRuntime ()) {\r
        EfiReleaseLock (&Global->RtcLock);\r
      }\r
@@ -404,7 +404,6 @@ PcRtcSetTime (
   //\r
   // Release RTC Lock.\r
   //\r
   //\r
   // Release RTC Lock.\r
   //\r
-  //Code here doesn't consider the runtime environment.\r
   if (!EfiAtRuntime ()) {\r
     EfiReleaseLock (&Global->RtcLock);\r
   }\r
   if (!EfiAtRuntime ()) {\r
     EfiReleaseLock (&Global->RtcLock);\r
   }\r
@@ -467,7 +466,6 @@ PcRtcGetWakeupTime (
   //\r
   // Acquire RTC Lock to make access to RTC atomic\r
   //\r
   //\r
   // Acquire RTC Lock to make access to RTC atomic\r
   //\r
-  //Code here doesn't consider the runtime environment.\r
   if (!EfiAtRuntime ()) {\r
     EfiAcquireLock (&Global->RtcLock);\r
   }\r
   if (!EfiAtRuntime ()) {\r
     EfiAcquireLock (&Global->RtcLock);\r
   }\r
@@ -476,7 +474,6 @@ PcRtcGetWakeupTime (
   //\r
   Status = RtcWaitToUpdate (PcdGet32 (PcdRealTimeClockUpdateTimeout));\r
   if (EFI_ERROR (Status)) {\r
   //\r
   Status = RtcWaitToUpdate (PcdGet32 (PcdRealTimeClockUpdateTimeout));\r
   if (EFI_ERROR (Status)) {\r
-    //Code here doesn't consider the runtime environment.\r
     if (!EfiAtRuntime ()) {\r
     EfiReleaseLock (&Global->RtcLock);\r
     }\r
     if (!EfiAtRuntime ()) {\r
     EfiReleaseLock (&Global->RtcLock);\r
     }\r
@@ -513,10 +510,16 @@ PcRtcGetWakeupTime (
   //\r
   // Release RTC Lock.\r
   //\r
   //\r
   // Release RTC Lock.\r
   //\r
-  //Code here doesn't consider the runtime environment.\r
   if (!EfiAtRuntime ()) {\r
     EfiReleaseLock (&Global->RtcLock);\r
   }\r
   if (!EfiAtRuntime ()) {\r
     EfiReleaseLock (&Global->RtcLock);\r
   }\r
+\r
+  //\r
+  // Get the variable that contains the TimeZone and Daylight fields\r
+  //\r
+  Time->TimeZone  = Global->SavedTimeZone;\r
+  Time->Daylight  = Global->Daylight;\r
+\r
   //\r
   // Make sure all field values are in correct range\r
   //\r
   //\r
   // Make sure all field values are in correct range\r
   //\r
@@ -593,7 +596,6 @@ PcRtcSetWakeupTime (
   //\r
   // Acquire RTC Lock to make access to RTC atomic\r
   //\r
   //\r
   // Acquire RTC Lock to make access to RTC atomic\r
   //\r
-  //Code here doesn't consider the runtime environment.\r
   if (!EfiAtRuntime ()) {\r
     EfiAcquireLock (&Global->RtcLock);\r
   }\r
   if (!EfiAtRuntime ()) {\r
     EfiAcquireLock (&Global->RtcLock);\r
   }\r
@@ -602,7 +604,6 @@ PcRtcSetWakeupTime (
   //\r
   Status = RtcWaitToUpdate (PcdGet32 (PcdRealTimeClockUpdateTimeout));\r
   if (EFI_ERROR (Status)) {\r
   //\r
   Status = RtcWaitToUpdate (PcdGet32 (PcdRealTimeClockUpdateTimeout));\r
   if (EFI_ERROR (Status)) {\r
-    //Code here doesn't consider the runtime environment.\r
     if (!EfiAtRuntime ()) {\r
     EfiReleaseLock (&Global->RtcLock);\r
     }\r
     if (!EfiAtRuntime ()) {\r
     EfiReleaseLock (&Global->RtcLock);\r
     }\r
@@ -640,7 +641,6 @@ PcRtcSetWakeupTime (
   //\r
   // Release RTC Lock.\r
   //\r
   //\r
   // Release RTC Lock.\r
   //\r
-  //Code here doesn't consider the runtime environment.\r
   if (!EfiAtRuntime ()) {\r
     EfiReleaseLock (&Global->RtcLock);\r
   }\r
   if (!EfiAtRuntime ()) {\r
     EfiReleaseLock (&Global->RtcLock);\r
   }\r
@@ -739,8 +739,6 @@ ConvertRtcTimeToEfiTime (
   }\r
 \r
   Time->Nanosecond  = 0;\r
   }\r
 \r
   Time->Nanosecond  = 0;\r
-  Time->TimeZone    = EFI_UNSPECIFIED_TIMEZONE;\r
-  Time->Daylight    = 0;\r
 \r
   return EFI_SUCCESS;\r
 }\r
 \r
   return EFI_SUCCESS;\r
 }\r
@@ -806,16 +804,14 @@ RtcTimeFieldsValid (
       Time->Year > 2099 ||\r
       Time->Month < 1 ||\r
       Time->Month > 12 ||\r
       Time->Year > 2099 ||\r
       Time->Month < 1 ||\r
       Time->Month > 12 ||\r
+      (!DayValid (Time)) ||\r
       Time->Hour > 23 ||\r
       Time->Minute > 59 ||\r
       Time->Second > 59 ||\r
       Time->Nanosecond > 999999999 ||\r
       (!(Time->TimeZone == EFI_UNSPECIFIED_TIMEZONE || (Time->TimeZone >= -1440 && Time->TimeZone <= 1440))) ||\r
       Time->Hour > 23 ||\r
       Time->Minute > 59 ||\r
       Time->Second > 59 ||\r
       Time->Nanosecond > 999999999 ||\r
       (!(Time->TimeZone == EFI_UNSPECIFIED_TIMEZONE || (Time->TimeZone >= -1440 && Time->TimeZone <= 1440))) ||\r
-      ((Time->Daylight & (~(EFI_TIME_ADJUST_DAYLIGHT | EFI_TIME_IN_DAYLIGHT))) != 0)\r
-      ) {\r
-    if (!DayValid (Time)) {\r
-      return EFI_INVALID_PARAMETER;\r
-    }\r
+      ((Time->Daylight & (~(EFI_TIME_ADJUST_DAYLIGHT | EFI_TIME_IN_DAYLIGHT))) != 0)) {\r
+    return EFI_INVALID_PARAMETER;\r
   }\r
 \r
   return EFI_SUCCESS;\r
   }\r
 \r
   return EFI_SUCCESS;\r