]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleRuntime.c
MdeModulePkg/DxeCapsuleLibFmp: Add DxeCapsuleLibFmp instance.
[mirror_edk2.git] / MdeModulePkg / Library / DxeCapsuleLibFmp / DxeCapsuleRuntime.c
diff --git a/MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleRuntime.c b/MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleRuntime.c
new file mode 100644 (file)
index 0000000..8801439
--- /dev/null
@@ -0,0 +1,112 @@
+/** @file\r
+  Capsule library runtime support.\r
+\r
+  Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>\r
+  This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#include <PiDxe.h>\r
+\r
+#include <Guid/FmpCapsule.h>\r
+#include <Guid/SystemResourceTable.h>\r
+#include <Guid/EventGroup.h>\r
+\r
+#include <Library/BaseLib.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/BaseMemoryLib.h>\r
+#include <Library/DxeServicesTableLib.h>\r
+#include <Library/UefiBootServicesTableLib.h>\r
+#include <Library/UefiRuntimeServicesTableLib.h>\r
+#include <Library/MemoryAllocationLib.h>\r
+\r
+extern EFI_SYSTEM_RESOURCE_TABLE *mEsrtTable;\r
+extern BOOLEAN                   mIsVirtualAddrConverted;\r
+\r
+/**\r
+  Convert EsrtTable physical address to virtual address.\r
+\r
+  @param[in] Event      Event whose notification function is being invoked.\r
+  @param[in] Context    The pointer to the notification function's context, which\r
+                        is implementation-dependent.\r
+**/\r
+VOID\r
+EFIAPI\r
+DxeCapsuleLibVirtualAddressChangeEvent (\r
+  IN  EFI_EVENT   Event,\r
+  IN  VOID        *Context\r
+  )\r
+{\r
+  UINTN                    Index;\r
+  EFI_CONFIGURATION_TABLE  *ConfigEntry;\r
+\r
+  //\r
+  // Get Esrt table first\r
+  //\r
+  ConfigEntry = gST->ConfigurationTable;\r
+  for (Index = 0; Index < gST->NumberOfTableEntries; Index++) {\r
+    if (CompareGuid(&gEfiSystemResourceTableGuid, &ConfigEntry->VendorGuid)) {\r
+      break;\r
+    }\r
+    ConfigEntry++;\r
+  }\r
+\r
+  //\r
+  // If no Esrt table installed in Configure Table\r
+  //\r
+  if (Index < gST->NumberOfTableEntries) {\r
+    //\r
+    // Search Esrt to check given capsule is qualified\r
+    //\r
+    mEsrtTable = (EFI_SYSTEM_RESOURCE_TABLE *) ConfigEntry->VendorTable;\r
+\r
+    //\r
+    // Update protocol pointer to Esrt Table.\r
+    //\r
+    gRT->ConvertPointer (0x00, (VOID**) &(mEsrtTable));\r
+  }\r
+\r
+  mIsVirtualAddrConverted = TRUE;\r
+\r
+}\r
+\r
+/**\r
+  The constructor function hook VirtualAddressChange event to use ESRT table as capsule routing table.\r
+\r
+  @param  ImageHandle   The firmware allocated handle for the EFI image.\r
+  @param  SystemTable   A pointer to the EFI System Table.\r
+\r
+  @retval EFI_SUCCESS   The constructor successfully .\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+DxeRuntimeCapsuleLibConstructor (\r
+  IN EFI_HANDLE         ImageHandle,\r
+  IN EFI_SYSTEM_TABLE   *SystemTable\r
+  )\r
+{\r
+  EFI_STATUS     Status;\r
+  EFI_EVENT      Event;\r
+\r
+  //\r
+  // Make sure we can handle virtual address changes.\r
+  //\r
+  Event = NULL;\r
+  Status = gBS->CreateEventEx (\r
+                  EVT_NOTIFY_SIGNAL,\r
+                  TPL_NOTIFY,\r
+                  DxeCapsuleLibVirtualAddressChangeEvent,\r
+                  NULL,\r
+                  &gEfiEventVirtualAddressChangeGuid,\r
+                  &Event\r
+                  );\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  return EFI_SUCCESS;\r
+}\r