TianoCore EDK2 master
Loading...
Searching...
No Matches
Page.c File Reference

Go to the source code of this file.

Data Structures

struct  MEMORY_MAP
 

Macros

#define TRUNCATE_TO_PAGES(a)   ((a) >> EFI_PAGE_SHIFT)
 
#define MEMORY_MAP_SIGNATURE   SIGNATURE_32('m','m','a','p')
 
#define MAX_MAP_DEPTH   6
 

Functions

EFI_STATUS SmmInternalAllocatePagesEx (IN EFI_ALLOCATE_TYPE Type, IN EFI_MEMORY_TYPE MemoryType, IN UINTN NumberOfPages, OUT EFI_PHYSICAL_ADDRESS *Memory, IN BOOLEAN AddRegion, IN BOOLEAN NeedGuard)
 
MEMORY_MAP * AllocateMemoryMapEntry (VOID)
 
VOID CoreFreeMemoryMapStack (VOID)
 
VOID InsertNewEntry (IN LIST_ENTRY *Link, IN UINT64 Start, IN UINT64 End, IN EFI_MEMORY_TYPE Type, IN BOOLEAN Next, IN BOOLEAN AddRegion)
 
VOID RemoveOldEntry (IN MEMORY_MAP *Entry)
 
VOID ConvertSmmMemoryMapEntry (IN EFI_MEMORY_TYPE Type, IN EFI_PHYSICAL_ADDRESS Memory, IN UINTN NumberOfPages, IN BOOLEAN AddRegion)
 
UINTN GetSmmMemoryMapEntryCount (VOID)
 
UINTN InternalAllocPagesOnOneNode (IN OUT FREE_PAGE_LIST *Pages, IN UINTN NumberOfPages, IN UINTN MaxAddress)
 
UINTN InternalAllocMaxAddress (IN OUT LIST_ENTRY *FreePageList, IN UINTN NumberOfPages, IN UINTN MaxAddress)
 
UINTN InternalAllocAddress (IN OUT LIST_ENTRY *FreePageList, IN UINTN NumberOfPages, IN UINTN Address)
 
EFI_STATUS EFIAPI SmmInternalAllocatePages (IN EFI_ALLOCATE_TYPE Type, IN EFI_MEMORY_TYPE MemoryType, IN UINTN NumberOfPages, OUT EFI_PHYSICAL_ADDRESS *Memory, IN BOOLEAN NeedGuard)
 
EFI_STATUS EFIAPI SmmAllocatePages (IN EFI_ALLOCATE_TYPE Type, IN EFI_MEMORY_TYPE MemoryType, IN UINTN NumberOfPages, OUT EFI_PHYSICAL_ADDRESS *Memory)
 
FREE_PAGE_LIST * InternalMergeNodes (IN FREE_PAGE_LIST *First)
 
EFI_STATUS SmmInternalFreePagesEx (IN EFI_PHYSICAL_ADDRESS Memory, IN UINTN NumberOfPages, IN BOOLEAN AddRegion)
 
EFI_STATUS EFIAPI SmmInternalFreePages (IN EFI_PHYSICAL_ADDRESS Memory, IN UINTN NumberOfPages, IN BOOLEAN IsGuarded)
 
BOOLEAN InMemMap (IN EFI_PHYSICAL_ADDRESS Memory, IN UINTN NumberOfPages)
 
EFI_STATUS EFIAPI SmmFreePages (IN EFI_PHYSICAL_ADDRESS Memory, IN UINTN NumberOfPages)
 
VOID SmmAddMemoryRegion (IN EFI_PHYSICAL_ADDRESS MemBase, IN UINT64 MemLength, IN EFI_MEMORY_TYPE Type, IN UINT64 Attributes)
 
EFI_STATUS EFIAPI SmmCoreGetMemoryMap (IN OUT UINTN *MemoryMapSize, IN OUT EFI_MEMORY_DESCRIPTOR *MemoryMap, OUT UINTN *MapKey, OUT UINTN *DescriptorSize, OUT UINT32 *DescriptorVersion)
 

Variables

LIST_ENTRY mSmmMemoryMap = INITIALIZE_LIST_HEAD_VARIABLE (mSmmMemoryMap)
 
LIST_ENTRY gMemoryMap = INITIALIZE_LIST_HEAD_VARIABLE (gMemoryMap)
 
UINTN mMapDepth = 0
 
MEMORY_MAP mMapStack [MAX_MAP_DEPTH]
 
UINTN mFreeMapStack = 0
 
LIST_ENTRY mFreeMemoryMapEntryList = INITIALIZE_LIST_HEAD_VARIABLE (mFreeMemoryMapEntryList)
 

