]> git.proxmox.com Git - mirror_edk2.git/blame - OvmfPkg/Tcg/Tcg2Config/Tcg2ConfigPeim.c
OvmfPkg/Tcg2ConfigPei: factor out InternalTpm12Detect()
[mirror_edk2.git] / OvmfPkg / Tcg / Tcg2Config / Tcg2ConfigPeim.c
CommitLineData
6cf1880f 1/** @file\r
1affa1c0 2 Set TPM device type\r
6cf1880f 3\r
1affa1c0
LE
4 In SecurityPkg, this module initializes the TPM device type based on a UEFI\r
5 variable and/or hardware detection. In OvmfPkg, the module only performs TPM2\r
6 hardware detection.\r
6cf1880f 7\r
1affa1c0
LE
8 Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>\r
9 Copyright (C) 2018, Red Hat, Inc.\r
6cf1880f 10\r
b26f0cf9 11 SPDX-License-Identifier: BSD-2-Clause-Patent\r
6cf1880f
MAL
12**/\r
13\r
14\r
15#include <PiPei.h>\r
16\r
17#include <Guid/TpmInstance.h>\r
18#include <Library/DebugLib.h>\r
19#include <Library/PeiServicesLib.h>\r
20#include <Library/Tpm2DeviceLib.h>\r
21#include <Ppi/TpmInitialized.h>\r
22\r
fc72a6ce
LE
23#include "Tpm12Support.h"\r
24\r
6cf1880f
MAL
25STATIC CONST EFI_PEI_PPI_DESCRIPTOR mTpmSelectedPpi = {\r
26 (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),\r
27 &gEfiTpmDeviceSelectedGuid,\r
28 NULL\r
29};\r
30\r
31STATIC CONST EFI_PEI_PPI_DESCRIPTOR mTpmInitializationDonePpiList = {\r
32 EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST,\r
33 &gPeiTpmInitializationDonePpiGuid,\r
34 NULL\r
35};\r
36\r
37/**\r
38 The entry point for Tcg2 configuration driver.\r
39\r
40 @param FileHandle Handle of the file being invoked.\r
41 @param PeiServices Describes the list of possible PEI Services.\r
42**/\r
43EFI_STATUS\r
44EFIAPI\r
45Tcg2ConfigPeimEntryPoint (\r
46 IN EFI_PEI_FILE_HANDLE FileHandle,\r
47 IN CONST EFI_PEI_SERVICES **PeiServices\r
48 )\r
49{\r
50 UINTN Size;\r
51 EFI_STATUS Status;\r
52\r
53 DEBUG ((DEBUG_INFO, "%a\n", __FUNCTION__));\r
54\r
fc72a6ce
LE
55 Status = InternalTpm12Detect ();\r
56 if (!EFI_ERROR (Status)) {\r
89236992
MAL
57 DEBUG ((DEBUG_INFO, "%a: TPM1.2 detected\n", __FUNCTION__));\r
58 Size = sizeof (gEfiTpmDeviceInstanceTpm12Guid);\r
1affa1c0
LE
59 Status = PcdSetPtrS (\r
60 PcdTpmInstanceGuid,\r
61 &Size,\r
89236992 62 &gEfiTpmDeviceInstanceTpm12Guid\r
1affa1c0
LE
63 );\r
64 ASSERT_EFI_ERROR (Status);\r
6cf1880f 65 } else {\r
89236992
MAL
66 Status = Tpm2RequestUseTpm ();\r
67 if (!EFI_ERROR (Status)) {\r
68 DEBUG ((DEBUG_INFO, "%a: TPM2 detected\n", __FUNCTION__));\r
69 Size = sizeof (gEfiTpmDeviceInstanceTpm20DtpmGuid);\r
70 Status = PcdSetPtrS (\r
71 PcdTpmInstanceGuid,\r
72 &Size,\r
73 &gEfiTpmDeviceInstanceTpm20DtpmGuid\r
74 );\r
75 ASSERT_EFI_ERROR (Status);\r
76 } else {\r
77 DEBUG ((DEBUG_INFO, "%a: no TPM detected\n", __FUNCTION__));\r
78 //\r
79 // If no TPM2 was detected, we still need to install\r
80 // TpmInitializationDonePpi. Namely, Tcg2Pei will exit early upon seeing\r
81 // the default (all-bits-zero) contents of PcdTpmInstanceGuid, thus we have\r
82 // to install the PPI in its place, in order to unblock any dependent\r
83 // PEIMs.\r
84 //\r
85 Status = PeiServicesInstallPpi (&mTpmInitializationDonePpiList);\r
86 ASSERT_EFI_ERROR (Status);\r
87 }\r
6cf1880f
MAL
88 }\r
89\r
90 //\r
91 // Selection done\r
92 //\r
93 Status = PeiServicesInstallPpi (&mTpmSelectedPpi);\r
94 ASSERT_EFI_ERROR (Status);\r
95\r
96 return Status;\r
97}\r