Revision: 18824
          http://sourceforge.net/p/edk2/code/18824
Author:   vanjeff
Date:     2015-11-17 04:50:47 +0000 (Tue, 17 Nov 2015)
Log Message:
-----------
UefiCpuPkg: Update CPU MP drivers to support single CPU configuration

Only perform AP detection if PcdCpuMaxLogicalProcessorNumber > 1
Only free AP related structures of they were allocated

(Sync patch r18629 from main trunk.)

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Michael Kinney <[email protected]>
Reviewed-by: Jeff Fan <[email protected]>

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

Modified Paths:
--------------
    branches/UDK2015/UefiCpuPkg/CpuDxe/CpuMp.c
    branches/UDK2015/UefiCpuPkg/CpuMpPei/CpuMpPei.c

Modified: branches/UDK2015/UefiCpuPkg/CpuDxe/CpuMp.c
===================================================================
--- branches/UDK2015/UefiCpuPkg/CpuDxe/CpuMp.c  2015-11-16 18:29:14 UTC (rev 
18823)
+++ branches/UDK2015/UefiCpuPkg/CpuDxe/CpuMp.c  2015-11-17 04:50:47 UTC (rev 
18824)
@@ -1642,35 +1642,40 @@
     return;
   }
 
-  if (gMaxLogicalProcessorNumber == 1) {
-    return;
-  }
 
-  gApStackSize = (UINTN) PcdGet32 (PcdCpuApStackSize);
-  ASSERT ((gApStackSize & (SIZE_4KB - 1)) == 0);
 
-  mApStackStart = AllocatePages (EFI_SIZE_TO_PAGES (gMaxLogicalProcessorNumber 
* gApStackSize));
-  ASSERT (mApStackStart != NULL);
+  InitMpSystemData ();
 
   //
-  // the first buffer of stack size used for common stack, when the amount of 
AP
-  // more than 1, we should never free the common stack which maybe used for 
AP reset.
+  // Only perform AP detection if PcdCpuMaxLogicalProcessorNumber is greater 
than 1
   //
-  mCommonStack = mApStackStart;
-  mTopOfApCommonStack = (UINT8*) mApStackStart + gApStackSize;
-  mApStackStart = mTopOfApCommonStack;
+  if (gMaxLogicalProcessorNumber > 1) {
 
-  InitMpSystemData ();
+    gApStackSize = (UINTN) PcdGet32 (PcdCpuApStackSize);
+    ASSERT ((gApStackSize & (SIZE_4KB - 1)) == 0);
 
-  PrepareAPStartupCode ();
+    mApStackStart = AllocatePages (EFI_SIZE_TO_PAGES 
(gMaxLogicalProcessorNumber * gApStackSize));
+    ASSERT (mApStackStart != NULL);
 
-  StartApsStackless ();
+    //
+    // the first buffer of stack size used for common stack, when the amount 
of AP
+    // more than 1, we should never free the common stack which maybe used for 
AP reset.
+    //
+    mCommonStack = mApStackStart;
+    mTopOfApCommonStack = (UINT8*) mApStackStart + gApStackSize;
+    mApStackStart = mTopOfApCommonStack;
 
+    PrepareAPStartupCode ();
+
+    StartApsStackless ();
+  }
+
   DEBUG ((DEBUG_INFO, "Detect CPU count: %d\n", 
mMpSystemData.NumberOfProcessors));
   if (mMpSystemData.NumberOfProcessors == 1) {
     FreeApStartupCode ();
-    FreePages (mCommonStack, EFI_SIZE_TO_PAGES (gMaxLogicalProcessorNumber * 
gApStackSize));
-    return;
+    if (mCommonStack != NULL) {
+      FreePages (mCommonStack, EFI_SIZE_TO_PAGES (gMaxLogicalProcessorNumber * 
gApStackSize));
+    }
   }
 
   mMpSystemData.CpuDatas = ReallocatePool (
@@ -1692,10 +1697,12 @@
                   );
   ASSERT_EFI_ERROR (Status);
 
-  if (mMpSystemData.NumberOfProcessors < gMaxLogicalProcessorNumber) {
-    FreePages (mApStackStart, EFI_SIZE_TO_PAGES (
-                                (gMaxLogicalProcessorNumber - 
mMpSystemData.NumberOfProcessors) *
-                                gApStackSize));
+  if (mMpSystemData.NumberOfProcessors > 1 && mMpSystemData.NumberOfProcessors 
< gMaxLogicalProcessorNumber) {
+    if (mApStackStart != NULL) {
+      FreePages (mApStackStart, EFI_SIZE_TO_PAGES (
+                                  (gMaxLogicalProcessorNumber - 
mMpSystemData.NumberOfProcessors) *
+                                  gApStackSize));
+    }
   }
 
   Status = gBS->CreateEvent (

Modified: branches/UDK2015/UefiCpuPkg/CpuMpPei/CpuMpPei.c
===================================================================
--- branches/UDK2015/UefiCpuPkg/CpuMpPei/CpuMpPei.c     2015-11-16 18:29:14 UTC 
(rev 18823)
+++ branches/UDK2015/UefiCpuPkg/CpuMpPei/CpuMpPei.c     2015-11-17 04:50:47 UTC 
(rev 18824)
@@ -357,22 +357,28 @@
   // Store BSP's MTRR setting
   //
   MtrrGetAllMtrrs (&PeiCpuMpData->MtrrTable);
+
   //
-  // Send broadcast IPI to APs to wakeup APs
+  // Only perform AP detection if PcdCpuMaxLogicalProcessorNumber is greater 
than 1
   //
-  PeiCpuMpData->InitFlag = 1;
-  WakeUpAP (PeiCpuMpData, TRUE, 0, NULL, NULL);
-  //
-  // Wait for AP task to complete and then exit.
-  //
-  MicroSecondDelay (PcdGet32 (PcdCpuApInitTimeOutInMicroSeconds));
-  PeiCpuMpData->InitFlag  = 0;
-  PeiCpuMpData->CpuCount += (UINT32) 
PeiCpuMpData->MpCpuExchangeInfo->NumApsExecuting;
-  ASSERT (PeiCpuMpData->CpuCount <= PcdGet32(PcdCpuMaxLogicalProcessorNumber));
-  //
-  // Sort BSP/Aps by CPU APIC ID in ascending order
-  //
-  SortApicId (PeiCpuMpData);
+  if (PcdGet32 (PcdCpuMaxLogicalProcessorNumber) > 1) {
+    //
+    // Send broadcast IPI to APs to wakeup APs
+    //
+    PeiCpuMpData->InitFlag = 1;
+    WakeUpAP (PeiCpuMpData, TRUE, 0, NULL, NULL);
+    //
+    // Wait for AP task to complete and then exit.
+    //
+    MicroSecondDelay (PcdGet32 (PcdCpuApInitTimeOutInMicroSeconds));
+    PeiCpuMpData->InitFlag = 0;
+    PeiCpuMpData->CpuCount += 
(UINT32)PeiCpuMpData->MpCpuExchangeInfo->NumApsExecuting;
+    ASSERT (PeiCpuMpData->CpuCount <= PcdGet32 
(PcdCpuMaxLogicalProcessorNumber));
+    //
+    // Sort BSP/Aps by CPU APIC ID in ascending order
+    //
+    SortApicId (PeiCpuMpData);
+  }
 
   DEBUG ((EFI_D_INFO, "CpuMpPei: Find %d processors in system.\n", 
PeiCpuMpData->CpuCount));
   return PeiCpuMpData->CpuCount;


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

Reply via email to