--- /dev/null
+/** @file\r
+\r
+Copyright (c) 2017, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) Microsoft Corporation.<BR>\r
+SPDX-License-Identifier: BSD-2-Clause-Patent\r
+\r
+**/\r
+\r
+#include <PiPei.h>\r
+#include <Library/PeiServicesLib.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/BaseMemoryLib.h>\r
+#include <Library/MemoryAllocationLib.h>\r
+#include <Library/HobLib.h>\r
+#include <Library/Tpm2CommandLib.h>\r
+#include <Library/Tpm2DeviceLib.h>\r
+#include <Library/TpmPlatformHierarchyLib.h>\r
+#include <Library/RngLib.h>\r
+\r
+#include <Ppi/EndOfPeiPhase.h>\r
+\r
+#define MAX_NEW_AUTHORIZATION_SIZE SHA512_DIGEST_SIZE\r
+\r
+/**\r
+ This function handles PlatformInit task at the end of PEI\r
+\r
+ @param[in] PeiServices Pointer to PEI Services Table.\r
+ @param[in] NotifyDesc Pointer to the descriptor for the Notification event that\r
+ caused this function to execute.\r
+ @param[in] Ppi Pointer to the PPI data associated with this function.\r
+\r
+ @retval EFI_SUCCESS The function completes successfully\r
+ @retval others\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+PlatformInitEndOfPei (\r
+ IN CONST EFI_PEI_SERVICES **PeiServices,\r
+ IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor,\r
+ IN VOID *Ppi\r
+ )\r
+{\r
+ VOID *TcgEventLog;\r
+\r
+ //\r
+ // Try to get TcgEventLog in S3 to see if S3 error is reported.\r
+ //\r
+ TcgEventLog = GetFirstGuidHob(&gTcgEventEntryHobGuid);\r
+ if (TcgEventLog == NULL) {\r
+ TcgEventLog = GetFirstGuidHob(&gTcgEvent2EntryHobGuid);\r
+ }\r
+\r
+ if (TcgEventLog == NULL) {\r
+ //\r
+ // no S3 error reported\r
+ //\r
+ return EFI_SUCCESS;\r
+ }\r
+\r
+ //\r
+ // If there is S3 error on TPM_SU_STATE and success on TPM_SU_CLEAR,\r
+ // configure the TPM Platform Hierarchy.\r
+ //\r
+ ConfigureTpmPlatformHierarchy ();\r
+\r
+ return EFI_SUCCESS;\r
+}\r
+\r
+static EFI_PEI_NOTIFY_DESCRIPTOR mEndOfPeiNotifyList = {\r
+ (EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),\r
+ &gEfiEndOfPeiSignalPpiGuid,\r
+ (EFI_PEIM_NOTIFY_ENTRY_POINT)PlatformInitEndOfPei\r
+};\r
+\r
+/**\r
+ Main entry\r
+\r
+ @param[in] FileHandle Handle of the file being invoked.\r
+ @param[in] PeiServices Pointer to PEI Services table.\r
+\r
+ @retval EFI_SUCCESS Install function successfully.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+Tcg2PlatformPeiEntryPoint (\r
+ IN EFI_PEI_FILE_HANDLE FileHandle,\r
+ IN CONST EFI_PEI_SERVICES **PeiServices\r
+ )\r
+{\r
+ EFI_STATUS Status;\r
+ EFI_BOOT_MODE BootMode;\r
+\r
+ Status = PeiServicesGetBootMode (&BootMode);\r
+ ASSERT_EFI_ERROR(Status);\r
+\r
+ if (BootMode != BOOT_ON_S3_RESUME) {\r
+ return EFI_SUCCESS;\r
+ }\r
+\r
+ //\r
+ // Performing PlatformInitEndOfPei after EndOfPei PPI produced\r
+ //\r
+ Status = PeiServicesNotifyPpi (&mEndOfPeiNotifyList);\r
+\r
+ return Status;\r
+}\r
--- /dev/null
+### @file\r
+#\r
+# Copyright (c) 2017, Intel Corporation. All rights reserved.<BR>\r
+#\r
+# SPDX-License-Identifier: BSD-2-Clause-Patent\r
+#\r
+###\r
+\r
+[Defines]\r
+ INF_VERSION = 0x00010017\r
+ BASE_NAME = Tcg2PlatformPei\r
+ FILE_GUID = 47727552-A54B-4A84-8CC1-BFF23E239636\r
+ VERSION_STRING = 1.0\r
+ MODULE_TYPE = PEIM\r
+ ENTRY_POINT = Tcg2PlatformPeiEntryPoint\r
+\r
+#\r
+# The following information is for reference only and not required by the build tools.\r
+#\r
+# VALID_ARCHITECTURES = IA32 X64 IPF EBC\r
+#\r
+\r
+[LibraryClasses]\r
+ PcdLib\r
+ BaseMemoryLib\r
+ MemoryAllocationLib\r
+ PeiServicesLib\r
+ PeimEntryPoint\r
+ DebugLib\r
+ Tpm2DeviceLib\r
+ Tpm2CommandLib\r
+ TpmPlatformHierarchyLib\r
+ RngLib\r
+\r
+[Packages]\r
+ MdePkg/MdePkg.dec\r
+ SecurityPkg/SecurityPkg.dec\r
+ MinPlatformPkg/MinPlatformPkg.dec\r
+\r
+[Sources]\r
+ Tcg2PlatformPei.c\r
+\r
+[Guids]\r
+ gTcgEventEntryHobGuid\r
+ gTcgEvent2EntryHobGuid\r
+\r
+[Ppis]\r
+ gEfiEndOfPeiSignalPpiGuid\r
+\r
+[Depex]\r
+ gEfiTpmDeviceSelectedGuid\r
+\r