/** @file\r
Provides Set/Get time operations.\r
\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
-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) 2006 - 2018, Intel Corporation. All rights reserved.<BR>\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 = { 0 };\r
+PC_RTC_MODULE_GLOBALS mModuleGlobal;\r
+\r
+EFI_HANDLE mHandle = NULL;\r
\r
-EFI_HANDLE mHandle = NULL;\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
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
EFI_STATUS\r
EFIAPI\r
PcRtcEfiSetTime (\r
- IN EFI_TIME *Time\r
+ IN EFI_TIME *Time\r
)\r
{\r
return PcRtcSetTime (Time, &mModuleGlobal);\r
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
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
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
EFI_EVENT Event;\r
\r
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
+\r
Status = gBS->CreateEventEx (\r
EVT_NOTIFY_SIGNAL,\r
TPL_CALLBACK,\r
&Event\r
);\r
ASSERT_EFI_ERROR (Status);\r
- \r
+\r
Status = gBS->CreateEventEx (\r
EVT_NOTIFY_SIGNAL,\r
TPL_CALLBACK,\r
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