From nobody Sun Apr 28 20:42:41 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.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 1512381663660688.330014451189; Mon, 4 Dec 2017 02:01:03 -0800 (PST) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 9CAC1220EE086; Mon, 4 Dec 2017 01:56:32 -0800 (PST) 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 F2A4A220EE07C for ; Mon, 4 Dec 2017 01:56:30 -0800 (PST) Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 04 Dec 2017 02:00:59 -0800 Received: from shwdeopenpsi068.ccr.corp.intel.com ([10.239.158.46]) by fmsmga005.fm.intel.com with ESMTP; 04 Dec 2017 02:00:58 -0800 X-Original-To: edk2-devel@lists.01.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; Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=134.134.136.24; helo=mga09.intel.com; envelope-from=star.zeng@intel.com; receiver=edk2-devel@lists.01.org X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.45,358,1508828400"; d="scan'208";a="183328817" From: Star Zeng To: edk2-devel@lists.01.org Date: Mon, 4 Dec 2017 18:00:56 +0800 Message-Id: <1512381656-10312-1-git-send-email-star.zeng@intel.com> X-Mailer: git-send-email 2.7.0.windows.1 Subject: [edk2] [PATCH] MdeModulePkg CapsulePei: Sort and merge memory resource entries 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: Dakota Chiang , Jiewen Yao , Star Zeng 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" Sort and merge memory resource entries to handle the case that the memory resource HOBs are reported differently between BOOT_ON_FLASH_UPDATE boot mode and normal boot mode, and the capsule buffer from UpdateCapsule at normal boot sits across two memory resource descriptors at BOOT_ON_FLASH_UPDATE boot mode. Cc: Jiewen Yao Cc: Chasel Chiu Cc: Dakota Chiang Tested-by: Dakota Chiang Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Star Zeng Reviewed-by: Chasel Chiu Reviewed-by: Jiewen.yao@intel.com --- MdeModulePkg/Universal/CapsulePei/UefiCapsule.c | 90 +++++++++++++++++++++= ++++ 1 file changed, 90 insertions(+) diff --git a/MdeModulePkg/Universal/CapsulePei/UefiCapsule.c b/MdeModulePkg= /Universal/CapsulePei/UefiCapsule.c index cca455ec396c..043365f7f770 100644 --- a/MdeModulePkg/Universal/CapsulePei/UefiCapsule.c +++ b/MdeModulePkg/Universal/CapsulePei/UefiCapsule.c @@ -625,6 +625,82 @@ GetPhysicalAddressBits ( #endif =20 /** + Sort memory resource entries based upon PhysicalStart, from low to high. + + @param[in, out] MemoryResource A pointer to the memory resource entry= buffer. + +**/ +VOID +SortMemoryResourceDescriptor ( + IN OUT MEMORY_RESOURCE_DESCRIPTOR *MemoryResource + ) +{ + MEMORY_RESOURCE_DESCRIPTOR *MemoryResourceEntry; + MEMORY_RESOURCE_DESCRIPTOR *NextMemoryResourceEntry; + MEMORY_RESOURCE_DESCRIPTOR TempMemoryResource; + + MemoryResourceEntry =3D MemoryResource; + NextMemoryResourceEntry =3D MemoryResource + 1; + while (MemoryResourceEntry->ResourceLength !=3D 0) { + while (NextMemoryResourceEntry->ResourceLength !=3D 0) { + if (MemoryResourceEntry->PhysicalStart > NextMemoryResourceEntry->Ph= ysicalStart) { + CopyMem (&TempMemoryResource, MemoryResourceEntry, sizeof (MEMORY_= RESOURCE_DESCRIPTOR)); + CopyMem (MemoryResourceEntry, NextMemoryResourceEntry, sizeof (MEM= ORY_RESOURCE_DESCRIPTOR)); + CopyMem (NextMemoryResourceEntry, &TempMemoryResource, sizeof (MEM= ORY_RESOURCE_DESCRIPTOR)); + } + + NextMemoryResourceEntry =3D NextMemoryResourceEntry + 1; + } + + MemoryResourceEntry =3D MemoryResourceEntry + 1; + NextMemoryResourceEntry =3D MemoryResourceEntry + 1; + } +} + +/** + Merge continous memory resource entries. + + @param[in, out] MemoryResource A pointer to the memory resource entry= buffer. + +**/ +VOID +MergeMemoryResourceDescriptor ( + IN OUT MEMORY_RESOURCE_DESCRIPTOR *MemoryResource + ) +{ + MEMORY_RESOURCE_DESCRIPTOR *MemoryResourceEntry; + MEMORY_RESOURCE_DESCRIPTOR *NewMemoryResourceEntry; + MEMORY_RESOURCE_DESCRIPTOR *NextMemoryResourceEntry; + MEMORY_RESOURCE_DESCRIPTOR *MemoryResourceEnd; + + MemoryResourceEntry =3D MemoryResource; + NewMemoryResourceEntry =3D MemoryResource; + while (MemoryResourceEntry->ResourceLength !=3D 0) { + CopyMem (NewMemoryResourceEntry, MemoryResourceEntry, sizeof (MEMORY_R= ESOURCE_DESCRIPTOR)); + NextMemoryResourceEntry =3D MemoryResourceEntry + 1; + + while ((NextMemoryResourceEntry->ResourceLength !=3D 0) && + (NextMemoryResourceEntry->PhysicalStart =3D=3D (MemoryResourceE= ntry->PhysicalStart + MemoryResourceEntry->ResourceLength))) { + MemoryResourceEntry->ResourceLength +=3D NextMemoryResourceEntry->Re= sourceLength; + if (NewMemoryResourceEntry !=3D MemoryResourceEntry) { + NewMemoryResourceEntry->ResourceLength +=3D NextMemoryResourceEntr= y->ResourceLength; + } +=20 + NextMemoryResourceEntry =3D NextMemoryResourceEntry + 1; + } + + MemoryResourceEntry =3D NextMemoryResourceEntry; + NewMemoryResourceEntry =3D NewMemoryResourceEntry + 1; + } + + // + // Set NULL terminate memory resource descriptor after merging. + // + MemoryResourceEnd =3D NewMemoryResourceEntry; + ZeroMem (MemoryResourceEnd, sizeof (MEMORY_RESOURCE_DESCRIPTOR)); +} + +/** Build memory resource descriptor from resource descriptor in HOB list. =20 @return Pointer to the buffer of memory resource descriptor. @@ -704,6 +780,20 @@ BuildMemoryResourceDescriptor ( Hob.Raw =3D GetNextHob (EFI_HOB_TYPE_RESOURCE_DESCRIPTOR, Hob.Raw); } =20 + SortMemoryResourceDescriptor (MemoryResource); + MergeMemoryResourceDescriptor (MemoryResource); + + DEBUG ((DEBUG_INFO, "Dump MemoryResource[] after sorted and merged\n")); + for (Index =3D 0; MemoryResource[Index].ResourceLength !=3D 0; Index++) { + DEBUG (( + DEBUG_INFO, + " MemoryResource[0x%x] - Start(0x%0lx) Length(0x%0lx)\n", + Index, + MemoryResource[Index].PhysicalStart, + MemoryResource[Index].ResourceLength + )); + } + return MemoryResource; } =20 --=20 2.7.0.windows.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel