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 <dakota.chiang@intel.com>
Signed-off-by: Jason1 Lin <jason1.lin@intel.com>
This commit is contained in:
Jason1 Lin 2024-08-15 18:05:32 +08:00 committed by mergify[bot]
parent f2557032d6
commit dadd8c7a95

View File

@ -1,7 +1,7 @@
/** @file
Capsule library runtime support.
Copyright (c) 2016 - 2017, Intel Corporation. All rights reserved.<BR>
Copyright (c) 2016 - 2024, Intel Corporation. All rights reserved.<BR>
Copyright (c) 2024, Ampere Computing LLC. All rights reserved.<BR>
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.
//