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