]> git.proxmox.com Git - mirror_edk2.git/commitdiff
1. Add CPU arch type in Mailbox, debug agent will not access HOB if CPU arch changed.
authorvanjeff <vanjeff@6f19259b-4bc3-4df7-8a09-765794883524>
Sat, 20 Apr 2013 03:34:16 +0000 (03:34 +0000)
committervanjeff <vanjeff@6f19259b-4bc3-4df7-8a09-765794883524>
Sat, 20 Apr 2013 03:34:16 +0000 (03:34 +0000)
2. Updated DxeDebugAgentLib instance to copy DebugPortHandler buffer into allocated ACPIMemoryNVS besides the mailbox.
3. Remove deprecated SendingPacket from mailbox.

Signed-off-by: Jeff Fan <jeff.fan@intel.com>
Reviewed-by: Ruiyu Ni <ruiyu.ni@intel.com>
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@14302 6f19259b-4bc3-4df7-8a09-765794883524

SourceLevelDebugPkg/Library/DebugAgent/DebugAgentCommon/DebugAgent.h
SourceLevelDebugPkg/Library/DebugAgent/DxeDebugAgent/DxeDebugAgentLib.c
SourceLevelDebugPkg/Library/DebugAgent/DxeDebugAgentLib.inf
SourceLevelDebugPkg/Library/DebugAgent/SecPeiDebugAgent/SecPeiDebugAgentLib.c

