From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by mx.groups.io with SMTP id smtpd.web10.7924.1664441389908235125 for ; Thu, 29 Sep 2022 01:49:50 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="unable to parse pub key" header.i=@intel.com header.s=intel header.b=VScmw+xL; spf=pass (domain: intel.com, ip: 192.55.52.151, mailfrom: bob.c.feng@intel.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1664441389; x=1695977389; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=EToTo589jvGxTqc6VQLUfmr6PZoyNkTIZ45Wa8HM4Xc=; b=VScmw+xLRaHr4CqF8ZQwG3uRXPdfuD+MDUv7gvXlelIi0nxWJIWf+i0P 5HIJJqsTLzbvy5InAngbCXgHHWCwylhR/qi2+tFG6qBcdWtrVWNOczxqb 1h2tUAgHWd0iWCaFdFAxSdHjPyV0YB7ygZ76p0KBgPabcYbRuJkXb/Wjl ddMf2I0tvVuzA4tC/Xl7sCFYyR0XwN0PwFKrKOdi3bHhWtCFQnKA97RU+ zigtZQU5KvX2gBRdI2WvyvzhIQ0/ffCbIZjHyQgSEhl0Qq/IZRMd16UiD INIpnJF3/ur91mzIyN7OukFgt6ccsFrduh+ypL0VRK1tcT1XyhHJp4PIs A==; X-IronPort-AV: E=McAfee;i="6500,9779,10484"; a="282201715" X-IronPort-AV: E=Sophos;i="5.93,354,1654585200"; d="scan'208";a="282201715" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Sep 2022 01:49:48 -0700 X-IronPort-AV: E=McAfee;i="6500,9779,10484"; a="622273171" X-IronPort-AV: E=Sophos;i="5.93,354,1654585200"; d="scan'208";a="622273171" Received: from bfeng1-mobl.ccr.corp.intel.com ([10.238.5.140]) by orsmga002-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Sep 2022 01:49:47 -0700 From: "Bob Feng" To: devel@edk2.groups.io Cc: Foster Nong Subject: [PATCH] MdeModulePkg: Handle InitialVFs=0 case for SR-IOV Date: Thu, 29 Sep 2022 16:49:40 +0800 Message-Id: <14266957051500e82d927d794b07e44954db06c3.1664416117.git.foster.nong@intel.com> X-Mailer: git-send-email 2.37.0.windows.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Foster Nong Per SR-IOV spec,InitialVFs minimum is 0. Below code which use to calculate SR-IOV bus number, if InitialVFs =0, it maybe calculate the wrong bus number. 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 --- .../Bus/Pci/PciBusDxe/PciEnumeratorSupport.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/MdeModulePkg/Bus/Pci/PciBusDxe/PciEnumeratorSupport.c b/MdeModulePkg/Bus/Pci/PciBusDxe/PciEnumeratorSupport.c index 509f828b62..eb250f6f7b 100644 --- a/MdeModulePkg/Bus/Pci/PciBusDxe/PciEnumeratorSupport.c +++ b/MdeModulePkg/Bus/Pci/PciBusDxe/PciEnumeratorSupport.c @@ -2416,13 +2416,17 @@ CreatePciIoDevice ( // // Calculate LastVF // - PFRid = EFI_PCI_RID (Bus, Device, Func); - LastVF = PFRid + FirstVFOffset + (PciIoDevice->InitialVFs - 1) * VFStride; + 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); + } DEBUG (( DEBUG_INFO, -- 2.37.1.windows.1