]> git.proxmox.com Git - mirror_edk2.git/blame - SecurityPkg/Tcg/TrEEConfig/TrEEConfigPeim.c
Fix execution status & DEBUG message level mismatch. EFI_D_ERROR is used only...
[mirror_edk2.git] / SecurityPkg / Tcg / TrEEConfig / TrEEConfigPeim.c
CommitLineData
c1d93242
JY
1/** @file\r
2 The module entry point for TrEE configuration module.\r
3\r
33985e3b 4Copyright (c) 2013 - 2014, Intel Corporation. All rights reserved.<BR>\r
c1d93242
JY
5This program and the accompanying materials \r
6are licensed and made available under the terms and conditions of the BSD License \r
7which accompanies this distribution. The full text of the license may be found at \r
8http://opensource.org/licenses/bsd-license.php\r
9\r
10THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r
11WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12\r
13**/\r
14\r
15\r
16#include <PiPei.h>\r
17\r
18#include <Guid/TpmInstance.h>\r
19\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
26\r
27#include <Ppi/ReadOnlyVariable2.h>\r
28#include <Protocol/TrEEProtocol.h>\r
29\r
30#include "TrEEConfigNvData.h"\r
31\r
32TPM_INSTANCE_ID mTpmInstanceId[] = TPM_INSTANCE_ID_LIST;\r
33\r
34CONST EFI_PEI_PPI_DESCRIPTOR gTpmSelectedPpi = {\r
35 (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),\r
36 &gEfiTpmDeviceSelectedGuid,\r
37 NULL\r
38};\r
39\r
40/**\r
41 This routine check both SetupVariable and real TPM device, and return final TpmDevice configuration.\r
42\r
43 @param SetupTpmDevice TpmDevice configuration in setup driver\r
44\r
45 @return TpmDevice configuration\r
46**/\r
47UINT8\r
48DetectTpmDevice (\r
49 IN UINT8 SetupTpmDevice\r
50 );\r
51\r
52/**\r
53 The entry point for TrEE configuration driver.\r
54\r
55 @param FileHandle Handle of the file being invoked.\r
56 @param PeiServices Describes the list of possible PEI Services.\r
57\r
58 @retval EFI_SUCCES Convert variable to PCD successfully.\r
59 @retval Others Fail to convert variable to PCD.\r
60**/\r
61EFI_STATUS\r
62EFIAPI\r
63TrEEConfigPeimEntryPoint (\r
64 IN EFI_PEI_FILE_HANDLE FileHandle,\r
65 IN CONST EFI_PEI_SERVICES **PeiServices\r
66 )\r
67{\r
68 UINTN Size;\r
69 EFI_STATUS Status;\r
70 EFI_PEI_READ_ONLY_VARIABLE2_PPI *VariablePpi;\r
71 TREE_CONFIGURATION TrEEConfiguration;\r
72 UINTN Index;\r
73 UINT8 TpmDevice;\r
74\r
75 Status = PeiServicesLocatePpi (&gEfiPeiReadOnlyVariable2PpiGuid, 0, NULL, (VOID **) &VariablePpi);\r
76 ASSERT_EFI_ERROR (Status);\r
77\r
78 Size = sizeof(TrEEConfiguration);\r
79 Status = VariablePpi->GetVariable (\r
80 VariablePpi,\r
81 TREE_STORAGE_NAME,\r
82 &gTrEEConfigFormSetGuid,\r
83 NULL,\r
84 &Size,\r
85 &TrEEConfiguration\r
86 );\r
87 if (EFI_ERROR (Status)) {\r
88 //\r
89 // Variable not ready, set default value\r
90 //\r
91 TrEEConfiguration.TpmDevice = TPM_DEVICE_DEFAULT;\r
92 }\r
93\r
94 //\r
95 // Validation\r
96 //\r
5437d457
JY
97 if ((TrEEConfiguration.TpmDevice > TPM_DEVICE_MAX) || (TrEEConfiguration.TpmDevice < TPM_DEVICE_MIN)) {\r
98 TrEEConfiguration.TpmDevice = TPM_DEVICE_DEFAULT;\r
c1d93242
JY
99 }\r
100\r
101 //\r
102 // Although we have SetupVariable info, we still need detect TPM device manually.\r
103 //\r
33985e3b 104 DEBUG ((EFI_D_INFO, "TrEEConfiguration.TpmDevice from Setup: %x\n", TrEEConfiguration.TpmDevice));\r
c1d93242
JY
105\r
106 if (PcdGetBool (PcdTpmAutoDetection)) {\r
107 TpmDevice = DetectTpmDevice (TrEEConfiguration.TpmDevice);\r
33985e3b 108 DEBUG ((EFI_D_INFO, "TpmDevice final: %x\n", TpmDevice));\r
5437d457
JY
109 if (TpmDevice != TPM_DEVICE_NULL) {\r
110 TrEEConfiguration.TpmDevice = TpmDevice;\r
111 }\r
112 } else {\r
113 TpmDevice = TrEEConfiguration.TpmDevice;\r
c1d93242
JY
114 }\r
115\r
116 //\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
120 //\r
5437d457
JY
121 // NOTE: TrEEConfiguration variable contains the desired TpmDevice type,\r
122 // while PcdTpmInstanceGuid PCD contains the real detected TpmDevice type\r
123 //\r
c1d93242 124 for (Index = 0; Index < sizeof(mTpmInstanceId)/sizeof(mTpmInstanceId[0]); Index++) {\r
5437d457 125 if (TpmDevice == mTpmInstanceId[Index].TpmDevice) {\r
c1d93242
JY
126 Size = sizeof(mTpmInstanceId[Index].TpmInstanceGuid);\r
127 PcdSetPtr (PcdTpmInstanceGuid, &Size, &mTpmInstanceId[Index].TpmInstanceGuid);\r
33985e3b 128 DEBUG ((EFI_D_INFO, "TpmDevice PCD: %g\n", &mTpmInstanceId[Index].TpmInstanceGuid));\r
c1d93242
JY
129 break;\r
130 }\r
131 }\r
132\r
133 //\r
134 // Selection done\r
135 //\r
136 Status = PeiServicesInstallPpi (&gTpmSelectedPpi);\r
137 ASSERT_EFI_ERROR (Status);\r
138\r
139 return Status;\r
140}\r