]> git.proxmox.com Git - mirror_edk2.git/commitdiff
OvmfPkg: QemuFlashFvbServicesRuntimeDxe: no dual addressing needed
authorLaszlo Ersek <lersek@redhat.com>
Mon, 26 Oct 2015 14:58:33 +0000 (14:58 +0000)
committerlersek <lersek@Edk2>
Mon, 26 Oct 2015 14:58:33 +0000 (14:58 +0000)
Currently the EFI_FW_VOL_INSTANCE and ESAL_FWB_GLOBAL structures declare
the following entries as arrays, with two entries each:

- EFI_FW_VOL_INSTANCE.FvBase[2]
- ESAL_FWB_GLOBAL.FvInstance[2]

In every case, the entry at subscript zero is meant as "physical address",
while the entry at subscript one is meant as "virtual address" -- a
pointer to the same object. The virtual address entry is originally
initialized to the physical address, and then it is converted to the
virtual mapping in FvbVirtualddressChangeEvent().

Functions that (a) read the listed fields and (b) run both before and
after the virtual address change event -- since this is a runtime DXE
driver -- derive the correct array subscript by calling the
EfiGoneVirtual() function from UefiRuntimeLib.

The problem with the above infrastructure is that it's entirely
superfluous.

EfiGoneVirtual() "knows" whether EFI has gone virtual only because the
UefiRuntimeLib constructor registers the exact same kind of virtual
address change callback, and the callback flips a static variabe to TRUE,
and EfiGoneVirtual() queries that static variable.

In effect this means for QemuFlashFvbServicesRuntimeDxe: "when there is a
virtual address change, convert the entries with subscript one from
physical to virtual, and from then on use the entries with subscript one".

This would only make sense if QemuFlashFvbServicesRuntimeDxe ever needed
the original (physical) addresses (ie. the entries with subscript zero)
after the virtual address change, but that is not the case.

Replace the arrays with single elements. The subscript zero elements
simply disappear, and the single elements take the role of the prior
subscript one elements.

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@18670 6f19259b-4bc3-4df7-8a09-765794883524

OvmfPkg/QemuFlashFvbServicesRuntimeDxe/FwBlockService.c
OvmfPkg/QemuFlashFvbServicesRuntimeDxe/FwBlockService.h

