TianoCore EDK2 master
Loading...
Searching...
No Matches
TcgPei.c
Go to the documentation of this file.
1
9#include <PiPei.h>
10
16#include <Ppi/TpmInitialized.h>
17#include <Ppi/FirmwareVolume.h>
18#include <Ppi/EndOfPeiPhase.h>
20#include <Ppi/Tcg.h>
21
22#include <Guid/TcgEventHob.h>
23#include <Guid/MeasuredFvHob.h>
24#include <Guid/TpmInstance.h>
25#include <Guid/MigratedFvInfo.h>
26
27#include <Library/DebugLib.h>
31#include <Library/HobLib.h>
32#include <Library/PcdLib.h>
34#include <Library/BaseLib.h>
41
42BOOLEAN mImageInMemory = FALSE;
43
44EFI_PEI_PPI_DESCRIPTOR mTpmInitializedPpiList = {
45 EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST,
46 &gPeiTpmInitializedPpiGuid,
47 NULL
48};
49
50EFI_PEI_PPI_DESCRIPTOR mTpmInitializationDonePpiList = {
51 EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST,
52 &gPeiTpmInitializationDonePpiGuid,
53 NULL
54};
55
75EFIAPI
77 IN EDKII_TCG_PPI *This,
78 IN UINT64 Flags,
79 IN UINT8 *HashData,
80 IN UINTN HashDataLen,
81 IN TCG_PCR_EVENT_HDR *NewEventHdr,
82 IN UINT8 *NewEventData
83 );
84
85EDKII_TCG_PPI mEdkiiTcgPpi = {
87};
88
89EFI_PEI_PPI_DESCRIPTOR mTcgPpiList = {
90 EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST,
91 &gEdkiiTcgPpiGuid,
92 &mEdkiiTcgPpi
93};
94
95//
96// Number of firmware blobs to grow by each time we run out of room
97//
98#define FIRMWARE_BLOB_GROWTH_STEP 4
99
100EFI_PLATFORM_FIRMWARE_BLOB *mMeasuredBaseFvInfo;
101UINT32 mMeasuredMaxBaseFvIndex = 0;
102UINT32 mMeasuredBaseFvIndex = 0;
103
104EFI_PLATFORM_FIRMWARE_BLOB *mMeasuredChildFvInfo;
105UINT32 mMeasuredMaxChildFvIndex = 0;
106UINT32 mMeasuredChildFvIndex = 0;
107
109
121EFIAPI
123 IN EFI_PEI_SERVICES **PeiServices,
124 IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor,
125 IN VOID *Ppi
126 );
127
140EFIAPI
142 IN EFI_PEI_SERVICES **PeiServices,
143 IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor,
144 IN VOID *Ppi
145 );
146
159EFIAPI
161 IN EFI_PEI_SERVICES **PeiServices,
162 IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor,
163 IN VOID *Ppi
164 );
165
166EFI_PEI_NOTIFY_DESCRIPTOR mNotifyList[] = {
167 {
168 EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK,
169 &gPeiLockPhysicalPresencePpiGuid,
171 },
172 {
173 EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK,
174 &gEfiPeiFirmwareVolumeInfoPpiGuid,
176 },
177 {
178 EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK,
179 &gEfiPeiFirmwareVolumeInfo2PpiGuid,
181 },
182 {
183 (EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),
184 &gEfiEndOfPeiSignalPpiGuid,
186 }
187};
188
205EFIAPI
207 IN EFI_PEI_SERVICES **PeiServices,
208 IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor,
209 IN VOID *Ppi
210 )
211{
212 MEASURED_HOB_DATA *MeasuredHobData;
213
214 MeasuredHobData = NULL;
215
216 PERF_CALLBACK_BEGIN (&gEfiEndOfPeiSignalPpiGuid);
217
218 //
219 // Create a Guid hob to save all measured Fv
220 //
221 MeasuredHobData = BuildGuidHob (
222 &gMeasuredFvHobGuid,
223 sizeof (UINTN) + sizeof (EFI_PLATFORM_FIRMWARE_BLOB) * (mMeasuredBaseFvIndex + mMeasuredChildFvIndex)
224 );
225
226 if (MeasuredHobData != NULL) {
227 //
228 // Save measured FV info enty number
229 //
230 MeasuredHobData->Num = mMeasuredBaseFvIndex + mMeasuredChildFvIndex;
231
232 //
233 // Save measured base Fv info
234 //
235 CopyMem (MeasuredHobData->MeasuredFvBuf, mMeasuredBaseFvInfo, sizeof (EFI_PLATFORM_FIRMWARE_BLOB) * (mMeasuredBaseFvIndex));
236
237 //
238 // Save measured child Fv info
239 //
240 CopyMem (&MeasuredHobData->MeasuredFvBuf[mMeasuredBaseFvIndex], mMeasuredChildFvInfo, sizeof (EFI_PLATFORM_FIRMWARE_BLOB) * (mMeasuredChildFvIndex));
241 }
242
243 PERF_CALLBACK_END (&gEfiEndOfPeiSignalPpiGuid);
244
245 return EFI_SUCCESS;
246}
247
259EFIAPI
261 IN CONST UINT8 *Data,
262 IN UINTN DataLen,
263 OUT TPM_DIGEST *Digest
264 )
265{
266 VOID *Sha1Ctx;
267 UINTN CtxSize;
268
269 CtxSize = Sha1GetContextSize ();
270 Sha1Ctx = AllocatePool (CtxSize);
271 ASSERT (Sha1Ctx != NULL);
272
273 Sha1Init (Sha1Ctx);
274 Sha1Update (Sha1Ctx, Data, DataLen);
275 Sha1Final (Sha1Ctx, (UINT8 *)Digest);
276
277 FreePool (Sha1Ctx);
278
279 return EFI_SUCCESS;
280}
281
301EFIAPI
303 IN EDKII_TCG_PPI *This,
304 IN UINT64 Flags,
305 IN UINT8 *HashData,
306 IN UINTN HashDataLen,
307 IN TCG_PCR_EVENT_HDR *NewEventHdr,
308 IN UINT8 *NewEventData
309 )
310{
311 EFI_STATUS Status;
312 VOID *HobData;
313
314 if (GetFirstGuidHob (&gTpmErrorHobGuid) != NULL) {
315 return EFI_DEVICE_ERROR;
316 }
317
318 HobData = NULL;
319 if (HashDataLen != 0) {
320 Status = TpmCommHashAll (
321 HashData,
322 HashDataLen,
323 &NewEventHdr->Digest
324 );
325 if (EFI_ERROR (Status)) {
326 goto Done;
327 }
328 }
329
330 Status = Tpm12Extend (
331 &NewEventHdr->Digest,
332 NewEventHdr->PCRIndex,
333 NULL
334 );
335 if (EFI_ERROR (Status)) {
336 goto Done;
337 }
338
339 HobData = BuildGuidHob (
340 &gTcgEventEntryHobGuid,
341 sizeof (*NewEventHdr) + NewEventHdr->EventSize
342 );
343 if (HobData == NULL) {
344 Status = EFI_OUT_OF_RESOURCES;
345 goto Done;
346 }
347
348 CopyMem (HobData, NewEventHdr, sizeof (*NewEventHdr));
349 HobData = (VOID *)((UINT8 *)HobData + sizeof (*NewEventHdr));
350 CopyMem (HobData, NewEventData, NewEventHdr->EventSize);
351
352Done:
353 if ((Status == EFI_DEVICE_ERROR) || (Status == EFI_TIMEOUT)) {
354 DEBUG ((DEBUG_ERROR, "HashLogExtendEvent - %r. Disable TPM.\n", Status));
355 BuildGuidHob (&gTpmErrorHobGuid, 0);
357 EFI_ERROR_CODE | EFI_ERROR_MINOR,
358 (PcdGet32 (PcdStatusCodeSubClassTpmDevice) | EFI_P_EC_INTERFACE_ERROR)
359 );
360 Status = EFI_DEVICE_ERROR;
361 }
362
363 return Status;
364}
365
377EFIAPI
379 IN EFI_PEI_SERVICES **PeiServices
380 )
381{
382 TCG_PCR_EVENT_HDR TcgEventHdr;
383
384 //
385 // Use FirmwareVersion string to represent CRTM version.
386 // OEMs should get real CRTM version string and measure it.
387 //
388
389 TcgEventHdr.PCRIndex = 0;
390 TcgEventHdr.EventType = EV_S_CRTM_VERSION;
391 TcgEventHdr.EventSize = (UINT32)StrSize ((CHAR16 *)PcdGetPtr (PcdFirmwareVersionString));
392
393 return HashLogExtendEvent (
394 &mEdkiiTcgPpi,
395 0,
396 (UINT8 *)PcdGetPtr (PcdFirmwareVersionString),
397 TcgEventHdr.EventSize,
398 &TcgEventHdr,
399 (UINT8 *)PcdGetPtr (PcdFirmwareVersionString)
400 );
401}
402
417EFIAPI
420 IN UINT64 FvLength
421 )
422{
423 UINT32 Index;
424 EFI_STATUS Status;
426 TCG_PCR_EVENT_HDR TcgEventHdr;
427 EFI_PHYSICAL_ADDRESS FvOrgBase;
428 EFI_PHYSICAL_ADDRESS FvDataBase;
430 EDKII_MIGRATED_FV_INFO *MigratedFvInfo;
431
432 //
433 // Check if it is in Excluded FV list
434 //
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));
440 return EFI_SUCCESS;
441 }
442 }
443 }
444
445 //
446 // Check whether FV is in the measured FV list.
447 //
448 for (Index = 0; Index < mMeasuredBaseFvIndex; Index++) {
449 if (mMeasuredBaseFvInfo[Index].BlobBase == FvBase) {
450 return EFI_SUCCESS;
451 }
452 }
453
454 //
455 // Search the matched migration FV info
456 //
457 FvOrgBase = FvBase;
458 FvDataBase = FvBase;
459 Hob.Raw = GetFirstGuidHob (&gEdkiiMigratedFvInfoGuid);
460 while (Hob.Raw != NULL) {
461 MigratedFvInfo = GET_GUID_HOB_DATA (Hob);
462 if ((MigratedFvInfo->FvNewBase == (UINT32)FvBase) && (MigratedFvInfo->FvLength == (UINT32)FvLength)) {
463 //
464 // Found the migrated FV info
465 //
466 FvOrgBase = (EFI_PHYSICAL_ADDRESS)(UINTN)MigratedFvInfo->FvOrgBase;
467 FvDataBase = (EFI_PHYSICAL_ADDRESS)(UINTN)MigratedFvInfo->FvDataBase;
468 break;
469 }
470
471 Hob.Raw = GET_NEXT_HOB (Hob);
472 Hob.Raw = GetNextGuidHob (&gEdkiiMigratedFvInfoGuid, Hob.Raw);
473 }
474
475 //
476 // Measure and record the FV to the TPM
477 //
478 FvBlob.BlobBase = FvOrgBase;
479 FvBlob.BlobLength = FvLength;
480
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));
483
484 TcgEventHdr.PCRIndex = 0;
485 TcgEventHdr.EventType = EV_EFI_PLATFORM_FIRMWARE_BLOB;
486 TcgEventHdr.EventSize = sizeof (FvBlob);
487
488 Status = HashLogExtendEvent (
489 &mEdkiiTcgPpi,
490 0,
491 (UINT8 *)(UINTN)FvDataBase,
492 (UINTN)FvBlob.BlobLength,
493 &TcgEventHdr,
494 (UINT8 *)&FvBlob
495 );
496
497 //
498 // Add new FV into the measured FV list.
499 //
500 if (mMeasuredBaseFvIndex >= mMeasuredMaxBaseFvIndex) {
501 mMeasuredBaseFvInfo = ReallocatePool (
502 sizeof (EFI_PLATFORM_FIRMWARE_BLOB) * mMeasuredMaxBaseFvIndex,
503 sizeof (EFI_PLATFORM_FIRMWARE_BLOB) * (mMeasuredMaxBaseFvIndex + FIRMWARE_BLOB_GROWTH_STEP),
504 mMeasuredBaseFvInfo
505 );
506 ASSERT (mMeasuredBaseFvInfo != NULL);
507 mMeasuredMaxBaseFvIndex = mMeasuredMaxBaseFvIndex + FIRMWARE_BLOB_GROWTH_STEP;
508 }
509
510 mMeasuredBaseFvInfo[mMeasuredBaseFvIndex].BlobBase = FvBase;
511 mMeasuredBaseFvInfo[mMeasuredBaseFvIndex].BlobLength = FvLength;
512 mMeasuredBaseFvIndex++;
513
514 return Status;
515}
516
528EFIAPI
530 IN EFI_PEI_SERVICES **PeiServices
531 )
532{
533 EFI_STATUS Status;
534 UINT32 FvInstances;
535 EFI_PEI_FV_HANDLE VolumeHandle;
536 EFI_FV_INFO VolumeInfo;
538
539 FvInstances = 0;
540 while (TRUE) {
541 //
542 // Traverse all firmware volume instances of Static Core Root of Trust for Measurement
543 // (S-CRTM), this firmware volume measure policy can be modified/enhanced by special
544 // platform for special CRTM TPM measuring.
545 //
546 Status = PeiServicesFfsFindNextVolume (FvInstances, &VolumeHandle);
547 if (EFI_ERROR (Status)) {
548 break;
549 }
550
551 //
552 // Measure and record the firmware volume that is dispatched by PeiCore
553 //
554 Status = PeiServicesFfsGetVolumeInfo (VolumeHandle, &VolumeInfo);
555 ASSERT_EFI_ERROR (Status);
556 //
557 // Locate the corresponding FV_PPI according to founded FV's format guid
558 //
559 Status = PeiServicesLocatePpi (
560 &VolumeInfo.FvFormat,
561 0,
562 NULL,
563 (VOID **)&FvPpi
564 );
565 if (!EFI_ERROR (Status)) {
566 MeasureFvImage ((EFI_PHYSICAL_ADDRESS)(UINTN)VolumeInfo.FvStart, VolumeInfo.FvSize);
567 }
568
569 FvInstances++;
570 }
571
572 return EFI_SUCCESS;
573}
574
587EFIAPI
589 IN EFI_PEI_SERVICES **PeiServices,
590 IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor,
591 IN VOID *Ppi
592 )
593{
595 EFI_STATUS Status;
597 UINTN Index;
598
600
601 //
602 // The PEI Core can not dispatch or load files from memory mapped FVs that do not support FvPpi.
603 //
604 Status = PeiServicesLocatePpi (
605 &Fv->FvFormat,
606 0,
607 NULL,
608 (VOID **)&FvPpi
609 );
610 if (EFI_ERROR (Status)) {
611 return EFI_SUCCESS;
612 }
613
614 //
615 // This is an FV from an FFS file, and the parent FV must have already been measured,
616 // No need to measure twice, so just record the FV and return
617 //
618 if ((Fv->ParentFvName != NULL) || (Fv->ParentFileName != NULL)) {
619 if (mMeasuredChildFvIndex >= mMeasuredMaxChildFvIndex) {
620 mMeasuredChildFvInfo = ReallocatePool (
621 sizeof (EFI_PLATFORM_FIRMWARE_BLOB) * mMeasuredMaxChildFvIndex,
622 sizeof (EFI_PLATFORM_FIRMWARE_BLOB) * (mMeasuredMaxChildFvIndex + FIRMWARE_BLOB_GROWTH_STEP),
623 mMeasuredChildFvInfo
624 );
625 ASSERT (mMeasuredChildFvInfo != NULL);
626 mMeasuredMaxChildFvIndex = mMeasuredMaxChildFvIndex + FIRMWARE_BLOB_GROWTH_STEP;
627 }
628
629 //
630 // Check whether FV is in the measured child FV list.
631 //
632 for (Index = 0; Index < mMeasuredChildFvIndex; Index++) {
633 if (mMeasuredChildFvInfo[Index].BlobBase == (EFI_PHYSICAL_ADDRESS)(UINTN)Fv->FvInfo) {
634 return EFI_SUCCESS;
635 }
636 }
637
638 mMeasuredChildFvInfo[mMeasuredChildFvIndex].BlobBase = (EFI_PHYSICAL_ADDRESS)(UINTN)Fv->FvInfo;
639 mMeasuredChildFvInfo[mMeasuredChildFvIndex].BlobLength = Fv->FvInfoSize;
640 mMeasuredChildFvIndex++;
641 return EFI_SUCCESS;
642 }
643
645}
646
661EFIAPI
663 IN EFI_PEI_SERVICES **PeiServices,
664 IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor,
665 IN VOID *Ppi
666 )
667{
668 EFI_STATUS Status;
669 TPM_PERMANENT_FLAGS TpmPermanentFlags;
670 PEI_LOCK_PHYSICAL_PRESENCE_PPI *LockPhysicalPresencePpi;
671 TPM_PHYSICAL_PRESENCE PhysicalPresenceValue;
672
673 Status = Tpm12GetCapabilityFlagPermanent (&TpmPermanentFlags);
674 if (EFI_ERROR (Status)) {
675 return Status;
676 }
677
678 //
679 // 1. Set physicalPresenceLifetimeLock, physicalPresenceHWEnable and physicalPresenceCMDEnable bit by PCDs.
680 //
681 if (PcdGetBool (PcdPhysicalPresenceLifetimeLock) && !TpmPermanentFlags.physicalPresenceLifetimeLock) {
682 //
683 // Lock TPM LifetimeLock is required, and LifetimeLock is not locked yet.
684 //
685 PhysicalPresenceValue = TPM_PHYSICAL_PRESENCE_LIFETIME_LOCK;
686 TpmPermanentFlags.physicalPresenceLifetimeLock = TRUE;
687
688 if (PcdGetBool (PcdPhysicalPresenceCmdEnable)) {
689 PhysicalPresenceValue |= TPM_PHYSICAL_PRESENCE_CMD_ENABLE;
690 TpmPermanentFlags.physicalPresenceCMDEnable = TRUE;
691 } else {
692 PhysicalPresenceValue |= TPM_PHYSICAL_PRESENCE_CMD_DISABLE;
693 TpmPermanentFlags.physicalPresenceCMDEnable = FALSE;
694 }
695
696 if (PcdGetBool (PcdPhysicalPresenceHwEnable)) {
697 PhysicalPresenceValue |= TPM_PHYSICAL_PRESENCE_HW_ENABLE;
698 } else {
699 PhysicalPresenceValue |= TPM_PHYSICAL_PRESENCE_HW_DISABLE;
700 }
701
702 Status = Tpm12PhysicalPresence (
703 PhysicalPresenceValue
704 );
705 if (EFI_ERROR (Status)) {
706 return Status;
707 }
708 }
709
710 //
711 // 2. Lock physical presence if it is required.
712 //
713 LockPhysicalPresencePpi = (PEI_LOCK_PHYSICAL_PRESENCE_PPI *)Ppi;
714 if (!LockPhysicalPresencePpi->LockPhysicalPresence ((CONST EFI_PEI_SERVICES **)PeiServices)) {
715 return EFI_SUCCESS;
716 }
717
718 if (!TpmPermanentFlags.physicalPresenceCMDEnable) {
719 if (TpmPermanentFlags.physicalPresenceLifetimeLock) {
720 //
721 // physicalPresenceCMDEnable is locked, can't change.
722 //
723 return EFI_ABORTED;
724 }
725
726 //
727 // Enable physical presence command
728 // It is necessary in order to lock physical presence
729 //
730 Status = Tpm12PhysicalPresence (
732 );
733 if (EFI_ERROR (Status)) {
734 return Status;
735 }
736 }
737
738 //
739 // Lock physical presence
740 //
741 Status = Tpm12PhysicalPresence (
743 );
744 return Status;
745}
746
756BOOLEAN
758 VOID
759 )
760{
761 EFI_STATUS Status;
762 TPM_PERMANENT_FLAGS TpmPermanentFlags;
763
764 Status = Tpm12GetCapabilityFlagPermanent (&TpmPermanentFlags);
765 if (EFI_ERROR (Status)) {
766 return FALSE;
767 }
768
769 return (BOOLEAN)(!TpmPermanentFlags.deactivated);
770}
771
783EFIAPI
785 IN EFI_PEI_SERVICES **PeiServices
786 )
787{
788 EFI_STATUS Status;
789
790 Status = PeiServicesLocatePpi (
791 &gEfiPeiFirmwareVolumeInfoMeasurementExcludedPpiGuid,
792 0,
793 NULL,
794 (VOID **)&mMeasurementExcludedFvPpi
795 );
796 // Do not check status, because it is optional
797
798 Status = Tpm12RequestUseTpm ();
799 if (EFI_ERROR (Status)) {
800 return Status;
801 }
802
803 if (IsTpmUsable ()) {
804 if (PcdGet8 (PcdTpmScrtmPolicy) == 1) {
805 Status = MeasureCRTMVersion (PeiServices);
806 }
807
808 Status = MeasureMainBios (PeiServices);
809 }
810
811 //
812 // Post callbacks:
813 // 1). for the FvInfoPpi services to measure and record
814 // the additional Fvs to TPM
815 // 2). for the OperatorPresencePpi service to determine whether to
816 // lock the TPM
817 //
818 Status = PeiServicesNotifyPpi (&mNotifyList[0]);
819 ASSERT_EFI_ERROR (Status);
820
821 //
822 // install Tcg Services
823 //
824 Status = PeiServicesInstallPpi (&mTcgPpiList);
825 ASSERT_EFI_ERROR (Status);
826
827 return Status;
828}
829
840EFIAPI
842 IN EFI_PEI_FILE_HANDLE FileHandle,
843 IN CONST EFI_PEI_SERVICES **PeiServices
844 )
845{
846 EFI_STATUS Status;
847 EFI_STATUS Status2;
848 EFI_BOOT_MODE BootMode;
849
850 if (!CompareGuid (PcdGetPtr (PcdTpmInstanceGuid), &gEfiTpmDeviceInstanceTpm12Guid)) {
851 DEBUG ((DEBUG_ERROR, "No TPM12 instance required!\n"));
852 return EFI_UNSUPPORTED;
853 }
854
855 if (GetFirstGuidHob (&gTpmErrorHobGuid) != NULL) {
856 DEBUG ((DEBUG_ERROR, "TPM error!\n"));
857 return EFI_DEVICE_ERROR;
858 }
859
860 //
861 // Initialize TPM device
862 //
863 Status = PeiServicesGetBootMode (&BootMode);
864 ASSERT_EFI_ERROR (Status);
865
866 //
867 // In S3 path, skip shadow logic. no measurement is required
868 //
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) {
874 ASSERT_EFI_ERROR (Status);
875 }
876 }
877
878 if (!mImageInMemory) {
879 Status = Tpm12RequestUseTpm ();
880 if (EFI_ERROR (Status)) {
881 DEBUG ((DEBUG_ERROR, "TPM not detected!\n"));
882 goto Done;
883 }
884
885 if (PcdGet8 (PcdTpmInitializationPolicy) == 1) {
886 if (BootMode == BOOT_ON_S3_RESUME) {
887 Status = Tpm12Startup (TPM_ST_STATE);
888 } else {
889 Status = Tpm12Startup (TPM_ST_CLEAR);
890 }
891
892 if (EFI_ERROR (Status)) {
893 goto Done;
894 }
895 }
896
897 //
898 // TpmSelfTest is optional on S3 path, skip it to save S3 time
899 //
900 if (BootMode != BOOT_ON_S3_RESUME) {
901 Status = Tpm12ContinueSelfTest ();
902 if (EFI_ERROR (Status)) {
903 goto Done;
904 }
905 }
906
907 //
908 // Only install TpmInitializedPpi on success
909 //
910 Status = PeiServicesInstallPpi (&mTpmInitializedPpiList);
911 ASSERT_EFI_ERROR (Status);
912 }
913
914 if (mImageInMemory) {
915 Status = PeimEntryMP ((EFI_PEI_SERVICES **)PeiServices);
916 return Status;
917 }
918
919Done:
920 if (EFI_ERROR (Status)) {
921 DEBUG ((DEBUG_ERROR, "TPM error! Build Hob\n"));
922 BuildGuidHob (&gTpmErrorHobGuid, 0);
924 EFI_ERROR_CODE | EFI_ERROR_MINOR,
925 (PcdGet32 (PcdStatusCodeSubClassTpmDevice) | EFI_P_EC_INTERFACE_ERROR)
926 );
927 }
928
929 //
930 // Always install TpmInitializationDonePpi no matter success or fail.
931 // Other driver can know TPM initialization state by TpmInitializedPpi.
932 //
933 Status2 = PeiServicesInstallPpi (&mTpmInitializationDonePpiList);
934 ASSERT_EFI_ERROR (Status2);
935
936 return Status;
937}
UINT64 UINTN
VOID *EFIAPI GetFirstGuidHob(IN CONST EFI_GUID *Guid)
Definition: HobLib.c:215
VOID *EFIAPI BuildGuidHob(IN CONST EFI_GUID *Guid, IN UINTN DataLength)
Definition: HobLib.c:336
VOID *EFIAPI GetNextGuidHob(IN CONST EFI_GUID *Guid, IN CONST VOID *HobStart)
Definition: HobLib.c:176
BOOLEAN EFIAPI Sha1Final(IN OUT VOID *Sha1Context, OUT UINT8 *HashValue)
Definition: CryptSha1.c:163
BOOLEAN EFIAPI Sha1Init(OUT VOID *Sha1Context)
Definition: CryptSha1.c:46
UINTN EFIAPI Sha1GetContextSize(VOID)
Definition: CryptSha1.c:22
BOOLEAN EFIAPI Sha1Update(IN OUT VOID *Sha1Context, IN CONST VOID *Data, IN UINTN DataSize)
Definition: CryptSha1.c:115
UINTN EFIAPI StrSize(IN CONST CHAR16 *String)
Definition: String.c:72
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
BOOLEAN EFIAPI CompareGuid(IN CONST GUID *Guid1, IN CONST GUID *Guid2)
Definition: MemLibGuid.c:73
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 NULL
Definition: Base.h:319
#define CONST
Definition: Base.h:259
#define TRUE
Definition: Base.h:301
#define FALSE
Definition: Base.h:307
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
#define ASSERT_EFI_ERROR(StatusParameter)
Definition: DebugLib.h:462
#define DEBUG(Expression)
Definition: DebugLib.h:434
#define REPORT_STATUS_CODE(Type, Value)
#define PcdGet8(TokenName)
Definition: PcdLib.h:336
#define PcdGet32(TokenName)
Definition: PcdLib.h:362
#define PcdGetBool(TokenName)
Definition: PcdLib.h:401
#define PcdGetPtr(TokenName)
Definition: PcdLib.h:388
#define PERF_CALLBACK_END(TriggerGuid)
#define PERF_CALLBACK_BEGIN(TriggerGuid)
UINT32 EFI_BOOT_MODE
Definition: PiBootMode.h:18
VOID * EFI_PEI_FILE_HANDLE
Definition: PiPeiCis.h:26
VOID * EFI_PEI_FV_HANDLE
Definition: PiPeiCis.h:21
#define EFI_ERROR_MINOR
Definition: PiStatusCode.h:58
VOID *EFIAPI AllocatePool(IN UINTN AllocationSize)
EFI_STATUS EFIAPI PeimEntryMA(IN EFI_PEI_FILE_HANDLE FileHandle, IN CONST EFI_PEI_SERVICES **PeiServices)
Definition: TcgPei.c:841
EFI_STATUS EFIAPI MeasureCRTMVersion(IN EFI_PEI_SERVICES **PeiServices)
Definition: TcgPei.c:378
EFI_STATUS EFIAPI FirmwareVolumeInfoPpiNotifyCallback(IN EFI_PEI_SERVICES **PeiServices, IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor, IN VOID *Ppi)
Definition: TcgPei.c:588
EFI_STATUS EFIAPI MeasureMainBios(IN EFI_PEI_SERVICES **PeiServices)
Definition: TcgPei.c:529
EFI_STATUS EFIAPI TpmCommHashAll(IN CONST UINT8 *Data, IN UINTN DataLen, OUT TPM_DIGEST *Digest)
Definition: TcgPei.c:260
EFI_STATUS EFIAPI PeimEntryMP(IN EFI_PEI_SERVICES **PeiServices)
Definition: TcgPei.c:784
EFI_STATUS EFIAPI PhysicalPresencePpiNotifyCallback(IN EFI_PEI_SERVICES **PeiServices, IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor, IN VOID *Ppi)
Definition: TcgPei.c:662
EFI_STATUS EFIAPI EndofPeiSignalNotifyCallBack(IN EFI_PEI_SERVICES **PeiServices, IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor, IN VOID *Ppi)
Definition: TcgPei.c:206
BOOLEAN IsTpmUsable(VOID)
Definition: TcgPei.c:757
EFI_STATUS EFIAPI MeasureFvImage(IN EFI_PHYSICAL_ADDRESS FvBase, IN UINT64 FvLength)
Definition: TcgPei.c:418
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)
Definition: TcgPei.c:302
#define TPM_ST_STATE
The TPM is starting up from a saved state.
Definition: Tpm12.h:338
#define TPM_PHYSICAL_PRESENCE_LOCK
Sets PhysicalPresenceLock = TRUE.
Definition: Tpm12.h:383
#define TPM_PHYSICAL_PRESENCE_LIFETIME_LOCK
Sets the physicalPresenceLifetimeLock to TRUE.
Definition: Tpm12.h:378
UINT16 TPM_PHYSICAL_PRESENCE
Definition: Tpm12.h:69
#define TPM_ST_CLEAR
The TPM is starting up from a clean state.
Definition: Tpm12.h:337
#define TPM_PHYSICAL_PRESENCE_CMD_ENABLE
Sets the physicalPresenceCMDEnable to TRUE.
Definition: Tpm12.h:380
#define TPM_PHYSICAL_PRESENCE_CMD_DISABLE
Sets the physicalPresenceCMDEnable to FALSE.
Definition: Tpm12.h:377
#define TPM_PHYSICAL_PRESENCE_HW_DISABLE
Sets the physicalPresenceHWEnable to FALSE.
Definition: Tpm12.h:376
#define TPM_PHYSICAL_PRESENCE_HW_ENABLE
Sets the physicalPresenceHWEnable to TRUE.
Definition: Tpm12.h:379
EFI_STATUS EFIAPI Tpm12PhysicalPresence(IN TPM_PHYSICAL_PRESENCE PhysicalPresence)
EFI_STATUS EFIAPI Tpm12ContinueSelfTest(VOID)
Definition: Tpm12SelfTest.c:27
EFI_STATUS EFIAPI Tpm12Extend(IN TPM_DIGEST *DigestToExtend, IN TPM_PCRINDEX PcrIndex, OUT TPM_DIGEST *NewPcrValue)
Definition: Tpm12Pcr.c:46
EFI_STATUS EFIAPI Tpm12GetCapabilityFlagPermanent(OUT TPM_PERMANENT_FLAGS *TpmPermanentFlags)
EFI_STATUS EFIAPI Tpm12Startup(IN TPM_STARTUP_TYPE TpmSt)
Definition: Tpm12Startup.c:35
EFI_STATUS EFIAPI Tpm12RequestUseTpm(VOID)
Definition: Tpm12Tis.c:555
UINT64 EFI_PHYSICAL_ADDRESS
Definition: UefiBaseType.h:50
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
#define EFI_SUCCESS
Definition: UefiBaseType.h:112
EFI_GUID FvFormat
Definition: PiPeiCis.h:775
UINT64 FvSize
Definition: PiPeiCis.h:789
VOID * FvStart
Definition: PiPeiCis.h:785