From: "Shifflett, Joseph" <[email protected]>

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.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Samer El-Haj-Mahmoud <[email protected]>
---
 MdeModulePkg/Bus/Pci/PciBusDxe/PciEnumerator.c     | 10 ++++--
 .../Bus/Pci/PciBusDxe/PciEnumeratorSupport.c       | 38 ++++++++++++++--------
 MdeModulePkg/Bus/Pci/PciBusDxe/PciLib.c            | 11 ++++++-
 3 files changed, 42 insertions(+), 17 deletions(-)

diff --git a/MdeModulePkg/Bus/Pci/PciBusDxe/PciEnumerator.c 
b/MdeModulePkg/Bus/Pci/PciBusDxe/PciEnumerator.c
index 7329143..e638014 100644
--- a/MdeModulePkg/Bus/Pci/PciBusDxe/PciEnumerator.c
+++ b/MdeModulePkg/Bus/Pci/PciBusDxe/PciEnumerator.c
@@ -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
@@ -382,6 +383,7 @@ PciAssignBusNumber (
   UINT16                          Register;
   UINT8                           Register8;
   EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *PciRootBridgeIo;
+  BOOLEAN                         MultiFunctionDevice;
 
   PciRootBridgeIo = Bridge->PciRootBridgeIo;
 
@@ -394,6 +396,7 @@ PciAssignBusNumber (
   // First check to see whether the parent is ppb
   //
   for (Device = 0; Device <= PCI_MAX_DEVICE; Device++) {
+    MultiFunctionDevice = FALSE;
     for (Func = 0; Func <= PCI_MAX_FUNC; Func++) {
 
       //
@@ -406,7 +409,9 @@ PciAssignBusNumber (
                 Device,
                 Func
                 );
-
+      if (Func == 0) {
+        MultiFunctionDevice = !EFI_ERROR (Status) && IS_PCI_MULTI_FUNC (&Pci);
+      }
       if (!EFI_ERROR (Status)   &&
           (IS_PCI_BRIDGE (&Pci) || IS_CARDBUS_BRIDGE (&Pci))) {
 
@@ -482,7 +487,8 @@ PciAssignBusNumber (
 
       }
 
-      if (Func == 0 && !IS_PCI_MULTI_FUNC (&Pci)) {
+      if (Func == 0 && !MultiFunctionDevice) {
+
 
         //
         // Skip sub functions, this is not a multi function device
diff --git a/MdeModulePkg/Bus/Pci/PciBusDxe/PciEnumeratorSupport.c 
b/MdeModulePkg/Bus/Pci/PciBusDxe/PciEnumeratorSupport.c
index f46025e..7b57374 100644
--- a/MdeModulePkg/Bus/Pci/PciBusDxe/PciEnumeratorSupport.c
+++ b/MdeModulePkg/Bus/Pci/PciBusDxe/PciEnumeratorSupport.c
@@ -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
@@ -101,12 +102,13 @@ PciPciDeviceInfoCollector (
   UINT8               SecBus;
   PCI_IO_DEVICE       *PciIoDevice;
   EFI_PCI_IO_PROTOCOL *PciIo;
+  BOOLEAN             MultiFunctionDevice;
 
   Status  = EFI_SUCCESS;
   SecBus  = 0;
 
   for (Device = 0; Device <= PCI_MAX_DEVICE; Device++) {
-
+    MultiFunctionDevice = FALSE;
     for (Func = 0; Func <= PCI_MAX_FUNC; Func++) {
 
       //
@@ -119,6 +121,9 @@ PciPciDeviceInfoCollector (
                  (UINT8) Device,
                  (UINT8) Func
                  );
+      if (Func == 0) {
+        MultiFunctionDevice = !EFI_ERROR (Status) && IS_PCI_MULTI_FUNC (&Pci);
+      }
       if (!EFI_ERROR (Status)) {
 
         //
@@ -169,17 +174,17 @@ PciPciDeviceInfoCollector (
                      );
 
         }
-
-        if (Func == 0 && !IS_PCI_MULTI_FUNC (&Pci)) {
-
-          //
-          // Skip sub functions, this is not a multi function device
-          //
-          Func = PCI_MAX_FUNC;
-        }
       }
+         
+      if (Func == 0 && !MultiFunctionDevice) {
 
+        //
+        // Skip sub functions, this is not a multi function device
+        //
+        Func = PCI_MAX_FUNC;
+      }
     }
+
   }
 
   return EFI_SUCCESS;
@@ -334,9 +339,9 @@ DumpPciBars (
 
     DEBUG ((
       EFI_D_INFO,
-      "   BAR[%d]: Type = %s; Alignment = 0x%lx;\tLength = 0x%lx;\tOffset = 
0x%02x\n",
+      "   BAR[%d]: Type = %s; Alignment = 0x%lx;\tLength = 0x%lx;\tOffset = 
0x%02x;\tValue = 0x%lx\n",
       Index, mBarTypeStr[MIN (PciIoDevice->PciBar[Index].BarType, 
PciBarTypeMaxType)],
-      PciIoDevice->PciBar[Index].Alignment, PciIoDevice->PciBar[Index].Length, 
PciIoDevice->PciBar[Index].Offset
+      PciIoDevice->PciBar[Index].Alignment, PciIoDevice->PciBar[Index].Length, 
PciIoDevice->PciBar[Index].Offset, PciIoDevice->PciBar[Index].BaseAddress
       ));
   }
 
@@ -347,9 +352,9 @@ DumpPciBars (
 
     DEBUG ((
       EFI_D_INFO,
-      " VFBAR[%d]: Type = %s; Alignment = 0x%lx;\tLength = 0x%lx;\tOffset = 
0x%02x\n",
+      " VFBAR[%d]: Type = %s; Alignment = 0x%lx;\tLength = 0x%lx;\tOffset = 
0x%02x;\tValue = 0x%lx\n",
       Index, mBarTypeStr[MIN (PciIoDevice->VfPciBar[Index].BarType, 
PciBarTypeMaxType)],
-      PciIoDevice->VfPciBar[Index].Alignment, 
PciIoDevice->VfPciBar[Index].Length, PciIoDevice->VfPciBar[Index].Offset
+      PciIoDevice->VfPciBar[Index].Alignment, 
PciIoDevice->VfPciBar[Index].Length, PciIoDevice->VfPciBar[Index].Offset, 
PciIoDevice->VfPciBar[Index].BaseAddress
       ));
   }
   DEBUG ((EFI_D_INFO, "\n"));
@@ -2580,10 +2585,12 @@ ResetAllPpbBusNumber (
   UINT64                          Address;
   UINT8                           SecondaryBus;
   EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *PciRootBridgeIo;
+  BOOLEAN                         MultiFunctionDevice;
 
   PciRootBridgeIo = Bridge->PciRootBridgeIo;
 
   for (Device = 0; Device <= PCI_MAX_DEVICE; Device++) {
+    MultiFunctionDevice = FALSE;
     for (Func = 0; Func <= PCI_MAX_FUNC; Func++) {
 
       //
@@ -2596,6 +2603,9 @@ ResetAllPpbBusNumber (
                  Device,
                  Func
                  );
+      if (Func == 0) {
+        MultiFunctionDevice = !EFI_ERROR (Status) && IS_PCI_MULTI_FUNC (&Pci);
+      }
 
       if (!EFI_ERROR (Status) && (IS_PCI_BRIDGE (&Pci))) {
 
@@ -2627,7 +2637,7 @@ ResetAllPpbBusNumber (
                                         );
       }
 
-      if (Func == 0 && !IS_PCI_MULTI_FUNC (&Pci)) {
+      if (Func == 0 && !MultiFunctionDevice) {
         //
         // Skip sub functions, this is not a multi function device
         //
diff --git a/MdeModulePkg/Bus/Pci/PciBusDxe/PciLib.c 
b/MdeModulePkg/Bus/Pci/PciBusDxe/PciLib.c
index b3d91a8..8d386da 100644
--- a/MdeModulePkg/Bus/Pci/PciBusDxe/PciLib.c
+++ b/MdeModulePkg/Bus/Pci/PciBusDxe/PciLib.c
@@ -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
@@ -996,6 +997,7 @@ PciScanBus (
   EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL   *PciRootBridgeIo;
   BOOLEAN                           BusPadding;
   UINT32                            TempReservedBusNum;
+  BOOLEAN                           MultiFunctionDevice;
 
   PciRootBridgeIo = Bridge->PciRootBridgeIo;
   SecondBus       = 0;
@@ -1008,6 +1010,7 @@ PciScanBus (
   PciAddress      = 0;
 
   for (Device = 0; Device <= PCI_MAX_DEVICE; Device++) {
+    MultiFunctionDevice = FALSE;
     TempReservedBusNum = 0;
     for (Func = 0; Func <= PCI_MAX_FUNC; Func++) {
 
@@ -1021,8 +1024,14 @@ PciScanBus (
                 Device,
                 Func
                 );
+      if (Func == 0) {
+        MultiFunctionDevice = !EFI_ERROR (Status) && IS_PCI_MULTI_FUNC (&Pci);
+      }
 
       if (EFI_ERROR (Status)) {
+        if (Func == 0 && !MultiFunctionDevice) {
+          Func = PCI_MAX_FUNC;
+        }
         continue;
       }
 
@@ -1270,7 +1279,7 @@ PciScanBus (
         }
       }
 
-      if (Func == 0 && !IS_PCI_MULTI_FUNC (&Pci)) {
+      if (Func == 0 && !MultiFunctionDevice) {
 
         //
         // Skip sub functions, this is not a multi function device
-- 
1.9.5.msysgit.1

_______________________________________________
edk2-devel mailing list
[email protected]
https://lists.01.org/mailman/listinfo/edk2-devel

Reply via email to