OpenCore  1.0.4
OpenCore Bootloader
1.0.4
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
OcMemoryLib.h File Reference
#include <Uefi.h>
#include <Guid/MemoryAttributesTable.h>
#include <IndustryStandard/VirtualMemory.h>

Go to the source code of this file.

Data Structures

struct  OC_MEMORY_TYPE_DESC
 
struct  OC_VMEM_CONTEXT_
 

Macros

#define PREV_MEMORY_DESCRIPTOR(MemoryDescriptor, Size)
 
#define LAST_DESCRIPTOR_ADDR(Desc)
 
#define AREA_WITHIN_DESCRIPTOR(Desc, Area, AreaSize)
 
#define OC_DEFAULT_VMEM_PAGE_COUNT   0x200
 
#define OC_DEFAULT_MEMORY_MAP_SIZE   (EFI_PAGE_SIZE*3)
 
#define OC_MEMORY_TYPE_DESC_COUNT   16
 

Typedefs

typedef BOOLEAN(* CHECK_ALLOCATION_RANGE) (IN EFI_PHYSICAL_ADDRESS Address, IN UINTN Size)
 
typedef VOID(* OC_MEMORY_FILTER) (IN VOID *Context OPTIONAL, IN UINTN MemoryMapSize, IN OUT EFI_MEMORY_DESCRIPTOR *MemoryMap, IN UINTN DescriptorSize)
 
typedef struct OC_VMEM_CONTEXT_ OC_VMEM_CONTEXT
 

Functions

EFI_STATUS LegacyRegionLock (IN UINT32 LegacyAddress, IN UINT32 LegacyLength)
 
EFI_STATUS LegacyRegionUnlock (IN UINT32 LegacyAddress, IN UINT32 LegacyLength)
 
EFI_MEMORY_DESCRIPTOR * OcGetCurrentMemoryMap (OUT UINTN *MemoryMapSize, OUT UINTN *DescriptorSize, OUT UINTN *MapKey OPTIONAL, OUT UINT32 *DescriptorVersion OPTIONAL, OUT UINTN *OriginalMemoryMapSize OPTIONAL, IN BOOLEAN IncludeSplitSpace)
 
EFI_STATUS OcGetCurrentMemoryMapAlloc (OUT UINTN *MemoryMapSize, OUT EFI_MEMORY_DESCRIPTOR **MemoryMap, OUT UINTN *MapKey, OUT UINTN *DescriptorSize, OUT UINT32 *DescriptorVersion, IN EFI_GET_MEMORY_MAP GetMemoryMap OPTIONAL, IN OUT EFI_PHYSICAL_ADDRESS *TopMemory OPTIONAL)
 
VOID OcSortMemoryMap (IN UINTN MemoryMapSize, IN OUT EFI_MEMORY_DESCRIPTOR *MemoryMap, IN UINTN DescriptorSize)
 
EFI_STATUS OcShrinkMemoryMap (IN OUT UINTN *MemoryMapSize, IN OUT EFI_MEMORY_DESCRIPTOR *MemoryMap, IN UINTN DescriptorSize)
 
EFI_STATUS OcDeduplicateDescriptors (IN OUT UINT32 *EntryCount, IN OUT EFI_MEMORY_DESCRIPTOR *MemoryMap, IN UINTN DescriptorSize)
 
EFI_STATUS OcAllocatePagesFromTop (IN EFI_MEMORY_TYPE MemoryType, IN UINTN Pages, IN OUT EFI_PHYSICAL_ADDRESS *Memory, IN EFI_GET_MEMORY_MAP GetMemoryMap OPTIONAL, IN EFI_ALLOCATE_PAGES AllocatePages OPTIONAL, IN CHECK_ALLOCATION_RANGE CheckRange OPTIONAL)
 
UINT64 OcCountRuntimePages (IN UINTN MemoryMapSize, IN EFI_MEMORY_DESCRIPTOR *MemoryMap, IN UINTN DescriptorSize, OUT UINTN *DescriptorCount OPTIONAL)
 
UINTN OcCountFreePages (OUT UINTN *LowerMemory OPTIONAL)
 
VOID OcPrintMemoryAttributesTable (VOID)
 
