2 Initialize TPM device and measure FVs before handing off control to DXE.
4 Copyright (c) 2005 - 2015, 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>
41 #include <Library/ReportStatusCodeLib.h>
45 BOOLEAN mImageInMemory
= FALSE
;
47 EFI_PEI_PPI_DESCRIPTOR mTpmInitializedPpiList
= {
48 EFI_PEI_PPI_DESCRIPTOR_PPI
| EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
,
49 &gPeiTpmInitializedPpiGuid
,
53 EFI_PLATFORM_FIRMWARE_BLOB
*mMeasuredBaseFvInfo
;
54 UINT32 mMeasuredBaseFvIndex
= 0;
56 EFI_PLATFORM_FIRMWARE_BLOB
*mMeasuredChildFvInfo
;
57 UINT32 mMeasuredChildFvIndex
= 0;
59 EFI_PEI_FIRMWARE_VOLUME_INFO_MEASUREMENT_EXCLUDED_PPI
*mMeasurementExcludedFvPpi
;
62 Lock physical presence if needed.
64 @param[in] PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation
65 @param[in] NotifyDescriptor Address of the notification descriptor data structure.
66 @param[in] Ppi Address of the PPI that was installed.
68 @retval EFI_SUCCESS Operation completed successfully.
73 PhysicalPresencePpiNotifyCallback (
74 IN EFI_PEI_SERVICES
**PeiServices
,
75 IN EFI_PEI_NOTIFY_DESCRIPTOR
*NotifyDescriptor
,
80 Measure and record the Firmware Volum Information once FvInfoPPI install.
82 @param[in] PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation.
83 @param[in] NotifyDescriptor Address of the notification descriptor data structure.
84 @param[in] Ppi Address of the PPI that was installed.
86 @retval EFI_SUCCESS The FV Info is measured and recorded to TPM.
87 @return Others Fail to measure FV.
92 FirmwareVolmeInfoPpiNotifyCallback (
93 IN EFI_PEI_SERVICES
**PeiServices
,
94 IN EFI_PEI_NOTIFY_DESCRIPTOR
*NotifyDescriptor
,
99 Record all measured Firmware Volum Information into a Guid Hob
101 @param[in] PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation.
102 @param[in] NotifyDescriptor Address of the notification descriptor data structure.
103 @param[in] Ppi Address of the PPI that was installed.
105 @retval EFI_SUCCESS The FV Info is measured and recorded to TPM.
106 @return Others Fail to measure FV.
111 EndofPeiSignalNotifyCallBack (
112 IN EFI_PEI_SERVICES
**PeiServices
,
113 IN EFI_PEI_NOTIFY_DESCRIPTOR
*NotifyDescriptor
,
117 EFI_PEI_NOTIFY_DESCRIPTOR mNotifyList
[] = {
119 EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK
,
120 &gPeiLockPhysicalPresencePpiGuid
,
121 PhysicalPresencePpiNotifyCallback
124 EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK
,
125 &gEfiPeiFirmwareVolumeInfoPpiGuid
,
126 FirmwareVolmeInfoPpiNotifyCallback
129 EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK
,
130 &gEfiPeiFirmwareVolumeInfo2PpiGuid
,
131 FirmwareVolmeInfoPpiNotifyCallback
134 (EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK
| EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
),
135 &gEfiEndOfPeiSignalPpiGuid
,
136 EndofPeiSignalNotifyCallBack
141 Record all measured Firmware Volum Information into a Guid Hob
142 Guid Hob payload layout is
144 UINT32 *************************** FIRMWARE_BLOB number
145 EFI_PLATFORM_FIRMWARE_BLOB******** BLOB Array
147 @param[in] PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation.
148 @param[in] NotifyDescriptor Address of the notification descriptor data structure.
149 @param[in] Ppi Address of the PPI that was installed.
151 @retval EFI_SUCCESS The FV Info is measured and recorded to TPM.
152 @return Others Fail to measure FV.
157 EndofPeiSignalNotifyCallBack (
158 IN EFI_PEI_SERVICES
**PeiServices
,
159 IN EFI_PEI_NOTIFY_DESCRIPTOR
*NotifyDescriptor
,
163 MEASURED_HOB_DATA
*MeasuredHobData
;
165 MeasuredHobData
= NULL
;
168 // Create a Guid hob to save all measured Fv
170 MeasuredHobData
= BuildGuidHob(
172 sizeof(UINTN
) + sizeof(EFI_PLATFORM_FIRMWARE_BLOB
) * (mMeasuredBaseFvIndex
+ mMeasuredChildFvIndex
)
175 if (MeasuredHobData
!= NULL
){
177 // Save measured FV info enty number
179 MeasuredHobData
->Num
= mMeasuredBaseFvIndex
+ mMeasuredChildFvIndex
;
182 // Save measured base Fv info
184 CopyMem (MeasuredHobData
->MeasuredFvBuf
, mMeasuredBaseFvInfo
, sizeof(EFI_PLATFORM_FIRMWARE_BLOB
) * (mMeasuredBaseFvIndex
));
187 // Save measured child Fv info
189 CopyMem (&MeasuredHobData
->MeasuredFvBuf
[mMeasuredBaseFvIndex
] , mMeasuredChildFvInfo
, sizeof(EFI_PLATFORM_FIRMWARE_BLOB
) * (mMeasuredChildFvIndex
));
196 Do a hash operation on a data buffer, extend a specific TPM PCR with the hash result,
197 and build a GUIDed HOB recording the event which will be passed to the DXE phase and
198 added into the Event Log.
200 @param[in] PeiServices Describes the list of possible PEI Services.
201 @param[in] HashData Physical address of the start of the data buffer
202 to be hashed, extended, and logged.
203 @param[in] HashDataLen The length, in bytes, of the buffer referenced by HashData.
204 @param[in] TpmHandle TPM handle.
205 @param[in] NewEventHdr Pointer to a TCG_PCR_EVENT_HDR data structure.
206 @param[in] NewEventData Pointer to the new event data.
208 @retval EFI_SUCCESS Operation completed successfully.
209 @retval EFI_OUT_OF_RESOURCES No enough memory to log the new event.
210 @retval EFI_DEVICE_ERROR The command was unsuccessful.
215 IN EFI_PEI_SERVICES
**PeiServices
,
217 IN UINTN HashDataLen
,
218 IN TIS_TPM_HANDLE TpmHandle
,
219 IN TCG_PCR_EVENT_HDR
*NewEventHdr
,
220 IN UINT8
*NewEventData
226 if (GetFirstGuidHob (&gTpmErrorHobGuid
) != NULL
) {
227 return EFI_DEVICE_ERROR
;
231 if (HashDataLen
!= 0) {
232 Status
= TpmCommHashAll (
237 if (EFI_ERROR (Status
)) {
242 Status
= TpmCommExtend (
245 &NewEventHdr
->Digest
,
246 NewEventHdr
->PCRIndex
,
249 if (EFI_ERROR (Status
)) {
253 HobData
= BuildGuidHob (
254 &gTcgEventEntryHobGuid
,
255 sizeof (*NewEventHdr
) + NewEventHdr
->EventSize
257 if (HobData
== NULL
) {
258 Status
= EFI_OUT_OF_RESOURCES
;
262 CopyMem (HobData
, NewEventHdr
, sizeof (*NewEventHdr
));
263 HobData
= (VOID
*) ((UINT8
*)HobData
+ sizeof (*NewEventHdr
));
264 CopyMem (HobData
, NewEventData
, NewEventHdr
->EventSize
);
267 if ((Status
== EFI_DEVICE_ERROR
) || (Status
== EFI_TIMEOUT
)) {
268 DEBUG ((EFI_D_ERROR
, "HashLogExtendEvent - %r. Disable TPM.\n", Status
));
269 BuildGuidHob (&gTpmErrorHobGuid
,0);
271 EFI_ERROR_CODE
| EFI_ERROR_MINOR
,
272 (PcdGet32 (PcdStatusCodeSubClassTpmDevice
) | EFI_P_EC_INTERFACE_ERROR
)
274 Status
= EFI_DEVICE_ERROR
;
280 Measure CRTM version.
282 @param[in] PeiServices Describes the list of possible PEI Services.
283 @param[in] TpmHandle TPM handle.
285 @retval EFI_SUCCESS Operation completed successfully.
286 @retval EFI_OUT_OF_RESOURCES No enough memory to log the new event.
287 @retval EFI_DEVICE_ERROR The command was unsuccessful.
293 IN EFI_PEI_SERVICES
**PeiServices
,
294 IN TIS_TPM_HANDLE TpmHandle
297 TCG_PCR_EVENT_HDR TcgEventHdr
;
300 // Use FirmwareVersion string to represent CRTM version.
301 // OEMs should get real CRTM version string and measure it.
304 TcgEventHdr
.PCRIndex
= 0;
305 TcgEventHdr
.EventType
= EV_S_CRTM_VERSION
;
306 TcgEventHdr
.EventSize
= (UINT32
) StrSize((CHAR16
*)PcdGetPtr (PcdFirmwareVersionString
));
308 return HashLogExtendEvent (
310 (UINT8
*)PcdGetPtr (PcdFirmwareVersionString
),
311 TcgEventHdr
.EventSize
,
314 (UINT8
*)PcdGetPtr (PcdFirmwareVersionString
)
320 Add it into the measured FV list after the FV is measured successfully.
322 @param[in] FvBase Base address of FV image.
323 @param[in] FvLength Length of FV image.
325 @retval EFI_SUCCESS Fv image is measured successfully
326 or it has been already measured.
327 @retval EFI_OUT_OF_RESOURCES No enough memory to log the new event.
328 @retval EFI_DEVICE_ERROR The command was unsuccessful.
334 IN EFI_PHYSICAL_ADDRESS FvBase
,
340 EFI_PLATFORM_FIRMWARE_BLOB FvBlob
;
341 TCG_PCR_EVENT_HDR TcgEventHdr
;
342 TIS_TPM_HANDLE TpmHandle
;
344 TpmHandle
= (TIS_TPM_HANDLE
) (UINTN
) TPM_BASE_ADDRESS
;
347 // Check if it is in Excluded FV list
349 if (mMeasurementExcludedFvPpi
!= NULL
) {
350 for (Index
= 0; Index
< mMeasurementExcludedFvPpi
->Count
; Index
++) {
351 if (mMeasurementExcludedFvPpi
->Fv
[Index
].FvBase
== FvBase
) {
352 DEBUG ((DEBUG_INFO
, "The FV which is excluded by TcgPei starts at: 0x%x\n", FvBase
));
353 DEBUG ((DEBUG_INFO
, "The FV which is excluded by TcgPei has the size: 0x%x\n", FvLength
));
360 // Check whether FV is in the measured FV list.
362 for (Index
= 0; Index
< mMeasuredBaseFvIndex
; Index
++) {
363 if (mMeasuredBaseFvInfo
[Index
].BlobBase
== FvBase
) {
369 // Measure and record the FV to the TPM
371 FvBlob
.BlobBase
= FvBase
;
372 FvBlob
.BlobLength
= FvLength
;
374 DEBUG ((DEBUG_INFO
, "The FV which is measured by TcgPei starts at: 0x%x\n", FvBlob
.BlobBase
));
375 DEBUG ((DEBUG_INFO
, "The FV which is measured by TcgPei has the size: 0x%x\n", FvBlob
.BlobLength
));
377 TcgEventHdr
.PCRIndex
= 0;
378 TcgEventHdr
.EventType
= EV_EFI_PLATFORM_FIRMWARE_BLOB
;
379 TcgEventHdr
.EventSize
= sizeof (FvBlob
);
381 Status
= HashLogExtendEvent (
382 (EFI_PEI_SERVICES
**) GetPeiServicesTablePointer(),
383 (UINT8
*) (UINTN
) FvBlob
.BlobBase
,
384 (UINTN
) FvBlob
.BlobLength
,
391 // Add new FV into the measured FV list.
393 ASSERT (mMeasuredBaseFvIndex
< PcdGet32 (PcdPeiCoreMaxFvSupported
));
394 if (mMeasuredBaseFvIndex
< PcdGet32 (PcdPeiCoreMaxFvSupported
)) {
395 mMeasuredBaseFvInfo
[mMeasuredBaseFvIndex
].BlobBase
= FvBase
;
396 mMeasuredBaseFvInfo
[mMeasuredBaseFvIndex
].BlobLength
= FvLength
;
397 mMeasuredBaseFvIndex
++;
406 @param[in] PeiServices Describes the list of possible PEI Services.
407 @param[in] TpmHandle TPM handle.
409 @retval EFI_SUCCESS Operation completed successfully.
410 @retval EFI_OUT_OF_RESOURCES No enough memory to log the new event.
411 @retval EFI_DEVICE_ERROR The command was unsuccessful.
417 IN EFI_PEI_SERVICES
**PeiServices
,
418 IN TIS_TPM_HANDLE TpmHandle
423 EFI_PEI_FV_HANDLE VolumeHandle
;
424 EFI_FV_INFO VolumeInfo
;
425 EFI_PEI_FIRMWARE_VOLUME_PPI
*FvPpi
;
430 // Traverse all firmware volume instances of Static Core Root of Trust for Measurement
431 // (S-CRTM), this firmware volume measure policy can be modified/enhanced by special
432 // platform for special CRTM TPM measuring.
434 Status
= PeiServicesFfsFindNextVolume (FvInstances
, &VolumeHandle
);
435 if (EFI_ERROR (Status
)) {
440 // Measure and record the firmware volume that is dispatched by PeiCore
442 Status
= PeiServicesFfsGetVolumeInfo (VolumeHandle
, &VolumeInfo
);
443 ASSERT_EFI_ERROR (Status
);
445 // Locate the corresponding FV_PPI according to founded FV's format guid
447 Status
= PeiServicesLocatePpi (
448 &VolumeInfo
.FvFormat
,
453 if (!EFI_ERROR (Status
)) {
454 MeasureFvImage ((EFI_PHYSICAL_ADDRESS
) (UINTN
) VolumeInfo
.FvStart
, VolumeInfo
.FvSize
);
464 Measure and record the Firmware Volum Information once FvInfoPPI install.
466 @param[in] PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation.
467 @param[in] NotifyDescriptor Address of the notification descriptor data structure.
468 @param[in] Ppi Address of the PPI that was installed.
470 @retval EFI_SUCCESS The FV Info is measured and recorded to TPM.
471 @return Others Fail to measure FV.
476 FirmwareVolmeInfoPpiNotifyCallback (
477 IN EFI_PEI_SERVICES
**PeiServices
,
478 IN EFI_PEI_NOTIFY_DESCRIPTOR
*NotifyDescriptor
,
482 EFI_PEI_FIRMWARE_VOLUME_INFO_PPI
*Fv
;
484 EFI_PEI_FIRMWARE_VOLUME_PPI
*FvPpi
;
487 Fv
= (EFI_PEI_FIRMWARE_VOLUME_INFO_PPI
*) Ppi
;
490 // The PEI Core can not dispatch or load files from memory mapped FVs that do not support FvPpi.
492 Status
= PeiServicesLocatePpi (
498 if (EFI_ERROR (Status
)) {
503 // This is an FV from an FFS file, and the parent FV must have already been measured,
504 // No need to measure twice, so just record the FV and return
506 if (Fv
->ParentFvName
!= NULL
|| Fv
->ParentFileName
!= NULL
) {
508 ASSERT (mMeasuredChildFvIndex
< PcdGet32 (PcdPeiCoreMaxFvSupported
));
509 if (mMeasuredChildFvIndex
< PcdGet32 (PcdPeiCoreMaxFvSupported
)) {
511 // Check whether FV is in the measured child FV list.
513 for (Index
= 0; Index
< mMeasuredChildFvIndex
; Index
++) {
514 if (mMeasuredChildFvInfo
[Index
].BlobBase
== (EFI_PHYSICAL_ADDRESS
) (UINTN
) Fv
->FvInfo
) {
518 mMeasuredChildFvInfo
[mMeasuredChildFvIndex
].BlobBase
= (EFI_PHYSICAL_ADDRESS
) (UINTN
) Fv
->FvInfo
;
519 mMeasuredChildFvInfo
[mMeasuredChildFvIndex
].BlobLength
= Fv
->FvInfoSize
;
520 mMeasuredChildFvIndex
++;
525 return MeasureFvImage ((EFI_PHYSICAL_ADDRESS
) (UINTN
) Fv
->FvInfo
, Fv
->FvInfoSize
);
529 Set physicalPresenceLifetimeLock, physicalPresenceHWEnable and physicalPresenceCMDEnable bit by corresponding PCDs.
530 And lock physical presence if needed.
532 @param[in] PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation
533 @param[in] NotifyDescriptor Address of the notification descriptor data structure.
534 @param[in] Ppi Address of the PPI that was installed.
536 @retval EFI_SUCCESS Operation completed successfully.
537 @retval EFI_ABORTED physicalPresenceCMDEnable is locked.
538 @retval EFI_DEVICE_ERROR The command was unsuccessful.
543 PhysicalPresencePpiNotifyCallback (
544 IN EFI_PEI_SERVICES
**PeiServices
,
545 IN EFI_PEI_NOTIFY_DESCRIPTOR
*NotifyDescriptor
,
550 PEI_LOCK_PHYSICAL_PRESENCE_PPI
*LockPhysicalPresencePpi
;
551 BOOLEAN LifetimeLock
;
553 TIS_TPM_HANDLE TpmHandle
;
554 TPM_PHYSICAL_PRESENCE PhysicalPresenceValue
;
556 TpmHandle
= (TIS_TPM_HANDLE
) (UINTN
) TPM_BASE_ADDRESS
;
558 Status
= TpmCommGetCapability (PeiServices
, TpmHandle
, NULL
, &LifetimeLock
, &CmdEnable
);
559 if (EFI_ERROR (Status
)) {
564 // 1. Set physicalPresenceLifetimeLock, physicalPresenceHWEnable and physicalPresenceCMDEnable bit by PCDs.
566 if (PcdGetBool (PcdPhysicalPresenceLifetimeLock
) && !LifetimeLock
) {
568 // Lock TPM LifetimeLock is required, and LifetimeLock is not locked yet.
570 PhysicalPresenceValue
= TPM_PHYSICAL_PRESENCE_LIFETIME_LOCK
;
572 if (PcdGetBool (PcdPhysicalPresenceCmdEnable
)) {
573 PhysicalPresenceValue
|= TPM_PHYSICAL_PRESENCE_CMD_ENABLE
;
576 PhysicalPresenceValue
|= TPM_PHYSICAL_PRESENCE_CMD_DISABLE
;
580 if (PcdGetBool (PcdPhysicalPresenceHwEnable
)) {
581 PhysicalPresenceValue
|= TPM_PHYSICAL_PRESENCE_HW_ENABLE
;
583 PhysicalPresenceValue
|= TPM_PHYSICAL_PRESENCE_HW_DISABLE
;
586 Status
= TpmCommPhysicalPresence (
589 PhysicalPresenceValue
591 if (EFI_ERROR (Status
)) {
597 // 2. Lock physical presence if it is required.
599 LockPhysicalPresencePpi
= (PEI_LOCK_PHYSICAL_PRESENCE_PPI
*) Ppi
;
600 if (!LockPhysicalPresencePpi
->LockPhysicalPresence ((CONST EFI_PEI_SERVICES
**) PeiServices
)) {
607 // physicalPresenceCMDEnable is locked, can't change.
613 // Enable physical presence command
614 // It is necessary in order to lock physical presence
616 Status
= TpmCommPhysicalPresence (
619 TPM_PHYSICAL_PRESENCE_CMD_ENABLE
621 if (EFI_ERROR (Status
)) {
627 // Lock physical presence
629 Status
= TpmCommPhysicalPresence (
632 TPM_PHYSICAL_PRESENCE_LOCK
638 Check if TPM chip is activeated or not.
640 @param[in] PeiServices Describes the list of possible PEI Services.
641 @param[in] TpmHandle TPM handle.
643 @retval TRUE TPM is activated.
644 @retval FALSE TPM is deactivated.
650 IN EFI_PEI_SERVICES
**PeiServices
,
651 IN TIS_TPM_HANDLE TpmHandle
657 Status
= TpmCommGetCapability (PeiServices
, TpmHandle
, &Deactivated
, NULL
, NULL
);
658 if (EFI_ERROR (Status
)) {
661 return (BOOLEAN
)(!Deactivated
);
665 Do measurement after memory is ready.
667 @param[in] PeiServices Describes the list of possible PEI Services.
669 @retval EFI_SUCCESS Operation completed successfully.
670 @retval EFI_OUT_OF_RESOURCES No enough memory to log the new event.
671 @retval EFI_DEVICE_ERROR The command was unsuccessful.
677 IN EFI_PEI_SERVICES
**PeiServices
681 TIS_TPM_HANDLE TpmHandle
;
683 Status
= PeiServicesLocatePpi (
684 &gEfiPeiFirmwareVolumeInfoMeasurementExcludedPpiGuid
,
687 (VOID
**)&mMeasurementExcludedFvPpi
689 // Do not check status, because it is optional
691 mMeasuredBaseFvInfo
= (EFI_PLATFORM_FIRMWARE_BLOB
*) AllocateZeroPool (sizeof (EFI_PLATFORM_FIRMWARE_BLOB
) * PcdGet32 (PcdPeiCoreMaxFvSupported
));
692 ASSERT (mMeasuredBaseFvInfo
!= NULL
);
693 mMeasuredChildFvInfo
= (EFI_PLATFORM_FIRMWARE_BLOB
*) AllocateZeroPool (sizeof (EFI_PLATFORM_FIRMWARE_BLOB
) * PcdGet32 (PcdPeiCoreMaxFvSupported
));
694 ASSERT (mMeasuredChildFvInfo
!= NULL
);
696 TpmHandle
= (TIS_TPM_HANDLE
)(UINTN
)TPM_BASE_ADDRESS
;
697 Status
= TisPcRequestUseTpm ((TIS_PC_REGISTERS_PTR
)TpmHandle
);
698 if (EFI_ERROR (Status
)) {
702 if (IsTpmUsable (PeiServices
, TpmHandle
)) {
703 if (PcdGet8 (PcdTpmScrtmPolicy
) == 1) {
704 Status
= MeasureCRTMVersion (PeiServices
, TpmHandle
);
707 Status
= MeasureMainBios (PeiServices
, TpmHandle
);
712 // 1). for the FvInfoPpi services to measure and record
713 // the additional Fvs to TPM
714 // 2). for the OperatorPresencePpi service to determine whether to
717 Status
= PeiServicesNotifyPpi (&mNotifyList
[0]);
718 ASSERT_EFI_ERROR (Status
);
724 Entry point of this module.
726 @param[in] FileHandle Handle of the file being invoked.
727 @param[in] PeiServices Describes the list of possible PEI Services.
735 IN EFI_PEI_FILE_HANDLE FileHandle
,
736 IN CONST EFI_PEI_SERVICES
**PeiServices
740 EFI_BOOT_MODE BootMode
;
741 TIS_TPM_HANDLE TpmHandle
;
743 if (!CompareGuid (PcdGetPtr(PcdTpmInstanceGuid
), &gEfiTpmDeviceInstanceTpm12Guid
)){
744 DEBUG ((EFI_D_ERROR
, "No TPM12 instance required!\n"));
745 return EFI_UNSUPPORTED
;
749 // Initialize TPM device
751 Status
= PeiServicesGetBootMode (&BootMode
);
752 ASSERT_EFI_ERROR (Status
);
755 // In S3 path, skip shadow logic. no measurement is required
757 if (BootMode
!= BOOT_ON_S3_RESUME
) {
758 Status
= (**PeiServices
).RegisterForShadow(FileHandle
);
759 if (Status
== EFI_ALREADY_STARTED
) {
760 mImageInMemory
= TRUE
;
761 } else if (Status
== EFI_NOT_FOUND
) {
762 ASSERT_EFI_ERROR (Status
);
766 if (!mImageInMemory
) {
767 TpmHandle
= (TIS_TPM_HANDLE
)(UINTN
)TPM_BASE_ADDRESS
;
768 Status
= TisPcRequestUseTpm ((TIS_PC_REGISTERS_PTR
)TpmHandle
);
769 if (EFI_ERROR (Status
)) {
770 DEBUG ((DEBUG_ERROR
, "TPM not detected!\n"));
774 if (PcdGet8 (PcdTpmInitializationPolicy
) == 1) {
775 Status
= TpmCommStartup ((EFI_PEI_SERVICES
**)PeiServices
, TpmHandle
, BootMode
);
776 if (EFI_ERROR (Status
) ) {
782 // TpmSelfTest is optional on S3 path, skip it to save S3 time
784 if (BootMode
!= BOOT_ON_S3_RESUME
) {
785 Status
= TpmCommContinueSelfTest ((EFI_PEI_SERVICES
**)PeiServices
, TpmHandle
);
786 if (EFI_ERROR (Status
)) {
791 Status
= PeiServicesInstallPpi (&mTpmInitializedPpiList
);
792 ASSERT_EFI_ERROR (Status
);
795 if (mImageInMemory
) {
796 Status
= PeimEntryMP ((EFI_PEI_SERVICES
**)PeiServices
);
797 if (EFI_ERROR (Status
)) {