]>
Commit | Line | Data |
---|---|---|
1 | /** @file\r | |
2 | Header file for real time clock driver.\r | |
3 | \r | |
4 | Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>\r | |
5 | Copyright (c) 2017, AMD Inc. All rights reserved.<BR>\r | |
6 | \r | |
7 | This program and the accompanying materials\r | |
8 | are licensed and made available under the terms and conditions of the BSD License\r | |
9 | which accompanies this distribution. The full text of the license may be found at\r | |
10 | http://opensource.org/licenses/bsd-license.php\r | |
11 | \r | |
12 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
13 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
14 | \r | |
15 | **/\r | |
16 | \r | |
17 | \r | |
18 | #ifndef _RTC_H_\r | |
19 | #define _RTC_H_\r | |
20 | \r | |
21 | \r | |
22 | #include <Uefi.h>\r | |
23 | \r | |
24 | #include <Guid/Acpi.h>\r | |
25 | \r | |
26 | #include <Protocol/RealTimeClock.h>\r | |
27 | \r | |
28 | #include <Library/BaseLib.h>\r | |
29 | #include <Library/DebugLib.h>\r | |
30 | #include <Library/UefiLib.h>\r | |
31 | #include <Library/BaseMemoryLib.h>\r | |
32 | #include <Library/IoLib.h>\r | |
33 | #include <Library/TimerLib.h>\r | |
34 | #include <Library/UefiDriverEntryPoint.h>\r | |
35 | #include <Library/UefiBootServicesTableLib.h>\r | |
36 | #include <Library/UefiRuntimeLib.h>\r | |
37 | #include <Library/UefiRuntimeServicesTableLib.h>\r | |
38 | #include <Library/PcdLib.h>\r | |
39 | #include <Library/ReportStatusCodeLib.h>\r | |
40 | \r | |
41 | typedef struct {\r | |
42 | EFI_LOCK RtcLock;\r | |
43 | INT16 SavedTimeZone;\r | |
44 | UINT8 Daylight;\r | |
45 | UINT8 CenturyRtcAddress;\r | |
46 | } PC_RTC_MODULE_GLOBALS;\r | |
47 | \r | |
48 | extern PC_RTC_MODULE_GLOBALS mModuleGlobal;\r | |
49 | \r | |
50 | #define PCAT_RTC_ADDRESS_REGISTER 0x70\r | |
51 | #define PCAT_RTC_DATA_REGISTER 0x71\r | |
52 | \r | |
53 | //\r | |
54 | // Dallas DS12C887 Real Time Clock\r | |
55 | //\r | |
56 | #define RTC_ADDRESS_SECONDS 0 // R/W Range 0..59\r | |
57 | #define RTC_ADDRESS_SECONDS_ALARM 1 // R/W Range 0..59\r | |
58 | #define RTC_ADDRESS_MINUTES 2 // R/W Range 0..59\r | |
59 | #define RTC_ADDRESS_MINUTES_ALARM 3 // R/W Range 0..59\r | |
60 | #define RTC_ADDRESS_HOURS 4 // R/W Range 1..12 or 0..23 Bit 7 is AM/PM\r | |
61 | #define RTC_ADDRESS_HOURS_ALARM 5 // R/W Range 1..12 or 0..23 Bit 7 is AM/PM\r | |
62 | #define RTC_ADDRESS_DAY_OF_THE_WEEK 6 // R/W Range 1..7\r | |
63 | #define RTC_ADDRESS_DAY_OF_THE_MONTH 7 // R/W Range 1..31\r | |
64 | #define RTC_ADDRESS_MONTH 8 // R/W Range 1..12\r | |
65 | #define RTC_ADDRESS_YEAR 9 // R/W Range 0..99\r | |
66 | #define RTC_ADDRESS_REGISTER_A 10 // R/W[0..6] R0[7]\r | |
67 | #define RTC_ADDRESS_REGISTER_B 11 // R/W\r | |
68 | #define RTC_ADDRESS_REGISTER_C 12 // RO\r | |
69 | #define RTC_ADDRESS_REGISTER_D 13 // RO\r | |
70 | //\r | |
71 | // Date and time initial values.\r | |
72 | // They are used if the RTC values are invalid during driver initialization\r | |
73 | //\r | |
74 | #define RTC_INIT_SECOND 0\r | |
75 | #define RTC_INIT_MINUTE 0\r | |
76 | #define RTC_INIT_HOUR 0\r | |
77 | #define RTC_INIT_DAY 1\r | |
78 | #define RTC_INIT_MONTH 1\r | |
79 | \r | |
80 | #pragma pack(1)\r | |
81 | //\r | |
82 | // Register A\r | |
83 | //\r | |
84 | typedef struct {\r | |
85 | UINT8 Rs : 4; // Rate Selection Bits\r | |
86 | UINT8 Dv : 3; // Divisor\r | |
87 | UINT8 Uip : 1; // Update in progress\r | |
88 | } RTC_REGISTER_A_BITS;\r | |
89 | \r | |
90 | typedef union {\r | |
91 | RTC_REGISTER_A_BITS Bits;\r | |
92 | UINT8 Data;\r | |
93 | } RTC_REGISTER_A;\r | |
94 | \r | |
95 | //\r | |
96 | // Register B\r | |
97 | //\r | |
98 | typedef struct {\r | |
99 | UINT8 Dse : 1; // 0 - Daylight saving disabled 1 - Daylight savings enabled\r | |
100 | UINT8 Mil : 1; // 0 - 12 hour mode 1 - 24 hour mode\r | |
101 | UINT8 Dm : 1; // 0 - BCD Format 1 - Binary Format\r | |
102 | UINT8 Sqwe : 1; // 0 - Disable SQWE output 1 - Enable SQWE output\r | |
103 | UINT8 Uie : 1; // 0 - Update INT disabled 1 - Update INT enabled\r | |
104 | UINT8 Aie : 1; // 0 - Alarm INT disabled 1 - Alarm INT Enabled\r | |
105 | UINT8 Pie : 1; // 0 - Periodic INT disabled 1 - Periodic INT Enabled\r | |
106 | UINT8 Set : 1; // 0 - Normal operation. 1 - Updates inhibited\r | |
107 | } RTC_REGISTER_B_BITS;\r | |
108 | \r | |
109 | typedef union {\r | |
110 | RTC_REGISTER_B_BITS Bits;\r | |
111 | UINT8 Data;\r | |
112 | } RTC_REGISTER_B;\r | |
113 | \r | |
114 | //\r | |
115 | // Register C\r | |
116 | //\r | |
117 | typedef struct {\r | |
118 | UINT8 Reserved : 4; // Read as zero. Can not be written.\r | |
119 | UINT8 Uf : 1; // Update End Interrupt Flag\r | |
120 | UINT8 Af : 1; // Alarm Interrupt Flag\r | |
121 | UINT8 Pf : 1; // Periodic Interrupt Flag\r | |
122 | UINT8 Irqf : 1; // Iterrupt Request Flag = PF & PIE | AF & AIE | UF & UIE\r | |
123 | } RTC_REGISTER_C_BITS;\r | |
124 | \r | |
125 | typedef union {\r | |
126 | RTC_REGISTER_C_BITS Bits;\r | |
127 | UINT8 Data;\r | |
128 | } RTC_REGISTER_C;\r | |
129 | \r | |
130 | //\r | |
131 | // Register D\r | |
132 | //\r | |
133 | typedef struct {\r | |
134 | UINT8 Reserved : 7; // Read as zero. Can not be written.\r | |
135 | UINT8 Vrt : 1; // Valid RAM and Time\r | |
136 | } RTC_REGISTER_D_BITS;\r | |
137 | \r | |
138 | typedef union {\r | |
139 | RTC_REGISTER_D_BITS Bits;\r | |
140 | UINT8 Data;\r | |
141 | } RTC_REGISTER_D;\r | |
142 | \r | |
143 | #pragma pack()\r | |
144 | \r | |
145 | /**\r | |
146 | Initialize RTC.\r | |
147 | \r | |
148 | @param Global For global use inside this module.\r | |
149 | \r | |
150 | @retval EFI_DEVICE_ERROR Initialization failed due to device error.\r | |
151 | @retval EFI_SUCCESS Initialization successful.\r | |
152 | \r | |
153 | **/\r | |
154 | EFI_STATUS\r | |
155 | PcRtcInit (\r | |
156 | IN PC_RTC_MODULE_GLOBALS *Global\r | |
157 | );\r | |
158 | \r | |
159 | /**\r | |
160 | Sets the current local time and date information.\r | |
161 | \r | |
162 | @param Time A pointer to the current time.\r | |
163 | @param Global For global use inside this module.\r | |
164 | \r | |
165 | @retval EFI_SUCCESS The operation completed successfully.\r | |
166 | @retval EFI_INVALID_PARAMETER A time field is out of range.\r | |
167 | @retval EFI_DEVICE_ERROR The time could not be set due due to hardware error.\r | |
168 | \r | |
169 | **/\r | |
170 | EFI_STATUS\r | |
171 | PcRtcSetTime (\r | |
172 | IN EFI_TIME *Time,\r | |
173 | IN PC_RTC_MODULE_GLOBALS *Global\r | |
174 | );\r | |
175 | \r | |
176 | /**\r | |
177 | Returns the current time and date information, and the time-keeping capabilities\r | |
178 | of the hardware platform.\r | |
179 | \r | |
180 | @param Time A pointer to storage to receive a snapshot of the current time.\r | |
181 | @param Capabilities An optional pointer to a buffer to receive the real time clock\r | |
182 | device's capabilities.\r | |
183 | @param Global For global use inside this module.\r | |
184 | \r | |
185 | @retval EFI_SUCCESS The operation completed successfully.\r | |
186 | @retval EFI_INVALID_PARAMETER Time is NULL.\r | |
187 | @retval EFI_DEVICE_ERROR The time could not be retrieved due to hardware error.\r | |
188 | \r | |
189 | **/\r | |
190 | EFI_STATUS\r | |
191 | PcRtcGetTime (\r | |
192 | OUT EFI_TIME *Time,\r | |
193 | OUT EFI_TIME_CAPABILITIES *Capabilities, OPTIONAL\r | |
194 | IN PC_RTC_MODULE_GLOBALS *Global\r | |
195 | );\r | |
196 | \r | |
197 | /**\r | |
198 | Sets the system wakeup alarm clock time.\r | |
199 | \r | |
200 | @param Enabled Enable or disable the wakeup alarm.\r | |
201 | @param Time If Enable is TRUE, the time to set the wakeup alarm for.\r | |
202 | If Enable is FALSE, then this parameter is optional, and may be NULL.\r | |
203 | @param Global For global use inside this module.\r | |
204 | \r | |
205 | @retval EFI_SUCCESS If Enable is TRUE, then the wakeup alarm was enabled.\r | |
206 | If Enable is FALSE, then the wakeup alarm was disabled.\r | |
207 | @retval EFI_INVALID_PARAMETER A time field is out of range.\r | |
208 | @retval EFI_DEVICE_ERROR The wakeup time could not be set due to a hardware error.\r | |
209 | @retval EFI_UNSUPPORTED A wakeup timer is not supported on this platform.\r | |
210 | \r | |
211 | **/\r | |
212 | EFI_STATUS\r | |
213 | PcRtcSetWakeupTime (\r | |
214 | IN BOOLEAN Enable,\r | |
215 | IN EFI_TIME *Time, OPTIONAL\r | |
216 | IN PC_RTC_MODULE_GLOBALS *Global\r | |
217 | );\r | |
218 | \r | |
219 | /**\r | |
220 | Returns the current wakeup alarm clock setting.\r | |
221 | \r | |
222 | @param Enabled Indicates if the alarm is currently enabled or disabled.\r | |
223 | @param Pending Indicates if the alarm signal is pending and requires acknowledgement.\r | |
224 | @param Time The current alarm setting.\r | |
225 | @param Global For global use inside this module.\r | |
226 | \r | |
227 | @retval EFI_SUCCESS The alarm settings were returned.\r | |
228 | @retval EFI_INVALID_PARAMETER Enabled is NULL.\r | |
229 | @retval EFI_INVALID_PARAMETER Pending is NULL.\r | |
230 | @retval EFI_INVALID_PARAMETER Time is NULL.\r | |
231 | @retval EFI_DEVICE_ERROR The wakeup time could not be retrieved due to a hardware error.\r | |
232 | @retval EFI_UNSUPPORTED A wakeup timer is not supported on this platform.\r | |
233 | \r | |
234 | **/\r | |
235 | EFI_STATUS\r | |
236 | PcRtcGetWakeupTime (\r | |
237 | OUT BOOLEAN *Enabled,\r | |
238 | OUT BOOLEAN *Pending,\r | |
239 | OUT EFI_TIME *Time,\r | |
240 | IN PC_RTC_MODULE_GLOBALS *Global\r | |
241 | );\r | |
242 | \r | |
243 | /**\r | |
244 | The user Entry Point for PcRTC module.\r | |
245 | \r | |
246 | This is the entrhy point for PcRTC module. It installs the UEFI runtime service\r | |
247 | including GetTime(),SetTime(),GetWakeupTime(),and SetWakeupTime().\r | |
248 | \r | |
249 | @param ImageHandle The firmware allocated handle for the EFI image.\r | |
250 | @param SystemTable A pointer to the EFI System Table.\r | |
251 | \r | |
252 | @retval EFI_SUCCESS The entry point is executed successfully.\r | |
253 | @retval Others Some error occurs when executing this entry point.\r | |
254 | \r | |
255 | **/\r | |
256 | EFI_STATUS\r | |
257 | EFIAPI\r | |
258 | InitializePcRtc (\r | |
259 | IN EFI_HANDLE ImageHandle,\r | |
260 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
261 | );\r | |
262 | \r | |
263 | /**\r | |
264 | See if all fields of a variable of EFI_TIME type is correct.\r | |
265 | \r | |
266 | @param Time The time to be checked.\r | |
267 | \r | |
268 | @retval EFI_INVALID_PARAMETER Some fields of Time are not correct.\r | |
269 | @retval EFI_SUCCESS Time is a valid EFI_TIME variable.\r | |
270 | \r | |
271 | **/\r | |
272 | EFI_STATUS\r | |
273 | RtcTimeFieldsValid (\r | |
274 | IN EFI_TIME *Time\r | |
275 | );\r | |
276 | \r | |
277 | /**\r | |
278 | Converts time from EFI_TIME format defined by UEFI spec to RTC's.\r | |
279 | \r | |
280 | This function converts time from EFI_TIME format defined by UEFI spec to RTC's.\r | |
281 | If data mode of RTC is BCD, then converts EFI_TIME to it.\r | |
282 | If RTC is in 12-hour format, then converts EFI_TIME to it.\r | |
283 | \r | |
284 | @param Time On input, the time data read from UEFI to convert\r | |
285 | On output, the time converted to RTC format\r | |
286 | @param RegisterB Value of Register B of RTC, indicating data mode\r | |
287 | **/\r | |
288 | VOID\r | |
289 | ConvertEfiTimeToRtcTime (\r | |
290 | IN OUT EFI_TIME *Time,\r | |
291 | IN RTC_REGISTER_B RegisterB\r | |
292 | );\r | |
293 | \r | |
294 | \r | |
295 | /**\r | |
296 | Converts time read from RTC to EFI_TIME format defined by UEFI spec.\r | |
297 | \r | |
298 | This function converts raw time data read from RTC to the EFI_TIME format\r | |
299 | defined by UEFI spec.\r | |
300 | If data mode of RTC is BCD, then converts it to decimal,\r | |
301 | If RTC is in 12-hour format, then converts it to 24-hour format.\r | |
302 | \r | |
303 | @param Time On input, the time data read from RTC to convert\r | |
304 | On output, the time converted to UEFI format\r | |
305 | @param RegisterB Value of Register B of RTC, indicating data mode\r | |
306 | and hour format.\r | |
307 | \r | |
308 | @retval EFI_INVALID_PARAMETER Parameters passed in are invalid.\r | |
309 | @retval EFI_SUCCESS Convert RTC time to EFI time successfully.\r | |
310 | \r | |
311 | **/\r | |
312 | EFI_STATUS\r | |
313 | ConvertRtcTimeToEfiTime (\r | |
314 | IN OUT EFI_TIME *Time,\r | |
315 | IN RTC_REGISTER_B RegisterB\r | |
316 | );\r | |
317 | \r | |
318 | /**\r | |
319 | Wait for a period for the RTC to be ready.\r | |
320 | \r | |
321 | @param Timeout Tell how long it should take to wait.\r | |
322 | \r | |
323 | @retval EFI_DEVICE_ERROR RTC device error.\r | |
324 | @retval EFI_SUCCESS RTC is updated and ready. \r | |
325 | **/\r | |
326 | EFI_STATUS\r | |
327 | RtcWaitToUpdate (\r | |
328 | UINTN Timeout\r | |
329 | );\r | |
330 | \r | |
331 | /**\r | |
332 | See if field Day of an EFI_TIME is correct.\r | |
333 | \r | |
334 | @param Time Its Day field is to be checked.\r | |
335 | \r | |
336 | @retval TRUE Day field of Time is correct.\r | |
337 | @retval FALSE Day field of Time is NOT correct.\r | |
338 | **/\r | |
339 | BOOLEAN\r | |
340 | DayValid (\r | |
341 | IN EFI_TIME *Time\r | |
342 | );\r | |
343 | \r | |
344 | /**\r | |
345 | Check if it is a leapyear.\r | |
346 | \r | |
347 | @param Time The time to be checked.\r | |
348 | \r | |
349 | @retval TRUE It is a leapyear.\r | |
350 | @retval FALSE It is NOT a leapyear.\r | |
351 | **/\r | |
352 | BOOLEAN\r | |
353 | IsLeapYear (\r | |
354 | IN EFI_TIME *Time\r | |
355 | );\r | |
356 | \r | |
357 | /**\r | |
358 | Get the century RTC address from the ACPI FADT table.\r | |
359 | \r | |
360 | @return The century RTC address or 0 if not found.\r | |
361 | **/\r | |
362 | UINT8\r | |
363 | GetCenturyRtcAddress (\r | |
364 | VOID\r | |
365 | );\r | |
366 | \r | |
367 | /**\r | |
368 | Notification function of ACPI Table change.\r | |
369 | \r | |
370 | This is a notification function registered on ACPI Table change event.\r | |
371 | It saves the Century address stored in ACPI FADT table.\r | |
372 | \r | |
373 | @param Event Event whose notification function is being invoked.\r | |
374 | @param Context Pointer to the notification function's context.\r | |
375 | \r | |
376 | **/\r | |
377 | VOID\r | |
378 | EFIAPI\r | |
379 | PcRtcAcpiTableChangeCallback (\r | |
380 | IN EFI_EVENT Event,\r | |
381 | IN VOID *Context\r | |
382 | );\r | |
383 | #endif\r |