TianoCore EDK2 master
Loading...
Searching...
No Matches
Gcd.c File Reference
#include <Pi/PiDxeCis.h>
#include <Pi/PiHob.h>
#include "DxeMain.h"
#include "Gcd.h"
#include "Mem/HeapGuard.h"

Go to the source code of this file.

Macros

#define MINIMUM_INITIAL_MEMORY_SIZE   0x10000
 
#define MEMORY_ATTRIBUTE_MASK
 
#define TESTED_MEMORY_ATTRIBUTES
 
#define INITIALIZED_MEMORY_ATTRIBUTES
 
#define PRESENT_MEMORY_ATTRIBUTES   (EFI_RESOURCE_ATTRIBUTE_PRESENT)
 

Functions

VOID EFIAPI CoreDumpGcdMemorySpaceMap (BOOLEAN InitialMap)
 
VOID EFIAPI CoreDumpGcdIoSpaceMap (BOOLEAN InitialMap)
 
VOID CoreValidateResourceDescriptorHobAttributes (IN UINT64 Attributes)
 
VOID CoreAcquireGcdMemoryLock (VOID)
 
VOID CoreReleaseGcdMemoryLock (VOID)
 
VOID CoreAcquireGcdIoLock (VOID)
 
VOID CoreReleaseGcdIoLock (VOID)
 
UINT64 AlignValue (IN UINT64 Value, IN UINTN Alignment, IN BOOLEAN RoundUp)
 
UINT64 PageAlignAddress (IN UINT64 Value)
 
UINT64 PageAlignLength (IN UINT64 Value)
 
EFI_STATUS CoreAllocateGcdMapEntry (IN OUT EFI_GCD_MAP_ENTRY **TopEntry, IN OUT EFI_GCD_MAP_ENTRY **BottomEntry)
 
EFI_STATUS CoreInsertGcdMapEntry (IN LIST_ENTRY *Link, IN EFI_GCD_MAP_ENTRY *Entry, IN EFI_PHYSICAL_ADDRESS BaseAddress, IN UINT64 Length, IN EFI_GCD_MAP_ENTRY *TopEntry, IN EFI_GCD_MAP_ENTRY *BottomEntry)
 
EFI_STATUS CoreMergeGcdMapEntry (IN LIST_ENTRY *Link, IN BOOLEAN Forward, IN LIST_ENTRY *Map)
 
EFI_STATUS CoreCleanupGcdMapEntry (IN EFI_GCD_MAP_ENTRY *TopEntry, IN EFI_GCD_MAP_ENTRY *BottomEntry, IN LIST_ENTRY *StartLink, IN LIST_ENTRY *EndLink, IN LIST_ENTRY *Map)
 
EFI_STATUS CoreSearchGcdMapEntry (IN EFI_PHYSICAL_ADDRESS BaseAddress, IN UINT64 Length, OUT LIST_ENTRY **StartLink, OUT LIST_ENTRY **EndLink, IN LIST_ENTRY *Map)
 
UINTN CoreCountGcdMapEntry (IN LIST_ENTRY *Map)
 
UINT64 ConverToCpuArchAttributes (UINT64 Attributes)
 
EFI_STATUS CoreConvertSpace (IN UINTN Operation, IN EFI_GCD_MEMORY_TYPE GcdMemoryType, IN EFI_GCD_IO_TYPE GcdIoType, IN EFI_PHYSICAL_ADDRESS BaseAddress, IN UINT64 Length, IN UINT64 Capabilities, IN UINT64 Attributes)
 
EFI_STATUS CoreAllocateSpaceCheckEntry (IN UINTN Operation, IN EFI_GCD_MAP_ENTRY *Entry, IN EFI_GCD_MEMORY_TYPE GcdMemoryType, IN EFI_GCD_IO_TYPE GcdIoType)
 
EFI_STATUS CoreAllocateSpace (IN UINTN Operation, IN EFI_GCD_ALLOCATE_TYPE GcdAllocateType, IN EFI_GCD_MEMORY_TYPE GcdMemoryType, IN EFI_GCD_IO_TYPE GcdIoType, IN UINTN Alignment, IN UINT64 Length, IN OUT EFI_PHYSICAL_ADDRESS *BaseAddress, IN EFI_HANDLE ImageHandle, IN EFI_HANDLE DeviceHandle OPTIONAL)
 
EFI_STATUS CoreInternalAddMemorySpace (IN EFI_GCD_MEMORY_TYPE GcdMemoryType, IN EFI_PHYSICAL_ADDRESS BaseAddress, IN UINT64 Length, IN UINT64 Capabilities)
 
EFI_STATUS EFIAPI CoreAllocateMemorySpace (IN EFI_GCD_ALLOCATE_TYPE GcdAllocateType, IN EFI_GCD_MEMORY_TYPE GcdMemoryType, IN UINTN Alignment, IN UINT64 Length, IN OUT EFI_PHYSICAL_ADDRESS *BaseAddress, IN EFI_HANDLE ImageHandle, IN EFI_HANDLE DeviceHandle OPTIONAL)
 
EFI_STATUS EFIAPI CoreAddMemorySpace (IN EFI_GCD_MEMORY_TYPE GcdMemoryType, IN EFI_PHYSICAL_ADDRESS BaseAddress, IN UINT64 Length, IN UINT64 Capabilities)
 
EFI_STATUS EFIAPI CoreFreeMemorySpace (IN EFI_PHYSICAL_ADDRESS BaseAddress, IN UINT64 Length)
 
EFI_STATUS EFIAPI CoreRemoveMemorySpace (IN EFI_PHYSICAL_ADDRESS BaseAddress, IN UINT64 Length)
 
