From: "duntan" <dun.tan@intel.com>
To: devel@edk2.groups.io
Cc: Eric Dong <eric.dong@intel.com>, Ray Ni <ray.ni@intel.com>,
Rahul Kumar <rahul1.kumar@intel.com>
Subject: [PATCH] UefiCpuPkg: Restore HpetTimer after CpuExceptionHandlerLib test
Date: Thu, 20 Oct 2022 11:00:55 +0800 [thread overview]
Message-ID: <20221020030055.815-1-dun.tan@intel.com> (raw)
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 <dun.tan@intel.com>
Cc: Eric Dong <eric.dong@intel.com>
Cc: Ray Ni <ray.ni@intel.com>
Cc: Rahul Kumar <rahul1.kumar@intel.com>
---
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 <Library/UefiBootServicesTableLib.h>
+#include <Library/LocalApicLib.h>
+#include <Protocol/Timer.h>
/**
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
next reply other threads:[~2022-10-20 3:01 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-20 3:00 duntan [this message]
2022-10-27 2:08 ` [PATCH] UefiCpuPkg: Restore HpetTimer after CpuExceptionHandlerLib test Ni, Ray
2022-10-27 2:26 ` [edk2-devel] " Michael D Kinney
2022-10-27 2:32 ` Ni, Ray
[not found] ` <1721CC636147BB21.550@groups.io>
2022-10-27 3:03 ` Ni, Ray
2022-10-27 3:08 ` duntan
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20221020030055.815-1-dun.tan@intel.com \
--to=devel@edk2.groups.io \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox