gpu: nova-core: obtain and display VRAM amount
Subsystems (5)
Alexandre Courbot
maintainercover gpu: nova-core: obtain and display VRAM amount
This series performs some light refactoring required to be able to initialize members of the Gpu struct from GSP commands, and makes use of that refactoring to obtain and store the amount of VRAM on the device.
This is useful as probe-time information to be displayed, but will also become a parameter that can be queried from user-space once the nova-drm to nova-core bridge is established.
---
Alexandre Courbot (2):
gpu: nova-core: move GSP unload state to a pinned Gpu subobject
gpu: nova-core: move GPU static information acquisition to a GSP method
Joel Fernandes (2):
gpu: nova-core: gsp: Extract usable FB region from GSP
gpu: nova-core: gsp: Expose total physical VRAM end from FB region info
drivers/gpu/nova-core/gpu.rs | 107 ++++++++++++++++++++----------- drivers/gpu/nova-core/gsp.rs | 15 +++-- drivers/gpu/nova-core/gsp/boot.rs | 7 -- drivers/gpu/nova-core/gsp/commands.rs | 14 +++- drivers/gpu/nova-core/gsp/fw/commands.rs | 47 +++++++++++++- 5 files changed, 138 insertions(+), 52 deletions(-)
---
base-commit: bfd90545ad9ef8bed2ac7c157fa9db7604befb27
change-id: 20260609-boot-vram-00d5057102d5
Best regards,
Signature · 1 line
Alexandre Courbot <[email protected]>
Alexandre Courbot
maintainerPATCH 1/4 gpu: nova-core: move GSP unload state to a pinned Gpu subobject
Gpu currently owns the state needed to unload the GSP directly. This means that unload_bundle has to be the last initialized field: once GSP boot succeeds, any later initialization failure would leave Gpu partially initialized, and its PinnedDrop implementation would not run.
This prevents adding fallible Gpu fields that need to query the GSP after it has booted.
Move the GSP state and unload bundle into a dedicated pinned GspResources object. Once that subobject has been initialized, its PinnedDrop implementation will run even if initialization of a later Gpu field fails, ensuring that the GSP unload sequence is executed.
--- drivers/gpu/nova-core/gpu.rs | 86 +++++++++++++++++++++++++------------------- 1 file changed, 49 insertions(+), 37 deletions(-)
drivers/gpu/nova-core/gpu.rs +49 -37
@@ -262,35 +262,59 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { } } -/// Structure holding the resources required to operate the GPU. +/// Self-contained resources to operate and drop the GSP. #[pin_data( PinnedDrop )] -pub (crate )struct Gpu <'gpu> { +struct GspResources <'gpu> {/// Device owning the GPU. device: &'gpu device::Device <device::Bound >, - spec:Spec ,/// MMIO mapping of PCI BAR 0. bar:Bar0 <'gpu>, -/// System memory page required for flushing all pending GPU-side memory writes done through -/// PCIE into system memory, via sysmembar (A GPU-initiated HW memory-barrier operation). - sysmem_flush:SysmemFlush <'gpu>,/// GSP falcon instance, used for GSP boot up and cleanup. gsp_falcon:Falcon <GspFalcon >,/// SEC2 falcon instance, used for GSP boot up and cleanup. sec2_falcon:Falcon <Sec2Falcon >, -/// GSP runtime data. Temporarily an empty placeholder. +/// GSP runtime data. #[pin] gsp:Gsp ,/// GSP unload firmware bundle, if any. unload_bundle:Option <gsp::UnloadBundle >, } +/// Structure holding the resources required to operate the GPU. +#[pin_data] +pub (crate )struct Gpu <'gpu> { + spec:Spec , +/// System memory page required for flushing all pending GPU-side memory writes done through +/// PCIE into system memory, via sysmembar (A GPU-initiated HW memory-barrier operation). + sysmem_flush:SysmemFlush <'gpu>, +/// GSP and its resources. +#[pin] + gsp_resources:GspResources <'gpu>, +} + +#[pinned_drop] +impl PinnedDrop for GspResources <'_> { +fn drop (self:Pin <&mut Self >) { +let this = self.project (); +let device = *this.device; +let bar = *this.bar; +let bundle = this.unload_bundle.take (); + +let _ = this + .gsp + .as_ref () + .get_ref () + .unload (device, bar, &*this.gsp_falcon, &*this.sec2_falcon, bundle) + .inspect_err (|e|dev_err! (device,"failed to unload GSP: {:?}\n" , e)); + } +} +impl <'gpu>Gpu <'gpu> {pub (crate )fn new ( pdev: &'gpu pci::Device <device::Core <'_>>, bar:Bar0 <'gpu>, ) ->impl PinInit <Self ,Error > + 'gpu {try_pin_init! (Self { - device: pdev.as_ref (), spec:Spec ::new (pdev.as_ref (), bar).inspect (|spec| {dev_info! (pdev,"NVIDIA ({})\n" , spec); })?,
@@ -310,38 +334,26 @@ pub(crate) fn new( sysmem_flush: SysmemFlush::register(pdev.as_ref(), bar, spec.chipset)?, - gsp_falcon: Falcon::new( - pdev.as_ref(), - spec.chipset, - ) - .inspect(|falcon| falcon.clear_swgen0_intr(bar))?, + gsp_resources <-try_pin_init! (GspResources { + device: pdev.as_ref (), - sec2_falcon: Falcon::new(pdev.as_ref(), spec.chipset)?, + bar, - gsp <- Gsp::new(pdev), + gsp_falcon:Falcon ::new ( + pdev.as_ref (), + spec.chipset, + ) + .inspect (|falcon| falcon.clear_swgen0_intr (bar))?, -// This member must be initialized last, so the `UnloadBundle` can never be dropped from -// outside of the constructed `Gpu`, ensuring that the unload sequence is properly run -// in case of failure. - unload_bundle: gsp.boot(pdev, bar, spec.chipset, gsp_falcon, sec2_falcon)?, - bar, + sec2_falcon:Falcon ::new (pdev.as_ref (), spec.chipset)?, + + gsp <-Gsp ::new (pdev), + +// This member must be initialized last, so the `UnloadBundle` can never be dropped +// from outside of the constructed `GspResources`, ensuring that the unload sequence +// is properly run in case of failure. + unload_bundle: gsp.boot (pdev, bar, spec.chipset, gsp_falcon, sec2_falcon)?, + }), }) } } - -#[pinned_drop] -impl PinnedDrop for Gpu <'_> { -fn drop (self:Pin <&mut Self >) { -let this = self.project (); -let device = *this.device; -let bar = *this.bar; -let bundle = this.unload_bundle.take (); - -let _ = this - .gsp - .as_ref () - .get_ref () - .unload (device, bar, &*this.gsp_falcon, &*this.sec2_falcon, bundle) - .inspect_err (|e|dev_err! (device,"failed to unload GSP: {:?}\n" , e)); - } -}
Signature · 1 line
2.54.0
Alexandre Courbot
maintainerPATCH 2/4 gpu: nova-core: move GPU static information acquisition to a GSP method
In reply to Alexandre CourbotThe GSP static information is useful during regular driver runtime; however it is currently obtained from Gsp::boot, with no elegant way to pass it back to the caller.
Solve this by moving the code acquiring it to a dedicated method of Gsp that can be called as soon as the Gsp is booted. This allows us to obtain and display the static information from the Gpu constructor, and to store the static information for later use.
Its location at the end of Gsp::boot was a bit out-of-place anyway:
technically, the GSP is considered booted after we have received the GspInitDone message, so anything that happens afterwards is not part of the boot sequence anymore.
--- drivers/gpu/nova-core/gpu.rs | 16 ++++++++++++++++ drivers/gpu/nova-core/gsp.rs | 15 +++++++++++---- drivers/gpu/nova-core/gsp/boot.rs | 7 ------- 3 files changed, 27 insertions(+), 11 deletions(-)
drivers/gpu/nova-core/gpu.rs +16 -0
@@ -23,6 +23,7 @@ fb::SysmemFlush, gsp::{ self, + commands::GetGspStaticInfoReply, Gsp, // }, regs,
@@ -290,6 +291,8 @@ pub(crate) struct Gpu<'gpu> {/// GSP and its resources. #[pin] gsp_resources: GspResources<'gpu>, +/// Static GPU information as provided by the GSP. + gsp_static_info: GetGspStaticInfoReply, }#[pinned_drop]
@@ -354,6 +357,19 @@ pub(crate) fn new(// is properly run in case of failure. unload_bundle: gsp.boot(pdev, bar, spec.chipset, gsp_falcon, sec2_falcon)?, }), + + gsp_static_info: { + let gsp = &gsp_resources.as_ref().get_ref().gsp; + +// Obtain and display basic GPU information. +let info = gsp.get_static_info (bar)?; +match info.gpu_name () { +Ok (name) =>dev_info! (pdev,"GPU name: {}\n" , name), +Err (e) =>dev_warn! (pdev,"GPU name unavailable: {:?}\n" , e), + } + + info + } }) } }
drivers/gpu/nova-core/gsp.rs +11 -4
@@ -31,10 +31,13 @@ };use crate ::{ - gsp::cmdq::Cmdq , - gsp::fw::{ -GspArgumentsPadded , -LibosMemoryRegionInitArgument ,// + driver::Bar0 , + gsp::{ + cmdq::Cmdq , + fw::{ +GspArgumentsPadded , +LibosMemoryRegionInitArgument ,// + }, }, num, };
@@ -185,6 +188,10 @@ pub(crate) fn new(pdev: &pci::Device<device::Bound>) -> impl PinInit<Self, Error })) }) } + +pub (crate )fn get_static_info (&self, bar:Bar0 <'_>) ->Result <commands::GetGspStaticInfoReply > { + self.cmdq.send_command (bar, commands::GetGspStaticInfo ) + } }/// Opaque bundle required to unload the GSP. Created by [`Gsp::boot`], consumed by [`Gsp::unload`].
drivers/gpu/nova-core/gsp/boot.rs +0 -7
@@ -153,13 +153,6 @@ pub(crate) fn boot(// Wait until GSP is fully initialized. commands::wait_gsp_init_done (&self.cmdq)?; -// Obtain and display basic GPU information. -let info = self.cmdq.send_command (bar, commands::GetGspStaticInfo )?; -match info.gpu_name () { -Ok (name) =>dev_info! (pdev,"GPU name: {}\n" , name), -Err (e) =>dev_warn! (pdev,"GPU name unavailable: {:?}\n" , e), - } -Ok (unload_guard.dismiss ()) }
Signature · 1 line
2.54.0
Alexandre Courbot
maintainerPATCH 3/4 gpu: nova-core: gsp: Extract usable FB region from GSP
In reply to Alexandre CourbotFrom: Joel Fernandes <[email protected]>
Add usable_fb_regions_iter() to GspStaticConfigInfo to extract the first usable FB region from GSP's fbRegionInfoParams. Usable regions are those that are not reserved or protected.
The extracted region is stored in GetGspStaticInfoReply and exposed as usable_fb_region field for use by the memory subsystem.
--- drivers/gpu/nova-core/gsp/commands.rs | 9 +++++-- drivers/gpu/nova-core/gsp/fw/commands.rs | 40 +++++++++++++++++++++++++++++++- 2 files changed, 46 insertions(+), 3 deletions(-)
drivers/gpu/nova-core/gsp/commands.rs +7 -2
@@ -5,6 +5,7 @@ array, convert::Infallible, ffi::FromBytesUntilNulError, + ops::Range, str::Utf8Error, // };
@@ -191,15 +192,18 @@ fn init(&self) -> impl Init<Self::Command, Self::InitError> { } } -/// The reply from the GSP to the [`GetGspInfo`] command. +/// The reply from the GSP to the [`GetGspStaticInfo`] command. pub (crate )struct GetGspStaticInfoReply { gpu_name: [u8 ;64 ], +/// Usable FB (VRAM) region for driver memory allocation. +#[expect(dead_code)] +pub (crate ) usable_fb_region:Range <u64 >, }impl MessageFromGsp for GetGspStaticInfoReply {const FUNCTION :MsgFunction =MsgFunction ::GetGspStaticInfo ;type Message = fw::commands::GspStaticConfigInfo ; -type InitError =Infallible ; +type InitError =Error ;fn read ( msg: &Self::Message,
@@ -207,6 +211,7 @@ fn read( ) -> Result<Self, Self::InitError> {Ok (GetGspStaticInfoReply { gpu_name: msg.gpu_name_str (), + usable_fb_region: msg.usable_fb_regions_iter ().next ().ok_or (ENODEV )?, }) } }
drivers/gpu/nova-core/gsp/fw/commands.rs +39 -1
@@ -1,6 +1,8 @@// SPDX-License-Identifier: GPL-2.0 // SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +use core::ops::Range ; +use kernel::{ device, pci,
@@ -13,7 +15,8 @@use crate ::{ gpu::Chipset , - gsp::GSP_PAGE_SIZE ,// + gsp::GSP_PAGE_SIZE , + num::IntoSafeCast ,// };use super ::bindings;
@@ -129,6 +132,41 @@ impl GspStaticConfigInfo {pub (crate )fn gpu_name_str (&self) -> [u8 ;64 ] { self.0 .gpuNameString } + +/// Returns an iterator over valid FB regions from GSP firmware data. +fn fb_regions ( + &self, + ) ->impl Iterator <Item = &bindings::NV2080_CTRL_CMD_FB_GET_FB_REGION_FB_REGION_INFO > { +let fb_info = &self.0 .fbRegionInfoParams; + fb_info + .fbRegion + .iter () + .take (fb_info.numFBRegions.into_safe_cast ()) + .filter (|reg| reg.limit >= reg.base) + } + +/// Iterates over usable FB regions from GSP firmware data. +/// +/// Each yielded region is a [`Range<u64>`] suitable for driver memory allocation. +/// Usable regions are those that satisfy all the following properties: +/// - Are not reserved for firmware internal use. +/// - Are not protected (hardware-enforced access restrictions). +/// - Support compression (can use GPU memory compression for bandwidth). +/// - Support ISO (isochronous memory for display requiring guaranteed bandwidth). +pub (crate )fn usable_fb_regions_iter (&self) ->impl Iterator <Item =Range <u64 >> + '_ { + self.fb_regions ().filter_map (|reg| { +// Filter: not reserved, not protected, supports compression and ISO. +if reg.reserved ==0 + && reg.bProtected ==0 + && reg.supportCompressed !=0 + && reg.supportISO !=0 + { + reg.limit.checked_add (1 ).map (|end| reg.base..end) + }else { +None + } + }) + } }// SAFETY: Padding is explicit and will not contain uninitialized data.
Signature · 1 line
2.54.0
Alexandre Courbot
maintainerPATCH 4/4 gpu: nova-core: gsp: Expose total physical VRAM end from FB region info
In reply to Alexandre CourbotFrom: Joel Fernandes <[email protected]>
Add total_fb_end() to GspStaticConfigInfo that computes the exclusive end address of the highest valid FB region covering both usable and GSP-reserved areas.
This allows callers to know the full physical VRAM extent, not just the allocatable portion.
--- drivers/gpu/nova-core/gpu.rs | 5 ++++- drivers/gpu/nova-core/gsp/commands.rs | 5 +++++ drivers/gpu/nova-core/gsp/fw/commands.rs | 7 +++++++ 3 files changed, 16 insertions(+), 1 deletion(-)
drivers/gpu/nova-core/gpu.rs +4 -1
@@ -9,7 +9,8 @@ io::Io, num::Bounded, pci, - prelude::*, // + prelude::*, + sizes::SizeConstants, // };use crate ::{
@@ -368,6 +369,8 @@ pub(crate) fn new( Err(e) => dev_warn!(pdev, "GPU name unavailable: {:?}\n", e), } +dev_info! (pdev,"Total VRAM: {} MiB\n" , info.total_fb_end /u64 ::SZ_1M ); + info } })
drivers/gpu/nova-core/gsp/commands.rs +5 -0
@@ -198,6 +198,8 @@ pub(crate) struct GetGspStaticInfoReply {/// Usable FB (VRAM) region for driver memory allocation. #[expect(dead_code)] pub(crate) usable_fb_region: Range<u64>, +/// End of VRAM. + pub(crate) total_fb_end: u64, }impl MessageFromGsp for GetGspStaticInfoReply {
@@ -209,9 +211,12 @@ fn read( msg: &Self::Message, _sbuffer: &mut SBufferIter<array::IntoIter<&[u8], 2>>, ) -> Result<Self, Self::InitError> { +let total_fb_end = msg.total_fb_end ().ok_or (ENODEV )?; +Ok (GetGspStaticInfoReply { gpu_name: msg.gpu_name_str (), usable_fb_region: msg.usable_fb_regions_iter ().next ().ok_or (ENODEV )?, + total_fb_end, }) } }
drivers/gpu/nova-core/gsp/fw/commands.rs +7 -0
@@ -167,6 +167,13 @@ pub(crate) fn usable_fb_regions_iter(&self) -> impl Iterator<Item = Range<u64>> } }) } + +/// Compute the end of physical VRAM from all FB regions. +pub (crate )fn total_fb_end (&self) ->Option <u64 > { + self.fb_regions () + .filter_map (|reg| reg.limit.checked_add (1 )) + .max () + } }// SAFETY: Padding is explicit and will not contain uninitialized data.
Signature · 1 line
2.54.0
[email protected]
AI reviewRe: [PATCH 2/4] gpu: nova-core: move GPU static information acquisition to a GSP method
In reply to Alexandre CourbotThank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [High] Incorrect drop order in `Gpu` struct causes sysmem flush page to be unregistered before GSP…
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Incorrect drop order in Gpu struct causes sysmem flush page to be unregistered before GSP falcons are reset, leading to driver timeouts or hardware faults. --
commit 70dc6b2e19cb0af3250719038111e9c9fcddf6e7
Author: Alexandre Courbot <[email protected]>
gpu: nova-core: move GPU static information acquisition to a GSP method
The GSP static information is useful during regular driver runtime; however it is currently obtained from Gsp::boot, with no elegant way to pass it back to the caller. This moves the code acquiring it to a dedicated method of Gsp that can be called as soon as the Gsp is booted.
Quoted 4 lines
drivers/gpu/nova-core/gpu.rs +0
-0
[ ... ]
drivers/gpu/nova-core/gpu.rs pub(crate) struct Gpu<'gpu> { · line 293
Quoted 4 lines
drivers/gpu/nova-core/gpu.rs +0
-0@@ -290,6 +291,8 @@ pub(crate) struct Gpu<'gpu> {/// GSP and its resources. #[pin] gsp_resources: GspResources<'gpu>,
[Severity: High]
Does this struct layout result in an incorrect drop order?
In Rust, struct fields are dropped in their declaration order. Since sysmem_flush is declared before gsp_resources in the Gpu struct, it will be dropped first.
When sysmem_flush drops, its Drop implementation unregisters the memory flush page by writing 0 to the hardware registers. Immediately after, gsp_resources drops, which shuts down the GSP and resets the falcons.
However, the sysmem flush memory page must be registered before any falcon is reset, because the reset handshake requires system memory writes. Dropping the flush page too early means the subsequent falcon reset handshake will write to address 0 or hang, potentially causing a driver timeout or IOMMU fault.
It appears the unload logic was moved to the GspResources subobject in this patch series without reordering the struct fields, which causes the reset to run after the flush page is already unregistered.
Quoted 3 lines
drivers/gpu/nova-core/gpu.rs +2
-0+/// Static GPU information as provided by the GSP. + gsp_static_info: GetGspStaticInfoReply, }
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
[email protected]
AI reviewRe: [PATCH 1/4] gpu: nova-core: move GSP unload state to a pinned Gpu subobject
In reply to Alexandre CourbotThank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [High] Moving the GSP unload logic into `GspResources` while leaving `sysmem_flush` declared before…
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Moving the GSP unload logic into GspResources while leaving sysmem_flush declared before gsp_resources in Gpu causes the sysmem flush memory page to be unregistered before the GSP is shut down, leading to hardware faults or DMA use-after-free. --
commit 77c9cd387aef2d5054c5d4097053c58f9a0d5c45
Author: Alexandre Courbot <[email protected]>
gpu: nova-core: move GSP unload state to a pinned Gpu subobject
This commit moves the GSP state and unload bundle into a dedicated pinned GspResources object to ensure that the GSP unload sequence is executed even if a later Gpu field initialization fails.
Quoted 4 lines
drivers/gpu/nova-core/gpu.rs +0
-0
[ ... ]
drivers/gpu/nova-core/gpu.rs fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { · line 293
Quoted 11 lines
drivers/gpu/nova-core/gpu.rs +11
-0+/// Structure holding the resources required to operate the GPU. +#[pin_data] +pub (crate )struct Gpu <'gpu> { + spec:Spec , +/// System memory page required for flushing all pending GPU-side memory writes done through +/// PCIE into system memory, via sysmembar (A GPU-initiated HW memory-barrier operation). + sysmem_flush:SysmemFlush <'gpu>, +/// GSP and its resources. +#[pin] + gsp_resources:GspResources <'gpu>, +}
[Severity: High]
Since Rust drops struct fields in their declaration order, will sysmem_flush be dropped before gsp_resources here?
If sysmem_flush drops first, it will unregister the system memory DMA page by writing 0 to the hardware register. Next, when gsp_resources drops, its PinnedDrop implementation will execute this.gsp.unload(...) which resets the falcons.
Since the unload sequence strictly relies on the sysmembar flush page to acknowledge resets and flush writes, won't this cause the hardware to attempt to write to physical address 0 after the page has already been unregistered, resulting in an IOMMU fault or driver timeout?
Should gsp_resources be declared before sysmem_flush to ensure the GSP is shut down fully before the flush page is unregistered?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Re: [PATCH 3/4] gpu: nova-core: gsp: Extract usable FB region from GSP
In reply to Alexandre CourbotQuoted 85 lines · Alexandre Courbot
From: Joel Fernandes <[email protected]>
Add
usable_fb_regions_iter()to GspStaticConfigInfo to extract the first usable FB region from GSP's fbRegionInfoParams. Usable regions are those that are not reserved or protected.The extracted region is stored in GetGspStaticInfoReply and exposed as
usable_fb_regionfield for use by the memory subsystem.Signed-off-by Joel Fernandes <[email protected]>Reviewed-by John Hubbard <[email protected]>--- drivers/gpu/nova-core/gsp/commands.rs | 9 +++++-- drivers/gpu/nova-core/gsp/fw/commands.rs | 40 +++++++++++++++++++++++++++++++- 2 files changed, 46 insertions(+), 3 deletions(-)drivers/gpu/nova-core/gsp/commands.rs +7
-2@@ -5,6 +5,7 @@ array, convert::Infallible, ffi::FromBytesUntilNulError, + ops::Range, str::Utf8Error, // };@@ -191,15 +192,18 @@ fn init(&self) -> impl Init<Self::Command, Self::InitError> { } } -/// The reply from the GSP to the [`GetGspInfo`] command. +/// The reply from the GSP to the [`GetGspStaticInfo`] command. pub (crate )struct GetGspStaticInfoReply { gpu_name: [u8 ;64 ], +/// Usable FB (VRAM) region for driver memory allocation. +#[expect(dead_code)] +pub (crate ) usable_fb_region:Range <u64 >, }impl MessageFromGsp for GetGspStaticInfoReply {const FUNCTION :MsgFunction =MsgFunction ::GetGspStaticInfo ;type Message = fw::commands::GspStaticConfigInfo ; -type InitError =Infallible ; +type InitError =Error ;fn read ( msg: &Self::Message,@@ -207,6 +211,7 @@ fn read( ) -> Result<Self, Self::InitError> {Ok (GetGspStaticInfoReply { gpu_name: msg.gpu_name_str (), + usable_fb_region: msg.usable_fb_regions_iter ().next ().ok_or (ENODEV )?, }) } }drivers/gpu/nova-core/gsp/fw/commands.rs +5
-1@@ -1,6 +1,8 @@// SPDX-License-Identifier: GPL-2.0 // SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +use core::ops::Range ; +use kernel::{ device, pci,@@ -13,7 +15,8 @@use crate ::{ gpu::Chipset , - gsp::GSP_PAGE_SIZE ,// + gsp::GSP_PAGE_SIZE , + num::IntoSafeCast ,// };use super ::bindings;@@ -129,6 +132,41 @@ impl GspStaticConfigInfo {pub (crate )fn gpu_name_str (&self) -> [u8 ;64 ] { self.0 .gpuNameString } +
drivers/gpu/nova-core/gsp/fw/commands.rs impl GspStaticConfigInfo { · line 145
Quoted 10 lines
drivers/gpu/nova-core/gsp/fw/commands.rs +10
-0+/// Returns an iterator over valid FB regions from GSP firmware data. +fn fb_regions ( + &self, + ) ->impl Iterator <Item = &bindings::NV2080_CTRL_CMD_FB_GET_FB_REGION_FB_REGION_INFO > { +let fb_info = &self.0 .fbRegionInfoParams; + fb_info + .fbRegion + .iter () + .take (fb_info.numFBRegions.into_safe_cast ()) + .filter (|reg| reg.limit >= reg.base)
Do you know if we actually get broken values like this (limit < base)?
Also we could print out the usable_fb_region as well, if you like?
Quoted 27 lines
drivers/gpu/nova-core/gsp/fw/commands.rs +24
-0+ } + +/// Iterates over usable FB regions from GSP firmware data. +/// +/// Each yielded region is a [`Range<u64>`] suitable for driver memory allocation. +/// Usable regions are those that satisfy all the following properties: +/// - Are not reserved for firmware internal use. +/// - Are not protected (hardware-enforced access restrictions). +/// - Support compression (can use GPU memory compression for bandwidth). +/// - Support ISO (isochronous memory for display requiring guaranteed bandwidth). +pub (crate )fn usable_fb_regions_iter (&self) ->impl Iterator <Item =Range <u64 >> + '_ { + self.fb_regions ().filter_map (|reg| { +// Filter: not reserved, not protected, supports compression and ISO. +if reg.reserved ==0 + && reg.bProtected ==0 + && reg.supportCompressed !=0 + && reg.supportISO !=0 + { + reg.limit.checked_add (1 ).map (|end| reg.base..end) + }else { +None + } + }) + } }// SAFETY: Padding is explicit and will not contain uninitialized data.
Re: [PATCH 4/4] gpu: nova-core: gsp: Expose total physical VRAM end from FB region info
In reply to Alexandre CourbotQuoted 11 lines · Alexandre Courbot
From: Joel Fernandes <[email protected]>
Add
total_fb_end()toGspStaticConfigInfothat computes the exclusive end address of the highest valid FB region covering both usable and GSP-reserved areas.This allows callers to know the full physical VRAM extent, not just the allocatable portion.
Signed-off-by Joel Fernandes <[email protected]>---
Re: [PATCH 2/4] gpu: nova-core: move GPU static information acquisition to a GSP method
In reply to Alexandre CourbotQuoted 9 lines · Alexandre Courbot
The GSP static information is useful during regular driver runtime; however it is currently obtained from
Gsp::boot, with no elegant way to pass it back to the caller.Solve this by moving the code acquiring it to a dedicated method of
Gspthat can be called as soon as theGspis booted. This allows us to obtain and display the static information from theGpuconstructor, and to store the static information for later use.
Quoted 7 lines
Its location at the end of
Gsp::bootwas a bit out-of-place anyway:
technically, the GSP is considered booted after we have received theGspInitDonemessage, so anything that happens afterwards is not part of the boot sequence anymore.Signed-off-by Alexandre Courbot <[email protected]>---
Re: [PATCH 1/4] gpu: nova-core: move GSP unload state to a pinned Gpu subobject
In reply to Alexandre CourbotQuoted 48 lines · Alexandre Courbot
Gpucurrently owns the state needed to unload the GSP directly. This means thatunload_bundlehas to be the last initialized field: once GSP boot succeeds, any later initialization failure would leaveGpupartially initialized, and itsPinnedDropimplementation would not run.This prevents adding fallible
Gpufields that need to query the GSP after it has booted.Move the GSP state and unload bundle into a dedicated pinned
GspResourcesobject. Once that subobject has been initialized, itsPinnedDropimplementation will run even if initialization of a laterGpufield fails, ensuring that the GSP unload sequence is executed.Signed-off-by Alexandre Courbot <[email protected]>--- drivers/gpu/nova-core/gpu.rs | 86 +++++++++++++++++++++++++------------------- 1 file changed, 49 insertions(+), 37 deletions(-)drivers/gpu/nova-core/gpu.rs +3
-7@@ -262,35 +262,59 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { } } -/// Structure holding the resources required to operate the GPU. +/// Self-contained resources to operate and drop the GSP. #[pin_data( PinnedDrop )] -pub (crate )struct Gpu <'gpu> { +struct GspResources <'gpu> {/// Device owning the GPU. device: &'gpu device::Device <device::Bound >, - spec:Spec ,/// MMIO mapping of PCI BAR 0. bar:Bar0 <'gpu>, -/// System memory page required for flushing all pending GPU-side memory writes done through -/// PCIE into system memory, via sysmembar (A GPU-initiated HW memory-barrier operation). - sysmem_flush:SysmemFlush <'gpu>,/// GSP falcon instance, used for GSP boot up and cleanup. gsp_falcon:Falcon <GspFalcon >,/// SEC2 falcon instance, used for GSP boot up and cleanup. sec2_falcon:Falcon <Sec2Falcon >, -/// GSP runtime data. Temporarily an empty placeholder. +/// GSP runtime data. #[pin] gsp:Gsp ,/// GSP unload firmware bundle, if any.
drivers/gpu/nova-core/gpu.rs fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { · line 289
Quoted 10 lines
drivers/gpu/nova-core/gpu.rs +7
-0unload_bundle: Option<gsp::UnloadBundle>, } +/// Structure holding the resources required to operate the GPU. +#[pin_data] +pub (crate )struct Gpu <'gpu> { + spec:Spec , +/// System memory page required for flushing all pending GPU-side memory writes done through +/// PCIE into system memory, via sysmembar (A GPU-initiated HW memory-barrier operation). + sysmem_flush:SysmemFlush <'gpu>,
This means sysmem_flush is dropped before unload is run. Before this patch, PinnedDrop runs the unload bundle before sysmem_flush's drop actually runs. But with this code it'll drop sysmem_flush first, and that isn't allowed according to the comment in fb.rs saying that it's needed for falcon reset. What about sysmem flush into GspResources as well?
Quoted 88 lines
drivers/gpu/nova-core/gpu.rs +39
-30+/// GSP and its resources. +#[pin] + gsp_resources: GspResources<'gpu>, +} + +#[pinned_drop] +impl PinnedDrop for GspResources <'_> { +fn drop (self:Pin <&mut Self >) { +let this = self.project (); +let device = *this.device; +let bar = *this.bar; +let bundle = this.unload_bundle.take (); + +let _ = this + .gsp + .as_ref () + .get_ref () + .unload (device, bar, &*this.gsp_falcon, &*this.sec2_falcon, bundle) + .inspect_err (|e|dev_err! (device,"failed to unload GSP: {:?}\n" , e)); + } +} +impl <'gpu>Gpu <'gpu> {pub (crate )fn new ( pdev: &'gpu pci::Device <device::Core <'_>>, bar:Bar0 <'gpu>, ) ->impl PinInit <Self ,Error > + 'gpu {try_pin_init! (Self { - device: pdev.as_ref (), spec:Spec ::new (pdev.as_ref (), bar).inspect (|spec| {dev_info! (pdev,"NVIDIA ({})\n" , spec); })?,@@ -310,38 +334,26 @@ pub(crate) fn new( sysmem_flush: SysmemFlush::register(pdev.as_ref(), bar, spec.chipset)?, - gsp_falcon: Falcon::new( - pdev.as_ref(), - spec.chipset, - ) - .inspect(|falcon| falcon.clear_swgen0_intr(bar))?, + gsp_resources <-try_pin_init! (GspResources { + device: pdev.as_ref (), - sec2_falcon: Falcon::new(pdev.as_ref(), spec.chipset)?, + bar, - gsp <- Gsp::new(pdev), + gsp_falcon:Falcon ::new ( + pdev.as_ref (), + spec.chipset, + ) + .inspect (|falcon| falcon.clear_swgen0_intr (bar))?, -// This member must be initialized last, so the `UnloadBundle` can never be dropped from -// outside of the constructed `Gpu`, ensuring that the unload sequence is properly run -// in case of failure. - unload_bundle: gsp.boot(pdev, bar, spec.chipset, gsp_falcon, sec2_falcon)?, - bar, + sec2_falcon:Falcon ::new (pdev.as_ref (), spec.chipset)?, + + gsp <-Gsp ::new (pdev), + +// This member must be initialized last, so the `UnloadBundle` can never be dropped +// from outside of the constructed `GspResources`, ensuring that the unload sequence +// is properly run in case of failure. + unload_bundle: gsp.boot (pdev, bar, spec.chipset, gsp_falcon, sec2_falcon)?, + }), }) } } - -#[pinned_drop] -impl PinnedDrop for Gpu <'_> { -fn drop (self:Pin <&mut Self >) { -let this = self.project (); -let device = *this.device; -let bar = *this.bar; -let bundle = this.unload_bundle.take (); - -let _ = this - .gsp - .as_ref () - .get_ref () - .unload (device, bar, &*this.gsp_falcon, &*this.sec2_falcon, bundle) - .inspect_err (|e|dev_err! (device,"failed to unload GSP: {:?}\n" , e)); - } -}
Gary Guo
reviewerRe: [PATCH 1/4] gpu: nova-core: move GSP unload state to a pinned Gpu subobject
In reply to Alexandre CourbotQuoted 39 lines · Alexandre Courbot
Gpucurrently owns the state needed to unload the GSP directly. This means thatunload_bundlehas to be the last initialized field: once GSP boot succeeds, any later initialization failure would leaveGpupartially initialized, and itsPinnedDropimplementation would not run.This prevents adding fallible
Gpufields that need to query the GSP after it has booted.Move the GSP state and unload bundle into a dedicated pinned
GspResourcesobject. Once that subobject has been initialized, itsPinnedDropimplementation will run even if initialization of a laterGpufield fails, ensuring that the GSP unload sequence is executed.Signed-off-by Alexandre Courbot <[email protected]>--- drivers/gpu/nova-core/gpu.rs | 86 +++++++++++++++++++++++++------------------- 1 file changed, 49 insertions(+), 37 deletions(-)drivers/gpu/nova-core/gpu.rs +2
-6@@ -262,35 +262,59 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { } } -/// Structure holding the resources required to operate the GPU. +/// Self-contained resources to operate and drop the GSP. #[pin_data( PinnedDrop )] -pub (crate )struct Gpu <'gpu> { +struct GspResources <'gpu> {/// Device owning the GPU. device: &'gpu device::Device <device::Bound >, - spec:Spec ,/// MMIO mapping of PCI BAR 0. bar:Bar0 <'gpu>, -/// System memory page required for flushing all pending GPU-side memory writes done through -/// PCIE into system memory, via sysmembar (A GPU-initiated HW memory-barrier operation). - sysmem_flush:SysmemFlush <'gpu>,
drivers/gpu/nova-core/gpu.rs fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { · line 280
Quoted 10 lines
drivers/gpu/nova-core/gpu.rs +1
-1/// GSP falcon instance, used for GSP boot up and cleanup. gsp_falcon: Falcon<GspFalcon>, /// SEC2 falcon instance, used for GSP boot up and cleanup. sec2_falcon: Falcon<Sec2Falcon>, -/// GSP runtime data. Temporarily an empty placeholder. +/// GSP runtime data. #[pin] gsp: Gsp,/// GSP unload firmware bundle, if any. unload_bundle: Option<gsp::UnloadBundle>,
I suppose this field is for unloading only? If so, you could just create a new type that stores device, bar, bundle only, which works as device and bar are Copy.
struct UnloadGuard<'gpu> {
deivce: &'gpu device::Device<device::Bound>,
bar: Bar0<'gpu>,
unload_bundle: Option<gsp::UnloadBundle>,
}
impl Drop for UnloadGuard {
...
}This does mean that the device and bar are stored repeatedly, but this way you get a very clean way of representing this: once UnloadGuard is created unload will happen.
Best,
Gary
Quoted 97 lines
drivers/gpu/nova-core/gpu.rs +46
-30} +/// Structure holding the resources required to operate the GPU. +#[pin_data] +pub (crate )struct Gpu <'gpu> { + spec:Spec , +/// System memory page required for flushing all pending GPU-side memory writes done through +/// PCIE into system memory, via sysmembar (A GPU-initiated HW memory-barrier operation). + sysmem_flush:SysmemFlush <'gpu>, +/// GSP and its resources. +#[pin] + gsp_resources:GspResources <'gpu>, +} + +#[pinned_drop] +impl PinnedDrop for GspResources <'_> { +fn drop (self:Pin <&mut Self >) { +let this = self.project (); +let device = *this.device; +let bar = *this.bar; +let bundle = this.unload_bundle.take (); + +let _ = this + .gsp + .as_ref () + .get_ref () + .unload (device, bar, &*this.gsp_falcon, &*this.sec2_falcon, bundle) + .inspect_err (|e|dev_err! (device,"failed to unload GSP: {:?}\n" , e)); + } +} +impl <'gpu>Gpu <'gpu> {pub (crate )fn new ( pdev: &'gpu pci::Device <device::Core <'_>>, bar:Bar0 <'gpu>, ) ->impl PinInit <Self ,Error > + 'gpu {try_pin_init! (Self { - device: pdev.as_ref (), spec:Spec ::new (pdev.as_ref (), bar).inspect (|spec| {dev_info! (pdev,"NVIDIA ({})\n" , spec); })?,@@ -310,38 +334,26 @@ pub(crate) fn new( sysmem_flush: SysmemFlush::register(pdev.as_ref(), bar, spec.chipset)?, - gsp_falcon: Falcon::new( - pdev.as_ref(), - spec.chipset, - ) - .inspect(|falcon| falcon.clear_swgen0_intr(bar))?, + gsp_resources <-try_pin_init! (GspResources { + device: pdev.as_ref (), - sec2_falcon: Falcon::new(pdev.as_ref(), spec.chipset)?, + bar, - gsp <- Gsp::new(pdev), + gsp_falcon:Falcon ::new ( + pdev.as_ref (), + spec.chipset, + ) + .inspect (|falcon| falcon.clear_swgen0_intr (bar))?, -// This member must be initialized last, so the `UnloadBundle` can never be dropped from -// outside of the constructed `Gpu`, ensuring that the unload sequence is properly run -// in case of failure. - unload_bundle: gsp.boot(pdev, bar, spec.chipset, gsp_falcon, sec2_falcon)?, - bar, + sec2_falcon:Falcon ::new (pdev.as_ref (), spec.chipset)?, + + gsp <-Gsp ::new (pdev), + +// This member must be initialized last, so the `UnloadBundle` can never be dropped +// from outside of the constructed `GspResources`, ensuring that the unload sequence +// is properly run in case of failure. + unload_bundle: gsp.boot (pdev, bar, spec.chipset, gsp_falcon, sec2_falcon)?, + }), }) } } - -#[pinned_drop] -impl PinnedDrop for Gpu <'_> { -fn drop (self:Pin <&mut Self >) { -let this = self.project (); -let device = *this.device; -let bar = *this.bar; -let bundle = this.unload_bundle.take (); - -let _ = this - .gsp - .as_ref () - .get_ref () - .unload (device, bar, &*this.gsp_falcon, &*this.sec2_falcon, bundle) - .inspect_err (|e|dev_err! (device,"failed to unload GSP: {:?}\n" , e)); - } -}
Gary Guo
reviewerRe: [PATCH 2/4] gpu: nova-core: move GPU static information acquisition to a GSP method
In reply to Alexandre CourbotQuoted 43 lines · Alexandre Courbot
The GSP static information is useful during regular driver runtime; however it is currently obtained from
Gsp::boot, with no elegant way to pass it back to the caller.Solve this by moving the code acquiring it to a dedicated method of
Gspthat can be called as soon as theGspis booted. This allows us to obtain and display the static information from theGpuconstructor, and to store the static information for later use.Its location at the end of
Gsp::bootwas a bit out-of-place anyway:
technically, the GSP is considered booted after we have received theGspInitDonemessage, so anything that happens afterwards is not part of the boot sequence anymore.Signed-off-by Alexandre Courbot <[email protected]>--- drivers/gpu/nova-core/gpu.rs | 16 ++++++++++++++++ drivers/gpu/nova-core/gsp.rs | 15 +++++++++++---- drivers/gpu/nova-core/gsp/boot.rs | 7 ------- 3 files changed, 27 insertions(+), 11 deletions(-)drivers/gpu/nova-core/gpu.rs +3
-0@@ -23,6 +23,7 @@ fb::SysmemFlush, gsp::{ self, + commands::GetGspStaticInfoReply, Gsp, // }, regs,@@ -290,6 +291,8 @@ pub(crate) struct Gpu<'gpu> {/// GSP and its resources. #[pin] gsp_resources: GspResources<'gpu>, +/// Static GPU information as provided by the GSP. + gsp_static_info: GetGspStaticInfoReply, }#[pinned_drop]
drivers/gpu/nova-core/gpu.rs pub(crate) fn new( · line 362
Quoted 6 lines
drivers/gpu/nova-core/gpu.rs +3
-0@@ -354,6 +357,19 @@ pub(crate) fn new(// is properly run in case of failure. unload_bundle: gsp.boot(pdev, bar, spec.chipset, gsp_falcon, sec2_falcon)?, }), + + gsp_static_info: { + let gsp = &gsp_resources.as_ref().get_ref().gsp;
What's this as_ref().get_ref() for? This could just be referenced as &gsp_resoruces.gsp? Or am I missing something?
Best,
Gary
Quoted 13 lines
drivers/gpu/nova-core/gpu.rs +10
-0+ +// Obtain and display basic GPU information. +let info = gsp.get_static_info (bar)?; +match info.gpu_name () { +Ok (name) =>dev_info! (pdev,"GPU name: {}\n" , name), +Err (e) =>dev_warn! (pdev,"GPU name unavailable: {:?}\n" , e), + } + + info + } }) } }
Gary Guo
reviewerRe: [PATCH 3/4] gpu: nova-core: gsp: Extract usable FB region from GSP
In reply to Alexandre CourbotQuoted 50 lines · Alexandre Courbot
From: Joel Fernandes <[email protected]>
Add
usable_fb_regions_iter()to GspStaticConfigInfo to extract the first usable FB region from GSP's fbRegionInfoParams. Usable regions are those that are not reserved or protected.The extracted region is stored in GetGspStaticInfoReply and exposed as
usable_fb_regionfield for use by the memory subsystem.Signed-off-by Joel Fernandes <[email protected]>Reviewed-by John Hubbard <[email protected]>--- drivers/gpu/nova-core/gsp/commands.rs | 9 +++++-- drivers/gpu/nova-core/gsp/fw/commands.rs | 40 +++++++++++++++++++++++++++++++- 2 files changed, 46 insertions(+), 3 deletions(-)drivers/gpu/nova-core/gsp/commands.rs +6
-2@@ -5,6 +5,7 @@ array, convert::Infallible, ffi::FromBytesUntilNulError, + ops::Range, str::Utf8Error, // };@@ -191,15 +192,18 @@ fn init(&self) -> impl Init<Self::Command, Self::InitError> { } } -/// The reply from the GSP to the [`GetGspInfo`] command. +/// The reply from the GSP to the [`GetGspStaticInfo`] command. pub (crate )struct GetGspStaticInfoReply { gpu_name: [u8 ;64 ], +/// Usable FB (VRAM) region for driver memory allocation. +#[expect(dead_code)] +pub (crate ) usable_fb_region:Range <u64 >, }impl MessageFromGsp for GetGspStaticInfoReply {const FUNCTION :MsgFunction =MsgFunction ::GetGspStaticInfo ;type Message = fw::commands::GspStaticConfigInfo ; -type InitError =Infallible ; +type InitError =Error ;fn read ( msg: &Self::Message,
drivers/gpu/nova-core/gsp/commands.rs fn read( · line 214
Quoted 4 lines
drivers/gpu/nova-core/gsp/commands.rs +1
-0@@ -207,6 +211,7 @@ fn read( ) -> Result<Self, Self::InitError> { Ok(GetGspStaticInfoReply { gpu_name: msg.gpu_name_str(), + usable_fb_region: msg.usable_fb_regions_iter().next().ok_or(ENODEV)?,
Does it just essentially require a FB to be present? What would happen to GPUs without display support like RTX PRO 4500 Blackwell Server Edition?
I feel that this check should be done by the user of GetGspStaticInfoReply, the firmware doesn't reply with an error.
Quoted 42 lines
drivers/gpu/nova-core/gsp/commands.rs +0
-0}) } }drivers/gpu/nova-core/gsp/fw/commands.rs +16
-1@@ -1,6 +1,8 @@// SPDX-License-Identifier: GPL-2.0 // SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +use core::ops::Range ; +use kernel::{ device, pci,@@ -13,7 +15,8 @@use crate ::{ gpu::Chipset , - gsp::GSP_PAGE_SIZE ,// + gsp::GSP_PAGE_SIZE , + num::IntoSafeCast ,// };use super ::bindings;@@ -129,6 +132,41 @@ impl GspStaticConfigInfo {pub (crate )fn gpu_name_str (&self) -> [u8 ;64 ] { self.0 .gpuNameString } + +/// Returns an iterator over valid FB regions from GSP firmware data. +fn fb_regions ( + &self, + ) ->impl Iterator <Item = &bindings::NV2080_CTRL_CMD_FB_GET_FB_REGION_FB_REGION_INFO > { +let fb_info = &self.0 .fbRegionInfoParams; + fb_info + .fbRegion + .iter () + .take (fb_info.numFBRegions.into_safe_cast ()) + .filter (|reg| reg.limit >= reg.base) + }
drivers/gpu/nova-core/gsp/fw/commands.rs impl GspStaticConfigInfo { · line 156
Quoted 10 lines
drivers/gpu/nova-core/gsp/fw/commands.rs +10
-0+ +/// Iterates over usable FB regions from GSP firmware data. +/// +/// Each yielded region is a [`Range<u64>`] suitable for driver memory allocation. +/// Usable regions are those that satisfy all the following properties: +/// - Are not reserved for firmware internal use. +/// - Are not protected (hardware-enforced access restrictions). +/// - Support compression (can use GPU memory compression for bandwidth). +/// - Support ISO (isochronous memory for display requiring guaranteed bandwidth). +pub (crate )fn usable_fb_regions_iter (&self) ->impl Iterator <Item =Range <u64 >> + '_ {
I think this is a bit too verbose. usable_fb_regions should be okay.
Best,
Gary
Quoted 16 lines
drivers/gpu/nova-core/gsp/fw/commands.rs +13
-0+ self.fb_regions ().filter_map (|reg| { +// Filter: not reserved, not protected, supports compression and ISO. +if reg.reserved ==0 + && reg.bProtected ==0 + && reg.supportCompressed !=0 + && reg.supportISO !=0 + { + reg.limit.checked_add (1 ).map (|end| reg.base..end) + }else { +None + } + }) + } }// SAFETY: Padding is explicit and will not contain uninitialized data.
Gary Guo
reviewerRe: [PATCH 3/4] gpu: nova-core: gsp: Extract usable FB region from GSP
Quoted 48 lines · Gary Guo
Quoted 47 lines · Alexandre Courbot
From: Joel Fernandes <[email protected]>
Add
usable_fb_regions_iter()to GspStaticConfigInfo to extract the first usable FB region from GSP's fbRegionInfoParams. Usable regions are those that are not reserved or protected.The extracted region is stored in GetGspStaticInfoReply and exposed as
usable_fb_regionfield for use by the memory subsystem.Signed-off-by Joel Fernandes <[email protected]>Reviewed-by John Hubbard <[email protected]>--- drivers/gpu/nova-core/gsp/commands.rs | 9 +++++-- drivers/gpu/nova-core/gsp/fw/commands.rs | 40 +++++++++++++++++++++++++++++++- 2 files changed, 46 insertions(+), 3 deletions(-)drivers/gpu/nova-core/gsp/commands.rs +6
-2@@ -5,6 +5,7 @@ array, convert::Infallible, ffi::FromBytesUntilNulError, + ops::Range, str::Utf8Error, // };@@ -191,15 +192,18 @@ fn init(&self) -> impl Init<Self::Command, Self::InitError> { } } -/// The reply from the GSP to the [`GetGspInfo`] command. +/// The reply from the GSP to the [`GetGspStaticInfo`] command. pub (crate )struct GetGspStaticInfoReply { gpu_name: [u8 ;64 ], +/// Usable FB (VRAM) region for driver memory allocation. +#[expect(dead_code)] +pub (crate ) usable_fb_region:Range <u64 >, }impl MessageFromGsp for GetGspStaticInfoReply {const FUNCTION :MsgFunction =MsgFunction ::GetGspStaticInfo ;type Message = fw::commands::GspStaticConfigInfo ; -type InitError =Infallible ; +type InitError =Error ;
Quoted 10 lines
drivers/gpu/nova-core/gsp/commands.rs fn read( · line 214
Quoted 7 lines
drivers/gpu/nova-core/gsp/commands.rs +1
-0fn read ( msg: &Self::Message,@@ -207,6 +211,7 @@ fn read( ) -> Result<Self, Self::InitError> { Ok(GetGspStaticInfoReply { gpu_name: msg.gpu_name_str(), + usable_fb_region: msg.usable_fb_regions_iter().next().ok_or(ENODEV)?,Does it just essentially require a FB to be present? What would happen to GPUs without display support like RTX PRO 4500 Blackwell Server Edition?
Actually looks like FB in Nova just means "VRAM" and not actually "Framebuffer". Is this documented somewhere or am I just incapable of finding it?
Best,
Gary
Quoted 3 lines
I feel that this check should be done by the user of
GetGspStaticInfoReply, the firmware doesn't reply with an error.
Alexandre Courbot
maintainerRe: [PATCH 1/4] gpu: nova-core: move GSP unload state to a pinned Gpu subobject
In reply to Eliot CourtneyQuoted 52 lines · Eliot Courtney
Quoted 51 lines · Alexandre Courbot
Gpucurrently owns the state needed to unload the GSP directly. This means thatunload_bundlehas to be the last initialized field: once GSP boot succeeds, any later initialization failure would leaveGpupartially initialized, and itsPinnedDropimplementation would not run.This prevents adding fallible
Gpufields that need to query the GSP after it has booted.Move the GSP state and unload bundle into a dedicated pinned
GspResourcesobject. Once that subobject has been initialized, itsPinnedDropimplementation will run even if initialization of a laterGpufield fails, ensuring that the GSP unload sequence is executed.Signed-off-by Alexandre Courbot <[email protected]>--- drivers/gpu/nova-core/gpu.rs | 86 +++++++++++++++++++++++++------------------- 1 file changed, 49 insertions(+), 37 deletions(-)drivers/gpu/nova-core/gpu.rs +3
-7@@ -262,35 +262,59 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { } } -/// Structure holding the resources required to operate the GPU. +/// Self-contained resources to operate and drop the GSP. #[pin_data( PinnedDrop )] -pub (crate )struct Gpu <'gpu> { +struct GspResources <'gpu> {/// Device owning the GPU. device: &'gpu device::Device <device::Bound >, - spec:Spec ,/// MMIO mapping of PCI BAR 0. bar:Bar0 <'gpu>, -/// System memory page required for flushing all pending GPU-side memory writes done through -/// PCIE into system memory, via sysmembar (A GPU-initiated HW memory-barrier operation). - sysmem_flush:SysmemFlush <'gpu>,/// GSP falcon instance, used for GSP boot up and cleanup. gsp_falcon:Falcon <GspFalcon >,/// SEC2 falcon instance, used for GSP boot up and cleanup. sec2_falcon:Falcon <Sec2Falcon >, -/// GSP runtime data. Temporarily an empty placeholder. +/// GSP runtime data. #[pin] gsp:Gsp ,/// GSP unload firmware bundle, if any. unload_bundle:Option <gsp::UnloadBundle >, }
Quoted 14 lines
drivers/gpu/nova-core/gpu.rs fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { · line 289
Quoted 7 lines
drivers/gpu/nova-core/gpu.rs +7
-0+/// Structure holding the resources required to operate the GPU. +#[pin_data] +pub (crate )struct Gpu <'gpu> { + spec:Spec , +/// System memory page required for flushing all pending GPU-side memory writes done through +/// PCIE into system memory, via sysmembar (A GPU-initiated HW memory-barrier operation). + sysmem_flush:SysmemFlush <'gpu>,This means
sysmem_flushis dropped before unload is run. Before this patch, PinnedDrop runs the unload bundle before sysmem_flush's drop actually runs. But with this code it'll dropsysmem_flushfirst, and that isn't allowed according to the comment infb.rssaying that it's needed for falcon reset. What about sysmem flush into GspResources as well?
Yes, Sashiko also found the same issue actually. I will fix that by declaring sysmem_flush after gsp_resources in Gpu so it is dropped after. Initialization is done in the given order by pin_init!, so we can still initialize sysmem_flush before gsp_resources.
Alexandre Courbot
maintainerRe: [PATCH 1/4] gpu: nova-core: move GSP unload state to a pinned Gpu subobject
In reply to Gary GuoQuoted 61 lines · Gary Guo
Quoted 39 lines · Alexandre Courbot
Gpucurrently owns the state needed to unload the GSP directly. This means thatunload_bundlehas to be the last initialized field: once GSP boot succeeds, any later initialization failure would leaveGpupartially initialized, and itsPinnedDropimplementation would not run.This prevents adding fallible
Gpufields that need to query the GSP after it has booted.Move the GSP state and unload bundle into a dedicated pinned
GspResourcesobject. Once that subobject has been initialized, itsPinnedDropimplementation will run even if initialization of a laterGpufield fails, ensuring that the GSP unload sequence is executed.Signed-off-by Alexandre Courbot <[email protected]>--- drivers/gpu/nova-core/gpu.rs | 86 +++++++++++++++++++++++++------------------- 1 file changed, 49 insertions(+), 37 deletions(-)drivers/gpu/nova-core/gpu.rs +2
-6@@ -262,35 +262,59 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { } } -/// Structure holding the resources required to operate the GPU. +/// Self-contained resources to operate and drop the GSP. #[pin_data( PinnedDrop )] -pub (crate )struct Gpu <'gpu> { +struct GspResources <'gpu> {/// Device owning the GPU. device: &'gpu device::Device <device::Bound >, - spec:Spec ,/// MMIO mapping of PCI BAR 0. bar:Bar0 <'gpu>, -/// System memory page required for flushing all pending GPU-side memory writes done through -/// PCIE into system memory, via sysmembar (A GPU-initiated HW memory-barrier operation). - sysmem_flush:SysmemFlush <'gpu>,drivers/gpu/nova-core/gpu.rs fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { · line 280
Quoted 10 lines
drivers/gpu/nova-core/gpu.rs +1
-1/// GSP falcon instance, used for GSP boot up and cleanup. gsp_falcon: Falcon<GspFalcon>, /// SEC2 falcon instance, used for GSP boot up and cleanup. sec2_falcon: Falcon<Sec2Falcon>, -/// GSP runtime data. Temporarily an empty placeholder. +/// GSP runtime data. #[pin] gsp: Gsp,/// GSP unload firmware bundle, if any. unload_bundle: Option<gsp::UnloadBundle>,I suppose this field is for unloading only? If so, you could just create a new type that stores
device,bar,bundleonly, which works asdeviceandbarare Copy.struct UnloadGuard<'gpu> {
deivce: &'gpu device::Device<device::Bound>,
bar: Bar0<'gpu>,
unload_bundle: Option<gsp::UnloadBundle>,
}
Quoted 7 lines
impl Drop for UnloadGuard { ... }This does mean that the
deviceandbarare stored repeatedly, but this way you get a very clean way of representing this: onceUnloadGuardis created unload will happen.
For UnloadGuard to be able to run the unload sequence, it would also need a reference to the Gsp itself, and to the GSP and SEC2 falcons - which would basically turn it into GspResources unless I misunderstood your suggestion.
(the falcons are owned by GspResources because I want to make their load and run methods take &mut self soon)
GspResources also already stores device and bar in the fashion you suggested, for the same reason.
Eliot Courtney
Reviewed-byRe: [PATCH 1/4] gpu: nova-core: move GSP unload state to a pinned Gpu subobject
In reply to Alexandre CourbotQuoted 68 lines · Alexandre Courbot
Quoted 52 lines · Eliot Courtney
Quoted 51 lines · Alexandre Courbot
Gpucurrently owns the state needed to unload the GSP directly. This means thatunload_bundlehas to be the last initialized field: once GSP boot succeeds, any later initialization failure would leaveGpupartially initialized, and itsPinnedDropimplementation would not run.This prevents adding fallible
Gpufields that need to query the GSP after it has booted.Move the GSP state and unload bundle into a dedicated pinned
GspResourcesobject. Once that subobject has been initialized, itsPinnedDropimplementation will run even if initialization of a laterGpufield fails, ensuring that the GSP unload sequence is executed.Signed-off-by Alexandre Courbot <[email protected]>--- drivers/gpu/nova-core/gpu.rs | 86 +++++++++++++++++++++++++------------------- 1 file changed, 49 insertions(+), 37 deletions(-)drivers/gpu/nova-core/gpu.rs +3
-7@@ -262,35 +262,59 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { } } -/// Structure holding the resources required to operate the GPU. +/// Self-contained resources to operate and drop the GSP. #[pin_data( PinnedDrop )] -pub (crate )struct Gpu <'gpu> { +struct GspResources <'gpu> {/// Device owning the GPU. device: &'gpu device::Device <device::Bound >, - spec:Spec ,/// MMIO mapping of PCI BAR 0. bar:Bar0 <'gpu>, -/// System memory page required for flushing all pending GPU-side memory writes done through -/// PCIE into system memory, via sysmembar (A GPU-initiated HW memory-barrier operation). - sysmem_flush:SysmemFlush <'gpu>,/// GSP falcon instance, used for GSP boot up and cleanup. gsp_falcon:Falcon <GspFalcon >,/// SEC2 falcon instance, used for GSP boot up and cleanup. sec2_falcon:Falcon <Sec2Falcon >, -/// GSP runtime data. Temporarily an empty placeholder. +/// GSP runtime data. #[pin] gsp:Gsp ,/// GSP unload firmware bundle, if any. unload_bundle:Option <gsp::UnloadBundle >, }Quoted 14 lines
drivers/gpu/nova-core/gpu.rs fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { · line 289
Quoted 7 lines
drivers/gpu/nova-core/gpu.rs +7
-0+/// Structure holding the resources required to operate the GPU. +#[pin_data] +pub (crate )struct Gpu <'gpu> { + spec:Spec , +/// System memory page required for flushing all pending GPU-side memory writes done through +/// PCIE into system memory, via sysmembar (A GPU-initiated HW memory-barrier operation). + sysmem_flush:SysmemFlush <'gpu>,This means
sysmem_flushis dropped before unload is run. Before this patch, PinnedDrop runs the unload bundle before sysmem_flush's drop actually runs. But with this code it'll dropsysmem_flushfirst, and that isn't allowed according to the comment infb.rssaying that it's needed for falcon reset. What about sysmem flush into GspResources as well?
Quoted 4 lines
Yes, Sashiko also found the same issue actually. I will fix that by declaring
sysmem_flushaftergsp_resourcesinGpuso it is dropped after. Initialization is done in the given order bypin_init!, so we can still initializesysmem_flushbeforegsp_resources.
With that change,
Re: [PATCH 3/4] gpu: nova-core: gsp: Extract usable FB region from GSP
In reply to Gary GuoQuoted 5 lines · Gary Guo
Quoted 2 lines
Does it just essentially require a FB to be present? What would happen to GPUs without display support like RTX PRO 4500 Blackwell Server Edition?
Actually looks like FB in Nova just means "VRAM" and not actually "Framebuffer". Is this documented somewhere or am I just incapable of finding it?
For some reason, internally we tend to use the term "framebuffer" instead of "vram", so that leaks into our code.
Alexandre Courbot
maintainerRe: [PATCH 3/4] gpu: nova-core: gsp: Extract usable FB region from GSP
In reply to Eliot CourtneyQuoted 90 lines · Eliot Courtney
Quoted 89 lines · Alexandre Courbot
From: Joel Fernandes <[email protected]>
Add
usable_fb_regions_iter()to GspStaticConfigInfo to extract the first usable FB region from GSP's fbRegionInfoParams. Usable regions are those that are not reserved or protected.The extracted region is stored in GetGspStaticInfoReply and exposed as
usable_fb_regionfield for use by the memory subsystem.Signed-off-by Joel Fernandes <[email protected]>Reviewed-by John Hubbard <[email protected]>--- drivers/gpu/nova-core/gsp/commands.rs | 9 +++++-- drivers/gpu/nova-core/gsp/fw/commands.rs | 40 +++++++++++++++++++++++++++++++- 2 files changed, 46 insertions(+), 3 deletions(-)drivers/gpu/nova-core/gsp/commands.rs +7
-2@@ -5,6 +5,7 @@ array, convert::Infallible, ffi::FromBytesUntilNulError, + ops::Range, str::Utf8Error, // };@@ -191,15 +192,18 @@ fn init(&self) -> impl Init<Self::Command, Self::InitError> { } } -/// The reply from the GSP to the [`GetGspInfo`] command. +/// The reply from the GSP to the [`GetGspStaticInfo`] command. pub (crate )struct GetGspStaticInfoReply { gpu_name: [u8 ;64 ], +/// Usable FB (VRAM) region for driver memory allocation. +#[expect(dead_code)] +pub (crate ) usable_fb_region:Range <u64 >, }impl MessageFromGsp for GetGspStaticInfoReply {const FUNCTION :MsgFunction =MsgFunction ::GetGspStaticInfo ;type Message = fw::commands::GspStaticConfigInfo ; -type InitError =Infallible ; +type InitError =Error ;fn read ( msg: &Self::Message,@@ -207,6 +211,7 @@ fn read( ) -> Result<Self, Self::InitError> {Ok (GetGspStaticInfoReply { gpu_name: msg.gpu_name_str (), + usable_fb_region: msg.usable_fb_regions_iter ().next ().ok_or (ENODEV )?, }) } }drivers/gpu/nova-core/gsp/fw/commands.rs +9
-1@@ -1,6 +1,8 @@// SPDX-License-Identifier: GPL-2.0 // SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +use core::ops::Range ; +use kernel::{ device, pci,@@ -13,7 +15,8 @@use crate ::{ gpu::Chipset , - gsp::GSP_PAGE_SIZE ,// + gsp::GSP_PAGE_SIZE , + num::IntoSafeCast ,// };use super ::bindings;@@ -129,6 +132,41 @@ impl GspStaticConfigInfo {pub (crate )fn gpu_name_str (&self) -> [u8 ;64 ] { self.0 .gpuNameString } + +/// Returns an iterator over valid FB regions from GSP firmware data. +fn fb_regions ( + &self, + ) ->impl Iterator <Item = &bindings::NV2080_CTRL_CMD_FB_GET_FB_REGION_FB_REGION_INFO > {
Quoted 8 lines
drivers/gpu/nova-core/gsp/fw/commands.rs impl GspStaticConfigInfo { · line 145
Quoted 6 lines
drivers/gpu/nova-core/gsp/fw/commands.rs +6
-0+let fb_info = &self.0 .fbRegionInfoParams; + fb_info + .fbRegion + .iter () + .take (fb_info.numFBRegions.into_safe_cast ()) + .filter (|reg| reg.limit >= reg.base)Do you know if we actually get broken values like this (limit < base)?
No idea; but filtering for correctness sounds sensible (and is cheap to do).
Quoted 2 lines
Also we could print out the
usable_fb_regionas well, if you like?
Good idea, this also lets us remove a dead_code.
Alexandre Courbot
maintainerRe: [PATCH 3/4] gpu: nova-core: gsp: Extract usable FB region from GSP
In reply to Gary GuoQuoted 48 lines · Gary Guo
Quoted 47 lines · Alexandre Courbot
From: Joel Fernandes <[email protected]>
Add
usable_fb_regions_iter()to GspStaticConfigInfo to extract the first usable FB region from GSP's fbRegionInfoParams. Usable regions are those that are not reserved or protected.The extracted region is stored in GetGspStaticInfoReply and exposed as
usable_fb_regionfield for use by the memory subsystem.Signed-off-by Joel Fernandes <[email protected]>Reviewed-by John Hubbard <[email protected]>--- drivers/gpu/nova-core/gsp/commands.rs | 9 +++++-- drivers/gpu/nova-core/gsp/fw/commands.rs | 40 +++++++++++++++++++++++++++++++- 2 files changed, 46 insertions(+), 3 deletions(-)drivers/gpu/nova-core/gsp/commands.rs +6
-2@@ -5,6 +5,7 @@ array, convert::Infallible, ffi::FromBytesUntilNulError, + ops::Range, str::Utf8Error, // };@@ -191,15 +192,18 @@ fn init(&self) -> impl Init<Self::Command, Self::InitError> { } } -/// The reply from the GSP to the [`GetGspInfo`] command. +/// The reply from the GSP to the [`GetGspStaticInfo`] command. pub (crate )struct GetGspStaticInfoReply { gpu_name: [u8 ;64 ], +/// Usable FB (VRAM) region for driver memory allocation. +#[expect(dead_code)] +pub (crate ) usable_fb_region:Range <u64 >, }impl MessageFromGsp for GetGspStaticInfoReply {const FUNCTION :MsgFunction =MsgFunction ::GetGspStaticInfo ;type Message = fw::commands::GspStaticConfigInfo ; -type InitError =Infallible ; +type InitError =Error ;
Quoted 10 lines
drivers/gpu/nova-core/gsp/commands.rs fn read( · line 214
Quoted 7 lines
drivers/gpu/nova-core/gsp/commands.rs +1
-0fn read ( msg: &Self::Message,@@ -207,6 +211,7 @@ fn read( ) -> Result<Self, Self::InitError> { Ok(GetGspStaticInfoReply { gpu_name: msg.gpu_name_str(), + usable_fb_region: msg.usable_fb_regions_iter().next().ok_or(ENODEV)?,Does it just essentially require a FB to be present? What would happen to GPUs without display support like RTX PRO 4500 Blackwell Server Edition?
The naming is a bit unfortunate, but "FB" is generally accepted to be a synonym for "VRAM" in NV-speak. Nouveau also uses this terminology to it is not internal-only.
Quoted 3 lines
I feel that this check should be done by the user of
GetGspStaticInfoReply, the firmware doesn't reply with an error.
Indeed. Moving the check to the caller is difficult with the current code since GetGspStaticInfoReply requires one region to be built.
But maybe we can collect all the regions into a KVec. This will let the caller check that at least one is present, and also be more useful as we will want to see all valid regions in the future anyway.
It will also let the caller compute the total amount of VRAM, rather than having to store it in the message reply, despite that information not technically being part of the message.
Quoted 47 lines
Quoted 47 lines
drivers/gpu/nova-core/gsp/commands.rs +0
-0}) } }drivers/gpu/nova-core/gsp/fw/commands.rs +20
-1@@ -1,6 +1,8 @@// SPDX-License-Identifier: GPL-2.0 // SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +use core::ops::Range ; +use kernel::{ device, pci,@@ -13,7 +15,8 @@use crate ::{ gpu::Chipset , - gsp::GSP_PAGE_SIZE ,// + gsp::GSP_PAGE_SIZE , + num::IntoSafeCast ,// };use super ::bindings;@@ -129,6 +132,41 @@ impl GspStaticConfigInfo {pub (crate )fn gpu_name_str (&self) -> [u8 ;64 ] { self.0 .gpuNameString } + +/// Returns an iterator over valid FB regions from GSP firmware data. +fn fb_regions ( + &self, + ) ->impl Iterator <Item = &bindings::NV2080_CTRL_CMD_FB_GET_FB_REGION_FB_REGION_INFO > { +let fb_info = &self.0 .fbRegionInfoParams; + fb_info + .fbRegion + .iter () + .take (fb_info.numFBRegions.into_safe_cast ()) + .filter (|reg| reg.limit >= reg.base) + } + +/// Iterates over usable FB regions from GSP firmware data. +/// +/// Each yielded region is a [`Range<u64>`] suitable for driver memory allocation.
Quoted 8 lines
drivers/gpu/nova-core/gsp/fw/commands.rs impl GspStaticConfigInfo { · line 156
Quoted 6 lines
drivers/gpu/nova-core/gsp/fw/commands.rs +6
-0+/// Usable regions are those that satisfy all the following properties: +/// - Are not reserved for firmware internal use. +/// - Are not protected (hardware-enforced access restrictions). +/// - Support compression (can use GPU memory compression for bandwidth). +/// - Support ISO (isochronous memory for display requiring guaranteed bandwidth). +pub (crate )fn usable_fb_regions_iter (&self) ->impl Iterator <Item =Range <u64 >> + '_ {I think this is a bit too verbose.
usable_fb_regionsshould be okay.
Agreed.
Alexandre Courbot
maintainerRe: [PATCH 2/4] gpu: nova-core: move GPU static information acquisition to a GSP method
In reply to Gary GuoQuoted 42 lines · Gary Guo
Quoted 41 lines · Alexandre Courbot
The GSP static information is useful during regular driver runtime; however it is currently obtained from
Gsp::boot, with no elegant way to pass it back to the caller.Solve this by moving the code acquiring it to a dedicated method of
Gspthat can be called as soon as theGspis booted. This allows us to obtain and display the static information from theGpuconstructor, and to store the static information for later use.Its location at the end of
Gsp::bootwas a bit out-of-place anyway:
technically, the GSP is considered booted after we have received theGspInitDonemessage, so anything that happens afterwards is not part of the boot sequence anymore.Signed-off-by Alexandre Courbot <[email protected]>--- drivers/gpu/nova-core/gpu.rs | 16 ++++++++++++++++ drivers/gpu/nova-core/gsp.rs | 15 +++++++++++---- drivers/gpu/nova-core/gsp/boot.rs | 7 ------- 3 files changed, 27 insertions(+), 11 deletions(-)drivers/gpu/nova-core/gpu.rs +3
-0@@ -23,6 +23,7 @@ fb::SysmemFlush, gsp::{ self, + commands::GetGspStaticInfoReply, Gsp, // }, regs,@@ -290,6 +291,8 @@ pub(crate) struct Gpu<'gpu> {/// GSP and its resources. #[pin] gsp_resources: GspResources<'gpu>, +/// Static GPU information as provided by the GSP. + gsp_static_info: GetGspStaticInfoReply, }
Quoted 11 lines
drivers/gpu/nova-core/gpu.rs pub(crate) fn new( · line 362
Quoted 8 lines
drivers/gpu/nova-core/gpu.rs +3
-0#[pinned_drop] @@ -354,6 +357,19 @@ pub(crate) fn new(// is properly run in case of failure. unload_bundle: gsp.boot(pdev, bar, spec.chipset, gsp_falcon, sec2_falcon)?, }), + + gsp_static_info: { + let gsp = &gsp_resources.as_ref().get_ref().gsp;What's this
as_ref().get_ref()for? This could just be referenced as&gsp_resoruces.gsp? Or am I missing something?
It can - I am not quite sure how I arrived at the above construct honestly.