Update DxeCore to collect PersistentMemory resource and report them in EFI memory map.
Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Liming Gao [email protected] Reviewed-by: Star Zeng <[email protected]> Signed-off-by: Liming Gao <[email protected]> --- .../MemoryProfileInfo/MemoryProfileInfo.c | 3 +- MdeModulePkg/Core/Dxe/Gcd/Gcd.c | 12 ++++++-- MdeModulePkg/Core/Dxe/Mem/Page.c | 34 ++++++++++++++++++---- MdeModulePkg/Core/Dxe/Mem/Pool.c | 5 ++-- MdeModulePkg/Core/PiSmmCore/SmramProfileRecord.c | 1 + 5 files changed, 45 insertions(+), 10 deletions(-) diff --git a/MdeModulePkg/Application/MemoryProfileInfo/MemoryProfileInfo.c b/MdeModulePkg/Application/MemoryProfileInfo/MemoryProfileInfo.c index 084b069..96bb9ad 100644 --- a/MdeModulePkg/Application/MemoryProfileInfo/MemoryProfileInfo.c +++ b/MdeModulePkg/Application/MemoryProfileInfo/MemoryProfileInfo.c @@ -1,8 +1,8 @@ /** @file - Copyright (c) 2014, Intel Corporation. All rights reserved.<BR> + Copyright (c) 2014 - 2015, 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 http://opensource.org/licenses/bsd-license.php @@ -52,10 +52,11 @@ CHAR16 *mMemoryTypeString[] = { L"EfiACPIReclaimMemory", L"EfiACPIMemoryNVS", L"EfiMemoryMappedIO", L"EfiMemoryMappedIOPortSpace", L"EfiPalCode", + L"EfiPersistentMemory", L"EfiOSReserved", }; CHAR16 *mSubsystemString[] = { L"Unknown", diff --git a/MdeModulePkg/Core/Dxe/Gcd/Gcd.c b/MdeModulePkg/Core/Dxe/Gcd/Gcd.c index 6703c84..bce01a0 100644 --- a/MdeModulePkg/Core/Dxe/Gcd/Gcd.c +++ b/MdeModulePkg/Core/Dxe/Gcd/Gcd.c @@ -1,11 +1,11 @@ /** @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 - 2014, Intel Corporation. All rights reserved.<BR> +Copyright (c) 2006 - 2015, 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 http://opensource.org/licenses/bsd-license.php @@ -25,11 +25,12 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. EFI_RESOURCE_ATTRIBUTE_READ_PROTECTED | \ EFI_RESOURCE_ATTRIBUTE_WRITE_PROTECTED | \ EFI_RESOURCE_ATTRIBUTE_EXECUTION_PROTECTED | \ EFI_RESOURCE_ATTRIBUTE_16_BIT_IO | \ EFI_RESOURCE_ATTRIBUTE_32_BIT_IO | \ - EFI_RESOURCE_ATTRIBUTE_64_BIT_IO ) + EFI_RESOURCE_ATTRIBUTE_64_BIT_IO | \ + EFI_RESOURCE_ATTRIBUTE_PERSISTENT ) #define TESTED_MEMORY_ATTRIBUTES (EFI_RESOURCE_ATTRIBUTE_PRESENT | \ EFI_RESOURCE_ATTRIBUTE_INITIALIZED | \ EFI_RESOURCE_ATTRIBUTE_TESTED ) @@ -90,10 +91,11 @@ GCD_ATTRIBUTE_CONVERSION_ENTRY mAttributeConversionTable[] = { { EFI_RESOURCE_ATTRIBUTE_WRITE_PROTECTABLE, EFI_MEMORY_WP, TRUE }, { EFI_RESOURCE_ATTRIBUTE_EXECUTION_PROTECTABLE, EFI_MEMORY_XP, 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 }, { 0, 0, FALSE } }; /// /// Lookup table used to print GCD Memory Space Map @@ -101,10 +103,11 @@ GCD_ATTRIBUTE_CONVERSION_ENTRY mAttributeConversionTable[] = { GLOBAL_REMOVE_IF_UNREFERENCED CONST CHAR8 *mGcdMemoryTypeNames[] = { "NonExist ", // EfiGcdMemoryTypeNonExistent "Reserved ", // EfiGcdMemoryTypeReserved "SystemMem", // EfiGcdMemoryTypeSystemMemory "MMIO ", // EfiGcdMemoryTypeMemoryMappedIo + "PersistentMem",// EfiGcdMemoryTypePersistentMemory "Unknown " // EfiGcdMemoryTypeMaximum }; /// /// Lookup table used to print GCD I/O Space Map @@ -229,10 +232,12 @@ CoreValidateResourceDescriptorHobAttributes ( ((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_PERSISTENT) == 0) || + ((Attributes & EFI_RESOURCE_ATTRIBUTE_PERSISTABLE) != 0)); } /** Acquire memory lock on mGcdMemorySpaceLock. @@ -2355,10 +2360,13 @@ CoreInitializeGcdServices ( 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 = EfiGcdMemoryTypePersistentMemory; + } break; case EFI_RESOURCE_MEMORY_MAPPED_IO: case EFI_RESOURCE_FIRMWARE_DEVICE: GcdMemoryType = EfiGcdMemoryTypeMemoryMappedIo; break; diff --git a/MdeModulePkg/Core/Dxe/Mem/Page.c b/MdeModulePkg/Core/Dxe/Mem/Page.c index 84ebbca..830b197 100644 --- a/MdeModulePkg/Core/Dxe/Mem/Page.c +++ b/MdeModulePkg/Core/Dxe/Mem/Page.c @@ -65,10 +65,11 @@ EFI_MEMORY_TYPE_STATISTICS mMemoryTypeStatistics[EfiMaxMemoryType + 1] = { { 0, MAX_ADDRESS, 0, 0, EfiMaxMemoryType, TRUE, FALSE }, // EfiACPIReclaimMemory { 0, MAX_ADDRESS, 0, 0, EfiMaxMemoryType, TRUE, FALSE }, // EfiACPIMemoryNVS { 0, MAX_ADDRESS, 0, 0, EfiMaxMemoryType, FALSE, FALSE }, // EfiMemoryMappedIO { 0, MAX_ADDRESS, 0, 0, EfiMaxMemoryType, FALSE, FALSE }, // EfiMemoryMappedIOPortSpace { 0, MAX_ADDRESS, 0, 0, EfiMaxMemoryType, TRUE, TRUE }, // EfiPalCode + { 0, MAX_ADDRESS, 0, 0, EfiMaxMemoryType, FALSE, FALSE }, // EfiPersistentMemory { 0, MAX_ADDRESS, 0, 0, EfiMaxMemoryType, FALSE, FALSE } // EfiMaxMemoryType }; EFI_PHYSICAL_ADDRESS mDefaultMaximumAddress = MAX_ADDRESS; EFI_PHYSICAL_ADDRESS mDefaultBaseAddress = MAX_ADDRESS; @@ -86,10 +87,11 @@ EFI_MEMORY_TYPE_INFORMATION gMemoryTypeInformation[EfiMaxMemoryType + 1] = { { EfiACPIReclaimMemory, 0 }, { EfiACPIMemoryNVS, 0 }, { EfiMemoryMappedIO, 0 }, { EfiMemoryMappedIOPortSpace, 0 }, { EfiPalCode, 0 }, + { EfiPersistentMemory, 0 }, { EfiMaxMemoryType, 0 } }; // // Only used when load module at fixed address feature is enabled. True means the memory is alreay successfully allocated // and ready to load the module in to specified address.or else, the memory is not ready and module will be loaded at a @@ -1196,11 +1198,11 @@ CoreInternalAllocatePages ( if ((UINT32)Type >= MaxAllocateType) { return EFI_INVALID_PARAMETER; } if ((MemoryType >= EfiMaxMemoryType && MemoryType <= 0x7fffffff) || - MemoryType == EfiConventionalMemory) { + (MemoryType == EfiConventionalMemory) || (MemoryType == EfiPersistentMemory)) { return EFI_INVALID_PARAMETER; } if (Memory == NULL) { return EFI_INVALID_PARAMETER; @@ -1526,11 +1528,11 @@ CoreGetMemoryMap ( ) { EFI_STATUS Status; UINTN Size; UINTN BufferSize; - UINTN NumberOfRuntimeEntries; + UINTN NumberOfRuntimePersistentEntries; LIST_ENTRY *Link; MEMORY_MAP *Entry; EFI_GCD_MAP_ENTRY *GcdMapEntry; EFI_MEMORY_TYPE Type; EFI_MEMORY_DESCRIPTOR *MemoryMapStart; @@ -1544,20 +1546,25 @@ CoreGetMemoryMap ( CoreAcquireGcdMemoryLock (); // // Count the number of Reserved and MMIO entries that are marked for runtime use + // And, count the number of Persistent entries. // - NumberOfRuntimeEntries = 0; + NumberOfRuntimePersistentEntries = 0; for (Link = mGcdMemorySpaceMap.ForwardLink; Link != &mGcdMemorySpaceMap; Link = Link->ForwardLink) { GcdMapEntry = CR (Link, EFI_GCD_MAP_ENTRY, Link, EFI_GCD_MAP_SIGNATURE); if ((GcdMapEntry->GcdMemoryType == EfiGcdMemoryTypeReserved) || (GcdMapEntry->GcdMemoryType == EfiGcdMemoryTypeMemoryMappedIo)) { if ((GcdMapEntry->Attributes & EFI_MEMORY_RUNTIME) == EFI_MEMORY_RUNTIME) { - NumberOfRuntimeEntries++; + NumberOfRuntimePersistentEntries ++; } } + + if (GcdMapEntry->GcdMemoryType == EfiGcdMemoryTypePersistentMemory) { + NumberOfRuntimePersistentEntries ++; + } } Size = sizeof (EFI_MEMORY_DESCRIPTOR); // @@ -1578,11 +1585,11 @@ CoreGetMemoryMap ( CoreAcquireMemoryLock (); // // Compute the buffer size needed to fit the entire map // - BufferSize = Size * NumberOfRuntimeEntries; + BufferSize = Size * NumberOfRuntimePersistentEntries; for (Link = gMemoryMap.ForwardLink; Link != &gMemoryMap; Link = Link->ForwardLink) { BufferSize += Size; } if (*MemoryMapSize < BufferSize) { @@ -1671,10 +1678,27 @@ CoreGetMemoryMap ( // existing descriptor if they are adjacent and have the same attributes // MemoryMap = MergeMemoryMapDescriptor (MemoryMapStart, MemoryMap, Size); } } + + if (GcdMapEntry->GcdMemoryType == EfiGcdMemoryTypePersistentMemory) { + // + // Create EFI_MEMORY_DESCRIPTOR for every Persistent GCD entries + // + MemoryMap->PhysicalStart = GcdMapEntry->BaseAddress; + MemoryMap->VirtualStart = 0; + MemoryMap->NumberOfPages = RShiftU64 ((GcdMapEntry->EndAddress - GcdMapEntry->BaseAddress + 1), EFI_PAGE_SHIFT); + MemoryMap->Attribute = GcdMapEntry->Attributes | EFI_MEMORY_NV; + MemoryMap->Type = EfiPersistentMemory; + + // + // Check to see if the new Memory Map Descriptor can be merged with an + // existing descriptor if they are adjacent and have the same attributes + // + MemoryMap = MergeMemoryMapDescriptor (MemoryMapStart, MemoryMap, Size); + } } // // Compute the size of the buffer actually used after all memory map descriptor merge operations // diff --git a/MdeModulePkg/Core/Dxe/Mem/Pool.c b/MdeModulePkg/Core/Dxe/Mem/Pool.c index e43bac8..ac717fb 100644 --- a/MdeModulePkg/Core/Dxe/Mem/Pool.c +++ b/MdeModulePkg/Core/Dxe/Mem/Pool.c @@ -1,9 +1,9 @@ /** @file UEFI Memory pool management functions. -Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.<BR> +Copyright (c) 2006 - 2015, 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 http://opensource.org/licenses/bsd-license.php @@ -195,10 +195,11 @@ LookupPoolHead ( @param Size The amount of pool to allocate @param Buffer The address to return a pointer to the allocated pool @retval EFI_INVALID_PARAMETER PoolType not valid or Buffer is NULL. + PoolType was EfiPersistentMemory. @retval EFI_OUT_OF_RESOURCES Size exceeds max pool size or allocation failed. @retval EFI_SUCCESS Pool successfully allocated. **/ EFI_STATUS @@ -213,11 +214,11 @@ CoreInternalAllocatePool ( // // If it's not a valid type, fail it // if ((PoolType >= EfiMaxMemoryType && PoolType <= 0x7fffffff) || - PoolType == EfiConventionalMemory) { + (PoolType == EfiConventionalMemory) || (PoolType == EfiPersistentMemory)) { return EFI_INVALID_PARAMETER; } if (Buffer == NULL) { return EFI_INVALID_PARAMETER; diff --git a/MdeModulePkg/Core/PiSmmCore/SmramProfileRecord.c b/MdeModulePkg/Core/PiSmmCore/SmramProfileRecord.c index a784429..38f806e 100644 --- a/MdeModulePkg/Core/PiSmmCore/SmramProfileRecord.c +++ b/MdeModulePkg/Core/PiSmmCore/SmramProfileRecord.c @@ -1791,10 +1791,11 @@ GLOBAL_REMOVE_IF_UNREFERENCED CHAR16 *mMemoryTypeString[] = { L"EfiACPIReclaimMemory", L"EfiACPIMemoryNVS", L"EfiMemoryMappedIO", L"EfiMemoryMappedIOPortSpace", L"EfiPalCode", + L"EfiPersistentMemory", L"EfiOSReserved", }; /** -- 1.9.5.msysgit.0 ------------------------------------------------------------------------------ One dashboard for servers and applications across Physical-Virtual-Cloud Widest out-of-the-box monitoring support with 50+ applications Performance metrics, stats and reports that give you Actionable Insights Deep dive visibility with transaction tracing using APM Insight. http://ad.doubleclick.net/ddm/clk/290420510;117567292;y _______________________________________________ edk2-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/edk2-devel
