Revision: 14304
          http://edk2.svn.sourceforge.net/edk2/?rev=14304&view=rev
Author:   vanjeff
Date:     2013-04-20 04:32:58 +0000 (Sat, 20 Apr 2013)
Log Message:
-----------
Sync patches r14285, r14302 and r14303 from main trunk.
1. Allocate ACPImemoryNVS type memory to save mailbox and debug port handle 
buffer since original allocated pool memory may be marked as free by DXE Core.
2. Add CPU arch type in Mailbox, debug agent will not access HOB if CPU arch 
changed.
3. Updated DxeDebugAgentLib instance to copy DebugPortHandler buffer into 
allocated ACPIMemoryNVS besides the mailbox.
4. Remove deprecated SendingPacket from mailbox.

Revision Links:
--------------
    http://edk2.svn.sourceforge.net/edk2/?rev=14285&view=rev
    http://edk2.svn.sourceforge.net/edk2/?rev=14302&view=rev
    http://edk2.svn.sourceforge.net/edk2/?rev=14303&view=rev

Modified Paths:
--------------
    
branches/UDK2010.SR1/SourceLevelDebugPkg/Library/DebugAgent/DebugAgentCommon/DebugAgent.h
    
branches/UDK2010.SR1/SourceLevelDebugPkg/Library/DebugAgent/DxeDebugAgent/DxeDebugAgentLib.c
    
branches/UDK2010.SR1/SourceLevelDebugPkg/Library/DebugAgent/DxeDebugAgentLib.inf
    
branches/UDK2010.SR1/SourceLevelDebugPkg/Library/DebugAgent/SecPeiDebugAgent/SecPeiDebugAgentLib.c

Modified: 
branches/UDK2010.SR1/SourceLevelDebugPkg/Library/DebugAgent/DebugAgentCommon/DebugAgent.h
===================================================================
--- 
branches/UDK2010.SR1/SourceLevelDebugPkg/Library/DebugAgent/DebugAgentCommon/DebugAgent.h
   2013-04-20 04:25:58 UTC (rev 14303)
+++ 
branches/UDK2010.SR1/SourceLevelDebugPkg/Library/DebugAgent/DebugAgentCommon/DebugAgent.h
   2013-04-20 04:32:58 UTC (rev 14304)
@@ -89,6 +89,7 @@
 #define DEBUG_AGENT_FLAG_MEMORY_READY          BIT2
 #define DEBUG_AGENT_FLAG_STEPPING              BIT3
 #define DEBUG_AGENT_FLAG_CHECK_MAILBOX_IN_HOB  BIT4
+#define DEBUG_AGENT_FLAG_INIT_ARCH             BIT5|BIT6
 #define DEBUG_AGENT_FLAG_BREAK_ON_NEXT_SMI     BIT32
 #define DEBUG_AGENT_FLAG_PRINT_ERROR_LEVEL     (BIT33|BIT34|BIT35|BIT36)
 #define DEBUG_AGENT_FLAG_BREAK_BOOT_SCRIPT     BIT37
@@ -111,8 +112,8 @@
     UINT32  MemoryReady       : 1;   // 1: Memory is ready
     UINT32  SteppingFlag      : 1;   // 1: Agent is running stepping command
     UINT32  CheckMailboxInHob : 1;   // 1: Need to check mailbox saved in HOB
-    UINT32  SendingPacket     : 1;   // 1: TARGET is sending debug packet to 
HOST
-    UINT32  Reserved1         : 26;
+    UINT32  InitArch          : 2;   // value of DEBUG_DATA_RESPONSE_ARCH_MODE
+    UINT32  Reserved1         : 25;
     //
     // Higher 32bits to control the behavior of DebugAgent
     //

Modified: 
branches/UDK2010.SR1/SourceLevelDebugPkg/Library/DebugAgent/DxeDebugAgent/DxeDebugAgentLib.c
===================================================================
--- 
branches/UDK2010.SR1/SourceLevelDebugPkg/Library/DebugAgent/DxeDebugAgent/DxeDebugAgentLib.c
        2013-04-20 04:25:58 UTC (rev 14303)
