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>,
Timur Tabi <ttabi@nvidia.com>, Zhi Wang <zhiw@nvidia.com>,
nova-gpu@lists.linux.dev, dri-devel@lists.freedesktop.org,
linux-kernel@vger.kernel.org,
Eliot Courtney <ecourtney@nvidia.com>
Subject: [PATCH 12/14] gpu: nova-core: gsp: add the r000 load-and-execute HS binary handler
Date: Mon, 30 Nov 2026 18:28:36 +0900 [thread overview]
Message-ID: <20261130-falcon-v1-12-cb94f87b5674@nvidia.com> (raw)
In-Reply-To: <20261130-falcon-v1-0-cb94f87b5674@nvidia.com>
From: John Hubbard <jhubbard@nvidia.com>
The GSP falcon is a microcontroller with two cores, a falcon core and a
RISC-V core, and only one of the two is active at a time. GSP-RM runs on
the RISC-V core.
On GA102 and later, the r000 GSP-RM requires a Heavy-Secured (HS) binary
to run on the falcon core during boot. GSP-RM is suspended while the
binary runs.
The driver runs the binary on behalf of GSP-RM, in the following steps:
1. GSP-RM places the binary in the framebuffer.
2. GSP-RM raises a load-and-execute event.
3. GSP-RM suspends the RISC-V core.
4. The driver waits until the RISC-V core is suspended.
5. The driver resets the GSP falcon, which selects the falcon core.
6. The driver loads the binary from the framebuffer into the GSP falcon.
7. The driver starts the binary and 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 load-and-execute event.
Add the handler, which performs steps 4 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>
[ecourtney: boot HS binary with `Falcon::boot()`, keeping `dma_wr()` private]
[ecourtney: zerocopy derives for `HsBinaryParams`, no `unsafe impl`]
[ecourtney: move MAILBOX0 check and resume to `handle_load_exec_event()`]
[ecourtney: module doc's FBIF sentence moved here from the bootloader patch]
[ecourtney: move some methods to be impls of `GspBootContext`]
Signed-off-by: Eliot Courtney <ecourtney@nvidia.com>
---
drivers/gpu/nova-core/falcon.rs | 1 -
drivers/gpu/nova-core/gsp/load_exec.rs | 228 ++++++++++++++++++++++++++++++++-
drivers/gpu/nova-core/sbuffer.rs | 1 -
3 files changed, 223 insertions(+), 7 deletions(-)
diff --git a/drivers/gpu/nova-core/falcon.rs b/drivers/gpu/nova-core/falcon.rs
index fe6a84509d09..0c10e225f1b0 100644
--- a/drivers/gpu/nova-core/falcon.rs
+++ b/drivers/gpu/nova-core/falcon.rs
@@ -211,7 +211,6 @@ pub(crate) enum FalconSegmentSource<'a> {
/// Bytes in system memory.
Sysmem(&'a [u8]),
/// Bytes in the framebuffer.
- #[expect(dead_code)]
Framebuffer {
/// DMA base address in the framebuffer. The falcon adds the segment's
/// virtual address to it, so the actual segment may not start directly
diff --git a/drivers/gpu/nova-core/gsp/load_exec.rs b/drivers/gpu/nova-core/gsp/load_exec.rs
index ac5eb8b7edd7..6d832cb9ec24 100644
--- a/drivers/gpu/nova-core/gsp/load_exec.rs
+++ b/drivers/gpu/nova-core/gsp/load_exec.rs
@@ -1,7 +1,18 @@
// SPDX-License-Identifier: GPL-2.0
// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
-//! The core resume of the GSP falcon.
+//! The load-and-execute events of the GSP boot.
+//!
+//! See `Documentation/gpu/nova/core/falcon.rst`:
+//!
+//! - "Falcon security levels" describes the Heavy-Secured (HS) mode of a falcon and the boot ROM
+//! 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. The DMA engine
+//! accesses the framebuffer or system memory through the FBIF (Framebuffer Interface).
+
+use core::array;
use kernel::{
device,
@@ -9,13 +20,35 @@
prelude::*,
time::Delta, //
};
+use zerocopy::FromZeros;
-use crate::falcon::{
- gsp::Gsp,
- sec2::Sec2,
- Falcon, //
+use crate::{
+ falcon::{
+ gsp::Gsp,
+ sec2::Sec2,
+ Falcon,
+ FalconBromParams,
+ FalconDmemSegment,
+ FalconFirmware,
+ FalconImage,
+ FalconImemSegment,
+ FalconSegmentSource, //
+ },
+ gsp::{
+ cmdq::gmc::MessageFromGsp,
+ GspBootContext, //
+ },
+ sbuffer::SBufferIter, //
};
+/// DMEM virtual address value that means "no virtual address assigned".
+const FLCN_DMEM_VA_INVALID: u32 = 0xffff_ffff;
+
+/// `MAILBOX0` value that means that a falcon binary has not started.
+///
+/// A binary that reports its status through `MAILBOX0` replaces it.
+const FLCN_ERR_BINARY_NOT_STARTED: u32 = 0xfe;
+
/// Resumes GSP-RM on the GSP falcon by starting the SEC2 falcon.
///
/// Resets the GSP falcon and writes `libos_dma_address` to its mailboxes before the start, and
@@ -73,3 +106,188 @@ pub(super) fn resume_gsp_rm(
}
Ok(())
}
+
+impl GspBootContext<'_, '_> {
+ /// Waits until GSP-RM has suspended the RISC-V core, and then resets the GSP
+ /// falcon.
+ fn reset_gsp_falcon_after_suspend(&self) -> Result {
+ let dev = self.dev();
+ let gsp_falcon = self.gsp_falcon;
+
+ gsp_falcon.wait_for_processor_suspend().inspect_err(|_| {
+ dev_err!(
+ dev,
+ "Timeout waiting for GSP-RM (RISC-V core) to suspend (mbox0={:#x})\n",
+ gsp_falcon.read_mailbox0()
+ );
+ })?;
+
+ gsp_falcon.reset()
+ }
+
+ /// Runs the Heavy-Secured (HS) binary of a `GMCAPI_CMD_EXEC_HS_BINARY` event
+ /// on the falcon core of the GSP falcon, and returns `MAILBOX0` once the
+ /// binary has halted.
+ ///
+ /// `params` describes the binary. The handler:
+ ///
+ /// 1. Waits until GSP-RM has suspended the RISC-V core, for up to five
+ /// seconds.
+ /// 2. Resets the GSP falcon, which selects the falcon core.
+ /// 3. Loads the code segment into IMEM and the data segment into DMEM, by
+ /// DMA from the framebuffer.
+ /// 4. Programs the boot ROM parameters and the boot vector, and writes
+ /// [`FLCN_ERR_BINARY_NOT_STARTED`] to `MAILBOX0`.
+ /// 5. Starts the falcon core, and waits until the falcon core halts, for up
+ /// to two seconds. The binary halts the falcon core when it is done, so
+ /// the handler learns from the halt that the binary has finished.
+ ///
+ /// # Errors
+ ///
+ /// - `EINVAL` if the engine ID mask or the ucode ID of `params` does not fit
+ /// its [`FalconBromParams`] field.
+ /// - `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 and the DMA transfers are
+ /// propagated as-is.
+ #[expect(dead_code)]
+ fn handle_hs_binary(&self, params: &HsBinaryParams) -> Result<u32> {
+ let dev = self.dev();
+ let gsp_falcon = self.gsp_falcon;
+ let hs_binary = HsBinary::try_from(params)?;
+
+ self.reset_gsp_falcon_after_suspend()?;
+
+ gsp_falcon
+ .boot(&hs_binary, Some(FLCN_ERR_BINARY_NOT_STARTED), None)
+ .map(|(mbox0, _)| mbox0)
+ .inspect_err(|e| {
+ dev_err!(
+ dev,
+ "Failed to run the HS binary: {:?} (mbox0={:#x})\n",
+ e,
+ gsp_falcon.read_mailbox0()
+ );
+ })
+ }
+}
+
+/// Payload of a `GMCAPI_CMD_EXEC_HS_BINARY` event, which describes the HS binary to run.
+#[repr(C)]
+#[derive(FromBytes, IntoBytes)]
+struct HsBinaryParams {
+ /// DMA base of the code segment, a physical address in the framebuffer.
+ ///
+ /// The code segment starts at `imem_dma_base + imem_va`.
+ imem_dma_base: u64,
+ /// DMA base of the data segment, a physical address in the framebuffer.
+ ///
+ /// The data segment starts at `dmem_dma_base + dmem_va`, or at `dmem_dma_base`
+ /// when the data segment has no virtual address.
+ dmem_dma_base: u64,
+ _reserved64: [u64; 2],
+ /// Virtual address of the code segment.
+ ///
+ /// The binary starts executing at this address.
+ imem_va: u32,
+ /// Physical address in IMEM at which the code segment is loaded.
+ imem_pa: u32,
+ /// Size in bytes of the code segment.
+ imem_size: u32,
+ /// Virtual address of the data segment, or [`FLCN_DMEM_VA_INVALID`] if the data
+ /// segment has no virtual address.
+ ///
+ /// The DMA transfer writes no tags in that case.
+ dmem_va: u32,
+ /// Physical address in DMEM at which the data segment is loaded.
+ dmem_pa: u32,
+ /// Size in bytes of the data segment.
+ dmem_size: u32,
+ /// Physical address in DMEM of the signature of the binary.
+ hs_sig_dmem_addr: u32,
+ /// Mask of the falcon engines on which the binary can run, with one bit per engine.
+ engine_id_mask: u32,
+ /// ID number of the binary.
+ ///
+ /// Each ID has a fuse register that holds a version number. The boot ROM uses
+ /// the ID and that version number as inputs of the signature verification.
+ ucode_id: u32,
+ _reserved32: [u32; 3],
+}
+
+impl MessageFromGsp for HsBinaryParams {
+ type InitError = Error;
+
+ fn read(payload: &mut SBufferIter<array::IntoIter<&[u8], 2>>) -> Result<Self> {
+ let mut params = Self::new_zeroed();
+
+ payload.read_exact(params.as_mut_bytes())?;
+
+ Ok(params)
+ }
+}
+
+/// HS binary of a `GMCAPI_CMD_EXEC_HS_BINARY` event, as a [`FalconFirmware`]
+/// loaded from the framebuffer.
+struct HsBinary {
+ /// Code segment, loaded into IMEM as secure code.
+ imem: FalconImemSegment<'static>,
+ /// Data segment, loaded into DMEM.
+ dmem: FalconDmemSegment<'static>,
+ /// Parameters that the boot ROM uses to check the signature of the binary.
+ brom_params: FalconBromParams,
+}
+
+impl TryFrom<&HsBinaryParams> for HsBinary {
+ type Error = Error;
+
+ fn try_from(params: &HsBinaryParams) -> Result<Self> {
+ Ok(Self {
+ imem: FalconImemSegment {
+ source: FalconSegmentSource::Framebuffer {
+ base: params.imem_dma_base,
+ len: params.imem_size,
+ },
+ dst_start: params.imem_pa,
+ va: params.imem_va,
+ },
+ dmem: FalconDmemSegment {
+ source: FalconSegmentSource::Framebuffer {
+ base: params.dmem_dma_base,
+ len: params.dmem_size,
+ },
+ dst_start: params.dmem_pa,
+ // A data segment with a virtual address is tagged with it. One without starts at
+ // the DMA base.
+ va: (params.dmem_va != FLCN_DMEM_VA_INVALID).then_some(params.dmem_va),
+ },
+ brom_params: FalconBromParams {
+ pkc_data_offset: params.hs_sig_dmem_addr,
+ engine_id_mask: u16::try_from(params.engine_id_mask)?,
+ ucode_id: u8::try_from(params.ucode_id)?,
+ },
+ })
+ }
+}
+
+impl FalconFirmware for HsBinary {
+ type Target = Gsp;
+
+ fn image(&self) -> Result<FalconImage<'_>> {
+ Ok(FalconImage {
+ imem_ns: None,
+ imem_sec: Some(self.imem.clone()),
+ dmem: self.dmem.clone(),
+ })
+ }
+
+ fn brom_params(&self) -> FalconBromParams {
+ self.brom_params.clone()
+ }
+
+ fn boot_addr(&self) -> u32 {
+ self.imem.va
+ }
+}
diff --git a/drivers/gpu/nova-core/sbuffer.rs b/drivers/gpu/nova-core/sbuffer.rs
index 3a41d224c77a..b8c01104c255 100644
--- a/drivers/gpu/nova-core/sbuffer.rs
+++ b/drivers/gpu/nova-core/sbuffer.rs
@@ -146,7 +146,6 @@ fn get_slice(&mut self, len: usize) -> Option<&'a [u8]> {
/// Ideally we would implement `Read`, but it is not available in `core`.
/// So mimic `std::io::Read::read_exact`.
- #[expect(unused)]
pub(crate) fn read_exact(&mut self, mut dst: &mut [u8]) -> Result {
while !dst.is_empty() {
match self.get_slice(dst.len()) {
--
2.56.1
next prev parent reply other threads:[~2026-11-30 9:29 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-30 9:28 [PATCH 00/14] gpu: nova-core: merge `load` and `boot` for falcons, add load+exec handlers Eliot Courtney
2026-11-30 9:28 ` [PATCH 01/14] gpu: nova-core: falcon: program BROM and BOOTVEC in `boot` Eliot Courtney
2026-11-30 9:28 ` [PATCH 02/14] gpu: nova-core: use correct offset for imem in `BooterFirmware` Eliot Courtney
2026-11-30 9:28 ` [PATCH 03/14] gpu: nova-core: remove some dependencies on FalconDmaLoadTarget Eliot Courtney
2026-11-30 9:28 ` [PATCH 04/14] gpu: nova-core: falcon: separate staging data for DMA from its location Eliot Courtney
2026-11-30 9:28 ` [PATCH 05/14] gpu: nova-core: falcon: add `FalconImage` for `FalconFirmware` trait Eliot Courtney
2026-11-30 9:28 ` [PATCH 06/14] gpu: nova-core: falcon: load the firmware image in Falcon::boot Eliot Courtney
2026-11-30 9:28 ` [PATCH 07/14] gpu: nova-core: firmware: use `zerocopy` for `BootloaderDmemDescV2` Eliot Courtney
2026-11-30 9:28 ` [PATCH 08/14] gpu: nova-core: falcon: factor out the wait for the GSP suspend Eliot Courtney
2026-11-30 9:28 ` [PATCH 09/14] gpu: nova-core: gsp: factor out the core resume Eliot Courtney
2026-11-30 9:28 ` [PATCH 10/14] gpu: nova-core: gsp: fix resume_gsp_rm()'s error messages Eliot Courtney
2026-11-30 9:28 ` [PATCH 11/14] gpu: nova-core: falcon: select the BAR2 engine ID for framebuffer DMA Eliot Courtney
2026-11-30 9:28 ` Eliot Courtney [this message]
2026-11-30 9:28 ` [PATCH 13/14] gpu: nova-core: gsp: add the r000 load-and-execute bootloader handler Eliot Courtney
2026-11-30 9:28 ` [PATCH 14/14] gpu: nova-core: gsp: add the load-and-execute event dispatcher 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=20261130-falcon-v1-12-cb94f87b5674@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=linux-kernel@vger.kernel.org \
--cc=nova-gpu@lists.linux.dev \
--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®