Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Chen Fan <chen.fan.f...@cn.fujitsu.com>
---
 UefiCpuPkg/CpuDxe/ApStartup.c | 54 ++++++++++++++++++++++++++++++++-----------
 UefiCpuPkg/CpuDxe/CpuMp.c     |  3 +++
 UefiCpuPkg/CpuDxe/CpuMp.h     | 27 ++++++++++++++++++----
 3 files changed, 66 insertions(+), 18 deletions(-)

diff --git a/UefiCpuPkg/CpuDxe/ApStartup.c b/UefiCpuPkg/CpuDxe/ApStartup.c
index 7b6f5dd..f985a5c 100644
--- a/UefiCpuPkg/CpuDxe/ApStartup.c
+++ b/UefiCpuPkg/CpuDxe/ApStartup.c
@@ -143,27 +143,22 @@ STARTUP_CODE mStartupCodeTemplate = {
 
 };
 
+volatile STARTUP_CODE *StartupCode = NULL;
 
 /**
-  Starts the Application Processors and directs them to jump to the
-  specified routine.
-
-  The processor jumps to this code in flat mode, but the processor's
-  stack is not initialized.
-
-  @param ApEntryPoint    Pointer to the Entry Point routine
+  Prepares Startup Code for APs.
+  This function prepares Startup Code for APs.
 
   @retval EFI_SUCCESS           The APs were started
   @retval EFI_OUT_OF_RESOURCES  Cannot allocate memory to start APs
 
 **/
 EFI_STATUS
-StartApsStackless (
-  IN STACKLESS_AP_ENTRY_POINT ApEntryPoint
+PrepareAPStartupCode (
+  VOID
   )
 {
   EFI_STATUS            Status;
-  volatile STARTUP_CODE *StartupCode;
   IA32_DESCRIPTOR       Gdtr;
   EFI_PHYSICAL_ADDRESS  StartAddress;
 
@@ -186,7 +181,7 @@ StartApsStackless (
   StartupCode->GdtLimit = Gdtr.Limit;
   StartupCode->GdtBase = (UINT32) Gdtr.Base;
 
-  StartupCode->CpuDxeEntryValue = (UINTN) ApEntryPoint;
+  StartupCode->CpuDxeEntryValue = (UINTN) AsmApEntryPoint;
 
   StartupCode->FlatJmpOffset += (UINT32) StartAddress;
 
@@ -195,15 +190,46 @@ StartApsStackless (
   StartupCode->LongJmpOffset += (UINT32) StartAddress;
 #endif
 
-  SendInitSipiSipiAllExcludingSelf ((UINT32)(UINTN)(VOID*) StartupCode);
+  return EFI_SUCCESS;
+}
+
+/**
+  Free the code buffer of startup AP.
+
+**/
+VOID
+FreeApStartupCode (
+  VOID
+  )
+{
+  if (StartupCode != NULL) {
+    gBS->FreePages ((EFI_PHYSICAL_ADDRESS)(VOID *) StartupCode,
+                    EFI_SIZE_TO_PAGES (sizeof (*StartupCode)));
+  }
+}
 
+
+/**
+  Starts the Application Processors and directs them to jump to the
+  specified routine.
+
+  The processor jumps to this code in flat mode, but the processor's
+  stack is not initialized.
+
+  @retval EFI_SUCCESS           The APs were started
+
+**/
+EFI_STATUS
+StartApsStackless (
+  VOID
+  )
+{
+  SendInitSipiSipiAllExcludingSelf ((UINT32)(UINTN)(VOID*) StartupCode);
   //
   // Wait 100 milliseconds for APs to arrive at the ApEntryPoint routine
   //
   MicroSecondDelay (100 * 1000);
 
-  gBS->FreePages (StartAddress, EFI_SIZE_TO_PAGES (sizeof (*StartupCode)));
-
   return EFI_SUCCESS;
 }
 
diff --git a/UefiCpuPkg/CpuDxe/CpuMp.c b/UefiCpuPkg/CpuDxe/CpuMp.c
index 1ef1cf3..25331c0 100644
--- a/UefiCpuPkg/CpuDxe/CpuMp.c
+++ b/UefiCpuPkg/CpuDxe/CpuMp.c
@@ -1448,7 +1448,10 @@ InitializeMpSupport (
 
   InitMpSystemData ();
 
+  PrepareAPStartupCode ();
+
   if (mMpSystemData.NumberOfProcessors == 1) {
+    FreeApStartupCode ();
     FreePages (mCommonStack, EFI_SIZE_TO_PAGES (gMaxLogicalProcessorNumber * 
gApStackSize));
     return;
   }
diff --git a/UefiCpuPkg/CpuDxe/CpuMp.h b/UefiCpuPkg/CpuDxe/CpuMp.h
index 7af822b..0337327 100644
--- a/UefiCpuPkg/CpuDxe/CpuMp.h
+++ b/UefiCpuPkg/CpuDxe/CpuMp.h
@@ -39,15 +39,12 @@ VOID
   The processor jumps to this code in flat mode, but the processor's
   stack is not initialized.
 
-  @param ApEntryPoint    Pointer to the Entry Point routine
-
   @retval EFI_SUCCESS           The APs were started
-  @retval EFI_OUT_OF_RESOURCES  Cannot allocate memory to start APs
 
 **/
 EFI_STATUS
 StartApsStackless (
-  IN STACKLESS_AP_ENTRY_POINT ApEntryPoint
+  VOID
   );
 
 /**
@@ -602,5 +599,27 @@ ResetProcessorToIdleState (
   IN CPU_DATA_BLOCK  *CpuData
   );
 
+/**
+  Prepares Startup Code for APs.
+  This function prepares Startup Code for APs.
+
+  @retval EFI_SUCCESS           The APs were started
+  @retval EFI_OUT_OF_RESOURCES  Cannot allocate memory to start APs
+
+**/
+EFI_STATUS
+PrepareAPStartupCode (
+  VOID
+  );
+
+/**
+  Free the code buffer of startup AP.
+
+**/
+VOID
+FreeApStartupCode (
+  VOID
+  );
+
 #endif // _CPU_MP_H_
 
-- 
1.9.3


------------------------------------------------------------------------------
_______________________________________________
edk2-devel mailing list
edk2-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/edk2-devel

Reply via email to