VOID BuildMemoryDescriptor (IN OUT EFI_GCD_MEMORY_SPACE_DESCRIPTOR *Descriptor, IN EFI_GCD_MAP_ENTRY *Entry)
 
EFI_STATUS EFIAPI CoreGetMemorySpaceDescriptor (IN EFI_PHYSICAL_ADDRESS BaseAddress, OUT EFI_GCD_MEMORY_SPACE_DESCRIPTOR *Descriptor)
 
EFI_STATUS EFIAPI CoreSetMemorySpaceAttributes (IN EFI_PHYSICAL_ADDRESS BaseAddress, IN UINT64 Length, IN UINT64 Attributes)
 
EFI_STATUS EFIAPI CoreSetMemorySpaceCapabilities (IN EFI_PHYSICAL_ADDRESS BaseAddress, IN UINT64 Length, IN UINT64 Capabilities)
 
EFI_STATUS EFIAPI CoreGetMemorySpaceMap (OUT UINTN *NumberOfDescriptors, OUT EFI_GCD_MEMORY_SPACE_DESCRIPTOR **MemorySpaceMap)
 
EFI_STATUS EFIAPI CoreAddIoSpace (IN EFI_GCD_IO_TYPE GcdIoType, IN EFI_PHYSICAL_ADDRESS BaseAddress, IN UINT64 Length)
 
EFI_STATUS EFIAPI CoreAllocateIoSpace (IN EFI_GCD_ALLOCATE_TYPE GcdAllocateType, IN EFI_GCD_IO_TYPE GcdIoType, IN UINTN Alignment, IN UINT64 Length, IN OUT EFI_PHYSICAL_ADDRESS *BaseAddress, IN EFI_HANDLE ImageHandle, IN EFI_HANDLE DeviceHandle OPTIONAL)
 
EFI_STATUS EFIAPI CoreFreeIoSpace (IN EFI_PHYSICAL_ADDRESS BaseAddress, IN UINT64 Length)
 
EFI_STATUS EFIAPI CoreRemoveIoSpace (IN EFI_PHYSICAL_ADDRESS BaseAddress, IN UINT64 Length)
 
VOID BuildIoDescriptor (IN EFI_GCD_IO_SPACE_DESCRIPTOR *Descriptor, IN EFI_GCD_MAP_ENTRY *Entry)
 
EFI_STATUS EFIAPI CoreGetIoSpaceDescriptor (IN EFI_PHYSICAL_ADDRESS BaseAddress, OUT EFI_GCD_IO_SPACE_DESCRIPTOR *Descriptor)
 
EFI_STATUS EFIAPI CoreGetIoSpaceMap (OUT UINTN *NumberOfDescriptors, OUT EFI_GCD_IO_SPACE_DESCRIPTOR **IoSpaceMap)
 
UINT64 CoreConvertResourceDescriptorHobAttributesToCapabilities (EFI_GCD_MEMORY_TYPE GcdMemoryType, UINT64 Attributes)
 
UINT64 CalculateTotalMemoryBinSizeNeeded (VOID)
 
VOID FindLargestFreeRegion (IN OUT EFI_PHYSICAL_ADDRESS *BaseAddress, IN OUT UINT64 *Length, IN EFI_HOB_MEMORY_ALLOCATION *MemoryHob)
 
EFI_STATUS CoreInitializeMemoryServices (IN VOID **HobStart, OUT EFI_PHYSICAL_ADDRESS *MemoryBaseAddress, OUT UINT64 *MemoryLength)
 
EFI_STATUS CoreInitializeGcdServices (IN OUT VOID **HobStart, IN EFI_PHYSICAL_ADDRESS MemoryBaseAddress, IN UINT64 MemoryLength)
 

Variables

EFI_LOCK mGcdMemorySpaceLock = EFI_INITIALIZE_LOCK_VARIABLE (TPL_NOTIFY)
 
EFI_LOCK mGcdIoSpaceLock = EFI_INITIALIZE_LOCK_VARIABLE (TPL_NOTIFY)
 
LIST_ENTRY mGcdMemorySpaceMap = INITIALIZE_LIST_HEAD_VARIABLE (mGcdMemorySpaceMap)
 
LIST_ENTRY mGcdIoSpaceMap = INITIALIZE_LIST_HEAD_VARIABLE (mGcdIoSpaceMap)
 
EFI_GCD_MAP_ENTRY mGcdMemorySpaceMapEntryTemplate
 
EFI_GCD_MAP_ENTRY mGcdIoSpaceMapEntryTemplate
 
GCD_ATTRIBUTE_CONVERSION_ENTRY mAttributeConversionTable []
 
GLOBAL_REMOVE_IF_UNREFERENCED CONST CHAR8 * mGcdMemoryTypeNames []
 
GLOBAL_REMOVE_IF_UNREFERENCED CONST CHAR8 * mGcdIoTypeNames []
 
GLOBAL_REMOVE_IF_UNREFERENCED CONST CHAR8 * mGcdAllocationTypeNames []
 

Detailed Description

The file contains the GCD related services in the EFI Boot Services Table. The GCD services are used to manage the memory and I/O regions that are accessible to the CPU that is executing the DXE core.

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

Definition in file Gcd.c.

Macro Definition Documentation

◆ INITIALIZED_MEMORY_ATTRIBUTES

#define INITIALIZED_MEMORY_ATTRIBUTES
Value:
(EFI_RESOURCE_ATTRIBUTE_PRESENT |\
EFI_RESOURCE_ATTRIBUTE_INITIALIZED )

Definition at line 35 of file Gcd.c.

◆ MEMORY_ATTRIBUTE_MASK

