2 The module entry point for TrEE configuration module.
\r
4 Copyright (c) 2013 - 2015, Intel Corporation. All rights reserved.<BR>
\r
5 This program and the accompanying materials
\r
6 are licensed and made available under the terms and conditions of the BSD License
\r
7 which accompanies this distribution. The full text of the license may be found at
\r
8 http://opensource.org/licenses/bsd-license.php
\r
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
\r
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
\r
18 #include <Guid/TpmInstance.h>
\r
20 #include <Library/BaseLib.h>
\r
21 #include <Library/BaseMemoryLib.h>
\r
22 #include <Library/DebugLib.h>
\r
23 #include <Library/MemoryAllocationLib.h>
\r
24 #include <Library/PeiServicesLib.h>
\r
25 #include <Library/PcdLib.h>
\r
27 #include <Ppi/ReadOnlyVariable2.h>
\r
28 #include <Ppi/TpmInitialized.h>
\r
29 #include <Protocol/TrEEProtocol.h>
\r
31 #include "TrEEConfigNvData.h"
\r
33 TPM_INSTANCE_ID mTpmInstanceId[] = TPM_INSTANCE_ID_LIST;
\r
35 CONST EFI_PEI_PPI_DESCRIPTOR gTpmSelectedPpi = {
\r
36 (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),
\r
37 &gEfiTpmDeviceSelectedGuid,
\r
41 EFI_PEI_PPI_DESCRIPTOR mTpmInitializationDonePpiList = {
\r
42 EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST,
\r
43 &gPeiTpmInitializationDonePpiGuid,
\r
48 This routine check both SetupVariable and real TPM device, and return final TpmDevice configuration.
\r
50 @param SetupTpmDevice TpmDevice configuration in setup driver
\r
52 @return TpmDevice configuration
\r
56 IN UINT8 SetupTpmDevice
\r
60 The entry point for TrEE configuration driver.
\r
62 @param FileHandle Handle of the file being invoked.
\r
63 @param PeiServices Describes the list of possible PEI Services.
\r
65 @retval EFI_SUCCES Convert variable to PCD successfully.
\r
66 @retval Others Fail to convert variable to PCD.
\r
70 TrEEConfigPeimEntryPoint (
\r
71 IN EFI_PEI_FILE_HANDLE FileHandle,
\r
72 IN CONST EFI_PEI_SERVICES **PeiServices
\r
78 EFI_PEI_READ_ONLY_VARIABLE2_PPI *VariablePpi;
\r
79 TREE_CONFIGURATION TrEEConfiguration;
\r
83 Status = PeiServicesLocatePpi (&gEfiPeiReadOnlyVariable2PpiGuid, 0, NULL, (VOID **) &VariablePpi);
\r
84 ASSERT_EFI_ERROR (Status);
\r
86 Size = sizeof(TrEEConfiguration);
\r
87 Status = VariablePpi->GetVariable (
\r
90 &gTrEEConfigFormSetGuid,
\r
95 if (EFI_ERROR (Status)) {
\r
97 // Variable not ready, set default value
\r
99 TrEEConfiguration.TpmDevice = TPM_DEVICE_DEFAULT;
\r
105 if ((TrEEConfiguration.TpmDevice > TPM_DEVICE_MAX) || (TrEEConfiguration.TpmDevice < TPM_DEVICE_MIN)) {
\r
106 TrEEConfiguration.TpmDevice = TPM_DEVICE_DEFAULT;
\r
110 // Although we have SetupVariable info, we still need detect TPM device manually.
\r
112 DEBUG ((EFI_D_INFO, "TrEEConfiguration.TpmDevice from Setup: %x\n", TrEEConfiguration.TpmDevice));
\r
114 if (PcdGetBool (PcdTpmAutoDetection)) {
\r
115 TpmDevice = DetectTpmDevice (TrEEConfiguration.TpmDevice);
\r
116 DEBUG ((EFI_D_INFO, "TpmDevice final: %x\n", TpmDevice));
\r
117 if (TpmDevice != TPM_DEVICE_NULL) {
\r
118 TrEEConfiguration.TpmDevice = TpmDevice;
\r
121 TpmDevice = TrEEConfiguration.TpmDevice;
\r
125 // Convert variable to PCD.
\r
126 // This is work-around because there is no gurantee DynamicHiiPcd can return correct value in DXE phase.
\r
127 // Using DynamicPcd instead.
\r
129 // NOTE: TrEEConfiguration variable contains the desired TpmDevice type,
\r
130 // while PcdTpmInstanceGuid PCD contains the real detected TpmDevice type
\r
132 for (Index = 0; Index < sizeof(mTpmInstanceId)/sizeof(mTpmInstanceId[0]); Index++) {
\r
133 if (TpmDevice == mTpmInstanceId[Index].TpmDevice) {
\r
134 Size = sizeof(mTpmInstanceId[Index].TpmInstanceGuid);
\r
135 PcdSetPtr (PcdTpmInstanceGuid, &Size, &mTpmInstanceId[Index].TpmInstanceGuid);
\r
136 DEBUG ((EFI_D_INFO, "TpmDevice PCD: %g\n", &mTpmInstanceId[Index].TpmInstanceGuid));
\r
144 Status = PeiServicesInstallPpi (&gTpmSelectedPpi);
\r
145 ASSERT_EFI_ERROR (Status);
\r
148 // Even if no TPM is selected or detected, we still need intall TpmInitializationDonePpi.
\r
149 // Because TcgPei or TrEEPei will not run, but we still need a way to notify other driver.
\r
150 // Other driver can know TPM initialization state by TpmInitializedPpi.
\r
152 if (CompareGuid (PcdGetPtr(PcdTpmInstanceGuid), &gEfiTpmDeviceInstanceNoneGuid)) {
\r
153 Status2 = PeiServicesInstallPpi (&mTpmInitializationDonePpiList);
\r
154 ASSERT_EFI_ERROR (Status2);
\r