Detailed Description

SMM Memory page management functions.

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

Definition in file Page.c.

Macro Definition Documentation

◆ MAX_MAP_DEPTH

#define MAX_MAP_DEPTH   6

Definition at line 33 of file Page.c.

◆ MEMORY_MAP_SIGNATURE

#define MEMORY_MAP_SIGNATURE   SIGNATURE_32('m','m','a','p')

Definition at line 20 of file Page.c.

◆ TRUNCATE_TO_PAGES

#define TRUNCATE_TO_PAGES (   a)    ((a) >> EFI_PAGE_SHIFT)

Definition at line 12 of file Page.c.

Function Documentation

◆ AllocateMemoryMapEntry()

MEMORY_MAP * AllocateMemoryMapEntry ( VOID  )

Internal function. Deque a descriptor entry from the mFreeMemoryMapEntryList. If the list is emtry, then allocate a new page to refuel the list. Please Note this algorithm to allocate the memory map descriptor has a property that the memory allocated for memory entries always grows, and will never really be freed.

Returns
The Memory map descriptor dequeued from the mFreeMemoryMapEntryList

Definition at line 88 of file Page.c.

◆ ConvertSmmMemoryMapEntry()

VOID ConvertSmmMemoryMapEntry ( IN EFI_MEMORY_TYPE  Type,
IN EFI_PHYSICAL_ADDRESS  Memory,
IN UINTN  NumberOfPages,
IN BOOLEAN  AddRegion 
)

Update SMM memory map entry.

Parameters
[in]TypeThe type of allocation to perform.
[in]MemoryThe base of memory address.
[in]NumberOfPagesThe number of pages to allocate.
[in]AddRegionIf this memory is new added region.

Definition at line 260 of file Page.c.

◆ CoreFreeMemoryMapStack()

VOID CoreFreeMemoryMapStack ( VOID  )

Internal function. Moves any memory descriptors that are on the temporary descriptor stack to heap.

Definition at line 144 of file Page.c.

◆ GetSmmMemoryMapEntryCount()

UINTN GetSmmMemoryMapEntryCount ( VOID  )

Return the count of Smm memory map entry.

Returns
The count of Smm memory map entry.

Definition at line 439 of file Page.c.

◆ InMemMap()

BOOLEAN InMemMap ( IN EFI_PHYSICAL_ADDRESS  Memory,
IN UINTN  NumberOfPages 
)

Check whether the input range is in memory map.

Parameters
MemoryBase address of memory being inputed.
NumberOfPagesThe number of pages.
Return values
TRUEIn memory map.
FALSENot in memory map.

Definition at line 901 of file Page.c.

◆ InsertNewEntry()

VOID InsertNewEntry ( IN LIST_ENTRY *  Link,
IN UINT64  Start,
IN UINT64  End,
IN EFI_MEMORY_TYPE  Type,
IN BOOLEAN  Next,
IN BOOLEAN  AddRegion 
)

Insert new entry from memory map.

Parameters
[in]LinkThe old memory map entry to be linked.
[in]StartThe start address of new memory map entry.
[in]EndThe end address of new memory map entry.
[in]TypeThe type of new memory map entry.
[in]NextIf new entry is inserted to the next of old entry.
[in]AddRegionIf this memory is new added region.

Definition at line 206 of file Page.c.

◆ InternalAllocAddress()

UINTN InternalAllocAddress ( IN OUT LIST_ENTRY *  FreePageList,
IN UINTN  NumberOfPages,
IN UINTN  Address 
)

Internal Function. Allocate n pages from free page list at given address.

Parameters
FreePageListThe free page node.
NumberOfPagesNumber of pages to be allocated.
MaxAddressRequest to allocate memory below this address.
Returns
Memory address of allocated pages.

Definition at line 542 of file Page.c.

◆ InternalAllocMaxAddress()

UINTN InternalAllocMaxAddress ( IN OUT LIST_ENTRY *  FreePageList,
IN UINTN  NumberOfPages,
IN UINTN  MaxAddress 
)

Internal Function. Allocate n pages from free page list below MaxAddress.

Parameters
FreePageListThe free page node.
NumberOfPagesNumber of pages to be allocated.
MaxAddressRequest to allocate memory below this address.
Returns
Memory address of allocated pages.

Definition at line 510 of file Page.c.

◆ InternalAllocPagesOnOneNode()

UINTN InternalAllocPagesOnOneNode ( IN OUT FREE_PAGE_LIST *  Pages,
IN UINTN  NumberOfPages,
IN UINTN  MaxAddress 
)

Internal Function. Allocate n pages from given free page node.

