42BOOLEAN mImageInMemory =
FALSE;
45 EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST,
46 &gPeiTpmInitializedPpiGuid,
51 EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST,
52 &gPeiTpmInitializationDonePpiGuid,
82 IN UINT8 *NewEventData
90 EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST,
98#define FIRMWARE_BLOB_GROWTH_STEP 4
101UINT32 mMeasuredMaxBaseFvIndex = 0;
102UINT32 mMeasuredBaseFvIndex = 0;
105UINT32 mMeasuredMaxChildFvIndex = 0;
106UINT32 mMeasuredChildFvIndex = 0;
168 EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK,
169 &gPeiLockPhysicalPresencePpiGuid,
173 EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK,
174 &gEfiPeiFirmwareVolumeInfoPpiGuid,
178 EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK,
179 &gEfiPeiFirmwareVolumeInfo2PpiGuid,
183 (EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),
184 &gEfiEndOfPeiSignalPpiGuid,
214 MeasuredHobData =
NULL;
226 if (MeasuredHobData !=
NULL) {
230 MeasuredHobData->Num = mMeasuredBaseFvIndex + mMeasuredChildFvIndex;
271 ASSERT (Sha1Ctx !=
NULL);
308 IN UINT8 *NewEventData
315 return EFI_DEVICE_ERROR;
319 if (HashDataLen != 0) {
325 if (EFI_ERROR (Status)) {
331 &NewEventHdr->Digest,
332 NewEventHdr->PCRIndex,
335 if (EFI_ERROR (Status)) {
340 &gTcgEventEntryHobGuid,
341 sizeof (*NewEventHdr) + NewEventHdr->EventSize
343 if (HobData ==
NULL) {
344 Status = EFI_OUT_OF_RESOURCES;
348 CopyMem (HobData, NewEventHdr,
sizeof (*NewEventHdr));
349 HobData = (VOID *)((UINT8 *)HobData +
sizeof (*NewEventHdr));
350 CopyMem (HobData, NewEventData, NewEventHdr->EventSize);
353 if ((Status == EFI_DEVICE_ERROR) || (Status == EFI_TIMEOUT)) {
354 DEBUG ((DEBUG_ERROR,
"HashLogExtendEvent - %r. Disable TPM.\n", Status));
358 (
PcdGet32 (PcdStatusCodeSubClassTpmDevice) | EFI_P_EC_INTERFACE_ERROR)
360 Status = EFI_DEVICE_ERROR;
389 TcgEventHdr.PCRIndex = 0;
390 TcgEventHdr.EventType = EV_S_CRTM_VERSION;
391 TcgEventHdr.EventSize = (UINT32)
StrSize ((CHAR16 *)
PcdGetPtr (PcdFirmwareVersionString));
396 (UINT8 *)
PcdGetPtr (PcdFirmwareVersionString),
397 TcgEventHdr.EventSize,
399 (UINT8 *)
PcdGetPtr (PcdFirmwareVersionString)
435 if (mMeasurementExcludedFvPpi !=
NULL) {
436 for (Index = 0; Index < mMeasurementExcludedFvPpi->Count; Index++) {
437 if (mMeasurementExcludedFvPpi->Fv[Index].FvBase == FvBase) {
438 DEBUG ((DEBUG_INFO,
"The FV which is excluded by TcgPei starts at: 0x%x\n", FvBase));
439 DEBUG ((DEBUG_INFO,
"The FV which is excluded by TcgPei has the size: 0x%x\n", FvLength));
448 for (Index = 0; Index < mMeasuredBaseFvIndex; Index++) {
449 if (mMeasuredBaseFvInfo[Index].BlobBase == FvBase) {
460 while (Hob.Raw !=
NULL) {
461 MigratedFvInfo = GET_GUID_HOB_DATA (Hob);
462 if ((MigratedFvInfo->FvNewBase == (UINT32)FvBase) && (MigratedFvInfo->FvLength == (UINT32)FvLength)) {
471 Hob.Raw = GET_NEXT_HOB (Hob);
478 FvBlob.BlobBase = FvOrgBase;
479 FvBlob.BlobLength = FvLength;
481 DEBUG ((DEBUG_INFO,
"The FV which is measured by TcgPei starts at: 0x%x\n", FvBlob.BlobBase));
482 DEBUG ((DEBUG_INFO,
"The FV which is measured by TcgPei has the size: 0x%x\n", FvBlob.BlobLength));
484 TcgEventHdr.PCRIndex = 0;
485 TcgEventHdr.EventType = EV_EFI_PLATFORM_FIRMWARE_BLOB;
486 TcgEventHdr.EventSize =
sizeof (FvBlob);
491 (UINT8 *)(
UINTN)FvDataBase,
492 (
UINTN)FvBlob.BlobLength,
500 if (mMeasuredBaseFvIndex >= mMeasuredMaxBaseFvIndex) {
506 ASSERT (mMeasuredBaseFvInfo !=
NULL);
507 mMeasuredMaxBaseFvIndex = mMeasuredMaxBaseFvIndex + FIRMWARE_BLOB_GROWTH_STEP;
510 mMeasuredBaseFvInfo[mMeasuredBaseFvIndex].BlobBase = FvBase;
511 mMeasuredBaseFvInfo[mMeasuredBaseFvIndex].BlobLength = FvLength;
512 mMeasuredBaseFvIndex++;
547 if (EFI_ERROR (Status)) {
565 if (!EFI_ERROR (Status)) {
610 if (EFI_ERROR (Status)) {
619 if (mMeasuredChildFvIndex >= mMeasuredMaxChildFvIndex) {
625 ASSERT (mMeasuredChildFvInfo !=
NULL);
626 mMeasuredMaxChildFvIndex = mMeasuredMaxChildFvIndex + FIRMWARE_BLOB_GROWTH_STEP;
632 for (Index = 0; Index < mMeasuredChildFvIndex; Index++) {
639 mMeasuredChildFvInfo[mMeasuredChildFvIndex].BlobLength = Fv->
FvInfoSize;
640 mMeasuredChildFvIndex++;
674 if (EFI_ERROR (Status)) {
681 if (
PcdGetBool (PcdPhysicalPresenceLifetimeLock) && !TpmPermanentFlags.physicalPresenceLifetimeLock) {
686 TpmPermanentFlags.physicalPresenceLifetimeLock =
TRUE;
688 if (
PcdGetBool (PcdPhysicalPresenceCmdEnable)) {
690 TpmPermanentFlags.physicalPresenceCMDEnable =
TRUE;
693 TpmPermanentFlags.physicalPresenceCMDEnable =
FALSE;
696 if (
PcdGetBool (PcdPhysicalPresenceHwEnable)) {
703 PhysicalPresenceValue
705 if (EFI_ERROR (Status)) {
718 if (!TpmPermanentFlags.physicalPresenceCMDEnable) {
719 if (TpmPermanentFlags.physicalPresenceLifetimeLock) {
733 if (EFI_ERROR (Status)) {
765 if (EFI_ERROR (Status)) {
769 return (BOOLEAN)(!TpmPermanentFlags.deactivated);
791 &gEfiPeiFirmwareVolumeInfoMeasurementExcludedPpiGuid,
794 (VOID **)&mMeasurementExcludedFvPpi
799 if (EFI_ERROR (Status)) {
804 if (
PcdGet8 (PcdTpmScrtmPolicy) == 1) {
851 DEBUG ((DEBUG_ERROR,
"No TPM12 instance required!\n"));
852 return EFI_UNSUPPORTED;
856 DEBUG ((DEBUG_ERROR,
"TPM error!\n"));
857 return EFI_DEVICE_ERROR;
869 if (BootMode != BOOT_ON_S3_RESUME) {
870 Status = (**PeiServices).RegisterForShadow (FileHandle);
871 if (Status == EFI_ALREADY_STARTED) {
872 mImageInMemory =
TRUE;
873 }
else if (Status == EFI_NOT_FOUND) {
878 if (!mImageInMemory) {
880 if (EFI_ERROR (Status)) {
881 DEBUG ((DEBUG_ERROR,
"TPM not detected!\n"));
885 if (
PcdGet8 (PcdTpmInitializationPolicy) == 1) {
886 if (BootMode == BOOT_ON_S3_RESUME) {
892 if (EFI_ERROR (Status)) {
900 if (BootMode != BOOT_ON_S3_RESUME) {
902 if (EFI_ERROR (Status)) {
914 if (mImageInMemory) {
920 if (EFI_ERROR (Status)) {
921 DEBUG ((DEBUG_ERROR,
"TPM error! Build Hob\n"));
925 (
PcdGet32 (PcdStatusCodeSubClassTpmDevice) | EFI_P_EC_INTERFACE_ERROR)
VOID *EFIAPI GetFirstGuidHob(IN CONST EFI_GUID *Guid)
VOID *EFIAPI BuildGuidHob(IN CONST EFI_GUID *Guid, IN UINTN DataLength)
VOID *EFIAPI GetNextGuidHob(IN CONST EFI_GUID *Guid, IN CONST VOID *HobStart)
BOOLEAN EFIAPI Sha1Final(IN OUT VOID *Sha1Context, OUT UINT8 *HashValue)
BOOLEAN EFIAPI Sha1Init(OUT VOID *Sha1Context)
UINTN EFIAPI Sha1GetContextSize(VOID)
BOOLEAN EFIAPI Sha1Update(IN OUT VOID *Sha1Context, IN CONST VOID *Data, IN UINTN DataSize)
UINTN EFIAPI StrSize(IN CONST CHAR16 *String)
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
BOOLEAN EFIAPI CompareGuid(IN CONST GUID *Guid1, IN CONST GUID *Guid2)
VOID *EFIAPI ReallocatePool(IN UINTN OldSize, IN UINTN NewSize, IN VOID *OldBuffer OPTIONAL)
VOID EFIAPI FreePool(IN VOID *Buffer)
EFI_STATUS EFIAPI PeiServicesFfsFindNextVolume(IN UINTN Instance, IN OUT EFI_PEI_FV_HANDLE *VolumeHandle)
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)
EFI_STATUS EFIAPI PeiServicesNotifyPpi(IN CONST EFI_PEI_NOTIFY_DESCRIPTOR *NotifyList)
EFI_STATUS EFIAPI PeiServicesInstallPpi(IN CONST EFI_PEI_PPI_DESCRIPTOR *PpiList)
EFI_STATUS EFIAPI PeiServicesFfsGetVolumeInfo(IN EFI_PEI_FV_HANDLE VolumeHandle, OUT EFI_FV_INFO *VolumeInfo)
#define ASSERT_EFI_ERROR(StatusParameter)
#define DEBUG(Expression)
#define REPORT_STATUS_CODE(Type, Value)
#define PcdGet8(TokenName)
#define PcdGet32(TokenName)
#define PcdGetBool(TokenName)
#define PcdGetPtr(TokenName)
VOID * EFI_PEI_FILE_HANDLE
VOID *EFIAPI AllocatePool(IN UINTN AllocationSize)
EFI_STATUS EFIAPI PeimEntryMA(IN EFI_PEI_FILE_HANDLE FileHandle, IN CONST EFI_PEI_SERVICES **PeiServices)
EFI_STATUS EFIAPI MeasureCRTMVersion(IN EFI_PEI_SERVICES **PeiServices)
EFI_STATUS EFIAPI FirmwareVolumeInfoPpiNotifyCallback(IN EFI_PEI_SERVICES **PeiServices, IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor, IN VOID *Ppi)
EFI_STATUS EFIAPI MeasureMainBios(IN EFI_PEI_SERVICES **PeiServices)
EFI_STATUS EFIAPI TpmCommHashAll(IN CONST UINT8 *Data, IN UINTN DataLen, OUT TPM_DIGEST *Digest)
EFI_STATUS EFIAPI PeimEntryMP(IN EFI_PEI_SERVICES **PeiServices)
EFI_STATUS EFIAPI PhysicalPresencePpiNotifyCallback(IN EFI_PEI_SERVICES **PeiServices, IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor, IN VOID *Ppi)
EFI_STATUS EFIAPI EndofPeiSignalNotifyCallBack(IN EFI_PEI_SERVICES **PeiServices, IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor, IN VOID *Ppi)
BOOLEAN IsTpmUsable(VOID)
EFI_STATUS EFIAPI MeasureFvImage(IN EFI_PHYSICAL_ADDRESS FvBase, IN UINT64 FvLength)
EFI_STATUS EFIAPI HashLogExtendEvent(IN EDKII_TCG_PPI *This, IN UINT64 Flags, IN UINT8 *HashData, IN UINTN HashDataLen, IN TCG_PCR_EVENT_HDR *NewEventHdr, IN UINT8 *NewEventData)
#define TPM_ST_STATE
The TPM is starting up from a saved state.
#define TPM_PHYSICAL_PRESENCE_LOCK
Sets PhysicalPresenceLock = TRUE.
#define TPM_PHYSICAL_PRESENCE_LIFETIME_LOCK
Sets the physicalPresenceLifetimeLock to TRUE.
UINT16 TPM_PHYSICAL_PRESENCE
#define TPM_ST_CLEAR
The TPM is starting up from a clean state.
#define TPM_PHYSICAL_PRESENCE_CMD_ENABLE
Sets the physicalPresenceCMDEnable to TRUE.
#define TPM_PHYSICAL_PRESENCE_CMD_DISABLE
Sets the physicalPresenceCMDEnable to FALSE.
#define TPM_PHYSICAL_PRESENCE_HW_DISABLE
Sets the physicalPresenceHWEnable to FALSE.
#define TPM_PHYSICAL_PRESENCE_HW_ENABLE
Sets the physicalPresenceHWEnable to TRUE.
EFI_STATUS EFIAPI Tpm12PhysicalPresence(IN TPM_PHYSICAL_PRESENCE PhysicalPresence)
EFI_STATUS EFIAPI Tpm12ContinueSelfTest(VOID)
EFI_STATUS EFIAPI Tpm12Extend(IN TPM_DIGEST *DigestToExtend, IN TPM_PCRINDEX PcrIndex, OUT TPM_DIGEST *NewPcrValue)
EFI_STATUS EFIAPI Tpm12GetCapabilityFlagPermanent(OUT TPM_PERMANENT_FLAGS *TpmPermanentFlags)
EFI_STATUS EFIAPI Tpm12Startup(IN TPM_STARTUP_TYPE TpmSt)
EFI_STATUS EFIAPI Tpm12RequestUseTpm(VOID)
UINT64 EFI_PHYSICAL_ADDRESS
EFI_GUID * ParentFileName