]> git.proxmox.com Git - mirror_edk2.git/commitdiff
OvmfPkg: QemuFlashFvbServicesRuntimeDxe: split out runtime DXE specifics
authorLaszlo Ersek <lersek@redhat.com>
Mon, 26 Oct 2015 14:58:39 +0000 (14:58 +0000)
committerlersek <lersek@Edk2>
Mon, 26 Oct 2015 14:58:39 +0000 (14:58 +0000)
In preparation for introducing an SMM interface to this driver, move the
following traits to separate files, so that we can replace them in the new
SMM INF file:

- Protocol installations. The SMM driver will install protocol interfaces
  in the SMM protocol database, using SMM services.

- Virtual address change handler and pointer conversions. SMM drivers run
  with physical mappings and pointers must not be converted.

There are further restrictions and changes for an SMM driver, but the rest
of the code either complies with those already, or will handle the changes
transparently. For example:

- SMM drivers have access to both UEFI and SMM protocols in their entry
  points (see the PI spec 1.4, "1.7 SMM Driver Initialization"),

- MemoryAllocationLib has an SMM instance that serves allocation requests
  with the gSmst->SmmAllocatePool() service transparently, allocating
  runtime-marked SMRAM.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Reviewed-by: Jordan Justen <jordan.l.justen@intel.com>
git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@18671 6f19259b-4bc3-4df7-8a09-765794883524

OvmfPkg/QemuFlashFvbServicesRuntimeDxe/FvbServicesRuntimeDxe.inf
OvmfPkg/QemuFlashFvbServicesRuntimeDxe/FwBlockService.c
OvmfPkg/QemuFlashFvbServicesRuntimeDxe/FwBlockService.h
OvmfPkg/QemuFlashFvbServicesRuntimeDxe/FwBlockServiceDxe.c [new file with mode: 0644]
OvmfPkg/QemuFlashFvbServicesRuntimeDxe/QemuFlash.c
OvmfPkg/QemuFlashFvbServicesRuntimeDxe/QemuFlash.h
OvmfPkg/QemuFlashFvbServicesRuntimeDxe/QemuFlashDxe.c [new file with mode: 0644]

index 5f0264bc9533fcd3be4983ed946e7e5bc16e6612..480b6946b1d03e9ffad2f9d058204aab706966a1 100644 (file)
@@ -36,7 +36,9 @@
 [Sources]\r
   FvbInfo.c\r
   FwBlockService.c\r
+  FwBlockServiceDxe.c\r
   QemuFlash.c\r
+  QemuFlashDxe.c\r
 \r
 [Packages]\r
   MdePkg/MdePkg.dec\r
index 3eccb1f9e4ed3285e1371a8b6604984af2860529..0158bf9cd08a5024676aea3f547aadea2375d782 100644 (file)
 \r
 **/\r
 \r
-//\r
-// The package level header files this module uses\r
-//\r
-#include <PiDxe.h>\r
-\r
 //\r
 // The protocols, PPI and GUID defintions for this module\r
 //\r
-#include <Guid/EventGroup.h>\r
 #include <Protocol/FirmwareVolumeBlock.h>\r
 #include <Protocol/DevicePath.h>\r
 \r
 //\r
 // The Library classes this module consumes\r
 //\r
-#include <Library/UefiLib.h>\r
-#include <Library/UefiDriverEntryPoint.h>\r
 #include <Library/BaseLib.h>\r
 #include <Library/DxeServicesTableLib.h>\r
-#include <Library/UefiRuntimeLib.h>\r
 #include <Library/DebugLib.h>\r
 #include <Library/BaseMemoryLib.h>\r
 #include <Library/MemoryAllocationLib.h>\r
@@ -117,56 +108,6 @@ EFI_FW_VOL_BLOCK_DEVICE mFvbDeviceTemplate = {
 };\r
 \r
 \r
