From nobody Sun Dec 29 02:56:16 2024 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Authentication-Results: mx.zoho.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org; Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1494498440727417.5778015566963; Thu, 11 May 2017 03:27:20 -0700 (PDT) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 53A8D2095C872; Thu, 11 May 2017 03:27:14 -0700 (PDT) Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id A508F21A16E36 for ; Thu, 11 May 2017 03:27:13 -0700 (PDT) Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 11 May 2017 03:27:13 -0700 Received: from ray-dev.ccr.corp.intel.com ([10.239.9.15]) by orsmga005.jf.intel.com with ESMTP; 11 May 2017 03:27:12 -0700 X-Original-To: edk2-devel@lists.01.org X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.38,323,1491289200"; d="scan'208";a="98630281" From: Ruiyu Ni To: edk2-devel@lists.01.org Date: Thu, 11 May 2017 18:27:06 +0800 Message-Id: <20170511102706.89404-3-ruiyu.ni@intel.com> X-Mailer: git-send-email 2.12.2.windows.2 In-Reply-To: <20170511102706.89404-1-ruiyu.ni@intel.com> References: <20170511102706.89404-1-ruiyu.ni@intel.com> Subject: [edk2] [PATCH 2/2] ShellPkg/memmap: Dump memory map information for all memory types X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jaben Carsey MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" 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 Cc: Jaben Carsey --- .../Library/UefiShellDebug1CommandsLib/MemMap.c | 92 ++++++++++++++++++= +++- .../UefiShellDebug1CommandsLib.uni | 4 +- 2 files changed, 93 insertions(+), 3 deletions(-) diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/MemMap.c b/ShellPk= g/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[= ] =3D L"MMIO_Port"; =20 #include "UefiShellDebug1CommandsLib.h" =20 +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 . + @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 =3D NULL; + for (Link =3D GetFirstNode (List); !IsNull (List, Link); Link =3D GetNex= tNode (List, Link)) { + Entry =3D BASE_CR (Link, MEMORY_LENGTH_ENTRY, Link); + if (Entry->Type >=3D Type) { + break; + } + } + + if ((Entry !=3D NULL) && (Entry->Type =3D=3D Type)) { + // + // The Entry is the one we look for. + // + NewEntry =3D 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 =3D AllocatePool (sizeof (*NewEntry)); + if (NewEntry =3D=3D NULL) { + return; + } + NewEntry->Type =3D Type; + NewEntry->NumberOfPages =3D 0; + InsertTailList (Link, &NewEntry->Link); + } + + NewEntry->NumberOfPages +=3D NumberOfPages; +} + /** Function for 'memmap' command. =20 @@ -104,6 +159,9 @@ ShellCommandRunMemMap ( UINT64 PersistentPages; UINT64 PersistentPagesSize; BOOLEAN Sfo; + LIST_ENTRY MemoryList; + MEMORY_LENGTH_ENTRY *Entry; + LIST_ENTRY *Link; =20 AcpiReclaimPages =3D 0; AcpiNvsPages =3D 0; @@ -125,6 +183,7 @@ ShellCommandRunMemMap ( Descriptors =3D NULL; ShellStatus =3D SHELL_SUCCESS; Status =3D EFI_SUCCESS; + InitializeListHead (&MemoryList); =20 // // initialize the shell lib (we must be in non-auto-init...) @@ -248,7 +307,16 @@ ShellCommandRunMemMap ( PalCodePages +=3D Walker->NumberOfPages; break; default: - ASSERT(FALSE); + // + // Shell Spec defines the SFO format. + // Do not print the OEM/OS memory usage in the SFO format, t= o avoid conflict with Shell Spec. + // + if (!Sfo) { + ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_MEMMAP_LI= ST_ITEM_OTHER), gShellDebug1HiiHandle, Walker->Type, Walker->PhysicalStart,= Walker->PhysicalStart + MultU64x64 (SIZE_4KB, Walker->NumberOfPages) - 1, = Walker->NumberOfPages, Walker->Attribute); + } + TotalPages +=3D Walker->NumberOfPages; + AddMemoryLength (&MemoryList, Walker->Type, Walker->NumberOf= Pages); + 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 orde= r of type. + // + for (Link =3D GetFirstNode (&MemoryList); !IsNull (&MemoryList, = Link); Link =3D GetNextNode (&MemoryList, Link)) { + Entry =3D BASE_CR (Link, MEMORY_LENGTH_ENTRY, Link); + ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_MEMMAP_LIST_S= UMM_OTHER), gShellDebug1HiiHandle, + Entry->Type, Entry->NumberOfPages, MultU64x64 (SIZE_4KB, Ent= ry->NumberOfPages) + ); + } + + ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_MEMMAP_LIST_SUM= M2), gShellDebug1HiiHandle, DivU64x32(MultU64x64(SIZE_4KB,TotalPages), SIZE_1MB), TotalPag= esSize ); } else { @@ -317,6 +398,13 @@ ShellCommandRunMemMap ( FreePool(Descriptors); } =20 + // + // Free the memory list. + // + for (Link =3D GetFirstNode (&MemoryList); !IsNull (&MemoryList, Link); )= { + Link =3D RemoveEntryList (Link); + } + return (ShellStatus); } =20 diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1Com= mandsLib.uni b/ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1C= ommandsLib.uni index 6c02abeeac..ee726cbbd4 100644 --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1CommandsLi= b.uni +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1CommandsLi= b.uni @@ -79,6 +79,7 @@ #string STR_MEMMAP_GET_FAILED #language en-US "%H%s%N: Unable to get m= emory 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 %0= 16LX %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 Pa= ges (%,ld Bytes)\r\n" " LoaderCode: %,14ld Pa= ges (%,ld Bytes)\r\n" @@ -94,7 +95,8 @@ " PalCode : %,14ld Pa= ges (%,ld Bytes)\r\n" " Available : %,14ld Pa= ges (%,ld Bytes)\r\n" " Persistent: %,14ld Pa= ges (%,ld Bytes)\r\n" - " ---------= ----- \r\n" +#string STR_MEMMAP_LIST_SUMM_OTHER #language en-US " %08x : %,14ld Pa= ges (%,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","%L= d","%Ld","%Ld"\r\n" --=20 2.12.2.windows.2 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel