2 TPM1.2/dTPM2.0 auto detection.
4 Copyright (c) 2015 - 2018, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
10 #include <Ppi/ReadOnlyVariable2.h>
12 #include <Library/BaseLib.h>
13 #include <Library/BaseMemoryLib.h>
14 #include <Library/DebugLib.h>
15 #include <Library/PeiServicesLib.h>
16 #include <Library/PcdLib.h>
17 #include <Library/Tpm12DeviceLib.h>
18 #include <Library/Tpm12CommandLib.h>
19 #include <IndustryStandard/Tpm12.h>
21 #include "Tcg2ConfigNvData.h"
22 #include "Tcg2Internal.h"
25 This routine check both SetupVariable and real TPM device, and return final TpmDevice configuration.
27 @param SetupTpmDevice TpmDevice configuration in setup driver
29 @return TpmDevice configuration
33 IN UINT8 SetupTpmDevice
37 EFI_BOOT_MODE BootMode
;
38 TCG2_DEVICE_DETECTION Tcg2DeviceDetection
;
39 EFI_PEI_READ_ONLY_VARIABLE2_PPI
*VariablePpi
;
42 Status
= PeiServicesGetBootMode (&BootMode
);
43 ASSERT_EFI_ERROR (Status
);
46 // In S3, we rely on normal boot Detection, because we save to ReadOnly Variable in normal boot.
48 if (BootMode
== BOOT_ON_S3_RESUME
) {
49 DEBUG ((DEBUG_INFO
, "DetectTpmDevice: S3 mode\n"));
51 Status
= PeiServicesLocatePpi (&gEfiPeiReadOnlyVariable2PpiGuid
, 0, NULL
, (VOID
**)&VariablePpi
);
52 ASSERT_EFI_ERROR (Status
);
54 Size
= sizeof (TCG2_DEVICE_DETECTION
);
55 ZeroMem (&Tcg2DeviceDetection
, sizeof (Tcg2DeviceDetection
));
56 Status
= VariablePpi
->GetVariable (
58 TCG2_DEVICE_DETECTION_NAME
,
59 &gTcg2ConfigFormSetGuid
,
64 if (!EFI_ERROR (Status
) &&
65 (Tcg2DeviceDetection
.TpmDeviceDetected
>= TPM_DEVICE_MIN
) &&
66 (Tcg2DeviceDetection
.TpmDeviceDetected
<= TPM_DEVICE_MAX
))
68 DEBUG ((DEBUG_ERROR
, "TpmDevice from DeviceDetection: %x\n", Tcg2DeviceDetection
.TpmDeviceDetected
));
69 return Tcg2DeviceDetection
.TpmDeviceDetected
;
73 DEBUG ((DEBUG_INFO
, "DetectTpmDevice:\n"));
75 // dTPM available and not disabled by setup
76 // We need check if it is TPM1.2 or TPM2.0
77 // So try TPM1.2 command at first
79 Status
= Tpm12RequestUseTpm ();
80 if (EFI_ERROR (Status
)) {
84 return TPM_DEVICE_NULL
;
87 if (BootMode
== BOOT_ON_S3_RESUME
) {
88 Status
= Tpm12Startup (TPM_ST_STATE
);
90 Status
= Tpm12Startup (TPM_ST_CLEAR
);
93 if (EFI_ERROR (Status
)) {
94 return TPM_DEVICE_2_0_DTPM
;
97 // NO initialization needed again.
98 Status
= PcdSet8S (PcdTpmInitializationPolicy
, 0);
99 ASSERT_EFI_ERROR (Status
);
100 return TPM_DEVICE_1_2
;