+++ 
branches/UDK2010.SR1/SourceLevelDebugPkg/Library/DebugAgent/DxeDebugAgent/DxeDebugAgentLib.c
        2013-04-20 04:32:58 UTC (rev 14304)
@@ -55,6 +55,8 @@
   EFI_STATUS                  Status;
   EFI_PHYSICAL_ADDRESS        Address;
   BOOLEAN                     DebugTimerInterruptState;
+  DEBUG_AGENT_MAILBOX         *Mailbox;
+  DEBUG_AGENT_MAILBOX         *NewMailbox;
 
   //
   // Install EFI Serial IO protocol on debug port
@@ -65,21 +67,29 @@
   Status = gBS->AllocatePages (
                   AllocateAnyPages,
                   EfiACPIMemoryNVS,
-                  EFI_SIZE_TO_PAGES (sizeof (DEBUG_AGENT_MAILBOX)),
+                  EFI_SIZE_TO_PAGES (sizeof(DEBUG_AGENT_MAILBOX) + 
PcdGet16(PcdDebugPortHandleBufferSize)),
                   &Address
                   );
   ASSERT_EFI_ERROR (Status);
 
   DebugTimerInterruptState = SaveAndSetDebugTimerInterrupt (FALSE);
-  CopyMem (
-    (UINT8 *) (UINTN) Address,
-    (UINT8 *) (UINTN) GetMailboxPointer (),
-    sizeof (DEBUG_AGENT_MAILBOX)
-    );
+
+  NewMailbox = (DEBUG_AGENT_MAILBOX *) (UINTN) Address;
+  //
+  // Copy Mailbox and Debug Port Handle buffer to new location in ACPI NVS 
memory, because original Mailbox
+  // and Debug Port Handle buffer may be free at runtime, SMM debug agent 
needs to access them
+  //
+  Mailbox = GetMailboxPointer ();
+  CopyMem (NewMailbox, Mailbox, sizeof (DEBUG_AGENT_MAILBOX));
+  CopyMem (NewMailbox + 1, (VOID *)(UINTN)Mailbox->DebugPortHandle, 
PcdGet16(PcdDebugPortHandleBufferSize));
+  //
+  // Update Debug Port Handle in new Mailbox
+  //
+  UpdateMailboxContent (NewMailbox, DEBUG_MAILBOX_DEBUG_PORT_HANDLE_INDEX, 
(UINT64)(UINTN)(NewMailbox + 1));
+  mMailboxPointer = NewMailbox;
+
   DebugTimerInterruptState = SaveAndSetDebugTimerInterrupt 
(DebugTimerInterruptState);
 
-  mMailboxPointer = (DEBUG_AGENT_MAILBOX *) (UINTN) Address;
-
   Status = gBS->InstallConfigurationTable (&gEfiDebugAgentGuid, (VOID *) 
mMailboxPointer);
   ASSERT_EFI_ERROR (Status);
 }

Modified: 
branches/UDK2010.SR1/SourceLevelDebugPkg/Library/DebugAgent/DxeDebugAgentLib.inf
===================================================================
--- 
branches/UDK2010.SR1/SourceLevelDebugPkg/Library/DebugAgent/DxeDebugAgentLib.inf
    2013-04-20 04:25:58 UTC (rev 14303)
+++ 
branches/UDK2010.SR1/SourceLevelDebugPkg/Library/DebugAgent/DxeDebugAgentLib.inf
    2013-04-20 04:32:58 UTC (rev 14304)
@@ -90,4 +90,5 @@
 [Pcd]
   gEfiMdePkgTokenSpaceGuid.PcdFSBClock                                  ## 
CONSUMES
   gEfiSourceLevelDebugPkgTokenSpaceGuid.PcdExceptionsIgnoredByDebugger  ## 
