]> git.proxmox.com Git - mirror_edk2.git/blame_incremental - PcAtChipsetPkg/PcatRealTimeClockRuntimeDxe/PcRtc.h
NetworkPkg: Clean up source files
[mirror_edk2.git] / PcAtChipsetPkg / PcatRealTimeClockRuntimeDxe / PcRtc.h
... / ...
CommitLineData
1/** @file\r
2 Header file for real time clock driver.\r
3\r
4Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>\r
5Copyright (c) 2017, AMD Inc. All rights reserved.<BR>\r
6\r
7This program and the accompanying materials\r
8are licensed and made available under the terms and conditions of the BSD License\r
9which accompanies this distribution. The full text of the license may be found at\r
10http://opensource.org/licenses/bsd-license.php\r
11\r
12THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
13WITHOUT 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
41typedef 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
48extern PC_RTC_MODULE_GLOBALS mModuleGlobal;\r
49\r
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
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
76\r
77#pragma pack(1)\r
78//\r
79// Register A\r
80//\r
81typedef struct {\r
82 UINT8 Rs : 4; // Rate Selection Bits\r
83 UINT8 Dv : 3; // Divisor\r
84 UINT8 Uip : 1; // Update in progress\r
85} RTC_REGISTER_A_BITS;\r
86\r
87typedef 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
95typedef struct {\r
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
104} RTC_REGISTER_B_BITS;\r
105\r
106typedef 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
114typedef struct {\r
115 UINT8 Reserved : 4; // Read as zero. Can not be written.\r
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
120} RTC_REGISTER_C_BITS;\r
121\r
122typedef 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
130typedef struct {\r
131 UINT8 Reserved : 7; // Read as zero. Can not be written.\r
132 UINT8 Vrt : 1; // Valid RAM and Time\r
133} RTC_REGISTER_D_BITS;\r
134\r
135typedef 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
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
151EFI_STATUS\r
152PcRtcInit (\r
153 IN PC_RTC_MODULE_GLOBALS *Global\r
154 );\r
155\r
156/**\r
157 Sets the current local time and date information.\r
158\r
159 @param Time A pointer to the current time.\r
160 @param Global For global use inside this module.\r
161\r
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
165\r
166**/\r
167EFI_STATUS\r
168PcRtcSetTime (\r
169 IN EFI_TIME *Time,\r
170 IN PC_RTC_MODULE_GLOBALS *Global\r
171 );\r
172\r
173/**\r
174 Returns the current time and date information, and the time-keeping capabilities\r
175 of the hardware platform.\r
176\r
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
181\r
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
185\r
186**/\r
187EFI_STATUS\r
188PcRtcGetTime (\r
189 OUT EFI_TIME *Time,\r
190 OUT EFI_TIME_CAPABILITIES *Capabilities, OPTIONAL\r
191 IN PC_RTC_MODULE_GLOBALS *Global\r
192 );\r
193\r
194/**\r
195 Sets the system wakeup alarm clock time.\r
196\r
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
201\r
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
207\r
208**/\r
209EFI_STATUS\r
210PcRtcSetWakeupTime (\r
211 IN BOOLEAN Enable,\r
212 IN EFI_TIME *Time, OPTIONAL\r
213 IN PC_RTC_MODULE_GLOBALS *Global\r
214 );\r
215\r
216/**\r
217 Returns the current wakeup alarm clock setting.\r
218\r
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
223\r
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
230\r
231**/\r
232EFI_STATUS\r
233PcRtcGetWakeupTime (\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
238 );\r
239\r
240/**\r
241 The user Entry Point for PcRTC module.\r
242\r
243 This is the entrhy point for PcRTC module. It installs the UEFI runtime service\r
244 including GetTime(),SetTime(),GetWakeupTime(),and SetWakeupTime().\r
245\r
246 @param ImageHandle The firmware allocated handle for the EFI image.\r
247 @param SystemTable A pointer to the EFI System Table.\r
248\r
249 @retval EFI_SUCCESS The entry point is executed successfully.\r
250 @retval Others Some error occurs when executing this entry point.\r
251\r
252**/\r
253EFI_STATUS\r
254EFIAPI\r
255InitializePcRtc (\r
256 IN EFI_HANDLE ImageHandle,\r
257 IN EFI_SYSTEM_TABLE *SystemTable\r
258 );\r
259\r
260/**\r
261 See if all fields of a variable of EFI_TIME type is correct.\r
262\r
263 @param Time The time to be checked.\r
264\r
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
267\r
268**/\r
269EFI_STATUS\r
270RtcTimeFieldsValid (\r
271 IN EFI_TIME *Time\r
272 );\r
273\r
274/**\r
275 Converts time from EFI_TIME format defined by UEFI spec to RTC's.\r
276\r
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
280\r
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
284**/\r
285VOID\r
286ConvertEfiTimeToRtcTime (\r
287 IN OUT EFI_TIME *Time,\r
288 IN RTC_REGISTER_B RegisterB\r
289 );\r
290\r
291\r
292/**\r
293 Converts time read from RTC to EFI_TIME format defined by UEFI spec.\r
294\r
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
299\r
300 @param Time On input, the time data read from RTC to convert\r
301 On output, the time converted to UEFI format\r
302 @param RegisterB Value of Register B of RTC, indicating data mode\r
303 and hour format.\r
304\r
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
308**/\r
309EFI_STATUS\r
310ConvertRtcTimeToEfiTime (\r
311 IN OUT EFI_TIME *Time,\r
312 IN RTC_REGISTER_B RegisterB\r
313 );\r
314\r
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
323EFI_STATUS\r
324RtcWaitToUpdate (\r
325 UINTN Timeout\r
326 );\r
327\r
328/**\r
329 See if field Day of an EFI_TIME is correct.\r
330\r
331 @param Time Its Day field is to be checked.\r
332\r
333 @retval TRUE Day field of Time is correct.\r
334 @retval FALSE Day field of Time is NOT correct.\r
335**/\r
336BOOLEAN\r
337DayValid (\r
338 IN EFI_TIME *Time\r
339 );\r
340\r
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
349BOOLEAN\r
350IsLeapYear (\r
351 IN EFI_TIME *Time\r
352 );\r
353\r
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
359UINT8\r
360GetCenturyRtcAddress (\r
361 VOID\r
362 );\r
363\r
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
374VOID\r
375EFIAPI\r
376PcRtcAcpiTableChangeCallback (\r
377 IN EFI_EVENT Event,\r
378 IN VOID *Context\r
379 );\r
380#endif\r