2 The module entry point for TrEE configuration module.
\r
4 Copyright (c) 2013 - 2014, 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 <Protocol/TrEEProtocol.h>
\r
30 #include "TrEEConfigNvData.h"
\r
32 TPM_INSTANCE_ID mTpmInstanceId[] = TPM_INSTANCE_ID_LIST;
\r
34 CONST EFI_PEI_PPI_DESCRIPTOR gTpmSelectedPpi = {
\r
35 (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),
\r
36 &gEfiTpmDeviceSelectedGuid,
\r
41 This routine check both SetupVariable and real TPM device, and return final TpmDevice configuration.
\r
43 @param SetupTpmDevice TpmDevice configuration in setup driver
\r
45 @return TpmDevice configuration
\r
49 IN UINT8 SetupTpmDevice
\r
53 The entry point for TrEE configuration driver.
\r
55 @param FileHandle Handle of the file being invoked.
\r
56 @param PeiServices Describes the list of possible PEI Services.
\r
58 @retval EFI_SUCCES Convert variable to PCD successfully.
\r
59 @retval Others Fail to convert variable to PCD.
\r
63 TrEEConfigPeimEntryPoint (
\r
64 IN EFI_PEI_FILE_HANDLE FileHandle,
\r
65 IN CONST EFI_PEI_SERVICES **PeiServices
\r
70 EFI_PEI_READ_ONLY_VARIABLE2_PPI *VariablePpi;
\r
71 TREE_CONFIGURATION TrEEConfiguration;
\r
75 Status = PeiServicesLocatePpi (&gEfiPeiReadOnlyVariable2PpiGuid, 0, NULL, (VOID **) &VariablePpi);
\r
76 ASSERT_EFI_ERROR (Status);
\r
78 Size = sizeof(TrEEConfiguration);
\r
79 Status = VariablePpi->GetVariable (
\r
82 &gTrEEConfigFormSetGuid,
\r
87 if (EFI_ERROR (Status)) {
\r
89 // Variable not ready, set default value
\r
91 TrEEConfiguration.TpmDevice = TPM_DEVICE_DEFAULT;
\r
97 if ((TrEEConfiguration.TpmDevice > TPM_DEVICE_MAX) || (TrEEConfiguration.TpmDevice < TPM_DEVICE_MIN)) {
\r
98 TrEEConfiguration.TpmDevice = TPM_DEVICE_DEFAULT;
\r
102 // Although we have SetupVariable info, we still need detect TPM device manually.
\r
104 DEBUG ((EFI_D_INFO, "TrEEConfiguration.TpmDevice from Setup: %x\n", TrEEConfiguration.TpmDevice));
\r
106 if (PcdGetBool (PcdTpmAutoDetection)) {
\r
107 TpmDevice = DetectTpmDevice (TrEEConfiguration.TpmDevice);
\r
108 DEBUG ((EFI_D_INFO, "TpmDevice final: %x\n", TpmDevice));
\r
109 if (TpmDevice != TPM_DEVICE_NULL) {
\r
110 TrEEConfiguration.TpmDevice = TpmDevice;
\r
113 TpmDevice = TrEEConfiguration.TpmDevice;
\r
117 // Convert variable to PCD.
\r
118 // This is work-around because there is no gurantee DynamicHiiPcd can return correct value in DXE phase.
\r
119 // Using DynamicPcd instead.
\r
121 // NOTE: TrEEConfiguration variable contains the desired TpmDevice type,
\r
122 // while PcdTpmInstanceGuid PCD contains the real detected TpmDevice type
\r
124 for (Index = 0; Index < sizeof(mTpmInstanceId)/sizeof(mTpmInstanceId[0]); Index++) {
\r
125 if (TpmDevice == mTpmInstanceId[Index].TpmDevice) {
\r
126 Size = sizeof(mTpmInstanceId[Index].TpmInstanceGuid);
\r
127 PcdSetPtr (PcdTpmInstanceGuid, &Size, &mTpmInstanceId[Index].TpmInstanceGuid);
\r
128 DEBUG ((EFI_D_INFO, "TpmDevice PCD: %g\n", &mTpmInstanceId[Index].TpmInstanceGuid));
\r
136 Status = PeiServicesInstallPpi (&gTpmSelectedPpi);
\r
137 ASSERT_EFI_ERROR (Status);
\r