#define MEMORY_ATTRIBUTE_MASK
Value:
(EFI_RESOURCE_ATTRIBUTE_PRESENT | \
EFI_RESOURCE_ATTRIBUTE_INITIALIZED | \
EFI_RESOURCE_ATTRIBUTE_TESTED | \
EFI_RESOURCE_ATTRIBUTE_READ_PROTECTED | \
EFI_RESOURCE_ATTRIBUTE_WRITE_PROTECTED | \
EFI_RESOURCE_ATTRIBUTE_EXECUTION_PROTECTED | \
EFI_RESOURCE_ATTRIBUTE_READ_ONLY_PROTECTED | \
EFI_RESOURCE_ATTRIBUTE_16_BIT_IO | \
EFI_RESOURCE_ATTRIBUTE_32_BIT_IO | \
EFI_RESOURCE_ATTRIBUTE_64_BIT_IO | \
EFI_RESOURCE_ATTRIBUTE_PERSISTENT )

Definition at line 19 of file Gcd.c.

◆ MINIMUM_INITIAL_MEMORY_SIZE

#define MINIMUM_INITIAL_MEMORY_SIZE   0x10000

Definition at line 17 of file Gcd.c.

◆ PRESENT_MEMORY_ATTRIBUTES

#define PRESENT_MEMORY_ATTRIBUTES   (EFI_RESOURCE_ATTRIBUTE_PRESENT)

Definition at line 38 of file Gcd.c.

◆ TESTED_MEMORY_ATTRIBUTES

#define TESTED_MEMORY_ATTRIBUTES
Value:
(EFI_RESOURCE_ATTRIBUTE_PRESENT | \
EFI_RESOURCE_ATTRIBUTE_INITIALIZED | \
EFI_RESOURCE_ATTRIBUTE_TESTED )

Definition at line 31 of file Gcd.c.

Function Documentation

◆ AlignValue()

UINT64 AlignValue ( IN UINT64  Value,
IN UINTN  Alignment,
IN BOOLEAN  RoundUp 
)

Aligns a value to the specified boundary.

Parameters
Value64 bit value to align
AlignmentLog base 2 of the boundary to align Value to
RoundUpTRUE if Value is to be rounded up to the nearest aligned boundary. FALSE is Value is to be rounded down to the nearest aligned boundary.
Returns
A 64 bit value is the aligned to the value nearest Value with an alignment by Alignment.

Definition at line 326 of file Gcd.c.

◆ BuildIoDescriptor()

VOID BuildIoDescriptor ( IN EFI_GCD_IO_SPACE_DESCRIPTOR Descriptor,
IN EFI_GCD_MAP_ENTRY Entry 
)

Build a IO descriptor according to an entry.

Parameters
DescriptorThe descriptor to be built
EntryAccording to this entry

Definition at line 1971 of file Gcd.c.

◆ BuildMemoryDescriptor()

VOID BuildMemoryDescriptor ( IN OUT EFI_GCD_MEMORY_SPACE_DESCRIPTOR Descriptor,
IN EFI_GCD_MAP_ENTRY Entry 
)

Build a memory descriptor according to an entry.

Parameters
DescriptorThe descriptor to be built
EntryAccording to this entry

Definition at line 1591 of file Gcd.c.

◆ CalculateTotalMemoryBinSizeNeeded()

UINT64 CalculateTotalMemoryBinSizeNeeded ( VOID  )

Calculate total memory bin size neeeded.

Returns
The total memory bin size neeeded.

Definition at line 2144 of file Gcd.c.

◆ ConverToCpuArchAttributes()

UINT64 ConverToCpuArchAttributes ( UINT64  Attributes)

Return the memory attribute specified by Attributes

Parameters
AttributesA num with some attribute bits on.
Returns
The enum value of memory attribute.

Definition at line 673 of file Gcd.c.

◆ CoreAcquireGcdIoLock()

VOID CoreAcquireGcdIoLock ( VOID  )

Acquire memory lock on mGcdIoSpaceLock.

Definition at line 290 of file Gcd.c.

◆ CoreAcquireGcdMemoryLock()

VOID CoreAcquireGcdMemoryLock ( VOID  )

Acquire memory lock on mGcdMemorySpaceLock.

Definition at line 266 of file Gcd.c.

◆ CoreAddIoSpace()

EFI_STATUS EFIAPI CoreAddIoSpace ( IN EFI_GCD_IO_TYPE  GcdIoType,
IN EFI_PHYSICAL_ADDRESS  BaseAddress,
IN UINT64  Length 
)

Adds reserved I/O or I/O resources to the global coherency domain of the processor.

Parameters
GcdIoTypeIO type of the segment.
BaseAddressBase address of the segment.
LengthLength of the segment.
Return values
EFI_SUCCESSMerged this segment into GCD map.
EFI_INVALID_PARAMETERParameter not valid

Definition at line 1846 of file Gcd.c.

◆ CoreAddMemorySpace()

EFI_STATUS EFIAPI CoreAddMemorySpace ( IN EFI_GCD_MEMORY_TYPE  GcdMemoryType,
IN EFI_PHYSICAL_ADDRESS  BaseAddress,
IN UINT64  Length,
IN UINT64  Capabilities 
)

Adds reserved memory, system memory, or memory-mapped I/O resources to the global coherency domain of the processor.

Parameters
GcdMemoryTypeMemory type of the memory space.
BaseAddressBase address of the memory space.
LengthLength of the memory space.
Capabilitiesalterable attributes of the memory space.
Return values
EFI_SUCCESSMerged this memory space into GCD map.

Definition at line 1478 of file Gcd.c.

◆ CoreAllocateGcdMapEntry()

