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