]> git.proxmox.com Git - mirror_edk2.git/blame - SecurityPkg/Tcg/TrEEConfig/TpmDetection.c
SecurityPkg: Update protocol usage in module INF files.
[mirror_edk2.git] / SecurityPkg / Tcg / TrEEConfig / TpmDetection.c
CommitLineData
c1d93242
JY
1/** @file\r
2 TPM1.2/dTPM2.0 auto detection.\r
3\r
cc71e263 4Copyright (c) 2013 - 2016, 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
5437d457 17#include <Ppi/ReadOnlyVariable2.h>\r
c1d93242
JY
18\r
19#include <Library/BaseLib.h>\r
20#include <Library/BaseMemoryLib.h>\r
c1d93242
JY
21#include <Library/DebugLib.h>\r
22#include <Library/PeiServicesLib.h>\r
23#include <Library/PcdLib.h>\r
24#include <Library/Tpm12DeviceLib.h>\r
25#include <Library/Tpm12CommandLib.h>\r
26#include <IndustryStandard/Tpm12.h>\r
27\r
28#include "TrEEConfigNvData.h"\r
29\r
c1d93242
JY
30/**\r
31 This routine check both SetupVariable and real TPM device, and return final TpmDevice configuration.\r
32\r
33 @param SetupTpmDevice TpmDevice configuration in setup driver\r
34\r
35 @return TpmDevice configuration\r
36**/\r
37UINT8\r
38DetectTpmDevice (\r
39 IN UINT8 SetupTpmDevice\r
40 )\r
41{\r
42 EFI_STATUS Status;\r
43 EFI_BOOT_MODE BootMode;\r
5437d457
JY
44 TREE_DEVICE_DETECTION TrEEDeviceDetection;\r
45 EFI_PEI_READ_ONLY_VARIABLE2_PPI *VariablePpi;\r
46 UINTN Size;\r
47\r
c1d93242
JY
48 Status = PeiServicesGetBootMode (&BootMode);\r
49 ASSERT_EFI_ERROR (Status);\r
50\r
51 //\r
5437d457 52 // In S3, we rely on normal boot Detection, because we save to ReadOnly Variable in normal boot.\r
c1d93242
JY
53 //\r
54 if (BootMode == BOOT_ON_S3_RESUME) {\r
33985e3b 55 DEBUG ((EFI_D_INFO, "DetectTpmDevice: S3 mode\n"));\r
c1d93242 56\r
5437d457
JY
57 Status = PeiServicesLocatePpi (&gEfiPeiReadOnlyVariable2PpiGuid, 0, NULL, (VOID **) &VariablePpi);\r
58 ASSERT_EFI_ERROR (Status);\r
59\r
60 Size = sizeof(TREE_DEVICE_DETECTION);\r
61 ZeroMem (&TrEEDeviceDetection, sizeof(TrEEDeviceDetection));\r
62 Status = VariablePpi->GetVariable (\r
63 VariablePpi,\r
64 TREE_DEVICE_DETECTION_NAME,\r
65 &gTrEEConfigFormSetGuid,\r
66 NULL,\r
67 &Size,\r
68 &TrEEDeviceDetection\r
69 );\r
70 if (!EFI_ERROR (Status) &&\r
71 (TrEEDeviceDetection.TpmDeviceDetected >= TPM_DEVICE_MIN) &&\r
72 (TrEEDeviceDetection.TpmDeviceDetected <= TPM_DEVICE_MAX)) {\r
73 DEBUG ((EFI_D_ERROR, "TpmDevice from DeviceDetection: %x\n", TrEEDeviceDetection.TpmDeviceDetected));\r
74 return TrEEDeviceDetection.TpmDeviceDetected;\r
75 }\r
c1d93242
JY
76 }\r
77\r
33985e3b 78 DEBUG ((EFI_D_INFO, "DetectTpmDevice:\n"));\r
c1d93242
JY
79\r
80 // dTPM available and not disabled by setup\r
81 // We need check if it is TPM1.2 or TPM2.0\r
82 // So try TPM1.2 command at first\r
83\r
84 Status = Tpm12RequestUseTpm ();\r
85 if (EFI_ERROR (Status)) {\r
cc71e263
MK
86 //\r
87 // dTPM not available\r
88 //\r
89 return TPM_DEVICE_NULL;\r
c1d93242
JY
90 }\r
91\r
5437d457
JY
92 if (BootMode == BOOT_ON_S3_RESUME) {\r
93 Status = Tpm12Startup (TPM_ST_STATE);\r
94 } else {\r
95 Status = Tpm12Startup (TPM_ST_CLEAR);\r
96 }\r
c1d93242
JY
97 if (EFI_ERROR (Status)) {\r
98 return TPM_DEVICE_2_0_DTPM;\r
99 }\r
100\r
101 // NO initialization needed again.\r
fe3ca12d
SZ
102 Status = PcdSet8S (PcdTpmInitializationPolicy, 0);\r
103 ASSERT_EFI_ERROR (Status);\r
c1d93242
JY
104 return TPM_DEVICE_1_2;\r
105}\r