StandaloneMmPkg/Core: pass HOB list in MMRAM to library constructor
The commit changes the code to initializes new HOB list in MMRAM before the ProcessLibraryConstructorList() and pass the MMRAM HOB list to lib constructor. Previously, the HOB list in non-MMRAM range is passed to the lib constructor. Then code in the library constructor would consume unverified HOB list in non-MMRAM buffer. With this commit, the HOB validation and memory allocation HOB migration are doned before the library constructor. Since the HOB list initialization needs to allocate memory in MMRAM, we also need to call the MmInitializeMemoryServices() before the HOB list initialization. Then the duplicated code in the StandaloneMmCore MemoryAllocationLib can also be removed. Signed-off-by: Dun Tan <dun.tan@intel.com>
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
/** @file
|
||||
MM Core Main Entry Point
|
||||
|
||||
Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.<BR>
|
||||
Copyright (c) 2009 - 2025, Intel Corporation. All rights reserved.<BR>
|
||||
Copyright (c) 2016 - 2021, Arm Limited. All rights reserved.<BR>
|
||||
SPDX-License-Identifier: BSD-2-Clause-Patent
|
||||
|
||||
@@ -797,8 +797,6 @@ StandaloneMmMain (
|
||||
EFI_MMRAM_DESCRIPTOR *MmramRanges;
|
||||
UINTN MmramRangeCount;
|
||||
|
||||
ProcessLibraryConstructorList (HobStart, &gMmCoreMmst);
|
||||
|
||||
DEBUG ((DEBUG_INFO, "MmMain - 0x%x\n", HobStart));
|
||||
|
||||
DEBUG_CODE (
|
||||
@@ -838,16 +836,19 @@ StandaloneMmMain (
|
||||
}
|
||||
|
||||
//
|
||||
// No need to initialize memory service.
|
||||
// It is done in the constructor of StandaloneMmCoreMemoryAllocationLib(),
|
||||
// so that the library linked with StandaloneMmCore can use AllocatePool() in
|
||||
// the constructor.
|
||||
// Initialize memory service using free MMRAM
|
||||
//
|
||||
DEBUG ((DEBUG_INFO, "MmInitializeMemoryServices\n"));
|
||||
MmInitializeMemoryServices (MmramRangeCount, MmramRanges);
|
||||
mMemoryAllocationMmst = &gMmCoreMmst;
|
||||
|
||||
//
|
||||
// Install HobList
|
||||
//
|
||||
gHobList = InitializeMmHobList (HobStart, MmramRanges, MmramRangeCount);
|
||||
|
||||
ProcessLibraryConstructorList (gHobList, &gMmCoreMmst);
|
||||
|
||||
//
|
||||
// Register notification for EFI_MM_CONFIGURATION_PROTOCOL registration and
|
||||
// use it to register the MM Foundation entrypoint
|
||||
|
||||
@@ -50,6 +50,8 @@
|
||||
|
||||
#include "StandaloneMmCorePrivateData.h"
|
||||
|
||||
extern EFI_MM_SYSTEM_TABLE *mMemoryAllocationMmst;
|
||||
|
||||
//
|
||||
// Used to build a table of MMI Handlers that the MM Core registers
|
||||
//
|
||||
|
||||
@@ -81,6 +81,7 @@
|
||||
gMmCommBufferHobGuid
|
||||
gEfiSmmSmramMemoryGuid
|
||||
gEdkiiPiSmmMemoryAttributesTableGuid
|
||||
gEfiMmPeiMmramMemoryReserveGuid
|
||||
|
||||
[Pcd]
|
||||
gStandaloneMmPkgTokenSpaceGuid.PcdFwVolMmMaxEncapsulationDepth ##CONSUMES
|
||||
|
||||
@@ -10,14 +10,11 @@
|
||||
|
||||
#include <PiMm.h>
|
||||
|
||||
#include <Guid/MmramMemoryReserve.h>
|
||||
#include <Library/MemoryAllocationLib.h>
|
||||
#include <Library/BaseMemoryLib.h>
|
||||
#include <Library/DebugLib.h>
|
||||
#include <Library/HobLib.h>
|
||||
#include "StandaloneMmCoreMemoryAllocationServices.h"
|
||||
|
||||
static EFI_MM_SYSTEM_TABLE *mMemoryAllocationMmst = NULL;
|
||||
EFI_MM_SYSTEM_TABLE *mMemoryAllocationMmst = NULL;
|
||||
|
||||
/**
|
||||
Allocates one or more 4KB pages of a certain memory type.
|
||||
@@ -827,81 +824,3 @@ FreePool (
|
||||
Status = mMemoryAllocationMmst->MmFreePool (Buffer);
|
||||
ASSERT_EFI_ERROR (Status);
|
||||
}
|
||||
|
||||
/**
|
||||
The constructor function calls MmInitializeMemoryServices to initialize
|
||||
memory in MMRAM and caches EFI_MM_SYSTEM_TABLE pointer.
|
||||
|
||||
@param [in] ImageHandle The firmware allocated handle for the EFI image.
|
||||
@param [in] MmSystemTable A pointer to the Management mode System Table.
|
||||
|
||||
@retval EFI_SUCCESS The constructor always returns EFI_SUCCESS.
|
||||
|
||||
**/
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
MemoryAllocationLibConstructor (
|
||||
IN EFI_HANDLE ImageHandle,
|
||||
IN EFI_MM_SYSTEM_TABLE *MmSystemTable
|
||||
)
|
||||
{
|
||||
VOID *HobStart;
|
||||
EFI_MMRAM_HOB_DESCRIPTOR_BLOCK *MmramRangesHobData;
|
||||
EFI_MMRAM_DESCRIPTOR *MmramRanges;
|
||||
UINTN MmramRangeCount;
|
||||
EFI_HOB_GUID_TYPE *MmramRangesHob;
|
||||
|
||||
HobStart = GetHobList ();
|
||||
DEBUG ((DEBUG_INFO, "StandaloneMmCoreMemoryAllocationLibConstructor - 0x%x\n", HobStart));
|
||||
|
||||
//
|
||||
// Search for a Hob containing the MMRAM ranges
|
||||
//
|
||||
MmramRangesHob = GetNextGuidHob (&gEfiSmmSmramMemoryGuid, HobStart);
|
||||
if (MmramRangesHob == NULL) {
|
||||
MmramRangesHob = GetNextGuidHob (&gEfiMmPeiMmramMemoryReserveGuid, HobStart);
|
||||
if (MmramRangesHob == NULL) {
|
||||
return EFI_UNSUPPORTED;
|
||||
}
|
||||
}
|
||||
|
||||
MmramRangesHobData = GET_GUID_HOB_DATA (MmramRangesHob);
|
||||
if (MmramRangesHobData == NULL) {
|
||||
return EFI_UNSUPPORTED;
|
||||
}
|
||||
|
||||
MmramRanges = MmramRangesHobData->Descriptor;
|
||||
if (MmramRanges == NULL) {
|
||||
return EFI_UNSUPPORTED;
|
||||
}
|
||||
|
||||
MmramRangeCount = (UINTN)MmramRangesHobData->NumberOfMmReservedRegions;
|
||||
if (MmramRanges == NULL) {
|
||||
return EFI_UNSUPPORTED;
|
||||
}
|
||||
|
||||
{
|
||||
UINTN Index;
|
||||
|
||||
DEBUG ((DEBUG_INFO, "MmramRangeCount - 0x%x\n", MmramRangeCount));
|
||||
for (Index = 0; Index < MmramRangeCount; Index++) {
|
||||
DEBUG ((
|
||||
DEBUG_INFO,
|
||||
"MmramRanges[%d]: 0x%016lx - 0x%016lx\n",
|
||||
Index,
|
||||
MmramRanges[Index].CpuStart,
|
||||
MmramRanges[Index].PhysicalSize
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Initialize memory service using free MMRAM
|
||||
//
|
||||
DEBUG ((DEBUG_INFO, "MmInitializeMemoryServices\n"));
|
||||
MmInitializeMemoryServices ((UINTN)MmramRangeCount, (VOID *)(UINTN)MmramRanges);
|
||||
|
||||
// Initialize MM Services Table
|
||||
mMemoryAllocationMmst = MmSystemTable;
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -19,7 +19,6 @@
|
||||
VERSION_STRING = 1.0
|
||||
PI_SPECIFICATION_VERSION = 0x00010032
|
||||
LIBRARY_CLASS = MemoryAllocationLib|MM_CORE_STANDALONE
|
||||
CONSTRUCTOR = MemoryAllocationLibConstructor
|
||||
|
||||
#
|
||||
# The following information is for reference only and not required by the build tools.
|
||||
@@ -29,7 +28,6 @@
|
||||
|
||||
[Sources]
|
||||
StandaloneMmCoreMemoryAllocationLib.c
|
||||
StandaloneMmCoreMemoryAllocationServices.h
|
||||
|
||||
[Packages]
|
||||
MdePkg/MdePkg.dec
|
||||
@@ -38,8 +36,3 @@
|
||||
[LibraryClasses]
|
||||
BaseMemoryLib
|
||||
DebugLib
|
||||
HobLib
|
||||
|
||||
[Guids]
|
||||
gEfiMmPeiMmramMemoryReserveGuid
|
||||
gEfiSmmSmramMemoryGuid
|
||||
|
||||
@@ -1,30 +0,0 @@
|
||||
/** @file
|
||||
Contains function prototypes for Memory Services in the MM Core.
|
||||
|
||||
This header file borrows the StandaloneMmCore Memory Allocation services as the primitive
|
||||
for memory allocation.
|
||||
|
||||
Copyright (c) 2008 - 2015, Intel Corporation. All rights reserved.<BR>
|
||||
Copyright (c) 2016 - 2018, ARM Limited. All rights reserved.<BR>
|
||||
|
||||
SPDX-License-Identifier: BSD-2-Clause-Patent
|
||||
|
||||
**/
|
||||
|
||||
#ifndef _PI_MM_CORE_MEMORY_ALLOCATION_SERVICES_H_
|
||||
#define _PI_MM_CORE_MEMORY_ALLOCATION_SERVICES_H_
|
||||
|
||||
/**
|
||||
Called to initialize the memory service.
|
||||
|
||||
@param MmramRangeCount Number of MMRAM Regions
|
||||
@param MmramRanges Pointer to MMRAM Descriptors
|
||||
|
||||
**/
|
||||
VOID
|
||||
MmInitializeMemoryServices (
|
||||
IN UINTN MmramRangeCount,
|
||||
IN EFI_MMRAM_DESCRIPTOR *MmramRanges
|
||||
);
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user