EFI_STATUS CoreAllocateGcdMapEntry ( IN OUT EFI_GCD_MAP_ENTRY **  TopEntry,
IN OUT EFI_GCD_MAP_ENTRY **  BottomEntry 
)

Allocate pool for two entries.

Parameters
TopEntryAn entry of GCD map
BottomEntryAn entry of GCD map
Return values
EFI_OUT_OF_RESOURCESNo enough buffer to be allocated.
EFI_SUCCESSBoth entries successfully allocated.

Definition at line 389 of file Gcd.c.

◆ CoreAllocateIoSpace()

EFI_STATUS EFIAPI CoreAllocateIoSpace ( IN EFI_GCD_ALLOCATE_TYPE  GcdAllocateType,
IN EFI_GCD_IO_TYPE  GcdIoType,
IN UINTN  Alignment,
IN UINT64  Length,
IN OUT EFI_PHYSICAL_ADDRESS BaseAddress,
IN EFI_HANDLE  ImageHandle,
IN EFI_HANDLE DeviceHandle  OPTIONAL 
)

Allocates nonexistent I/O, reserved I/O, or I/O resources from the global coherency domain of the processor.

Parameters
GcdAllocateTypeThe type of allocate operation
GcdIoTypeThe desired IO type
AlignmentAlign with 2^Alignment
LengthLength to allocate
BaseAddressBase address to allocate
ImageHandleThe image handle consume the allocated space.
DeviceHandleThe device handle consume the allocated space.
Return values
EFI_INVALID_PARAMETERInvalid parameter.
EFI_NOT_FOUNDNo descriptor contains the desired space.
EFI_SUCCESSIO space successfully allocated.

Definition at line 1884 of file Gcd.c.

◆ CoreAllocateMemorySpace()

EFI_STATUS EFIAPI CoreAllocateMemorySpace ( IN EFI_GCD_ALLOCATE_TYPE  GcdAllocateType,
IN EFI_GCD_MEMORY_TYPE  GcdMemoryType,
IN UINTN  Alignment,
IN UINT64  Length,
IN OUT EFI_PHYSICAL_ADDRESS BaseAddress,
IN EFI_HANDLE  ImageHandle,
IN EFI_HANDLE DeviceHandle  OPTIONAL 
)

Allocates nonexistent memory, reserved memory, system memory, or memorymapped I/O resources from the global coherency domain of the processor.

Parameters
GcdAllocateTypeThe type of allocate operation
GcdMemoryTypeThe desired memory type
AlignmentAlign with 2^Alignment
LengthLength to allocate
BaseAddressBase address to allocate
ImageHandleThe image handle consume the allocated space.
DeviceHandleThe device handle consume the allocated space.
Return values
EFI_INVALID_PARAMETERInvalid parameter.
EFI_NOT_FOUNDNo descriptor contains the desired space.
EFI_SUCCESSMemory space successfully allocated.

Definition at line 1429 of file Gcd.c.

◆ CoreAllocateSpace()

EFI_STATUS CoreAllocateSpace ( IN UINTN  Operation,
IN EFI_GCD_ALLOCATE_TYPE  GcdAllocateType,
IN EFI_GCD_MEMORY_TYPE  GcdMemoryType,
IN EFI_GCD_IO_TYPE  GcdIoType,
IN UINTN  Alignment,
IN UINT64  Length,
IN OUT EFI_PHYSICAL_ADDRESS BaseAddress,
IN EFI_HANDLE  ImageHandle,
IN EFI_HANDLE DeviceHandle  OPTIONAL 
)

Allocate space on specified address and length.

Parameters
OperationThe type of operation (memory or IO)
GcdAllocateTypeThe type of allocate operation
GcdMemoryTypeThe desired memory type
GcdIoTypeThe desired IO type
AlignmentAlign with 2^Alignment
LengthLength to allocate
BaseAddressBase address to allocate
ImageHandleThe image handle consume the allocated space.
DeviceHandleThe device handle consume the allocated space.
Return values
EFI_INVALID_PARAMETERInvalid parameter.
EFI_NOT_FOUNDNo descriptor for the desired space exists.
EFI_SUCCESSSpace successfully allocated.

Definition at line 1099 of file Gcd.c.

◆ CoreAllocateSpaceCheckEntry()

EFI_STATUS CoreAllocateSpaceCheckEntry ( IN UINTN  Operation,
IN EFI_GCD_MAP_ENTRY Entry,
IN EFI_GCD_MEMORY_TYPE  GcdMemoryType,
IN EFI_GCD_IO_TYPE  GcdIoType 
)

Check whether an entry could be used to allocate space.

Parameters
OperationAllocate memory or IO
EntryThe entry to be tested
GcdMemoryTypeThe desired memory type
GcdIoTypeThe desired IO type
Return values
EFI_NOT_FOUNDThe memory type does not match or there's an image handle on the entry.
EFI_UNSUPPORTEDThe operation unsupported.
EFI_SUCCESSIt's ok for this entry to be used to allocate space.

Definition at line 1049 of file Gcd.c.

◆ CoreCleanupGcdMapEntry()

EFI_STATUS CoreCleanupGcdMapEntry ( IN EFI_GCD_MAP_ENTRY TopEntry,
IN EFI_GCD_MAP_ENTRY BottomEntry,
IN LIST_ENTRY StartLink,
IN LIST_ENTRY EndLink,
IN LIST_ENTRY Map 
)

Merge adjacent entries on total chain.

Parameters
TopEntryTop entry of GCD map.
BottomEntryBottom entry of GCD map.
StartLinkStart link of the list for this loop.
EndLinkEnd link of the list for this loop.
MapBoundary.
Return values
EFI_SUCCESSGCD map successfully cleaned up.

