From: Zhi Wang GSP boot uses the detected vGPU mode to size firmware resources and populate GSP_INIT. The mode must be available before resource allocation, even when vGPU is disabled, but neither boot nor unload needs the runtime manager. Move state detection into VgpuState and store the result in GspResources. Copy the state into GspBootContext, removing its dependency on VgpuManager and keeping the state available throughout the firmware lifecycle. No functional change is intended. Cc: Alexandre Courbot Signed-off-by: Zhi Wang Signed-off-by: Alok Kumar --- drivers/gpu/nova-core/fb.rs | 2 +- drivers/gpu/nova-core/gpu.rs | 11 +++++----- drivers/gpu/nova-core/gsp.rs | 4 ++-- drivers/gpu/nova-core/gsp/fw/commands.rs | 4 ++-- drivers/gpu/nova-core/vgpu.rs | 26 ++++++++---------------- 5 files changed, 19 insertions(+), 28 deletions(-) diff --git a/drivers/gpu/nova-core/fb.rs b/drivers/gpu/nova-core/fb.rs index e4ff5c4d35ff..fa7f285c44b8 100644 --- a/drivers/gpu/nova-core/fb.rs +++ b/drivers/gpu/nova-core/fb.rs @@ -295,7 +295,7 @@ pub(crate) fn wpr2_range(bar: Bar0<'_>) -> Option> { /// Computes the number of VF partitions and the WPR2 heap size from the vGPU state. fn wpr2_heap_params(ctx: &gsp::GspBootContext<'_, '_>, fb_size: u64) -> Result<(u8, u64)> { - Ok(match ctx.vgpu.state() { + Ok(match ctx.vgpu_state { VgpuState::Disabled => ( 0, gsp::LibosParams::from_chipset(ctx.chipset).wpr_heap_size(ctx.chipset, fb_size)?, diff --git a/drivers/gpu/nova-core/gpu.rs b/drivers/gpu/nova-core/gpu.rs index e4db5ce47316..debfc8089b2e 100644 --- a/drivers/gpu/nova-core/gpu.rs +++ b/drivers/gpu/nova-core/gpu.rs @@ -53,7 +53,7 @@ Timer, TimerState, // }, - vgpu::VgpuManager, // + vgpu::VgpuState, }; #[cfg_attr(not(CONFIG_KUNIT = "y"), expect(dead_code))] @@ -335,8 +335,7 @@ struct GspResources<'gpu> { fsp: Option>, /// Timer state - contains system timer offset timer: TimerState, - /// vGPU state detected before GSP boot. - vgpu: VgpuManager, + vgpu_state: VgpuState, /// GSP runtime data. #[pin] gsp: Gsp<'gpu>, @@ -436,7 +435,7 @@ fn drop(self: Pin<&mut Self>) { gsp_falcon: &*this.gsp_falcon, sec2_falcon: &*this.sec2_falcon, fsp: this.fsp.as_mut(), - vgpu: &*this.vgpu, + vgpu_state: *this.vgpu_state, }, bundle, ) @@ -495,7 +494,7 @@ pub(crate) fn new<'a>( timer: Timer::setup(dev, bar, spec.chipset, fsp.as_ref())?, - vgpu: VgpuManager::new(pdev, spec.chipset, fsp.as_mut()), + vgpu_state: VgpuState::detect(pdev, spec.chipset, fsp.as_mut()), gsp <- Gsp::new(pdev, bar), @@ -509,7 +508,7 @@ pub(crate) fn new<'a>( gsp_falcon, sec2_falcon, fsp: fsp.as_mut(), - vgpu, + vgpu_state: *vgpu_state, })?, }), diff --git a/drivers/gpu/nova-core/gsp.rs b/drivers/gpu/nova-core/gsp.rs index 47bafd2688f5..687f455a17fa 100644 --- a/drivers/gpu/nova-core/gsp.rs +++ b/drivers/gpu/nova-core/gsp.rs @@ -50,7 +50,7 @@ fw::GspArgumentsPadded, // }, num, - vgpu::VgpuManager, // + vgpu::VgpuState, // }; pub(crate) const GSP_PAGE_SHIFT: usize = 12; @@ -69,7 +69,7 @@ pub(crate) struct GspBootContext<'ctx, 'gpu> { pub(crate) gsp_falcon: &'ctx Falcon<'gpu, GspFalcon>, pub(crate) sec2_falcon: &'ctx Falcon<'gpu, Sec2Falcon>, pub(crate) fsp: Option<&'ctx mut Fsp<'gpu>>, - pub(crate) vgpu: &'ctx VgpuManager, + pub(crate) vgpu_state: VgpuState, } impl<'ctx, 'gpu> GspBootContext<'ctx, 'gpu> { diff --git a/drivers/gpu/nova-core/gsp/fw/commands.rs b/drivers/gpu/nova-core/gsp/fw/commands.rs index 7f880bf708ee..06dccfbaa4a5 100644 --- a/drivers/gpu/nova-core/gsp/fw/commands.rs +++ b/drivers/gpu/nova-core/gsp/fw/commands.rs @@ -251,7 +251,7 @@ fn new(dev: &pci::Device) -> Self { impl GspInitRequest { fn build_vf_info(ctx: &GspBootContext<'_, '_>) -> Result> { - let total_vfs = match ctx.vgpu.state() { + let total_vfs = match ctx.vgpu_state { VgpuState::Disabled => return Ok(None), VgpuState::Enabled { total_vfs } => total_vfs, }; @@ -292,7 +292,7 @@ fn build_vf_info(ctx: &GspBootContext<'_, '_>) -> Result> { pub(crate) fn new(ctx: &GspBootContext<'_, '_>) -> Result { let dev = ctx.pdev; let chipset = ctx.chipset; - let vgpu_state = ctx.vgpu.state(); + let vgpu_state = ctx.vgpu_state; let mut regkeys = KVVec::new(); for &(name, value) in REGISTRY_ENTRIES { regkeys.push(RegKey::new(name, value), GFP_KERNEL)?; diff --git a/drivers/gpu/nova-core/vgpu.rs b/drivers/gpu/nova-core/vgpu.rs index 6b7e045acea8..c59e7d2f933c 100644 --- a/drivers/gpu/nova-core/vgpu.rs +++ b/drivers/gpu/nova-core/vgpu.rs @@ -1,4 +1,5 @@ // SPDX-License-Identifier: GPL-2.0 +// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. use core::num::NonZero; @@ -30,19 +31,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>, 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 +49,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>, chipset: Chipset, fsp: Option<&mut Fsp<'_>>, @@ -83,9 +80,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 - } }