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