VOID OcPrintMemoryMap (IN UINTN MemoryMapSize, IN EFI_MEMORY_DESCRIPTOR *MemoryMap, IN UINTN DescriptorSize)
 
EFI_STATUS OcUpdateDescriptors (IN UINTN MemoryMapSize, IN EFI_MEMORY_DESCRIPTOR *MemoryMap, IN UINTN DescriptorSize, IN EFI_PHYSICAL_ADDRESS Address, IN EFI_MEMORY_TYPE Type, IN UINT64 SetAttributes, IN UINT64 DropAttributes)
 
EFI_MEMORY_ATTRIBUTES_TABLE * OcGetMemoryAttributes (OUT EFI_MEMORY_DESCRIPTOR **MemoryAttributesEntry OPTIONAL)
 
EFI_STATUS OcRebuildAttributes (IN EFI_PHYSICAL_ADDRESS Address, IN EFI_GET_MEMORY_MAP GetMemoryMap OPTIONAL)
 
UINTN OcCountSplitDescriptors (VOID)
 
EFI_STATUS OcSplitMemoryMapByAttributes (IN UINTN MaxMemoryMapSize, IN OUT UINTN *MemoryMapSize, IN OUT EFI_MEMORY_DESCRIPTOR *MemoryMap, IN UINTN DescriptorSize)
 
BOOLEAN OcIsPatSupported (VOID)
 
CHAR8 * OcGetMtrrTypeString (UINT8 MtrrType)
 
CHAR8 * OcGetPatTypeString (UINT8 PatType)
 
PAGE_MAP_AND_DIRECTORY_POINTEROcGetCurrentPageTable (OUT UINTN *Flags OPTIONAL)
 
EFI_STATUS OcGetPhysicalAddress (IN PAGE_MAP_AND_DIRECTORY_POINTER *PageTable OPTIONAL, IN EFI_VIRTUAL_ADDRESS VirtualAddr, OUT EFI_PHYSICAL_ADDRESS *PhysicalAddr)
 
EFI_STATUS OcGetSetPageTableInfoForAddress (IN PAGE_MAP_AND_DIRECTORY_POINTER *PageTable OPTIONAL, IN EFI_VIRTUAL_ADDRESS VirtualAddr, OUT EFI_PHYSICAL_ADDRESS *PhysicalAddr OPTIONAL, OUT UINT8 *Level OPTIONAL, OUT UINT64 *Bits OPTIONAL, IN OUT PAT_INDEX *PatIndex OPTIONAL, IN BOOLEAN SetPat)
 
EFI_STATUS OcSetPatIndexForAddressRange (IN PAGE_MAP_AND_DIRECTORY_POINTER *PageTable OPTIONAL, IN EFI_VIRTUAL_ADDRESS VirtualAddr, IN UINT64 Length, IN PAT_INDEX *PatIndex)
 
EFI_STATUS OcDescToMemoryType (IN CHAR8 *MemoryTypeDesc, OUT EFI_MEMORY_TYPE *MemoryType)
 
EFI_STATUS OcModifyMtrrRange (IN EFI_PHYSICAL_ADDRESS Address, IN UINT8 MtrrType, OUT UINT64 *Length OPTIONAL)
 
EFI_STATUS VmAllocateMemoryPool (OUT OC_VMEM_CONTEXT *Context, IN UINTN NumPages, IN EFI_GET_MEMORY_MAP GetMemoryMap OPTIONAL)
 
VOID * VmAllocatePages (IN OUT OC_VMEM_CONTEXT *Context, IN UINTN NumPages)
 
EFI_STATUS VmMapVirtualPage (IN OUT OC_VMEM_CONTEXT *Context, IN OUT PAGE_MAP_AND_DIRECTORY_POINTER *PageTable OPTIONAL, IN EFI_VIRTUAL_ADDRESS VirtualAddr, IN EFI_PHYSICAL_ADDRESS PhysicalAddr)
 
EFI_STATUS VmMapVirtualPages (IN OUT OC_VMEM_CONTEXT *Context, IN OUT PAGE_MAP_AND_DIRECTORY_POINTER *PageTable OPTIONAL, IN EFI_VIRTUAL_ADDRESS VirtualAddr, IN UINT64 NumPages, IN EFI_PHYSICAL_ADDRESS PhysicalAddr)
 
