2 The module entry point for TrEE configuration module.
4 Copyright (c) 2013, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
18 #include <Guid/TpmInstance.h>
20 #include <Library/BaseLib.h>
21 #include <Library/BaseMemoryLib.h>
22 #include <Library/DebugLib.h>
23 #include <Library/MemoryAllocationLib.h>
24 #include <Library/PeiServicesLib.h>
25 #include <Library/PcdLib.h>
27 #include <Ppi/ReadOnlyVariable2.h>
28 #include <Protocol/TrEEProtocol.h>
30 #include "TrEEConfigNvData.h"
32 TPM_INSTANCE_ID mTpmInstanceId
[] = TPM_INSTANCE_ID_LIST
;
34 CONST EFI_PEI_PPI_DESCRIPTOR gTpmSelectedPpi
= {
35 (EFI_PEI_PPI_DESCRIPTOR_PPI
| EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
),
36 &gEfiTpmDeviceSelectedGuid
,
41 This routine check both SetupVariable and real TPM device, and return final TpmDevice configuration.
43 @param SetupTpmDevice TpmDevice configuration in setup driver
45 @return TpmDevice configuration
49 IN UINT8 SetupTpmDevice
53 The entry point for TrEE configuration driver.
55 @param FileHandle Handle of the file being invoked.
56 @param PeiServices Describes the list of possible PEI Services.
58 @retval EFI_SUCCES Convert variable to PCD successfully.
59 @retval Others Fail to convert variable to PCD.
63 TrEEConfigPeimEntryPoint (
64 IN EFI_PEI_FILE_HANDLE FileHandle
,
65 IN CONST EFI_PEI_SERVICES
**PeiServices
70 EFI_PEI_READ_ONLY_VARIABLE2_PPI
*VariablePpi
;
71 TREE_CONFIGURATION TrEEConfiguration
;
75 Status
= PeiServicesLocatePpi (&gEfiPeiReadOnlyVariable2PpiGuid
, 0, NULL
, (VOID
**) &VariablePpi
);
76 ASSERT_EFI_ERROR (Status
);
78 Size
= sizeof(TrEEConfiguration
);
79 Status
= VariablePpi
->GetVariable (
82 &gTrEEConfigFormSetGuid
,
87 if (EFI_ERROR (Status
)) {
89 // Variable not ready, set default value
91 TrEEConfiguration
.TpmDevice
= TPM_DEVICE_DEFAULT
;
97 if ((TrEEConfiguration
.TpmDevice
> TPM_DEVICE_MAX
) || (TrEEConfiguration
.TpmDevice
< TPM_DEVICE_MIN
)) {
98 TrEEConfiguration
.TpmDevice
= TPM_DEVICE_DEFAULT
;
102 // Although we have SetupVariable info, we still need detect TPM device manually.
104 DEBUG ((EFI_D_ERROR
, "TrEEConfiguration.TpmDevice from Setup: %x\n", TrEEConfiguration
.TpmDevice
));
106 if (PcdGetBool (PcdTpmAutoDetection
)) {
107 TpmDevice
= DetectTpmDevice (TrEEConfiguration
.TpmDevice
);
108 DEBUG ((EFI_D_ERROR
, "TpmDevice final: %x\n", TpmDevice
));
109 if (TpmDevice
!= TPM_DEVICE_NULL
) {
110 TrEEConfiguration
.TpmDevice
= TpmDevice
;
113 TpmDevice
= TrEEConfiguration
.TpmDevice
;
117 // Convert variable to PCD.
118 // This is work-around because there is no gurantee DynamicHiiPcd can return correct value in DXE phase.
119 // Using DynamicPcd instead.
121 // NOTE: TrEEConfiguration variable contains the desired TpmDevice type,
122 // while PcdTpmInstanceGuid PCD contains the real detected TpmDevice type
124 for (Index
= 0; Index
< sizeof(mTpmInstanceId
)/sizeof(mTpmInstanceId
[0]); Index
++) {
125 if (TpmDevice
== mTpmInstanceId
[Index
].TpmDevice
) {
126 Size
= sizeof(mTpmInstanceId
[Index
].TpmInstanceGuid
);
127 PcdSetPtr (PcdTpmInstanceGuid
, &Size
, &mTpmInstanceId
[Index
].TpmInstanceGuid
);
128 DEBUG ((EFI_D_ERROR
, "TpmDevice PCD: %g\n", &mTpmInstanceId
[Index
].TpmInstanceGuid
));
136 Status
= PeiServicesInstallPpi (&gTpmSelectedPpi
);
137 ASSERT_EFI_ERROR (Status
);