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.151; helo=mga17.intel.com; envelope-from=star.zeng@intel.com; receiver=edk2-devel@lists.01.org Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) (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 C79BA21199B1C for ; Mon, 17 Dec 2018 18:46:44 -0800 (PST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga107.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 17 Dec 2018 18:46:44 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,367,1539673200"; d="scan'208";a="304657679" Received: from fmsmsx106.amr.corp.intel.com ([10.18.124.204]) by fmsmga005.fm.intel.com with ESMTP; 17 Dec 2018 18:46:43 -0800 Received: from shsmsx103.ccr.corp.intel.com (10.239.4.69) by FMSMSX106.amr.corp.intel.com (10.18.124.204) with Microsoft SMTP Server (TLS) id 14.3.408.0; Mon, 17 Dec 2018 18:46:43 -0800 Received: from shsmsx102.ccr.corp.intel.com ([169.254.2.182]) by SHSMSX103.ccr.corp.intel.com ([169.254.4.59]) with mapi id 14.03.0415.000; Tue, 18 Dec 2018 10:45:30 +0800 From: "Zeng, Star" To: "Wang, Jian J" , "edk2-devel@lists.01.org" CC: "Wu, Hao A" , "Gao, Liming" , "Ni, Ruiyu" , "Kinney, Michael D" , "Desimone, Nathaniel L" , "Chiu, Chasel" , "Zeng, Star" Thread-Topic: [PATCH 1/7] MdeModulePkg PeiCore: Remove the using of PcdPeiCoreMaxPeimPerFv Thread-Index: AQHUk5flgIDIGAz3XEyH/yuYWMct6aWDPpoAgACRMDA= Date: Tue, 18 Dec 2018 02:45:28 +0000 Message-ID: <0C09AFA07DD0434D9E2A0C6AEB04831040220C40@shsmsx102.ccr.corp.intel.com> References: <1544783322-17436-1-git-send-email-star.zeng@intel.com> <1544783322-17436-2-git-send-email-star.zeng@intel.com> In-Reply-To: Accept-Language: zh-CN, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.239.127.40] MIME-Version: 1.0 Subject: Re: [PATCH 1/7] MdeModulePkg PeiCore: Remove the using of PcdPeiCoreMaxPeimPerFv X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 18 Dec 2018 02:46:45 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Good suggestion. It will make the buffer extension log consistent. I will send V2 to cover it with some test. Thanks, Star -----Original Message----- From: Wang, Jian J=20 Sent: Tuesday, December 18, 2018 10:04 AM To: Zeng, Star ; edk2-devel@lists.01.org Cc: Wu, Hao A ; Gao, Liming ; Ni,= Ruiyu ; Kinney, Michael D = ; Desimone, Nathaniel L ; Chiu, Chasel Subject: RE: [PATCH 1/7] MdeModulePkg PeiCore: Remove the using of PcdPeiCo= reMaxPeimPerFv Star, Just one place which might need refine. Please see it below. Regards, Jian > -----Original Message----- > From: Zeng, Star > Sent: Friday, December 14, 2018 6:29 PM > To: edk2-devel@lists.01.org > Cc: Zeng, Star ; Wang, Jian J=20 > ; Wu, Hao A ; Gao, Liming=20 > ; Ni, Ruiyu ; Kinney,=20 > Michael D ; Desimone, Nathaniel L=20 > ; Chiu, Chasel > Subject: [PATCH 1/7] MdeModulePkg PeiCore: Remove the using of=20 > PcdPeiCoreMaxPeimPerFv >=20 > REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D1405 >=20 > Background as below. >=20 > Problem: > As static configuration from the PCDs, the binary PeiCore (for example=20 > in FSP binary with dispatch mode) could not predict how many FVs,=20 > Files or PPIs for different platforms. >=20 > Burden: > Platform developers need configure the PCDs accordingly for different=20 > platforms. >=20 > To solve the problem and remove the burden, we can update code to=20 > remove the using of PcdPeiCoreMaxFvSupported, PcdPeiCoreMaxPeimPerFv=20 > and PcdPeiCoreMaxPpiSupported by extending buffer dynamically for FV,=20 > File and PPI management. >=20 > This patch removes the using of PcdPeiCoreMaxPeimPerFv in PeiCore. >=20 > Cc: Jian J Wang > Cc: Hao Wu > Cc: Liming Gao > Cc: Ruiyu Ni > Cc: Michael D Kinney > Cc: Nate DeSimone > Cc: Chasel Chiu > Contributed-under: TianoCore Contribution Agreement 1.1 > Signed-off-by: Star Zeng > --- > MdeModulePkg/Core/Pei/Dispatcher/Dispatcher.c | 199=20 > ++++++++++++++++---- > ------ > MdeModulePkg/Core/Pei/PeiMain.h | 17 ++- > MdeModulePkg/Core/Pei/PeiMain.inf | 1 - > MdeModulePkg/Core/Pei/PeiMain/PeiMain.c | 48 +++---- > 4 files changed, 157 insertions(+), 108 deletions(-) >=20 > diff --git a/MdeModulePkg/Core/Pei/Dispatcher/Dispatcher.c > b/MdeModulePkg/Core/Pei/Dispatcher/Dispatcher.c > index f6bb35a5fe8d..71440bab9488 100644 > --- a/MdeModulePkg/Core/Pei/Dispatcher/Dispatcher.c > +++ b/MdeModulePkg/Core/Pei/Dispatcher/Dispatcher.c > @@ -41,7 +41,8 @@ DiscoverPeimsAndOrderWithApriori ( > UINTN PeimCount; > EFI_GUID *Guid; > EFI_PEI_FILE_HANDLE *TempFileHandles; > - EFI_GUID *FileGuid; > + EFI_GUID *TempFileGuid; > + UINTN TempPeimCount; > EFI_PEI_FIRMWARE_VOLUME_PPI *FvPpi; > EFI_FV_FILE_INFO FileInfo; >=20 > @@ -51,38 +52,106 @@ DiscoverPeimsAndOrderWithApriori ( > // Walk the FV and find all the PEIMs and the Apriori file. > // > AprioriFileHandle =3D NULL; > - Private->CurrentFvFileHandles[0] =3D NULL; > + Private->CurrentFvFileHandles =3D NULL; > Guid =3D NULL; > - FileHandle =3D NULL; > - TempFileHandles =3D Private->FileHandles; > - FileGuid =3D Private->FileGuid; >=20 > // > - // If the current Fv has been scanned, directly get its cachable recor= d. > + // If the current Fv has been scanned, directly get its cached records= . > // > - if (Private->Fv[Private->CurrentPeimFvCount].ScanFv) { > - CopyMem (Private->CurrentFvFileHandles, Private->Fv[Private- > >CurrentPeimFvCount].FvFileHandles, sizeof (EFI_PEI_FILE_HANDLE) *=20 > >PcdGet32 > (PcdPeiCoreMaxPeimPerFv)); > + if (CoreFileHandle->ScanFv) { > + Private->CurrentFvFileHandles =3D CoreFileHandle->FvFileHandles; > return; > } >=20 > + if (Private->TempPeimCount =3D=3D 0) { > + // > + // Initialize the temp buffers. > + // > + Private->TempPeimCount =3D 32; > + Private->TempFileHandles =3D AllocatePool (sizeof=20 > + (EFI_PEI_FILE_HANDLE) * > 32); > + ASSERT (Private->TempFileHandles !=3D NULL); > + Private->TempFileGuid =3D AllocatePool (sizeof (EFI_GUID) * 32); > + ASSERT (Private->TempFileGuid !=3D NULL); } TempFileHandles =3D=20 > + Private->TempFileHandles; > + TempFileGuid =3D Private->TempFileGuid; > + > // > - // Go ahead to scan this Fv, and cache FileHandles within it. > + // Go ahead to scan this Fv, get PeimCount and cache FileHandles=20 > + within it to > TempFileHandles. > // > - Status =3D EFI_NOT_FOUND; > - for (PeimCount =3D 0; PeimCount <=3D PcdGet32 (PcdPeiCoreMaxPeimPerFv)= ; > PeimCount++) { > + PeimCount =3D 0; > + FileHandle =3D NULL; > + TempPeimCount =3D 0; > + do { > Status =3D FvPpi->FindFileByType (FvPpi,=20 > PEI_CORE_INTERNAL_FFS_FILE_DISPATCH_TYPE, CoreFileHandle->FvHandle,=20 > &FileHandle); > - if (Status !=3D EFI_SUCCESS || PeimCount =3D=3D PcdGet32 > (PcdPeiCoreMaxPeimPerFv)) { > - break; > + if (!EFI_ERROR (Status)) { > + if (TempPeimCount < Private->TempPeimCount) { > + TempFileHandles[TempPeimCount] =3D FileHandle; > + TempPeimCount++; > + } > + PeimCount++; > } > + } while (!EFI_ERROR (Status)); >=20 > - Private->CurrentFvFileHandles[PeimCount] =3D FileHandle; > + DEBUG (( > + DEBUG_INFO, > + "%a(): Found 0x%x PEI FFS files in the %dth FV\n", > + __FUNCTION__, > + PeimCount, > + Private->CurrentPeimFvCount > + )); > + > + if (PeimCount =3D=3D 0) { > + // > + // No PEIM FFS file is found, set ScanFv flag and return. > + // > + CoreFileHandle->ScanFv =3D TRUE; > + return; > + } > + > + if (PeimCount > Private->TempPeimCount) { > + // > + // The temp buffers are too small, allocate bigger ones. > + // > + TempFileHandles =3D AllocatePool (sizeof (EFI_PEI_FILE_HANDLE) * > PeimCount); > + ASSERT (TempFileHandles !=3D NULL); > + CopyMem ( > + TempFileHandles, > + Private->TempFileHandles, > + sizeof (EFI_PEI_FILE_HANDLE) * Private->TempPeimCount > + ); > + Private->TempFileHandles =3D TempFileHandles; > + TempFileGuid =3D AllocatePool (sizeof (EFI_GUID) * PeimCount); > + ASSERT (TempFileGuid !=3D NULL); > + CopyMem ( > + TempFileGuid, > + Private->TempFileGuid, > + sizeof (EFI_GUID) * Private->TempPeimCount > + ); > + Private->TempFileGuid =3D TempFileGuid; > + Private->TempPeimCount =3D PeimCount; > } >=20 > // > - // Check whether the count of files exceeds the max support files=20 > in a FV image > - // If more files are required in a FV image, PcdPeiCoreMaxPeimPerFv=20 > can be set to a larger value in DSC file. > + // Record PeimCount, allocate buffer for PeimState and FvFileHandles. > + // > + CoreFileHandle->PeimCount =3D PeimCount; CoreFileHandle->PeimState = =3D=20 > + AllocateZeroPool (sizeof (UINT8) * PeimCount); ASSERT=20 > + (CoreFileHandle->PeimState !=3D NULL); CoreFileHandle->FvFileHandles=20 > + =3D AllocateZeroPool (sizeof > (EFI_PEI_FILE_HANDLE) * PeimCount); > + ASSERT (CoreFileHandle->FvFileHandles !=3D NULL); > + > // > - ASSERT ((Status !=3D EFI_SUCCESS) || (PeimCount < PcdGet32=20 > (PcdPeiCoreMaxPeimPerFv))); > + // TempFileHandles may be not big enough in last scan. > + // Go ahead to rescan this Fv, and cache remaining FileHandles=20 > + within it to > TempFileHandles. > + // > + FileHandle =3D TempFileHandles[TempPeimCount - 1]; for (;=20 > + TempPeimCount < PeimCount; TempPeimCount++) { > + Status =3D FvPpi->FindFileByType (FvPpi, > PEI_CORE_INTERNAL_FFS_FILE_DISPATCH_TYPE, CoreFileHandle->FvHandle,=20 > &FileHandle); > + ASSERT_EFI_ERROR (Status); > + > + TempFileHandles[TempPeimCount] =3D FileHandle; } >=20 Above logic looks have some redundant code. And the FV might be re-scanned = if there're more than 32 PEIMs in it. If the scan is time consuming task, m= aybe it'd be better to refine the logic. Maybe something like below (just s= how the idea, not verified yet). PeimCount =3D 0; FileHandle =3D NULL; TempPeimCount =3D 0; TempFileHandles =3D Private->TempFileHandles; TempFileGuid =3D Private->TempFileGuid; do { Status =3D FvPpi->FindFileByType(FvPpi, PEI_CORE_INTERNAL_FFS_FILE_DISP= ATCH_TYPE, CoreFileHandle->FvHandle, &FileHandle); if (!EFI_ERROR (Status)) { PeimCount++; // // Have enought buffer? // if (Private->TempPeimCount < PeimCount) { Private->TempPeimCount +=3D 32; TempFileHandles =3D Private->TempFileHandles; TempFileGuid =3D Private->TempFileGuid; Private->TempFileHandles =3D AllocatePool (sizeof (EFI_PEI_FILE_HAN= DLE) * Private->TempPeimCount); ASSERT (Private->TempFileHandles !=3D NULL); Private->TempFileGuid =3D AllocatePool (sizeof (EFI_GUID) * Priv= ate->TempPeimCount); ASSERT (Private->TempFileGuid !=3D NULL); if (TempFileHandles !=3D NULL) { CopyMem ( Private->TempFileHandles, TempFileHandles, sizeof (EFI_PEI_FILE_HANDLE) * (PeimCount - 1) ); } if (TempFileGuid !=3D NULL) { CopyMem ( Private->TempFileGuid, TempFileGuid, sizeof (EFI_GUID) * (PeimCount - 1) ); } TempPeimCount =3D 0; TempFileHandles =3D Private->TempFileHandles + PeimCount - 1; TempFileGuid =3D Private->TempFileGuid + PeimCount - 1; } TempFileHandles[TempPeimCount++] =3D FileHandle; } } while (!EFI_ERROR (Status)); > // > // Get Apriori File handle > @@ -96,7 +165,7 @@ DiscoverPeimsAndOrderWithApriori ( > Status =3D FvPpi->FindSectionByType (FvPpi, EFI_SECTION_RAW,=20 > AprioriFileHandle, (VOID **) &Apriori); > if (!EFI_ERROR (Status)) { > // > - // Calculate the number of PEIMs in the A Priori list > + // Calculate the number of PEIMs in the Apriori file > // > Status =3D FvPpi->GetFileInfo (FvPpi, AprioriFileHandle, &FileInfo= ); > ASSERT_EFI_ERROR (Status); > @@ -113,71 +182,55 @@ DiscoverPeimsAndOrderWithApriori ( > // Make an array of file name guids that matches the=20 > FileHandle array so we can convert > // quickly from file name to file handle > // > - Status =3D FvPpi->GetFileInfo (FvPpi, Private->CurrentFvFileHand= les[Index], > &FileInfo); > - CopyMem (&FileGuid[Index], &FileInfo.FileName, sizeof(EFI_GUID))= ; > + Status =3D FvPpi->GetFileInfo (FvPpi, TempFileHandles[Index], &F= ileInfo); > + ASSERT_EFI_ERROR (Status); > + CopyMem (&TempFileGuid[Index], &FileInfo.FileName,=20 > + sizeof(EFI_GUID)); > } >=20 > // > - // Walk through FileGuid array to find out who is invalid PEIM gui= d in Apriori > file. > - // Add available PEIMs in Apriori file into TempFileHandles array = at first. > + // Walk through TempFileGuid array to find out who is invalid=20 > + PEIM guid in > Apriori file. > + // Add available PEIMs in Apriori file into FvFileHandles array. > // > - Index2 =3D 0; > - for (Index =3D 0; Index2 < Private->AprioriCount; Index++) { > - while (Index2 < Private->AprioriCount) { > - Guid =3D ScanGuid (FileGuid, PeimCount * sizeof (EFI_GUID), > &Apriori[Index2++]); > - if (Guid !=3D NULL) { > - break; > - } > - } > - if (Guid =3D=3D NULL) { > - break; > - } > - PeimIndex =3D ((UINTN)Guid - (UINTN)&FileGuid[0])/sizeof (EFI_GU= ID); > - TempFileHandles[Index] =3D Private->CurrentFvFileHandles[PeimInd= ex]; > + Index =3D 0; > + for (Index2 =3D 0; Index2 < Private->AprioriCount; Index2++) { > + Guid =3D ScanGuid (TempFileGuid, PeimCount * sizeof (EFI_GUID), > &Apriori[Index2]); > + if (Guid !=3D NULL) { > + PeimIndex =3D ((UINTN)Guid - (UINTN)&TempFileGuid[0])/sizeof (= EFI_GUID); > + CoreFileHandle->FvFileHandles[Index++] =3D=20 > + TempFileHandles[PeimIndex]; >=20 > - // > - // Since we have copied the file handle we can remove it from th= is list. > - // > - Private->CurrentFvFileHandles[PeimIndex] =3D NULL; > + // > + // Since we have copied the file handle we can remove it from = this list. > + // > + TempFileHandles[PeimIndex] =3D NULL; > + } > } >=20 > // > - // Update valid Aprioricount > + // Update valid AprioriCount > // > Private->AprioriCount =3D Index; >=20 > // > // Add in any PEIMs not in the Apriori file > // > - for (;Index < PeimCount; Index++) { > - for (Index2 =3D 0; Index2 < PeimCount; Index2++) { > - if (Private->CurrentFvFileHandles[Index2] !=3D NULL) { > - TempFileHandles[Index] =3D Private->CurrentFvFileHandles[Ind= ex2]; > - Private->CurrentFvFileHandles[Index2] =3D NULL; > - break; > - } > + for (Index2 =3D 0; Index2 < PeimCount; Index2++) { > + if (TempFileHandles[Index2] !=3D NULL) { > + CoreFileHandle->FvFileHandles[Index++] =3D TempFileHandles[Ind= ex2]; > + TempFileHandles[Index2] =3D NULL; > } > } > - // > - //Index the end of array contains re-range Pei moudle. > - // > - TempFileHandles[Index] =3D NULL; > - > - // > - // Private->CurrentFvFileHandles is currently in PEIM in the FV or= der. > - // We need to update it to start with files in the A Priori list a= nd > - // then the remaining files in PEIM order. > - // > - CopyMem (Private->CurrentFvFileHandles, TempFileHandles, sizeof > (EFI_PEI_FILE_HANDLE) * PcdGet32 (PcdPeiCoreMaxPeimPerFv)); > + ASSERT (Index =3D=3D PeimCount); > } > + } else { > + CopyMem (CoreFileHandle->FvFileHandles, TempFileHandles, sizeof > (EFI_PEI_FILE_HANDLE) * PeimCount); > } > + > // > - // Cache the current Fv File Handle. So that we don't have to scan the= Fv again. > - // Instead, we can retrieve the file handles within this Fv from cacha= ble data. > + // The current Fv File Handles have been cached. So that we don't=20 > + have to > scan the Fv again. > + // Instead, we can retrieve the file handles within this Fv from cache= d records. > // > - Private->Fv[Private->CurrentPeimFvCount].ScanFv =3D TRUE; > - CopyMem (Private->Fv[Private->CurrentPeimFvCount].FvFileHandles,=20 > Private- > >CurrentFvFileHandles, sizeof (EFI_PEI_FILE_HANDLE) * PcdGet32 > (PcdPeiCoreMaxPeimPerFv)); > - > + CoreFileHandle->ScanFv =3D TRUE; > + Private->CurrentFvFileHandles =3D CoreFileHandle->FvFileHandles; > } >=20 > // > @@ -977,7 +1030,7 @@ PeiDispatcher ( > SaveCurrentFileHandle =3D Private->CurrentFileHandle; >=20 > for (Index1 =3D 0; Index1 < Private->FvCount; Index1++) { > - for (Index2 =3D 0; (Index2 < PcdGet32 (PcdPeiCoreMaxPeimPerFv)) && > (Private->Fv[Index1].FvFileHandles[Index2] !=3D NULL); Index2++) { > + for (Index2 =3D 0; Index2 < Private->Fv[Index1].PeimCount;=20 > + Index2++) { > if (Private->Fv[Index1].PeimState[Index2] =3D=3D > PEIM_STATE_REGISTER_FOR_SHADOW) { > PeimFileHandle =3D Private->Fv[Index1].FvFileHandles[Index2]; > Private->CurrentFileHandle =3D PeimFileHandle; > @@ -1063,7 +1116,7 @@ PeiDispatcher ( > // Start to dispatch all modules within the current Fv. > // > for (PeimCount =3D Private->CurrentPeimCount; > - (PeimCount < PcdGet32 (PcdPeiCoreMaxPeimPerFv)) && (Private- > >CurrentFvFileHandles[PeimCount] !=3D NULL); > + PeimCount < Private->Fv[FvCount].PeimCount; > PeimCount++) { > Private->CurrentPeimCount =3D PeimCount; > PeimFileHandle =3D Private->CurrentFileHandle =3D Private- > >CurrentFvFileHandles[PeimCount]; > @@ -1207,21 +1260,17 @@ PeiDispatcher ( > } >=20 > // > - // We set to NULL here to optimize the 2nd entry to this routine a= fter > - // memory is found. This reprevents rescanning of the FV. We set = to > - // NULL here so we start at the begining of the next FV > + // Before walking through the next FV, we should set them to NULL/= 0 to > + // start at the begining of the next FV. > // > Private->CurrentFileHandle =3D NULL; > Private->CurrentPeimCount =3D 0; > - // > - // Before walking through the next FV,Private- > >CurrentFvFileHandles[]should set to NULL > - // > - SetMem (Private->CurrentFvFileHandles, sizeof (EFI_PEI_FILE_HANDLE= ) * > PcdGet32 (PcdPeiCoreMaxPeimPerFv), 0); > + Private->CurrentFvFileHandles =3D NULL; > } >=20 > // > - // Before making another pass, we should set Private->CurrentPeimFvC= ount > =3D0 to go > - // through all the FV. > + // Before making another pass, we should set it to 0 to > + // go through all the FVs. > // > Private->CurrentPeimFvCount =3D 0; >=20 > @@ -1300,7 +1349,7 @@ DepexSatisfied ( >=20 > if (PeimCount < Private->AprioriCount) { > // > - // If its in the A priori file then we set Depex to TRUE > + // If it's in the Apriori file then we set Depex to TRUE > // > DEBUG ((DEBUG_DISPATCH, " RESULT =3D TRUE (Apriori)\n")); > return TRUE; > diff --git a/MdeModulePkg/Core/Pei/PeiMain.h=20 > b/MdeModulePkg/Core/Pei/PeiMain.h index 6469436b8f79..ab914c7d2e44=20 > 100644 > --- a/MdeModulePkg/Core/Pei/PeiMain.h > +++ b/MdeModulePkg/Core/Pei/PeiMain.h > @@ -111,12 +111,13 @@ typedef struct { > EFI_FIRMWARE_VOLUME_HEADER *FvHeader; > EFI_PEI_FIRMWARE_VOLUME_PPI *FvPpi; > EFI_PEI_FV_HANDLE FvHandle; > + UINTN PeimCount; > // > - // Ponter to the buffer with the PcdPeiCoreMaxPeimPerFv number of Entr= ies. > + // Ponter to the buffer with the PeimCount number of Entries. > // > UINT8 *PeimState; > // > - // Ponter to the buffer with the PcdPeiCoreMaxPeimPerFv number of Entr= ies. > + // Ponter to the buffer with the PeimCount number of Entries. > // > EFI_PEI_FILE_HANDLE *FvFileHandles; > BOOLEAN ScanFv; > @@ -209,7 +210,7 @@ struct _PEI_CORE_INSTANCE { > UINTN UnknownFvInfoCount; >=20 > /// > - /// Pointer to the buffer with the PcdPeiCoreMaxPeimPerFv number of en= tries. > + /// Pointer to the buffer FvFileHandlers in PEI_CORE_FV_HANDLE=20 > + specified by > CurrentPeimFvCount. > /// > EFI_PEI_FILE_HANDLE *CurrentFvFileHandles; > UINTN AprioriCount; > @@ -256,14 +257,16 @@ struct _PEI_CORE_INSTANCE { > // > PE_COFF_LOADER_READ_FILE ShadowedImageRead; >=20 > + UINTN TempPeimCount; > + > // > - // Pointer to the temp buffer with the PcdPeiCoreMaxPeimPerFv + 1=20 > number of entries. > + // Pointer to the temp buffer with the TempPeimCount number of entries= . > // > - EFI_PEI_FILE_HANDLE *FileHandles; > + EFI_PEI_FILE_HANDLE *TempFileHandles; > // > - // Pointer to the temp buffer with the PcdPeiCoreMaxPeimPerFv=20 > number of entries. > + // Pointer to the temp buffer with the TempPeimCount number of entries= . > // > - EFI_GUID *FileGuid; > + EFI_GUID *TempFileGuid; >=20 > // > // Temp Memory Range is not covered by PeiTempMem and Stack. > diff --git a/MdeModulePkg/Core/Pei/PeiMain.inf > b/MdeModulePkg/Core/Pei/PeiMain.inf > index 4e1581a926d9..d106c3606e97 100644 > --- a/MdeModulePkg/Core/Pei/PeiMain.inf > +++ b/MdeModulePkg/Core/Pei/PeiMain.inf > @@ -105,7 +105,6 @@ [Ppis] >=20 > [Pcd] > gEfiMdeModulePkgTokenSpaceGuid.PcdPeiCoreMaxFvSupported = ## > CONSUMES > - gEfiMdeModulePkgTokenSpaceGuid.PcdPeiCoreMaxPeimPerFv = ## > CONSUMES > gEfiMdeModulePkgTokenSpaceGuid.PcdPeiCoreMaxPpiSupported = ## > CONSUMES > gEfiMdeModulePkgTokenSpaceGuid.PcdPeiCoreMaxPeiStackSize = ## > CONSUMES >=20 > gEfiMdeModulePkgTokenSpaceGuid.PcdPeiCoreImageLoaderSearchTeSectionFir > st ## CONSUMES > diff --git a/MdeModulePkg/Core/Pei/PeiMain/PeiMain.c > b/MdeModulePkg/Core/Pei/PeiMain/PeiMain.c > index e3a301dfe0f2..52adefeb44b4 100644 > --- a/MdeModulePkg/Core/Pei/PeiMain/PeiMain.c > +++ b/MdeModulePkg/Core/Pei/PeiMain/PeiMain.c > @@ -185,27 +185,39 @@ PeiCore ( > if (OldCoreData->HeapOffsetPositive) { > OldCoreData->HobList.Raw =3D (VOID *)(OldCoreData->HobList.Raw=20 > + > OldCoreData->HeapOffset); > OldCoreData->UnknownFvInfo =3D > (PEI_CORE_UNKNOW_FORMAT_FV_INFO *) ((UINT8 *) OldCoreData- > >UnknownFvInfo + OldCoreData->HeapOffset); > - OldCoreData->CurrentFvFileHandles =3D (EFI_PEI_FILE_HANDLE *) ((= UINT8 *) > OldCoreData->CurrentFvFileHandles + OldCoreData->HeapOffset); > + if (OldCoreData->CurrentFvFileHandles !=3D NULL) { > + OldCoreData->CurrentFvFileHandles =3D (EFI_PEI_FILE_HANDLE *)= =20 > + ((UINT8 > *) OldCoreData->CurrentFvFileHandles + OldCoreData->HeapOffset); > + } > OldCoreData->PpiData.PpiListPtrs =3D (PEI_PPI_LIST_POINTERS *)= =20 > ((UINT8 *) > OldCoreData->PpiData.PpiListPtrs + OldCoreData->HeapOffset); > OldCoreData->Fv =3D (PEI_CORE_FV_HANDLE *) ((U= INT8 *) > OldCoreData->Fv + OldCoreData->HeapOffset); > for (Index =3D 0; Index < PcdGet32 (PcdPeiCoreMaxFvSupported); I= ndex ++) { > - OldCoreData->Fv[Index].PeimState =3D (UINT8 *) OldCoreData= - > >Fv[Index].PeimState + OldCoreData->HeapOffset; > - OldCoreData->Fv[Index].FvFileHandles =3D (EFI_PEI_FILE_HANDLE = *) > ((UINT8 *) OldCoreData->Fv[Index].FvFileHandles +=20 > OldCoreData->HeapOffset); > + if (OldCoreData->Fv[Index].PeimState !=3D NULL) { > + OldCoreData->Fv[Index].PeimState =3D (UINT8 *) OldCoreDa= ta- > >Fv[Index].PeimState + OldCoreData->HeapOffset; > + } > + if (OldCoreData->Fv[Index].FvFileHandles !=3D NULL) { > + OldCoreData->Fv[Index].FvFileHandles =3D=20 > + (EFI_PEI_FILE_HANDLE *) > ((UINT8 *) OldCoreData->Fv[Index].FvFileHandles +=20 > OldCoreData->HeapOffset); > + } > } > - OldCoreData->FileGuid =3D (EFI_GUID *) ((UINT8 *) Ol= dCoreData- > >FileGuid + OldCoreData->HeapOffset); > - OldCoreData->FileHandles =3D (EFI_PEI_FILE_HANDLE *) ((= UINT8 *) > OldCoreData->FileHandles + OldCoreData->HeapOffset); > + OldCoreData->TempFileGuid =3D (EFI_GUID *) ((UINT8 *) Ol= dCoreData- > >TempFileGuid + OldCoreData->HeapOffset); > + OldCoreData->TempFileHandles =3D (EFI_PEI_FILE_HANDLE *) ((= UINT8 *) > OldCoreData->TempFileHandles + OldCoreData->HeapOffset); > } else { > OldCoreData->HobList.Raw =3D (VOID *)(OldCoreData->HobList.Raw=20 > - > OldCoreData->HeapOffset); > OldCoreData->UnknownFvInfo =3D > (PEI_CORE_UNKNOW_FORMAT_FV_INFO *) ((UINT8 *) OldCoreData- > >UnknownFvInfo - OldCoreData->HeapOffset); > - OldCoreData->CurrentFvFileHandles =3D (EFI_PEI_FILE_HANDLE *) ((= UINT8 *) > OldCoreData->CurrentFvFileHandles - OldCoreData->HeapOffset); > + if (OldCoreData->CurrentFvFileHandles !=3D NULL) { > + OldCoreData->CurrentFvFileHandles =3D (EFI_PEI_FILE_HANDLE *)= =20 > + ((UINT8 > *) OldCoreData->CurrentFvFileHandles - OldCoreData->HeapOffset); > + } > OldCoreData->PpiData.PpiListPtrs =3D (PEI_PPI_LIST_POINTERS *)= =20 > ((UINT8 *) > OldCoreData->PpiData.PpiListPtrs - OldCoreData->HeapOffset); > OldCoreData->Fv =3D (PEI_CORE_FV_HANDLE *) ((U= INT8 *) > OldCoreData->Fv - OldCoreData->HeapOffset); > for (Index =3D 0; Index < PcdGet32 (PcdPeiCoreMaxFvSupported); I= ndex ++) { > - OldCoreData->Fv[Index].PeimState =3D (UINT8 *) OldCoreData= - > >Fv[Index].PeimState - OldCoreData->HeapOffset; > - OldCoreData->Fv[Index].FvFileHandles =3D (EFI_PEI_FILE_HANDLE = *) > ((UINT8 *) OldCoreData->Fv[Index].FvFileHandles -=20 > OldCoreData->HeapOffset); > + if (OldCoreData->Fv[Index].PeimState !=3D NULL) { > + OldCoreData->Fv[Index].PeimState =3D (UINT8 *) OldCoreDa= ta- > >Fv[Index].PeimState - OldCoreData->HeapOffset; > + } > + if (OldCoreData->Fv[Index].FvFileHandles !=3D NULL) { > + OldCoreData->Fv[Index].FvFileHandles =3D=20 > + (EFI_PEI_FILE_HANDLE *) > ((UINT8 *) OldCoreData->Fv[Index].FvFileHandles -=20 > OldCoreData->HeapOffset); > + } > } > - OldCoreData->FileGuid =3D (EFI_GUID *) ((UINT8 *) Ol= dCoreData- > >FileGuid - OldCoreData->HeapOffset); > - OldCoreData->FileHandles =3D (EFI_PEI_FILE_HANDLE *) ((= UINT8 *) > OldCoreData->FileHandles - OldCoreData->HeapOffset); > + OldCoreData->TempFileGuid =3D (EFI_GUID *) ((UINT8 *) Ol= dCoreData- > >TempFileGuid - OldCoreData->HeapOffset); > + OldCoreData->TempFileHandles =3D (EFI_PEI_FILE_HANDLE *) ((= UINT8 *) > OldCoreData->TempFileHandles - OldCoreData->HeapOffset); > } >=20 > // > @@ -320,7 +332,7 @@ PeiCore ( > // > // Initialize PEI Core Services > // > - InitializeMemoryServices (&PrivateData, SecCoreData, OldCoreData)= ; > + InitializeMemoryServices (&PrivateData, SecCoreData, OldCoreData); > if (OldCoreData =3D=3D NULL) { > // > // Initialize PEI Core Private Data Buffer @@ -329,22 +341,8 @@=20 > PeiCore ( > ASSERT (PrivateData.PpiData.PpiListPtrs !=3D NULL); > PrivateData.Fv =3D AllocateZeroPool (sizeof (PEI_C= ORE_FV_HANDLE) > * PcdGet32 (PcdPeiCoreMaxFvSupported)); > ASSERT (PrivateData.Fv !=3D NULL); > - PrivateData.Fv[0].PeimState =3D AllocateZeroPool (sizeof (UINT8= ) * > PcdGet32 (PcdPeiCoreMaxPeimPerFv) * PcdGet32 (PcdPeiCoreMaxFvSupported)); > - ASSERT (PrivateData.Fv[0].PeimState !=3D NULL); > - PrivateData.Fv[0].FvFileHandles =3D AllocateZeroPool (sizeof > (EFI_PEI_FILE_HANDLE) * PcdGet32 (PcdPeiCoreMaxPeimPerFv) * PcdGet32=20 > (PcdPeiCoreMaxFvSupported)); > - ASSERT (PrivateData.Fv[0].FvFileHandles !=3D NULL); > - for (Index =3D 1; Index < PcdGet32 (PcdPeiCoreMaxFvSupported); Index= ++) { > - PrivateData.Fv[Index].PeimState =3D PrivateData.Fv[Index - 1].= PeimState + > PcdGet32 (PcdPeiCoreMaxPeimPerFv); > - PrivateData.Fv[Index].FvFileHandles =3D PrivateData.Fv[Index - > 1].FvFileHandles + PcdGet32 (PcdPeiCoreMaxPeimPerFv); > - } > PrivateData.UnknownFvInfo =3D AllocateZeroPool (sizeof > (PEI_CORE_UNKNOW_FORMAT_FV_INFO) * PcdGet32=20 > (PcdPeiCoreMaxFvSupported)); > ASSERT (PrivateData.UnknownFvInfo !=3D NULL); > - PrivateData.CurrentFvFileHandles =3D AllocateZeroPool (sizeof > (EFI_PEI_FILE_HANDLE) * PcdGet32 (PcdPeiCoreMaxPeimPerFv)); > - ASSERT (PrivateData.CurrentFvFileHandles !=3D NULL); > - PrivateData.FileGuid =3D AllocatePool (sizeof (EFI_GUID)= * PcdGet32 > (PcdPeiCoreMaxPeimPerFv)); > - ASSERT (PrivateData.FileGuid !=3D NULL); > - PrivateData.FileHandles =3D AllocatePool (sizeof (EFI_PEI_F= ILE_HANDLE) * > (PcdGet32 (PcdPeiCoreMaxPeimPerFv) + 1)); > - ASSERT (PrivateData.FileHandles !=3D NULL); > } > InitializePpiServices (&PrivateData, OldCoreData); >=20 > -- > 2.7.0.windows.1