[PATCH 2/4] gpu: nova-core: gsp: add the GMC API header

From: Alexandre Courbot

Date: Mon Nov 02 2026 - 19:04:10 EST


From: John Hubbard <jhubbard@xxxxxxxxxx>

The r000 firmware carries GSP-RM's boot protocol, and its newer
interfaces in general, over the GMC (GPU Management Controller) API:
messages that follow the queue element header with a GMC API header
instead of an RPC header.

Add the GmcApiHeader type as a newtype over the GMCAPI_HEADER binding,
so we can define the GMC send and receive paths in the following
patches.

[ acourbot: wrap the bindings type instead of redefining it; make
`status` return an `Option` to avoid returning a value whose semantics
are ambiguous.]

Assisted-by: LLM
Signed-off-by: John Hubbard <jhubbard@xxxxxxxxxx>
Co-developed-by: Alexandre Courbot <acourbot@xxxxxxxxxx>
Signed-off-by: Alexandre Courbot <acourbot@xxxxxxxxxx>
---
drivers/gpu/nova-core/gsp/fw.rs | 106 ++++++++++++++++++++++++++++++++++++++++
1 file changed, 106 insertions(+)

diff --git a/drivers/gpu/nova-core/gsp/fw.rs b/drivers/gpu/nova-core/gsp/fw.rs
index 213ef5bfb258..367c8b5e3443 100644
--- a/drivers/gpu/nova-core/gsp/fw.rs
+++ b/drivers/gpu/nova-core/gsp/fw.rs
@@ -37,6 +37,7 @@
};

use crate::{
+ bounded_enum,
fb::{
FbRanges,
FbSizes, //
@@ -906,6 +907,111 @@ pub(crate) fn function(&self) -> Result<MsgFunction, u32> {
}
}

+bounded_enum! {
+ /// Commands of the GMC API.
+ #[derive(Debug, Clone, Copy, PartialEq, Eq)]
+ #[repr(u32)]
+ pub(crate) enum GmcCommandId with TryFrom<Bounded<u32, 24>> {
+ GspInit = r000_00::GMCAPI_COMMANDS_GMCAPI_CMD_GSP_INIT,
+ ExecGenericBootloader = r000_00::GMCAPI_COMMANDS_GMCAPI_CMD_EXEC_GENERIC_BOOTLOADER,
+ ExecHsBinary = r000_00::GMCAPI_COMMANDS_GMCAPI_CMD_EXEC_HS_BINARY,
+ GspSuspend = r000_00::GMCAPI_COMMANDS_GMCAPI_CMD_GSP_SUSPEND,
+ MmuFaultQueued = r000_00::GMCAPI_COMMANDS_GMCAPI_CMD_MMU_FAULT_QUEUED,
+ }
+}
+
+bitfield! {
+ /// The `command` word of a [`GmcApiHeader`].
+ pub(crate) struct GmcCommandWord(u32) {
+ /// Command ID.
+ 23:0 id ?=> GmcCommandId;
+ /// Set by GSP-RM on the response to a request. Not set for requests and events.
+ 24:24 is_response => bool;
+ }
+}
+
+/// Header of a GMC (GPU Management Controller) API message.
+///
+/// In a queue element, it follows the queue element header and precedes the payload of the
+/// command.
+#[repr(transparent)]
+#[expect(dead_code)]
+pub(crate) struct GmcApiHeader {
+ inner: r000_00::GMCAPI_HEADER,
+}
+
+#[expect(dead_code)]
+impl GmcApiHeader {
+ /// Creates the header of a request for `command`, sent with sequence number `sequence` and
+ /// followed by `payload_size` bytes of payload.
+ ///
+ /// `max_reply_size` is the largest reply the sender accepts, and zero for a request that
+ /// GSP-RM does not answer.
+ ///
+ /// # Errors
+ ///
+ /// - `EOVERFLOW` if `payload_size` does not fit its 32-bit field.
+ pub(crate) fn init(
+ command: GmcCommandId,
+ sequence: u64,
+ payload_size: usize,
+ max_reply_size: u32,
+ ) -> impl Init<Self, Error> {
+ let init_inner = try_init!(r000_00::GMCAPI_HEADER {
+ command: GmcCommandWord::zeroed().with_id(command).into(),
+ size: payload_size.try_into().map_err(|_| EOVERFLOW)?,
+ sequence,
+ __bindgen_anon_1: r000_00::GMCAPI_HEADER__bindgen_ty_1 {
+ request: r000_00::GMCAPI_HEADER__bindgen_ty_1__bindgen_ty_1 {
+ max_response_size: max_reply_size,
+ },
+ },
+ ..Zeroable::init_zeroed()
+ });
+
+ try_init!(GmcApiHeader {
+ inner <- init_inner,
+ })
+ }
+
+ /// Returns the `command` word of the header.
+ pub(crate) fn command(&self) -> GmcCommandWord {
+ GmcCommandWord::from(self.inner.command)
+ }
+
+ /// Returns the sequence number of the message.
+ pub(crate) fn sequence(&self) -> u64 {
+ self.inner.sequence
+ }
+
+ /// Returns the size in bytes of the payload following the header.
+ pub(crate) fn payload_size(&self) -> usize {
+ num::u32_as_usize(self.inner.size)
+ }
+
+ /// Returns the `NV_STATUS` carried by a response to a command.
+ ///
+ /// Returns `Some` with the `NV_STATUS` code if the `response` flag of [`Self::command`] is set;
+ /// otherwise returns `None`.
+ pub(crate) fn status(&self) -> Option<u32> {
+ if self.command().is_response() {
+ // SAFETY: we just checked that the message is a response.
+ let status = unsafe { self.inner.__bindgen_anon_1.response.status };
+
+ Some(status)
+ } else {
+ None
+ }
+ }
+}
+
+// SAFETY: This struct only contains integer types, including inside its union, and a zero-sized
+// array. It has no padding.
+unsafe impl AsBytes for GmcApiHeader {}
+
+// SAFETY: This struct only contains integer types for which all bit patterns are valid.
+unsafe impl FromBytes for GmcApiHeader {}
+
/// Arguments for GSP startup.
#[repr(transparent)]
#[derive(Zeroable)]

--
2.56.0