From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by mx.groups.io with SMTP id smtpd.web08.8181.1651916386219383154 for ; Sat, 07 May 2022 02:39:47 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="unable to parse pub key" header.i=@intel.com header.s=intel header.b=mEHLIhi/; spf=pass (domain: intel.com, ip: 192.55.52.93, mailfrom: zhuoran.chao@intel.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1651916386; x=1683452386; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=UUXI/YH6QNeA32GsZigcDhxQ4xf0elPKrrFmhMEcIjA=; b=mEHLIhi/UaeFpdTDtxKe2RnwbopSCvaygp5viElpfkcFuQmucPJGXlDb w4L8OVONeegVlMv1ttnC2ZFcwXYz6M6VGgeuA2HrypTmIp+ZIoZXL6rqn lI2N3nbL+4XeiIoY4fDfwOY5jKVHeM6fwSkdUBqAcPTeJL5ngmTew+cqT KiD9En4MMWY+KK1xmbxc7xz1VXQXSgGnWvbmoUH418eAtbyYII4o190QK SSO+kur9GdEckQT1Mw1cpMXYbYvrTOa7lH0lFC9EWS8VdodOKe7BJhQs5 7nRDXs+zd8YioT9kFY0o4uGAafTWgJtFYVFYKHvQFuuLXyUI0Lk4SODig w==; X-IronPort-AV: E=McAfee;i="6400,9594,10339"; a="266275632" X-IronPort-AV: E=Sophos;i="5.91,206,1647327600"; d="scan'208";a="266275632" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 May 2022 02:39:45 -0700 X-IronPort-AV: E=Sophos;i="5.91,206,1647327600"; d="scan'208";a="586441587" Received: from zchao-mobl1.ccr.corp.intel.com ([10.249.172.67]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 May 2022 02:39:43 -0700 From: "Zhuoran Chao" To: devel@edk2.groups.io Cc: Zhuoran Chao , Ray Ni Subject: [PATCH v3] PcAtChipsetPkg: Change the flow of PcRtcInit() Date: Sat, 7 May 2022 17:39:37 +0800 Message-Id: <1d9ab6d031b853fb580366834fd1809c84d321fd.1651915058.git.zhuoran.chao@intel.com> X-Mailer: git-send-email 2.31.1.windows.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 Signed-off-by: Zhuoran Chao --- .../PcatRealTimeClockRuntimeDxe/PcRtc.c | 29 ++++++++++--------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/PcAtChipsetPkg/PcatRealTimeClockRuntimeDxe/PcRtc.c b/PcAtChipsetPkg/PcatRealTimeClockRuntimeDxe/PcRtc.c index 0fbfa4bcee..9242a2e826 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,13 +995,16 @@ ConvertRtcTimeToEfiTime ( BOOLEAN IsPM; UINT8 Century; - if ((Time->Hour & 0x80) != 0) { - IsPM = TRUE; - } else { - IsPM = FALSE; - } + // 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); + Time->Hour = (UINT8)(Time->Hour & 0x7f); + } if (RegisterB.Bits.Dm == 0) { Time->Year = CheckAndConvertBcd8ToDecimal8 ((UINT8)Time->Year); -- 2.31.1.windows.1