]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdeModulePkg: Handle InitialVFs=0 case for SR-IOV
authorFoster Nong <foster.nong@intel.com>
Thu, 29 Sep 2022 09:20:01 +0000 (17:20 +0800)
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Sat, 8 Oct 2022 08:58:05 +0000 (08:58 +0000)
Per the section 3.3.5 SR-IOV spec v1.1, InitialVFs (0ch).
InitialVFs indicates to SR-PCIM the number of VFs that are initially associated with the PF.
The minimum value of InitialVFs is 0.

Below code is used to calculate SR-IOV reserved bus number,
if InitialVFs =0, it maybe calculate the wrong bus number in this case.
  LastVF = PFRid + FirstVFOffset + (PciIoDevice->InitialVFs - 1) * VFStride

we can fix it with below code:
 if (PciIoDevice->InitialVFs == 0) {
 PciIoDevice->ReservedBusNum = 0;
} else {
PFRid  = EFI_PCI_RID (Bus, Device, Func);
 LastVF = PFRid + FirstVFOffset + (PciIoDevice->InitialVFs - 1) * VFStride;
//
// Calculate ReservedBusNum for this PF
//
PciIoDevice->ReservedBusNum = (UINT16)(EFI_PCI_BUS_OF_RID (LastVF) - Bus + 1);
//
 // Calculate ReservedBusNum for this PF
//
 PciIoDevice->ReservedBusNum = (UINT16)(EFI_PCI_BUS_OF_RID (LastVF) - Bus + 1);
}

https://bugzilla.tianocore.org/show_bug.cgi?id=4069

Signed-off-by: Foster Nong <foster.nong@intel.com>
Reviewed-by: Ray Ni <ray.ni@intel.com>
MdeModulePkg/Bus/Pci/PciBusDxe/PciEnumeratorSupport.c

index 509f828b621d07258cb864ab328327fc5d35285e..eb250f6f7b622405b13e31894e27e26345c7577a 100644 (file)
@@ -2416,13 +2416,17 @@ CreatePciIoDevice (
       //\r
       // Calculate LastVF\r
       //\r
-      PFRid  = EFI_PCI_RID (Bus, Device, Func);\r
-      LastVF = PFRid + FirstVFOffset + (PciIoDevice->InitialVFs - 1) * VFStride;\r
+      if (PciIoDevice->InitialVFs == 0) {\r
+        PciIoDevice->ReservedBusNum = 0;\r
+      } else {\r
+        PFRid  = EFI_PCI_RID (Bus, Device, Func);\r
+        LastVF = PFRid + FirstVFOffset + (PciIoDevice->InitialVFs - 1) * VFStride;\r
 \r
-      //\r
-      // Calculate ReservedBusNum for this PF\r
-      //\r
-      PciIoDevice->ReservedBusNum = (UINT16)(EFI_PCI_BUS_OF_RID (LastVF) - Bus + 1);\r
+        //\r
+        // Calculate ReservedBusNum for this PF\r
+        //\r
+        PciIoDevice->ReservedBusNum = (UINT16)(EFI_PCI_BUS_OF_RID (LastVF) - Bus + 1);\r
+      }\r
 \r
       DEBUG ((\r
         DEBUG_INFO,\r