[PATCH 03/15] gpu: nova-core: gsp: populate VF information in GSP_INIT

From: Alexandre Courbot

Date: Thu Dec 03 2026 - 07:12:44 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>
[acourbot: also add `RMSetSriovMode` regkey here.]
[acourbot: avoid double-match of `VgpuState`.]
[acourbot: use `bitfield!` for `VfInfo::flags`.]
[acourbot: document more returned errors.]
Co-developed-by: Alexandre Courbot <acourbot@xxxxxxxxxx>
Signed-off-by: Alexandre Courbot <acourbot@xxxxxxxxxx>
---
drivers/gpu/nova-core/gsp/commands/gmc.rs | 13 +++++--
drivers/gpu/nova-core/gsp/fw/commands.rs | 65 ++++++++++++++++++++++++++++---
2 files changed, 70 insertions(+), 8 deletions(-)

diff --git a/drivers/gpu/nova-core/gsp/commands/gmc.rs b/drivers/gpu/nova-core/gsp/commands/gmc.rs
index f74ada78f7ac..f0a0a6798d6b 100644
--- a/drivers/gpu/nova-core/gsp/commands/gmc.rs
+++ b/drivers/gpu/nova-core/gsp/commands/gmc.rs
@@ -37,6 +37,7 @@
},
},
sbuffer::SBufferIter,
+ vgpu::VgpuState, //
};

/// The `GSP_INIT` command, which carries the system information and registry keys to GSP-RM.
@@ -52,10 +53,16 @@ impl GspInit {
///
/// # Errors
///
- /// - `ENOMEM` if the request or the encoder buffer cannot be allocated.
- pub(crate) fn new(pdev: &pci::Device<device::Bound>, chipset: Chipset) -> Result<Self> {
+ /// - `ENOMEM` if the encoder buffer cannot be allocated.
+ ///
+ /// Errors from [`GspInitRequest::new`] are propagated as-is.
+ pub(crate) fn new(
+ pdev: &pci::Device<device::Bound>,
+ chipset: Chipset,
+ vgpu_state: VgpuState,
+ ) -> Result<Self> {
let mut encoder = Encoder::new();
- GspInitRequest::new(pdev, chipset)?.encode(&mut encoder)?;
+ GspInitRequest::new(pdev, chipset, vgpu_state)?.encode(&mut encoder)?;

Ok(Self {
payload: encoder.finish(),
diff --git a/drivers/gpu/nova-core/gsp/fw/commands.rs b/drivers/gpu/nova-core/gsp/fw/commands.rs
index c7f544775ce9..791a336bce16 100644
--- a/drivers/gpu/nova-core/gsp/fw/commands.rs
+++ b/drivers/gpu/nova-core/gsp/fw/commands.rs
@@ -1,7 +1,10 @@
// SPDX-License-Identifier: GPL-2.0
// SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.

-use core::ops::Range;
+use core::{
+ num::NonZero,
+ ops::Range, //
+};

use kernel::{
alloc::ArrayVec,
@@ -379,12 +382,24 @@ fn encode(&self, encoder: &mut Encoder) -> Result {
}
}

+bitfield! {
+ /// SR-IOV virtual function BAR capability flags.
+ struct VfFlags(u64) {
+ /// VF BAR0 uses 64-bit addressing.
+ 0:0 bar0_is_64bit => bool;
+ /// VF BAR1 uses 64-bit addressing.
+ 1:1 bar1_is_64bit => bool;
+ /// VF BAR2 uses 64-bit addressing.
+ 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<VfFlags, 0x1003, u64>,
first_bar0_address: Key<u64, 0x1050>,
first_bar1_address: Key<u64, 0x1051>,
first_bar2_address: Key<u64, 0x1052>,
@@ -445,18 +460,58 @@ fn new(dev: &pci::Device<device::Bound>) -> Self {
];

impl GspInitRequest {
+ fn build_vf_info(dev: &pci::Device<device::Bound>, total_vfs: NonZero<u16>) -> Result<VfInfo> {
+ 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 = VfFlags::zeroed()
+ .with_bar0_is_64bit(bar0.is_64bit)
+ .with_bar1_is_64bit(bar1.is_64bit)
+ .with_bar2_is_64bit(bar2.is_64bit);
+
+ Ok(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`].
+ /// The registry keys are [`REGISTRY_ENTRIES`], plus `RMSetSriovMode` when `vgpu_state` reports
+ /// that vGPU is enabled.
///
/// # Errors
///
/// - `ENOMEM` if the registry list cannot be allocated.
- pub(crate) fn new(dev: &pci::Device<device::Bound>, chipset: Chipset) -> Result<Self> {
+ /// - `ENODEV` if vGPU is enabled and the PCI SR-IOV capability is missing.
+ /// - `EINVAL` if vGPU is enabled and the extended configuration space, SR-IOV capability, or
+ /// VF BAR layout is invalid.
+ pub(crate) fn new(
+ dev: &pci::Device<device::Bound>,
+ chipset: Chipset,
+ vgpu_state: VgpuState,
+ ) -> Result<Self> {
let mut regkeys = KVVec::new();
for entry in REGISTRY_ENTRIES {
regkeys.push(entry, GFP_KERNEL)?;
}
+ let vf_info = match vgpu_state {
+ VgpuState::Enabled { total_vfs } => {
+ regkeys.push(RegKey::new(c"RMSetSriovMode", 1), GFP_KERNEL)?;
+ Some(Self::build_vf_info(dev, total_vfs)?)
+ }
+ VgpuState::Disabled => None,
+ };

let mirror = chipset.pci_config_mirror_range();
let device_id = (u32::from(dev.device_id()) << 16) | u32::from(dev.vendor_id().as_raw());
@@ -472,7 +527,7 @@ pub(crate) fn new(dev: &pci::Device<device::Bound>, chipset: Chipset) -> Result<
host_arch: HostArch::host().into(),
bus_device_func: u64::from(DomainBusDevice::new(dev)).into(),
regkeys,
- vf_info: None,
+ vf_info,
})
}
}

--
2.56.1