mirror of https://lore.kernel.org/lkml/
 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 8/9] gpu: nova-core: gsp: add the r000 load-and-execute bootloader handler
Date: Thu, 19 Nov 2026 20:47:03 -0800	[thread overview]
Message-ID: <20261120044704.165223-9-jhubbard@nvidia.com> (raw)
In-Reply-To: <20261120044704.165223-1-jhubbard@nvidia.com>

On Turing and GA100, the r000 GSP-RM requires an image to run on the
falcon core during boot, through the generic falcon bootloader. GSP-RM
is suspended while the image runs.

The driver runs the image on behalf of GSP-RM, in the following steps:

1. GSP-RM raises a load-and-execute event, which carries a descriptor of
   the image.
2. GSP-RM suspends the RISC-V core.
3. The driver waits until the RISC-V core is suspended.
4. The driver resets the GSP falcon, which selects the falcon core.
5. The driver loads the bootloader and the descriptor into the GSP
   falcon.
6. The driver starts the bootloader, which loads the image and starts
   it.
7. The driver waits for the falcon core to halt.
8. The driver resumes GSP-RM on the RISC-V core.

Nova-core has no handler for the bootloader's load-and-execute event.

Add the handler, which performs steps 3 through 8.

Co-developed-by: Alexandre Courbot <acourbot@nvidia.com>
Signed-off-by: Alexandre Courbot <acourbot@nvidia.com>
Signed-off-by: John Hubbard <jhubbard@nvidia.com>
---
 .../gpu/nova-core/firmware/gen_bootloader.rs  |   8 +-
 drivers/gpu/nova-core/gsp/load_exec.rs        | 164 +++++++++++++++++-
 2 files changed, 170 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/nova-core/firmware/gen_bootloader.rs b/drivers/gpu/nova-core/firmware/gen_bootloader.rs
index 751335c97e35..8d8c94cc19ee 100644
--- a/drivers/gpu/nova-core/firmware/gen_bootloader.rs
+++ b/drivers/gpu/nova-core/firmware/gen_bootloader.rs
@@ -13,7 +13,10 @@
     },
     prelude::*,
     ptr::Alignable,
