From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by mx.groups.io with SMTP id smtpd.web08.6190.1651891834212473311 for ; Fri, 06 May 2022 19:50:35 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="unable to parse pub key" header.i=@intel.com header.s=intel header.b=WI0d42EZ; spf=pass (domain: intel.com, ip: 192.55.52.151, 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=1651891834; x=1683427834; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=jH7TIsdIwDXz/3lLG4ZeiI7FWnbDk8pj4XTDc9m11Ng=; b=WI0d42EZgDdYjnp0RHZL8zbXaZTokQm5TpeXajcRyu33fwbXetotqzG3 nOK9fV8Kt8Dfo9FQGTmTh7YACTAHDJKlYCj9bsE+eykdHDmfXoAwGfZjE lNt+2kSwc5hmnlWg7KGL/sC13ZMzo59oE3yF9ZaxEjRkAXxj3+xM/nwjf tm1szWNECEXXpfaOk9itbZQn2Tw9/BSiyVt03FWzJsY/7H2DP8Ti4cpoA LbVF3fhZQXwAI1SYlLaLqcBpfILbQqzCETR9kWQhUb7yqdwuY8OzuDxC6 uF1E8F6fsTpROXcWQjhjZTDm1tEYry8N6acuqKk5f4lurBUx/QMjp2HWs Q==; X-IronPort-AV: E=McAfee;i="6400,9594,10339"; a="249172642" X-IronPort-AV: E=Sophos;i="5.91,205,1647327600"; d="scan'208";a="249172642" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 May 2022 19:50:31 -0700 X-IronPort-AV: E=Sophos;i="5.91,205,1647327600"; d="scan'208";a="586319128" 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; 06 May 2022 19:50:30 -0700 From: "Zhuoran Chao" To: devel@edk2.groups.io Cc: Zhuoran Chao , Ray Ni Subject: [PATCH v2] PcAtChipsetPkg: Change the flow of PcRtcInit() Date: Sat, 7 May 2022 10:50:19 +0800 Message-Id: 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 | 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