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.
18 #include <Library/BaseLib.h>
19 #include <Library/BaseMemoryLib.h>
20 #include <Library/IoLib.h>
21 #include <Library/DebugLib.h>
22 #include <Library/PeiServicesLib.h>
23 #include <Library/PcdLib.h>
24 #include <Library/Tpm12DeviceLib.h>
25 #include <Library/Tpm12CommandLib.h>
26 #include <IndustryStandard/Tpm12.h>
28 #include "TrEEConfigNvData.h"
31 This routine return if dTPM (1.2 or 2.0) present.
33 @retval TRUE dTPM present
34 @retval FALSE dTPM not present
43 RegRead
= MmioRead8 ((UINTN
)PcdGet64 (PcdTpmBaseAddress
));
44 if (RegRead
== 0xFF) {
45 DEBUG ((EFI_D_ERROR
, "DetectTpmDevice: Dtpm not present\n"));
48 DEBUG ((EFI_D_ERROR
, "DetectTpmDevice: Dtpm present\n"));
54 This routine check both SetupVariable and real TPM device, and return final TpmDevice configuration.
56 @param SetupTpmDevice TpmDevice configuration in setup driver
58 @return TpmDevice configuration
62 IN UINT8 SetupTpmDevice
66 EFI_BOOT_MODE BootMode
;
68 Status
= PeiServicesGetBootMode (&BootMode
);
69 ASSERT_EFI_ERROR (Status
);
72 // In S3, we rely on Setup option, because we save to Setup in normal boot.
74 if (BootMode
== BOOT_ON_S3_RESUME
) {
75 DEBUG ((EFI_D_ERROR
, "DetectTpmDevice: S3 mode\n"));
76 return SetupTpmDevice
;
79 if (PcdGetBool (PcdHideTpmSupport
) && PcdGetBool (PcdHideTpm
)) {
80 DEBUG ((EFI_D_ERROR
, "DetectTpmDevice: Tpm is hide\n"));
81 return TPM_DEVICE_NULL
;
84 DEBUG ((EFI_D_ERROR
, "DetectTpmDevice:\n"));
85 if ((!IsDtpmPresent ()) || (SetupTpmDevice
== TPM_DEVICE_NULL
)) {
87 return TPM_DEVICE_NULL
;
90 // dTPM available and not disabled by setup
91 // We need check if it is TPM1.2 or TPM2.0
92 // So try TPM1.2 command at first
94 Status
= Tpm12RequestUseTpm ();
95 if (EFI_ERROR (Status
)) {
96 return TPM_DEVICE_2_0_DTPM
;
99 Status
= Tpm12Startup (TPM_ST_CLEAR
);
100 if (EFI_ERROR (Status
)) {
101 return TPM_DEVICE_2_0_DTPM
;
104 // NO initialization needed again.
105 PcdSet8 (PcdTpmInitializationPolicy
, 0);
106 return TPM_DEVICE_1_2
;