2 Provides Set/Get time operations.
4 Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
5 Copyright (c) 2018 - 2020, ARM Limited. All rights reserved.<BR>
6 SPDX-License-Identifier: BSD-2-Clause-Patent
10 #include <Library/DxeServicesTableLib.h>
13 PC_RTC_MODULE_GLOBALS mModuleGlobal
;
15 EFI_HANDLE mHandle
= NULL
;
17 STATIC EFI_EVENT mVirtualAddrChangeEvent
;
19 UINTN mRtcIndexRegister
;
20 UINTN mRtcTargetRegister
;
23 Returns the current time and date information, and the time-keeping capabilities
24 of the hardware platform.
26 @param Time A pointer to storage to receive a snapshot of the current time.
27 @param Capabilities An optional pointer to a buffer to receive the real time
28 clock device's capabilities.
30 @retval EFI_SUCCESS The operation completed successfully.
31 @retval EFI_INVALID_PARAMETER Time is NULL.
32 @retval EFI_DEVICE_ERROR The time could not be retrieved due to hardware error.
39 OUT EFI_TIME_CAPABILITIES
*Capabilities OPTIONAL
42 return PcRtcGetTime (Time
, Capabilities
, &mModuleGlobal
);
46 Sets the current local time and date information.
48 @param Time A pointer to the current time.
50 @retval EFI_SUCCESS The operation completed successfully.
51 @retval EFI_INVALID_PARAMETER A time field is out of range.
52 @retval EFI_DEVICE_ERROR The time could not be set due due to hardware error.
61 return PcRtcSetTime (Time
, &mModuleGlobal
);
65 Returns the current wakeup alarm clock setting.
67 @param Enabled Indicates if the alarm is currently enabled or disabled.
68 @param Pending Indicates if the alarm signal is pending and requires acknowledgement.
69 @param Time The current alarm setting.
71 @retval EFI_SUCCESS The alarm settings were returned.
72 @retval EFI_INVALID_PARAMETER Enabled is NULL.
73 @retval EFI_INVALID_PARAMETER Pending is NULL.
74 @retval EFI_INVALID_PARAMETER Time is NULL.
75 @retval EFI_DEVICE_ERROR The wakeup time could not be retrieved due to a hardware error.
76 @retval EFI_UNSUPPORTED A wakeup timer is not supported on this platform.
81 PcRtcEfiGetWakeupTime (
87 return PcRtcGetWakeupTime (Enabled
, Pending
, Time
, &mModuleGlobal
);
91 Sets the system wakeup alarm clock time.
93 @param Enabled Enable or disable the wakeup alarm.
94 @param Time If Enable is TRUE, the time to set the wakeup alarm for.
95 If Enable is FALSE, then this parameter is optional, and may be NULL.
97 @retval EFI_SUCCESS If Enable is TRUE, then the wakeup alarm was enabled.
98 If Enable is FALSE, then the wakeup alarm was disabled.
99 @retval EFI_INVALID_PARAMETER A time field is out of range.
100 @retval EFI_DEVICE_ERROR The wakeup time could not be set due to a hardware error.
101 @retval EFI_UNSUPPORTED A wakeup timer is not supported on this platform.
106 PcRtcEfiSetWakeupTime (
108 IN EFI_TIME
*Time OPTIONAL
111 return PcRtcSetWakeupTime (Enabled
, Time
, &mModuleGlobal
);
115 Fixup internal data so that EFI can be called in virtual mode.
116 Call the passed in Child Notify event and convert any pointers in
119 @param[in] Event The Event that is being processed
120 @param[in] Context Event Context
124 LibRtcVirtualNotifyEvent (
129 // Only needed if you are going to support the OS calling RTC functions in
130 // virtual mode. You will need to call EfiConvertPointer (). To convert any
131 // stored physical addresses to virtual address. After the OS transitions to
132 // calling in virtual mode, all future runtime calls will be made in virtual
134 EfiConvertPointer (0x0, (VOID
**)&mRtcIndexRegister
);
135 EfiConvertPointer (0x0, (VOID
**)&mRtcTargetRegister
);
139 The user Entry Point for PcRTC module.
141 This is the entry point for PcRTC module. It installs the UEFI runtime service
142 including GetTime(),SetTime(),GetWakeupTime(),and SetWakeupTime().
144 @param ImageHandle The firmware allocated handle for the EFI image.
145 @param SystemTable A pointer to the EFI System Table.
147 @retval EFI_SUCCESS The entry point is executed successfully.
148 @retval Others Some error occurs when executing this entry point.
154 IN EFI_HANDLE ImageHandle
,
155 IN EFI_SYSTEM_TABLE
*SystemTable
161 EfiInitializeLock (&mModuleGlobal
.RtcLock
, TPL_CALLBACK
);
162 mModuleGlobal
.CenturyRtcAddress
= GetCenturyRtcAddress ();
164 if (FeaturePcdGet (PcdRtcUseMmio
)) {
165 mRtcIndexRegister
= (UINTN
)PcdGet64 (PcdRtcIndexRegister64
);
166 mRtcTargetRegister
= (UINTN
)PcdGet64 (PcdRtcTargetRegister64
);
169 Status
= PcRtcInit (&mModuleGlobal
);
170 ASSERT_EFI_ERROR (Status
);
172 Status
= gBS
->CreateEventEx (
175 PcRtcAcpiTableChangeCallback
,
177 &gEfiAcpi10TableGuid
,
180 ASSERT_EFI_ERROR (Status
);
182 Status
= gBS
->CreateEventEx (
185 PcRtcAcpiTableChangeCallback
,
190 ASSERT_EFI_ERROR (Status
);
192 gRT
->GetTime
= PcRtcEfiGetTime
;
193 gRT
->SetTime
= PcRtcEfiSetTime
;
194 gRT
->GetWakeupTime
= PcRtcEfiGetWakeupTime
;
195 gRT
->SetWakeupTime
= PcRtcEfiSetWakeupTime
;
197 Status
= gBS
->InstallMultipleProtocolInterfaces (
199 &gEfiRealTimeClockArchProtocolGuid
,
203 if (EFI_ERROR (Status
)) {
204 ASSERT_EFI_ERROR (Status
);
208 if (FeaturePcdGet (PcdRtcUseMmio
)) {
209 // Register for the virtual address change event
210 Status
= gBS
->CreateEventEx (
213 LibRtcVirtualNotifyEvent
,
215 &gEfiEventVirtualAddressChangeGuid
,
216 &mVirtualAddrChangeEvent
218 ASSERT_EFI_ERROR (Status
);