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 <ler...@redhat.com>
---
 OvmfPkg/QemuFlashFvbServicesRuntimeDxe/FvbServicesRuntimeDxe.inf |   2 +
 OvmfPkg/QemuFlashFvbServicesRuntimeDxe/FwBlockService.h          |  15 ++
 OvmfPkg/QemuFlashFvbServicesRuntimeDxe/QemuFlash.h               |   2 +
 OvmfPkg/QemuFlashFvbServicesRuntimeDxe/FwBlockService.c          | 122 
+---------------
 OvmfPkg/QemuFlashFvbServicesRuntimeDxe/FwBlockServiceDxe.c       | 154 
++++++++++++++++++++
 OvmfPkg/QemuFlashFvbServicesRuntimeDxe/QemuFlash.c               |  17 +--
 OvmfPkg/QemuFlashFvbServicesRuntimeDxe/QemuFlashDxe.c            |  28 ++++
 7 files changed, 209 insertions(+), 131 deletions(-)

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


_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel

Reply via email to