]> git.proxmox.com Git - mirror_edk2.git/blobdiff - OvmfPkg/QemuFlashFvbServicesRuntimeDxe/FwBlockService.c
OvmfPkg/QemuFlashFvbServicesRuntimeDxe: eliminate unchecked PcdSetXX() calls
[mirror_edk2.git] / OvmfPkg / QemuFlashFvbServicesRuntimeDxe / FwBlockService.c
index 3eccb1f9e4ed3285e1371a8b6604984af2860529..ff27c1100c01bcce9c17493d2788e1b9cf866f9d 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
+#include <Protocol/FirmwareVolumeBlock.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/DebugLib.h>\r
+#include <Library/DevicePathLib.h>\r
+#include <Library/DxeServicesTableLib.h>\r
 #include <Library/MemoryAllocationLib.h>\r
 #include <Library/UefiBootServicesTableLib.h>\r
-#include <Library/DevicePathLib.h>\r
 \r
 #include "FwBlockService.h"\r
 #include "QemuFlash.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,12 @@ 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
+  RETURN_STATUS                       PcdStatus;\r
 \r
   if (EFI_ERROR (QemuFlashInitialize ())) {\r
     //\r
@@ -1148,69 +1087,30 @@ 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
   //\r
   // Set several PCD values to point to flash\r
   //\r
-  PcdSet64 (\r
+  PcdStatus = PcdSet64S (\r
     PcdFlashNvStorageVariableBase64,\r
     (UINTN) PcdGet32 (PcdOvmfFlashNvStorageVariableBase)\r
     );\r
-  PcdSet32 (\r
+  ASSERT_RETURN_ERROR (PcdStatus);\r
+  PcdStatus = PcdSet32S (\r
     PcdFlashNvStorageFtwWorkingBase,\r
     PcdGet32 (PcdOvmfFlashNvStorageFtwWorkingBase)\r
     );\r
-  PcdSet32 (\r
+  ASSERT_RETURN_ERROR (PcdStatus);\r
+  PcdStatus = PcdSet32S (\r
     PcdFlashNvStorageFtwSpareBase,\r
     PcdGet32 (PcdOvmfFlashNvStorageFtwSpareBase)\r
     );\r
+  ASSERT_RETURN_ERROR (PcdStatus);\r
 \r
   FwhInstance = (EFI_FW_VOL_INSTANCE *)\r
     (\r
@@ -1218,17 +1118,12 @@ 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
+  PcdStatus = PcdSetBoolS (PcdOvmfFlashVariablesEnable, TRUE);\r
+  ASSERT_RETURN_ERROR (PcdStatus);\r
   return EFI_SUCCESS;\r
 }\r