ArmPlatformPkg: Minor code changes (comments, misspellings, coding stylei, line endings)
[mirror_edk2.git] / ArmPlatformPkg / Library / PL031RealTimeClockLib / PL031RealTimeClockLib.c
CommitLineData
1d5d0ae9 1/** @file\r
2 Implement EFI RealTimeClock runtime services via RTC Lib.\r
0f4386e7 3\r
1d5d0ae9 4 Currently this driver does not support runtime virtual calling.\r
5\r
6 Copyright (c) 2008 - 2010, Apple Inc. All rights reserved.<BR>\r
0f4386e7 7\r
1d5d0ae9 8 This program and the accompanying materials\r
9 are licensed and made available under the terms and conditions of the BSD License\r
10 which accompanies this distribution. The full text of the license may be found at\r
11 http://opensource.org/licenses/bsd-license.php\r
12\r
13 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
14 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
15\r
16**/\r
17\r
0f4386e7 18#include <Uefi.h>\r
1d5d0ae9 19#include <PiDxe.h>\r
20#include <Library/BaseLib.h>\r
21#include <Library/DebugLib.h>\r
0f4386e7 22#include <Library/UefiLib.h>\r
1d5d0ae9 23#include <Library/IoLib.h>\r
24#include <Library/RealTimeClockLib.h>\r
0f4386e7 25#include <Library/MemoryAllocationLib.h>\r
5cc45b70 26#include <Library/PcdLib.h>\r
0f4386e7 27#include <Library/ArmPlatformSysConfigLib.h>\r
28#include <Library/UefiBootServicesTableLib.h>\r
29#include <Library/UefiRuntimeServicesTableLib.h>\r
30#include <Protocol/RealTimeClock.h>\r
31#include <Guid/GlobalVariable.h>\r
0f4386e7 32#include <Drivers/PL031RealTimeClock.h>\r
33\r
5cc45b70 34#include <ArmPlatform.h>\r
35\r
0f4386e7 36CHAR16 mTimeZoneVariableName[] = L"PL031_TimeZone";\r
37CHAR16 mDaylightVariableName[] = L"PL031_Daylight";\r
38BOOLEAN mPL031Initialized = FALSE;\r
39\r
40EFI_STATUS\r
41IdentifyPL031 (\r
42 VOID\r
43 )\r
44{\r
45 EFI_STATUS Status;\r
46\r
47 // Check if this is a PrimeCell Peripheral\r
5cc45b70 48 if ( (MmioRead8 (PL031_RTC_PCELL_ID0) != 0x0D)\r
49 || (MmioRead8 (PL031_RTC_PCELL_ID1) != 0xF0)\r
50 || (MmioRead8 (PL031_RTC_PCELL_ID2) != 0x05)\r
51 || (MmioRead8 (PL031_RTC_PCELL_ID3) != 0xB1)) {\r
0f4386e7 52 Status = EFI_NOT_FOUND;\r
53 goto EXIT;\r
54 }\r
55\r
0db25ccc 56 // Check if this PrimeCell Peripheral is the PL031 Real Time Clock\r
5cc45b70 57 if ( (MmioRead8 (PL031_RTC_PERIPH_ID0) != 0x31)\r
58 || (MmioRead8 (PL031_RTC_PERIPH_ID1) != 0x10)\r
59 || ((MmioRead8 (PL031_RTC_PERIPH_ID2) & 0xF) != 0x04)\r
60 || (MmioRead8 (PL031_RTC_PERIPH_ID3) != 0x00)) {\r
0f4386e7 61 Status = EFI_NOT_FOUND;\r
62 goto EXIT;\r
63 }\r
64\r
65 Status = EFI_SUCCESS;\r
66\r
67 EXIT:\r
68 return Status;\r
69}\r
70\r
71EFI_STATUS\r
72InitializePL031 (\r
73 VOID\r
74 )\r
75{\r
76 EFI_STATUS Status;\r
77\r
78 // Prepare the hardware\r
79 Status = IdentifyPL031();\r
80 if (EFI_ERROR (Status)) {\r
81 goto EXIT;\r
82 }\r
83\r
84 // Ensure interrupts are masked. We do not want RTC interrupts in UEFI\r
5cc45b70 85 if ((MmioRead32 (PL031_RTC_IMSC_IRQ_MASK_SET_CLEAR_REGISTER) & PL031_SET_IRQ_MASK) != PL031_SET_IRQ_MASK) {\r
86 MmioOr32 (PL031_RTC_IMSC_IRQ_MASK_SET_CLEAR_REGISTER, PL031_SET_IRQ_MASK);\r
0f4386e7 87 }\r
88\r
89 // Clear any existing interrupts\r
5cc45b70 90 if ((MmioRead32 (PL031_RTC_RIS_RAW_IRQ_STATUS_REGISTER) & PL031_IRQ_TRIGGERED) == PL031_IRQ_TRIGGERED) {\r
91 MmioOr32 (PL031_RTC_ICR_IRQ_CLEAR_REGISTER, PL031_CLEAR_IRQ);\r
0f4386e7 92 }\r
93\r
94 // Start the clock counter\r
5cc45b70 95 if ((MmioRead32 (PL031_RTC_CR_CONTROL_REGISTER) & PL031_RTC_ENABLED) != PL031_RTC_ENABLED) {\r
96 MmioOr32 (PL031_RTC_CR_CONTROL_REGISTER, PL031_RTC_ENABLED);\r
0f4386e7 97 }\r
98\r
99 mPL031Initialized = TRUE;\r
100\r
101 EXIT:\r
102 return Status;\r
103}\r
104\r
105/**\r
106 Converts Epoch seconds (elapsed since 1970 JANUARY 01, 00:00:00 UTC) to EFI_TIME\r
107 **/\r
108VOID\r
109EpochToEfiTime (\r
110 IN UINTN EpochSeconds,\r
111 OUT EFI_TIME *Time\r
112 )\r
113{\r
114 UINTN a;\r
115 UINTN b;\r
116 UINTN c;\r
117 UINTN d;\r
118 UINTN g;\r
119 UINTN j;\r
120 UINTN m;\r
121 UINTN y;\r
122 UINTN da;\r
123 UINTN db;\r
124 UINTN dc;\r
125 UINTN dg;\r
126 UINTN hh;\r
127 UINTN mm;\r
128 UINTN ss;\r
129 UINTN J;\r
130\r
5cc45b70 131 if (Time->Daylight == TRUE) {\r
0f4386e7 132\r
133 }\r
134\r
135 J = (EpochSeconds / 86400) + 2440588;\r
136 j = J + 32044;\r
137 g = j / 146097;\r
138 dg = j % 146097;\r
139 c = (((dg / 36524) + 1) * 3) / 4;\r
140 dc = dg - (c * 36524);\r
141 b = dc / 1461;\r
142 db = dc % 1461;\r
143 a = (((db / 365) + 1) * 3) / 4;\r
144 da = db - (a * 365);\r
145 y = (g * 400) + (c * 100) + (b * 4) + a;\r
146 m = (((da * 5) + 308) / 153) - 2;\r
147 d = da - (((m + 4) * 153) / 5) + 122;\r
148\r
149 Time->Year = y - 4800 + ((m + 2) / 12);\r
150 Time->Month = ((m + 2) % 12) + 1;\r
151 Time->Day = d + 1;\r
152\r
153 ss = EpochSeconds % 60;\r
154 a = (EpochSeconds - ss) / 60;\r
155 mm = a % 60;\r
156 b = (a - mm) / 60;\r
157 hh = b % 24;\r
158\r
159 Time->Hour = hh;\r
160 Time->Minute = mm;\r
161 Time->Second = ss;\r
162 Time->Nanosecond = 0;\r
163\r
164}\r
165\r
166/**\r
167 Converts EFI_TIME to Epoch seconds (elapsed since 1970 JANUARY 01, 00:00:00 UTC)\r
168 **/\r
169UINTN\r
170EfiTimeToEpoch (\r
171 IN EFI_TIME *Time\r
172 )\r
173{\r
174 UINTN a;\r
175 UINTN y;\r
176 UINTN m;\r
177 UINTN JulianDate; // Absolute Julian Date representation of the supplied Time\r
178 UINTN EpochDays; // Number of days elapsed since EPOCH_JULIAN_DAY\r
179 UINTN EpochSeconds;\r
180\r
181 a = (14 - Time->Month) / 12 ;\r
182 y = Time->Year + 4800 - a;\r
183 m = Time->Month + (12*a) - 3;\r
184\r
185 JulianDate = Time->Day + ((153*m + 2)/5) + (365*y) + (y/4) - (y/100) + (y/400) - 32045;\r
186\r
5cc45b70 187 ASSERT(JulianDate > EPOCH_JULIAN_DATE);\r
0f4386e7 188 EpochDays = JulianDate - EPOCH_JULIAN_DATE;\r
189\r
190 EpochSeconds = (EpochDays * SEC_PER_DAY) + ((UINTN)Time->Hour * SEC_PER_HOUR) + (Time->Minute * SEC_PER_MIN) + Time->Second;\r
191\r
192 return EpochSeconds;\r
193}\r
194\r
195BOOLEAN\r
196IsLeapYear (\r
197 IN EFI_TIME *Time\r
198 )\r
199{\r
200 if (Time->Year % 4 == 0) {\r
201 if (Time->Year % 100 == 0) {\r
202 if (Time->Year % 400 == 0) {\r
203 return TRUE;\r
204 } else {\r
205 return FALSE;\r
206 }\r
207 } else {\r
208 return TRUE;\r
209 }\r
210 } else {\r
211 return FALSE;\r
212 }\r
213}\r
214\r
215BOOLEAN\r
216DayValid (\r
217 IN EFI_TIME *Time\r
218 )\r
219{\r
220 INTN DayOfMonth[12] = { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };\r
1d5d0ae9 221\r
0f4386e7 222 if (Time->Day < 1 ||\r
223 Time->Day > DayOfMonth[Time->Month - 1] ||\r
224 (Time->Month == 2 && (!IsLeapYear (Time) && Time->Day > 28))\r
5cc45b70 225 ) {\r
0f4386e7 226 return FALSE;\r
227 }\r
228\r
229 return TRUE;\r
230}\r
1d5d0ae9 231\r
232/**\r
233 Returns the current time and date information, and the time-keeping capabilities\r
234 of the hardware platform.\r
235\r
236 @param Time A pointer to storage to receive a snapshot of the current time.\r
237 @param Capabilities An optional pointer to a buffer to receive the real time clock\r
238 device's capabilities.\r
239\r
240 @retval EFI_SUCCESS The operation completed successfully.\r
241 @retval EFI_INVALID_PARAMETER Time is NULL.\r
242 @retval EFI_DEVICE_ERROR The time could not be retrieved due to hardware error.\r
243\r
244**/\r
245EFI_STATUS\r
246EFIAPI\r
247LibGetTime (\r
248 OUT EFI_TIME *Time,\r
0f4386e7 249 OUT EFI_TIME_CAPABILITIES *Capabilities\r
1d5d0ae9 250 )\r
251{\r
0f4386e7 252 EFI_STATUS Status = EFI_SUCCESS;\r
253 UINTN EpochSeconds;\r
254 INT16 *TimeZone = 0;\r
255 UINTN *Daylight = 0;\r
256\r
257 // Initialize the hardware if not already done\r
5cc45b70 258 if (!mPL031Initialized) {\r
259 Status = InitializePL031 ();\r
0f4386e7 260 if (EFI_ERROR (Status)) {\r
261 goto EXIT;\r
262 }\r
263 }\r
264\r
265 // Snapshot the time as early in the function call as possible\r
266 // On some platforms we may have access to a battery backed up hardware clock.\r
267 // If such RTC exists try to use it first.\r
268 Status = ArmPlatformSysConfigGet (SYS_CFG_RTC, &EpochSeconds);\r
269 if (Status == EFI_UNSUPPORTED) {\r
270 // Battery backed up hardware RTC does not exist, revert to PL031\r
5cc45b70 271 EpochSeconds = MmioRead32 (PL031_RTC_DR_DATA_REGISTER);\r
0f4386e7 272 Status = EFI_SUCCESS;\r
273 } else if (EFI_ERROR (Status)) {\r
274 // Battery backed up hardware RTC exists but could not be read due to error. Abort.\r
275 goto EXIT;\r
276 } else {\r
277 // Battery backed up hardware RTC exists and we read the time correctly from it.\r
278 // Now sync the PL031 to the new time.\r
5cc45b70 279 MmioWrite32 (PL031_RTC_LR_LOAD_REGISTER, EpochSeconds);\r
0f4386e7 280 }\r
281\r
282 // Ensure Time is a valid pointer\r
5cc45b70 283 if (Time == NULL) {\r
0f4386e7 284 Status = EFI_INVALID_PARAMETER;\r
285 goto EXIT;\r
286 }\r
287\r
288 // Get the current time zone information from non-volatile storage\r
289 TimeZone = (INT16 *)GetVariable(mTimeZoneVariableName, &gEfiGlobalVariableGuid);\r
290\r
5cc45b70 291 if (TimeZone == NULL) {\r
0f4386e7 292 // The time zone variable does not exist in non-volatile storage, so create it.\r
293 Time->TimeZone = EFI_UNSPECIFIED_TIMEZONE;\r
294 // Store it\r
295 Status = gRT->SetVariable (\r
296 mTimeZoneVariableName,\r
297 &gEfiGlobalVariableGuid,\r
298 EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,\r
299 sizeof(Time->TimeZone),\r
300 &(Time->TimeZone)\r
5cc45b70 301 );\r
0f4386e7 302 if (EFI_ERROR (Status)) {\r
303 DEBUG((EFI_D_ERROR,"LibGetTime: ERROR: TimeZone\n"));\r
304 goto EXIT;\r
305 }\r
306 } else {\r
307 // Got the time zone\r
308 Time->TimeZone = *TimeZone;\r
309 FreePool(TimeZone);\r
310\r
311 // Check TimeZone bounds: -1440 to 1440 or 2047\r
5cc45b70 312 if (((Time->TimeZone < -1440) || (Time->TimeZone > 1440))\r
313 && (Time->TimeZone != EFI_UNSPECIFIED_TIMEZONE)) {\r
0f4386e7 314 Time->TimeZone = EFI_UNSPECIFIED_TIMEZONE;\r
315 }\r
316\r
317 // Adjust for the correct time zone\r
5cc45b70 318 if (Time->TimeZone != EFI_UNSPECIFIED_TIMEZONE) {\r
0f4386e7 319 EpochSeconds += Time->TimeZone * SEC_PER_MIN;\r
320 }\r
321 }\r
322\r
323 // Get the current daylight information from non-volatile storage\r
324 Daylight = (UINTN *)GetVariable(mDaylightVariableName, &gEfiGlobalVariableGuid);\r
325\r
5cc45b70 326 if (Daylight == NULL) {\r
0f4386e7 327 // The daylight variable does not exist in non-volatile storage, so create it.\r
328 Time->Daylight = 0;\r
329 // Store it\r
330 Status = gRT->SetVariable (\r
331 mDaylightVariableName,\r
332 &gEfiGlobalVariableGuid,\r
333 EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,\r
334 sizeof(Time->Daylight),\r
335 &(Time->Daylight)\r
5cc45b70 336 );\r
0f4386e7 337 if (EFI_ERROR (Status)) {\r
338 DEBUG((EFI_D_ERROR,"LibGetTime: ERROR: Daylight\n"));\r
339 goto EXIT;\r
340 }\r
341 } else {\r
342 // Got the daylight information\r
343 Time->Daylight = *Daylight;\r
344 FreePool(Daylight);\r
345\r
346 // Adjust for the correct period\r
5cc45b70 347 if ((Time->Daylight & EFI_TIME_IN_DAYLIGHT) == EFI_TIME_IN_DAYLIGHT) {\r
0f4386e7 348 // Convert to adjusted time, i.e. spring forwards one hour\r
349 EpochSeconds += SEC_PER_HOUR;\r
350 }\r
351 }\r
352\r
353 // Convert from internal 32-bit time to UEFI time\r
5cc45b70 354 EpochToEfiTime (EpochSeconds, Time);\r
0f4386e7 355\r
356 // Update the Capabilities info\r
5cc45b70 357 if (Capabilities != NULL) {\r
358 // PL031 runs at frequency 1Hz\r
359 Capabilities->Resolution = PL031_COUNTS_PER_SECOND;\r
360 // Accuracy in ppm multiplied by 1,000,000, e.g. for 50ppm set 50,000,000\r
361 Capabilities->Accuracy = (UINT32)PcdGet32 (PcdPL031RtcPpmAccuracy);\r
362 // FALSE: Setting the time does not clear the values below the resolution level\r
363 Capabilities->SetsToZero = FALSE;\r
0f4386e7 364 }\r
365\r
366 EXIT:\r
367 return Status;\r
1d5d0ae9 368}\r
369\r
370\r
371/**\r
372 Sets the current local time and date information.\r
373\r
374 @param Time A pointer to the current time.\r
375\r
376 @retval EFI_SUCCESS The operation completed successfully.\r
377 @retval EFI_INVALID_PARAMETER A time field is out of range.\r
378 @retval EFI_DEVICE_ERROR The time could not be set due due to hardware error.\r
379\r
380**/\r
381EFI_STATUS\r
382EFIAPI\r
383LibSetTime (\r
0f4386e7 384 IN EFI_TIME *Time\r
1d5d0ae9 385 )\r
386{\r
0f4386e7 387 EFI_STATUS Status;\r
388 UINTN EpochSeconds;\r
389\r
390 // Because the PL031 is a 32-bit counter counting seconds,\r
391 // the maximum time span is just over 136 years.\r
392 // Time is stored in Unix Epoch format, so it starts in 1970,\r
393 // Therefore it can not exceed the year 2106.\r
394 // This is not a problem for UEFI, as the current spec limits the years\r
395 // to the range 1998 .. 2011\r
396\r
397 // Check the input parameters' range.\r
5cc45b70 398 if ((Time->Year < 1998) ||\r
399 (Time->Year > 2099) ||\r
400 (Time->Month < 1 ) ||\r
401 (Time->Month > 12 ) ||\r
402 (!DayValid (Time) ) ||\r
403 (Time->Hour > 23 ) ||\r
404 (Time->Minute > 59 ) ||\r
405 (Time->Second > 59 ) ||\r
406 (Time->Nanosecond > 999999999) ||\r
407 (!((Time->TimeZone == EFI_UNSPECIFIED_TIMEZONE) || ((Time->TimeZone >= -1440) && (Time->TimeZone <= 1440)))) ||\r
408 (Time->Daylight & (~(EFI_TIME_ADJUST_DAYLIGHT | EFI_TIME_IN_DAYLIGHT)))\r
409 ) {\r
0f4386e7 410 Status = EFI_INVALID_PARAMETER;\r
411 goto EXIT;\r
412 }\r
413\r
414 // Initialize the hardware if not already done\r
5cc45b70 415 if (!mPL031Initialized) {\r
416 Status = InitializePL031 ();\r
0f4386e7 417 if (EFI_ERROR (Status)) {\r
418 goto EXIT;\r
419 }\r
420 }\r
421\r
5cc45b70 422 EpochSeconds = EfiTimeToEpoch (Time);\r
0f4386e7 423\r
424 // Adjust for the correct time zone, i.e. convert to UTC time zone\r
5cc45b70 425 if (Time->TimeZone != EFI_UNSPECIFIED_TIMEZONE) {\r
0f4386e7 426 EpochSeconds -= Time->TimeZone * SEC_PER_MIN;\r
427 }\r
428\r
429 // TODO: Automatic Daylight activation\r
430\r
431 // Adjust for the correct period\r
5cc45b70 432 if ((Time->Daylight & EFI_TIME_IN_DAYLIGHT) == EFI_TIME_IN_DAYLIGHT) {\r
0f4386e7 433 // Convert to un-adjusted time, i.e. fall back one hour\r
434 EpochSeconds -= SEC_PER_HOUR;\r
435 }\r
436\r
437 // On some platforms we may have access to a battery backed up hardware clock.\r
1d5d0ae9 438 //\r
0f4386e7 439 // If such RTC exists then it must be updated first, before the PL031,\r
440 // to minimise any time drift. This is important because the battery backed-up\r
441 // RTC maintains the master time for the platform across reboots.\r
1d5d0ae9 442 //\r
0f4386e7 443 // If such RTC does not exist then the following function returns UNSUPPORTED.\r
444 Status = ArmPlatformSysConfigSet (SYS_CFG_RTC, EpochSeconds);\r
445 if ((EFI_ERROR (Status)) && (Status != EFI_UNSUPPORTED)){\r
446 // Any status message except SUCCESS and UNSUPPORTED indicates a hardware failure.\r
447 goto EXIT;\r
448 }\r
449\r
450\r
451 // Set the PL031\r
5cc45b70 452 MmioWrite32 (PL031_RTC_LR_LOAD_REGISTER, EpochSeconds);\r
0f4386e7 453\r
454 // The accesses to Variable Services can be very slow, because we may be writing to Flash.\r
455 // Do this after having set the RTC.\r
456\r
457 // Save the current time zone information into non-volatile storage\r
458 Status = gRT->SetVariable (\r
459 mTimeZoneVariableName,\r
460 &gEfiGlobalVariableGuid,\r
461 EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,\r
462 sizeof(Time->TimeZone),\r
463 &(Time->TimeZone)\r
5cc45b70 464 );\r
0f4386e7 465 if (EFI_ERROR (Status)) {\r
466 DEBUG((EFI_D_ERROR,"LibSetTime: ERROR: TimeZone\n"));\r
467 goto EXIT;\r
468 }\r
469\r
470 // Save the current daylight information into non-volatile storage\r
471 Status = gRT->SetVariable (\r
472 mDaylightVariableName,\r
473 &gEfiGlobalVariableGuid,\r
474 EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,\r
475 sizeof(Time->Daylight),\r
476 &(Time->Daylight)\r
5cc45b70 477 );\r
0f4386e7 478 if (EFI_ERROR (Status)) {\r
479 DEBUG((EFI_D_ERROR,"LibSetTime: ERROR: Daylight\n"));\r
480 goto EXIT;\r
481 }\r
482\r
483 EXIT:\r
484 return Status;\r
1d5d0ae9 485}\r
486\r
487\r
488/**\r
489 Returns the current wakeup alarm clock setting.\r
490\r
491 @param Enabled Indicates if the alarm is currently enabled or disabled.\r
492 @param Pending Indicates if the alarm signal is pending and requires acknowledgement.\r
493 @param Time The current alarm setting.\r
494\r
495 @retval EFI_SUCCESS The alarm settings were returned.\r
496 @retval EFI_INVALID_PARAMETER Any parameter is NULL.\r
497 @retval EFI_DEVICE_ERROR The wakeup time could not be retrieved due to a hardware error.\r
498\r
499**/\r
500EFI_STATUS\r
501EFIAPI\r
502LibGetWakeupTime (\r
503 OUT BOOLEAN *Enabled,\r
504 OUT BOOLEAN *Pending,\r
505 OUT EFI_TIME *Time\r
506 )\r
507{\r
508 // Not a required feature\r
509 return EFI_UNSUPPORTED;\r
510}\r
511\r
512\r
513/**\r
514 Sets the system wakeup alarm clock time.\r
515\r
516 @param Enabled Enable or disable the wakeup alarm.\r
517 @param Time If Enable is TRUE, the time to set the wakeup alarm for.\r
518\r
519 @retval EFI_SUCCESS If Enable is TRUE, then the wakeup alarm was enabled. If\r
520 Enable is FALSE, then the wakeup alarm was disabled.\r
521 @retval EFI_INVALID_PARAMETER A time field is out of range.\r
522 @retval EFI_DEVICE_ERROR The wakeup time could not be set due to a hardware error.\r
523 @retval EFI_UNSUPPORTED A wakeup timer is not supported on this platform.\r
524\r
525**/\r
526EFI_STATUS\r
527EFIAPI\r
528LibSetWakeupTime (\r
529 IN BOOLEAN Enabled,\r
530 OUT EFI_TIME *Time\r
531 )\r
532{\r
533 // Not a required feature\r
534 return EFI_UNSUPPORTED;\r
535}\r
536\r
537\r
538\r
539/**\r
540 This is the declaration of an EFI image entry point. This can be the entry point to an application\r
541 written to this specification, an EFI boot service driver, or an EFI runtime driver.\r
542\r
543 @param ImageHandle Handle that identifies the loaded image.\r
544 @param SystemTable System Table for this image.\r
545\r
546 @retval EFI_SUCCESS The operation completed successfully.\r
547\r
548**/\r
549EFI_STATUS\r
550EFIAPI\r
551LibRtcInitialize (\r
552 IN EFI_HANDLE ImageHandle,\r
553 IN EFI_SYSTEM_TABLE *SystemTable\r
554 )\r
555{\r
0f4386e7 556 EFI_STATUS Status;\r
557 EFI_HANDLE Handle;\r
558\r
559 // Setup the setters and getters\r
560 gRT->GetTime = LibGetTime;\r
561 gRT->SetTime = LibSetTime;\r
562 gRT->GetWakeupTime = LibGetWakeupTime;\r
563 gRT->SetWakeupTime = LibSetWakeupTime;\r
564\r
565 // Install the protocol\r
566 Handle = NULL;\r
567 Status = gBS->InstallMultipleProtocolInterfaces (\r
568 &Handle,\r
569 &gEfiRealTimeClockArchProtocolGuid, NULL,\r
570 NULL\r
5cc45b70 571 );\r
0f4386e7 572\r
573 return Status;\r
1d5d0ae9 574}\r
575\r
576\r
577/**\r
578 Fixup internal data so that EFI can be call in virtual mode.\r
579 Call the passed in Child Notify event and convert any pointers in\r
580 lib to virtual mode.\r
581\r
582 @param[in] Event The Event that is being processed\r
583 @param[in] Context Event Context\r
584**/\r
585VOID\r
586EFIAPI\r
587LibRtcVirtualNotifyEvent (\r
588 IN EFI_EVENT Event,\r
589 IN VOID *Context\r
590 )\r
591{\r
592 //\r
593 // Only needed if you are going to support the OS calling RTC functions in virtual mode.\r
0f4386e7 594 // You will need to call EfiConvertPointer (). To convert any stored physical addresses\r
595 // to virtual address. After the OS transitions to calling in virtual mode, all future\r
1d5d0ae9 596 // runtime calls will be made in virtual mode.\r
597 //\r
598 return;\r
599}\r