public inbox for rust-for-linux@vger.kernel.org
 help / color / mirror / Atom feed
From: Eliot Courtney <ecourtney@nvidia.com>
To: Danilo Krummrich <dakr@kernel.org>,
	Alice Ryhl <aliceryhl@google.com>,
	 Alexandre Courbot <acourbot@nvidia.com>,
	David Airlie <airlied@gmail.com>,
	 Simona Vetter <simona@ffwll.ch>
Cc: John Hubbard <jhubbard@nvidia.com>,
	 Alistair Popple <apopple@nvidia.com>,
	 Joel Fernandes <joelagnelf@nvidia.com>,
	Timur Tabi <ttabi@nvidia.com>,
	 rust-for-linux@vger.kernel.org, dri-devel@lists.freedesktop.org,
	 linux-kernel@vger.kernel.org,
	Eliot Courtney <ecourtney@nvidia.com>
Subject: [PATCH v3 7/9] gpu: nova-core: gsp: add RM control command infrastructure
Date: Wed, 25 Mar 2026 21:13:45 +0900	[thread overview]
Message-ID: <20260325-rmcontrol-v3-7-f3101093484e@nvidia.com> (raw)
In-Reply-To: <20260325-rmcontrol-v3-0-f3101093484e@nvidia.com>

Add `RawRmControl` which implements CommandToGsp for sending RM control
RPCs. Add `RmControlReply` which implements MessageFromGsp for getting
the reply back. Add the `RmControlCommand` trait for defining an RM
control message.

Add `RmControl` which sends an RM control RPC via the command queue
using the above structures.

This gives a generic way to send each RM control RPC. Each new RM
control RPC can be added by extending RmControlMsgFunction, adding its
bindings wrappers and writing an implementation of `RmControlCommand`
that can be sent using `RmControl`.

Signed-off-by: Eliot Courtney <ecourtney@nvidia.com>
---
 drivers/gpu/nova-core/gsp.rs             |   1 +
 drivers/gpu/nova-core/gsp/fw/rm.rs       |   1 -
 drivers/gpu/nova-core/gsp/rm.rs          |   3 +
 drivers/gpu/nova-core/gsp/rm/commands.rs | 141 +++++++++++++++++++++++++++++++
 4 files changed, 145 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/nova-core/gsp.rs b/drivers/gpu/nova-core/gsp.rs
index 04e3976127cc..09d6e673aa65 100644
--- a/drivers/gpu/nova-core/gsp.rs
+++ b/drivers/gpu/nova-core/gsp.rs
@@ -21,6 +21,7 @@
 pub(crate) mod cmdq;
 pub(crate) mod commands;
 mod fw;
