+/** @file\r
+ The module entry point for Tcg2 configuration module.\r
+\r
+Copyright (c) 2018, Red Hat, Inc.\r
+Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>\r
+\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
+\r
+#include <PiPei.h>\r
+\r
+#include <Guid/TpmInstance.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/PeiServicesLib.h>\r
+#include <Library/Tpm2DeviceLib.h>\r
+#include <Ppi/TpmInitialized.h>\r
+\r
+STATIC CONST EFI_PEI_PPI_DESCRIPTOR mTpmSelectedPpi = {\r
+ (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),\r
+ &gEfiTpmDeviceSelectedGuid,\r
+ NULL\r
+};\r
+\r
+STATIC CONST EFI_PEI_PPI_DESCRIPTOR mTpmInitializationDonePpiList = {\r
+ EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST,\r
+ &gPeiTpmInitializationDonePpiGuid,\r
+ NULL\r
+};\r
+\r
+/**\r
+ The entry point for Tcg2 configuration driver.\r
+\r
+ @param FileHandle Handle of the file being invoked.\r
+ @param PeiServices Describes the list of possible PEI Services.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+Tcg2ConfigPeimEntryPoint (\r
+ IN EFI_PEI_FILE_HANDLE FileHandle,\r
+ IN CONST EFI_PEI_SERVICES **PeiServices\r
+ )\r
+{\r
+ UINTN Size;\r
+ EFI_STATUS Status;\r
+\r
+ DEBUG ((DEBUG_INFO, "%a\n", __FUNCTION__));\r
+\r
+ Status = Tpm2RequestUseTpm ();\r
+ if (!EFI_ERROR (Status)) {\r
+ DEBUG ((DEBUG_INFO, "%a: TPM2 detected\n", __FUNCTION__));\r
+ Size = sizeof(gEfiTpmDeviceInstanceTpm20DtpmGuid);\r
+ Status = PcdSetPtrS (\r
+ PcdTpmInstanceGuid,\r
+ &Size,\r
+ &gEfiTpmDeviceInstanceTpm20DtpmGuid\r
+ );\r
+ ASSERT_EFI_ERROR (Status);\r
+ } else {\r
+ DEBUG ((DEBUG_INFO, "%a: no TPM2 detected\n", __FUNCTION__));\r
+ // If no TPM2 was detected, we still need to install\r
+ // TpmInitializationDonePpi. Namely, Tcg2Pei will exit early upon\r
+ // seeing the default (all-bits-zero) contents of\r
+ // PcdTpmInstanceGuid, thus we have to install the PPI in its place,\r
+ // in order to unblock any dependent PEIMs.\r
+ Status = PeiServicesInstallPpi (&mTpmInitializationDonePpiList);\r
+ ASSERT_EFI_ERROR (Status);\r
+ }\r
+\r
+ //\r
+ // Selection done\r
+ //\r
+ Status = PeiServicesInstallPpi (&mTpmSelectedPpi);\r
+ ASSERT_EFI_ERROR (Status);\r
+\r
+ return Status;\r
+}\r