TianoCore EDK2 master
Loading...
Searching...
No Matches
TpmDetection.c
Go to the documentation of this file.
1
9#include <PiPei.h>
11
12#include <Library/BaseLib.h>
14#include <Library/DebugLib.h>
16#include <Library/PcdLib.h>
20
21#include "Tcg2ConfigNvData.h"
22#include "Tcg2Internal.h"
23
31UINT8
33 IN UINT8 SetupTpmDevice
34 )
35{
36 EFI_STATUS Status;
37 EFI_BOOT_MODE BootMode;
38 TCG2_DEVICE_DETECTION Tcg2DeviceDetection;
40 UINTN Size;
41
42 Status = PeiServicesGetBootMode (&BootMode);
43 ASSERT_EFI_ERROR (Status);
44
45 //
46 // In S3, we rely on normal boot Detection, because we save to ReadOnly Variable in normal boot.
47 //
48 if (BootMode == BOOT_ON_S3_RESUME) {
49 DEBUG ((DEBUG_INFO, "DetectTpmDevice: S3 mode\n"));
50
51 Status = PeiServicesLocatePpi (&gEfiPeiReadOnlyVariable2PpiGuid, 0, NULL, (VOID **)&VariablePpi);
52 ASSERT_EFI_ERROR (Status);
53
54 Size = sizeof (TCG2_DEVICE_DETECTION);
55 ZeroMem (&Tcg2DeviceDetection, sizeof (Tcg2DeviceDetection));
56 Status = VariablePpi->GetVariable (
57 VariablePpi,
58 TCG2_DEVICE_DETECTION_NAME,
59 &gTcg2ConfigFormSetGuid,
60 NULL,
61 &Size,
62 &Tcg2DeviceDetection
63 );
64 if (!EFI_ERROR (Status) &&
65 (Tcg2DeviceDetection.TpmDeviceDetected >= TPM_DEVICE_MIN) &&
66 (Tcg2DeviceDetection.TpmDeviceDetected <= TPM_DEVICE_MAX))
67 {
68 DEBUG ((DEBUG_ERROR, "TpmDevice from DeviceDetection: %x\n", Tcg2DeviceDetection.TpmDeviceDetected));
69 return Tcg2DeviceDetection.TpmDeviceDetected;
70 }
71 }
72
73 DEBUG ((DEBUG_INFO, "DetectTpmDevice:\n"));
74
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
78
79 Status = Tpm12RequestUseTpm ();
80 if (EFI_ERROR (Status)) {
81 //
82 // dTPM not available
83 //
84 return TPM_DEVICE_NULL;
85 }
86
87 if (BootMode == BOOT_ON_S3_RESUME) {
88 Status = Tpm12Startup (TPM_ST_STATE);
89 } else {
90 Status = Tpm12Startup (TPM_ST_CLEAR);
91 }
92
93 if (EFI_ERROR (Status)) {
94 return TPM_DEVICE_2_0_DTPM;
95 }
96
97 // NO initialization needed again.
98 Status = PcdSet8S (PcdTpmInitializationPolicy, 0);
99 ASSERT_EFI_ERROR (Status);
100 return TPM_DEVICE_1_2;
101}
UINT64 UINTN
VOID *EFIAPI ZeroMem(OUT VOID *Buffer, IN UINTN Length)
EFI_STATUS EFIAPI PeiServicesGetBootMode(OUT EFI_BOOT_MODE *BootMode)
EFI_STATUS EFIAPI PeiServicesLocatePpi(IN CONST EFI_GUID *Guid, IN UINTN Instance, IN OUT EFI_PEI_PPI_DESCRIPTOR **PpiDescriptor, IN OUT VOID **Ppi)
#define NULL
Definition: Base.h:319
#define IN
Definition: Base.h:279
#define ASSERT_EFI_ERROR(StatusParameter)
Definition: DebugLib.h:462
#define DEBUG(Expression)
Definition: DebugLib.h:434
#define PcdSet8S(TokenName, Value)
Definition: PcdLib.h:469
UINT32 EFI_BOOT_MODE
Definition: PiBootMode.h:18
#define TPM_ST_STATE
The TPM is starting up from a saved state.
Definition: Tpm12.h:338
#define TPM_ST_CLEAR
The TPM is starting up from a clean state.
Definition: Tpm12.h:337
EFI_STATUS EFIAPI Tpm12Startup(IN TPM_STARTUP_TYPE TpmSt)
Definition: Tpm12Startup.c:35
EFI_STATUS EFIAPI Tpm12RequestUseTpm(VOID)
Definition: Tpm12Tis.c:555
UINT8 DetectTpmDevice(IN UINT8 SetupTpmDevice)
Definition: TpmDetection.c:32
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29