--- /dev/null
+/** @file\r
+ Get SEC platform information(2) PPI and reinstall it.\r
+\r
+ Copyright (c) 2006 - 2016, 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
+ http://opensource.org/licenses/bsd-license.php\r
+\r
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#include "SecMain.h"\r
+\r
+/**\r
+ Implementation of the PlatformInformation2 service in EFI_SEC_PLATFORM_INFORMATION2_PPI.\r
+\r
+ @param PeiServices The pointer to the PEI Services Table.\r
+ @param StructureSize The pointer to the variable describing size of the input buffer.\r
+ @param PlatformInformationRecord2 The pointer to the EFI_SEC_PLATFORM_INFORMATION_RECORD2.\r
+\r
+ @retval EFI_SUCCESS The data was successfully returned.\r
+ @retval EFI_BUFFER_TOO_SMALL The buffer was too small. The current buffer size needed to\r
+ hold the record is returned in StructureSize.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+SecPlatformInformation2 (\r
+ IN CONST EFI_PEI_SERVICES **PeiServices,\r
+ IN OUT UINT64 *StructureSize,\r
+ OUT EFI_SEC_PLATFORM_INFORMATION_RECORD2 *PlatformInformationRecord2\r
+ )\r
+{\r
+ EFI_HOB_GUID_TYPE *GuidHob;\r
+ VOID *DataInHob;\r
+ UINTN DataSize;\r
+\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
+ //\r
+ // return the information from BistHob\r
+ //\r
+ if ((*StructureSize) < (UINT64) DataSize) {\r
+ *StructureSize = (UINT64) DataSize;\r
+ return EFI_BUFFER_TOO_SMALL;\r
+ }\r
+\r
+ *StructureSize = (UINT64) DataSize;\r
+ CopyMem (PlatformInformationRecord2, DataInHob, DataSize);\r
+ return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+ Worker function to get CPUs' BIST by calling SecPlatformInformationPpi\r
+ or SecPlatformInformation2Ppi.\r
+\r
+ @param PeiServices Pointer to PEI Services Table\r
+ @param Guid PPI Guid\r
+ @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
+ @retval EFI_DEVICE_ERROR Failed to get CPU Information\r
+\r
+**/\r
+EFI_STATUS\r
+GetBistInfoFromPpi (\r
+ 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 UINT64 *BistInformationSize OPTIONAL\r
+ )\r
+{\r
+ EFI_STATUS Status;\r
+ EFI_SEC_PLATFORM_INFORMATION2_PPI *SecPlatformInformation2Ppi;\r
+ EFI_SEC_PLATFORM_INFORMATION_RECORD2 *SecPlatformInformation2;\r
+ UINT64 InformationSize;\r
+\r
+ Status = PeiServicesLocatePpi (\r
+ Guid, // GUID\r
+ 0, // INSTANCE\r
+ PpiDescriptor, // EFI_PEI_PPI_DESCRIPTOR\r
+ (VOID **)&SecPlatformInformation2Ppi // PPI\r
+ );\r
+ if (Status == EFI_NOT_FOUND) {\r
+ return EFI_NOT_FOUND;\r
+ }\r
+\r
+ if (Status == EFI_SUCCESS) {\r
+ //\r
+ // Get the size of the sec platform information2(BSP/APs' BIST data)\r
+ //\r
+ InformationSize = 0;\r
+ SecPlatformInformation2 = NULL;\r
+ Status = SecPlatformInformation2Ppi->PlatformInformation2 (\r
+ PeiServices,\r
+ &InformationSize,\r
+ SecPlatformInformation2\r
+ );\r
+ if (Status == EFI_BUFFER_TOO_SMALL) {\r
+ Status = PeiServicesAllocatePool (\r
+ (UINTN) InformationSize,\r
+ (VOID **) &SecPlatformInformation2\r
+ );\r
+ if (Status == EFI_SUCCESS) {\r
+ //\r
+ // Retrieve BIST data\r
+ //\r
+ Status = SecPlatformInformation2Ppi->PlatformInformation2 (\r
+ PeiServices,\r
+ &InformationSize,\r
+ SecPlatformInformation2\r
+ );\r
+ if (Status == EFI_SUCCESS) {\r
+ *BistInformationData = SecPlatformInformation2;\r
+ if (BistInformationSize != NULL) {\r
+ *BistInformationSize = InformationSize;\r
+ }\r
+ return EFI_SUCCESS;\r
+ }\r
+ }\r
+ }\r
+ }\r
+\r
+ return EFI_DEVICE_ERROR;\r
+}\r