public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: "Danilo Krummrich" <dakr@kernel.org>
To: "Eliot Courtney" <ecourtney@nvidia.com>
Cc: "Alice Ryhl" <aliceryhl@google.com>,
	"Alexandre Courbot" <acourbot@nvidia.com>,
	"David Airlie" <airlied@gmail.com>,
	"Simona Vetter" <simona@ffwll.ch>,
	"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>,
	"Zhi Wang" <zhiw@nvidia.com>
Subject: Re: [PATCH v2 7/9] gpu: nova-core: gsp: add RM control command infrastructure
Date: Wed, 18 Mar 2026 13:35:30 +0100	[thread overview]
Message-ID: <DH5WURVBQNI5.1ZO9K0IR3PEOQ@kernel.org> (raw)
In-Reply-To: <20260318-rmcontrol-v2-7-9a9fa6f1c4c3@nvidia.com>

On Wed Mar 18, 2026 at 8:14 AM CET, Eliot Courtney wrote:
> Add `RmControl` which implements CommandToGsp for sending RM control
> RPCs.
>
> Add `RmControlReply` which implements MessageFromGsp for getting the
> reply back.
>
> Add `send_rm_control` 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 and adding
> its bindings wrappers and writing a helper function to send it via
> `send_rm_control`.
>
> Tested-by: Zhi Wang <zhiw@nvidia.com>
> 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 | 118 +++++++++++++++++++++++++++++++
>  4 files changed, 122 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/nova-core/gsp.rs b/drivers/gpu/nova-core/gsp.rs
> index 72f173726f87..14c734c53e7c 100644
> --- a/drivers/gpu/nova-core/gsp.rs
> +++ b/drivers/gpu/nova-core/gsp.rs
> @@ -17,6 +17,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..5a3ac7bd415a
> --- /dev/null
> +++ b/drivers/gpu/nova-core/gsp/rm/commands.rs
> @@ -0,0 +1,118 @@
> +// SPDX-License-Identifier: GPL-2.0
> +
> +use core::{
> +    array,
> +    convert::Infallible, //
> +};
> +
> +use kernel::prelude::*;
> +
> +use crate::{
> +    driver::Bar0,
> +    gsp::{
> +        cmdq::{
> +            Cmdq,
> +            CommandToGsp,
> +            MessageFromGsp, //
> +        },
> +        commands::{
> +            Client,
> +            Handle, //
> +        },
> +        fw::{
> +            rm::*,
> +            MsgFunction,
> +            NvStatus, //
> +        },
> +    },
> +    sbuffer::SBufferIter,
> +};
> +
> +/// 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.
> +struct RmControl<'a, T> {
> +    /// The client handle under which `object` is allocated.
> +    client: Handle<Client>,
> +    /// The RM object handle to query or control.
> +    object: Handle<T>,
> +    /// The specific control message to send.
> +    cmd: RmControlMsgFunction,
> +    /// The raw parameter bytes to send with the control message. Interpretation of these bytes is
> +    /// specific to the control message being sent.
> +    params: &'a [u8],
> +}
> +
> +impl<'a, T> RmControl<'a, T> {
> +    /// Creates a new RM control command.
> +    #[expect(dead_code)]
> +    fn new(
> +        client: Handle<Client>,
> +        object: Handle<T>,
> +        cmd: RmControlMsgFunction,
> +        params: &'a [u8],
> +    ) -> Self {
> +        Self {
> +            client,
> +            object,
> +            cmd,
> +            params,
> +        }
> +    }
> +}
> +
> +impl<T> CommandToGsp for RmControl<'_, T> {
> +    const FUNCTION: MsgFunction = MsgFunction::GspRmControl;
> +    type Command = GspRmControl;
> +    type Reply = RmControlReply;
> +    type InitError = Infallible;
> +
> +    fn init(&self) -> impl Init<Self::Command, Self::InitError> {
> +        GspRmControl::new(self.client, self.object, self.cmd, self.params.len() as u32)
> +    }
> +
> +    fn variable_payload_len(&self) -> usize {
> +        self.params.len()
> +    }
> +
> +    fn init_variable_payload(
> +        &self,
> +        dst: &mut SBufferIter<array::IntoIter<&mut [u8], 2>>,
> +    ) -> Result {
> +        dst.write_all(self.params)
> +    }
> +}
> +
> +/// Response from an RM control message.
> +pub(crate) 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)?,
> +        })
> +    }
> +}
> +
> +/// Sends an RM control command, checks the reply status, and returns the raw parameter bytes.
> +#[expect(dead_code)]
> +fn send_rm_control<T>(cmdq: &Cmdq, bar: &Bar0, cmd: RmControl<'_, T>) -> Result<KVVec<u8>> {
> +    let reply = cmdq.send_command(bar, cmd)?;
> +
> +    Result::from(reply.status)?;
> +
> +    Ok(reply.params)
> +}

It still feels wrong to me for this to be a standalone function.

It should either be a method of Cmdq, or it should be a method of RmControl,
that takes self by value, i.e. either Cmdq::send_rm_ctrl() or RmControl::send().

Please choose one of those options.

  reply	other threads:[~2026-03-18 12:35 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-18  7:13 [PATCH v2 0/9] gpu: nova-core: gsp: add RM control command infrastructure Eliot Courtney
2026-03-18  7:13 ` [PATCH v2 1/9] gpu: nova-core: gsp: add NV_STATUS error code bindings Eliot Courtney
2026-03-20  4:10   ` Alistair Popple
2026-03-18  7:13 ` [PATCH v2 2/9] gpu: nova-core: gsp: add NvStatus enum for RM control errors Eliot Courtney
2026-03-18  7:13 ` [PATCH v2 3/9] gpu: nova-core: gsp: expose GSP-RM internal client and subdevice handles Eliot Courtney
2026-03-18  7:14 ` [PATCH v2 4/9] gpu: nova-core: gsp: add RM control RPC structure binding Eliot Courtney
2026-03-20  4:19   ` Alistair Popple
2026-03-18  7:14 ` [PATCH v2 5/9] gpu: nova-core: gsp: add types for RM control RPCs Eliot Courtney
2026-03-20  4:26   ` Alistair Popple
2026-03-18  7:14 ` [PATCH v2 6/9] gpu: nova-core: use KVVec for SBufferIter flush Eliot Courtney
2026-03-20  4:32   ` Alistair Popple
2026-03-25  7:43     ` Eliot Courtney
2026-03-18  7:14 ` [PATCH v2 7/9] gpu: nova-core: gsp: add RM control command infrastructure Eliot Courtney
2026-03-18 12:35   ` Danilo Krummrich [this message]
2026-03-19  1:06     ` Eliot Courtney
2026-03-20 14:42       ` Alexandre Courbot
2026-03-25  3:28         ` Eliot Courtney
2026-03-18  7:14 ` [PATCH v2 8/9] gpu: nova-core: gsp: add CE fault method buffer size bindings Eliot Courtney
2026-03-18  7:14 ` [PATCH v2 9/9] gpu: nova-core: gsp: add CeGetFaultMethodBufferSize RM control command Eliot Courtney
2026-03-20 13:27   ` Danilo Krummrich
2026-03-25 12:13     ` 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=DH5WURVBQNI5.1ZO9K0IR3PEOQ@kernel.org \
    --to=dakr@kernel.org \
    --cc=acourbot@nvidia.com \
    --cc=airlied@gmail.com \
    --cc=aliceryhl@google.com \
    --cc=apopple@nvidia.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=ecourtney@nvidia.com \
    --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 \
    --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