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