2 RTC Architectural Protocol GUID as defined in DxeCis 0.96.
4 Copyright (c) 2006 - 2007, Intel Corporation
5 All rights reserved. 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 //Code here doesn't consider the runtime environment.
112 if (!EfiAtRuntime ()) {
113 EfiAcquireLock (&Global
->RtcLock
);
116 // Initialize RTC Register
118 // Make sure Division Chain is properly configured,
119 // or RTC clock won't "tick" -- time won't increment
121 RegisterA
.Data
= RTC_INIT_REGISTER_A
;
122 RtcWrite (RTC_ADDRESS_REGISTER_A
, RegisterA
.Data
);
127 RegisterB
.Data
= RtcRead (RTC_ADDRESS_REGISTER_B
);
130 // Clear RTC flag register
132 RtcRead (RTC_ADDRESS_REGISTER_C
);
135 // Clear RTC register D
137 RegisterD
.Data
= RTC_INIT_REGISTER_D
;
138 RtcWrite (RTC_ADDRESS_REGISTER_D
, RegisterD
.Data
);
141 // Wait for up to 0.1 seconds for the RTC to be updated
143 Status
= RtcWaitToUpdate (PcdGet32 (PcdRealTimeClockUpdateTimeout
));
144 if (EFI_ERROR (Status
)) {
145 //Code here doesn't consider the runtime environment.
146 if (!EfiAtRuntime ()) {
147 EfiReleaseLock (&Global
->RtcLock
);
149 return EFI_DEVICE_ERROR
;
152 // Get the Time/Date/Daylight Savings values.
154 Time
.Second
= RtcRead (RTC_ADDRESS_SECONDS
);
155 Time
.Minute
= RtcRead (RTC_ADDRESS_MINUTES
);
156 Time
.Hour
= RtcRead (RTC_ADDRESS_HOURS
);
157 Time
.Day
= RtcRead (RTC_ADDRESS_DAY_OF_THE_MONTH
);
158 Time
.Month
= RtcRead (RTC_ADDRESS_MONTH
);
159 Time
.Year
= RtcRead (RTC_ADDRESS_YEAR
);
161 Century
= RtcRead (RTC_ADDRESS_CENTURY
);
162 Time
.Year
= (UINT16
) (Century
* 100 + Time
.Year
);
165 // Set RTC configuration after get original time
166 // The value of bit AIE should be reserved.
168 RtcWrite (RTC_ADDRESS_REGISTER_B
, (UINT8
)(RTC_INIT_REGISTER_B
| (RegisterB
.Data
& BIT5
)));
173 //Code here doesn't consider the runtime environment.
174 if (!EfiAtRuntime ()) {
175 EfiReleaseLock (&Global
->RtcLock
);
179 // Validate time fields
181 Status
= ConvertRtcTimeToEfiTime (&Time
, Century
, RegisterB
);
182 if (!EFI_ERROR (Status
)) {
183 Status
= RtcTimeFieldsValid (&Time
);
185 if (EFI_ERROR (Status
)) {
186 Time
.Second
= RTC_INIT_SECOND
;
187 Time
.Minute
= RTC_INIT_MINUTE
;
188 Time
.Hour
= RTC_INIT_HOUR
;
189 Time
.Day
= RTC_INIT_DAY
;
190 Time
.Month
= RTC_INIT_MONTH
;
191 Time
.Year
= RTC_INIT_YEAR
;
194 // Get the data of Daylight saving and time zone, if they have been
195 // stored in NV variable during previous boot.
197 DataSize
= sizeof (UINT32
);
198 Status
= EfiGetVariable (
205 if (!EFI_ERROR (Status
)) {
206 Global
->SavedTimeZone
= (INT16
) TimerVar
;
207 Global
->Daylight
= (UINT8
) (TimerVar
>> 16);
209 Time
.TimeZone
= Global
->SavedTimeZone
;
210 Time
.Daylight
= Global
->Daylight
;
213 // Reset time value according to new RTC configuration
215 PcRtcSetTime (&Time
, Global
);
221 Returns the current time and date information, and the time-keeping capabilities
222 of the hardware platform.
224 @param Time A pointer to storage to receive a snapshot of the current time.
225 @param Capabilities An optional pointer to a buffer to receive the real time clock
226 device's capabilities.
227 @param Global For global use inside this module.
229 @retval EFI_SUCCESS The operation completed successfully.
230 @retval EFI_INVALID_PARAMETER Time is NULL.
231 @retval EFI_DEVICE_ERROR The time could not be retrieved due to hardware error.
237 OUT EFI_TIME_CAPABILITIES
*Capabilities
, OPTIONAL
238 IN PC_RTC_MODULE_GLOBALS
*Global
242 RTC_REGISTER_B RegisterB
;
246 // Check parameters for null pointer
249 return EFI_INVALID_PARAMETER
;
253 // Acquire RTC Lock to make access to RTC atomic
255 //Code here doesn't consider the runtime environment.
256 if (!EfiAtRuntime ()) {
257 EfiAcquireLock (&Global
->RtcLock
);
260 // Wait for up to 0.1 seconds for the RTC to be updated
262 Status
= RtcWaitToUpdate (PcdGet32 (PcdRealTimeClockUpdateTimeout
));
263 if (EFI_ERROR (Status
)) {
264 //Code here doesn't consider the runtime environment.
265 if (!EfiAtRuntime ()) {
266 EfiReleaseLock (&Global
->RtcLock
);
273 RegisterB
.Data
= RtcRead (RTC_ADDRESS_REGISTER_B
);
276 // Get the Time/Date/Daylight Savings values.
278 Time
->Second
= RtcRead (RTC_ADDRESS_SECONDS
);
279 Time
->Minute
= RtcRead (RTC_ADDRESS_MINUTES
);
280 Time
->Hour
= RtcRead (RTC_ADDRESS_HOURS
);
281 Time
->Day
= RtcRead (RTC_ADDRESS_DAY_OF_THE_MONTH
);
282 Time
->Month
= RtcRead (RTC_ADDRESS_MONTH
);
283 Time
->Year
= RtcRead (RTC_ADDRESS_YEAR
);
285 Century
= RtcRead (RTC_ADDRESS_CENTURY
);
286 Time
->Year
= (UINT16
) (Century
* 100 + Time
->Year
);
291 //Code here doesn't consider the runtime environment.
292 if (!EfiAtRuntime ()) {
293 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
;
312 // Fill in Capabilities if it was passed in
314 if (Capabilities
!= NULL
) {
315 Capabilities
->Resolution
= 1;
319 Capabilities
->Accuracy
= 50000000;
323 Capabilities
->SetsToZero
= FALSE
;
330 Sets the current local time and date information.
332 @param Time A pointer to the current time.
333 @param Global For global use inside this module.
335 @retval EFI_SUCCESS The operation completed successfully.
336 @retval EFI_INVALID_PARAMETER A time field is out of range.
337 @retval EFI_DEVICE_ERROR The time could not be set due due to hardware error.
343 IN PC_RTC_MODULE_GLOBALS
*Global
348 RTC_REGISTER_B RegisterB
;
353 return EFI_INVALID_PARAMETER
;
356 // Make sure that the time fields are valid
358 Status
= RtcTimeFieldsValid (Time
);
359 if (EFI_ERROR (Status
)) {
363 CopyMem (&RtcTime
, Time
, sizeof (EFI_TIME
));
366 // Acquire RTC Lock to make access to RTC atomic
368 //Code here doesn't consider the runtime environment.
369 if (!EfiAtRuntime ()) {
370 EfiAcquireLock (&Global
->RtcLock
);
373 // Wait for up to 0.1 seconds for the RTC to be updated
375 Status
= RtcWaitToUpdate (PcdGet32 (PcdRealTimeClockUpdateTimeout
));
376 if (EFI_ERROR (Status
)) {
377 //Code here doesn't consider the runtime environment.
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 //Code here doesn't consider the runtime environment.
410 if (!EfiAtRuntime ()) {
411 EfiReleaseLock (&Global
->RtcLock
);
414 // Set the variable that contains the TimeZone and Daylight fields
416 Global
->SavedTimeZone
= Time
->TimeZone
;
417 Global
->Daylight
= Time
->Daylight
;
419 TimerVar
= Time
->Daylight
;
420 TimerVar
= (UINT32
) ((TimerVar
<< 16) | Time
->TimeZone
);
421 Status
= EfiSetVariable (
424 EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_RUNTIME_ACCESS
| EFI_VARIABLE_NON_VOLATILE
,
428 ASSERT_EFI_ERROR (Status
);
434 Returns the current wakeup alarm clock setting.
436 @param Enabled Indicates if the alarm is currently enabled or disabled.
437 @param Pending Indicates if the alarm signal is pending and requires acknowledgment.
438 @param Time The current alarm setting.
439 @param Global For global use inside this module.
441 @retval EFI_SUCCESS The alarm settings were returned.
442 @retval EFI_INVALID_PARAMETER Enabled is NULL.
443 @retval EFI_INVALID_PARAMETER Pending is NULL.
444 @retval EFI_INVALID_PARAMETER Time is NULL.
445 @retval EFI_DEVICE_ERROR The wakeup time could not be retrieved due to a hardware error.
446 @retval EFI_UNSUPPORTED A wakeup timer is not supported on this platform.
451 OUT BOOLEAN
*Enabled
,
452 OUT BOOLEAN
*Pending
,
454 IN PC_RTC_MODULE_GLOBALS
*Global
458 RTC_REGISTER_B RegisterB
;
459 RTC_REGISTER_C RegisterC
;
463 // Check parameters for null pointers
465 if ((Enabled
== NULL
) || (Pending
== NULL
) || (Time
== NULL
)) {
466 return EFI_INVALID_PARAMETER
;
470 // Acquire RTC Lock to make access to RTC atomic
472 //Code here doesn't consider the runtime environment.
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 //Code here doesn't consider the runtime environment.
482 if (!EfiAtRuntime ()) {
483 EfiReleaseLock (&Global
->RtcLock
);
485 return EFI_DEVICE_ERROR
;
488 // Read Register B and Register C
490 RegisterB
.Data
= RtcRead (RTC_ADDRESS_REGISTER_B
);
491 RegisterC
.Data
= RtcRead (RTC_ADDRESS_REGISTER_C
);
494 // Get the Time/Date/Daylight Savings values.
496 *Enabled
= RegisterB
.Bits
.AIE
;
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
);
508 Time
->Day
= RtcRead (RTC_ADDRESS_DAY_OF_THE_MONTH
);
509 Time
->Month
= RtcRead (RTC_ADDRESS_MONTH
);
510 Time
->Year
= RtcRead (RTC_ADDRESS_YEAR
);
513 Century
= RtcRead (RTC_ADDRESS_CENTURY
);
514 Time
->Year
= (UINT16
) (Century
* 100 + Time
->Year
);
519 //Code here doesn't consider the runtime environment.
520 if (!EfiAtRuntime ()) {
521 EfiReleaseLock (&Global
->RtcLock
);
524 // Make sure all field values are in correct range
526 Status
= ConvertRtcTimeToEfiTime (Time
, Century
, RegisterB
);
527 if (!EFI_ERROR (Status
)) {
528 Status
= RtcTimeFieldsValid (Time
);
530 if (EFI_ERROR (Status
)) {
531 return EFI_DEVICE_ERROR
;
534 *Pending
= RegisterC
.Bits
.AF
;
540 Sets the system wakeup alarm clock time.
542 @param Enabled Enable or disable the wakeup alarm.
543 @param Time If Enable is TRUE, the time to set the wakeup alarm for.
544 If Enable is FALSE, then this parameter is optional, and may be NULL.
545 @param Global For global use inside this module.
547 @retval EFI_SUCCESS If Enable is TRUE, then the wakeup alarm was enabled.
548 If Enable is FALSE, then the wakeup alarm was disabled.
549 @retval EFI_INVALID_PARAMETER A time field is out of range.
550 @retval EFI_DEVICE_ERROR The wakeup time could not be set due to a hardware error.
551 @retval EFI_UNSUPPORTED A wakeup timer is not supported on this platform.
557 IN EFI_TIME
*Time
, OPTIONAL
558 IN PC_RTC_MODULE_GLOBALS
*Global
563 RTC_REGISTER_B RegisterB
;
565 EFI_TIME_CAPABILITIES Capabilities
;
570 return EFI_INVALID_PARAMETER
;
573 // Make sure that the time fields are valid
575 Status
= RtcTimeFieldsValid (Time
);
576 if (EFI_ERROR (Status
)) {
577 return EFI_INVALID_PARAMETER
;
580 // Just support set alarm time within 24 hours
582 PcRtcGetTime (&RtcTime
, &Capabilities
, Global
);
583 Status
= RtcTimeFieldsValid (&RtcTime
);
584 if (EFI_ERROR (Status
)) {
585 return EFI_DEVICE_ERROR
;
587 if (!IsWithinOneDay (&RtcTime
, Time
)) {
588 return EFI_UNSUPPORTED
;
591 // Make a local copy of the time and date
593 CopyMem (&RtcTime
, Time
, sizeof (EFI_TIME
));
597 // Acquire RTC Lock to make access to RTC atomic
599 //Code here doesn't consider the runtime environment.
600 if (!EfiAtRuntime ()) {
601 EfiAcquireLock (&Global
->RtcLock
);
604 // Wait for up to 0.1 seconds for the RTC to be updated
606 Status
= RtcWaitToUpdate (PcdGet32 (PcdRealTimeClockUpdateTimeout
));
607 if (EFI_ERROR (Status
)) {
608 //Code here doesn't consider the runtime environment.
609 if (!EfiAtRuntime ()) {
610 EfiReleaseLock (&Global
->RtcLock
);
612 return EFI_DEVICE_ERROR
;
615 // Read Register B, and inhibit updates of the RTC
617 RegisterB
.Data
= RtcRead (RTC_ADDRESS_REGISTER_B
);
619 RegisterB
.Bits
.SET
= 1;
620 RtcWrite (RTC_ADDRESS_REGISTER_B
, RegisterB
.Data
);
623 ConvertEfiTimeToRtcTime (&RtcTime
, RegisterB
, &Century
);
626 // Set RTC alarm time
628 RtcWrite (RTC_ADDRESS_SECONDS_ALARM
, RtcTime
.Second
);
629 RtcWrite (RTC_ADDRESS_MINUTES_ALARM
, RtcTime
.Minute
);
630 RtcWrite (RTC_ADDRESS_HOURS_ALARM
, RtcTime
.Hour
);
632 RegisterB
.Bits
.AIE
= 1;
635 RegisterB
.Bits
.AIE
= 0;
638 // Allow updates of the RTC registers
640 RegisterB
.Bits
.SET
= 0;
641 RtcWrite (RTC_ADDRESS_REGISTER_B
, RegisterB
.Data
);
646 //Code here doesn't consider the runtime environment.
647 if (!EfiAtRuntime ()) {
648 EfiReleaseLock (&Global
->RtcLock
);
655 Checks an 8-bit BCD value, and converts to an 8-bit value if valid.
657 This function checks the 8-bit BCD value specified by Value.
658 If valid, the function converts it to an 8-bit value and returns it.
659 Otherwise, return 0xff.
661 @param Value The 8-bit BCD value to check and convert
663 @return The 8-bit value converted. Or 0xff if Value is invalid.
667 CheckAndConvertBcd8ToDecimal8 (
671 if ((Value
< 0xa0) && ((Value
& 0xf) < 0xa)) {
672 return BcdToDecimal8 (Value
);
679 Converts time read from RTC to EFI_TIME format defined by UEFI spec.
681 This function converts raw time data read from RTC to the EFI_TIME format
682 defined by UEFI spec.
683 If data mode of RTC is BCD, then converts it to decimal,
684 If RTC is in 12-hour format, then converts it to 24-hour format.
686 @param Time On input, the time data read from RTC to convert
687 On output, the time converted to UEFI format
688 @param Century Value of century read from RTC.
689 @param RegisterB Value of Register B of RTC, indicating data mode
692 @retval EFI_INVALID_PARAMETER Parameters passed in are invalid.
693 @retval EFI_SUCCESS Convert RTC time to EFI time successfully.
697 ConvertRtcTimeToEfiTime (
698 IN OUT EFI_TIME
*Time
,
700 IN RTC_REGISTER_B RegisterB
705 if ((Time
->Hour
& 0x80) != 0) {
711 Time
->Hour
= (UINT8
) (Time
->Hour
& 0x7f);
713 if (RegisterB
.Bits
.DM
== 0) {
714 Time
->Year
= CheckAndConvertBcd8ToDecimal8 ((UINT8
) Time
->Year
);
715 Time
->Month
= CheckAndConvertBcd8ToDecimal8 (Time
->Month
);
716 Time
->Day
= CheckAndConvertBcd8ToDecimal8 (Time
->Day
);
717 Time
->Hour
= CheckAndConvertBcd8ToDecimal8 (Time
->Hour
);
718 Time
->Minute
= CheckAndConvertBcd8ToDecimal8 (Time
->Minute
);
719 Time
->Second
= CheckAndConvertBcd8ToDecimal8 (Time
->Second
);
720 Century
= CheckAndConvertBcd8ToDecimal8 (Century
);
723 if (Time
->Year
== 0xff || Time
->Month
== 0xff || Time
->Day
== 0xff ||
724 Time
->Hour
== 0xff || Time
->Minute
== 0xff || Time
->Second
== 0xff ||
726 return EFI_INVALID_PARAMETER
;
729 Time
->Year
= (UINT16
) (Century
* 100 + Time
->Year
);
732 // If time is in 12 hour format, convert it to 24 hour format
734 if (RegisterB
.Bits
.MIL
== 0) {
735 if (IsPM
&& Time
->Hour
< 12) {
736 Time
->Hour
= (UINT8
) (Time
->Hour
+ 12);
739 if (!IsPM
&& Time
->Hour
== 12) {
744 Time
->Nanosecond
= 0;
745 Time
->TimeZone
= EFI_UNSPECIFIED_TIMEZONE
;
752 Wait for a period for the RTC to be ready.
754 @param Timeout Tell how long it should take to wait.
756 @retval EFI_DEVICE_ERROR RTC device error.
757 @retval EFI_SUCCESS RTC is updated and ready.
764 RTC_REGISTER_A RegisterA
;
765 RTC_REGISTER_D RegisterD
;
768 // See if the RTC is functioning correctly
770 RegisterD
.Data
= RtcRead (RTC_ADDRESS_REGISTER_D
);
772 if (RegisterD
.Bits
.VRT
== 0) {
773 return EFI_DEVICE_ERROR
;
776 // Wait for up to 0.1 seconds for the RTC to be ready.
778 Timeout
= (Timeout
/ 10) + 1;
779 RegisterA
.Data
= RtcRead (RTC_ADDRESS_REGISTER_A
);
780 while (RegisterA
.Bits
.UIP
== 1 && Timeout
> 0) {
781 MicroSecondDelay (10);
782 RegisterA
.Data
= RtcRead (RTC_ADDRESS_REGISTER_A
);
786 RegisterD
.Data
= RtcRead (RTC_ADDRESS_REGISTER_D
);
787 if (Timeout
== 0 || RegisterD
.Bits
.VRT
== 0) {
788 return EFI_DEVICE_ERROR
;
795 See if all fields of a variable of EFI_TIME type is correct.
797 @param Time The time to be checked.
799 @retval EFI_INVALID_PARAMETER Some fields of Time are not correct.
800 @retval EFI_SUCCESS Time is a valid EFI_TIME variable.
808 if (Time
->Year
< 1998 ||
815 Time
->Nanosecond
> 999999999 ||
816 (!(Time
->TimeZone
== EFI_UNSPECIFIED_TIMEZONE
|| (Time
->TimeZone
>= -1440 && Time
->TimeZone
<= 1440))) ||
817 ((Time
->Daylight
& (~(EFI_TIME_ADJUST_DAYLIGHT
| EFI_TIME_IN_DAYLIGHT
))) != 0)
819 if (!DayValid (Time
)) {
820 return EFI_INVALID_PARAMETER
;
828 See if field Day of an EFI_TIME is correct.
830 @param Time Its Day field is to be checked.
832 @retval TRUE Day field of Time is correct.
833 @retval FALSE Day field of Time is NOT correct.
856 // The validity of Time->Month field should be checked before
858 ASSERT (Time
->Month
>=1);
859 ASSERT (Time
->Month
<=12);
861 Time
->Day
> DayOfMonth
[Time
->Month
- 1] ||
862 (Time
->Month
== 2 && (!IsLeapYear (Time
) && Time
->Day
> 28))
871 Check if it is a leap year.
873 @param Time The time to be checked.
875 @retval TRUE It is a leap year.
876 @retval FALSE It is NOT a leap year.
883 if (Time
->Year
% 4 == 0) {
884 if (Time
->Year
% 100 == 0) {
885 if (Time
->Year
% 400 == 0) {
899 Converts time from EFI_TIME format defined by UEFI spec to RTC's.
901 This function converts time from EFI_TIME format defined by UEFI spec to RTC's.
902 If data mode of RTC is BCD, then converts EFI_TIME to it.
903 If RTC is in 12-hour format, then converts EFI_TIME to it.
905 @param Time On input, the time data read from UEFI to convert
906 On output, the time converted to RTC format
907 @param RegisterB Value of Register B of RTC, indicating data mode
908 @param Century It is set according to EFI_TIME Time.
912 ConvertEfiTimeToRtcTime (
913 IN OUT EFI_TIME
*Time
,
914 IN RTC_REGISTER_B RegisterB
,
922 // Adjust hour field if RTC is in 12 hour mode
924 if (RegisterB
.Bits
.MIL
== 0) {
925 if (Time
->Hour
< 12) {
929 if (Time
->Hour
>= 13) {
930 Time
->Hour
= (UINT8
) (Time
->Hour
- 12);
931 } else if (Time
->Hour
== 0) {
936 // Set the Time/Date/Daylight Savings values.
938 *Century
= DecimalToBcd8 ((UINT8
) (Time
->Year
/ 100));
940 Time
->Year
= (UINT16
) (Time
->Year
% 100);
942 if (RegisterB
.Bits
.DM
== 0) {
943 Time
->Year
= DecimalToBcd8 ((UINT8
) Time
->Year
);
944 Time
->Month
= DecimalToBcd8 (Time
->Month
);
945 Time
->Day
= DecimalToBcd8 (Time
->Day
);
946 Time
->Hour
= DecimalToBcd8 (Time
->Hour
);
947 Time
->Minute
= DecimalToBcd8 (Time
->Minute
);
948 Time
->Second
= DecimalToBcd8 (Time
->Second
);
951 // If we are in 12 hour mode and PM is set, then set bit 7 of the Hour field.
953 if (RegisterB
.Bits
.MIL
== 0 && IsPM
) {
954 Time
->Hour
= (UINT8
) (Time
->Hour
| 0x80);
959 Compare the Hour, Minute and Second of the From time and the To time.
961 Only compare H/M/S in EFI_TIME and ignore other fields here.
963 @param From the first time
964 @param To the second time
966 @return >0 The H/M/S of the From time is later than those of To time
967 @return ==0 The H/M/S of the From time is same as those of To time
968 @return <0 The H/M/S of the From time is earlier than those of To time
976 if ((From
->Hour
> To
->Hour
) ||
977 ((From
->Hour
== To
->Hour
) && (From
->Minute
> To
->Minute
)) ||
978 ((From
->Hour
== To
->Hour
) && (From
->Minute
== To
->Minute
) && (From
->Second
> To
->Second
))) {
980 } else if ((From
->Hour
== To
->Hour
) && (From
->Minute
== To
->Minute
) && (From
->Second
== To
->Second
)) {
988 To check if second date is later than first date within 24 hours.
990 @param From the first date
991 @param To the second date
993 @retval TRUE From is previous to To within 24 hours.
994 @retval FALSE From is later, or it is previous to To more than 24 hours.
1002 UINT8 DayOfMonth
[12];
1015 DayOfMonth
[10] = 30;
1016 DayOfMonth
[11] = 31;
1021 // The validity of From->Month field should be checked before
1023 ASSERT (From
->Month
>=1);
1024 ASSERT (From
->Month
<=12);
1026 if (From
->Year
== To
->Year
) {
1027 if (From
->Month
== To
->Month
) {
1028 if ((From
->Day
+ 1) == To
->Day
) {
1029 if ((CompareHMS(From
, To
) >= 0)) {
1032 } else if (From
->Day
== To
->Day
) {
1033 if ((CompareHMS(From
, To
) <= 0)) {
1037 } else if (((From
->Month
+ 1) == To
->Month
) && (To
->Day
== 1)) {
1038 if ((From
->Month
== 2) && !IsLeapYear(From
)) {
1039 if (From
->Day
== 28) {
1040 if ((CompareHMS(From
, To
) >= 0)) {
1044 } else if (From
->Day
== DayOfMonth
[From
->Month
- 1]) {
1045 if ((CompareHMS(From
, To
) >= 0)) {
1050 } else if (((From
->Year
+ 1) == To
->Year
) &&
1051 (From
->Month
== 12) &&
1052 (From
->Day
== 31) &&
1055 if ((CompareHMS(From
, To
) >= 0)) {