|
TianoCore EDK2 master
|
Go to the source code of this file.
Data Structures | |
| struct | EFI_MEMORY_TYPE_STATISTICS |
Macros | |
| #define | MAX_MAP_DEPTH 6 |
Variables | |
| UINTN | mMemoryMapKey = 0 |
| UINTN | mMapDepth = 0 |
| MEMORY_MAP | mMapStack [MAX_MAP_DEPTH] |
| UINTN | mFreeMapStack = 0 |
| LIST_ENTRY | mFreeMemoryMapEntryList = INITIALIZE_LIST_HEAD_VARIABLE (mFreeMemoryMapEntryList) |
| BOOLEAN | mMemoryTypeInformationInitialized = FALSE |
| EFI_MEMORY_TYPE_STATISTICS | mMemoryTypeStatistics [EfiMaxMemoryType+1] |
| EFI_PHYSICAL_ADDRESS | mDefaultMaximumAddress = MAX_ALLOC_ADDRESS |
| EFI_PHYSICAL_ADDRESS | mDefaultBaseAddress = MAX_ALLOC_ADDRESS |
| EFI_MEMORY_TYPE_INFORMATION | gMemoryTypeInformation [EfiMaxMemoryType+1] |
| GLOBAL_REMOVE_IF_UNREFERENCED BOOLEAN | gLoadFixedAddressCodeMemoryReady = FALSE |
UEFI Memory page management functions.
Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent
Definition in file Page.c.
| 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 For example, if the current boot uses 2000 memory map entries at the maximum point, but ends up with only 50 at the time the OS is booted, then the memory associated with the 1950 memory map entries is still allocated from EfiBootServicesMemory.
| VOID CoreAddMemoryDescriptor | ( | IN EFI_MEMORY_TYPE | Type, |
| IN EFI_PHYSICAL_ADDRESS | Start, | ||
| IN UINT64 | NumberOfPages, | ||
| IN UINT64 | Attribute | ||
| ) |
Called to initialize the memory map and add descriptors to the current descriptor list. The first descriptor that is added must be general usable memory as the addition allocates heap.
| Type | The type of memory to add |
| Start | The starting address in the memory range Must be page aligned |
| NumberOfPages | The number of pages in the range |
| Attribute | Attributes of the memory to add |
| VOID CoreAddRange | ( | IN EFI_MEMORY_TYPE | Type, |
| IN EFI_PHYSICAL_ADDRESS | Start, | ||
| IN EFI_PHYSICAL_ADDRESS | End, | ||
| IN UINT64 | Attribute | ||
| ) |
Internal function. Adds a ranges to the memory map. The range must not already exist in the map.
| Type | The type of memory range to add |
| Start | The starting address in the memory range Must be paged aligned |
| End | The last address in the range Must be the last byte of a page |
| Attribute | The attributes of the memory range to add |
| EFI_STATUS EFIAPI CoreAllocatePages | ( | IN EFI_ALLOCATE_TYPE | Type, |
| IN EFI_MEMORY_TYPE | MemoryType, | ||
| IN UINTN | NumberOfPages, | ||
| OUT EFI_PHYSICAL_ADDRESS * | Memory | ||
| ) |
Allocates pages from the memory map.
| Type | The type of allocation to perform |
| MemoryType | The type of memory to turn the allocated pages into |
| NumberOfPages | The number of pages to allocate |
| Memory | A pointer to receive the base allocated memory address |
| EFI_INVALID_PARAMETER | Parameters violate checking rules defined in spec. |
| EFI_NOT_FOUND | Could not allocate pages match the requirement. |
| EFI_OUT_OF_RESOURCES | No enough pages to allocate. |
| EFI_SUCCESS | Pages successfully allocated. |
| VOID * CoreAllocatePoolPages | ( | IN EFI_MEMORY_TYPE | PoolType, |
| IN UINTN | NumberOfPages, | ||
| IN UINTN | Alignment, | ||
| IN BOOLEAN | NeedGuard | ||
| ) |
Internal function. Used by the pool functions to allocate pages to back pool allocation requests.
| PoolType | The type of memory for the new pool pages |
| NumberOfPages | No of pages to allocate |
| Alignment | Bits to align. |
| NeedGuard | Flag to indicate Guard page is needed or not |
| EFI_STATUS CoreConvertPages | ( | IN UINT64 | Start, |
| IN UINT64 | NumberOfPages, | ||
| IN EFI_MEMORY_TYPE | NewType | ||
| ) |
Internal function. Converts a memory range to the specified type. The range must exist in the memory map.
| Start | The first address of the range Must be page aligned |
| NumberOfPages | The number of pages to convert |
| NewType | The new type for the memory range |
| EFI_INVALID_PARAMETER | Invalid parameter |
| EFI_NOT_FOUND | Could not find a descriptor cover the specified range or convertion not allowed. |
| EFI_SUCCESS | Successfully converts the memory range to the specified type. |
| EFI_STATUS CoreConvertPagesEx | ( | IN UINT64 | Start, |
| IN UINT64 | NumberOfPages, | ||
| IN BOOLEAN | ChangingType, | ||
| IN EFI_MEMORY_TYPE | NewType, | ||
| IN BOOLEAN | ChangingAttributes, | ||
| IN UINT64 | NewAttributes | ||
| ) |
Internal function. Converts a memory range to the specified type or attributes. The range must exist in the memory map. Either ChangingType or ChangingAttributes must be set, but not both.
| Start | The first address of the range Must be page aligned |
| NumberOfPages | The number of pages to convert |
| ChangingType | Boolean indicating that type value should be changed |
| NewType | The new type for the memory range |
| ChangingAttributes | Boolean indicating that attributes value should be changed |
| NewAttributes | The new attributes for the memory range |
| EFI_INVALID_PARAMETER | Invalid parameter |
| EFI_NOT_FOUND | Could not find a descriptor cover the specified range or convertion not allowed. |
| EFI_SUCCESS | Successfully converts the memory range to the specified type. |
| UINT64 CoreFindFreePagesI | ( | IN UINT64 | MaxAddress, |
| IN UINT64 | MinAddress, | ||
| IN UINT64 | NumberOfPages, | ||
| IN EFI_MEMORY_TYPE | NewType, | ||
| IN UINTN | Alignment, | ||
| IN BOOLEAN | NeedGuard | ||
| ) |
Internal function. Finds a consecutive free page range below the requested address.
| MaxAddress | The address that the range must be below |
| MinAddress | The address that the range must be above |
| NumberOfPages | Number of pages needed |
| NewType | The type of memory the range is going to be turned into |
| Alignment | Bits to align with |
| NeedGuard | Flag to indicate Guard page is needed or not |
| EFI_STATUS EFIAPI CoreFreePages | ( | IN EFI_PHYSICAL_ADDRESS | Memory, |
| IN UINTN | NumberOfPages | ||
| ) |
Frees previous allocated pages.
| Memory | Base address of memory being freed |
| NumberOfPages | The number of pages to free |
| EFI_NOT_FOUND | Could not find the entry that covers the range |
| EFI_INVALID_PARAMETER | Address not aligned |
| VOID CoreFreePoolPages | ( | IN EFI_PHYSICAL_ADDRESS | Memory, |
| IN UINTN | NumberOfPages | ||
| ) |
| EFI_STATUS EFIAPI CoreGetMemoryMap | ( | 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.
| MemoryMapSize | A 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. |
| MemoryMap | A pointer to the buffer in which firmware places the current memory map. |
| MapKey | A pointer to the location in which firmware returns the key for the current memory map. |
| DescriptorSize | A pointer to the location in which firmware returns the size, in bytes, of an individual EFI_MEMORY_DESCRIPTOR. |
| DescriptorVersion | A pointer to the location in which firmware returns the version number associated with the EFI_MEMORY_DESCRIPTOR. |
| EFI_SUCCESS | The memory map was returned in the MemoryMap buffer. |
| EFI_BUFFER_TOO_SMALL | The MemoryMap buffer was too small. The current buffer size needed to hold the memory map is returned in MemoryMapSize. |
| EFI_INVALID_PARAMETER | One of the parameters has an invalid value. |
| EFI_STATUS EFIAPI CoreInternalAllocatePages | ( | IN EFI_ALLOCATE_TYPE | Type, |
| IN EFI_MEMORY_TYPE | MemoryType, | ||
| IN UINTN | NumberOfPages, | ||
| IN OUT EFI_PHYSICAL_ADDRESS * | Memory, | ||
| IN BOOLEAN | NeedGuard | ||
| ) |
Allocates pages from the memory map.
| Type | The type of allocation to perform |
| MemoryType | The type of memory to turn the allocated pages into |
| NumberOfPages | The number of pages to allocate |
| Memory | A pointer to receive the base allocated memory address |
| NeedGuard | Flag to indicate Guard page is needed or not |
| EFI_INVALID_PARAMETER | Parameters violate checking rules defined in spec. |
| EFI_NOT_FOUND | Could not allocate pages match the requirement. |
| EFI_OUT_OF_RESOURCES | No enough pages to allocate. |
| EFI_SUCCESS | Pages successfully allocated. |
| EFI_STATUS EFIAPI CoreInternalFreePages | ( | IN EFI_PHYSICAL_ADDRESS | Memory, |
| IN UINTN | NumberOfPages, | ||
| OUT EFI_MEMORY_TYPE *MemoryType | OPTIONAL | ||
| ) |
Frees previous allocated pages.
| Memory | Base address of memory being freed |
| NumberOfPages | The number of pages to free |
| MemoryType | Pointer to memory type |
| EFI_NOT_FOUND | Could not find the entry that covers the range |
| EFI_INVALID_PARAMETER | Address not aligned |
This function try to allocate Runtime code & Boot time code memory range. If LMFA enabled, 2 patchable PCD PcdLoadFixAddressRuntimeCodePageNumber & PcdLoadFixAddressBootTimeCodePageNumber which are set by tools will record the size of boot time and runtime code.
| VOID CoreSetMemoryTypeInformationRange | ( | IN EFI_PHYSICAL_ADDRESS | Start, |
| IN UINT64 | Length | ||
| ) |
Sets the preferred memory range to use for the Memory Type Information bins. This service must be called before fist call to CoreAddMemoryDescriptor().
If the location of the Memory Type Information bins has already been established or the size of the range provides is smaller than all the Memory Type Information bins, then the range provides is not used.
| Start | The start address of the Memory Type Information range. |
| Length | The size, in bytes, of the Memory Type Information range. |
| EFI_STATUS CoreTerminateMemoryMap | ( | IN UINTN | MapKey | ) |
Make sure the memory map is following all the construction rules, it is the last time to check memory map error before exit boot services.
| MapKey | Memory map key |
| EFI_INVALID_PARAMETER | Memory map not consistent with construction rules. |
| EFI_SUCCESS | Valid memory map. |
| VOID CoreUpdateMemoryAttributes | ( | IN EFI_PHYSICAL_ADDRESS | Start, |
| IN UINT64 | NumberOfPages, | ||
| IN UINT64 | NewAttributes | ||
| ) |
| UINT64 FindFreePages | ( | IN UINT64 | MaxAddress, |
| IN UINT64 | NoPages, | ||
| IN EFI_MEMORY_TYPE | NewType, | ||
| IN UINTN | Alignment, | ||
| IN BOOLEAN | NeedGuard | ||
| ) |
Internal function. Finds a consecutive free page range below the requested address
| MaxAddress | The address that the range must be below |
| NoPages | Number of pages needed |
| NewType | The type of memory the range is going to be turned into |
| Alignment | Bits to align with |
| NeedGuard | Flag to indicate Guard page is needed or not |
| EFI_MEMORY_DESCRIPTOR * MergeMemoryMapDescriptor | ( | IN EFI_MEMORY_DESCRIPTOR * | MemoryMap, |
| IN EFI_MEMORY_DESCRIPTOR * | MemoryMapDescriptor, | ||
| IN UINTN | DescriptorSize | ||
| ) |
This function checks to see if the last memory map descriptor in a memory map can be merged with any of the other memory map descriptors in a memorymap. Memory descriptors may be merged if they are adjacent and have the same type and attributes.
| MemoryMap | A pointer to the start of the memory map. |
| MemoryMapDescriptor | A pointer to the last descriptor in MemoryMap. |
| DescriptorSize | The size, in bytes, of an individual EFI_MEMORY_DESCRIPTOR. |
| BOOLEAN PromoteMemoryResource | ( | VOID | ) |
| VOID RemoveMemoryMapEntry | ( | IN OUT MEMORY_MAP * | Entry | ) |
| GLOBAL_REMOVE_IF_UNREFERENCED BOOLEAN gLoadFixedAddressCodeMemoryReady = FALSE |
| EFI_MEMORY_TYPE_INFORMATION gMemoryTypeInformation[EfiMaxMemoryType+1] |
| EFI_PHYSICAL_ADDRESS mDefaultBaseAddress = MAX_ALLOC_ADDRESS |
| EFI_PHYSICAL_ADDRESS mDefaultMaximumAddress = MAX_ALLOC_ADDRESS |
| LIST_ENTRY mFreeMemoryMapEntryList = INITIALIZE_LIST_HEAD_VARIABLE (mFreeMemoryMapEntryList) |
| MEMORY_MAP mMapStack[MAX_MAP_DEPTH] |
| EFI_MEMORY_TYPE_STATISTICS mMemoryTypeStatistics[EfiMaxMemoryType+1] |