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