Set RTC initial time to be BIOS Release time.
authorDavid Wei <david.wei@intel.com>
Thu, 22 Jan 2015 05:50:45 +0000 (05:50 +0000)
committerzwei4 <zwei4@Edk2>
Thu, 22 Jan 2015 05:50:45 +0000 (05:50 +0000)
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: David Wei <david.wei@intel.com>
Reviewed-by: Star Zeng <star.zeng@intel.com>
git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@16639 6f19259b-4bc3-4df7-8a09-765794883524

Vlv2TbltDevicePkg/PlatformDxe/Platform.c
Vlv2TbltDevicePkg/PlatformDxe/PlatformDxe.h
Vlv2TbltDevicePkg/PlatformDxe/PlatformDxe.inf
Vlv2TbltDevicePkg/PlatformDxe/Rtc.c [new file with mode: 0644]

index 0f3a414..760b8b0 100644 (file)
@@ -1,15 +1,24 @@
 /** @file\r
 \r
-  Copyright (c) 2004  - 2014, Intel Corporation. All rights reserved.<BR>\r
-                                                                                   \r\r
-  This program and the accompanying materials are licensed and made available under\r\r
-  the terms and conditions of the BSD License that accompanies this distribution.  \r\r
-  The full text of the license may be found at                                     \r\r
-  http://opensource.org/licenses/bsd-license.php.                                  \r\r
-                                                                                   \r\r
-  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,            \r\r
-  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.    \r\r
-                                                                                   \r\r
+  Copyright (c) 2004  - 2015, Intel Corporation. All rights reserved.<BR>\r
+                                                                                   \r
+\r
+  This program and the accompanying materials are licensed and made available under\r
+\r
+  the terms and conditions of the BSD License that accompanies this distribution.  \r
+\r
+  The full text of the license may be found at                                     \r
+\r
+  http://opensource.org/licenses/bsd-license.php.                                  \r
+\r
+                                                                                   \r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,            \r
+\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.    \r
+\r
+                                                                                   \r
+\r
 \r
 Module Name:\r
 \r
@@ -613,11 +622,11 @@ InitializePlatform (
   EFI_STATUS                          Status;\r
   UINTN                               VarSize;\r
   EFI_HANDLE                          Handle = NULL;\r
-\r
   EFI_EVENT                           mEfiExitBootServicesEvent;\r
-\r
-  //\r
-mImageHandle = ImageHandle;\r
+  EFI_EVENT                           RtcEvent;\r
+  VOID                                *RtcCallbackReg = NULL;\r
+  \r
+  mImageHandle = ImageHandle;\r
 \r
   Status = gBS->InstallProtocolInterface (\r
                   &Handle,\r
@@ -789,13 +798,24 @@ mImageHandle = ImageHandle;
                   &mEfiExitBootServicesEvent\r
                   );\r
 \r
+  //\r
+  // Adjust RTC deafult time to be BIOS-built time.\r
+  //\r
+  Status = gBS->CreateEvent (\r
+                    EVT_NOTIFY_SIGNAL,\r
+                    TPL_CALLBACK,\r
+                    AdjustDefaultRtcTimeCallback,\r
+                    NULL,\r
+                    &RtcEvent\r
+                    );\r
+  if (!EFI_ERROR (Status)) {\r
+      Status = gBS->RegisterProtocolNotify (\r
+                      &gExitPmAuthProtocolGuid,\r
+                      RtcEvent,\r
+                      &RtcCallbackReg\r
+                      );\r
 \r
-//\r
-// Tristae Lpc pins at last moment\r
-//\r
-if (mSystemConfiguration.TristateLpc == 1)\r
-{\r
-}\r
+  }\r
 \r
   return EFI_SUCCESS;\r
 }\r
index 42197ca..ec69e61 100644 (file)
@@ -1,15 +1,15 @@
 /*++\r
 \r
-  Copyright (c) 2004  - 2014, Intel Corporation. All rights reserved.<BR>\r
-                                                                                   \r\r
-  This program and the accompanying materials are licensed and made available under\r\r
-  the terms and conditions of the BSD License that accompanies this distribution.  \r\r
-  The full text of the license may be found at                                     \r\r
-  http://opensource.org/licenses/bsd-license.php.                                  \r\r
-                                                                                   \r\r
-  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,            \r\r
-  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.    \r\r
-                                                                                   \r\r
+  Copyright (c) 2004  - 2015, Intel Corporation. All rights reserved.<BR>\r
+                                                                                   \r
+  This program and the accompanying materials are licensed and made available under\r
+  the terms and conditions of the BSD License that accompanies this distribution.  \r
+  The full text of the license may be found at                                     \r
+  http://opensource.org/licenses/bsd-license.php.                                  \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
+                                                                                   \r
 \r
 \r
 Module Name:\r
@@ -45,6 +45,7 @@ Abstract:
 #include <Library/Tpm2CommandLib.h>\r
 #include <Library/Tpm2DeviceLib.h>\r
 #include <Library/BaseCryptLib.h>\r
+#include <Library/BiosIdLib.h>\r
 #include <Protocol/GlobalNvsArea.h>\r
 #include <Protocol/PciRootBridgeIo.h>\r
 #include <Protocol/IsaAcpi.h>\r
@@ -60,6 +61,7 @@ Abstract:
 #include <Protocol/DataHub.h>\r
 #include <Protocol/PciIo.h>\r
 #include <Protocol/Speaker.h>\r
+#include <Protocol/ExitPmAuth.h>\r
 #include <IndustryStandard/Pci22.h>\r
 #include <Guid/SetupVariable.h>\r
 #include <Guid/PlatformInfo.h>\r
@@ -634,6 +636,13 @@ InitializeObservableProtocol();
 EFI_STATUS\r
 PciBusDriverHook();\r
 \r
+VOID\r
+EFIAPI\r
+AdjustDefaultRtcTimeCallback (\r
+  IN EFI_EVENT        Event,\r
+  IN VOID             *Context\r
+  );\r
+\r
 typedef struct _GOP_DISPLAY_BRIGHTNESS_PROTOCOL GOP_DISPLAY_BRIGHTNESS_PROTOCOL;\r
 \r
 typedef\r
index 6fa0700..daf6d70 100644 (file)
@@ -1,15 +1,15 @@
 #/*++\r
 #\r
-#  Copyright (c)  1999  - 2014, Intel Corporation. All rights reserved\r
-#                                                                                  \r\r
-# This program and the accompanying materials are licensed and made available under\r\r
-# the terms and conditions of the BSD License that accompanies this distribution.  \r\r
-# The full text of the license may be found at                                     \r\r
-# http://opensource.org/licenses/bsd-license.php.                                  \r\r
-#                                                                                  \r\r
-# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,            \r\r
-# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.    \r\r
-#                                                                                  \r\r
+#  Copyright (c)  1999  - 2015, Intel Corporation. All rights reserved\r
+#                                                                                  \r
+# This program and the accompanying materials are licensed and made available under\r
+# the terms and conditions of the BSD License that accompanies this distribution.  \r
+# The full text of the license may be found at                                     \r
+# http://opensource.org/licenses/bsd-license.php.                                  \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
+#                                                                                  \r
 #\r
 #  Module Name:\r
 #\r
@@ -51,6 +51,7 @@
   LegacySpeaker.c\r
   Observable/Observable.c\r
   ExI.c\r
+  Rtc.c\r
 \r
 [Packages]\r
   MdePkg/MdePkg.dec\r
   gEfiGlobalNvsAreaProtocolGuid\r
   gEfiCpuIo2ProtocolGuid\r
   gIgdOpRegionProtocolGuid\r
+  gExitPmAuthProtocolGuid\r
 \r
 [Pcd.common]\r
   gPlatformModuleTokenSpaceGuid.PcdPBTNDisableInterval\r
diff --git a/Vlv2TbltDevicePkg/PlatformDxe/Rtc.c b/Vlv2TbltDevicePkg/PlatformDxe/Rtc.c
new file mode 100644 (file)
index 0000000..caa042f
--- /dev/null
@@ -0,0 +1,160 @@
+/** @file\r
+  Adjust Default System Time.\r
+  \r
+  Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>\r
+                                                                                   \r
+  This program and the accompanying materials are licensed and made available under\r
+  the terms and conditions of the BSD License that accompanies this distribution.  \r
+  The full text of the license may be found at                                     \r
+  http://opensource.org/licenses/bsd-license.php.                                  \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
+                                                                                   \r
+--*/\r
+\r
+#include <PlatformDxe.h>\r
+\r
+//\r
+// Date and time initial values.\r
+// They are used if the RTC values are invalid during driver initialization\r
+//\r
+#define RTC_INIT_SECOND 0\r
+#define RTC_INIT_MINUTE 0\r
+#define RTC_INIT_HOUR   0\r
\r
+CHAR16  mBiosReleaseDate[20];    \r
+  \r
+/**\r
+  Convert a single character to number.\r
+  It assumes the input Char is in the scope of L'0' ~ L'9' and L'A' ~ L'F'\r
+  \r
+  @param Char    The input char which need to change to a hex number.\r
+  \r
+**/\r
+UINTN\r
+CharToUint (\r
+  IN CHAR16                           Char\r
+  )\r
+{\r
+  if ((Char >= L'0') && (Char <= L'9')) {\r
+    return (UINTN) (Char - L'0');\r
+  }\r
+\r
+  if ((Char >= L'A') && (Char <= L'F')) {\r
+    return (UINTN) (Char - L'A' + 0xA);\r
+  }\r
+\r
+  ASSERT (FALSE);\r
+  return 0;\r
+}\r
+\r
+/**\r
+  See if YEAR field of a variable of EFI_TIME type is correct.\r
+\r
+  @param   Time   The time to be checked.\r
+\r
+  @retval  EFI_INVALID_PARAMETER  Some fields of Time are not correct.\r
+  @retval  EFI_SUCCESS            Time is a valid EFI_TIME variable.\r
+\r
+**/\r
+EFI_STATUS\r
+CheckRtcTimeFields (\r
+  IN EFI_TIME *Time\r
+  )\r
+{\r
+  UINT16 YearBuilt;\r
+  \r
+  YearBuilt = (UINT16)(CharToUint(mBiosReleaseDate[8])*10 + CharToUint(mBiosReleaseDate[9]) + 2000);\r
+  \r
+  if ((Time->Year) < YearBuilt) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+  ExitPmAuth Protocol notification event handler, which set initial system time to be\r
+  the time when BIOS was built.\r
+\r
+  @param[in] Event    Event whose notification function is being invoked.\r
+  @param[in] Context  Pointer to the notification function's context.\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+AdjustDefaultRtcTimeCallback (\r
+  IN EFI_EVENT        Event,\r
+  IN VOID             *Context\r
+  )\r
+{\r
+  EFI_STATUS      Status;\r
+  EFI_TIME        EfiTime;\r
+  CHAR16          BiosVersion[60];    \r
+  CHAR16          BiosReleaseTime[20];    \r
+  //\r
+  // Get BIOS built time from Bios-ID. \r
+  //\r
+  \r
+  SetMem(BiosVersion, sizeof(BiosVersion), 0);\r
+  SetMem(mBiosReleaseDate, sizeof(mBiosReleaseDate), 0);\r
+  SetMem(BiosReleaseTime, sizeof(BiosReleaseTime), 0);\r
+    \r
+  Status = GetBiosVersionDateTime (BiosVersion, mBiosReleaseDate, BiosReleaseTime);\r
+  ASSERT_EFI_ERROR(Status);\r
+  if (EFI_ERROR (Status)) {\r
+    return; \r
+  }\r
+  \r
+  //\r
+  // Get current RTC time.\r
+  // \r
+  Status = gRT->GetTime (&EfiTime, NULL);\r
\r
+  //\r
+  // Validate RTC time fields\r
+  //\r
+  Status = CheckRtcTimeFields (&EfiTime);\r
+  \r
+  if (EFI_ERROR (Status)) {\r
+    //\r
+    // Date such as Dec 28th of 2015\r
+    //\r
+    // Month\r
+    // BiosReleaseDate[0] = '1';\r
+    // BiosReleaseDate[1] = '2';\r
+    //\r
+    // Day\r
+    // BiosReleaseDate[3] = '2';\r
+    // BiosReleaseDate[4] = '8';\r
+    //  \r
+    //\r
+    // Year\r
+    //\r
+    // BiosReleaseDate[6] = '2';\r
+    // BiosReleaseDate[7] = '0';\r
+    // BiosReleaseDate[8] = '1'\r
+    // BiosReleaseDate[9] = '5';\r
+    \r
+    EfiTime.Second = RTC_INIT_SECOND;\r
+    EfiTime.Minute = RTC_INIT_MINUTE;\r
+    EfiTime.Hour   = RTC_INIT_HOUR;\r
+    EfiTime.Day    = (UINT8)(CharToUint(mBiosReleaseDate[3])*10 + CharToUint(mBiosReleaseDate[4]));\r
+    EfiTime.Month  = (UINT8)(CharToUint(mBiosReleaseDate[0])*10 + CharToUint(mBiosReleaseDate[1]));\r
+    EfiTime.Year   = (UINT16)(CharToUint(mBiosReleaseDate[8])*10 + CharToUint(mBiosReleaseDate[9]) + 2000);\r
+    EfiTime.Nanosecond  = 0;\r
+    EfiTime.TimeZone = EFI_UNSPECIFIED_TIMEZONE;\r
+    EfiTime.Daylight = 1; \r
+\r
+    DEBUG ((EFI_D_INFO, "Day:%d Month:%d Year:%d \n", (UINT32)EfiTime.Day, (UINT32)EfiTime.Month, (UINT32)EfiTime.Year));\r
+\r
+    //\r
+    // Reset time value according to new RTC configuration\r
+    //\r
+    Status = gRT->SetTime (&EfiTime);\r
+    ASSERT_EFI_ERROR(Status);\r
+  }\r
+\r
+  return;\r
+}\r