]> git.proxmox.com Git - mirror_edk2.git/commitdiff
Dispatch the UEFI option rom returned from PciPlatform/PciOverride protocol.
authorRuiyu Ni <ruiyu.ni@intel.com>
Tue, 20 Jan 2015 06:45:01 +0000 (06:45 +0000)
committerniruiyu <niruiyu@Edk2>
Tue, 20 Jan 2015 06:45:01 +0000 (06:45 +0000)
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com>
Reviewed-by: Chao B Zhang <chao.b.zhang@intel.com>
git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@16625 6f19259b-4bc3-4df7-8a09-765794883524

MdeModulePkg/Bus/Pci/PciBusDxe/PciBus.h
MdeModulePkg/Bus/Pci/PciBusDxe/PciDeviceSupport.c
MdeModulePkg/Bus/Pci/PciBusDxe/PciOptionRomSupport.c
MdeModulePkg/Bus/Pci/PciBusDxe/PciOptionRomSupport.h

index fc62a251c231d28f9df0a93a2d2a80ea7a676b73..b99d3181acc8386618cf4c92901f469bd9e0e621 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Header files and data structures needed by PCI Bus module.\r
 \r
-Copyright (c) 2006 - 2013, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2006 - 2015, Intel Corporation. All rights reserved.<BR>\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
@@ -249,11 +249,6 @@ struct _PCI_IO_DEVICE {
   //\r
   BOOLEAN                                   AllOpRomProcessed;\r
 \r
-  //\r
-  // TRUE if the ROM image contains EFI OpROM\r
-  //\r
-  BOOLEAN                                   HasEfiOpRom;\r
-\r
   //\r
   // TRUE if there is any EFI driver in the OptionRom\r
   //\r
index 5ace222e602886df5eb8f3fceec17038ad9c1704..c0227fa2b69635bf3d440e714f52a63554df2867 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Supporting functions implementaion for PCI devices management.\r
 \r
-Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2006 - 2015, Intel Corporation. All rights reserved.<BR>\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
@@ -214,6 +214,7 @@ RegisterPciDevice (
   UINT8               PciExpressCapRegOffset;\r
   EFI_PCI_IO_PROTOCOL *PciIo;\r
   UINT8               Data8;\r
+  BOOLEAN             HasEfiImage;\r
 \r
   //\r
   // Install the pciio protocol, device path protocol\r
@@ -314,7 +315,12 @@ RegisterPciDevice (
     }\r
   }\r
 \r
-  if (PciIoDevice->HasEfiOpRom) {\r
+  //\r
+  // Determine if there are EFI images in the option rom\r
+  //\r
+  HasEfiImage = ContainEfiImage (PciIoDevice->PciIo.RomImage, PciIoDevice->PciIo.RomSize);\r
+\r
+  if (HasEfiImage) {\r
     Status = gBS->InstallMultipleProtocolInterfaces (\r
                     &PciIoDevice->Handle,\r
                     &gEfiLoadFile2ProtocolGuid,\r
@@ -344,7 +350,7 @@ RegisterPciDevice (
     // The OpRom is got from platform in the above code\r
     // or loaded from device in the previous round of bus enumeration\r
     //\r
-    if (PciIoDevice->HasEfiOpRom) {\r
+    if (HasEfiImage) {\r
       ProcessOpRomImage (PciIoDevice);\r
     }\r
   }\r
@@ -368,7 +374,7 @@ RegisterPciDevice (
              &PciIoDevice->PciIo,\r
              NULL\r
              );\r
-      if (PciIoDevice->HasEfiOpRom) {\r
+      if (HasEfiImage) {\r
         gBS->UninstallMultipleProtocolInterfaces (\r
                &PciIoDevice->Handle,\r
                &gEfiLoadFile2ProtocolGuid,\r
index 33dbfa4af72db94cf9c9e750afb43769f68aa690..2bc4f8c5e8573a144e05ea21605d17a7479a994a 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   PCI Rom supporting funtions implementation for PCI Bus module.\r
 \r
-Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2006 - 2015, Intel Corporation. All rights reserved.<BR>\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
@@ -309,6 +309,63 @@ GetOpRomInfo (
   return EFI_SUCCESS;\r
 }\r
 \r
+/**\r
+  Check if the RomImage contains EFI Images.\r
+\r
+  @param  RomImage  The ROM address of Image for check.\r
+  @param  RomSize   Size of ROM for check.\r
+\r
+  @retval TRUE     ROM contain EFI Image.\r
+  @retval FALSE    ROM not contain EFI Image.\r
+\r
+**/\r
+BOOLEAN\r
+ContainEfiImage (\r
+  IN VOID            *RomImage,\r
+  IN UINT64          RomSize\r
+  )\r
+{\r
+  PCI_EXPANSION_ROM_HEADER  *RomHeader;\r
+  PCI_DATA_STRUCTURE        *RomPcir;\r
+  UINT8                     Indicator;\r
+\r
+  Indicator = 0;\r
+  RomHeader = RomImage;\r
+  if (RomHeader == NULL) {\r
+    return FALSE;\r
+  }\r
+\r
+  do {\r
+    if (RomHeader->Signature != PCI_EXPANSION_ROM_HEADER_SIGNATURE) {\r
+      RomHeader = (PCI_EXPANSION_ROM_HEADER *) ((UINT8 *) RomHeader + 512);\r
+      continue;\r
+    }\r
+\r
+    //\r
+    // The PCI Data Structure must be DWORD aligned. \r
+    //\r
+    if (RomHeader->PcirOffset == 0 ||\r
+        (RomHeader->PcirOffset & 3) != 0 ||\r
+        (UINT8 *) RomHeader + RomHeader->PcirOffset + sizeof (PCI_DATA_STRUCTURE) > (UINT8 *) RomImage + RomSize) {\r
+      break;\r
+    }\r
+\r
+    RomPcir = (PCI_DATA_STRUCTURE *) ((UINT8 *) RomHeader + RomHeader->PcirOffset);\r
+    if (RomPcir->Signature != PCI_DATA_STRUCTURE_SIGNATURE) {\r
+      break;\r
+    }\r
+\r
+    if (RomPcir->CodeType == PCI_CODE_TYPE_EFI_IMAGE) {\r
+      return TRUE;\r
+    }\r
+\r
+    Indicator = RomPcir->Indicator;\r
+    RomHeader = (PCI_EXPANSION_ROM_HEADER *) ((UINT8 *) RomHeader + RomPcir->ImageLength * 512);\r
+  } while (((UINT8 *) RomHeader < (UINT8 *) RomImage + RomSize) && ((Indicator & 0x80) == 0x00));\r
+\r
+  return FALSE;\r
+}\r
+\r
 /**\r
   Load Option Rom image for specified PCI device.\r
 \r
@@ -340,7 +397,6 @@ LoadOpRomImage (
   UINT32                    LegacyImageLength;\r
   UINT8                     *RomInMemory;\r
   UINT8                     CodeType;\r
-  BOOLEAN                   HasEfiOpRom;\r
 \r
   RomSize       = PciDevice->RomSize;\r
 \r
@@ -392,7 +448,6 @@ LoadOpRomImage (
   RetStatus     = EFI_NOT_FOUND;\r
   FirstCheck    = TRUE;\r
   LegacyImageLength = 0;\r
-  HasEfiOpRom   = FALSE;\r
 \r
   do {\r
     PciDevice->PciRootBridgeIo->Mem.Read (\r
@@ -443,8 +498,6 @@ LoadOpRomImage (
     if (RomPcir->CodeType == PCI_CODE_TYPE_PCAT_IMAGE) {\r
       CodeType = PCI_CODE_TYPE_PCAT_IMAGE;\r
       LegacyImageLength = ((UINT32)((EFI_LEGACY_EXPANSION_ROM_HEADER *)RomHeader)->Size512) * 512;\r
-    } else if (RomPcir->CodeType == PCI_CODE_TYPE_EFI_IMAGE) {\r
-      HasEfiOpRom = TRUE;\r
     }\r
     Indicator     = RomPcir->Indicator;\r
     RomImageSize  = RomImageSize + RomPcir->ImageLength * 512;\r
@@ -484,7 +537,6 @@ LoadOpRomImage (
 \r
   RomDecode (PciDevice, RomBarIndex, RomBar, FALSE);\r
 \r
-  PciDevice->HasEfiOpRom    = HasEfiOpRom;\r
   PciDevice->EmbeddedRom    = TRUE;\r
   PciDevice->PciIo.RomSize  = RomImageSize;\r
   PciDevice->PciIo.RomImage = RomInMemory;\r
index 6a7f0e30718f641edb72aa210e73bc37cbfbc34f..25f78a417f2d1bcd2f2369a508d2bd968b16665d 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   PCI Rom supporting funtions declaration for PCI Bus module.\r
 \r
-Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2006 - 2015, Intel Corporation. All rights reserved.<BR>\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
@@ -60,6 +60,22 @@ LoadFile2 (
   IN VOID                     *Buffer      OPTIONAL\r
   );\r
 \r
+/**\r
+  Check if the RomImage contains EFI Images.\r
+\r
+  @param  RomImage  The ROM address of Image for check.\r
+  @param  RomSize   Size of ROM for check.\r
+\r
+  @retval TRUE     ROM contain EFI Image.\r
+  @retval FALSE    ROM not contain EFI Image.\r
+\r
+**/\r
+BOOLEAN\r
+ContainEfiImage (\r
+  IN VOID            *RomImage,\r
+  IN UINT64          RomSize\r
+  );\r
+\r
 /**\r
   Get Pci device's oprom information.\r
 \r