Revision: 19363
          http://sourceforge.net/p/edk2/code/19363
Author:   vanjeff
Date:     2015-12-18 05:51:24 +0000 (Fri, 18 Dec 2015)
Log Message:
-----------
UefiCpuPkg/CpuMpPei: Wake up APs by proper method

If ApLoopMode is ApInHltLoop, BSP will send INIT-SIPI-SIPI to wake up APs.
If ApLoopMode is ApInMwaitLoop or ApInRunLoop, BSP will write one semaphore to
wake up APs.

(Sync patch r19346 from main trunk.)

Contributed-under: TianoCore Contribution Agreement 1.0
Cc: Feng Tian <[email protected]>
Cc: Michael Kinney <[email protected]>
Cc: Jordan Justen <[email protected]>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jeff Fan <[email protected]>
Tested-by: Michael Kinney <[email protected]>
Reviewed-by: Michael Kinney <[email protected]>

Revision Links:
--------------
    http://sourceforge.net/p/edk2/code/19346

Modified Paths:
--------------
    branches/UDK2015/UefiCpuPkg/CpuMpPei/CpuMpPei.c
    branches/UDK2015/UefiCpuPkg/CpuMpPei/CpuMpPei.h
    branches/UDK2015/UefiCpuPkg/CpuMpPei/CpuMpPei.inf
    branches/UDK2015/UefiCpuPkg/CpuMpPei/PeiMpServices.c

Modified: branches/UDK2015/UefiCpuPkg/CpuMpPei/CpuMpPei.c
===================================================================
--- branches/UDK2015/UefiCpuPkg/CpuMpPei/CpuMpPei.c     2015-12-18 05:50:19 UTC 
(rev 19362)
+++ branches/UDK2015/UefiCpuPkg/CpuMpPei/CpuMpPei.c     2015-12-18 05:51:24 UTC 
(rev 19363)
@@ -399,7 +399,7 @@
   @param PeiCpuMpData       Pointer to PEI CPU MP Data
   @param Broadcast          TRUE:  Send broadcast IPI to all APs
                             FALSE: Send IPI to AP by ApicId
-  @param ApicId             Apic ID for the processor to be waked
+  @param ProcessorNumber    The handle number of specified processor
   @param Procedure          The function to be invoked by AP
   @param ProcedureArgument  The argument to be passed into AP function
 **/
