[PATCH v2 03/32] gpu: nova-core: vgpu: detect boot state independently

From: Zhi Wang

Date: Mon Sep 14 2026 - 03:56:40 EST


The vGPU manager currently contains only the detected boot mode. Its
construction couples mode detection to an object with no runtime
management responsibilities.

Firmware setup needs the mode before allocating GSP resources, even
when vGPU is disabled. Keeping that value with GspResources also makes
it available throughout the firmware lifecycle without a manager.

Move detection to VgpuState and store its result in GspResources.
Borrow it directly when constructing the boot and unload contexts, and
remove the state-only manager wrapper. Preserve the FSP query order,
existing diagnostics and disabled fallback.

No functional change is intended.

Cc: Alexandre Courbot <acourbot@xxxxxxxxxx>
Signed-off-by: Zhi Wang <zhiw@xxxxxxxxxx>
---
drivers/gpu/nova-core/gpu.rs | 11 +++++------
drivers/gpu/nova-core/vgpu.rs | 25 ++++++++-----------------
2 files changed, 13 insertions(+), 23 deletions(-)

diff --git a/drivers/gpu/nova-core/gpu.rs b/drivers/gpu/nova-core/gpu.rs
index cf24c0d00173..39e9e4ab0be6 100644
--- a/drivers/gpu/nova-core/gpu.rs
+++ b/drivers/gpu/nova-core/gpu.rs
@@ -48,7 +48,7 @@
GpuMm,
VramAddress, //
},
- vgpu::VgpuManager, //
+ vgpu::VgpuState, //
};

#[cfg_attr(not(CONFIG_KUNIT = "y"), expect(dead_code))]
@@ -294,8 +294,7 @@ struct GspResources<'gpu> {
// TODO: use different resource types for each boot method, and make the relevant Gsp methods
// generic against them.
fsp: Option<Fsp<'gpu>>,
- /// vGPU state detected before GSP boot.
- vgpu: VgpuManager,
+ vgpu_state: VgpuState,
/// GSP runtime data.
#[pin]
gsp: Gsp<'gpu>,
@@ -359,7 +358,7 @@ fn drop(self: Pin<&mut Self>) {
gsp_falcon: &*this.gsp_falcon,
sec2_falcon: &*this.sec2_falcon,
fsp: this.fsp.as_mut(),
- vgpu_state: this.vgpu.state(),
+ vgpu_state: this.vgpu_state,
},
bundle,
)
@@ -410,7 +409,7 @@ pub(crate) fn new<'a>(

fsp: Fsp::try_new(dev, bar, spec.chipset)?,

- vgpu: VgpuManager::new(pdev, spec.chipset, fsp.as_mut()),
+ vgpu_state: VgpuState::detect(pdev, spec.chipset, fsp.as_mut()),

gsp <- Gsp::new(pdev, bar),

@@ -424,7 +423,7 @@ pub(crate) fn new<'a>(
gsp_falcon,
sec2_falcon,
fsp: fsp.as_mut(),
- vgpu_state: vgpu.state(),
+ vgpu_state,
})?,
}),

diff --git a/drivers/gpu/nova-core/vgpu.rs b/drivers/gpu/nova-core/vgpu.rs
index 905b3a7331fd..b405ba49c490 100644
--- a/drivers/gpu/nova-core/vgpu.rs
+++ b/drivers/gpu/nova-core/vgpu.rs
@@ -30,19 +30,16 @@ pub(crate) enum VgpuState {
},
}

-/// vGPU state manager.
-pub(crate) struct VgpuManager {
- state: VgpuState,
-}
-
-impl VgpuManager {
- /// Creates a vGPU manager by querying SR-IOV and the FSP PRC vGPU knob.
- pub(crate) fn new(
+impl VgpuState {
+ /// Detects the boot mode, falling back to disabled if querying the device fails.
+ ///
+ /// Call after creating the FSP and before allocating GSP firmware resources.
+ pub(crate) fn detect(
pdev: &pci::Device<device::Core<'_>>,
chipset: Chipset,
fsp: Option<&mut Fsp<'_>>,
) -> Self {
- let state = Self::detect_state(pdev, chipset, fsp).unwrap_or_else(|e| {
+ let state = Self::query_state(pdev, chipset, fsp).unwrap_or_else(|e| {
dev_warn!(
pdev,
"vGPU state detection failed: {:?}; disabling vGPU\n",
@@ -51,12 +48,11 @@ pub(crate) fn new(
VgpuState::Disabled
});
dev_dbg!(pdev, "vGPU state: {:?}\n", state);
-
- Self { state }
+ state
}

/// Detects the vGPU state from the chipset, SR-IOV capability and FSP PRC knob.
- fn detect_state(
+ fn query_state(
pdev: &pci::Device<device::Core<'_>>,
chipset: Chipset,
fsp: Option<&mut Fsp<'_>>,
@@ -83,9 +79,4 @@ fn detect_state(
VgpuMode::Disabled => Ok(VgpuState::Disabled),
}
}
-
- /// Returns the detected vGPU state for this boot.
- pub(crate) fn state(&self) -> &VgpuState {
- &self.state
- }
}