TianoCore EDK2 master
|
#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) |
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 [] |
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.
#define INITIALIZED_MEMORY_ATTRIBUTES |
#define MEMORY_ATTRIBUTE_MASK |
#define PRESENT_MEMORY_ATTRIBUTES (EFI_RESOURCE_ATTRIBUTE_PRESENT) |
#define TESTED_MEMORY_ATTRIBUTES |
Aligns a value to the specified boundary.
Value | 64 bit value to align |
Alignment | Log base 2 of the boundary to align Value to |
RoundUp | TRUE 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. |
VOID BuildIoDescriptor | ( | IN EFI_GCD_IO_SPACE_DESCRIPTOR * | Descriptor, |
IN EFI_GCD_MAP_ENTRY * | Entry | ||
) |
VOID BuildMemoryDescriptor | ( | IN OUT EFI_GCD_MEMORY_SPACE_DESCRIPTOR * | Descriptor, |
IN EFI_GCD_MAP_ENTRY * | Entry | ||
) |
UINT64 CalculateTotalMemoryBinSizeNeeded | ( | VOID | ) |
UINT64 ConverToCpuArchAttributes | ( | UINT64 | Attributes | ) |
VOID CoreAcquireGcdIoLock | ( | VOID | ) |
VOID CoreAcquireGcdMemoryLock | ( | VOID | ) |
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.
GcdIoType | IO type of the segment. |
BaseAddress | Base address of the segment. |
Length | Length of the segment. |
EFI_SUCCESS | Merged this segment into GCD map. |
EFI_INVALID_PARAMETER | Parameter not valid |
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.
GcdMemoryType | Memory type of the memory space. |
BaseAddress | Base address of the memory space. |
Length | Length of the memory space. |
Capabilities | alterable attributes of the memory space. |
EFI_SUCCESS | Merged this memory space into GCD map. |
EFI_STATUS CoreAllocateGcdMapEntry | ( | IN OUT EFI_GCD_MAP_ENTRY ** | TopEntry, |
IN OUT EFI_GCD_MAP_ENTRY ** | BottomEntry | ||
) |
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.
GcdAllocateType | The type of allocate operation |
GcdIoType | The desired IO type |
Alignment | Align with 2^Alignment |
Length | Length to allocate |
BaseAddress | Base address to allocate |
ImageHandle | The image handle consume the allocated space. |
DeviceHandle | The device handle consume the allocated space. |
EFI_INVALID_PARAMETER | Invalid parameter. |
EFI_NOT_FOUND | No descriptor contains the desired space. |
EFI_SUCCESS | IO space successfully allocated. |
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.
GcdAllocateType | The type of allocate operation |
GcdMemoryType | The desired memory type |
Alignment | Align with 2^Alignment |
Length | Length to allocate |
BaseAddress | Base address to allocate |
ImageHandle | The image handle consume the allocated space. |
DeviceHandle | The device handle consume the allocated space. |
EFI_INVALID_PARAMETER | Invalid parameter. |
EFI_NOT_FOUND | No descriptor contains the desired space. |
EFI_SUCCESS | Memory space successfully allocated. |
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.
Operation | The type of operation (memory or IO) |
GcdAllocateType | The type of allocate operation |
GcdMemoryType | The desired memory type |
GcdIoType | The desired IO type |
Alignment | Align with 2^Alignment |
Length | Length to allocate |
BaseAddress | Base address to allocate |
ImageHandle | The image handle consume the allocated space. |
DeviceHandle | The device handle consume the allocated space. |
EFI_INVALID_PARAMETER | Invalid parameter. |
EFI_NOT_FOUND | No descriptor for the desired space exists. |
EFI_SUCCESS | Space successfully allocated. |
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.
Operation | Allocate memory or IO |
Entry | The entry to be tested |
GcdMemoryType | The desired memory type |
GcdIoType | The desired IO type |
EFI_NOT_FOUND | The memory type does not match or there's an image handle on the entry. |
EFI_UNSUPPORTED | The operation unsupported. |
EFI_SUCCESS | It's ok for this entry to be used to allocate space. |
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.
TopEntry | Top entry of GCD map. |
BottomEntry | Bottom entry of GCD map. |
StartLink | Start link of the list for this loop. |
EndLink | End link of the list for this loop. |
Map | Boundary. |
EFI_SUCCESS | GCD map successfully cleaned up. |
UINT64 CoreConvertResourceDescriptorHobAttributesToCapabilities | ( | EFI_GCD_MEMORY_TYPE | GcdMemoryType, |
UINT64 | Attributes | ||
) |
Converts a Resource Descriptor HOB attributes mask to an EFI Memory Descriptor capabilities mask
GcdMemoryType | Type of resource in the GCD memory map. |
Attributes | The attribute mask in the Resource Descriptor HOB. |
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 ...).
Operation | The type of the operation |
GcdMemoryType | Additional information for the operation |
GcdIoType | Additional information for the operation |
BaseAddress | Start address of the segment |
Length | length of the segment |
Capabilities | The alterable attributes of a newly added entry |
Attributes | The attributes needs to be set |
EFI_INVALID_PARAMETER | Length is 0 or address (length) not aligned when setting attribute. |
EFI_SUCCESS | Action successfully done. |
EFI_UNSUPPORTED | Could not find the proper descriptor on this segment or set an upsupported attribute. |
EFI_ACCESS_DENIED | Operate on an space non-exist or is used for an image. |
EFI_NOT_FOUND | Free a non-using space or remove a non-exist space, and so on. |
EFI_OUT_OF_RESOURCES | No buffer could be allocated. |
EFI_NOT_AVAILABLE_YET | The attributes cannot be set because CPU architectural protocol is not available yet. |
UINTN CoreCountGcdMapEntry | ( | IN LIST_ENTRY * | Map | ) |
VOID EFIAPI CoreDumpGcdIoSpaceMap | ( | BOOLEAN | InitialMap | ) |
VOID EFIAPI CoreDumpGcdMemorySpaceMap | ( | BOOLEAN | InitialMap | ) |
EFI_STATUS EFIAPI CoreFreeIoSpace | ( | IN EFI_PHYSICAL_ADDRESS | BaseAddress, |
IN UINT64 | Length | ||
) |
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.
BaseAddress | Base address of the memory space. |
Length | Length of the memory space. |
EFI_SUCCESS | Space successfully freed. |
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 | ||
) |
Returns a map of the I/O resources in the global coherency domain of the processor.
NumberOfDescriptors | Number of descriptors. |
IoSpaceMap | Descriptor array |
EFI_INVALID_PARAMETER | Invalid parameter |
EFI_OUT_OF_RESOURCES | No enough buffer to allocate |
EFI_SUCCESS | Successfully get IO space map. |
EFI_STATUS EFIAPI CoreGetMemorySpaceDescriptor | ( | IN EFI_PHYSICAL_ADDRESS | BaseAddress, |
OUT EFI_GCD_MEMORY_SPACE_DESCRIPTOR * | Descriptor | ||
) |
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.
NumberOfDescriptors | Number of descriptors. |
MemorySpaceMap | Descriptor array |
EFI_INVALID_PARAMETER | Invalid parameter |
EFI_OUT_OF_RESOURCES | No enough buffer to allocate |
EFI_SUCCESS | Successfully get memory space map. |
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.
HobStart | The start address of the HOB |
MemoryBaseAddress | Start address of memory region found to init DXE core. |
MemoryLength | Length of memory region found to init DXE core. |
EFI_SUCCESS | GCD services successfully initialized. |
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.
HobStart | The start address of the HOB. |
MemoryBaseAddress | Start address of memory region found to init DXE core. |
MemoryLength | Length of memory region found to init DXE core. |
EFI_SUCCESS | Memory services successfully initialized. |
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
Link | The linked list to insert the range BaseAddress and Length into |
Entry | A pointer to the entry that is inserted |
BaseAddress | The base address of the new range |
Length | The length of the new range in bytes |
TopEntry | Top pad entry to insert if needed. |
BottomEntry | Bottom pad entry to insert if needed. |
EFI_SUCCESS | The new range was inserted into the linked list |
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.
GcdMemoryType | Memory type of the segment. |
BaseAddress | Base address of the segment. |
Length | Length of the segment. |
Capabilities | alterable attributes of the segment. |
EFI_INVALID_PARAMETER | Invalid parameters. |
EFI_SUCCESS | Successfully add a segment of memory space. |
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.
Link | Specify the entry to be merged (with its adjacent entry). |
Forward | Direction (forward or backward). |
Map | Boundary. |
EFI_SUCCESS | Successfully returned. |
EFI_UNSUPPORTED | These adjacent regions could not merge. |
VOID CoreReleaseGcdIoLock | ( | VOID | ) |
VOID CoreReleaseGcdMemoryLock | ( | VOID | ) |
EFI_STATUS EFIAPI CoreRemoveIoSpace | ( | IN EFI_PHYSICAL_ADDRESS | BaseAddress, |
IN UINT64 | Length | ||
) |
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.
BaseAddress | Base address of the memory space. |
Length | Length of the memory space. |
EFI_SUCCESS | Successfully remove a segment of memory space. |
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.
BaseAddress | The start address of the segment. |
Length | The length of the segment. |
StartLink | The first GCD entry involves this segment of memory space. |
EndLink | The first GCD entry involves this segment of memory space. |
Map | Points to the start entry to search. |
EFI_SUCCESS | Successfully found the entry. |
EFI_NOT_FOUND | Not found. |
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.
BaseAddress | Specified start address |
Length | Specified length |
Attributes | Specified attributes |
EFI_SUCCESS | The attributes were set for the memory region. |
EFI_INVALID_PARAMETER | Length is zero. |
EFI_UNSUPPORTED | The processor does not support one or more bytes of the memory resource range specified by BaseAddress and Length. |
EFI_UNSUPPORTED | The bit mask of attributes is not support for the memory resource range specified by BaseAddress and Length. |
EFI_ACCESS_DEFINED | The attributes for the memory resource range specified by BaseAddress and Length cannot be modified. |
EFI_OUT_OF_RESOURCES | There are not enough system resources to modify the attributes of the memory resource range. |
EFI_NOT_AVAILABLE_YET | The attributes cannot be set because CPU architectural protocol is not available yet. |
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.
BaseAddress | The physical address that is the start address of a memory region. |
Length | The size in bytes of the memory region. |
Capabilities | The bit mask of capabilities that the memory region supports. |
EFI_SUCCESS | The capabilities were set for the memory region. |
EFI_INVALID_PARAMETER | Length is zero. |
EFI_UNSUPPORTED | The capabilities specified by Capabilities do not include the memory region attributes currently in use. |
EFI_ACCESS_DENIED | The capabilities for the memory resource range specified by BaseAddress and Length cannot be modified. |
EFI_OUT_OF_RESOURCES | There are not enough system resources to modify the capabilities of the memory resource range. |
VOID CoreValidateResourceDescriptorHobAttributes | ( | IN UINT64 | Attributes | ) |
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
BaseAddress | On input start of the region to check. On output start of the largest free region. |
Length | On input size of region to check. On output size of the largest free region. |
MemoryHob | Hob pointer for the first memory allocation pointer to check |
UINT64 PageAlignAddress | ( | IN UINT64 | Value | ) |
UINT64 PageAlignLength | ( | IN UINT64 | Value | ) |
GCD_ATTRIBUTE_CONVERSION_ENTRY mAttributeConversionTable[] |
GLOBAL_REMOVE_IF_UNREFERENCED CONST CHAR8* mGcdAllocationTypeNames[] |
EFI_LOCK mGcdIoSpaceLock = EFI_INITIALIZE_LOCK_VARIABLE (TPL_NOTIFY) |
LIST_ENTRY mGcdIoSpaceMap = INITIALIZE_LIST_HEAD_VARIABLE (mGcdIoSpaceMap) |
EFI_GCD_MAP_ENTRY mGcdIoSpaceMapEntryTemplate |
GLOBAL_REMOVE_IF_UNREFERENCED CONST CHAR8* mGcdIoTypeNames[] |
EFI_LOCK mGcdMemorySpaceLock = EFI_INITIALIZE_LOCK_VARIABLE (TPL_NOTIFY) |
LIST_ENTRY mGcdMemorySpaceMap = INITIALIZE_LIST_HEAD_VARIABLE (mGcdMemorySpaceMap) |
EFI_GCD_MAP_ENTRY mGcdMemorySpaceMapEntryTemplate |
GLOBAL_REMOVE_IF_UNREFERENCED CONST CHAR8* mGcdMemoryTypeNames[] |