mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v2 00/11] gpu: nova-core: gsp: preparatory patches for the r000 firmware
@ 2026-11-29 15:10 Alexandre Courbot
  2026-11-29 15:11 ` [PATCH v2 01/11] gpu: nova-core: gsp: add the r000 queue element header Alexandre Courbot
                   ` (10 more replies)
  0 siblings, 11 replies; 12+ messages in thread
From: Alexandre Courbot @ 2026-11-29 15:10 UTC (permalink / raw)
  To: Danilo Krummrich, Alice Ryhl, David Airlie, Simona Vetter
  Cc: John Hubbard, Alistair Popple, Timur Tabi, Eliot Courtney,
	Zhi Wang, nova-gpu, dri-devel, linux-kernel, Alexandre Courbot

These patches come from John's series switching nova-core to the r000
GSP firmware [1]. They do not depend on the switch itself, and both the
rest of the r000 work and the vGPU series build on them, so I would
like to get them in soon.

Patch 1 adds the r000 queue element header. It has no user yet and was
previously posted on its own [2].

Patches 2 and 3 make the static GPU configuration something the boot
sequence returns, since that is where r000 provides it. Patch 4 adds
the GPU short name and GID to the schema of the GSP_INIT reply, which
is not used yet either.

Patches 5 to 7 prepare the log buffers code for the extra buffers of
r000, without functional change.

Patches 8 to 10 tidy the command queue constants and make the msgq TX
header take its values from the queue layout, without functional
change.

Patch 11 moves the loading of the file referenced by a TLV into the TLV
parser, so the r000 ucodes loader can use it.

There are two runtime changes: patch 3 queries the static configuration
at the end of the boot sequence instead of after it, and patch 11 fails
with ENODATA if the size given by the TLV is zero.

The patches were reworked since v3 (patch 2 also moves the type,
patches 4, 8 and 10 are new, patches 5 to 7 are a split of the log
buffers patch), so Timur's Reviewed-by on v3 is not carried.

Based on drm-rust-next.

[1] https://lore.kernel.org/20260918010719.1176945-1-jhubbard@nvidia.com
[2] https://lore.kernel.org/20261117-msgelement-v1-1-b918ffae5e7b@nvidia.com

Signed-off-by: Alexandre Courbot <acourbot@nvidia.com>
---
Changes in v2:
- Use an anonymous const for the queue element header checks. (Gary)
- Import offset_of for the queue element header checks. (Gary)
- Derive the zerocopy traits on the queue element header. (Gary)
- Add patches 5 to 11 (log buffers, msgq TX header, TLV loading).
- Use the defined constants in more places on patch 4.
- Link to v1: https://patch.msgid.link/20261127-nova-r000-staging-v1-0-4eaf6e3c0942@nvidia.com

---
Alexandre Courbot (2):
      gpu: nova-core: gsp: cmdq: reduce visibility of gsp-level constants
      gpu: nova-core: gsp: take all the msgq layout values from Cmdq in MsgqTxHeader::new()

John Hubbard (9):
      gpu: nova-core: gsp: add the r000 queue element header
      gpu: nova-core: gsp: rename and move the static configuration type
      gpu: nova-core: gsp: return the static GPU configuration from boot
      gpu: nova-core: gsp: add the short name and GID to the GSP_INIT reply
      gpu: nova-core: gsp: logbuffer: add LogBuffers::init_arguments()
      gpu: nova-core: gsp: logbuffer: make LogBuffer generic over its size
      gpu: nova-core: gsp: logbuffer: add RetainedLogBuffers::is_empty()
      gpu: nova-core: gsp: compute the msgq entry offset in MsgqTxHeader::new()
      gpu: nova-core: firmware: tlv: add method to load the file referenced by a TLV

 drivers/gpu/nova-core/api.rs                     |   8 +-
 drivers/gpu/nova-core/firmware/gsp.rs            |  15 +-
 drivers/gpu/nova-core/firmware/tlv.rs            |  40 ++++-
 drivers/gpu/nova-core/gpu.rs                     |  36 ++--
 drivers/gpu/nova-core/gsp.rs                     |  27 ++-
 drivers/gpu/nova-core/gsp/boot.rs                |  15 +-
 drivers/gpu/nova-core/gsp/cmdq.rs                |  27 +--
 drivers/gpu/nova-core/gsp/commands.rs            |  70 ++++++++
 drivers/gpu/nova-core/gsp/commands/rpc.rs        |  68 +-------
 drivers/gpu/nova-core/gsp/fw.rs                  | 210 +++++++++++++++++++++--
 drivers/gpu/nova-core/gsp/fw/commands.rs         |  23 +--
 drivers/gpu/nova-core/gsp/fw/r000_00/bindings.rs |  97 +++++++++++
 drivers/gpu/nova-core/gsp/logbuffer.rs           |  78 +++++++--
 drivers/gpu/nova-core/mctp.rs                    |  27 ++-
 14 files changed, 566 insertions(+), 175 deletions(-)
---
base-commit: abfb640b2374e26de8ff81d488c39d8254db538e
change-id: 20261127-nova-r000-staging-905c7f559e47

Best regards,
--  
Alexandre Courbot <acourbot@nvidia.com>


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH v2 01/11] gpu: nova-core: gsp: add the r000 queue element header
  2026-11-29 15:10 [PATCH v2 00/11] gpu: nova-core: gsp: preparatory patches for the r000 firmware Alexandre Courbot
@ 2026-11-29 15:11 ` Alexandre Courbot
  2026-11-29 15:11 ` [PATCH v2 02/11] gpu: nova-core: gsp: rename and move the static configuration type Alexandre Courbot
                   ` (9 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: Alexandre Courbot @ 2026-11-29 15:11 UTC (permalink / raw)
  To: Danilo Krummrich, Alice Ryhl, David Airlie, Simona Vetter
  Cc: John Hubbard, Alistair Popple, Timur Tabi, Eliot Courtney,
	Zhi Wang, nova-gpu, dri-devel, linux-kernel, Alexandre Courbot

From: John Hubbard <jhubbard@nvidia.com>

The upcoming r000 firmware uses a new queue element header that includes
MCTP and NVDM headers describing the type of message (RPC or GMC) that
follows.

Add that header as the `QueueElementHeader` type, along with the two
NVDM types that the GSP queues use and the MCTP version and NVDM vendor
checks that validating it requires.

The type is written out field by field rather than wrapped around the
generated binding, as `GSP_MSG_QUEUE_ELEMENT` keeps a 16-byte encryption
tag, only used with confidential computing, in a union with its last two
fields, making the binding 16 bytes larger than what the GSP expects on
the queues. Static assertions check every field offset and the size of
the type against the binding.

The header has no user yet: it replaces `GspMsgElement` at the transport
level in a later patch that switches to the r000 firmware, and is built
as dead code until then.

Signed-off-by: John Hubbard <jhubbard@nvidia.com>
Co-developed-by: Alexandre Courbot <acourbot@nvidia.com>
Signed-off-by: Alexandre Courbot <acourbot@nvidia.com>
---
 drivers/gpu/nova-core/gsp/fw.rs                  | 183 ++++++++++++++++++++++-
 drivers/gpu/nova-core/gsp/fw/r000_00/bindings.rs |  97 ++++++++++++
 drivers/gpu/nova-core/mctp.rs                    |  27 +++-
 3 files changed, 304 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/nova-core/gsp/fw.rs b/drivers/gpu/nova-core/gsp/fw.rs
index 5c216d777dff..937cbbc24e93 100644
--- a/drivers/gpu/nova-core/gsp/fw.rs
+++ b/drivers/gpu/nova-core/gsp/fw.rs
@@ -33,6 +33,11 @@
     },
 };
 
+use zerocopy_derive::{
+    Immutable,
+    KnownLayout, //
+};
+
 use crate::{
     bounded_enum,
     fb::{
@@ -48,6 +53,11 @@
         cmdq::Cmdq, //
         GSP_PAGE_SIZE,
     },
+    mctp::{
+        MctpHeader,
+        NvdmHeader,
+        NvdmType, //
+    },
     num::{
         self,
         FromSafeCast, //
@@ -835,7 +845,7 @@ pub(crate) fn msg_length(&self) -> usize {
         size_of::<Self>() + self.rpc_header().rpc_length()
     }
 
-    /// Returns the number of elements (i.e. memory pages) used by this message.
+    /// Returns the number of slots (i.e. memory pages) used by this message.
     pub(crate) fn element_count(&self) -> u32 {
         self.inner.elemCount
     }
@@ -901,6 +911,177 @@ pub(crate) fn function(&self) -> Result<MsgFunction, u32> {
     }
 }
 
+/// First word of every r000 queue element: `"MCTP"` in ASCII.
+const MCTP_MAGIC: u32 = 0x4D43_5450;
+
+/// Header opening every element of the r000 GSP queues.
+///
+/// A queue element is laid out as follows:
+///
+/// ```text
+///     +------------------------------------+
+///     | Queue element header               |  QueueElementHeader: MCTP magic, element length,
+///     |                                    |  MCTP header, NVDM header, message length.
+///     +------------------------------------+
+///     | Message header                     |  RPC header or GMC API header. The NVDM type
+///     |                                    |  selects between the two.
+///     +------------------------------------+
+///     | Payload                            |  Message-specific data.
+///     +------------------------------------+
+/// ```
+///
+/// This is the `noEncryption` layout of the `GSP_MSG_QUEUE_ELEMENT` binding. That binding keeps
+/// a 16-byte encryption tag, used only with confidential computing, in a union with the two
+/// trailing fields of the queue element header, so wrapping the binding would make every element
+/// 16 bytes larger than what the GSP expects. The fields are therefore declared again here, with
+/// their offsets checked against the binding.
+#[repr(C)]
+#[derive(FromBytes, IntoBytes, Immutable, KnownLayout)]
+pub(crate) struct QueueElementHeader {
+    /// Always [`MCTP_MAGIC`].
+    mctp_magic: u32,
+    /// Length in bytes of the whole element, this header included.
+    ///
+    /// Under confidential computing the GSP pads elements out to whole queue slots, so this can
+    /// be larger than `nvdm_payload_size` plus the size of this header, but never smaller.
+    mctp_payload_size: u32,
+    /// MCTP transport header of the element.
+    mctp_header: MctpHeader,
+    /// NVDM header of the message.
+    nvdm_header: NvdmHeader,
+    /// Length in bytes of the message following this header: the message header and its
+    /// payload.
+    nvdm_payload_size: u32,
+    reserved: u32,
+}
+
+// Static validation of `QueueElementHeader` against its bindings type.
+const _: () = {
+    use core::mem::offset_of;
+
+    // Offsets of `QueueElementHeader`'s fields
+
+    static_assert!(
+        offset_of!(QueueElementHeader, mctp_magic)
+            == offset_of!(r000_00::GSP_MSG_QUEUE_ELEMENT, mctpMagic)
+    );
+    static_assert!(
+        offset_of!(QueueElementHeader, mctp_payload_size)
+            == offset_of!(r000_00::GSP_MSG_QUEUE_ELEMENT, mctpPayloadSize)
+    );
+    static_assert!(
+        offset_of!(QueueElementHeader, mctp_header)
+            == offset_of!(r000_00::GSP_MSG_QUEUE_ELEMENT, mctpHeader)
+    );
+    static_assert!(
+        offset_of!(QueueElementHeader, nvdm_header)
+            == offset_of!(r000_00::GSP_MSG_QUEUE_ELEMENT, nvdmHeader)
+    );
+
+    /// The `noEncryption` member of the union of `GSP_MSG_QUEUE_ELEMENT`, which holds the two
+    /// trailing fields of [`QueueElementHeader`].
+    // Using `allow` instead of `expect` as rustc 1.85 ignores uses from `static_assert!` and
+    // reports this as dead code.
+    #[allow(dead_code)]
+    type QueueElementNoEncryption = r000_00::GSP_MSG_QUEUE_ELEMENT__bindgen_ty_1__bindgen_ty_2;
+
+    // Offsets of fields under [`QueueElementNoEncryption`] within `GSP_MSG_QUEUE_ELEMENT`.
+
+    // Using `allow` instead of `expect` as rustc 1.85 ignores uses from `static_assert!` and
+    // reports this as dead code.
+    #[allow(dead_code)]
+    const QUEUE_ELEMENT_NO_ENCRYPTION_OFFSET: usize =
+        offset_of!(r000_00::GSP_MSG_QUEUE_ELEMENT, __bindgen_anon_1)
+            + offset_of!(r000_00::GSP_MSG_QUEUE_ELEMENT__bindgen_ty_1, noEncryption);
+
+    static_assert!(
+        offset_of!(QueueElementHeader, nvdm_payload_size)
+            == QUEUE_ELEMENT_NO_ENCRYPTION_OFFSET
+                + offset_of!(QueueElementNoEncryption, nvdmPayloadSize)
+    );
+    static_assert!(
+        offset_of!(QueueElementHeader, reserved)
+            == QUEUE_ELEMENT_NO_ENCRYPTION_OFFSET + offset_of!(QueueElementNoEncryption, reserved)
+    );
+
+    // Ensure the size of `QueueElementHeader` matches the `noEncryption` layout.
+
+    static_assert!(
+        size_of::<QueueElementHeader>()
+            == QUEUE_ELEMENT_NO_ENCRYPTION_OFFSET + size_of::<QueueElementNoEncryption>()
+    );
+};
+
+#[expect(dead_code)]
+impl QueueElementHeader {
+    /// Creates the queue element header of an element carrying a message of NVDM type `nvdm_type`
+    /// and `message_len` bytes, message header included.
+    ///
+    /// # Errors
+    ///
+    /// - `EOVERFLOW` if a length does not fit its 32-bit field.
+    pub(crate) fn init(nvdm_type: NvdmType, message_len: usize) -> impl Init<Self, Error> {
+        try_init!(QueueElementHeader {
+            mctp_magic: MCTP_MAGIC,
+            mctp_payload_size: size_of::<Self>()
+                .checked_add(message_len)
+                .ok_or(EOVERFLOW)?
+                .try_into()
+                .map_err(|_| EOVERFLOW)?,
+            mctp_header: MctpHeader::single_packet(),
+            nvdm_header: NvdmHeader::new(nvdm_type),
+            nvdm_payload_size: message_len.try_into().map_err(|_| EOVERFLOW)?,
+            reserved: 0,
+        })
+    }
+
+    /// Returns the length of the whole element, this header included.
+    pub(crate) fn element_len(&self) -> usize {
+        num::u32_as_usize(self.mctp_payload_size)
+    }
+
+    /// Returns the length of the message following this header, message header included.
+    pub(crate) fn message_len(&self) -> usize {
+        num::u32_as_usize(self.nvdm_payload_size)
+    }
+
+    /// Returns the number of slots (i.e. memory pages) used by this element.
+    pub(crate) fn element_count(&self) -> u32 {
+        self.mctp_payload_size.div_ceil(cv!(GSP_PAGE_SIZE))
+    }
+
+    /// Returns the NVDM type of the message following this header, or `EINVAL` if it is not a
+    /// known one.
+    pub(crate) fn nvdm_type(&self) -> Result<NvdmType> {
+        self.nvdm_header.nvdm_type()
+    }
+
+    /// Validates the framing of the element.
+    ///
+    /// # Errors
+    ///
+    /// - `EIO` if the magic, the MCTP version or the NVDM vendor is wrong, or if the element
+    ///   length is smaller than this header and the message together, or larger than the
+    ///   maximum element size.
+    pub(crate) fn validate(&self) -> Result {
+        if self.mctp_magic != MCTP_MAGIC
+            || !self.mctp_header.has_expected_version()
+            || !self.nvdm_header.has_nvidia_vendor()
+        {
+            return Err(EIO);
+        }
+
+        let element_len = self.element_len();
+        if element_len < size_of::<Self>().saturating_add(self.message_len())
+            || element_len > GSP_MSG_QUEUE_ELEMENT_SIZE_MAX
+        {
+            return Err(EIO);
+        }
+
+        Ok(())
+    }
+}
+
 bounded_enum! {
     /// Commands of the GMC API.
     #[derive(Debug, Clone, Copy, PartialEq, Eq)]
diff --git a/drivers/gpu/nova-core/gsp/fw/r000_00/bindings.rs b/drivers/gpu/nova-core/gsp/fw/r000_00/bindings.rs
index 552299c98169..959e397c26aa 100644
--- a/drivers/gpu/nova-core/gsp/fw/r000_00/bindings.rs
+++ b/drivers/gpu/nova-core/gsp/fw/r000_00/bindings.rs
@@ -30,6 +30,49 @@ fn fmt(&self, fmt: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
         fmt.write_str("__IncompleteArrayField")
     }
 }
