Skip to content

Commit

Permalink
[Cherry-Pick] SecurityPkg: Build gEdkiiTcg2AcpiCommunicateBufferHobGuid
Browse files Browse the repository at this point in the history
Install a callback of gEfiPeiMemoryDiscoveredPpiGuid to
build the gEdkiiTcg2AcpiCommunicateBufferHobGuid in the
Tcg2ConfigPei PEIM.
The HOB contains a buffer reserved by MmUnblockMemoryLib.
The buffer will be used in Tcg2Acpi driver to retrive
information from standalone mm environment.

Signed-off-by: Dun Tan <dun.tan@intel.com>
  • Loading branch information
td36 authored and apop5 committed Oct 31, 2024
1 parent e693d7c commit 4aa6f1d
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
3 changes: 3 additions & 0 deletions SecurityPkg/Tcg/Tcg2Config/Tcg2ConfigPei.inf
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
Tpm12CommandLib
Tpm12DeviceLib
HobLib
MmUnblockMemoryLib

[Guids]
## SOMETIMES_CONSUMES ## Variable:L"TCG2_CONFIGURATION"
Expand All @@ -56,10 +57,12 @@
gEfiTpmDeviceInstanceNoneGuid ## SOMETIMES_CONSUMES ## GUID # TPM device identifier
gEdkiiTpmInstanceHobGuid
gEdkiiTcgPhysicalPresenceInterfaceVerHobGuid
gEdkiiTcg2AcpiCommunicateBufferHobGuid

[Ppis]
gEfiPeiReadOnlyVariable2PpiGuid ## CONSUMES
gPeiTpmInitializationDonePpiGuid ## SOMETIMES_PRODUCES
gEfiPeiMemoryDiscoveredPpiGuid

[Pcd]
gEfiSecurityPkgTokenSpaceGuid.PcdTpmInstanceGuid ## PRODUCES
Expand Down
52 changes: 52 additions & 0 deletions SecurityPkg/Tcg/Tcg2Config/Tcg2ConfigPeim.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
#include <PiPei.h>

#include <Guid/TpmInstance.h>
#include <Guid/Tcg2AcpiCommunicateBuffer.h>
#include <Guid/TpmNvsMm.h>

#include <Library/BaseLib.h>
#include <Library/BaseMemoryLib.h>
Expand All @@ -17,6 +19,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
#include <Library/PeiServicesLib.h>
#include <Library/PcdLib.h>
#include <Library/HobLib.h>
#include <Library/MmUnblockMemoryLib.h>

#include <Ppi/ReadOnlyVariable2.h>
#include <Ppi/TpmInitialized.h>
Expand Down Expand Up @@ -51,6 +54,53 @@ DetectTpmDevice (
IN UINT8 SetupTpmDevice
);

/**
Build gEdkiiTcg2AcpiCommunicateBufferHobGuid.
@param[in] PeiServices General purpose services available to every PEIM.
@param[in] NotifyDescriptor The notification structure this PEIM registered on install.
@param[in] Ppi The memory discovered PPI. Not used.
@retval EFI_SUCCESS The function completed successfully.
@retval others Failed to build Tcg2AcpiCommunicateBuffer Hob.
**/
EFI_STATUS
EFIAPI
BuildTcg2AcpiCommunicateBufferHob (
IN EFI_PEI_SERVICES **PeiServices,
IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor,
IN VOID *Ppi
)
{
TCG2_ACPI_COMMUNICATE_BUFFER *Tcg2AcpiCommunicateBufferHob;
EFI_STATUS Status;
VOID *Buffer;
UINTN Pages;

Pages = sizeof (TCG_NVS);
Buffer = AllocateRuntimePages (Pages);
ASSERT (Buffer != NULL);

Status = MmUnblockMemoryRequest ((UINTN)Buffer, Pages);
if ((Status != EFI_UNSUPPORTED) && EFI_ERROR (Status)) {
return Status;
}

Tcg2AcpiCommunicateBufferHob = BuildGuidHob (&gEdkiiTcg2AcpiCommunicateBufferHobGuid, sizeof (TCG2_ACPI_COMMUNICATE_BUFFER));
ASSERT (Tcg2AcpiCommunicateBufferHob != NULL);
Tcg2AcpiCommunicateBufferHob->Tcg2AcpiCommunicateBuffer = (UINTN)Buffer;
Tcg2AcpiCommunicateBufferHob->Pages = Pages;

return EFI_SUCCESS;
}

EFI_PEI_NOTIFY_DESCRIPTOR mPostMemNotifyList = {
(EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),
&gEfiPeiMemoryDiscoveredPpiGuid,
BuildTcg2AcpiCommunicateBufferHob
};

/**
The entry point for Tcg2 configuration driver.
Expand Down Expand Up @@ -155,6 +205,8 @@ Tcg2ConfigPeimEntryPoint (
);
ASSERT (Hob != NULL);

PeiServicesNotifyPpi (&mPostMemNotifyList);

//
// Selection done
//
Expand Down

0 comments on commit 4aa6f1d

Please sign in to comment.