Parameters
PagesThe free page node.
NumberOfPagesNumber of pages to be allocated.
MaxAddressRequest to allocate memory below this address.
Returns
Memory address of allocated pages.

Definition at line 467 of file Page.c.

◆ InternalMergeNodes()

FREE_PAGE_LIST * InternalMergeNodes ( IN FREE_PAGE_LIST *  First)

Internal Function. Merge two adjacent nodes.

Parameters
FirstThe first of two nodes to merge.
Returns
Pointer to node after merge (if success) or pointer to next node (if fail).

Definition at line 768 of file Page.c.

◆ RemoveOldEntry()

VOID RemoveOldEntry ( IN MEMORY_MAP *  Entry)

Remove old entry from memory map.

Parameters
[in]EntryMemory map entry to be removed.

Definition at line 239 of file Page.c.

◆ SmmAddMemoryRegion()

VOID SmmAddMemoryRegion ( IN EFI_PHYSICAL_ADDRESS  MemBase,
IN UINT64  MemLength,
IN EFI_MEMORY_TYPE  Type,
IN UINT64  Attributes 
)

Add free SMRAM region for use by memory service.

Parameters
MemBaseBase address of memory region.
MemLengthLength of the memory region.
TypeMemory type.
AttributesMemory region state.

Definition at line 976 of file Page.c.

◆ SmmAllocatePages()

EFI_STATUS EFIAPI SmmAllocatePages ( IN EFI_ALLOCATE_TYPE  Type,
IN EFI_MEMORY_TYPE  MemoryType,
IN UINTN  NumberOfPages,
OUT EFI_PHYSICAL_ADDRESS *  Memory 
)

Allocates pages from the memory map.

Parameters
TypeThe type of allocation to perform.
MemoryTypeThe type of memory to turn the allocated pages into.
NumberOfPagesThe number of pages to allocate.
MemoryA pointer to receive the base allocated memory address.
Return values
EFI_INVALID_PARAMETERParameters violate checking rules defined in spec.
EFI_NOT_FOUNDCould not allocate pages match the requirement.
EFI_OUT_OF_RESOURCESNo enough pages to allocate.
EFI_SUCCESSPages successfully allocated.

Definition at line 727 of file Page.c.

◆ SmmCoreGetMemoryMap()

EFI_STATUS EFIAPI SmmCoreGetMemoryMap ( IN OUT UINTN *  MemoryMapSize,
IN OUT EFI_MEMORY_DESCRIPTOR *  MemoryMap,
OUT UINTN *  MapKey,
OUT UINTN *  DescriptorSize,
OUT UINT32 *  DescriptorVersion 
)

This function returns a copy of the current memory map. The map is an array of memory descriptors, each of which describes a contiguous block of memory.

Parameters
[in,out]MemoryMapSizeA pointer to the size, in bytes, of the MemoryMap buffer. On input, this is the size of the buffer allocated by the caller. On output, it is the size of the buffer returned by the firmware if the buffer was large enough, or the size of the buffer needed to contain the map if the buffer was too small.
[in,out]MemoryMapA pointer to the buffer in which firmware places the current memory map.
[out]MapKeyA pointer to the location in which firmware returns the key for the current memory map.
[out]DescriptorSizeA pointer to the location in which firmware returns the size, in bytes, of an individual EFI_MEMORY_DESCRIPTOR.
[out]DescriptorVersionA pointer to the location in which firmware returns the version number associated with the EFI_MEMORY_DESCRIPTOR.
Return values
EFI_SUCCESSThe memory map was returned in the MemoryMap buffer.
EFI_BUFFER_TOO_SMALLThe MemoryMap buffer was too small. The current buffer size needed to hold the memory map is returned in MemoryMapSize.
EFI_INVALID_PARAMETEROne of the parameters has an invalid value.

Definition at line 1046 of file Page.c.

◆ SmmFreePages()

EFI_STATUS EFIAPI SmmFreePages ( IN EFI_PHYSICAL_ADDRESS  Memory,
IN UINTN  NumberOfPages 
)

Frees previous allocated pages.

Parameters
MemoryBase address of memory being freed.
NumberOfPagesThe number of pages to free.
Return values
EFI_NOT_FOUNDCould not find the entry that covers the range.
EFI_INVALID_PARAMETERAddress not aligned, Address is zero or NumberOfPages is zero.
Returns
EFI_SUCCESS Pages successfully freed.

Definition at line 938 of file Page.c.

◆ SmmInternalAllocatePages()