-\r
-VOID\r
-EFIAPI\r
-FvbVirtualddressChangeEvent (\r
-  IN EFI_EVENT        Event,\r
-  IN VOID             *Context\r
-  )\r
-/*++\r
-\r
-  Routine Description:\r
-\r
-    Fixup internal data so that EFI and SAL can be call in virtual mode.\r
-    Call the passed in Child Notify event and convert the mFvbModuleGlobal\r
-    date items to there virtual address.\r
-\r
-  Arguments:\r
-\r
-    (Standard EFI notify event - EFI_EVENT_NOTIFY)\r
-\r
-  Returns:\r
-\r
-    None\r
-\r
---*/\r
-{\r
-  EFI_FW_VOL_INSTANCE *FwhInstance;\r
-  UINTN               Index;\r
-\r
-  FwhInstance = mFvbModuleGlobal->FvInstance;\r
-  EfiConvertPointer (0x0, (VOID **) &mFvbModuleGlobal->FvInstance);\r
-\r
-  //\r
-  // Convert the base address of all the instances\r
-  //\r
-  Index       = 0;\r
-  while (Index < mFvbModuleGlobal->NumFv) {\r
-    EfiConvertPointer (0x0, (VOID **) &FwhInstance->FvBase);\r
-    FwhInstance = (EFI_FW_VOL_INSTANCE *)\r
-      (\r
-        (UINTN) ((UINT8 *) FwhInstance) +\r
-        FwhInstance->VolumeHeader.HeaderLength +\r
-        (sizeof (EFI_FW_VOL_INSTANCE) - sizeof (EFI_FIRMWARE_VOLUME_HEADER))\r
-      );\r
-    Index++;\r
-  }\r
-\r
-  EfiConvertPointer (0x0, (VOID **) &mFvbModuleGlobal);\r
-  QemuFlashConvertPointers ();\r
-}\r
-\r
 EFI_STATUS\r
 GetFvbInstance (\r
   IN  UINTN                               Instance,\r
@@ -1019,14 +960,11 @@ FvbInitialize (
   EFI_FIRMWARE_VOLUME_HEADER          *FwVolHeader;\r
   UINT32                              BufferSize;\r
   EFI_FV_BLOCK_MAP_ENTRY              *PtrBlockMapEntry;\r
-  EFI_HANDLE                          FwbHandle;\r
   EFI_FW_VOL_BLOCK_DEVICE             *FvbDevice;\r
-  EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL  *OldFwbInterface;\r
   UINT32                              MaxLbaSize;\r
   EFI_PHYSICAL_ADDRESS                BaseAddress;\r
   UINTN                               Length;\r
   UINTN                               NumOfBlocks;\r
-  EFI_EVENT                           VirtualAddressChangeEvent;\r
 \r
   if (EFI_ERROR (QemuFlashInitialize ())) {\r
     //\r
@@ -1148,51 +1086,9 @@ FvbInitialize (
   }\r
 \r
   //\r
-  // Find a handle with a matching device path that has supports FW Block\r
-  // protocol\r
+  // Module type specific hook.\r
   //\r
-  Status = gBS->LocateDevicePath (&gEfiFirmwareVolumeBlockProtocolGuid,\r
-                  &FvbDevice->DevicePath, &FwbHandle);\r
-  if (EFI_ERROR (Status)) {\r
-    //\r
-    // LocateDevicePath fails so install a new interface and device path\r
-    //\r
-    FwbHandle = NULL;\r
-    DEBUG ((EFI_D_INFO, "Installing QEMU flash FVB\n"));\r
-    Status = gBS->InstallMultipleProtocolInterfaces (\r
-                    &FwbHandle,\r
-                    &gEfiFirmwareVolumeBlockProtocolGuid,\r
-                    &FvbDevice->FwVolBlockInstance,\r
-                    &gEfiDevicePathProtocolGuid,\r
-                    FvbDevice->DevicePath,\r
-                    NULL\r
-                    );\r
-    ASSERT_EFI_ERROR (Status);\r
-  } else if (IsDevicePathEnd (FvbDevice->DevicePath)) {\r
-    //\r
-    // Device already exists, so reinstall the FVB protocol\r
-    //\r
-    Status = gBS->HandleProtocol (\r
-                    FwbHandle,\r
-                    &gEfiFirmwareVolumeBlockProtocolGuid,\r
-                    (VOID**)&OldFwbInterface\r
-                    );\r
-    ASSERT_EFI_ERROR (Status);\r
-\r
-    DEBUG ((EFI_D_INFO, "Reinstalling FVB for QEMU flash region\n"));\r
-    Status = gBS->ReinstallProtocolInterface (\r
-                    FwbHandle,\r
-                    &gEfiFirmwareVolumeBlockProtocolGuid,\r
-                    OldFwbInterface,\r
-                    &FvbDevice->FwVolBlockInstance\r
-                    );\r
-    ASSERT_EFI_ERROR (Status);\r
-  } else {\r
-    //\r
-    // There was a FVB protocol on an End Device Path node\r
-    //\r
-    ASSERT (FALSE);\r
-  }\r
+  InstallProtocolInterfaces (FvbDevice);\r
 \r
   MarkMemoryRangeForRuntimeAccess (BaseAddress, Length);\r
 \r
@@ -1218,16 +1114,10 @@ FvbInitialize (
       (sizeof (EFI_FW_VOL_INSTANCE) - sizeof (EFI_FIRMWARE_VOLUME_HEADER))\r
     );\r
 \r
-  VirtualAddressChangeEvent = NULL;\r
-  Status = gBS->CreateEventEx (\r
-                  EVT_NOTIFY_SIGNAL,\r
-                  TPL_NOTIFY,\r
-                  FvbVirtualddressChangeEvent,\r
-                  NULL,\r
-                  &gEfiEventVirtualAddressChangeGuid,\r
-                  &VirtualAddressChangeEvent\r
-                  );\r
-  ASSERT_EFI_ERROR (Status);\r
+  //\r
+  // Module type specific hook.\r
+  //\r
+  InstallVirtualAddressChangeHandler ();\r
 \r
   PcdSetBool (PcdOvmfFlashVariablesEnable, TRUE);\r
   return EFI_SUCCESS;\r
index 5e8c2c7aad1695ddd3d2cfde0ffe639265324532..1f9287b0876971cb7c2b9be620a128ee1099de6f 100644 (file)
@@ -34,6 +34,8 @@ typedef struct {
   EFI_FW_VOL_INSTANCE *FvInstance;\r
 } ESAL_FWB_GLOBAL;\r
 \r
+extern ESAL_FWB_GLOBAL *mFvbModuleGlobal;\r
+\r
 //\r
 // Fvb Protocol instance data\r
 //\r
@@ -174,4 +176,17 @@ FvbProtocolEraseBlocks (
   ...\r
   );\r
 \r
+//\r
+// The following functions have different implementations dependent on the\r
+// module type chosen for building this driver.\r
+//\r
+VOID\r
+InstallProtocolInterfaces (\r
+  IN EFI_FW_VOL_BLOCK_DEVICE *FvbDevice\r
+  );\r
+\r
+VOID\r
+InstallVirtualAddressChangeHandler (\r
+  VOID\r
+  );\r
 #endif\r
diff --git a/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/FwBlockServiceDxe.c b/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/FwBlockServiceDxe.c
new file mode 100644 (file)
index 0000000..c11f598
--- /dev/null
@@ -0,0 +1,154 @@
+/**@file\r
+  Functions related to the Firmware Volume Block service whose\r
+  implementation is specific to the runtime DXE driver build.\r
+\r
+  Copyright (C) 2015, Red Hat, Inc.\r
+  Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.<BR>\r
+\r
+  This program and the accompanying materials are licensed and made available\r
+  under the terms and conditions of the BSD License which accompanies this\r
+  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
+#include <Guid/EventGroup.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/DevicePathLib.h>\r
+#include <Library/UefiBootServicesTableLib.h>\r
+#include <Library/UefiRuntimeLib.h>\r
+#include <Protocol/DevicePath.h>\r
+#include <Protocol/FirmwareVolumeBlock.h>\r
+\r
+#include "FwBlockService.h"\r
+#include "QemuFlash.h"\r
+\r
+VOID\r
+InstallProtocolInterfaces (\r
+  IN EFI_FW_VOL_BLOCK_DEVICE *FvbDevice\r
+  )\r
+{\r
+  EFI_STATUS                         Status;\r
+  EFI_HANDLE                         FwbHandle;\r
+  EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *OldFwbInterface;\r
+\r
+  //\r
+  // Find a handle with a matching device path that has supports FW Block\r
+  // protocol\r
+  //\r
+  Status = gBS->LocateDevicePath (&gEfiFirmwareVolumeBlockProtocolGuid,\r
+                  &FvbDevice->DevicePath, &FwbHandle);\r
+  if (EFI_ERROR (Status)) {\r
+    //\r
+    // LocateDevicePath fails so install a new interface and device path\r
+    //\r
+    FwbHandle = NULL;\r
+    DEBUG ((EFI_D_INFO, "Installing QEMU flash FVB\n"));\r
+    Status = gBS->InstallMultipleProtocolInterfaces (\r
+                    &FwbHandle,\r
+                    &gEfiFirmwareVolumeBlockProtocolGuid,\r
+                    &FvbDevice->FwVolBlockInstance,\r
+                    &gEfiDevicePathProtocolGuid,\r
+                    FvbDevice->DevicePath,\r
+                    NULL\r
+                    );\r
+    ASSERT_EFI_ERROR (Status);\r
+  } else if (IsDevicePathEnd (FvbDevice->DevicePath)) {\r
+    //\r
+    // Device already exists, so reinstall the FVB protocol\r
+    //\r
+    Status = gBS->HandleProtocol (\r
+                    FwbHandle,\r
+                    &gEfiFirmwareVolumeBlockProtocolGuid,\r
+                    (VOID**)&OldFwbInterface\r
+                    );\r
+    ASSERT_EFI_ERROR (Status);\r
+\r
+    DEBUG ((EFI_D_INFO, "Reinstalling FVB for QEMU flash region\n"));\r
+    Status = gBS->ReinstallProtocolInterface (\r
+                    FwbHandle,\r
+                    &gEfiFirmwareVolumeBlockProtocolGuid,\r
+                    OldFwbInterface,\r
+                    &FvbDevice->FwVolBlockInstance\r
+                    );\r
+    ASSERT_EFI_ERROR (Status);\r
+  } else {\r
+    //\r
+    // There was a FVB protocol on an End Device Path node\r
+    //\r
+    ASSERT (FALSE);\r
+  }\r
+}\r
+\r
+\r
+STATIC\r
+VOID\r
+EFIAPI\r
+FvbVirtualAddressChangeEvent (\r
+  IN EFI_EVENT        Event,\r
+  IN VOID             *Context\r
+  )\r
+/*++\r
+\r
+  Routine Description:\r
+\r
+    Fixup internal data so that EFI and SAL can be call in virtual mode.\r
+    Call the passed in Child Notify event and convert the mFvbModuleGlobal\r
+    date items to there virtual address.\r
+\r
+  Arguments:\r
+\r
+    (Standard EFI notify event - EFI_EVENT_NOTIFY)\r
+\r
+  Returns:\r
+\r
+    None\r
+\r
+--*/\r
+{\r
+  EFI_FW_VOL_INSTANCE *FwhInstance;\r
+  UINTN               Index;\r
+\r
+  FwhInstance = mFvbModuleGlobal->FvInstance;\r
+  EfiConvertPointer (0x0, (VOID **) &mFvbModuleGlobal->FvInstance);\r
+\r
+  //\r
+  // Convert the base address of all the instances\r
+  //\r
+  Index       = 0;\r
+  while (Index < mFvbModuleGlobal->NumFv) {\r
+    EfiConvertPointer (0x0, (VOID **) &FwhInstance->FvBase);\r
+    FwhInstance = (EFI_FW_VOL_INSTANCE *)\r
+      (\r
+        (UINTN) ((UINT8 *) FwhInstance) +\r
+        FwhInstance->VolumeHeader.HeaderLength +\r
+        (sizeof (EFI_FW_VOL_INSTANCE) - sizeof (EFI_FIRMWARE_VOLUME_HEADER))\r
+      );\r
+    Index++;\r
+  }\r
+\r
+  EfiConvertPointer (0x0, (VOID **) &mFvbModuleGlobal);\r
+  QemuFlashConvertPointers ();\r
+}\r
+\r
+\r
+VOID\r
+InstallVirtualAddressChangeHandler (\r
+  VOID\r
+  )\r
+{\r
+  EFI_STATUS Status;\r
+  EFI_EVENT  VirtualAddressChangeEvent;\r
+\r
+  Status = gBS->CreateEventEx (\r
+                  EVT_NOTIFY_SIGNAL,\r
+                  TPL_NOTIFY,\r
+                  FvbVirtualAddressChangeEvent,\r
+                  NULL,\r
+                  &gEfiEventVirtualAddressChangeGuid,\r
+                  &VirtualAddressChangeEvent\r
+                  );\r
+  ASSERT_EFI_ERROR (Status);\r
+}\r
index 888d1eaa42e18f24b0448d1c71a80c057525bbf3..5b030468963523a168433168d6daadf92d14b4dc 100644 (file)
 \r
 **/\r
 \r
-#include "PiDxe.h"\r
 #include <Library/DebugLib.h>\r
 #include <Library/BaseMemoryLib.h>\r
 #include <Library/PcdLib.h>\r
-#include <Library/UefiBootServicesTableLib.h>\r
-#include <Library/UefiRuntimeLib.h>\r
-#include <Guid/EventGroup.h>\r
 \r
 #include "QemuFlash.h"\r
 \r
 #define CLEARED_ARRAY_STATUS  0x00\r
 \r
 \r
-STATIC UINT8       *mFlashBase = NULL;\r
+UINT8 *mFlashBase;\r
+\r
 STATIC UINTN       mFdBlockSize = 0;\r
 STATIC UINTN       mFdBlockCount = 0;\r
 \r
-\r
-VOID\r
-QemuFlashConvertPointers (\r
-  VOID\r
-  )\r
-{\r
-  EfiConvertPointer (0x0, (VOID **) &mFlashBase);\r
-}\r
-\r
-\r
 STATIC\r
 volatile UINT8*\r
 QemuFlashPtr (\r
index 975010e7f15585575ac304adec541b2cbd57ebcf..8d83dca7a52c36dfd1749955da518304b601b48d 100644 (file)
@@ -18,6 +18,8 @@
 \r
 #include <Protocol/FirmwareVolumeBlock.h>\r
 \r
+extern UINT8 *mFlashBase;\r
+\r
 /**\r
   Read from QEMU Flash\r
 \r
diff --git a/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/QemuFlashDxe.c b/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/QemuFlashDxe.c
new file mode 100644 (file)
index 0000000..08ece2b
--- /dev/null
@@ -0,0 +1,28 @@
+/** @file\r
+  OVMF support for QEMU system firmware flash device: functions specific to the\r
+  runtime DXE driver build.\r
+\r
+  Copyright (C) 2015, Red Hat, Inc.\r
+  Copyright (c) 2009 - 2013, Intel Corporation. All rights reserved.<BR>\r
+\r
+  This program and the accompanying materials are licensed and made available\r
+  under the terms and conditions of the BSD License which accompanies this\r
+  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 <Library/UefiRuntimeLib.h>\r
+\r
+#include "QemuFlash.h"\r
+\r
+VOID\r
+QemuFlashConvertPointers (\r
+  VOID\r
+  )\r
+{\r
+  EfiConvertPointer (0x0, (VOID **) &mFlashBase);\r
+}\r