Definition at line 555 of file Gcd.c.

◆ CoreConvertResourceDescriptorHobAttributesToCapabilities()

UINT64 CoreConvertResourceDescriptorHobAttributesToCapabilities ( EFI_GCD_MEMORY_TYPE  GcdMemoryType,
UINT64  Attributes 
)

Converts a Resource Descriptor HOB attributes mask to an EFI Memory Descriptor capabilities mask

Parameters
GcdMemoryTypeType of resource in the GCD memory map.
AttributesThe attribute mask in the Resource Descriptor HOB.
Returns
The capabilities mask for an EFI Memory Descriptor.

Definition at line 2115 of file Gcd.c.

◆ CoreConvertSpace()

EFI_STATUS CoreConvertSpace ( IN UINTN  Operation,
IN EFI_GCD_MEMORY_TYPE  GcdMemoryType,
IN EFI_GCD_IO_TYPE  GcdIoType,
IN EFI_PHYSICAL_ADDRESS  BaseAddress,
IN UINT64  Length,
IN UINT64  Capabilities,
IN UINT64  Attributes 
)

Do operation on a segment of memory space specified (add, free, remove, change attribute ...).

Parameters
OperationThe type of the operation
GcdMemoryTypeAdditional information for the operation
GcdIoTypeAdditional information for the operation
BaseAddressStart address of the segment
Lengthlength of the segment
CapabilitiesThe alterable attributes of a newly added entry
AttributesThe attributes needs to be set
Return values
EFI_INVALID_PARAMETERLength is 0 or address (length) not aligned when setting attribute.
EFI_SUCCESSAction successfully done.
EFI_UNSUPPORTEDCould not find the proper descriptor on this segment or set an upsupported attribute.
EFI_ACCESS_DENIEDOperate on an space non-exist or is used for an image.
EFI_NOT_FOUNDFree a non-using space or remove a non-exist space, and so on.
EFI_OUT_OF_RESOURCESNo buffer could be allocated.
EFI_NOT_AVAILABLE_YETThe attributes cannot be set because CPU architectural protocol is not available yet.

Definition at line 723 of file Gcd.c.

◆ CoreCountGcdMapEntry()

UINTN CoreCountGcdMapEntry ( IN LIST_ENTRY Map)

Count the amount of GCD map entries.

Parameters
MapPoints to the start entry to do the count loop.
Returns
The count.

Definition at line 647 of file Gcd.c.

◆ CoreDumpGcdIoSpaceMap()

VOID EFIAPI CoreDumpGcdIoSpaceMap ( BOOLEAN  InitialMap)

Dump the entire contents if the GCD I/O Space Map using DEBUG() macros when PcdDebugPrintErrorLevel has the DEBUG_GCD bit set.

Parameters
InitialMapTRUE if the initial GCD I/O Map is being dumped. Otherwise, FALSE.

Definition at line 190 of file Gcd.c.

◆ CoreDumpGcdMemorySpaceMap()

VOID EFIAPI CoreDumpGcdMemorySpaceMap ( BOOLEAN  InitialMap)

Dump the entire contents if the GCD Memory Space Map using DEBUG() macros when PcdDebugPrintErrorLevel has the DEBUG_GCD bit set.

Parameters
InitialMapTRUE if the initial GCD Memory Map is being dumped. Otherwise, FALSE.

Definition at line 144 of file Gcd.c.

◆ CoreFreeIoSpace()

EFI_STATUS EFIAPI CoreFreeIoSpace ( IN EFI_PHYSICAL_ADDRESS  BaseAddress,
IN UINT64  Length 
)

Frees nonexistent I/O, reserved I/O, or I/O resources from the global coherency domain of the processor.

Parameters
BaseAddressBase address of the segment.
LengthLength of the segment.
Return values
EFI_SUCCESSSpace successfully freed.

Definition at line 1931 of file Gcd.c.

◆ CoreFreeMemorySpace()

EFI_STATUS EFIAPI CoreFreeMemorySpace ( IN EFI_PHYSICAL_ADDRESS  BaseAddress,
IN UINT64  Length 
)

Frees nonexistent memory, reserved memory, system memory, or memory-mapped I/O resources from the global coherency domain of the processor.

Parameters
BaseAddressBase address of the memory space.
LengthLength of the memory space.
Return values
EFI_SUCCESSSpace successfully freed.

Definition at line 1551 of file Gcd.c.

◆ CoreGetIoSpaceDescriptor()

EFI_STATUS EFIAPI CoreGetIoSpaceDescriptor ( IN EFI_PHYSICAL_ADDRESS  BaseAddress,
OUT EFI_GCD_IO_SPACE_DESCRIPTOR Descriptor 
)

Retrieves the descriptor for an I/O region containing a specified address.

Parameters
BaseAddressSpecified start address
DescriptorSpecified length
Return values
EFI_INVALID_PARAMETERDescriptor is NULL.
EFI_SUCCESSSuccessfully get the IO space descriptor.

Definition at line 1995 of file Gcd.c.

◆ CoreGetIoSpaceMap()

EFI_STATUS EFIAPI CoreGetIoSpaceMap ( OUT UINTN NumberOfDescriptors,
OUT EFI_GCD_IO_SPACE_DESCRIPTOR **  IoSpaceMap 
)

Returns a map of the I/O resources in the global coherency domain of the processor.

Parameters
NumberOfDescriptorsNumber of descriptors.
IoSpaceMapDescriptor array
Return values
EFI_INVALID_PARAMETERInvalid parameter
EFI_OUT_OF_RESOURCESNo enough buffer to allocate
EFI_SUCCESSSuccessfully get IO space map.

