From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by mx.groups.io with SMTP id smtpd.web12.8268.1664443227761781943 for ; Thu, 29 Sep 2022 02:20:28 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="unable to parse pub key" header.i=@intel.com header.s=intel header.b=VRktDpKC; spf=pass (domain: intel.com, ip: 192.55.52.136, mailfrom: foster.nong@intel.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1664443228; x=1695979228; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=hT4RE9gxH67lpDGnXj9d1mu2r6FJJjCGTIQYSiAJqhk=; b=VRktDpKCQ0IWFFxVy+KIEDgXW0UciguLKhY51bykQq5tV8zWHB/cNcIZ 34PSqTagxV297oj5HoaAMXPR4Tx2qyF5mL5K96DRnb7EcnvEVLAIyix3k VhZJd5vPdEgvnyeOqvqD4P91/ixaf9JqGEgLKtHm/thPxahWJQr/dUnGI YGl03NPD3Lp1qpK5XmDBqjQyW0XAPD7/KfmgmANRAK/JUw3SkZ45Pj3oD jk1al9tD3p4upod/zuro4lkARoS7uhe7C0oN1fZPsr6z7wi/QA0m8r21/ egWgaORZsMLlzHFxRHw2xKqZWym8gkEvzgNgPGcKZuXwDfn0X9AqG4N98 Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10484"; a="281556614" X-IronPort-AV: E=Sophos;i="5.93,354,1654585200"; d="scan'208";a="281556614" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Sep 2022 02:20:18 -0700 X-IronPort-AV: E=McAfee;i="6500,9779,10484"; a="655481699" X-IronPort-AV: E=Sophos;i="5.93,354,1654585200"; d="scan'208";a="655481699" Received: from shwdeopenlab108.ccr.corp.intel.com ([10.239.56.147]) by orsmga001-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Sep 2022 02:20:17 -0700 From: Foster Nong To: devel@edk2.groups.io Cc: Foster Nong Subject: [PATCH 1/1] MdeModulePkg: Handle InitialVFs=0 case for SR-IOV Date: Thu, 29 Sep 2022 17:20:01 +0800 Message-Id: <5f9999143741b8741a2978056390f6f3f728fe31.1664442988.git.foster.nong@intel.com> X-Mailer: git-send-email 2.37.1.windows.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 --- .../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 509f828b621d..eb250f6f7b62 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