Build a valid device path to an EFI driver loaded from a PCI Option ROM


git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@3852 6f19259b-4bc3-4df7-8a09-765794883524
diff --git a/IntelFrameworkModulePkg/Bus/Pci/PciBusDxe/PciOptionRomSupport.c b/IntelFrameworkModulePkg/Bus/Pci/PciBusDxe/PciOptionRomSupport.c
index c76c3eb..99c34d5 100644
--- a/IntelFrameworkModulePkg/Bus/Pci/PciBusDxe/PciOptionRomSupport.c
+++ b/IntelFrameworkModulePkg/Bus/Pci/PciBusDxe/PciOptionRomSupport.c
@@ -16,6 +16,20 @@
 

 #include <IndustryStandard/Pci23.h>

 

+//

+// Module global for a template of the PCI option ROM Image Device Path Node

+//

+MEMMAP_DEVICE_PATH  mPciOptionRomImageDevicePathNodeTemplate = {

+  {                 

+    HARDWARE_DEVICE_PATH,

+    HW_MEMMAP_DP,

+    sizeof (MEMMAP_DEVICE_PATH)

+  },

+  EfiMemoryMappedIO,

+  0,

+  0

+};

+

 EFI_STATUS

 GetOpRomInfo (

   IN PCI_IO_DEVICE    *PciIoDevice

@@ -415,6 +429,7 @@
   EFI_DECOMPRESS_PROTOCOL       *Decompress;

   EFI_PCI_EXPANSION_ROM_HEADER  *EfiRomHeader;

   PCI_DATA_STRUCTURE            *Pcir;

+  EFI_DEVICE_PATH_PROTOCOL      *PciOptionRomImageDevicePath;

 

   Indicator = 0;

 

@@ -505,17 +520,31 @@
         }

 

         if (!SkipImage) {

+          //   

+          // Build full device path to the PCI Option ROM Image being loaded

+          //

+          mPciOptionRomImageDevicePathNodeTemplate.StartingAddress = (EFI_PHYSICAL_ADDRESS)(UINTN)RomBarOffset;

+          mPciOptionRomImageDevicePathNodeTemplate.EndingAddress   = (EFI_PHYSICAL_ADDRESS)(UINTN)(RomBarOffset + ImageSize - 1);

+          PciOptionRomImageDevicePath = AppendDevicePathNode (PciDevice->DevicePath, (const EFI_DEVICE_PATH_PROTOCOL *)&mPciOptionRomImageDevicePathNodeTemplate);

+          ASSERT (PciOptionRomImageDevicePath != NULL);

+

           //

           // load image and start image

           //

           Status = gBS->LoadImage (

                           FALSE,

                           gPciBusDriverBinding.DriverBindingHandle,

-                          PciDevice->Handle,

+                          PciOptionRomImageDevicePath,

                           ImageBuffer,

                           ImageLength,

                           &ImageHandle

                           );

+

+          //

+          // Free the device path after it has been used by LoadImage

+          //

+          gBS->FreePool (PciOptionRomImageDevicePath);

+

           if (!EFI_ERROR (Status)) {

             Status = gBS->StartImage (ImageHandle, NULL, NULL);

             if (!EFI_ERROR (Status)) {