2 RTC Architectural Protocol GUID as defined in DxeCis 0.96.
4 Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
18 Compare the Hour, Minute and Second of the From time and the To time.
20 Only compare H/M/S in EFI_TIME and ignore other fields here.
22 @param From the first time
23 @param To the second time
25 @return >0 The H/M/S of the From time is later than those of To time
26 @return ==0 The H/M/S of the From time is same as those of To time
27 @return <0 The H/M/S of the From time is earlier than those of To time
36 To check if second date is later than first date within 24 hours.
38 @param From the first date
39 @param To the second date
41 @retval TRUE From is previous to To within 24 hours.
42 @retval FALSE From is later, or it is previous to To more than 24 hours.
51 Read RTC content through its registers.
53 @param Address Address offset of RTC. It is recommended to use macros such as
56 @return The data of UINT8 type read from RTC.
63 IoWrite8 (PCAT_RTC_ADDRESS_REGISTER
, (UINT8
) (Address
| (UINT8
) (IoRead8 (PCAT_RTC_ADDRESS_REGISTER
) & 0x80)));
64 return IoRead8 (PCAT_RTC_DATA_REGISTER
);
68 Write RTC through its registers.
70 @param Address Address offset of RTC. It is recommended to use macros such as
72 @param Data The content you want to write into RTC.
81 IoWrite8 (PCAT_RTC_ADDRESS_REGISTER
, (UINT8
) (Address
| (UINT8
) (IoRead8 (PCAT_RTC_ADDRESS_REGISTER
) & 0x80)));
82 IoWrite8 (PCAT_RTC_DATA_REGISTER
, Data
);
88 @param Global For global use inside this module.
90 @retval EFI_DEVICE_ERROR Initialization failed due to device error.
91 @retval EFI_SUCCESS Initialization successful.
96 IN PC_RTC_MODULE_GLOBALS
*Global
100 RTC_REGISTER_A RegisterA
;
101 RTC_REGISTER_B RegisterB
;
102 RTC_REGISTER_D RegisterD
;
109 // Acquire RTC Lock to make access to RTC atomic
111 if (!EfiAtRuntime ()) {
112 EfiAcquireLock (&Global
->RtcLock
);
115 // Initialize RTC Register
117 // Make sure Division Chain is properly configured,
118 // or RTC clock won't "tick" -- time won't increment
120 RegisterA
.Data
= RTC_INIT_REGISTER_A
;
121 RtcWrite (RTC_ADDRESS_REGISTER_A
, RegisterA
.Data
);
126 RegisterB
.Data
= RtcRead (RTC_ADDRESS_REGISTER_B
);
129 // Clear RTC flag register
131 RtcRead (RTC_ADDRESS_REGISTER_C
);
134 // Clear RTC register D
136 RegisterD
.Data
= RTC_INIT_REGISTER_D
;
137 RtcWrite (RTC_ADDRESS_REGISTER_D
, RegisterD
.Data
);
140 // Wait for up to 0.1 seconds for the RTC to be updated
142 Status
= RtcWaitToUpdate (PcdGet32 (PcdRealTimeClockUpdateTimeout
));
143 if (EFI_ERROR (Status
)) {
144 if (!EfiAtRuntime ()) {
145 EfiReleaseLock (&Global
->RtcLock
);
147 return EFI_DEVICE_ERROR
;
150 // Get the Time/Date/Daylight Savings values.
152 Time
.Second
= RtcRead (RTC_ADDRESS_SECONDS
);
153 Time
.Minute
= RtcRead (RTC_ADDRESS_MINUTES
);
154 Time
.Hour
= RtcRead (RTC_ADDRESS_HOURS
);
155 Time
.Day
= RtcRead (RTC_ADDRESS_DAY_OF_THE_MONTH
);
156 Time
.Month
= RtcRead (RTC_ADDRESS_MONTH
);
157 Time
.Year
= RtcRead (RTC_ADDRESS_YEAR
);
159 Century
= RtcRead (RTC_ADDRESS_CENTURY
);
162 // Set RTC configuration after get original time
163 // The value of bit AIE should be reserved.
165 RtcWrite (RTC_ADDRESS_REGISTER_B
, (UINT8
)(RTC_INIT_REGISTER_B
| (RegisterB
.Data
& BIT5
)));
170 if (!EfiAtRuntime ()) {
171 EfiReleaseLock (&Global
->RtcLock
);
175 // Get the data of Daylight saving and time zone, if they have been
176 // stored in NV variable during previous boot.
178 DataSize
= sizeof (UINT32
);
179 Status
= EfiGetVariable (
186 if (!EFI_ERROR (Status
)) {
187 Time
.TimeZone
= (INT16
) TimerVar
;
188 Time
.Daylight
= (UINT8
) (TimerVar
>> 16);
190 Time
.TimeZone
= EFI_UNSPECIFIED_TIMEZONE
;
195 // Validate time fields
197 Status
= ConvertRtcTimeToEfiTime (&Time
, Century
, RegisterB
);
198 if (!EFI_ERROR (Status
)) {
199 Status
= RtcTimeFieldsValid (&Time
);
201 if (EFI_ERROR (Status
)) {
202 Time
.Second
= RTC_INIT_SECOND
;
203 Time
.Minute
= RTC_INIT_MINUTE
;
204 Time
.Hour
= RTC_INIT_HOUR
;
205 Time
.Day
= RTC_INIT_DAY
;
206 Time
.Month
= RTC_INIT_MONTH
;
207 Time
.Year
= RTC_INIT_YEAR
;
209 Time
.TimeZone
= EFI_UNSPECIFIED_TIMEZONE
;
214 // Reset time value according to new RTC configuration
216 Status
= PcRtcSetTime (&Time
, Global
);
217 if(!EFI_ERROR (Status
)) {
220 return EFI_DEVICE_ERROR
;
225 Returns the current time and date information, and the time-keeping capabilities
226 of the hardware platform.
228 @param Time A pointer to storage to receive a snapshot of the current time.
229 @param Capabilities An optional pointer to a buffer to receive the real time clock
230 device's capabilities.
231 @param Global For global use inside this module.
233 @retval EFI_SUCCESS The operation completed successfully.
234 @retval EFI_INVALID_PARAMETER Time is NULL.
235 @retval EFI_DEVICE_ERROR The time could not be retrieved due to hardware error.
241 OUT EFI_TIME_CAPABILITIES
*Capabilities
, OPTIONAL
242 IN PC_RTC_MODULE_GLOBALS
*Global
246 RTC_REGISTER_B RegisterB
;
250 // Check parameters for null pointer
253 return EFI_INVALID_PARAMETER
;
257 // Acquire RTC Lock to make access to RTC atomic
259 if (!EfiAtRuntime ()) {
260 EfiAcquireLock (&Global
->RtcLock
);
263 // Wait for up to 0.1 seconds for the RTC to be updated
265 Status
= RtcWaitToUpdate (PcdGet32 (PcdRealTimeClockUpdateTimeout
));
266 if (EFI_ERROR (Status
)) {
267 if (!EfiAtRuntime ()) {
268 EfiReleaseLock (&Global
->RtcLock
);
275 RegisterB
.Data
= RtcRead (RTC_ADDRESS_REGISTER_B
);
278 // Get the Time/Date/Daylight Savings values.
280 Time
->Second
= RtcRead (RTC_ADDRESS_SECONDS
);
281 Time
->Minute
= RtcRead (RTC_ADDRESS_MINUTES
);
282 Time
->Hour
= RtcRead (RTC_ADDRESS_HOURS
);
283 Time
->Day
= RtcRead (RTC_ADDRESS_DAY_OF_THE_MONTH
);
284 Time
->Month
= RtcRead (RTC_ADDRESS_MONTH
);
285 Time
->Year
= RtcRead (RTC_ADDRESS_YEAR
);
287 Century
= RtcRead (RTC_ADDRESS_CENTURY
);
292 if (!EfiAtRuntime ()) {
293 EfiReleaseLock (&Global
->RtcLock
);
297 // Get the variable that contains the TimeZone and Daylight fields
299 Time
->TimeZone
= Global
->SavedTimeZone
;
300 Time
->Daylight
= Global
->Daylight
;
303 // Make sure all field values are in correct range
305 Status
= ConvertRtcTimeToEfiTime (Time
, Century
, RegisterB
);
306 if (!EFI_ERROR (Status
)) {
307 Status
= RtcTimeFieldsValid (Time
);
309 if (EFI_ERROR (Status
)) {
310 return EFI_DEVICE_ERROR
;
314 // Fill in Capabilities if it was passed in
316 if (Capabilities
!= NULL
) {
317 Capabilities
->Resolution
= 1;
321 Capabilities
->Accuracy
= 50000000;
325 Capabilities
->SetsToZero
= FALSE
;
332 Sets the current local time and date information.
334 @param Time A pointer to the current time.
335 @param Global For global use inside this module.
337 @retval EFI_SUCCESS The operation completed successfully.
338 @retval EFI_INVALID_PARAMETER A time field is out of range.
339 @retval EFI_DEVICE_ERROR The time could not be set due due to hardware error.
345 IN PC_RTC_MODULE_GLOBALS
*Global
350 RTC_REGISTER_B RegisterB
;
355 return EFI_INVALID_PARAMETER
;
358 // Make sure that the time fields are valid
360 Status
= RtcTimeFieldsValid (Time
);
361 if (EFI_ERROR (Status
)) {
365 CopyMem (&RtcTime
, Time
, sizeof (EFI_TIME
));
368 // Acquire RTC Lock to make access to RTC atomic
370 if (!EfiAtRuntime ()) {
371 EfiAcquireLock (&Global
->RtcLock
);
374 // Wait for up to 0.1 seconds for the RTC to be updated
376 Status
= RtcWaitToUpdate (PcdGet32 (PcdRealTimeClockUpdateTimeout
));
377 if (EFI_ERROR (Status
)) {
378 if (!EfiAtRuntime ()) {
379 EfiReleaseLock (&Global
->RtcLock
);
384 // Read Register B, and inhibit updates of the RTC
386 RegisterB
.Data
= RtcRead (RTC_ADDRESS_REGISTER_B
);
387 RegisterB
.Bits
.Set
= 1;
388 RtcWrite (RTC_ADDRESS_REGISTER_B
, RegisterB
.Data
);
390 ConvertEfiTimeToRtcTime (&RtcTime
, RegisterB
, &Century
);
392 RtcWrite (RTC_ADDRESS_SECONDS
, RtcTime
.Second
);
393 RtcWrite (RTC_ADDRESS_MINUTES
, RtcTime
.Minute
);
394 RtcWrite (RTC_ADDRESS_HOURS
, RtcTime
.Hour
);
395 RtcWrite (RTC_ADDRESS_DAY_OF_THE_MONTH
, RtcTime
.Day
);
396 RtcWrite (RTC_ADDRESS_MONTH
, RtcTime
.Month
);
397 RtcWrite (RTC_ADDRESS_YEAR
, (UINT8
) RtcTime
.Year
);
398 RtcWrite (RTC_ADDRESS_CENTURY
, Century
);
401 // Allow updates of the RTC registers
403 RegisterB
.Bits
.Set
= 0;
404 RtcWrite (RTC_ADDRESS_REGISTER_B
, RegisterB
.Data
);
409 if (!EfiAtRuntime ()) {
410 EfiReleaseLock (&Global
->RtcLock
);
413 // Set the variable that contains the TimeZone and Daylight fields
415 Global
->SavedTimeZone
= Time
->TimeZone
;
416 Global
->Daylight
= Time
->Daylight
;
418 TimerVar
= Time
->Daylight
;
419 TimerVar
= (UINT32
) ((TimerVar
<< 16) | (UINT16
)(Time
->TimeZone
));
420 Status
= EfiSetVariable (
423 EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_RUNTIME_ACCESS
| EFI_VARIABLE_NON_VOLATILE
,
427 ASSERT_EFI_ERROR (Status
);
433 Returns the current wakeup alarm clock setting.
435 @param Enabled Indicates if the alarm is currently enabled or disabled.
436 @param Pending Indicates if the alarm signal is pending and requires acknowledgment.
437 @param Time The current alarm setting.
438 @param Global For global use inside this module.
440 @retval EFI_SUCCESS The alarm settings were returned.
441 @retval EFI_INVALID_PARAMETER Enabled is NULL.
442 @retval EFI_INVALID_PARAMETER Pending is NULL.
443 @retval EFI_INVALID_PARAMETER Time is NULL.
444 @retval EFI_DEVICE_ERROR The wakeup time could not be retrieved due to a hardware error.
445 @retval EFI_UNSUPPORTED A wakeup timer is not supported on this platform.
450 OUT BOOLEAN
*Enabled
,
451 OUT BOOLEAN
*Pending
,
453 IN PC_RTC_MODULE_GLOBALS
*Global
457 RTC_REGISTER_B RegisterB
;
458 RTC_REGISTER_C RegisterC
;
464 // Check parameters for null pointers
466 if ((Enabled
== NULL
) || (Pending
== NULL
) || (Time
== NULL
)) {
467 return EFI_INVALID_PARAMETER
;
471 // Acquire RTC Lock to make access to RTC atomic
473 if (!EfiAtRuntime ()) {
474 EfiAcquireLock (&Global
->RtcLock
);
477 // Wait for up to 0.1 seconds for the RTC to be updated
479 Status
= RtcWaitToUpdate (PcdGet32 (PcdRealTimeClockUpdateTimeout
));
480 if (EFI_ERROR (Status
)) {
481 if (!EfiAtRuntime ()) {
482 EfiReleaseLock (&Global
->RtcLock
);
484 return EFI_DEVICE_ERROR
;
487 // Read Register B and Register C
489 RegisterB
.Data
= RtcRead (RTC_ADDRESS_REGISTER_B
);
490 RegisterC
.Data
= RtcRead (RTC_ADDRESS_REGISTER_C
);
493 // Get the Time/Date/Daylight Savings values.
495 *Enabled
= RegisterB
.Bits
.Aie
;
496 *Pending
= RegisterC
.Bits
.Af
;
498 Time
->Second
= RtcRead (RTC_ADDRESS_SECONDS_ALARM
);
499 Time
->Minute
= RtcRead (RTC_ADDRESS_MINUTES_ALARM
);
500 Time
->Hour
= RtcRead (RTC_ADDRESS_HOURS_ALARM
);
501 Time
->Day
= RtcRead (RTC_ADDRESS_DAY_OF_THE_MONTH
);
502 Time
->Month
= RtcRead (RTC_ADDRESS_MONTH
);
503 Time
->Year
= RtcRead (RTC_ADDRESS_YEAR
);
504 Time
->TimeZone
= Global
->SavedTimeZone
;
505 Time
->Daylight
= Global
->Daylight
;
507 Century
= RtcRead (RTC_ADDRESS_CENTURY
);
510 // Get the alarm info from variable
512 Status
= EfiGetVariable (
519 if (!EFI_ERROR (Status
)) {
521 // The alarm variable exists. In this case, we read variable to get info.
523 Time
->Day
= RtcTime
.Day
;
524 Time
->Month
= RtcTime
.Month
;
525 Time
->Year
= RtcTime
.Year
;
531 if (!EfiAtRuntime ()) {
532 EfiReleaseLock (&Global
->RtcLock
);
536 // Make sure all field values are in correct range
538 Status
= ConvertRtcTimeToEfiTime (Time
, Century
, RegisterB
);
539 if (!EFI_ERROR (Status
)) {
540 Status
= RtcTimeFieldsValid (Time
);
542 if (EFI_ERROR (Status
)) {
543 return EFI_DEVICE_ERROR
;
550 Sets the system wakeup alarm clock time.
552 @param Enabled Enable or disable the wakeup alarm.
553 @param Time If Enable is TRUE, the time to set the wakeup alarm for.
554 If Enable is FALSE, then this parameter is optional, and may be NULL.
555 @param Global For global use inside this module.
557 @retval EFI_SUCCESS If Enable is TRUE, then the wakeup alarm was enabled.
558 If Enable is FALSE, then the wakeup alarm was disabled.
559 @retval EFI_INVALID_PARAMETER A time field is out of range.
560 @retval EFI_DEVICE_ERROR The wakeup time could not be set due to a hardware error.
561 @retval EFI_UNSUPPORTED A wakeup timer is not supported on this platform.
567 IN EFI_TIME
*Time
, OPTIONAL
568 IN PC_RTC_MODULE_GLOBALS
*Global
573 RTC_REGISTER_B RegisterB
;
575 EFI_TIME_CAPABILITIES Capabilities
;
577 ZeroMem (&RtcTime
, sizeof (RtcTime
));
582 return EFI_INVALID_PARAMETER
;
585 // Make sure that the time fields are valid
587 Status
= RtcTimeFieldsValid (Time
);
588 if (EFI_ERROR (Status
)) {
589 return EFI_INVALID_PARAMETER
;
592 // Just support set alarm time within 24 hours
594 PcRtcGetTime (&RtcTime
, &Capabilities
, Global
);
595 Status
= RtcTimeFieldsValid (&RtcTime
);
596 if (EFI_ERROR (Status
)) {
597 return EFI_DEVICE_ERROR
;
599 if (!IsWithinOneDay (&RtcTime
, Time
)) {
600 return EFI_UNSUPPORTED
;
603 // Make a local copy of the time and date
605 CopyMem (&RtcTime
, Time
, sizeof (EFI_TIME
));
609 // Acquire RTC Lock to make access to RTC atomic
611 if (!EfiAtRuntime ()) {
612 EfiAcquireLock (&Global
->RtcLock
);
615 // Wait for up to 0.1 seconds for the RTC to be updated
617 Status
= RtcWaitToUpdate (PcdGet32 (PcdRealTimeClockUpdateTimeout
));
618 if (EFI_ERROR (Status
)) {
619 if (!EfiAtRuntime ()) {
620 EfiReleaseLock (&Global
->RtcLock
);
622 return EFI_DEVICE_ERROR
;
625 // Read Register B, and inhibit updates of the RTC
627 RegisterB
.Data
= RtcRead (RTC_ADDRESS_REGISTER_B
);
629 RegisterB
.Bits
.Set
= 1;
630 RtcWrite (RTC_ADDRESS_REGISTER_B
, RegisterB
.Data
);
633 ConvertEfiTimeToRtcTime (&RtcTime
, RegisterB
, &Century
);
636 // Set RTC alarm time
638 RtcWrite (RTC_ADDRESS_SECONDS_ALARM
, RtcTime
.Second
);
639 RtcWrite (RTC_ADDRESS_MINUTES_ALARM
, RtcTime
.Minute
);
640 RtcWrite (RTC_ADDRESS_HOURS_ALARM
, RtcTime
.Hour
);
642 RegisterB
.Bits
.Aie
= 1;
645 RegisterB
.Bits
.Aie
= 0;
647 // if the alarm is disable, record the current setting.
649 RtcTime
.Second
= RtcRead (RTC_ADDRESS_SECONDS_ALARM
);
650 RtcTime
.Minute
= RtcRead (RTC_ADDRESS_MINUTES_ALARM
);
651 RtcTime
.Hour
= RtcRead (RTC_ADDRESS_HOURS_ALARM
);
652 RtcTime
.Day
= RtcRead (RTC_ADDRESS_DAY_OF_THE_MONTH
);
653 RtcTime
.Month
= RtcRead (RTC_ADDRESS_MONTH
);
654 RtcTime
.Year
= RtcRead (RTC_ADDRESS_YEAR
);
655 RtcTime
.TimeZone
= Global
->SavedTimeZone
;
656 RtcTime
.Daylight
= Global
->Daylight
;
659 // Allow updates of the RTC registers
661 RegisterB
.Bits
.Set
= 0;
662 RtcWrite (RTC_ADDRESS_REGISTER_B
, RegisterB
.Data
);
665 // Set the Y/M/D info to variable as it has no corresponding hw registers.
667 Status
= EfiSetVariable (
670 EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_RUNTIME_ACCESS
| EFI_VARIABLE_NON_VOLATILE
,
674 if (EFI_ERROR (Status
)) {
675 return EFI_DEVICE_ERROR
;
681 if (!EfiAtRuntime ()) {
682 EfiReleaseLock (&Global
->RtcLock
);
689 Checks an 8-bit BCD value, and converts to an 8-bit value if valid.
691 This function checks the 8-bit BCD value specified by Value.
692 If valid, the function converts it to an 8-bit value and returns it.
693 Otherwise, return 0xff.
695 @param Value The 8-bit BCD value to check and convert
697 @return The 8-bit value converted. Or 0xff if Value is invalid.
701 CheckAndConvertBcd8ToDecimal8 (
705 if ((Value
< 0xa0) && ((Value
& 0xf) < 0xa)) {
706 return BcdToDecimal8 (Value
);
713 Converts time read from RTC to EFI_TIME format defined by UEFI spec.
715 This function converts raw time data read from RTC to the EFI_TIME format
716 defined by UEFI spec.
717 If data mode of RTC is BCD, then converts it to decimal,
718 If RTC is in 12-hour format, then converts it to 24-hour format.
720 @param Time On input, the time data read from RTC to convert
721 On output, the time converted to UEFI format
722 @param Century Value of century read from RTC.
723 @param RegisterB Value of Register B of RTC, indicating data mode
726 @retval EFI_INVALID_PARAMETER Parameters passed in are invalid.
727 @retval EFI_SUCCESS Convert RTC time to EFI time successfully.
731 ConvertRtcTimeToEfiTime (
732 IN OUT EFI_TIME
*Time
,
734 IN RTC_REGISTER_B RegisterB
739 if ((Time
->Hour
& 0x80) != 0) {
745 Time
->Hour
= (UINT8
) (Time
->Hour
& 0x7f);
747 if (RegisterB
.Bits
.Dm
== 0) {
748 Time
->Year
= CheckAndConvertBcd8ToDecimal8 ((UINT8
) Time
->Year
);
749 Time
->Month
= CheckAndConvertBcd8ToDecimal8 (Time
->Month
);
750 Time
->Day
= CheckAndConvertBcd8ToDecimal8 (Time
->Day
);
751 Time
->Hour
= CheckAndConvertBcd8ToDecimal8 (Time
->Hour
);
752 Time
->Minute
= CheckAndConvertBcd8ToDecimal8 (Time
->Minute
);
753 Time
->Second
= CheckAndConvertBcd8ToDecimal8 (Time
->Second
);
755 Century
= CheckAndConvertBcd8ToDecimal8 (Century
);
757 if (Time
->Year
== 0xff || Time
->Month
== 0xff || Time
->Day
== 0xff ||
758 Time
->Hour
== 0xff || Time
->Minute
== 0xff || Time
->Second
== 0xff ||
760 return EFI_INVALID_PARAMETER
;
763 Time
->Year
= (UINT16
) (Century
* 100 + Time
->Year
);
766 // If time is in 12 hour format, convert it to 24 hour format
768 if (RegisterB
.Bits
.Mil
== 0) {
769 if (IsPM
&& Time
->Hour
< 12) {
770 Time
->Hour
= (UINT8
) (Time
->Hour
+ 12);
773 if (!IsPM
&& Time
->Hour
== 12) {
778 Time
->Nanosecond
= 0;
784 Wait for a period for the RTC to be ready.
786 @param Timeout Tell how long it should take to wait.
788 @retval EFI_DEVICE_ERROR RTC device error.
789 @retval EFI_SUCCESS RTC is updated and ready.
796 RTC_REGISTER_A RegisterA
;
797 RTC_REGISTER_D RegisterD
;
800 // See if the RTC is functioning correctly
802 RegisterD
.Data
= RtcRead (RTC_ADDRESS_REGISTER_D
);
804 if (RegisterD
.Bits
.Vrt
== 0) {
805 return EFI_DEVICE_ERROR
;
808 // Wait for up to 0.1 seconds for the RTC to be ready.
810 Timeout
= (Timeout
/ 10) + 1;
811 RegisterA
.Data
= RtcRead (RTC_ADDRESS_REGISTER_A
);
812 while (RegisterA
.Bits
.Uip
== 1 && Timeout
> 0) {
813 MicroSecondDelay (10);
814 RegisterA
.Data
= RtcRead (RTC_ADDRESS_REGISTER_A
);
818 RegisterD
.Data
= RtcRead (RTC_ADDRESS_REGISTER_D
);
819 if (Timeout
== 0 || RegisterD
.Bits
.Vrt
== 0) {
820 return EFI_DEVICE_ERROR
;
827 See if all fields of a variable of EFI_TIME type is correct.
829 @param Time The time to be checked.
831 @retval EFI_INVALID_PARAMETER Some fields of Time are not correct.
832 @retval EFI_SUCCESS Time is a valid EFI_TIME variable.
840 if (Time
->Year
< 1998 ||
844 (!DayValid (Time
)) ||
848 Time
->Nanosecond
> 999999999 ||
849 (!(Time
->TimeZone
== EFI_UNSPECIFIED_TIMEZONE
|| (Time
->TimeZone
>= -1440 && Time
->TimeZone
<= 1440))) ||
850 ((Time
->Daylight
& (~(EFI_TIME_ADJUST_DAYLIGHT
| EFI_TIME_IN_DAYLIGHT
))) != 0)) {
851 return EFI_INVALID_PARAMETER
;
858 See if field Day of an EFI_TIME is correct.
860 @param Time Its Day field is to be checked.
862 @retval TRUE Day field of Time is correct.
863 @retval FALSE Day field of Time is NOT correct.
886 // The validity of Time->Month field should be checked before
888 ASSERT (Time
->Month
>=1);
889 ASSERT (Time
->Month
<=12);
891 Time
->Day
> DayOfMonth
[Time
->Month
- 1] ||
892 (Time
->Month
== 2 && (!IsLeapYear (Time
) && Time
->Day
> 28))
901 Check if it is a leap year.
903 @param Time The time to be checked.
905 @retval TRUE It is a leap year.
906 @retval FALSE It is NOT a leap year.
913 if (Time
->Year
% 4 == 0) {
914 if (Time
->Year
% 100 == 0) {
915 if (Time
->Year
% 400 == 0) {
929 Converts time from EFI_TIME format defined by UEFI spec to RTC's.
931 This function converts time from EFI_TIME format defined by UEFI spec to RTC's.
932 If data mode of RTC is BCD, then converts EFI_TIME to it.
933 If RTC is in 12-hour format, then converts EFI_TIME to it.
935 @param Time On input, the time data read from UEFI to convert
936 On output, the time converted to RTC format
937 @param RegisterB Value of Register B of RTC, indicating data mode
938 @param Century It is set according to EFI_TIME Time.
942 ConvertEfiTimeToRtcTime (
943 IN OUT EFI_TIME
*Time
,
944 IN RTC_REGISTER_B RegisterB
,
952 // Adjust hour field if RTC is in 12 hour mode
954 if (RegisterB
.Bits
.Mil
== 0) {
955 if (Time
->Hour
< 12) {
959 if (Time
->Hour
>= 13) {
960 Time
->Hour
= (UINT8
) (Time
->Hour
- 12);
961 } else if (Time
->Hour
== 0) {
966 // Set the Time/Date/Daylight Savings values.
968 *Century
= DecimalToBcd8 ((UINT8
) (Time
->Year
/ 100));
970 Time
->Year
= (UINT16
) (Time
->Year
% 100);
972 if (RegisterB
.Bits
.Dm
== 0) {
973 Time
->Year
= DecimalToBcd8 ((UINT8
) Time
->Year
);
974 Time
->Month
= DecimalToBcd8 (Time
->Month
);
975 Time
->Day
= DecimalToBcd8 (Time
->Day
);
976 Time
->Hour
= DecimalToBcd8 (Time
->Hour
);
977 Time
->Minute
= DecimalToBcd8 (Time
->Minute
);
978 Time
->Second
= DecimalToBcd8 (Time
->Second
);
981 // If we are in 12 hour mode and PM is set, then set bit 7 of the Hour field.
983 if (RegisterB
.Bits
.Mil
== 0 && IsPM
) {
984 Time
->Hour
= (UINT8
) (Time
->Hour
| 0x80);
989 Compare the Hour, Minute and Second of the From time and the To time.
991 Only compare H/M/S in EFI_TIME and ignore other fields here.
993 @param From the first time
994 @param To the second time
996 @return >0 The H/M/S of the From time is later than those of To time
997 @return ==0 The H/M/S of the From time is same as those of To time
998 @return <0 The H/M/S of the From time is earlier than those of To time
1006 if ((From
->Hour
> To
->Hour
) ||
1007 ((From
->Hour
== To
->Hour
) && (From
->Minute
> To
->Minute
)) ||
1008 ((From
->Hour
== To
->Hour
) && (From
->Minute
== To
->Minute
) && (From
->Second
> To
->Second
))) {
1010 } else if ((From
->Hour
== To
->Hour
) && (From
->Minute
== To
->Minute
) && (From
->Second
== To
->Second
)) {
1018 To check if second date is later than first date within 24 hours.
1020 @param From the first date
1021 @param To the second date
1023 @retval TRUE From is previous to To within 24 hours.
1024 @retval FALSE From is later, or it is previous to To more than 24 hours.
1032 UINT8 DayOfMonth
[12];
1045 DayOfMonth
[10] = 30;
1046 DayOfMonth
[11] = 31;
1051 // The validity of From->Month field should be checked before
1053 ASSERT (From
->Month
>=1);
1054 ASSERT (From
->Month
<=12);
1056 if (From
->Year
== To
->Year
) {
1057 if (From
->Month
== To
->Month
) {
1058 if ((From
->Day
+ 1) == To
->Day
) {
1059 if ((CompareHMS(From
, To
) >= 0)) {
1062 } else if (From
->Day
== To
->Day
) {
1063 if ((CompareHMS(From
, To
) <= 0)) {
1067 } else if (((From
->Month
+ 1) == To
->Month
) && (To
->Day
== 1)) {
1068 if ((From
->Month
== 2) && !IsLeapYear(From
)) {
1069 if (From
->Day
== 28) {
1070 if ((CompareHMS(From
, To
) >= 0)) {
1074 } else if (From
->Day
== DayOfMonth
[From
->Month
- 1]) {
1075 if ((CompareHMS(From
, To
) >= 0)) {
1080 } else if (((From
->Year
+ 1) == To
->Year
) &&
1081 (From
->Month
== 12) &&
1082 (From
->Day
== 31) &&
1085 if ((CompareHMS(From
, To
) >= 0)) {