]> git.proxmox.com Git - mirror_edk2.git/blobdiff - UefiCpuPkg/CpuMpPei/CpuBist.c
BaseTool: Fixed the incorrect cache key.
[mirror_edk2.git] / UefiCpuPkg / CpuMpPei / CpuBist.c
index 2bee7a4a665becf232cd69dc27601131d20f2048..20728525e2d9f98ed0d126af4a94831b83fd8604 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Update and publish processors' BIST information.\r
 \r
-  Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2015 - 2018, 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
@@ -44,30 +44,29 @@ SecPlatformInformation2 (
      OUT EFI_SEC_PLATFORM_INFORMATION_RECORD2 *PlatformInformationRecord2\r
   )\r
 {\r
-  PEI_CPU_MP_DATA                      *PeiCpuMpData;\r
-  UINTN                                BistInformationSize;\r
-  UINTN                                CpuIndex;\r
-  EFI_SEC_PLATFORM_INFORMATION_CPU     *CpuInstance;\r
+  EFI_HOB_GUID_TYPE       *GuidHob;\r
+  VOID                    *DataInHob;\r
+  UINTN                   DataSize;\r
 \r
-  PeiCpuMpData = GetMpHobData ();\r
+  GuidHob = GetFirstGuidHob (&gEfiSecPlatformInformation2PpiGuid);\r
+  if (GuidHob == NULL) {\r
+    *StructureSize = 0;\r
+    return EFI_SUCCESS;\r
+  }\r
+\r
+  DataInHob = GET_GUID_HOB_DATA (GuidHob);\r
+  DataSize  = GET_GUID_HOB_DATA_SIZE (GuidHob);\r
 \r
-  BistInformationSize = sizeof (EFI_SEC_PLATFORM_INFORMATION_RECORD2) +\r
-                        sizeof (EFI_SEC_PLATFORM_INFORMATION_CPU) * PeiCpuMpData->CpuCount;\r
   //\r
-  // return the information size if input buffer size is too small\r
+  // return the information from BistHob\r
   //\r
-  if ((*StructureSize) < (UINT64) BistInformationSize) {\r
-    *StructureSize = (UINT64) BistInformationSize;\r
+  if ((*StructureSize) < (UINT64) DataSize) {\r
+    *StructureSize = (UINT64) DataSize;\r
     return EFI_BUFFER_TOO_SMALL;\r
   }\r
 \r
-  PlatformInformationRecord2->NumberOfCpus = PeiCpuMpData->CpuCount;\r
-  CpuInstance = PlatformInformationRecord2->CpuInstance;\r
-  for (CpuIndex = 0; CpuIndex < PeiCpuMpData->CpuCount; CpuIndex ++) {\r
-    CpuInstance[CpuIndex].CpuLocation                = PeiCpuMpData->CpuData[CpuIndex].ApicId;\r
-    CpuInstance[CpuIndex].InfoRecord.IA32HealthFlags = PeiCpuMpData->CpuData[CpuIndex].Health;\r
-  }\r
-\r
+  *StructureSize = (UINT64) DataSize;\r
+  CopyMem (PlatformInformationRecord2, DataInHob, DataSize);\r
   return EFI_SUCCESS;\r
 }\r
 \r
@@ -80,6 +79,7 @@ SecPlatformInformation2 (
   @param  PpiDescriptor       Return a pointer to instance of the\r
                               EFI_PEI_PPI_DESCRIPTOR\r
   @param  BistInformationData Pointer to BIST information data\r
+  @param  BistInformationSize Return the size in bytes of BIST information\r
 \r
   @retval EFI_SUCCESS         Retrieve of the BIST data successfully\r
   @retval EFI_NOT_FOUND       No sec platform information(2) ppi export\r
@@ -91,7 +91,8 @@ GetBistInfoFromPpi (
   IN CONST EFI_PEI_SERVICES     **PeiServices,\r
   IN CONST EFI_GUID             *Guid,\r
      OUT EFI_PEI_PPI_DESCRIPTOR **PpiDescriptor,\r
-     OUT VOID                   **BistInformationData\r
+     OUT VOID                   **BistInformationData,\r
+     OUT UINT64                 *BistInformationSize OPTIONAL\r
   )\r
 {\r
   EFI_STATUS                            Status;\r
@@ -136,6 +137,9 @@ GetBistInfoFromPpi (
                                                );\r
         if (Status == EFI_SUCCESS) {\r
           *BistInformationData = SecPlatformInformation2;\r
+          if (BistInformationSize != NULL) {\r
+            *BistInformationSize = InformationSize;\r
+          }\r
           return EFI_SUCCESS;\r
         }\r
       }\r
@@ -152,13 +156,11 @@ GetBistInfoFromPpi (
   or SEC Platform Information PPI.\r
 \r
   @param PeiServices         Pointer to PEI Services Table\r
-  @param PeiCpuMpData        Pointer to PEI CPU MP Data\r
 \r
 **/\r
 VOID\r
 CollectBistDataFromPpi (\r
-  IN CONST EFI_PEI_SERVICES             **PeiServices,\r
-  IN PEI_CPU_MP_DATA                    *PeiCpuMpData\r
+  IN CONST EFI_PEI_SERVICES             **PeiServices\r
   )\r
 {\r
   EFI_STATUS                            Status;\r
@@ -170,13 +172,30 @@ CollectBistDataFromPpi (
   EFI_SEC_PLATFORM_INFORMATION_CPU      BspCpuInstance;\r
   UINTN                                 ProcessorNumber;\r
   UINTN                                 CpuIndex;\r
-  PEI_CPU_DATA                          *CpuData;\r
+  EFI_PROCESSOR_INFORMATION             ProcessorInfo;\r
+  EFI_HEALTH_FLAGS                      BistData;\r
+  UINTN                                 NumberOfProcessors;\r
+  UINTN                                 NumberOfEnabledProcessors;\r
+  UINTN                                 BistInformationSize;\r
+  EFI_SEC_PLATFORM_INFORMATION_RECORD2  *PlatformInformationRecord2;\r
+  EFI_SEC_PLATFORM_INFORMATION_CPU      *CpuInstanceInHob;\r
+\r
+\r
+  MpInitLibGetNumberOfProcessors(&NumberOfProcessors, &NumberOfEnabledProcessors);\r
+\r
+  BistInformationSize = sizeof (EFI_SEC_PLATFORM_INFORMATION_RECORD2) +\r
+                        sizeof (EFI_SEC_PLATFORM_INFORMATION_CPU) * NumberOfProcessors;\r
+  Status = PeiServicesAllocatePool (\r
+             (UINTN) BistInformationSize,\r
+             (VOID **) &PlatformInformationRecord2\r
+             );\r
+  ASSERT_EFI_ERROR (Status);\r
+  PlatformInformationRecord2->NumberOfCpus = (UINT32)NumberOfProcessors;\r
 \r
   SecPlatformInformation2 = NULL;\r
   SecPlatformInformation  = NULL;\r
   NumberOfData            = 0;\r
   CpuInstance             = NULL;\r
-\r
   //\r
   // Get BIST information from Sec Platform Information2 Ppi firstly\r
   //\r
@@ -184,7 +203,8 @@ CollectBistDataFromPpi (
              PeiServices,\r
              &gEfiSecPlatformInformation2PpiGuid,\r
              &SecInformationDescriptor,\r
-             (VOID *) &SecPlatformInformation2\r
+             (VOID *) &SecPlatformInformation2,\r
+             NULL\r
              );\r
   if (Status == EFI_SUCCESS) {\r
     //\r
@@ -200,7 +220,8 @@ CollectBistDataFromPpi (
                PeiServices,\r
                &gEfiSecPlatformInformationPpiGuid,\r
                &SecInformationDescriptor,\r
-               (VOID *) &SecPlatformInformation\r
+               (VOID *) &SecPlatformInformation,\r
+               NULL\r
                );\r
     if (Status == EFI_SUCCESS) {\r
       NumberOfData = 1;\r
@@ -215,18 +236,18 @@ CollectBistDataFromPpi (
       DEBUG ((EFI_D_INFO, "Does not find any stored CPU BIST information from PPI!\n"));\r
     }\r
   }\r
-  for (ProcessorNumber = 0; ProcessorNumber < PeiCpuMpData->CpuCount; ProcessorNumber ++) {\r
-    CpuData = &PeiCpuMpData->CpuData[ProcessorNumber];\r
+  for (ProcessorNumber = 0; ProcessorNumber < NumberOfProcessors; ProcessorNumber ++) {\r
+    MpInitLibGetProcessorInfo (ProcessorNumber, &ProcessorInfo, &BistData);\r
     for (CpuIndex = 0; CpuIndex < NumberOfData; CpuIndex ++) {\r
       ASSERT (CpuInstance != NULL);\r
-      if (CpuData->ApicId == CpuInstance[CpuIndex].CpuLocation) {\r
+      if (ProcessorInfo.ProcessorId == CpuInstance[CpuIndex].CpuLocation) {\r
         //\r
         // Update processor's BIST data if it is already stored before\r
         //\r
-        CpuData->Health = CpuInstance[CpuIndex].InfoRecord.IA32HealthFlags;\r
+        BistData = CpuInstance[CpuIndex].InfoRecord.IA32HealthFlags;\r
       }\r
     }\r
-    if (CpuData->Health.Uint32 != 0) {\r
+    if (BistData.Uint32 != 0) {\r
       //\r
       // Report Status Code that self test is failed\r
       //\r
@@ -236,14 +257,27 @@ CollectBistDataFromPpi (
         );\r
     }\r
     DEBUG ((EFI_D_INFO, "  APICID - 0x%08x, BIST - 0x%08x\n",\r
-            PeiCpuMpData->CpuData[ProcessorNumber].ApicId,\r
-            PeiCpuMpData->CpuData[ProcessorNumber].Health.Uint32\r
+            (UINT32) ProcessorInfo.ProcessorId,\r
+            BistData\r
             ));\r
+    CpuInstanceInHob = PlatformInformationRecord2->CpuInstance;\r
+    CpuInstanceInHob[ProcessorNumber].CpuLocation = (UINT32) ProcessorInfo.ProcessorId;\r
+    CpuInstanceInHob[ProcessorNumber].InfoRecord.IA32HealthFlags = BistData;\r
   }\r
 \r
-  if (SecPlatformInformation2 != NULL && NumberOfData < PeiCpuMpData->CpuCount) {\r
+  //\r
+  // Build SecPlatformInformation2 PPI GUIDed HOB that also could be consumed\r
+  // by CPU MP driver to get CPU BIST data\r
+  //\r
+  BuildGuidDataHob (\r
+    &gEfiSecPlatformInformation2PpiGuid,\r
+    PlatformInformationRecord2,\r
+    (UINTN) BistInformationSize\r
+    );\r
+\r
+  if (SecPlatformInformation2 != NULL && NumberOfData < NumberOfProcessors) {\r
     //\r
-    // Reinstall SecPlatformInformation2 PPI to include new BIST inforamtion\r
+    // Reinstall SecPlatformInformation2 PPI to include new BIST information\r
     //\r
     Status = PeiServicesReInstallPpi (\r
                SecInformationDescriptor,\r
@@ -252,9 +286,10 @@ CollectBistDataFromPpi (
     ASSERT_EFI_ERROR (Status);\r
   } else {\r
     //\r
-    // Install SecPlatformInformation2 PPI to include new BIST inforamtion\r
+    // Install SecPlatformInformation2 PPI to include new BIST information\r
     //\r
     Status = PeiServicesInstallPpi (&mPeiSecPlatformInformation2Ppi);\r
     ASSERT_EFI_ERROR(Status);\r
   }\r
 }\r
+\r