/** @file
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 - 2011, Intel Corporation. All rights reserved.<BR>
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
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#include "DxeMain.h"
#include "Gcd.h"
//
// Module Variables
//
{
NULL,
},
0,
0,
0,
0,
(EFI_GCD_IO_TYPE) 0,
NULL,
};
{
NULL,
},
0,
0,
0,
0,
(EFI_GCD_MEMORY_TYPE) 0,
NULL,
};
{ 0, 0, FALSE }
};
///
/// Lookup table used to print GCD Memory Space Map
///
"NonExist ", // EfiGcdMemoryTypeNonExistent
"Reserved ", // EfiGcdMemoryTypeReserved
"SystemMem", // EfiGcdMemoryTypeSystemMemory
"MMIO ", // EfiGcdMemoryTypeMemoryMappedIo
"Unknown " // EfiGcdMemoryTypeMaximum
};
///
/// Lookup table used to print GCD I/O Space Map
///
"NonExist", // EfiGcdIoTypeNonExistent
"Reserved", // EfiGcdIoTypeReserved
"I/O ", // EfiGcdIoTypeIo
"Unknown " // EfiGcdIoTypeMaximum
};
///
/// Lookup table used to print GCD Allocation Types
///
"AnySearchBottomUp ", // EfiGcdAllocateAnySearchBottomUp
"MaxAddressSearchBottomUp ", // EfiGcdAllocateMaxAddressSearchBottomUp
"AtAddress ", // EfiGcdAllocateAddress
"AnySearchTopDown ", // EfiGcdAllocateAnySearchTopDown
"MaxAddressSearchTopDown ", // EfiGcdAllocateMaxAddressSearchTopDown
"Unknown " // EfiGcdMaxAllocateType
};
/**
Dump the entire contents if the GCD Memory Space Map using DEBUG() macros when
PcdDebugPrintErrorLevel has the DEBUG_GCD bit set.
@param InitialMap TRUE if the initial GCD Memory Map is being dumped. Otherwise, FALSE.
**/
)
{
if (InitialMap) {
}
DEBUG ((DEBUG_GCD, "========== ================================= ================ ================\n"));
));
}
);
}
/**
Dump the entire contents if the GCD I/O Space Map using DEBUG() macros when
PcdDebugPrintErrorLevel has the DEBUG_GCD bit set.
@param InitialMap TRUE if the initial GCD I/O Map is being dumped. Otherwise, FALSE.
**/
)
{
if (InitialMap) {
}
));
}
);
}
/**
Validate resource descriptor HOB's attributes.
If Attributes includes some memory resource's settings, it should include
the corresponding capabilites also.
@param Attributes Resource descriptor HOB attributes.
**/
)
{
((Attributes & EFI_RESOURCE_ATTRIBUTE_READ_PROTECTABLE) != 0));
((Attributes & EFI_RESOURCE_ATTRIBUTE_WRITE_PROTECTABLE) != 0));
((Attributes & EFI_RESOURCE_ATTRIBUTE_EXECUTION_PROTECTABLE) != 0));
}
/**
Acquire memory lock on mGcdMemorySpaceLock.
**/
)
{
}
/**
Release memory lock on mGcdMemorySpaceLock.
**/
)
{
}
/**
Acquire memory lock on mGcdIoSpaceLock.
**/
)
{
}
/**
Release memory lock on mGcdIoSpaceLock.
**/
)
{
}
//
// GCD Initialization Worker Functions
//
/**
Aligns a value to the specified boundary.
@param Value 64 bit value to align
@param Alignment Log base 2 of the boundary to align Value to
@param 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.
@return A 64 bit value is the aligned to the value nearest Value with an alignment by Alignment.
**/
)
{
if (RoundUp) {
Value += AlignmentMask;
}
return Value & (~AlignmentMask);
}
/**
Aligns address to the page boundary.
@param Value 64 bit address to align
@return A 64 bit value is the aligned to the value nearest Value with an alignment by Alignment.
**/
)
{
}
/**
Aligns length to the page boundary.
@param Value 64 bit length to align
@return A 64 bit value is the aligned to the value nearest Value with an alignment by Alignment.
**/
)
{
}
//
// GCD Memory Space Worker Functions
//
/**
Allocate pool for two entries.
@param TopEntry An entry of GCD map
@param BottomEntry An entry of GCD map
@retval EFI_OUT_OF_RESOURCES No enough buffer to be allocated.
@retval EFI_SUCCESS Both entries successfully allocated.
**/
)
{
return EFI_OUT_OF_RESOURCES;
}
if (*BottomEntry == NULL) {
CoreFreePool (*TopEntry);
return EFI_OUT_OF_RESOURCES;
}
return EFI_SUCCESS;
}
/**
Internal function. Inserts a new descriptor into a sorted list
@param Link The linked list to insert the range BaseAddress
and Length into
@param Entry A pointer to the entry that is inserted
@param BaseAddress The base address of the new range
@param Length The length of the new range in bytes
@param TopEntry Top pad entry to insert if needed.
@param BottomEntry Bottom pad entry to insert if needed.
@retval EFI_SUCCESS The new range was inserted into the linked list
**/
)
{
}
}
return EFI_SUCCESS;
}
/**
Merge the Gcd region specified by Link and its adjacent entry.
@param Link Specify the entry to be merged (with its
adjacent entry).
@param Forward Direction (forward or backward).
@param Map Boundary.
@retval EFI_SUCCESS Successfully returned.
@retval EFI_UNSUPPORTED These adjacent regions could not merge.
**/
)
{
//
// Get adjacent entry
//
if (Forward) {
} else {
}
//
// If AdjacentLink is the head of the list, then no merge can be performed
//
if (AdjacentLink == Map) {
return EFI_SUCCESS;
}
return EFI_UNSUPPORTED;
}
return EFI_UNSUPPORTED;
}
return EFI_UNSUPPORTED;
}
return EFI_UNSUPPORTED;
}
return EFI_UNSUPPORTED;
}
return EFI_UNSUPPORTED;
}
if (Forward) {
} else {
}
return EFI_SUCCESS;
}
/**
Merge adjacent entries on total chain.
@param TopEntry Top entry of GCD map.
@param BottomEntry Bottom entry of GCD map.
@param StartLink Start link of the list for this loop.
@param EndLink End link of the list for this loop.
@param Map Boundary.
@retval EFI_SUCCESS GCD map successfully cleaned up.
**/
)
{
}
if (BottomEntry->Signature == 0) {
}
}
return EFI_SUCCESS;
}
/**
Search a segment of memory space in GCD map. The result is a range of GCD entry list.
@param BaseAddress The start address of the segment.
@param Length The length of the segment.
@param StartLink The first GCD entry involves this segment of
memory space.
@param EndLink The first GCD entry involves this segment of
memory space.
@param Map Points to the start entry to search.
@retval EFI_SUCCESS Successfully found the entry.
@retval EFI_NOT_FOUND Not found.
**/
)
{
}
return EFI_SUCCESS;
}
}
}
return EFI_NOT_FOUND;
}
/**
Count the amount of GCD map entries.
@param Map Points to the start entry to do the count loop.
@return The count.
**/
)
{
Count = 0;
Count++;
}
return Count;
}
/**
Return the memory attribute specified by Attributes
@param Attributes A num with some attribute bits on.
@return The enum value of memory attribute.
**/
)
{
return EFI_MEMORY_UC;
}
return EFI_MEMORY_WC;
}
return EFI_MEMORY_WT;
}
return EFI_MEMORY_WB;
}
return EFI_MEMORY_WP;
}
return INVALID_CPU_ARCH_ATTRIBUTES;
}
/**
Do operation on a segment of memory space specified (add, free, remove, change attribute ...).
@param Operation The type of the operation
@param GcdMemoryType Additional information for the operation
@param GcdIoType Additional information for the operation
@param BaseAddress Start address of the segment
@param Length length of the segment
@param Capabilities The alterable attributes of a newly added entry
@param Attributes The attributes needs to be set
@retval EFI_INVALID_PARAMETER Length is 0 or address (length) not aligned when
setting attribute.
@retval EFI_SUCCESS Action successfully done.
@retval EFI_UNSUPPORTED Could not find the proper descriptor on this
segment or set an upsupported attribute.
@retval EFI_ACCESS_DENIED Operate on an space non-exist or is used for an
image.
@retval EFI_NOT_FOUND Free a non-using space or remove a non-exist
space, and so on.
@retval EFI_OUT_OF_RESOURCES No buffer could be allocated.
@retval EFI_NOT_AVAILABLE_YET The attributes cannot be set because CPU architectural protocol
is not available yet.
**/
)
{
if (Length == 0) {
return EFI_INVALID_PARAMETER;
}
if ((Operation & GCD_MEMORY_SPACE_OPERATION) != 0) {
} else if ((Operation & GCD_IO_SPACE_OPERATION) != 0) {
Map = &mGcdIoSpaceMap;
} else {
}
//
// Search for the list of descriptors that cover the range BaseAddress to BaseAddress+Length
//
goto Done;
}
//
// Verify that the list of descriptors are unallocated non-existent memory.
//
switch (Operation) {
//
// Add operations
//
case GCD_ADD_MEMORY_OPERATION:
goto Done;
}
break;
case GCD_ADD_IO_OPERATION:
goto Done;
}
break;
//
// Free operations
//
case GCD_FREE_IO_OPERATION:
goto Done;
}
break;
//
// Remove operations
//
goto Done;
}
goto Done;
}
break;
case GCD_REMOVE_IO_OPERATION:
goto Done;
}
goto Done;
}
break;
//
// Set attribute operations
//
if ((Attributes & EFI_MEMORY_RUNTIME) != 0) {
goto Done;
}
}
goto Done;
}
break;
}
}
//
// Allocate work space to perform this operation
//
goto Done;
}
if (Operation == GCD_SET_ATTRIBUTES_MEMORY_OPERATION) {
//
// Call CPU Arch Protocol to attempt to set attributes on the range
//
if (CpuArchAttributes != INVALID_CPU_ARCH_ATTRIBUTES) {
} else {
gCpu,
);
}
goto Done;
}
}
}
//
//
switch (Operation) {
//
// Add operations
//
case GCD_ADD_MEMORY_OPERATION:
if (GcdMemoryType == EfiGcdMemoryTypeMemoryMappedIo) {
} else {
}
break;
case GCD_ADD_IO_OPERATION:
break;
//
// Free operations
//
case GCD_FREE_IO_OPERATION:
break;
//
// Remove operations
//
Entry->Capabilities = 0;
break;
case GCD_REMOVE_IO_OPERATION:
break;
//
// Set attribute operations
//
break;
}
}
//
// Cleanup
//
Done:
if ((Operation & GCD_MEMORY_SPACE_OPERATION) != 0) {
}
if ((Operation & GCD_IO_SPACE_OPERATION) != 0) {
}
return Status;
}
/**
Check whether an entry could be used to allocate space.
@param Operation Allocate memory or IO
@param Entry The entry to be tested
@param GcdMemoryType The desired memory type
@param GcdIoType The desired IO type
@retval EFI_NOT_FOUND The memory type does not match or there's an
image handle on the entry.
@retval EFI_UNSUPPORTED The operation unsupported.
@retval EFI_SUCCESS It's ok for this entry to be used to allocate
space.
**/
)
{
return EFI_NOT_FOUND;
}
switch (Operation) {
return EFI_NOT_FOUND;
}
break;
return EFI_NOT_FOUND;
}
break;
default:
return EFI_UNSUPPORTED;
}
return EFI_SUCCESS;
}
/**
Allocate space on specified address and length.
@param Operation The type of operation (memory or IO)
@param GcdAllocateType The type of allocate operation
@param GcdMemoryType The desired memory type
@param GcdIoType The desired IO type
@param Alignment Align with 2^Alignment
@param Length Length to allocate
@param BaseAddress Base address to allocate
@param ImageHandle The image handle consume the allocated space.
@param DeviceHandle The device handle consume the allocated space.
@retval EFI_INVALID_PARAMETER Invalid parameter.
@retval EFI_NOT_FOUND No descriptor for the desired space exists.
@retval EFI_SUCCESS Space successfully allocated.
**/
)
{
//
// Make sure parameters are valid
//
return EFI_INVALID_PARAMETER;
}
return EFI_INVALID_PARAMETER;
}
return EFI_INVALID_PARAMETER;
}
if (BaseAddress == NULL) {
return EFI_INVALID_PARAMETER;
}
if (ImageHandle == NULL) {
return EFI_INVALID_PARAMETER;
}
if (Alignment >= 64) {
return EFI_NOT_FOUND;
}
if (Length == 0) {
return EFI_INVALID_PARAMETER;
}
if ((Operation & GCD_MEMORY_SPACE_OPERATION) != 0) {
} else if ((Operation & GCD_IO_SPACE_OPERATION) != 0) {
Map = &mGcdIoSpaceMap;
} else {
}
//
// Compute alignment bit mask
//
if (GcdAllocateType == EfiGcdAllocateAddress) {
//
// Verify that the BaseAddress passed in is aligned correctly
//
if ((*BaseAddress & AlignmentMask) != 0) {
goto Done;
}
//
// Search for the list of descriptors that cover the range BaseAddress to BaseAddress+Length
//
goto Done;
}
//
// Verify that the list of descriptors are unallocated memory matching GcdMemoryType.
//
goto Done;
}
}
} else {
//
// Compute the maximum address to use in the search algorithm
//
} else {
}
//
// Verify that the list of descriptors are unallocated memory matching GcdMemoryType.
//
} else {
}
} else {
}
continue;
}
continue;
}
goto Done;
}
} else {
}
} else {
goto Done;
}
}
//
// Search for the list of descriptors that cover the range BaseAddress to BaseAddress+Length
//
goto Done;
}
//
// Verify that the list of descriptors are unallocated memory matching GcdMemoryType.
//
break;
}
}
if (Found) {
break;
}
}
}
if (!Found) {
goto Done;
}
//
// Allocate work space to perform this operation
//
goto Done;
}
//
//
}
//
// Cleanup
//
Done:
}
if ((Operation & GCD_MEMORY_SPACE_OPERATION) != 0) {
}
if ((Operation & GCD_IO_SPACE_OPERATION) !=0) {
}
return Status;
}
/**
Add a segment of memory to GCD map.
@param GcdMemoryType Memory type of the segment.
@param BaseAddress Base address of the segment.
@param Length Length of the segment.
@param Capabilities alterable attributes of the segment.
@retval EFI_INVALID_PARAMETER Invalid parameters.
@retval EFI_SUCCESS Successfully add a segment of memory space.
**/
)
{
DEBUG ((DEBUG_GCD, " GcdMemoryType = %a\n", mGcdMemoryTypeNames[MIN (GcdMemoryType, EfiGcdMemoryTypeMaximum)]));
//
// Make sure parameters are valid
//
return EFI_INVALID_PARAMETER;
}
return CoreConvertSpace (GCD_ADD_MEMORY_OPERATION, GcdMemoryType, (EFI_GCD_IO_TYPE) 0, BaseAddress, Length, Capabilities, 0);
}
//
// GCD Core Services
//
/**
Allocates nonexistent memory, reserved memory, system memory, or memorymapped
I/O resources from the global coherency domain of the processor.
@param GcdAllocateType The type of allocate operation
@param GcdMemoryType The desired memory type
@param Alignment Align with 2^Alignment
@param Length Length to allocate
@param BaseAddress Base address to allocate
@param ImageHandle The image handle consume the allocated space.
@param DeviceHandle The device handle consume the allocated space.
@retval EFI_INVALID_PARAMETER Invalid parameter.
@retval EFI_NOT_FOUND No descriptor contains the desired space.
@retval EFI_SUCCESS Memory space successfully allocated.
**/
)
{
DEBUG ((DEBUG_GCD, " GcdAllocateType = %a\n", mGcdAllocationTypeNames[MIN (GcdAllocateType, EfiGcdMaxAllocateType)]));
DEBUG ((DEBUG_GCD, " GcdMemoryType = %a\n", mGcdMemoryTypeNames[MIN (GcdMemoryType, EfiGcdMemoryTypeMaximum)]));
return CoreAllocateSpace (
(EFI_GCD_IO_TYPE) 0,
);
}
/**
Adds reserved memory, system memory, or memory-mapped I/O resources to the
global coherency domain of the processor.
@param GcdMemoryType Memory type of the memory space.
@param BaseAddress Base address of the memory space.
@param Length Length of the memory space.
@param Capabilities alterable attributes of the memory space.
@retval EFI_SUCCESS Merged this memory space into GCD map.
**/
)
{
);
);
} else {
);
1,
);
}
}
}
}
return Status;
}
/**
Frees nonexistent memory, reserved memory, system memory, or memory-mapped
I/O resources from the global coherency domain of the processor.
@param BaseAddress Base address of the memory space.
@param Length Length of the memory space.
@retval EFI_SUCCESS Space successfully freed.
**/
)
{
return CoreConvertSpace (GCD_FREE_MEMORY_OPERATION, (EFI_GCD_MEMORY_TYPE) 0, (EFI_GCD_IO_TYPE) 0, BaseAddress, Length, 0, 0);
}
/**
Removes reserved memory, system memory, or memory-mapped I/O resources from
the global coherency domain of the processor.
@param BaseAddress Base address of the memory space.
@param Length Length of the memory space.
@retval EFI_SUCCESS Successfully remove a segment of memory space.
**/
)
{
return CoreConvertSpace (GCD_REMOVE_MEMORY_OPERATION, (EFI_GCD_MEMORY_TYPE) 0, (EFI_GCD_IO_TYPE) 0, BaseAddress, Length, 0, 0);
}
/**
Build a memory descriptor according to an entry.
@param Descriptor The descriptor to be built
@param Entry According to this entry
**/
)
{
}
/**
Retrieves the descriptor for a memory region containing a specified address.
@param BaseAddress Specified start address
@param Descriptor Specified length
@retval EFI_INVALID_PARAMETER Invalid parameter
@retval EFI_SUCCESS Successfully get memory space descriptor.
**/
)
{
//
// Make sure parameters are valid
//
if (Descriptor == NULL) {
return EFI_INVALID_PARAMETER;
}
//
// Search for the list of descriptors that contain BaseAddress
//
} else {
//
// Copy the contents of the found descriptor into Descriptor
//
}
return Status;
}
/**
Modifies the attributes for a memory region in the global coherency domain of the
processor.
@param BaseAddress Specified start address
@param Length Specified length
@param Attributes Specified attributes
@retval EFI_SUCCESS The attributes were set for the memory region.
@retval EFI_INVALID_PARAMETER Length is zero.
@retval EFI_UNSUPPORTED The processor does not support one or more bytes of the memory
resource range specified by BaseAddress and Length.
@retval EFI_UNSUPPORTED The bit mask of attributes is not support for the memory resource
range specified by BaseAddress and Length.
@retval EFI_ACCESS_DEFINED The attributes for the memory resource range specified by
BaseAddress and Length cannot be modified.
@retval EFI_OUT_OF_RESOURCES There are not enough system resources to modify the attributes of
the memory resource range.
@retval EFI_NOT_AVAILABLE_YET The attributes cannot be set because CPU architectural protocol is
not available yet.
**/
)
{
DEBUG ((DEBUG_GCD, "GCD:SetMemorySpaceAttributes(Base=%016lx,Length=%016lx)\n", BaseAddress, Length));
return CoreConvertSpace (GCD_SET_ATTRIBUTES_MEMORY_OPERATION, (EFI_GCD_MEMORY_TYPE) 0, (EFI_GCD_IO_TYPE) 0, BaseAddress, Length, 0, Attributes);
}
/**
Returns a map of the memory resources in the global coherency domain of the
processor.
@param NumberOfDescriptors Number of descriptors.
@param MemorySpaceMap Descriptor array
@retval EFI_INVALID_PARAMETER Invalid parameter
@retval EFI_OUT_OF_RESOURCES No enough buffer to allocate
@retval EFI_SUCCESS Successfully get memory space map.
**/
)
{
//
// Make sure parameters are valid
//
if (NumberOfDescriptors == NULL) {
return EFI_INVALID_PARAMETER;
}
if (MemorySpaceMap == NULL) {
return EFI_INVALID_PARAMETER;
}
//
// Count the number of descriptors
//
//
// Allocate the MemorySpaceMap
//
if (*MemorySpaceMap == NULL) {
goto Done;
}
//
// Fill in the MemorySpaceMap
//
while (Link != &mGcdMemorySpaceMap) {
Descriptor++;
}
Done:
return Status;
}
/**
Adds reserved I/O or I/O resources to the global coherency domain of the processor.
@param GcdIoType IO type of the segment.
@param BaseAddress Base address of the segment.
@param Length Length of the segment.
@retval EFI_SUCCESS Merged this segment into GCD map.
@retval EFI_INVALID_PARAMETER Parameter not valid
**/
)
{
//
// Make sure parameters are valid
//
return EFI_INVALID_PARAMETER;
}
return CoreConvertSpace (GCD_ADD_IO_OPERATION, (EFI_GCD_MEMORY_TYPE) 0, GcdIoType, BaseAddress, Length, 0, 0);
}
/**
Allocates nonexistent I/O, reserved I/O, or I/O resources from the global coherency
domain of the processor.
@param GcdAllocateType The type of allocate operation
@param GcdIoType The desired IO type
@param Alignment Align with 2^Alignment
@param Length Length to allocate
@param BaseAddress Base address to allocate
@param ImageHandle The image handle consume the allocated space.
@param DeviceHandle The device handle consume the allocated space.
@retval EFI_INVALID_PARAMETER Invalid parameter.
@retval EFI_NOT_FOUND No descriptor contains the desired space.
@retval EFI_SUCCESS IO space successfully allocated.
**/
)
{
DEBUG ((DEBUG_GCD, " GcdAllocateType = %a\n", mGcdAllocationTypeNames[MIN (GcdAllocateType, EfiGcdMaxAllocateType)]));
return CoreAllocateSpace (
(EFI_GCD_MEMORY_TYPE) 0,
);
}
/**
Frees nonexistent I/O, reserved I/O, or I/O resources from the global coherency
domain of the processor.
@param BaseAddress Base address of the segment.
@param Length Length of the segment.
@retval EFI_SUCCESS Space successfully freed.
**/
)
{
return CoreConvertSpace (GCD_FREE_IO_OPERATION, (EFI_GCD_MEMORY_TYPE) 0, (EFI_GCD_IO_TYPE) 0, BaseAddress, Length, 0, 0);
}
/**
Removes reserved I/O or I/O resources from the global coherency domain of the
processor.
@param BaseAddress Base address of the segment.
@param Length Length of the segment.
@retval EFI_SUCCESS Successfully removed a segment of IO space.
**/
)
{
return CoreConvertSpace (GCD_REMOVE_IO_OPERATION, (EFI_GCD_MEMORY_TYPE) 0, (EFI_GCD_IO_TYPE) 0, BaseAddress, Length, 0, 0);
}
/**
Build a IO descriptor according to an entry.
@param Descriptor The descriptor to be built
@param Entry According to this entry
**/
)
{
}
/**
Retrieves the descriptor for an I/O region containing a specified address.
@param BaseAddress Specified start address
@param Descriptor Specified length
@retval EFI_INVALID_PARAMETER Descriptor is NULL.
@retval EFI_SUCCESS Successfully get the IO space descriptor.
**/
)
{
//
// Make sure parameters are valid
//
if (Descriptor == NULL) {
return EFI_INVALID_PARAMETER;
}
//
// Search for the list of descriptors that contain BaseAddress
//
} else {
//
// Copy the contents of the found descriptor into Descriptor
//
}
return Status;
}
/**
Returns a map of the I/O resources in the global coherency domain of the processor.
@param NumberOfDescriptors Number of descriptors.
@param IoSpaceMap Descriptor array
@retval EFI_INVALID_PARAMETER Invalid parameter
@retval EFI_OUT_OF_RESOURCES No enough buffer to allocate
@retval EFI_SUCCESS Successfully get IO space map.
**/
)
{
//
// Make sure parameters are valid
//
if (NumberOfDescriptors == NULL) {
return EFI_INVALID_PARAMETER;
}
if (IoSpaceMap == NULL) {
return EFI_INVALID_PARAMETER;
}
//
// Count the number of descriptors
//
//
// Allocate the IoSpaceMap
//
if (*IoSpaceMap == NULL) {
goto Done;
}
//
// Fill in the IoSpaceMap
//
Descriptor = *IoSpaceMap;
while (Link != &mGcdIoSpaceMap) {
Descriptor++;
}
Done:
return Status;
}
/**
Converts a Resource Descriptor HOB attributes mask to an EFI Memory Descriptor
capabilities mask
@param GcdMemoryType Type of resource in the GCD memory map.
@param Attributes The attribute mask in the Resource Descriptor
HOB.
@return The capabilities mask for an EFI Memory Descriptor.
**/
)
{
//
// Convert the Resource HOB Attributes to an EFI Memory Capabilities mask
//
for (Capabilities = 0, Conversion = mAttributeConversionTable; Conversion->Attribute != 0; Conversion++) {
}
}
}
return Capabilities;
}
/**
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.
@param HobStart The start address of the HOB.
@param MemoryBaseAddress Start address of memory region found to init DXE
core.
@param MemoryLength Length of memory region found to init DXE core.
@retval EFI_SUCCESS Memory services successfully initialized.
**/
)
{
//
// Point at the first HOB. This must be the PHIT HOB.
//
//
// Initialize the spin locks and maps in the memory services.
// Also fill in the memory services into the EFI Boot Services Table
//
//
// Initialize Local Variables
//
ResourceHob = NULL;
BaseAddress = 0;
Length = 0;
Attributes = 0;
MaxMemoryBaseAddress = 0;
MaxMemoryLength = 0;
MaxMemoryAttributes = 0;
//
// Cache the PHIT HOB for later use
//
if (PcdGet64(PcdLoadModuleAtFixAddressEnable) != 0) {
//
// cache the Top address for loading modules at Fixed Address
//
}
//
// See if a Memory Type Information HOB is available
//
if (EfiMemoryTypeInformation != NULL && DataSize > 0 && DataSize <= (EfiMaxMemoryType + 1) * sizeof (EFI_MEMORY_TYPE_INFORMATION)) {
}
}
//
// Find the Resource Descriptor HOB that contains PHIT range EfiFreeMemoryBottom..EfiFreeMemoryTop
//
Length = 0;
//
// Skip all HOBs except Resource Descriptor HOBs
//
continue;
}
//
// Skip Resource Descriptor HOBs that do not describe tested system memory
//
continue;
}
continue;
}
//
// Skip Resource Descriptor HOBs that do not contain the PHIT range EfiFreeMemoryBottom..EfiFreeMemoryTop
//
continue;
}
continue;
}
//
// Cache the resource descriptor HOB for the memory region described by the PHIT HOB
//
//
// Compute range between PHIT EfiFreeMemoryTop and the end of the Resource Descriptor HOB
//
if (Length < MINIMUM_INITIAL_MEMORY_SIZE) {
//
// If that range is not large enough to intialize the DXE Core, then
// Compute range between PHIT EfiFreeMemoryBottom and PHIT EfiFreeMemoryTop
//
if (Length < MINIMUM_INITIAL_MEMORY_SIZE) {
//
// If that range is not large enough to intialize the DXE Core, then
// Compute range between the start of the Resource Descriptor HOB and the start of the HOB List
//
}
}
break;
}
//
// Assert if a resource descriptor HOB for the memory region described by the PHIT was not found
//
//
// Search all the resource descriptor HOBs from the highest possible addresses down for a memory
// region that is big enough to initialize the DXE core. Always skip the PHIT Resource HOB.
// The max address must be within the physically addressible range for the processor.
//
//
// Skip the Resource Descriptor HOB that contains the PHIT
//
continue;
}
//
// Skip all HOBs except Resource Descriptor HOBs
//
continue;
}
//
// Skip Resource Descriptor HOBs that do not describe tested system memory below MAX_ADDRESS
//
continue;
}
continue;
}
if ((ResourceHob->PhysicalStart + ResourceHob->ResourceLength) > (EFI_PHYSICAL_ADDRESS)MAX_ADDRESS) {
continue;
}
//
// Skip Resource Descriptor HOBs that are below a previously found Resource Descriptor HOB
//
if (HighAddress != (EFI_PHYSICAL_ADDRESS)MAX_ADDRESS && ResourceHob->PhysicalStart <= HighAddress) {
continue;
}
//
// Skip Resource Descriptor HOBs that are not large enough to initilize the DXE Core
//
TestedMemoryLength = PageAlignLength (ResourceHob->PhysicalStart + ResourceHob->ResourceLength - TestedMemoryBaseAddress);
continue;
}
//
// Save the Resource Descriptor HOB context that is large enough to initilize the DXE Core
//
}
//
// If Length is not large enough to initialize the DXE Core or a Resource
// Descriptor HOB was found above the PHIT HOB that is large enough to initialize
// the DXE Core, then use the range described by the Resource Descriptor
// HOB that was found above the PHIT HOB.
//
if ((Length < MINIMUM_INITIAL_MEMORY_SIZE) ||
}
//
// If no memory regions are found that are big enough to initialize the DXE core, then ASSERT().
//
//
// Convert the Resource HOB Attributes to an EFI Memory Capabilities mask
//
Capabilities = CoreConvertResourceDescriptorHobAttributesToCapabilities (EfiGcdMemoryTypeSystemMemory, Attributes);
//
// Declare the very first memory region, so the EFI Memory Services are available.
//
);
*MemoryLength = Length;
return EFI_SUCCESS;
}
/**
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.
@param HobStart The start address of the HOB
@param MemoryBaseAddress Start address of memory region found to init DXE
core.
@param MemoryLength Length of memory region found to init DXE core.
@retval EFI_SUCCESS GCD services successfully initialized.
**/
)
{
//
// Cache the PHIT HOB for later use
//
//
// Get the number of address lines in the I/O and Memory space for the CPU
//
//
// Initialize the GCD Memory Space Map
//
//
// Initialize the GCD I/O Space Map
//
//
// Walk the HOB list and add all resource descriptors to the GCD
//
switch (ResourceHob->ResourceType) {
}
}
}
break;
break;
break;
case EFI_RESOURCE_IO:
break;
case EFI_RESOURCE_IO_RESERVED:
break;
}
if (GcdMemoryType != EfiGcdMemoryTypeNonExistent) {
//
// Validate the Resource HOB Attributes
//
//
// Convert the Resource HOB Attributes to an EFI Memory Capabilities mask
//
);
);
}
if (GcdIoType != EfiGcdIoTypeNonExistent) {
Status = CoreAddIoSpace (
);
}
}
}
//
// Allocate first memory region from the GCD by the DXE core
//
0,
);
//
// Walk the HOB list and allocate all memory space that is consumed by memory allocation HOBs,
// and Firmware Volume HOBs. Also update the EFI Memory Map with the memory allocation HOBs.
//
0,
);
);
}
}
}
0,
);
}
}
//
// Relocate HOB List to an allocated pool buffer.
//
);
*HobStart = NewHobList;
//
// Add and allocate the remaining unallocated system memory to the memory services.
//
Length = PageAlignLength (MemorySpaceMap[Index].BaseAddress + MemorySpaceMap[Index].Length - BaseAddress);
if (Length == 0 || MemorySpaceMap[Index].BaseAddress + MemorySpaceMap[Index].Length < BaseAddress) {
continue;
}
);
0,
);
}
}
}
return EFI_SUCCESS;
}