]> xenbits.xensource.com Git - people/aperard/ovmf.git/commitdiff
MdeModulePkg/DxeCapsuleLibFmp: Change the Event Notify to Cache ESRT Table
authorJason1 Lin <jason1.lin@intel.com>
Thu, 15 Aug 2024 10:05:32 +0000 (18:05 +0800)
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Wed, 11 Sep 2024 20:26:20 +0000 (20:26 +0000)
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>
MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleRuntime.c

index 855b7a60fc23884566a81a1ff7ed5c1730c18002..9bea682bee4c7e34e3395f060f91ff7c79e1ec95 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Capsule library runtime support.\r
 \r
-  Copyright (c) 2016 - 2017, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2016 - 2024, Intel Corporation. All rights reserved.<BR>\r
   Copyright (c) 2024, Ampere Computing LLC. All rights reserved.<BR>\r
   SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
@@ -23,6 +23,7 @@
 \r
 extern EFI_SYSTEM_RESOURCE_TABLE  *mEsrtTable;\r
 EFI_EVENT                         mDxeRuntimeCapsuleLibVirtualAddressChangeEvent = NULL;\r
+EFI_EVENT                         mDxeRuntimeCapsuleLibSystemResourceTableEvent  = NULL;\r
 EFI_EVENT                         mDxeRuntimeCapsuleLibReadyToBootEvent          = NULL;\r
 extern BOOLEAN                    mDxeCapsuleLibReadyToBootEvent;\r
 \r
@@ -44,16 +45,16 @@ DxeCapsuleLibVirtualAddressChangeEvent (
 }\r
 \r
 /**\r
-  Notify function for event group EFI_EVENT_GROUP_READY_TO_BOOT.\r
+  Notify function for event of system resource table installation.\r
 \r
-  @param[in]  Event   The Event that is being processed.\r
-  @param[in]  Context The Event Context.\r
+  @param[in]  Event    The Event that is being processed.\r
+  @param[in]  Context  The Event Context.\r
 \r
 **/\r
 STATIC\r
 VOID\r
 EFIAPI\r
-DxeCapsuleLibReadyToBootEventNotify (\r
+DxeCapsuleLibSystemResourceTableInstallEventNotify (\r
   IN EFI_EVENT  Event,\r
   IN VOID       *Context\r
   )\r
@@ -78,6 +79,14 @@ DxeCapsuleLibReadyToBootEventNotify (
   // If no Esrt table installed in Configure Table\r
   //\r
   if (Index < gST->NumberOfTableEntries) {\r
+    //\r
+    // Free the pool to remove the cached ESRT table.\r
+    //\r
+    if (mEsrtTable != NULL) {\r
+      FreePool ((VOID *)mEsrtTable);\r
+      mEsrtTable = NULL;\r
+    }\r
+\r
     //\r
     // Search Esrt to check given capsule is qualified\r
     //\r
@@ -95,12 +104,28 @@ DxeCapsuleLibReadyToBootEventNotify (
     //\r
     mEsrtTable->FwResourceCountMax = mEsrtTable->FwResourceCount;\r
   }\r
+}\r
 \r
+/**\r
+  Notify function for event group EFI_EVENT_GROUP_READY_TO_BOOT.\r
+\r
+  @param[in]  Event    The Event that is being processed.\r
+  @param[in]  Context  The Event Context.\r
+\r
+**/\r
+STATIC\r
+VOID\r
+EFIAPI\r
+DxeCapsuleLibReadyToBootEventNotify (\r
+  IN EFI_EVENT  Event,\r
+  IN VOID       *Context\r
+  )\r
+{\r
   mDxeCapsuleLibReadyToBootEvent = TRUE;\r
 }\r
 \r
 /**\r
-  The constructor function hook VirtualAddressChange event to use ESRT table as capsule routing table.\r
+  The constructor function for the file of DxeCapsuleRuntime.\r
 \r
   @param  ImageHandle   The firmware allocated handle for the EFI image.\r
   @param  SystemTable   A pointer to the EFI System Table.\r
@@ -130,7 +155,20 @@ DxeRuntimeCapsuleLibConstructor (
   ASSERT_EFI_ERROR (Status);\r
 \r
   //\r
-  // Register notify function to cache the FMP capsule GUIDs at ReadyToBoot.\r
+  // Register notify function to cache the FMP capsule GUIDs when system resource table installed.\r
+  //\r
+  Status = gBS->CreateEventEx (\r
+                  EVT_NOTIFY_SIGNAL,\r
+                  TPL_CALLBACK,\r
+                  DxeCapsuleLibSystemResourceTableInstallEventNotify,\r
+                  NULL,\r
+                  &gEfiSystemResourceTableGuid,\r
+                  &mDxeRuntimeCapsuleLibSystemResourceTableEvent\r
+                  );\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  //\r
+  // Register notify function to indicate the event is signaled at ReadyToBoot.\r
   //\r
   Status = gBS->CreateEventEx (\r
                   EVT_NOTIFY_SIGNAL,\r
@@ -146,7 +184,7 @@ DxeRuntimeCapsuleLibConstructor (
 }\r
 \r
 /**\r
-  The destructor function closes the VirtualAddressChange event.\r
+  The destructor function for the file of DxeCapsuleRuntime.\r
 \r
   @param  ImageHandle   The firmware allocated handle for the EFI image.\r
   @param  SystemTable   A pointer to the EFI System Table.\r
@@ -168,6 +206,12 @@ DxeRuntimeCapsuleLibDestructor (
   Status = gBS->CloseEvent (mDxeRuntimeCapsuleLibVirtualAddressChangeEvent);\r
   ASSERT_EFI_ERROR (Status);\r
 \r
+  //\r
+  // Close the system resource table installed event.\r
+  //\r
+  Status = gBS->CloseEvent (mDxeRuntimeCapsuleLibSystemResourceTableEvent);\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
   //\r
   // Close the ReadyToBoot event.\r
   //\r