From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=192.55.52.43; helo=mga05.intel.com; envelope-from=chasel.chiu@intel.com; receiver=edk2-devel@lists.01.org Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) (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 C7A5E220EE096 for ; Mon, 4 Dec 2017 04:46:48 -0800 (PST) Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga105.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 04 Dec 2017 04:51:18 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.45,359,1508828400"; d="scan'208";a="181087035" Received: from pgsmsx102.gar.corp.intel.com ([10.221.44.80]) by orsmga005.jf.intel.com with ESMTP; 04 Dec 2017 04:51:16 -0800 Received: from pgsmsx111.gar.corp.intel.com ([169.254.2.109]) by PGSMSX102.gar.corp.intel.com ([169.254.6.144]) with mapi id 14.03.0319.002; Mon, 4 Dec 2017 20:51:15 +0800 From: "Chiu, Chasel" To: "Zeng, Star" , "edk2-devel@lists.01.org" CC: "Yao, Jiewen" , "Chiang, Dakota" Thread-Topic: [PATCH] MdeModulePkg CapsulePei: Sort and merge memory resource entries Thread-Index: AQHTbOba6qgYnuH1nkemh4Mip1adYKMzIqyQ Date: Mon, 4 Dec 2017 12:51:15 +0000 Message-ID: <3C3EFB470A303B4AB093197B6777CCEC4FF5D37D@PGSMSX111.gar.corp.intel.com> References: <1512381656-10312-1-git-send-email-star.zeng@intel.com> In-Reply-To: <1512381656-10312-1-git-send-email-star.zeng@intel.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: dlp-product: dlpe-windows dlp-version: 11.0.0.116 dlp-reaction: no-action x-titus-metadata-40: eyJDYXRlZ29yeUxhYmVscyI6IiIsIk1ldGFkYXRhIjp7Im5zIjoiaHR0cDpcL1wvd3d3LnRpdHVzLmNvbVwvbnNcL0ludGVsMyIsImlkIjoiNjQwNDE2NzQtZTk1Ni00NjUwLTgwY2MtZmZiYzliNTg3OWRjIiwicHJvcHMiOlt7Im4iOiJDVFBDbGFzc2lmaWNhdGlvbiIsInZhbHMiOlt7InZhbHVlIjoiQ1RQX0lDIn1dfV19LCJTdWJqZWN0TGFiZWxzIjpbXSwiVE1DVmVyc2lvbiI6IjE3LjIuNS4xOCIsIlRydXN0ZWRMYWJlbEhhc2giOiJRNDBaOFZ5bnZVSDVpUTFGdk5iN2ZKUUdWbnV1VlNWTHRFYU40Q0R5MDhHU0dDVm1vSkpPNGptcHhheWVFZDF0In0= x-ctpclassification: CTP_IC x-originating-ip: [172.30.20.206] MIME-Version: 1.0 Subject: Re: [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: , X-List-Received-Date: Mon, 04 Dec 2017 12:46:49 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Reviewed-by: Chasel Chiu -----Original Message----- From: Zeng, Star=20 Sent: Monday, December 4, 2017 6:01 PM To: edk2-devel@lists.01.org Cc: Zeng, Star ; Yao, Jiewen ; C= hiu, Chasel ; Chiang, Dakota Subject: [PATCH] MdeModulePkg CapsulePei: Sort and merge memory resource en= tries Sort and merge memory resource entries to handle the case that the memory r= esource HOBs are reported differently between BOOT_ON_FLASH_UPDATE boot mod= e and normal boot mode, and the capsule buffer from UpdateCapsule at normal= boot sits across two memory resource descriptors at BOOT_ON_FLASH_UPDATE b= oot 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 --- 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=20 + MemoryResource + 1; while (MemoryResourceEntry->ResourceLength !=3D 0)=20 + { + 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=20 + 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); =20 + MergeMemoryResourceDescriptor (MemoryResource); + + DEBUG ((DEBUG_INFO, "Dump MemoryResource[] after sorted and=20 + 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 -- 2.7.0.windows.1