@@ -407,12 +407,13 @@
 WakeUpAP (
   IN PEI_CPU_MP_DATA           *PeiCpuMpData,
   IN BOOLEAN                   Broadcast,
-  IN UINT32                    ApicId,
+  IN UINTN                     ProcessorNumber,
   IN EFI_AP_PROCEDURE          Procedure,              OPTIONAL
   IN VOID                      *ProcedureArgument      OPTIONAL
   )
 {
   volatile MP_CPU_EXCHANGE_INFO    *ExchangeInfo;
+  UINTN                            Index;
 
   PeiCpuMpData->ApFunction         = (UINTN) Procedure;
   PeiCpuMpData->ApFunctionArgument = (UINTN) ProcedureArgument;
@@ -436,12 +437,40 @@
   CopyMem ((VOID *)&ExchangeInfo->GdtrProfile, &mGdt, sizeof(mGdt));
   AsmReadIdtr ((IA32_DESCRIPTOR *) &ExchangeInfo->IdtrProfile);
 
-  if (Broadcast) {
-    SendInitSipiSipiAllExcludingSelf ((UINT32) ExchangeInfo->BufferStart);
+  if (PeiCpuMpData->ApLoopMode == ApInMwaitLoop) {
+    //
+    // Get AP target C-state each time when waking up AP,
+    // for it maybe updated by platform again
+    //
+    PeiCpuMpData->ApTargetCState = PcdGet8 (PcdCpuApTargetCstate);
+  }
+
+  //
+  // Wakeup APs per AP loop state
+  //
+  if (PeiCpuMpData->ApLoopMode == ApInHltLoop || PeiCpuMpData->InitFlag) {
+    if (Broadcast) {
+      SendInitSipiSipiAllExcludingSelf ((UINT32) ExchangeInfo->BufferStart);
+    } else {
+      SendInitSipiSipi (
+        PeiCpuMpData->CpuData[ProcessorNumber].ApicId,
+        (UINT32) ExchangeInfo->BufferStart
+        );
+    }
+  } else if ((PeiCpuMpData->ApLoopMode == ApInMwaitLoop) ||
+             (PeiCpuMpData->ApLoopMode == ApInRunLoop)) {
+    if (Broadcast) {
+      for (Index = 0; Index < PeiCpuMpData->CpuCount; Index++) {
+        if (Index != PeiCpuMpData->BspNumber) {
+          *(PeiCpuMpData->CpuData[Index].StartupApSignal) = WAKEUP_AP_SIGNAL;
+        }
+      }
+    } else {
+      *(PeiCpuMpData->CpuData[ProcessorNumber].StartupApSignal) = 
WAKEUP_AP_SIGNAL;
+    }
   } else {
-    SendInitSipiSipi (ApicId, (UINT32) ExchangeInfo->BufferStart);
+    ASSERT (FALSE);
   }
-
   return ;
 }
 
@@ -600,7 +629,7 @@
     if (PeiCpuMpData->X2ApicEnable) {
       DEBUG ((EFI_D_INFO, "Force x2APIC mode!\n"));
       //
-      // Send 2nd broadcast IPI to all APs to enable x2APIC mode
+      // Wakeup all APs to enable x2APIC mode
       //
       WakeUpAP (PeiCpuMpData, TRUE, 0, ApFuncEnableX2Apic, NULL);
       //

Modified: branches/UDK2015/UefiCpuPkg/CpuMpPei/CpuMpPei.h
===================================================================
--- branches/UDK2015/UefiCpuPkg/CpuMpPei/CpuMpPei.h     2015-12-18 05:50:19 UTC 
(rev 19362)
+++ branches/UDK2015/UefiCpuPkg/CpuMpPei/CpuMpPei.h     2015-12-18 05:51:24 UTC 
(rev 19363)
@@ -255,7 +255,7 @@
   @param PeiCpuMpData       Pointer to PEI CPU MP Data
   @param Broadcast          TRUE:  Send broadcast IPI to all APs
                             FALSE: Send IPI to AP by ApicId
-  @param ApicId             Apic ID for the processor to be waked
+  @param ProcessorNumber    The handle number of specified processor
   @param Procedure          The function to be invoked by AP
   @param ProcedureArgument  The argument to be passed into AP function
 **/
@@ -263,7 +263,7 @@
 WakeUpAP (
   IN PEI_CPU_MP_DATA           *PeiCpuMpData,
   IN BOOLEAN                   Broadcast,
-  IN UINT32                    ApicId,
+  IN UINTN                     ProcessorNumber,
   IN EFI_AP_PROCEDURE          Procedure,              OPTIONAL
   IN VOID                      *ProcedureArgument      OPTIONAL
   );

Modified: branches/UDK2015/UefiCpuPkg/CpuMpPei/CpuMpPei.inf
===================================================================
--- branches/UDK2015/UefiCpuPkg/CpuMpPei/CpuMpPei.inf   2015-12-18 05:50:19 UTC 
(rev 19362)
+++ branches/UDK2015/UefiCpuPkg/CpuMpPei/CpuMpPei.inf   2015-12-18 05:51:24 UTC 
(rev 19363)
@@ -83,6 +83,7 @@
   gUefiCpuPkgTokenSpaceGuid.PcdCpuMicrocodePatchAddress            ## CONSUMES
   gUefiCpuPkgTokenSpaceGuid.PcdCpuMicrocodePatchRegionSize         ## CONSUMES
   gUefiCpuPkgTokenSpaceGuid.PcdCpuApLoopMode                       ## CONSUMES
+  gUefiCpuPkgTokenSpaceGuid.PcdCpuApTargetCstate                   ## 
SOMETIMES_CONSUMES
 
 [Depex]
   gEfiPeiMemoryDiscoveredPpiGuid

Modified: branches/UDK2015/UefiCpuPkg/CpuMpPei/PeiMpServices.c
===================================================================
--- branches/UDK2015/UefiCpuPkg/CpuMpPei/PeiMpServices.c        2015-12-18 
05:50:19 UTC (rev 19362)
+++ branches/UDK2015/UefiCpuPkg/CpuMpPei/PeiMpServices.c        2015-12-18 
05:51:24 UTC (rev 19363)
@@ -520,7 +520,7 @@
       if (Index == CallerNumber) {
         continue;
       }
-      WakeUpAP (PeiCpuMpData, FALSE, PeiCpuMpData->CpuData[Index].ApicId, 
Procedure, ProcedureArgument);
+      WakeUpAP (PeiCpuMpData, FALSE, Index, Procedure, ProcedureArgument);
       //
       // Wait to finish
       //
@@ -655,7 +655,7 @@
   WaitCountIndex = 0;
   FinishedCount = &PeiCpuMpData->FinishedCount;
 
-  WakeUpAP (PeiCpuMpData, FALSE, 
PeiCpuMpData->CpuData[ProcessorNumber].ApicId, Procedure, ProcedureArgument);
+  WakeUpAP (PeiCpuMpData, FALSE, ProcessorNumber, Procedure, 
ProcedureArgument);
 
   //
   // Wait to finish
@@ -791,7 +791,7 @@
   //
   // Need to wakeUp AP (future BSP).
   //
-  WakeUpAP (PeiCpuMpData, FALSE, 
PeiCpuMpData->CpuData[ProcessorNumber].ApicId, FutureBSPProc, PeiCpuMpData);
+  WakeUpAP (PeiCpuMpData, FALSE, ProcessorNumber, FutureBSPProc, PeiCpuMpData);
 
   AsmExchangeRole (&PeiCpuMpData->BSPInfo, &PeiCpuMpData->APInfo);
 


------------------------------------------------------------------------------
_______________________________________________
edk2-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/edk2-commits

Reply via email to