2 RTC Architectural Protocol GUID as defined in DxeCis 0.96.
4 Copyright (c) 2006 - 2010, 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
;
212 // Reset time value according to new RTC configuration
214 Status
= PcRtcSetTime (&Time
, Global
);
215 if(!EFI_ERROR (Status
)) {
218 return EFI_DEVICE_ERROR
;
223 Returns the current time and date information, and the time-keeping capabilities
224 of the hardware platform.
226 @param Time A pointer to storage to receive a snapshot of the current time.
227 @param Capabilities An optional pointer to a buffer to receive the real time clock
228 device's capabilities.
229 @param Global For global use inside this module.
231 @retval EFI_SUCCESS The operation completed successfully.
232 @retval EFI_INVALID_PARAMETER Time is NULL.
233 @retval EFI_DEVICE_ERROR The time could not be retrieved due to hardware error.
240 OUT EFI_TIME_CAPABILITIES
*Capabilities
, OPTIONAL
241 IN PC_RTC_MODULE_GLOBALS
*Global
245 RTC_REGISTER_B RegisterB
;
249 // Check parameters for null pointer
252 return EFI_INVALID_PARAMETER
;
256 // Acquire RTC Lock to make access to RTC atomic
258 if (!EfiAtRuntime ()) {
259 EfiAcquireLock (&Global
->RtcLock
);
262 // Wait for up to 0.1 seconds for the RTC to be updated
264 Status
= RtcWaitToUpdate (PcdGet32 (PcdRealTimeClockUpdateTimeout
));
265 if (EFI_ERROR (Status
)) {
266 if (!EfiAtRuntime ()) {
267 EfiReleaseLock (&Global
->RtcLock
);
274 RegisterB
.Data
= RtcRead (RTC_ADDRESS_REGISTER_B
);
277 // Get the Time/Date/Daylight Savings values.
279 Time
->Second
= RtcRead (RTC_ADDRESS_SECONDS
);
280 Time
->Minute
= RtcRead (RTC_ADDRESS_MINUTES
);
281 Time
->Hour
= RtcRead (RTC_ADDRESS_HOURS
);
282 Time
->Day
= RtcRead (RTC_ADDRESS_DAY_OF_THE_MONTH
);
283 Time
->Month
= RtcRead (RTC_ADDRESS_MONTH
);
284 Time
->Year
= RtcRead (RTC_ADDRESS_YEAR
);
286 Century
= RtcRead (RTC_ADDRESS_CENTURY
);
291 if (!EfiAtRuntime ()) {
292 EfiReleaseLock (&Global
->RtcLock
);
296 // Get the variable that contains the TimeZone and Daylight fields
298 Time
->TimeZone
= Global
->SavedTimeZone
;
299 Time
->Daylight
= Global
->Daylight
;
302 // Make sure all field values are in correct range
304 Status
= ConvertRtcTimeToEfiTime (Time
, Century
, RegisterB
);
305 if (!EFI_ERROR (Status
)) {
306 Status
= RtcTimeFieldsValid (Time
);
308 if (EFI_ERROR (Status
)) {
309 return EFI_DEVICE_ERROR
;
313 // Fill in Capabilities if it was passed in
315 if (Capabilities
!= NULL
) {
316 Capabilities
->Resolution
= 1;
320 Capabilities
->Accuracy
= 50000000;
324 Capabilities
->SetsToZero
= FALSE
;
331 Sets the current local time and date information.
333 @param Time A pointer to the current time.
334 @param Global For global use inside this module.
336 @retval EFI_SUCCESS The operation completed successfully.
337 @retval EFI_INVALID_PARAMETER A time field is out of range.
338 @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) | 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.
568 IN EFI_TIME
*Time
, OPTIONAL
569 IN PC_RTC_MODULE_GLOBALS
*Global
574 RTC_REGISTER_B RegisterB
;
576 EFI_TIME_CAPABILITIES Capabilities
;
583 return EFI_INVALID_PARAMETER
;
586 // Make sure that the time fields are valid
588 Status
= RtcTimeFieldsValid (Time
);
589 if (EFI_ERROR (Status
)) {
590 return EFI_INVALID_PARAMETER
;
593 // Just support set alarm time within 24 hours
595 PcRtcGetTime (&RtcTime
, &Capabilities
, Global
);
596 Status
= RtcTimeFieldsValid (&RtcTime
);
597 if (EFI_ERROR (Status
)) {
598 return EFI_DEVICE_ERROR
;
600 if (!IsWithinOneDay (&RtcTime
, Time
)) {
601 return EFI_UNSUPPORTED
;
604 // Make a local copy of the time and date
606 CopyMem (&RtcTime
, Time
, sizeof (EFI_TIME
));
610 // Acquire RTC Lock to make access to RTC atomic
612 if (!EfiAtRuntime ()) {
613 EfiAcquireLock (&Global
->RtcLock
);
616 // Wait for up to 0.1 seconds for the RTC to be updated
618 Status
= RtcWaitToUpdate (PcdGet32 (PcdRealTimeClockUpdateTimeout
));
619 if (EFI_ERROR (Status
)) {
620 if (!EfiAtRuntime ()) {
621 EfiReleaseLock (&Global
->RtcLock
);
623 return EFI_DEVICE_ERROR
;
626 // Read Register B, and inhibit updates of the RTC
628 RegisterB
.Data
= RtcRead (RTC_ADDRESS_REGISTER_B
);
630 RegisterB
.Bits
.Set
= 1;
631 RtcWrite (RTC_ADDRESS_REGISTER_B
, RegisterB
.Data
);
634 ConvertEfiTimeToRtcTime (&RtcTime
, RegisterB
, &Century
);
637 // Set RTC alarm time
639 RtcWrite (RTC_ADDRESS_SECONDS_ALARM
, RtcTime
.Second
);
640 RtcWrite (RTC_ADDRESS_MINUTES_ALARM
, RtcTime
.Minute
);
641 RtcWrite (RTC_ADDRESS_HOURS_ALARM
, RtcTime
.Hour
);
643 RegisterB
.Bits
.Aie
= 1;
646 RegisterB
.Bits
.Aie
= 0;
648 // if the alarm is disable, record the current setting.
650 RtcTime
.Second
= RtcRead (RTC_ADDRESS_SECONDS_ALARM
);
651 RtcTime
.Minute
= RtcRead (RTC_ADDRESS_MINUTES_ALARM
);
652 RtcTime
.Hour
= RtcRead (RTC_ADDRESS_HOURS_ALARM
);
653 RtcTime
.Day
= RtcRead (RTC_ADDRESS_DAY_OF_THE_MONTH
);
654 RtcTime
.Month
= RtcRead (RTC_ADDRESS_MONTH
);
655 RtcTime
.Year
= RtcRead (RTC_ADDRESS_YEAR
);
656 RtcTime
.TimeZone
= Global
->SavedTimeZone
;
657 RtcTime
.Daylight
= Global
->Daylight
;
660 // Allow updates of the RTC registers
662 RegisterB
.Bits
.Set
= 0;
663 RtcWrite (RTC_ADDRESS_REGISTER_B
, RegisterB
.Data
);
666 // Set the Y/M/D info to variable as it has no corresponding hw registers.
668 Status
= EfiSetVariable (
671 EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_RUNTIME_ACCESS
| EFI_VARIABLE_NON_VOLATILE
,
675 if (EFI_ERROR (Status
)) {
676 return EFI_DEVICE_ERROR
;
682 if (!EfiAtRuntime ()) {
683 EfiReleaseLock (&Global
->RtcLock
);
690 Checks an 8-bit BCD value, and converts to an 8-bit value if valid.
692 This function checks the 8-bit BCD value specified by Value.
693 If valid, the function converts it to an 8-bit value and returns it.
694 Otherwise, return 0xff.
696 @param Value The 8-bit BCD value to check and convert
698 @return The 8-bit value converted. Or 0xff if Value is invalid.
702 CheckAndConvertBcd8ToDecimal8 (
706 if ((Value
< 0xa0) && ((Value
& 0xf) < 0xa)) {
707 return BcdToDecimal8 (Value
);
714 Converts time read from RTC to EFI_TIME format defined by UEFI spec.
716 This function converts raw time data read from RTC to the EFI_TIME format
717 defined by UEFI spec.
718 If data mode of RTC is BCD, then converts it to decimal,
719 If RTC is in 12-hour format, then converts it to 24-hour format.
721 @param Time On input, the time data read from RTC to convert
722 On output, the time converted to UEFI format
723 @param Century Value of century read from RTC.
724 @param RegisterB Value of Register B of RTC, indicating data mode
727 @retval EFI_INVALID_PARAMETER Parameters passed in are invalid.
728 @retval EFI_SUCCESS Convert RTC time to EFI time successfully.
732 ConvertRtcTimeToEfiTime (
733 IN OUT EFI_TIME
*Time
,
735 IN RTC_REGISTER_B RegisterB
740 if ((Time
->Hour
& 0x80) != 0) {
746 Time
->Hour
= (UINT8
) (Time
->Hour
& 0x7f);
748 if (RegisterB
.Bits
.Dm
== 0) {
749 Time
->Year
= CheckAndConvertBcd8ToDecimal8 ((UINT8
) Time
->Year
);
750 Time
->Month
= CheckAndConvertBcd8ToDecimal8 (Time
->Month
);
751 Time
->Day
= CheckAndConvertBcd8ToDecimal8 (Time
->Day
);
752 Time
->Hour
= CheckAndConvertBcd8ToDecimal8 (Time
->Hour
);
753 Time
->Minute
= CheckAndConvertBcd8ToDecimal8 (Time
->Minute
);
754 Time
->Second
= CheckAndConvertBcd8ToDecimal8 (Time
->Second
);
756 Century
= CheckAndConvertBcd8ToDecimal8 (Century
);
758 if (Time
->Year
== 0xff || Time
->Month
== 0xff || Time
->Day
== 0xff ||
759 Time
->Hour
== 0xff || Time
->Minute
== 0xff || Time
->Second
== 0xff ||
761 return EFI_INVALID_PARAMETER
;
764 Time
->Year
= (UINT16
) (Century
* 100 + Time
->Year
);
767 // If time is in 12 hour format, convert it to 24 hour format
769 if (RegisterB
.Bits
.Mil
== 0) {
770 if (IsPM
&& Time
->Hour
< 12) {
771 Time
->Hour
= (UINT8
) (Time
->Hour
+ 12);
774 if (!IsPM
&& Time
->Hour
== 12) {
779 Time
->Nanosecond
= 0;
785 Wait for a period for the RTC to be ready.
787 @param Timeout Tell how long it should take to wait.
789 @retval EFI_DEVICE_ERROR RTC device error.
790 @retval EFI_SUCCESS RTC is updated and ready.
797 RTC_REGISTER_A RegisterA
;
798 RTC_REGISTER_D RegisterD
;
801 // See if the RTC is functioning correctly
803 RegisterD
.Data
= RtcRead (RTC_ADDRESS_REGISTER_D
);
805 if (RegisterD
.Bits
.Vrt
== 0) {
806 return EFI_DEVICE_ERROR
;
809 // Wait for up to 0.1 seconds for the RTC to be ready.
811 Timeout
= (Timeout
/ 10) + 1;
812 RegisterA
.Data
= RtcRead (RTC_ADDRESS_REGISTER_A
);
813 while (RegisterA
.Bits
.Uip
== 1 && Timeout
> 0) {
814 MicroSecondDelay (10);
815 RegisterA
.Data
= RtcRead (RTC_ADDRESS_REGISTER_A
);
819 RegisterD
.Data
= RtcRead (RTC_ADDRESS_REGISTER_D
);
820 if (Timeout
== 0 || RegisterD
.Bits
.Vrt
== 0) {
821 return EFI_DEVICE_ERROR
;
828 See if all fields of a variable of EFI_TIME type is correct.
830 @param Time The time to be checked.
832 @retval EFI_INVALID_PARAMETER Some fields of Time are not correct.
833 @retval EFI_SUCCESS Time is a valid EFI_TIME variable.
841 if (Time
->Year
< 1998 ||
845 (!DayValid (Time
)) ||
849 Time
->Nanosecond
> 999999999 ||
850 (!(Time
->TimeZone
== EFI_UNSPECIFIED_TIMEZONE
|| (Time
->TimeZone
>= -1440 && Time
->TimeZone
<= 1440))) ||
851 ((Time
->Daylight
& (~(EFI_TIME_ADJUST_DAYLIGHT
| EFI_TIME_IN_DAYLIGHT
))) != 0)) {
852 return EFI_INVALID_PARAMETER
;
859 See if field Day of an EFI_TIME is correct.
861 @param Time Its Day field is to be checked.
863 @retval TRUE Day field of Time is correct.
864 @retval FALSE Day field of Time is NOT correct.
887 // The validity of Time->Month field should be checked before
889 ASSERT (Time
->Month
>=1);
890 ASSERT (Time
->Month
<=12);
892 Time
->Day
> DayOfMonth
[Time
->Month
- 1] ||
893 (Time
->Month
== 2 && (!IsLeapYear (Time
) && Time
->Day
> 28))
902 Check if it is a leap year.
904 @param Time The time to be checked.
906 @retval TRUE It is a leap year.
907 @retval FALSE It is NOT a leap year.
914 if (Time
->Year
% 4 == 0) {
915 if (Time
->Year
% 100 == 0) {
916 if (Time
->Year
% 400 == 0) {
930 Converts time from EFI_TIME format defined by UEFI spec to RTC's.
932 This function converts time from EFI_TIME format defined by UEFI spec to RTC's.
933 If data mode of RTC is BCD, then converts EFI_TIME to it.
934 If RTC is in 12-hour format, then converts EFI_TIME to it.
936 @param Time On input, the time data read from UEFI to convert
937 On output, the time converted to RTC format
938 @param RegisterB Value of Register B of RTC, indicating data mode
939 @param Century It is set according to EFI_TIME Time.
943 ConvertEfiTimeToRtcTime (
944 IN OUT EFI_TIME
*Time
,
945 IN RTC_REGISTER_B RegisterB
,
953 // Adjust hour field if RTC is in 12 hour mode
955 if (RegisterB
.Bits
.Mil
== 0) {
956 if (Time
->Hour
< 12) {
960 if (Time
->Hour
>= 13) {
961 Time
->Hour
= (UINT8
) (Time
->Hour
- 12);
962 } else if (Time
->Hour
== 0) {
967 // Set the Time/Date/Daylight Savings values.
969 *Century
= DecimalToBcd8 ((UINT8
) (Time
->Year
/ 100));
971 Time
->Year
= (UINT16
) (Time
->Year
% 100);
973 if (RegisterB
.Bits
.Dm
== 0) {
974 Time
->Year
= DecimalToBcd8 ((UINT8
) Time
->Year
);
975 Time
->Month
= DecimalToBcd8 (Time
->Month
);
976 Time
->Day
= DecimalToBcd8 (Time
->Day
);
977 Time
->Hour
= DecimalToBcd8 (Time
->Hour
);
978 Time
->Minute
= DecimalToBcd8 (Time
->Minute
);
979 Time
->Second
= DecimalToBcd8 (Time
->Second
);
982 // If we are in 12 hour mode and PM is set, then set bit 7 of the Hour field.
984 if (RegisterB
.Bits
.Mil
== 0 && IsPM
) {
985 Time
->Hour
= (UINT8
) (Time
->Hour
| 0x80);
990 Compare the Hour, Minute and Second of the From time and the To time.
992 Only compare H/M/S in EFI_TIME and ignore other fields here.
994 @param From the first time
995 @param To the second time
997 @return >0 The H/M/S of the From time is later than those of To time
998 @return ==0 The H/M/S of the From time is same as those of To time
999 @return <0 The H/M/S of the From time is earlier than those of To time
1007 if ((From
->Hour
> To
->Hour
) ||
1008 ((From
->Hour
== To
->Hour
) && (From
->Minute
> To
->Minute
)) ||
1009 ((From
->Hour
== To
->Hour
) && (From
->Minute
== To
->Minute
) && (From
->Second
> To
->Second
))) {
1011 } else if ((From
->Hour
== To
->Hour
) && (From
->Minute
== To
->Minute
) && (From
->Second
== To
->Second
)) {
1019 To check if second date is later than first date within 24 hours.
1021 @param From the first date
1022 @param To the second date
1024 @retval TRUE From is previous to To within 24 hours.
1025 @retval FALSE From is later, or it is previous to To more than 24 hours.
1033 UINT8 DayOfMonth
[12];
1046 DayOfMonth
[10] = 30;
1047 DayOfMonth
[11] = 31;
1052 // The validity of From->Month field should be checked before
1054 ASSERT (From
->Month
>=1);
1055 ASSERT (From
->Month
<=12);
1057 if (From
->Year
== To
->Year
) {
1058 if (From
->Month
== To
->Month
) {
1059 if ((From
->Day
+ 1) == To
->Day
) {
1060 if ((CompareHMS(From
, To
) >= 0)) {
1063 } else if (From
->Day
== To
->Day
) {
1064 if ((CompareHMS(From
, To
) <= 0)) {
1068 } else if (((From
->Month
+ 1) == To
->Month
) && (To
->Day
== 1)) {
1069 if ((From
->Month
== 2) && !IsLeapYear(From
)) {
1070 if (From
->Day
== 28) {
1071 if ((CompareHMS(From
, To
) >= 0)) {
1075 } else if (From
->Day
== DayOfMonth
[From
->Month
- 1]) {
1076 if ((CompareHMS(From
, To
) >= 0)) {
1081 } else if (((From
->Year
+ 1) == To
->Year
) &&
1082 (From
->Month
== 12) &&
1083 (From
->Day
== 31) &&
1086 if ((CompareHMS(From
, To
) >= 0)) {