]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Bus/Pci/PciBusDxe/PciCommand.c
MdeModulePkg/PciBus: Change PCI_IO_DEVICE.RomSize to UINT32 type
[mirror_edk2.git] / MdeModulePkg / Bus / Pci / PciBusDxe / PciCommand.c
index 601af309b7c2e76d7aa2b9f2944d39146e7b5ea5..0bc1fbfefffe7b778642f90700b0a5fdc44f60e2 100644 (file)
@@ -1,8 +1,8 @@
 /** @file\r
   PCI command register operations supporting functions implementation for PCI Bus module.\r
 \r
-Copyright (c) 2006 - 2009, Intel Corporation\r
-All rights reserved. This program and the accompanying materials\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
 http://opensource.org/licenses/bsd-license.php\r
@@ -173,6 +173,14 @@ LocateCapabilityRegBlock (
       return EFI_SUCCESS;\r
     }\r
 \r
+    //\r
+    // Certain PCI device may incorrectly have capability pointing to itself,\r
+    // break to avoid dead loop.\r
+    //\r
+    if (CapabilityPtr == (UINT8) (CapabilityEntry >> 8)) {\r
+      break;\r
+    }\r
+\r
     CapabilityPtr = (UINT8) (CapabilityEntry >> 8);\r
   }\r
 \r
@@ -200,9 +208,10 @@ LocatePciExpressCapabilityRegBlock (
      OUT UINT32        *NextRegBlock OPTIONAL\r
   )\r
 {\r
-  UINT32  CapabilityPtr;\r
-  UINT32  CapabilityEntry;\r
-  UINT16  CapabilityID;\r
+  EFI_STATUS           Status;\r
+  UINT32               CapabilityPtr;\r
+  UINT32               CapabilityEntry;\r
+  UINT16               CapabilityID;\r
 \r
   //\r
   // To check the capability of this device supports\r
@@ -222,13 +231,16 @@ LocatePciExpressCapabilityRegBlock (
     // Mask it to DWORD alignment per PCI spec\r
     //\r
     CapabilityPtr &= 0xFFC;\r
-    PciIoDevice->PciIo.Pci.Read (\r
-                             &PciIoDevice->PciIo,\r
-                             EfiPciIoWidthUint32,\r
-                             CapabilityPtr,\r
-                             1,\r
-                             &CapabilityEntry\r
-                             );\r
+    Status = PciIoDevice->PciIo.Pci.Read (\r
+                                      &PciIoDevice->PciIo,\r
+                                      EfiPciIoWidthUint32,\r
+                                      CapabilityPtr,\r
+                                      1,\r
+                                      &CapabilityEntry\r
+                                      );\r
+    if (EFI_ERROR (Status)) {\r
+      break;\r
+    }\r
 \r
     CapabilityID = (UINT16) CapabilityEntry;\r
 \r