VOID VmFlushCaches (VOID)
 
BOOLEAN UmmInitialized (VOID)
 
VOID UmmSetHeap (IN VOID *Heap, IN UINT32 Size)
 
VOID * UmmMalloc (IN UINT32 Size)
 
BOOLEAN UmmFree (IN VOID *Ptr)
 

Detailed Description

Copyright (C) 2019, vit9696. All rights reserved.

All rights reserved.

This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this distribution. The full text of the license may be found at http://opensource.org/licenses/bsd-license.php

THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.

Definition in file OcMemoryLib.h.

Macro Definition Documentation

◆ AREA_WITHIN_DESCRIPTOR

#define AREA_WITHIN_DESCRIPTOR ( Desc,
Area,
AreaSize )
Value:
((Area) >= (Desc)->PhysicalStart && ((Area) + ((AreaSize) - 1)) <= LAST_DESCRIPTOR_ADDR (Desc))
#define LAST_DESCRIPTOR_ADDR(Desc)
Definition OcMemoryLib.h:32

Check if area is within the specified descriptor. It is assumed that the descriptor contains pages and AreaSize is not 0.

Definition at line 39 of file OcMemoryLib.h.

◆ LAST_DESCRIPTOR_ADDR

#define LAST_DESCRIPTOR_ADDR ( Desc)
Value:
((Desc)->PhysicalStart + (EFI_PAGES_TO_SIZE ((UINTN) (Desc)->NumberOfPages) - 1))

Get last descriptor address. It is assumed that the descriptor contains pages.

Definition at line 32 of file OcMemoryLib.h.

◆ OC_DEFAULT_MEMORY_MAP_SIZE

#define OC_DEFAULT_MEMORY_MAP_SIZE   (EFI_PAGE_SIZE*3)

Reasonable default memory map size used when allocations are problematic. Note, that MacPro5,1 is known to have 8880 memory map.

Definition at line 51 of file OcMemoryLib.h.

◆ OC_DEFAULT_VMEM_PAGE_COUNT

#define OC_DEFAULT_VMEM_PAGE_COUNT   0x200

Reasonable default virtual memory page pool size (2 MB).

Definition at line 45 of file OcMemoryLib.h.

◆ OC_MEMORY_TYPE_DESC_COUNT

#define OC_MEMORY_TYPE_DESC_COUNT   16

Definition at line 53 of file OcMemoryLib.h.

◆ PREV_MEMORY_DESCRIPTOR

#define PREV_MEMORY_DESCRIPTOR ( MemoryDescriptor,
Size )
Value:
((EFI_MEMORY_DESCRIPTOR *)((UINT8 *)(MemoryDescriptor) - (Size)))
DMG_SIZE_DEVICE_PATH Size

Reverse equivalent of NEXT_MEMORY_DESCRIPTOR.

Definition at line 25 of file OcMemoryLib.h.

Typedef Documentation

◆ CHECK_ALLOCATION_RANGE

typedef BOOLEAN(* CHECK_ALLOCATION_RANGE) (IN EFI_PHYSICAL_ADDRESS Address, IN UINTN Size)

Check range allocation compatibility callback.

Parameters
[in]AddressStarting address.
[in]SizeSize of memory range.
Return values
TRUEwhen suitable for allocation.

Definition at line 193 of file OcMemoryLib.h.

◆ OC_MEMORY_FILTER

typedef VOID(* OC_MEMORY_FILTER) (IN VOID *Context OPTIONAL, IN UINTN MemoryMapSize, IN OUT EFI_MEMORY_DESCRIPTOR *MemoryMap, IN UINTN DescriptorSize)

Filter memory map entries.

Parameters
[in]ContextParameterised filter data.
[in,out]MemoryMapSizeMemory map size in bytes.
[in,out]MemoryMapMemory map to filter.
[in]DescriptorSizeMemory map descriptor size in bytes.

Definition at line 208 of file OcMemoryLib.h.

◆ OC_VMEM_CONTEXT

Virtual memory context

