]> git.proxmox.com Git - mirror_edk2.git/blame - SecurityPkg/Tcg/Tcg2Config/TpmDetection.c
SecurityPkg: Change use of EFI_D_* to DEBUG_*
[mirror_edk2.git] / SecurityPkg / Tcg / Tcg2Config / TpmDetection.c
CommitLineData
1abfa4ce
JY
1/** @file\r
2 TPM1.2/dTPM2.0 auto detection.\r
3\r
b3548d32 4Copyright (c) 2015 - 2018, Intel Corporation. All rights reserved.<BR>\r
289b714b 5SPDX-License-Identifier: BSD-2-Clause-Patent\r
1abfa4ce
JY
6\r
7**/\r
8\r
9\r
10#include <PiPei.h>\r
11#include <Ppi/ReadOnlyVariable2.h>\r
12\r
13#include <Library/BaseLib.h>\r
14#include <Library/BaseMemoryLib.h>\r
1abfa4ce
JY
15#include <Library/DebugLib.h>\r
16#include <Library/PeiServicesLib.h>\r
17#include <Library/PcdLib.h>\r
18#include <Library/Tpm12DeviceLib.h>\r
19#include <Library/Tpm12CommandLib.h>\r
20#include <IndustryStandard/Tpm12.h>\r
21\r
22#include "Tcg2ConfigNvData.h"\r
26fc074a 23#include "Tcg2Internal.h"\r
1abfa4ce 24\r
1abfa4ce
JY
25/**\r
26 This routine check both SetupVariable and real TPM device, and return final TpmDevice configuration.\r
27\r
28 @param SetupTpmDevice TpmDevice configuration in setup driver\r
29\r
30 @return TpmDevice configuration\r
31**/\r
32UINT8\r
33DetectTpmDevice (\r
34 IN UINT8 SetupTpmDevice\r
35 )\r
36{\r
37 EFI_STATUS Status;\r
38 EFI_BOOT_MODE BootMode;\r
39 TCG2_DEVICE_DETECTION Tcg2DeviceDetection;\r
40 EFI_PEI_READ_ONLY_VARIABLE2_PPI *VariablePpi;\r
41 UINTN Size;\r
42\r
43 Status = PeiServicesGetBootMode (&BootMode);\r
44 ASSERT_EFI_ERROR (Status);\r
45\r
46 //\r
47 // In S3, we rely on normal boot Detection, because we save to ReadOnly Variable in normal boot.\r
48 //\r
49 if (BootMode == BOOT_ON_S3_RESUME) {\r
e905fbb0 50 DEBUG ((DEBUG_INFO, "DetectTpmDevice: S3 mode\n"));\r
1abfa4ce
JY
51\r
52 Status = PeiServicesLocatePpi (&gEfiPeiReadOnlyVariable2PpiGuid, 0, NULL, (VOID **) &VariablePpi);\r
53 ASSERT_EFI_ERROR (Status);\r
54\r
55 Size = sizeof(TCG2_DEVICE_DETECTION);\r
56 ZeroMem (&Tcg2DeviceDetection, sizeof(Tcg2DeviceDetection));\r
57 Status = VariablePpi->GetVariable (\r
58 VariablePpi,\r
59 TCG2_DEVICE_DETECTION_NAME,\r
60 &gTcg2ConfigFormSetGuid,\r
61 NULL,\r
62 &Size,\r
63 &Tcg2DeviceDetection\r
64 );\r
65 if (!EFI_ERROR (Status) &&\r
66 (Tcg2DeviceDetection.TpmDeviceDetected >= TPM_DEVICE_MIN) &&\r
67 (Tcg2DeviceDetection.TpmDeviceDetected <= TPM_DEVICE_MAX)) {\r
e905fbb0 68 DEBUG ((DEBUG_ERROR, "TpmDevice from DeviceDetection: %x\n", Tcg2DeviceDetection.TpmDeviceDetected));\r
1abfa4ce
JY
69 return Tcg2DeviceDetection.TpmDeviceDetected;\r
70 }\r
71 }\r
72\r
e905fbb0 73 DEBUG ((DEBUG_INFO, "DetectTpmDevice:\n"));\r
1abfa4ce
JY
74\r
75 // dTPM available and not disabled by setup\r
76 // We need check if it is TPM1.2 or TPM2.0\r
77 // So try TPM1.2 command at first\r
78\r
79 Status = Tpm12RequestUseTpm ();\r
80 if (EFI_ERROR (Status)) {\r
6d2eec02
MK
81 //\r
82 // dTPM not available\r
83 //\r
84 return TPM_DEVICE_NULL;\r
1abfa4ce
JY
85 }\r
86\r
87 if (BootMode == BOOT_ON_S3_RESUME) {\r
88 Status = Tpm12Startup (TPM_ST_STATE);\r
89 } else {\r
90 Status = Tpm12Startup (TPM_ST_CLEAR);\r
91 }\r
92 if (EFI_ERROR (Status)) {\r
93 return TPM_DEVICE_2_0_DTPM;\r
94 }\r
95\r
96 // NO initialization needed again.\r
fe3ca12d
SZ
97 Status = PcdSet8S (PcdTpmInitializationPolicy, 0);\r
98 ASSERT_EFI_ERROR (Status);\r
1abfa4ce
JY
99 return TPM_DEVICE_1_2;\r
100}\r