OpenCore  1.0.4
OpenCore Bootloader
Loading...
Searching...
No Matches
MemoryMap.c File Reference
#include <Uefi.h>
#include <Guid/MemoryAttributesTable.h>
#include <Library/BaseMemoryLib.h>
#include <Library/BaseOverflowLib.h>
#include <Library/DebugLib.h>
#include <Library/MemoryAllocationLib.h>
#include <Library/OcMemoryLib.h>
#include <Library/UefiBootServicesTableLib.h>
#include <Library/UefiLib.h>

Go to the source code of this file.

Functions

EFI_STATUS OcDescToMemoryType (IN CHAR8 *MemoryTypeDesc, OUT EFI_MEMORY_TYPE *MemoryType)
 
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 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)
 

Variables

STATIC OC_MEMORY_TYPE_DESC OcMemoryTypeString [OC_MEMORY_TYPE_DESC_COUNT]
 

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 MemoryMap.c.

Function Documentation

◆ 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.

◆ 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.

◆ 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.

Variable Documentation

◆ OcMemoryTypeString

STATIC OC_MEMORY_TYPE_DESC OcMemoryTypeString[OC_MEMORY_TYPE_DESC_COUNT]

Definition at line 26 of file MemoryMap.c.