Definition at line 2047 of file Gcd.c.

◆ CoreGetMemorySpaceDescriptor()

EFI_STATUS EFIAPI CoreGetMemorySpaceDescriptor ( IN EFI_PHYSICAL_ADDRESS  BaseAddress,
OUT EFI_GCD_MEMORY_SPACE_DESCRIPTOR Descriptor 
)

Retrieves the descriptor for a memory region containing a specified address.

Parameters
BaseAddressSpecified start address
DescriptorSpecified length
Return values
EFI_INVALID_PARAMETERInvalid parameter
EFI_SUCCESSSuccessfully get memory space descriptor.

Definition at line 1617 of file Gcd.c.

◆ CoreGetMemorySpaceMap()

EFI_STATUS EFIAPI CoreGetMemorySpaceMap ( OUT UINTN NumberOfDescriptors,
OUT EFI_GCD_MEMORY_SPACE_DESCRIPTOR **  MemorySpaceMap 
)

Returns a map of the memory resources in the global coherency domain of the processor.

Parameters
NumberOfDescriptorsNumber of descriptors.
MemorySpaceMapDescriptor array
Return values
EFI_INVALID_PARAMETERInvalid parameter
EFI_OUT_OF_RESOURCESNo enough buffer to allocate
EFI_SUCCESSSuccessfully get memory space map.

Definition at line 1737 of file Gcd.c.

◆ CoreInitializeGcdServices()

EFI_STATUS CoreInitializeGcdServices ( IN OUT VOID **  HobStart,
IN EFI_PHYSICAL_ADDRESS  MemoryBaseAddress,
IN UINT64  MemoryLength 
)

External function. Initializes the GCD and memory services based on the memory descriptor HOBs. This function is responsible for priming the GCD map and the memory map, so memory allocations and resource allocations can be made. The HobStart will be relocated to a pool buffer.

Parameters
HobStartThe start address of the HOB
MemoryBaseAddressStart address of memory region found to init DXE core.
MemoryLengthLength of memory region found to init DXE core.
Return values
EFI_SUCCESSGCD services successfully initialized.

Definition at line 2574 of file Gcd.c.

◆ CoreInitializeMemoryServices()

EFI_STATUS CoreInitializeMemoryServices ( IN VOID **  HobStart,
OUT EFI_PHYSICAL_ADDRESS MemoryBaseAddress,
OUT UINT64 *  MemoryLength 
)

External function. Initializes memory services based on the memory descriptor HOBs. This function is responsible for priming the memory map, so memory allocations and resource allocations can be made. The first part of this function can not depend on any memory services until at least one memory descriptor is provided to the memory services.

Parameters
HobStartThe start address of the HOB.
MemoryBaseAddressStart address of memory region found to init DXE core.
MemoryLengthLength of memory region found to init DXE core.
Return values
EFI_SUCCESSMemory services successfully initialized.

Definition at line 2236 of file Gcd.c.

◆ CoreInsertGcdMapEntry()

EFI_STATUS CoreInsertGcdMapEntry ( IN LIST_ENTRY Link,
IN EFI_GCD_MAP_ENTRY Entry,
IN EFI_PHYSICAL_ADDRESS  BaseAddress,
IN UINT64  Length,
IN EFI_GCD_MAP_ENTRY TopEntry,
IN EFI_GCD_MAP_ENTRY BottomEntry 
)

Internal function. Inserts a new descriptor into a sorted list

Parameters
LinkThe linked list to insert the range BaseAddress and Length into
EntryA pointer to the entry that is inserted
BaseAddressThe base address of the new range
LengthThe length of the new range in bytes
TopEntryTop pad entry to insert if needed.
BottomEntryBottom pad entry to insert if needed.
Return values
EFI_SUCCESSThe new range was inserted into the linked list

Definition at line 432 of file Gcd.c.

◆ CoreInternalAddMemorySpace()

EFI_STATUS CoreInternalAddMemorySpace ( IN EFI_GCD_MEMORY_TYPE  GcdMemoryType,
IN EFI_PHYSICAL_ADDRESS  BaseAddress,
IN UINT64  Length,
IN UINT64  Capabilities 
)

Add a segment of memory to GCD map.

Parameters
GcdMemoryTypeMemory type of the segment.
BaseAddressBase address of the segment.
LengthLength of the segment.
Capabilitiesalterable attributes of the segment.
Return values
EFI_INVALID_PARAMETERInvalid parameters.
EFI_SUCCESSSuccessfully add a segment of memory space.

Definition at line 1385 of file Gcd.c.

◆ CoreMergeGcdMapEntry()

EFI_STATUS CoreMergeGcdMapEntry ( IN LIST_ENTRY Link,
IN BOOLEAN  Forward,
IN LIST_ENTRY Map 
)

Merge the Gcd region specified by Link and its adjacent entry.

Parameters
LinkSpecify the entry to be merged (with its adjacent entry).
ForwardDirection (forward or backward).
MapBoundary.
Return values
EFI_SUCCESSSuccessfully returned.
EFI_UNSUPPORTEDThese adjacent regions could not merge.

Definition at line 477 of file Gcd.c.

◆ CoreReleaseGcdIoLock()

VOID CoreReleaseGcdIoLock ( VOID  )

Release memory lock on mGcdIoSpaceLock.

Definition at line 302 of file Gcd.c.

◆ CoreReleaseGcdMemoryLock()

VOID CoreReleaseGcdMemoryLock ( VOID  )

Release memory lock on mGcdMemorySpaceLock.

Definition at line 278 of file Gcd.c.

◆ CoreRemoveIoSpace()

