Rust for Linux List
 help / color / mirror / Atom feed
From: John Hubbard <jhubbard@nvidia.com>
To: Danilo Krummrich <dakr@kernel.org>,
	Alexandre Courbot <acourbot@nvidia.com>
Cc: "Timur Tabi" <ttabi@nvidia.com>,
	"Alistair Popple" <apopple@nvidia.com>,
	"Eliot Courtney" <ecourtney@nvidia.com>,
	"Zhi Wang" <zhiw@nvidia.com>, "David Airlie" <airlied@gmail.com>,
	"Simona Vetter" <simona@ffwll.ch>,
	"Bjorn Helgaas" <bhelgaas@google.com>,
	"Miguel Ojeda" <ojeda@kernel.org>,
	"Boqun Feng" <boqun@kernel.org>, "Gary Guo" <gary@garyguo.net>,
	"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
	"Benno Lossin" <lossin@kernel.org>,
	"Andreas Hindborg" <a.hindborg@kernel.org>,
	"Alice Ryhl" <aliceryhl@google.com>,
	"Trevor Gross" <tmgross@umich.edu>,
	"Daniel Almeida" <daniel.almeida@collabora.com>,
	"Tamir Duberstein" <tamird@kernel.org>,
	"Onur Özkan" <work@onurozkan.dev>,
	nova-gpu@lists.linux.dev, dri-devel@lists.freedesktop.org,
	LKML <linux-kernel@vger.kernel.org>,
	linux-pci@vger.kernel.org, rust-for-linux@vger.kernel.org,
	"John Hubbard" <jhubbard@nvidia.com>
Subject: [PATCH 9/9] gpu: nova-core: gsp: add the load-and-execute event dispatcher
Date: Thu, 19 Nov 2026 20:47:04 -0800	[thread overview]
Message-ID: <20261120044704.165223-10-jhubbard@nvidia.com> (raw)
In-Reply-To: <20261120044704.165223-1-jhubbard@nvidia.com>

The two load-and-execute events of the r000 boot protocol arrive as GMC
events, and the command ID of a GMC event names its kind. Nova-core has
a handler for each of the two events, and no code that selects the
handler from the command ID.

Add a dispatcher that selects the handler from the command ID of a GMC
event, decodes the payload of the event into the parameters of that
handler, and rejects an event with any other command ID.

Co-developed-by: Alexandre Courbot <acourbot@nvidia.com>
Signed-off-by: Alexandre Courbot <acourbot@nvidia.com>
Signed-off-by: John Hubbard <jhubbard@nvidia.com>
---
 drivers/gpu/nova-core/gsp/load_exec.rs | 64 ++++++++++++++++++++++++--
 1 file changed, 61 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/nova-core/gsp/load_exec.rs b/drivers/gpu/nova-core/gsp/load_exec.rs
index ab0c2959d3e8..5fef09f16185 100644
--- a/drivers/gpu/nova-core/gsp/load_exec.rs
+++ b/drivers/gpu/nova-core/gsp/load_exec.rs
@@ -38,7 +38,11 @@
         GenericBootloader, //
     },
     gsp::{
-        cmdq::gmc::MessageFromGsp,
+        cmdq::gmc::{
+            GmcMessage,
+            MessageFromGsp, //
+        },
+        fw::GmcCommandId,
         GspBootContext, //
     },
     sbuffer::SBufferIter, //
@@ -116,6 +120,62 @@ pub(super) fn resume_gsp_rm(
     Ok(())
 }
 
