2 Initialize TPM device and measure FVs before handing off control to DXE.
4 Copyright (c) 2005 - 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 <IndustryStandard/Tpm12.h>
18 #include <IndustryStandard/UefiTcgPlatform.h>
19 #include <Ppi/FirmwareVolumeInfo.h>
20 #include <Ppi/FirmwareVolumeInfo2.h>
21 #include <Ppi/LockPhysicalPresence.h>
22 #include <Ppi/TpmInitialized.h>
23 #include <Ppi/FirmwareVolume.h>
24 #include <Ppi/EndOfPeiPhase.h>
25 #include <Ppi/FirmwareVolumeInfoMeasurementExcluded.h>
27 #include <Guid/TcgEventHob.h>
28 #include <Guid/MeasuredFvHob.h>
29 #include <Guid/TpmInstance.h>
31 #include <Library/DebugLib.h>
32 #include <Library/BaseMemoryLib.h>
33 #include <Library/PeiServicesLib.h>
34 #include <Library/PeimEntryPoint.h>
35 #include <Library/TpmCommLib.h>
36 #include <Library/HobLib.h>
37 #include <Library/PcdLib.h>
38 #include <Library/PeiServicesTablePointerLib.h>
39 #include <Library/BaseLib.h>
40 #include <Library/MemoryAllocationLib.h>
44 BOOLEAN mImageInMemory
= FALSE
;
46 EFI_PEI_PPI_DESCRIPTOR mTpmInitializedPpiList
= {
47 EFI_PEI_PPI_DESCRIPTOR_PPI
| EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
,
48 &gPeiTpmInitializedPpiGuid
,
52 EFI_PLATFORM_FIRMWARE_BLOB
*mMeasuredBaseFvInfo
;
53 UINT32 mMeasuredBaseFvIndex
= 0;
55 EFI_PLATFORM_FIRMWARE_BLOB
*mMeasuredChildFvInfo
;
56 UINT32 mMeasuredChildFvIndex
= 0;
58 EFI_PEI_FIRMWARE_VOLUME_INFO_MEASUREMENT_EXCLUDED_PPI
*mMeasurementExcludedFvPpi
;
61 Lock physical presence if needed.
63 @param[in] PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation
64 @param[in] NotifyDescriptor Address of the notification descriptor data structure.
65 @param[in] Ppi Address of the PPI that was installed.
67 @retval EFI_SUCCESS Operation completed successfully.
72 PhysicalPresencePpiNotifyCallback (
73 IN EFI_PEI_SERVICES
**PeiServices
,
74 IN EFI_PEI_NOTIFY_DESCRIPTOR
*NotifyDescriptor
,
79 Measure and record the Firmware Volum Information once FvInfoPPI install.
81 @param[in] PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation.
82 @param[in] NotifyDescriptor Address of the notification descriptor data structure.
83 @param[in] Ppi Address of the PPI that was installed.
85 @retval EFI_SUCCESS The FV Info is measured and recorded to TPM.
86 @return Others Fail to measure FV.
91 FirmwareVolmeInfoPpiNotifyCallback (
92 IN EFI_PEI_SERVICES
**PeiServices
,
93 IN EFI_PEI_NOTIFY_DESCRIPTOR
*NotifyDescriptor
,
98 Record all measured Firmware Volum Information into a Guid Hob
100 @param[in] PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation.
101 @param[in] NotifyDescriptor Address of the notification descriptor data structure.
102 @param[in] Ppi Address of the PPI that was installed.
104 @retval EFI_SUCCESS The FV Info is measured and recorded to TPM.
105 @return Others Fail to measure FV.
110 EndofPeiSignalNotifyCallBack (
111 IN EFI_PEI_SERVICES
**PeiServices
,
112 IN EFI_PEI_NOTIFY_DESCRIPTOR
*NotifyDescriptor
,
116 EFI_PEI_NOTIFY_DESCRIPTOR mNotifyList
[] = {
118 EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK
,
119 &gPeiLockPhysicalPresencePpiGuid
,
120 PhysicalPresencePpiNotifyCallback
123 EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK
,
124 &gEfiPeiFirmwareVolumeInfoPpiGuid
,
125 FirmwareVolmeInfoPpiNotifyCallback
128 EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK
,
129 &gEfiPeiFirmwareVolumeInfo2PpiGuid
,
130 FirmwareVolmeInfoPpiNotifyCallback
133 (EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK
| EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
),
134 &gEfiEndOfPeiSignalPpiGuid
,
135 EndofPeiSignalNotifyCallBack
140 Record all measured Firmware Volum Information into a Guid Hob
141 Guid Hob payload layout is
143 UINT32 *************************** FIRMWARE_BLOB number
144 EFI_PLATFORM_FIRMWARE_BLOB******** BLOB Array
146 @param[in] PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation.
147 @param[in] NotifyDescriptor Address of the notification descriptor data structure.
148 @param[in] Ppi Address of the PPI that was installed.
150 @retval EFI_SUCCESS The FV Info is measured and recorded to TPM.
151 @return Others Fail to measure FV.
156 EndofPeiSignalNotifyCallBack (
157 IN EFI_PEI_SERVICES
**PeiServices
,
158 IN EFI_PEI_NOTIFY_DESCRIPTOR
*NotifyDescriptor
,
162 MEASURED_HOB_DATA
*MeasuredHobData
;
164 MeasuredHobData
= NULL
;
167 // Create a Guid hob to save all measured Fv
169 MeasuredHobData
= BuildGuidHob(
171 sizeof(UINTN
) + sizeof(EFI_PLATFORM_FIRMWARE_BLOB
) * (mMeasuredBaseFvIndex
+ mMeasuredChildFvIndex
)
174 if (MeasuredHobData
!= NULL
){
176 // Save measured FV info enty number
178 MeasuredHobData
->Num
= mMeasuredBaseFvIndex
+ mMeasuredChildFvIndex
;
181 // Save measured base Fv info
183 CopyMem (MeasuredHobData
->MeasuredFvBuf
, mMeasuredBaseFvInfo
, sizeof(EFI_PLATFORM_FIRMWARE_BLOB
) * (mMeasuredBaseFvIndex
));
186 // Save measured child Fv info
188 CopyMem (&MeasuredHobData
->MeasuredFvBuf
[mMeasuredBaseFvIndex
] , mMeasuredChildFvInfo
, sizeof(EFI_PLATFORM_FIRMWARE_BLOB
) * (mMeasuredChildFvIndex
));
195 Do a hash operation on a data buffer, extend a specific TPM PCR with the hash result,
196 and build a GUIDed HOB recording the event which will be passed to the DXE phase and
197 added into the Event Log.
199 @param[in] PeiServices Describes the list of possible PEI Services.
200 @param[in] HashData Physical address of the start of the data buffer
201 to be hashed, extended, and logged.
202 @param[in] HashDataLen The length, in bytes, of the buffer referenced by HashData.
203 @param[in] TpmHandle TPM handle.
204 @param[in] NewEventHdr Pointer to a TCG_PCR_EVENT_HDR data structure.
205 @param[in] NewEventData Pointer to the new event data.
207 @retval EFI_SUCCESS Operation completed successfully.
208 @retval EFI_OUT_OF_RESOURCES No enough memory to log the new event.
209 @retval EFI_DEVICE_ERROR The command was unsuccessful.
214 IN EFI_PEI_SERVICES
**PeiServices
,
216 IN UINTN HashDataLen
,
217 IN TIS_TPM_HANDLE TpmHandle
,
218 IN TCG_PCR_EVENT_HDR
*NewEventHdr
,
219 IN UINT8
*NewEventData
226 if (HashDataLen
!= 0) {
227 Status
= TpmCommHashAll (
232 ASSERT_EFI_ERROR (Status
);
235 Status
= TpmCommExtend (
238 &NewEventHdr
->Digest
,
239 NewEventHdr
->PCRIndex
,
242 ASSERT_EFI_ERROR (Status
);
244 HobData
= BuildGuidHob (
245 &gTcgEventEntryHobGuid
,
246 sizeof (*NewEventHdr
) + NewEventHdr
->EventSize
248 if (HobData
== NULL
) {
249 return EFI_OUT_OF_RESOURCES
;
252 CopyMem (HobData
, NewEventHdr
, sizeof (*NewEventHdr
));
253 HobData
= (VOID
*) ((UINT8
*)HobData
+ sizeof (*NewEventHdr
));
254 CopyMem (HobData
, NewEventData
, NewEventHdr
->EventSize
);
259 Measure CRTM version.
261 @param[in] PeiServices Describes the list of possible PEI Services.
262 @param[in] TpmHandle TPM handle.
264 @retval EFI_SUCCESS Operation completed successfully.
265 @retval EFI_OUT_OF_RESOURCES No enough memory to log the new event.
266 @retval EFI_DEVICE_ERROR The command was unsuccessful.
272 IN EFI_PEI_SERVICES
**PeiServices
,
273 IN TIS_TPM_HANDLE TpmHandle
276 TCG_PCR_EVENT_HDR TcgEventHdr
;
279 // Use FirmwareVersion string to represent CRTM version.
280 // OEMs should get real CRTM version string and measure it.
283 TcgEventHdr
.PCRIndex
= 0;
284 TcgEventHdr
.EventType
= EV_S_CRTM_VERSION
;
285 TcgEventHdr
.EventSize
= (UINT32
) StrSize((CHAR16
*)PcdGetPtr (PcdFirmwareVersionString
));
287 return HashLogExtendEvent (
289 (UINT8
*)PcdGetPtr (PcdFirmwareVersionString
),
290 TcgEventHdr
.EventSize
,
293 (UINT8
*)PcdGetPtr (PcdFirmwareVersionString
)
299 Add it into the measured FV list after the FV is measured successfully.
301 @param[in] FvBase Base address of FV image.
302 @param[in] FvLength Length of FV image.
304 @retval EFI_SUCCESS Fv image is measured successfully
305 or it has been already measured.
306 @retval EFI_OUT_OF_RESOURCES No enough memory to log the new event.
307 @retval EFI_DEVICE_ERROR The command was unsuccessful.
313 IN EFI_PHYSICAL_ADDRESS FvBase
,
319 EFI_PLATFORM_FIRMWARE_BLOB FvBlob
;
320 TCG_PCR_EVENT_HDR TcgEventHdr
;
321 TIS_TPM_HANDLE TpmHandle
;
323 TpmHandle
= (TIS_TPM_HANDLE
) (UINTN
) TPM_BASE_ADDRESS
;
326 // Check if it is in Excluded FV list
328 if (mMeasurementExcludedFvPpi
!= NULL
) {
329 for (Index
= 0; Index
< mMeasurementExcludedFvPpi
->Count
; Index
++) {
330 if (mMeasurementExcludedFvPpi
->Fv
[Index
].FvBase
== FvBase
) {
331 DEBUG ((DEBUG_INFO
, "The FV which is excluded by TcgPei starts at: 0x%x\n", FvBase
));
332 DEBUG ((DEBUG_INFO
, "The FV which is excluded by TcgPei has the size: 0x%x\n", FvLength
));
339 // Check whether FV is in the measured FV list.
341 for (Index
= 0; Index
< mMeasuredBaseFvIndex
; Index
++) {
342 if (mMeasuredBaseFvInfo
[Index
].BlobBase
== FvBase
) {
348 // Measure and record the FV to the TPM
350 FvBlob
.BlobBase
= FvBase
;
351 FvBlob
.BlobLength
= FvLength
;
353 DEBUG ((DEBUG_INFO
, "The FV which is measured by TcgPei starts at: 0x%x\n", FvBlob
.BlobBase
));
354 DEBUG ((DEBUG_INFO
, "The FV which is measured by TcgPei has the size: 0x%x\n", FvBlob
.BlobLength
));
356 TcgEventHdr
.PCRIndex
= 0;
357 TcgEventHdr
.EventType
= EV_EFI_PLATFORM_FIRMWARE_BLOB
;
358 TcgEventHdr
.EventSize
= sizeof (FvBlob
);
360 Status
= HashLogExtendEvent (
361 (EFI_PEI_SERVICES
**) GetPeiServicesTablePointer(),
362 (UINT8
*) (UINTN
) FvBlob
.BlobBase
,
363 (UINTN
) FvBlob
.BlobLength
,
368 ASSERT_EFI_ERROR (Status
);
371 // Add new FV into the measured FV list.
373 ASSERT (mMeasuredBaseFvIndex
< PcdGet32 (PcdPeiCoreMaxFvSupported
));
374 if (mMeasuredBaseFvIndex
< PcdGet32 (PcdPeiCoreMaxFvSupported
)) {
375 mMeasuredBaseFvInfo
[mMeasuredBaseFvIndex
].BlobBase
= FvBase
;
376 mMeasuredBaseFvInfo
[mMeasuredBaseFvIndex
].BlobLength
= FvLength
;
377 mMeasuredBaseFvIndex
++;
386 @param[in] PeiServices Describes the list of possible PEI Services.
387 @param[in] TpmHandle TPM handle.
389 @retval EFI_SUCCESS Operation completed successfully.
390 @retval EFI_OUT_OF_RESOURCES No enough memory to log the new event.
391 @retval EFI_DEVICE_ERROR The command was unsuccessful.
397 IN EFI_PEI_SERVICES
**PeiServices
,
398 IN TIS_TPM_HANDLE TpmHandle
403 EFI_PEI_FV_HANDLE VolumeHandle
;
404 EFI_FV_INFO VolumeInfo
;
405 EFI_PEI_FIRMWARE_VOLUME_PPI
*FvPpi
;
410 // Traverse all firmware volume instances of Static Core Root of Trust for Measurement
411 // (S-CRTM), this firmware volume measure policy can be modified/enhanced by special
412 // platform for special CRTM TPM measuring.
414 Status
= PeiServicesFfsFindNextVolume (FvInstances
, &VolumeHandle
);
415 if (EFI_ERROR (Status
)) {
420 // Measure and record the firmware volume that is dispatched by PeiCore
422 Status
= PeiServicesFfsGetVolumeInfo (VolumeHandle
, &VolumeInfo
);
423 ASSERT_EFI_ERROR (Status
);
425 // Locate the corresponding FV_PPI according to founded FV's format guid
427 Status
= PeiServicesLocatePpi (
428 &VolumeInfo
.FvFormat
,
433 if (!EFI_ERROR (Status
)) {
434 MeasureFvImage ((EFI_PHYSICAL_ADDRESS
) (UINTN
) VolumeInfo
.FvStart
, VolumeInfo
.FvSize
);
444 Measure and record the Firmware Volum Information once FvInfoPPI install.
446 @param[in] PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation.
447 @param[in] NotifyDescriptor Address of the notification descriptor data structure.
448 @param[in] Ppi Address of the PPI that was installed.
450 @retval EFI_SUCCESS The FV Info is measured and recorded to TPM.
451 @return Others Fail to measure FV.
456 FirmwareVolmeInfoPpiNotifyCallback (
457 IN EFI_PEI_SERVICES
**PeiServices
,
458 IN EFI_PEI_NOTIFY_DESCRIPTOR
*NotifyDescriptor
,
462 EFI_PEI_FIRMWARE_VOLUME_INFO_PPI
*Fv
;
464 EFI_PEI_FIRMWARE_VOLUME_PPI
*FvPpi
;
467 Fv
= (EFI_PEI_FIRMWARE_VOLUME_INFO_PPI
*) Ppi
;
470 // The PEI Core can not dispatch or load files from memory mapped FVs that do not support FvPpi.
472 Status
= PeiServicesLocatePpi (
478 if (EFI_ERROR (Status
)) {
483 // This is an FV from an FFS file, and the parent FV must have already been measured,
484 // No need to measure twice, so just record the FV and return
486 if (Fv
->ParentFvName
!= NULL
|| Fv
->ParentFileName
!= NULL
) {
488 ASSERT (mMeasuredChildFvIndex
< PcdGet32 (PcdPeiCoreMaxFvSupported
));
489 if (mMeasuredChildFvIndex
< PcdGet32 (PcdPeiCoreMaxFvSupported
)) {
491 // Check whether FV is in the measured child FV list.
493 for (Index
= 0; Index
< mMeasuredChildFvIndex
; Index
++) {
494 if (mMeasuredChildFvInfo
[Index
].BlobBase
== (EFI_PHYSICAL_ADDRESS
) (UINTN
) Fv
->FvInfo
) {
498 mMeasuredChildFvInfo
[mMeasuredChildFvIndex
].BlobBase
= (EFI_PHYSICAL_ADDRESS
) (UINTN
) Fv
->FvInfo
;
499 mMeasuredChildFvInfo
[mMeasuredChildFvIndex
].BlobLength
= Fv
->FvInfoSize
;
500 mMeasuredChildFvIndex
++;
505 return MeasureFvImage ((EFI_PHYSICAL_ADDRESS
) (UINTN
) Fv
->FvInfo
, Fv
->FvInfoSize
);
509 Set physicalPresenceLifetimeLock, physicalPresenceHWEnable and physicalPresenceCMDEnable bit by corresponding PCDs.
510 And lock physical presence if needed.
512 @param[in] PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation
513 @param[in] NotifyDescriptor Address of the notification descriptor data structure.
514 @param[in] Ppi Address of the PPI that was installed.
516 @retval EFI_SUCCESS Operation completed successfully.
517 @retval EFI_ABORTED physicalPresenceCMDEnable is locked.
518 @retval EFI_DEVICE_ERROR The command was unsuccessful.
523 PhysicalPresencePpiNotifyCallback (
524 IN EFI_PEI_SERVICES
**PeiServices
,
525 IN EFI_PEI_NOTIFY_DESCRIPTOR
*NotifyDescriptor
,
530 PEI_LOCK_PHYSICAL_PRESENCE_PPI
*LockPhysicalPresencePpi
;
531 BOOLEAN LifetimeLock
;
533 TIS_TPM_HANDLE TpmHandle
;
534 TPM_PHYSICAL_PRESENCE PhysicalPresenceValue
;
536 TpmHandle
= (TIS_TPM_HANDLE
) (UINTN
) TPM_BASE_ADDRESS
;
538 Status
= TpmCommGetCapability (PeiServices
, TpmHandle
, NULL
, &LifetimeLock
, &CmdEnable
);
539 if (EFI_ERROR (Status
)) {
544 // 1. Set physicalPresenceLifetimeLock, physicalPresenceHWEnable and physicalPresenceCMDEnable bit by PCDs.
546 if (PcdGetBool (PcdPhysicalPresenceLifetimeLock
) && !LifetimeLock
) {
548 // Lock TPM LifetimeLock is required, and LifetimeLock is not locked yet.
550 PhysicalPresenceValue
= TPM_PHYSICAL_PRESENCE_LIFETIME_LOCK
;
552 if (PcdGetBool (PcdPhysicalPresenceCmdEnable
)) {
553 PhysicalPresenceValue
|= TPM_PHYSICAL_PRESENCE_CMD_ENABLE
;
556 PhysicalPresenceValue
|= TPM_PHYSICAL_PRESENCE_CMD_DISABLE
;
560 if (PcdGetBool (PcdPhysicalPresenceHwEnable
)) {
561 PhysicalPresenceValue
|= TPM_PHYSICAL_PRESENCE_HW_ENABLE
;
563 PhysicalPresenceValue
|= TPM_PHYSICAL_PRESENCE_HW_DISABLE
;
566 Status
= TpmCommPhysicalPresence (
569 PhysicalPresenceValue
571 if (EFI_ERROR (Status
)) {
577 // 2. Lock physical presence if it is required.
579 LockPhysicalPresencePpi
= (PEI_LOCK_PHYSICAL_PRESENCE_PPI
*) Ppi
;
580 if (!LockPhysicalPresencePpi
->LockPhysicalPresence ((CONST EFI_PEI_SERVICES
**) PeiServices
)) {
587 // physicalPresenceCMDEnable is locked, can't change.
593 // Enable physical presence command
594 // It is necessary in order to lock physical presence
596 Status
= TpmCommPhysicalPresence (
599 TPM_PHYSICAL_PRESENCE_CMD_ENABLE
601 if (EFI_ERROR (Status
)) {
607 // Lock physical presence
609 Status
= TpmCommPhysicalPresence (
612 TPM_PHYSICAL_PRESENCE_LOCK
618 Check if TPM chip is activeated or not.
620 @param[in] PeiServices Describes the list of possible PEI Services.
621 @param[in] TpmHandle TPM handle.
623 @retval TRUE TPM is activated.
624 @retval FALSE TPM is deactivated.
630 IN EFI_PEI_SERVICES
**PeiServices
,
631 IN TIS_TPM_HANDLE TpmHandle
637 Status
= TpmCommGetCapability (PeiServices
, TpmHandle
, &Deactivated
, NULL
, NULL
);
638 if (EFI_ERROR (Status
)) {
641 return (BOOLEAN
)(!Deactivated
);
645 Do measurement after memory is ready.
647 @param[in] PeiServices Describes the list of possible PEI Services.
649 @retval EFI_SUCCESS Operation completed successfully.
650 @retval EFI_OUT_OF_RESOURCES No enough memory to log the new event.
651 @retval EFI_DEVICE_ERROR The command was unsuccessful.
657 IN EFI_PEI_SERVICES
**PeiServices
661 TIS_TPM_HANDLE TpmHandle
;
663 Status
= PeiServicesLocatePpi (
664 &gEfiPeiFirmwareVolumeInfoMeasurementExcludedPpiGuid
,
667 (VOID
**)&mMeasurementExcludedFvPpi
669 // Do not check status, because it is optional
671 mMeasuredBaseFvInfo
= (EFI_PLATFORM_FIRMWARE_BLOB
*) AllocateZeroPool (sizeof (EFI_PLATFORM_FIRMWARE_BLOB
) * PcdGet32 (PcdPeiCoreMaxFvSupported
));
672 ASSERT (mMeasuredBaseFvInfo
!= NULL
);
673 mMeasuredChildFvInfo
= (EFI_PLATFORM_FIRMWARE_BLOB
*) AllocateZeroPool (sizeof (EFI_PLATFORM_FIRMWARE_BLOB
) * PcdGet32 (PcdPeiCoreMaxFvSupported
));
674 ASSERT (mMeasuredChildFvInfo
!= NULL
);
676 TpmHandle
= (TIS_TPM_HANDLE
)(UINTN
)TPM_BASE_ADDRESS
;
677 Status
= TisPcRequestUseTpm ((TIS_PC_REGISTERS_PTR
)TpmHandle
);
678 if (EFI_ERROR (Status
)) {
682 if (IsTpmUsable (PeiServices
, TpmHandle
)) {
683 if (PcdGet8 (PcdTpmScrtmPolicy
) == 1) {
684 Status
= MeasureCRTMVersion (PeiServices
, TpmHandle
);
685 ASSERT_EFI_ERROR (Status
);
688 Status
= MeasureMainBios (PeiServices
, TpmHandle
);
693 // 1). for the FvInfoPpi services to measure and record
694 // the additional Fvs to TPM
695 // 2). for the OperatorPresencePpi service to determine whether to
698 Status
= PeiServicesNotifyPpi (&mNotifyList
[0]);
699 ASSERT_EFI_ERROR (Status
);
705 Entry point of this module.
707 @param[in] FileHandle Handle of the file being invoked.
708 @param[in] PeiServices Describes the list of possible PEI Services.
716 IN EFI_PEI_FILE_HANDLE FileHandle
,
717 IN CONST EFI_PEI_SERVICES
**PeiServices
721 EFI_BOOT_MODE BootMode
;
722 TIS_TPM_HANDLE TpmHandle
;
724 if (!CompareGuid (PcdGetPtr(PcdTpmInstanceGuid
), &gEfiTpmDeviceInstanceTpm12Guid
)){
725 DEBUG ((EFI_D_ERROR
, "No TPM12 instance required!\n"));
726 return EFI_UNSUPPORTED
;
730 // Initialize TPM device
732 Status
= PeiServicesGetBootMode (&BootMode
);
733 ASSERT_EFI_ERROR (Status
);
736 // In S3 path, skip shadow logic. no measurement is required
738 if (BootMode
!= BOOT_ON_S3_RESUME
) {
739 Status
= (**PeiServices
).RegisterForShadow(FileHandle
);
740 if (Status
== EFI_ALREADY_STARTED
) {
741 mImageInMemory
= TRUE
;
742 } else if (Status
== EFI_NOT_FOUND
) {
743 ASSERT_EFI_ERROR (Status
);
747 if (!mImageInMemory
) {
748 TpmHandle
= (TIS_TPM_HANDLE
)(UINTN
)TPM_BASE_ADDRESS
;
749 Status
= TisPcRequestUseTpm ((TIS_PC_REGISTERS_PTR
)TpmHandle
);
750 if (EFI_ERROR (Status
)) {
751 DEBUG ((DEBUG_ERROR
, "TPM not detected!\n"));
755 if (PcdGet8 (PcdTpmInitializationPolicy
) == 1) {
756 Status
= TpmCommStartup ((EFI_PEI_SERVICES
**)PeiServices
, TpmHandle
, BootMode
);
757 if (EFI_ERROR (Status
) ) {
763 // TpmSelfTest is optional on S3 path, skip it to save S3 time
765 if (BootMode
!= BOOT_ON_S3_RESUME
) {
766 Status
= TpmCommContinueSelfTest ((EFI_PEI_SERVICES
**)PeiServices
, TpmHandle
);
767 if (EFI_ERROR (Status
)) {
772 Status
= PeiServicesInstallPpi (&mTpmInitializedPpiList
);
773 ASSERT_EFI_ERROR (Status
);
776 if (mImageInMemory
) {
777 Status
= PeimEntryMP ((EFI_PEI_SERVICES
**)PeiServices
);
778 if (EFI_ERROR (Status
)) {