index 95ae8ccb762adefe147733d1d5a118a0606239c5..3eccb1f9e4ed3285e1371a8b6604984af2860529 100644 (file)
@@ -132,11 +132,6 @@ FvbVirtualddressChangeEvent (
     Call the passed in Child Notify event and convert the mFvbModuleGlobal\r
     date items to there virtual address.\r
 \r
-    mFvbModuleGlobal->FvInstance[FVB_PHYSICAL]  - Physical copy of instance\r
-                                                  data\r
-    mFvbModuleGlobal->FvInstance[FVB_VIRTUAL]   - Virtual pointer to common\r
-                                                  instance data.\r
-\r
   Arguments:\r
 \r
     (Standard EFI notify event - EFI_EVENT_NOTIFY)\r
@@ -150,16 +145,15 @@ FvbVirtualddressChangeEvent (
   EFI_FW_VOL_INSTANCE *FwhInstance;\r
   UINTN               Index;\r
 \r
-  EfiConvertPointer (0x0,\r
-    (VOID **) &mFvbModuleGlobal->FvInstance[FVB_VIRTUAL]);\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
-  FwhInstance = mFvbModuleGlobal->FvInstance[FVB_PHYSICAL];\r
   while (Index < mFvbModuleGlobal->NumFv) {\r
-    EfiConvertPointer (0x0, (VOID **) &FwhInstance->FvBase[FVB_VIRTUAL]);\r
+    EfiConvertPointer (0x0, (VOID **) &FwhInstance->FvBase);\r
     FwhInstance = (EFI_FW_VOL_INSTANCE *)\r
       (\r
         (UINTN) ((UINT8 *) FwhInstance) +\r
@@ -177,8 +171,7 @@ EFI_STATUS
 GetFvbInstance (\r
   IN  UINTN                               Instance,\r
   IN  ESAL_FWB_GLOBAL                     *Global,\r
-  OUT EFI_FW_VOL_INSTANCE                 **FwhInstance,\r
-  IN BOOLEAN                              Virtual\r
+  OUT EFI_FW_VOL_INSTANCE                 **FwhInstance\r
   )\r
 /*++\r
 \r
@@ -191,7 +184,6 @@ GetFvbInstance (
     Global                - Pointer to ESAL_FWB_GLOBAL that contains all\r
                             instance data\r
     FwhInstance           - The EFI_FW_VOL_INSTANCE fimrware instance structure\r
-    Virtual               - Whether CPU is in virtual or physical mode\r
 \r
   Returns:\r
     EFI_SUCCESS           - Successfully returns\r
@@ -208,7 +200,7 @@ GetFvbInstance (
   //\r
   // Find the right instance of the FVB private data\r
   //\r
-  FwhRecord = Global->FvInstance[Virtual];\r
+  FwhRecord = Global->FvInstance;\r
   while (Instance > 0) {\r
     FwhRecord = (EFI_FW_VOL_INSTANCE *)\r
       (\r
@@ -227,8 +219,7 @@ EFI_STATUS
 FvbGetPhysicalAddress (\r
   IN UINTN                                Instance,\r
   OUT EFI_PHYSICAL_ADDRESS                *Address,\r
-  IN ESAL_FWB_GLOBAL                      *Global,\r
-  IN BOOLEAN                              Virtual\r
+  IN ESAL_FWB_GLOBAL                      *Global\r
   )\r
 /*++\r
 \r
@@ -243,7 +234,6 @@ FvbGetPhysicalAddress (
                             address of the firmware volume.\r
     Global                - Pointer to ESAL_FWB_GLOBAL that contains all\r
                             instance data\r
-    Virtual               - Whether CPU is in virtual or physical mode\r
 \r
   Returns:\r
     EFI_SUCCESS           - Successfully returns\r
@@ -257,9 +247,9 @@ FvbGetPhysicalAddress (
   //\r
   // Find the right instance of the FVB private data\r
   //\r
-  Status = GetFvbInstance (Instance, Global, &FwhInstance, Virtual);\r
+  Status = GetFvbInstance (Instance, Global, &FwhInstance);\r
   ASSERT_EFI_ERROR (Status);\r
-  *Address = FwhInstance->FvBase[Virtual];\r
+  *Address = FwhInstance->FvBase;\r
 \r
   return EFI_SUCCESS;\r
 }\r
@@ -268,8 +258,7 @@ EFI_STATUS
 FvbGetVolumeAttributes (\r
   IN UINTN                                Instance,\r
   OUT EFI_FVB_ATTRIBUTES_2                *Attributes,\r
-  IN ESAL_FWB_GLOBAL                      *Global,\r
-  IN BOOLEAN                              Virtual\r
+  IN ESAL_FWB_GLOBAL                      *Global\r
   )\r
 /*++\r
 \r
@@ -283,7 +272,6 @@ FvbGetVolumeAttributes (
     Attributes            - Output buffer which contains attributes\r
     Global                - Pointer to ESAL_FWB_GLOBAL that contains all\r
                             instance data\r
-    Virtual               - Whether CPU is in virtual or physical mode\r
 \r
   Returns:\r
     EFI_SUCCESS           - Successfully returns\r
@@ -297,7 +285,7 @@ FvbGetVolumeAttributes (
   //\r
   // Find the right instance of the FVB private data\r
   //\r
-  Status = GetFvbInstance (Instance, Global, &FwhInstance, Virtual);\r
+  Status = GetFvbInstance (Instance, Global, &FwhInstance);\r
   ASSERT_EFI_ERROR (Status);\r
   *Attributes = FwhInstance->VolumeHeader.Attributes;\r
 \r
@@ -311,8 +299,7 @@ FvbGetLbaAddress (
   OUT UINTN                               *LbaAddress,\r
   OUT UINTN                               *LbaLength,\r
   OUT UINTN                               *NumOfBlocks,\r
-  IN  ESAL_FWB_GLOBAL                     *Global,\r
-  IN  BOOLEAN                             Virtual\r
+  IN  ESAL_FWB_GLOBAL                     *Global\r
   )\r
 /*++\r
 \r
@@ -331,7 +318,6 @@ FvbGetLbaAddress (
                             BlockSize\r
     Global                - Pointer to ESAL_FWB_GLOBAL that contains all\r
                             instance data\r
-    Virtual               - Whether CPU is in virtual or physical mode\r
 \r
   Returns:\r
     EFI_SUCCESS           - Successfully returns\r
@@ -351,7 +337,7 @@ FvbGetLbaAddress (
   //\r
   // Find the right instance of the FVB private data\r
   //\r
-  Status = GetFvbInstance (Instance, Global, &FwhInstance, Virtual);\r
+  Status = GetFvbInstance (Instance, Global, &FwhInstance);\r
   ASSERT_EFI_ERROR (Status);\r
 \r
   StartLba  = 0;\r
@@ -377,7 +363,7 @@ FvbGetLbaAddress (
     if (Lba >= StartLba && Lba < NextLba) {\r
       Offset = Offset + (UINTN) MultU64x32 ((Lba - StartLba), BlockLength);\r
       if (LbaAddress != NULL) {\r
-        *LbaAddress = FwhInstance->FvBase[Virtual] + Offset;\r
+        *LbaAddress = FwhInstance->FvBase + Offset;\r
       }\r
 \r
       if (LbaLength != NULL) {\r
@@ -401,8 +387,7 @@ EFI_STATUS
 FvbSetVolumeAttributes (\r
   IN UINTN                                  Instance,\r
   IN OUT EFI_FVB_ATTRIBUTES_2               *Attributes,\r
-  IN ESAL_FWB_GLOBAL                        *Global,\r
-  IN BOOLEAN                                Virtual\r
+  IN ESAL_FWB_GLOBAL                        *Global\r
   )\r
 /*++\r
 \r
@@ -419,7 +404,6 @@ FvbSetVolumeAttributes (
                             of the firmware volume\r
     Global                - Pointer to ESAL_FWB_GLOBAL that contains all\r
                             instance data\r
-    Virtual               - Whether CPU is in virtual or physical mode\r
 \r
   Returns:\r
     EFI_SUCCESS           - Successfully returns\r
@@ -442,7 +426,7 @@ FvbSetVolumeAttributes (
   //\r
   // Find the right instance of the FVB private data\r
   //\r
-  Status = GetFvbInstance (Instance, Global, &FwhInstance, Virtual);\r
+  Status = GetFvbInstance (Instance, Global, &FwhInstance);\r
   ASSERT_EFI_ERROR (Status);\r
 \r
   AttribPtr     =\r
@@ -562,7 +546,7 @@ FvbProtocolGetPhysicalAddress (
   FvbDevice = FVB_DEVICE_FROM_THIS (This);\r
 \r
   return FvbGetPhysicalAddress (FvbDevice->Instance, Address,\r
-           mFvbModuleGlobal, EfiGoneVirtual ());\r
+           mFvbModuleGlobal);\r
 }\r
 \r
 EFI_STATUS\r
@@ -604,8 +588,7 @@ FvbProtocolGetBlockSize (
           NULL,\r
           BlockSize,\r
           NumOfBlocks,\r
-          mFvbModuleGlobal,\r
-          EfiGoneVirtual ()\r
+          mFvbModuleGlobal\r
           );\r
 }\r
 \r
@@ -634,7 +617,7 @@ FvbProtocolGetAttributes (
   FvbDevice = FVB_DEVICE_FROM_THIS (This);\r
 \r
   return FvbGetVolumeAttributes (FvbDevice->Instance, Attributes,\r
-           mFvbModuleGlobal, EfiGoneVirtual ());\r
+           mFvbModuleGlobal);\r
 }\r
 \r
 EFI_STATUS\r
@@ -662,7 +645,7 @@ FvbProtocolSetAttributes (
   FvbDevice = FVB_DEVICE_FROM_THIS (This);\r
 \r
   return FvbSetVolumeAttributes (FvbDevice->Instance, Attributes,\r
-           mFvbModuleGlobal, EfiGoneVirtual ());\r
+           mFvbModuleGlobal);\r
 }\r
 \r
 EFI_STATUS\r
@@ -708,7 +691,7 @@ FvbProtocolEraseBlocks (
   FvbDevice = FVB_DEVICE_FROM_THIS (This);\r
 \r
   Status    = GetFvbInstance (FvbDevice->Instance, mFvbModuleGlobal,\r
-                &FwhInstance, EfiGoneVirtual ());\r
+                &FwhInstance);\r
   ASSERT_EFI_ERROR (Status);\r
 \r
   NumOfBlocks = FwhInstance->NumOfBlocks;\r
@@ -1088,21 +1071,10 @@ FvbInitialize (
                 FwVolHeader->HeaderLength -\r
                 sizeof (EFI_FIRMWARE_VOLUME_HEADER)\r
                 );\r
+  mFvbModuleGlobal->FvInstance = AllocateRuntimePool (BufferSize);\r
+  ASSERT (mFvbModuleGlobal->FvInstance != NULL);\r
 \r
-  //\r
-  // Only need to allocate once. There is only one copy of physical memory for\r
-  // the private data of each FV instance. But in virtual mode or in physical\r
-  // mode, the address of the the physical memory may be different.\r
-  //\r
-  mFvbModuleGlobal->FvInstance[FVB_PHYSICAL] = AllocateRuntimePool (\r
-                                                 BufferSize);\r
-  ASSERT (mFvbModuleGlobal->FvInstance[FVB_PHYSICAL] != NULL);\r
-\r
-  //\r
-  // Make a virtual copy of the FvInstance pointer.\r
-  //\r
-  FwhInstance = mFvbModuleGlobal->FvInstance[FVB_PHYSICAL];\r
-  mFvbModuleGlobal->FvInstance[FVB_VIRTUAL] = FwhInstance;\r
+  FwhInstance = mFvbModuleGlobal->FvInstance;\r
 \r
   mFvbModuleGlobal->NumFv                   = 0;\r
   MaxLbaSize = 0;\r
@@ -1111,8 +1083,7 @@ FvbInitialize (
     (EFI_FIRMWARE_VOLUME_HEADER *) (UINTN)\r
       PcdGet32 (PcdOvmfFlashNvStorageVariableBase);\r
 \r
-  FwhInstance->FvBase[FVB_PHYSICAL] = (UINTN) BaseAddress;\r
-  FwhInstance->FvBase[FVB_VIRTUAL]  = (UINTN) BaseAddress;\r
+  FwhInstance->FvBase = (UINTN) BaseAddress;\r
 \r
   CopyMem ((UINTN *) &(FwhInstance->VolumeHeader), (UINTN *) FwVolHeader,\r
     FwVolHeader->HeaderLength);\r
index 7e4ff1e7a0d3eb83abd469a1788ed1e99aac20fc..5e8c2c7aad1695ddd3d2cfde0ffe639265324532 100644 (file)
 #ifndef _FW_BLOCK_SERVICE_H\r
 #define _FW_BLOCK_SERVICE_H\r
 \r
-//\r
-// BugBug: Add documentation here for data structure!!!!\r
-//\r
-#define FVB_PHYSICAL  0\r
-#define FVB_VIRTUAL   1\r
-\r
 typedef struct {\r
-  UINTN                       FvBase[2];\r
+  UINTN                       FvBase;\r
   UINTN                       NumOfBlocks;\r
   EFI_FIRMWARE_VOLUME_HEADER  VolumeHeader;\r
 } EFI_FW_VOL_INSTANCE;\r
 \r
 typedef struct {\r
   UINT32              NumFv;\r
-  EFI_FW_VOL_INSTANCE *FvInstance[2];\r
+  EFI_FW_VOL_INSTANCE *FvInstance;\r
 } ESAL_FWB_GLOBAL;\r
 \r
 //\r
@@ -78,24 +72,21 @@ EFI_STATUS
 FvbSetVolumeAttributes (\r
   IN UINTN                                Instance,\r
   IN OUT EFI_FVB_ATTRIBUTES_2             *Attributes,\r
-  IN ESAL_FWB_GLOBAL                      *Global,\r
-  IN BOOLEAN                              Virtual\r
+  IN ESAL_FWB_GLOBAL                      *Global\r
   );\r
 \r
 EFI_STATUS\r
 FvbGetVolumeAttributes (\r
   IN UINTN                                Instance,\r
   OUT EFI_FVB_ATTRIBUTES_2                *Attributes,\r
-  IN ESAL_FWB_GLOBAL                      *Global,\r
-  IN BOOLEAN                              Virtual\r
+  IN ESAL_FWB_GLOBAL                      *Global\r
   );\r
 \r
 EFI_STATUS\r
 FvbGetPhysicalAddress (\r
   IN UINTN                                Instance,\r
   OUT EFI_PHYSICAL_ADDRESS                *Address,\r
-  IN ESAL_FWB_GLOBAL                      *Global,\r
-  IN BOOLEAN                              Virtual\r
+  IN ESAL_FWB_GLOBAL                      *Global\r
   );\r
 \r
 EFI_STATUS\r
@@ -120,8 +111,7 @@ FvbGetLbaAddress (
   OUT UINTN                               *LbaAddress,\r
   OUT UINTN                               *LbaLength,\r
   OUT UINTN                               *NumOfBlocks,\r
-  IN  ESAL_FWB_GLOBAL                     *Global,\r
-  IN  BOOLEAN                             Virtual\r
+  IN  ESAL_FWB_GLOBAL                     *Global\r
   );\r
 \r
 //\r