]> git.proxmox.com Git - mirror_edk2.git/blobdiff - UefiCpuPkg/Library/MpInitLib/MpLib.c
UefiCpuPkg/MpInitLib: Send INIT-SIPI-SIPI to get processor count
[mirror_edk2.git] / UefiCpuPkg / Library / MpInitLib / MpLib.c
index de169e68501efd89be46be7da314a69b9552be66..8f7cf43a7c9103fd15a5d7375a8dc31bcdb3fb0e 100644 (file)
@@ -268,6 +268,42 @@ GetProcessorNumber (
   return EFI_NOT_FOUND;\r
 }\r
 \r
+/**\r
+  This function will get CPU count in the system.\r
+\r
+  @param[in] CpuMpData        Pointer to PEI CPU MP Data\r
+\r
+  @return  CPU count detected\r
+**/\r
+UINTN\r
+CollectProcessorCount (\r
+  IN CPU_MP_DATA         *CpuMpData\r
+  )\r
+{\r
+  //\r
+  // Send 1st broadcast IPI to APs to wakeup APs\r
+  //\r
+  CpuMpData->InitFlag     = ApInitConfig;\r
+  CpuMpData->X2ApicEnable = FALSE;\r
+  WakeUpAP (CpuMpData, TRUE, 0, NULL, NULL);\r
+  //\r
+  // Wait for AP task to complete and then exit.\r
+  //\r
+  MicroSecondDelay (PcdGet32(PcdCpuApInitTimeOutInMicroSeconds));\r
+  CpuMpData->InitFlag = ApInitDone;\r
+  ASSERT (CpuMpData->CpuCount <= PcdGet32 (PcdCpuMaxLogicalProcessorNumber));\r
+  //\r
+  // Wait for all APs finished the initialization\r
+  //\r
+  while (CpuMpData->FinishedCount < (CpuMpData->CpuCount - 1)) {\r
+    CpuPause ();\r
+  }\r
+\r
+  DEBUG ((DEBUG_INFO, "MpInitLib: Find %d processors in system.\n", CpuMpData->CpuCount));\r
+\r
+  return CpuMpData->CpuCount;\r
+}\r
+\r
 /*\r
   Initialize CPU AP Data when AP is wakeup at the first time.\r
 \r
@@ -704,6 +740,10 @@ MpInitLibInitialize (
   MtrrGetAllMtrrs (&CpuMpData->MtrrTable);\r
 \r
 \r
+  //\r
+  // Wakeup all APs and calculate the processor count in system\r
+  //\r
+  CollectProcessorCount (CpuMpData);\r
   //\r
   // Initialize global data for MP support\r
   //\r