diff --git a/StandaloneMmPkg/Drivers/StandaloneMmIplPei/StandaloneMmIplPei.c b/StandaloneMmPkg/Drivers/StandaloneMmIplPei/StandaloneMmIplPei.c index a3e371f6b9..659c546d71 100644 --- a/StandaloneMmPkg/Drivers/StandaloneMmIplPei/StandaloneMmIplPei.c +++ b/StandaloneMmPkg/Drivers/StandaloneMmIplPei/StandaloneMmIplPei.c @@ -8,6 +8,65 @@ #include "StandaloneMmIplPei.h" +/** + Build communication buffer HOB. + + @return MM_COMM_BUFFER Pointer of MM communication buffer + +**/ +MM_COMM_BUFFER * +MmIplBuildCommBufferHob ( + VOID + ) +{ + EFI_STATUS Status; + MM_COMM_BUFFER *MmCommBuffer; + UINT64 MmCommBufferPages; + + MmCommBufferPages = PcdGet32 (PcdMmCommBufferPages); + + MmCommBuffer = BuildGuidHob (&gMmCommBufferHobGuid, sizeof (MM_COMM_BUFFER)); + ASSERT (MmCommBuffer != NULL); + + // + // Set MM communicate buffer size + // + MmCommBuffer->NumberOfPages = MmCommBufferPages; + + // + // Allocate runtime memory for MM communicate buffer + // + MmCommBuffer->PhysicalStart = (EFI_PHYSICAL_ADDRESS)(UINTN)AllocateRuntimePages (MmCommBufferPages); + if (MmCommBuffer->PhysicalStart == 0) { + DEBUG ((DEBUG_ERROR, "Fail to allocate MM communication buffer\n")); + ASSERT (MmCommBuffer->PhysicalStart != 0); + } + + // + // Build MM unblock memory region HOB for MM communication buffer + // + Status = MmUnblockMemoryRequest (MmCommBuffer->PhysicalStart, MmCommBufferPages); + ASSERT_EFI_ERROR (Status); + + // + // Allocate runtime memory for MM communication status parameters : + // ReturnStatus, ReturnBufferSize, IsCommBufferValid + // + MmCommBuffer->Status = (EFI_PHYSICAL_ADDRESS)(UINTN)AllocateRuntimePages (EFI_SIZE_TO_PAGES (sizeof (MM_COMM_BUFFER_STATUS))); + if (MmCommBuffer->Status == 0) { + DEBUG ((DEBUG_ERROR, "Fail to allocate memory for MM communication status\n")); + ASSERT (MmCommBuffer->Status != 0); + } + + // + // Build MM unblock memory region HOB for MM communication status + // + Status = MmUnblockMemoryRequest (MmCommBuffer->Status, EFI_SIZE_TO_PAGES (sizeof (MM_COMM_BUFFER_STATUS))); + ASSERT_EFI_ERROR (Status); + + return MmCommBuffer; +} + /** The Entry Point for MM IPL at PEI stage. @@ -27,5 +86,13 @@ StandaloneMmIplPeiEntry ( IN CONST EFI_PEI_SERVICES **PeiServices ) { + MM_COMM_BUFFER *MmCommBuffer; + + // + // Build communication buffer HOB. + // + MmCommBuffer = MmIplBuildCommBufferHob (); + ASSERT (MmCommBuffer != NULL); + return EFI_SUCCESS; } diff --git a/StandaloneMmPkg/Drivers/StandaloneMmIplPei/StandaloneMmIplPei.h b/StandaloneMmPkg/Drivers/StandaloneMmIplPei/StandaloneMmIplPei.h index 1b2aef7062..e827852c31 100644 --- a/StandaloneMmPkg/Drivers/StandaloneMmIplPei/StandaloneMmIplPei.h +++ b/StandaloneMmPkg/Drivers/StandaloneMmIplPei/StandaloneMmIplPei.h @@ -9,4 +9,10 @@ #ifndef STANDALONE_MM_IPL_PEI_H_ #define STANDALONE_MM_IPL_PEI_H_ +#include +#include +#include +#include +#include + #endif diff --git a/StandaloneMmPkg/Drivers/StandaloneMmIplPei/StandaloneMmIplPei.inf b/StandaloneMmPkg/Drivers/StandaloneMmIplPei/StandaloneMmIplPei.inf index d5c3c54ebd..8811cc9e36 100644 --- a/StandaloneMmPkg/Drivers/StandaloneMmIplPei/StandaloneMmIplPei.inf +++ b/StandaloneMmPkg/Drivers/StandaloneMmIplPei/StandaloneMmIplPei.inf @@ -29,15 +29,22 @@ [Packages] MdePkg/MdePkg.dec MdeModulePkg/MdeModulePkg.dec + StandaloneMmPkg/StandaloneMmPkg.dec [LibraryClasses] PeimEntryPoint + DebugLib + HobLib + MemoryAllocationLib + MmUnblockMemoryLib [Guids] + gMmCommBufferHobGuid [Ppis] [Pcd] + gEfiMdeModulePkgTokenSpaceGuid.PcdMmCommBufferPages [Depex] TRUE diff --git a/StandaloneMmPkg/StandaloneMmPkg.dsc b/StandaloneMmPkg/StandaloneMmPkg.dsc index 140e6eca74..e42a161947 100644 --- a/StandaloneMmPkg/StandaloneMmPkg.dsc +++ b/StandaloneMmPkg/StandaloneMmPkg.dsc @@ -63,7 +63,10 @@ MmPlatformHobProducerLib|StandaloneMmPkg/Library/MmPlatformHobProducerLibNull/MmPlatformHobProducerLibNull.inf [LibraryClasses.common.PEIM] + HobLib|MdePkg/Library/PeiHobLib/PeiHobLib.inf PeimEntryPoint|MdePkg/Library/PeimEntryPoint/PeimEntryPoint.inf + MemoryAllocationLib|MdePkg/Library/PeiMemoryAllocationLib/PeiMemoryAllocationLib.inf + MmUnblockMemoryLib|MdePkg/Library/MmUnblockMemoryLib/MmUnblockMemoryLibNull.inf [LibraryClasses.AARCH64, LibraryClasses.ARM] ArmLib|ArmPkg/Library/ArmLib/ArmBaseLib.inf