2 TPM1.2/dTPM2.0 auto detection.
4 Copyright (c) 2013 - 2014, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
17 #include <Ppi/ReadOnlyVariable2.h>
19 #include <Library/BaseLib.h>
20 #include <Library/BaseMemoryLib.h>
21 #include <Library/IoLib.h>
22 #include <Library/DebugLib.h>
23 #include <Library/PeiServicesLib.h>
24 #include <Library/PcdLib.h>
25 #include <Library/Tpm12DeviceLib.h>
26 #include <Library/Tpm12CommandLib.h>
27 #include <IndustryStandard/Tpm12.h>
29 #include "TrEEConfigNvData.h"
32 This routine return if dTPM (1.2 or 2.0) present.
34 @retval TRUE dTPM present
35 @retval FALSE dTPM not present
44 RegRead
= MmioRead8 ((UINTN
)PcdGet64 (PcdTpmBaseAddress
));
45 if (RegRead
== 0xFF) {
46 DEBUG ((EFI_D_ERROR
, "DetectTpmDevice: Dtpm not present\n"));
49 DEBUG ((EFI_D_INFO
, "DetectTpmDevice: Dtpm present\n"));
55 This routine check both SetupVariable and real TPM device, and return final TpmDevice configuration.
57 @param SetupTpmDevice TpmDevice configuration in setup driver
59 @return TpmDevice configuration
63 IN UINT8 SetupTpmDevice
67 EFI_BOOT_MODE BootMode
;
68 TREE_DEVICE_DETECTION TrEEDeviceDetection
;
69 EFI_PEI_READ_ONLY_VARIABLE2_PPI
*VariablePpi
;
72 Status
= PeiServicesGetBootMode (&BootMode
);
73 ASSERT_EFI_ERROR (Status
);
76 // In S3, we rely on normal boot Detection, because we save to ReadOnly Variable in normal boot.
78 if (BootMode
== BOOT_ON_S3_RESUME
) {
79 DEBUG ((EFI_D_INFO
, "DetectTpmDevice: S3 mode\n"));
81 Status
= PeiServicesLocatePpi (&gEfiPeiReadOnlyVariable2PpiGuid
, 0, NULL
, (VOID
**) &VariablePpi
);
82 ASSERT_EFI_ERROR (Status
);
84 Size
= sizeof(TREE_DEVICE_DETECTION
);
85 ZeroMem (&TrEEDeviceDetection
, sizeof(TrEEDeviceDetection
));
86 Status
= VariablePpi
->GetVariable (
88 TREE_DEVICE_DETECTION_NAME
,
89 &gTrEEConfigFormSetGuid
,
94 if (!EFI_ERROR (Status
) &&
95 (TrEEDeviceDetection
.TpmDeviceDetected
>= TPM_DEVICE_MIN
) &&
96 (TrEEDeviceDetection
.TpmDeviceDetected
<= TPM_DEVICE_MAX
)) {
97 DEBUG ((EFI_D_ERROR
, "TpmDevice from DeviceDetection: %x\n", TrEEDeviceDetection
.TpmDeviceDetected
));
98 return TrEEDeviceDetection
.TpmDeviceDetected
;
102 DEBUG ((EFI_D_INFO
, "DetectTpmDevice:\n"));
103 if (!IsDtpmPresent ()) {
104 // dTPM not available
105 return TPM_DEVICE_NULL
;
108 // dTPM available and not disabled by setup
109 // We need check if it is TPM1.2 or TPM2.0
110 // So try TPM1.2 command at first
112 Status
= Tpm12RequestUseTpm ();
113 if (EFI_ERROR (Status
)) {
114 return TPM_DEVICE_2_0_DTPM
;
117 if (BootMode
== BOOT_ON_S3_RESUME
) {
118 Status
= Tpm12Startup (TPM_ST_STATE
);
120 Status
= Tpm12Startup (TPM_ST_CLEAR
);
122 if (EFI_ERROR (Status
)) {
123 return TPM_DEVICE_2_0_DTPM
;
126 // NO initialization needed again.
127 PcdSet8 (PcdTpmInitializationPolicy
, 0);
128 return TPM_DEVICE_1_2
;