/** @file\r
UEFI Memory page management functions.\r
\r
-Copyright (c) 2007 - 2014, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2007 - 2015, 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
{ 0, MAX_ADDRESS, 0, 0, EfiMaxMemoryType, FALSE, FALSE }, // EfiMemoryMappedIO\r
{ 0, MAX_ADDRESS, 0, 0, EfiMaxMemoryType, FALSE, FALSE }, // EfiMemoryMappedIOPortSpace\r
{ 0, MAX_ADDRESS, 0, 0, EfiMaxMemoryType, TRUE, TRUE }, // EfiPalCode\r
+ { 0, MAX_ADDRESS, 0, 0, EfiMaxMemoryType, FALSE, FALSE }, // EfiPersistentMemory\r
{ 0, MAX_ADDRESS, 0, 0, EfiMaxMemoryType, FALSE, FALSE } // EfiMaxMemoryType\r
};\r
\r
{ EfiMemoryMappedIO, 0 },\r
{ EfiMemoryMappedIOPortSpace, 0 },\r
{ EfiPalCode, 0 },\r
+ { EfiPersistentMemory, 0 },\r
{ EfiMaxMemoryType, 0 }\r
};\r
//\r
//\r
// Update the GCD map\r
//\r
- Entry->GcdMemoryType = EfiGcdMemoryTypeSystemMemory;\r
+ if ((Entry->Capabilities & EFI_MEMORY_MORE_RELIABLE) == EFI_MEMORY_MORE_RELIABLE) {\r
+ Entry->GcdMemoryType = EfiGcdMemoryTypeMoreReliable;\r
+ } else {\r
+ Entry->GcdMemoryType = EfiGcdMemoryTypeSystemMemory;\r
+ }\r
Entry->Capabilities |= EFI_MEMORY_TESTED;\r
Entry->ImageHandle = gDxeCoreImageHandle;\r
Entry->DeviceHandle = NULL;\r
return;\r
}\r
\r
- if (Type >= EfiMaxMemoryType && Type <= 0x7fffffff) {\r
+ if (Type >= EfiMaxMemoryType && Type < MEMORY_TYPE_OEM_RESERVED_MIN) {\r
return;\r
}\r
CoreAcquireMemoryLock ();\r
@param NumberOfPages The number of pages to convert\r
@param NewAttributes The new attributes value for the range.\r
\r
- @retval EFI_INVALID_PARAMETER Invalid parameter\r
- @retval EFI_NOT_FOUND Could not find a descriptor cover the specified\r
- range or convertion not allowed.\r
- @retval EFI_SUCCESS Successfully converts the memory range to the\r
- specified attributes.\r
-\r
**/\r
VOID\r
CoreUpdateMemoryAttributes (\r
\r
DescEnd = ((DescEnd + 1) & (~(Alignment - 1))) - 1;\r
\r
+ // Skip if DescEnd is less than DescStart after alignment clipping\r
+ if (DescEnd < DescStart) {\r
+ continue;\r
+ }\r
+\r
//\r
// Compute the number of bytes we can used from this\r
// descriptor, and see it's enough to satisfy the request\r
return EFI_INVALID_PARAMETER;\r
}\r
\r
- if ((MemoryType >= EfiMaxMemoryType && MemoryType <= 0x7fffffff) ||\r
- MemoryType == EfiConventionalMemory) {\r
+ if ((MemoryType >= EfiMaxMemoryType && MemoryType < MEMORY_TYPE_OEM_RESERVED_MIN) ||\r
+ (MemoryType == EfiConventionalMemory) || (MemoryType == EfiPersistentMemory)) {\r
return EFI_INVALID_PARAMETER;\r
}\r
\r
\r
Status = CoreInternalFreePages (Memory, NumberOfPages);\r
if (!EFI_ERROR (Status)) {\r
- CoreUpdateProfile ((EFI_PHYSICAL_ADDRESS) (UINTN) RETURN_ADDRESS (0), MemoryProfileActionFreePages, 0, EFI_PAGES_TO_SIZE (NumberOfPages), (VOID *) (UINTN) Memory);\r
+ CoreUpdateProfile ((EFI_PHYSICAL_ADDRESS) (UINTN) RETURN_ADDRESS (0), MemoryProfileActionFreePages, (EFI_MEMORY_TYPE) 0, EFI_PAGES_TO_SIZE (NumberOfPages), (VOID *) (UINTN) Memory);\r
}\r
return Status;\r
}\r
EFI_STATUS Status;\r
UINTN Size;\r
UINTN BufferSize;\r
- UINTN NumberOfRuntimeEntries;\r
+ UINTN NumberOfEntries;\r
LIST_ENTRY *Link;\r
MEMORY_MAP *Entry;\r
EFI_GCD_MAP_ENTRY *GcdMapEntry;\r
CoreAcquireGcdMemoryLock ();\r
\r
//\r
- // Count the number of Reserved and MMIO entries that are marked for runtime use\r
+ // Count the number of Reserved and runtime MMIO entries\r
+ // And, count the number of Persistent entries.\r
//\r
- NumberOfRuntimeEntries = 0;\r
+ NumberOfEntries = 0;\r
for (Link = mGcdMemorySpaceMap.ForwardLink; Link != &mGcdMemorySpaceMap; Link = Link->ForwardLink) {\r
GcdMapEntry = CR (Link, EFI_GCD_MAP_ENTRY, Link, EFI_GCD_MAP_SIGNATURE);\r
- if ((GcdMapEntry->GcdMemoryType == EfiGcdMemoryTypeReserved) ||\r
- (GcdMapEntry->GcdMemoryType == EfiGcdMemoryTypeMemoryMappedIo)) {\r
- if ((GcdMapEntry->Attributes & EFI_MEMORY_RUNTIME) == EFI_MEMORY_RUNTIME) {\r
- NumberOfRuntimeEntries++;\r
- }\r
+ if ((GcdMapEntry->GcdMemoryType == EfiGcdMemoryTypePersistentMemory) || \r
+ (GcdMapEntry->GcdMemoryType == EfiGcdMemoryTypeReserved) ||\r
+ ((GcdMapEntry->GcdMemoryType == EfiGcdMemoryTypeMemoryMappedIo) &&\r
+ ((GcdMapEntry->Attributes & EFI_MEMORY_RUNTIME) == EFI_MEMORY_RUNTIME))) {\r
+ NumberOfEntries ++;\r
}\r
}\r
\r
//\r
// Compute the buffer size needed to fit the entire map\r
//\r
- BufferSize = Size * NumberOfRuntimeEntries;\r
+ BufferSize = Size * NumberOfEntries;\r
for (Link = gMemoryMap.ForwardLink; Link != &gMemoryMap; Link = Link->ForwardLink) {\r
BufferSize += Size;\r
}\r
for (Link = mGcdMemorySpaceMap.ForwardLink; Link != &mGcdMemorySpaceMap; Link = Link->ForwardLink) {\r
GcdMapEntry = CR (Link, EFI_GCD_MAP_ENTRY, Link, EFI_GCD_MAP_SIGNATURE);\r
if ((GcdMapEntry->GcdMemoryType == EfiGcdMemoryTypeReserved) ||\r
- (GcdMapEntry->GcdMemoryType == EfiGcdMemoryTypeMemoryMappedIo)) {\r
- if ((GcdMapEntry->Attributes & EFI_MEMORY_RUNTIME) == EFI_MEMORY_RUNTIME) {\r
- // \r
- // Create EFI_MEMORY_DESCRIPTOR for every Reserved and MMIO GCD entries\r
- // that are marked for runtime use\r
- //\r
- MemoryMap->PhysicalStart = GcdMapEntry->BaseAddress;\r
- MemoryMap->VirtualStart = 0;\r
- MemoryMap->NumberOfPages = RShiftU64 ((GcdMapEntry->EndAddress - GcdMapEntry->BaseAddress + 1), EFI_PAGE_SHIFT);\r
- MemoryMap->Attribute = GcdMapEntry->Attributes & ~EFI_MEMORY_PORT_IO;\r
-\r
- if (GcdMapEntry->GcdMemoryType == EfiGcdMemoryTypeReserved) {\r
- MemoryMap->Type = EfiReservedMemoryType;\r
- } else if (GcdMapEntry->GcdMemoryType == EfiGcdMemoryTypeMemoryMappedIo) {\r
- if ((GcdMapEntry->Attributes & EFI_MEMORY_PORT_IO) == EFI_MEMORY_PORT_IO) {\r
- MemoryMap->Type = EfiMemoryMappedIOPortSpace;\r
- } else {\r
- MemoryMap->Type = EfiMemoryMappedIO;\r
- }\r
+ ((GcdMapEntry->GcdMemoryType == EfiGcdMemoryTypeMemoryMappedIo) &&\r
+ ((GcdMapEntry->Attributes & EFI_MEMORY_RUNTIME) == EFI_MEMORY_RUNTIME))) {\r
+ // \r
+ // Create EFI_MEMORY_DESCRIPTOR for every Reserved and runtime MMIO GCD entries\r
+ //\r
+ MemoryMap->PhysicalStart = GcdMapEntry->BaseAddress;\r
+ MemoryMap->VirtualStart = 0;\r
+ MemoryMap->NumberOfPages = RShiftU64 ((GcdMapEntry->EndAddress - GcdMapEntry->BaseAddress + 1), EFI_PAGE_SHIFT);\r
+ MemoryMap->Attribute = (GcdMapEntry->Attributes & ~EFI_MEMORY_PORT_IO) | \r
+ (GcdMapEntry->Capabilities & (EFI_MEMORY_RP | EFI_MEMORY_WP | EFI_MEMORY_XP | EFI_MEMORY_RO |\r
+ EFI_MEMORY_UC | EFI_MEMORY_UCE | EFI_MEMORY_WC | EFI_MEMORY_WT | EFI_MEMORY_WB));\r
+\r
+ if (GcdMapEntry->GcdMemoryType == EfiGcdMemoryTypeReserved) {\r
+ MemoryMap->Type = EfiReservedMemoryType;\r
+ } else if (GcdMapEntry->GcdMemoryType == EfiGcdMemoryTypeMemoryMappedIo) {\r
+ if ((GcdMapEntry->Attributes & EFI_MEMORY_PORT_IO) == EFI_MEMORY_PORT_IO) {\r
+ MemoryMap->Type = EfiMemoryMappedIOPortSpace;\r
+ } else {\r
+ MemoryMap->Type = EfiMemoryMappedIO;\r
}\r
-\r
- //\r
- // Check to see if the new Memory Map Descriptor can be merged with an \r
- // existing descriptor if they are adjacent and have the same attributes\r
- //\r
- MemoryMap = MergeMemoryMapDescriptor (MemoryMapStart, MemoryMap, Size);\r
}\r
+\r
+ //\r
+ // Check to see if the new Memory Map Descriptor can be merged with an \r
+ // existing descriptor if they are adjacent and have the same attributes\r
+ //\r
+ MemoryMap = MergeMemoryMapDescriptor (MemoryMapStart, MemoryMap, Size);\r
+ }\r
+ \r
+ if (GcdMapEntry->GcdMemoryType == EfiGcdMemoryTypePersistentMemory) {\r
+ // \r
+ // Create EFI_MEMORY_DESCRIPTOR for every Persistent GCD entries\r
+ //\r
+ MemoryMap->PhysicalStart = GcdMapEntry->BaseAddress;\r
+ MemoryMap->VirtualStart = 0;\r
+ MemoryMap->NumberOfPages = RShiftU64 ((GcdMapEntry->EndAddress - GcdMapEntry->BaseAddress + 1), EFI_PAGE_SHIFT);\r
+ MemoryMap->Attribute = GcdMapEntry->Attributes | EFI_MEMORY_NV | \r
+ (GcdMapEntry->Capabilities & (EFI_MEMORY_RP | EFI_MEMORY_WP | EFI_MEMORY_XP | EFI_MEMORY_RO |\r
+ EFI_MEMORY_UC | EFI_MEMORY_UCE | EFI_MEMORY_WC | EFI_MEMORY_WT | EFI_MEMORY_WB));\r
+ MemoryMap->Type = EfiPersistentMemory;\r
+ \r
+ //\r
+ // Check to see if the new Memory Map Descriptor can be merged with an \r
+ // existing descriptor if they are adjacent and have the same attributes\r
+ //\r
+ MemoryMap = MergeMemoryMapDescriptor (MemoryMapStart, MemoryMap, Size);\r
}\r
}\r
\r
\r
for (Link = gMemoryMap.ForwardLink; Link != &gMemoryMap; Link = Link->ForwardLink) {\r
Entry = CR(Link, MEMORY_MAP, Link, MEMORY_MAP_SIGNATURE);\r
- if ((Entry->Attribute & EFI_MEMORY_RUNTIME) != 0) {\r
- if (Entry->Type == EfiACPIReclaimMemory || Entry->Type == EfiACPIMemoryNVS) {\r
- DEBUG((DEBUG_ERROR | DEBUG_PAGE, "ExitBootServices: ACPI memory entry has RUNTIME attribute set.\n"));\r
- Status = EFI_INVALID_PARAMETER;\r
- goto Done;\r
- }\r
- if ((Entry->Start & (EFI_ACPI_RUNTIME_PAGE_ALLOCATION_ALIGNMENT - 1)) != 0) {\r
- DEBUG((DEBUG_ERROR | DEBUG_PAGE, "ExitBootServices: A RUNTIME memory entry is not on a proper alignment.\n"));\r
- Status = EFI_INVALID_PARAMETER;\r
- goto Done;\r
- }\r
- if (((Entry->End + 1) & (EFI_ACPI_RUNTIME_PAGE_ALLOCATION_ALIGNMENT - 1)) != 0) {\r
- DEBUG((DEBUG_ERROR | DEBUG_PAGE, "ExitBootServices: A RUNTIME memory entry is not on a proper alignment.\n"));\r
- Status = EFI_INVALID_PARAMETER;\r
- goto Done;\r
+ if (Entry->Type < EfiMaxMemoryType) {\r
+ if (mMemoryTypeStatistics[Entry->Type].Runtime) {\r
+ ASSERT (Entry->Type != EfiACPIReclaimMemory);\r
+ ASSERT (Entry->Type != EfiACPIMemoryNVS);\r
+ if ((Entry->Start & (EFI_ACPI_RUNTIME_PAGE_ALLOCATION_ALIGNMENT - 1)) != 0) {\r
+ DEBUG((DEBUG_ERROR | DEBUG_PAGE, "ExitBootServices: A RUNTIME memory entry is not on a proper alignment.\n"));\r
+ Status = EFI_INVALID_PARAMETER;\r
+ goto Done;\r
+ }\r
+ if (((Entry->End + 1) & (EFI_ACPI_RUNTIME_PAGE_ALLOCATION_ALIGNMENT - 1)) != 0) {\r
+ DEBUG((DEBUG_ERROR | DEBUG_PAGE, "ExitBootServices: A RUNTIME memory entry is not on a proper alignment.\n"));\r
+ Status = EFI_INVALID_PARAMETER;\r
+ goto Done;\r
+ }\r
}\r
}\r
}\r