Function Documentation

◆ LegacyRegionLock()

EFI_STATUS LegacyRegionLock ( IN UINT32 LegacyAddress,
IN UINT32 LegacyLength )

Lock the legacy region specified to enable modification.

Parameters
[in]LegacyAddressThe address of the region to lock.
[in]LegacyLengthThe size of the region to lock.
Return values
EFI_SUCCESSThe region was locked successfully.

Definition at line 43 of file LegacyRegionLock.c.

◆ LegacyRegionUnlock()

EFI_STATUS LegacyRegionUnlock ( IN UINT32 LegacyAddress,
IN UINT32 LegacyLength )

Unlock the legacy region specified to enable modification.

Parameters
[in]LegacyAddressThe address of the region to unlock.
[in]LegacyLengthThe size of the region to unlock.
Return values
EFI_SUCCESSThe region was unlocked successfully.

Definition at line 43 of file LegacyRegionUnLock.c.

◆ OcAllocatePagesFromTop()

EFI_STATUS OcAllocatePagesFromTop ( IN EFI_MEMORY_TYPE MemoryType,
IN UINTN Pages,
IN OUT EFI_PHYSICAL_ADDRESS * Memory,
IN EFI_GET_MEMORY_MAP GetMemoryMap OPTIONAL,
IN EFI_ALLOCATE_PAGES AllocatePages OPTIONAL,
IN CHECK_ALLOCATION_RANGE CheckRange OPTIONAL )

Allocate pages from the top of physical memory up to address specified in Memory. Unlike AllocateMaxAddress, this method guarantees to choose top most address.

Parameters
[in]MemoryTypeAllocated memory type.
[in]PagesAmount of pages to allocate.
[in,out]MemoryTop address for input, allocated address for output.
[in]GetMemoryMapCustom GetMemoryMap implementation to use, optional.
[in]AllocatePagesCustom AllocatePages implementation to use, optional.
[in]CheckRangeHandler allowing to not allocate select ranges, optional.
Return values
EFI_SUCCESSon successful allocation.

Definition at line 27 of file MemoryAlloc.c.

◆ OcCountFreePages()

UINTN OcCountFreePages ( OUT UINTN *LowerMemory OPTIONAL)

Calculate number of free pages in the memory map.

Parameters
[out]LowerMemoryNumber of free pages below 4 GB, optional.
Return values
Numberof free pages.

Definition at line 148 of file MemoryAlloc.c.

◆ OcCountRuntimePages()

UINT64 OcCountRuntimePages ( IN UINTN MemoryMapSize,
IN EFI_MEMORY_DESCRIPTOR * MemoryMap,
IN UINTN DescriptorSize,
OUT UINTN *DescriptorCount OPTIONAL )

Calculate number of runtime pages in the memory map.

Parameters
[in]MemoryMapSizeMemory map size in bytes.
[in]MemoryMapMemory map to inspect.
[in]DescriptorSizeMemory map descriptor size in bytes.
[out]DescriptorCountNumber of relevant descriptors, optional.
Return values
Numberof runtime pages.

Definition at line 111 of file MemoryAlloc.c.

◆ OcCountSplitDescriptors()

UINTN OcCountSplitDescriptors ( VOID )

Count upper bound of split runtime descriptors.

Return values
amountof runtime descriptors.

Definition at line 541 of file MemoryAttributes.c.

◆ OcDeduplicateDescriptors()

EFI_STATUS OcDeduplicateDescriptors ( IN OUT UINT32 * EntryCount,
IN OUT EFI_MEMORY_DESCRIPTOR * MemoryMap,
IN UINTN DescriptorSize )

Deduplicate memory descriptors. Requires sorted entry list.

Parameters
[in,out]EntryCountMemory map size in entries, updated on shrink.
[in,out]MemoryMapMemory map to shrink.
[in]DescriptorSizeMemory map descriptor size in bytes.
Return values
EFI_SUCCESSon success.
EFI_NOT_FOUNDwhen cannot join anything.

Definition at line 438 of file MemoryMap.c.

◆ OcDescToMemoryType()

EFI_STATUS OcDescToMemoryType ( IN CHAR8 * MemoryTypeDesc,
OUT EFI_MEMORY_TYPE * MemoryType )

Return EFI memory type for given type description

Parameters
[in]MemoryTypeDescMemory type string representation.
[out]MemoryTypeEFI memory type to return.
Return values
EFI_NOT_FOUNDon unsuccessful lookup.
EFI_INVALID_PARAMETERon wrong passed agruments.
EFI_SUCCESSon successful lookup.

Definition at line 90 of file MemoryMap.c.

◆ OcGetCurrentMemoryMap()

EFI_MEMORY_DESCRIPTOR * OcGetCurrentMemoryMap ( OUT UINTN * MemoryMapSize,
OUT UINTN * DescriptorSize,
OUT UINTN *MapKey OPTIONAL,
OUT UINT32 *DescriptorVersion OPTIONAL,
OUT UINTN *OriginalMemoryMapSize OPTIONAL,
IN BOOLEAN IncludeSplitSpace )

Get current memory map allocated on pool with reserved entries.

Parameters
[out]MemoryMapSizeResulting memory map size in bytes.
[out]DescriptorSizeResulting memory map descriptor size in bytes.
[out]MapKeyMemory map key, optional.
[out]DescriptorVersionMemory map descriptor version, optional.
[out]OriginalMemoryMapSizeActual pool allocation memory, optional.
[out]IncludeSplitSpaceAllocate memory to permit splitting memory map.
Return values
currentmemory map or NULL.

Definition at line 116 of file MemoryMap.c.

◆ OcGetCurrentMemoryMapAlloc()

EFI_STATUS OcGetCurrentMemoryMapAlloc ( OUT UINTN * MemoryMapSize,
OUT EFI_MEMORY_DESCRIPTOR ** MemoryMap,
OUT UINTN * MapKey,
OUT UINTN * DescriptorSize,
OUT UINT32 * DescriptorVersion,
IN EFI_GET_MEMORY_MAP GetMemoryMap OPTIONAL,
IN OUT EFI_PHYSICAL_ADDRESS *TopMemory OPTIONAL )

Get current memory map of custom allocation.

Parameters
[out]MemoryMapSizeResulting memory map size in bytes.
[out]MemoryMapResulting memory map.
[out]MapKeyMemory map key.
[out]DescriptorSizeResulting memory map descriptor size in bytes.
[out]DescriptorVersionMemory map descriptor version.
[in]GetMemoryMapCustom GetMemoryMap implementation to use, optional.
[in,out]TopMemoryBase top address for OcAllocatePagesFromTop allocation, number of pages after return.
Return values
EFI_SUCCESSon success.

Definition at line 201 of file MemoryMap.c.

◆ OcGetCurrentPageTable()

PAGE_MAP_AND_DIRECTORY_POINTER * OcGetCurrentPageTable ( OUT UINTN *Flags OPTIONAL)

Return pointer to PML4 table in PageTable and PWT and PCD flags in Flags.

Parameters
[out]FlagsCurrent page table PWT and PCT flags.
Return values
Currentpage table address.

Definition at line 97 of file VirtualMemory.c.

◆ OcGetMemoryAttributes()

EFI_MEMORY_ATTRIBUTES_TABLE * OcGetMemoryAttributes ( OUT EFI_MEMORY_DESCRIPTOR **MemoryAttributesEntry OPTIONAL)

Obtain memory attributes table.

Parameters
[out]MemoryAttributesEntrymemory descriptor pointer, optional.
Return values
pointerto memory attributes table.
NULLif memory attributes table is unsupported.

Definition at line 409 of file MemoryAttributes.c.

◆ OcGetMtrrTypeString()

CHAR8 * OcGetMtrrTypeString ( UINT8 MtrrType)

Return short string representation of MTRR cache type, as used in Intel tables.

Parameters
[in]MtrrTypeMTRR type.
Return values
Stringrepresentation.

Definition at line 58 of file VirtualMemory.c.

◆ OcGetPatTypeString()

CHAR8 * OcGetPatTypeString ( UINT8 PatType)

Return short string representation of PAT cache type, as used in Intel tables.

Parameters
[in]PatTypePAT type.
Return values
Stringrepresentation.

Definition at line 70 of file VirtualMemory.c.

◆ OcGetPhysicalAddress()

EFI_STATUS OcGetPhysicalAddress ( IN PAGE_MAP_AND_DIRECTORY_POINTER *PageTable OPTIONAL,
IN EFI_VIRTUAL_ADDRESS VirtualAddr,
OUT EFI_PHYSICAL_ADDRESS * PhysicalAddr )

Return physical address for given virtual address.

Parameters
[in]PageTablePage table to use for solving.
[in]VirtualAddrVirtual address to look up.
[out]PhysicalAddrPhysical address to return.
Return values
EFI_SUCCESSon successful lookup.

Definition at line 146 of file VirtualMemory.c.

◆ OcGetSetPageTableInfoForAddress()

EFI_STATUS OcGetSetPageTableInfoForAddress ( IN PAGE_MAP_AND_DIRECTORY_POINTER *PageTable OPTIONAL,
IN EFI_VIRTUAL_ADDRESS VirtualAddr,
OUT EFI_PHYSICAL_ADDRESS *PhysicalAddr OPTIONAL,
OUT UINT8 *Level OPTIONAL,
OUT UINT64 *Bits OPTIONAL,
IN OUT PAT_INDEX *PatIndex OPTIONAL,
IN BOOLEAN SetPat )

Get page table info for a given virtual address. Includes option to get or set Page Attribute Table (PAT) index for caching type.

Parameters
[in]PageTablePage table to use for solving, and modify iff SetPat==TRUE.
[in]VirtualAddrVirtual address to look up.
[out]PhysicalAddrPhysical address to return.
[out]LevelPage table mapping level, 1, 2 or 4 for 1Gb, 2Mb or 4kb.
[out]BitsPage table mapping flag bits.
[in,out]PatIndexPAT index to get or set.
[in]SetPatIf TRUE then set PatIndex if present, else get.
Return values
EFI_SUCCESSon success.

Definition at line 221 of file VirtualMemory.c.

◆ OcIsPatSupported()

BOOLEAN OcIsPatSupported ( VOID )

Checks if PAT is supported.

Return values
TRUEPAT is supported.
FALSEPAT is not supported.

Definition at line 82 of file VirtualMemory.c.

◆ OcModifyMtrrRange()

EFI_STATUS OcModifyMtrrRange ( IN EFI_PHYSICAL_ADDRESS Address,
IN UINT8 MtrrType,
OUT UINT64 *Length OPTIONAL )

Attempt to set entire MTRR range which starts with address to new MTRR cache type. Use with caution - attempting to change cache-type on the fly of any region used for code or data is likely to hang. Works successfully to uncache GOP (i.e. WC->UC), producing visibly slower results, on newer firmware where GOP range is set to WC in the first place.

Parameters
[in]AddressStart of range.
[in]MtrrTypeMTRR cache type to assign.
[out]LengthLength of range converted or attempted to be converted, when non-zero.
Return values
EFI_SUCCESSif cache type is set and system is still running.
EFI_UNSUPPORTEDif MTRR is unsupported.
error- other error from methods called.

Definition at line 410 of file VirtualMemory.c.

◆ OcPrintMemoryAttributesTable()

VOID OcPrintMemoryAttributesTable ( VOID )

Print memory attributes table if present.

Definition at line 96 of file MemoryDebug.c.

◆ OcPrintMemoryMap()

VOID OcPrintMemoryMap ( IN UINTN MemoryMapSize,
IN EFI_MEMORY_DESCRIPTOR * MemoryMap,
IN UINTN DescriptorSize )

Print memory map.

Parameters
[in]MemoryMapSizeMemory map size in bytes.
[in]MemoryMapMemory map to print.
[in]DescriptorSizeMemory map descriptor size in bytes.

Definition at line 144 of file MemoryDebug.c.

◆ OcRebuildAttributes()

EFI_STATUS OcRebuildAttributes ( IN EFI_PHYSICAL_ADDRESS Address,
IN EFI_GET_MEMORY_MAP GetMemoryMap OPTIONAL )

Refresh memory attributes entry containing the specified address.

