From dadd8c7a95bab7e17aaa0d5bbd6c40eaf461d434 Mon Sep 17 00:00:00 2001 From: Jason1 Lin Date: Thu, 15 Aug 2024 18:05:32 +0800 Subject: MdeModulePkg/DxeCapsuleLibFmp: Change the Event Notify to Cache ESRT Table REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4831 In this patch introduced the below changes, [1] Add the event of system resource table installed callback. - Register the event in DxeRuntimeCapsuleLibConstructor () - Unregister the event in DxeRuntimeCapsuleLibDestructor () [2] Migrate the event to update the module variable to cache ESRT table from ReadyToBoot to system resource table installed. [3] Add the condition to free the pool of buffer when the "mEsrtTable" is not NULL. Co-authored-by: Dakota Chiang Signed-off-by: Jason1 Lin --- .../Library/DxeCapsuleLibFmp/DxeCapsuleRuntime.c | 60 +++++++++++++++++++--- 1 file changed, 52 insertions(+), 8 deletions(-) (limited to 'MdeModulePkg') diff --git a/MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleRuntime.c b/MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleRuntime.c index 855b7a60fc..9bea682bee 100644 --- a/MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleRuntime.c +++ b/MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleRuntime.c @@ -1,7 +1,7 @@ /** @file Capsule library runtime support. - Copyright (c) 2016 - 2017, Intel Corporation. All rights reserved.
+ Copyright (c) 2016 - 2024, Intel Corporation. All rights reserved.
Copyright (c) 2024, Ampere Computing LLC. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent @@ -23,6 +23,7 @@ extern EFI_SYSTEM_RESOURCE_TABLE *mEsrtTable; EFI_EVENT mDxeRuntimeCapsuleLibVirtualAddressChangeEvent = NULL; +EFI_EVENT mDxeRuntimeCapsuleLibSystemResourceTableEvent = NULL; EFI_EVENT mDxeRuntimeCapsuleLibReadyToBootEvent = NULL; extern BOOLEAN mDxeCapsuleLibReadyToBootEvent; @@ -44,16 +45,16 @@ DxeCapsuleLibVirtualAddressChangeEvent ( } /** - Notify function for event group EFI_EVENT_GROUP_READY_TO_BOOT. + Notify function for event of system resource table installation. - @param[in] Event The Event that is being processed. - @param[in] Context The Event Context. + @param[in] Event The Event that is being processed. + @param[in] Context The Event Context. **/ STATIC VOID EFIAPI -DxeCapsuleLibReadyToBootEventNotify ( +DxeCapsuleLibSystemResourceTableInstallEventNotify ( IN EFI_EVENT Event, IN VOID *Context ) @@ -78,6 +79,14 @@ DxeCapsuleLibReadyToBootEventNotify ( // If no Esrt table installed in Configure Table // if (Index < gST->NumberOfTableEntries) { + // + // Free the pool to remove the cached ESRT table. + // + if (mEsrtTable != NULL) { + FreePool ((VOID *)mEsrtTable); + mEsrtTable = NULL; + } + // // Search Esrt to check given capsule is qualified // @@ -95,12 +104,28 @@ DxeCapsuleLibReadyToBootEventNotify ( // mEsrtTable->FwResourceCountMax = mEsrtTable->FwResourceCount; } +} +/** + Notify function for event group EFI_EVENT_GROUP_READY_TO_BOOT. + + @param[in] Event The Event that is being processed. + @param[in] Context The Event Context. + +**/ +STATIC +VOID +EFIAPI +DxeCapsuleLibReadyToBootEventNotify ( + IN EFI_EVENT Event, + IN VOID *Context + ) +{ mDxeCapsuleLibReadyToBootEvent = TRUE; } /** - The constructor function hook VirtualAddressChange event to use ESRT table as capsule routing table. + The constructor function for the file of DxeCapsuleRuntime. @param ImageHandle The firmware allocated handle for the EFI image. @param SystemTable A pointer to the EFI System Table. @@ -130,7 +155,20 @@ DxeRuntimeCapsuleLibConstructor ( ASSERT_EFI_ERROR (Status); // - // Register notify function to cache the FMP capsule GUIDs at ReadyToBoot. + // Register notify function to cache the FMP capsule GUIDs when system resource table installed. + // + Status = gBS->CreateEventEx ( + EVT_NOTIFY_SIGNAL, + TPL_CALLBACK, + DxeCapsuleLibSystemResourceTableInstallEventNotify, + NULL, + &gEfiSystemResourceTableGuid, + &mDxeRuntimeCapsuleLibSystemResourceTableEvent + ); + ASSERT_EFI_ERROR (Status); + + // + // Register notify function to indicate the event is signaled at ReadyToBoot. // Status = gBS->CreateEventEx ( EVT_NOTIFY_SIGNAL, @@ -146,7 +184,7 @@ DxeRuntimeCapsuleLibConstructor ( } /** - The destructor function closes the VirtualAddressChange event. + The destructor function for the file of DxeCapsuleRuntime. @param ImageHandle The firmware allocated handle for the EFI image. @param SystemTable A pointer to the EFI System Table. @@ -168,6 +206,12 @@ DxeRuntimeCapsuleLibDestructor ( Status = gBS->CloseEvent (mDxeRuntimeCapsuleLibVirtualAddressChangeEvent); ASSERT_EFI_ERROR (Status); + // + // Close the system resource table installed event. + // + Status = gBS->CloseEvent (mDxeRuntimeCapsuleLibSystemResourceTableEvent); + ASSERT_EFI_ERROR (Status); + // // Close the ReadyToBoot event. // -- cgit v1.2.3