]> git.proxmox.com Git - mirror_edk2.git/blobdiff - SecurityPkg/Tcg/TcgPei/TcgPei.c
SecurityPkg/Tcg: Add use case for new Perf macro
[mirror_edk2.git] / SecurityPkg / Tcg / TcgPei / TcgPei.c
index 63807f44ff6963811879957fea182baf86837047..d07047580c5b2d9eb0cd4a7bf7cfa8237b120f52 100644 (file)
@@ -1,13 +1,13 @@
 /** @file\r
   Initialize TPM device and measure FVs before handing off control to DXE.\r
 \r
-Copyright (c) 2005 - 2017, Intel Corporation. All rights reserved.<BR>\r
-This program and the accompanying materials \r
-are licensed and made available under the terms and conditions of the BSD License \r
-which accompanies this distribution.  The full text of the license may be found at \r
+Copyright (c) 2005 - 2018, Intel Corporation. All rights reserved.<BR>\r
+This program and the accompanying materials\r
+are licensed and made available under the terms and conditions of the BSD License\r
+which accompanies this distribution.  The full text of the license may be found at\r
 http://opensource.org/licenses/bsd-license.php\r
 \r
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
 \r
 **/\r
@@ -41,6 +41,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 #include <Library/Tpm12DeviceLib.h>\r
 #include <Library/Tpm12CommandLib.h>\r
 #include <Library/BaseCryptLib.h>\r
+#include <Library/PerformanceLib.h>\r
 \r
 BOOLEAN                 mImageInMemory  = FALSE;\r
 \r
