]>
Commit | Line | Data |
---|---|---|
1 | /** @file\r | |
2 | Implement EFI RealTimeClock runtime services via RTC Lib.\r | |
3 | \r | |
4 | Copyright (c) 2008 - 2010, Apple Inc. All rights reserved.<BR>\r | |
5 | Copyright (c) 2011 - 2014, ARM Ltd. All rights reserved.<BR>\r | |
6 | \r | |
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 | |
17 | #include <Uefi.h>\r | |
18 | #include <PiDxe.h>\r | |
19 | #include <Library/BaseLib.h>\r | |
20 | #include <Library/DebugLib.h>\r | |
21 | #include <Library/UefiLib.h>\r | |
22 | #include <Library/IoLib.h>\r | |
23 | #include <Library/RealTimeClockLib.h>\r | |
24 | #include <Library/MemoryAllocationLib.h>\r | |
25 | #include <Library/PcdLib.h>\r | |
26 | #include <Library/ArmPlatformSysConfigLib.h>\r | |
27 | #include <Library/DxeServicesTableLib.h>\r | |
28 | #include <Library/UefiBootServicesTableLib.h>\r | |
29 | #include <Library/UefiRuntimeServicesTableLib.h>\r | |
30 | #include <Library/UefiRuntimeLib.h>\r | |
31 | \r | |
32 | #include <Protocol/RealTimeClock.h>\r | |
33 | \r | |
34 | #include <Guid/GlobalVariable.h>\r | |
35 | #include <Guid/EventGroup.h>\r | |
36 | \r | |
37 | #include <Drivers/PL031RealTimeClock.h>\r | |
38 | \r | |
39 | #include <Library/TimeBaseLib.h>\r | |
40 | \r | |
41 | #include <ArmPlatform.h>\r | |
42 | \r | |
43 | STATIC CONST CHAR16 mTimeZoneVariableName[] = L"PL031RtcTimeZone";\r | |
44 | STATIC CONST CHAR16 mDaylightVariableName[] = L"PL031RtcDaylight";\r | |
45 | STATIC BOOLEAN mPL031Initialized = FALSE;\r | |
46 | STATIC EFI_EVENT mRtcVirtualAddrChangeEvent;\r | |
47 | STATIC UINTN mPL031RtcBase;\r | |
48 | \r | |
49 | EFI_STATUS\r | |
50 | IdentifyPL031 (\r | |
51 | VOID\r | |
52 | )\r | |
53 | {\r | |
54 | EFI_STATUS Status;\r | |
55 | \r | |
56 | // Check if this is a PrimeCell Peripheral\r | |
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 | |
61 | Status = EFI_NOT_FOUND;\r | |
62 | goto EXIT;\r | |
63 | }\r | |
64 | \r | |
65 | // Check if this PrimeCell Peripheral is the PL031 Real Time Clock\r | |
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 | |
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 | |
80 | EFI_STATUS\r | |
81 | InitializePL031 (\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 | |
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 | |
96 | }\r | |
97 | \r | |
98 | // Clear any existing interrupts\r | |
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 | |
101 | }\r | |
102 | \r | |
103 | // Start the clock counter\r | |
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 | |
106 | }\r | |
107 | \r | |
108 | mPL031Initialized = TRUE;\r | |
109 | \r | |
110 | EXIT:\r | |
111 | return Status;\r | |
112 | }\r | |
113 | \r | |
114 | /**\r | |
115 | Returns the current time and date information, and the time-keeping capabilities\r | |
116 | of the hardware platform.\r | |
117 | \r | |
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 | |
121 | \r | |
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 | |
126 | \r | |
127 | **/\r | |
128 | EFI_STATUS\r | |
129 | EFIAPI\r | |
130 | LibGetTime (\r | |
131 | OUT EFI_TIME *Time,\r | |
132 | OUT EFI_TIME_CAPABILITIES *Capabilities\r | |
133 | )\r | |
134 | {\r | |
135 | EFI_STATUS Status = EFI_SUCCESS;\r | |
136 | UINT32 EpochSeconds;\r | |
137 | INT16 TimeZone;\r | |
138 | UINT8 Daylight;\r | |
139 | UINTN Size;\r | |
140 | \r | |
141 | // Initialize the hardware if not already done\r | |
142 | if (!mPL031Initialized) {\r | |
143 | Status = InitializePL031 ();\r | |
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 | |
155 | EpochSeconds = MmioRead32 (mPL031RtcBase + PL031_RTC_DR_DATA_REGISTER);\r | |
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 | |
163 | MmioWrite32 (mPL031RtcBase + PL031_RTC_LR_LOAD_REGISTER, EpochSeconds);\r | |
164 | }\r | |
165 | \r | |
166 | // Ensure Time is a valid pointer\r | |
167 | if (Time == NULL) {\r | |
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 | |
173 | Size = sizeof (TimeZone);\r | |
174 | Status = EfiGetVariable (\r | |
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 | |
188 | \r | |
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 | |
192 | Status = EfiSetVariable (\r | |
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 | |
199 | if (EFI_ERROR (Status)) {\r | |
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 | |
206 | goto EXIT;\r | |
207 | }\r | |
208 | } else {\r | |
209 | // Got the time zone\r | |
210 | Time->TimeZone = TimeZone;\r | |
211 | \r | |
212 | // Check TimeZone bounds: -1440 to 1440 or 2047\r | |
213 | if (((Time->TimeZone < -1440) || (Time->TimeZone > 1440))\r | |
214 | && (Time->TimeZone != EFI_UNSPECIFIED_TIMEZONE)) {\r | |
215 | Time->TimeZone = EFI_UNSPECIFIED_TIMEZONE;\r | |
216 | }\r | |
217 | \r | |
218 | // Adjust for the correct time zone\r | |
219 | if (Time->TimeZone != EFI_UNSPECIFIED_TIMEZONE) {\r | |
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 | |
225 | Size = sizeof (Daylight);\r | |
226 | Status = EfiGetVariable (\r | |
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 | |
240 | \r | |
241 | // The daylight variable does not exist in non-volatile storage, so create it.\r | |
242 | Time->Daylight = 0;\r | |
243 | // Store it\r | |
244 | Status = EfiSetVariable (\r | |
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 | |
251 | if (EFI_ERROR (Status)) {\r | |
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 | |
258 | goto EXIT;\r | |
259 | }\r | |
260 | } else {\r | |
261 | // Got the daylight information\r | |
262 | Time->Daylight = Daylight;\r | |
263 | \r | |
264 | // Adjust for the correct period\r | |
265 | if ((Time->Daylight & EFI_TIME_IN_DAYLIGHT) == EFI_TIME_IN_DAYLIGHT) {\r | |
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 | |
272 | EpochToEfiTime (EpochSeconds, Time);\r | |
273 | \r | |
274 | // Update the Capabilities info\r | |
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 | |
282 | }\r | |
283 | \r | |
284 | EXIT:\r | |
285 | return Status;\r | |
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 | |
299 | EFI_STATUS\r | |
300 | EFIAPI\r | |
301 | LibSetTime (\r | |
302 | IN EFI_TIME *Time\r | |
303 | )\r | |
304 | {\r | |
305 | EFI_STATUS Status;\r | |
306 | UINTN EpochSeconds;\r | |
307 | \r | |
308 | // Check the input parameters are within the range specified by UEFI\r | |
309 | if ((Time->Year < 1900) ||\r | |
310 | (Time->Year > 9999) ||\r | |
311 | (Time->Month < 1 ) ||\r | |
312 | (Time->Month > 12 ) ||\r | |
313 | (!IsDayValid (Time) ) ||\r | |
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 | |
321 | Status = EFI_INVALID_PARAMETER;\r | |
322 | goto EXIT;\r | |
323 | }\r | |
324 | \r | |
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 | |
334 | // Initialize the hardware if not already done\r | |
335 | if (!mPL031Initialized) {\r | |
336 | Status = InitializePL031 ();\r | |
337 | if (EFI_ERROR (Status)) {\r | |
338 | goto EXIT;\r | |
339 | }\r | |
340 | }\r | |
341 | \r | |
342 | EpochSeconds = EfiTimeToEpoch (Time);\r | |
343 | \r | |
344 | // Adjust for the correct time zone, i.e. convert to UTC time zone\r | |
345 | if (Time->TimeZone != EFI_UNSPECIFIED_TIMEZONE) {\r | |
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 | |
352 | if ((Time->Daylight & EFI_TIME_IN_DAYLIGHT) == EFI_TIME_IN_DAYLIGHT) {\r | |
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 | |
358 | //\r | |
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 | |
362 | //\r | |
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 | |
372 | MmioWrite32 (mPL031RtcBase + PL031_RTC_LR_LOAD_REGISTER, EpochSeconds);\r | |
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 | |
378 | Status = EfiSetVariable (\r | |
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 | |
385 | if (EFI_ERROR (Status)) {\r | |
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 | |
392 | goto EXIT;\r | |
393 | }\r | |
394 | \r | |
395 | // Save the current daylight information into non-volatile storage\r | |
396 | Status = EfiSetVariable (\r | |
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 | |
403 | if (EFI_ERROR (Status)) {\r | |
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 | |
410 | goto EXIT;\r | |
411 | }\r | |
412 | \r | |
413 | EXIT:\r | |
414 | return Status;\r | |
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 | |
430 | EFI_STATUS\r | |
431 | EFIAPI\r | |
432 | LibGetWakeupTime (\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 | |
456 | EFI_STATUS\r | |
457 | EFIAPI\r | |
458 | LibSetWakeupTime (\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 | |
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 | |
471 | \r | |
472 | @param[in] Event The Event that is being processed\r | |
473 | @param[in] Context Event Context\r | |
474 | **/\r | |
475 | VOID\r | |
476 | EFIAPI\r | |
477 | LibRtcVirtualNotifyEvent (\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 | |
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 | |
502 | EFI_STATUS\r | |
503 | EFIAPI\r | |
504 | LibRtcInitialize (\r | |
505 | IN EFI_HANDLE ImageHandle,\r | |
506 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
507 | )\r | |
508 | {\r | |
509 | EFI_STATUS Status;\r | |
510 | EFI_HANDLE Handle;\r | |
511 | \r | |
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 | |
530 | // Install the protocol\r | |
531 | Handle = NULL;\r | |
532 | Status = gBS->InstallMultipleProtocolInterfaces (\r | |
533 | &Handle,\r | |
534 | &gEfiRealTimeClockArchProtocolGuid, NULL,\r | |
535 | NULL\r | |
536 | );\r | |
537 | ASSERT_EFI_ERROR (Status);\r | |
538 | \r | |
539 | //\r | |
540 | // Register for the virtual address change event\r | |
541 | //\r | |
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 | |
553 | }\r |