CONSUMES
+  gEfiSourceLevelDebugPkgTokenSpaceGuid.PcdDebugPortHandleBufferSize    ## 
CONSUMES
 

Modified: 
branches/UDK2010.SR1/SourceLevelDebugPkg/Library/DebugAgent/SecPeiDebugAgent/SecPeiDebugAgentLib.c
===================================================================
--- 
branches/UDK2010.SR1/SourceLevelDebugPkg/Library/DebugAgent/SecPeiDebugAgent/SecPeiDebugAgentLib.c
  2013-04-20 04:25:58 UTC (rev 14303)
+++ 
branches/UDK2010.SR1/SourceLevelDebugPkg/Library/DebugAgent/SecPeiDebugAgent/SecPeiDebugAgentLib.c
  2013-04-20 04:32:58 UTC (rev 14304)
@@ -174,19 +174,22 @@
   MailboxLocationInIdt = GetLocationSavedMailboxPointerInIdtEntry ();
   Mailbox = (DEBUG_AGENT_MAILBOX *)(UINTN)(*MailboxLocationInIdt);
   //
-  // Check if mailbox was setup in PEI firstly, cannot used GetDebugFlag() to 
-  // get CheckMailboxInHob flag to avoid GetMailboxPointer() nesting.
+  // Cannot used GetDebugFlag() to get Debug Flag to avoid GetMailboxPointer() 
nested
   //
