]> git.proxmox.com Git - mirror_edk2.git/blame - SecurityPkg/Tcg/Tcg2Config/TpmDetection.c
SecurityPkg: Tcg2Dxe: Report correct FinalEventLog size
[mirror_edk2.git] / SecurityPkg / Tcg / Tcg2Config / TpmDetection.c
CommitLineData
1abfa4ce
JY
1/** @file\r
2 TPM1.2/dTPM2.0 auto detection.\r
3\r
6d2eec02 4Copyright (c) 2015 - 2016, Intel Corporation. All rights reserved.<BR>\r
1abfa4ce
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#include <Ppi/ReadOnlyVariable2.h>\r
18\r
19#include <Library/BaseLib.h>\r
20#include <Library/BaseMemoryLib.h>\r
1abfa4ce
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 "Tcg2ConfigNvData.h"\r
29\r
1abfa4ce
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
44 TCG2_DEVICE_DETECTION Tcg2DeviceDetection;\r
45 EFI_PEI_READ_ONLY_VARIABLE2_PPI *VariablePpi;\r
46 UINTN Size;\r
47\r
48 Status = PeiServicesGetBootMode (&BootMode);\r
49 ASSERT_EFI_ERROR (Status);\r
50\r
51 //\r
52 // In S3, we rely on normal boot Detection, because we save to ReadOnly Variable in normal boot.\r
53 //\r
54 if (BootMode == BOOT_ON_S3_RESUME) {\r
55 DEBUG ((EFI_D_INFO, "DetectTpmDevice: S3 mode\n"));\r
56\r
57 Status = PeiServicesLocatePpi (&gEfiPeiReadOnlyVariable2PpiGuid, 0, NULL, (VOID **) &VariablePpi);\r
58 ASSERT_EFI_ERROR (Status);\r
59\r
60 Size = sizeof(TCG2_DEVICE_DETECTION);\r
61 ZeroMem (&Tcg2DeviceDetection, sizeof(Tcg2DeviceDetection));\r
62 Status = VariablePpi->GetVariable (\r
63 VariablePpi,\r
64 TCG2_DEVICE_DETECTION_NAME,\r
65 &gTcg2ConfigFormSetGuid,\r
66 NULL,\r
67 &Size,\r
68 &Tcg2DeviceDetection\r
69 );\r
70 if (!EFI_ERROR (Status) &&\r
71 (Tcg2DeviceDetection.TpmDeviceDetected >= TPM_DEVICE_MIN) &&\r
72 (Tcg2DeviceDetection.TpmDeviceDetected <= TPM_DEVICE_MAX)) {\r
73 DEBUG ((EFI_D_ERROR, "TpmDevice from DeviceDetection: %x\n", Tcg2DeviceDetection.TpmDeviceDetected));\r
74 return Tcg2DeviceDetection.TpmDeviceDetected;\r
75 }\r
76 }\r
77\r
78 DEBUG ((EFI_D_INFO, "DetectTpmDevice:\n"));\r
1abfa4ce
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
6d2eec02
MK
86 //\r
87 // dTPM not available\r
88 //\r
89 return TPM_DEVICE_NULL;\r
1abfa4ce
JY
90 }\r
91\r
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
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
1abfa4ce
JY
104 return TPM_DEVICE_1_2;\r
105}\r