From nobody Fri Apr 19 10:20:32 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+89569+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+89569+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1651891837; cv=none; d=zohomail.com; s=zohoarc; b=NPURO5EZ5GHbOHtWNVnonxmrCGZ+64anFGN5HksL9OJMsIQryot46XTJJiskYAHaUB9yv//czOIzvFBSLFYDVCCHRrgb+dSnb8FsPC6hk52kOqj2ZDe2ZE/Bhp1sPeutGWYJ4MC2HF5AZ5ua98DU5mnUg5BRq9DnF2zKFRFDMcc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1651891837; h=Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Sender:Subject:To; bh=POAOb+oHm2uBco+FinLd3lNfHSI/ipLgIVyJwAuYODw=; b=P/ouDMHa3hheSfu95WSYlpNo80gysIIqH+5zv/5uWmQGCaXP6ecA8cYi22QW4ZmSFr9BuMiIggkkJeLD7eIoI3nj7wZBV712WvPhvHF3j3TKI2jt9p6shKpUfxmpiJvbPkhmtkBGJbBYLmmGytBAhd8+Kzu7ZVwfrBRrPEhrWQU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+89569+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1651891837700119.97277479077127; Fri, 6 May 2022 19:50:37 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id Ext2YY1788612xtHRODGGSpN; Fri, 06 May 2022 19:50:37 -0700 X-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 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" X-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" X-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: [edk2-devel] [PATCH v2] PcAtChipsetPkg: Change the flow of PcRtcInit() Date: Sat, 7 May 2022 10:50:19 +0800 Message-Id: MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,zhuoran.chao@intel.com X-Gm-Message-State: n3N1vHmH6h36WB1SWrZHg5Z1x1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1651891837; bh=d6PyR7CjLQVuP7bEc/NeIWBTwBMRxf1V24EqjSgOZVU=; h=Cc:Date:From:Reply-To:Subject:To; b=j/hZB2bdl1rVg6bVNmLQe5AbHzXg39flw3+YEzGtKSC4PHFlu2KTR+astTOrOxnJEiS LJmzVCOv61FgyMezw6YnQs7Yv4CY3TXRsvg1zUWSKc+nBakeVWlm6x5k/qAN0REPuTI76 XylAqWnJNjFok/oN8ojD+z8NuU+Otnv0B1Q= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1651891838327100001 Content-Type: text/plain; charset="utf-8" REF:https://bugzilla.tianocore.org/show_bug.cgi?id=3D3913 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/PcAtChips= etPkg/PcatRealTimeClockRuntimeDxe/PcRtc.c index 0fbfa4bcee..dbce7c217c 100644 --- a/PcAtChipsetPkg/PcatRealTimeClockRuntimeDxe/PcRtc.c +++ b/PcAtChipsetPkg/PcatRealTimeClockRuntimeDxe/PcRtc.c @@ -269,13 +269,6 @@ PcRtcInit ( Time.Month =3D RtcRead (RTC_ADDRESS_MONTH); Time.Year =3D RtcRead (RTC_ADDRESS_YEAR); =20 - // - // Set RTC configuration after get original time - // The value of bit AIE should be reserved. - // - RegisterB.Data =3D FixedPcdGet8 (PcdInitialValueRtcRegisterB) | (Registe= rB.Data & BIT5); - RtcWrite (RTC_ADDRESS_REGISTER_B, RegisterB.Data); - // // Release RTC Lock. // @@ -330,6 +323,13 @@ PcRtcInit ( Time.Daylight =3D 0; } =20 + // + // Set RTC configuration after get original time + // The value of bit AIE should be reserved. + // + RegisterB.Data =3D FixedPcdGet8 (PcdInitialValueRtcRegisterB) | (Registe= rB.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; =20 - if ((Time->Hour & 0x80) !=3D 0) { - IsPM =3D TRUE; - } else { - IsPM =3D FALSE; + // Check 24-hour format situation + if (RegisterB.Bits.Mil =3D=3D 1) { + if (RegisterB.Bits.Dm =3D=3D 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 =3D=3D 0) { + if ((Time->Hour & 0x80) !=3D 0) { + IsPM =3D TRUE; + } else { + IsPM =3D FALSE; + } } =20 Time->Hour =3D (UINT8)(Time->Hour & 0x7f); --=20 2.31.1.windows.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#89569): https://edk2.groups.io/g/devel/message/89569 Mute This Topic: https://groups.io/mt/90947516/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-