2 TPM1.2/dTPM2.0 auto detection.
4 Copyright (c) 2013, 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_ERROR
, "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 if (PcdGetBool (PcdHideTpmSupport
) && PcdGetBool (PcdHideTpm
)) {
73 DEBUG ((EFI_D_ERROR
, "DetectTpmDevice: Tpm is hide\n"));
74 return TPM_DEVICE_NULL
;
77 Status
= PeiServicesGetBootMode (&BootMode
);
78 ASSERT_EFI_ERROR (Status
);
81 // In S3, we rely on normal boot Detection, because we save to ReadOnly Variable in normal boot.
83 if (BootMode
== BOOT_ON_S3_RESUME
) {
84 DEBUG ((EFI_D_ERROR
, "DetectTpmDevice: S3 mode\n"));
86 Status
= PeiServicesLocatePpi (&gEfiPeiReadOnlyVariable2PpiGuid
, 0, NULL
, (VOID
**) &VariablePpi
);
87 ASSERT_EFI_ERROR (Status
);
89 Size
= sizeof(TREE_DEVICE_DETECTION
);
90 ZeroMem (&TrEEDeviceDetection
, sizeof(TrEEDeviceDetection
));
91 Status
= VariablePpi
->GetVariable (
93 TREE_DEVICE_DETECTION_NAME
,
94 &gTrEEConfigFormSetGuid
,
99 if (!EFI_ERROR (Status
) &&
100 (TrEEDeviceDetection
.TpmDeviceDetected
>= TPM_DEVICE_MIN
) &&
101 (TrEEDeviceDetection
.TpmDeviceDetected
<= TPM_DEVICE_MAX
)) {
102 DEBUG ((EFI_D_ERROR
, "TpmDevice from DeviceDetection: %x\n", TrEEDeviceDetection
.TpmDeviceDetected
));
103 return TrEEDeviceDetection
.TpmDeviceDetected
;
107 DEBUG ((EFI_D_ERROR
, "DetectTpmDevice:\n"));
108 if (!IsDtpmPresent ()) {
109 // dTPM not available
110 return TPM_DEVICE_NULL
;
113 // dTPM available and not disabled by setup
114 // We need check if it is TPM1.2 or TPM2.0
115 // So try TPM1.2 command at first
117 Status
= Tpm12RequestUseTpm ();
118 if (EFI_ERROR (Status
)) {
119 return TPM_DEVICE_2_0_DTPM
;
122 if (BootMode
== BOOT_ON_S3_RESUME
) {
123 Status
= Tpm12Startup (TPM_ST_STATE
);
125 Status
= Tpm12Startup (TPM_ST_CLEAR
);
127 if (EFI_ERROR (Status
)) {
128 return TPM_DEVICE_2_0_DTPM
;
131 // NO initialization needed again.
132 PcdSet8 (PcdTpmInitializationPolicy
, 0);
133 return TPM_DEVICE_1_2
;