]> git.proxmox.com Git - mirror_edk2.git/blobdiff - UefiCpuPkg/CpuDxe/CpuMp.c
UefiCpuPkg: Update CPU MP drivers to support single CPU configuration
[mirror_edk2.git] / UefiCpuPkg / CpuDxe / CpuMp.c
index e5d2f5f7e28ece9b0796dd759830c1bd77c6dc43..da3686e2788e8c50f0652bd743a3a010c42e5a2e 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   CPU DXE Module.\r
 \r
-  Copyright (c) 2008 - 2014, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2008 - 2015, 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
@@ -1193,7 +1193,7 @@ ProcessorToIdleState (
   UINTN                 ProcessorNumber;\r
   CPU_DATA_BLOCK        *CpuData;\r
   EFI_AP_PROCEDURE      Procedure;\r
-  VOID                  *ProcedureArgument;\r
+  volatile VOID         *ProcedureArgument;\r
 \r
   AsmApDoneWithCommonStack ();\r
 \r
@@ -1231,7 +1231,7 @@ ProcessorToIdleState (
     if (Procedure != NULL) {\r
       SetApState (CpuData, CpuStateBusy);\r
 \r
-      Procedure (ProcedureArgument);\r
+      Procedure ((VOID*) ProcedureArgument);\r
 \r
       GetMpSpinLock (CpuData);\r
       CpuData->Procedure = NULL;\r
@@ -1520,6 +1520,89 @@ InitMpSystemData (
   return EFI_SUCCESS;\r
 }\r
 \r
+/**\r
+  Collects BIST data from HOB.\r
+\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
+CollectBistDataFromHob (\r
+  VOID\r
+  )\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
+  UINT32                                InitialLocalApicId;\r
+  CPU_DATA_BLOCK                        *CpuData;\r
+\r
+  SecPlatformInformation2 = NULL;\r
+  SecPlatformInformation  = NULL;\r
+\r
+  //\r
+  // Get gEfiSecPlatformInformation2PpiGuid Guided HOB firstly\r
+  //\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
+    // Otherwise, get gEfiSecPlatformInformationPpiGuid Guided HOB\r
+    //\r
+    GuidHob = GetFirstGuidHob (&gEfiSecPlatformInformationPpiGuid);\r
+    if (GuidHob != NULL) {\r
+      SecPlatformInformation = GET_GUID_HOB_DATA (GuidHob);\r
+      NumberOfData = 1;\r
+      //\r
+      // SEC Platform Information only includes BSP's BIST information\r
+      // does not have BSP's APIC ID\r
+      //\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
+\r
+  while ((NumberOfData--) > 0) {\r
+    for (ProcessorNumber = 0; ProcessorNumber < mMpSystemData.NumberOfProcessors; ProcessorNumber++) {\r
+      CpuData = &mMpSystemData.CpuDatas[ProcessorNumber];\r
+      InitialLocalApicId = (UINT32) CpuData->Info.ProcessorId;\r
+      if (InitialLocalApicId == CpuInstance[NumberOfData].CpuLocation) {\r
+        //\r
+        // Update CPU health status for MP Services Protocol according to BIST data.\r
+        //\r
+        if (CpuInstance[NumberOfData].InfoRecord.IA32HealthFlags.Uint32 != 0) {\r
+          CpuData->Info.StatusFlag &= ~PROCESSOR_HEALTH_STATUS_BIT;\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
+  }\r
+}\r
+\r
 /**\r
   Callback function for ExitBootServices.\r
 \r
@@ -1559,35 +1642,40 @@ InitializeMpSupport (
     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
+  InitMpSystemData ();\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
+  // Only perform AP detection if PcdCpuMaxLogicalProcessorNumber is greater than 1\r
   //\r
-  mCommonStack = mApStackStart;\r
-  mTopOfApCommonStack = (UINT8*) mApStackStart + gApStackSize;\r
-  mApStackStart = mTopOfApCommonStack;\r
+  if (gMaxLogicalProcessorNumber > 1) {\r
 \r
-  InitMpSystemData ();\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
+\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
+    //\r
+    mCommonStack = mApStackStart;\r
+    mTopOfApCommonStack = (UINT8*) mApStackStart + gApStackSize;\r
+    mApStackStart = mTopOfApCommonStack;\r
 \r
-  PrepareAPStartupCode ();\r
+    PrepareAPStartupCode ();\r
 \r
-  StartApsStackless ();\r
+    StartApsStackless ();\r
+  }\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
+    if (mCommonStack != NULL) {\r
+      FreePages (mCommonStack, EFI_SIZE_TO_PAGES (gMaxLogicalProcessorNumber * gApStackSize));\r
+    }\r
   }\r
 \r
   mMpSystemData.CpuDatas = ReallocatePool (\r
@@ -1597,6 +1685,11 @@ InitializeMpSupport (
 \r
   mAPsAlreadyInitFinished = TRUE;\r
 \r
+  //\r
+  // Update CPU healthy information from Guided HOB\r
+  //\r
+  CollectBistDataFromHob ();\r
+\r
   Status = gBS->InstallMultipleProtocolInterfaces (\r
                   &mMpServiceHandle,\r
                   &gEfiMpServiceProtocolGuid,  &mMpServicesTemplate,\r
@@ -1604,10 +1697,12 @@ InitializeMpSupport (
                   );\r
   ASSERT_EFI_ERROR (Status);\r
 \r
-  if (mMpSystemData.NumberOfProcessors < gMaxLogicalProcessorNumber) {\r
-    FreePages (mApStackStart, EFI_SIZE_TO_PAGES (\r
-                                (gMaxLogicalProcessorNumber - mMpSystemData.NumberOfProcessors) *\r
-                                gApStackSize));\r
+  if (mMpSystemData.NumberOfProcessors > 1 && mMpSystemData.NumberOfProcessors < gMaxLogicalProcessorNumber) {\r
+    if (mApStackStart != NULL) {\r
+      FreePages (mApStackStart, EFI_SIZE_TO_PAGES (\r
+                                  (gMaxLogicalProcessorNumber - mMpSystemData.NumberOfProcessors) *\r
+                                  gApStackSize));\r
+    }\r
   }\r
 \r
   Status = gBS->CreateEvent (\r