Revision: 18574
          http://sourceforge.net/p/edk2/code/18574
Author:   lersek
Date:     2015-10-06 20:55:31 +0000 (Tue, 06 Oct 2015)
Log Message:
-----------
MdeModulePkg: exit pci function loops early if device is not multi-function

When looping through all PCI functions, code should not look for functions
1-7 if function 0 is not present or if function 0 indicates the device is
not multifunction.  Prior to this fix the code would use stale data in a
buffer to determine if a device is multifunction even if function 0 is not
present.  This fixes a code bug and provides very small performance
improvements.

PCI 2.3 Specification states: They [multifunction devices] are also
required to always implement function 0 in the device. Implementing other
functions is optional and may be assigned in any order.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Joseph Shifflett <[email protected]>
Reviewed-by: Ruiyu Ni <[email protected]>

Modified Paths:
--------------
    trunk/edk2/MdeModulePkg/Bus/Pci/PciBusDxe/PciEnumerator.c
    trunk/edk2/MdeModulePkg/Bus/Pci/PciBusDxe/PciEnumeratorSupport.c
    trunk/edk2/MdeModulePkg/Bus/Pci/PciBusDxe/PciLib.c

Modified: trunk/edk2/MdeModulePkg/Bus/Pci/PciBusDxe/PciEnumerator.c
===================================================================
--- trunk/edk2/MdeModulePkg/Bus/Pci/PciBusDxe/PciEnumerator.c   2015-10-06 
19:49:13 UTC (rev 18573)
+++ trunk/edk2/MdeModulePkg/Bus/Pci/PciBusDxe/PciEnumerator.c   2015-10-06 
20:55:31 UTC (rev 18574)
@@ -2,6 +2,7 @@
   PCI eunmeration implementation on entire PCI bus system for PCI Bus module.
 
 Copyright (c) 2006 - 2013, Intel Corporation. All rights reserved.<BR>
+(C) Copyright 2015 Hewlett Packard Enterprise Development LP<BR>
 This program and the accompanying materials
 are licensed and made available under the terms and conditions of the BSD 
License
 which accompanies this distribution.  The full text of the license may be 
found at
@@ -407,6 +408,13 @@
                 Func
                 );
 
+      if (EFI_ERROR (Status) && Func == 0) {
+        //
+        // go to next device if there is no Function 0
+        //
+        break;
+      }
+
       if (!EFI_ERROR (Status)   &&
           (IS_PCI_BRIDGE (&Pci) || IS_CARDBUS_BRIDGE (&Pci))) {
 

Modified: trunk/edk2/MdeModulePkg/Bus/Pci/PciBusDxe/PciEnumeratorSupport.c
===================================================================
--- trunk/edk2/MdeModulePkg/Bus/Pci/PciBusDxe/PciEnumeratorSupport.c    
2015-10-06 19:49:13 UTC (rev 18573)
+++ trunk/edk2/MdeModulePkg/Bus/Pci/PciBusDxe/PciEnumeratorSupport.c    
2015-10-06 20:55:31 UTC (rev 18574)
@@ -2,6 +2,7 @@
   PCI emumeration support functions implementation for PCI Bus module.
 
 Copyright (c) 2006 - 2015, Intel Corporation. All rights reserved.<BR>
+(C) Copyright 2015 Hewlett Packard Enterprise Development LP<BR>
 This program and the accompanying materials
 are licensed and made available under the terms and conditions of the BSD 
License
 which accompanies this distribution.  The full text of the license may be 
found at
@@ -119,6 +120,14 @@
                  (UINT8) Device,
                  (UINT8) Func
                  );
+
+      if (EFI_ERROR (Status) && Func == 0) {
+        //
+        // go to next device if there is no Function 0
+        //
+        break;
+      }
+
       if (!EFI_ERROR (Status)) {
 
         //
@@ -2597,6 +2606,13 @@
                  Func
                  );
 
+      if (EFI_ERROR (Status) && Func == 0) {
+        //
+        // go to next device if there is no Function 0
+        //
+        break;
+      }
+
       if (!EFI_ERROR (Status) && (IS_PCI_BRIDGE (&Pci))) {
 
         Register  = 0;

Modified: trunk/edk2/MdeModulePkg/Bus/Pci/PciBusDxe/PciLib.c
===================================================================
--- trunk/edk2/MdeModulePkg/Bus/Pci/PciBusDxe/PciLib.c  2015-10-06 19:49:13 UTC 
(rev 18573)
+++ trunk/edk2/MdeModulePkg/Bus/Pci/PciBusDxe/PciLib.c  2015-10-06 20:55:31 UTC 
(rev 18574)
@@ -2,6 +2,7 @@
   Internal library implementation for PCI Bus module.
 
 Copyright (c) 2006 - 2013, Intel Corporation. All rights reserved.<BR>
+(C) Copyright 2015 Hewlett Packard Enterprise Development LP<BR>
 This program and the accompanying materials
 are licensed and made available under the terms and conditions of the BSD 
License
 which accompanies this distribution.  The full text of the license may be 
found at
@@ -1022,6 +1023,13 @@
                 Func
                 );
 
+      if (EFI_ERROR (Status) && Func == 0) {
+        //
+        // go to next device if there is no Function 0
+        //
+        break;
+      }
+
       if (EFI_ERROR (Status)) {
         continue;
       }


------------------------------------------------------------------------------
_______________________________________________
edk2-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/edk2-commits

Reply via email to