The GCD services are used to manage the memory and I/O regions that\r
are accessible to the CPU that is executing the DXE core.\r
\r
-Copyright (c) 2006 - 2015, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.<BR>\r
This program and the accompanying materials\r
are licensed and made available under the terms and conditions of the BSD License\r
which accompanies this distribution. The full text of the license may be found at\r
\r
#include "DxeMain.h"\r
#include "Gcd.h"\r
+#include "Mem/HeapGuard.h"\r
\r
#define MINIMUM_INITIAL_MEMORY_SIZE 0x10000\r
\r
\r
#define PRESENT_MEMORY_ATTRIBUTES (EFI_RESOURCE_ATTRIBUTE_PRESENT)\r
\r
+#define EXCLUSIVE_MEMORY_ATTRIBUTES (EFI_MEMORY_UC | EFI_MEMORY_WC | \\r
+ EFI_MEMORY_WT | EFI_MEMORY_WB | \\r
+ EFI_MEMORY_WP | EFI_MEMORY_UCE)\r
+\r
+#define NONEXCLUSIVE_MEMORY_ATTRIBUTES (EFI_MEMORY_XP | EFI_MEMORY_RP | \\r
+ EFI_MEMORY_RO)\r
+\r
#define INVALID_CPU_ARCH_ATTRIBUTES 0xffffffff\r
\r
//\r
"Reserved ", // EfiGcdMemoryTypeReserved\r
"SystemMem", // EfiGcdMemoryTypeSystemMemory\r
"MMIO ", // EfiGcdMemoryTypeMemoryMappedIo\r
- "PersisMem", // EfiGcdMemoryTypePersistentMemory\r
+ "PersisMem", // EfiGcdMemoryTypePersistent\r
"MoreRelia", // EfiGcdMemoryTypeMoreReliable\r
"Unknown " // EfiGcdMemoryTypeMaximum\r
};\r
IN OUT EFI_GCD_MAP_ENTRY **BottomEntry\r
)\r
{\r
+ //\r
+ // Set to mOnGuarding to TRUE before memory allocation. This will make sure\r
+ // that the entry memory is not "guarded" by HeapGuard. Otherwise it might\r
+ // cause problem when it's freed (if HeapGuard is enabled).\r
+ //\r
+ mOnGuarding = TRUE;\r
*TopEntry = AllocateZeroPool (sizeof (EFI_GCD_MAP_ENTRY));\r
+ mOnGuarding = FALSE;\r
if (*TopEntry == NULL) {\r
return EFI_OUT_OF_RESOURCES;\r
}\r
\r
+ mOnGuarding = TRUE;\r
*BottomEntry = AllocateZeroPool (sizeof (EFI_GCD_MAP_ENTRY));\r
+ mOnGuarding = FALSE;\r
if (*BottomEntry == NULL) {\r
CoreFreePool (*TopEntry);\r
return EFI_OUT_OF_RESOURCES;\r
UINT64 Attributes\r
)\r
{\r
- if ( (Attributes & EFI_MEMORY_UC) == EFI_MEMORY_UC) {\r
- return EFI_MEMORY_UC;\r
- }\r
+ UINT64 CpuArchAttributes;\r
\r
- if ( (Attributes & EFI_MEMORY_WC ) == EFI_MEMORY_WC) {\r
- return EFI_MEMORY_WC;\r
- }\r
-\r
- if ( (Attributes & EFI_MEMORY_WT ) == EFI_MEMORY_WT) {\r
- return EFI_MEMORY_WT;\r
- }\r
-\r
- if ( (Attributes & EFI_MEMORY_WB) == EFI_MEMORY_WB) {\r
- return EFI_MEMORY_WB;\r
- }\r
-\r
- if ( (Attributes & EFI_MEMORY_WP) == EFI_MEMORY_WP) {\r
- return EFI_MEMORY_WP;\r
- }\r
-\r
- return INVALID_CPU_ARCH_ATTRIBUTES;\r
+ CpuArchAttributes = Attributes & NONEXCLUSIVE_MEMORY_ATTRIBUTES;\r
\r
+ if ( (Attributes & EFI_MEMORY_UC) == EFI_MEMORY_UC) {\r
+ CpuArchAttributes |= EFI_MEMORY_UC;\r
+ } else if ( (Attributes & EFI_MEMORY_WC ) == EFI_MEMORY_WC) {\r
+ CpuArchAttributes |= EFI_MEMORY_WC;\r
+ } else if ( (Attributes & EFI_MEMORY_WT ) == EFI_MEMORY_WT) {\r
+ CpuArchAttributes |= EFI_MEMORY_WT;\r
+ } else if ( (Attributes & EFI_MEMORY_WB) == EFI_MEMORY_WB) {\r
+ CpuArchAttributes |= EFI_MEMORY_WB;\r
+ } else if ( (Attributes & EFI_MEMORY_UCE) == EFI_MEMORY_UCE) {\r
+ CpuArchAttributes |= EFI_MEMORY_UCE;\r
+ } else if ( (Attributes & EFI_MEMORY_WP) == EFI_MEMORY_WP) {\r
+ CpuArchAttributes |= EFI_MEMORY_WP;\r
+ }\r
+\r
+ return CpuArchAttributes;\r
}\r
\r
\r
IN EFI_HANDLE DeviceHandle OPTIONAL\r
)\r
{\r
- DEBUG ((DEBUG_GCD, "GCD:AllocateMemorySpace(Base=%016lx,Length=%016lx)\n", *BaseAddress, Length));\r
+ if (BaseAddress != NULL) {\r
+ DEBUG ((DEBUG_GCD, "GCD:AllocateMemorySpace(Base=%016lx,Length=%016lx)\n", *BaseAddress, Length));\r
+ } else {\r
+ DEBUG ((DEBUG_GCD, "GCD:AllocateMemorySpace(Base=<NULL>,Length=%016lx)\n", Length));\r
+ }\r
DEBUG ((DEBUG_GCD, " GcdAllocateType = %a\n", mGcdAllocationTypeNames[MIN (GcdAllocateType, EfiGcdMaxAllocateType)]));\r
DEBUG ((DEBUG_GCD, " GcdMemoryType = %a\n", mGcdMemoryTypeNames[MIN (GcdMemoryType, EfiGcdMemoryTypeMaximum)]));\r
DEBUG ((DEBUG_GCD, " Alignment = %016lx\n", LShiftU64 (1, Alignment)));\r
\r
Status = CoreConvertSpace (GCD_SET_CAPABILITIES_MEMORY_OPERATION, (EFI_GCD_MEMORY_TYPE) 0, (EFI_GCD_IO_TYPE) 0, BaseAddress, Length, Capabilities, 0);\r
if (!EFI_ERROR(Status)) {\r
- CoreUpdateMemoryAttributes(BaseAddress, RShiftU64(Length, EFI_PAGE_SHIFT), Capabilities);\r
+ CoreUpdateMemoryAttributes(BaseAddress, RShiftU64(Length, EFI_PAGE_SHIFT), Capabilities & (~EFI_MEMORY_RUNTIME));\r
}\r
\r
return Status;\r
IN EFI_HANDLE DeviceHandle OPTIONAL\r
)\r
{\r
- DEBUG ((DEBUG_GCD, "GCD:AllocateIoSpace(Base=%016lx,Length=%016lx)\n", *BaseAddress, Length));\r
+ if (BaseAddress != NULL) {\r
+ DEBUG ((DEBUG_GCD, "GCD:AllocateIoSpace(Base=%016lx,Length=%016lx)\n", *BaseAddress, Length));\r
+ } else {\r
+ DEBUG ((DEBUG_GCD, "GCD:AllocateIoSpace(Base=<NULL>,Length=%016lx)\n", Length));\r
+ }\r
DEBUG ((DEBUG_GCD, " GcdAllocateType = %a\n", mGcdAllocationTypeNames[MIN (GcdAllocateType, EfiGcdMaxAllocateType)]));\r
DEBUG ((DEBUG_GCD, " GcdIoType = %a\n", mGcdIoTypeNames[MIN (GcdIoType, EfiGcdIoTypeMaximum)]));\r
DEBUG ((DEBUG_GCD, " Alignment = %016lx\n", LShiftU64 (1, Alignment)));\r
UINT64 Length;\r
UINT64 Attributes;\r
UINT64 Capabilities;\r
- EFI_PHYSICAL_ADDRESS MaxMemoryBaseAddress;\r
- UINT64 MaxMemoryLength;\r
- UINT64 MaxMemoryAttributes;\r
EFI_PHYSICAL_ADDRESS TestedMemoryBaseAddress;\r
UINT64 TestedMemoryLength;\r
EFI_PHYSICAL_ADDRESS HighAddress;\r
BaseAddress = 0;\r
Length = 0;\r
Attributes = 0;\r
- MaxMemoryBaseAddress = 0;\r
- MaxMemoryLength = 0;\r
- MaxMemoryAttributes = 0;\r
\r
//\r
// Cache the PHIT HOB for later use\r
GcdMemoryType = EfiGcdMemoryTypeReserved;\r
}\r
if ((ResourceHob->ResourceAttribute & EFI_RESOURCE_ATTRIBUTE_PERSISTENT) == EFI_RESOURCE_ATTRIBUTE_PERSISTENT) {\r
- GcdMemoryType = EfiGcdMemoryTypePersistentMemory;\r
+ GcdMemoryType = EfiGcdMemoryTypePersistent;\r
}\r
break;\r
case EFI_RESOURCE_MEMORY_MAPPED_IO:\r