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