@@ -129,12 +130,12 @@ EFI_PEI_NOTIFY_DESCRIPTOR           mNotifyList[] = {
   {\r
     EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK,\r
     &gEfiPeiFirmwareVolumeInfoPpiGuid,\r
-    FirmwareVolmeInfoPpiNotifyCallback \r
+    FirmwareVolmeInfoPpiNotifyCallback\r
   },\r
   {\r
     EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK,\r
     &gEfiPeiFirmwareVolumeInfo2PpiGuid,\r
-    FirmwareVolmeInfoPpiNotifyCallback \r
+    FirmwareVolmeInfoPpiNotifyCallback\r
   },\r
   {\r
     (EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),\r
@@ -145,7 +146,7 @@ EFI_PEI_NOTIFY_DESCRIPTOR           mNotifyList[] = {
 \r
 /**\r
   Record all measured Firmware Volum Information into a Guid Hob\r
-  Guid Hob payload layout is \r
+  Guid Hob payload layout is\r
 \r
      UINT32 *************************** FIRMWARE_BLOB number\r
      EFI_PLATFORM_FIRMWARE_BLOB******** BLOB Array\r
@@ -165,13 +166,15 @@ EndofPeiSignalNotifyCallBack (
   IN EFI_PEI_NOTIFY_DESCRIPTOR     *NotifyDescriptor,\r
   IN VOID                          *Ppi\r
   )\r
-{  \r
+{\r
   MEASURED_HOB_DATA *MeasuredHobData;\r
 \r
   MeasuredHobData = NULL;\r
 \r
+  PERF_CALLBACK_BEGIN (&gEfiEndOfPeiSignalPpiGuid);\r
+\r
   //\r
-  // Create a Guid hob to save all measured Fv \r
+  // Create a Guid hob to save all measured Fv\r
   //\r
   MeasuredHobData = BuildGuidHob(\r
                       &gMeasuredFvHobGuid,\r
@@ -195,6 +198,8 @@ EndofPeiSignalNotifyCallBack (
     CopyMem (&MeasuredHobData->MeasuredFvBuf[mMeasuredBaseFvIndex] , mMeasuredChildFvInfo, sizeof(EFI_PLATFORM_FIRMWARE_BLOB) * (mMeasuredChildFvIndex));\r
   }\r
 \r
+  PERF_CALLBACK_END (&gEfiEndOfPeiSignalPpiGuid);\r
+\r
   return EFI_SUCCESS;\r
 }\r
 \r
@@ -238,11 +243,11 @@ TpmCommHashAll (
   added into the Event Log.\r
 \r
   @param[in]      PeiServices   Describes the list of possible PEI Services.\r
-  @param[in]      HashData      Physical address of the start of the data buffer \r
+  @param[in]      HashData      Physical address of the start of the data buffer\r
                                 to be hashed, extended, and logged.\r
   @param[in]      HashDataLen   The length, in bytes, of the buffer referenced by HashData.\r
-  @param[in]      NewEventHdr   Pointer to a TCG_PCR_EVENT_HDR data structure.  \r
-  @param[in]      NewEventData  Pointer to the new event data.  \r
+  @param[in]      NewEventHdr   Pointer to a TCG_PCR_EVENT_HDR data structure.\r
+  @param[in]      NewEventData  Pointer to the new event data.\r
 \r
   @retval EFI_SUCCESS           Operation completed successfully.\r
   @retval EFI_OUT_OF_RESOURCES  No enough memory to log the new event.\r
@@ -260,7 +265,7 @@ HashLogExtendEvent (
 {\r
   EFI_STATUS                        Status;\r
   VOID                              *HobData;\r
-  \r
+\r
   if (GetFirstGuidHob (&gTpmErrorHobGuid) != NULL) {\r
     return EFI_DEVICE_ERROR;\r
   }\r
@@ -349,13 +354,13 @@ MeasureCRTMVersion (
 }\r
 \r
 /**\r
-  Measure FV image. \r
-  Add it into the measured FV list after the FV is measured successfully. \r
+  Measure FV image.\r
+  Add it into the measured FV list after the FV is measured successfully.\r
 \r
   @param[in]  FvBase            Base address of FV image.\r
   @param[in]  FvLength          Length of FV image.\r
 \r
-  @retval EFI_SUCCESS           Fv image is measured successfully \r
+  @retval EFI_SUCCESS           Fv image is measured successfully\r
                                 or it has been already measured.\r
   @retval EFI_OUT_OF_RESOURCES  No enough memory to log the new event.\r
   @retval EFI_DEVICE_ERROR      The command was unsuccessful.\r
@@ -394,7 +399,7 @@ MeasureFvImage (
       return EFI_SUCCESS;\r
     }\r
   }\r
-  \r
+\r
   //\r
   // Measure and record the FV to the TPM\r
   //\r
@@ -450,7 +455,7 @@ MeasureMainBios (
   EFI_PEI_FV_HANDLE                 VolumeHandle;\r
   EFI_FV_INFO                       VolumeInfo;\r
   EFI_PEI_FIRMWARE_VOLUME_PPI       *FvPpi;\r
-  \r
+\r
   FvInstances    = 0;\r
   while (TRUE) {\r
     //\r
@@ -462,7 +467,7 @@ MeasureMainBios (
     if (EFI_ERROR (Status)) {\r
       break;\r
     }\r
-  \r
+\r
     //\r
     // Measure and record the firmware volume that is dispatched by PeiCore\r
     //\r
@@ -472,8 +477,8 @@ MeasureMainBios (
     // Locate the corresponding FV_PPI according to founded FV's format guid\r
     //\r
     Status = PeiServicesLocatePpi (\r
-               &VolumeInfo.FvFormat, \r
-               0, \r
+               &VolumeInfo.FvFormat,\r
+               0,\r
                NULL,\r
                (VOID**)&FvPpi\r
                );\r
@@ -517,21 +522,21 @@ FirmwareVolmeInfoPpiNotifyCallback (
   // The PEI Core can not dispatch or load files from memory mapped FVs that do not support FvPpi.\r
   //\r
   Status = PeiServicesLocatePpi (\r
-             &Fv->FvFormat, \r
-             0, \r
+             &Fv->FvFormat,\r
+             0,\r
              NULL,\r
              (VOID**)&FvPpi\r
              );\r
   if (EFI_ERROR (Status)) {\r
     return EFI_SUCCESS;\r
   }\r
-  \r
+\r
   //\r
   // This is an FV from an FFS file, and the parent FV must have already been measured,\r
   // No need to measure twice, so just record the FV and return\r
   //\r
   if (Fv->ParentFvName != NULL || Fv->ParentFileName != NULL ) {\r
-    \r
+\r
     ASSERT (mMeasuredChildFvIndex < PcdGet32 (PcdPeiCoreMaxFvSupported));\r
     if (mMeasuredChildFvIndex < PcdGet32 (PcdPeiCoreMaxFvSupported)) {\r
       //\r
@@ -588,7 +593,7 @@ PhysicalPresencePpiNotifyCallback (
   //\r
   if (PcdGetBool (PcdPhysicalPresenceLifetimeLock) && !TpmPermanentFlags.physicalPresenceLifetimeLock) {\r
     //\r
-    // Lock TPM LifetimeLock is required, and LifetimeLock is not locked yet. \r
+    // Lock TPM LifetimeLock is required, and LifetimeLock is not locked yet.\r
     //\r
     PhysicalPresenceValue = TPM_PHYSICAL_PRESENCE_LIFETIME_LOCK;\r
     TpmPermanentFlags.physicalPresenceLifetimeLock = TRUE;\r
@@ -605,8 +610,8 @@ PhysicalPresencePpiNotifyCallback (
       PhysicalPresenceValue |= TPM_PHYSICAL_PRESENCE_HW_ENABLE;\r
     } else {\r
       PhysicalPresenceValue |= TPM_PHYSICAL_PRESENCE_HW_DISABLE;\r
-    }      \r
-     \r
+    }\r
+\r
     Status = Tpm12PhysicalPresence (\r
                PhysicalPresenceValue\r
                );\r
@@ -614,7 +619,7 @@ PhysicalPresencePpiNotifyCallback (
       return Status;\r
     }\r
   }\r
-  \r
+\r
   //\r
   // 2. Lock physical presence if it is required.\r
   //\r
@@ -645,7 +650,7 @@ PhysicalPresencePpiNotifyCallback (
 \r
   //\r
   // Lock physical presence\r
-  // \r
+  //\r
   Status = Tpm12PhysicalPresence (\r
               TPM_PHYSICAL_PRESENCE_LOCK\r
               );\r
@@ -695,8 +700,8 @@ PeimEntryMP (
   EFI_STATUS                        Status;\r
 \r
   Status = PeiServicesLocatePpi (\r
-               &gEfiPeiFirmwareVolumeInfoMeasurementExcludedPpiGuid, \r
-               0, \r
+               &gEfiPeiFirmwareVolumeInfoMeasurementExcludedPpiGuid,\r
+               0,\r
                NULL,\r
                (VOID**)&mMeasurementExcludedFvPpi\r
                );\r
@@ -718,13 +723,13 @@ PeimEntryMP (
     }\r
 \r
     Status = MeasureMainBios (PeiServices);\r
-  }  \r
+  }\r
 \r
   //\r
   // Post callbacks:\r
   // 1). for the FvInfoPpi services to measure and record\r
   // the additional Fvs to TPM\r
-  // 2). for the OperatorPresencePpi service to determine whether to \r
+  // 2). for the OperatorPresencePpi service to determine whether to\r
   // lock the TPM\r
   //\r
   Status = PeiServicesNotifyPpi (&mNotifyList[0]);\r