* [PATCH v2 0/3] gpu: nova-core: obtain and display VRAM amount
@ 2026-06-17 6:43 Alexandre Courbot
2026-06-17 6:43 ` [PATCH v2 1/3] gpu: nova-core: move GSP unload state to a pinned Gpu subobject Alexandre Courbot
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Alexandre Courbot @ 2026-06-17 6:43 UTC (permalink / raw)
To: Danilo Krummrich, Alice Ryhl, David Airlie, Simona Vetter,
Benno Lossin, Gary Guo
Cc: nova-gpu, dri-devel, linux-kernel, rust-for-linux,
Alexandre Courbot, Eliot Courtney, Joel Fernandes
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.
Signed-off-by: Alexandre Courbot <acourbot@nvidia.com>
---
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/20260609-boot-vram-v1-0-d9382610507a@nvidia.com
To: Danilo Krummrich <dakr@kernel.org>
To: Alice Ryhl <aliceryhl@google.com>
To: Alexandre Courbot <acourbot@nvidia.com>
To: David Airlie <airlied@gmail.com>
To: Simona Vetter <simona@ffwll.ch>
To: Benno Lossin <lossin@kernel.org>
To: Gary Guo <gary@garyguo.net>
Cc: nova-gpu@lists.linux.dev
Cc: dri-devel@lists.freedesktop.org
Cc: linux-kernel@vger.kernel.org
Cc: rust-for-linux@vger.kernel.org
---
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 | 122 +++++++++++++++++++++----------
drivers/gpu/nova-core/gsp.rs | 15 +++-
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, 145 insertions(+), 52 deletions(-)
---
base-commit: 5f7410aa26524101d34b627fbe16670b1514962c
change-id: 20260609-boot-vram-00d5057102d5
Best regards,
--
Alexandre Courbot <acourbot@nvidia.com>
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH v2 1/3] gpu: nova-core: move GSP unload state to a pinned Gpu subobject
2026-06-17 6:43 [PATCH v2 0/3] gpu: nova-core: obtain and display VRAM amount Alexandre Courbot
@ 2026-06-17 6:43 ` Alexandre Courbot
2026-06-17 6:43 ` [PATCH v2 2/3] gpu: nova-core: move GPU static information acquisition to a GSP method Alexandre Courbot
2026-06-17 6:43 ` [PATCH v2 3/3] gpu: nova-core: gsp: Extract and display usable FB regions from GSP Alexandre Courbot
2 siblings, 0 replies; 4+ messages in thread
From: Alexandre Courbot @ 2026-06-17 6:43 UTC (permalink / raw)
To: Danilo Krummrich, Alice Ryhl, David Airlie, Simona Vetter,
Benno Lossin, Gary Guo
Cc: nova-gpu, dri-devel, linux-kernel, rust-for-linux,
Alexandre Courbot, Eliot Courtney
`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.
Signed-off-by: Alexandre Courbot <acourbot@nvidia.com>
Reviewed-by: Eliot Courtney <ecourtney@nvidia.com>
---
drivers/gpu/nova-core/gpu.rs | 90 ++++++++++++++++++++++++++------------------
1 file changed, 53 insertions(+), 37 deletions(-)
diff --git a/drivers/gpu/nova-core/gpu.rs b/drivers/gpu/nova-core/gpu.rs
index b3c91731db45..b5cffcee9817 100644
--- a/drivers/gpu/nova-core/gpu.rs
+++ b/drivers/gpu/nova-core/gpu.rs
@@ -262,35 +262,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);
})?,
@@ -308,40 +335,29 @@ 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)?,
+ 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));
- }
-}
--
2.54.0
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH v2 2/3] gpu: nova-core: move GPU static information acquisition to a GSP method
2026-06-17 6:43 [PATCH v2 0/3] gpu: nova-core: obtain and display VRAM amount Alexandre Courbot
2026-06-17 6:43 ` [PATCH v2 1/3] gpu: nova-core: move GSP unload state to a pinned Gpu subobject Alexandre Courbot
@ 2026-06-17 6:43 ` Alexandre Courbot
2026-06-17 6:43 ` [PATCH v2 3/3] gpu: nova-core: gsp: Extract and display usable FB regions from GSP Alexandre Courbot
2 siblings, 0 replies; 4+ messages in thread
From: Alexandre Courbot @ 2026-06-17 6:43 UTC (permalink / raw)
To: Danilo Krummrich, Alice Ryhl, David Airlie, Simona Vetter,
Benno Lossin, Gary Guo
Cc: nova-gpu, dri-devel, linux-kernel, rust-for-linux,
Alexandre Courbot, Eliot Courtney
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
`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.
Signed-off-by: Alexandre Courbot <acourbot@nvidia.com>
Reviewed-by: Eliot Courtney <ecourtney@nvidia.com>
---
drivers/gpu/nova-core/gpu.rs | 14 ++++++++++++++
drivers/gpu/nova-core/gsp.rs | 15 +++++++++++----
drivers/gpu/nova-core/gsp/boot.rs | 7 -------
3 files changed, 25 insertions(+), 11 deletions(-)
diff --git a/drivers/gpu/nova-core/gpu.rs b/drivers/gpu/nova-core/gpu.rs
index b5cffcee9817..a02a86f556e7 100644
--- a/drivers/gpu/nova-core/gpu.rs
+++ b/drivers/gpu/nova-core/gpu.rs
@@ -23,6 +23,7 @@
fb::SysmemFlush,
gsp::{
self,
+ commands::GetGspStaticInfoReply,
Gsp, //
},
regs,
@@ -284,6 +285,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>,
@@ -358,6 +361,17 @@ 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: {
+ // 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
+ }
})
}
}
diff --git a/drivers/gpu/nova-core/gsp.rs b/drivers/gpu/nova-core/gsp.rs
index 385b4c09582b..9ba4e0063159 100644
--- a/drivers/gpu/nova-core/gsp.rs
+++ b/drivers/gpu/nova-core/gsp.rs
@@ -32,10 +32,13 @@
};
use crate::{
- gsp::cmdq::Cmdq,
- gsp::fw::{
- GspArgumentsPadded,
- LibosMemoryRegionInitArgument, //
+ driver::Bar0,
+ gsp::{
+ cmdq::Cmdq,
+ fw::{
+ GspArgumentsPadded,
+ LibosMemoryRegionInitArgument, //
+ },
},
num,
};
@@ -186,6 +189,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`].
diff --git a/drivers/gpu/nova-core/gsp/boot.rs b/drivers/gpu/nova-core/gsp/boot.rs
index 8afb62d689cb..2eef4d1b058d 100644
--- a/drivers/gpu/nova-core/gsp/boot.rs
+++ b/drivers/gpu/nova-core/gsp/boot.rs
@@ -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())
}
--
2.54.0
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH v2 3/3] gpu: nova-core: gsp: Extract and display usable FB regions from GSP
2026-06-17 6:43 [PATCH v2 0/3] gpu: nova-core: obtain and display VRAM amount Alexandre Courbot
2026-06-17 6:43 ` [PATCH v2 1/3] gpu: nova-core: move GSP unload state to a pinned Gpu subobject Alexandre Courbot
2026-06-17 6:43 ` [PATCH v2 2/3] gpu: nova-core: move GPU static information acquisition to a GSP method Alexandre Courbot
@ 2026-06-17 6:43 ` Alexandre Courbot
2 siblings, 0 replies; 4+ messages in thread
From: Alexandre Courbot @ 2026-06-17 6:43 UTC (permalink / raw)
To: Danilo Krummrich, Alice Ryhl, David Airlie, Simona Vetter,
Benno Lossin, Gary Guo
Cc: nova-gpu, dri-devel, linux-kernel, rust-for-linux,
Alexandre Courbot, Joel Fernandes
From: Joel Fernandes <joelagnelf@nvidia.com>
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.
Signed-off-by: Joel Fernandes <joelagnelf@nvidia.com>
[acourbot: expose all regions as a KVec, display usable regions and
total usable VRAM.]
Signed-off-by: Alexandre Courbot <acourbot@nvidia.com>
---
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(-)
diff --git a/drivers/gpu/nova-core/gpu.rs b/drivers/gpu/nova-core/gpu.rs
index a02a86f556e7..075821f371f7 100644
--- a/drivers/gpu/nova-core/gpu.rs
+++ b/drivers/gpu/nova-core/gpu.rs
@@ -9,7 +9,8 @@
io::Io,
num::Bounded,
pci,
- prelude::*, //
+ prelude::*,
+ sizes::SizeConstants, //
};
use crate::{
@@ -370,6 +371,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 region in &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
}
})
diff --git a/drivers/gpu/nova-core/gsp/commands.rs b/drivers/gpu/nova-core/gsp/commands.rs
index f84de9f4f045..86a3747cd31c 100644
--- a/drivers/gpu/nova-core/gsp/commands.rs
+++ b/drivers/gpu/nova-core/gsp/commands.rs
@@ -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 region in msg.usable_fb_regions() {
+ usable_fb_regions.push(region, GFP_KERNEL)?;
+ }
+
Ok(GetGspStaticInfoReply {
gpu_name: msg.gpu_name_str(),
+ usable_fb_regions,
})
}
}
diff --git a/drivers/gpu/nova-core/gsp/fw/commands.rs b/drivers/gpu/nova-core/gsp/fw/commands.rs
index 7bcc41fc7fa0..ebdc12bcd4e3 100644
--- a/drivers/gpu/nova-core/gsp/fw/commands.rs
+++ b/drivers/gpu/nova-core/gsp/fw/commands.rs
@@ -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.
--
2.54.0
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-06-17 6:43 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-06-17 6:43 [PATCH v2 0/3] gpu: nova-core: obtain and display VRAM amount Alexandre Courbot
2026-06-17 6:43 ` [PATCH v2 1/3] gpu: nova-core: move GSP unload state to a pinned Gpu subobject Alexandre Courbot
2026-06-17 6:43 ` [PATCH v2 2/3] gpu: nova-core: move GPU static information acquisition to a GSP method Alexandre Courbot
2026-06-17 6:43 ` [PATCH v2 3/3] gpu: nova-core: gsp: Extract and display usable FB regions from GSP Alexandre Courbot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®