Get CPU BIST information from SEC Platform Information(2) PPIs and update them
accordingly. Install(Reinstall) SEC Platform Information2 PPI to published the
new CPU BIST.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jeff Fan <jeff....@intel.com>
CC: Feng Tian <feng.t...@intel.com>
CC: Jiewen Yao <jiewen....@intel.com>
CC: Michael Kinney <michael.d.kin...@intel.com>
---
 UefiCpuPkg/CpuMpPei/CpuBist.c    | 260 +++++++++++++++++++++++++++++++++++++++
 UefiCpuPkg/CpuMpPei/CpuMpPei.c   |   4 +
 UefiCpuPkg/CpuMpPei/CpuMpPei.h   |  48 ++++++++
 UefiCpuPkg/CpuMpPei/CpuMpPei.inf |   7 ++
 4 files changed, 319 insertions(+)
 create mode 100644 UefiCpuPkg/CpuMpPei/CpuBist.c

diff --git a/UefiCpuPkg/CpuMpPei/CpuBist.c b/UefiCpuPkg/CpuMpPei/CpuBist.c
new file mode 100644
index 0000000..579b6b0
--- /dev/null
+++ b/UefiCpuPkg/CpuMpPei/CpuBist.c
@@ -0,0 +1,260 @@
+/** @file
+  Update and publish processors' BIST information.
+
+  Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>
+  This program and the accompanying materials
+  are licensed and made available under the terms and conditions of the BSD 
License
+  which accompanies this distribution.  The full text of the license may be 
found at
+  http://opensource.org/licenses/bsd-license.php
+
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+**/
+
+#include "CpuMpPei.h"
+
+EFI_SEC_PLATFORM_INFORMATION2_PPI mSecPlatformInformation2Ppi = {
+  SecPlatformInformation2
+};
+
+EFI_PEI_PPI_DESCRIPTOR mPeiSecPlatformInformation2Ppi = {
+  (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),
+  &gEfiSecPlatformInformation2PpiGuid,
+  &mSecPlatformInformation2Ppi
+};
+
+/**
+  Implementation of the PlatformInformation2 service in 
EFI_SEC_PLATFORM_INFORMATION2_PPI.
+
+  @param  PeiServices                The pointer to the PEI Services Table.
+  @param  StructureSize              The pointer to the variable describing 
size of the input buffer.
+  @param  PlatformInformationRecord2 The pointer to the 
EFI_SEC_PLATFORM_INFORMATION_RECORD2.
+
+  @retval EFI_SUCCESS                The data was successfully returned.
+  @retval EFI_BUFFER_TOO_SMALL       The buffer was too small. The current 
buffer size needed to
+                                     hold the record is returned in 
StructureSize.
+
+**/
+EFI_STATUS
+EFIAPI
+SecPlatformInformation2 (
+  IN CONST EFI_PEI_SERVICES                   **PeiServices,
+  IN OUT UINT64                               *StructureSize,
+     OUT EFI_SEC_PLATFORM_INFORMATION_RECORD2 *PlatformInformationRecord2
+  )
+{
+  PEI_CPU_MP_DATA                      *PeiCpuMpData;
+  UINTN                                BistInformationSize;
+  UINTN                                CpuIndex;
+  EFI_SEC_PLATFORM_INFORMATION_CPU     *CpuInstance;
+
+  PeiCpuMpData = GetMpHobData ();
+
+  BistInformationSize = sizeof (EFI_SEC_PLATFORM_INFORMATION_RECORD2) +
+                        sizeof (EFI_SEC_PLATFORM_INFORMATION_CPU) * 
PeiCpuMpData->CpuCount;
+  //
+  // return the information size if input buffer size is too small
+  //
+  if ((*StructureSize) < (UINT64) BistInformationSize) {
+    *StructureSize = (UINT64) BistInformationSize;
+    return EFI_BUFFER_TOO_SMALL;
+  }
+
+  PlatformInformationRecord2->NumberOfCpus = PeiCpuMpData->CpuCount;
+  CpuInstance = PlatformInformationRecord2->CpuInstance;
+  for (CpuIndex = 0; CpuIndex < PeiCpuMpData->CpuCount; CpuIndex ++) {
+    CpuInstance[CpuIndex].CpuLocation                = 
PeiCpuMpData->CpuData[CpuIndex].ApicId;
+    CpuInstance[CpuIndex].InfoRecord.IA32HealthFlags = 
PeiCpuMpData->CpuData[CpuIndex].Health;
+  }
+
+  return EFI_SUCCESS;
+}
+
+/**
+  Worker function to get CPUs' BIST by calling SecPlatformInformationPpi
+  or SecPlatformInformation2Ppi.
+
+  @param  PeiServices         Pointer to PEI Services Table
+  @param  Guid                PPI Guid
+  @param  PpiDescriptor       Return a pointer to instance of the
+                              EFI_PEI_PPI_DESCRIPTOR
+  @param  BistInformationData Pointer to BIST information data
+
+  @retval EFI_SUCCESS         Retrieve of the BIST data successfully
+  @retval EFI_NOT_FOUND       No sec platform information(2) ppi export
+  @retval EFI_DEVICE_ERROR    Failed to get CPU Information
+
+**/
+EFI_STATUS
+GetBistInfoFromPpi (
+  IN CONST EFI_PEI_SERVICES     **PeiServices,
+  IN CONST EFI_GUID             *Guid,
+     OUT EFI_PEI_PPI_DESCRIPTOR **PpiDescriptor,
+     OUT VOID                   **BistInformationData
+  )
+{
+  EFI_STATUS                            Status;
+  EFI_SEC_PLATFORM_INFORMATION2_PPI     *SecPlatformInformation2Ppi;
+  EFI_SEC_PLATFORM_INFORMATION_RECORD2  *SecPlatformInformation2;
+  UINT64                                InformationSize;
+
+  Status = PeiServicesLocatePpi (
+             Guid,                                // GUID
+             0,                                   // INSTANCE
+             PpiDescriptor,                       // EFI_PEI_PPI_DESCRIPTOR
+             (VOID **)&SecPlatformInformation2Ppi // PPI
+             );
+  if (Status == EFI_NOT_FOUND) {
+    return EFI_NOT_FOUND;
+  }
+
+  if (Status == EFI_SUCCESS) {
+    //
+    // Get the size of the sec platform information2(BSP/APs' BIST data)
+    //
+    InformationSize         = 0;
+    SecPlatformInformation2 = NULL;
+    Status = SecPlatformInformation2Ppi->PlatformInformation2 (
+                                           PeiServices,
+                                           &InformationSize,
+                                           SecPlatformInformation2
+                                           );
+    if (Status == EFI_BUFFER_TOO_SMALL) {
+      Status = PeiServicesAllocatePool (
+                 (UINTN) InformationSize,
+                 (VOID **) &SecPlatformInformation2
+                 );
+      if (Status == EFI_SUCCESS) {
+        //
+        // Retrieve BIST data
+        //
+        Status = SecPlatformInformation2Ppi->PlatformInformation2 (
+                                               PeiServices,
+                                               &InformationSize,
+                                               SecPlatformInformation2
+                                               );
+        if (Status == EFI_SUCCESS) {
+          *BistInformationData = SecPlatformInformation2;
+          return EFI_SUCCESS;
+        }
+      }
+    }
+  }
+
+  return EFI_DEVICE_ERROR;
+}
+
+/**
+  Collects BIST data from PPI.
+
+  This function collects BIST data from Sec Platform Information2 PPI
+  or SEC Platform Information PPI.
+
+  @param PeiServices         Pointer to PEI Services Table
+  @param PeiCpuMpData        Pointer to PEI CPU MP Data
+
+**/
+VOID
+CollectBistDataFromPpi (
+  IN CONST EFI_PEI_SERVICES             **PeiServices,
+  IN PEI_CPU_MP_DATA                    *PeiCpuMpData
+  )
+{
+  EFI_STATUS                            Status;
+  EFI_PEI_PPI_DESCRIPTOR                *SecInformationDescriptor;
+  EFI_SEC_PLATFORM_INFORMATION_RECORD2  *SecPlatformInformation2;
+  EFI_SEC_PLATFORM_INFORMATION_RECORD   *SecPlatformInformation;
+  UINTN                                 NumberOfData;
+  EFI_SEC_PLATFORM_INFORMATION_CPU      *CpuInstance;
+  EFI_SEC_PLATFORM_INFORMATION_CPU      BspCpuInstance;
+  UINTN                                 ProcessorNumber;
+  UINTN                                 CpuIndex;
+  PEI_CPU_DATA                          *CpuData;
+
+  SecPlatformInformation2 = NULL;
+  SecPlatformInformation  = NULL;
+  NumberOfData            = 0;
+  CpuInstance             = NULL;
+
+  //
+  // Get BIST information from Sec Platform Information2 Ppi firstly
+  //
+  Status = GetBistInfoFromPpi (
+             PeiServices,
+             &gEfiSecPlatformInformation2PpiGuid,
+             &SecInformationDescriptor,
+             (VOID *) &SecPlatformInformation2
+             );
+  if (Status == EFI_SUCCESS) {
+    //
+    // Sec Platform Information2 PPI includes BSP/APs' BIST information
+    //
+    NumberOfData = SecPlatformInformation2->NumberOfCpus;
+    CpuInstance  = SecPlatformInformation2->CpuInstance;
+  } else {
+    //
+    // Otherwise, get BIST information from Sec Platform Information Ppi
+    //
+    Status = GetBistInfoFromPpi (
+               PeiServices,
+               &gEfiSecPlatformInformationPpiGuid,
+               &SecInformationDescriptor,
+               (VOID *) &SecPlatformInformation
+               );
+    if (Status == EFI_SUCCESS) {
+      NumberOfData = 1;
+      //
+      // SEC Platform Information only includes BSP's BIST information
+      // and does not have BSP's APIC ID
+      //
+      BspCpuInstance.CpuLocation = GetInitialApicId ();
+      BspCpuInstance.InfoRecord.IA32HealthFlags.Uint32  = 
SecPlatformInformation->IA32HealthFlags.Uint32;
+      CpuInstance = &BspCpuInstance;
+    } else {
+      DEBUG ((EFI_D_INFO, "Does not find any stored CPU BIST information from 
PPI!\n"));
+    }
+  }
+  for (ProcessorNumber = 0; ProcessorNumber < PeiCpuMpData->CpuCount; 
ProcessorNumber ++) {
+    CpuData = &PeiCpuMpData->CpuData[ProcessorNumber];
+    for (CpuIndex = 0; CpuIndex < NumberOfData; CpuIndex ++) {
+      ASSERT (CpuInstance != NULL);
+      if (CpuData->ApicId == CpuInstance[CpuIndex].CpuLocation) {
+        //
+        // Update processor's BIST data if it is already stored before
+        //
+        CpuData->Health = CpuInstance[CpuIndex].InfoRecord.IA32HealthFlags;
+      }
+    }
+    if (CpuData->Health.Uint32 != 0) {
+      //
+      // Report Status Code that self test is failed
+      //
+      REPORT_STATUS_CODE (
+        EFI_ERROR_CODE | EFI_ERROR_MAJOR,
+        (EFI_COMPUTING_UNIT_HOST_PROCESSOR | EFI_CU_HP_EC_SELF_TEST)
+        );
+    }
+    DEBUG ((EFI_D_INFO, "  APICID - 0x%08x, BIST - 0x%08x\n",
+            PeiCpuMpData->CpuData[ProcessorNumber].ApicId,
+            PeiCpuMpData->CpuData[ProcessorNumber].Health.Uint32
+            ));
+  }
+
+  if (SecPlatformInformation2 != NULL && NumberOfData < 
PeiCpuMpData->CpuCount) {
+    //
+    // Reinstall SecPlatformInformation2 PPI to include new BIST inforamtion
+    //
+    Status = PeiServicesReInstallPpi (
+               SecInformationDescriptor,
+               &mPeiSecPlatformInformation2Ppi
+               );
+    ASSERT_EFI_ERROR (Status);
+  } else {
+    //
+    // Install SecPlatformInformation2 PPI to include new BIST inforamtion
+    //
+    Status = PeiServicesInstallPpi (&mPeiSecPlatformInformation2Ppi);
+    ASSERT_EFI_ERROR(Status);
+  }
+}
diff --git a/UefiCpuPkg/CpuMpPei/CpuMpPei.c b/UefiCpuPkg/CpuMpPei/CpuMpPei.c
index ae98c38..d218313 100644
--- a/UefiCpuPkg/CpuMpPei/CpuMpPei.c
+++ b/UefiCpuPkg/CpuMpPei/CpuMpPei.c
@@ -446,6 +446,10 @@ CpuMpPeimInit (
     (VOID *)&PeiCpuMpData,
     sizeof(UINT64)
     );
+  //
+  // Update and publish CPU BIST information
+  //
+  CollectBistDataFromPpi (PeiServices, PeiCpuMpData);
 
   return EFI_SUCCESS;
 }
diff --git a/UefiCpuPkg/CpuMpPei/CpuMpPei.h b/UefiCpuPkg/CpuMpPei/CpuMpPei.h
index 7a34a98..aa926ab 100644
--- a/UefiCpuPkg/CpuMpPei/CpuMpPei.h
+++ b/UefiCpuPkg/CpuMpPei/CpuMpPei.h
@@ -18,6 +18,7 @@
 #include <PiPei.h>
 
 #include <Ppi/SecPlatformInformation.h>
+#include <Ppi/SecPlatformInformation2.h>
 
 #include <Register/LocalApic.h>
 
@@ -30,6 +31,7 @@
 #include <Library/PcdLib.h>
 #include <Library/PeimEntryPoint.h>
 #include <Library/PeiServicesLib.h>
+#include <Library/ReportStatusCodeLib.h>
 #include <Library/SynchronizationLib.h>
 #include <Library/TimerLib.h>
 #include <Library/UefiCpuLib.h>
@@ -150,4 +152,50 @@ AsmInitializeGdt (
   );
 
 
+/**
+  Get CPU MP Data pointer from the Guided HOB.
+
+  @return  Pointer to Pointer to PEI CPU MP Data
+**/
+PEI_CPU_MP_DATA *
+GetMpHobData (
+  VOID
+  );
+
+/**
+  Collects BIST data from PPI.
+
+  This function collects BIST data from Sec Platform Information2 PPI
+  or SEC Platform Information PPI.
+
+  @param PeiServices         Pointer to PEI Services Table
+  @param PeiCpuMpData        Pointer to PEI CPU MP Data
+
+**/
+VOID
+CollectBistDataFromPpi (
+  IN CONST EFI_PEI_SERVICES             **PeiServices,
+  IN PEI_CPU_MP_DATA                    *PeiCpuMpData
+  );
+
+/**
+  Implementation of the PlatformInformation2 service in 
EFI_SEC_PLATFORM_INFORMATION2_PPI.
+
+  @param  PeiServices                The pointer to the PEI Services Table.
+  @param  StructureSize              The pointer to the variable describing 
size of the input buffer.
+  @param  PlatformInformationRecord2 The pointer to the 
EFI_SEC_PLATFORM_INFORMATION_RECORD2.
+
+  @retval EFI_SUCCESS                The data was successfully returned.
+  @retval EFI_BUFFER_TOO_SMALL       The buffer was too small. The current 
buffer size needed to
+                                     hold the record is returned in 
StructureSize.
+
+**/
+EFI_STATUS
+EFIAPI
+SecPlatformInformation2 (
+  IN CONST EFI_PEI_SERVICES                   **PeiServices,
+  IN OUT UINT64                               *StructureSize,
+     OUT EFI_SEC_PLATFORM_INFORMATION_RECORD2 *PlatformInformationRecord2
+  );
+
 #endif
diff --git a/UefiCpuPkg/CpuMpPei/CpuMpPei.inf b/UefiCpuPkg/CpuMpPei/CpuMpPei.inf
index 1bb4dae..36126af 100644
--- a/UefiCpuPkg/CpuMpPei/CpuMpPei.inf
+++ b/UefiCpuPkg/CpuMpPei/CpuMpPei.inf
@@ -30,6 +30,7 @@
 [Sources]
   CpuMpPei.h
   CpuMpPei.c
+  CpuBist.c
   Microcode.h
   Microcode.c
 
@@ -59,10 +60,16 @@
   PcdLib
   PeimEntryPoint
   PeiServicesLib
+  ReportStatusCodeLib
   SynchronizationLib
   TimerLib
   UefiCpuLib
 
+[Ppis]
+  gEfiSecPlatformInformationPpiGuid             ## SOMETIMES_CONSUMES
+  ## SOMETIMES_CONSUMES
+  ## SOMETIMES_PRODUCES
+  gEfiSecPlatformInformation2PpiGuid
 
 [Pcd]
   gUefiCpuPkgTokenSpaceGuid.PcdCpuMaxLogicalProcessorNumber
-- 
1.9.5.msysgit.0


------------------------------------------------------------------------------
Don't Limit Your Business. Reach for the Cloud.
GigeNET's Cloud Solutions provide you with the tools and support that
you need to offload your IT needs and focus on growing your business.
Configured For All Businesses. Start Your Cloud Today.
https://www.gigenetcloud.com/
_______________________________________________
edk2-devel mailing list
edk2-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/edk2-devel

Reply via email to