MdeModulePkg/DxeCapsuleLibFmp: clone ESRT for runtime access
[mirror_edk2.git] / MdeModulePkg / Library / DxeCapsuleLibFmp / DxeCapsuleRuntime.c
index 602921d..f94044a 100644 (file)
@@ -23,6 +23,7 @@
 extern EFI_SYSTEM_RESOURCE_TABLE *mEsrtTable;\r
 extern BOOLEAN                   mIsVirtualAddrConverted;\r
 EFI_EVENT                 mDxeRuntimeCapsuleLibVirtualAddressChangeEvent  = NULL;\r
+EFI_EVENT                 mDxeRuntimeCapsuleLibReadyToBootEvent  = NULL;\r
 \r
 /**\r
   Convert EsrtTable physical address to virtual address.\r
@@ -38,8 +39,28 @@ DxeCapsuleLibVirtualAddressChangeEvent (
   IN  VOID        *Context\r
   )\r
 {\r
-  UINTN                    Index;\r
-  EFI_CONFIGURATION_TABLE  *ConfigEntry;\r
+  gRT->ConvertPointer (EFI_OPTIONAL_PTR, (VOID **)&mEsrtTable);\r
+  mIsVirtualAddrConverted = TRUE;\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
+  UINTN                       Index;\r
+  EFI_CONFIGURATION_TABLE     *ConfigEntry;\r
+  EFI_SYSTEM_RESOURCE_TABLE   *EsrtTable;\r
 \r
   //\r
   // Get Esrt table first\r
@@ -59,16 +80,19 @@ DxeCapsuleLibVirtualAddressChangeEvent (
     //\r
     // Search Esrt to check given capsule is qualified\r
     //\r
-    mEsrtTable = (EFI_SYSTEM_RESOURCE_TABLE *) ConfigEntry->VendorTable;\r
+    EsrtTable = (EFI_SYSTEM_RESOURCE_TABLE *) ConfigEntry->VendorTable;\r
+\r
+    mEsrtTable = AllocateRuntimeCopyPool (\r
+                   sizeof (EFI_SYSTEM_RESOURCE_TABLE) +\r
+                   EsrtTable->FwResourceCount * sizeof (EFI_SYSTEM_RESOURCE_ENTRY),\r
+                   EsrtTable);\r
+    ASSERT (mEsrtTable != NULL);\r
 \r
     //\r
-    // Update protocol pointer to Esrt Table.\r
+    // Set FwResourceCountMax to a sane value.\r
     //\r
-    gRT->ConvertPointer (0x00, (VOID**) &(mEsrtTable));\r
+    mEsrtTable->FwResourceCountMax = mEsrtTable->FwResourceCount;\r
   }\r
-\r
-  mIsVirtualAddrConverted = TRUE;\r
-\r
 }\r
 \r
 /**\r
@@ -101,6 +125,19 @@ DxeRuntimeCapsuleLibConstructor (
                   );\r
   ASSERT_EFI_ERROR (Status);\r
 \r
+  //\r
+  // Register notify function to cache the FMP capsule GUIDs at ReadyToBoot.\r
+  //\r
+  Status = gBS->CreateEventEx (\r
+                  EVT_NOTIFY_SIGNAL,\r
+                  TPL_CALLBACK,\r
+                  DxeCapsuleLibReadyToBootEventNotify,\r
+                  NULL,\r
+                  &gEfiEventReadyToBootGuid,\r
+                  &mDxeRuntimeCapsuleLibReadyToBootEvent\r
+                  );\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
   return EFI_SUCCESS;\r
 }\r
 \r
@@ -127,5 +164,11 @@ DxeRuntimeCapsuleLibDestructor (
   Status = gBS->CloseEvent (mDxeRuntimeCapsuleLibVirtualAddressChangeEvent);\r
   ASSERT_EFI_ERROR (Status);\r
 \r
+  //\r
+  // Close the ReadyToBoot event.\r
+  //\r
+  Status = gBS->CloseEvent (mDxeRuntimeCapsuleLibReadyToBootEvent);\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
   return EFI_SUCCESS;\r
 }\r