]> git.proxmox.com Git - mirror_edk2.git/blobdiff - SourceLevelDebugPkg/Library/DebugAgent/SecPeiDebugAgent/SecPeiDebugAgentLib.c
Add InitFlag member in DEBUG_AGENT_PHASE2_CONTEXT to pass into InitializeDebugAgentPh...
[mirror_edk2.git] / SourceLevelDebugPkg / Library / DebugAgent / SecPeiDebugAgent / SecPeiDebugAgentLib.c
index 0388807697081ceab0e228beaad0866727810694..a3f91d3358085b667037cae5e5579c08026e7c90 100644 (file)
@@ -402,6 +402,7 @@ InitializeDebugAgent (
 \r
     InitializeDebugTimer ();\r
 \r
+    Phase2Context.InitFlag = InitFlag;\r
     Phase2Context.Context  = Context;\r
     Phase2Context.Function = Function;\r
     DebugPortInitialize ((VOID *) &Phase2Context, InitializeDebugAgentPhase2);\r
@@ -487,14 +488,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
@@ -550,6 +550,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
@@ -598,6 +599,9 @@ InitializeDebugAgent (
     break;\r
   }\r
 \r
+  //\r
+  // Enable CPU interrupts so debug timer interrupts can be delivered\r
+  //\r
   EnableInterrupts ();\r
 \r
   //\r
@@ -606,6 +610,12 @@ InitializeDebugAgent (
   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) {\r
+    *(EFI_STATUS *)Context = EFI_SUCCESS;\r
+  }\r
 }\r
 \r
 /**\r
@@ -635,7 +645,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) {\r
     NewDebugPortHandle = (UINT64)(UINTN)AllocateCopyPool (BufferSize, DebugPortHandle);\r
   } else {\r
     NewDebugPortHandle = (UINT64)(UINTN)DebugPortHandle;\r
@@ -647,25 +657,23 @@ 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 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