From nobody Sat May 18 23:14:58 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+95414+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+95414+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1666234901; cv=none; d=zohomail.com; s=zohoarc; b=UwnZfqkMXVCdrsMrdOKiIux65UY1y8GwyfKqXMVGjJHDM+SA1CdNDu/FWHwDzU+ghKuypPdjoYbEYg+pLArt9oexs8iukcQRokJbH+0MrC3HXyZtSim+tAndb1A79kJydH3yIYCg1KT+fhBK1Pz7iACwgeWXbDiuezeY6fcHlec= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1666234901; 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=Pb2ktCk3wEorJ42p+jhYDClFn0l+sM6FF+8qnUM5KAY=; b=JVxlOjBJsnFd1QukgLEm0xtCKQb1Arb9o8Pr7E1xLPL8xuuI4i+Q2kQ3vuryQztW+iACd0ZPUEP6Kbys/NnX1vAXYsYQ4icPbPLWGk9VhLyAq4P1FdnKyAdZTsbxtduxAKdrUWMYyupT6WR0tFmixJPpei5b2iJlRZg6wHVxQUQ= 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+95414+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 1666234900984108.66160807162771; Wed, 19 Oct 2022 20:01:40 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id kdvYYY1788612xYVUPRJAgJ5; Wed, 19 Oct 2022 20:01:40 -0700 X-Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by mx.groups.io with SMTP id smtpd.web12.5561.1666234899706363835 for ; Wed, 19 Oct 2022 20:01:39 -0700 X-IronPort-AV: E=McAfee;i="6500,9779,10505"; a="289899557" X-IronPort-AV: E=Sophos;i="5.95,196,1661842800"; d="scan'208";a="289899557" X-Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Oct 2022 20:01:39 -0700 X-IronPort-AV: E=McAfee;i="6500,9779,10505"; a="662777336" X-IronPort-AV: E=Sophos;i="5.95,196,1661842800"; d="scan'208";a="662777336" X-Received: from shwdeopenlab702.ccr.corp.intel.com ([10.239.56.220]) by orsmga001-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Oct 2022 20:01:37 -0700 From: "duntan" To: devel@edk2.groups.io Cc: Eric Dong , Ray Ni , Rahul Kumar Subject: [edk2-devel] [PATCH] UefiCpuPkg: Restore HpetTimer after CpuExceptionHandlerLib test Date: Thu, 20 Oct 2022 11:00:55 +0800 Message-Id: <20221020030055.815-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: X3gMUNorZgo26E3oGgyI1Dgex1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1666234900; bh=9Uw/fReCUBnfeUIDeJ2t9et3d4Fj97jUoQYGWiP6nEk=; h=Cc:Date:From:Reply-To:Subject:To; b=tXX+KCveAnz3uFPF3HFNYALIn8gqJrlxywgigoZXd0szQasUk3WbDD+Latebu4ICWqO O1RycV0Zq9324PJqea4XkZfX5o8/SiM0hEkVk9/6rCaQs3Dw9EvEDe+ui+0O9kT+lkOCK lPjTcvKxMPfu3GJTj03QHo2LuMP42/14F9s= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1666234901971100001 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. Besides, send Apic EOI before restore HpetTimer. Signed-off-by: Dun Tan Cc: Eric Dong Cc: Ray Ni Cc: Rahul Kumar Reviewed-by: Ray Ni --- UefiCpuPkg/Library/CpuExceptionHandlerLib/UnitTest/DxeCpuExceptionHandlerL= ibUnitTest.inf | 2 ++ UefiCpuPkg/Library/CpuExceptionHandlerLib/UnitTest/DxeCpuExceptionHandlerU= nitTest.c | 33 ++++++++++++++++++++++++++++++++- 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/UnitTest/DxeCpuExcep= tionHandlerLibUnitTest.inf b/UefiCpuPkg/Library/CpuExceptionHandlerLib/Unit= Test/DxeCpuExceptionHandlerLibUnitTest.inf index e3dbe7b9ab..24f905936c 100644 --- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/UnitTest/DxeCpuExceptionHan= dlerLibUnitTest.inf +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/UnitTest/DxeCpuExceptionHan= dlerLibUnitTest.inf @@ -43,6 +43,7 @@ HobLib UefiBootServicesTableLib CpuPageTableLib + LocalApicLib =20 [Guids] gEfiHobMemoryAllocStackGuid @@ -53,6 +54,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..045f39fa00 100644 --- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/UnitTest/DxeCpuExceptionHan= dlerUnitTest.c +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/UnitTest/DxeCpuExceptionHan= dlerUnitTest.c @@ -8,6 +8,8 @@ =20 #include "CpuExceptionHandlerTest.h" #include +#include +#include =20 /** Initialize Bsp Idt with a new Idt table and return the IA32_DESCRIPTOR b= uffer. @@ -162,8 +164,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 +188,36 @@ 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. + // Send APIC EOI before SetTimerPeriod. + // + if ((TimerArchProtocol !=3D NULL) && (TimerPeriod > 0)) { + DEBUG ((DEBUG_INFO, "Restore HpetTimer after DxeCpuExceptionHandlerLib= UnitTest.\n")); + SendApicEoi (); + 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 (#95414): https://edk2.groups.io/g/devel/message/95414 Mute This Topic: https://groups.io/mt/94446624/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-