From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=134.134.136.126; helo=mga18.intel.com; envelope-from=chasel.chiu@intel.com; receiver=edk2-devel@lists.01.org Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) (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 F11882119705F for ; Mon, 17 Dec 2018 15:20:16 -0800 (PST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga106.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 17 Dec 2018 15:20:16 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,366,1539673200"; d="scan'208";a="302985455" Received: from kmsmsx155.gar.corp.intel.com ([172.21.73.106]) by fmsmga006.fm.intel.com with ESMTP; 17 Dec 2018 15:20:14 -0800 Received: from pgsmsx111.gar.corp.intel.com ([169.254.2.232]) by KMSMSX155.gar.corp.intel.com ([169.254.15.91]) with mapi id 14.03.0415.000; Tue, 18 Dec 2018 07:20:14 +0800 From: "Chiu, Chasel" To: "Zeng, Star" , "edk2-devel@lists.01.org" CC: "Wang, Jian J" , "Wu, Hao A" , "Gao, Liming" , "Ni, Ruiyu" , "Kinney, Michael D" , "Desimone, Nathaniel L" Thread-Topic: [PATCH 4/7] MdeModulePkg PeiCore: Remove the using of PcdPeiCoreMaxPpiSupported Thread-Index: AQHUk5foKaJaMlFJEEyZNY4PjoM7hKWDlucg Date: Mon, 17 Dec 2018 23:20:13 +0000 Message-ID: <3C3EFB470A303B4AB093197B6777CCEC501F5291@PGSMSX111.gar.corp.intel.com> References: <1544783322-17436-1-git-send-email-star.zeng@intel.com> <1544783322-17436-5-git-send-email-star.zeng@intel.com> In-Reply-To: <1544783322-17436-5-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.400.15 dlp-reaction: no-action x-titus-metadata-40: eyJDYXRlZ29yeUxhYmVscyI6IiIsIk1ldGFkYXRhIjp7Im5zIjoiaHR0cDpcL1wvd3d3LnRpdHVzLmNvbVwvbnNcL0ludGVsMyIsImlkIjoiZDhkYTNmMDktYzRmMC00OGRlLWJkMTYtNjQ5NjlkMzBjM2NhIiwicHJvcHMiOlt7Im4iOiJDVFBDbGFzc2lmaWNhdGlvbiIsInZhbHMiOlt7InZhbHVlIjoiQ1RQX05UIn1dfV19LCJTdWJqZWN0TGFiZWxzIjpbXSwiVE1DVmVyc2lvbiI6IjE3LjEwLjE4MDQuNDkiLCJUcnVzdGVkTGFiZWxIYXNoIjoiSHdaaGNndGVlQlRneGRpSjJOSk12NDBVK1czQWFOVlJEamh4ZFNPZXNTVWM0TklLUTJNVmQ0UXpvQ1ppcmdEMyJ9 x-ctpclassification: CTP_NT x-originating-ip: [172.30.20.205] MIME-Version: 1.0 Subject: Re: [PATCH 4/7] MdeModulePkg PeiCore: Remove the using of PcdPeiCoreMaxPpiSupported 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: Mon, 17 Dec 2018 23:20:17 -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: Friday, December 14, 2018 6:29 PM To: edk2-devel@lists.01.org Cc: Zeng, Star ; Wang, Jian J ;= Wu, Hao A ; Gao, Liming ; Ni, Ru= iyu ; Kinney, Michael D ; D= esimone, Nathaniel L ; Chiu, Chasel Subject: [PATCH 4/7] MdeModulePkg PeiCore: Remove the using of PcdPeiCoreMa= xPpiSupported REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D1405 Background as below. Problem: As static configuration from the PCDs, the binary PeiCore (for example in F= SP binary with dispatch mode) could not predict how many FVs, Files or PPIs= for different platforms. Burden: Platform developers need configure the PCDs accordingly for different platf= orms. To solve the problem and remove the burden, we can update code to remove th= e using of PcdPeiCoreMaxFvSupported, PcdPeiCoreMaxPeimPerFv and PcdPeiCoreM= axPpiSupported by extending buffer dynamically for FV, File and PPI managem= ent. This patch removes the using of PcdPeiCoreMaxPpiSupported in PeiCore. 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 | 8 +- MdeModulePkg/Core/Pei/PeiMain.h | 59 +++-- MdeModulePkg/Core/Pei/PeiMain.inf | 1 - MdeModulePkg/Core/Pei/PeiMain/PeiMain.c | 30 ++- MdeModulePkg/Core/Pei/Ppi/Ppi.c | 355 ++++++++++++++--------= ---- 5 files changed, 254 insertions(+), 199 deletions(-) diff --git a/MdeModulePkg/Core/Pei/Dispatcher/Dispatcher.c b/MdeModulePkg/C= ore/Pei/Dispatcher/Dispatcher.c index 71440bab9488..55a300adbdb8 100644 --- a/MdeModulePkg/Core/Pei/Dispatcher/Dispatcher.c +++ b/MdeModulePkg/Core/Pei/Dispatcher/Dispatcher.c @@ -1062,7 +1062,7 @@ PeiDispatcher ( // Process the Notify list and dispatch any notifies for // newly installed PPIs. // - ProcessNotifyList (Private); + ProcessDispatchNotifyList (Private); } } } @@ -1209,10 +1209,10 @@ PeiDispatcher ( // Process the Notify list and dispatch any notifies for // newly installed PPIs. // - ProcessNotifyList (Private); + ProcessDispatchNotifyList (Private); =20 // - // Recheck SwitchStackSignal after ProcessNotifyList() + // Recheck SwitchStackSignal after=20 + ProcessDispatchNotifyList() // in case PeiInstallPeiMemory() is done in a callback with // EFI_PEI_PPI_DESCRIPTOR_NOTIFY_DISPATCH. // @@ -1253,7 +1253,7 @@ PeiDispatcher ( // Process the Notify list and dispatch any notifies for // newly installed PPIs. // - ProcessNotifyList (Private); + ProcessDispatchNotifyList (Private); } } } diff --git a/MdeModulePkg/Core/Pei/PeiMain.h b/MdeModulePkg/Core/Pei/PeiMai= n.h index b248118087ad..c6c932c3e233 100644 --- a/MdeModulePkg/Core/Pei/PeiMain.h +++ b/MdeModulePkg/Core/Pei/PeiMain.h @@ -66,37 +66,60 @@ typedef union { } PEI_PPI_LIST_POINTERS; =20 /// -/// PPI database structure which contains two link: PpiList and NotifyList= . PpiList -/// is in head of PpiListPtrs array and notify is in end of PpiL= istPtrs. +/// Number of PEI_PPI_LIST_POINTERS to grow by each time we run out of=20 +room /// +#define PPI_GROWTH_STEP 64 +#define CALLBACK_NOTIFY_GROWTH_STEP 32 +#define DISPATCH_NOTIFY_GROWTH_STEP 8 + typedef struct { + UINTN CurrentCount; + UINTN MaxCount; + UINTN LastDispatchedCount; /// - /// index of end of PpiList link list. + /// MaxCount number of entries. /// - INTN PpiListEnd; + PEI_PPI_LIST_POINTERS *PpiPtrs; +} PEI_PPI_LIST; + +typedef struct { + UINTN CurrentCount; + UINTN MaxCount; /// - /// index of end of notify link list. + /// MaxCount number of entries. /// - INTN NotifyListEnd; + PEI_PPI_LIST_POINTERS *NotifyPtrs; +} PEI_CALLBACK_NOTIFY_LIST; + +typedef struct { + UINTN CurrentCount; + UINTN MaxCount; + UINTN LastDispatchedCount; /// - /// index of the dispatched notify list. + /// MaxCount number of entries. /// - INTN DispatchListEnd; + PEI_PPI_LIST_POINTERS *NotifyPtrs; +} PEI_DISPATCH_NOTIFY_LIST; + +/// +/// PPI database structure which contains three links: +/// PpiList, CallbackNotifyList and DispatchNotifyList. +/// +typedef struct { /// - /// index of last installed Ppi description in PpiList link list. + /// PPI List. /// - INTN LastDispatchedInstall; + PEI_PPI_LIST PpiList; /// - /// index of last dispatched notify in Notify link list. + /// Notify List at dispatch level. /// - INTN LastDispatchedNotify; + PEI_CALLBACK_NOTIFY_LIST CallbackNotifyList; /// - /// Ppi database has the PcdPeiCoreMaxPpiSupported number of entries. + /// Notify List at callback level. /// - PEI_PPI_LIST_POINTERS *PpiListPtrs; + PEI_DISPATCH_NOTIFY_LIST DispatchNotifyList; } PEI_PPI_DATABASE; =20 - // // PEI_CORE_FV_HANDE.PeimState // Do not change these values as there is code doing math to change states= . @@ -550,13 +573,13 @@ PeiNotifyPpi ( =20 **/ VOID -ProcessNotifyList ( +ProcessDispatchNotifyList ( IN PEI_CORE_INSTANCE *PrivateData ); =20 /** =20 - Dispatch notifications. + Process notifications. =20 @param PrivateData PeiCore's private data structure @param NotifyType Type of notify to fire. @@ -567,7 +590,7 @@ ProcessNotifyList ( =20 **/ VOID -DispatchNotify ( +ProcessNotify ( IN PEI_CORE_INSTANCE *PrivateData, IN UINTN NotifyType, IN INTN InstallStartIndex, diff --git a/MdeModulePkg/Core/Pei/PeiMain.inf b/MdeModulePkg/Core/Pei/PeiM= ain.inf index dd41fe41bc89..140c4444b107 100644 --- a/MdeModulePkg/Core/Pei/PeiMain.inf +++ b/MdeModulePkg/Core/Pei/PeiMain.inf @@ -104,7 +104,6 @@ [Ppis] gEfiSecHobDataPpiGuid ## SOMETIMES_CONSUMES =20 [Pcd] - gEfiMdeModulePkgTokenSpaceGuid.PcdPeiCoreMaxPpiSupported = ## CONSUMES gEfiMdeModulePkgTokenSpaceGuid.PcdPeiCoreMaxPeiStackSize = ## CONSUMES gEfiMdeModulePkgTokenSpaceGuid.PcdPeiCoreImageLoaderSearchTeSectionFirst= ## CONSUMES gEfiMdeModulePkgTokenSpaceGuid.PcdFrameworkCompatibilitySupport = ## CONSUMES diff --git a/MdeModulePkg/Core/Pei/PeiMain/PeiMain.c b/MdeModulePkg/Core/Pe= i/PeiMain/PeiMain.c index 4869bf18f005..4da80a8222bc 100644 --- a/MdeModulePkg/Core/Pei/PeiMain/PeiMain.c +++ b/MdeModulePkg/Core/Pei/PeiMain/PeiMain.c @@ -190,7 +190,15 @@ PeiCore ( if (OldCoreData->CurrentFvFileHandles !=3D NULL) { OldCoreData->CurrentFvFileHandles =3D (EFI_PEI_FILE_HANDLE *) ((= UINT8 *) OldCoreData->CurrentFvFileHandles + OldCoreData->HeapOffset); } - OldCoreData->PpiData.PpiListPtrs =3D (PEI_PPI_LIST_POINTERS *) ((= UINT8 *) OldCoreData->PpiData.PpiListPtrs + OldCoreData->HeapOffset); + if (OldCoreData->PpiData.PpiList.PpiPtrs !=3D NULL) { + OldCoreData->PpiData.PpiList.PpiPtrs =3D (PEI_PPI_LIST_POINTERS = *) ((UINT8 *) OldCoreData->PpiData.PpiList.PpiPtrs + OldCoreData->HeapOffse= t); + } + if (OldCoreData->PpiData.CallbackNotifyList.NotifyPtrs !=3D NULL) = { + OldCoreData->PpiData.CallbackNotifyList.NotifyPtrs =3D (PEI_PPI_= LIST_POINTERS *) ((UINT8 *) OldCoreData->PpiData.CallbackNotifyList.NotifyP= trs + OldCoreData->HeapOffset); + } + if (OldCoreData->PpiData.DispatchNotifyList.NotifyPtrs !=3D NULL) = { + OldCoreData->PpiData.DispatchNotifyList.NotifyPtrs =3D (PEI_PPI_= LIST_POINTERS *) ((UINT8 *) OldCoreData->PpiData.DispatchNotifyList.NotifyP= trs + OldCoreData->HeapOffset); + } OldCoreData->Fv =3D (PEI_CORE_FV_HANDLE *) ((UIN= T8 *) OldCoreData->Fv + OldCoreData->HeapOffset); for (Index =3D 0; Index < OldCoreData->FvCount; Index ++) { if (OldCoreData->Fv[Index].PeimState !=3D NULL) { @@ -210,7 +218= ,15 @@ PeiCore ( if (OldCoreData->CurrentFvFileHandles !=3D NULL) { OldCoreData->CurrentFvFileHandles =3D (EFI_PEI_FILE_HANDLE *) ((= UINT8 *) OldCoreData->CurrentFvFileHandles - OldCoreData->HeapOffset); } - OldCoreData->PpiData.PpiListPtrs =3D (PEI_PPI_LIST_POINTERS *) ((= UINT8 *) OldCoreData->PpiData.PpiListPtrs - OldCoreData->HeapOffset); + if (OldCoreData->PpiData.PpiList.PpiPtrs !=3D NULL) { + OldCoreData->PpiData.PpiList.PpiPtrs =3D (PEI_PPI_LIST_POINTERS = *) ((UINT8 *) OldCoreData->PpiData.PpiList.PpiPtrs - OldCoreData->HeapOffse= t); + } + if (OldCoreData->PpiData.CallbackNotifyList.NotifyPtrs !=3D NULL) = { + OldCoreData->PpiData.CallbackNotifyList.NotifyPtrs =3D (PEI_PPI_= LIST_POINTERS *) ((UINT8 *) OldCoreData->PpiData.CallbackNotifyList.NotifyP= trs - OldCoreData->HeapOffset); + } + if (OldCoreData->PpiData.DispatchNotifyList.NotifyPtrs !=3D NULL) = { + OldCoreData->PpiData.DispatchNotifyList.NotifyPtrs =3D (PEI_PPI_= LIST_POINTERS *) ((UINT8 *) OldCoreData->PpiData.DispatchNotifyList.NotifyP= trs - OldCoreData->HeapOffset); + } OldCoreData->Fv =3D (PEI_CORE_FV_HANDLE *) ((UIN= T8 *) OldCoreData->Fv - OldCoreData->HeapOffset); for (Index =3D 0; Index < OldCoreData->FvCount; Index ++) { if (OldCoreData->Fv[Index].PeimState !=3D NULL) { @@ -337,14 +35= 3,6 @@ PeiCore ( // Initialize PEI Core Services // InitializeMemoryServices (&PrivateData, SecCoreData, OldCoreData); - if (OldCoreData =3D=3D NULL) { - // - // Initialize PEI Core Private Data Buffer - // - PrivateData.PpiData.PpiListPtrs =3D AllocateZeroPool (sizeof (PEI_PPI= _LIST_POINTERS) * PcdGet32 (PcdPeiCoreMaxPpiSupported)); - ASSERT (PrivateData.PpiData.PpiListPtrs !=3D NULL); - } - InitializePpiServices (&PrivateData, OldCoreData); =20 // // Update performance measurements @@ -414,7 +422,7 @@ PeiCore ( // // Process the Notify list and dispatch any notifies for the Memory Di= scovered PPI // - ProcessNotifyList (&PrivateData); + ProcessDispatchNotifyList (&PrivateData); =20 PERF_INMODULE_END ("DisMem"); } diff --git a/MdeModulePkg/Core/Pei/Ppi/Ppi.c b/MdeModulePkg/Core/Pei/Ppi/Pp= i.c index 6f03858b8a94..907b2bbcf466 100644 --- a/MdeModulePkg/Core/Pei/Ppi/Ppi.c +++ b/MdeModulePkg/Core/Pei/Ppi/Ppi.c @@ -16,28 +16,6 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHE= R EXPRESS OR IMPLIED. =20 /** =20 - Initialize PPI services. - - @param PrivateData Pointer to the PEI Core data. - @param OldCoreData Pointer to old PEI Core data. - NULL if being run in non-permament memory mode. - -**/ -VOID -InitializePpiServices ( - IN PEI_CORE_INSTANCE *PrivateData, - IN PEI_CORE_INSTANCE *OldCoreData - ) -{ - if (OldCoreData =3D=3D NULL) { - PrivateData->PpiData.NotifyListEnd =3D PcdGet32 (PcdPeiCoreMaxPpiSuppo= rted)-1; - PrivateData->PpiData.DispatchListEnd =3D PcdGet32 (PcdPeiCoreMaxPpiSup= ported)-1; - PrivateData->PpiData.LastDispatchedNotify =3D PcdGet32 (PcdPeiCoreMaxP= piSupported)-1; - } -} - -/** - Migrate Pointer from the temporary memory to PEI installed memory. =20 @param Pointer Pointer to the Pointer needs to be converted. @@ -192,14 +170,37 @@ ConvertPpiPointers ( { UINT8 Index; =20 - for (Index =3D 0; Index < PcdGet32 (PcdPeiCoreMaxPpiSupported); Index++)= { - if (Index < PrivateData->PpiData.PpiListEnd || Index > PrivateData->Pp= iData.NotifyListEnd) { - ConvertSinglePpiPointer ( - SecCoreData, - PrivateData, - &PrivateData->PpiData.PpiListPtrs[Index] - ); - } + // + // Convert normal PPIs. + // + for (Index =3D 0; Index < PrivateData->PpiData.PpiList.CurrentCount; Ind= ex++) { + ConvertSinglePpiPointer ( + SecCoreData, + PrivateData, + &PrivateData->PpiData.PpiList.PpiPtrs[Index] + ); + } + + // + // Convert Callback Notification PPIs. + // + for (Index =3D 0; Index < PrivateData->PpiData.CallbackNotifyList.Curren= tCount; Index++) { + ConvertSinglePpiPointer ( + SecCoreData, + PrivateData, + &PrivateData->PpiData.CallbackNotifyList.NotifyPtrs[Index] + ); + } + + // + // Convert Dispatch Notification PPIs. + // + for (Index =3D 0; Index < PrivateData->PpiData.DispatchNotifyList.Curren= tCount; Index++) { + ConvertSinglePpiPointer ( + SecCoreData, + PrivateData, + &PrivateData->PpiData.DispatchNotifyList.NotifyPtrs[Index] + ); } } =20 @@ -228,10 +229,11 @@ InternalPeiInstallPpi ( IN BOOLEAN Single ) { - PEI_CORE_INSTANCE *PrivateData; - INTN Index; - INTN LastCallbackInstall; - + PEI_CORE_INSTANCE *PrivateData; + PEI_PPI_LIST *PpiListPointer; + UINTN Index; + UINTN LastCount; + VOID *TempPtr; =20 if (PpiList =3D=3D NULL) { return EFI_INVALID_PARAMETER; @@ -239,8 +241,9 @@ InternalPeiInstallPpi ( =20 PrivateData =3D PEI_CORE_INSTANCE_FROM_PS_THIS(PeiServices); =20 - Index =3D PrivateData->PpiData.PpiListEnd; - LastCallbackInstall =3D Index; + PpiListPointer =3D &PrivateData->PpiData.PpiList; Index =3D=20 + PpiListPointer->CurrentCount; LastCount =3D Index; =20 // // This is loop installs all PPI descriptors in the PpiList. It is term= inated @@ -250,27 +253,37 @@ InternalPeiInstallPpi ( =20 for (;;) { // - // Since PpiData is used for NotifyList and PpiList, max resource - // is reached if the Install reaches the NotifyList - // PcdPeiCoreMaxPpiSupported can be set to a larger value in DSC to sa= tisfy more PPI requirement. - // - if (Index =3D=3D PrivateData->PpiData.NotifyListEnd + 1) { - return EFI_OUT_OF_RESOURCES; - } - // // Check if it is a valid PPI. // If not, rollback list to exclude all in this list. // Try to indicate which item failed. // if ((PpiList->Flags & EFI_PEI_PPI_DESCRIPTOR_PPI) =3D=3D 0) { - PrivateData->PpiData.PpiListEnd =3D LastCallbackInstall; + PpiListPointer->CurrentCount =3D LastCount; DEBUG((EFI_D_ERROR, "ERROR -> InstallPpi: %g %p\n", PpiList->Guid, P= piList->Ppi)); return EFI_INVALID_PARAMETER; } =20 + if (Index =3D=3D PpiListPointer->MaxCount) { + // + // Run out of room, grow the buffer. + // + TempPtr =3D AllocateZeroPool ( + sizeof (PEI_PPI_LIST_POINTERS) * (PpiListPointer->MaxCou= nt + PPI_GROWTH_STEP) + ); + ASSERT (TempPtr !=3D NULL); + CopyMem ( + TempPtr, + PpiListPointer->PpiPtrs, + sizeof (PEI_PPI_LIST_POINTERS) * PpiListPointer->MaxCount + ); + PpiListPointer->PpiPtrs =3D TempPtr; + PpiListPointer->MaxCount =3D PpiListPointer->MaxCount + PPI_GROWTH_S= TEP; + } + DEBUG((EFI_D_INFO, "Install PPI: %g\n", PpiList->Guid)); - PrivateData->PpiData.PpiListPtrs[Index].Ppi =3D (EFI_PEI_PPI_DESCRIPTO= R*) PpiList; - PrivateData->PpiData.PpiListEnd++; + PpiListPointer->PpiPtrs[Index].Ppi =3D (EFI_PEI_PPI_DESCRIPTOR *) PpiL= ist; + Index++; + PpiListPointer->CurrentCount++; =20 if (Single) { // @@ -284,23 +297,24 @@ InternalPeiInstallPpi ( // break; } + // + // Go to the next descriptor. + // PpiList++; - Index++; } =20 // - // Dispatch any callback level notifies for newly installed PPIs. + // Process any callback level notifies for newly installed PPIs. // - DispatchNotify ( + ProcessNotify ( PrivateData, EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK, - LastCallbackInstall, - PrivateData->PpiData.PpiListEnd, - PrivateData->PpiData.DispatchListEnd, - PrivateData->PpiData.NotifyListEnd + LastCount, + PpiListPointer->CurrentCount, + 0, + PrivateData->PpiData.CallbackNotifyList.CurrentCount ); =20 - return EFI_SUCCESS; } =20 @@ -355,7 +369,7 @@ PeiReInstallPpi ( ) { PEI_CORE_INSTANCE *PrivateData; - INTN Index; + UINTN Index; =20 =20 if ((OldPpi =3D=3D NULL) || (NewPpi =3D=3D NULL)) { @@ -372,35 +386,33 @= @ PeiReInstallPpi ( // Find the old PPI instance in the database. If we can not find it, // return the EFI_NOT_FOUND error. // - for (Index =3D 0; Index < PrivateData->PpiData.PpiListEnd; Index++) { - if (OldPpi =3D=3D PrivateData->PpiData.PpiListPtrs[Index].Ppi) { + for (Index =3D 0; Index < PrivateData->PpiData.PpiList.CurrentCount; Ind= ex++) { + if (OldPpi =3D=3D PrivateData->PpiData.PpiList.PpiPtrs[Index].Ppi) { break; } } - if (Index =3D=3D PrivateData->PpiData.PpiListEnd) { + if (Index =3D=3D PrivateData->PpiData.PpiList.CurrentCount) { return EFI_NOT_FOUND; } =20 // - // Remove the old PPI from the database, add the new one. + // Replace the old PPI with the new one. // DEBUG((EFI_D_INFO, "Reinstall PPI: %g\n", NewPpi->Guid)); - ASSERT (Index < (INTN)(PcdGet32 (PcdPeiCoreMaxPpiSupported))); - PrivateData->PpiData.PpiListPtrs[Index].Ppi =3D (EFI_PEI_PPI_DESCRIPTOR = *) NewPpi; + PrivateData->PpiData.PpiList.PpiPtrs[Index].Ppi =3D=20 + (EFI_PEI_PPI_DESCRIPTOR *) NewPpi; =20 // - // Dispatch any callback level notifies for the newly installed PPI. + // Process any callback level notifies for the newly installed PPI. // - DispatchNotify ( + ProcessNotify ( PrivateData, EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK, Index, Index+1, - PrivateData->PpiData.DispatchListEnd, - PrivateData->PpiData.NotifyListEnd + 0, + PrivateData->PpiData.CallbackNotifyList.CurrentCount ); =20 - return EFI_SUCCESS; } =20 @@ -430,10 +442,10 @@ PeiLocatePpi ( IN OUT VOID **Ppi ) { - PEI_CORE_INSTANCE *PrivateData; - INTN Index; - EFI_GUID *CheckGuid; - EFI_PEI_PPI_DESCRIPTOR *TempPtr; + PEI_CORE_INSTANCE *PrivateData; + UINTN Index; + EFI_GUID *CheckGuid; + EFI_PEI_PPI_DESCRIPTOR *TempPtr; =20 =20 PrivateData =3D PEI_CORE_INSTANCE_FROM_PS_THIS(PeiServices); @@ -441,8 +453,8 @@ PeiLocatePpi ( // // Search the data base for the matching instance of the GUIDed PPI. // - for (Index =3D 0; Index < PrivateData->PpiData.PpiListEnd; Index++) { - TempPtr =3D PrivateData->PpiData.PpiListPtrs[Index].Ppi; + for (Index =3D 0; Index < PrivateData->PpiData.PpiList.CurrentCount; Ind= ex++) { + TempPtr =3D PrivateData->PpiData.PpiList.PpiPtrs[Index].Ppi; CheckGuid =3D TempPtr->Guid; =20 // @@ -498,15 +510,14 @@ InternalPeiNotifyPpi ( IN BOOLEAN Single ) { - PEI_CORE_INSTANCE *PrivateData; - INTN Index; - INTN NotifyIndex; - INTN LastCallbackNotify; - EFI_PEI_NOTIFY_DESCRIPTOR *NotifyPtr; - UINTN NotifyDispatchCount; - - - NotifyDispatchCount =3D 0; + PEI_CORE_INSTANCE *PrivateData; + PEI_CALLBACK_NOTIFY_LIST *CallbackNotifyListPointer; + UINTN CallbackNotifyIndex; + UINTN LastCallbackNotifyCount; + PEI_DISPATCH_NOTIFY_LIST *DispatchNotifyListPointer; + UINTN DispatchNotifyIndex; + UINTN LastDispatchNotifyCount; + VOID *TempPtr; =20 if (NotifyList =3D=3D NULL) { return EFI_INVALID_PARAMETER; @@ -514,8 +525,13 @@ InternalPeiNotifyPpi ( =20 PrivateData =3D PEI_CORE_INSTANCE_FROM_PS_THIS(PeiServices); =20 - Index =3D PrivateData->PpiData.NotifyListEnd; - LastCallbackNotify =3D Index; + CallbackNotifyListPointer =3D &PrivateData->PpiData.CallbackNotifyList; + CallbackNotifyIndex =3D CallbackNotifyListPointer->CurrentCount; + LastCallbackNotifyCount =3D CallbackNotifyIndex; + + DispatchNotifyListPointer =3D &PrivateData->PpiData.DispatchNotifyList; + DispatchNotifyIndex =3D DispatchNotifyListPointer->CurrentCount; + LastDispatchNotifyCount =3D DispatchNotifyIndex; =20 // // This is loop installs all Notify descriptors in the NotifyList. It i= s @@ -525,31 +541,59 @@ InternalPeiNotifyPpi ( =20 for (;;) { // - // Since PpiData is used for NotifyList and InstallList, max resource - // is reached if the Install reaches the PpiList - // PcdPeiCoreMaxPpiSupported can be set to a larger value in DSC to sa= tisfy more Notify PPIs requirement. - // - if (Index =3D=3D PrivateData->PpiData.PpiListEnd - 1) { - return EFI_OUT_OF_RESOURCES; - } - - // // If some of the PPI data is invalid restore original Notify PPI data= base value // if ((NotifyList->Flags & EFI_PEI_PPI_DESCRIPTOR_NOTIFY_TYPES) =3D=3D 0= ) { - PrivateData->PpiData.NotifyListEnd =3D LastCallbackNotify; - DEBUG((EFI_D_ERROR, "ERROR -> InstallNotify: %g %p\n", NotifyList-= >Guid, NotifyList->Notify)); + CallbackNotifyListPointer->CurrentCount =3D LastCallbackNotifyCoun= t; + DispatchNotifyListPointer->CurrentCount =3D LastDispatchNotifyCoun= t; + DEBUG((EFI_D_ERROR, "ERROR -> NotifyPpi: %g %p\n",=20 + NotifyList->Guid, NotifyList->Notify)); return EFI_INVALID_PARAMETER; } =20 - if ((NotifyList->Flags & EFI_PEI_PPI_DESCRIPTOR_NOTIFY_DISPATCH) !=3D = 0) { - NotifyDispatchCount ++; + if ((NotifyList->Flags & EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK) !=3D = 0) { + if (CallbackNotifyIndex =3D=3D CallbackNotifyListPointer->MaxCount) = { + // + // Run out of room, grow the buffer. + // + TempPtr =3D AllocateZeroPool ( + sizeof (PEI_PPI_LIST_POINTERS) * (CallbackNotifyListPo= inter->MaxCount + CALLBACK_NOTIFY_GROWTH_STEP) + ); + ASSERT (TempPtr !=3D NULL); + CopyMem ( + TempPtr, + CallbackNotifyListPointer->NotifyPtrs, + sizeof (PEI_PPI_LIST_POINTERS) * CallbackNotifyListPointer->MaxC= ount + ); + CallbackNotifyListPointer->NotifyPtrs =3D TempPtr; + CallbackNotifyListPointer->MaxCount =3D CallbackNotifyListPointer-= >MaxCount + CALLBACK_NOTIFY_GROWTH_STEP; + } + CallbackNotifyListPointer->NotifyPtrs[CallbackNotifyIndex].Notify = =3D (EFI_PEI_NOTIFY_DESCRIPTOR *) NotifyList; + CallbackNotifyIndex++; + CallbackNotifyListPointer->CurrentCount++; + } else { + if (DispatchNotifyIndex =3D=3D DispatchNotifyListPointer->MaxCount) = { + // + // Run out of room, grow the buffer. + // + TempPtr =3D AllocateZeroPool ( + sizeof (PEI_PPI_LIST_POINTERS) * (DispatchNotifyListPo= inter->MaxCount + DISPATCH_NOTIFY_GROWTH_STEP) + ); + ASSERT (TempPtr !=3D NULL); + CopyMem ( + TempPtr, + DispatchNotifyListPointer->NotifyPtrs, + sizeof (PEI_PPI_LIST_POINTERS) * DispatchNotifyListPointer->MaxC= ount + ); + DispatchNotifyListPointer->NotifyPtrs =3D TempPtr; + DispatchNotifyListPointer->MaxCount =3D DispatchNotifyListPointer-= >MaxCount + DISPATCH_NOTIFY_GROWTH_STEP; + } + DispatchNotifyListPointer->NotifyPtrs[DispatchNotifyIndex].Notify = =3D (EFI_PEI_NOTIFY_DESCRIPTOR *) NotifyList; + DispatchNotifyIndex++; + DispatchNotifyListPointer->CurrentCount++; } =20 - PrivateData->PpiData.PpiListPtrs[Index].Notify =3D (EFI_PEI_NOTIFY_DES= CRIPTOR *) NotifyList; - - PrivateData->PpiData.NotifyListEnd--; DEBUG((EFI_D_INFO, "Register PPI Notify: %g\n", NotifyList->Guid)); + if (Single) { // // Only single entry in the NotifyList. @@ -563,41 +607,21 @@ InternalPeiNotifyPpi ( break; } // - // Go the next descriptor. Remember the NotifyList moves down. + // Go to the next descriptor. // NotifyList++; - Index--; - } - - // - // If there is Dispatch Notify PPI installed put them on the bottom - // - if (NotifyDispatchCount > 0) { - for (NotifyIndex =3D LastCallbackNotify; NotifyIndex > PrivateData->Pp= iData.NotifyListEnd; NotifyIndex--) { - if ((PrivateData->PpiData.PpiListPtrs[NotifyIndex].Notify->Flags & E= FI_PEI_PPI_DESCRIPTOR_NOTIFY_DISPATCH) !=3D 0) { - NotifyPtr =3D PrivateData->PpiData.PpiListPtrs[NotifyIndex].Notify= ; - - for (Index =3D NotifyIndex; Index < PrivateData->PpiData.DispatchL= istEnd; Index++){ - PrivateData->PpiData.PpiListPtrs[Index].Notify =3D PrivateData->= PpiData.PpiListPtrs[Index + 1].Notify; - } - PrivateData->PpiData.PpiListPtrs[Index].Notify =3D NotifyPtr; - PrivateData->PpiData.DispatchListEnd--; - } - } - - LastCallbackNotify -=3D NotifyDispatchCount; } =20 // - // Dispatch any callback level notifies for all previously installed PPI= s. + // Process any callback level notifies for all previously installed PPIs= . // - DispatchNotify ( + ProcessNotify ( PrivateData, EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK, 0, - PrivateData->PpiData.PpiListEnd, - LastCallbackNotify, - PrivateData->PpiData.NotifyListEnd + PrivateData->PpiData.PpiList.CurrentCount, + LastCallbackNotifyCount, + CallbackNotifyListPointer->CurrentCount ); =20 return EFI_SUCCESS; @@ -627,7 +651,6 @@ PeiNotifyPpi ( return InternalPeiNotifyPpi (PeiServices, NotifyList, FALSE); } =20 - /** =20 Process the Notify List at dispatch level. @@ -636,55 +659,56 @@ PeiNotifyPpi ( =20 **/ VOID -ProcessNotifyList ( +ProcessDispatchNotifyList ( IN PEI_CORE_INSTANCE *PrivateData ) { - INTN TempValue; + UINTN TempValue; =20 while (TRUE) { // // Check if the PEIM that was just dispatched resulted in any // Notifies getting installed. If so, go process any dispatch // level Notifies that match the previouly installed PPIs. - // Use "while" instead of "if" since DispatchNotify can modify - // DispatchListEnd (with NotifyPpi) so we have to iterate until the sa= me. + // Use "while" instead of "if" since ProcessNotify can modify + // DispatchNotifyList.CurrentCount (with NotifyPpi) so we have + // to iterate until the same. // - while (PrivateData->PpiData.LastDispatchedNotify !=3D PrivateData->Ppi= Data.DispatchListEnd) { - TempValue =3D PrivateData->PpiData.DispatchListEnd; - DispatchNotify ( + while (PrivateData->PpiData.DispatchNotifyList.LastDispatchedCount != =3D PrivateData->PpiData.DispatchNotifyList.CurrentCount) { + TempValue =3D PrivateData->PpiData.DispatchNotifyList.CurrentCount; + ProcessNotify ( PrivateData, EFI_PEI_PPI_DESCRIPTOR_NOTIFY_DISPATCH, 0, - PrivateData->PpiData.LastDispatchedInstall, - PrivateData->PpiData.LastDispatchedNotify, - PrivateData->PpiData.DispatchListEnd + PrivateData->PpiData.PpiList.LastDispatchedCount, + PrivateData->PpiData.DispatchNotifyList.LastDispatchedCount, + PrivateData->PpiData.DispatchNotifyList.CurrentCount ); - PrivateData->PpiData.LastDispatchedNotify =3D TempValue; + PrivateData->PpiData.DispatchNotifyList.LastDispatchedCount =3D=20 + TempValue; } =20 - // // Check if the PEIM that was just dispatched resulted in any // PPIs getting installed. If so, go process any dispatch // level Notifies that match the installed PPIs. - // Use "while" instead of "if" since DispatchNotify can modify - // PpiListEnd (with InstallPpi) so we have to iterate until the same. + // Use "while" instead of "if" since ProcessNotify can modify + // PpiList.CurrentCount (with InstallPpi) so we have to iterate + // until the same. // - while (PrivateData->PpiData.LastDispatchedInstall !=3D PrivateData->Pp= iData.PpiListEnd) { - TempValue =3D PrivateData->PpiData.PpiListEnd; - DispatchNotify ( + while (PrivateData->PpiData.PpiList.LastDispatchedCount !=3D PrivateDa= ta->PpiData.PpiList.CurrentCount) { + TempValue =3D PrivateData->PpiData.PpiList.CurrentCount; + ProcessNotify ( PrivateData, EFI_PEI_PPI_DESCRIPTOR_NOTIFY_DISPATCH, - PrivateData->PpiData.LastDispatchedInstall, - PrivateData->PpiData.PpiListEnd, - PcdGet32 (PcdPeiCoreMaxPpiSupported)-1, - PrivateData->PpiData.DispatchListEnd + PrivateData->PpiData.PpiList.LastDispatchedCount, + PrivateData->PpiData.PpiList.CurrentCount, + 0, + PrivateData->PpiData.DispatchNotifyList.LastDispatchedCount ); - PrivateData->PpiData.LastDispatchedInstall =3D TempValue; + PrivateData->PpiData.PpiList.LastDispatchedCount =3D TempValue; } =20 - if (PrivateData->PpiData.LastDispatchedNotify =3D=3D PrivateData->PpiD= ata.DispatchListEnd) { + if (PrivateData->PpiData.DispatchNotifyList.LastDispatchedCount =3D=3D= =20 + PrivateData->PpiData.DispatchNotifyList.CurrentCount) { break; } } @@ -693,7 +717,7 @@ ProcessNotifyList ( =20 /** =20 - Dispatch notifications. + Process notifications. =20 @param PrivateData PeiCore's private data structure @param NotifyType Type of notify to fire. @@ -704,7 +728,7 @@ ProcessNotifyList ( =20 **/ VOID -DispatchNotify ( +ProcessNotify ( IN PEI_CORE_INSTANCE *PrivateData, IN UINTN NotifyType, IN INTN InstallStartIndex, @@ -713,22 +737,23 @@ DispatchNotify ( IN INTN NotifyStopIndex ) { - INTN Index1; - INTN Index2; - EFI_GUID *SearchGuid; - EFI_GUID *CheckGuid; - EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor; - - // - // Remember that Installs moves up and Notifies moves down. - // - for (Index1 =3D NotifyStartIndex; Index1 > NotifyStopIndex; Index1--) { - NotifyDescriptor =3D PrivateData->PpiData.PpiListPtrs[Index1].Notify; + INTN Index1; + INTN Index2; + EFI_GUID *SearchGuid; + EFI_GUID *CheckGuid; + EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor; + + for (Index1 =3D NotifyStartIndex; Index1 < NotifyStopIndex; Index1++) { + if (NotifyType =3D=3D EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK) { + NotifyDescriptor =3D PrivateData->PpiData.CallbackNotifyList.NotifyP= trs[Index1].Notify; + } else { + NotifyDescriptor =3D PrivateData->PpiData.DispatchNotifyList.NotifyP= trs[Index1].Notify; + } =20 CheckGuid =3D NotifyDescriptor->Guid; =20 for (Index2 =3D InstallStartIndex; Index2 < InstallStopIndex; Index2++= ) { - SearchGuid =3D PrivateData->PpiData.PpiListPtrs[Index2].Ppi->Guid; + SearchGuid =3D=20 + PrivateData->PpiData.PpiList.PpiPtrs[Index2].Ppi->Guid; // // Don't use CompareGuid function here for performance reasons. // Instead we compare the GUID as INT32 at a time and branch @@ -745= ,7 +770,7 @@ DispatchNotify ( NotifyDescriptor->Notify ( (EFI_PEI_SERVICES **) GetPeiServicesTablePoint= er (), NotifyDescriptor, - (PrivateData->PpiData.PpiListPtrs[Index2].Ppi)= ->Ppi + =20 + (PrivateData->PpiData.PpiList.PpiPtrs[Index2].Ppi)->Ppi ); } } -- 2.7.0.windows.1