]> git.proxmox.com Git - mirror_edk2.git/blobdiff - UefiCpuPkg/CpuDxe/CpuMp.c
UefiCpuPkg: Make the comments align with the functions
[mirror_edk2.git] / UefiCpuPkg / CpuDxe / CpuMp.c
index 2bc9f70bbbe4e19c06935db06a2972f410304e5e..9659bd280725c56a5a6ed325a191a4ff3f7bd83a 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
-  CPU DXE Module.\r
+  CPU DXE Module to produce CPU MP Protocol.\r
 \r
-  Copyright (c) 2008 - 2014, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2008 - 2016, 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
 #include "CpuDxe.h"\r
 #include "CpuMp.h"\r
 \r
-UINTN gMaxLogicalProcessorNumber;\r
-UINTN gApStackSize;\r
-UINTN gPollInterval = 100; // 100 microseconds\r
-\r
-MP_SYSTEM_DATA mMpSystemData;\r
-\r
-VOID *mCommonStack = 0;\r
-VOID *mTopOfApCommonStack = 0;\r
-VOID *mApStackStart = 0;\r
-\r
-volatile BOOLEAN mAPsAlreadyInitFinished = FALSE;\r
-volatile BOOLEAN mStopCheckAllAPsStatus = TRUE;\r
+EFI_HANDLE     mMpServiceHandle       = NULL;\r
+UINTN          mNumberOfProcessors    = 1;\r
 \r
 EFI_MP_SERVICES_PROTOCOL  mMpServicesTemplate = {\r
   GetNumberOfProcessors,\r
@@ -38,322 +28,6 @@ EFI_MP_SERVICES_PROTOCOL  mMpServicesTemplate = {
   WhoAmI\r
 };\r
 \r
-/**\r
-   Get Mp Service Lock.\r
-\r
-  @param   CpuData    the pointer to CPU_DATA_BLOCK of specified processor\r
-\r
-**/\r
-VOID\r
-GetMpSpinLock (\r
-  IN  CPU_DATA_BLOCK  *CpuData\r
-  )\r
-{\r
-  while (!AcquireSpinLockOrFail (&CpuData->CpuDataLock)) {\r
-    CpuPause ();\r
-  }\r
-  CpuData->LockSelf = GetApicId ();\r
-}\r
-\r
-/**\r
-   Release Mp Service Lock.\r
-\r
-  @param   CpuData    the pointer to CPU_DATA_BLOCK of specified processor\r
-\r
-**/\r
-VOID\r
-ReleaseMpSpinLock (\r
-  IN  CPU_DATA_BLOCK  *CpuData\r
-  )\r
-{\r
-  ReleaseSpinLock (&CpuData->CpuDataLock);\r
-}\r
-\r
-/**\r
-  Check whether caller processor is BSP.\r
-\r
-  @retval  TRUE       the caller is BSP\r
-  @retval  FALSE      the caller is AP\r
-\r
-**/\r
-BOOLEAN\r
-IsBSP (\r
-  VOID\r
-  )\r
-{\r
-  UINTN           CpuIndex;\r
-  CPU_DATA_BLOCK  *CpuData;\r
-\r
-  CpuData = NULL;\r
-\r
-  WhoAmI (&mMpServicesTemplate, &CpuIndex);\r
-  CpuData = &mMpSystemData.CpuDatas[CpuIndex];\r
-\r
-  return CpuData->Info.StatusFlag & PROCESSOR_AS_BSP_BIT ? TRUE : FALSE;\r
-}\r
-\r
-/**\r
-  Get the Application Processors state.\r
-\r
-  @param   CpuData    the pointer to CPU_DATA_BLOCK of specified AP\r
-\r
-  @retval  CPU_STATE  the AP status\r
-\r
-**/\r
-CPU_STATE\r
-GetApState (\r
-  IN  CPU_DATA_BLOCK  *CpuData\r
-  )\r
-{\r
-  CPU_STATE State;\r
-\r
-  GetMpSpinLock (CpuData);\r
-  State = CpuData->State;\r
-  ReleaseMpSpinLock (CpuData);\r
-\r
-  return State;\r
-}\r
-\r
-/**\r
-  Set the Application Processors state.\r
-\r
-  @param   CpuData    The pointer to CPU_DATA_BLOCK of specified AP\r
-  @param   State      The AP status\r
-\r
-**/\r
-VOID\r
-SetApState (\r
-  IN  CPU_DATA_BLOCK   *CpuData,\r
-  IN  CPU_STATE        State\r
-  )\r
-{\r
-  GetMpSpinLock (CpuData);\r
-  CpuData->State = State;\r
-  ReleaseMpSpinLock (CpuData);\r
-}\r
-\r
-/**\r
-  Set the Application Processor prepare to run a function specified\r
-  by Params.\r
-\r
-  @param CpuData           the pointer to CPU_DATA_BLOCK of specified AP\r
-  @param Procedure         A pointer to the function to be run on enabled APs of the system\r
-  @param ProcedureArgument Pointer to the optional parameter of the assigned function\r
-\r
-**/\r
-VOID\r
-SetApProcedure (\r
-  IN   CPU_DATA_BLOCK        *CpuData,\r
-  IN   EFI_AP_PROCEDURE      Procedure,\r
-  IN   VOID                  *ProcedureArgument\r
-  )\r
-{\r
-  GetMpSpinLock (CpuData);\r
-  CpuData->Parameter  = ProcedureArgument;\r
-  CpuData->Procedure  = Procedure;\r
-  ReleaseMpSpinLock (CpuData);\r
-}\r
-\r
-/**\r
-  Check the Application Processors Status whether contains the Flags.\r
-\r
-  @param     CpuData  the pointer to CPU_DATA_BLOCK of specified AP\r
-  @param     Flags    the StatusFlag describing in EFI_PROCESSOR_INFORMATION\r
-\r
-  @retval    TRUE     the AP status includes the StatusFlag\r
-  @retval    FALSE    the AP status excludes the StatusFlag\r
-\r
-**/\r
-BOOLEAN\r
-TestCpuStatusFlag (\r
-  IN  CPU_DATA_BLOCK  *CpuData,\r
-  IN  UINT32          Flags\r
-  )\r
-{\r
-  UINT32 Ret;\r
-\r
-  GetMpSpinLock (CpuData);\r
-  Ret = CpuData->Info.StatusFlag & Flags;\r
-  ReleaseMpSpinLock (CpuData);\r
-\r
-  return !!(Ret);\r
-}\r
-\r
-/**\r
-  Bitwise-Or of the Application Processors Status with the Flags.\r
-\r
-  @param     CpuData  the pointer to CPU_DATA_BLOCK of specified AP\r
-  @param     Flags    the StatusFlag describing in EFI_PROCESSOR_INFORMATION\r
-\r
-**/\r
-VOID\r
-CpuStatusFlagOr (\r
-  IN  CPU_DATA_BLOCK  *CpuData,\r
-  IN  UINT32          Flags\r
-  )\r
-{\r
-  GetMpSpinLock (CpuData);\r
-  CpuData->Info.StatusFlag |= Flags;\r
-  ReleaseMpSpinLock (CpuData);\r
-}\r
-\r
-/**\r
-  Bitwise-AndNot of the Application Processors Status with the Flags.\r
-\r
-  @param     CpuData  the pointer to CPU_DATA_BLOCK of specified AP\r
-  @param     Flags    the StatusFlag describing in EFI_PROCESSOR_INFORMATION\r
-\r
-**/\r
-VOID\r
-CpuStatusFlagAndNot (\r
-  IN  CPU_DATA_BLOCK  *CpuData,\r
-  IN  UINT32          Flags\r
-  )\r
-{\r
-  GetMpSpinLock (CpuData);\r
-  CpuData->Info.StatusFlag &= ~Flags;\r
-  ReleaseMpSpinLock (CpuData);\r
-}\r
-\r
-/**\r
-  Searches for the next blocking AP.\r
-\r
-  Search for the next AP that is put in blocking state by single-threaded StartupAllAPs().\r
-\r
-  @param  NextNumber           Pointer to the processor number of the next blocking AP.\r
-\r
-  @retval EFI_SUCCESS          The next blocking AP has been found.\r
-  @retval EFI_NOT_FOUND        No blocking AP exists.\r
-\r
-**/\r
-EFI_STATUS\r
-GetNextBlockedNumber (\r
-  OUT UINTN  *NextNumber\r
-  )\r
-{\r
-  UINTN                 Number;\r
-  CPU_STATE             CpuState;\r
-  CPU_DATA_BLOCK        *CpuData;\r
-\r
-  for (Number = 0; Number < mMpSystemData.NumberOfProcessors; Number++) {\r
-    CpuData = &mMpSystemData.CpuDatas[Number];\r
-    if (TestCpuStatusFlag (CpuData, PROCESSOR_AS_BSP_BIT)) {\r
-      //\r
-      // Skip BSP\r
-      //\r
-      continue;\r
-    }\r
-\r
-    CpuState = GetApState (CpuData);\r
-    if (CpuState == CpuStateBlocked) {\r
-      *NextNumber = Number;\r
-      return EFI_SUCCESS;\r
-    }\r
-  }\r
-\r
-  return EFI_NOT_FOUND;\r
-}\r
-\r
-/**\r
-  Check if the APs state are finished, and update them to idle state\r
-  by StartupAllAPs().\r
-\r
-**/\r
-VOID\r
-CheckAndUpdateAllAPsToIdleState (\r
-  VOID\r
-  )\r
-{\r
-  UINTN                 ProcessorNumber;\r
-  UINTN                 NextNumber;\r
-  CPU_DATA_BLOCK        *CpuData;\r
-  EFI_STATUS            Status;\r
-  CPU_STATE             CpuState;\r
-\r
-  for (ProcessorNumber = 0; ProcessorNumber < mMpSystemData.NumberOfProcessors; ProcessorNumber++) {\r
-    CpuData = &mMpSystemData.CpuDatas[ProcessorNumber];\r
-    if (TestCpuStatusFlag (CpuData, PROCESSOR_AS_BSP_BIT)) {\r
-      //\r
-      // Skip BSP\r
-      //\r
-      continue;\r
-    }\r
-\r
-    if (!TestCpuStatusFlag (CpuData, PROCESSOR_ENABLED_BIT)) {\r
-      //\r
-      // Skip Disabled processors\r
-      //\r
-      continue;\r
-    }\r
-\r
-    CpuState = GetApState (CpuData);\r
-    if (CpuState == CpuStateFinished) {\r
-      mMpSystemData.FinishCount++;\r
-      if (mMpSystemData.SingleThread) {\r
-        Status = GetNextBlockedNumber (&NextNumber);\r
-        if (!EFI_ERROR (Status)) {\r
-          SetApState (&mMpSystemData.CpuDatas[NextNumber], CpuStateReady);\r
-          SetApProcedure (&mMpSystemData.CpuDatas[NextNumber],\r
-                          mMpSystemData.Procedure,\r
-                          mMpSystemData.ProcedureArgument);\r
-        }\r
-      }\r
-\r
-      SetApState (CpuData, CpuStateIdle);\r
-    }\r
-  }\r
-}\r
-\r
-/**\r
-  If the timeout expires before all APs returns from Procedure,\r
-  we should forcibly terminate the executing AP and fill FailedList back\r
-  by StartupAllAPs().\r
-\r
-**/\r
-VOID\r
-ResetAllFailedAPs (\r
-  VOID\r
-  )\r
-{\r
-  CPU_DATA_BLOCK        *CpuData;\r
-  UINTN                 Number;\r
-  CPU_STATE             CpuState;\r
-\r
-  if (mMpSystemData.FailedList != NULL) {\r
-     *mMpSystemData.FailedList = AllocatePool ((mMpSystemData.StartCount - mMpSystemData.FinishCount + 1) * sizeof(UINTN));\r
-     ASSERT (*mMpSystemData.FailedList != NULL);\r
-  }\r
-\r
-  for (Number = 0; Number < mMpSystemData.NumberOfProcessors; Number++) {\r
-    CpuData = &mMpSystemData.CpuDatas[Number];\r
-    if (TestCpuStatusFlag (CpuData,  PROCESSOR_AS_BSP_BIT)) {\r
-      //\r
-      // Skip BSP\r
-      //\r
-      continue;\r
-    }\r
-\r
-    if (!TestCpuStatusFlag (CpuData, PROCESSOR_ENABLED_BIT)) {\r
-      //\r
-      // Skip Disabled processors\r
-      //\r
-      continue;\r
-    }\r
-\r
-    CpuState = GetApState (CpuData);\r
-    if (CpuState != CpuStateIdle) {\r
-      if (mMpSystemData.FailedList != NULL) {\r
-        (*mMpSystemData.FailedList)[mMpSystemData.FailedListIndex++] = Number;\r
-      }\r
-      ResetProcessorToIdleState (CpuData);\r
-    }\r
-  }\r
-\r
-  if (mMpSystemData.FailedList != NULL) {\r
-    (*mMpSystemData.FailedList)[mMpSystemData.FailedListIndex] = END_OF_CPU_LIST;\r
-  }\r
-}\r
-\r
 /**\r
   This service retrieves the number of logical processor in the platform\r
   and the number of those logical processors that are enabled on this boot.\r
@@ -402,13 +76,10 @@ GetNumberOfProcessors (
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
-  if (!IsBSP ()) {\r
-    return EFI_DEVICE_ERROR;\r
-  }\r
-\r
-  *NumberOfProcessors        = mMpSystemData.NumberOfProcessors;\r
-  *NumberOfEnabledProcessors = mMpSystemData.NumberOfEnabledProcessors;\r
-  return EFI_SUCCESS;\r
+  return MpInitLibGetNumberOfProcessors (\r
+           NumberOfProcessors,\r
+           NumberOfEnabledProcessors\r
+           );\r
 }\r
 \r
 /**\r
@@ -445,20 +116,7 @@ GetProcessorInfo (
   OUT EFI_PROCESSOR_INFORMATION  *ProcessorInfoBuffer\r
   )\r
 {\r
-  if (ProcessorInfoBuffer == NULL) {\r
-    return EFI_INVALID_PARAMETER;\r
-  }\r
-\r
-  if (!IsBSP ()) {\r
-    return EFI_DEVICE_ERROR;\r
-  }\r
-\r
-  if (ProcessorNumber >= mMpSystemData.NumberOfProcessors) {\r
-    return EFI_NOT_FOUND;\r
-  }\r
-\r
-  CopyMem (ProcessorInfoBuffer, &mMpSystemData.CpuDatas[ProcessorNumber], sizeof (EFI_PROCESSOR_INFORMATION));\r
-  return EFI_SUCCESS;\r
+  return MpInitLibGetProcessorInfo (ProcessorNumber, ProcessorInfoBuffer, NULL);\r
 }\r
 \r
 /**\r
@@ -609,141 +267,14 @@ StartupAllAPs (
   OUT UINTN                     **FailedCpuList         OPTIONAL\r
   )\r
 {\r
-  EFI_STATUS            Status;\r
-  CPU_DATA_BLOCK        *CpuData;\r
-  UINTN                 Number;\r
-  CPU_STATE             APInitialState;\r
-\r
-  CpuData = NULL;\r
-\r
-  if (FailedCpuList != NULL) {\r
-    *FailedCpuList = NULL;\r
-  }\r
-\r
-  if (!IsBSP ()) {\r
-    return EFI_DEVICE_ERROR;\r
-  }\r
-\r
-  if (mMpSystemData.NumberOfProcessors == 1) {\r
-    return EFI_NOT_STARTED;\r
-  }\r
-\r
-  if (Procedure == NULL) {\r
-    return EFI_INVALID_PARAMETER;\r
-  }\r
-\r
-  //\r
-  // temporarily stop checkAllAPsStatus for avoid resource dead-lock.\r
-  //\r
-  mStopCheckAllAPsStatus = TRUE;\r
-\r
-  for (Number = 0; Number < mMpSystemData.NumberOfProcessors; Number++) {\r
-    CpuData = &mMpSystemData.CpuDatas[Number];\r
-    if (TestCpuStatusFlag (CpuData, PROCESSOR_AS_BSP_BIT)) {\r
-      //\r
-      // Skip BSP\r
-      //\r
-      continue;\r
-    }\r
-\r
-    if (!TestCpuStatusFlag (CpuData, PROCESSOR_ENABLED_BIT)) {\r
-      //\r
-      // Skip Disabled processors\r
-      //\r
-      continue;\r
-    }\r
-\r
-    if (GetApState (CpuData) != CpuStateIdle) {\r
-      return EFI_NOT_READY;\r
-    }\r
-  }\r
-\r
-  mMpSystemData.Procedure         = Procedure;\r
-  mMpSystemData.ProcedureArgument = ProcedureArgument;\r
-  mMpSystemData.WaitEvent         = WaitEvent;\r
-  mMpSystemData.Timeout           = TimeoutInMicroseconds;\r
-  mMpSystemData.TimeoutActive     = !!(TimeoutInMicroseconds);\r
-  mMpSystemData.FinishCount       = 0;\r
-  mMpSystemData.StartCount        = 0;\r
-  mMpSystemData.SingleThread      = SingleThread;\r
-  mMpSystemData.FailedList        = FailedCpuList;\r
-  mMpSystemData.FailedListIndex   = 0;\r
-  APInitialState                  = CpuStateReady;\r
-\r
-  for (Number = 0; Number < mMpSystemData.NumberOfProcessors; Number++) {\r
-    CpuData = &mMpSystemData.CpuDatas[Number];\r
-    if (TestCpuStatusFlag (CpuData, PROCESSOR_AS_BSP_BIT)) {\r
-      //\r
-      // Skip BSP\r
-      //\r
-      continue;\r
-    }\r
-\r
-    if (!TestCpuStatusFlag (CpuData, PROCESSOR_ENABLED_BIT)) {\r
-      //\r
-      // Skip Disabled processors\r
-      //\r
-      continue;\r
-    }\r
-\r
-    //\r
-    // Get APs prepared, and put failing APs into FailedCpuList\r
-    // if "SingleThread", only 1 AP will put to ready state, other AP will be put to ready\r
-    // state 1 by 1, until the previous 1 finished its task\r
-    // if not "SingleThread", all APs are put to ready state from the beginning\r
-    //\r
-    if (GetApState (CpuData) == CpuStateIdle) {\r
-      mMpSystemData.StartCount++;\r
-\r
-      SetApState (CpuData, APInitialState);\r
-\r
-      if (APInitialState == CpuStateReady) {\r
-        SetApProcedure (CpuData, Procedure, ProcedureArgument);\r
-      }\r
-\r
-      if (SingleThread) {\r
-        APInitialState = CpuStateBlocked;\r
-      }\r
-    }\r
-  }\r
-\r
-  mStopCheckAllAPsStatus = FALSE;\r
-\r
-  if (WaitEvent != NULL) {\r
-    //\r
-    // non blocking\r
-    //\r
-    return EFI_SUCCESS;\r
-  }\r
-\r
-  //\r
-  // Blocking temporarily stop CheckAllAPsStatus()\r
-  //\r
-  mStopCheckAllAPsStatus = TRUE;\r
-\r
-  while (TRUE) {\r
-    CheckAndUpdateAllAPsToIdleState ();\r
-    if (mMpSystemData.FinishCount == mMpSystemData.StartCount) {\r
-      Status = EFI_SUCCESS;\r
-      goto Done;\r
-    }\r
-\r
-    //\r
-    // task timeout\r
-    //\r
-    if (mMpSystemData.TimeoutActive && mMpSystemData.Timeout < 0) {\r
-      ResetAllFailedAPs();\r
-      Status = EFI_TIMEOUT;\r
-      goto Done;\r
-    }\r
-\r
-    gBS->Stall (gPollInterval);\r
-    mMpSystemData.Timeout -= gPollInterval;\r
-  }\r
-\r
-Done:\r
-\r
-  return Status;\r
+  return MpInitLibStartupAllAPs (\r
+           Procedure,\r
+           SingleThread,\r
+           WaitEvent,\r
+           TimeoutInMicroseconds,\r
+           ProcedureArgument,\r
+           FailedCpuList\r
+           );\r
 }\r
 \r
 /**\r
@@ -768,8 +299,8 @@ Done:
 \r
   @param[in]  This                    A pointer to the EFI_MP_SERVICES_PROTOCOL\r
                                       instance.\r
-  @param[in]  Procedure               A pointer to the function to be run on\r
-                                      enabled APs of the system. See type\r
+  @param[in]  Procedure               A pointer to the function to be run on the\r
+                                      designated AP of the system. See type\r
                                       EFI_AP_PROCEDURE.\r
   @param[in]  ProcessorNumber         The handle number of the AP. The range is\r
                                       from 0 to the total number of logical\r
@@ -778,13 +309,13 @@ Done:
                                       EFI_MP_SERVICES_PROTOCOL.GetNumberOfProcessors().\r
   @param[in]  WaitEvent               The event created by the caller with CreateEvent()\r
                                       service.  If it is NULL, then execute in\r
-                                      blocking mode. BSP waits until all APs finish\r
-                                      or TimeoutInMicroseconds expires.  If it's\r
+                                      blocking mode. BSP waits until this AP finish\r
+                                      or TimeoutInMicroSeconds expires.  If it's\r
                                       not NULL, then execute in non-blocking mode.\r
                                       BSP requests the function specified by\r
-                                      Procedure to be started on all the enabled\r
-                                      APs, and go on executing immediately. If\r
-                                      all return from Procedure or TimeoutInMicroseconds\r
+                                      Procedure to be started on this AP,\r
+                                      and go on executing immediately. If this AP\r
+                                      return from Procedure or TimeoutInMicroSeconds\r
                                       expires, this event is signaled. The BSP\r
                                       can use the CheckEvent() or WaitForEvent()\r
                                       services to check the state of event.  Type\r
@@ -792,20 +323,20 @@ Done:
                                       the Unified Extensible Firmware Interface\r
                                       Specification.\r
   @param[in]  TimeoutInMicroseconds   Indicates the time limit in microseconds for\r
-                                      APs to return from Procedure, either for\r
+                                      this AP to finish this Procedure, either for\r
                                       blocking or non-blocking mode. Zero means\r
                                       infinity.  If the timeout expires before\r
-                                      all APs return from Procedure, then Procedure\r
-                                      on the failed APs is terminated. All enabled\r
-                                      APs are available for next function assigned\r
+                                      this AP returns from Procedure, then Procedure\r
+                                      on the AP is terminated. The\r
+                                      AP is available for next function assigned\r
                                       by EFI_MP_SERVICES_PROTOCOL.StartupAllAPs()\r
                                       or EFI_MP_SERVICES_PROTOCOL.StartupThisAP().\r
                                       If the timeout expires in blocking mode,\r
                                       BSP returns EFI_TIMEOUT.  If the timeout\r
                                       expires in non-blocking mode, WaitEvent\r
                                       is signaled with SignalEvent().\r
-  @param[in]  ProcedureArgument       The parameter passed into Procedure for\r
-                                      all APs.\r
+  @param[in]  ProcedureArgument       The parameter passed into Procedure on the\r
+                                      specified AP.\r
   @param[out] Finished                If NULL, this parameter is ignored.  In\r
                                       blocking mode, this parameter is ignored.\r
                                       In non-blocking mode, if AP returns from\r
@@ -844,78 +375,14 @@ StartupThisAP (
   OUT BOOLEAN                   *Finished               OPTIONAL\r
   )\r
 {\r
-  CPU_DATA_BLOCK        *CpuData;\r
-\r
-  CpuData = NULL;\r
-\r
-  if (Finished != NULL) {\r
-    *Finished = FALSE;\r
-  }\r
-\r
-  if (!IsBSP ()) {\r
-    return EFI_DEVICE_ERROR;\r
-  }\r
-\r
-  if (Procedure == NULL) {\r
-    return EFI_INVALID_PARAMETER;\r
-  }\r
-\r
-  if (ProcessorNumber >= mMpSystemData.NumberOfProcessors) {\r
-    return EFI_NOT_FOUND;\r
-  }\r
-\r
-  //\r
-  // temporarily stop checkAllAPsStatus for avoid resource dead-lock.\r
-  //\r
-  mStopCheckAllAPsStatus = TRUE;\r
-\r
-  CpuData = &mMpSystemData.CpuDatas[ProcessorNumber];\r
-  if (TestCpuStatusFlag (CpuData, PROCESSOR_AS_BSP_BIT) ||\r
-      !TestCpuStatusFlag (CpuData, PROCESSOR_ENABLED_BIT)) {\r
-    return EFI_INVALID_PARAMETER;\r
-  }\r
-\r
-  if (GetApState (CpuData) != CpuStateIdle) {\r
-    return EFI_NOT_READY;\r
-  }\r
-\r
-  SetApState (CpuData, CpuStateReady);\r
-\r
-  SetApProcedure (CpuData, Procedure, ProcedureArgument);\r
-\r
-  CpuData->Timeout = TimeoutInMicroseconds;\r
-  CpuData->WaitEvent = WaitEvent;\r
-  CpuData->TimeoutActive = !!(TimeoutInMicroseconds);\r
-  CpuData->Finished = Finished;\r
-\r
-  mStopCheckAllAPsStatus = FALSE;\r
-\r
-  if (WaitEvent != NULL) {\r
-    //\r
-    // Non Blocking\r
-    //\r
-    return EFI_SUCCESS;\r
-  }\r
-\r
-  //\r
-  // Blocking\r
-  //\r
-  while (TRUE) {\r
-    if (GetApState (CpuData) == CpuStateFinished) {\r
-      SetApState (CpuData, CpuStateIdle);\r
-      break;\r
-    }\r
-\r
-    if (CpuData->TimeoutActive && CpuData->Timeout < 0) {\r
-      ResetProcessorToIdleState (CpuData);\r
-      return EFI_TIMEOUT;\r
-    }\r
-\r
-    gBS->Stall (gPollInterval);\r
-    CpuData->Timeout -= gPollInterval;\r
-  }\r
-\r
-  return EFI_SUCCESS;\r
+  return MpInitLibStartupThisAP (\r
+           Procedure,\r
+           ProcessorNumber,\r
+           WaitEvent,\r
+           TimeoutInMicroseconds,\r
+           ProcedureArgument,\r
+           Finished\r
+           );\r
 }\r
 \r
 /**\r
@@ -961,10 +428,7 @@ SwitchBSP (
   IN  BOOLEAN                  EnableOldBSP\r
   )\r
 {\r
-   //\r
-   // Current always return unsupported.\r
-   //\r
-   return EFI_UNSUPPORTED;\r
+  return MpInitLibSwitchBSP (ProcessorNumber, EnableOldBSP);\r
 }\r
 \r
 /**\r
@@ -983,8 +447,8 @@ SwitchBSP (
   from this service, then EFI_UNSUPPORTED must be returned.\r
 \r
   @param[in] This              A pointer to the EFI_MP_SERVICES_PROTOCOL instance.\r
-  @param[in] ProcessorNumber   The handle number of AP that is to become the new\r
-                               BSP. The range is from 0 to the total number of\r
+  @param[in] ProcessorNumber   The handle number of AP.\r
+                               The range is from 0 to the total number of\r
                                logical processors minus 1. The total number of\r
                                logical processors can be retrieved by\r
                                EFI_MP_SERVICES_PROTOCOL.GetNumberOfProcessors().\r
@@ -1017,59 +481,7 @@ EnableDisableAP (
   IN  UINT32                    *HealthFlag OPTIONAL\r
   )\r
 {\r
-  CPU_DATA_BLOCK *CpuData;\r
-  BOOLEAN        TempStopCheckState;\r
-\r
-  CpuData = NULL;\r
-  TempStopCheckState = FALSE;\r
-\r
-  if (!IsBSP ()) {\r
-    return EFI_DEVICE_ERROR;\r
-  }\r
-\r
-  if (ProcessorNumber >= mMpSystemData.NumberOfProcessors) {\r
-    return EFI_NOT_FOUND;\r
-  }\r
-\r
-  //\r
-  // temporarily stop checkAllAPsStatus for initialize parameters.\r
-  //\r
-  if (!mStopCheckAllAPsStatus) {\r
-    mStopCheckAllAPsStatus = TRUE;\r
-    TempStopCheckState = TRUE;\r
-  }\r
-\r
-  CpuData = &mMpSystemData.CpuDatas[ProcessorNumber];\r
-  if (TestCpuStatusFlag (CpuData, PROCESSOR_AS_BSP_BIT)) {\r
-    return EFI_INVALID_PARAMETER;\r
-  }\r
-\r
-  if (GetApState (CpuData) != CpuStateIdle) {\r
-    return EFI_UNSUPPORTED;\r
-  }\r
-\r
-  if (EnableAP) {\r
-    if (!(TestCpuStatusFlag (CpuData, PROCESSOR_ENABLED_BIT))) {\r
-      mMpSystemData.NumberOfEnabledProcessors++;\r
-    }\r
-    CpuStatusFlagOr (CpuData, PROCESSOR_ENABLED_BIT);\r
-  } else {\r
-    if (TestCpuStatusFlag (CpuData, PROCESSOR_ENABLED_BIT)) {\r
-      mMpSystemData.NumberOfEnabledProcessors--;\r
-    }\r
-    CpuStatusFlagAndNot (CpuData, PROCESSOR_ENABLED_BIT);\r
-  }\r
-\r
-  if (HealthFlag != NULL) {\r
-    CpuStatusFlagAndNot (CpuData, (UINT32)~PROCESSOR_HEALTH_STATUS_BIT);\r
-    CpuStatusFlagOr (CpuData, (*HealthFlag & PROCESSOR_HEALTH_STATUS_BIT));\r
-  }\r
-\r
-  if (TempStopCheckState) {\r
-    mStopCheckAllAPsStatus = FALSE;\r
-  }\r
-\r
-  return EFI_SUCCESS;\r
+  return MpInitLibEnableDisableAP (ProcessorNumber, EnableAP, HealthFlag);\r
 }\r
 \r
 /**\r
@@ -1085,8 +497,8 @@ EnableDisableAP (
   ProcessorNumber, and EFI_SUCCESS is returned.\r
 \r
   @param[in]  This             A pointer to the EFI_MP_SERVICES_PROTOCOL instance.\r
-  @param[out] ProcessorNumber  The handle number of AP that is to become the new\r
-                               BSP. The range is from 0 to the total number of\r
+  @param[out] ProcessorNumber  Pointer to the handle number of AP.\r
+                               The range is from 0 to the total number of\r
                                logical processors minus 1. The total number of\r
                                logical processors can be retrieved by\r
                                EFI_MP_SERVICES_PROTOCOL.GetNumberOfProcessors().\r
@@ -1103,422 +515,125 @@ WhoAmI (
   OUT UINTN                    *ProcessorNumber\r
   )\r
 {\r
-  UINTN   Index;\r
-  UINT32  ProcessorId;\r
-\r
-  if (ProcessorNumber == NULL) {\r
-    return EFI_INVALID_PARAMETER;\r
-  }\r
-\r
-  ProcessorId = GetApicId ();\r
-  for (Index = 0; Index < mMpSystemData.NumberOfProcessors; Index++) {\r
-    if (mMpSystemData.CpuDatas[Index].Info.ProcessorId == ProcessorId) {\r
-      break;\r
-    }\r
-  }\r
-\r
-  *ProcessorNumber = Index;\r
-  return EFI_SUCCESS;\r
-}\r
-\r
-/**\r
-  Terminate AP's task and set it to idle state.\r
-\r
-  This function terminates AP's task due to timeout by sending INIT-SIPI,\r
-  and sends it to idle state.\r
-\r
-  @param CpuData           the pointer to CPU_DATA_BLOCK of specified AP\r
-\r
-**/\r
-VOID\r
-ResetProcessorToIdleState (\r
-  IN CPU_DATA_BLOCK  *CpuData\r
-  )\r
-{\r
-  ResetApStackless ((UINT32)CpuData->Info.ProcessorId);\r
-}\r
-\r
-/**\r
-  Application Processors do loop routine\r
-  after switch to its own stack.\r
-\r
-  @param  Context1    A pointer to the context to pass into the function.\r
-  @param  Context2    A pointer to the context to pass into the function.\r
-\r
-**/\r
-VOID\r
-ProcessorToIdleState (\r
-  IN      VOID                      *Context1,  OPTIONAL\r
-  IN      VOID                      *Context2   OPTIONAL\r
-  )\r
-{\r
-  UINTN                 ProcessorNumber;\r
-  CPU_DATA_BLOCK        *CpuData;\r
-  EFI_AP_PROCEDURE      Procedure;\r
-  VOID                  *ProcedureArgument;\r
-\r
-  AsmApDoneWithCommonStack ();\r
-\r
-  while (!mAPsAlreadyInitFinished) {\r
-    CpuPause ();\r
-  }\r
-\r
-  WhoAmI (&mMpServicesTemplate, &ProcessorNumber);\r
-  CpuData = &mMpSystemData.CpuDatas[ProcessorNumber];\r
-\r
-  //\r
-  // Avoid forcibly reset AP caused the AP got lock not release.\r
-  //\r
-  if (CpuData->LockSelf == (INTN) GetApicId ()) {\r
-    ReleaseSpinLock (&CpuData->CpuDataLock);\r
-  }\r
-\r
-  //\r
-  // Avoid forcibly reset AP caused the AP State is not updated.\r
-  //\r
-  GetMpSpinLock (CpuData);\r
-  CpuData->State = CpuStateIdle;\r
-  CpuData->Procedure = NULL;\r
-  ReleaseMpSpinLock (CpuData);\r
-\r
-  while (TRUE) {\r
-    GetMpSpinLock (CpuData);\r
-    ProcedureArgument = CpuData->Parameter;\r
-    Procedure = CpuData->Procedure;\r
-    ReleaseMpSpinLock (CpuData);\r
-\r
-    if (Procedure != NULL) {\r
-      Procedure (ProcedureArgument);\r
-\r
-      GetMpSpinLock (CpuData);\r
-      CpuData->Procedure = NULL;\r
-      CpuData->State = CpuStateFinished;\r
-      ReleaseMpSpinLock (CpuData);\r
-    }\r
-\r
-    CpuPause ();\r
-  }\r
-\r
-  CpuSleep ();\r
-  CpuDeadLoop ();\r
-}\r
-\r
-/**\r
-  Checks AP' status periodically.\r
-\r
-  This function is triggerred by timer perodically to check the\r
-  state of AP forStartupThisAP() executed in non-blocking mode.\r
-\r
-  @param  Event    Event triggered.\r
-  @param  Context  Parameter passed with the event.\r
-\r
-**/\r
-VOID\r
-EFIAPI\r
-CheckThisAPStatus (\r
-  IN  EFI_EVENT        Event,\r
-  IN  VOID             *Context\r
-  )\r
-{\r
-  CPU_DATA_BLOCK  *CpuData;\r
-  CPU_STATE       CpuState;\r
-\r
-  CpuData = (CPU_DATA_BLOCK *) Context;\r
-  if (CpuData->TimeoutActive) {\r
-    CpuData->Timeout -= gPollInterval;\r
-  }\r
-\r
-  CpuState = GetApState (CpuData);\r
-\r
-  if (CpuState == CpuStateFinished) {\r
-    if (CpuData->Finished) {\r
-      *CpuData->Finished = TRUE;\r
-    }\r
-    SetApState (CpuData, CpuStateIdle);\r
-    goto out;\r
-  }\r
-\r
-  if (CpuData->TimeoutActive && CpuData->Timeout < 0) {\r
-    if (CpuState != CpuStateIdle &&\r
-        CpuData->Finished) {\r
-      *CpuData->Finished = FALSE;\r
-    }\r
-    ResetProcessorToIdleState (CpuData);\r
-    goto out;\r
-  }\r
-\r
-  return;\r
-\r
-out:\r
-  CpuData->TimeoutActive = FALSE;\r
-  gBS->SignalEvent (CpuData->WaitEvent);\r
-  CpuData->WaitEvent = NULL;\r
+  return MpInitLibWhoAmI (ProcessorNumber);;\r
 }\r
 \r
 /**\r
-  Checks APs' status periodically.\r
+  Collects BIST data from HOB.\r
 \r
-  This function is triggerred by timer perodically to check the\r
-  state of APs for StartupAllAPs() executed in non-blocking mode.\r
-\r
-  @param  Event    Event triggered.\r
-  @param  Context  Parameter passed with the event.\r
+  This function collects BIST data from HOB built from Sec Platform Information\r
+  PPI or SEC Platform Information2 PPI.\r
 \r
 **/\r
 VOID\r
-EFIAPI\r
-CheckAllAPsStatus (\r
-  IN  EFI_EVENT        Event,\r
-  IN  VOID             *Context\r
+CollectBistDataFromHob (\r
+  VOID\r
   )\r
 {\r
-  CPU_DATA_BLOCK *CpuData;\r
-  UINTN          Number;\r
-  EFI_STATUS     Status;\r
-\r
-  if (mMpSystemData.TimeoutActive) {\r
-    mMpSystemData.Timeout -= gPollInterval;\r
-  }\r
-\r
-  if (mStopCheckAllAPsStatus) {\r
-    return;\r
-  }\r
+  EFI_HOB_GUID_TYPE                     *GuidHob;\r
+  EFI_SEC_PLATFORM_INFORMATION_RECORD2  *SecPlatformInformation2;\r
+  EFI_SEC_PLATFORM_INFORMATION_RECORD   *SecPlatformInformation;\r
+  UINTN                                 NumberOfData;\r
+  EFI_SEC_PLATFORM_INFORMATION_CPU      *CpuInstance;\r
+  EFI_SEC_PLATFORM_INFORMATION_CPU      BspCpuInstance;\r
+  UINTN                                 ProcessorNumber;\r
+  EFI_PROCESSOR_INFORMATION             ProcessorInfo;\r
+  EFI_HEALTH_FLAGS                      BistData;\r
+  UINTN                                 CpuInstanceNumber;\r
+\r
+  SecPlatformInformation2 = NULL;\r
+  SecPlatformInformation  = NULL;\r
 \r
   //\r
-  // avoid next timer enter.\r
+  // Get gEfiSecPlatformInformation2PpiGuid Guided HOB firstly\r
   //\r
-  Status = gBS->SetTimer (\r
-                  mMpSystemData.CheckAllAPsEvent,\r
-                  TimerCancel,\r
-                  0\r
-                  );\r
-  ASSERT_EFI_ERROR (Status);\r
-\r
-  if (mMpSystemData.WaitEvent != NULL) {\r
-    CheckAndUpdateAllAPsToIdleState ();\r
+  GuidHob = GetFirstGuidHob (&gEfiSecPlatformInformation2PpiGuid);\r
+  if (GuidHob != NULL) {\r
+    //\r
+    // Sec Platform Information2 PPI includes BSP/APs' BIST information\r
+    //\r
+    SecPlatformInformation2 = GET_GUID_HOB_DATA (GuidHob);\r
+    NumberOfData = SecPlatformInformation2->NumberOfCpus;\r
+    CpuInstance  = SecPlatformInformation2->CpuInstance;\r
+  } else {\r
     //\r
-    // task timeout\r
+    // Otherwise, get gEfiSecPlatformInformationPpiGuid Guided HOB\r
     //\r
-    if (mMpSystemData.TimeoutActive && mMpSystemData.Timeout < 0) {\r
-      ResetAllFailedAPs();\r
+    GuidHob = GetFirstGuidHob (&gEfiSecPlatformInformationPpiGuid);\r
+    if (GuidHob != NULL) {\r
+      SecPlatformInformation = GET_GUID_HOB_DATA (GuidHob);\r
+      NumberOfData = 1;\r
       //\r
-      // force exit\r
+      // SEC Platform Information only includes BSP's BIST information\r
+      // does not have BSP's APIC ID\r
       //\r
-      mMpSystemData.FinishCount = mMpSystemData.StartCount;\r
-    }\r
-\r
-    if (mMpSystemData.FinishCount != mMpSystemData.StartCount) {\r
-      goto EXIT;\r
+      BspCpuInstance.CpuLocation = GetApicId ();\r
+      BspCpuInstance.InfoRecord.IA32HealthFlags.Uint32  = SecPlatformInformation->IA32HealthFlags.Uint32;\r
+      CpuInstance = &BspCpuInstance;\r
+    } else {\r
+      DEBUG ((EFI_D_INFO, "Does not find any HOB stored CPU BIST information!\n"));\r
+      //\r
+      // Does not find any HOB stored BIST information\r
+      //\r
+      return;\r
     }\r
-\r
-    mMpSystemData.TimeoutActive = FALSE;\r
-    gBS->SignalEvent (mMpSystemData.WaitEvent);\r
-    mMpSystemData.WaitEvent = NULL;\r
-    mStopCheckAllAPsStatus = TRUE;\r
-\r
-    goto EXIT;\r
   }\r
 \r
-  //\r
-  // check each AP status for StartupThisAP\r
-  //\r
-  for (Number = 0; Number < mMpSystemData.NumberOfProcessors; Number++) {\r
-    CpuData = &mMpSystemData.CpuDatas[Number];\r
-    if (CpuData->WaitEvent) {\r
-      CheckThisAPStatus (NULL, (VOID *)CpuData);\r
+  for (ProcessorNumber = 0; ProcessorNumber < mNumberOfProcessors; ProcessorNumber++) {\r
+    MpInitLibGetProcessorInfo (ProcessorNumber, &ProcessorInfo, &BistData);\r
+    for (CpuInstanceNumber = 0; CpuInstanceNumber < NumberOfData; CpuInstanceNumber++) {\r
+      if (ProcessorInfo.ProcessorId == CpuInstance[CpuInstanceNumber].CpuLocation) {\r
+        //\r
+        // Update CPU health status for MP Services Protocol according to BIST data.\r
+        //\r
+        BistData = CpuInstance[CpuInstanceNumber].InfoRecord.IA32HealthFlags;\r
+      }\r
+    }\r
+    if (BistData.Uint32 != 0) {\r
+      //\r
+      // Report Status Code that self test is failed\r
+      //\r
+      REPORT_STATUS_CODE (\r
+        EFI_ERROR_CODE | EFI_ERROR_MAJOR,\r
+        (EFI_COMPUTING_UNIT_HOST_PROCESSOR | EFI_CU_HP_EC_SELF_TEST)\r
+        );\r
     }\r
   }\r
-\r
-EXIT:\r
-  Status = gBS->SetTimer (\r
-                  mMpSystemData.CheckAllAPsEvent,\r
-                  TimerPeriodic,\r
-                  EFI_TIMER_PERIOD_MICROSECONDS (100)\r
-                  );\r
-  ASSERT_EFI_ERROR (Status);\r
 }\r
 \r
 /**\r
-  Application Processor C code entry point.\r
+  Initialize Multi-processor support.\r
 \r
 **/\r
 VOID\r
-EFIAPI\r
-ApEntryPointInC (\r
-  VOID\r
-  )\r
-{\r
-  VOID*           TopOfApStack;\r
-  UINTN           ProcessorNumber;\r
-\r
-  if (!mAPsAlreadyInitFinished) {\r
-    FillInProcessorInformation (FALSE, mMpSystemData.NumberOfProcessors);\r
-    TopOfApStack  = (UINT8*)mApStackStart + gApStackSize;\r
-    mApStackStart = TopOfApStack;\r
-\r
-    //\r
-    // Store the Stack address, when reset the AP, We can found the original address.\r
-    //\r
-    mMpSystemData.CpuDatas[mMpSystemData.NumberOfProcessors].TopOfStack = TopOfApStack;\r
-    mMpSystemData.NumberOfProcessors++;\r
-    mMpSystemData.NumberOfEnabledProcessors++;\r
-  } else {\r
-    WhoAmI (&mMpServicesTemplate, &ProcessorNumber);\r
-    //\r
-    // Get the original stack address.\r
-    //\r
-    TopOfApStack = mMpSystemData.CpuDatas[ProcessorNumber].TopOfStack;\r
-  }\r
-\r
-  SwitchStack (\r
-    (SWITCH_STACK_ENTRY_POINT)(UINTN)ProcessorToIdleState,\r
-    NULL,\r
-    NULL,\r
-    TopOfApStack);\r
-}\r
-\r
-/**\r
-  This function is called by all processors (both BSP and AP) once and collects MP related data.\r
-\r
-  @param Bsp             TRUE if the CPU is BSP\r
-  @param ProcessorNumber The specific processor number\r
-\r
-  @retval EFI_SUCCESS    Data for the processor collected and filled in\r
-\r
-**/\r
-EFI_STATUS\r
-FillInProcessorInformation (\r
-  IN     BOOLEAN              Bsp,\r
-  IN     UINTN                ProcessorNumber\r
-  )\r
-{\r
-  CPU_DATA_BLOCK  *CpuData;\r
-  UINT32          ProcessorId;\r
-\r
-  CpuData = &mMpSystemData.CpuDatas[ProcessorNumber];\r
-  ProcessorId  = GetApicId ();\r
-  CpuData->Info.ProcessorId  = ProcessorId;\r
-  CpuData->Info.StatusFlag   = PROCESSOR_ENABLED_BIT | PROCESSOR_HEALTH_STATUS_BIT;\r
-  if (Bsp) {\r
-    CpuData->Info.StatusFlag |= PROCESSOR_AS_BSP_BIT;\r
-  }\r
-  CpuData->Info.Location.Package = ProcessorId;\r
-  CpuData->Info.Location.Core    = 0;\r
-  CpuData->Info.Location.Thread  = 0;\r
-  CpuData->State = Bsp ? CpuStateBuzy : CpuStateIdle;\r
-\r
-  CpuData->Procedure        = NULL;\r
-  CpuData->Parameter        = NULL;\r
-  InitializeSpinLock (&CpuData->CpuDataLock);\r
-  CpuData->LockSelf         = -1;\r
-\r
-  return EFI_SUCCESS;\r
-}\r
-\r
-/**\r
-  Prepare the System Data.\r
-\r
-  @retval EFI_SUCCESS     the System Data finished initilization.\r
-\r
-**/\r
-EFI_STATUS\r
-InitMpSystemData (\r
+InitializeMpSupport (\r
   VOID\r
   )\r
 {\r
   EFI_STATUS     Status;\r
-\r
-  ZeroMem (&mMpSystemData, sizeof (MP_SYSTEM_DATA));\r
-\r
-  mMpSystemData.NumberOfProcessors = 1;\r
-  mMpSystemData.NumberOfEnabledProcessors = 1;\r
-\r
-  mMpSystemData.CpuDatas = AllocateZeroPool (sizeof (CPU_DATA_BLOCK) * gMaxLogicalProcessorNumber);\r
-  ASSERT(mMpSystemData.CpuDatas != NULL);\r
-\r
-  Status = gBS->CreateEvent (\r
-                  EVT_TIMER | EVT_NOTIFY_SIGNAL,\r
-                  TPL_CALLBACK,\r
-                  CheckAllAPsStatus,\r
-                  NULL,\r
-                  &mMpSystemData.CheckAllAPsEvent\r
-                  );\r
-  ASSERT_EFI_ERROR (Status);\r
+  UINTN          NumberOfProcessors;\r
+  UINTN          NumberOfEnabledProcessors;\r
 \r
   //\r
-  // Set timer to check all APs status.\r
+  // Wakeup APs to do initialization\r
   //\r
-  Status = gBS->SetTimer (\r
-                  mMpSystemData.CheckAllAPsEvent,\r
-                  TimerPeriodic,\r
-                  EFI_TIMER_PERIOD_MICROSECONDS (100)\r
-                  );\r
+  Status = MpInitLibInitialize ();\r
   ASSERT_EFI_ERROR (Status);\r
 \r
-  //\r
-  // BSP\r
-  //\r
-  FillInProcessorInformation (TRUE, 0);\r
-\r
-  return EFI_SUCCESS;\r
-}\r
-\r
-/**\r
-  Initialize Multi-processor support.\r
-\r
-**/\r
-VOID\r
-InitializeMpSupport (\r
-  VOID\r
-  )\r
-{\r
-  gMaxLogicalProcessorNumber = (UINTN) PcdGet32 (PcdCpuMaxLogicalProcessorNumber);\r
-  if (gMaxLogicalProcessorNumber < 1) {\r
-    DEBUG ((DEBUG_ERROR, "Setting PcdCpuMaxLogicalProcessorNumber should be more than zero.\n"));\r
-    return;\r
-  }\r
-\r
-  if (gMaxLogicalProcessorNumber == 1) {\r
-    return;\r
-  }\r
-\r
-  gApStackSize = (UINTN) PcdGet32 (PcdCpuApStackSize);\r
-  ASSERT ((gApStackSize & (SIZE_4KB - 1)) == 0);\r
-\r
-  mApStackStart = AllocatePages (EFI_SIZE_TO_PAGES (gMaxLogicalProcessorNumber * gApStackSize));\r
-  ASSERT (mApStackStart != NULL);\r
+  MpInitLibGetNumberOfProcessors (&NumberOfProcessors, &NumberOfEnabledProcessors);\r
+  mNumberOfProcessors = NumberOfProcessors;\r
+  DEBUG ((EFI_D_ERROR, "Detect CPU count: %d\n", mNumberOfProcessors));\r
 \r
   //\r
-  // the first buffer of stack size used for common stack, when the amount of AP\r
-  // more than 1, we should never free the common stack which maybe used for AP reset.\r
+  // Update CPU healthy information from Guided HOB\r
   //\r
-  mCommonStack = mApStackStart;\r
-  mTopOfApCommonStack = (UINT8*) mApStackStart + gApStackSize;\r
-  mApStackStart = mTopOfApCommonStack;\r
-\r
-  InitMpSystemData ();\r
-\r
-  PrepareAPStartupCode ();\r
-\r
-  StartApsStackless ();\r
-\r
-  DEBUG ((DEBUG_INFO, "Detect CPU count: %d\n", mMpSystemData.NumberOfProcessors));\r
-  if (mMpSystemData.NumberOfProcessors == 1) {\r
-    FreeApStartupCode ();\r
-    FreePages (mCommonStack, EFI_SIZE_TO_PAGES (gMaxLogicalProcessorNumber * gApStackSize));\r
-    return;\r
-  }\r
-\r
-  mMpSystemData.CpuDatas = ReallocatePool (\r
-                             sizeof (CPU_DATA_BLOCK) * gMaxLogicalProcessorNumber,\r
-                             sizeof (CPU_DATA_BLOCK) * mMpSystemData.NumberOfProcessors,\r
-                             mMpSystemData.CpuDatas);\r
+  CollectBistDataFromHob ();\r
 \r
-  mAPsAlreadyInitFinished = TRUE;\r
-\r
-  if (mMpSystemData.NumberOfProcessors < gMaxLogicalProcessorNumber) {\r
-    FreePages (mApStackStart, EFI_SIZE_TO_PAGES (\r
-                                (gMaxLogicalProcessorNumber - mMpSystemData.NumberOfProcessors) *\r
-                                gApStackSize));\r
-  }\r
+  Status = gBS->InstallMultipleProtocolInterfaces (\r
+                  &mMpServiceHandle,\r
+                  &gEfiMpServiceProtocolGuid,  &mMpServicesTemplate,\r
+                  NULL\r
+                  );\r
+  ASSERT_EFI_ERROR (Status);\r
 }\r
+\r