[PATCH v3 5/7] drm: nova: Add GETPARAM parameter to read usable VRAM size
From: Alistair Popple
Date: Thu Jul 23 2026 - 02:37:08 EST
Add a parameter to the existing GETPARAM ioctl to return the total
usable framebuffer size. The usable framebuffer excludes GSP carveouts
and other protected regions so may differ in size from BAR size and
total physical VRAM.
Signed-off-by: Alistair Popple <apopple@xxxxxxxxxx>
---
Changes since v2:
- Commit wording
Changes since v1:
- Fix rustfmt
---
drivers/gpu/drm/nova/file.rs | 1 +
drivers/gpu/nova-core/api.rs | 5 +++++
drivers/gpu/nova-core/gpu.rs | 6 ++----
drivers/gpu/nova-core/gsp/commands.rs | 8 ++++++++
include/uapi/drm/nova_drm.h | 7 +++++++
5 files changed, 23 insertions(+), 4 deletions(-)
diff --git a/drivers/gpu/drm/nova/file.rs b/drivers/gpu/drm/nova/file.rs
index 855f23877734..8c02be4f15bf 100644
--- a/drivers/gpu/drm/nova/file.rs
+++ b/drivers/gpu/drm/nova/file.rs
@@ -44,6 +44,7 @@ pub(crate) fn get_param(
let value = match getparam.param as u32 {
uapi::NOVA_GETPARAM_VRAM_BAR_SIZE => pdev.resource_len(1)?,
uapi::NOVA_GETPARAM_GPU_CHIPID => reg_data.api.chipset() as u64,
+ uapi::NOVA_GETPARAM_VRAM_SIZE => reg_data.api.vram_size(),
_ => return Err(EINVAL),
};
diff --git a/drivers/gpu/nova-core/api.rs b/drivers/gpu/nova-core/api.rs
index 09da0b4e9103..f025df90dc5d 100644
--- a/drivers/gpu/nova-core/api.rs
+++ b/drivers/gpu/nova-core/api.rs
@@ -33,4 +33,9 @@ pub fn of(adev: &auxiliary::Device<Bound>) -> Result<Pin<&NovaCoreApi<'_>>> {
pub fn chipset(&self) -> Chipset {
self.gpu.spec.chipset
}
+
+ /// Returns the total usable VRAM size of this GPU in bytes.
+ pub fn vram_size(&self) -> u64 {
+ self.gpu.gsp_static_info.vram_size()
+ }
}
diff --git a/drivers/gpu/nova-core/gpu.rs b/drivers/gpu/nova-core/gpu.rs
index 264fe4e65b3f..6581c91a0b78 100644
--- a/drivers/gpu/nova-core/gpu.rs
+++ b/drivers/gpu/nova-core/gpu.rs
@@ -283,7 +283,7 @@ struct GspResources<'gpu> {
pub(crate) struct Gpu<'gpu> {
pub(crate) spec: Spec,
/// Static GPU information as provided by the GSP.
- gsp_static_info: GetGspStaticInfoReply,
+ pub(crate) gsp_static_info: GetGspStaticInfoReply,
/// GSP and its resources.
#[pin]
gsp_resources: GspResources<'gpu>,
@@ -400,9 +400,7 @@ pub(crate) fn new(
dev_dbg!(
dev,
"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.vram_size() / u64::SZ_1M
);
}
diff --git a/drivers/gpu/nova-core/gsp/commands.rs b/drivers/gpu/nova-core/gsp/commands.rs
index 08380de39048..49ff3f5edcec 100644
--- a/drivers/gpu/nova-core/gsp/commands.rs
+++ b/drivers/gpu/nova-core/gsp/commands.rs
@@ -252,6 +252,14 @@ pub(crate) fn gpu_name(&self) -> core::result::Result<&str, GpuNameError> {
.to_str()
.map_err(GpuNameError::InvalidUtf8)
}
+
+ /// Returns the total usable VRAM size in bytes, i.e. the summed lengths of all usable FB
+ /// regions.
+ pub(crate) fn vram_size(&self) -> u64 {
+ self.usable_fb_regions.iter().fold(0, |size, region| {
+ size.saturating_add(region.end - region.start)
+ })
+ }
}
pub(crate) use fw::commands::PowerStateLevel;
diff --git a/include/uapi/drm/nova_drm.h b/include/uapi/drm/nova_drm.h
index c655302a40fd..0f9f4ffa5b90 100644
--- a/include/uapi/drm/nova_drm.h
+++ b/include/uapi/drm/nova_drm.h
@@ -32,6 +32,13 @@ extern "C" {
*/
#define NOVA_GETPARAM_GPU_CHIPID 0x2
+/*
+ * NOVA_GETPARAM_VRAM_SIZE
+ *
+ * Query the total usable VRAM size in bytes.
+ */
+#define NOVA_GETPARAM_VRAM_SIZE 0x3
+
enum drm_nova_chipid {
/* Turing */
NOVA_DRM_CHIPID_TU102 = 0x162,
--
2.54.0