* [PATCH 0/2] ShellPkg/memmap: Dump memory map information for all memory types
@ 2017-05-11 10:27 Ruiyu Ni
2017-05-11 10:27 ` [PATCH 1/2] ShellPkg/memmap: Refine code Ruiyu Ni
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Ruiyu Ni @ 2017-05-11 10:27 UTC (permalink / raw)
To: edk2-devel
The patch dumps memory map information for all memory types.
But to follow the SFO format of "memmap" defined in Shell 2.2 spec,
the patch doesn't dump the memory map information for OEM/OS
memory types. But it does include the OEM/OS memory in the total
size in SFO format.
Ruiyu Ni (2):
ShellPkg/memmap: Refine code
ShellPkg/memmap: Dump memory map information for all memory types
.../Library/UefiShellDebug1CommandsLib/MemMap.c | 199 +++++++++++++++------
.../UefiShellDebug1CommandsLib.uni | 4 +-
2 files changed, 148 insertions(+), 55 deletions(-)
--
2.12.2.windows.2
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 1/2] ShellPkg/memmap: Refine code
2017-05-11 10:27 [PATCH 0/2] ShellPkg/memmap: Dump memory map information for all memory types Ruiyu Ni
@ 2017-05-11 10:27 ` Ruiyu Ni
2017-05-11 10:27 ` [PATCH 2/2] ShellPkg/memmap: Dump memory map information for all memory types Ruiyu Ni
2017-05-11 16:23 ` [PATCH 0/2] " Carsey, Jaben
2 siblings, 0 replies; 4+ messages in thread
From: Ruiyu Ni @ 2017-05-11 10:27 UTC (permalink / raw)
To: edk2-devel; +Cc: Jaben Carsey
The patch changes Buffer to Descriptors, changes
(UINT8 *Walker) to (EFI_MEMORY_DESCRIPTOR *Walker).
The change makes lots of type conversion unnecessary.
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com>
Cc: Jaben Carsey <jaben.carsey@intel.com>
---
.../Library/UefiShellDebug1CommandsLib/MemMap.c | 107 +++++++++++----------
1 file changed, 55 insertions(+), 52 deletions(-)
diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/MemMap.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/MemMap.c
index a4eb1be27e..a99e3c4723 100644
--- a/ShellPkg/Library/UefiShellDebug1CommandsLib/MemMap.c
+++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/MemMap.c
@@ -3,7 +3,7 @@
(C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>
(C) Copyright 2013-2015 Hewlett-Packard Development Company, L.P.<BR>
- Copyright (c) 2010 - 2015, Intel Corporation. All rights reserved.<BR>
+ Copyright (c) 2010 - 2017, 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 acModeanies this distribution. The full text of the license may be found at
@@ -66,11 +66,11 @@ ShellCommandRunMemMap (
CHAR16 *ProblemParam;
SHELL_STATUS ShellStatus;
UINTN Size;
- EFI_MEMORY_DESCRIPTOR *Buffer;
+ EFI_MEMORY_DESCRIPTOR *Descriptors;
UINTN MapKey;
UINTN ItemSize;
UINT32 Version;
- UINT8 *Walker;
+ EFI_MEMORY_DESCRIPTOR *Walker;
UINT64 ReservedPages;
UINT64 LoadCodePages;
UINT64 LoadDataPages;
@@ -122,7 +122,7 @@ ShellCommandRunMemMap (
PalCodePages = 0;
PersistentPages = 0;
Size = 0;
- Buffer = NULL;
+ Descriptors = NULL;
ShellStatus = SHELL_SUCCESS;
Status = EFI_SUCCESS;
@@ -152,11 +152,11 @@ ShellCommandRunMemMap (
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellDebug1HiiHandle, L"memmap");
ShellStatus = SHELL_INVALID_PARAMETER;
} else {
- Status = gBS->GetMemoryMap(&Size, Buffer, &MapKey, &ItemSize, &Version);
+ Status = gBS->GetMemoryMap(&Size, Descriptors, &MapKey, &ItemSize, &Version);
if (Status == EFI_BUFFER_TOO_SMALL){
Size += SIZE_1KB;
- Buffer = AllocateZeroPool(Size);
- Status = gBS->GetMemoryMap(&Size, Buffer, &MapKey, &ItemSize, &Version);
+ Descriptors = AllocateZeroPool(Size);
+ Status = gBS->GetMemoryMap(&Size, Descriptors, &MapKey, &ItemSize, &Version);
}
if (EFI_ERROR(Status)) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MEMMAP_GET_FAILED), gShellDebug1HiiHandle, L"memmap");
@@ -171,78 +171,81 @@ ShellCommandRunMemMap (
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_SFO_HEADER), gShellDebug1HiiHandle, L"memmap");
}
- for (Walker = (UINT8*)Buffer; Walker < (((UINT8*)Buffer)+Size) && Walker != NULL; Walker += ItemSize){
- switch (((EFI_MEMORY_DESCRIPTOR*)Walker)->Type) {
+ for ( Walker = Descriptors
+ ; (Walker < (EFI_MEMORY_DESCRIPTOR *) ((UINT8*)Descriptors + Size)) && (Walker != NULL)
+ ; Walker = (EFI_MEMORY_DESCRIPTOR *) ((UINT8 *)Walker + ItemSize)
+ ){
+ switch (Walker->Type) {
case EfiReservedMemoryType:
- ShellPrintHiiEx(-1, -1, NULL, (EFI_STRING_ID)(!Sfo?STRING_TOKEN (STR_MEMMAP_LIST_ITEM):STRING_TOKEN (STR_MEMMAP_LIST_ITEM_SFO)), gShellDebug1HiiHandle, NameEfiReservedMemoryType, ((EFI_MEMORY_DESCRIPTOR*)Walker)->PhysicalStart, ((EFI_MEMORY_DESCRIPTOR*)Walker)->PhysicalStart+MultU64x64(SIZE_4KB,((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages)-1, ((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages, ((EFI_MEMORY_DESCRIPTOR*)Walker)->Attribute);
- ReservedPages += ((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages;
+ ShellPrintHiiEx(-1, -1, NULL, (EFI_STRING_ID)(!Sfo?STRING_TOKEN (STR_MEMMAP_LIST_ITEM):STRING_TOKEN (STR_MEMMAP_LIST_ITEM_SFO)), gShellDebug1HiiHandle, NameEfiReservedMemoryType, Walker->PhysicalStart, Walker->PhysicalStart+MultU64x64(SIZE_4KB,Walker->NumberOfPages)-1, Walker->NumberOfPages, Walker->Attribute);
+ ReservedPages += Walker->NumberOfPages;
break;
case EfiLoaderCode:
- ShellPrintHiiEx(-1, -1, NULL, (EFI_STRING_ID)(!Sfo?STRING_TOKEN (STR_MEMMAP_LIST_ITEM):STRING_TOKEN (STR_MEMMAP_LIST_ITEM_SFO)), gShellDebug1HiiHandle, NameEfiLoaderCode, ((EFI_MEMORY_DESCRIPTOR*)Walker)->PhysicalStart, ((EFI_MEMORY_DESCRIPTOR*)Walker)->PhysicalStart+MultU64x64(SIZE_4KB,((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages)-1, ((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages, ((EFI_MEMORY_DESCRIPTOR*)Walker)->Attribute);
- LoadCodePages += ((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages;
- TotalPages += ((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages;
+ ShellPrintHiiEx(-1, -1, NULL, (EFI_STRING_ID)(!Sfo?STRING_TOKEN (STR_MEMMAP_LIST_ITEM):STRING_TOKEN (STR_MEMMAP_LIST_ITEM_SFO)), gShellDebug1HiiHandle, NameEfiLoaderCode, Walker->PhysicalStart, Walker->PhysicalStart+MultU64x64(SIZE_4KB,Walker->NumberOfPages)-1, Walker->NumberOfPages, Walker->Attribute);
+ LoadCodePages += Walker->NumberOfPages;
+ TotalPages += Walker->NumberOfPages;
break;
case EfiLoaderData:
- ShellPrintHiiEx(-1, -1, NULL, (EFI_STRING_ID)(!Sfo?STRING_TOKEN (STR_MEMMAP_LIST_ITEM):STRING_TOKEN (STR_MEMMAP_LIST_ITEM_SFO)), gShellDebug1HiiHandle, NameEfiLoaderData, ((EFI_MEMORY_DESCRIPTOR*)Walker)->PhysicalStart, ((EFI_MEMORY_DESCRIPTOR*)Walker)->PhysicalStart+MultU64x64(SIZE_4KB,((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages)-1, ((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages, ((EFI_MEMORY_DESCRIPTOR*)Walker)->Attribute);
- LoadDataPages += ((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages;
- TotalPages += ((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages;
+ ShellPrintHiiEx(-1, -1, NULL, (EFI_STRING_ID)(!Sfo?STRING_TOKEN (STR_MEMMAP_LIST_ITEM):STRING_TOKEN (STR_MEMMAP_LIST_ITEM_SFO)), gShellDebug1HiiHandle, NameEfiLoaderData, Walker->PhysicalStart, Walker->PhysicalStart+MultU64x64(SIZE_4KB,Walker->NumberOfPages)-1, Walker->NumberOfPages, Walker->Attribute);
+ LoadDataPages += Walker->NumberOfPages;
+ TotalPages += Walker->NumberOfPages;
break;
case EfiBootServicesCode:
- ShellPrintHiiEx(-1, -1, NULL, (EFI_STRING_ID)(!Sfo?STRING_TOKEN (STR_MEMMAP_LIST_ITEM):STRING_TOKEN (STR_MEMMAP_LIST_ITEM_SFO)), gShellDebug1HiiHandle, !Sfo?NameEfiBootServicesCodeShort:NameEfiBootServicesCode, ((EFI_MEMORY_DESCRIPTOR*)Walker)->PhysicalStart, ((EFI_MEMORY_DESCRIPTOR*)Walker)->PhysicalStart+MultU64x64(SIZE_4KB,((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages)-1, ((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages, ((EFI_MEMORY_DESCRIPTOR*)Walker)->Attribute);
- BSCodePages += ((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages;
- TotalPages += ((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages;
+ ShellPrintHiiEx(-1, -1, NULL, (EFI_STRING_ID)(!Sfo?STRING_TOKEN (STR_MEMMAP_LIST_ITEM):STRING_TOKEN (STR_MEMMAP_LIST_ITEM_SFO)), gShellDebug1HiiHandle, !Sfo?NameEfiBootServicesCodeShort:NameEfiBootServicesCode, Walker->PhysicalStart, Walker->PhysicalStart+MultU64x64(SIZE_4KB,Walker->NumberOfPages)-1, Walker->NumberOfPages, Walker->Attribute);
+ BSCodePages += Walker->NumberOfPages;
+ TotalPages += Walker->NumberOfPages;
break;
case EfiBootServicesData:
- ShellPrintHiiEx(-1, -1, NULL, (EFI_STRING_ID)(!Sfo?STRING_TOKEN (STR_MEMMAP_LIST_ITEM):STRING_TOKEN (STR_MEMMAP_LIST_ITEM_SFO)), gShellDebug1HiiHandle, !Sfo?NameEfiBootServicesDataShort:NameEfiBootServicesData, ((EFI_MEMORY_DESCRIPTOR*)Walker)->PhysicalStart, ((EFI_MEMORY_DESCRIPTOR*)Walker)->PhysicalStart+MultU64x64(SIZE_4KB,((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages)-1, ((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages, ((EFI_MEMORY_DESCRIPTOR*)Walker)->Attribute);
- BSDataPages += ((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages;
- TotalPages += ((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages;
+ ShellPrintHiiEx(-1, -1, NULL, (EFI_STRING_ID)(!Sfo?STRING_TOKEN (STR_MEMMAP_LIST_ITEM):STRING_TOKEN (STR_MEMMAP_LIST_ITEM_SFO)), gShellDebug1HiiHandle, !Sfo?NameEfiBootServicesDataShort:NameEfiBootServicesData, Walker->PhysicalStart, Walker->PhysicalStart+MultU64x64(SIZE_4KB,Walker->NumberOfPages)-1, Walker->NumberOfPages, Walker->Attribute);
+ BSDataPages += Walker->NumberOfPages;
+ TotalPages += Walker->NumberOfPages;
break;
case EfiRuntimeServicesCode:
- ShellPrintHiiEx(-1, -1, NULL, (EFI_STRING_ID)(!Sfo?STRING_TOKEN (STR_MEMMAP_LIST_ITEM):STRING_TOKEN (STR_MEMMAP_LIST_ITEM_SFO)), gShellDebug1HiiHandle, !Sfo?NameEfiRuntimeServicesCodeShort:NameEfiRuntimeServicesCode, ((EFI_MEMORY_DESCRIPTOR*)Walker)->PhysicalStart, ((EFI_MEMORY_DESCRIPTOR*)Walker)->PhysicalStart+MultU64x64(SIZE_4KB,((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages)-1, ((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages, ((EFI_MEMORY_DESCRIPTOR*)Walker)->Attribute);
- RTCodePages += ((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages;
- TotalPages += ((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages;
+ ShellPrintHiiEx(-1, -1, NULL, (EFI_STRING_ID)(!Sfo?STRING_TOKEN (STR_MEMMAP_LIST_ITEM):STRING_TOKEN (STR_MEMMAP_LIST_ITEM_SFO)), gShellDebug1HiiHandle, !Sfo?NameEfiRuntimeServicesCodeShort:NameEfiRuntimeServicesCode, Walker->PhysicalStart, Walker->PhysicalStart+MultU64x64(SIZE_4KB,Walker->NumberOfPages)-1, Walker->NumberOfPages, Walker->Attribute);
+ RTCodePages += Walker->NumberOfPages;
+ TotalPages += Walker->NumberOfPages;
break;
case EfiRuntimeServicesData:
- ShellPrintHiiEx(-1, -1, NULL, (EFI_STRING_ID)(!Sfo?STRING_TOKEN (STR_MEMMAP_LIST_ITEM):STRING_TOKEN (STR_MEMMAP_LIST_ITEM_SFO)), gShellDebug1HiiHandle, !Sfo?NameEfiRuntimeServicesDataShort:NameEfiRuntimeServicesData, ((EFI_MEMORY_DESCRIPTOR*)Walker)->PhysicalStart, ((EFI_MEMORY_DESCRIPTOR*)Walker)->PhysicalStart+MultU64x64(SIZE_4KB,((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages)-1, ((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages, ((EFI_MEMORY_DESCRIPTOR*)Walker)->Attribute);
- RTDataPages += ((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages;
- TotalPages += ((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages;
+ ShellPrintHiiEx(-1, -1, NULL, (EFI_STRING_ID)(!Sfo?STRING_TOKEN (STR_MEMMAP_LIST_ITEM):STRING_TOKEN (STR_MEMMAP_LIST_ITEM_SFO)), gShellDebug1HiiHandle, !Sfo?NameEfiRuntimeServicesDataShort:NameEfiRuntimeServicesData, Walker->PhysicalStart, Walker->PhysicalStart+MultU64x64(SIZE_4KB,Walker->NumberOfPages)-1, Walker->NumberOfPages, Walker->Attribute);
+ RTDataPages += Walker->NumberOfPages;
+ TotalPages += Walker->NumberOfPages;
break;
case EfiConventionalMemory:
- ShellPrintHiiEx(-1, -1, NULL, (EFI_STRING_ID)(!Sfo?STRING_TOKEN (STR_MEMMAP_LIST_ITEM):STRING_TOKEN (STR_MEMMAP_LIST_ITEM_SFO)), gShellDebug1HiiHandle, NameEfiConventionalMemory, ((EFI_MEMORY_DESCRIPTOR*)Walker)->PhysicalStart, ((EFI_MEMORY_DESCRIPTOR*)Walker)->PhysicalStart+MultU64x64(SIZE_4KB,((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages)-1, ((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages, ((EFI_MEMORY_DESCRIPTOR*)Walker)->Attribute);
- AvailPages += ((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages;
- TotalPages += ((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages;
+ ShellPrintHiiEx(-1, -1, NULL, (EFI_STRING_ID)(!Sfo?STRING_TOKEN (STR_MEMMAP_LIST_ITEM):STRING_TOKEN (STR_MEMMAP_LIST_ITEM_SFO)), gShellDebug1HiiHandle, NameEfiConventionalMemory, Walker->PhysicalStart, Walker->PhysicalStart+MultU64x64(SIZE_4KB,Walker->NumberOfPages)-1, Walker->NumberOfPages, Walker->Attribute);
+ AvailPages += Walker->NumberOfPages;
+ TotalPages += Walker->NumberOfPages;
break;
case EfiPersistentMemory:
- ShellPrintHiiEx(-1, -1, NULL, (EFI_STRING_ID)(!Sfo?STRING_TOKEN (STR_MEMMAP_LIST_ITEM):STRING_TOKEN (STR_MEMMAP_LIST_ITEM_SFO)), gShellDebug1HiiHandle, NameEfiPersistentMemory, ((EFI_MEMORY_DESCRIPTOR*)Walker)->PhysicalStart, ((EFI_MEMORY_DESCRIPTOR*)Walker)->PhysicalStart+MultU64x64(SIZE_4KB,((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages)-1, ((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages, ((EFI_MEMORY_DESCRIPTOR*)Walker)->Attribute);
- PersistentPages += ((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages;
- TotalPages += ((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages;
+ ShellPrintHiiEx(-1, -1, NULL, (EFI_STRING_ID)(!Sfo?STRING_TOKEN (STR_MEMMAP_LIST_ITEM):STRING_TOKEN (STR_MEMMAP_LIST_ITEM_SFO)), gShellDebug1HiiHandle, NameEfiPersistentMemory, Walker->PhysicalStart, Walker->PhysicalStart+MultU64x64(SIZE_4KB,Walker->NumberOfPages)-1, Walker->NumberOfPages, Walker->Attribute);
+ PersistentPages += Walker->NumberOfPages;
+ TotalPages += Walker->NumberOfPages;
break;
case EfiUnusableMemory:
- ShellPrintHiiEx(-1, -1, NULL, (EFI_STRING_ID)(!Sfo?STRING_TOKEN (STR_MEMMAP_LIST_ITEM):STRING_TOKEN (STR_MEMMAP_LIST_ITEM_SFO)), gShellDebug1HiiHandle, !Sfo?NameEfiUnusableMemoryShort:NameEfiUnusableMemory, ((EFI_MEMORY_DESCRIPTOR*)Walker)->PhysicalStart, ((EFI_MEMORY_DESCRIPTOR*)Walker)->PhysicalStart+MultU64x64(SIZE_4KB,((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages)-1, ((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages, ((EFI_MEMORY_DESCRIPTOR*)Walker)->Attribute);
- UnusableMemoryPages += ((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages;
+ ShellPrintHiiEx(-1, -1, NULL, (EFI_STRING_ID)(!Sfo?STRING_TOKEN (STR_MEMMAP_LIST_ITEM):STRING_TOKEN (STR_MEMMAP_LIST_ITEM_SFO)), gShellDebug1HiiHandle, !Sfo?NameEfiUnusableMemoryShort:NameEfiUnusableMemory, Walker->PhysicalStart, Walker->PhysicalStart+MultU64x64(SIZE_4KB,Walker->NumberOfPages)-1, Walker->NumberOfPages, Walker->Attribute);
+ UnusableMemoryPages += Walker->NumberOfPages;
break;
case EfiACPIReclaimMemory:
- ShellPrintHiiEx(-1, -1, NULL, (EFI_STRING_ID)(!Sfo?STRING_TOKEN (STR_MEMMAP_LIST_ITEM):STRING_TOKEN (STR_MEMMAP_LIST_ITEM_SFO)), gShellDebug1HiiHandle, !Sfo?NameEfiACPIReclaimMemoryShort:NameEfiACPIReclaimMemory, ((EFI_MEMORY_DESCRIPTOR*)Walker)->PhysicalStart, ((EFI_MEMORY_DESCRIPTOR*)Walker)->PhysicalStart+MultU64x64(SIZE_4KB,((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages)-1, ((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages, ((EFI_MEMORY_DESCRIPTOR*)Walker)->Attribute);
- TotalPages += ((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages;
- AcpiReclaimPages += ((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages;
+ ShellPrintHiiEx(-1, -1, NULL, (EFI_STRING_ID)(!Sfo?STRING_TOKEN (STR_MEMMAP_LIST_ITEM):STRING_TOKEN (STR_MEMMAP_LIST_ITEM_SFO)), gShellDebug1HiiHandle, !Sfo?NameEfiACPIReclaimMemoryShort:NameEfiACPIReclaimMemory, Walker->PhysicalStart, Walker->PhysicalStart+MultU64x64(SIZE_4KB,Walker->NumberOfPages)-1, Walker->NumberOfPages, Walker->Attribute);
+ TotalPages += Walker->NumberOfPages;
+ AcpiReclaimPages += Walker->NumberOfPages;
break;
case EfiACPIMemoryNVS:
- ShellPrintHiiEx(-1, -1, NULL, (EFI_STRING_ID)(!Sfo?STRING_TOKEN (STR_MEMMAP_LIST_ITEM):STRING_TOKEN (STR_MEMMAP_LIST_ITEM_SFO)), gShellDebug1HiiHandle, !Sfo?NameEfiACPIMemoryNVSShort:NameEfiACPIMemoryNVS, ((EFI_MEMORY_DESCRIPTOR*)Walker)->PhysicalStart, ((EFI_MEMORY_DESCRIPTOR*)Walker)->PhysicalStart+MultU64x64(SIZE_4KB,((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages)-1, ((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages, ((EFI_MEMORY_DESCRIPTOR*)Walker)->Attribute);
- TotalPages += ((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages;
- AcpiNvsPages += ((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages;
+ ShellPrintHiiEx(-1, -1, NULL, (EFI_STRING_ID)(!Sfo?STRING_TOKEN (STR_MEMMAP_LIST_ITEM):STRING_TOKEN (STR_MEMMAP_LIST_ITEM_SFO)), gShellDebug1HiiHandle, !Sfo?NameEfiACPIMemoryNVSShort:NameEfiACPIMemoryNVS, Walker->PhysicalStart, Walker->PhysicalStart+MultU64x64(SIZE_4KB,Walker->NumberOfPages)-1, Walker->NumberOfPages, Walker->Attribute);
+ TotalPages += Walker->NumberOfPages;
+ AcpiNvsPages += Walker->NumberOfPages;
break;
case EfiMemoryMappedIO:
- ShellPrintHiiEx(-1, -1, NULL, (EFI_STRING_ID)(!Sfo?STRING_TOKEN (STR_MEMMAP_LIST_ITEM):STRING_TOKEN (STR_MEMMAP_LIST_ITEM_SFO)), gShellDebug1HiiHandle, !Sfo?NameEfiMemoryMappedIOShort:NameEfiMemoryMappedIO, ((EFI_MEMORY_DESCRIPTOR*)Walker)->PhysicalStart, ((EFI_MEMORY_DESCRIPTOR*)Walker)->PhysicalStart+MultU64x64(SIZE_4KB,((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages)-1, ((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages, ((EFI_MEMORY_DESCRIPTOR*)Walker)->Attribute);
- MmioSpacePages += ((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages;
+ ShellPrintHiiEx(-1, -1, NULL, (EFI_STRING_ID)(!Sfo?STRING_TOKEN (STR_MEMMAP_LIST_ITEM):STRING_TOKEN (STR_MEMMAP_LIST_ITEM_SFO)), gShellDebug1HiiHandle, !Sfo?NameEfiMemoryMappedIOShort:NameEfiMemoryMappedIO, Walker->PhysicalStart, Walker->PhysicalStart+MultU64x64(SIZE_4KB,Walker->NumberOfPages)-1, Walker->NumberOfPages, Walker->Attribute);
+ MmioSpacePages += Walker->NumberOfPages;
break;
case EfiMemoryMappedIOPortSpace:
- ShellPrintHiiEx(-1, -1, NULL, (EFI_STRING_ID)(!Sfo?STRING_TOKEN (STR_MEMMAP_LIST_ITEM):STRING_TOKEN (STR_MEMMAP_LIST_ITEM_SFO)), gShellDebug1HiiHandle, !Sfo?NameEfiMemoryMappedIOPortSpaceShort:NameEfiMemoryMappedIOPortSpace, ((EFI_MEMORY_DESCRIPTOR*)Walker)->PhysicalStart, ((EFI_MEMORY_DESCRIPTOR*)Walker)->PhysicalStart+MultU64x64(SIZE_4KB,((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages)-1, ((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages, ((EFI_MEMORY_DESCRIPTOR*)Walker)->Attribute);
- MmioPortPages += ((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages;
+ ShellPrintHiiEx(-1, -1, NULL, (EFI_STRING_ID)(!Sfo?STRING_TOKEN (STR_MEMMAP_LIST_ITEM):STRING_TOKEN (STR_MEMMAP_LIST_ITEM_SFO)), gShellDebug1HiiHandle, !Sfo?NameEfiMemoryMappedIOPortSpaceShort:NameEfiMemoryMappedIOPortSpace, Walker->PhysicalStart, Walker->PhysicalStart+MultU64x64(SIZE_4KB,Walker->NumberOfPages)-1, Walker->NumberOfPages, Walker->Attribute);
+ MmioPortPages += Walker->NumberOfPages;
break;
case EfiPalCode:
- ShellPrintHiiEx(-1, -1, NULL, (EFI_STRING_ID)(!Sfo?STRING_TOKEN (STR_MEMMAP_LIST_ITEM):STRING_TOKEN (STR_MEMMAP_LIST_ITEM_SFO)), gShellDebug1HiiHandle, NameEfiPalCode, ((EFI_MEMORY_DESCRIPTOR*)Walker)->PhysicalStart, ((EFI_MEMORY_DESCRIPTOR*)Walker)->PhysicalStart+MultU64x64(SIZE_4KB,((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages)-1, ((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages, ((EFI_MEMORY_DESCRIPTOR*)Walker)->Attribute);
- TotalPages += ((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages;
- PalCodePages += ((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages;
+ ShellPrintHiiEx(-1, -1, NULL, (EFI_STRING_ID)(!Sfo?STRING_TOKEN (STR_MEMMAP_LIST_ITEM):STRING_TOKEN (STR_MEMMAP_LIST_ITEM_SFO)), gShellDebug1HiiHandle, NameEfiPalCode, Walker->PhysicalStart, Walker->PhysicalStart+MultU64x64(SIZE_4KB,Walker->NumberOfPages)-1, Walker->NumberOfPages, Walker->Attribute);
+ TotalPages += Walker->NumberOfPages;
+ PalCodePages += Walker->NumberOfPages;
break;
default:
ASSERT(FALSE);
@@ -310,8 +313,8 @@ ShellCommandRunMemMap (
ShellCommandLineFreeVarList (Package);
}
- if (Buffer != NULL) {
- FreePool(Buffer);
+ if (Descriptors != NULL) {
+ FreePool(Descriptors);
}
return (ShellStatus);
--
2.12.2.windows.2
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 2/2] ShellPkg/memmap: Dump memory map information for all memory types
2017-05-11 10:27 [PATCH 0/2] ShellPkg/memmap: Dump memory map information for all memory types Ruiyu Ni
2017-05-11 10:27 ` [PATCH 1/2] ShellPkg/memmap: Refine code Ruiyu Ni
@ 2017-05-11 10:27 ` Ruiyu Ni
2017-05-11 16:23 ` [PATCH 0/2] " Carsey, Jaben
2 siblings, 0 replies; 4+ messages in thread
From: Ruiyu Ni @ 2017-05-11 10:27 UTC (permalink / raw)
To: edk2-devel; +Cc: Jaben Carsey
The patch dumps memory map information for all memory types.
But to follow the SFO format of "memmap" defined in Shell 2.2 spec,
the patch doesn't dump the memory map information for OEM/OS
memory types. But it does include the OEM/OS memory in the total
size in SFO format.
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com>
Cc: Jaben Carsey <jaben.carsey@intel.com>
---
.../Library/UefiShellDebug1CommandsLib/MemMap.c | 92 +++++++++++++++++++++-
.../UefiShellDebug1CommandsLib.uni | 4 +-
2 files changed, 93 insertions(+), 3 deletions(-)
diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/MemMap.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/MemMap.c
index a99e3c4723..c856661917 100644
--- a/ShellPkg/Library/UefiShellDebug1CommandsLib/MemMap.c
+++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/MemMap.c
@@ -48,6 +48,61 @@ STATIC CONST CHAR16 NameEfiMemoryMappedIOPortSpaceShort[] = L"MMIO_Port";
#include "UefiShellDebug1CommandsLib.h"
+typedef struct {
+ UINT32 Type;
+ UINT64 NumberOfPages;
+ LIST_ENTRY Link;
+} MEMORY_LENGTH_ENTRY;
+
+/**
+ Add the length of the specified type to List.
+
+ @param List A list to hold all pairs of <Type, NumberOfPages>.
+ @param Type Memory type.
+ @param NumberOfPages Number of pages.
+**/
+VOID
+AddMemoryLength (
+ LIST_ENTRY *List,
+ UINT32 Type,
+ UINT64 NumberOfPages
+ )
+{
+ MEMORY_LENGTH_ENTRY *Entry;
+ MEMORY_LENGTH_ENTRY *NewEntry;
+ LIST_ENTRY *Link;
+
+ Entry = NULL;
+ for (Link = GetFirstNode (List); !IsNull (List, Link); Link = GetNextNode (List, Link)) {
+ Entry = BASE_CR (Link, MEMORY_LENGTH_ENTRY, Link);
+ if (Entry->Type >= Type) {
+ break;
+ }
+ }
+
+ if ((Entry != NULL) && (Entry->Type == Type)) {
+ //
+ // The Entry is the one we look for.
+ //
+ NewEntry = Entry;
+ } else {
+ //
+ // The search operation breaks due to:
+ // 1. Type of every entry < Type --> Insert to tail
+ // 2. Type of an entry > Type --> Insert to previous of this entry
+ //
+ NewEntry = AllocatePool (sizeof (*NewEntry));
+ if (NewEntry == NULL) {
+ return;
+ }
+ NewEntry->Type = Type;
+ NewEntry->NumberOfPages = 0;
+ InsertTailList (Link, &NewEntry->Link);
+ }
+
+ NewEntry->NumberOfPages += NumberOfPages;
+}
+
/**
Function for 'memmap' command.
@@ -104,6 +159,9 @@ ShellCommandRunMemMap (
UINT64 PersistentPages;
UINT64 PersistentPagesSize;
BOOLEAN Sfo;
+ LIST_ENTRY MemoryList;
+ MEMORY_LENGTH_ENTRY *Entry;
+ LIST_ENTRY *Link;
AcpiReclaimPages = 0;
AcpiNvsPages = 0;
@@ -125,6 +183,7 @@ ShellCommandRunMemMap (
Descriptors = NULL;
ShellStatus = SHELL_SUCCESS;
Status = EFI_SUCCESS;
+ InitializeListHead (&MemoryList);
//
// initialize the shell lib (we must be in non-auto-init...)
@@ -248,7 +307,16 @@ ShellCommandRunMemMap (
PalCodePages += Walker->NumberOfPages;
break;
default:
- ASSERT(FALSE);
+ //
+ // Shell Spec defines the SFO format.
+ // Do not print the OEM/OS memory usage in the SFO format, to avoid conflict with Shell Spec.
+ //
+ if (!Sfo) {
+ ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_MEMMAP_LIST_ITEM_OTHER), gShellDebug1HiiHandle, Walker->Type, Walker->PhysicalStart, Walker->PhysicalStart + MultU64x64 (SIZE_4KB, Walker->NumberOfPages) - 1, Walker->NumberOfPages, Walker->Attribute);
+ }
+ TotalPages += Walker->NumberOfPages;
+ AddMemoryLength (&MemoryList, Walker->Type, Walker->NumberOfPages);
+ break;
}
}
//
@@ -285,7 +353,20 @@ ShellCommandRunMemMap (
MmioPortPages, MmioPortPagesSize,
PalCodePages, PalCodePagesSize,
AvailPages, AvailPagesSize,
- PersistentPages, PersistentPagesSize,
+ PersistentPages, PersistentPagesSize
+ );
+
+ //
+ // Print out the total memory usage for OEM/OS types in the order of type.
+ //
+ for (Link = GetFirstNode (&MemoryList); !IsNull (&MemoryList, Link); Link = GetNextNode (&MemoryList, Link)) {
+ Entry = BASE_CR (Link, MEMORY_LENGTH_ENTRY, Link);
+ ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_MEMMAP_LIST_SUMM_OTHER), gShellDebug1HiiHandle,
+ Entry->Type, Entry->NumberOfPages, MultU64x64 (SIZE_4KB, Entry->NumberOfPages)
+ );
+ }
+
+ ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_MEMMAP_LIST_SUMM2), gShellDebug1HiiHandle,
DivU64x32(MultU64x64(SIZE_4KB,TotalPages), SIZE_1MB), TotalPagesSize
);
} else {
@@ -317,6 +398,13 @@ ShellCommandRunMemMap (
FreePool(Descriptors);
}
+ //
+ // Free the memory list.
+ //
+ for (Link = GetFirstNode (&MemoryList); !IsNull (&MemoryList, Link); ) {
+ Link = RemoveEntryList (Link);
+ }
+
return (ShellStatus);
}
diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1CommandsLib.uni b/ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1CommandsLib.uni
index 6c02abeeac..ee726cbbd4 100644
--- a/ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1CommandsLib.uni
+++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1CommandsLib.uni
@@ -79,6 +79,7 @@
#string STR_MEMMAP_GET_FAILED #language en-US "%H%s%N: Unable to get memory map\r\n"
#string STR_MEMMAP_LIST_HEAD #language en-US "Type Start End # Pages Attributes\r\n"
#string STR_MEMMAP_LIST_ITEM #language en-US "% -10s %016LX-%016LX %016LX %016LX\r\n"
+#string STR_MEMMAP_LIST_ITEM_OTHER #language en-US "%08x %016LX-%016LX %016LX %016LX\r\n"
#string STR_MEMMAP_LIST_SUMM #language en-US " \r\n"
" Reserved : %,14ld Pages (%,ld Bytes)\r\n"
" LoaderCode: %,14ld Pages (%,ld Bytes)\r\n"
@@ -94,7 +95,8 @@
" PalCode : %,14ld Pages (%,ld Bytes)\r\n"
" Available : %,14ld Pages (%,ld Bytes)\r\n"
" Persistent: %,14ld Pages (%,ld Bytes)\r\n"
- " -------------- \r\n"
+#string STR_MEMMAP_LIST_SUMM_OTHER #language en-US " %08x : %,14ld Pages (%,ld Bytes)\r\n"
+#string STR_MEMMAP_LIST_SUMM2 #language en-US " -------------- \r\n"
"Total Memory: %,14ld MB (%,ld Bytes)\r\n"
#string STR_MEMMAP_LIST_ITEM_SFO #language en-US "MemoryMap,"%s","%LX","%LX","%LX","%LX"\r\n"
#string STR_MEMMAP_LIST_SUMM_SFO #language en-US "MemoryMapSummary,"%Ld","%Ld","%Ld","%Ld","%Ld","%Ld","%Ld","%Ld","%Ld","%Ld","%Ld","%Ld","%Ld","%Ld","%Ld","%Ld"\r\n"
--
2.12.2.windows.2
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH 0/2] ShellPkg/memmap: Dump memory map information for all memory types
2017-05-11 10:27 [PATCH 0/2] ShellPkg/memmap: Dump memory map information for all memory types Ruiyu Ni
2017-05-11 10:27 ` [PATCH 1/2] ShellPkg/memmap: Refine code Ruiyu Ni
2017-05-11 10:27 ` [PATCH 2/2] ShellPkg/memmap: Dump memory map information for all memory types Ruiyu Ni
@ 2017-05-11 16:23 ` Carsey, Jaben
2 siblings, 0 replies; 4+ messages in thread
From: Carsey, Jaben @ 2017-05-11 16:23 UTC (permalink / raw)
To: Ni, Ruiyu, edk2-devel@lists.01.org
For series.
Reviewed-by: Jaben Carsey <jaben.carsey@intel.com>
> -----Original Message-----
> From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of
> Ruiyu Ni
> Sent: Thursday, May 11, 2017 3:27 AM
> To: edk2-devel@lists.01.org
> Subject: [edk2] [PATCH 0/2] ShellPkg/memmap: Dump memory map
> information for all memory types
> Importance: High
>
> The patch dumps memory map information for all memory types.
> But to follow the SFO format of "memmap" defined in Shell 2.2 spec,
> the patch doesn't dump the memory map information for OEM/OS
> memory types. But it does include the OEM/OS memory in the total
> size in SFO format.
>
> Ruiyu Ni (2):
> ShellPkg/memmap: Refine code
> ShellPkg/memmap: Dump memory map information for all memory types
>
> .../Library/UefiShellDebug1CommandsLib/MemMap.c | 199
> +++++++++++++++------
> .../UefiShellDebug1CommandsLib.uni | 4 +-
> 2 files changed, 148 insertions(+), 55 deletions(-)
>
> --
> 2.12.2.windows.2
>
> _______________________________________________
> edk2-devel mailing list
> edk2-devel@lists.01.org
> https://lists.01.org/mailman/listinfo/edk2-devel
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2017-05-11 16:23 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-05-11 10:27 [PATCH 0/2] ShellPkg/memmap: Dump memory map information for all memory types Ruiyu Ni
2017-05-11 10:27 ` [PATCH 1/2] ShellPkg/memmap: Refine code Ruiyu Ni
2017-05-11 10:27 ` [PATCH 2/2] ShellPkg/memmap: Dump memory map information for all memory types Ruiyu Ni
2017-05-11 16:23 ` [PATCH 0/2] " Carsey, Jaben
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox