* [PATCH v2] PcAtChipsetPkg: Change the flow of PcRtcInit()
@ 2022-05-07 2:50 Zhuoran Chao
2022-05-07 5:43 ` Ni, Ray
0 siblings, 1 reply; 2+ messages in thread
From: Zhuoran Chao @ 2022-05-07 2:50 UTC (permalink / raw)
To: devel; +Cc: Zhuoran Chao, Ray Ni
REF:https://bugzilla.tianocore.org/show_bug.cgi?id=3913
The original flow of PcRtcInit() is like:
1. Guarantee atomic accesses to the RTC time registers and
read out the value.
2. Program RTC register B. (adopt 12h mode or 24h mode. Current
bios code sets RTC to 24h mode by default).
3. Then function ConvertRtcTimeToEfiTime converts the RTC time
value to their 24h mode by checking the hour format bit
(1:24h mode,0:12h mode).
And here lies the problem: Step3 will fail to adjust the value
if Step2 already sets RTC to 24h mode. The hour value in 12h mode
will not be converted to its 24h mode.
The solution is to program RTC register B a little later when all
the original RTC registers' value is retrieved, adjusted
and validated.
ConvertRtcTimeToEfiTime is modified to be more robust.
Cc: Ray Ni <ray.ni@intel.com>
Signed-off-by: Zhuoran Chao <zhuoran.chao@intel.com>
---
.../PcatRealTimeClockRuntimeDxe/PcRtc.c | 38 +++++++++++++------
1 file changed, 27 insertions(+), 11 deletions(-)
diff --git a/PcAtChipsetPkg/PcatRealTimeClockRuntimeDxe/PcRtc.c b/PcAtChipsetPkg/PcatRealTimeClockRuntimeDxe/PcRtc.c
index 0fbfa4bcee..dbce7c217c 100644
--- a/PcAtChipsetPkg/PcatRealTimeClockRuntimeDxe/PcRtc.c
+++ b/PcAtChipsetPkg/PcatRealTimeClockRuntimeDxe/PcRtc.c
@@ -269,13 +269,6 @@ PcRtcInit (
Time.Month = RtcRead (RTC_ADDRESS_MONTH);
Time.Year = RtcRead (RTC_ADDRESS_YEAR);
- //
- // Set RTC configuration after get original time
- // The value of bit AIE should be reserved.
- //
- RegisterB.Data = FixedPcdGet8 (PcdInitialValueRtcRegisterB) | (RegisterB.Data & BIT5);
- RtcWrite (RTC_ADDRESS_REGISTER_B, RegisterB.Data);
-
//
// Release RTC Lock.
//
@@ -330,6 +323,13 @@ PcRtcInit (
Time.Daylight = 0;
}
+ //
+ // Set RTC configuration after get original time
+ // The value of bit AIE should be reserved.
+ //
+ RegisterB.Data = FixedPcdGet8 (PcdInitialValueRtcRegisterB) | (RegisterB.Data & BIT5);
+ RtcWrite (RTC_ADDRESS_REGISTER_B, RegisterB.Data);
+
//
// Reset time value according to new RTC configuration
//
@@ -995,10 +995,26 @@ ConvertRtcTimeToEfiTime (
BOOLEAN IsPM;
UINT8 Century;
- if ((Time->Hour & 0x80) != 0) {
- IsPM = TRUE;
- } else {
- IsPM = FALSE;
+ // Check 24-hour format situation
+ if (RegisterB.Bits.Mil == 1) {
+ if (RegisterB.Bits.Dm == 0) {
+ if (Time->Hour > 0x23) {
+ return EFI_INVALID_PARAMETER;
+ }
+ } else {
+ if (Time->Hour > 0x17) {
+ return EFI_INVALID_PARAMETER;
+ }
+ }
+ }
+
+ // IsPM only makes sense for 12-hour format.
+ if (RegisterB.Bits.Mil == 0) {
+ if ((Time->Hour & 0x80) != 0) {
+ IsPM = TRUE;
+ } else {
+ IsPM = FALSE;
+ }
}
Time->Hour = (UINT8)(Time->Hour & 0x7f);
--
2.31.1.windows.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH v2] PcAtChipsetPkg: Change the flow of PcRtcInit()
2022-05-07 2:50 [PATCH v2] PcAtChipsetPkg: Change the flow of PcRtcInit() Zhuoran Chao
@ 2022-05-07 5:43 ` Ni, Ray
0 siblings, 0 replies; 2+ messages in thread
From: Ni, Ray @ 2022-05-07 5:43 UTC (permalink / raw)
To: Chao, Zhuoran, devel@edk2.groups.io
> - if ((Time->Hour & 0x80) != 0) {
> - IsPM = TRUE;
> - } else {
> - IsPM = FALSE;
> + // Check 24-hour format situation
> + if (RegisterB.Bits.Mil == 1) {
> + if (RegisterB.Bits.Dm == 0) {
> + if (Time->Hour > 0x23) {
> + return EFI_INVALID_PARAMETER;
> + }
> + } else {
> + if (Time->Hour > 0x17) {
> + return EFI_INVALID_PARAMETER;
> + }
> + }
> + }
> +
> + // IsPM only makes sense for 12-hour format.
> + if (RegisterB.Bits.Mil == 0) {
> + if ((Time->Hour & 0x80) != 0) {
> + IsPM = TRUE;
> + } else {
> + IsPM = FALSE;
> + }
> }
>
Is it possible to remove above check?
RtcTimeFieldsValid() already does the check.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2022-05-07 5:43 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-05-07 2:50 [PATCH v2] PcAtChipsetPkg: Change the flow of PcRtcInit() Zhuoran Chao
2022-05-07 5:43 ` Ni, Ray
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox