]> git.proxmox.com Git - mirror_edk2.git/blobdiff - SecurityPkg/Tcg/Tcg2PlatformPei/Tcg2PlatformPei.c
SecurityPkg/Tcg: Import Tcg2PlatformPei from edk2-platforms
[mirror_edk2.git] / SecurityPkg / Tcg / Tcg2PlatformPei / Tcg2PlatformPei.c
diff --git a/SecurityPkg/Tcg/Tcg2PlatformPei/Tcg2PlatformPei.c b/SecurityPkg/Tcg/Tcg2PlatformPei/Tcg2PlatformPei.c
new file mode 100644 (file)
index 0000000..66ec75a
--- /dev/null
@@ -0,0 +1,107 @@
+/** @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