From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 2B72B1A1E8C for ; Wed, 26 Oct 2016 17:10:04 -0700 (PDT) Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga105.fm.intel.com with ESMTP; 26 Oct 2016 17:10:03 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.31,551,1473145200"; d="scan'208";a="24497907" Received: from orsmsx109.amr.corp.intel.com ([10.22.240.7]) by orsmga004.jf.intel.com with ESMTP; 26 Oct 2016 17:10:03 -0700 Received: from orsmsx113.amr.corp.intel.com ([169.254.9.50]) by ORSMSX109.amr.corp.intel.com ([169.254.11.208]) with mapi id 14.03.0248.002; Wed, 26 Oct 2016 17:10:03 -0700 From: "Ma, Maurice" To: "Dong, Guo" CC: "Agyeman, Prince" , "edk2-devel@lists.01.org" Thread-Topic: [edk2] [PATCH] CorebootModulePkg: Fix memmap issue Thread-Index: AQHSKXNowTt0S5QdPkS6TgMfBc1wm6C7ed1A Date: Thu, 27 Oct 2016 00:10:03 +0000 Message-ID: <7AAC936950815649B5F88FAE785306C284176A6A@ORSMSX113.amr.corp.intel.com> References: In-Reply-To: Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ctpclassification: CTP_IC x-titus-metadata-40: eyJDYXRlZ29yeUxhYmVscyI6IiIsIk1ldGFkYXRhIjp7Im5zIjoiaHR0cDpcL1wvd3d3LnRpdHVzLmNvbVwvbnNcL0ludGVsMyIsImlkIjoiODVkMjE5NzQtMDZiOS00NTcyLTg0N2UtYjA5MTUwY2JmZTEwIiwicHJvcHMiOlt7Im4iOiJDVFBDbGFzc2lmaWNhdGlvbiIsInZhbHMiOlt7InZhbHVlIjoiQ1RQX0lDIn1dfV19LCJTdWJqZWN0TGFiZWxzIjpbXSwiVE1DVmVyc2lvbiI6IjE1LjkuNi42IiwiVHJ1c3RlZExhYmVsSGFzaCI6IlVrYjFKUUJ1YkJcL2ordFF0cTQrdFl5ZlN6bkFYK1BVeUhubGlsOHhJQkhnPSJ9 x-originating-ip: [10.22.254.139] MIME-Version: 1.0 Subject: Re: [PATCH] CorebootModulePkg: Fix memmap issue X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 27 Oct 2016 00:10:04 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Reviewed-by: Maurice Ma -----Original Message----- From: Dong, Guo=20 Sent: Tuesday, October 18, 2016 12:11 PM To: edk2-devel@lists.01.org Cc: Ma, Maurice; Agyeman, Prince; Dong, Guo Subject: [edk2] [PATCH] CorebootModulePkg: Fix memmap issue Some reserved memory (e.g. CSE reserved memory) might be in the middle of u= sable physical memory. The current memory map caculation could not handle t= his case. This patch fixed this issue. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: gdong1 --- CorebootModulePkg/CbSupportPei/CbSupportPei.c | 126 ++++++++++++++----= ---- CorebootModulePkg/CbSupportPei/CbSupportPei.h | 8 +- CorebootModulePkg/Include/Library/CbParseLib.h | 13 ++- CorebootModulePkg/Library/CbParseLib/CbParseLib.c | 27 +---- 4 files changed, 100 insertions(+), 74 deletions(-) diff --git a/CorebootModulePkg/CbSupportPei/CbSupportPei.c b/CorebootModule= Pkg/CbSupportPei/CbSupportPei.c index 366682b..004d1e9 100755 --- a/CorebootModulePkg/CbSupportPei/CbSupportPei.c +++ b/CorebootModulePkg/CbSupportPei/CbSupportPei.c @@ -141,6 +141,72 @@ CbPeiReportRemainedFvs ( } =20 /** + Based on memory base, size and type, build resource descripter HOB. + + @param Base Memory base address. + @param Size Memory size. + @param Type Memory type. + @param Param A pointer to CB_MEM_INFO. + + @retval EFI_SUCCESS if it completed successfully. +**/ +EFI_STATUS +CbMemInfoCallback ( + UINT64 Base, + UINT64 Size, + UINT32 Type, + VOID *Param + ) +{ + CB_MEM_INFO *MemInfo; + UINTN Attribue; + + Attribue =3D EFI_RESOURCE_ATTRIBUTE_PRESENT | + EFI_RESOURCE_ATTRIBUTE_INITIALIZED | + EFI_RESOURCE_ATTRIBUTE_TESTED | + EFI_RESOURCE_ATTRIBUTE_UNCACHEABLE | + EFI_RESOURCE_ATTRIBUTE_WRITE_COMBINEABLE | + EFI_RESOURCE_ATTRIBUTE_WRITE_THROUGH_CACHEABLE | + EFI_RESOURCE_ATTRIBUTE_WRITE_BACK_CACHEABLE; + + MemInfo =3D (CB_MEM_INFO *)Param; + if (Base >=3D 0x100000) { + if (Type =3D=3D CB_MEM_RAM) { + if (Base < 0x100000000ULL) { + MemInfo->UsableLowMemTop =3D (UINT32)(Base + Size); + } else { + Attribue &=3D ~EFI_RESOURCE_ATTRIBUTE_TESTED; + } + BuildResourceDescriptorHob ( + EFI_RESOURCE_SYSTEM_MEMORY, + Attribue, + (EFI_PHYSICAL_ADDRESS)Base, + Size + ); + } else if (Type =3D=3D CB_MEM_TABLE) { + BuildResourceDescriptorHob ( + EFI_RESOURCE_MEMORY_RESERVED, + Attribue, + (EFI_PHYSICAL_ADDRESS)Base, + Size + ); + MemInfo->SystemLowMemTop =3D ((UINT32)(Base + Size) + 0x0FFFFFFF) & = 0xF0000000; + } else if (Type =3D=3D CB_MEM_RESERVED) { + if ((MemInfo->SystemLowMemTop =3D=3D 0) || (Base < MemInfo->SystemLo= wMemTop)) { + BuildResourceDescriptorHob ( + EFI_RESOURCE_MEMORY_RESERVED, + Attribue, + (EFI_PHYSICAL_ADDRESS)Base, + Size + );=20 + } + } + } + =20 + return EFI_SUCCESS; +} + +/** This is the entrypoint of PEIM =20 @param FileHandle Handle of the file being invoked. @@ -155,9 +221,9 @@ CbPeiEntryPoint ( IN CONST EFI_PEI_SERVICES **PeiServices ) { - EFI_STATUS Status; - UINT64 LowMemorySize, HighMemorySize; - UINT64 PeiMemSize =3D SIZE_64MB; // 64 MB + EFI_STATUS Status; + UINT64 LowMemorySize; + UINT64 PeiMemSize =3D SIZE_64MB; // 64 MB EFI_PHYSICAL_ADDRESS PeiMemBase =3D 0; UINT32 RegEax; UINT8 PhysicalAddressBits; @@ -173,23 +239,12 @@ CbPeiEntryPoint ( UINTN PmCtrlRegBase, PmTimerRegBase, ResetRegAddress, Res= etValue; UINTN PmEvtBase; UINTN PmGpeEnBase; - - LowMemorySize =3D 0; - HighMemorySize =3D 0; - - Status =3D CbParseMemoryInfo (&LowMemorySize, &HighMemorySize); - if (EFI_ERROR(Status)) - return Status; - - DEBUG((EFI_D_ERROR, "LowMemorySize: 0x%lx.\n", LowMemorySize)); - DEBUG((EFI_D_ERROR, "HighMemorySize: 0x%lx.\n", HighMemorySize)); - - ASSERT (LowMemorySize > 0); + CB_MEM_INFO CbMemInfo; =20 // // Report lower 640KB of RAM. Attribute EFI_RESOURCE_ATTRIBUTE_TESTED - // is intentionally omitted to prevent erasing of the coreboot header - // record before it is processed by CbParseMemoryInfo. + // is intentionally omitted to prevent erasing of the coreboot header =20 + // record before it is processed by CbParseMemoryInfo. // BuildResourceDescriptorHob ( EFI_RESOURCE_SYSTEM_MEMORY, @@ -221,37 +276,16 @@ CbPeiEntryPoint ( (UINT64)(0x60000) ); =20 - BuildResourceDescriptorHob ( - EFI_RESOURCE_SYSTEM_MEMORY, - ( - EFI_RESOURCE_ATTRIBUTE_PRESENT | - EFI_RESOURCE_ATTRIBUTE_INITIALIZED | - EFI_RESOURCE_ATTRIBUTE_TESTED | - EFI_RESOURCE_ATTRIBUTE_UNCACHEABLE | - EFI_RESOURCE_ATTRIBUTE_WRITE_COMBINEABLE | - EFI_RESOURCE_ATTRIBUTE_WRITE_THROUGH_CACHEABLE | - EFI_RESOURCE_ATTRIBUTE_WRITE_BACK_CACHEABLE - ), - (EFI_PHYSICAL_ADDRESS)(0x100000), - (UINT64) (LowMemorySize - 0x100000) - ); - - if (HighMemorySize > 0) { - BuildResourceDescriptorHob ( - EFI_RESOURCE_SYSTEM_MEMORY, - ( - EFI_RESOURCE_ATTRIBUTE_PRESENT | - EFI_RESOURCE_ATTRIBUTE_INITIALIZED | - EFI_RESOURCE_ATTRIBUTE_UNCACHEABLE | - EFI_RESOURCE_ATTRIBUTE_WRITE_COMBINEABLE | - EFI_RESOURCE_ATTRIBUTE_WRITE_THROUGH_CACHEABLE | - EFI_RESOURCE_ATTRIBUTE_WRITE_BACK_CACHEABLE - ), - (EFI_PHYSICAL_ADDRESS)(0x100000000ULL), - HighMemorySize - ); + ZeroMem (&CbMemInfo, sizeof(CbMemInfo)); Status =3D CbParseMemoryInfo=20 + (CbMemInfoCallback, (VOID *)&CbMemInfo); if (EFI_ERROR(Status)) { + return Status; } =20 + LowMemorySize =3D CbMemInfo.UsableLowMemTop; DEBUG ((EFI_D_INFO, "Low=20 + memory 0x%lx\n", LowMemorySize)); DEBUG ((EFI_D_INFO,=20 + "SystemLowMemTop 0x%x\n", CbMemInfo.SystemLowMemTop)); + // // Should be 64k aligned // diff --git a/CorebootModulePkg/CbSupportPei/CbSupportPei.h b/CorebootModule= Pkg/CbSupportPei/CbSupportPei.h index 3c9a3fe..d3166aa 100644 --- a/CorebootModulePkg/CbSupportPei/CbSupportPei.h +++ b/CorebootModulePkg/CbSupportPei/CbSupportPei.h @@ -1,7 +1,7 @@ /** @file The header file of Coreboot Support PEIM. =20 -Copyright (c) 2014 - 2015, Intel Corporation. All rights reserved.
+Copyright (c) 2014 - 2016, Intel Corporation. All rights reserved.
This program and the accompanying materials are licensed and made availab= le under the terms and conditions of the BSD License which accompanies thi= s distribution. The full text of the license may be found at @@ -37,5 +37,= 11 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR = IMPLIED. #include =20 #include +#include "Coreboot.h" + +typedef struct { + UINT32 UsableLowMemTop; + UINT32 SystemLowMemTop; +} CB_MEM_INFO; =20 #endif diff --git a/CorebootModulePkg/Include/Library/CbParseLib.h b/CorebootModul= ePkg/Include/Library/CbParseLib.h index a023246..7304715 100644 --- a/CorebootModulePkg/Include/Library/CbParseLib.h +++ b/CorebootModulePkg/Include/Library/CbParseLib.h @@ -14,22 +14,25 @@ **/ #include =20 +typedef RETURN_STATUS \ + (*CB_MEM_INFO_CALLBACK) (UINT64 Base, UINT64 Size, UINT32 Type,=20 +VOID *Param); + /** Acquire the memory information from the coreboot table in memory. =20 - @param pLowMemorySize Pointer to the variable of low memory size - @param pHighMemorySize Pointer to the variable of high memory size + @param MemInfoCallback The callback routine + @param pParam Pointer to the callback routine parameter =20 @retval RETURN_SUCCESS Successfully find out the memory information. - @retval RETURN_INVALID_PARAMETER Invalid input parameters. @retval RETURN_NOT_FOUND Failed to find the memory information. =20 **/ RETURN_STATUS CbParseMemoryInfo ( - IN UINT64* pLowMemorySize, - IN UINT64* pHighMemorySize + IN CB_MEM_INFO_CALLBACK MemInfoCallback, + IN VOID *pParam ); + =20 /** Acquire the coreboot memory table with the given table id diff --git a/C= orebootModulePkg/Library/CbParseLib/CbParseLib.c b/CorebootModulePkg/Librar= y/CbParseLib/CbParseLib.c index 7c81a51..a72d048 100644 --- a/CorebootModulePkg/Library/CbParseLib/CbParseLib.c +++ b/CorebootModulePkg/Library/CbParseLib/CbParseLib.c @@ -229,18 +229,17 @@ FindCbMemTable ( /** Acquire the memory information from the coreboot table in memory. =20 - @param pLowMemorySize Pointer to the variable of low memory size - @param pHighMemorySize Pointer to the variable of high memory size + @param MemInfoCallback The callback routine + @param pParam Pointer to the callback routine parameter =20 @retval RETURN_SUCCESS Successfully find out the memory information. - @retval RETURN_INVALID_PARAMETER Invalid input parameters. @retval RETURN_NOT_FOUND Failed to find the memory information. =20 **/ RETURN_STATUS CbParseMemoryInfo ( - OUT UINT64 *pLowMemorySize, - OUT UINT64 *pHighMemorySize + IN CB_MEM_INFO_CALLBACK MemInfoCallback, + IN VOID *pParam ) { struct cb_memory *rec; @@ -249,9 +248,6 @@ CbParseMemoryInfo ( UINT64 Size; UINTN Index; =20 - if ((pLowMemorySize =3D=3D NULL) || (pHighMemorySize =3D=3D NULL)) { - return RETURN_INVALID_PARAMETER; - } =20 // // Get the coreboot memory table @@ -265,9 +261,6 @@ CbParseMemoryInfo ( return RETURN_NOT_FOUND; } =20 - *pLowMemorySize =3D 0; - *pHighMemorySize =3D 0; - for (Index =3D 0; Index < MEM_RANGE_COUNT(rec); Index++) { Range =3D MEM_RANGE_PTR(rec, Index); Start =3D cb_unpack64(Range->start); @@ -275,18 +268,8 @@ CbParseMemoryInfo ( DEBUG ((EFI_D_INFO, "%d. %016lx - %016lx [%02x]\n", Index, Start, Start + Size - 1, Range->type)); =20 - if (Range->type !=3D CB_MEM_RAM) { - continue; - } - - if (Start + Size < 0x100000000ULL) { - *pLowMemorySize =3D Start + Size; - } else { - *pHighMemorySize =3D Start + Size - 0x100000000ULL; + MemInfoCallback (Start, Size, Range->type, pParam); } - } - - DEBUG ((EFI_D_INFO, "Low memory 0x%lx, High Memory 0x%lx\n", *pLowMemory= Size, *pHighMemorySize)); =20 return RETURN_SUCCESS; } -- 2.7.0.windows.1