TianoCore EDK2 master
Loading...
Searching...
No Matches
MemoryServices.c File Reference
#include "PeiMain.h"

Go to the source code of this file.

Functions

VOID InitializeMemoryServices (IN PEI_CORE_INSTANCE *PrivateData, IN CONST EFI_SEC_PEI_HAND_OFF *SecCoreData, IN PEI_CORE_INSTANCE *OldCoreData)
 
EFI_STATUS EFIAPI PeiInstallPeiMemory (IN CONST EFI_PEI_SERVICES **PeiServices, IN EFI_PHYSICAL_ADDRESS MemoryBegin, IN UINT64 MemoryLength)
 
VOID MigrateMemoryPages (IN PEI_CORE_INSTANCE *Private, IN BOOLEAN TemporaryRamMigrated)
 
VOID ConvertFvHob (IN PEI_CORE_INSTANCE *PrivateData, IN UINTN OrgFvHandle, IN UINTN FvHandle)
 
VOID ConvertMemoryAllocationHobs (IN PEI_CORE_INSTANCE *PrivateData)
 
VOID InternalBuildMemoryAllocationHob (IN EFI_PHYSICAL_ADDRESS BaseAddress, IN UINT64 Length, IN EFI_MEMORY_TYPE MemoryType)
 
VOID UpdateOrSplitMemoryAllocationHob (IN OUT EFI_HOB_MEMORY_ALLOCATION *MemoryAllocationHob, IN EFI_PHYSICAL_ADDRESS Memory, IN UINT64 Bytes, IN EFI_MEMORY_TYPE MemoryType)
 
BOOLEAN MergeFreeMemoryInMemoryAllocationHob (VOID)
 
EFI_STATUS FindFreeMemoryFromMemoryAllocationHob (IN EFI_MEMORY_TYPE MemoryType, IN UINTN Pages, IN UINTN Granularity, OUT EFI_PHYSICAL_ADDRESS *Memory)
 
EFI_STATUS EFIAPI PeiAllocatePages (IN CONST EFI_PEI_SERVICES **PeiServices, IN EFI_MEMORY_TYPE MemoryType, IN UINTN Pages, OUT EFI_PHYSICAL_ADDRESS *Memory)
 
VOID FreeMemoryAllocationHob (IN PEI_CORE_INSTANCE *PrivateData, IN OUT EFI_HOB_MEMORY_ALLOCATION *MemoryAllocationHobToFree)
 
EFI_STATUS EFIAPI PeiFreePages (IN CONST EFI_PEI_SERVICES **PeiServices, IN EFI_PHYSICAL_ADDRESS Memory, IN UINTN Pages)
 
EFI_STATUS EFIAPI PeiAllocatePool (IN CONST EFI_PEI_SERVICES **PeiServices, IN UINTN Size, OUT VOID **Buffer)
 

Detailed Description

EFI PEI Core memory services

Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent

Definition in file MemoryServices.c.

Function Documentation

◆ ConvertFvHob()

VOID ConvertFvHob ( IN PEI_CORE_INSTANCE PrivateData,
IN UINTN  OrgFvHandle,
IN UINTN  FvHandle 
)

Migrate the base address in firmware volume allocation HOBs from temporary memory to PEI installed memory.

Parameters
[in]PrivateDataPointer to PeiCore's private data structure.
[in]OrgFvHandleAddress of FV Handle in temporary memory.
[in]FvHandleAddress of FV Handle in permanent memory.

Definition at line 179 of file MemoryServices.c.

◆ ConvertMemoryAllocationHobs()

VOID ConvertMemoryAllocationHobs ( IN PEI_CORE_INSTANCE PrivateData)

Migrate MemoryBaseAddress in memory allocation HOBs from the temporary memory to PEI installed memory.

Parameters
[in]PrivateDataPointer to PeiCore's private data structure.

Definition at line 220 of file MemoryServices.c.

◆ FindFreeMemoryFromMemoryAllocationHob()

EFI_STATUS FindFreeMemoryFromMemoryAllocationHob ( IN EFI_MEMORY_TYPE  MemoryType,
IN UINTN  Pages,
IN UINTN  Granularity,
OUT EFI_PHYSICAL_ADDRESS Memory 
)

Find free memory by searching memory allocation HOBs.

Parameters
[in]MemoryTypeThe type of memory to allocate.
[in]PagesThe number of contiguous 4 KB pages to allocate.
[in]GranularityPage allocation granularity.
[out]MemoryPointer to a physical address. On output, the address is set to the base of the page range that was allocated.
Return values
EFI_SUCCESSThe memory range was successfully allocated.
EFI_NOT_FOUNDNo memory allocation HOB with big enough free memory found.

Definition at line 459 of file MemoryServices.c.

◆ FreeMemoryAllocationHob()

VOID FreeMemoryAllocationHob ( IN PEI_CORE_INSTANCE PrivateData,
IN OUT EFI_HOB_MEMORY_ALLOCATION MemoryAllocationHobToFree 
)

Mark the memory allocation HOB to be unused(freed) and update *FreeMemoryTop if MemoryBaseAddress == *FreeMemoryTop.

Parameters
[in]PrivateDataPointer to PeiCore's private data structure.
[in,out]MemoryAllocationHobToFreePointer to memory allocation HOB to be freed.

Definition at line 696 of file MemoryServices.c.

◆ InitializeMemoryServices()

VOID InitializeMemoryServices ( IN PEI_CORE_INSTANCE PrivateData,
IN CONST EFI_SEC_PEI_HAND_OFF SecCoreData,
IN PEI_CORE_INSTANCE OldCoreData 
)

Initialize the memory services.

Parameters
PrivateDataPoints to PeiCore's private instance data.
SecCoreDataPoints to a data structure containing information about the PEI core's operating environment, such as the size and location of temporary RAM, the stack location and the BFV location.
OldCoreDataPointer to the PEI Core data. NULL if being run in non-permanent memory mode.

Definition at line 24 of file MemoryServices.c.

◆ InternalBuildMemoryAllocationHob()

VOID InternalBuildMemoryAllocationHob ( IN EFI_PHYSICAL_ADDRESS  BaseAddress,
IN UINT64  Length,
IN EFI_MEMORY_TYPE  MemoryType 
)

Internal function to build a HOB for the memory allocation. It will search and reuse the unused(freed) memory allocation HOB, or build memory allocation HOB normally if no unused(freed) memory allocation HOB found.

Parameters
[in]BaseAddressThe 64 bit physical address of the memory.
[in]LengthThe length of the memory allocation in bytes.
[in]MemoryTypeThe type of memory allocated by this HOB.

Definition at line 270 of file MemoryServices.c.

◆ MergeFreeMemoryInMemoryAllocationHob()

BOOLEAN MergeFreeMemoryInMemoryAllocationHob ( VOID  )

Merge adjacent free memory ranges in memory allocation HOBs.

Return values
TRUEThere are free memory ranges merged.
FALSENo free memory ranges merged.

Definition at line 381 of file MemoryServices.c.

◆ MigrateMemoryPages()

VOID MigrateMemoryPages ( IN PEI_CORE_INSTANCE Private,
IN BOOLEAN  TemporaryRamMigrated 
)

Migrate memory pages allocated in pre-memory phase. Copy memory pages at temporary heap top to permanent heap top.

Parameters
[in]PrivatePointer to the private data passed in from caller.
[in]TemporaryRamMigratedTemporary memory has been migrated to permanent memory.

Definition at line 113 of file MemoryServices.c.

◆ PeiAllocatePages()

EFI_STATUS EFIAPI PeiAllocatePages ( IN CONST EFI_PEI_SERVICES **  PeiServices,
IN EFI_MEMORY_TYPE  MemoryType,
IN UINTN  Pages,
OUT EFI_PHYSICAL_ADDRESS Memory 
)

The purpose of the service is to publish an interface that allows PEIMs to allocate memory ranges that are managed by the PEI Foundation.

Prior to InstallPeiMemory() being called, PEI will allocate pages from the heap. After InstallPeiMemory() is called, PEI will allocate pages within the region of memory provided by InstallPeiMemory() service in a best-effort fashion. Location-specific allocations are not managed by the PEI foundation code.

