From mboxrd@z Thu Jan 1 00:00:00 1970 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 Authentication-Results: mx.groups.io; dkim=fail reason="unable to parse pub key" header.i=@intel.com header.s=intel header.b=ZpvzHpmN; spf=pass (domain: intel.com, ip: 192.55.52.136, mailfrom: dun.tan@intel.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1666929101; x=1698465101; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=c2MZgoYwjJ53dPvrv22wC4TLRpYBiK8uhzQbOwh3OOU=; b=ZpvzHpmNy1M9eMd42fX3HZ+/MLdyb+sLMyguowOc4jItVfhzihsAea76 EOVLw5ilY+fxR+P+cG4wdjnTr+UCNbZfxbjgk4ptKHOPKYeIHtJx+cYod RwU4poXyFBSQECOem657FWxJVlsyV2XClWSiah4/fAkHQLla3+kPyfR/7 At2sNE8b+SQBZPvpqnoA6T99GTqlB2CTN9Ox6jGJsaU4xtbR+mRHbbYs0 ZkwYIgQHENXqe1ICGMeyqFLRpSB1h3f+skelZap2BjVb7ftZACOJKs5jq ZFFG1u0m5nJ65Bm7pHcBjwvC59MC0HceUVJCQJx+Iws3A+AOxbdCoiUGl A==; 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" 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" 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: [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> X-Mailer: git-send-email 2.31.1.windows.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 --- UefiCpuPkg/Library/CpuExceptionHandlerLib/UnitTest/DxeCpuExceptionHandlerLibUnitTest.inf | 1 + UefiCpuPkg/Library/CpuExceptionHandlerLib/UnitTest/DxeCpuExceptionHandlerUnitTest.c | 30 +++++++++++++++++++++++++++++- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/UnitTest/DxeCpuExceptionHandlerLibUnitTest.inf b/UefiCpuPkg/Library/CpuExceptionHandlerLib/UnitTest/DxeCpuExceptionHandlerLibUnitTest.inf index e3dbe7b9ab..a904eb2504 100644 --- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/UnitTest/DxeCpuExceptionHandlerLibUnitTest.inf +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/UnitTest/DxeCpuExceptionHandlerLibUnitTest.inf @@ -53,6 +53,7 @@ [Protocols] gEfiMpServiceProtocolGuid + gEfiTimerArchProtocolGuid [Depex] gEfiMpServiceProtocolGuid diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/UnitTest/DxeCpuExceptionHandlerUnitTest.c b/UefiCpuPkg/Library/CpuExceptionHandlerLib/UnitTest/DxeCpuExceptionHandlerUnitTest.c index 917fc549bf..1cec3ed809 100644 --- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/UnitTest/DxeCpuExceptionHandlerUnitTest.c +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/UnitTest/DxeCpuExceptionHandlerUnitTest.c @@ -8,6 +8,7 @@ #include "CpuExceptionHandlerTest.h" #include +#include /** Initialize Bsp Idt with a new Idt table and return the IA32_DESCRIPTOR buffer. @@ -162,8 +163,12 @@ CpuExceptionHandlerTestEntry ( { EFI_STATUS Status; UNIT_TEST_FRAMEWORK_HANDLE Framework; + EFI_TIMER_ARCH_PROTOCOL *TimerArchProtocol; + UINT64 TimerPeriod; - Framework = NULL; + Framework = NULL; + TimerArchProtocol = NULL; + TimerPeriod = 0; DEBUG ((DEBUG_INFO, "%a v%a\n", UNIT_TEST_APP_NAME, UNIT_TEST_APP_VERSION)); @@ -182,11 +187,34 @@ CpuExceptionHandlerTestEntry ( goto EXIT; } + // + // If HpetTimer driver has been dispatched, disable HpetTimer before Unit Test. + // + gBS->LocateProtocol (&gEfiTimerArchProtocolGuid, NULL, (VOID **)&TimerArchProtocol); + if (TimerArchProtocol != NULL) { + Status = TimerArchProtocol->GetTimerPeriod (TimerArchProtocol, &TimerPeriod); + ASSERT_EFI_ERROR (Status); + if (TimerPeriod > 0) { + DEBUG ((DEBUG_INFO, "HpetTimer has been dispatched. Disable HpetTimer.\n")); + Status = TimerArchProtocol->SetTimerPeriod (TimerArchProtocol, 0); + ASSERT_EFI_ERROR (Status); + } + } + // // Execute the tests. // Status = RunAllTestSuites (Framework); + // + // Restore HpetTimer after Unit Test. + // + if ((TimerArchProtocol != NULL) && (TimerPeriod > 0)) { + DEBUG ((DEBUG_INFO, "Restore HpetTimer after DxeCpuExceptionHandlerLib UnitTest.\n")); + Status = TimerArchProtocol->SetTimerPeriod (TimerArchProtocol, TimerPeriod); + ASSERT_EFI_ERROR (Status); + } + EXIT: if (Framework) { FreeUnitTestFramework (Framework); -- 2.31.1.windows.1