From: Alexandre Courbot <acourbot@nvidia.com>
To: Danilo Krummrich <dakr@kernel.org>,
Alice Ryhl <aliceryhl@google.com>,
David Airlie <airlied@gmail.com>,
Simona Vetter <simona@ffwll.ch>,
Benno Lossin <lossin@kernel.org>, Gary Guo <gary@garyguo.net>
Cc: John Hubbard <jhubbard@nvidia.com>,
Alistair Popple <apopple@nvidia.com>,
Timur Tabi <ttabi@nvidia.com>,
Eliot Courtney <ecourtney@nvidia.com>,
Zhi Wang <zhiw@nvidia.com>,
linux-kernel@vger.kernel.org, nova-gpu@lists.linux.dev,
rust-for-linux@vger.kernel.org,
Alexandre Courbot <acourbot@nvidia.com>
Subject: [PATCH v2 2/6] gpu: nova-core: gsp: add the GMC API header
Date: Fri, 06 Nov 2026 16:06:10 +0900 [thread overview]
Message-ID: <20261106-r000_rebase_on_cmdq-rpc-v2-2-e481ea2168ef@nvidia.com> (raw)
In-Reply-To: <20261106-r000_rebase_on_cmdq-rpc-v2-0-e481ea2168ef@nvidia.com>
From: John Hubbard <jhubbard@nvidia.com>
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.]
Signed-off-by: John Hubbard <jhubbard@nvidia.com>
Co-developed-by: Alexandre Courbot <acourbot@nvidia.com>
Signed-off-by: Alexandre Courbot <acourbot@nvidia.com>
Reviewed-by: Eliot Courtney <ecourtney@nvidia.com>
---
drivers/gpu/nova-core/gsp/fw.rs | 105 ++++++++++++++++++++++++++++++++++++++++
1 file changed, 105 insertions(+)
diff --git a/drivers/gpu/nova-core/gsp/fw.rs b/drivers/gpu/nova-core/gsp/fw.rs
index 213ef5bfb258..08f97c4e73a0 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,110 @@ 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)]
+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. It is zero for a request that does
+ /// not expect a reply or expects a reply with an empty payload (i.e. just the status value).
+ ///
+ /// # 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
next prev parent reply other threads:[~2026-11-06 7:06 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-06 7:06 [PATCH v2 0/6] gpu: nova-core: gsp: add support for GMC messages Alexandre Courbot
2026-11-06 7:06 ` [PATCH v2 1/6] gpu: nova-core: gsp: fw: add the r000 bindings for the GMC API header Alexandre Courbot
2026-11-06 7:06 ` Alexandre Courbot [this message]
2026-11-06 7:06 ` [PATCH v2 3/6] gpu: nova-core: gsp: cmdq: add the GMC send path Alexandre Courbot
2026-11-06 7:06 ` [PATCH v2 4/6] gpu: nova-core: gsp: cmdq: move message trimming into its own function Alexandre Courbot
2026-11-06 9:08 ` Eliot Courtney
2026-11-06 7:06 ` [PATCH v2 5/6] gpu: nova-core: gsp: cmdq: do not use ENOMSG to skip messages Alexandre Courbot
2026-11-06 9:09 ` Eliot Courtney
2026-11-06 7:06 ` [PATCH v2 6/6] gpu: nova-core: gsp: cmdq: add the GMC receive path Alexandre Courbot
2026-11-06 9:38 ` Eliot Courtney
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261106-r000_rebase_on_cmdq-rpc-v2-2-e481ea2168ef@nvidia.com \
--to=acourbot@nvidia.com \
--cc=airlied@gmail.com \
--cc=aliceryhl@google.com \
--cc=apopple@nvidia.com \
--cc=dakr@kernel.org \
--cc=ecourtney@nvidia.com \
--cc=gary@garyguo.net \
--cc=jhubbard@nvidia.com \
--cc=linux-kernel@vger.kernel.org \
--cc=lossin@kernel.org \
--cc=nova-gpu@lists.linux.dev \
--cc=rust-for-linux@vger.kernel.org \
--cc=simona@ffwll.ch \
--cc=ttabi@nvidia.com \
--cc=zhiw@nvidia.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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®