[PATCH v3 28/33] gpu: nova-core: gsp: make the GSP_INIT reply the static configuration
From: John Hubbard
Date: Thu Sep 17 2026 - 21:34:28 EST
The boot sequence returns the static GPU configuration, the GPU's name,
its usable framebuffer regions and its BAR1 page directory base, to the
rest of the driver. On r000 that configuration is the decoded GSP_INIT
reply.
The configuration type came from the r570 boot protocol, where the
reader of the r570 static-info reply filled it from a C struct. The
GSP_INIT decoder filled the same type by copying the name and the
usable regions out of the decoded reply. The decoder failed the boot
with EINVAL when the reply reported no framebuffer region. With the
r570 reader gone, that copy was the type's only purpose.
Make the decoded reply the static configuration type, and read the
configuration through its accessors. The accessor for the usable
regions yields an iterator, so the regions are no longer copied into a
vector. A reply that reports no framebuffer region now fails with
ENODEV when the driver creates its memory manager.
Assisted-by: LLM
Signed-off-by: John Hubbard <jhubbard@xxxxxxxxxx>
---
drivers/gpu/nova-core/gpu.rs | 16 +++---
drivers/gpu/nova-core/gsp/commands.rs | 70 ++----------------------
drivers/gpu/nova-core/gsp/fw/commands.rs | 41 +++++++++++---
drivers/gpu/nova-core/mm.rs | 4 +-
4 files changed, 48 insertions(+), 83 deletions(-)
diff --git a/drivers/gpu/nova-core/gpu.rs b/drivers/gpu/nova-core/gpu.rs
index 0ed0f4722dc5..fd1a74913d7c 100644
--- a/drivers/gpu/nova-core/gpu.rs
+++ b/drivers/gpu/nova-core/gpu.rs
@@ -465,16 +465,16 @@ pub(crate) fn new<'a>(
Err(e) => dev_warn!(dev, "GPU name unavailable: {:?}\n", e),
}
- if !info.usable_fb_regions.is_empty() {
+ if info.usable_fb_regions().next().is_some() {
dev_dbg!(dev, "Usable FB regions:\n");
- for region in &info.usable_fb_regions {
+ for region in info.usable_fb_regions() {
dev_dbg!(dev, " - {:#x?}\n", region);
}
dev_dbg!(
dev,
"Total usable VRAM: {} MiB\n",
- info.usable_fb_regions.iter().fold(0u64, |res, region| res
+ info.usable_fb_regions().fold(0u64, |res, region| res
.saturating_add(region.end - region.start))
/ u64::SZ_1M
);
@@ -484,7 +484,7 @@ pub(crate) fn new<'a>(
// Create GPU memory manager owning memory management resources.
mm: {
let info = gsp_resources.static_info();
- let usable_vram = info.usable_fb_regions.first().ok_or(ENODEV)?;
+ let usable_vram = info.usable_fb_regions().next().ok_or(ENODEV)?;
let buddy_params = GpuBuddyParams {
base_offset: usable_vram.start,
size: usable_vram.end - usable_vram.start,
@@ -495,13 +495,13 @@ pub(crate) fn new<'a>(
bar,
gsp_resources.spec.chipset,
buddy_params,
- VramAddress::from_raw(info.total_fb_end),
+ VramAddress::from_raw(info.total_fb_end().ok_or(ENODEV)?),
)?
},
// Create BAR1 user interface for CPU access to GPU virtual memory.
bar_user: {
- let pdb_addr = VramAddress::from_raw(gsp_resources.static_info().bar1_pde_base);
+ let pdb_addr = VramAddress::from_raw(gsp_resources.static_info().bar1_pde_base());
let bar1_idx = crate::driver::bar1_resource_index(pdev)?;
let bar1_size = pdev.resource_len(bar1_idx)?;
Arc::pin_init(
@@ -527,9 +527,9 @@ pub(crate) fn run_selftests(self: Pin<&mut Self>, pdev: &pci::Device<device::Bou
if let Err(err) = crate::mm::selftest::run(
dev,
this.mm,
- &info.usable_fb_regions,
+ info.usable_fb_regions(),
this.bar_user,
- info.bar1_pde_base,
+ info.bar1_pde_base(),
this.spec.chipset,
) {
dev_err!(dev, "self-tests failed: {:?}\n", err);
diff --git a/drivers/gpu/nova-core/gsp/commands.rs b/drivers/gpu/nova-core/gsp/commands.rs
index 24f80c449c13..128d6f8dcb43 100644
--- a/drivers/gpu/nova-core/gsp/commands.rs
+++ b/drivers/gpu/nova-core/gsp/commands.rs
@@ -1,12 +1,6 @@
// SPDX-License-Identifier: GPL-2.0
// SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
-use core::{
- ffi::FromBytesUntilNulError,
- ops::Range,
- str::Utf8Error, //
-};
-
use kernel::{
device,
pci,
@@ -22,7 +16,6 @@
self,
commands::{
GspInitRequest,
- GspInitResponse,
GspInitResponseSchema, //
},
GspGmcMsgElement,
@@ -41,40 +34,7 @@
vgpu::VgpuState, //
};
-/// The static GPU configuration, as decoded from the `GSP_INIT` reply.
-pub(crate) struct GspStaticInfo {
- gpu_name: [u8; 64],
- /// BAR1 Page Directory Entry base address.
- pub(crate) bar1_pde_base: u64,
- /// Usable FB (VRAM) regions for driver memory allocation.
- pub(crate) usable_fb_regions: KVec<Range<u64>>,
- /// Exclusive end of the FB physical address space.
- pub(crate) total_fb_end: u64,
-}
-
-/// Error type for [`GspStaticInfo::gpu_name`].
-#[derive(Debug)]
-pub(crate) enum GpuNameError {
- /// The GPU name string does not contain a null terminator.
- NoNullTerminator(FromBytesUntilNulError),
-
- /// The GPU name string contains invalid UTF-8.
- #[expect(dead_code)]
- InvalidUtf8(Utf8Error),
-}
-
-impl GspStaticInfo {
- /// Returns the name of the GPU as a string.
- ///
- /// Returns an error if the string given by the GSP does not contain a null terminator or
- /// contains invalid UTF-8.
- pub(crate) fn gpu_name(&self) -> core::result::Result<&str, GpuNameError> {
- CStr::from_bytes_until_nul(&self.gpu_name)
- .map_err(GpuNameError::NoNullTerminator)?
- .to_str()
- .map_err(GpuNameError::InvalidUtf8)
- }
-}
+pub(crate) use fw::commands::GspStaticInfo;
/// Builds the NVKV-encoded payload of a `GSP_INIT` request for `pdev`.
///
@@ -128,13 +88,12 @@ pub(crate) fn gsp_init(
)
}
-/// Decodes the `GSP_INIT` reply from its payload, which the ring may have split in two, into the
-/// static configuration type that the boot sequence returns.
+/// Decodes the `GSP_INIT` reply from its payload, which the ring may have split in two.
///
/// # Errors
///
-/// - `EINVAL` if the payload is not a whole number of NVKV words, if the stream is malformed or
-/// omits a required key, or if GSP-RM reported no framebuffer region.
+/// - `EINVAL` if the payload is not a whole number of NVKV words, or if the stream is malformed
+/// or omits a required key.
/// - `ENOMEM` if the words or the decoded regions cannot be allocated.
fn decode_gsp_init_reply(payload_0: &[u8], payload_1: &[u8]) -> Result<GspStaticInfo> {
const WORD_SIZE: usize = size_of::<u64>();
@@ -154,26 +113,9 @@ fn decode_gsp_init_reply(payload_0: &[u8], payload_1: &[u8]) -> Result<GspStatic
let decoder = Decoder::new(&words, UnknownKeyPolicy::Ignore);
let mut schema = GspInitResponseSchema::default();
- let decoded = KBox::try_init(decoder.decode(&mut schema)?, GFP_KERNEL)?;
-
- let mut gpu_name = [0u8; GspInitResponse::MAX_GPU_NAME_LEN];
- let name = decoded.gpu_name();
- gpu_name
- .get_mut(..name.len())
- .ok_or(EINVAL)?
- .copy_from_slice(name);
-
- let mut usable_fb_regions = KVec::new();
- for region in decoded.usable_fb_regions() {
- usable_fb_regions.push(region, GFP_KERNEL)?;
- }
+ let info = KBox::try_init(decoder.decode(&mut schema)?, GFP_KERNEL)?;
- Ok(GspStaticInfo {
- gpu_name,
- bar1_pde_base: decoded.bar1_pde_base(),
- usable_fb_regions,
- total_fb_end: decoded.total_fb_end().ok_or(EINVAL)?,
- })
+ Ok(KBox::into_inner(info))
}
pub(crate) use fw::commands::PowerStateLevel;
diff --git a/drivers/gpu/nova-core/gsp/fw/commands.rs b/drivers/gpu/nova-core/gsp/fw/commands.rs
index 9792cea36770..60edbb12627f 100644
--- a/drivers/gpu/nova-core/gsp/fw/commands.rs
+++ b/drivers/gpu/nova-core/gsp/fw/commands.rs
@@ -1,7 +1,11 @@
// SPDX-License-Identifier: GPL-2.0
// SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
-use core::ops::Range;
+use core::{
+ ffi::FromBytesUntilNulError,
+ ops::Range,
+ str::Utf8Error, //
+};
use kernel::{
alloc::ArrayVec,
@@ -288,9 +292,9 @@ pub(crate) fn new(
// Should decode with UnknownKeyPolicy::Ignore.
nvkv_decode! {
/// Schema for the `GSP_INIT` response.
- pub(crate) struct GspInitResponseSchema => GspInitResponse {
+ pub(crate) struct GspInitResponseSchema => GspStaticInfo {
gpu_name:
- Array<u8, { GspInitResponse::MAX_GPU_NAME_LEN }, { Self::GPU_NAME_STRING_KEY }>,
+ Array<u8, { GspStaticInfo::MAX_GPU_NAME_LEN }, { Self::GPU_NAME_STRING_KEY }>,
fb_regions: Accumulated<FbRegionSchema>,
bar1_pde_base: Required<u64, { Self::BAR1_PDE_BASE_KEY }>,
vmmu_segment_size: Key<u64, { Self::VMMU_SEGMENT_SIZE_KEY }>,
@@ -304,8 +308,8 @@ impl GspInitResponseSchema {
const VMMU_SEGMENT_SIZE_KEY: KeyId = 0x1050;
}
-/// Payload of the `GSP_INIT` response.
-pub(crate) struct GspInitResponse {
+/// The static GPU configuration, as decoded from the `GSP_INIT` reply.
+pub(crate) struct GspStaticInfo {
gpu_name: ArrayVec<u8, { Self::MAX_GPU_NAME_LEN }>,
fb_regions: KVVec<FbRegion>,
bar1_pde_base: u64,
@@ -313,16 +317,35 @@ pub(crate) struct GspInitResponse {
vmmu_segment_size: u64,
}
-impl GspInitResponse {
+/// Error type for [`GspStaticInfo::gpu_name`].
+#[derive(Debug)]
+pub(crate) enum GpuNameError {
+ /// The GPU name string does not contain a NUL terminator.
+ NoNullTerminator(FromBytesUntilNulError),
+
+ /// The GPU name string contains invalid UTF-8.
+ #[expect(dead_code)]
+ InvalidUtf8(Utf8Error),
+}
+
+impl GspStaticInfo {
pub(crate) const MAX_GPU_NAME_LEN: usize = 64;
/// Tag of a general-purpose region. Any other tag marks a region that GSP-RM reserves for the
/// use that the tag names.
const FB_REGION_TAG_NONE: u32 = 0;
- /// Returns the GPU name, which GSP-RM sends with its NUL terminator.
- pub(crate) fn gpu_name(&self) -> &[u8] {
- self.gpu_name.as_slice()
+ /// Returns the name of the GPU as a string.
+ ///
+ /// # Errors
+ ///
+ /// - [`GpuNameError::NoNullTerminator`] if the name that GSP-RM sent has no NUL terminator.
+ /// - [`GpuNameError::InvalidUtf8`] if the name is not valid UTF-8.
+ pub(crate) fn gpu_name(&self) -> core::result::Result<&str, GpuNameError> {
+ CStr::from_bytes_until_nul(self.gpu_name.as_slice())
+ .map_err(GpuNameError::NoNullTerminator)?
+ .to_str()
+ .map_err(GpuNameError::InvalidUtf8)
}
/// Returns an iterator over the FB regions from which the driver may allocate: the
diff --git a/drivers/gpu/nova-core/mm.rs b/drivers/gpu/nova-core/mm.rs
index a5bc4042577b..ea85c821f0e2 100644
--- a/drivers/gpu/nova-core/mm.rs
+++ b/drivers/gpu/nova-core/mm.rs
@@ -308,7 +308,7 @@ pub(crate) mod selftest {
pub(crate) fn run(
dev: &device::Device<device::Bound>,
mm: &mut GpuMm<'_>,
- usable_fb_regions: &[Range<u64>],
+ mut usable_fb_regions: impl Iterator<Item = Range<u64>>,
bar_user: &Arc<bar_user::BarUser<'_>>,
bar1_pdb: u64,
chipset: Chipset,
@@ -316,7 +316,7 @@ pub(crate) fn run(
// VRAM span the self-tests are free to overwrite, from the chosen test base.
const SELFTEST_SPAN: u64 = u64::SZ_64M;
- let base = usable_fb_regions.iter().find_map(|region| {
+ let base = usable_fb_regions.find_map(|region| {
// Tests rely on this being 8 byte aligned for checking misalignment handling.
let base = region.start.align_up(Alignment::new::<8>())?;
(base.checked_add(SELFTEST_SPAN)? <= region.end).then_some(base)
--
2.55.0