EFI_STATUS EFIAPI CoreRemoveIoSpace ( IN EFI_PHYSICAL_ADDRESS  BaseAddress,
IN UINT64  Length 
)

Removes reserved I/O or I/O resources from the global coherency domain of the processor.

Parameters
BaseAddressBase address of the segment.
LengthLength of the segment.
Return values
EFI_SUCCESSSuccessfully removed a segment of IO space.

Definition at line 1953 of file Gcd.c.

◆ CoreRemoveMemorySpace()

EFI_STATUS EFIAPI CoreRemoveMemorySpace ( IN EFI_PHYSICAL_ADDRESS  BaseAddress,
IN UINT64  Length 
)

Removes reserved memory, system memory, or memory-mapped I/O resources from the global coherency domain of the processor.

Parameters
BaseAddressBase address of the memory space.
LengthLength of the memory space.
Return values
EFI_SUCCESSSuccessfully remove a segment of memory space.

Definition at line 1573 of file Gcd.c.

◆ CoreSearchGcdMapEntry()

EFI_STATUS CoreSearchGcdMapEntry ( IN EFI_PHYSICAL_ADDRESS  BaseAddress,
IN UINT64  Length,
OUT LIST_ENTRY **  StartLink,
OUT LIST_ENTRY **  EndLink,
IN LIST_ENTRY Map 
)

Search a segment of memory space in GCD map. The result is a range of GCD entry list.

Parameters
BaseAddressThe start address of the segment.
LengthThe length of the segment.
StartLinkThe first GCD entry involves this segment of memory space.
EndLinkThe first GCD entry involves this segment of memory space.
MapPoints to the start entry to search.
Return values
EFI_SUCCESSSuccessfully found the entry.
EFI_NOT_FOUNDNot found.

Definition at line 600 of file Gcd.c.

◆ CoreSetMemorySpaceAttributes()

EFI_STATUS EFIAPI CoreSetMemorySpaceAttributes ( IN EFI_PHYSICAL_ADDRESS  BaseAddress,
IN UINT64  Length,
IN UINT64  Attributes 
)

Modifies the attributes for a memory region in the global coherency domain of the processor.

Parameters
BaseAddressSpecified start address
LengthSpecified length
AttributesSpecified attributes
Return values
EFI_SUCCESSThe attributes were set for the memory region.
EFI_INVALID_PARAMETERLength is zero.
EFI_UNSUPPORTEDThe processor does not support one or more bytes of the memory resource range specified by BaseAddress and Length.
EFI_UNSUPPORTEDThe bit mask of attributes is not support for the memory resource range specified by BaseAddress and Length.
EFI_ACCESS_DEFINEDThe attributes for the memory resource range specified by BaseAddress and Length cannot be modified.
EFI_OUT_OF_RESOURCESThere are not enough system resources to modify the attributes of the memory resource range.
EFI_NOT_AVAILABLE_YETThe attributes cannot be set because CPU architectural protocol is not available yet.

Definition at line 1680 of file Gcd.c.

◆ CoreSetMemorySpaceCapabilities()

EFI_STATUS EFIAPI CoreSetMemorySpaceCapabilities ( IN EFI_PHYSICAL_ADDRESS  BaseAddress,
IN UINT64  Length,
IN UINT64  Capabilities 
)

Modifies the capabilities for a memory region in the global coherency domain of the processor.

Parameters
BaseAddressThe physical address that is the start address of a memory region.
LengthThe size in bytes of the memory region.
CapabilitiesThe bit mask of capabilities that the memory region supports.
Return values
EFI_SUCCESSThe capabilities were set for the memory region.
EFI_INVALID_PARAMETERLength is zero.
EFI_UNSUPPORTEDThe capabilities specified by Capabilities do not include the memory region attributes currently in use.
EFI_ACCESS_DENIEDThe capabilities for the memory resource range specified by BaseAddress and Length cannot be modified.
EFI_OUT_OF_RESOURCESThere are not enough system resources to modify the capabilities of the memory resource range.

Definition at line 1711 of file Gcd.c.

◆ CoreValidateResourceDescriptorHobAttributes()

VOID CoreValidateResourceDescriptorHobAttributes ( IN UINT64  Attributes)

Validate resource descriptor HOB's attributes.

If Attributes includes some memory resource's settings, it should include the corresponding capabilites also.

Parameters
AttributesResource descriptor HOB attributes.

Definition at line 235 of file Gcd.c.

◆ FindLargestFreeRegion()

VOID FindLargestFreeRegion ( IN OUT EFI_PHYSICAL_ADDRESS BaseAddress,
IN OUT UINT64 *  Length,
IN EFI_HOB_MEMORY_ALLOCATION MemoryHob 
)

Find the largest region in the specified region that is not covered by an existing memory allocation

Parameters
BaseAddressOn input start of the region to check. On output start of the largest free region.
LengthOn input size of region to check. On output size of the largest free region.
MemoryHobHob pointer for the first memory allocation pointer to check

Definition at line 2172 of file Gcd.c.

◆ PageAlignAddress()

UINT64 PageAlignAddress ( IN UINT64  Value)

Aligns address to the page boundary.

Parameters
Value64 bit address to align
Returns
A 64 bit value is the aligned to the value nearest Value with an alignment by Alignment.

Definition at line 351 of file Gcd.c.

◆ PageAlignLength()

UINT64 PageAlignLength ( IN UINT64  Value)

Aligns length to the page boundary.

Parameters
Value64 bit length to align
Returns
A 64 bit value is the aligned to the value nearest Value with an alignment by Alignment.

Definition at line 367 of file Gcd.c.

Variable Documentation