Parameters
[in]AddressAddress contained in the updated entry.
[in]GetMemoryMap
Return values
EFI_SUCCESSon success.
EFI_NOT_FOUNDno entry contains the specified address.
EFI_UNSUPPORTEDmemory attributes are not supported by the platform.

Definition at line 431 of file MemoryAttributes.c.

◆ OcSetPatIndexForAddressRange()

EFI_STATUS OcSetPatIndexForAddressRange ( IN PAGE_MAP_AND_DIRECTORY_POINTER *PageTable OPTIONAL,
IN EFI_VIRTUAL_ADDRESS VirtualAddr,
IN UINT64 Length,
IN PAT_INDEX * PatIndex )

Set Page Attribute Table (PAT) index for an address range. Assumes UEFI identity mapping between physical and virtual addresses.

Parameters
[in]PageTablePage table to use and modify.
[in]VirtualAddrAddress range start.
[in]LengthAddress range length.
[in]PatIndexPAT index to set.
Return values
EFI_SUCCESSon success.
EFI_INVALID_PARAMETERon invalid memory range.
error- other error from called methods.

Definition at line 164 of file VirtualMemory.c.

◆ OcShrinkMemoryMap()

EFI_STATUS OcShrinkMemoryMap ( IN OUT UINTN * MemoryMapSize,
IN OUT EFI_MEMORY_DESCRIPTOR * MemoryMap,
IN UINTN DescriptorSize )

Shrink memory map by joining non-runtime records. Requires sorted memory map.

Parameters
[in,out]MemoryMapSizeMemory map size in bytes, updated on shrink.
[in,out]MemoryMapMemory map to shrink.
[in]DescriptorSizeMemory map descriptor size in bytes.
Return values
EFI_SUCCESSon success.
EFI_NOT_FOUNDwhen cannot join anything.

Definition at line 333 of file MemoryMap.c.

◆ OcSortMemoryMap()

VOID OcSortMemoryMap ( IN UINTN MemoryMapSize,
IN OUT EFI_MEMORY_DESCRIPTOR * MemoryMap,
IN UINTN DescriptorSize )

Sort memory map entries based upon PhysicalStart, from low to high.

Parameters
MemoryMapSizeSize, in bytes, of the MemoryMap buffer.
MemoryMapA pointer to the buffer in which firmware places the current memory map.
DescriptorSizeSize, in bytes, of an individual EFI_MEMORY_DESCRIPTOR.

Definition at line 302 of file MemoryMap.c.

◆ OcSplitMemoryMapByAttributes()

EFI_STATUS OcSplitMemoryMapByAttributes ( IN UINTN MaxMemoryMapSize,
IN OUT UINTN * MemoryMapSize,
IN OUT EFI_MEMORY_DESCRIPTOR * MemoryMap,
IN UINTN DescriptorSize )

Split memory map by memory attributes if available. Requires sorted memory map!

Parameters
[in]MaxMemoryMapSizeUpper memory map size bound for growth.
[in,out]MemoryMapSizeCurrent memory map size, updated on return.
[in,out]MemoryMapMemory map to split.
[in]DescriptorSizeMemory map descriptor size.

Note, the function is guaranteed to return valid memory map, though not necessarily split.

Return values
EFI_SUCCESSon success.
EFI_UNSUPPORTEDmemory attributes are not supported by the platform.
EFI_OUT_OF_RESOURCESnew memory map did not fit.

Definition at line 573 of file MemoryAttributes.c.

◆ OcUpdateDescriptors()

EFI_STATUS OcUpdateDescriptors ( IN UINTN MemoryMapSize,
IN EFI_MEMORY_DESCRIPTOR * MemoryMap,
IN UINTN DescriptorSize,
IN EFI_PHYSICAL_ADDRESS Address,
IN EFI_MEMORY_TYPE Type,
IN UINT64 SetAttributes,
IN UINT64 DropAttributes )

Refresh memory descriptor containing the specified address.

Parameters
[in]MemoryMapSizeMemory map size in bytes.
[in]MemoryMapMemory map to refresh.
[in]DescriptorSizeMemory map descriptor size in bytes.
[in]AddressAddress contained in the updated entry.
[in]TypeMemory type to assign to the entry.
[in]SetAttributesAttributes to set.
[in]DropAttributesAttributes to remove.
Return values
EFI_SUCCESSon success.
EFI_NOT_FOUNDno entry contains the specified address.
EFI_UNSUPPORTEDmemory attributes are not supported by the platform.

