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"
26 #include "Tcg2Internal.h"
28 TPM_INSTANCE_ID mTpmInstanceId
[] = TPM_INSTANCE_ID_LIST
;
30 CONST EFI_PEI_PPI_DESCRIPTOR gTpmSelectedPpi
= {
31 (EFI_PEI_PPI_DESCRIPTOR_PPI
| EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
),
32 &gEfiTpmDeviceSelectedGuid
,
36 EFI_PEI_PPI_DESCRIPTOR mTpmInitializationDonePpiList
= {
37 EFI_PEI_PPI_DESCRIPTOR_PPI
| EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
,
38 &gPeiTpmInitializationDonePpiGuid
,
43 This routine check both SetupVariable and real TPM device, and return final TpmDevice configuration.
45 @param SetupTpmDevice TpmDevice configuration in setup driver
47 @return TpmDevice configuration
51 IN UINT8 SetupTpmDevice
55 The entry point for Tcg2 configuration driver.
57 @param FileHandle Handle of the file being invoked.
58 @param PeiServices Describes the list of possible PEI Services.
60 @retval EFI_SUCCESS Convert variable to PCD successfully.
61 @retval Others Fail to convert variable to PCD.
65 Tcg2ConfigPeimEntryPoint (
66 IN EFI_PEI_FILE_HANDLE FileHandle
,
67 IN CONST EFI_PEI_SERVICES
**PeiServices
73 EFI_PEI_READ_ONLY_VARIABLE2_PPI
*VariablePpi
;
74 TCG2_CONFIGURATION Tcg2Configuration
;
78 Status
= PeiServicesLocatePpi (&gEfiPeiReadOnlyVariable2PpiGuid
, 0, NULL
, (VOID
**) &VariablePpi
);
79 ASSERT_EFI_ERROR (Status
);
81 Size
= sizeof(Tcg2Configuration
);
82 Status
= VariablePpi
->GetVariable (
85 &gTcg2ConfigFormSetGuid
,
90 if (EFI_ERROR (Status
)) {
92 // Variable not ready, set default value
94 Tcg2Configuration
.TpmDevice
= TPM_DEVICE_DEFAULT
;
100 if ((Tcg2Configuration
.TpmDevice
> TPM_DEVICE_MAX
) || (Tcg2Configuration
.TpmDevice
< TPM_DEVICE_MIN
)) {
101 Tcg2Configuration
.TpmDevice
= TPM_DEVICE_DEFAULT
;
105 // Although we have SetupVariable info, we still need detect TPM device manually.
107 DEBUG ((EFI_D_INFO
, "Tcg2Configuration.TpmDevice from Setup: %x\n", Tcg2Configuration
.TpmDevice
));
109 if (PcdGetBool (PcdTpmAutoDetection
)) {
110 TpmDevice
= DetectTpmDevice (Tcg2Configuration
.TpmDevice
);
111 DEBUG ((EFI_D_INFO
, "TpmDevice final: %x\n", TpmDevice
));
112 if (TpmDevice
!= TPM_DEVICE_NULL
) {
113 Tcg2Configuration
.TpmDevice
= TpmDevice
;
116 TpmDevice
= Tcg2Configuration
.TpmDevice
;
120 // Convert variable to PCD.
121 // This is work-around because there is no guarantee DynamicHiiPcd can return correct value in DXE phase.
122 // Using DynamicPcd instead.
124 // NOTE: Tcg2Configuration variable contains the desired TpmDevice type,
125 // while PcdTpmInstanceGuid PCD contains the real detected TpmDevice type
127 for (Index
= 0; Index
< sizeof(mTpmInstanceId
)/sizeof(mTpmInstanceId
[0]); Index
++) {
128 if (TpmDevice
== mTpmInstanceId
[Index
].TpmDevice
) {
129 Size
= sizeof(mTpmInstanceId
[Index
].TpmInstanceGuid
);
130 Status
= PcdSetPtrS (PcdTpmInstanceGuid
, &Size
, &mTpmInstanceId
[Index
].TpmInstanceGuid
);
131 ASSERT_EFI_ERROR (Status
);
132 DEBUG ((EFI_D_INFO
, "TpmDevice PCD: %g\n", &mTpmInstanceId
[Index
].TpmInstanceGuid
));
140 Status
= PeiServicesInstallPpi (&gTpmSelectedPpi
);
141 ASSERT_EFI_ERROR (Status
);
144 // Even if no TPM is selected or detected, we still need intall TpmInitializationDonePpi.
145 // Because TcgPei or Tcg2Pei will not run, but we still need a way to notify other driver.
146 // Other driver can know TPM initialization state by TpmInitializedPpi.
148 if (CompareGuid (PcdGetPtr(PcdTpmInstanceGuid
), &gEfiTpmDeviceInstanceNoneGuid
)) {
149 Status2
= PeiServicesInstallPpi (&mTpmInitializationDonePpiList
);
150 ASSERT_EFI_ERROR (Status2
);