gpu: nova-core: obtain and display VRAM amount
Subsystems (5)
Alexandre Courbot
maintainerv3 cover 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.
This revision is just a rebase on top of the latest drm-rust-next, as the newly pushed patches introduced some non-trivial conflicts.
---
Changes in v3:
- Rebase against latest drm-rust-next.
- Link to v2: https://patch.msgid.link/[email protected]
Changes in v2:
- Move sysmem_flush after gsp_resources to avoid use-after-drop. (Eliot and Sashiko)
- Rename usable_fb_regions_iter to usable_fb_regions.
- Return all usable regions as a KVec.
- Let the caller compute the usable VRAM size instead of storing it as a GetGspStaticInfoReply property.
- Dropped Reviewed-by tags on patch 3 as code has changed considerably.
- Link to v1: https://patch.msgid.link/[email protected]
To: Danilo Krummrich <[email protected]>
To: Alice Ryhl <[email protected]>
To: Alexandre Courbot <[email protected]>
To: David Airlie <[email protected]>
To: Simona Vetter <[email protected]>
To: Benno Lossin <[email protected]>
To: Gary Guo <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
---
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 (1):
gpu: nova-core: gsp: Extract and display usable FB regions from GSP
drivers/gpu/nova-core/gpu.rs | 136 +++++++++++++++++++++---------- drivers/gpu/nova-core/gsp.rs | 14 +++- drivers/gpu/nova-core/gsp/boot.rs | 7 -- drivers/gpu/nova-core/gsp/commands.rs | 13 ++- drivers/gpu/nova-core/gsp/fw/commands.rs | 40 ++++++++- 5 files changed, 151 insertions(+), 59 deletions(-)
---
base-commit: e655873885063245fd7f49f81cebfdfdef66a59d
change-id: 20260609-boot-vram-00d5057102d5
Best regards,
Signature · 1 line
Alexandre Courbot <[email protected]>
Alexandre Courbot
maintainerPATCH v3 1/3 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 | 104 +++++++++++++++++++++++++------------------ 1 file changed, 60 insertions(+), 44 deletions(-)
drivers/gpu/nova-core/gpu.rs +60 -44
@@ -263,35 +263,62 @@ 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 , +/// GSP and its resources. +#[pin] + gsp_resources:GspResources <'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). +/// +/// Must be kept declared *after* `gsp_resources`, as the latter's `PinnedDrop` implementation +/// requires the sysmem flush page to be in place. + sysmem_flush:SysmemFlush <'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); })?,
@@ -309,46 +336,35 @@ pub(crate) fn new( .inspect_err(|_| dev_err!(pdev, "GFW boot did not complete\n"))?; }, +// Initialize this early because `gsp_resources` depends on it. 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)?, - - gsp <- Gsp::new(pdev), - -// 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(GspBootContext { - pdev, bar, - chipset: spec.chipset, - gsp_falcon, - sec2_falcon, - })?, - bar, + + gsp_falcon:Falcon ::new ( + pdev.as_ref (), + spec.chipset, + ) + .inspect (|falcon| falcon.clear_swgen0_intr (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 (GspBootContext { + pdev, + bar, + chipset: 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 v3 2/3 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 | 14 ++++++++++++++ drivers/gpu/nova-core/gsp.rs | 14 ++++++++++---- drivers/gpu/nova-core/gsp/boot.rs | 7 ------- 3 files changed, 24 insertions(+), 11 deletions(-)
drivers/gpu/nova-core/gpu.rs +14 -0
@@ -23,6 +23,7 @@ fb::SysmemFlush, gsp::{ self, + commands::GetGspStaticInfoReply,Gsp ,GspBootContext ,// },
@@ -285,6 +286,8 @@ struct GspResources<'gpu> {#[pin_data] pub (crate )struct Gpu <'gpu> { spec:Spec , +/// Static GPU information as provided by the GSP. + gsp_static_info:GetGspStaticInfoReply ,/// GSP and its resources. #[pin] gsp_resources:GspResources <'gpu>,
@@ -365,6 +368,17 @@ pub(crate) fn new( sec2_falcon, })?, }), + + gsp_static_info: { + // Obtain and display basic GPU information. + let info = gsp_resources.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 +10 -4
@@ -39,10 +39,12 @@ Falcon, // }, gpu::Chipset, - gsp::cmdq::Cmdq, - gsp::fw::{ - GspArgumentsPadded, - LibosMemoryRegionInitArgument, // + gsp::{ + cmdq::Cmdq, + fw::{ +GspArgumentsPadded , +LibosMemoryRegionInitArgument ,// + }, }, num, };
@@ -208,6 +210,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
@@ -142,13 +142,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 v3 3/3 gpu: nova-core: gsp: Extract and display usable FB regions from GSP
In reply to Alexandre CourbotFrom: Joel Fernandes <[email protected]>
Add usable_fb_regions() to GspStaticConfigInfo to extract the usable FB regions from GSP's fbRegionInfoParams. Usable regions are those that are not reserved or protected.
The extracted regions are stored in GetGspStaticInfoReply and exposed for use by the memory subsystem.
Display the regions and their total size upon device probe.
[acourbot: expose all regions as a KVec, display usable regions and total usable VRAM.]
--- drivers/gpu/nova-core/gpu.rs | 18 +++++++++++++- drivers/gpu/nova-core/gsp/commands.rs | 13 +++++++++-- drivers/gpu/nova-core/gsp/fw/commands.rs | 40 +++++++++++++++++++++++++++++++- 3 files changed, 67 insertions(+), 4 deletions(-)
drivers/gpu/nova-core/gpu.rs +17 -1
@@ -9,7 +9,8 @@ io::Io, num::Bounded, pci, - prelude::*, // + prelude::*, + sizes::SizeConstants, // };use crate ::{
@@ -377,6 +378,21 @@ pub(crate) fn new( Err(e) => dev_warn!(pdev, "GPU name unavailable: {:?}\n", e), } +if !info.usable_fb_regions.is_empty () { +dev_info! (pdev,"Usable FB regions:\n" ); +for regionin &info.usable_fb_regions { +dev_info! (pdev," - {:#x?}\n" , region); + } + +dev_info! ( + pdev, +"Total usable VRAM: {} MiB\n" , + info.usable_fb_regions.iter ().fold (0u64 , |res, region| res + .saturating_add (region.end - region.start)) + /u64 ::SZ_1M + ); + } + info } })
drivers/gpu/nova-core/gsp/commands.rs +11 -2
@@ -5,6 +5,7 @@ array, convert::Infallible, ffi::FromBytesUntilNulError, + ops::Range, str::Utf8Error, // };
@@ -191,22 +192,30 @@ 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) regions for driver memory allocation. +pub (crate ) usable_fb_regions:KVec <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 , _sbuffer: &mut SBufferIter <array::IntoIter <&[u8 ],2 >>, ) ->Result <Self ,Self ::InitError > { +let mut usable_fb_regions =KVec ::new (); +for regionin msg.usable_fb_regions () { + usable_fb_regions.push (region,GFP_KERNEL )?; + } +Ok (GetGspStaticInfoReply { gpu_name: msg.gpu_name_str (), + usable_fb_regions, }) } }
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 (&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
maintainerQuoted 2 lines · Alexandre Courbot
gpu: nova-core: move GSP unload state to a pinned Gpu subobject
gpu: nova-core: move GPU static information acquisition to a GSP method
These two pushed to drm-rust-next, thanks!
Quoted 1 line
gpu: nova-core: gsp: Extract and display usable FB regions from GSP
Waiting for a review tag to push this one as well, since it has changed a bit.
Danilo Krummrich
maintainerRe: [PATCH v3 3/3] gpu: nova-core: gsp: Extract and display usable FB regions from GSP
In reply to Alexandre CourbotQuoted 8 lines · Alexandre Courbot
drivers/gpu/nova-core/gpu.rs +4
-0@@ -377,6 +378,21 @@ pub(crate) fn new( Err(e) => dev_warn!(pdev, "GPU name unavailable: {:?}\n", e), } +if !info.usable_fb_regions.is_empty () { +dev_info! (pdev,"Usable FB regions:\n" ); +for regionin &info.usable_fb_regions { +dev_info! (pdev," - {:#x?}\n" , region);
drivers/gpu/nova-core/gpu.rs pub(crate) fn new( · line 394
Quoted 10 lines
drivers/gpu/nova-core/gpu.rs +10
-0+ } + +dev_info! ( + pdev, +"Total usable VRAM: {} MiB\n" , + info.usable_fb_regions.iter ().fold (0u64 , |res, region| res + .saturating_add (region.end - region.start)) + /u64 ::SZ_1M + ); + }
Drivers should generally remain silent when they work properly, some exceptions are fine, but this seems too verbose. Let's use dev_dbg!() instead.
Also, would it make sense to (rather) warn in the else case? (I think OpenRM treats this as error, although the check in OpenRM checks whether there are no regions at all.)
Alexandre Courbot
maintainerRe: [PATCH v3 3/3] gpu: nova-core: gsp: Extract and display usable FB regions from GSP
Quoted 14 lines · Danilo Krummrich
Quoted 13 lines · Alexandre Courbot
drivers/gpu/nova-core/gpu.rs +9
-0@@ -377,6 +378,21 @@ pub(crate) fn new( Err(e) => dev_warn!(pdev, "GPU name unavailable: {:?}\n", e), } +if !info.usable_fb_regions.is_empty () { +dev_info! (pdev,"Usable FB regions:\n" ); +for regionin &info.usable_fb_regions { +dev_info! (pdev," - {:#x?}\n" , region); + } + +dev_info! ( + pdev, +"Total usable VRAM: {} MiB\n" ,
Quoted 8 lines
drivers/gpu/nova-core/gpu.rs pub(crate) fn new( · line 394
Quoted 5 lines
drivers/gpu/nova-core/gpu.rs +5
-0+ info.usable_fb_regions.iter ().fold (0u64 , |res, region| res + .saturating_add (region.end - region.start)) + / u64::SZ_1M + ); + }Drivers should generally remain silent when they work properly, some exceptions are fine, but this seems too verbose. Let's use dev_dbg!() instead.
Right, it seemed useful for the time being to display some information since that's all the driver is currently able to do, but I'll change it to dev_dbg!.
Quoted 4 lines
Also, would it make sense to (rather) warn in the else case? (I think OpenRM treats this as error, although the check in OpenRM checks whether there are no regions at all.)
I expect that the users of the VRAM regions (i.e. the MM subsystem) will not be able to contruct properly if no region is detected, and that sounds like the right place to raise an error rather than making an assumption here that no VRAM region is an error. For instance, I am not sure what the regions layout will be on Tegra systems, although your comment about OpenRM seems to hint that there are regions defined for them as well.
Danilo Krummrich
maintainerRe: [PATCH v3 3/3] gpu: nova-core: gsp: Extract and display usable FB regions from GSP
Quoted 6 lines · Alexandre Courbot
I expect that the users of the VRAM regions (i.e. the MM subsystem) will not be able to contruct properly if no region is detected, and that sounds like the right place to raise an error rather than making an assumption here that no VRAM region is an error. For instance, I am not sure what the regions layout will be on Tegra systems, although your comment about OpenRM seems to hint that there are regions defined for them as well.
Well, the question is whether it would just be an assumption that no VRAM region is an error. I'm not entirely sure, but I think it generally is an error. If that's confirmed I'd rather fail early and with a clear message, and not carry on with something we already know won't work out.
Alexandre Courbot
maintainerRe: [PATCH v3 3/3] gpu: nova-core: gsp: Extract and display usable FB regions from GSP
Quoted 8 lines · Danilo Krummrich
Quoted 6 lines · Alexandre Courbot
I expect that the users of the VRAM regions (i.e. the MM subsystem) will not be able to contruct properly if no region is detected, and that sounds like the right place to raise an error rather than making an assumption here that no VRAM region is an error. For instance, I am not sure what the regions layout will be on Tegra systems, although your comment about OpenRM seems to hint that there are regions defined for them as well.
Quoted 4 lines
Well, the question is whether it would just be an assumption that no VRAM region is an error. I'm not entirely sure, but I think it generally is an error. If that's confirmed I'd rather fail early and with a clear message, and not carry on with something we already know won't work out.
I took a deeper look at OpenRM. The zero FB region error is emitted when mirroring the list of FB regions [1], which is a default HAL method. Zero-VRAM chips like Tegra replace it with an empty stub.
So gpu.rs doesn't look like the right place to do that check imho - especially since the list we are checking against is the list of *usable* regions, whereas OpenRM checks the full list. The current code is just getting the list from the GSP - the code that does something meaningful with it doesn't exist yet, and it is that code that should error if there are no FB regions at all.
Re: [PATCH v3 3/3] gpu: nova-core: gsp: Extract and display usable FB regions from GSP
In reply to Alexandre CourbotQuoted 9 lines · Alexandre Courbot
From: Joel Fernandes <[email protected]>
Add
usable_fb_regions()to GspStaticConfigInfo to extract the usable FB regions from GSP's fbRegionInfoParams. Usable regions are those that are not reserved or protected.The extracted regions are stored in GetGspStaticInfoReply and exposed for use by the memory subsystem.
Quoted 7 lines
Display the regions and their total size upon device probe.
Signed-off-by Joel Fernandes <[email protected]>[acourbot: expose all regions as a KVec, display usable regions and total usable VRAM.]
Signed-off-by Alexandre Courbot <[email protected]>---
Re: [PATCH v3 3/3] gpu: nova-core: gsp: Extract and display usable FB regions from GSP
In reply to Alexandre CourbotQuoted 3 lines · Alexandre Courbot
I took a deeper look at OpenRM. The zero FB region error is emitted when mirroring the list of FB regions [1], which is a default HAL method. Zero-VRAM chips like Tegra replace it with an empty stub.
Thanks for checking! With the dev_info!() logs fixed,
Re: [PATCH v3 3/3] gpu: nova-core: gsp: Extract and display usable FB regions from GSP
In reply to Alexandre CourbotQuoted 9 lines · Alexandre Courbot
From: Joel Fernandes <[email protected]>
Add
usable_fb_regions()to GspStaticConfigInfo to extract the usable FB regions from GSP's fbRegionInfoParams. Usable regions are those that are not reserved or protected.The extracted regions are stored in GetGspStaticInfoReply and exposed for use by the memory subsystem.
Quoted 6 lines
Display the regions and their total size upon device probe.
Signed-off-by Joel Fernandes <[email protected]>[acourbot: expose all regions as a KVec, display usable regions and total usable VRAM.]
Signed-off-by Alexandre Courbot <[email protected]>
Pushed to drm-rust-next, thanks for the reviews!
[acourbot: replace dev_info!() with dev_dbg!().]