+#[repr(C)]
+pub struct __BindgenUnionField<T>(::core::marker::PhantomData<T>);
+impl<T> __BindgenUnionField<T> {
+    #[inline]
+    pub const fn new() -> Self {
+        __BindgenUnionField(::core::marker::PhantomData)
+    }
+    #[inline]
+    pub unsafe fn as_ref(&self) -> &T {
+        ::core::mem::transmute(self)
+    }
+    #[inline]
+    pub unsafe fn as_mut(&mut self) -> &mut T {
+        ::core::mem::transmute(self)
+    }
+}
+impl<T> ::core::default::Default for __BindgenUnionField<T> {
+    #[inline]
+    fn default() -> Self {
+        Self::new()
+    }
+}
+impl<T> ::core::clone::Clone for __BindgenUnionField<T> {
+    #[inline]
+    fn clone(&self) -> Self {
+        *self
+    }
+}
+impl<T> ::core::marker::Copy for __BindgenUnionField<T> {}
+impl<T> ::core::fmt::Debug for __BindgenUnionField<T> {
+    fn fmt(&self, fmt: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
+        fmt.write_str("__BindgenUnionField")
+    }
+}
+impl<T> ::core::hash::Hash for __BindgenUnionField<T> {
+    fn hash<H: ::core::hash::Hasher>(&self, _state: &mut H) {}
+}
+impl<T> ::core::cmp::PartialEq for __BindgenUnionField<T> {
+    fn eq(&self, _other: &__BindgenUnionField<T>) -> bool {
+        true
+    }
+}
+impl<T> ::core::cmp::Eq for __BindgenUnionField<T> {}
 pub type __u8 = ffi::c_uchar;
 pub type __u16 = ffi::c_ushort;
 pub type __u32 = ffi::c_uint;
