]> git.proxmox.com Git - mirror_edk2.git/blobdiff - SourceLevelDebugPkg/Library/DebugAgent/SecPeiDebugAgent/SecPeiDebugAgentLib.c
SourceLevelDebugPkg: Fix typos in comments
[mirror_edk2.git] / SourceLevelDebugPkg / Library / DebugAgent / SecPeiDebugAgent / SecPeiDebugAgentLib.c
index 0388807697081ceab0e228beaad0866727810694..128c69f60cb24901724c6b642a1cb46b90047e98 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   SEC Core Debug Agent Library instance implementition.\r
 \r
-  Copyright (c) 2010 - 2013, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2010 - 2015, Intel Corporation. All rights reserved.<BR>\r
   This program and the accompanying materials\r
   are licensed and made available under the terms and conditions of the BSD License\r
   which accompanies this distribution.  The full text of the license may be found at\r
 \r
 #include "SecPeiDebugAgentLib.h"\r
 \r
-BOOLEAN  mSkipBreakpoint = FALSE;\r
+GLOBAL_REMOVE_IF_UNREFERENCED BOOLEAN  mSkipBreakpoint = FALSE;\r
 \r
 \r
-EFI_PEI_VECTOR_HANDOFF_INFO_PPI mVectorHandoffInfoPpi = {\r
+GLOBAL_REMOVE_IF_UNREFERENCED EFI_PEI_VECTOR_HANDOFF_INFO_PPI mVectorHandoffInfoPpi = {\r
   &mVectorHandoffInfoDebugAgent[0]\r
 };\r
 \r
 //\r
 // Ppis to be installed\r
 //\r
-EFI_PEI_PPI_DESCRIPTOR           mVectorHandoffInfoPpiList[] = { \r
+GLOBAL_REMOVE_IF_UNREFERENCED EFI_PEI_PPI_DESCRIPTOR           mVectorHandoffInfoPpiList[] = {\r
   {\r
     (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),\r
     &gEfiVectorHandoffInfoPpiGuid,\r
@@ -32,7 +32,7 @@ EFI_PEI_PPI_DESCRIPTOR           mVectorHandoffInfoPpiList[] = {
   }\r
 };\r
 \r
-EFI_PEI_NOTIFY_DESCRIPTOR mMemoryDiscoveredNotifyList[1] = {\r
+GLOBAL_REMOVE_IF_UNREFERENCED EFI_PEI_NOTIFY_DESCRIPTOR mMemoryDiscoveredNotifyList[1] = {\r
   {\r
     (EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),\r
     &gEfiPeiMemoryDiscoveredPpiGuid,\r
@@ -93,12 +93,12 @@ DebugReadBreakSymbol (
     //\r
     // Try to read the start symbol\r
     //\r
-    DebugPortReadBuffer (Handle, Data8, 1, 0);\r
+    DebugAgentReadBuffer (Handle, Data8, 1, 0);\r
     if (*Data8 == DEBUG_STARTING_SYMBOL_ATTACH) {\r
       *BreakSymbol = *Data8;\r
       DebugAgentMsgPrint (DEBUG_AGENT_INFO, "Debug Timer attach symbol received %x", *BreakSymbol);\r
       return EFI_SUCCESS;\r
-    } \r
+    }\r
     if (*Data8 == DEBUG_STARTING_SYMBOL_NORMAL) {\r
       Status = ReadRemainingBreakPacket (Handle, &DebugHeader);\r
       if (Status == EFI_SUCCESS) {\r
@@ -111,7 +111,7 @@ DebugReadBreakSymbol (
       }\r
     }\r
   }\r
-  \r
+\r
   return EFI_NOT_FOUND;\r
 }\r
 \r
@@ -183,7 +183,7 @@ GetMailboxPointer (
   UINT64               *MailboxLocationInIdt;\r
   UINT64               *MailboxLocationInHob;\r
   DEBUG_AGENT_MAILBOX  *Mailbox;\r
-  \r
+\r
   //\r
   // Get mailbox from IDT entry firstly\r
   //\r
@@ -198,7 +198,7 @@ GetMailboxPointer (
     // 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
+    //\r
     return Mailbox;\r
   }\r
 \r
@@ -239,7 +239,7 @@ GetDebugPortHandle (
   )\r
 {\r
   DEBUG_AGENT_MAILBOX    *DebugAgentMailbox;\r
-  \r
+\r
   DebugAgentMailbox = GetMailboxPointer ();\r
 \r
   return (DEBUG_PORT_HANDLE) (UINTN)(DebugAgentMailbox->DebugPortHandle);\r
@@ -266,7 +266,7 @@ DebugAgentCallbackMemoryDiscoveredPpi (
   EFI_STATUS                     Status;\r
   DEBUG_AGENT_MAILBOX            *Mailbox;\r
   BOOLEAN                        InterruptStatus;\r
-  EFI_PHYSICAL_ADDRESS           Address; \r
+  EFI_PHYSICAL_ADDRESS           Address;\r
   DEBUG_AGENT_MAILBOX            *NewMailbox;\r
   UINT64                         *MailboxLocationInHob;\r
 \r
@@ -320,7 +320,7 @@ DebugAgentCallbackMemoryDiscoveredPpi (
   // Restore interrupt state.\r
   //\r
   SetInterruptState (InterruptStatus);\r
-  \r
+\r
   return EFI_SUCCESS;\r
 }\r
 \r
@@ -343,7 +343,7 @@ DebugAgentCallbackMemoryDiscoveredPpi (
   function and pass it into InitializeDebugAgent(). InitializeDebugAgent() is\r
   responsible to invoke the passing-in function at the end of InitializeDebugAgent().\r
 \r
-  If the parameter Function is not NULL, Debug Agent Libary instance will invoke it by\r
+  If the parameter Function is not NULL, Debug Agent Library instance will invoke it by\r
   passing in the Context to be its parameter.\r
 \r
   If Function() is NULL, Debug Agent Library instance will return after setup debug\r
@@ -374,9 +374,14 @@ InitializeDebugAgent (
   UINT64                           DebugPortHandle;\r
   UINT64                           MailboxLocation;\r
   UINT64                           *MailboxLocationPointer;\r
-  EFI_PHYSICAL_ADDRESS             Address; \r
-  \r
-  DisableInterrupts ();\r
+  EFI_PHYSICAL_ADDRESS             Address;\r
+  UINT32                           DebugTimerFrequency;\r
+  BOOLEAN                          CpuInterruptState;\r
+\r
+  //\r
+  // Disable interrupts and save current interrupt state\r
+  //\r
+  CpuInterruptState = SaveAndDisableInterrupts();\r
 \r
   switch (InitFlag) {\r
 \r
@@ -399,9 +404,13 @@ InitializeDebugAgent (
     // Save init arch type when debug agent initialized\r
     //\r
     SetDebugFlag (DEBUG_AGENT_FLAG_INIT_ARCH, DEBUG_ARCH_SYMBOL);\r
+    //\r
+    // Initialize Debug Timer hardware and save its frequency\r
+    //\r
+    InitializeDebugTimer (&DebugTimerFrequency, TRUE);\r
+    UpdateMailboxContent (Mailbox, DEBUG_MAILBOX_DEBUG_TIMER_FREQUENCY, DebugTimerFrequency);\r
 \r
-    InitializeDebugTimer ();\r
-\r
+    Phase2Context.InitFlag = InitFlag;\r
     Phase2Context.Context  = Context;\r
     Phase2Context.Function = Function;\r
     DebugPortInitialize ((VOID *) &Phase2Context, InitializeDebugAgentPhase2);\r
@@ -487,14 +496,13 @@ InitializeDebugAgent (
     // Update IDT entry to save the location saved mailbox pointer\r
     //\r
     SetLocationSavedMailboxPointerInIdtEntry (MailboxLocationPointer);\r
-    //\r
-    // Enable CPU interrupts so debug timer interrupts can be delivered\r
-    //\r
-    EnableInterrupts ();\r
-\r
     break;\r
 \r
   case DEBUG_AGENT_INIT_PEI:\r
+    if (Context == NULL) {\r
+      DEBUG ((EFI_D_ERROR, "DebugAgent: Input parameter Context cannot be NULL!\n"));\r
+      CpuDeadLoop ();\r
+    }\r
     //\r
     // Check if Debug Agent has initialized before\r
     //\r
@@ -518,18 +526,26 @@ InitializeDebugAgent (
     // Build mailbox in HOB and setup Mailbox Set In Pei flag\r
     //\r
     Mailbox = AllocateZeroPool (sizeof (DEBUG_AGENT_MAILBOX));\r
-    MailboxLocation = (UINT64)(UINTN)Mailbox;\r
-    MailboxLocationPointer = BuildGuidDataHob (\r
-                               &gEfiDebugAgentGuid,\r
-                               &MailboxLocation,\r
-                               sizeof (UINT64)\r
-                               );\r
-\r
-    InitializeDebugTimer ();\r
-    //\r
-    // Update IDT entry to save the location pointer saved mailbox pointer\r
-    //\r
-    SetLocationSavedMailboxPointerInIdtEntry (MailboxLocationPointer);\r
+    if (Mailbox == NULL) {\r
+      DEBUG ((EFI_D_ERROR, "DebugAgent: Failed to allocate memory!\n"));\r
+      CpuDeadLoop ();\r
+    } else {\r
+      MailboxLocation = (UINT64)(UINTN)Mailbox;\r
+      MailboxLocationPointer = BuildGuidDataHob (\r
+                                 &gEfiDebugAgentGuid,\r
+                                 &MailboxLocation,\r
+                                 sizeof (UINT64)\r
+                                 );\r
+      //\r
+      // Initialize Debug Timer hardware and save its frequency\r
+      //\r
+      InitializeDebugTimer (&DebugTimerFrequency, TRUE);\r
+      UpdateMailboxContent (Mailbox, DEBUG_MAILBOX_DEBUG_TIMER_FREQUENCY, DebugTimerFrequency);\r
+      //\r
+      // Update IDT entry to save the location pointer saved mailbox pointer\r
+      //\r
+      SetLocationSavedMailboxPointerInIdtEntry (MailboxLocationPointer);\r
+    }\r
     //\r
     // Save init arch type when debug agent initialized\r
     //\r
@@ -550,6 +566,7 @@ InitializeDebugAgent (
       SetDebugFlag (DEBUG_AGENT_FLAG_CHECK_MAILBOX_IN_HOB, 1);\r
     }\r
 \r
+    Phase2Context.InitFlag = InitFlag;\r
     Phase2Context.Context  = Context;\r
     Phase2Context.Function = Function;\r
     DebugPortInitialize ((VOID *) &Phase2Context, InitializeDebugAgentPhase2);\r
@@ -566,7 +583,7 @@ InitializeDebugAgent (
       Ia32Idtr =  (IA32_DESCRIPTOR *) Context;\r
       Ia32IdtEntry = (IA32_IDT_ENTRY *)(Ia32Idtr->Base);\r
       MailboxLocationPointer = (UINT64 *) (UINTN) (Ia32IdtEntry[DEBUG_MAILBOX_VECTOR].Bits.OffsetLow +\r
-                                                (Ia32IdtEntry[DEBUG_MAILBOX_VECTOR].Bits.OffsetHigh << 16));\r
+                                         (UINT32) (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
@@ -590,7 +607,7 @@ InitializeDebugAgent (
 \r
   default:\r
     //\r
-    // Only DEBUG_AGENT_INIT_PREMEM_SEC and DEBUG_AGENT_INIT_POSTMEM_SEC are allowed for this \r
+    // Only DEBUG_AGENT_INIT_PREMEM_SEC and DEBUG_AGENT_INIT_POSTMEM_SEC are allowed for this\r
     // Debug Agent library instance.\r
     //\r
     DEBUG ((EFI_D_ERROR, "Debug Agent: The InitFlag value is not allowed!\n"));\r
@@ -598,23 +615,43 @@ InitializeDebugAgent (
     break;\r
   }\r
 \r
-  EnableInterrupts ();\r
-\r
+  if (InitFlag == DEBUG_AGENT_INIT_POSTMEM_SEC) {\r
+    //\r
+    // Restore CPU Interrupt state and keep debug timer interrupt state as is\r
+    // in DEBUG_AGENT_INIT_POSTMEM_SEC case\r
+    //\r
+    SetInterruptState (CpuInterruptState);\r
+  } else {\r
+    //\r
+    // Enable Debug Timer interrupt\r
+    //\r
+    SaveAndSetDebugTimerInterrupt (TRUE);\r
+    //\r
+    // Enable CPU interrupts so debug timer interrupts can be delivered\r
+    //\r
+    EnableInterrupts ();\r
+  }\r
   //\r
   // If Function is not NULL, invoke it always whatever debug agent was initialized sucesssfully or not.\r
   //\r
   if (Function != NULL) {\r
     Function (Context);\r
   }\r
+  //\r
+  // Set return status for DEBUG_AGENT_INIT_PEI\r
+  //\r
+  if (InitFlag == DEBUG_AGENT_INIT_PEI && Context != NULL) {\r
+    *(EFI_STATUS *)Context = EFI_SUCCESS;\r
+  }\r
 }\r
 \r
 /**\r
   Caller provided function to be invoked at the end of DebugPortInitialize().\r
 \r
-  Refer to the descrption for DebugPortInitialize() for more details.\r
+  Refer to the description for DebugPortInitialize() for more details.\r
 \r
   @param[in] Context           The first input argument of DebugPortInitialize().\r
-  @param[in] DebugPortHandle   Debug port handle created by Debug Communication Libary.\r
+  @param[in] DebugPortHandle   Debug port handle created by Debug Communication Library.\r
 \r
 **/\r
 VOID\r
@@ -635,7 +672,7 @@ InitializeDebugAgentPhase2 (
   MailboxLocation = GetLocationSavedMailboxPointerInIdtEntry ();\r
   Mailbox = (DEBUG_AGENT_MAILBOX *)(UINTN)(*MailboxLocation);\r
   BufferSize = PcdGet16(PcdDebugPortHandleBufferSize);\r
-  if (Phase2Context->Function == NULL && DebugPortHandle != NULL && BufferSize != 0) {\r
+  if (Phase2Context->InitFlag == DEBUG_AGENT_INIT_PEI && BufferSize != 0) {\r
     NewDebugPortHandle = (UINT64)(UINTN)AllocateCopyPool (BufferSize, DebugPortHandle);\r
   } else {\r
     NewDebugPortHandle = (UINT64)(UINTN)DebugPortHandle;\r
@@ -647,25 +684,27 @@ InitializeDebugAgentPhase2 (
   //\r
   TriggerSoftInterrupt (SYSTEM_RESET_SIGNATURE);\r
 \r
-  //\r
-  // If Temporary RAM region is below 128 MB, then send message to \r
-  // host to disable low memory filtering.\r
-  //\r
-  SecCoreData = (EFI_SEC_PEI_HAND_OFF *)Phase2Context->Context;\r
-  if ((UINTN)SecCoreData->TemporaryRamBase < BASE_128MB && IsHostAttached ()) {\r
-    SetDebugFlag (DEBUG_AGENT_FLAG_MEMORY_READY, 1);\r
-    TriggerSoftInterrupt (MEMORY_READY_SIGNATURE);\r
-  }\r
-\r
-  //\r
-  // Enable CPU interrupts so debug timer interrupts can be delivered\r
-  //\r
-  EnableInterrupts ();\r
-\r
-  //\r
-  // Call continuation function if it is not NULL.\r
-  //\r
-  if (Phase2Context->Function != NULL) {\r
+  if (Phase2Context->InitFlag == DEBUG_AGENT_INIT_PREMEM_SEC) {\r
+    //\r
+    // If Temporary RAM region is below 128 MB, then send message to\r
+    // host to disable low memory filtering.\r
+    //\r
+    SecCoreData = (EFI_SEC_PEI_HAND_OFF *)Phase2Context->Context;\r
+    if ((UINTN)SecCoreData->TemporaryRamBase < BASE_128MB && IsHostAttached ()) {\r
+      SetDebugFlag (DEBUG_AGENT_FLAG_MEMORY_READY, 1);\r
+      TriggerSoftInterrupt (MEMORY_READY_SIGNATURE);\r
+    }\r
+    //\r
+    // Enable Debug Timer interrupt\r
+    //\r
+    SaveAndSetDebugTimerInterrupt (TRUE);\r
+    //\r
+    // Enable CPU interrupts so debug timer interrupts can be delivered\r
+    //\r
+    EnableInterrupts ();\r
+    //\r
+    // Call continuation function if it is not NULL.\r
+    //\r
     Phase2Context->Function (Phase2Context->Context);\r
   }\r
 }\r