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