InitializeApicTimer() will enable Local APIC timer interrupt. Even though we
disable CPU interrupt at the beginning and enable CPU Interrupt after debug
agent initialized completely, some Boot Service may invoke RestoreTpl () which
may enable CPU interrupt.
We should disable Local APIC timer in InitializeDebugTimer () to avoid Debug
Timer interrupt happens during debug port and debug agent initialization phase.
And enable Debug Timer interrupt after debug agent is initialized.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jeff Fan <jeff....@intel.com>
CC: Ruiyu Ni <ruiyu...@intel.com>
---
 .../Library/DebugAgent/DebugAgentCommon/DebugAgent.c              | 1 +
 .../Library/DebugAgent/DebugAgentCommon/DebugTimer.c              | 5 +++++
 .../Library/DebugAgent/DxeDebugAgent/DxeDebugAgentLib.c           | 8 ++++++++
 .../Library/DebugAgent/SecPeiDebugAgent/SecPeiDebugAgentLib.c     | 4 ++++
 .../Library/DebugAgent/SmmDebugAgent/SmmDebugAgentLib.c           | 5 ++++-
 5 files changed, 22 insertions(+), 1 deletion(-)

diff --git 
a/SourceLevelDebugPkg/Library/DebugAgent/DebugAgentCommon/DebugAgent.c 
b/SourceLevelDebugPkg/Library/DebugAgent/DebugAgentCommon/DebugAgent.c
index 3eca304..6c32586 100644
--- a/SourceLevelDebugPkg/Library/DebugAgent/DebugAgentCommon/DebugAgent.c
+++ b/SourceLevelDebugPkg/Library/DebugAgent/DebugAgentCommon/DebugAgent.c
@@ -2535,6 +2535,7 @@ InterruptProcess (
         CurrentDebugTimerInitCount = GetApicTimerInitCount ();
         if (mDebugMpContext.DebugTimerInitCount != CurrentDebugTimerInitCount) 
{
           InitializeDebugTimer (NULL, FALSE);
+          SaveAndSetDebugTimerInterrupt (TRUE);
         }
       }
 
diff --git 
a/SourceLevelDebugPkg/Library/DebugAgent/DebugAgentCommon/DebugTimer.c 
b/SourceLevelDebugPkg/Library/DebugAgent/DebugAgentCommon/DebugTimer.c
index 25d6468..4a6ccdb 100644
--- a/SourceLevelDebugPkg/Library/DebugAgent/DebugAgentCommon/DebugTimer.c
+++ b/SourceLevelDebugPkg/Library/DebugAgent/DebugAgentCommon/DebugTimer.c
@@ -46,6 +46,11 @@ InitializeDebugTimer (
                    );
 
   InitializeApicTimer (ApicTimerDivisor, InitialCount, TRUE, 
DEBUG_TIMER_VECTOR);
+  //
+  // Disable Debug Timer interrupt to avoid it is delivered before Debug Port
+  // is initialized
+  //
+  DisableApicTimerInterrupt ();
 
   if (DumpFlag) {
     DEBUG ((EFI_D_INFO, "Debug Timer: FSB Clock    = %d\n", 
PcdGet32(PcdFSBClock)));
diff --git 
a/SourceLevelDebugPkg/Library/DebugAgent/DxeDebugAgent/DxeDebugAgentLib.c 
b/SourceLevelDebugPkg/Library/DebugAgent/DxeDebugAgent/DxeDebugAgentLib.c
index aaf342e..56a5e1a 100644
--- a/SourceLevelDebugPkg/Library/DebugAgent/DxeDebugAgent/DxeDebugAgentLib.c
+++ b/SourceLevelDebugPkg/Library/DebugAgent/DxeDebugAgent/DxeDebugAgentLib.c
@@ -428,6 +428,10 @@ InitializeDebugAgent (
     //
     InternalConstructorWorker ();
     //
+    // Enable Debug Timer interrupt
+    //
+    SaveAndSetDebugTimerInterrupt (TRUE);
+    //
     // Enable interrupt to receive Debug Timer interrupt
     //
     EnableInterrupts ();
@@ -482,6 +486,10 @@ InitializeDebugAgent (
     //
     SetupDebugAgentEnvironment (Mailbox);
     //
+    // Enable Debug Timer interrupt
+    //
+    SaveAndSetDebugTimerInterrupt (TRUE);
+    //
     // Enable interrupt to receive Debug Timer interrupt
     //
     EnableInterrupts ();
diff --git 
a/SourceLevelDebugPkg/Library/DebugAgent/SecPeiDebugAgent/SecPeiDebugAgentLib.c 
b/SourceLevelDebugPkg/Library/DebugAgent/SecPeiDebugAgent/SecPeiDebugAgentLib.c
index 20b6a37..e77ff72 100644
--- 
a/SourceLevelDebugPkg/Library/DebugAgent/SecPeiDebugAgent/SecPeiDebugAgentLib.c
+++ 
b/SourceLevelDebugPkg/Library/DebugAgent/SecPeiDebugAgent/SecPeiDebugAgentLib.c
@@ -612,6 +612,10 @@ InitializeDebugAgent (
   }
 
   //
+  // Enable Debug Timer interrupt
+  //
+  SaveAndSetDebugTimerInterrupt (TRUE);
+  //
   // Enable CPU interrupts so debug timer interrupts can be delivered
   //
   EnableInterrupts ();
diff --git 
a/SourceLevelDebugPkg/Library/DebugAgent/SmmDebugAgent/SmmDebugAgentLib.c 
b/SourceLevelDebugPkg/Library/DebugAgent/SmmDebugAgent/SmmDebugAgentLib.c
index 4e4e1f5..6ac5f88 100644
--- a/SourceLevelDebugPkg/Library/DebugAgent/SmmDebugAgent/SmmDebugAgentLib.c
+++ b/SourceLevelDebugPkg/Library/DebugAgent/SmmDebugAgent/SmmDebugAgentLib.c
@@ -284,7 +284,6 @@ InitializeDebugAgent (
     TimerCycle = GetApicTimerInitCount ();
     if (!PeriodicMode || TimerCycle == 0) {
       InitializeDebugTimer (NULL, FALSE);
-      DisableApicTimerInterrupt ();
     }
     Mailbox = GetMailboxPointer ();
     if (GetDebugFlag (DEBUG_AGENT_FLAG_AGENT_IN_PROGRESS) == 1) {
@@ -350,6 +349,10 @@ InitializeDebugAgent (
       //
       InitializeDebugTimer (&DebugTimerFrequency, TRUE);
       UpdateMailboxContent (mMailboxPointer, 
DEBUG_MAILBOX_DEBUG_TIMER_FREQUENCY, DebugTimerFrequency);
+      //
+      // Enable Debug Timer interrupt and CPU interrupt
+      //
+      SaveAndSetDebugTimerInterrupt (TRUE);
       EnableInterrupts ();
 
       FindAndReportModuleImageInfo (SIZE_4KB);
-- 
1.9.5.msysgit.0


------------------------------------------------------------------------------
_______________________________________________
edk2-devel mailing list
edk2-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/edk2-devel

Reply via email to