-    transmute::AsBytes, //
+    transmute::{
+        AsBytes,
+        FromBytes, //
+    },
 };
 
 use crate::{
@@ -123,6 +126,9 @@ pub(crate) fn new(
 // SAFETY: This struct doesn't contain uninitialized bytes and doesn't have interior mutability.
 unsafe impl AsBytes for BootloaderDmemDescV2 {}
 
+// SAFETY: This struct only contains integer types for which all bit patterns are valid.
+unsafe impl FromBytes for BootloaderDmemDescV2 {}
+
 /// The generic falcon bootloader image and its IMEM load parameters.
 pub(crate) struct GenericBootloader {
     /// Bootloader code, zero-padded to a whole number of falcon memory blocks.
diff --git a/drivers/gpu/nova-core/gsp/load_exec.rs b/drivers/gpu/nova-core/gsp/load_exec.rs
index d9a4ccd88289..ab0c2959d3e8 100644
--- a/drivers/gpu/nova-core/gsp/load_exec.rs
+++ b/drivers/gpu/nova-core/gsp/load_exec.rs
@@ -9,7 +9,8 @@
 //!   that verifies an HS binary. The note in "Root of trust establishment" says why the GSP falcon
 //!   stops running GSP-RM, runs an HS binary, and then resumes GSP-RM.
 //! - "Falcon memory subsystem and DMA engine" describes the instruction memory (IMEM) and the data
-//!   memory (DMEM) of a falcon, and the DMA engine that loads a binary into them.
+//!   memory (DMEM) of a falcon, and the DMA engine that loads a binary into them. The DMA engine
+//!   accesses the framebuffer or system memory through the FBIF (Framebuffer Interface).
 
 use core::array;
 
@@ -29,8 +30,13 @@
         FalconBromParams,
         FalconDmaLoadTarget,
         FalconDmaSource,
+        FalconFbifTarget,
         FalconMem, //
     },
+    firmware::gen_bootloader::{
+        BootloaderDmemDescV2,
+        GenericBootloader, //
+    },
     gsp::{
         cmdq::gmc::MessageFromGsp,
         GspBootContext, //
@@ -223,6 +229,106 @@ fn handle_hs_binary(
     )
 }
 
+/// Runs the image of a `GMCAPI_CMD_EXEC_GENERIC_BOOTLOADER` event on the falcon core of the GSP
+/// falcon, through the generic falcon bootloader, and then resumes GSP-RM.
+///
+/// `params` holds the descriptor of the image. The generic falcon bootloader loads and starts the
+/// image that the descriptor names, per [`GenericBootloader::run`]. The handler:
+///
+/// 1. Checks that the descriptor in `params` has the size of [`BootloaderDmemDescV2`], and gets
+///    the FBIF (Framebuffer Interface) target that `params` selects.
+/// 2. Waits until GSP-RM has suspended the RISC-V core, for up to five seconds.
+/// 3. Resets the GSP falcon, which selects the falcon core.
+/// 4. Runs `bootloader` with the descriptor and with [`FLCN_ERR_BINARY_NOT_STARTED`] in
+///    `MAILBOX0`, and waits until the falcon core halts, for up to two seconds. The image halts
+///    the falcon core when it is done, so the handler learns from the halt that the image has
+///    finished.
+/// 5. Logs an error if `MAILBOX0` still holds [`FLCN_ERR_BINARY_NOT_STARTED`], which means that
+///    the image did not start.
+/// 6. Resumes GSP-RM on the RISC-V core, via [`resume_gsp_rm`].
+///
+/// An image that reports a status writes the status to `MAILBOX0` before it halts. The handler
+/// does not check that status, so the result does not depend on it.
+///
+/// # Errors
+///
+/// - `EINVAL` if `bootloader` is `None`, if the descriptor size in `params` is not the size of
+///   [`BootloaderDmemDescV2`], or if the address space and the cache attribute in `params` select
+///   no FBIF target.
+/// - `ETIMEDOUT` if GSP-RM has not suspended the RISC-V core within five seconds, or if the
+///   falcon core has not halted within two seconds of its start.
+///
+/// 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>,
+    libos_dma_address: DmaAddress,
+    bootloader_app_version: u32,
+    params: &GenericBootloaderParams,
+) -> Result {
+    /// Expected size of the descriptor, in bytes.
+    const DMEM_DESC_SIZE: u32 = cv!(size_of::<BootloaderDmemDescV2>());
+
+    let dev = ctx.dev();
+    let gsp_falcon = ctx.gsp_falcon;
+    let Some(bootloader) = bootloader else {
+        dev_err!(
+            dev,
+            "No generic bootloader for the load-and-execute event\n"
+        );
+        return Err(EINVAL);
+    };
+
+    if params.dmem_desc_size != DMEM_DESC_SIZE {
+        dev_err!(
+            dev,
+            "Generic bootloader descriptor is {} bytes, expected {}\n",
+            params.dmem_desc_size,
+            DMEM_DESC_SIZE
+        );
+        return Err(EINVAL);
+    }
+
+    let fbif_target = params.fbif_target()?;
+
+    reset_gsp_falcon_after_suspend(dev, gsp_falcon)?;
+
+    let (mbox0, _) = bootloader
+        .run(
+            gsp_falcon,
+            &params.dmem_desc,
+            fbif_target,
+            FLCN_ERR_BINARY_NOT_STARTED,
+        )
+        .inspect_err(|e| {
+            dev_err!(
+                dev,
+                "Failed to run the generic bootloader: {:?} (mbox0={:#x})\n",
+                e,
+                gsp_falcon.read_mailbox0()
+            );
+        })?;
+    if mbox0 == FLCN_ERR_BINARY_NOT_STARTED {
+        dev_err!(dev, "Image of the generic bootloader did not start\n");
+    } else {
+        dev_dbg!(
+            dev,
+            "Image of the generic bootloader halted with mbox0={:#x}\n",
+            mbox0
+        );
+    }
+
+    resume_gsp_rm(
+        dev,
+        gsp_falcon,
+        ctx.sec2_falcon,
+        libos_dma_address,
+        bootloader_app_version,
+    )
+}
+
 /// Payload of a `GMCAPI_CMD_EXEC_HS_BINARY` event, which describes the HS binary to run.
 #[repr(C)]
 struct HsBinaryParams {
@@ -271,3 +377,59 @@ fn read(payload: &mut SBufferIter<array::IntoIter<&[u8], 2>>) -> Result<Self> {
         Self::from_bytes_copy(&bytes).ok_or(EINVAL)
     }
 }
+
+/// Payload of a `GMCAPI_CMD_EXEC_GENERIC_BOOTLOADER` event, which describes the image for the
+/// generic falcon bootloader to run.
+#[repr(C)]
+struct GenericBootloaderParams {
+    /// Descriptor of the image, which the bootloader reads from DMEM.
+    dmem_desc: BootloaderDmemDescV2,
+    /// Size in bytes of the descriptor, as GSP-RM defines it.
+    dmem_desc_size: u32,
+    /// Address space of the image: [`Self::ADDR_SYSMEM`] for system memory, or
+    /// [`Self::ADDR_FBMEM`] for the framebuffer.
+    addr_space: u32,
+    /// CPU cache attribute of an image in system memory: [`Self::NV_MEMORY_CACHED`] or
+    /// [`Self::NV_MEMORY_UNCACHED`].
+    cpu_cache_attrib: u32,
+    _reserved: [u32; 4],
+}
+
+impl GenericBootloaderParams {
+    const ADDR_SYSMEM: u32 = 1;
+    const ADDR_FBMEM: u32 = 2;
+    const NV_MEMORY_CACHED: u32 = 0;
+    const NV_MEMORY_UNCACHED: u32 = 1;
+
+    /// Returns the FBIF target that `addr_space` and `cpu_cache_attrib` select.
+    ///
+    /// # Errors
+    ///
+    /// - `EINVAL` if the pair selects no FBIF target.
+    fn fbif_target(&self) -> Result<FalconFbifTarget> {
+        match (self.addr_space, self.cpu_cache_attrib) {
+            (Self::ADDR_FBMEM, _) => Ok(FalconFbifTarget::LocalFb),
+            (Self::ADDR_SYSMEM, Self::NV_MEMORY_CACHED) => Ok(FalconFbifTarget::CoherentSysmem),
+            (Self::ADDR_SYSMEM, Self::NV_MEMORY_UNCACHED) => {
+                Ok(FalconFbifTarget::NoncoherentSysmem)
+            }
+            _ => Err(EINVAL),
+        }
+    }
+}
+
+// SAFETY: The nested descriptor is `FromBytes`, and every other field is an integer type for
+// which all bit patterns are valid.
+unsafe impl FromBytes for GenericBootloaderParams {}
+
+impl MessageFromGsp for GenericBootloaderParams {
+    type InitError = Error;
+
+    fn read(payload: &mut SBufferIter<array::IntoIter<&[u8], 2>>) -> Result<Self> {
+        let mut bytes = [0u8; size_of::<Self>()];
+
+        payload.read_exact(&mut bytes)?;
+
+        Self::from_bytes_copy(&bytes).ok_or(EINVAL)
+    }
+}
-- 
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 ` John Hubbard [this message]
2026-11-20  4:47 ` [PATCH 9/9] gpu: nova-core: gsp: add the load-and-execute event dispatcher John Hubbard

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-9-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

all inboxes | Powered by JetHome®