From: Zhi Wang The vGPU manager needs the VMMU segment size and FIFO engine topology returned by a successful GSP boot to divide instance resources. Construct VgpuManager only for a vGPU-enabled boot. Retain the GPU-owned channel pool, the ordered host-driven engine list and the VMMU segment size. Expose the existing decoded VMMU value from GspStaticInfo at its first consumer, preserving zero when firmware omits the key. Keep the runtime values in the manager for its instance module, and drop the manager before the pool and memory resources it borrows. Cc: Alexandre Courbot Signed-off-by: Zhi Wang Signed-off-by: Alok Kumar --- drivers/gpu/nova-core/gpu.rs | 22 ++++++++++++-- drivers/gpu/nova-core/gsp/commands.rs | 5 ++-- drivers/gpu/nova-core/gsp/commands/gmc.rs | 1 + drivers/gpu/nova-core/gsp/fw/commands.rs | 2 +- drivers/gpu/nova-core/vgpu.rs | 36 ++++++++++++++++++++++- 5 files changed, 60 insertions(+), 6 deletions(-) diff --git a/drivers/gpu/nova-core/gpu.rs b/drivers/gpu/nova-core/gpu.rs index 829ef9cea00b..5ad7e90dad5e 100644 --- a/drivers/gpu/nova-core/gpu.rs +++ b/drivers/gpu/nova-core/gpu.rs @@ -57,11 +57,14 @@ Timer, TimerState, // }, - vgpu::VgpuState, + vgpu::{ + VgpuManager, + VgpuState, // + }, }; #[cfg_attr(not(CONFIG_KUNIT = "y"), expect(dead_code))] -mod channel; +pub(crate) mod channel; mod hal; mod regs; @@ -387,6 +390,7 @@ unsafe fn new( #[pin_data] pub(crate) struct Gpu<'gpu> { pub(crate) spec: Spec, + vgpu: Option>, /// GSP event interrupt registration, and the enable of its subtree. /// /// Must be kept declared *before* `gsp_resources`, so that the handler is unregistered, and @@ -595,6 +599,20 @@ pub(crate) fn new<'a>( bar1, ) }, + + vgpu: { + let info = &gsp_resources.boot_result.static_info; + match gsp_resources.vgpu_state { + VgpuState::Disabled => None, + VgpuState::Enabled { .. } => Some(VgpuManager::new( + chid_pool.get_ref(), + &info.fifo_engine_list(), + info.vmmu_segment_size, + TOTAL_CHANNELS, + )), + } + }, + }) } diff --git a/drivers/gpu/nova-core/gsp/commands.rs b/drivers/gpu/nova-core/gsp/commands.rs index 8a2fcae05989..46fdc79e91bb 100644 --- a/drivers/gpu/nova-core/gsp/commands.rs +++ b/drivers/gpu/nova-core/gsp/commands.rs @@ -11,7 +11,7 @@ use kernel::prelude::*; -use super::fw::commands::FifoEngineList; +pub(crate) use super::fw::commands::FifoEngineList; /// The static GPU configuration, which GSP-RM reports in reply to [`GspInit`](gmc::GspInit). pub struct GspStaticInfo { @@ -25,6 +25,8 @@ pub struct GspStaticInfo { pub(crate) usable_fb_regions: KVec>, /// Exclusive end of the FB physical address space. pub(crate) total_fb_end: u64, + /// VMMU segment size in bytes, or zero if GSP-RM omitted it. + pub(crate) vmmu_segment_size: u64, /// Host-driven engines in firmware FIFO order. fifo_engine_list: FifoEngineList, } @@ -68,7 +70,6 @@ pub fn gpu_short_name(&self) -> Result<&str, GpuNameError> { } /// Returns the host-driven engines in their firmware FIFO order. - #[expect(dead_code)] pub(crate) fn fifo_engine_list(&self) -> FifoEngineList { self.fifo_engine_list } diff --git a/drivers/gpu/nova-core/gsp/commands/gmc.rs b/drivers/gpu/nova-core/gsp/commands/gmc.rs index 4f813a780d1b..14e04db90594 100644 --- a/drivers/gpu/nova-core/gsp/commands/gmc.rs +++ b/drivers/gpu/nova-core/gsp/commands/gmc.rs @@ -185,6 +185,7 @@ fn read(payload: &mut SBufferIter>) -> Result, fb_regions: KVVec, bar1_pde_base: u64, - vmmu_segment_size: u64, + pub(crate) vmmu_segment_size: u64, fifo_engine_count: FifoEngineCount, fifo_engine_gmc_ids: [u32; MAX_FIFO_ENGINES], fifo_engine_flags: [u32; MAX_FIFO_ENGINES], diff --git a/drivers/gpu/nova-core/vgpu.rs b/drivers/gpu/nova-core/vgpu.rs index c59e7d2f933c..eb76eb9913c4 100644 --- a/drivers/gpu/nova-core/vgpu.rs +++ b/drivers/gpu/nova-core/vgpu.rs @@ -14,7 +14,11 @@ Fsp, VgpuMode, // }, - gpu::Chipset, // + gpu::{ + channel::ChannelIdPool, + Chipset, // + }, + gsp::commands::FifoEngineList, // }; mod hal; @@ -81,3 +85,33 @@ fn query_state( } } } + +/// Runtime resources for an enabled vGPU boot. +pub(crate) struct VgpuManager<'gpu> { + #[expect(dead_code)] + chid_pool: &'gpu ChannelIdPool, + /// VMMU segment size in bytes, or zero if GSP-RM omitted it. + #[expect(dead_code)] + vmmu_segment_size: u64, + #[expect(dead_code)] + total_channels: u32, + #[expect(dead_code)] + fifo_engine_list: FifoEngineList, +} + +impl<'gpu> VgpuManager<'gpu> { + /// Retains runtime parameters from a completed vGPU-enabled GSP boot. + pub(crate) fn new( + chid_pool: &'gpu ChannelIdPool, + fifo_engine_list: &FifoEngineList, + vmmu_segment_size: u64, + total_channels: u32, + ) -> Self { + Self { + chid_pool, + vmmu_segment_size, + total_channels, + fifo_engine_list: *fifo_engine_list, + } + } +}