2 The module entry point for Tcg2 configuration module.
4 Copyright (c) 2015 - 2018, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
12 #include <Guid/TpmInstance.h>
14 #include <Library/BaseLib.h>
15 #include <Library/BaseMemoryLib.h>
16 #include <Library/DebugLib.h>
17 #include <Library/MemoryAllocationLib.h>
18 #include <Library/PeiServicesLib.h>
19 #include <Library/PcdLib.h>
21 #include <Ppi/ReadOnlyVariable2.h>
22 #include <Ppi/TpmInitialized.h>
23 #include <Protocol/Tcg2Protocol.h>
25 #include "Tcg2ConfigNvData.h"
27 TPM_INSTANCE_ID mTpmInstanceId
[] = TPM_INSTANCE_ID_LIST
;
29 CONST EFI_PEI_PPI_DESCRIPTOR gTpmSelectedPpi
= {
30 (EFI_PEI_PPI_DESCRIPTOR_PPI
| EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
),
31 &gEfiTpmDeviceSelectedGuid
,
35 EFI_PEI_PPI_DESCRIPTOR mTpmInitializationDonePpiList
= {
36 EFI_PEI_PPI_DESCRIPTOR_PPI
| EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
,
37 &gPeiTpmInitializationDonePpiGuid
,
42 This routine check both SetupVariable and real TPM device, and return final TpmDevice configuration.
44 @param SetupTpmDevice TpmDevice configuration in setup driver
46 @return TpmDevice configuration
50 IN UINT8 SetupTpmDevice
54 The entry point for Tcg2 configuration driver.
56 @param FileHandle Handle of the file being invoked.
57 @param PeiServices Describes the list of possible PEI Services.
59 @retval EFI_SUCCES Convert variable to PCD successfully.
60 @retval Others Fail to convert variable to PCD.
64 Tcg2ConfigPeimEntryPoint (
65 IN EFI_PEI_FILE_HANDLE FileHandle
,
66 IN CONST EFI_PEI_SERVICES
**PeiServices
72 EFI_PEI_READ_ONLY_VARIABLE2_PPI
*VariablePpi
;
73 TCG2_CONFIGURATION Tcg2Configuration
;
77 Status
= PeiServicesLocatePpi (&gEfiPeiReadOnlyVariable2PpiGuid
, 0, NULL
, (VOID
**) &VariablePpi
);
78 ASSERT_EFI_ERROR (Status
);
80 Size
= sizeof(Tcg2Configuration
);
81 Status
= VariablePpi
->GetVariable (
84 &gTcg2ConfigFormSetGuid
,
89 if (EFI_ERROR (Status
)) {
91 // Variable not ready, set default value
93 Tcg2Configuration
.TpmDevice
= TPM_DEVICE_DEFAULT
;
99 if ((Tcg2Configuration
.TpmDevice
> TPM_DEVICE_MAX
) || (Tcg2Configuration
.TpmDevice
< TPM_DEVICE_MIN
)) {
100 Tcg2Configuration
.TpmDevice
= TPM_DEVICE_DEFAULT
;
104 // Although we have SetupVariable info, we still need detect TPM device manually.
106 DEBUG ((EFI_D_INFO
, "Tcg2Configuration.TpmDevice from Setup: %x\n", Tcg2Configuration
.TpmDevice
));
108 if (PcdGetBool (PcdTpmAutoDetection
)) {
109 TpmDevice
= DetectTpmDevice (Tcg2Configuration
.TpmDevice
);
110 DEBUG ((EFI_D_INFO
, "TpmDevice final: %x\n", TpmDevice
));
111 if (TpmDevice
!= TPM_DEVICE_NULL
) {
112 Tcg2Configuration
.TpmDevice
= TpmDevice
;
115 TpmDevice
= Tcg2Configuration
.TpmDevice
;
119 // Convert variable to PCD.
120 // This is work-around because there is no gurantee DynamicHiiPcd can return correct value in DXE phase.
121 // Using DynamicPcd instead.
123 // NOTE: Tcg2Configuration variable contains the desired TpmDevice type,
124 // while PcdTpmInstanceGuid PCD contains the real detected TpmDevice type
126 for (Index
= 0; Index
< sizeof(mTpmInstanceId
)/sizeof(mTpmInstanceId
[0]); Index
++) {
127 if (TpmDevice
== mTpmInstanceId
[Index
].TpmDevice
) {
128 Size
= sizeof(mTpmInstanceId
[Index
].TpmInstanceGuid
);
129 Status
= PcdSetPtrS (PcdTpmInstanceGuid
, &Size
, &mTpmInstanceId
[Index
].TpmInstanceGuid
);
130 ASSERT_EFI_ERROR (Status
);
131 DEBUG ((EFI_D_INFO
, "TpmDevice PCD: %g\n", &mTpmInstanceId
[Index
].TpmInstanceGuid
));
139 Status
= PeiServicesInstallPpi (&gTpmSelectedPpi
);
140 ASSERT_EFI_ERROR (Status
);
143 // Even if no TPM is selected or detected, we still need intall TpmInitializationDonePpi.
144 // Because TcgPei or Tcg2Pei will not run, but we still need a way to notify other driver.
145 // Other driver can know TPM initialization state by TpmInitializedPpi.
147 if (CompareGuid (PcdGetPtr(PcdTpmInstanceGuid
), &gEfiTpmDeviceInstanceNoneGuid
)) {
148 Status2
= PeiServicesInstallPpi (&mTpmInitializationDonePpiList
);
149 ASSERT_EFI_ERROR (Status2
);