index 5eb50d038c0433e5ff049f973d252f42d00c1411..748d562a59f37f33a5ad4d2573da634a2b7072cb 100644 (file)
@@ -89,6 +89,7 @@ typedef struct {
 #define DEBUG_AGENT_FLAG_MEMORY_READY          BIT2\r
 #define DEBUG_AGENT_FLAG_STEPPING              BIT3\r
 #define DEBUG_AGENT_FLAG_CHECK_MAILBOX_IN_HOB  BIT4\r
+#define DEBUG_AGENT_FLAG_INIT_ARCH             BIT5|BIT6\r
 #define DEBUG_AGENT_FLAG_BREAK_ON_NEXT_SMI     BIT32\r
 #define DEBUG_AGENT_FLAG_PRINT_ERROR_LEVEL     (BIT33|BIT34|BIT35|BIT36)\r
 #define DEBUG_AGENT_FLAG_BREAK_BOOT_SCRIPT     BIT37\r
@@ -111,8 +112,8 @@ typedef union {
     UINT32  MemoryReady       : 1;   // 1: Memory is ready\r
     UINT32  SteppingFlag      : 1;   // 1: Agent is running stepping command\r
     UINT32  CheckMailboxInHob : 1;   // 1: Need to check mailbox saved in HOB\r
-    UINT32  SendingPacket     : 1;   // 1: TARGET is sending debug packet to HOST\r
-    UINT32  Reserved1         : 26;\r
+    UINT32  InitArch          : 2;   // value of DEBUG_DATA_RESPONSE_ARCH_MODE\r
+    UINT32  Reserved1         : 25;\r
     //\r
     // Higher 32bits to control the behavior of DebugAgent\r
     //\r
index 35c6acfd9da5e3c359f07d79f972c5948d2bac9c..d560b5235993e18a9070a910816537ac09fccc64 100644 (file)
@@ -55,6 +55,8 @@ InternalConstructorWorker (
   EFI_STATUS                  Status;\r
   EFI_PHYSICAL_ADDRESS        Address;\r
   BOOLEAN                     DebugTimerInterruptState;\r
+  DEBUG_AGENT_MAILBOX         *Mailbox;\r
+  DEBUG_AGENT_MAILBOX         *NewMailbox;\r
 \r
   //\r
   // Install EFI Serial IO protocol on debug port\r
@@ -65,20 +67,28 @@ InternalConstructorWorker (
   Status = gBS->AllocatePages (\r
                   AllocateAnyPages,\r
                   EfiACPIMemoryNVS,\r
-                  EFI_SIZE_TO_PAGES (sizeof (DEBUG_AGENT_MAILBOX)),\r
+                  EFI_SIZE_TO_PAGES (sizeof(DEBUG_AGENT_MAILBOX) + PcdGet16(PcdDebugPortHandleBufferSize)),\r
                   &Address\r
                   );\r
   ASSERT_EFI_ERROR (Status);\r
 \r
   DebugTimerInterruptState = SaveAndSetDebugTimerInterrupt (FALSE);\r
-  CopyMem (\r
-    (UINT8 *) (UINTN) Address,\r
-    (UINT8 *) (UINTN) GetMailboxPointer (),\r
-    sizeof (DEBUG_AGENT_MAILBOX)\r
-    );\r
-  DebugTimerInterruptState = SaveAndSetDebugTimerInterrupt (DebugTimerInterruptState);\r
 \r
-  mMailboxPointer = (DEBUG_AGENT_MAILBOX *) (UINTN) Address;\r
+  NewMailbox = (DEBUG_AGENT_MAILBOX *) (UINTN) Address;\r
+  //\r
+  // Copy Mailbox and Debug Port Handle buffer to new location in ACPI NVS memory, because original Mailbox\r
+  // and Debug Port Handle buffer may be free at runtime, SMM debug agent needs to access them\r
+  //\r
+  Mailbox = GetMailboxPointer ();\r
+  CopyMem (NewMailbox, Mailbox, sizeof (DEBUG_AGENT_MAILBOX));\r
+  CopyMem (NewMailbox + 1, (VOID *)(UINTN)Mailbox->DebugPortHandle, PcdGet16(PcdDebugPortHandleBufferSize));\r
+  //\r
+  // Update Debug Port Handle in new Mailbox\r
+  //\r
+  UpdateMailboxContent (NewMailbox, DEBUG_MAILBOX_DEBUG_PORT_HANDLE_INDEX, (UINT64)(UINTN)(NewMailbox + 1));\r
+  mMailboxPointer = NewMailbox;\r
+\r
+  DebugTimerInterruptState = SaveAndSetDebugTimerInterrupt (DebugTimerInterruptState);\r
 \r
   Status = gBS->InstallConfigurationTable (&gEfiDebugAgentGuid, (VOID *) mMailboxPointer);\r
   ASSERT_EFI_ERROR (Status);\r
index f73385ce714134863d2252d0a1bc85c4b1cb5c04..cc9b48191daadcf3f2a25220f2012efbc1c0028a 100644 (file)
@@ -90,4 +90,5 @@
 [Pcd]\r
   gEfiMdePkgTokenSpaceGuid.PcdFSBClock                                  ## CONSUMES\r
   gEfiSourceLevelDebugPkgTokenSpaceGuid.PcdExceptionsIgnoredByDebugger  ## CONSUMES\r
+  gEfiSourceLevelDebugPkgTokenSpaceGuid.PcdDebugPortHandleBufferSize    ## CONSUMES\r
 \r
index 828407304f2c090df8c54fab2ae66f8896aaefe7..0132942dea6b7e6cbb9f1fdce727de3c09b0e273 100644 (file)
@@ -174,19 +174,22 @@ GetMailboxPointer (
   MailboxLocationInIdt = GetLocationSavedMailboxPointerInIdtEntry ();\r
   Mailbox = (DEBUG_AGENT_MAILBOX *)(UINTN)(*MailboxLocationInIdt);\r
   //\r
-  // Check if mailbox was setup in PEI firstly, cannot used GetDebugFlag() to \r
-  // get CheckMailboxInHob flag to avoid GetMailboxPointer() nesting.\r
+  // Cannot used GetDebugFlag() to get Debug Flag to avoid GetMailboxPointer() nested\r
   //\r
-  if (Mailbox->DebugFlag.Bits.CheckMailboxInHob != 1) {\r
-    //\r
-    // If mailbox in IDT entry has already been the final one\r
+  if (Mailbox->DebugFlag.Bits.CheckMailboxInHob != 1 ||\r
+      Mailbox->DebugFlag.Bits.InitArch != DEBUG_ARCH_SYMBOL) {\r
     //\r
+    // If mailbox was setup in SEC or the current CPU arch is different from the init arch\r
+    // Debug Agent initialized, return the mailbox from IDT entry directly.\r
+    // Otherwise, we need to check the mailbox location saved in GUIDed HOB further.\r
+    // \r
     return Mailbox;\r
   }\r
 \r
   MailboxLocationInHob = GetMailboxLocationFromHob ();\r
   //\r
-  // Compare mailbox in IDT enry with mailbox in HOB\r
+  // Compare mailbox in IDT enry with mailbox in HOB,\r
+  // need to fix mailbox location if HOB moved by PEI CORE\r
   //\r
   if (MailboxLocationInHob != MailboxLocationInIdt && MailboxLocationInHob != NULL) {\r
     Mailbox = (DEBUG_AGENT_MAILBOX *)(UINTN)(*MailboxLocationInHob);\r
@@ -247,7 +250,7 @@ DebugAgentCallbackMemoryDiscoveredPpi (
   EFI_STATUS                     Status;\r
   DEBUG_AGENT_MAILBOX            *Mailbox;\r
   BOOLEAN                        InterruptStatus;\r
-  EFI_PHYSICAL_ADDRESS           Memory\r
+  EFI_PHYSICAL_ADDRESS           Address\r
   DEBUG_AGENT_MAILBOX            *NewMailbox;\r
   UINT64                         *MailboxLocationInHob;\r
 \r
@@ -262,10 +265,10 @@ DebugAgentCallbackMemoryDiscoveredPpi (
   Status = PeiServicesAllocatePages (\r
              EfiACPIMemoryNVS,\r
              EFI_SIZE_TO_PAGES (sizeof(DEBUG_AGENT_MAILBOX) + PcdGet16(PcdDebugPortHandleBufferSize)),\r
-             &Memory\r
+             &Address\r
              );\r
   ASSERT_EFI_ERROR (Status);\r
-  NewMailbox = (DEBUG_AGENT_MAILBOX *) (UINTN) Memory;\r
+  NewMailbox = (DEBUG_AGENT_MAILBOX *) (UINTN) Address;\r
   //\r
   // Copy Mailbox and Debug Port Handle buffer to new location in ACPI NVS memory, because original Mailbox\r
   // and Debug Port Handle buffer in the allocated pool that may be marked as free by DXE Core after DXE Core\r
@@ -369,7 +372,14 @@ InitializeDebugAgent (
     // Get and save debug port handle and set the length of memory block.\r
     //\r
     SetLocationSavedMailboxPointerInIdtEntry (&MailboxLocation);\r
+    //\r
+    // Force error message could be printed during the first shakehand between Target/HOST.\r
+    //\r
     SetDebugFlag (DEBUG_AGENT_FLAG_PRINT_ERROR_LEVEL, DEBUG_AGENT_ERROR);\r
+    //\r
+    // Save init arch type when debug agent initialized\r
+    //\r
+    SetDebugFlag (DEBUG_AGENT_FLAG_INIT_ARCH, sizeof (UINTN) / 4);\r
 \r
     InitializeDebugTimer ();\r
 \r
@@ -453,6 +463,10 @@ InitializeDebugAgent (
     //\r
     SetLocationSavedMailboxPointerInIdtEntry (MailboxLocationPointer);\r
     //\r
+    // Save init arch type when debug agent initialized\r
+    //\r
+    SetDebugFlag (DEBUG_AGENT_FLAG_INIT_ARCH, DEBUG_ARCH_SYMBOL);\r
+    //\r
     // Register for a callback once memory has been initialized.\r
     // If memery has been ready, the callback funtion will be invoked immediately\r
     //\r
@@ -483,6 +497,9 @@ InitializeDebugAgent (
       MailboxLocationPointer = (UINT64 *) (UINTN) (Ia32IdtEntry[DEBUG_MAILBOX_VECTOR].Bits.OffsetLow +\r
                                                 (Ia32IdtEntry[DEBUG_MAILBOX_VECTOR].Bits.OffsetHigh << 16));\r
       Mailbox = (DEBUG_AGENT_MAILBOX *) (UINTN)(*MailboxLocationPointer);\r
+      //\r
+      // Mailbox should valid and setup before executing thunk code\r
+      //\r
       VerifyMailboxChecksum (Mailbox);\r
 \r
       DebugPortHandle = (UINT64) (UINTN)DebugPortInitialize ((VOID *)(UINTN)Mailbox->DebugPortHandle, NULL);\r
@@ -508,7 +525,6 @@ InitializeDebugAgent (
     DEBUG ((EFI_D_ERROR, "Debug Agent: The InitFlag value is not allowed!\n"));\r
     CpuDeadLoop ();\r
     break;\r
-\r
   }\r
 \r
   EnableInterrupts ();\r