[PATCH v6 01/34] gpu: nova-core: populate VF information in GSP_INIT
From: Alok Kumar
Date: Wed Dec 02 2026 - 03:33:10 EST
From: Zhi Wang <zhiw@xxxxxxxxxx>
GSP firmware requires the VF BAR layout to route interrupts and doorbell
events to individual virtual functions.
When vGPU mode is enabled, read the VF topology from the typed PCI SR-IOV
extended capability and populate the existing NVKV VF information schema
in GSP_INIT.
Signed-off-by: Zhi Wang <zhiw@xxxxxxxxxx>
Signed-off-by: Alok Kumar <alkumar@xxxxxxxxxx>
Signed-off-by: Alexandre Courbot <acourbot@xxxxxxxxxx>
---
drivers/gpu/nova-core/gsp/fw/commands.rs | 49 +++++++++++++++++++++++-
1 file changed, 47 insertions(+), 2 deletions(-)
diff --git a/drivers/gpu/nova-core/gsp/fw/commands.rs b/drivers/gpu/nova-core/gsp/fw/commands.rs
index 1ed839f0eb15..6cfd6c48eac4 100644
--- a/drivers/gpu/nova-core/gsp/fw/commands.rs
+++ b/drivers/gpu/nova-core/gsp/fw/commands.rs
@@ -171,12 +171,24 @@ fn encode(&self, encoder: &mut Encoder) -> Result {
}
}
+bitfield! {
+ /// VF BAR address-width flags sent to GSP-RM.
+ struct VfInfoFlags(u64) {
+ /// VF BAR0 uses a 64-bit address.
+ 0:0 bar0_is_64bit => bool;
+ /// VF BAR1 uses a 64-bit address.
+ 1:1 bar1_is_64bit => bool;
+ /// VF BAR2 uses a 64-bit address.
+ 2:2 bar2_is_64bit => bool;
+ }
+}
+
nvkv_encode! {
/// SR-IOV virtual function information.
struct VfInfo {
total_vfs: Key<u32, 0x0080>,
first_vf_offset: Key<u32, 0x0081>,
- flags: Key<u64, 0x1003>,
+ flags: Key<VfInfoFlags, 0x1003, u64>,
first_bar0_address: Key<u64, 0x1050>,
first_bar1_address: Key<u64, 0x1051>,
first_bar2_address: Key<u64, 0x1052>,
@@ -238,6 +250,39 @@ fn new(dev: &pci::Device<device::Bound>) -> Self {
];
impl GspInitRequest {
+ fn build_vf_info(
+ dev: &pci::Device<device::Bound>,
+ vgpu_state: VgpuState,
+ ) -> Result<Option<VfInfo>> {
+ let total_vfs = match vgpu_state {
+ VgpuState::Disabled => return Ok(None),
+ VgpuState::Enabled { total_vfs } => total_vfs,
+ };
+
+ let sriov = dev
+ .config_space_extended()?
+ .find_ext_capability::<pci::ExtSriovRegs>()?
+ .ok_or(ENODEV)?;
+
+ let mut vf_bars = sriov.vf_bars()?;
+ let bar0 = vf_bars.next().ok_or(EINVAL)?;
+ let bar1 = vf_bars.next().ok_or(EINVAL)?;
+ let bar2 = vf_bars.next().ok_or(EINVAL)?;
+ let flags = VfInfoFlags::zeroed()
+ .with_bar0_is_64bit(bar0.is_64bit)
+ .with_bar1_is_64bit(bar1.is_64bit)
+ .with_bar2_is_64bit(bar2.is_64bit);
+
+ Ok(Some(VfInfo {
+ total_vfs: u32::from(total_vfs.get()).into(),
+ first_vf_offset: u32::from(sriov.first_vf_offset()).into(),
+ flags: flags.into(),
+ first_bar0_address: bar0.address.into(),
+ first_bar1_address: bar1.address.into(),
+ first_bar2_address: bar2.address.into(),
+ }))
+ }
+
/// Creates the request for `dev`.
///
/// The registry keys are [`REGISTRY_ENTRIES`], plus `RMSetSriovMode` when `vgpu_state` reports
@@ -273,7 +318,7 @@ pub(crate) fn new(
host_arch: HostArch::host().into(),
bus_device_func: u64::from(DomainBusDevice::new(dev)).into(),
regkeys,
- vf_info: None,
+ vf_info: Self::build_vf_info(dev, vgpu_state)?,
})
}
}