]> git.proxmox.com Git - mirror_edk2.git/blobdiff - SecurityPkg/Tcg/TcgPei/TcgPei.c
SecurityPkg/Tcg: Add TcgPpi
[mirror_edk2.git] / SecurityPkg / Tcg / TcgPei / TcgPei.c
index a9a808c9ecf35702825311dbc6c807845531828e..25333888490774a0ea94e4363eef6d29db31d3f5 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Initialize TPM device and measure FVs before handing off control to DXE.\r
 \r
-Copyright (c) 2005 - 2018, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2005 - 2020, Intel Corporation. All rights reserved.<BR>\r
 SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
 **/\r
@@ -17,6 +17,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
 #include <Ppi/FirmwareVolume.h>\r
 #include <Ppi/EndOfPeiPhase.h>\r
 #include <Ppi/FirmwareVolumeInfoMeasurementExcluded.h>\r
+#include <Ppi/Tcg.h>\r
 \r
 #include <Guid/TcgEventHob.h>\r
 #include <Guid/MeasuredFvHob.h>\r
@@ -51,6 +52,45 @@ EFI_PEI_PPI_DESCRIPTOR  mTpmInitializationDonePpiList = {
   NULL\r
 };\r
 \r
+/**\r
+  Do a hash operation on a data buffer, extend a specific TPM PCR with the hash result,\r
+  and build a GUIDed HOB recording the event which will be passed to the DXE phase and\r
+  added into the Event Log.\r
+\r
+  @param[in]      This          Indicates the calling context\r
+  @param[in]      Flags         Bitmap providing additional information.\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
+\r
+  @retval EFI_SUCCESS           Operation completed successfully.\r
+  @retval EFI_OUT_OF_RESOURCES  No enough memory to log the new event.\r
+  @retval EFI_DEVICE_ERROR      The command was unsuccessful.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+HashLogExtendEvent (\r
+  IN      EDKII_TCG_PPI             *This,\r
+  IN      UINT64                    Flags,\r
+  IN      UINT8                     *HashData,\r
+  IN      UINTN                     HashDataLen,\r
+  IN      TCG_PCR_EVENT_HDR         *NewEventHdr,\r
+  IN      UINT8                     *NewEventData\r
+  );\r
+\r
+EDKII_TCG_PPI mEdkiiTcgPpi = {\r
+  HashLogExtendEvent\r
+};\r
+\r
+EFI_PEI_PPI_DESCRIPTOR  mTcgPpiList = {\r
+  EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST,\r
+  &gEdkiiTcgPpiGuid,\r
+  &mEdkiiTcgPpi\r
+};\r
+\r
 //\r
 // Number of firmware blobs to grow by each time we run out of room\r
 //\r
@@ -243,7 +283,8 @@ TpmCommHashAll (
   and build a GUIDed HOB recording the event which will be passed to the DXE phase and\r
   added into the Event Log.\r
 \r
-  @param[in]      PeiServices   Describes the list of possible PEI Services.\r
+  @param[in]      This          Indicates the calling context.\r
+  @param[in]      Flags         Bitmap providing additional information.\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
@@ -256,8 +297,10 @@ TpmCommHashAll (
 \r
 **/\r
 EFI_STATUS\r
+EFIAPI\r
 HashLogExtendEvent (\r
-  IN      EFI_PEI_SERVICES          **PeiServices,\r
+  IN      EDKII_TCG_PPI             *This,\r
+  IN      UINT64                    Flags,\r
   IN      UINT8                     *HashData,\r
   IN      UINTN                     HashDataLen,\r
   IN      TCG_PCR_EVENT_HDR         *NewEventHdr,\r
@@ -346,7 +389,8 @@ MeasureCRTMVersion (
   TcgEventHdr.EventSize = (UINT32) StrSize((CHAR16*)PcdGetPtr (PcdFirmwareVersionString));\r
 \r
   return HashLogExtendEvent (\r
-           PeiServices,\r
+           &mEdkiiTcgPpi,\r
+           0,\r
            (UINT8*)PcdGetPtr (PcdFirmwareVersionString),\r
            TcgEventHdr.EventSize,\r
            &TcgEventHdr,\r
@@ -415,7 +459,8 @@ MeasureFvImage (
   TcgEventHdr.EventSize = sizeof (FvBlob);\r
 \r
   Status = HashLogExtendEvent (\r
-             (EFI_PEI_SERVICES **) GetPeiServicesTablePointer(),\r
+             &mEdkiiTcgPpi,\r
+             0,\r
              (UINT8*) (UINTN) FvBlob.BlobBase,\r
              (UINTN) FvBlob.BlobLength,\r
              &TcgEventHdr,\r
@@ -744,6 +789,12 @@ PeimEntryMP (
   Status = PeiServicesNotifyPpi (&mNotifyList[0]);\r
   ASSERT_EFI_ERROR (Status);\r
 \r
+  //\r
+  // install Tcg Services\r
+  //\r
+  Status = PeiServicesInstallPpi (&mTcgPpiList);\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
   return Status;\r
 }\r
 \r