-  if (Mailbox->DebugFlag.Bits.CheckMailboxInHob != 1) {
+  if (Mailbox->DebugFlag.Bits.CheckMailboxInHob != 1 ||
+      Mailbox->DebugFlag.Bits.InitArch != DEBUG_ARCH_SYMBOL) {
     //
-    // If mailbox in IDT entry has already been the final one
-    //
+    // If mailbox was setup in SEC or the current CPU arch is different from 
the init arch
+    // Debug Agent initialized, return the mailbox from IDT entry directly.
+    // Otherwise, we need to check the mailbox location saved in GUIDed HOB 
further.
+    // 
     return Mailbox;
   }
 
   MailboxLocationInHob = GetMailboxLocationFromHob ();
   //
-  // Compare mailbox in IDT enry with mailbox in HOB
+  // Compare mailbox in IDT enry with mailbox in HOB,
+  // need to fix mailbox location if HOB moved by PEI CORE
   //
   if (MailboxLocationInHob != MailboxLocationInIdt && MailboxLocationInHob != 
NULL) {
     Mailbox = (DEBUG_AGENT_MAILBOX *)(UINTN)(*MailboxLocationInHob);
@@ -244,23 +247,51 @@
   IN VOID                                 *Ppi
   )
 {
+  EFI_STATUS                     Status;
   DEBUG_AGENT_MAILBOX            *Mailbox;
   BOOLEAN                        InterruptStatus;
-  
+  EFI_PHYSICAL_ADDRESS           Address; 
+  DEBUG_AGENT_MAILBOX            *NewMailbox;
+  UINT64                         *MailboxLocationInHob;
+
   //
   // Save and disable original interrupt status
   //
   InterruptStatus = SaveAndDisableInterrupts ();
-  
+
   //
+  // Allocate ACPI NVS memory for new Mailbox and Debug Port Handle buffer
+  //
+  Status = PeiServicesAllocatePages (
+             EfiACPIMemoryNVS,
+             EFI_SIZE_TO_PAGES (sizeof(DEBUG_AGENT_MAILBOX) + 
PcdGet16(PcdDebugPortHandleBufferSize)),
+             &Address
+             );
+  ASSERT_EFI_ERROR (Status);
+  NewMailbox = (DEBUG_AGENT_MAILBOX *) (UINTN) Address;
+  //
+  // Copy Mailbox and Debug Port Handle buffer to new location in ACPI NVS 
memory, because original Mailbox
+  // and Debug Port Handle buffer in the allocated pool that may be marked as 
free by DXE Core after DXE Core
+  // reallocates the HOB.
+  //
+  Mailbox = GetMailboxPointer ();
+  CopyMem (NewMailbox, Mailbox, sizeof (DEBUG_AGENT_MAILBOX));
+  CopyMem (NewMailbox + 1, (VOID *)(UINTN)Mailbox->DebugPortHandle, 
PcdGet16(PcdDebugPortHandleBufferSize));
+  //
+  // Update Mailbox Location pointer in GUIDed HOB and IDT entry with new one
+  //
+  MailboxLocationInHob = GetMailboxLocationFromHob ();
+  *MailboxLocationInHob = (UINT64)(UINTN)NewMailbox;
+  SetLocationSavedMailboxPointerInIdtEntry (MailboxLocationInHob);
+  //
+  // Update Debug Port Handle in new Mailbox
+  //
+  UpdateMailboxContent (NewMailbox, DEBUG_MAILBOX_DEBUG_PORT_HANDLE_INDEX, 
(UINT64)(UINTN)(NewMailbox + 1));
+  //
   // Set physical memory ready flag
   //
-  Mailbox = GetMailboxPointer ();
   SetDebugFlag (DEBUG_AGENT_FLAG_MEMORY_READY, 1);
 
-  //
-  // Memory has been ready
-  //
   if (IsHostAttached ()) {
     //
     // Trigger one software interrupt to inform HOST
@@ -341,7 +372,14 @@
     // Get and save debug port handle and set the length of memory block.
     //
     SetLocationSavedMailboxPointerInIdtEntry (&MailboxLocation);
+    //
+    // Force error message could be printed during the first shakehand between 
Target/HOST.
+    //
     SetDebugFlag (DEBUG_AGENT_FLAG_PRINT_ERROR_LEVEL, DEBUG_AGENT_ERROR);
+    //
+    // Save init arch type when debug agent initialized
+    //
+    SetDebugFlag (DEBUG_AGENT_FLAG_INIT_ARCH, DEBUG_ARCH_SYMBOL);
 
     InitializeDebugTimer ();
 
@@ -425,6 +463,10 @@
     //
     SetLocationSavedMailboxPointerInIdtEntry (MailboxLocationPointer);
     //
+    // Save init arch type when debug agent initialized
+    //
+    SetDebugFlag (DEBUG_AGENT_FLAG_INIT_ARCH, DEBUG_ARCH_SYMBOL);
+    //
     // Register for a callback once memory has been initialized.
     // If memery has been ready, the callback funtion will be invoked 
immediately
     //
@@ -455,6 +497,9 @@
       MailboxLocationPointer = (UINT64 *) (UINTN) 
(Ia32IdtEntry[DEBUG_MAILBOX_VECTOR].Bits.OffsetLow +
                                                 
(Ia32IdtEntry[DEBUG_MAILBOX_VECTOR].Bits.OffsetHigh << 16));
       Mailbox = (DEBUG_AGENT_MAILBOX *) (UINTN)(*MailboxLocationPointer);
+      //
+      // Mailbox should valid and setup before executing thunk code
+      //
       VerifyMailboxChecksum (Mailbox);
 
       DebugPortHandle = (UINT64) (UINTN)DebugPortInitialize ((VOID 
*)(UINTN)Mailbox->DebugPortHandle, NULL);
@@ -480,7 +525,6 @@
     DEBUG ((EFI_D_ERROR, "Debug Agent: The InitFlag value is not allowed!\n"));
     CpuDeadLoop ();
     break;
-
   }
 
   EnableInterrupts ();

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.


------------------------------------------------------------------------------
Precog is a next-generation analytics platform capable of advanced
analytics on semi-structured data. The platform includes APIs for building
apps and a phenomenal toolset for data science. Developers can use
our toolset for easy data analysis & visualization. Get a free account!
http://www2.precog.com/precogplatform/slashdotnewsletter
_______________________________________________
edk2-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/edk2-commits

Reply via email to