From nobody Fri May 3 04:15:34 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+95663+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+95663+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1666929103; cv=none; d=zohomail.com; s=zohoarc; b=ZWqG/HUOU8S+NyVEbYwsja6Je5U61JnEFpfrZUPsmyaKIRi6O87uuj8qTlzYaYyjf3Jr7DNWwOFsaRh2Hizoaku7krkUKofcM01/xyOIE9rmw2pPA2ku86FKE+QOqdTJglqRj3qOsRuju93q+dOzFIsaGtUAQNqduQW0v0Vr1gg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1666929103; 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=4hZ1t1ovoeKoiGYGxeSolY7W5QBcu5qfaCRgJQVWZ5c=; b=N8QnxBSB6530bczqfPbBsNHU7yuz97Pa4q6U69ahCzfMkdvEmW51v41XUBez5gcIawST+u3tXIuTypL5NheO6DLy1P9KA22Zib3jWyb4qdHTYioerQO4S5vaDonRdoKCkc9DEq3eNIYhJYUg3uLxbQ0FbGYfsdlvGA7uh/IgjuA= 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+95663+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 1666929103429606.1456031293842; Thu, 27 Oct 2022 20:51:43 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id 8xDhYY1788612xu7K8MpPwFM; Thu, 27 Oct 2022 20:51:42 -0700 X-Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by mx.groups.io with SMTP id smtpd.web08.2560.1666929101340310126 for ; Thu, 27 Oct 2022 20:51:42 -0700 X-IronPort-AV: E=McAfee;i="6500,9779,10513"; a="288118653" X-IronPort-AV: E=Sophos;i="5.95,219,1661842800"; d="scan'208";a="288118653" X-Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Oct 2022 20:51:40 -0700 X-IronPort-AV: E=McAfee;i="6500,9779,10513"; a="701590268" X-IronPort-AV: E=Sophos;i="5.95,219,1661842800"; d="scan'208";a="701590268" X-Received: from shwdeopenlab702.ccr.corp.intel.com ([10.239.56.220]) by fmsmga004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Oct 2022 20:51:38 -0700 From: "duntan" To: devel@edk2.groups.io Cc: Eric Dong , Ray Ni , Rahul Kumar , Michael D Kinney Subject: [edk2-devel] [Patch V2] UefiCpuPkg: Restore HpetTimer after CpuExceptionHandlerLib test Date: Fri, 28 Oct 2022 11:51:18 +0800 Message-Id: <20221028035118.1828-1-dun.tan@intel.com> 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,dun.tan@intel.com X-Gm-Message-State: QFycjp1fbTc5sXfniNfScgGGx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1666929102; bh=HNEvxFnkqVd9HVH9ay0jBzJ5quvlN0xO6LTj5vOhJNo=; h=Cc:Date:From:Reply-To:Subject:To; b=ORTwQlW1KI5blSu+CC26bssHKWxxG44gsKiemKkciRWRgCT0szzOZ4Zmu4pseVal+xL eQjaZPgcMWMImb1qp+5a8JaOU+uUTKOz8iRWKu9bg5JXf9qRb91o4dBVl1a7ZTMvqW8e5 3TU6qrVCEY8qBmtS1OaQIOi7E8Oo+gJSV60= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1666929105550100002 Content-Type: text/plain; charset="utf-8" Disable/Restore HpetTimer before and after running the Dxe CpuExceptionHandlerLib unit test module. During the UnitTest, a new Idt is initialized for the test. There is no handler for timer intrrupt in this new idt. After the test module, HpetTimer does not work any more since the comparator value register and main counter value register for timer does not match. To fix this issue, disable/restore HpetTimer before and after Unit Test if HpetTimer driver has been dispatched. We don't need to send Apic Eoi in this unit test module.When disabling timer, after RaiseTPL(), if there is a pending timer interrupt, bit64 of Interrupt Request Register (IRR) will be set to 1 to indicate there is a pending timer interrupt. After RestoreTPL(), CPU will handle the pending interrupt in IRR.Then TimerInterruptHandler calls SendApicEoi(). Signed-off-by: Dun Tan Cc: Eric Dong Cc: Ray Ni Cc: Rahul Kumar Cc: Michael D Kinney Reviewed-by: Ray Ni --- UefiCpuPkg/Library/CpuExceptionHandlerLib/UnitTest/DxeCpuExceptionHandlerL= ibUnitTest.inf | 1 + UefiCpuPkg/Library/CpuExceptionHandlerLib/UnitTest/DxeCpuExceptionHandlerU= nitTest.c | 30 +++++++++++++++++++++++++++++- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/UnitTest/DxeCpuExcep= tionHandlerLibUnitTest.inf b/UefiCpuPkg/Library/CpuExceptionHandlerLib/Unit= Test/DxeCpuExceptionHandlerLibUnitTest.inf index e3dbe7b9ab..a904eb2504 100644 --- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/UnitTest/DxeCpuExceptionHan= dlerLibUnitTest.inf +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/UnitTest/DxeCpuExceptionHan= dlerLibUnitTest.inf @@ -53,6 +53,7 @@ =20 [Protocols] gEfiMpServiceProtocolGuid + gEfiTimerArchProtocolGuid =20 [Depex] gEfiMpServiceProtocolGuid diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/UnitTest/DxeCpuExcep= tionHandlerUnitTest.c b/UefiCpuPkg/Library/CpuExceptionHandlerLib/UnitTest/= DxeCpuExceptionHandlerUnitTest.c index 917fc549bf..1cec3ed809 100644 --- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/UnitTest/DxeCpuExceptionHan= dlerUnitTest.c +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/UnitTest/DxeCpuExceptionHan= dlerUnitTest.c @@ -8,6 +8,7 @@ =20 #include "CpuExceptionHandlerTest.h" #include +#include =20 /** Initialize Bsp Idt with a new Idt table and return the IA32_DESCRIPTOR b= uffer. @@ -162,8 +163,12 @@ CpuExceptionHandlerTestEntry ( { EFI_STATUS Status; UNIT_TEST_FRAMEWORK_HANDLE Framework; + EFI_TIMER_ARCH_PROTOCOL *TimerArchProtocol; + UINT64 TimerPeriod; =20 - Framework =3D NULL; + Framework =3D NULL; + TimerArchProtocol =3D NULL; + TimerPeriod =3D 0; =20 DEBUG ((DEBUG_INFO, "%a v%a\n", UNIT_TEST_APP_NAME, UNIT_TEST_APP_VERSIO= N)); =20 @@ -182,11 +187,34 @@ CpuExceptionHandlerTestEntry ( goto EXIT; } =20 + // + // If HpetTimer driver has been dispatched, disable HpetTimer before Uni= t Test. + // + gBS->LocateProtocol (&gEfiTimerArchProtocolGuid, NULL, (VOID **)&TimerAr= chProtocol); + if (TimerArchProtocol !=3D NULL) { + Status =3D TimerArchProtocol->GetTimerPeriod (TimerArchProtocol, &Time= rPeriod); + ASSERT_EFI_ERROR (Status); + if (TimerPeriod > 0) { + DEBUG ((DEBUG_INFO, "HpetTimer has been dispatched. Disable HpetTime= r.\n")); + Status =3D TimerArchProtocol->SetTimerPeriod (TimerArchProtocol, 0); + ASSERT_EFI_ERROR (Status); + } + } + // // Execute the tests. // Status =3D RunAllTestSuites (Framework); =20 + // + // Restore HpetTimer after Unit Test. + // + if ((TimerArchProtocol !=3D NULL) && (TimerPeriod > 0)) { + DEBUG ((DEBUG_INFO, "Restore HpetTimer after DxeCpuExceptionHandlerLib= UnitTest.\n")); + Status =3D TimerArchProtocol->SetTimerPeriod (TimerArchProtocol, Timer= Period); + ASSERT_EFI_ERROR (Status); + } + EXIT: if (Framework) { FreeUnitTestFramework (Framework); --=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 (#95663): https://edk2.groups.io/g/devel/message/95663 Mute This Topic: https://groups.io/mt/94619956/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-