+pub(crate) mod rm;
 mod sequencer;
 
 pub(crate) use fw::{
diff --git a/drivers/gpu/nova-core/gsp/fw/rm.rs b/drivers/gpu/nova-core/gsp/fw/rm.rs
index 4a4f97d88ecf..1c6e8b4c4865 100644
--- a/drivers/gpu/nova-core/gsp/fw/rm.rs
+++ b/drivers/gpu/nova-core/gsp/fw/rm.rs
@@ -53,7 +53,6 @@ pub(crate) struct GspRmControl {
     inner: bindings::rpc_gsp_rm_control_v03_00,
 }
 
-#[expect(dead_code)]
 impl GspRmControl {
     /// Creates a new RM control command.
     pub(crate) fn new<T>(
diff --git a/drivers/gpu/nova-core/gsp/rm.rs b/drivers/gpu/nova-core/gsp/rm.rs
new file mode 100644
index 000000000000..10e879a3e842
--- /dev/null
+++ b/drivers/gpu/nova-core/gsp/rm.rs
@@ -0,0 +1,3 @@
+// SPDX-License-Identifier: GPL-2.0
+
+pub(crate) mod commands;
diff --git a/drivers/gpu/nova-core/gsp/rm/commands.rs b/drivers/gpu/nova-core/gsp/rm/commands.rs
new file mode 100644
index 000000000000..8845ca0a0225
--- /dev/null
+++ b/drivers/gpu/nova-core/gsp/rm/commands.rs
@@ -0,0 +1,141 @@
+// SPDX-License-Identifier: GPL-2.0
+
+use core::array;
+
+use kernel::prelude::*;
+
+use crate::{
+    driver::Bar0,
+    gsp::{
+        cmdq::{
+            Cmdq,
+            CommandToGsp,
+            MessageFromGsp, //
+        },
+        commands::{
+            Client,
+            Handle, //
+        },
+        fw::{
+            rm::*,
+            MsgFunction,
+            NvStatus, //
+        },
+    },
+    sbuffer::SBufferIter, //
+};
+
+/// Wraps a [`RmControl`] command to provide the infrastructure for sending it on the command queue.
+struct RawRmControl<'a, T>(&'a RmControl<T>)
+where
+    T: RmControlCommand;
+
+impl<'a, T: RmControlCommand> CommandToGsp for RawRmControl<'a, T> {
+    const FUNCTION: MsgFunction = MsgFunction::GspRmControl;
+    type Command = GspRmControl;
+    type Reply = RmControlReply;
+    type InitError = Error;
+
+    fn init(&self) -> impl Init<Self::Command, Self::InitError> {
+        let params_size: u32 = T::LEN.try_into()?;
+        Ok(GspRmControl::new(
+            self.0.client,
+            self.0.object,
+            T::FUNCTION,
+            params_size,
+        ))
+    }
+
+    fn variable_payload_len(&self) -> usize {
+        T::LEN
+    }
+
+    fn init_variable_payload(
+        &self,
+        dst: &mut SBufferIter<array::IntoIter<&mut [u8], 2>>,
+    ) -> Result {
+        self.0.cmd.write_payload(dst)
+    }
+}
+
+/// Command for sending an RM control message to the GSP.
+///
+/// RM control messages are used to query or control RM objects (see [`Handle`] for more info on RM
+/// objects). It takes a client handle and an RM object handle identifying the target of the
+/// message, within the given client.
+pub(crate) struct RmControl<T>
+where
+    T: RmControlCommand,
+{
+    /// The client handle under which `object` is allocated.
+    client: Handle<Client>,
+    /// The RM object handle to query or control.
+    object: Handle<T::Target>,
+    /// The specific RM control command to send.
+    cmd: T,
+}
+
+#[expect(unused)]
+impl<T: RmControlCommand> RmControl<T> {
+    /// Creates a new RM control command.
+    pub(crate) fn new(client: Handle<Client>, object: Handle<T::Target>, cmd: T) -> Self {
+        Self {
+            client,
+            object,
+            cmd,
+        }
+    }
+
+    /// Sends an RM control command, checks the reply status, and returns the reply.
+    pub(crate) fn send(self, cmdq: &Cmdq, bar: &Bar0) -> Result<T::Reply> {
+        let reply = cmdq.send_command(bar, RawRmControl(&self))?;
+
+        Result::from(reply.status)?;
+
+        self.cmd.parse_reply(&reply.params)
+    }
+}
+
+/// Response from an RM control message.
+struct RmControlReply {
+    status: NvStatus,
+    params: KVVec<u8>,
+}
+
+impl MessageFromGsp for RmControlReply {
+    const FUNCTION: MsgFunction = MsgFunction::GspRmControl;
+    type Message = GspRmControl;
+    type InitError = Error;
+
+    fn read(
+        msg: &Self::Message,
+        sbuffer: &mut SBufferIter<array::IntoIter<&[u8], 2>>,
+    ) -> Result<Self, Self::InitError> {
+        Ok(RmControlReply {
+            status: msg.status(),
+            params: sbuffer.read_to_vec(GFP_KERNEL)?,
+        })
+    }
+}
+
+/// Trait for RM control commands that can be sent using [`RmControl`].
+pub(crate) trait RmControlCommand {
+    /// The specific RM control message kind to send.
+    const FUNCTION: RmControlMsgFunction;
+
+    /// Length of the command-specific payload to send with the RM control message.
+    const LEN: usize;
+
+    /// The type of the reply after parsing the raw bytes from the RM control reply message.
+    type Reply;
+
+    /// The type of the RM object that this command targets.
+    type Target;
+
+    /// Writes the payload of the command into `dst`.
+    fn write_payload(&self, dst: &mut SBufferIter<array::IntoIter<&mut [u8], 2>>) -> Result;
+
+    /// Parses the reply bytes from an RM control reply message into the command-specific
+    /// reply type.
+    fn parse_reply(&self, params: &[u8]) -> Result<Self::Reply>;
+}

-- 
2.53.0


  parent reply	other threads:[~2026-03-25 12:14 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-25 12:13 [PATCH v3 0/9] gpu: nova-core: gsp: add RM control command infrastructure Eliot Courtney
2026-03-25 12:13 ` [PATCH v3 1/9] gpu: nova-core: gsp: add NV_STATUS error code bindings Eliot Courtney
2026-04-05 19:55   ` John Hubbard
2026-04-06  8:54     ` Eliot Courtney
2026-04-06 19:05       ` John Hubbard
2026-03-25 12:13 ` [PATCH v3 2/9] gpu: nova-core: gsp: add NvStatus enum for RM control errors Eliot Courtney
2026-04-05 20:05   ` John Hubbard
2026-04-06 12:09     ` Eliot Courtney
2026-04-06 19:02       ` John Hubbard
2026-03-25 12:13 ` [PATCH v3 3/9] gpu: nova-core: gsp: expose GSP-RM internal client and subdevice handles Eliot Courtney
2026-03-25 12:13 ` [PATCH v3 4/9] gpu: nova-core: gsp: add RM control RPC structure binding Eliot Courtney
2026-03-25 12:13 ` [PATCH v3 5/9] gpu: nova-core: gsp: add types for RM control RPCs Eliot Courtney
2026-03-25 12:13 ` [PATCH v3 6/9] gpu: nova-core: use KVVec for SBufferIter flush Eliot Courtney
2026-03-25 12:13 ` Eliot Courtney [this message]
2026-03-25 12:13 ` [PATCH v3 8/9] gpu: nova-core: gsp: add CE fault method buffer size bindings Eliot Courtney
2026-03-25 12:13 ` [PATCH v3 9/9] gpu: nova-core: gsp: add FaultMethodBufferSize RM control command Eliot Courtney
2026-04-05 20:12   ` John Hubbard
2026-04-06  2:30     ` Eliot Courtney
2026-04-05 19:48 ` [PATCH v3 0/9] gpu: nova-core: gsp: add RM control command infrastructure John Hubbard
2026-04-06  2:29   ` 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=20260325-rmcontrol-v3-7-f3101093484e@nvidia.com \
    --to=ecourtney@nvidia.com \
    --cc=acourbot@nvidia.com \
    --cc=airlied@gmail.com \
    --cc=aliceryhl@google.com \
    --cc=apopple@nvidia.com \
    --cc=dakr@kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=jhubbard@nvidia.com \
    --cc=joelagnelf@nvidia.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=simona@ffwll.ch \
    --cc=ttabi@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