From mboxrd@z Thu Jan 1 00:00:00 1970 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 Authentication-Results: mx.groups.io; dkim=fail reason="unable to parse pub key" header.i=@intel.com header.s=intel header.b=nBG3iFoI; spf=pass (domain: intel.com, ip: 134.134.136.126, 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=1666234899; x=1697770899; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=+z2DP5VEZ2TQ4PLoxgjtznfGTXOaC2j9GVHIItqFWgI=; b=nBG3iFoItM6J658IDSfLFw5l/sgmMBlNXKmFCE/dMn6Z7O3H+lAK52PS yoF7VVTySKBUEnmQLS25jPLyz7oXl//UgdJFeGUfwAxO2tvks8oy0gdu6 7aULEmzU0CwpA2dd49ptw7W6+2DheR2RvlZ8BkJOhct8IYuN5Z9RkUNWo ceu0st/v/BVTAgeiZW/KLkRKrSlelzNMJB4OU2Pbaw/5vs007300Brvkc mTJL1NDzqLWmcBq5TRqLzHL7jHum7FxYRL7GEtrhYk8REX/dIvA2L8KE9 Oj0tdcBTMTlV6mDlzKPvX9pANI055WrEli4X0eYMIe6lERrtA3y1xsK3h Q==; 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" 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" 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: [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> 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. Besides, send Apic EOI before restore HpetTimer. Signed-off-by: Dun Tan Cc: Eric Dong Cc: Ray Ni Cc: Rahul Kumar --- UefiCpuPkg/Library/CpuExceptionHandlerLib/UnitTest/DxeCpuExceptionHandlerLibUnitTest.inf | 2 ++ UefiCpuPkg/Library/CpuExceptionHandlerLib/UnitTest/DxeCpuExceptionHandlerUnitTest.c | 33 ++++++++++++++++++++++++++++++++- 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/UnitTest/DxeCpuExceptionHandlerLibUnitTest.inf b/UefiCpuPkg/Library/CpuExceptionHandlerLib/UnitTest/DxeCpuExceptionHandlerLibUnitTest.inf index e3dbe7b9ab..24f905936c 100644 --- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/UnitTest/DxeCpuExceptionHandlerLibUnitTest.inf +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/UnitTest/DxeCpuExceptionHandlerLibUnitTest.inf @@ -43,6 +43,7 @@ HobLib UefiBootServicesTableLib CpuPageTableLib + LocalApicLib [Guids] gEfiHobMemoryAllocStackGuid @@ -53,6 +54,7 @@ [Protocols] gEfiMpServiceProtocolGuid + gEfiTimerArchProtocolGuid [Depex] gEfiMpServiceProtocolGuid diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/UnitTest/DxeCpuExceptionHandlerUnitTest.c b/UefiCpuPkg/Library/CpuExceptionHandlerLib/UnitTest/DxeCpuExceptionHandlerUnitTest.c index 917fc549bf..045f39fa00 100644 --- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/UnitTest/DxeCpuExceptionHandlerUnitTest.c +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/UnitTest/DxeCpuExceptionHandlerUnitTest.c @@ -8,6 +8,8 @@ #include "CpuExceptionHandlerTest.h" #include +#include +#include /** Initialize Bsp Idt with a new Idt table and return the IA32_DESCRIPTOR buffer. @@ -162,8 +164,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 +188,36 @@ 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. + // Send APIC EOI before SetTimerPeriod. + // + if ((TimerArchProtocol != NULL) && (TimerPeriod > 0)) { + DEBUG ((DEBUG_INFO, "Restore HpetTimer after DxeCpuExceptionHandlerLib UnitTest.\n")); + SendApicEoi (); + Status = TimerArchProtocol->SetTimerPeriod (TimerArchProtocol, TimerPeriod); + ASSERT_EFI_ERROR (Status); + } + EXIT: if (Framework) { FreeUnitTestFramework (Framework); -- 2.31.1.windows.1