1 | /** @file
|
---|
2 | Provides Set/Get time operations.
|
---|
3 |
|
---|
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
|
---|
7 |
|
---|
8 | **/
|
---|
9 |
|
---|
10 | #include <Library/DxeServicesTableLib.h>
|
---|
11 | #include "PcRtc.h"
|
---|
12 |
|
---|
13 | PC_RTC_MODULE_GLOBALS mModuleGlobal;
|
---|
14 |
|
---|
15 | EFI_HANDLE mHandle = NULL;
|
---|
16 |
|
---|
17 | STATIC EFI_EVENT mVirtualAddrChangeEvent;
|
---|
18 |
|
---|
19 | UINTN mRtcIndexRegister;
|
---|
20 | UINTN mRtcTargetRegister;
|
---|
21 |
|
---|
22 | /**
|
---|
23 | Returns the current time and date information, and the time-keeping capabilities
|
---|
24 | of the hardware platform.
|
---|
25 |
|
---|
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.
|
---|
29 |
|
---|
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.
|
---|
33 |
|
---|
34 | **/
|
---|
35 | EFI_STATUS
|
---|
36 | EFIAPI
|
---|
37 | PcRtcEfiGetTime (
|
---|
38 | OUT EFI_TIME *Time,
|
---|
39 | OUT EFI_TIME_CAPABILITIES *Capabilities OPTIONAL
|
---|
40 | )
|
---|
41 | {
|
---|
42 | return PcRtcGetTime (Time, Capabilities, &mModuleGlobal);
|
---|
43 | }
|
---|
44 |
|
---|
45 | /**
|
---|
46 | Sets the current local time and date information.
|
---|
47 |
|
---|
48 | @param Time A pointer to the current time.
|
---|
49 |
|
---|
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.
|
---|
53 |
|
---|
54 | **/
|
---|
55 | EFI_STATUS
|
---|
56 | EFIAPI
|
---|
57 | PcRtcEfiSetTime (
|
---|
58 | IN EFI_TIME *Time
|
---|
59 | )
|
---|
60 | {
|
---|
61 | return PcRtcSetTime (Time, &mModuleGlobal);
|
---|
62 | }
|
---|
63 |
|
---|
64 | /**
|
---|
65 | Returns the current wakeup alarm clock setting.
|
---|
66 |
|
---|
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.
|
---|
70 |
|
---|
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.
|
---|
77 |
|
---|
78 | **/
|
---|
79 | EFI_STATUS
|
---|
80 | EFIAPI
|
---|
81 | PcRtcEfiGetWakeupTime (
|
---|
82 | OUT BOOLEAN *Enabled,
|
---|
83 | OUT BOOLEAN *Pending,
|
---|
84 | OUT EFI_TIME *Time
|
---|
85 | )
|
---|
86 | {
|
---|
87 | return PcRtcGetWakeupTime (Enabled, Pending, Time, &mModuleGlobal);
|
---|
88 | }
|
---|
89 |
|
---|
90 |
|
---|
91 | /**
|
---|
92 | Sets the system wakeup alarm clock time.
|
---|
93 |
|
---|
94 | @param Enabled Enable or disable the wakeup alarm.
|
---|
95 | @param Time If Enable is TRUE, the time to set the wakeup alarm for.
|
---|
96 | If Enable is FALSE, then this parameter is optional, and may be NULL.
|
---|
97 |
|
---|
98 | @retval EFI_SUCCESS If Enable is TRUE, then the wakeup alarm was enabled.
|
---|
99 | If Enable is FALSE, then the wakeup alarm was disabled.
|
---|
100 | @retval EFI_INVALID_PARAMETER A time field is out of range.
|
---|
101 | @retval EFI_DEVICE_ERROR The wakeup time could not be set due to a hardware error.
|
---|
102 | @retval EFI_UNSUPPORTED A wakeup timer is not supported on this platform.
|
---|
103 |
|
---|
104 | **/
|
---|
105 | EFI_STATUS
|
---|
106 | EFIAPI
|
---|
107 | PcRtcEfiSetWakeupTime (
|
---|
108 | IN BOOLEAN Enabled,
|
---|
109 | IN EFI_TIME *Time OPTIONAL
|
---|
110 | )
|
---|
111 | {
|
---|
112 | return PcRtcSetWakeupTime (Enabled, Time, &mModuleGlobal);
|
---|
113 | }
|
---|
114 |
|
---|
115 | /**
|
---|
116 | Fixup internal data so that EFI can be called in virtual mode.
|
---|
117 | Call the passed in Child Notify event and convert any pointers in
|
---|
118 | lib to virtual mode.
|
---|
119 |
|
---|
120 | @param[in] Event The Event that is being processed
|
---|
121 | @param[in] Context Event Context
|
---|
122 | **/
|
---|
123 | VOID
|
---|
124 | EFIAPI
|
---|
125 | LibRtcVirtualNotifyEvent (
|
---|
126 | IN EFI_EVENT Event,
|
---|
127 | IN VOID *Context
|
---|
128 | )
|
---|
129 | {
|
---|
130 | // Only needed if you are going to support the OS calling RTC functions in
|
---|
131 | // virtual mode. You will need to call EfiConvertPointer (). To convert any
|
---|
132 | // stored physical addresses to virtual address. After the OS transitions to
|
---|
133 | // calling in virtual mode, all future runtime calls will be made in virtual
|
---|
134 | // mode.
|
---|
135 | EfiConvertPointer (0x0, (VOID**)&mRtcIndexRegister);
|
---|
136 | EfiConvertPointer (0x0, (VOID**)&mRtcTargetRegister);
|
---|
137 | }
|
---|
138 |
|
---|
139 | /**
|
---|
140 | The user Entry Point for PcRTC module.
|
---|
141 |
|
---|
142 | This is the entry point for PcRTC module. It installs the UEFI runtime service
|
---|
143 | including GetTime(),SetTime(),GetWakeupTime(),and SetWakeupTime().
|
---|
144 |
|
---|
145 | @param ImageHandle The firmware allocated handle for the EFI image.
|
---|
146 | @param SystemTable A pointer to the EFI System Table.
|
---|
147 |
|
---|
148 | @retval EFI_SUCCESS The entry point is executed successfully.
|
---|
149 | @retval Others Some error occurs when executing this entry point.
|
---|
150 |
|
---|
151 | **/
|
---|
152 | EFI_STATUS
|
---|
153 | EFIAPI
|
---|
154 | InitializePcRtc (
|
---|
155 | IN EFI_HANDLE ImageHandle,
|
---|
156 | IN EFI_SYSTEM_TABLE *SystemTable
|
---|
157 | )
|
---|
158 | {
|
---|
159 | EFI_STATUS Status;
|
---|
160 | EFI_EVENT Event;
|
---|
161 |
|
---|
162 | EfiInitializeLock (&mModuleGlobal.RtcLock, TPL_CALLBACK);
|
---|
163 | mModuleGlobal.CenturyRtcAddress = GetCenturyRtcAddress ();
|
---|
164 |
|
---|
165 | if (FeaturePcdGet (PcdRtcUseMmio)) {
|
---|
166 | mRtcIndexRegister = (UINTN)PcdGet64 (PcdRtcIndexRegister64);
|
---|
167 | mRtcTargetRegister = (UINTN)PcdGet64 (PcdRtcTargetRegister64);
|
---|
168 | }
|
---|
169 |
|
---|
170 | Status = PcRtcInit (&mModuleGlobal);
|
---|
171 | ASSERT_EFI_ERROR (Status);
|
---|
172 |
|
---|
173 | Status = gBS->CreateEventEx (
|
---|
174 | EVT_NOTIFY_SIGNAL,
|
---|
175 | TPL_CALLBACK,
|
---|
176 | PcRtcAcpiTableChangeCallback,
|
---|
177 | NULL,
|
---|
178 | &gEfiAcpi10TableGuid,
|
---|
179 | &Event
|
---|
180 | );
|
---|
181 | ASSERT_EFI_ERROR (Status);
|
---|
182 |
|
---|
183 | Status = gBS->CreateEventEx (
|
---|
184 | EVT_NOTIFY_SIGNAL,
|
---|
185 | TPL_CALLBACK,
|
---|
186 | PcRtcAcpiTableChangeCallback,
|
---|
187 | NULL,
|
---|
188 | &gEfiAcpiTableGuid,
|
---|
189 | &Event
|
---|
190 | );
|
---|
191 | ASSERT_EFI_ERROR (Status);
|
---|
192 |
|
---|
193 | gRT->GetTime = PcRtcEfiGetTime;
|
---|
194 | gRT->SetTime = PcRtcEfiSetTime;
|
---|
195 | gRT->GetWakeupTime = PcRtcEfiGetWakeupTime;
|
---|
196 | gRT->SetWakeupTime = PcRtcEfiSetWakeupTime;
|
---|
197 |
|
---|
198 | Status = gBS->InstallMultipleProtocolInterfaces (
|
---|
199 | &mHandle,
|
---|
200 | &gEfiRealTimeClockArchProtocolGuid,
|
---|
201 | NULL,
|
---|
202 | NULL
|
---|
203 | );
|
---|
204 | if (EFI_ERROR (Status)) {
|
---|
205 | ASSERT_EFI_ERROR (Status);
|
---|
206 | return Status;
|
---|
207 | }
|
---|
208 |
|
---|
209 | if (FeaturePcdGet (PcdRtcUseMmio)) {
|
---|
210 | // Register for the virtual address change event
|
---|
211 | Status = gBS->CreateEventEx (
|
---|
212 | EVT_NOTIFY_SIGNAL,
|
---|
213 | TPL_NOTIFY,
|
---|
214 | LibRtcVirtualNotifyEvent,
|
---|
215 | NULL,
|
---|
216 | &gEfiEventVirtualAddressChangeGuid,
|
---|
217 | &mVirtualAddrChangeEvent
|
---|
218 | );
|
---|
219 | ASSERT_EFI_ERROR (Status);
|
---|
220 | }
|
---|
221 |
|
---|
222 | return Status;
|
---|
223 | }
|
---|