Parameters
PeiServicesAn indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation.
MemoryTypeThe type of memory to allocate.
PagesThe number of contiguous 4 KB pages to allocate.
MemoryPointer to a physical address. On output, the address is set to the base of the page range that was allocated.
Return values
EFI_SUCCESSThe memory range was successfully allocated.
EFI_OUT_OF_RESOURCESThe pages could not be allocated.
EFI_INVALID_PARAMETERType is not equal to EfiLoaderCode, EfiLoaderData, EfiRuntimeServicesCode, EfiRuntimeServicesData, EfiBootServicesCode, EfiBootServicesData, EfiACPIReclaimMemory, EfiReservedMemoryType, or EfiACPIMemoryNVS.

Definition at line 545 of file MemoryServices.c.

◆ PeiAllocatePool()

EFI_STATUS EFIAPI PeiAllocatePool ( IN CONST EFI_PEI_SERVICES **  PeiServices,
IN UINTN  Size,
OUT VOID **  Buffer 
)

Pool allocation service. Before permanent memory is discovered, the pool will be allocated in the heap in temporary memory. Generally, the size of the heap in temporary memory does not exceed 64K, so the biggest pool size could be allocated is 64K.

Parameters
PeiServicesAn indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation.
SizeAmount of memory required
BufferAddress of pointer to the buffer
Return values
EFI_SUCCESSThe allocation was successful
EFI_OUT_OF_RESOURCESThere is not enough heap to satisfy the requirement to allocate the requested size.

Definition at line 845 of file MemoryServices.c.

◆ PeiFreePages()

EFI_STATUS EFIAPI PeiFreePages ( IN CONST EFI_PEI_SERVICES **  PeiServices,
IN EFI_PHYSICAL_ADDRESS  Memory,
IN UINTN  Pages 
)

Frees memory pages.

Parameters
[in]PeiServicesAn indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation.
[in]MemoryThe base physical address of the pages to be freed.
[in]PagesThe number of contiguous 4 KB pages to free.
Return values
EFI_SUCCESSThe requested pages were freed.
EFI_INVALID_PARAMETERMemory is not a page-aligned address or Pages is invalid.
EFI_NOT_FOUNDThe requested memory pages were not allocated with AllocatePages().

Definition at line 769 of file MemoryServices.c.

◆ PeiInstallPeiMemory()

EFI_STATUS EFIAPI PeiInstallPeiMemory ( IN CONST EFI_PEI_SERVICES **  PeiServices,
IN EFI_PHYSICAL_ADDRESS  MemoryBegin,
IN UINT64  MemoryLength 
)

This function registers the found memory configuration with the PEI Foundation.

The usage model is that the PEIM that discovers the permanent memory shall invoke this service. This routine will hold discoveried memory information into PeiCore's private data, and set SwitchStackSignal flag. After PEIM who discovery memory is dispatched, PeiDispatcher will migrate temporary memory to permanent memory.

Parameters
PeiServicesAn indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation.
MemoryBeginStart of memory address.
MemoryLengthLength of memory.
Returns
EFI_SUCCESS Always success.

Definition at line 73 of file MemoryServices.c.

◆ UpdateOrSplitMemoryAllocationHob()

VOID UpdateOrSplitMemoryAllocationHob ( IN OUT EFI_HOB_MEMORY_ALLOCATION MemoryAllocationHob,
IN EFI_PHYSICAL_ADDRESS  Memory,
IN UINT64  Bytes,
IN EFI_MEMORY_TYPE  MemoryType 
)

Update or split memory allocation HOB for memory pages allocate and free.

Parameters
[in,out]MemoryAllocationHobPointer to the memory allocation HOB that needs to be updated or split. On output, it will be filled with the input Memory, Bytes and MemoryType.
[in]MemoryMemory to allocate or free.
[in]BytesBytes to allocate or free.
[in]MemoryTypeEfiConventionalMemory for pages free, others for pages allocate.

Definition at line 334 of file MemoryServices.c.