@@ -39,6 +82,60 @@ fn fmt(&self, fmt: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
 pub type u32_ = __u32;
 pub type u64_ = __u64;
 #[repr(C)]
+#[derive(Debug, Default, Copy, Clone, MaybeZeroable)]
+pub struct GSP_MSG_QUEUE_ENCRYPTION_TAG {
+    pub authTagBuffer: [u8_; 16usize],
+}
+#[repr(C)]
+#[derive(MaybeZeroable)]
+pub struct GSP_MSG_QUEUE_ELEMENT {
+    pub mctpMagic: u32_,
+    pub mctpPayloadSize: u32_,
+    pub mctpHeader: u32_,
+    pub nvdmHeader: u32_,
+    pub __bindgen_anon_1: GSP_MSG_QUEUE_ELEMENT__bindgen_ty_1,
+}
+#[repr(C)]
+#[derive(MaybeZeroable)]
+pub struct GSP_MSG_QUEUE_ELEMENT__bindgen_ty_1 {
+    pub withEncryption: __BindgenUnionField<GSP_MSG_QUEUE_ELEMENT__bindgen_ty_1__bindgen_ty_1>,
+    pub noEncryption: __BindgenUnionField<GSP_MSG_QUEUE_ELEMENT__bindgen_ty_1__bindgen_ty_2>,
+    pub bindgen_union_field: [u32; 6usize],
+}
+#[repr(C)]
+#[derive(Debug, Default, MaybeZeroable)]
+pub struct GSP_MSG_QUEUE_ELEMENT__bindgen_ty_1__bindgen_ty_1 {
+    pub encryptionTag: GSP_MSG_QUEUE_ENCRYPTION_TAG,
+    pub nvdmPayloadSize: u32_,
+    pub reserved: u32_,
+    pub payload: __IncompleteArrayField<u8_>,
+}
+#[repr(C)]
+#[derive(Debug, Default, MaybeZeroable)]
+pub struct GSP_MSG_QUEUE_ELEMENT__bindgen_ty_1__bindgen_ty_2 {
+    pub nvdmPayloadSize: u32_,
+    pub reserved: u32_,
+    pub payload: __IncompleteArrayField<u8_>,
+}
+impl Default for GSP_MSG_QUEUE_ELEMENT__bindgen_ty_1 {
+    fn default() -> Self {
+        let mut s = ::core::mem::MaybeUninit::<Self>::uninit();
+        unsafe {
+            ::core::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
+            s.assume_init()
+        }
+    }
+}
+impl Default for GSP_MSG_QUEUE_ELEMENT {
+    fn default() -> Self {
+        let mut s = ::core::mem::MaybeUninit::<Self>::uninit();
+        unsafe {
+            ::core::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
+            s.assume_init()
+        }
+    }
+}
+#[repr(C)]
 #[derive(MaybeZeroable)]
 pub struct GMCAPI_HEADER {
     pub command: u32_,
diff --git a/drivers/gpu/nova-core/mctp.rs b/drivers/gpu/nova-core/mctp.rs
index f62e79f56b05..2058303dfbb9 100644
--- a/drivers/gpu/nova-core/mctp.rs
+++ b/drivers/gpu/nova-core/mctp.rs
@@ -13,6 +13,11 @@
     prelude::*, //
 };
 
+use zerocopy_derive::{
+    Immutable,
+    KnownLayout, //
+};
+
 use crate::{
     bounded_enum,
     num, //
@@ -28,11 +33,16 @@ pub(crate) enum NvdmType with TryFrom<Bounded<u32, 8>> {
         Cot = 0x14,
         /// FSP command response.
         FspResponse = 0x15,
+        /// RPC message to or from GSP-RM.
+        RmRpc = 0x25,
+        /// GMC (GPU Management Controller) API message to or from GSP-RM.
+        GmcApi = 0x26,
     }
 }
 
 bitfield! {
     /// MCTP transport header for NVIDIA firmware messages.
+    #[derive(FromBytes, IntoBytes, Immutable, KnownLayout)]
     pub(crate) struct MctpHeader(u32) {
         /// Start-of-message bit.
         31:31 som;
@@ -67,6 +77,11 @@ pub(crate) fn single_packet() -> Self {
     pub(crate) fn is_single_packet(self) -> bool {
         self.som().into_bool() && self.eom().into_bool()
     }
+
+    /// Returns `true` if this MCTP header carries the version that this driver uses.
+    pub(crate) fn has_expected_version(self) -> bool {
+        u32::from(self.version()) == Self::VERSION
+    }
 }
 
 /// MCTP message type for PCI vendor-defined messages.
@@ -74,6 +89,7 @@ pub(crate) fn is_single_packet(self) -> bool {
 
 bitfield! {
     /// NVIDIA Vendor-Defined Message header over MCTP.
+    #[derive(FromBytes, IntoBytes, Immutable, KnownLayout)]
     pub(crate) struct NvdmHeader(u32) {
         /// NVDM message type.
         31:24 nvdm_type ?=> NvdmType;
@@ -93,10 +109,17 @@ pub(crate) fn new(nvdm_type: NvdmType) -> Self {
             .with_nvdm_type(nvdm_type)
     }
 
-    /// Validates this header against the expected NVIDIA NVDM format and type.
-    pub(crate) fn validate(self, expected_type: NvdmType) -> bool {
+    /// Returns `true` if this NVDM header belongs to a PCI vendor-defined message from NVIDIA.
+    ///
+    /// The GPU firmware only ever sends such messages, so a mismatch is a sign of corruption.
+    pub(crate) fn has_nvidia_vendor(self) -> bool {
         u8::from(self.msg_type()) == MSG_TYPE_VENDOR_PCI
             && u16::from(self.vendor_id()) == Vendor::NVIDIA.as_raw()
+    }
+
+    /// Validates this header against the expected NVIDIA NVDM format and type.
+    pub(crate) fn validate(self, expected_type: NvdmType) -> bool {
+        self.has_nvidia_vendor()
             && matches!(self.nvdm_type(), Ok(nvdm_type) if nvdm_type == expected_type)
     }
 }

-- 
2.56.1


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH v2 02/11] gpu: nova-core: gsp: rename and move the static configuration type
  2026-11-29 15:10 [PATCH v2 00/11] gpu: nova-core: gsp: preparatory patches for the r000 firmware Alexandre Courbot
  2026-11-29 15:11 ` [PATCH v2 01/11] gpu: nova-core: gsp: add the r000 queue element header Alexandre Courbot
@ 2026-11-29 15:11 ` Alexandre Courbot
  2026-11-29 15:11 ` [PATCH v2 03/11] gpu: nova-core: gsp: return the static GPU configuration from boot Alexandre Courbot
                   ` (8 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: Alexandre Courbot @ 2026-11-29 15:11 UTC (permalink / raw)
  To: Danilo Krummrich, Alice Ryhl, David Airlie, Simona Vetter
  Cc: John Hubbard, Alistair Popple, Timur Tabi, Eliot Courtney,
	Zhi Wang, nova-gpu, dri-devel, linux-kernel, Alexandre Courbot

From: John Hubbard <jhubbard@nvidia.com>

With the r000 firmware, GSP-RM reports the static GPU configuration in
its reply to GSP_INIT, a GMC command, and no RPC command fetches it.

The type that holds the configuration is named after the r570 RPC
command that fetches it, and it is defined among the RPC commands.

In order to make the type available to a GMC reply, name it after its
contents, and move it out of the RPC commands, up into the commands
module.

No functional changes.

Signed-off-by: John Hubbard <jhubbard@nvidia.com>
Signed-off-by: Alexandre Courbot <acourbot@nvidia.com>
---
 drivers/gpu/nova-core/api.rs              |  6 +--
 drivers/gpu/nova-core/gpu.rs              |  4 +-
 drivers/gpu/nova-core/gsp.rs              |  2 +-
 drivers/gpu/nova-core/gsp/commands.rs     | 65 +++++++++++++++++++++++++++++
 drivers/gpu/nova-core/gsp/commands/rpc.rs | 68 +++----------------------------
 5 files changed, 76 insertions(+), 69 deletions(-)

diff --git a/drivers/gpu/nova-core/api.rs b/drivers/gpu/nova-core/api.rs
index dc877ddebe8c..f800ba6c4183 100644
--- a/drivers/gpu/nova-core/api.rs
+++ b/drivers/gpu/nova-core/api.rs
@@ -18,7 +18,7 @@
 use crate::{
     driver,
     gpu::Gpu,
-    gsp::commands::rpc::GetGspStaticInfoReply, //
+    gsp::commands::GspStaticInfo, //
 };
 
 /// API handle for the auxiliary bus child drivers to interact with nova-core.
@@ -39,8 +39,8 @@ pub fn of(adev: &auxiliary::Device<Bound>) -> Result<NovaCoreApiHandle<'_>> {
         NovaCoreApiHandle::of(adev)
     }
 
-    /// Returns the GPU [`GetGspStaticInfoReply`].
-    pub fn gsp_static_info(&self) -> &GetGspStaticInfoReply {
+    /// Returns the GPU [`GspStaticInfo`].
+    pub fn gsp_static_info(&self) -> &GspStaticInfo {
         &self.gpu.gsp_static_info
     }
 
diff --git a/drivers/gpu/nova-core/gpu.rs b/drivers/gpu/nova-core/gpu.rs
index 8ab1687847ff..590d81f4e479 100644
--- a/drivers/gpu/nova-core/gpu.rs
+++ b/drivers/gpu/nova-core/gpu.rs
@@ -32,7 +32,7 @@
     gsp::{
         self,
         cmdq::Cmdq,
-        commands::rpc::GetGspStaticInfoReply,
+        commands::GspStaticInfo,
         Gsp,
         GspBootContext, //
     },
@@ -394,7 +394,7 @@ pub(crate) struct Gpu<'gpu> {
     #[uses('tree)]
     _gsp_subtree: GspSubtree<'gsp_resources>,
     /// Static GPU information as provided by the GSP.
-    pub(crate) gsp_static_info: GetGspStaticInfoReply,
+    pub(crate) gsp_static_info: GspStaticInfo,
     /// GPU memory manager owning memory management resources.
     ///
     /// Must be kept declared *before* `gsp_resources`, so that its components are dropped while
diff --git a/drivers/gpu/nova-core/gsp.rs b/drivers/gpu/nova-core/gsp.rs
index 2f1cdf8b7bec..398d6525b133 100644
--- a/drivers/gpu/nova-core/gsp.rs
+++ b/drivers/gpu/nova-core/gsp.rs
@@ -159,7 +159,7 @@ pub(crate) fn new(
     }
 
     /// Query the GSP for the static GPU information.
-    pub(crate) fn get_static_info(&self) -> Result<commands::rpc::GetGspStaticInfoReply> {
+    pub(crate) fn get_static_info(&self) -> Result<commands::GspStaticInfo> {
         self.cmdq.send_rpc_command(commands::rpc::GetGspStaticInfo)
     }
 }
diff --git a/drivers/gpu/nova-core/gsp/commands.rs b/drivers/gpu/nova-core/gsp/commands.rs
index 5f1c944678be..4aae94b7ca2e 100644
--- a/drivers/gpu/nova-core/gsp/commands.rs
+++ b/drivers/gpu/nova-core/gsp/commands.rs
@@ -2,3 +2,68 @@
 // SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
 
 pub(crate) mod rpc;
+
+use core::{
+    ffi::FromBytesUntilNulError,
+    ops::Range,
+    str::Utf8Error, //
+};
+
+use kernel::prelude::*;
+
+/// The static GPU configuration, which GSP-RM reports in reply to
+/// [`GetGspStaticInfo`](rpc::GetGspStaticInfo).
+pub struct GspStaticInfo {
+    gpu_name: [u8; 64],
+    gpu_short_name: [u8; 64],
+    /// The 16-byte SHA-1 based GPU identifier (GID) reported by GSP-RM.
+    pub gpu_gid: [u8; 16],
+    /// 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 enum GpuNameError {
+    /// The GPU name string does not contain a null terminator.
+    NoNullTerminator(FromBytesUntilNulError),
+
+    /// The GPU name string contains invalid UTF-8.
+    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 fn gpu_name(&self) -> Result<&str, GpuNameError> {
+        CStr::from_bytes_until_nul(&self.gpu_name)
+            .map_err(GpuNameError::NoNullTerminator)?
+            .to_str()
+            .map_err(GpuNameError::InvalidUtf8)
+    }
+
+    /// Returns the short 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 fn gpu_short_name(&self) -> core::result::Result<&str, GpuNameError> {
+        CStr::from_bytes_until_nul(&self.gpu_short_name)
+            .map_err(GpuNameError::NoNullTerminator)?
+            .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 fn vram_size(&self) -> u64 {
+        self.usable_fb_regions.iter().fold(0, |size, region| {
+            size.saturating_add(region.end - region.start)
+        })
+    }
+}
diff --git a/drivers/gpu/nova-core/gsp/commands/rpc.rs b/drivers/gpu/nova-core/gsp/commands/rpc.rs
index 023090ac6bd9..ab6d1114cead 100644
--- a/drivers/gpu/nova-core/gsp/commands/rpc.rs
+++ b/drivers/gpu/nova-core/gsp/commands/rpc.rs
@@ -3,10 +3,7 @@
 
 use core::{
     array,
-    convert::Infallible,
-    ffi::FromBytesUntilNulError,
-    ops::Range,
-    str::Utf8Error, //
+    convert::Infallible, //
 };
 
 use kernel::{
@@ -30,6 +27,7 @@
             Cmdq,
             NoReply, //
         },
+        commands::GspStaticInfo,
         fw::{
             self,
             MsgFunction, //
@@ -208,7 +206,7 @@ pub(crate) fn wait_gsp_init_done(cmdq: &Cmdq<'_>) -> Result {
 impl CommandToGsp for GetGspStaticInfo {
     const FUNCTION: MsgFunction = MsgFunction::GetGspStaticInfo;
     type Command = fw::commands::GspStaticConfigInfo;
-    type Reply = GetGspStaticInfoReply;
+    type Reply = GspStaticInfo;
     type InitError = Infallible;
 
     fn init(&self) -> impl Init<Self::Command, Self::InitError> {
@@ -216,21 +214,7 @@ fn init(&self) -> impl Init<Self::Command, Self::InitError> {
     }
 }
 
-/// The reply from the GSP to the [`GetGspStaticInfo`] command.
-pub struct GetGspStaticInfoReply {
-    gpu_name: [u8; 64],
-    gpu_short_name: [u8; 64],
-    /// The 16-byte SHA-1 based GPU identifier (GID) reported by GSP-RM.
-    pub gpu_gid: [u8; 16],
-    /// 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,
-}
-
-impl MessageFromGsp for GetGspStaticInfoReply {
+impl MessageFromGsp for GspStaticInfo {
     const FUNCTION: MsgFunction = MsgFunction::GetGspStaticInfo;
     type Message = fw::commands::GspStaticConfigInfo;
     type InitError = Error;
@@ -245,7 +229,7 @@ fn read(
         }
         let total_fb_end = msg.total_fb_end().ok_or(EINVAL)?;
 
-        Ok(GetGspStaticInfoReply {
+        Ok(GspStaticInfo {
             gpu_name: msg.gpu_name_str(),
             gpu_short_name: msg.gpu_short_name_str(),
             gpu_gid: msg.gpu_gid(),
@@ -256,48 +240,6 @@ fn read(
     }
 }
 
-/// Error type for [`GetGspStaticInfoReply::gpu_name`].
-#[derive(Debug)]
-pub enum GpuNameError {
-    /// The GPU name string does not contain a null terminator.
-    NoNullTerminator(FromBytesUntilNulError),
-
-    /// The GPU name string contains invalid UTF-8.
-    InvalidUtf8(Utf8Error),
-}
-
-impl GetGspStaticInfoReply {
-    /// 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 fn gpu_name(&self) -> Result<&str, GpuNameError> {
-        CStr::from_bytes_until_nul(&self.gpu_name)
-            .map_err(GpuNameError::NoNullTerminator)?
-            .to_str()
-            .map_err(GpuNameError::InvalidUtf8)
-    }
-
-    /// Returns the short 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 fn gpu_short_name(&self) -> core::result::Result<&str, GpuNameError> {
-        CStr::from_bytes_until_nul(&self.gpu_short_name)
-            .map_err(GpuNameError::NoNullTerminator)?
-            .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 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;
 
 /// The `UnloadingGuestDriver` command, used to shut down the GSP.

-- 
2.56.1


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH v2 03/11] gpu: nova-core: gsp: return the static GPU configuration from boot
  2026-11-29 15:10 [PATCH v2 00/11] gpu: nova-core: gsp: preparatory patches for the r000 firmware Alexandre Courbot
  2026-11-29 15:11 ` [PATCH v2 01/11] gpu: nova-core: gsp: add the r000 queue element header Alexandre Courbot
  2026-11-29 15:11 ` [PATCH v2 02/11] gpu: nova-core: gsp: rename and move the static configuration type Alexandre Courbot
@ 2026-11-29 15:11 ` Alexandre Courbot
  2026-11-29 15:11 ` [PATCH v2 04/11] gpu: nova-core: gsp: add the short name and GID to the GSP_INIT reply Alexandre Courbot
                   ` (7 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: Alexandre Courbot @ 2026-11-29 15:11 UTC (permalink / raw)
  To: Danilo Krummrich, Alice Ryhl, David Airlie, Simona Vetter
  Cc: John Hubbard, Alistair Popple, Timur Tabi, Eliot Courtney,
	Zhi Wang, nova-gpu, dri-devel, linux-kernel, Alexandre Courbot

From: John Hubbard <jhubbard@nvidia.com>

With the r000 firmware, GSP-RM reports the static GPU configuration in
its reply to the GSP_INIT command that ends the boot, so the boot
sequence holds the configuration when it returns.

Nova-core fetches the configuration with an RPC command after the boot,
once the interrupt handler is registered. On r000, the boot sequence
would have to keep the GSP_INIT reply for that later step to read.

Return the configuration from the boot sequence, together with the
unload bundle, and send the RPC command at the end of the boot sequence
instead.

Signed-off-by: John Hubbard <jhubbard@nvidia.com>
Signed-off-by: Alexandre Courbot <acourbot@nvidia.com>
---
 drivers/gpu/nova-core/api.rs      |  2 +-
 drivers/gpu/nova-core/gpu.rs      | 36 +++++++++++++++++++-----------------
 drivers/gpu/nova-core/gsp.rs      | 13 ++++++++-----
 drivers/gpu/nova-core/gsp/boot.rs | 15 +++++++++++----
 4 files changed, 39 insertions(+), 27 deletions(-)

diff --git a/drivers/gpu/nova-core/api.rs b/drivers/gpu/nova-core/api.rs
index f800ba6c4183..a665eabc44c2 100644
--- a/drivers/gpu/nova-core/api.rs
+++ b/drivers/gpu/nova-core/api.rs
@@ -41,7 +41,7 @@ pub fn of(adev: &auxiliary::Device<Bound>) -> Result<NovaCoreApiHandle<'_>> {
 
     /// Returns the GPU [`GspStaticInfo`].
     pub fn gsp_static_info(&self) -> &GspStaticInfo {
-        &self.gpu.gsp_static_info
+        self.gpu.gsp_static_info()
     }
 
     /// Returns the GPU [`Spec`].
diff --git a/drivers/gpu/nova-core/gpu.rs b/drivers/gpu/nova-core/gpu.rs
index 590d81f4e479..e4db5ce47316 100644
--- a/drivers/gpu/nova-core/gpu.rs
+++ b/drivers/gpu/nova-core/gpu.rs
@@ -32,7 +32,6 @@
     gsp::{
         self,
         cmdq::Cmdq,
-        commands::GspStaticInfo,
         Gsp,
         GspBootContext, //
     },
@@ -341,8 +340,8 @@ struct GspResources<'gpu> {
     /// GSP runtime data.
     #[pin]
     gsp: Gsp<'gpu>,
-    /// GSP unload firmware bundle, if any.
-    unload_bundle: Option<gsp::UnloadBundle<'gpu>>,
+    /// The static GPU configuration and the unload bundle that the boot sequence returned.
+    boot_result: gsp::BootResult<'gpu>,
 }
 
 /// The GSP event handler's registration and the enable of its subtree at `TOP`.
@@ -393,8 +392,6 @@ pub(crate) struct Gpu<'gpu> {
     #[pin]
     #[uses('tree)]
     _gsp_subtree: GspSubtree<'gsp_resources>,
-    /// Static GPU information as provided by the GSP.
-    pub(crate) gsp_static_info: GspStaticInfo,
     /// GPU memory manager owning memory management resources.
     ///
     /// Must be kept declared *before* `gsp_resources`, so that its components are dropped while
@@ -425,7 +422,7 @@ 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 bundle = this.boot_result.unload_bundle.take();
 
         let _ = this
             .gsp
@@ -505,7 +502,7 @@ pub(crate) fn new<'a>(
                 // 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 {
+                boot_result: gsp.boot(GspBootContext {
                     pdev,
                     bar,
                     chipset: spec.chipset,
@@ -537,9 +534,9 @@ pub(crate) fn new<'a>(
                 gsp_resources.gsp.cmdq.drain()?;
             },
 
-            gsp_static_info: {
+            _: {
                 // Obtain and display basic GPU information.
-                let info = gsp_resources.gsp.get_static_info()?;
+                let info = &gsp_resources.boot_result.static_info;
                 match info.gpu_name() {
                     Ok(name) => dev_info!(dev, "GPU name: {}\n", name),
                     Err(e) => dev_warn!(dev, "GPU name unavailable: {:?}\n", e),
@@ -557,13 +554,12 @@ pub(crate) fn new<'a>(
                         info.vram_size() / u64::SZ_1M
                     );
                 }
-
-                info
             },
 
             // Create GPU memory manager owning memory management resources.
             mm: {
-                let usable_vram = gsp_static_info.usable_fb_regions.first().ok_or(ENODEV)?;
+                let info = &gsp_resources.boot_result.static_info;
+                let usable_vram = info.usable_fb_regions.first().ok_or(ENODEV)?;
                 let buddy_params = GpuBuddyParams {
                     base_offset: usable_vram.start,
                     size: usable_vram.end - usable_vram.start,
@@ -574,13 +570,14 @@ pub(crate) fn new<'a>(
                     bar,
                     gsp_resources.spec.chipset,
                     buddy_params,
-                    VramAddress::from_raw(gsp_static_info.total_fb_end),
+                    VramAddress::from_raw(info.total_fb_end),
                 )?
             },
 
             // Create BAR1 user interface for CPU access to GPU virtual memory.
             bar_user <- {
-                let pdb_addr = VramAddress::from_raw(gsp_static_info.bar1_pde_base);
+                let info = &gsp_resources.boot_result.static_info;
+                let pdb_addr = VramAddress::from_raw(info.bar1_pde_base);
                 let bar1_idx = crate::driver::bar1_resource_index(pdev)?;
                 let bar1_size = pdev.resource_len(bar1_idx)?;
 
@@ -594,6 +591,11 @@ pub(crate) fn new<'a>(
         })
     }
 
+    /// Returns the static GPU configuration that GSP-RM reported at boot.
+    pub(crate) fn gsp_static_info(&self) -> &gsp::commands::GspStaticInfo {
+        &self.gsp_resources.boot_result.static_info
+    }
+
     /// Waits for GFW, the GPU's boot firmware, to report completion.
     ///
     /// The driver must not program the GPU before then.
@@ -616,14 +618,14 @@ pub(crate) fn wait_gfw_boot_completion(
     pub(crate) fn run_selftests(self: Pin<&mut Self>, pdev: &pci::Device<device::Bound>) {
         let this = self.project();
         let dev = pdev.as_ref();
-        let regions = &this.gsp_static_info.usable_fb_regions;
+        let info = &this.gsp_resources.boot_result.static_info;
 
         if let Err(err) = crate::mm::selftest::run(
             dev,
             this.mm,
-            regions,
+            &info.usable_fb_regions,
             &this.bar_user,
-            this.gsp_static_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.rs b/drivers/gpu/nova-core/gsp.rs
index 398d6525b133..bf0028e52e3c 100644
--- a/drivers/gpu/nova-core/gsp.rs
+++ b/drivers/gpu/nova-core/gsp.rs
@@ -157,12 +157,15 @@ pub(crate) fn new(
             }))
         })
     }
-
-    /// Query the GSP for the static GPU information.
-    pub(crate) fn get_static_info(&self) -> Result<commands::GspStaticInfo> {
-        self.cmdq.send_rpc_command(commands::rpc::GetGspStaticInfo)
-    }
 }
 
 /// Opaque bundle required to unload the GSP. Created by [`Gsp::boot`], consumed by [`Gsp::unload`].
 pub(crate) struct UnloadBundle<'a>(KBox<dyn hal::UnloadBundle + 'a>);
+
+/// The output of [`Gsp::boot`]: the static GPU configuration and the unload bundle.
+pub(crate) struct BootResult<'a> {
+    /// The unload bundle for [`Gsp::unload`], if one could be built.
+    pub(crate) unload_bundle: Option<UnloadBundle<'a>>,
+    /// The static GPU configuration as reported by GSP-RM.
+    pub(crate) static_info: commands::GspStaticInfo,
+}
diff --git a/drivers/gpu/nova-core/gsp/boot.rs b/drivers/gpu/nova-core/gsp/boot.rs
index 9d5da5b165ac..a45f2b21a2ab 100644
--- a/drivers/gpu/nova-core/gsp/boot.rs
+++ b/drivers/gpu/nova-core/gsp/boot.rs
@@ -27,12 +27,12 @@ impl<'gsp> super::Gsp<'gsp> {
     /// user-space, patching them with signatures, and building firmware-specific intricate data
     /// structures that the GSP will use at runtime.
     ///
-    /// Upon return, the GSP is up and running, and its unload bundle (to be given as argument to
-    /// [`Self::unload`]) returned.
+    /// Returns, with the GSP running, the static configuration that GSP-RM reported and the
+    /// unload bundle for [`Self::unload`].
     pub(crate) fn boot(
         self: Pin<&mut Self>,
         mut ctx: super::GspBootContext<'_, 'gsp>,
-    ) -> Result<Option<super::UnloadBundle<'gsp>>> {
+    ) -> Result<super::BootResult<'gsp>> {
         let pdev = ctx.pdev;
         let chipset = ctx.chipset;
         let gsp_falcon = ctx.gsp_falcon;
@@ -84,7 +84,14 @@ pub(crate) fn boot(
         // Wait until GSP is fully initialized.
         commands::rpc::wait_gsp_init_done(&self.cmdq)?;
 
-        Ok(unload_guard.dismiss().1)
+        let static_info = self
+            .cmdq
+            .send_rpc_command(commands::rpc::GetGspStaticInfo)?;
+
+        Ok(super::BootResult {
+            unload_bundle: unload_guard.dismiss().1,
+            static_info,
+        })
     }
 
     /// Shut down the GSP and wait until it is offline.

-- 
2.56.1


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH v2 04/11] gpu: nova-core: gsp: add the short name and GID to the GSP_INIT reply
  2026-11-29 15:10 [PATCH v2 00/11] gpu: nova-core: gsp: preparatory patches for the r000 firmware Alexandre Courbot
                   ` (2 preceding siblings ...)
  2026-11-29 15:11 ` [PATCH v2 03/11] gpu: nova-core: gsp: return the static GPU configuration from boot Alexandre Courbot
@ 2026-11-29 15:11 ` Alexandre Courbot
  2026-11-29 15:11 ` [PATCH v2 05/11] gpu: nova-core: gsp: logbuffer: add LogBuffers::init_arguments() Alexandre Courbot
                   ` (6 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: Alexandre Courbot @ 2026-11-29 15:11 UTC (permalink / raw)
  To: Danilo Krummrich, Alice Ryhl, David Airlie, Simona Vetter
  Cc: John Hubbard, Alistair Popple, Timur Tabi, Eliot Courtney,
	Zhi Wang, nova-gpu, dri-devel, linux-kernel, Alexandre Courbot

From: John Hubbard <jhubbard@nvidia.com>

The static GPU configuration holds the short name of the GPU and the GPU
identifier (GID). Nova-drm reports both to user space, and the r570
static-info reply provides both.

The r000 GSP-RM sends both in its reply to GSP_INIT, and nova-core's
schema of that reply has no key for either.

Add the two keys to the schema. Move the lengths of the names and of the
identifier onto the static configuration type, so that the schema and
the type share them.

Signed-off-by: John Hubbard <jhubbard@nvidia.com>
Signed-off-by: Alexandre Courbot <acourbot@nvidia.com>
---
 drivers/gpu/nova-core/gsp/commands.rs    | 11 ++++++++---
 drivers/gpu/nova-core/gsp/fw/commands.rs | 23 ++++++++++++-----------
 2 files changed, 20 insertions(+), 14 deletions(-)

diff --git a/drivers/gpu/nova-core/gsp/commands.rs b/drivers/gpu/nova-core/gsp/commands.rs
index 4aae94b7ca2e..390be8fdd0ba 100644
--- a/drivers/gpu/nova-core/gsp/commands.rs
+++ b/drivers/gpu/nova-core/gsp/commands.rs
@@ -14,10 +14,10 @@
 /// The static GPU configuration, which GSP-RM reports in reply to
 /// [`GetGspStaticInfo`](rpc::GetGspStaticInfo).
 pub struct GspStaticInfo {
-    gpu_name: [u8; 64],
-    gpu_short_name: [u8; 64],
+    gpu_name: [u8; Self::MAX_GPU_NAME_LEN],
+    gpu_short_name: [u8; Self::MAX_GPU_NAME_LEN],
     /// The 16-byte SHA-1 based GPU identifier (GID) reported by GSP-RM.
-    pub gpu_gid: [u8; 16],
+    pub gpu_gid: [u8; Self::GID_LEN],
     /// BAR1 Page Directory Entry base address.
     pub(crate) bar1_pde_base: u64,
     /// Usable FB (VRAM) regions for driver memory allocation.
@@ -37,6 +37,11 @@ pub enum GpuNameError {
 }
 
 impl GspStaticInfo {
+    /// Length of the buffers holding the GPU names, NUL terminator included.
+    pub(crate) const MAX_GPU_NAME_LEN: usize = 64;
+    /// Length of the GPU identifier.
+    pub(crate) const GID_LEN: usize = 16;
+
     /// 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
diff --git a/drivers/gpu/nova-core/gsp/fw/commands.rs b/drivers/gpu/nova-core/gsp/fw/commands.rs
index b4bdbddad79f..d6926709a368 100644
--- a/drivers/gpu/nova-core/gsp/fw/commands.rs
+++ b/drivers/gpu/nova-core/gsp/fw/commands.rs
@@ -18,6 +18,7 @@
 use crate::{
     gpu::Chipset,
     gsp::{
+        commands::GspStaticInfo,
         nvkv::{
             nvkv_decode,
             nvkv_encode,
@@ -176,12 +177,12 @@ unsafe impl FromBytes for PackedRegistryTable {}
 
 impl GspStaticConfigInfo {
     /// Returns a bytes array containing the (hopefully) zero-terminated name of this GPU.
-    pub(crate) fn gpu_name_str(&self) -> [u8; 64] {
+    pub(crate) fn gpu_name_str(&self) -> [u8; GspStaticInfo::MAX_GPU_NAME_LEN] {
         self.0.gpuNameString
     }
 
     /// Returns a bytes array containing the (hopefully) zero-terminated short name of this GPU.
-    pub(crate) fn gpu_short_name_str(&self) -> [u8; 64] {
+    pub(crate) fn gpu_short_name_str(&self) -> [u8; GspStaticInfo::MAX_GPU_NAME_LEN] {
         self.0.gpuShortNameString
     }
 
@@ -189,9 +190,9 @@ impl GspStaticConfigInfo {
     ///
     /// GSP-RM reports the GID in binary SHA-1 form, which occupies the first 16 bytes of the
     /// GID info payload.
-    pub(crate) fn gpu_gid(&self) -> [u8; 16] {
-        let mut gid = [0u8; 16];
-        gid.copy_from_slice(&self.0.gidInfo.data[..16]);
+    pub(crate) fn gpu_gid(&self) -> [u8; GspStaticInfo::GID_LEN] {
+        let mut gid = [0u8; GspStaticInfo::GID_LEN];
+        gid.copy_from_slice(&self.0.gidInfo.data[..GspStaticInfo::GID_LEN]);
         gid
     }
 
@@ -386,7 +387,9 @@ struct GspInitRequest {
     // https://github.com/rust-lang/rust/pull/154377
     #[allow(dead_code)]
     struct GspInitResponseSchema => GspInitResponse {
-        gpu_name: TruncatingArray<u8, { GspInitResponse::MAX_GPU_NAME_LEN }, 0x2000>,
+        gpu_name: TruncatingArray<u8, { GspStaticInfo::MAX_GPU_NAME_LEN }, 0x2000>,
+        gpu_short_name: TruncatingArray<u8, { GspStaticInfo::MAX_GPU_NAME_LEN }, 0x2001>,
+        gpu_gid: TruncatingArray<u8, { GspStaticInfo::GID_LEN }, 0x2002>,
         fb_regions: Accumulated<FbRegionSchema>,
         bar1_pde_base: Required<Key<u64, 0x1020>>,
         vmmu_segment_size: Key<u64, 0x1050>,
@@ -398,16 +401,14 @@ struct GspInitResponseSchema => GspInitResponse {
 // https://github.com/rust-lang/rust/pull/154377
 #[allow(dead_code)]
 struct GspInitResponse {
-    gpu_name: ArrayVec<u8, { Self::MAX_GPU_NAME_LEN }>,
+    gpu_name: ArrayVec<u8, { GspStaticInfo::MAX_GPU_NAME_LEN }>,
+    gpu_short_name: ArrayVec<u8, { GspStaticInfo::MAX_GPU_NAME_LEN }>,
+    gpu_gid: ArrayVec<u8, { GspStaticInfo::GID_LEN }>,
     fb_regions: KVVec<FbRegion>,
     bar1_pde_base: u64,
     vmmu_segment_size: u64,
 }
 
-impl GspInitResponse {
-    const MAX_GPU_NAME_LEN: usize = 64;
-}
-
 nvkv_decode! {
     /// Schema for one FB region of the `GSP_INIT` response.
     struct FbRegionSchema => FbRegion {

-- 
2.56.1


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH v2 05/11] gpu: nova-core: gsp: logbuffer: add LogBuffers::init_arguments()
  2026-11-29 15:10 [PATCH v2 00/11] gpu: nova-core: gsp: preparatory patches for the r000 firmware Alexandre Courbot
                   ` (3 preceding siblings ...)
  2026-11-29 15:11 ` [PATCH v2 04/11] gpu: nova-core: gsp: add the short name and GID to the GSP_INIT reply Alexandre Courbot
@ 2026-11-29 15:11 ` Alexandre Courbot
  2026-11-29 15:11 ` [PATCH v2 06/11] gpu: nova-core: gsp: logbuffer: make LogBuffer generic over its size Alexandre Courbot
                   ` (5 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: Alexandre Courbot @ 2026-11-29 15:11 UTC (permalink / raw)
  To: Danilo Krummrich, Alice Ryhl, David Airlie, Simona Vetter
  Cc: John Hubbard, Alistair Popple, Timur Tabi, Eliot Courtney,
	Zhi Wang, nova-gpu, dri-devel, linux-kernel, Alexandre Courbot

From: John Hubbard <jhubbard@nvidia.com>

`Gsp::new()` names each log buffer in the init argument array itself,
which requires the buffers to be visible outside of their module.

Move that code into `LogBuffers::init_arguments()`, and add
`LogBuffers::COUNT` for the index of the argument that follows.

No functional change.

Signed-off-by: John Hubbard <jhubbard@nvidia.com>
Signed-off-by: Alexandre Courbot <acourbot@nvidia.com>
---
 drivers/gpu/nova-core/gsp.rs           | 14 +++----------
 drivers/gpu/nova-core/gsp/logbuffer.rs | 37 ++++++++++++++++++++++++++++++----
 2 files changed, 36 insertions(+), 15 deletions(-)

diff --git a/drivers/gpu/nova-core/gsp.rs b/drivers/gpu/nova-core/gsp.rs
index bf0028e52e3c..eb5b62aa8bc0 100644
--- a/drivers/gpu/nova-core/gsp.rs
+++ b/drivers/gpu/nova-core/gsp.rs
@@ -137,19 +137,11 @@ pub(crate) fn new(
                         GFP_KERNEL,
                     )?;
 
+                    log_buffers.init_arguments(&mut libos)?;
                     libos.init_at(
-                        0,
-                        LibosMemoryRegionInitArgument::new("LOGINIT", &log_buffers.loginit.0),
+                        LogBuffers::COUNT,
+                        LibosMemoryRegionInitArgument::new("RMARGS", rmargs),
                     )?;
-                    libos.init_at(
-                        1,
-                        LibosMemoryRegionInitArgument::new("LOGINTR", &log_buffers.logintr.0),
-                    )?;
-                    libos.init_at(
-                        2,
-                        LibosMemoryRegionInitArgument::new("LOGRM", &log_buffers.logrm.0),
-                    )?;
-                    libos.init_at(3, LibosMemoryRegionInitArgument::new("RMARGS", rmargs))?;
 
                     libos.into()
                 },
diff --git a/drivers/gpu/nova-core/gsp/logbuffer.rs b/drivers/gpu/nova-core/gsp/logbuffer.rs
index 5455d990ffb4..a825cb57dba5 100644
--- a/drivers/gpu/nova-core/gsp/logbuffer.rs
+++ b/drivers/gpu/nova-core/gsp/logbuffer.rs
@@ -5,7 +5,10 @@
 use kernel::{
     debugfs,
     device,
-    dma::Coherent,
+    dma::{
+        Coherent,
+        CoherentBox, //
+    },
     io::{
         io_project,
         Io, //
@@ -20,6 +23,7 @@
 
 use crate::{
     gsp::{
+        LibosMemoryRegionInitArgument,
         PteArray,
         GSP_PAGE_SIZE, //
     },
@@ -90,14 +94,17 @@ pub(super) struct LogBuffers<'a> {
     /// Device the buffers belong to.
     dev: &'a device::Device<device::Bound>,
     /// Init log buffer.
-    pub(super) loginit: LogBuffer<'a>,
+    loginit: LogBuffer<'a>,
     /// Interrupts log buffer.
-    pub(super) logintr: LogBuffer<'a>,
+    logintr: LogBuffer<'a>,
     /// RM log buffer.
-    pub(super) logrm: LogBuffer<'a>,
+    logrm: LogBuffer<'a>,
 }
 
 impl<'a> LogBuffers<'a> {
+    /// Number of log buffers.
+    pub(super) const COUNT: usize = 3;
+
     /// Allocates the log buffers of `dev`.
     pub(super) fn new(dev: &'a device::Device<device::Bound>) -> Result<Self> {
         Ok(Self {
@@ -108,6 +115,28 @@ pub(super) fn new(dev: &'a device::Device<device::Bound>) -> Result<Self> {
         })
     }
 
+    /// Fills the first [`Self::COUNT`] entries of `libos` with the log buffers, under the names
+    /// that GSP-RM looks them up by.
+    pub(super) fn init_arguments(
+        &self,
+        libos: &mut CoherentBox<'_, [LibosMemoryRegionInitArgument]>,
+    ) -> Result {
+        libos.init_at(
+            0,
+            LibosMemoryRegionInitArgument::new("LOGINIT", &self.loginit.0),
+        )?;
+        libos.init_at(
+            1,
+            LibosMemoryRegionInitArgument::new("LOGINTR", &self.logintr.0),
+        )?;
+        libos.init_at(
+            2,
+            LibosMemoryRegionInitArgument::new("LOGRM", &self.logrm.0),
+        )?;
+
+        Ok(())
+    }
+
     /// Exposes the buffers in debugfs, in a directory named after their device.
     pub(super) fn into_debugfs_scope(self) -> impl PinInit<debugfs::Scope<Self>> + 'a {
         let dev = self.dev;

-- 
2.56.1


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH v2 06/11] gpu: nova-core: gsp: logbuffer: make LogBuffer generic over its size
  2026-11-29 15:10 [PATCH v2 00/11] gpu: nova-core: gsp: preparatory patches for the r000 firmware Alexandre Courbot
                   ` (4 preceding siblings ...)
  2026-11-29 15:11 ` [PATCH v2 05/11] gpu: nova-core: gsp: logbuffer: add LogBuffers::init_arguments() Alexandre Courbot
@ 2026-11-29 15:11 ` Alexandre Courbot
  2026-11-29 15:11 ` [PATCH v2 07/11] gpu: nova-core: gsp: logbuffer: add RetainedLogBuffers::is_empty() Alexandre Courbot
                   ` (4 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: Alexandre Courbot @ 2026-11-29 15:11 UTC (permalink / raw)
  To: Danilo Krummrich, Alice Ryhl, David Airlie, Simona Vetter
  Cc: John Hubbard, Alistair Popple, Timur Tabi, Eliot Courtney,
	Zhi Wang, nova-gpu, dri-devel, linux-kernel, Alexandre Courbot

From: John Hubbard <jhubbard@nvidia.com>

The r000 firmware has more log buffers than r570, of two sizes.

Make `LogBuffer` generic over its number of pages. An array length
cannot be computed from a const parameter, so the buffer becomes an
array of pages instead of an array of bytes, and a snapshot is copied
page by page.

No functional change.

Signed-off-by: John Hubbard <jhubbard@nvidia.com>
Signed-off-by: Alexandre Courbot <acourbot@nvidia.com>
---
 drivers/gpu/nova-core/gsp/logbuffer.rs | 38 +++++++++++++++++++++-------------
 1 file changed, 24 insertions(+), 14 deletions(-)

diff --git a/drivers/gpu/nova-core/gsp/logbuffer.rs b/drivers/gpu/nova-core/gsp/logbuffer.rs
index a825cb57dba5..40fb6682d83d 100644
--- a/drivers/gpu/nova-core/gsp/logbuffer.rs
+++ b/drivers/gpu/nova-core/gsp/logbuffer.rs
@@ -32,7 +32,6 @@
 
 /// Number of GSP pages to use in a RM log buffer.
 const RM_LOG_BUFFER_NUM_PAGES: usize = 0x10;
-const LOG_BUFFER_SIZE: usize = RM_LOG_BUFFER_NUM_PAGES * GSP_PAGE_SIZE;
 
 /// The logging buffers are byte queues that contain encoded printf-like
 /// messages from GSP-RM.  They need to be decoded by a special application
@@ -48,9 +47,17 @@
 /// then pp points to index into the buffer where the next logging entry will
 /// be written. Therefore, the logging data is valid if:
 ///   1 <= pp < sizeof(buffer)/sizeof(u64)
-pub(super) struct LogBuffer<'a>(pub(super) Coherent<'a, [u8; LOG_BUFFER_SIZE]>);
+pub(super) struct LogBuffer<'a, const NUM_PAGES: usize>(
+    pub(super) Coherent<'a, [[u8; GSP_PAGE_SIZE]; NUM_PAGES]>,
+);
 
-impl<'a> LogBuffer<'a> {
+/// A log buffer at the default size, [`RM_LOG_BUFFER_NUM_PAGES`] pages.
+///
+/// Matches the registry defaults for the init, interrupt and RM tasks
+/// (`NV_REG_STR_RM_GSP_LOG_BUFFER_SIZE_TASK_*_DEFAULT`).
+type TaskLogBuffer<'a> = LogBuffer<'a, RM_LOG_BUFFER_NUM_PAGES>;
+
+impl<'a, const NUM_PAGES: usize> LogBuffer<'a, NUM_PAGES> {
     /// Creates a new `LogBuffer` mapped on `dev`.
     fn new(dev: &'a device::Device<device::Bound>) -> Result<Self> {
         let obj = Self(Coherent::zeroed(dev, GFP_KERNEL)?);
@@ -59,9 +66,9 @@ fn new(dev: &'a device::Device<device::Bound>) -> Result<Self> {
 
         let pte_view = io_project!(
             obj.0,
-            [build: size_of::<u64>()..][build: ..RM_LOG_BUFFER_NUM_PAGES * size_of::<u64>()]
+            [build: 0][build: size_of::<u64>()..][build: ..NUM_PAGES * size_of::<u64>()]
         )
-        .try_cast::<PteArray<RM_LOG_BUFFER_NUM_PAGES>>()?;
+        .try_cast::<PteArray<NUM_PAGES>>()?;
         PteArray::init(pte_view, start_addr)?;
 
         Ok(obj)
@@ -69,7 +76,7 @@ fn new(dev: &'a device::Device<device::Bound>) -> Result<Self> {
 
     /// Copies the buffer, or returns an empty vector if the GSP never wrote to it.
     fn snapshot(&self) -> Result<VVec<u8>> {
-        let put = io_project!(self.0, [build: ..size_of::<u64>()])
+        let put = io_project!(self.0, [build: 0][build: ..size_of::<u64>()])
             .try_cast::<u64>()?
             .read_val();
         if put == 0 {
@@ -80,8 +87,11 @@ fn snapshot(&self) -> Result<VVec<u8>> {
         // GSP that failed to boot may still be writing.
         dma_mb(Read);
 
-        let mut snapshot = VVec::zeroed(LOG_BUFFER_SIZE, GFP_KERNEL)?;
-        io_project!(self.0, [build: ..]).copy_to_slice(&mut snapshot);
+        let mut snapshot = VVec::zeroed(NUM_PAGES * GSP_PAGE_SIZE, GFP_KERNEL)?;
+        for (i, page) in snapshot.chunks_exact_mut(GSP_PAGE_SIZE).enumerate() {
+            // PANIC: `snapshot` holds `NUM_PAGES` pages, so `i` is below `NUM_PAGES`.
+            io_project!(self.0, [panic: i][build: ..]).copy_to_slice(page);
+        }
 
         // The copy reads "put" again, unordered against the data, so keep the value read above.
         snapshot[..size_of::<u64>()].copy_from_slice(&put.to_ne_bytes());
@@ -94,11 +104,11 @@ pub(super) struct LogBuffers<'a> {
     /// Device the buffers belong to.
     dev: &'a device::Device<device::Bound>,
     /// Init log buffer.
-    loginit: LogBuffer<'a>,
+    loginit: TaskLogBuffer<'a>,
     /// Interrupts log buffer.
-    logintr: LogBuffer<'a>,
+    logintr: TaskLogBuffer<'a>,
     /// RM log buffer.
-    logrm: LogBuffer<'a>,
+    logrm: TaskLogBuffer<'a>,
 }
 
 impl<'a> LogBuffers<'a> {
@@ -109,9 +119,9 @@ impl<'a> LogBuffers<'a> {
     pub(super) fn new(dev: &'a device::Device<device::Bound>) -> Result<Self> {
         Ok(Self {
             dev,
-            loginit: LogBuffer::new(dev)?,
-            logintr: LogBuffer::new(dev)?,
-            logrm: LogBuffer::new(dev)?,
+            loginit: TaskLogBuffer::new(dev)?,
+            logintr: TaskLogBuffer::new(dev)?,
+            logrm: TaskLogBuffer::new(dev)?,
         })
     }
 

-- 
2.56.1


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH v2 07/11] gpu: nova-core: gsp: logbuffer: add RetainedLogBuffers::is_empty()
  2026-11-29 15:10 [PATCH v2 00/11] gpu: nova-core: gsp: preparatory patches for the r000 firmware Alexandre Courbot
                   ` (5 preceding siblings ...)
  2026-11-29 15:11 ` [PATCH v2 06/11] gpu: nova-core: gsp: logbuffer: make LogBuffer generic over its size Alexandre Courbot
@ 2026-11-29 15:11 ` Alexandre Courbot
  2026-11-29 15:11 ` [PATCH v2 08/11] gpu: nova-core: gsp: cmdq: reduce visibility of gsp-level constants Alexandre Courbot
                   ` (3 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: Alexandre Courbot @ 2026-11-29 15:11 UTC (permalink / raw)
  To: Danilo Krummrich, Alice Ryhl, David Airlie, Simona Vetter
  Cc: John Hubbard, Alistair Popple, Timur Tabi, Eliot Courtney,
	Zhi Wang, nova-gpu, dri-devel, linux-kernel, Alexandre Courbot

From: John Hubbard <jhubbard@nvidia.com>

Move the check for retained logs that the GSP never wrote to into a
helper, so that it stays in one place when buffers are added.

No functional change.

Signed-off-by: John Hubbard <jhubbard@nvidia.com>
Signed-off-by: Alexandre Courbot <acourbot@nvidia.com>
---
 drivers/gpu/nova-core/gsp/logbuffer.rs | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/nova-core/gsp/logbuffer.rs b/drivers/gpu/nova-core/gsp/logbuffer.rs
index 40fb6682d83d..bfc1712ea458 100644
--- a/drivers/gpu/nova-core/gsp/logbuffer.rs
+++ b/drivers/gpu/nova-core/gsp/logbuffer.rs
@@ -175,7 +175,7 @@ fn retain(&self) -> Result {
             logrm: self.logrm.snapshot()?,
         };
 
-        if logs.loginit.is_empty() && logs.logintr.is_empty() && logs.logrm.is_empty() {
+        if logs.is_empty() {
             return Ok(());
         }
 
@@ -221,6 +221,13 @@ struct RetainedLogBuffers {
     logrm: VVec<u8>,
 }
 
+impl RetainedLogBuffers {
+    /// Returns `true` if the GSP never wrote to any of the buffers.
+    fn is_empty(&self) -> bool {
+        self.loginit.is_empty() && self.logintr.is_empty() && self.logrm.is_empty()
+    }
+}
+
 /// Copies of the log buffers of all GPUs that are no longer bound.
 pub(crate) struct RetainedLogs(KVec<Pin<KBox<debugfs::Scope<RetainedLogBuffers>>>>);
 

-- 
2.56.1


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH v2 08/11] gpu: nova-core: gsp: cmdq: reduce visibility of gsp-level constants
  2026-11-29 15:10 [PATCH v2 00/11] gpu: nova-core: gsp: preparatory patches for the r000 firmware Alexandre Courbot
                   ` (6 preceding siblings ...)
  2026-11-29 15:11 ` [PATCH v2 07/11] gpu: nova-core: gsp: logbuffer: add RetainedLogBuffers::is_empty() Alexandre Courbot
@ 2026-11-29 15:11 ` Alexandre Courbot
  2026-11-29 15:11 ` [PATCH v2 09/11] gpu: nova-core: gsp: compute the msgq entry offset in MsgqTxHeader::new() Alexandre Courbot
                   ` (2 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: Alexandre Courbot @ 2026-11-29 15:11 UTC (permalink / raw)
  To: Danilo Krummrich, Alice Ryhl, David Airlie, Simona Vetter
  Cc: John Hubbard, Alistair Popple, Timur Tabi, Eliot Courtney,
	Zhi Wang, nova-gpu, dri-devel, linux-kernel, Alexandre Courbot

These constants are defined for sibling modules, not the whole crate.

No functional change.

Signed-off-by: Alexandre Courbot <acourbot@nvidia.com>
---
 drivers/gpu/nova-core/gsp/cmdq.rs | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/gpu/nova-core/gsp/cmdq.rs b/drivers/gpu/nova-core/gsp/cmdq.rs
index e2b9a5383a66..2cdf8c1f7189 100644
--- a/drivers/gpu/nova-core/gsp/cmdq.rs
+++ b/drivers/gpu/nova-core/gsp/cmdq.rs
@@ -84,7 +84,7 @@ trait CommandElement {
 }
 
 /// Number of GSP pages making the [`Msgq`].
-pub(crate) const MSGQ_NUM_PAGES: u32 = 64;
+pub(super) const MSGQ_NUM_PAGES: u32 = 64;
 
 // The queue pointers are wrapping `u32` counters, and the slot is
 // `counter % MSGQ_NUM_PAGES`. For slots to remain contiguous when a counter
@@ -474,17 +474,17 @@ impl<'cmdq> Cmdq<'cmdq> {
     const POST_PTE_OFFSET: usize = core::mem::offset_of!(GspMem, cpuq);
 
     /// Offset of command queue ring buffer.
-    pub(crate) const CMDQ_OFFSET: usize = core::mem::offset_of!(GspMem, cpuq)
+    pub(super) const CMDQ_OFFSET: usize = core::mem::offset_of!(GspMem, cpuq)
         + core::mem::offset_of!(Msgq, msgq)
         - Self::POST_PTE_OFFSET;
 
     /// Offset of message queue ring buffer.
-    pub(crate) const STATQ_OFFSET: usize = core::mem::offset_of!(GspMem, gspq)
+    pub(super) const STATQ_OFFSET: usize = core::mem::offset_of!(GspMem, gspq)
         + core::mem::offset_of!(Msgq, msgq)
         - Self::POST_PTE_OFFSET;
 
     /// Number of page table entries for the GSP shared region.
-    pub(crate) const NUM_PTES: usize = size_of::<GspMem>() >> GSP_PAGE_SHIFT;
+    pub(super) const NUM_PTES: usize = size_of::<GspMem>() >> GSP_PAGE_SHIFT;
 
     /// Default timeout for receiving a message from the GSP.
     pub(super) const RECEIVE_TIMEOUT: Delta = Delta::from_secs(5);

-- 
2.56.1


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH v2 09/11] gpu: nova-core: gsp: compute the msgq entry offset in MsgqTxHeader::new()
  2026-11-29 15:10 [PATCH v2 00/11] gpu: nova-core: gsp: preparatory patches for the r000 firmware Alexandre Courbot
                   ` (7 preceding siblings ...)
  2026-11-29 15:11 ` [PATCH v2 08/11] gpu: nova-core: gsp: cmdq: reduce visibility of gsp-level constants Alexandre Courbot
@ 2026-11-29 15:11 ` Alexandre Courbot
  2026-11-29 15:11 ` [PATCH v2 10/11] gpu: nova-core: gsp: take all the msgq layout values from Cmdq " Alexandre Courbot
  2026-11-29 15:11 ` [PATCH v2 11/11] gpu: nova-core: firmware: tlv: add method to load the file referenced by a TLV Alexandre Courbot
  10 siblings, 0 replies; 12+ messages in thread
From: Alexandre Courbot @ 2026-11-29 15:11 UTC (permalink / raw)
  To: Danilo Krummrich, Alice Ryhl, David Airlie, Simona Vetter
  Cc: John Hubbard, Alistair Popple, Timur Tabi, Eliot Courtney,
	Zhi Wang, nova-gpu, dri-devel, linux-kernel, Alexandre Courbot

From: John Hubbard <jhubbard@nvidia.com>

The entry offset is a property of the queue layout. Take it from the
layout of `Msgq`.

No functional change as both values are `GSP_PAGE_SIZE`.

Signed-off-by: John Hubbard <jhubbard@nvidia.com>
[acourbot: use associated consts instead of parameters for constant values.]
Co-developed-by: Alexandre Courbot <acourbot@nvidia.com>
Signed-off-by: Alexandre Courbot <acourbot@nvidia.com>
---
 drivers/gpu/nova-core/gsp/cmdq.rs | 6 ++++++
 drivers/gpu/nova-core/gsp/fw.rs   | 4 ++--
 2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/nova-core/gsp/cmdq.rs b/drivers/gpu/nova-core/gsp/cmdq.rs
index 2cdf8c1f7189..54b5d94d1328 100644
--- a/drivers/gpu/nova-core/gsp/cmdq.rs
+++ b/drivers/gpu/nova-core/gsp/cmdq.rs
@@ -473,6 +473,12 @@ impl<'cmdq> Cmdq<'cmdq> {
     /// Offset of the data after the PTEs.
     const POST_PTE_OFFSET: usize = core::mem::offset_of!(GspMem, cpuq);
 
+    /// Size of a queue slot. An element spans one or more slots.
+    pub(super) const MSG_SIZE: usize = GSP_PAGE_SIZE;
+
+    /// Offset of the ring buffer of a queue from its TX header.
+    pub(super) const MSGQ_ENTRY_OFFSET: usize = core::mem::offset_of!(Msgq, msgq);
+
     /// Offset of command queue ring buffer.
     pub(super) const CMDQ_OFFSET: usize = core::mem::offset_of!(GspMem, cpuq)
         + core::mem::offset_of!(Msgq, msgq)
diff --git a/drivers/gpu/nova-core/gsp/fw.rs b/drivers/gpu/nova-core/gsp/fw.rs
index 937cbbc24e93..2ddc2e8f6274 100644
--- a/drivers/gpu/nova-core/gsp/fw.rs
+++ b/drivers/gpu/nova-core/gsp/fw.rs
@@ -715,12 +715,12 @@ pub(crate) fn new(msgq_size: u32, rx_hdr_offset: u32, msg_count: u32) -> Self {
         Self(bindings::msgqTxHeader {
             version: 0,
             size: msgq_size,
-            msgSize: cv!(GSP_PAGE_SIZE),
+            msgSize: cv!(Cmdq::MSG_SIZE),
             msgCount: msg_count,
             writePtr: 0,
             flags: 1,
             rxHdrOff: rx_hdr_offset,
-            entryOff: cv!(GSP_PAGE_SIZE),
+            entryOff: cv!(Cmdq::MSGQ_ENTRY_OFFSET),
         })
     }
 

-- 
2.56.1


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH v2 10/11] gpu: nova-core: gsp: take all the msgq layout values from Cmdq in MsgqTxHeader::new()
  2026-11-29 15:10 [PATCH v2 00/11] gpu: nova-core: gsp: preparatory patches for the r000 firmware Alexandre Courbot
                   ` (8 preceding siblings ...)
  2026-11-29 15:11 ` [PATCH v2 09/11] gpu: nova-core: gsp: compute the msgq entry offset in MsgqTxHeader::new() Alexandre Courbot
@ 2026-11-29 15:11 ` Alexandre Courbot
  2026-11-29 15:11 ` [PATCH v2 11/11] gpu: nova-core: firmware: tlv: add method to load the file referenced by a TLV Alexandre Courbot
  10 siblings, 0 replies; 12+ messages in thread
From: Alexandre Courbot @ 2026-11-29 15:11 UTC (permalink / raw)
  To: Danilo Krummrich, Alice Ryhl, David Airlie, Simona Vetter
  Cc: John Hubbard, Alistair Popple, Timur Tabi, Eliot Courtney,
	Zhi Wang, nova-gpu, dri-devel, linux-kernel, Alexandre Courbot

The queue size, RX header offset and slot count are layout constants
just like the entry offset, so stop passing them as parameters.

No functional change.

Signed-off-by: Alexandre Courbot <acourbot@nvidia.com>
---
 drivers/gpu/nova-core/gsp/cmdq.rs | 13 +++++++------
 drivers/gpu/nova-core/gsp/fw.rs   | 23 +++++++++--------------
 2 files changed, 16 insertions(+), 20 deletions(-)

diff --git a/drivers/gpu/nova-core/gsp/cmdq.rs b/drivers/gpu/nova-core/gsp/cmdq.rs
index 54b5d94d1328..10f6ddcf3eb5 100644
--- a/drivers/gpu/nova-core/gsp/cmdq.rs
+++ b/drivers/gpu/nova-core/gsp/cmdq.rs
@@ -7,8 +7,6 @@
 pub(super) mod gmc;
 pub(super) mod rpc;
 
-use core::mem;
-
 use kernel::{
     device,
     dma::{
@@ -176,11 +174,8 @@ struct DmaGspMem<'a> {
 impl<'a> DmaGspMem<'a> {
     /// Allocate a new instance and map it for `dev`.
     fn new(dev: &'a device::Device<device::Bound>, bar: Bar0<'a>) -> Result<Self> {
-        const MSGQ_SIZE: u32 = cv!(size_of::<Msgq>());
-        const RX_HDR_OFF: u32 = cv!(mem::offset_of!(Msgq, rx));
-
         let mut gsp_mem = CoherentBox::<'_, GspMem>::zeroed(dev, GFP_KERNEL)?;
-        gsp_mem.cpuq.tx = MsgqTxHeader::new(MSGQ_SIZE, RX_HDR_OFF, MSGQ_NUM_PAGES);
+        gsp_mem.cpuq.tx = MsgqTxHeader::new();
         gsp_mem.cpuq.rx = MsgqRxHeader::new();
 
         let gsp_mem: Coherent<'_, _> = gsp_mem.into();
@@ -476,6 +471,12 @@ impl<'cmdq> Cmdq<'cmdq> {
     /// Size of a queue slot. An element spans one or more slots.
     pub(super) const MSG_SIZE: usize = GSP_PAGE_SIZE;
 
+    /// Total size of a queue, headers included.
+    pub(super) const MSGQ_SIZE: usize = size_of::<Msgq>();
+
+    /// Offset of the RX header of a queue from its TX header.
+    pub(super) const MSGQ_RX_HDR_OFFSET: usize = core::mem::offset_of!(Msgq, rx);
+
     /// Offset of the ring buffer of a queue from its TX header.
     pub(super) const MSGQ_ENTRY_OFFSET: usize = core::mem::offset_of!(Msgq, msgq);
 
diff --git a/drivers/gpu/nova-core/gsp/fw.rs b/drivers/gpu/nova-core/gsp/fw.rs
index 2ddc2e8f6274..10674939f524 100644
--- a/drivers/gpu/nova-core/gsp/fw.rs
+++ b/drivers/gpu/nova-core/gsp/fw.rs
@@ -50,7 +50,10 @@
         Chipset, //
     },
     gsp::{
-        cmdq::Cmdq, //
+        cmdq::{
+            Cmdq,
+            MSGQ_NUM_PAGES, //
+        },
         GSP_PAGE_SIZE,
     },
     mctp::{
@@ -702,24 +705,16 @@ fn id8(name: &str) -> u64 {
 pub(crate) struct MsgqTxHeader(bindings::msgqTxHeader);
 
 impl MsgqTxHeader {
-    /// Create a new TX queue header.
-    ///
-    /// # Arguments
-    ///
-    /// * `msgq_size` - Total size of the message queue structure, in bytes.
-    /// * `rx_hdr_offset` - Offset, in bytes, of the start of the RX header in the message queue
-    ///   structure.
-    /// * `msg_count` - Number of messages that can be sent, i.e. the number of memory pages
-    ///   allocated for the message queue in the message queue structure.
-    pub(crate) fn new(msgq_size: u32, rx_hdr_offset: u32, msg_count: u32) -> Self {
+    /// Create a new TX queue header, describing the queue layout defined by [`Cmdq`].
+    pub(crate) fn new() -> Self {
         Self(bindings::msgqTxHeader {
             version: 0,
-            size: msgq_size,
+            size: cv!(Cmdq::MSGQ_SIZE),
             msgSize: cv!(Cmdq::MSG_SIZE),
-            msgCount: msg_count,
+            msgCount: MSGQ_NUM_PAGES,
             writePtr: 0,
             flags: 1,
-            rxHdrOff: rx_hdr_offset,
+            rxHdrOff: cv!(Cmdq::MSGQ_RX_HDR_OFFSET),
             entryOff: cv!(Cmdq::MSGQ_ENTRY_OFFSET),
         })
     }

-- 
2.56.1


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH v2 11/11] gpu: nova-core: firmware: tlv: add method to load the file referenced by a TLV
  2026-11-29 15:10 [PATCH v2 00/11] gpu: nova-core: gsp: preparatory patches for the r000 firmware Alexandre Courbot
                   ` (9 preceding siblings ...)
  2026-11-29 15:11 ` [PATCH v2 10/11] gpu: nova-core: gsp: take all the msgq layout values from Cmdq " Alexandre Courbot
@ 2026-11-29 15:11 ` Alexandre Courbot
  10 siblings, 0 replies; 12+ messages in thread
From: Alexandre Courbot @ 2026-11-29 15:11 UTC (permalink / raw)
  To: Danilo Krummrich, Alice Ryhl, David Airlie, Simona Vetter
  Cc: John Hubbard, Alistair Popple, Timur Tabi, Eliot Courtney,
	Zhi Wang, nova-gpu, dri-devel, linux-kernel, Alexandre Courbot

From: John Hubbard <jhubbard@nvidia.com>

The GSP firmware TLV names a separate file in its FILE tag and gives
that file's length in its SIZE tag. The GSP firmware wrapper reads the
two tags and loads the file itself, so no other loader can share that
code.

Move it into the TLV parser as `Tlv::load_file()`, which also fails with
ENODATA when SIZE is zero.

The r000 ucodes loader will be the second user of this.

Signed-off-by: John Hubbard <jhubbard@nvidia.com>
Signed-off-by: Alexandre Courbot <acourbot@nvidia.com>
---
 drivers/gpu/nova-core/firmware/gsp.rs | 15 +++----------
 drivers/gpu/nova-core/firmware/tlv.rs | 40 ++++++++++++++++++++++++++++++++---
 2 files changed, 40 insertions(+), 15 deletions(-)

diff --git a/drivers/gpu/nova-core/firmware/gsp.rs b/drivers/gpu/nova-core/firmware/gsp.rs
index 341a8b19aa38..a2db7b6ba131 100644
--- a/drivers/gpu/nova-core/firmware/gsp.rs
+++ b/drivers/gpu/nova-core/firmware/gsp.rs
@@ -6,9 +6,7 @@
         Coherent,
         DmaAddress, //
     },
-    firmware,
-    prelude::*,
-    str::CString,
+    prelude::*, //
 };
 
 use crate::{
@@ -20,8 +18,7 @@
             Tlv,
         },
     },
-    gpu::Chipset,
-    num::FromSafeCast,
+    gpu::Chipset, //
 };
 
 /// The GSP firmware image, its signatures, and the GSP bootloader.
@@ -48,13 +45,7 @@ pub(crate) fn new(
             let tlv = Tlv::new(firmware.data())?;
             dev_dbg!(dev, "loaded gsp firmware v{}\n", tlv.get_string(b"VERS")?);
 
-            let size = usize::from_safe_cast(tlv.get_u32(b"SIZE")?);
-            let mut fw_vvec = VVec::zeroed(size, GFP_KERNEL).map_err(|_| ENOMEM)?;
-
-            let chip_name = chipset.name();
-            let file = tlv.get_string(b"FILE")?;
-            let filename = CString::try_from_fmt(fmt!("nvidia/{chip_name}/gsp/{file}"))?;
-            firmware::request_into_buf(&filename, dev, fw_vvec.as_mut_slice())?;
+            let fw_vvec = tlv.load_file(dev, chipset)?;
 
             let signatures = Coherent::from_slice(dev, tlv.get_bytes(b"SIGN")?, GFP_KERNEL)?;
 
diff --git a/drivers/gpu/nova-core/firmware/tlv.rs b/drivers/gpu/nova-core/firmware/tlv.rs
index 7b879f13a61e..59807ca702ba 100644
--- a/drivers/gpu/nova-core/firmware/tlv.rs
+++ b/drivers/gpu/nova-core/firmware/tlv.rs
@@ -4,6 +4,7 @@
 use kernel::{
     device,
     firmware,
+    fmt,
     prelude::*,
     str::CString, //
 };
@@ -13,15 +14,18 @@
     num::*, //
 };
 
+/// Returns the path of `file` in `chipset`'s GSP firmware directory.
+fn gsp_firmware_path(chipset: gpu::Chipset, file: fmt::Arguments<'_>) -> Result<CString> {
+    CString::try_from_fmt(fmt!("nvidia/{}/gsp/{}", chipset.name(), file))
+}
+
 /// Requests the GPU firmware TLV `name` suitable for `chipset`.
 pub(crate) fn request_tlv(
     dev: &device::Device,
     chipset: gpu::Chipset,
     name: &str,
 ) -> Result<firmware::Firmware> {
-    let chip_name = chipset.name();
-
-    let filename = CString::try_from_fmt(fmt!("nvidia/{chip_name}/gsp/{name}.tlv"))?;
+    let filename = gsp_firmware_path(chipset, fmt!("{name}.tlv"))?;
 
     dev_dbg!(dev, "loading firmware image {:?}\n", &filename);
 
@@ -198,6 +202,36 @@ fn iter(&self) -> TlvIter<'_, 'a> {
         self.iter().find(|b| b.tag == *tag).ok_or(EINVAL)
     }
 
+    /// Loads the file that the `FILE` tag names from `chipset`'s GSP firmware directory.
+    ///
+    /// The `SIZE` tag gives the file's length, and the returned buffer is that long.
+    ///
+    /// # Errors
+    ///
+    /// - `EINVAL` if `FILE` or `SIZE` is absent, or `FILE` does not hold a valid string.
+    /// - `ENODATA` if `SIZE` is zero.
+    /// - `ENOMEM` if the buffer cannot be allocated.
+    ///
+    /// Errors from the firmware request are propagated as-is.
+    pub(crate) fn load_file(
+        &self,
+        dev: &device::Device,
+        chipset: gpu::Chipset,
+    ) -> Result<VVec<u8>> {
+        let file = self.get_string(b"FILE")?;
+        let path = gsp_firmware_path(chipset, fmt!("{file}"))?;
+
+        let size = usize::from_safe_cast(self.get_u32(b"SIZE")?);
+        if size == 0 {
+            return Err(ENODATA);
+        }
+
+        let mut data = VVec::zeroed(size, GFP_KERNEL).map_err(|_| ENOMEM)?;
+        firmware::request_into_buf(&path, dev, data.as_mut_slice())?;
+
+        Ok(data)
+    }
+
     /// Return a slice of bytes.
     ///
     /// Returns `EINVAL` if the value is empty.

-- 
2.56.1


^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2026-11-29 15:11 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-29 15:10 [PATCH v2 00/11] gpu: nova-core: gsp: preparatory patches for the r000 firmware Alexandre Courbot
2026-11-29 15:11 ` [PATCH v2 01/11] gpu: nova-core: gsp: add the r000 queue element header Alexandre Courbot
2026-11-29 15:11 ` [PATCH v2 02/11] gpu: nova-core: gsp: rename and move the static configuration type Alexandre Courbot
2026-11-29 15:11 ` [PATCH v2 03/11] gpu: nova-core: gsp: return the static GPU configuration from boot Alexandre Courbot
2026-11-29 15:11 ` [PATCH v2 04/11] gpu: nova-core: gsp: add the short name and GID to the GSP_INIT reply Alexandre Courbot
2026-11-29 15:11 ` [PATCH v2 05/11] gpu: nova-core: gsp: logbuffer: add LogBuffers::init_arguments() Alexandre Courbot
2026-11-29 15:11 ` [PATCH v2 06/11] gpu: nova-core: gsp: logbuffer: make LogBuffer generic over its size Alexandre Courbot
2026-11-29 15:11 ` [PATCH v2 07/11] gpu: nova-core: gsp: logbuffer: add RetainedLogBuffers::is_empty() Alexandre Courbot
2026-11-29 15:11 ` [PATCH v2 08/11] gpu: nova-core: gsp: cmdq: reduce visibility of gsp-level constants Alexandre Courbot
2026-11-29 15:11 ` [PATCH v2 09/11] gpu: nova-core: gsp: compute the msgq entry offset in MsgqTxHeader::new() Alexandre Courbot
2026-11-29 15:11 ` [PATCH v2 10/11] gpu: nova-core: gsp: take all the msgq layout values from Cmdq " Alexandre Courbot
2026-11-29 15:11 ` [PATCH v2 11/11] gpu: nova-core: firmware: tlv: add method to load the file referenced by a TLV 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®