]> git.proxmox.com Git - mirror_edk2.git/blobdiff - PcAtChipsetPkg/PcatRealTimeClockRuntimeDxe/PcRtcEntry.c
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[mirror_edk2.git] / PcAtChipsetPkg / PcatRealTimeClockRuntimeDxe / PcRtcEntry.c
index 56ddc3ed5b1accc2b1a99ab4515f851f89fb6e43..e6e9458d7544295e0087868dd16c4e92f8a2835a 100644 (file)
@@ -2,21 +2,22 @@
   Provides Set/Get time operations.\r
 \r
 Copyright (c) 2006 - 2018, 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
-\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
+Copyright (c) 2018 - 2020, ARM Limited. All rights reserved.<BR>\r
+SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
 **/\r
 \r
+#include <Library/DxeServicesTableLib.h>\r
 #include "PcRtc.h"\r
 \r
 PC_RTC_MODULE_GLOBALS  mModuleGlobal;\r
 \r
-EFI_HANDLE             mHandle = NULL;\r
+EFI_HANDLE  mHandle = NULL;\r
+\r
+STATIC EFI_EVENT  mVirtualAddrChangeEvent;\r
+\r
+UINTN  mRtcIndexRegister;\r
+UINTN  mRtcTargetRegister;\r
 \r
 /**\r
   Returns the current time and date information, and the time-keeping capabilities\r
@@ -34,8 +35,8 @@ EFI_HANDLE             mHandle = NULL;
 EFI_STATUS\r
 EFIAPI\r
 PcRtcEfiGetTime (\r
-  OUT EFI_TIME                *Time,\r
-  OUT EFI_TIME_CAPABILITIES   *Capabilities  OPTIONAL\r
+  OUT EFI_TIME               *Time,\r
+  OUT EFI_TIME_CAPABILITIES  *Capabilities  OPTIONAL\r
   )\r
 {\r
   return PcRtcGetTime (Time, Capabilities, &mModuleGlobal);\r
@@ -54,7 +55,7 @@ PcRtcEfiGetTime (
 EFI_STATUS\r
 EFIAPI\r
 PcRtcEfiSetTime (\r
-  IN EFI_TIME                *Time\r
+  IN EFI_TIME  *Time\r
   )\r
 {\r
   return PcRtcSetTime (Time, &mModuleGlobal);\r
@@ -78,15 +79,14 @@ PcRtcEfiSetTime (
 EFI_STATUS\r
 EFIAPI\r
 PcRtcEfiGetWakeupTime (\r
-  OUT BOOLEAN     *Enabled,\r
-  OUT BOOLEAN     *Pending,\r
-  OUT EFI_TIME    *Time\r
+  OUT BOOLEAN   *Enabled,\r
+  OUT BOOLEAN   *Pending,\r
+  OUT EFI_TIME  *Time\r
   )\r
 {\r
   return PcRtcGetWakeupTime (Enabled, Pending, Time, &mModuleGlobal);\r
 }\r
 \r
-\r
 /**\r
   Sets the system wakeup alarm clock time.\r
 \r
@@ -104,17 +104,41 @@ PcRtcEfiGetWakeupTime (
 EFI_STATUS\r
 EFIAPI\r
 PcRtcEfiSetWakeupTime (\r
-  IN BOOLEAN      Enabled,\r
-  IN EFI_TIME    *Time       OPTIONAL\r
+  IN BOOLEAN   Enabled,\r
+  IN EFI_TIME  *Time       OPTIONAL\r
   )\r
 {\r
   return PcRtcSetWakeupTime (Enabled, Time, &mModuleGlobal);\r
 }\r
 \r
+/**\r
+  Fixup internal data so that EFI can be called in virtual mode.\r
+  Call the passed in Child Notify event and convert any pointers in\r
+  lib to virtual mode.\r
+\r
+  @param[in]    Event   The Event that is being processed\r
+  @param[in]    Context Event Context\r
+**/\r
+VOID\r
+EFIAPI\r
+LibRtcVirtualNotifyEvent (\r
+  IN EFI_EVENT  Event,\r
+  IN VOID       *Context\r
+  )\r
+{\r
+  // Only needed if you are going to support the OS calling RTC functions in\r
+  // virtual mode. You will need to call EfiConvertPointer (). To convert any\r
+  // stored physical addresses to virtual address. After the OS transitions to\r
+  // calling in virtual mode, all future runtime calls will be made in virtual\r
+  // mode.\r
+  EfiConvertPointer (0x0, (VOID **)&mRtcIndexRegister);\r
+  EfiConvertPointer (0x0, (VOID **)&mRtcTargetRegister);\r
+}\r
+\r
 /**\r
   The user Entry Point for PcRTC module.\r
 \r
-  This is the entrhy point for PcRTC module. It installs the UEFI runtime service\r
+  This is the entry point for PcRTC module. It installs the UEFI runtime service\r
   including GetTime(),SetTime(),GetWakeupTime(),and SetWakeupTime().\r
 \r
   @param  ImageHandle    The firmware allocated handle for the EFI image.\r
@@ -127,8 +151,8 @@ PcRtcEfiSetWakeupTime (
 EFI_STATUS\r
 EFIAPI\r
 InitializePcRtc (\r
-  IN EFI_HANDLE                            ImageHandle,\r
-  IN EFI_SYSTEM_TABLE                      *SystemTable\r
+  IN EFI_HANDLE        ImageHandle,\r
+  IN EFI_SYSTEM_TABLE  *SystemTable\r
   )\r
 {\r
   EFI_STATUS  Status;\r
@@ -137,6 +161,11 @@ InitializePcRtc (
   EfiInitializeLock (&mModuleGlobal.RtcLock, TPL_CALLBACK);\r
   mModuleGlobal.CenturyRtcAddress = GetCenturyRtcAddress ();\r
 \r
+  if (FeaturePcdGet (PcdRtcUseMmio)) {\r
+    mRtcIndexRegister  = (UINTN)PcdGet64 (PcdRtcIndexRegister64);\r
+    mRtcTargetRegister = (UINTN)PcdGet64 (PcdRtcTargetRegister64);\r
+  }\r
+\r
   Status = PcRtcInit (&mModuleGlobal);\r
   ASSERT_EFI_ERROR (Status);\r
 \r
@@ -171,7 +200,23 @@ InitializePcRtc (
                   NULL,\r
                   NULL\r
                   );\r
-  ASSERT_EFI_ERROR (Status);\r
+  if (EFI_ERROR (Status)) {\r
+    ASSERT_EFI_ERROR (Status);\r
+    return Status;\r
+  }\r
+\r
+  if (FeaturePcdGet (PcdRtcUseMmio)) {\r
+    // Register for the virtual address change event\r
+    Status = gBS->CreateEventEx (\r
+                    EVT_NOTIFY_SIGNAL,\r
+                    TPL_NOTIFY,\r
+                    LibRtcVirtualNotifyEvent,\r
+                    NULL,\r
+                    &gEfiEventVirtualAddressChangeGuid,\r
+                    &mVirtualAddrChangeEvent\r
+                    );\r
+    ASSERT_EFI_ERROR (Status);\r
+  }\r
 \r
   return Status;\r
 }\r