diff options
Diffstat (limited to 'MdeModulePkg/Core/Dxe/Gcd')
-rw-r--r-- | MdeModulePkg/Core/Dxe/Gcd/Gcd.c | 998 | ||||
-rw-r--r-- | MdeModulePkg/Core/Dxe/Gcd/Gcd.h | 18 |
2 files changed, 543 insertions, 473 deletions
diff --git a/MdeModulePkg/Core/Dxe/Gcd/Gcd.c b/MdeModulePkg/Core/Dxe/Gcd/Gcd.c index 2224aae281..3763467bdb 100644 --- a/MdeModulePkg/Core/Dxe/Gcd/Gcd.c +++ b/MdeModulePkg/Core/Dxe/Gcd/Gcd.c @@ -12,9 +12,9 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #include "Gcd.h"
#include "Mem/HeapGuard.h"
-#define MINIMUM_INITIAL_MEMORY_SIZE 0x10000
+#define MINIMUM_INITIAL_MEMORY_SIZE 0x10000
-#define MEMORY_ATTRIBUTE_MASK (EFI_RESOURCE_ATTRIBUTE_PRESENT | \
+#define MEMORY_ATTRIBUTE_MASK (EFI_RESOURCE_ATTRIBUTE_PRESENT | \
EFI_RESOURCE_ATTRIBUTE_INITIALIZED | \
EFI_RESOURCE_ATTRIBUTE_TESTED | \
EFI_RESOURCE_ATTRIBUTE_READ_PROTECTED | \
@@ -26,24 +26,24 @@ SPDX-License-Identifier: BSD-2-Clause-Patent EFI_RESOURCE_ATTRIBUTE_64_BIT_IO | \
EFI_RESOURCE_ATTRIBUTE_PERSISTENT )
-#define TESTED_MEMORY_ATTRIBUTES (EFI_RESOURCE_ATTRIBUTE_PRESENT | \
+#define TESTED_MEMORY_ATTRIBUTES (EFI_RESOURCE_ATTRIBUTE_PRESENT | \
EFI_RESOURCE_ATTRIBUTE_INITIALIZED | \
EFI_RESOURCE_ATTRIBUTE_TESTED )
-#define INITIALIZED_MEMORY_ATTRIBUTES (EFI_RESOURCE_ATTRIBUTE_PRESENT | \
+#define INITIALIZED_MEMORY_ATTRIBUTES (EFI_RESOURCE_ATTRIBUTE_PRESENT |\
EFI_RESOURCE_ATTRIBUTE_INITIALIZED )
-#define PRESENT_MEMORY_ATTRIBUTES (EFI_RESOURCE_ATTRIBUTE_PRESENT)
+#define PRESENT_MEMORY_ATTRIBUTES (EFI_RESOURCE_ATTRIBUTE_PRESENT)
//
// Module 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_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 mGcdMemorySpaceMapEntryTemplate = {
EFI_GCD_MAP_SIGNATURE,
{
NULL,
@@ -54,12 +54,12 @@ EFI_GCD_MAP_ENTRY mGcdMemorySpaceMapEntryTemplate = { 0,
0,
EfiGcdMemoryTypeNonExistent,
- (EFI_GCD_IO_TYPE) 0,
+ (EFI_GCD_IO_TYPE)0,
NULL,
NULL
};
-EFI_GCD_MAP_ENTRY mGcdIoSpaceMapEntryTemplate = {
+EFI_GCD_MAP_ENTRY mGcdIoSpaceMapEntryTemplate = {
EFI_GCD_MAP_SIGNATURE,
{
NULL,
@@ -69,34 +69,34 @@ EFI_GCD_MAP_ENTRY mGcdIoSpaceMapEntryTemplate = { 0,
0,
0,
- (EFI_GCD_MEMORY_TYPE) 0,
+ (EFI_GCD_MEMORY_TYPE)0,
EfiGcdIoTypeNonExistent,
NULL,
NULL
};
-GCD_ATTRIBUTE_CONVERSION_ENTRY mAttributeConversionTable[] = {
- { 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 },
- { 0, 0, FALSE }
+GCD_ATTRIBUTE_CONVERSION_ENTRY mAttributeConversionTable[] = {
+ { 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 },
+ { 0, 0, FALSE }
};
///
/// Lookup table used to print GCD Memory Space Map
///
-GLOBAL_REMOVE_IF_UNREFERENCED CONST CHAR8 *mGcdMemoryTypeNames[] = {
+GLOBAL_REMOVE_IF_UNREFERENCED CONST CHAR8 *mGcdMemoryTypeNames[] = {
"NonExist ", // EfiGcdMemoryTypeNonExistent
"Reserved ", // EfiGcdMemoryTypeReserved
"SystemMem", // EfiGcdMemoryTypeSystemMemory
@@ -109,7 +109,7 @@ GLOBAL_REMOVE_IF_UNREFERENCED CONST CHAR8 *mGcdMemoryTypeNames[] = { ///
/// Lookup table used to print GCD I/O Space Map
///
-GLOBAL_REMOVE_IF_UNREFERENCED CONST CHAR8 *mGcdIoTypeNames[] = {
+GLOBAL_REMOVE_IF_UNREFERENCED CONST CHAR8 *mGcdIoTypeNames[] = {
"NonExist", // EfiGcdIoTypeNonExistent
"Reserved", // EfiGcdIoTypeReserved
"I/O ", // EfiGcdIoTypeIo
@@ -119,7 +119,7 @@ GLOBAL_REMOVE_IF_UNREFERENCED CONST CHAR8 *mGcdIoTypeNames[] = { ///
/// Lookup table used to print GCD Allocation Types
///
-GLOBAL_REMOVE_IF_UNREFERENCED CONST CHAR8 *mGcdAllocationTypeNames[] = {
+GLOBAL_REMOVE_IF_UNREFERENCED CONST CHAR8 *mGcdAllocationTypeNames[] = {
"AnySearchBottomUp ", // EfiGcdAllocateAnySearchBottomUp
"MaxAddressSearchBottomUp ", // EfiGcdAllocateMaxAddressSearchBottomUp
"AtAddress ", // EfiGcdAllocateAddress
@@ -141,33 +141,37 @@ CoreDumpGcdMemorySpaceMap ( BOOLEAN InitialMap
)
{
- DEBUG_CODE_BEGIN ();
- EFI_STATUS Status;
- UINTN NumberOfDescriptors;
- EFI_GCD_MEMORY_SPACE_DESCRIPTOR *MemorySpaceMap;
- UINTN Index;
+ DEBUG_CODE_BEGIN ();
+ EFI_STATUS Status;
+ UINTN NumberOfDescriptors;
+ EFI_GCD_MEMORY_SPACE_DESCRIPTOR *MemorySpaceMap;
+ UINTN Index;
- Status = CoreGetMemorySpaceMap (&NumberOfDescriptors, &MemorySpaceMap);
- ASSERT (Status == EFI_SUCCESS && MemorySpaceMap != NULL);
+ Status = CoreGetMemorySpaceMap (&NumberOfDescriptors, &MemorySpaceMap);
+ ASSERT (Status == EFI_SUCCESS && MemorySpaceMap != NULL);
- if (InitialMap) {
- DEBUG ((DEBUG_GCD, "GCD:Initial GCD Memory Space Map\n"));
- }
- DEBUG ((DEBUG_GCD, "GCDMemType Range Capabilities Attributes \n"));
- DEBUG ((DEBUG_GCD, "========== ================================= ================ ================\n"));
- for (Index = 0; Index < NumberOfDescriptors; Index++) {
- DEBUG ((DEBUG_GCD, "%a %016lx-%016lx %016lx %016lx%c\n",
- mGcdMemoryTypeNames[MIN (MemorySpaceMap[Index].GcdMemoryType, EfiGcdMemoryTypeMaximum)],
- MemorySpaceMap[Index].BaseAddress,
- MemorySpaceMap[Index].BaseAddress + MemorySpaceMap[Index].Length - 1,
- MemorySpaceMap[Index].Capabilities,
- MemorySpaceMap[Index].Attributes,
- MemorySpaceMap[Index].ImageHandle == NULL ? ' ' : '*'
- ));
- }
- DEBUG ((DEBUG_GCD, "\n"));
- FreePool (MemorySpaceMap);
- DEBUG_CODE_END ();
+ if (InitialMap) {
+ DEBUG ((DEBUG_GCD, "GCD:Initial GCD Memory Space Map\n"));
+ }
+
+ DEBUG ((DEBUG_GCD, "GCDMemType Range Capabilities Attributes \n"));
+ DEBUG ((DEBUG_GCD, "========== ================================= ================ ================\n"));
+ for (Index = 0; Index < NumberOfDescriptors; Index++) {
+ DEBUG ((
+ DEBUG_GCD,
+ "%a %016lx-%016lx %016lx %016lx%c\n",
+ mGcdMemoryTypeNames[MIN (MemorySpaceMap[Index].GcdMemoryType, EfiGcdMemoryTypeMaximum)],
+ MemorySpaceMap[Index].BaseAddress,
+ MemorySpaceMap[Index].BaseAddress + MemorySpaceMap[Index].Length - 1,
+ MemorySpaceMap[Index].Capabilities,
+ MemorySpaceMap[Index].Attributes,
+ MemorySpaceMap[Index].ImageHandle == NULL ? ' ' : '*'
+ ));
+ }
+
+ DEBUG ((DEBUG_GCD, "\n"));
+ FreePool (MemorySpaceMap);
+ DEBUG_CODE_END ();
}
/**
@@ -183,32 +187,35 @@ CoreDumpGcdIoSpaceMap ( BOOLEAN InitialMap
)
{
- DEBUG_CODE_BEGIN ();
- EFI_STATUS Status;
- UINTN NumberOfDescriptors;
- EFI_GCD_IO_SPACE_DESCRIPTOR *IoSpaceMap;
- UINTN Index;
+ DEBUG_CODE_BEGIN ();
+ EFI_STATUS Status;
+ UINTN NumberOfDescriptors;
+ EFI_GCD_IO_SPACE_DESCRIPTOR *IoSpaceMap;
+ UINTN Index;
- Status = CoreGetIoSpaceMap (&NumberOfDescriptors, &IoSpaceMap);
- ASSERT (Status == EFI_SUCCESS && IoSpaceMap != NULL);
+ Status = CoreGetIoSpaceMap (&NumberOfDescriptors, &IoSpaceMap);
+ ASSERT (Status == EFI_SUCCESS && IoSpaceMap != NULL);
- if (InitialMap) {
- DEBUG ((DEBUG_GCD, "GCD:Initial GCD I/O Space Map\n"));
- }
+ if (InitialMap) {
+ DEBUG ((DEBUG_GCD, "GCD:Initial GCD I/O Space Map\n"));
+ }
- DEBUG ((DEBUG_GCD, "GCDIoType Range \n"));
- DEBUG ((DEBUG_GCD, "========== =================================\n"));
- for (Index = 0; Index < NumberOfDescriptors; Index++) {
- DEBUG ((DEBUG_GCD, "%a %016lx-%016lx%c\n",
- mGcdIoTypeNames[MIN (IoSpaceMap[Index].GcdIoType, EfiGcdIoTypeMaximum)],
- IoSpaceMap[Index].BaseAddress,
- IoSpaceMap[Index].BaseAddress + IoSpaceMap[Index].Length - 1,
- IoSpaceMap[Index].ImageHandle == NULL ? ' ' : '*'
- ));
- }
- DEBUG ((DEBUG_GCD, "\n"));
- FreePool (IoSpaceMap);
- DEBUG_CODE_END ();
+ DEBUG ((DEBUG_GCD, "GCDIoType Range \n"));
+ DEBUG ((DEBUG_GCD, "========== =================================\n"));
+ for (Index = 0; Index < NumberOfDescriptors; Index++) {
+ DEBUG ((
+ DEBUG_GCD,
+ "%a %016lx-%016lx%c\n",
+ mGcdIoTypeNames[MIN (IoSpaceMap[Index].GcdIoType, EfiGcdIoTypeMaximum)],
+ IoSpaceMap[Index].BaseAddress,
+ IoSpaceMap[Index].BaseAddress + IoSpaceMap[Index].Length - 1,
+ IoSpaceMap[Index].ImageHandle == NULL ? ' ' : '*'
+ ));
+ }
+
+ DEBUG ((DEBUG_GCD, "\n"));
+ FreePool (IoSpaceMap);
+ DEBUG_CODE_END ();
}
/**
@@ -225,16 +232,26 @@ CoreValidateResourceDescriptorHobAttributes ( IN UINT64 Attributes
)
{
- ASSERT (((Attributes & EFI_RESOURCE_ATTRIBUTE_READ_PROTECTED) == 0) ||
- ((Attributes & EFI_RESOURCE_ATTRIBUTE_READ_PROTECTABLE) != 0));
- ASSERT (((Attributes & EFI_RESOURCE_ATTRIBUTE_WRITE_PROTECTED) == 0) ||
- ((Attributes & EFI_RESOURCE_ATTRIBUTE_WRITE_PROTECTABLE) != 0));
- ASSERT (((Attributes & EFI_RESOURCE_ATTRIBUTE_EXECUTION_PROTECTED) == 0) ||
- ((Attributes & EFI_RESOURCE_ATTRIBUTE_EXECUTION_PROTECTABLE) != 0));
- ASSERT (((Attributes & EFI_RESOURCE_ATTRIBUTE_READ_ONLY_PROTECTED) == 0) ||
- ((Attributes & EFI_RESOURCE_ATTRIBUTE_READ_ONLY_PROTECTABLE) != 0));
- ASSERT (((Attributes & EFI_RESOURCE_ATTRIBUTE_PERSISTENT) == 0) ||
- ((Attributes & EFI_RESOURCE_ATTRIBUTE_PERSISTABLE) != 0));
+ ASSERT (
+ ((Attributes & EFI_RESOURCE_ATTRIBUTE_READ_PROTECTED) == 0) ||
+ ((Attributes & EFI_RESOURCE_ATTRIBUTE_READ_PROTECTABLE) != 0)
+ );
+ ASSERT (
+ ((Attributes & EFI_RESOURCE_ATTRIBUTE_WRITE_PROTECTED) == 0) ||
+ ((Attributes & EFI_RESOURCE_ATTRIBUTE_WRITE_PROTECTABLE) != 0)
+ );
+ ASSERT (
+ ((Attributes & EFI_RESOURCE_ATTRIBUTE_EXECUTION_PROTECTED) == 0) ||
+ ((Attributes & EFI_RESOURCE_ATTRIBUTE_EXECUTION_PROTECTABLE) != 0)
+ );
+ ASSERT (
+ ((Attributes & EFI_RESOURCE_ATTRIBUTE_READ_ONLY_PROTECTED) == 0) ||
+ ((Attributes & EFI_RESOURCE_ATTRIBUTE_READ_ONLY_PROTECTABLE) != 0)
+ );
+ ASSERT (
+ ((Attributes & EFI_RESOURCE_ATTRIBUTE_PERSISTENT) == 0) ||
+ ((Attributes & EFI_RESOURCE_ATTRIBUTE_PERSISTABLE) != 0)
+ );
}
/**
@@ -249,8 +266,6 @@ CoreAcquireGcdMemoryLock ( CoreAcquireLock (&mGcdMemorySpaceLock);
}
-
-
/**
Release memory lock on mGcdMemorySpaceLock.
@@ -263,8 +278,6 @@ CoreReleaseGcdMemoryLock ( CoreReleaseLock (&mGcdMemorySpaceLock);
}
-
-
/**
Acquire memory lock on mGcdIoSpaceLock.
@@ -277,7 +290,6 @@ CoreAcquireGcdIoLock ( CoreAcquireLock (&mGcdIoSpaceLock);
}
-
/**
Release memory lock on mGcdIoSpaceLock.
@@ -290,11 +302,10 @@ CoreReleaseGcdIoLock ( CoreReleaseLock (&mGcdIoSpaceLock);
}
-
-
//
// GCD Initialization Worker Functions
//
+
/**
Aligns a value to the specified boundary.
@@ -320,10 +331,10 @@ AlignValue ( if (RoundUp) {
Value += AlignmentMask;
}
+
return Value & (~AlignmentMask);
}
-
/**
Aligns address to the page boundary.
@@ -334,13 +345,12 @@ AlignValue ( **/
UINT64
PageAlignAddress (
- IN UINT64 Value
+ IN UINT64 Value
)
{
return AlignValue (Value, EFI_PAGE_SHIFT, TRUE);
}
-
/**
Aligns length to the page boundary.
@@ -351,7 +361,7 @@ PageAlignAddress ( **/
UINT64
PageAlignLength (
- IN UINT64 Value
+ IN UINT64 Value
)
{
return AlignValue (Value, EFI_PAGE_SHIFT, FALSE);
@@ -383,15 +393,15 @@ CoreAllocateGcdMapEntry ( // cause problem when it's freed (if HeapGuard is enabled).
//
mOnGuarding = TRUE;
- *TopEntry = AllocateZeroPool (sizeof (EFI_GCD_MAP_ENTRY));
+ *TopEntry = AllocateZeroPool (sizeof (EFI_GCD_MAP_ENTRY));
mOnGuarding = FALSE;
if (*TopEntry == NULL) {
return EFI_OUT_OF_RESOURCES;
}
- mOnGuarding = TRUE;
+ mOnGuarding = TRUE;
*BottomEntry = AllocateZeroPool (sizeof (EFI_GCD_MAP_ENTRY));
- mOnGuarding = FALSE;
+ mOnGuarding = FALSE;
if (*BottomEntry == NULL) {
CoreFreePool (*TopEntry);
return EFI_OUT_OF_RESOURCES;
@@ -400,7 +410,6 @@ CoreAllocateGcdMapEntry ( return EFI_SUCCESS;
}
-
/**
Internal function. Inserts a new descriptor into a sorted list
@@ -417,7 +426,7 @@ CoreAllocateGcdMapEntry ( **/
EFI_STATUS
CoreInsertGcdMapEntry (
- IN LIST_ENTRY *Link,
+ IN LIST_ENTRY *Link,
IN EFI_GCD_MAP_ENTRY *Entry,
IN EFI_PHYSICAL_ADDRESS BaseAddress,
IN UINT64 Length,
@@ -448,7 +457,6 @@ CoreInsertGcdMapEntry ( return EFI_SUCCESS;
}
-
/**
Merge the Gcd region specified by Link and its adjacent entry.
@@ -463,9 +471,9 @@ CoreInsertGcdMapEntry ( **/
EFI_STATUS
CoreMergeGcdMapEntry (
- IN LIST_ENTRY *Link,
- IN BOOLEAN Forward,
- IN LIST_ENTRY *Map
+ IN LIST_ENTRY *Link,
+ IN BOOLEAN Forward,
+ IN LIST_ENTRY *Map
)
{
LIST_ENTRY *AdjacentLink;
@@ -494,34 +502,39 @@ CoreMergeGcdMapEntry ( if (Entry->Capabilities != AdjacentEntry->Capabilities) {
return EFI_UNSUPPORTED;
}
+
if (Entry->Attributes != AdjacentEntry->Attributes) {
return EFI_UNSUPPORTED;
}
+
if (Entry->GcdMemoryType != AdjacentEntry->GcdMemoryType) {
return EFI_UNSUPPORTED;
}
+
if (Entry->GcdIoType != AdjacentEntry->GcdIoType) {
return EFI_UNSUPPORTED;
}
+
if (Entry->ImageHandle != AdjacentEntry->ImageHandle) {
return EFI_UNSUPPORTED;
}
+
if (Entry->DeviceHandle != AdjacentEntry->DeviceHandle) {
return EFI_UNSUPPORTED;
}
if (Forward) {
- Entry->EndAddress = AdjacentEntry->EndAddress;
+ Entry->EndAddress = AdjacentEntry->EndAddress;
} else {
Entry->BaseAddress = AdjacentEntry->BaseAddress;
}
+
RemoveEntryList (AdjacentLink);
CoreFreePool (AdjacentEntry);
return EFI_SUCCESS;
}
-
/**
Merge adjacent entries on total chain.
@@ -548,6 +561,7 @@ CoreCleanupGcdMapEntry ( if (TopEntry->Signature == 0) {
CoreFreePool (TopEntry);
}
+
if (BottomEntry->Signature == 0) {
CoreFreePool (BottomEntry);
}
@@ -557,12 +571,12 @@ CoreCleanupGcdMapEntry ( CoreMergeGcdMapEntry (Link, FALSE, Map);
Link = Link->ForwardLink;
}
+
CoreMergeGcdMapEntry (EndLink, TRUE, Map);
return EFI_SUCCESS;
}
-
/**
Search a segment of memory space in GCD map. The result is a range of GCD entry list.
@@ -598,23 +612,25 @@ CoreSearchGcdMapEntry ( Link = Map->ForwardLink;
while (Link != Map) {
Entry = CR (Link, EFI_GCD_MAP_ENTRY, Link, EFI_GCD_MAP_SIGNATURE);
- if (BaseAddress >= Entry->BaseAddress && BaseAddress <= Entry->EndAddress) {
+ if ((BaseAddress >= Entry->BaseAddress) && (BaseAddress <= Entry->EndAddress)) {
*StartLink = Link;
}
+
if (*StartLink != NULL) {
- if ((BaseAddress + Length - 1) >= Entry->BaseAddress &&
- (BaseAddress + Length - 1) <= Entry->EndAddress ) {
+ if (((BaseAddress + Length - 1) >= Entry->BaseAddress) &&
+ ((BaseAddress + Length - 1) <= Entry->EndAddress))
+ {
*EndLink = Link;
return EFI_SUCCESS;
}
}
+
Link = Link->ForwardLink;
}
return EFI_NOT_FOUND;
}
-
/**
Count the amount of GCD map entries.
@@ -628,11 +644,11 @@ CoreCountGcdMapEntry ( IN LIST_ENTRY *Map
)
{
- UINTN Count;
- LIST_ENTRY *Link;
+ UINTN Count;
+ LIST_ENTRY *Link;
Count = 0;
- Link = Map->ForwardLink;
+ Link = Map->ForwardLink;
while (Link != Map) {
Count++;
Link = Link->ForwardLink;
@@ -641,8 +657,6 @@ CoreCountGcdMapEntry ( return Count;
}
-
-
/**
Return the memory attribute specified by Attributes
@@ -653,31 +667,30 @@ CoreCountGcdMapEntry ( **/
UINT64
ConverToCpuArchAttributes (
- UINT64 Attributes
+ UINT64 Attributes
)
{
- UINT64 CpuArchAttributes;
+ UINT64 CpuArchAttributes;
CpuArchAttributes = Attributes & EFI_MEMORY_ATTRIBUTE_MASK;
- if ( (Attributes & EFI_MEMORY_UC) == EFI_MEMORY_UC) {
+ if ((Attributes & EFI_MEMORY_UC) == EFI_MEMORY_UC) {
CpuArchAttributes |= EFI_MEMORY_UC;
- } else if ( (Attributes & EFI_MEMORY_WC ) == EFI_MEMORY_WC) {
+ } else if ((Attributes & EFI_MEMORY_WC) == EFI_MEMORY_WC) {
CpuArchAttributes |= EFI_MEMORY_WC;
- } else if ( (Attributes & EFI_MEMORY_WT ) == EFI_MEMORY_WT) {
+ } else if ((Attributes & EFI_MEMORY_WT) == EFI_MEMORY_WT) {
CpuArchAttributes |= EFI_MEMORY_WT;
- } else if ( (Attributes & EFI_MEMORY_WB) == EFI_MEMORY_WB) {
+ } else if ((Attributes & EFI_MEMORY_WB) == EFI_MEMORY_WB) {
CpuArchAttributes |= EFI_MEMORY_WB;
- } else if ( (Attributes & EFI_MEMORY_UCE) == EFI_MEMORY_UCE) {
+ } else if ((Attributes & EFI_MEMORY_UCE) == EFI_MEMORY_UCE) {
CpuArchAttributes |= EFI_MEMORY_UCE;
- } else if ( (Attributes & EFI_MEMORY_WP) == EFI_MEMORY_WP) {
+ } else if ((Attributes & EFI_MEMORY_WP) == EFI_MEMORY_WP) {
CpuArchAttributes |= EFI_MEMORY_WP;
}
return CpuArchAttributes;
}
-
/**
Do operation on a segment of memory space specified (add, free, remove, change attribute ...).
@@ -748,6 +761,7 @@ CoreConvertSpace ( goto Done;
}
+
ASSERT (StartLink != NULL && EndLink != NULL);
//
@@ -757,89 +771,103 @@ CoreConvertSpace ( while (Link != EndLink->ForwardLink) {
Entry = CR (Link, EFI_GCD_MAP_ENTRY, Link, EFI_GCD_MAP_SIGNATURE);
switch (Operation) {
- //
- // Add operations
- //
- case GCD_ADD_MEMORY_OPERATION:
- if (Entry->GcdMemoryType != EfiGcdMemoryTypeNonExistent ||
- Entry->ImageHandle != NULL ) {
- Status = EFI_ACCESS_DENIED;
- goto Done;
- }
- break;
- case GCD_ADD_IO_OPERATION:
- if (Entry->GcdIoType != EfiGcdIoTypeNonExistent ||
- Entry->ImageHandle != NULL ) {
- Status = EFI_ACCESS_DENIED;
- goto Done;
- }
- break;
- //
- // Free operations
- //
- case GCD_FREE_MEMORY_OPERATION:
- case GCD_FREE_IO_OPERATION:
- if (Entry->ImageHandle == NULL) {
- Status = EFI_NOT_FOUND;
- goto Done;
- }
- break;
- //
- // Remove operations
- //
- case GCD_REMOVE_MEMORY_OPERATION:
- if (Entry->GcdMemoryType == EfiGcdMemoryTypeNonExistent) {
- Status = EFI_NOT_FOUND;
- goto Done;
- }
- if (Entry->ImageHandle != NULL) {
- Status = EFI_ACCESS_DENIED;
- goto Done;
- }
- break;
- case GCD_REMOVE_IO_OPERATION:
- if (Entry->GcdIoType == EfiGcdIoTypeNonExistent) {
- Status = EFI_NOT_FOUND;
- goto Done;
- }
- if (Entry->ImageHandle != NULL) {
- Status = EFI_ACCESS_DENIED;
- goto Done;
- }
- break;
- //
- // Set attributes operation
- //
- case GCD_SET_ATTRIBUTES_MEMORY_OPERATION:
- if ((Attributes & EFI_MEMORY_RUNTIME) != 0) {
- if ((BaseAddress & EFI_PAGE_MASK) != 0 || (Length & EFI_PAGE_MASK) != 0) {
- Status = EFI_INVALID_PARAMETER;
+ //
+ // Add operations
+ //
+ case GCD_ADD_MEMORY_OPERATION:
+ if ((Entry->GcdMemoryType != EfiGcdMemoryTypeNonExistent) ||
+ (Entry->ImageHandle != NULL))
+ {
+ Status = EFI_ACCESS_DENIED;
goto Done;
}
- }
- if ((Entry->Capabilities & Attributes) != Attributes) {
- Status = EFI_UNSUPPORTED;
- goto Done;
- }
- break;
- //
- // Set capabilities operation
- //
- case GCD_SET_CAPABILITIES_MEMORY_OPERATION:
- if ((BaseAddress & EFI_PAGE_MASK) != 0 || (Length & EFI_PAGE_MASK) != 0) {
- Status = EFI_INVALID_PARAMETER;
- goto Done;
- }
+ break;
+ case GCD_ADD_IO_OPERATION:
+ if ((Entry->GcdIoType != EfiGcdIoTypeNonExistent) ||
+ (Entry->ImageHandle != NULL))
+ {
+ Status = EFI_ACCESS_DENIED;
+ goto Done;
+ }
+
+ break;
//
- // Current attributes must still be supported with new capabilities
+ // Free operations
//
- if ((Capabilities & Entry->Attributes) != Entry->Attributes) {
- Status = EFI_UNSUPPORTED;
- goto Done;
- }
- break;
+ case GCD_FREE_MEMORY_OPERATION:
+ case GCD_FREE_IO_OPERATION:
+ if (Entry->ImageHandle == NULL) {
+ Status = EFI_NOT_FOUND;
+ goto Done;
+ }
+
+ break;
+ //
+ // Remove operations
+ //
+ case GCD_REMOVE_MEMORY_OPERATION:
+ if (Entry->GcdMemoryType == EfiGcdMemoryTypeNonExistent) {
+ Status = EFI_NOT_FOUND;
+ goto Done;
+ }
+
+ if (Entry->ImageHandle != NULL) {
+ Status = EFI_ACCESS_DENIED;
+ goto Done;
+ }
+
+ break;
+ case GCD_REMOVE_IO_OPERATION:
+ if (Entry->GcdIoType == EfiGcdIoTypeNonExistent) {
+ Status = EFI_NOT_FOUND;
+ goto Done;
+ }
+
+ if (Entry->ImageHandle != NULL) {
+ Status = EFI_ACCESS_DENIED;
+ goto Done;
+ }
+
+ break;
+ //
+ // Set attributes operation
+ //
+ case GCD_SET_ATTRIBUTES_MEMORY_OPERATION:
+ if ((Attributes & EFI_MEMORY_RUNTIME) != 0) {
+ if (((BaseAddress & EFI_PAGE_MASK) != 0) || ((Length & EFI_PAGE_MASK) != 0)) {
+ Status = EFI_INVALID_PARAMETER;
+ goto Done;
+ }
+ }
+
+ if ((Entry->Capabilities & Attributes) != Attributes) {
+ Status = EFI_UNSUPPORTED;
+ goto Done;
+ }
+
+ break;
+ //
+ // Set capabilities operation
+ //
+ case GCD_SET_CAPABILITIES_MEMORY_OPERATION:
+ if (((BaseAddress & EFI_PAGE_MASK) != 0) || ((Length & EFI_PAGE_MASK) != 0)) {
+ Status = EFI_INVALID_PARAMETER;
+
+ goto Done;
+ }
+
+ //
+ // Current attributes must still be supported with new capabilities
+ //
+ if ((Capabilities & Entry->Attributes) != Entry->Attributes) {
+ Status = EFI_UNSUPPORTED;
+ goto Done;
+ }
+
+ break;
}
+
Link = Link->ForwardLink;
}
@@ -851,6 +879,7 @@ CoreConvertSpace ( Status = EFI_OUT_OF_RESOURCES;
goto Done;
}
+
ASSERT (TopEntry != NULL && BottomEntry != NULL);
//
@@ -887,6 +916,7 @@ CoreConvertSpace ( CpuArchAttributes
);
}
+
if (EFI_ERROR (Status)) {
CoreFreePool (TopEntry);
CoreFreePool (BottomEntry);
@@ -903,58 +933,61 @@ CoreConvertSpace ( Entry = CR (Link, EFI_GCD_MAP_ENTRY, Link, EFI_GCD_MAP_SIGNATURE);
CoreInsertGcdMapEntry (Link, Entry, BaseAddress, Length, TopEntry, BottomEntry);
switch (Operation) {
- //
- // Add operations
- //
- case GCD_ADD_MEMORY_OPERATION:
- Entry->GcdMemoryType = GcdMemoryType;
- if (GcdMemoryType == EfiGcdMemoryTypeMemoryMappedIo) {
- Entry->Capabilities = Capabilities | EFI_MEMORY_RUNTIME | EFI_MEMORY_PORT_IO;
- } else {
- Entry->Capabilities = Capabilities | EFI_MEMORY_RUNTIME;
- }
- break;
- case GCD_ADD_IO_OPERATION:
- Entry->GcdIoType = GcdIoType;
- break;
- //
- // Free operations
- //
- case GCD_FREE_MEMORY_OPERATION:
- case GCD_FREE_IO_OPERATION:
- Entry->ImageHandle = NULL;
- Entry->DeviceHandle = NULL;
- break;
- //
- // Remove operations
- //
- case GCD_REMOVE_MEMORY_OPERATION:
- Entry->GcdMemoryType = EfiGcdMemoryTypeNonExistent;
- Entry->Capabilities = 0;
- break;
- case GCD_REMOVE_IO_OPERATION:
- Entry->GcdIoType = EfiGcdIoTypeNonExistent;
- break;
- //
- // Set attributes operation
- //
- case GCD_SET_ATTRIBUTES_MEMORY_OPERATION:
- if (CpuArchAttributes == 0) {
- //
- // Keep original CPU arch attributes when caller just calls
- // SetMemorySpaceAttributes() with none CPU arch attributes (for example, RUNTIME).
- //
- Attributes |= (Entry->Attributes & (EFI_CACHE_ATTRIBUTE_MASK | EFI_MEMORY_ATTRIBUTE_MASK));
- }
- Entry->Attributes = Attributes;
- break;
- //
- // Set capabilities operation
- //
- case GCD_SET_CAPABILITIES_MEMORY_OPERATION:
- Entry->Capabilities = Capabilities;
- break;
+ //
+ // Add operations
+ //
+ case GCD_ADD_MEMORY_OPERATION:
+ Entry->GcdMemoryType = GcdMemoryType;
+ if (GcdMemoryType == EfiGcdMemoryTypeMemoryMappedIo) {
+ Entry->Capabilities = Capabilities | EFI_MEMORY_RUNTIME | EFI_MEMORY_PORT_IO;
+ } else {
+ Entry->Capabilities = Capabilities | EFI_MEMORY_RUNTIME;
+ }
+
+ break;
+ case GCD_ADD_IO_OPERATION:
+ Entry->GcdIoType = GcdIoType;
+ break;
+ //
+ // Free operations
+ //
+ case GCD_FREE_MEMORY_OPERATION:
+ case GCD_FREE_IO_OPERATION:
+ Entry->ImageHandle = NULL;
+ Entry->DeviceHandle = NULL;
+ break;
+ //
+ // Remove operations
+ //
+ case GCD_REMOVE_MEMORY_OPERATION:
+ Entry->GcdMemoryType = EfiGcdMemoryTypeNonExistent;
+ Entry->Capabilities = 0;
+ break;
+ case GCD_REMOVE_IO_OPERATION:
+ Entry->GcdIoType = EfiGcdIoTypeNonExistent;
+ break;
+ //
+ // Set attributes operation
+ //
+ case GCD_SET_ATTRIBUTES_MEMORY_OPERATION:
+ if (CpuArchAttributes == 0) {
+ //
+ // Keep original CPU arch attributes when caller just calls
+ // SetMemorySpaceAttributes() with none CPU arch attributes (for example, RUNTIME).
+ //
+ Attributes |= (Entry->Attributes & (EFI_CACHE_ATTRIBUTE_MASK | EFI_MEMORY_ATTRIBUTE_MASK));
+ }
+
+ Entry->Attributes = Attributes;
+ break;
+ //
+ // Set capabilities operation
+ //
+ case GCD_SET_CAPABILITIES_MEMORY_OPERATION:
+ Entry->Capabilities = Capabilities;
+ break;
}
+
Link = Link->ForwardLink;
}
@@ -970,6 +1003,7 @@ Done: CoreReleaseGcdMemoryLock ();
CoreDumpGcdMemorySpaceMap (FALSE);
}
+
if ((Operation & GCD_IO_SPACE_OPERATION) != 0) {
CoreReleaseGcdIoLock ();
CoreDumpGcdIoSpaceMap (FALSE);
@@ -978,7 +1012,6 @@ Done: return Status;
}
-
/**
Check whether an entry could be used to allocate space.
@@ -1005,24 +1038,27 @@ CoreAllocateSpaceCheckEntry ( if (Entry->ImageHandle != NULL) {
return EFI_NOT_FOUND;
}
+
switch (Operation) {
- case GCD_ALLOCATE_MEMORY_OPERATION:
- if (Entry->GcdMemoryType != GcdMemoryType) {
- return EFI_NOT_FOUND;
- }
- break;
- case GCD_ALLOCATE_IO_OPERATION:
- if (Entry->GcdIoType != GcdIoType) {
- return EFI_NOT_FOUND;
- }
- break;
- default:
- return EFI_UNSUPPORTED;
+ case GCD_ALLOCATE_MEMORY_OPERATION:
+ if (Entry->GcdMemoryType != GcdMemoryType) {
+ return EFI_NOT_FOUND;
+ }
+
+ break;
+ case GCD_ALLOCATE_IO_OPERATION:
+ if (Entry->GcdIoType != GcdIoType) {
+ return EFI_NOT_FOUND;
+ }
+
+ break;
+ default:
+ return EFI_UNSUPPORTED;
}
+
return EFI_SUCCESS;
}
-
/**
Allocate space on specified address and length.
@@ -1074,26 +1110,32 @@ CoreAllocateSpace ( DEBUG ((DEBUG_GCD, " Status = %r\n", EFI_INVALID_PARAMETER));
return EFI_INVALID_PARAMETER;
}
+
if ((UINT32)GcdMemoryType >= EfiGcdMemoryTypeMaximum) {
DEBUG ((DEBUG_GCD, " Status = %r\n", EFI_INVALID_PARAMETER));
return EFI_INVALID_PARAMETER;
}
+
if ((UINT32)GcdIoType >= EfiGcdIoTypeMaximum) {
DEBUG ((DEBUG_GCD, " Status = %r\n", EFI_INVALID_PARAMETER));
return EFI_INVALID_PARAMETER;
}
+
if (BaseAddress == NULL) {
DEBUG ((DEBUG_GCD, " Status = %r\n", EFI_INVALID_PARAMETER));
return EFI_INVALID_PARAMETER;
}
+
if (ImageHandle == NULL) {
DEBUG ((DEBUG_GCD, " Status = %r\n", EFI_INVALID_PARAMETER));
return EFI_INVALID_PARAMETER;
}
+
if (Alignment >= 64) {
DEBUG ((DEBUG_GCD, " Status = %r\n", EFI_NOT_FOUND));
return EFI_NOT_FOUND;
}
+
if (Length == 0) {
DEBUG ((DEBUG_GCD, " Status = %r\n", EFI_INVALID_PARAMETER));
return EFI_INVALID_PARAMETER;
@@ -1135,6 +1177,7 @@ CoreAllocateSpace ( Status = EFI_NOT_FOUND;
goto Done;
}
+
ASSERT (StartLink != NULL && EndLink != NULL);
//
@@ -1142,23 +1185,24 @@ CoreAllocateSpace ( //
Link = StartLink;
while (Link != EndLink->ForwardLink) {
- Entry = CR (Link, EFI_GCD_MAP_ENTRY, Link, EFI_GCD_MAP_SIGNATURE);
- Link = Link->ForwardLink;
+ Entry = CR (Link, EFI_GCD_MAP_ENTRY, Link, EFI_GCD_MAP_SIGNATURE);
+ Link = Link->ForwardLink;
Status = CoreAllocateSpaceCheckEntry (Operation, Entry, GcdMemoryType, GcdIoType);
if (EFI_ERROR (Status)) {
goto Done;
}
}
+
Found = TRUE;
} else {
-
Entry = CR (Map->BackLink, EFI_GCD_MAP_ENTRY, Link, EFI_GCD_MAP_SIGNATURE);
//
// Compute the maximum address to use in the search algorithm
//
- if (GcdAllocateType == EfiGcdAllocateMaxAddressSearchBottomUp ||
- GcdAllocateType == EfiGcdAllocateMaxAddressSearchTopDown ) {
+ if ((GcdAllocateType == EfiGcdAllocateMaxAddressSearchBottomUp) ||
+ (GcdAllocateType == EfiGcdAllocateMaxAddressSearchTopDown))
+ {
MaxAddress = *BaseAddress;
} else {
MaxAddress = Entry->EndAddress;
@@ -1167,17 +1211,20 @@ CoreAllocateSpace ( //
// Verify that the list of descriptors are unallocated memory matching GcdMemoryType.
//
- if (GcdAllocateType == EfiGcdAllocateMaxAddressSearchTopDown ||
- GcdAllocateType == EfiGcdAllocateAnySearchTopDown ) {
+ if ((GcdAllocateType == EfiGcdAllocateMaxAddressSearchTopDown) ||
+ (GcdAllocateType == EfiGcdAllocateAnySearchTopDown))
+ {
Link = Map->BackLink;
} else {
Link = Map->ForwardLink;
}
+
while (Link != Map) {
Entry = CR (Link, EFI_GCD_MAP_ENTRY, Link, EFI_GCD_MAP_SIGNATURE);
- if (GcdAllocateType == EfiGcdAllocateMaxAddressSearchTopDown ||
- GcdAllocateType == EfiGcdAllocateAnySearchTopDown ) {
+ if ((GcdAllocateType == EfiGcdAllocateMaxAddressSearchTopDown) ||
+ (GcdAllocateType == EfiGcdAllocateAnySearchTopDown))
+ {
Link = Link->BackLink;
} else {
Link = Link->ForwardLink;
@@ -1188,20 +1235,24 @@ CoreAllocateSpace ( continue;
}
- if (GcdAllocateType == EfiGcdAllocateMaxAddressSearchTopDown ||
- GcdAllocateType == EfiGcdAllocateAnySearchTopDown) {
+ if ((GcdAllocateType == EfiGcdAllocateMaxAddressSearchTopDown) ||
+ (GcdAllocateType == EfiGcdAllocateAnySearchTopDown))
+ {
if ((Entry->BaseAddress + Length) > MaxAddress) {
continue;
}
+
if (Length > (Entry->EndAddress + 1)) {
Status = EFI_NOT_FOUND;
goto Done;
}
+
if (Entry->EndAddress > MaxAddress) {
*BaseAddress = MaxAddress;
} else {
*BaseAddress = Entry->EndAddress;
}
+
*BaseAddress = (*BaseAddress + 1 - Length) & (~AlignmentMask);
} else {
*BaseAddress = (Entry->BaseAddress + AlignmentMask) & (~AlignmentMask);
@@ -1219,29 +1270,33 @@ CoreAllocateSpace ( Status = EFI_NOT_FOUND;
goto Done;
}
+
ASSERT (StartLink != NULL && EndLink != NULL);
Link = StartLink;
//
// Verify that the list of descriptors are unallocated memory matching GcdMemoryType.
//
- Found = TRUE;
+ Found = TRUE;
SubLink = StartLink;
while (SubLink != EndLink->ForwardLink) {
- Entry = CR (SubLink, EFI_GCD_MAP_ENTRY, Link, EFI_GCD_MAP_SIGNATURE);
+ Entry = CR (SubLink, EFI_GCD_MAP_ENTRY, Link, EFI_GCD_MAP_SIGNATURE);
Status = CoreAllocateSpaceCheckEntry (Operation, Entry, GcdMemoryType, GcdIoType);
if (EFI_ERROR (Status)) {
- Link = SubLink;
+ Link = SubLink;
Found = FALSE;
break;
}
+
SubLink = SubLink->ForwardLink;
}
+
if (Found) {
break;
}
}
}
+
if (!Found) {
Status = EFI_NOT_FOUND;
goto Done;
@@ -1255,6 +1310,7 @@ CoreAllocateSpace ( Status = EFI_OUT_OF_RESOURCES;
goto Done;
}
+
ASSERT (TopEntry != NULL && BottomEntry != NULL);
//
@@ -1266,7 +1322,7 @@ CoreAllocateSpace ( CoreInsertGcdMapEntry (Link, Entry, *BaseAddress, Length, TopEntry, BottomEntry);
Entry->ImageHandle = ImageHandle;
Entry->DeviceHandle = DeviceHandle;
- Link = Link->ForwardLink;
+ Link = Link->ForwardLink;
}
//
@@ -1279,13 +1335,15 @@ Done: if (!EFI_ERROR (Status)) {
DEBUG ((DEBUG_GCD, " (BaseAddress = %016lx)", *BaseAddress));
}
+
DEBUG ((DEBUG_GCD, "\n"));
if ((Operation & GCD_MEMORY_SPACE_OPERATION) != 0) {
CoreReleaseGcdMemoryLock ();
CoreDumpGcdMemorySpaceMap (FALSE);
}
- if ((Operation & GCD_IO_SPACE_OPERATION) !=0) {
+
+ if ((Operation & GCD_IO_SPACE_OPERATION) != 0) {
CoreReleaseGcdIoLock ();
CoreDumpGcdIoSpaceMap (FALSE);
}
@@ -1293,7 +1351,6 @@ Done: return Status;
}
-
/**
Add a segment of memory to GCD map.
@@ -1321,11 +1378,11 @@ CoreInternalAddMemorySpace ( //
// Make sure parameters are valid
//
- if (GcdMemoryType <= EfiGcdMemoryTypeNonExistent || GcdMemoryType >= EfiGcdMemoryTypeMaximum) {
+ if ((GcdMemoryType <= EfiGcdMemoryTypeNonExistent) || (GcdMemoryType >= EfiGcdMemoryTypeMaximum)) {
return EFI_INVALID_PARAMETER;
}
- return CoreConvertSpace (GCD_ADD_MEMORY_OPERATION, GcdMemoryType, (EFI_GCD_IO_TYPE) 0, BaseAddress, Length, Capabilities, 0);
+ return CoreConvertSpace (GCD_ADD_MEMORY_OPERATION, GcdMemoryType, (EFI_GCD_IO_TYPE)0, BaseAddress, Length, Capabilities, 0);
}
//
@@ -1366,6 +1423,7 @@ CoreAllocateMemorySpace ( } else {
DEBUG ((DEBUG_GCD, "GCD:AllocateMemorySpace(Base=<NULL>,Length=%016lx)\n", Length));
}
+
DEBUG ((DEBUG_GCD, " GcdAllocateType = %a\n", mGcdAllocationTypeNames[MIN (GcdAllocateType, EfiGcdMaxAllocateType)]));
DEBUG ((DEBUG_GCD, " GcdMemoryType = %a\n", mGcdMemoryTypeNames[MIN (GcdMemoryType, EfiGcdMemoryTypeMaximum)]));
DEBUG ((DEBUG_GCD, " Alignment = %016lx\n", LShiftU64 (1, Alignment)));
@@ -1376,7 +1434,7 @@ CoreAllocateMemorySpace ( GCD_ALLOCATE_MEMORY_OPERATION,
GcdAllocateType,
GcdMemoryType,
- (EFI_GCD_IO_TYPE) 0,
+ (EFI_GCD_IO_TYPE)0,
Alignment,
Length,
BaseAddress,
@@ -1385,7 +1443,6 @@ CoreAllocateMemorySpace ( );
}
-
/**
Adds reserved memory, system memory, or memory-mapped I/O resources to the
global coherency domain of the processor.
@@ -1414,7 +1471,6 @@ CoreAddMemorySpace ( Status = CoreInternalAddMemorySpace (GcdMemoryType, BaseAddress, Length, Capabilities);
if (!EFI_ERROR (Status) && ((GcdMemoryType == EfiGcdMemoryTypeSystemMemory) || (GcdMemoryType == EfiGcdMemoryTypeMoreReliable))) {
-
PageBaseAddress = PageAlignAddress (BaseAddress);
PageLength = PageAlignLength (BaseAddress + Length - PageBaseAddress);
@@ -1436,7 +1492,7 @@ CoreAddMemorySpace ( Capabilities
);
} else {
- for (; PageLength != 0; PageLength -= EFI_PAGE_SIZE, PageBaseAddress += EFI_PAGE_SIZE) {
+ for ( ; PageLength != 0; PageLength -= EFI_PAGE_SIZE, PageBaseAddress += EFI_PAGE_SIZE) {
Status = CoreAllocateMemorySpace (
EfiGcdAllocateAddress,
GcdMemoryType,
@@ -1458,10 +1514,10 @@ CoreAddMemorySpace ( }
}
}
+
return Status;
}
-
/**
Frees nonexistent memory, reserved memory, system memory, or memory-mapped
I/O resources from the global coherency domain of the processor.
@@ -1481,10 +1537,9 @@ CoreFreeMemorySpace ( {
DEBUG ((DEBUG_GCD, "GCD:FreeMemorySpace(Base=%016lx,Length=%016lx)\n", BaseAddress, Length));
- return CoreConvertSpace (GCD_FREE_MEMORY_OPERATION, (EFI_GCD_MEMORY_TYPE) 0, (EFI_GCD_IO_TYPE) 0, BaseAddress, Length, 0, 0);
+ 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.
@@ -1504,10 +1559,9 @@ CoreRemoveMemorySpace ( {
DEBUG ((DEBUG_GCD, "GCD:RemoveMemorySpace(Base=%016lx,Length=%016lx)\n", BaseAddress, Length));
- return CoreConvertSpace (GCD_REMOVE_MEMORY_OPERATION, (EFI_GCD_MEMORY_TYPE) 0, (EFI_GCD_IO_TYPE) 0, BaseAddress, Length, 0, 0);
+ 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.
@@ -1518,7 +1572,7 @@ CoreRemoveMemorySpace ( VOID
BuildMemoryDescriptor (
IN OUT EFI_GCD_MEMORY_SPACE_DESCRIPTOR *Descriptor,
- IN EFI_GCD_MAP_ENTRY *Entry
+ IN EFI_GCD_MAP_ENTRY *Entry
)
{
Descriptor->BaseAddress = Entry->BaseAddress;
@@ -1530,7 +1584,6 @@ BuildMemoryDescriptor ( Descriptor->DeviceHandle = Entry->DeviceHandle;
}
-
/**
Retrieves the descriptor for a memory region containing a specified address.
@@ -1582,7 +1635,6 @@ CoreGetMemorySpaceDescriptor ( return Status;
}
-
/**
Modifies the attributes for a memory region in the global coherency domain of the
processor.
@@ -1616,10 +1668,9 @@ CoreSetMemorySpaceAttributes ( DEBUG ((DEBUG_GCD, "GCD:SetMemorySpaceAttributes(Base=%016lx,Length=%016lx)\n", BaseAddress, Length));
DEBUG ((DEBUG_GCD, " Attributes = %016lx\n", Attributes));
- return CoreConvertSpace (GCD_SET_ATTRIBUTES_MEMORY_OPERATION, (EFI_GCD_MEMORY_TYPE) 0, (EFI_GCD_IO_TYPE) 0, BaseAddress, Length, 0, Attributes);
+ return CoreConvertSpace (GCD_SET_ATTRIBUTES_MEMORY_OPERATION, (EFI_GCD_MEMORY_TYPE)0, (EFI_GCD_IO_TYPE)0, BaseAddress, Length, 0, Attributes);
}
-
/**
Modifies the capabilities for a memory region in the global coherency domain of the
processor.
@@ -1645,20 +1696,19 @@ CoreSetMemorySpaceCapabilities ( IN UINT64 Capabilities
)
{
- EFI_STATUS Status;
+ EFI_STATUS Status;
DEBUG ((DEBUG_GCD, "GCD:CoreSetMemorySpaceCapabilities(Base=%016lx,Length=%016lx)\n", BaseAddress, Length));
DEBUG ((DEBUG_GCD, " Capabilities = %016lx\n", Capabilities));
- Status = CoreConvertSpace (GCD_SET_CAPABILITIES_MEMORY_OPERATION, (EFI_GCD_MEMORY_TYPE) 0, (EFI_GCD_IO_TYPE) 0, BaseAddress, Length, Capabilities, 0);
- if (!EFI_ERROR(Status)) {
- CoreUpdateMemoryAttributes(BaseAddress, RShiftU64(Length, EFI_PAGE_SHIFT), Capabilities & (~EFI_MEMORY_RUNTIME));
+ Status = CoreConvertSpace (GCD_SET_CAPABILITIES_MEMORY_OPERATION, (EFI_GCD_MEMORY_TYPE)0, (EFI_GCD_IO_TYPE)0, BaseAddress, Length, Capabilities, 0);
+ if (!EFI_ERROR (Status)) {
+ CoreUpdateMemoryAttributes (BaseAddress, RShiftU64 (Length, EFI_PAGE_SHIFT), Capabilities & (~EFI_MEMORY_RUNTIME));
}
return Status;
}
-
/**
Returns a map of the memory resources in the global coherency domain of the
processor.
@@ -1689,12 +1739,13 @@ CoreGetMemorySpaceMap ( if (NumberOfDescriptors == NULL) {
return EFI_INVALID_PARAMETER;
}
+
if (MemorySpaceMap == NULL) {
return EFI_INVALID_PARAMETER;
}
- *NumberOfDescriptors = 0;
- *MemorySpaceMap = NULL;
+ *NumberOfDescriptors = 0;
+ *MemorySpaceMap = NULL;
//
// Take the lock, for entering the loop with the lock held.
@@ -1706,18 +1757,19 @@ CoreGetMemorySpaceMap ( // AllocatePool() called below has to be running outside the GCD lock.
//
DescriptorCount = CoreCountGcdMapEntry (&mGcdMemorySpaceMap);
- if (DescriptorCount == *NumberOfDescriptors && *MemorySpaceMap != NULL) {
+ if ((DescriptorCount == *NumberOfDescriptors) && (*MemorySpaceMap != NULL)) {
//
// Fill in the MemorySpaceMap if no memory space map change.
//
Descriptor = *MemorySpaceMap;
- Link = mGcdMemorySpaceMap.ForwardLink;
+ Link = mGcdMemorySpaceMap.ForwardLink;
while (Link != &mGcdMemorySpaceMap) {
Entry = CR (Link, EFI_GCD_MAP_ENTRY, Link, EFI_GCD_MAP_SIGNATURE);
BuildMemoryDescriptor (Descriptor, Entry);
Descriptor++;
Link = Link->ForwardLink;
}
+
//
// We're done; exit the loop with the lock held.
//
@@ -1739,8 +1791,10 @@ CoreGetMemorySpaceMap ( FreePool (*MemorySpaceMap);
}
- *MemorySpaceMap = AllocatePool (DescriptorCount *
- sizeof (EFI_GCD_MEMORY_SPACE_DESCRIPTOR));
+ *MemorySpaceMap = AllocatePool (
+ DescriptorCount *
+ sizeof (EFI_GCD_MEMORY_SPACE_DESCRIPTOR)
+ );
if (*MemorySpaceMap == NULL) {
*NumberOfDescriptors = 0;
return EFI_OUT_OF_RESOURCES;
@@ -1756,6 +1810,7 @@ CoreGetMemorySpaceMap ( //
CoreAcquireGcdMemoryLock ();
}
+
//
// We exited the loop with the lock held, release it.
//
@@ -1764,7 +1819,6 @@ CoreGetMemorySpaceMap ( return EFI_SUCCESS;
}
-
/**
Adds reserved I/O or I/O resources to the global coherency domain of the processor.
@@ -1790,12 +1844,12 @@ CoreAddIoSpace ( //
// Make sure parameters are valid
//
- if (GcdIoType <= EfiGcdIoTypeNonExistent || GcdIoType >= EfiGcdIoTypeMaximum) {
+ if ((GcdIoType <= EfiGcdIoTypeNonExistent) || (GcdIoType >= EfiGcdIoTypeMaximum)) {
return EFI_INVALID_PARAMETER;
}
- return CoreConvertSpace (GCD_ADD_IO_OPERATION, (EFI_GCD_MEMORY_TYPE) 0, GcdIoType, BaseAddress, Length, 0, 0);
-}
+ 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
@@ -1831,6 +1885,7 @@ CoreAllocateIoSpace ( } else {
DEBUG ((DEBUG_GCD, "GCD:AllocateIoSpace(Base=<NULL>,Length=%016lx)\n", Length));
}
+
DEBUG ((DEBUG_GCD, " GcdAllocateType = %a\n", mGcdAllocationTypeNames[MIN (GcdAllocateType, EfiGcdMaxAllocateType)]));
DEBUG ((DEBUG_GCD, " GcdIoType = %a\n", mGcdIoTypeNames[MIN (GcdIoType, EfiGcdIoTypeMaximum)]));
DEBUG ((DEBUG_GCD, " Alignment = %016lx\n", LShiftU64 (1, Alignment)));
@@ -1840,7 +1895,7 @@ CoreAllocateIoSpace ( return CoreAllocateSpace (
GCD_ALLOCATE_IO_OPERATION,
GcdAllocateType,
- (EFI_GCD_MEMORY_TYPE) 0,
+ (EFI_GCD_MEMORY_TYPE)0,
GcdIoType,
Alignment,
Length,
@@ -1850,7 +1905,6 @@ CoreAllocateIoSpace ( );
}
-
/**
Frees nonexistent I/O, reserved I/O, or I/O resources from the global coherency
domain of the processor.
@@ -1870,10 +1924,9 @@ CoreFreeIoSpace ( {
DEBUG ((DEBUG_GCD, "GCD:FreeIoSpace(Base=%016lx,Length=%016lx)\n", BaseAddress, Length));
- return CoreConvertSpace (GCD_FREE_IO_OPERATION, (EFI_GCD_MEMORY_TYPE) 0, (EFI_GCD_IO_TYPE) 0, BaseAddress, Length, 0, 0);
+ 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.
@@ -1893,10 +1946,9 @@ CoreRemoveIoSpace ( {
DEBUG ((DEBUG_GCD, "GCD:RemoveIoSpace(Base=%016lx,Length=%016lx)\n", BaseAddress, Length));
- return CoreConvertSpace (GCD_REMOVE_IO_OPERATION, (EFI_GCD_MEMORY_TYPE) 0, (EFI_GCD_IO_TYPE) 0, BaseAddress, Length, 0, 0);
+ 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.
@@ -1917,7 +1969,6 @@ BuildIoDescriptor ( Descriptor->DeviceHandle = Entry->DeviceHandle;
}
-
/**
Retrieves the descriptor for an I/O region containing a specified address.
@@ -1969,7 +2020,6 @@ CoreGetIoSpaceDescriptor ( return Status;
}
-
/**
Returns a map of the I/O resources in the global coherency domain of the processor.
@@ -1999,6 +2049,7 @@ CoreGetIoSpaceMap ( if (NumberOfDescriptors == NULL) {
return EFI_INVALID_PARAMETER;
}
+
if (IoSpaceMap == NULL) {
return EFI_INVALID_PARAMETER;
}
@@ -2023,13 +2074,14 @@ CoreGetIoSpaceMap ( // Fill in the IoSpaceMap
//
Descriptor = *IoSpaceMap;
- Link = mGcdIoSpaceMap.ForwardLink;
+ Link = mGcdIoSpaceMap.ForwardLink;
while (Link != &mGcdIoSpaceMap) {
Entry = CR (Link, EFI_GCD_MAP_ENTRY, Link, EFI_GCD_MAP_SIGNATURE);
BuildIoDescriptor (Descriptor, Entry);
Descriptor++;
Link = Link->ForwardLink;
}
+
Status = EFI_SUCCESS;
Done:
@@ -2037,7 +2089,6 @@ Done: return Status;
}
-
/**
Converts a Resource Descriptor HOB attributes mask to an EFI Memory Descriptor
capabilities mask
@@ -2083,8 +2134,8 @@ CalculateTotalMemoryBinSizeNeeded ( VOID
)
{
- UINTN Index;
- UINT64 TotalSize;
+ UINTN Index;
+ UINT64 TotalSize;
//
// Loop through each memory type in the order specified by the gMemoryTypeInformation[] array
@@ -2108,45 +2159,49 @@ CalculateTotalMemoryBinSizeNeeded ( **/
VOID
FindLargestFreeRegion (
- IN OUT EFI_PHYSICAL_ADDRESS *BaseAddress,
- IN OUT UINT64 *Length,
- IN EFI_HOB_MEMORY_ALLOCATION *MemoryHob
- )
+ IN OUT EFI_PHYSICAL_ADDRESS *BaseAddress,
+ IN OUT UINT64 *Length,
+ IN EFI_HOB_MEMORY_ALLOCATION *MemoryHob
+ )
{
- EFI_PHYSICAL_ADDRESS TopAddress;
- EFI_PHYSICAL_ADDRESS AllocatedTop;
- EFI_PHYSICAL_ADDRESS LowerBase;
- UINT64 LowerSize;
- EFI_PHYSICAL_ADDRESS UpperBase;
- UINT64 UpperSize;
+ EFI_PHYSICAL_ADDRESS TopAddress;
+ EFI_PHYSICAL_ADDRESS AllocatedTop;
+ EFI_PHYSICAL_ADDRESS LowerBase;
+ UINT64 LowerSize;
+ EFI_PHYSICAL_ADDRESS UpperBase;
+ UINT64 UpperSize;
TopAddress = *BaseAddress + *Length;
while (MemoryHob != NULL) {
AllocatedTop = MemoryHob->AllocDescriptor.MemoryBaseAddress + MemoryHob->AllocDescriptor.MemoryLength;
if ((MemoryHob->AllocDescriptor.MemoryBaseAddress >= *BaseAddress) &&
- (AllocatedTop <= TopAddress)) {
+ (AllocatedTop <= TopAddress))
+ {
LowerBase = *BaseAddress;
LowerSize = MemoryHob->AllocDescriptor.MemoryBaseAddress - *BaseAddress;
UpperBase = AllocatedTop;
UpperSize = TopAddress - AllocatedTop;
if (LowerSize != 0) {
- FindLargestFreeRegion (&LowerBase, &LowerSize, (EFI_HOB_MEMORY_ALLOCATION *) GetNextHob (EFI_HOB_TYPE_MEMORY_ALLOCATION, GET_NEXT_HOB (MemoryHob)));
+ FindLargestFreeRegion (&LowerBase, &LowerSize, (EFI_HOB_MEMORY_ALLOCATION *)GetNextHob (EFI_HOB_TYPE_MEMORY_ALLOCATION, GET_NEXT_HOB (MemoryHob)));
}
+
if (UpperSize != 0) {
- FindLargestFreeRegion (&UpperBase, &UpperSize, (EFI_HOB_MEMORY_ALLOCATION *) GetNextHob (EFI_HOB_TYPE_MEMORY_ALLOCATION, GET_NEXT_HOB (MemoryHob)));
+ FindLargestFreeRegion (&UpperBase, &UpperSize, (EFI_HOB_MEMORY_ALLOCATION *)GetNextHob (EFI_HOB_TYPE_MEMORY_ALLOCATION, GET_NEXT_HOB (MemoryHob)));
}
if (UpperSize >= LowerSize) {
- *Length = UpperSize;
+ *Length = UpperSize;
*BaseAddress = UpperBase;
} else {
- *Length = LowerSize;
+ *Length = LowerSize;
*BaseAddress = LowerBase;
}
+
return;
}
+
MemoryHob = GetNextHob (EFI_HOB_TYPE_MEMORY_ALLOCATION, GET_NEXT_HOB (MemoryHob));
}
}
@@ -2173,23 +2228,23 @@ CoreInitializeMemoryServices ( OUT UINT64 *MemoryLength
)
{
- EFI_PEI_HOB_POINTERS Hob;
- EFI_MEMORY_TYPE_INFORMATION *EfiMemoryTypeInformation;
- UINTN DataSize;
- BOOLEAN Found;
- EFI_HOB_HANDOFF_INFO_TABLE *PhitHob;
- EFI_HOB_RESOURCE_DESCRIPTOR *ResourceHob;
- EFI_HOB_RESOURCE_DESCRIPTOR *PhitResourceHob;
- EFI_PHYSICAL_ADDRESS BaseAddress;
- UINT64 Length;
- UINT64 Attributes;
- UINT64 Capabilities;
- EFI_PHYSICAL_ADDRESS TestedMemoryBaseAddress;
- UINT64 TestedMemoryLength;
- EFI_PHYSICAL_ADDRESS HighAddress;
- EFI_HOB_GUID_TYPE *GuidHob;
- UINT32 ReservedCodePageNumber;
- UINT64 MinimalMemorySizeNeeded;
+ EFI_PEI_HOB_POINTERS Hob;
+ EFI_MEMORY_TYPE_INFORMATION *EfiMemoryTypeInformation;
+ UINTN DataSize;
+ BOOLEAN Found;
+ EFI_HOB_HANDOFF_INFO_TABLE *PhitHob;
+ EFI_HOB_RESOURCE_DESCRIPTOR *ResourceHob;
+ EFI_HOB_RESOURCE_DESCRIPTOR *PhitResourceHob;
+ EFI_PHYSICAL_ADDRESS BaseAddress;
+ UINT64 Length;
+ UINT64 Attributes;
+ UINT64 Capabilities;
+ EFI_PHYSICAL_ADDRESS TestedMemoryBaseAddress;
+ UINT64 TestedMemoryLength;
+ EFI_PHYSICAL_ADDRESS HighAddress;
+ EFI_HOB_GUID_TYPE *GuidHob;
+ UINT32 ReservedCodePageNumber;
+ UINT64 MinimalMemorySizeNeeded;
//
// Point at the first HOB. This must be the PHIT HOB.
@@ -2206,27 +2261,28 @@ CoreInitializeMemoryServices ( //
// Initialize Local Variables
//
- PhitResourceHob = NULL;
- ResourceHob = NULL;
- BaseAddress = 0;
- Length = 0;
- Attributes = 0;
+ PhitResourceHob = NULL;
+ ResourceHob = NULL;
+ BaseAddress = 0;
+ Length = 0;
+ Attributes = 0;
//
// Cache the PHIT HOB for later use
//
PhitHob = Hob.HandoffInformationTable;
- if (PcdGet64(PcdLoadModuleAtFixAddressEnable) != 0) {
- ReservedCodePageNumber = PcdGet32(PcdLoadFixAddressRuntimeCodePageNumber);
- ReservedCodePageNumber += PcdGet32(PcdLoadFixAddressBootTimeCodePageNumber);
+ if (PcdGet64 (PcdLoadModuleAtFixAddressEnable) != 0) {
+ ReservedCodePageNumber = PcdGet32 (PcdLoadFixAddressRuntimeCodePageNumber);
+ ReservedCodePageNumber += PcdGet32 (PcdLoadFixAddressBootTimeCodePageNumber);
//
// cache the Top address for loading modules at Fixed Address
//
gLoadModuleAtFixAddressConfigurationTable.DxeCodeTopAddress = PhitHob->EfiMemoryTop
- + EFI_PAGES_TO_SIZE(ReservedCodePageNumber);
+ + EFI_PAGES_TO_SIZE (ReservedCodePageNumber);
}
+
//
// See if a Memory Type Information HOB is available
//
@@ -2234,7 +2290,7 @@ CoreInitializeMemoryServices ( if (GuidHob != NULL) {
EfiMemoryTypeInformation = GET_GUID_HOB_DATA (GuidHob);
DataSize = GET_GUID_HOB_DATA_SIZE (GuidHob);
- if (EfiMemoryTypeInformation != NULL && DataSize > 0 && DataSize <= (EfiMaxMemoryType + 1) * sizeof (EFI_MEMORY_TYPE_INFORMATION)) {
+ if ((EfiMemoryTypeInformation != NULL) && (DataSize > 0) && (DataSize <= (EfiMaxMemoryType + 1) * sizeof (EFI_MEMORY_TYPE_INFORMATION))) {
CopyMem (&gMemoryTypeInformation, EfiMemoryTypeInformation, DataSize);
}
}
@@ -2247,8 +2303,8 @@ CoreInitializeMemoryServices ( //
// Find the Resource Descriptor HOB that contains PHIT range EfiFreeMemoryBottom..EfiFreeMemoryTop
//
- Found = FALSE;
- for (Hob.Raw = *HobStart; !END_OF_HOB_LIST(Hob); Hob.Raw = GET_NEXT_HOB(Hob)) {
+ Found = FALSE;
+ for (Hob.Raw = *HobStart; !END_OF_HOB_LIST (Hob); Hob.Raw = GET_NEXT_HOB (Hob)) {
//
// Skip all HOBs except Resource Descriptor HOBs
//
@@ -2263,6 +2319,7 @@ CoreInitializeMemoryServices ( if (ResourceHob->ResourceType != EFI_RESOURCE_SYSTEM_MEMORY) {
continue;
}
+
if ((ResourceHob->ResourceAttribute & MEMORY_ATTRIBUTE_MASK) != TESTED_MEMORY_ATTRIBUTES) {
continue;
}
@@ -2273,6 +2330,7 @@ CoreInitializeMemoryServices ( if (PhitHob->EfiFreeMemoryBottom < ResourceHob->PhysicalStart) {
continue;
}
+
if (PhitHob->EfiFreeMemoryTop > (ResourceHob->PhysicalStart + ResourceHob->ResourceLength)) {
continue;
}
@@ -2281,14 +2339,14 @@ CoreInitializeMemoryServices ( // Cache the resource descriptor HOB for the memory region described by the PHIT HOB
//
PhitResourceHob = ResourceHob;
- Found = TRUE;
+ Found = TRUE;
//
// Compute range between PHIT EfiMemoryTop and the end of the Resource Descriptor HOB
//
Attributes = PhitResourceHob->ResourceAttribute;
BaseAddress = PageAlignAddress (PhitHob->EfiMemoryTop);
- Length = PageAlignLength (ResourceHob->PhysicalStart + ResourceHob->ResourceLength - BaseAddress);
+ Length = PageAlignLength (ResourceHob->PhysicalStart + ResourceHob->ResourceLength - BaseAddress);
FindLargestFreeRegion (&BaseAddress, &Length, (EFI_HOB_MEMORY_ALLOCATION *)GetFirstHob (EFI_HOB_TYPE_MEMORY_ALLOCATION));
if (Length < MinimalMemorySizeNeeded) {
//
@@ -2296,18 +2354,19 @@ CoreInitializeMemoryServices ( // Compute range between PHIT EfiFreeMemoryBottom and PHIT EfiFreeMemoryTop
//
BaseAddress = PageAlignAddress (PhitHob->EfiFreeMemoryBottom);
- Length = PageAlignLength (PhitHob->EfiFreeMemoryTop - BaseAddress);
- //This region is required to have no memory allocation inside it, skip check for entries in HOB List
+ Length = PageAlignLength (PhitHob->EfiFreeMemoryTop - BaseAddress);
+ // This region is required to have no memory allocation inside it, skip check for entries in HOB List
if (Length < MinimalMemorySizeNeeded) {
//
// 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
//
BaseAddress = PageAlignAddress (ResourceHob->PhysicalStart);
- Length = PageAlignLength ((UINT64)((UINTN)*HobStart - BaseAddress));
+ Length = PageAlignLength ((UINT64)((UINTN)*HobStart - BaseAddress));
FindLargestFreeRegion (&BaseAddress, &Length, (EFI_HOB_MEMORY_ALLOCATION *)GetFirstHob (EFI_HOB_TYPE_MEMORY_ALLOCATION));
}
}
+
break;
}
@@ -2329,13 +2388,14 @@ CoreInitializeMemoryServices ( // The max address must be within the physically addressible range for the processor.
//
HighAddress = MAX_ALLOC_ADDRESS;
- for (Hob.Raw = *HobStart; !END_OF_HOB_LIST(Hob); Hob.Raw = GET_NEXT_HOB(Hob)) {
+ for (Hob.Raw = *HobStart; !END_OF_HOB_LIST (Hob); Hob.Raw = GET_NEXT_HOB (Hob)) {
//
// Skip the Resource Descriptor HOB that contains the PHIT
//
if (Hob.ResourceDescriptor == PhitResourceHob) {
continue;
}
+
//
// Skip all HOBs except Resource Descriptor HOBs
//
@@ -2350,9 +2410,11 @@ CoreInitializeMemoryServices ( if (ResourceHob->ResourceType != EFI_RESOURCE_SYSTEM_MEMORY) {
continue;
}
+
if ((ResourceHob->ResourceAttribute & MEMORY_ATTRIBUTE_MASK) != TESTED_MEMORY_ATTRIBUTES) {
continue;
}
+
if ((ResourceHob->PhysicalStart + ResourceHob->ResourceLength) > (EFI_PHYSICAL_ADDRESS)MAX_ALLOC_ADDRESS) {
continue;
}
@@ -2360,7 +2422,7 @@ CoreInitializeMemoryServices ( //
// Skip Resource Descriptor HOBs that are below a previously found Resource Descriptor HOB
//
- if (HighAddress != (EFI_PHYSICAL_ADDRESS)MAX_ALLOC_ADDRESS && ResourceHob->PhysicalStart <= HighAddress) {
+ if ((HighAddress != (EFI_PHYSICAL_ADDRESS)MAX_ALLOC_ADDRESS) && (ResourceHob->PhysicalStart <= HighAddress)) {
continue;
}
@@ -2368,7 +2430,7 @@ CoreInitializeMemoryServices ( // Skip Resource Descriptor HOBs that are not large enough to initilize the DXE Core
//
TestedMemoryBaseAddress = PageAlignAddress (ResourceHob->PhysicalStart);
- TestedMemoryLength = PageAlignLength (ResourceHob->PhysicalStart + ResourceHob->ResourceLength - TestedMemoryBaseAddress);
+ TestedMemoryLength = PageAlignLength (ResourceHob->PhysicalStart + ResourceHob->ResourceLength - TestedMemoryBaseAddress);
FindLargestFreeRegion (&TestedMemoryBaseAddress, &TestedMemoryLength, (EFI_HOB_MEMORY_ALLOCATION *)GetFirstHob (EFI_HOB_TYPE_MEMORY_ALLOCATION));
if (TestedMemoryLength < MinimalMemorySizeNeeded) {
continue;
@@ -2417,7 +2479,6 @@ CoreInitializeMemoryServices ( 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
@@ -2439,27 +2500,27 @@ CoreInitializeGcdServices ( IN UINT64 MemoryLength
)
{
- EFI_PEI_HOB_POINTERS Hob;
- VOID *NewHobList;
- EFI_HOB_HANDOFF_INFO_TABLE *PhitHob;
- UINT8 SizeOfMemorySpace;
- UINT8 SizeOfIoSpace;
- EFI_HOB_RESOURCE_DESCRIPTOR *ResourceHob;
- EFI_PHYSICAL_ADDRESS BaseAddress;
- UINT64 Length;
- EFI_STATUS Status;
- EFI_GCD_MAP_ENTRY *Entry;
- EFI_GCD_MEMORY_TYPE GcdMemoryType;
- EFI_GCD_IO_TYPE GcdIoType;
- EFI_GCD_MEMORY_SPACE_DESCRIPTOR Descriptor;
- EFI_HOB_MEMORY_ALLOCATION *MemoryHob;
- EFI_HOB_FIRMWARE_VOLUME *FirmwareVolumeHob;
- UINTN NumberOfDescriptors;
- EFI_GCD_MEMORY_SPACE_DESCRIPTOR *MemorySpaceMap;
- UINTN Index;
- UINT64 Capabilities;
- EFI_HOB_CPU * CpuHob;
- EFI_GCD_MEMORY_SPACE_DESCRIPTOR *MemorySpaceMapHobList;
+ EFI_PEI_HOB_POINTERS Hob;
+ VOID *NewHobList;
+ EFI_HOB_HANDOFF_INFO_TABLE *PhitHob;
+ UINT8 SizeOfMemorySpace;
+ UINT8 SizeOfIoSpace;
+ EFI_HOB_RESOURCE_DESCRIPTOR *ResourceHob;
+ EFI_PHYSICAL_ADDRESS BaseAddress;
+ UINT64 Length;
+ EFI_STATUS Status;
+ EFI_GCD_MAP_ENTRY *Entry;
+ EFI_GCD_MEMORY_TYPE GcdMemoryType;
+ EFI_GCD_IO_TYPE GcdIoType;
+ EFI_GCD_MEMORY_SPACE_DESCRIPTOR Descriptor;
+ EFI_HOB_MEMORY_ALLOCATION *MemoryHob;
+ EFI_HOB_FIRMWARE_VOLUME *FirmwareVolumeHob;
+ UINTN NumberOfDescriptors;
+ EFI_GCD_MEMORY_SPACE_DESCRIPTOR *MemorySpaceMap;
+ UINTN Index;
+ UINT64 Capabilities;
+ EFI_HOB_CPU *CpuHob;
+ EFI_GCD_MEMORY_SPACE_DESCRIPTOR *MemorySpaceMapHobList;
//
// Cache the PHIT HOB for later use
@@ -2501,48 +2562,50 @@ CoreInitializeGcdServices ( //
// Walk the HOB list and add all resource descriptors to the GCD
//
- for (Hob.Raw = *HobStart; !END_OF_HOB_LIST(Hob); Hob.Raw = GET_NEXT_HOB(Hob)) {
-
+ for (Hob.Raw = *HobStart; !END_OF_HOB_LIST (Hob); Hob.Raw = GET_NEXT_HOB (Hob)) {
GcdMemoryType = EfiGcdMemoryTypeNonExistent;
GcdIoType = EfiGcdIoTypeNonExistent;
if (GET_HOB_TYPE (Hob) == EFI_HOB_TYPE_RESOURCE_DESCRIPTOR) {
-
ResourceHob = Hob.ResourceDescriptor;
switch (ResourceHob->ResourceType) {
- case EFI_RESOURCE_SYSTEM_MEMORY:
- if ((ResourceHob->ResourceAttribute & MEMORY_ATTRIBUTE_MASK) == TESTED_MEMORY_ATTRIBUTES) {
- if ((ResourceHob->ResourceAttribute & EFI_RESOURCE_ATTRIBUTE_MORE_RELIABLE) == EFI_RESOURCE_ATTRIBUTE_MORE_RELIABLE) {
- GcdMemoryType = EfiGcdMemoryTypeMoreReliable;
- } else {
- GcdMemoryType = EfiGcdMemoryTypeSystemMemory;
+ case EFI_RESOURCE_SYSTEM_MEMORY:
+ if ((ResourceHob->ResourceAttribute & MEMORY_ATTRIBUTE_MASK) == TESTED_MEMORY_ATTRIBUTES) {
+ if ((ResourceHob->ResourceAttribute & EFI_RESOURCE_ATTRIBUTE_MORE_RELIABLE) == EFI_RESOURCE_ATTRIBUTE_MORE_RELIABLE) {
+ GcdMemoryType = EfiGcdMemoryTypeMoreReliable;
+ } else {
+ GcdMemoryType = EfiGcdMemoryTypeSystemMemory;
+ }
}
- }
- if ((ResourceHob->ResourceAttribute & MEMORY_ATTRIBUTE_MASK) == INITIALIZED_MEMORY_ATTRIBUTES) {
- GcdMemoryType = EfiGcdMemoryTypeReserved;
- }
- if ((ResourceHob->ResourceAttribute & MEMORY_ATTRIBUTE_MASK) == PRESENT_MEMORY_ATTRIBUTES) {
+
+ if ((ResourceHob->ResourceAttribute & MEMORY_ATTRIBUTE_MASK) == INITIALIZED_MEMORY_ATTRIBUTES) {
+ GcdMemoryType = EfiGcdMemoryTypeReserved;
+ }
+
+ if ((ResourceHob->ResourceAttribute & MEMORY_ATTRIBUTE_MASK) == PRESENT_MEMORY_ATTRIBUTES) {
+ GcdMemoryType = EfiGcdMemoryTypeReserved;
+ }
+
+ if ((ResourceHob->ResourceAttribute & EFI_RESOURCE_ATTRIBUTE_PERSISTENT) == EFI_RESOURCE_ATTRIBUTE_PERSISTENT) {
+ GcdMemoryType = EfiGcdMemoryTypePersistent;
+ }
+
+ break;
+ case EFI_RESOURCE_MEMORY_MAPPED_IO:
+ case EFI_RESOURCE_FIRMWARE_DEVICE:
+ GcdMemoryType = EfiGcdMemoryTypeMemoryMappedIo;
+ break;
+ case EFI_RESOURCE_MEMORY_MAPPED_IO_PORT:
+ case EFI_RESOURCE_MEMORY_RESERVED:
GcdMemoryType = EfiGcdMemoryTypeReserved;
- }
- if ((ResourceHob->ResourceAttribute & EFI_RESOURCE_ATTRIBUTE_PERSISTENT) == EFI_RESOURCE_ATTRIBUTE_PERSISTENT) {
- GcdMemoryType = EfiGcdMemoryTypePersistent;
- }
- break;
- case EFI_RESOURCE_MEMORY_MAPPED_IO:
- case EFI_RESOURCE_FIRMWARE_DEVICE:
- GcdMemoryType = EfiGcdMemoryTypeMemoryMappedIo;
- break;
- case EFI_RESOURCE_MEMORY_MAPPED_IO_PORT:
- case EFI_RESOURCE_MEMORY_RESERVED:
- GcdMemoryType = EfiGcdMemoryTypeReserved;
- break;
- case EFI_RESOURCE_IO:
- GcdIoType = EfiGcdIoTypeIo;
- break;
- case EFI_RESOURCE_IO_RESERVED:
- GcdIoType = EfiGcdIoTypeReserved;
- break;
+ break;
+ case EFI_RESOURCE_IO:
+ GcdIoType = EfiGcdIoTypeIo;
+ break;
+ case EFI_RESOURCE_IO_RESERVED:
+ GcdIoType = EfiGcdIoTypeReserved;
+ break;
}
if (GcdMemoryType != EfiGcdMemoryTypeNonExistent) {
@@ -2582,8 +2645,10 @@ CoreInitializeGcdServices ( //
Status = CoreGetMemorySpaceDescriptor (MemoryBaseAddress, &Descriptor);
if (!EFI_ERROR (Status)) {
- ASSERT ((Descriptor.GcdMemoryType == EfiGcdMemoryTypeSystemMemory) ||
- (Descriptor.GcdMemoryType == EfiGcdMemoryTypeMoreReliable));
+ ASSERT (
+ (Descriptor.GcdMemoryType == EfiGcdMemoryTypeSystemMemory) ||
+ (Descriptor.GcdMemoryType == EfiGcdMemoryTypeMoreReliable)
+ );
Status = CoreAllocateMemorySpace (
EfiGcdAllocateAddress,
Descriptor.GcdMemoryType,
@@ -2599,11 +2664,11 @@ CoreInitializeGcdServices ( // 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.
//
- for (Hob.Raw = *HobStart; !END_OF_HOB_LIST(Hob); Hob.Raw = GET_NEXT_HOB(Hob)) {
+ for (Hob.Raw = *HobStart; !END_OF_HOB_LIST (Hob); Hob.Raw = GET_NEXT_HOB (Hob)) {
if (GET_HOB_TYPE (Hob) == EFI_HOB_TYPE_MEMORY_ALLOCATION) {
- MemoryHob = Hob.MemoryAllocation;
+ MemoryHob = Hob.MemoryAllocation;
BaseAddress = MemoryHob->AllocDescriptor.MemoryBaseAddress;
- Status = CoreGetMemorySpaceDescriptor (BaseAddress, &Descriptor);
+ Status = CoreGetMemorySpaceDescriptor (BaseAddress, &Descriptor);
if (!EFI_ERROR (Status)) {
Status = CoreAllocateMemorySpace (
EfiGcdAllocateAddress,
@@ -2616,7 +2681,8 @@ CoreInitializeGcdServices ( );
if (!EFI_ERROR (Status) &&
((Descriptor.GcdMemoryType == EfiGcdMemoryTypeSystemMemory) ||
- (Descriptor.GcdMemoryType == EfiGcdMemoryTypeMoreReliable))) {
+ (Descriptor.GcdMemoryType == EfiGcdMemoryTypeMoreReliable)))
+ {
CoreAddMemoryDescriptor (
MemoryHob->AllocDescriptor.MemoryType,
MemoryHob->AllocDescriptor.MemoryBaseAddress,
@@ -2629,16 +2695,16 @@ CoreInitializeGcdServices ( if (GET_HOB_TYPE (Hob) == EFI_HOB_TYPE_FV) {
FirmwareVolumeHob = Hob.FirmwareVolume;
- BaseAddress = FirmwareVolumeHob->BaseAddress;
- Status = CoreAllocateMemorySpace (
- EfiGcdAllocateAddress,
- EfiGcdMemoryTypeMemoryMappedIo,
- 0,
- FirmwareVolumeHob->Length,
- &BaseAddress,
- gDxeCoreImageHandle,
- NULL
- );
+ BaseAddress = FirmwareVolumeHob->BaseAddress;
+ Status = CoreAllocateMemorySpace (
+ EfiGcdAllocateAddress,
+ EfiGcdMemoryTypeMemoryMappedIo,
+ 0,
+ FirmwareVolumeHob->Length,
+ &BaseAddress,
+ gDxeCoreImageHandle,
+ NULL
+ );
}
}
@@ -2651,15 +2717,18 @@ CoreInitializeGcdServices ( MemorySpaceMapHobList = NULL;
for (Index = 0; Index < NumberOfDescriptors; Index++) {
if ((MemorySpaceMap[Index].GcdMemoryType == EfiGcdMemoryTypeSystemMemory) ||
- (MemorySpaceMap[Index].GcdMemoryType == EfiGcdMemoryTypeMoreReliable)) {
+ (MemorySpaceMap[Index].GcdMemoryType == EfiGcdMemoryTypeMoreReliable))
+ {
if (MemorySpaceMap[Index].ImageHandle == NULL) {
- BaseAddress = PageAlignAddress (MemorySpaceMap[Index].BaseAddress);
- Length = PageAlignLength (MemorySpaceMap[Index].BaseAddress + MemorySpaceMap[Index].Length - BaseAddress);
- if (Length == 0 || MemorySpaceMap[Index].BaseAddress + MemorySpaceMap[Index].Length < BaseAddress) {
+ BaseAddress = PageAlignAddress (MemorySpaceMap[Index].BaseAddress);
+ Length = PageAlignLength (MemorySpaceMap[Index].BaseAddress + MemorySpaceMap[Index].Length - BaseAddress);
+ if ((Length == 0) || (MemorySpaceMap[Index].BaseAddress + MemorySpaceMap[Index].Length < BaseAddress)) {
continue;
}
- if (((UINTN) MemorySpaceMap[Index].BaseAddress <= (UINTN) (*HobStart)) &&
- ((UINTN) (MemorySpaceMap[Index].BaseAddress + MemorySpaceMap[Index].Length) >= (UINTN) PhitHob->EfiFreeMemoryBottom)) {
+
+ if (((UINTN)MemorySpaceMap[Index].BaseAddress <= (UINTN)(*HobStart)) &&
+ ((UINTN)(MemorySpaceMap[Index].BaseAddress + MemorySpaceMap[Index].Length) >= (UINTN)PhitHob->EfiFreeMemoryBottom))
+ {
//
// Skip the memory space that covers HOB List, it should be processed
// after HOB List relocation to avoid the resources allocated by others
@@ -2668,6 +2737,7 @@ CoreInitializeGcdServices ( MemorySpaceMapHobList = &MemorySpaceMap[Index];
continue;
}
+
CoreAddMemoryDescriptor (
EfiConventionalMemory,
BaseAddress,
@@ -2695,7 +2765,7 @@ CoreInitializeGcdServices ( // may have not enough remaining resource for HOB List.
//
NewHobList = AllocateCopyPool (
- (UINTN) PhitHob->EfiFreeMemoryBottom - (UINTN) (*HobStart),
+ (UINTN)PhitHob->EfiFreeMemoryBottom - (UINTN)(*HobStart),
*HobStart
);
ASSERT (NewHobList != NULL);
@@ -2709,7 +2779,7 @@ CoreInitializeGcdServices ( // after HOB List relocation.
//
BaseAddress = PageAlignAddress (MemorySpaceMapHobList->BaseAddress);
- Length = PageAlignLength (MemorySpaceMapHobList->BaseAddress + MemorySpaceMapHobList->Length - BaseAddress);
+ Length = PageAlignLength (MemorySpaceMapHobList->BaseAddress + MemorySpaceMapHobList->Length - BaseAddress);
CoreAddMemoryDescriptor (
EfiConventionalMemory,
BaseAddress,
diff --git a/MdeModulePkg/Core/Dxe/Gcd/Gcd.h b/MdeModulePkg/Core/Dxe/Gcd/Gcd.h index 715687b928..d4a4dd7c1b 100644 --- a/MdeModulePkg/Core/Dxe/Gcd/Gcd.h +++ b/MdeModulePkg/Core/Dxe/Gcd/Gcd.h @@ -13,8 +13,8 @@ SPDX-License-Identifier: BSD-2-Clause-Patent //
// GCD Operations
//
-#define GCD_MEMORY_SPACE_OPERATION 0x20
-#define GCD_IO_SPACE_OPERATION 0x40
+#define GCD_MEMORY_SPACE_OPERATION 0x20
+#define GCD_IO_SPACE_OPERATION 0x40
#define GCD_ADD_MEMORY_OPERATION (GCD_MEMORY_SPACE_OPERATION | 0)
#define GCD_ALLOCATE_MEMORY_OPERATION (GCD_MEMORY_SPACE_OPERATION | 1)
@@ -23,18 +23,18 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #define GCD_SET_ATTRIBUTES_MEMORY_OPERATION (GCD_MEMORY_SPACE_OPERATION | 4)
#define GCD_SET_CAPABILITIES_MEMORY_OPERATION (GCD_MEMORY_SPACE_OPERATION | 5)
-#define GCD_ADD_IO_OPERATION (GCD_IO_SPACE_OPERATION | 0)
-#define GCD_ALLOCATE_IO_OPERATION (GCD_IO_SPACE_OPERATION | 1)
-#define GCD_FREE_IO_OPERATION (GCD_IO_SPACE_OPERATION | 2)
-#define GCD_REMOVE_IO_OPERATION (GCD_IO_SPACE_OPERATION | 3)
+#define GCD_ADD_IO_OPERATION (GCD_IO_SPACE_OPERATION | 0)
+#define GCD_ALLOCATE_IO_OPERATION (GCD_IO_SPACE_OPERATION | 1)
+#define GCD_FREE_IO_OPERATION (GCD_IO_SPACE_OPERATION | 2)
+#define GCD_REMOVE_IO_OPERATION (GCD_IO_SPACE_OPERATION | 3)
//
// The data structure used to convert from GCD attributes to EFI Memory Map attributes
//
typedef struct {
- UINT64 Attribute;
- UINT64 Capability;
- BOOLEAN Memory;
+ UINT64 Attribute;
+ UINT64 Capability;
+ BOOLEAN Memory;
} GCD_ATTRIBUTE_CONVERSION_ENTRY;
#endif
|