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