]> git.proxmox.com Git - mirror_edk2.git/blobdiff - SourceLevelDebugPkg/Library/DebugAgent/SecPeiDebugAgent/SecPeiDebugAgentLib.c
SourceLevelDebugPkg: Convert source file to DOS format
[mirror_edk2.git] / SourceLevelDebugPkg / Library / DebugAgent / SecPeiDebugAgent / SecPeiDebugAgentLib.c
index ec389c7e8b9d0d9b4d5ea986ce7482c1e14a2612..9f5223a6957df0d68a5c86b053ae4be937d6cc93 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   SEC Core Debug Agent Library instance implementition.\r
 \r
-  Copyright (c) 2010 - 2015, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2010 - 2017, 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
@@ -32,7 +32,7 @@ GLOBAL_REMOVE_IF_UNREFERENCED EFI_PEI_PPI_DESCRIPTOR           mVectorHandoffInf
   }\r
 };\r
 \r
-GLOBAL_REMOVE_IF_UNREFERENCED EFI_PEI_NOTIFY_DESCRIPTOR mMemoryDiscoveredNotifyList[1] = {\r
+GLOBAL_REMOVE_IF_UNREFERENCED EFI_PEI_NOTIFY_DESCRIPTOR mDebugAgentMemoryDiscoveredNotifyList[1] = {\r
   {\r
     (EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),\r
     &gEfiPeiMemoryDiscoveredPpiGuid,\r
@@ -213,7 +213,7 @@ GetMailboxPointer (
     // Fix up Debug Port handler and save new mailbox in IDT entry\r
     //\r
     Mailbox = (DEBUG_AGENT_MAILBOX *)((UINTN)Mailbox + ((UINTN)(MailboxLocationInHob) - (UINTN)MailboxLocationInIdt));\r
-    DebugPortHandle = (UINT64)((UINTN)Mailbox->DebugPortHandle + ((UINTN)(MailboxLocationInHob) - (UINTN)MailboxLocationInIdt));\r
+    DebugPortHandle = (UINTN)Mailbox->DebugPortHandle + ((UINTN)(MailboxLocationInHob) - (UINTN)MailboxLocationInIdt);\r
     UpdateMailboxContent (Mailbox, DEBUG_MAILBOX_DEBUG_PORT_HANDLE_INDEX, DebugPortHandle);\r
     *MailboxLocationInHob = (UINT64)(UINTN)Mailbox;\r
     SetLocationSavedMailboxPointerInIdtEntry (MailboxLocationInHob);\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
@@ -376,8 +376,12 @@ InitializeDebugAgent (
   UINT64                           *MailboxLocationPointer;\r
   EFI_PHYSICAL_ADDRESS             Address;\r
   UINT32                           DebugTimerFrequency;\r
+  BOOLEAN                          CpuInterruptState;\r
 \r
-  DisableInterrupts ();\r
+  //\r
+  // Disable interrupts and save current interrupt state\r
+  //\r
+  CpuInterruptState = SaveAndDisableInterrupts();\r
 \r
   switch (InitFlag) {\r
 \r
@@ -403,7 +407,7 @@ InitializeDebugAgent (
     //\r
     // Initialize Debug Timer hardware and save its frequency\r
     //\r
-    InitializeDebugTimer (&DebugTimerFrequency);\r
+    InitializeDebugTimer (&DebugTimerFrequency, TRUE);\r
     UpdateMailboxContent (Mailbox, DEBUG_MAILBOX_DEBUG_TIMER_FREQUENCY, DebugTimerFrequency);\r
 \r
     Phase2Context.InitFlag = InitFlag;\r
@@ -525,22 +529,23 @@ InitializeDebugAgent (
     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
-    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);\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
     // Save init arch type when debug agent initialized\r
     //\r
@@ -549,7 +554,7 @@ InitializeDebugAgent (
     // Register for a callback once memory has been initialized.\r
     // If memery has been ready, the callback funtion will be invoked immediately\r
     //\r
-    Status = PeiServicesNotifyPpi (&mMemoryDiscoveredNotifyList[0]);\r
+    Status = PeiServicesNotifyPpi (&mDebugAgentMemoryDiscoveredNotifyList[0]);\r
     if (EFI_ERROR (Status)) {\r
       DEBUG ((EFI_D_ERROR, "DebugAgent: Failed to register memory discovered callback function!\n"));\r
       CpuDeadLoop ();\r
@@ -577,8 +582,8 @@ InitializeDebugAgent (
     } else {\r
       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
+      MailboxLocationPointer = (UINT64 *) ((UINTN) Ia32IdtEntry[DEBUG_MAILBOX_VECTOR].Bits.OffsetLow +\r
+                                          ((UINTN) 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
@@ -610,11 +615,22 @@ InitializeDebugAgent (
     break;\r
   }\r
 \r
-  //\r
-  // Enable CPU interrupts so debug timer interrupts can be delivered\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
@@ -632,10 +648,10 @@ InitializeDebugAgent (
 /**\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
@@ -656,7 +672,7 @@ InitializeDebugAgentPhase2 (
   MailboxLocation = GetLocationSavedMailboxPointerInIdtEntry ();\r
   Mailbox = (DEBUG_AGENT_MAILBOX *)(UINTN)(*MailboxLocation);\r
   BufferSize = PcdGet16(PcdDebugPortHandleBufferSize);\r
-  if (Phase2Context->InitFlag == DEBUG_AGENT_INIT_PEI) {\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
@@ -679,6 +695,10 @@ InitializeDebugAgentPhase2 (
       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