◆ mAttributeConversionTable

GCD_ATTRIBUTE_CONVERSION_ENTRY mAttributeConversionTable[]
Initial value:
= {
{ EFI_RESOURCE_ATTRIBUTE_UNCACHEABLE, EFI_MEMORY_UC, TRUE },
{ EFI_RESOURCE_ATTRIBUTE_UNCACHED_EXPORTED, EFI_MEMORY_UCE, TRUE },
{ EFI_RESOURCE_ATTRIBUTE_WRITE_COMBINEABLE, EFI_MEMORY_WC, TRUE },
{ EFI_RESOURCE_ATTRIBUTE_WRITE_THROUGH_CACHEABLE, EFI_MEMORY_WT, TRUE },
{ EFI_RESOURCE_ATTRIBUTE_WRITE_BACK_CACHEABLE, EFI_MEMORY_WB, TRUE },
{ EFI_RESOURCE_ATTRIBUTE_READ_PROTECTABLE, EFI_MEMORY_RP, TRUE },
{ EFI_RESOURCE_ATTRIBUTE_WRITE_PROTECTABLE, EFI_MEMORY_WP, TRUE },
{ EFI_RESOURCE_ATTRIBUTE_EXECUTION_PROTECTABLE, EFI_MEMORY_XP, TRUE },
{ EFI_RESOURCE_ATTRIBUTE_READ_ONLY_PROTECTABLE, EFI_MEMORY_RO, TRUE },
{ EFI_RESOURCE_ATTRIBUTE_PRESENT, EFI_MEMORY_PRESENT, FALSE },
{ EFI_RESOURCE_ATTRIBUTE_INITIALIZED, EFI_MEMORY_INITIALIZED, FALSE },
{ EFI_RESOURCE_ATTRIBUTE_TESTED, EFI_MEMORY_TESTED, FALSE },
{ EFI_RESOURCE_ATTRIBUTE_PERSISTABLE, EFI_MEMORY_NV, TRUE },
{ EFI_RESOURCE_ATTRIBUTE_MORE_RELIABLE, EFI_MEMORY_MORE_RELIABLE, TRUE },
{ EFI_RESOURCE_ATTRIBUTE_SPECIAL_PURPOSE, EFI_MEMORY_SP, TRUE },
{ 0, 0, FALSE }
}
#define TRUE
Definition: Base.h:301
#define FALSE
Definition: Base.h:307

Definition at line 80 of file Gcd.c.

◆ mGcdAllocationTypeNames

GLOBAL_REMOVE_IF_UNREFERENCED CONST CHAR8* mGcdAllocationTypeNames[]
Initial value:
= {
"AnySearchBottomUp ",
"MaxAddressSearchBottomUp ",
"AtAddress ",
"AnySearchTopDown ",
"MaxAddressSearchTopDown ",
"Unknown "
}

Lookup table used to print GCD Allocation Types

Definition at line 126 of file Gcd.c.

◆ mGcdIoSpaceLock

EFI_LOCK mGcdIoSpaceLock = EFI_INITIALIZE_LOCK_VARIABLE (TPL_NOTIFY)

Definition at line 44 of file Gcd.c.

◆ mGcdIoSpaceMap

LIST_ENTRY mGcdIoSpaceMap = INITIALIZE_LIST_HEAD_VARIABLE (mGcdIoSpaceMap)

Definition at line 46 of file Gcd.c.

◆ mGcdIoSpaceMapEntryTemplate

EFI_GCD_MAP_ENTRY mGcdIoSpaceMapEntryTemplate
Initial value:
= {
EFI_GCD_MAP_SIGNATURE,
{
},
0,
0,
0,
0,
}
#define NULL
Definition: Base.h:319
EFI_GCD_MEMORY_TYPE
Definition: PiDxeCis.h:21
@ EfiGcdIoTypeNonExistent
Definition: PiDxeCis.h:75

Definition at line 64 of file Gcd.c.

◆ mGcdIoTypeNames

GLOBAL_REMOVE_IF_UNREFERENCED CONST CHAR8* mGcdIoTypeNames[]
Initial value:
= {
"NonExist",
"Reserved",
"I/O ",
"Unknown "
}

Lookup table used to print GCD I/O Space Map

Definition at line 116 of file Gcd.c.

◆ mGcdMemorySpaceLock

EFI_LOCK mGcdMemorySpaceLock = EFI_INITIALIZE_LOCK_VARIABLE (TPL_NOTIFY)

Definition at line 43 of file Gcd.c.

◆ mGcdMemorySpaceMap

LIST_ENTRY mGcdMemorySpaceMap = INITIALIZE_LIST_HEAD_VARIABLE (mGcdMemorySpaceMap)

Definition at line 45 of file Gcd.c.

◆ mGcdMemorySpaceMapEntryTemplate

EFI_GCD_MAP_ENTRY mGcdMemorySpaceMapEntryTemplate
Initial value:
= {
EFI_GCD_MAP_SIGNATURE,
{
},
0,
0,
0,
0,
}
@ EfiGcdMemoryTypeNonExistent
Definition: PiDxeCis.h:26
EFI_GCD_IO_TYPE
Definition: PiDxeCis.h:70

Definition at line 48 of file Gcd.c.

◆ mGcdMemoryTypeNames

GLOBAL_REMOVE_IF_UNREFERENCED CONST CHAR8* mGcdMemoryTypeNames[]
Initial value:
= {
"NonExist ",
"Reserved ",
"SystemMem",
"MMIO ",
"PersisMem",
"MoreRelia",
"Unaccepte",
"Unknown "
}

Lookup table used to print GCD Memory Space Map

Definition at line 102 of file Gcd.c.