Definition at line 505 of file MemoryMap.c.

◆ UmmFree()

BOOLEAN UmmFree ( IN VOID * Ptr)

Perform free of allocated memory. Accepts NULL pointer and checks whether memory belongs to itself.

Parameters
[in]PtrMemory to free.
Return values
TRUEon success

◆ UmmInitialized()

BOOLEAN UmmInitialized ( VOID )

Check whether built-in allocator is initialized.

Return values
TRUEon success.

Definition at line 276 of file UmmMalloc.c.

◆ UmmMalloc()

VOID * UmmMalloc ( IN UINT32 Size)

Perform allocation from built-in allocator.

Parameters
[in]SizeAllocation size.
Return values
allocatedmemory on success.

◆ UmmSetHeap()

VOID UmmSetHeap ( IN VOID * Heap,
IN UINT32 Size )

Initialize built-in allocator.

Parameters
[in]HeapMemory pool used for allocations.
[in]SizeMemory pool size.

◆ VmAllocateMemoryPool()

EFI_STATUS VmAllocateMemoryPool ( OUT OC_VMEM_CONTEXT * Context,
IN UINTN NumPages,
IN EFI_GET_MEMORY_MAP GetMemoryMap OPTIONAL )

Allocate EfiBootServicesData virtual memory pool from boot services in the end of BASE_4GB of RAM. Should be called while boot services are still usable.

Parameters
[out]ContextVirtual memory pool context.
[in]NumPagesNumber of pages to be allocated in the pool.
[in]GetMemoryMapCustom GetMemoryMap implementation to use, optional.
Return values
EFI_SUCCESSon successful allocation.

Definition at line 441 of file VirtualMemory.c.

◆ VmAllocatePages()

VOID * VmAllocatePages ( IN OUT OC_VMEM_CONTEXT * Context,
IN UINTN NumPages )

Allocate pages for e.g. vm page maps.

Parameters
[in,out]ContextVirtual memory pool context.
[in]NumPagesNumber of pages to allocate.
Return values
allocatedpages or NULL.

Definition at line 469 of file VirtualMemory.c.

◆ VmFlushCaches()

VOID VmFlushCaches ( VOID )

Flushes TLB caches.

Definition at line 726 of file VirtualMemory.c.

◆ VmMapVirtualPage()

EFI_STATUS VmMapVirtualPage ( IN OUT OC_VMEM_CONTEXT * Context,
IN OUT PAGE_MAP_AND_DIRECTORY_POINTER *PageTable OPTIONAL,
IN EFI_VIRTUAL_ADDRESS VirtualAddr,
IN EFI_PHYSICAL_ADDRESS PhysicalAddr )

Map (remap) given page at physical address to given virtual address in the specified page table.

Parameters
[in,out]ContextVirtual memory pool context.
[in]PageTablePage table to update.
[in]VirtualAddrVirtual memory address to map at.
[in]PhysicalAddrPhysical memory address to map from.
Return values
EFI_SUCCESSon success.

Definition at line 488 of file VirtualMemory.c.

◆ VmMapVirtualPages()

EFI_STATUS VmMapVirtualPages ( IN OUT OC_VMEM_CONTEXT * Context,
IN OUT PAGE_MAP_AND_DIRECTORY_POINTER *PageTable OPTIONAL,
IN EFI_VIRTUAL_ADDRESS VirtualAddr,
IN UINT64 NumPages,
IN EFI_PHYSICAL_ADDRESS PhysicalAddr )

Map (remap) a range of 4K pages at physical address to given virtual address in the specified page table.

Parameters
[in,out]ContextVirtual memory pool context.
[in]PageTablePage table to update.
[in]VirtualAddrVirtual memory address to map at.
[in]NumPagesNumber of 4K pages to map.
[in]PhysicalAddrPhysical memory address to map from.
Return values
EFI_SUCCESSon success.

Definition at line 693 of file VirtualMemory.c.