EFI_STATUS EFIAPI SmmInternalAllocatePages ( IN EFI_ALLOCATE_TYPE  Type,
IN EFI_MEMORY_TYPE  MemoryType,
IN UINTN  NumberOfPages,
OUT EFI_PHYSICAL_ADDRESS *  Memory,
IN BOOLEAN  NeedGuard 
)

Allocates pages from the memory map.

Parameters
[in]TypeThe type of allocation to perform.
[in]MemoryTypeThe type of memory to turn the allocated pages into.
[in]NumberOfPagesThe number of pages to allocate.
[out]MemoryA pointer to receive the base allocated memory address.
[in]NeedGuardFlag to indicate Guard page is needed or not
Return values
EFI_INVALID_PARAMETERParameters violate checking rules defined in spec.
EFI_NOT_FOUNDCould not allocate pages match the requirement.
EFI_OUT_OF_RESOURCESNo enough pages to allocate.
EFI_SUCCESSPages successfully allocated.

Definition at line 691 of file Page.c.

◆ SmmInternalAllocatePagesEx()

EFI_STATUS SmmInternalAllocatePagesEx ( IN EFI_ALLOCATE_TYPE  Type,
IN EFI_MEMORY_TYPE  MemoryType,
IN UINTN  NumberOfPages,
OUT EFI_PHYSICAL_ADDRESS *  Memory,
IN BOOLEAN  AddRegion,
IN BOOLEAN  NeedGuard 
)

Allocates pages from the memory map.

Parameters
[in]TypeThe type of allocation to perform.
[in]MemoryTypeThe type of memory to turn the allocated pages into.
[in]NumberOfPagesThe number of pages to allocate.
[out]MemoryA pointer to receive the base allocated memory address.
[in]AddRegionIf this memory is new added region.
[in]NeedGuardFlag to indicate Guard page is needed or not
Return values
EFI_INVALID_PARAMETERParameters violate checking rules defined in spec.
EFI_NOT_FOUNDCould not allocate pages match the requirement.
EFI_OUT_OF_RESOURCESNo enough pages to allocate.
EFI_SUCCESSPages successfully allocated.

Definition at line 591 of file Page.c.

◆ SmmInternalFreePages()

EFI_STATUS EFIAPI SmmInternalFreePages ( IN EFI_PHYSICAL_ADDRESS  Memory,
IN UINTN  NumberOfPages,
IN BOOLEAN  IsGuarded 
)

Frees previous allocated pages.

Parameters
[in]MemoryBase address of memory being freed.
[in]NumberOfPagesThe number of pages to free.
[in]IsGuardedIs the memory to free guarded or not.
Return values
EFI_NOT_FOUNDCould not find the entry that covers the range.
EFI_INVALID_PARAMETERAddress not aligned, Address is zero or NumberOfPages is zero.
Returns
EFI_SUCCESS Pages successfully freed.

Definition at line 877 of file Page.c.

◆ SmmInternalFreePagesEx()

EFI_STATUS SmmInternalFreePagesEx ( IN EFI_PHYSICAL_ADDRESS  Memory,
IN UINTN  NumberOfPages,
IN BOOLEAN  AddRegion 
)

Frees previous allocated pages.

Parameters
[in]MemoryBase address of memory being freed.
[in]NumberOfPagesThe number of pages to free.
[in]AddRegionIf this memory is new added region.
Return values
EFI_NOT_FOUNDCould not find the entry that covers the range.
EFI_INVALID_PARAMETERAddress not aligned, Address is zero or NumberOfPages is zero.
Returns
EFI_SUCCESS Pages successfully freed.

Definition at line 801 of file Page.c.

Variable Documentation

◆ gMemoryMap

LIST_ENTRY gMemoryMap = INITIALIZE_LIST_HEAD_VARIABLE (gMemoryMap)

Definition at line 31 of file Page.c.

◆ mFreeMapStack

UINTN mFreeMapStack = 0

Definition at line 43 of file Page.c.

◆ mFreeMemoryMapEntryList

LIST_ENTRY mFreeMemoryMapEntryList = INITIALIZE_LIST_HEAD_VARIABLE (mFreeMemoryMapEntryList)

This list maintain the free memory map list

Definition at line 47 of file Page.c.

◆ mMapDepth

UINTN mMapDepth = 0

mMapDepth - depth of new descriptor stack

Definition at line 38 of file Page.c.

◆ mMapStack

MEMORY_MAP mMapStack[MAX_MAP_DEPTH]

mMapStack - space to use as temp storage to build new map descriptors

Definition at line 42 of file Page.c.

◆ mSmmMemoryMap

LIST_ENTRY mSmmMemoryMap = INITIALIZE_LIST_HEAD_VARIABLE (mSmmMemoryMap)

Definition at line 14 of file Page.c.