+/// Runs the handler of the load-and-execute event `event`.
+///
+/// The command ID of `event` selects the handler, and the payload of `event` holds the parameters
+/// of that handler. `bootloader` is the generic falcon bootloader, which the handler of a
+/// `GMCAPI_CMD_EXEC_GENERIC_BOOTLOADER` event requires. Each handler ends in [`resume_gsp_rm`],
+/// which receives `libos_dma_address` and `bootloader_app_version`.
+///
+/// # Errors
+///
+/// - `EINVAL` if the command ID of `event` is not that of a load-and-execute event, or if the
+///   payload of `event` is shorter than the parameters of the handler.
+///
+/// Errors from the handlers are propagated as-is.
+#[expect(dead_code)]
+pub(super) fn handle_event(
+    ctx: &GspBootContext<'_, '_>,
+    bootloader: Option<&GenericBootloader>,
+    libos_dma_address: DmaAddress,
+    bootloader_app_version: u32,
+    event: &GmcMessage<'_>,
+) -> Result {
+    let dev = ctx.dev();
+    let command = event.header().command();
+    let (slice_1, slice_2) = event.payload();
+    let mut payload = SBufferIter::new_reader([slice_1, slice_2]);
+
+    let (id, result) = match command.id() {
+        Ok(id @ GmcCommandId::ExecGenericBootloader) => (
+            id,
+            GenericBootloaderParams::read(&mut payload).and_then(|params| {
+                handle_generic_bootloader(
+                    ctx,
+                    bootloader,
+                    libos_dma_address,
+                    bootloader_app_version,
+                    &params,
+                )
+            }),
+        ),
+        Ok(id @ GmcCommandId::ExecHsBinary) => (
+            id,
+            HsBinaryParams::read(&mut payload).and_then(|params| {
+                handle_hs_binary(ctx, libos_dma_address, bootloader_app_version, &params)
+            }),
+        ),
+        _ => {
+            dev_err!(dev, "Not a load-and-execute event: {:?}\n", command);
+            return Err(EINVAL);
+        }
+    };
+
+    result.inspect_err(|e| {
+        dev_err!(dev, "Load-and-execute event {:?} failed: {:?}\n", id, e);
+    })
+}
+
 /// Waits until GSP-RM has suspended the RISC-V core, and then resets the GSP falcon.
 fn reset_gsp_falcon_after_suspend(dev: &device::Device, gsp_falcon: &Falcon<'_, Gsp>) -> Result {
     gsp_falcon.wait_for_processor_suspend().inspect_err(|_| {
@@ -159,7 +219,6 @@ fn reset_gsp_falcon_after_suspend(dev: &device::Device, gsp_falcon: &Falcon<'_,
 ///
 /// Errors from the reset of the GSP falcon, the DMA transfers and the resume of GSP-RM are
 /// propagated as-is.
-#[expect(dead_code)]
 fn handle_hs_binary(
     ctx: &GspBootContext<'_, '_>,
     libos_dma_address: DmaAddress,
@@ -260,7 +319,6 @@ fn handle_hs_binary(
 ///
 /// Errors from the reset of the GSP falcon, the run of the bootloader and the resume of GSP-RM
 /// are propagated as-is.
-#[expect(dead_code)]
 fn handle_generic_bootloader(
     ctx: &GspBootContext<'_, '_>,
     bootloader: Option<&GenericBootloader>,
-- 
2.56.1


      parent reply	other threads:[~2026-11-20  4:47 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-20  4:46 [PATCH 0/9] gpu: nova-core: run falcon binaries for the r000 GSP-RM John Hubbard
2026-11-20  4:46 ` [PATCH 1/9] rust: pci: add domain_nr() accessor John Hubbard
2026-11-20  4:46 ` [PATCH 2/9] gpu: nova-core: falcon: factor out the wait for the GSP suspend John Hubbard
2026-11-20  4:46 ` [PATCH 3/9] gpu: nova-core: falcon: factor out the BROM and BOOTVEC programming John Hubbard
2026-11-20  4:46 ` [PATCH 4/9] gpu: nova-core: gsp: factor out the core reset and the core resume John Hubbard
2026-11-20  4:47 ` [PATCH 5/9] gpu: nova-core: gsp: fix resume_gsp_rm()'s error messages John Hubbard
2026-11-20  4:47 ` [PATCH 6/9] gpu: nova-core: falcon: select the BAR2 engine ID for framebuffer DMA John Hubbard
2026-11-20  4:47 ` [PATCH 7/9] gpu: nova-core: gsp: add the r000 load-and-execute HS binary handler John Hubbard
2026-11-20  4:47 ` [PATCH 8/9] gpu: nova-core: gsp: add the r000 load-and-execute bootloader handler John Hubbard
2026-11-20  4:47 ` John Hubbard [this message]

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=20261120044704.165223-10-jhubbard@nvidia.com \
    --to=jhubbard@nvidia.com \
    --cc=a.hindborg@kernel.org \
    --cc=acourbot@nvidia.com \
    --cc=airlied@gmail.com \
    --cc=aliceryhl@google.com \
    --cc=apopple@nvidia.com \
    --cc=bhelgaas@google.com \
    --cc=bjorn3_gh@protonmail.com \
    --cc=boqun@kernel.org \
    --cc=dakr@kernel.org \
    --cc=daniel.almeida@collabora.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=ecourtney@nvidia.com \
    --cc=gary@garyguo.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=lossin@kernel.org \
    --cc=nova-gpu@lists.linux.dev \
    --cc=ojeda@kernel.org \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=simona@ffwll.ch \
    --cc=tamird@kernel.org \
    --cc=tmgross@umich.edu \
    --cc=ttabi@nvidia.com \
    --cc=work@onurozkan.dev \
    --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