* [PATCH 00/14] gpu: nova-core: merge `load` and `boot` for falcons, add load+exec handlers
@ 2026-11-30 9:28 Eliot Courtney
2026-11-30 9:28 ` [PATCH 01/14] gpu: nova-core: falcon: program BROM and BOOTVEC in `boot` Eliot Courtney
` (13 more replies)
0 siblings, 14 replies; 15+ messages in thread
From: Eliot Courtney @ 2026-11-30 9:28 UTC (permalink / raw)
To: Danilo Krummrich, Alice Ryhl, Alexandre Courbot, David Airlie,
Simona Vetter
Cc: John Hubbard, Alistair Popple, Timur Tabi, Zhi Wang, nova-gpu,
dri-devel, linux-kernel, Eliot Courtney
This combines my falcon `load`/`boot` rework (patches 1-6) with John's
r000 load+exec handlers [1] (patches 8-14). Patch 7 is a small prep
patch for John's patches.
Currently, loading the firmware and booting it is split into two
separate steps. Load is always called in combination with boot. Rewrite
the process to basically look like:
falcon.boot(<the firmware you want>, ...)
Additionally, add a segment source for firmware already in the
framebuffer (this is for HS binaries).
This simplifies running HS binaries in the r000 load+exec boot process
[1], because they can be treated as falcon firmware binaries directly,
without having to call into the guts of the boot process code + make fns
like `dma_wr` public.
This is not a pure refactor, with this `dma_load` uses two `Coherent`s
(one for imem, one for dmem) instead of one. The extra `Coherent` is a
consequence of splitting the storage vs transfer method more
orthogonally. I don't think it's consequential but jfyi.
Tested boot on TU104, GA104, AD106 and GB205.
This is based on drm-rust-next.
[1]: https://lore.kernel.org/20261120044704.165223-1-jhubbard@nvidia.com
John's cover letter for patches 8-14, trimmed to what still applies:
> This series adds the code that runs a falcon binary on behalf of the
> r000 GSP-RM during boot. It is the next part of the r000 GSP firmware
> series [2], which moves nova-core onto the GSP firmware of the r615 and
> later releases. The patches do not depend on the switch to r000, so they
> are posted on their own, in order to make the rest of that series
> smaller. With these applied, the driver still boots the r570 firmware.
>
> Some background (perhaps a refresher for some readers): the GSP falcon
> has 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.
>
> During boot, the r000 GSP-RM requires a binary to run on the falcon
> core. GSP-RM raises a load-and-execute event and suspends the RISC-V
> core. The driver then resets the GSP falcon, loads and runs the binary,
> and resumes GSP-RM. There are two such events:
>
> * On GA102 and later, the binary is a Heavy-Secured (HS) binary that
> GSP-RM has placed in the framebuffer.
>
> * On Turing and GA100, the binary is an image that the generic falcon
> bootloader loads. The event carries a descriptor of the image.
>
> The series adds a handler for each of the two events, and a dispatcher
> that selects the handler from the command ID of an event. The handlers
> share steps with code that the driver already has, so the series first
> factors those steps out:
>
> * the wait for the GSP suspend, out of the shutdown path
> * the core resume, out of the CPU sequencer
>
> The only change in what the driver does with the r570 firmware is a
> slight change in the appearance of two error messages (mentioned below).
>
> Changes since v3 of the r000 series. The two handlers and the dispatcher
> come from v3 patches 15, 17 and 18:
>
> * GSP-RM is now resumed with the core resume of the CPU sequencer.
>
> * Typesafe handler code: a handler receives its decoded parameters, and
> the dispatcher decodes the payload of the event, instead of using two
> raw byte slices to describe the payload.
>
> * The selection of the BAR2 engine ID is now introduced in a separate,
> small patch.
>
> * Fixed two error messages in GSP-RM resume.
>
> An LLM coding assistant (Claude Code) helped write every patch, and
> drafted the commit messages and this letter, all of which I've edited by
> hand afterwards.
>
> [2] https://lore.kernel.org/all/20260918010719.1176945-1-jhubbard@nvidia.com/
Signed-off-by: Eliot Courtney <ecourtney@nvidia.com>
---
Changes since boot-rework2 v2 and John's v1 [1]:
- Merge the two series into one (Alex)
- Add a comment on V2-only bootloader-loaded FWSEC in patch #3 (Alex)
- Add patch #7, which derives the `zerocopy` traits for
`BootloaderDmemDescV2`
- Drop John's 1/9 (in drm-rust-next as 002b9422b314) and 3/9 (patch #1
programs BROM and BOOTVEC in `boot`)
- Rework John's patches on top of patches #1-#6
- Link to boot-rework2 v2: https://patch.msgid.link/20261129-boot-rework2-v2-0-622f3560e18a@nvidia.com
---
Eliot Courtney (7):
gpu: nova-core: falcon: program BROM and BOOTVEC in `boot`
gpu: nova-core: use correct offset for imem in `BooterFirmware`
gpu: nova-core: remove some dependencies on FalconDmaLoadTarget
gpu: nova-core: falcon: separate staging data for DMA from its location
gpu: nova-core: falcon: add `FalconImage` for `FalconFirmware` trait
gpu: nova-core: falcon: load the firmware image in Falcon::boot
gpu: nova-core: firmware: use `zerocopy` for `BootloaderDmemDescV2`
John Hubbard (7):
gpu: nova-core: falcon: factor out the wait for the GSP suspend
gpu: nova-core: gsp: factor out the core resume
gpu: nova-core: gsp: fix resume_gsp_rm()'s error messages
gpu: nova-core: falcon: select the BAR2 engine ID for framebuffer DMA
gpu: nova-core: gsp: add the r000 load-and-execute HS binary handler
gpu: nova-core: gsp: add the r000 load-and-execute bootloader handler
gpu: nova-core: gsp: add the load-and-execute event dispatcher
drivers/gpu/nova-core/falcon.rs | 451 ++++++++----------
drivers/gpu/nova-core/falcon/gsp.rs | 15 +
drivers/gpu/nova-core/firmware.rs | 74 +--
drivers/gpu/nova-core/firmware/booter.rs | 120 ++---
drivers/gpu/nova-core/firmware/fwsec.rs | 57 ++-
drivers/gpu/nova-core/firmware/fwsec/bootloader.rs | 50 +-
drivers/gpu/nova-core/firmware/gen_bootloader.rs | 112 ++---
drivers/gpu/nova-core/gsp.rs | 1 +
drivers/gpu/nova-core/gsp/boot.rs | 8 +-
drivers/gpu/nova-core/gsp/hal/tu102.rs | 9 +-
drivers/gpu/nova-core/gsp/load_exec.rs | 511 +++++++++++++++++++++
drivers/gpu/nova-core/gsp/sequencer.rs | 42 +-
drivers/gpu/nova-core/regs.rs | 2 +
drivers/gpu/nova-core/sbuffer.rs | 1 -
14 files changed, 906 insertions(+), 547 deletions(-)
---
base-commit: abfb640b2374e26de8ff81d488c39d8254db538e
change-id: 20261130-falcon-adc42c387291
Best regards,
--
Eliot Courtney <ecourtney@nvidia.com>
^ permalink raw reply [flat|nested] 15+ messages in thread
* [PATCH 01/14] gpu: nova-core: falcon: program BROM and BOOTVEC in `boot`
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 ` Eliot Courtney
2026-11-30 9:28 ` [PATCH 02/14] gpu: nova-core: use correct offset for imem in `BooterFirmware` Eliot Courtney
` (12 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: Eliot Courtney @ 2026-11-30 9:28 UTC (permalink / raw)
To: Danilo Krummrich, Alice Ryhl, Alexandre Courbot, David Airlie,
Simona Vetter
Cc: John Hubbard, Alistair Popple, Timur Tabi, Zhi Wang, nova-gpu,
dri-devel, linux-kernel, Eliot Courtney
Move the programming of BROM and BOOTVEC into `boot`. This is in
preparation to merge the `load` and `boot` calls in `Falcon`. To do this
requires passing the firmware to program to `boot`. A later change will
make the `load` related functions private and have `boot` call them.
Reviewed-by: Alexandre Courbot <acourbot@nvidia.com>
Signed-off-by: Eliot Courtney <ecourtney@nvidia.com>
---
drivers/gpu/nova-core/falcon.rs | 35 ++++++++++--------------
drivers/gpu/nova-core/firmware/booter.rs | 1 +
drivers/gpu/nova-core/firmware/fwsec.rs | 2 +-
drivers/gpu/nova-core/firmware/gen_bootloader.rs | 7 +++--
drivers/gpu/nova-core/gsp/hal/tu102.rs | 8 ++++--
5 files changed, 25 insertions(+), 28 deletions(-)
diff --git a/drivers/gpu/nova-core/falcon.rs b/drivers/gpu/nova-core/falcon.rs
index 8bcc9240d1bd..7dfe71e4cd49 100644
--- a/drivers/gpu/nova-core/falcon.rs
+++ b/drivers/gpu/nova-core/falcon.rs
@@ -494,7 +494,7 @@ fn pio_wr_dmem_slice(&self, load_offsets: FalconPioDmemLoadTarget<'_>) -> Result
Ok(())
}
- /// Perform a PIO copy into `IMEM` and `DMEM` of `fw`, and prepare the falcon to run it.
+ /// Perform a PIO copy into `IMEM` and `DMEM` of `fw`.
pub(crate) fn pio_load<F: FalconFirmware<Target = E> + FalconPioLoadable>(
&self,
fw: &F,
@@ -512,14 +512,7 @@ pub(crate) fn pio_load<F: FalconFirmware<Target = E> + FalconPioLoadable>(
if let Some(imem_sec) = fw.imem_sec_load_params() {
self.pio_wr_imem_slice(imem_sec)?;
}
- self.pio_wr_dmem_slice(fw.dmem_load_params())?;
-
- self.hal.program_brom(self, &fw.brom_params());
-
- self.pfalcon
- .write_reg(regs::NV_PFALCON_FALCON_BOOTVEC::zeroed().with_value(fw.boot_addr()));
-
- Ok(())
+ self.pio_wr_dmem_slice(fw.dmem_load_params())
}
/// Programs FBIF context DMA slot `ctx_dma` with the value that `configure` returns, runs `f`,
@@ -641,7 +634,7 @@ fn dma_wr(
Ok(())
}
- /// Perform a DMA load into `IMEM` and `DMEM` of `fw`, and prepare the falcon to run it.
+ /// Perform a DMA load into `IMEM` and `DMEM` of `fw`.
fn dma_load<F: FalconFirmware<Target = E> + FalconDmaLoadable>(&self, fw: &F) -> Result {
// DMA object with firmware content as the source of the DMA engine.
let dma_obj = {
@@ -673,15 +666,7 @@ fn dma_load<F: FalconFirmware<Target = E> + FalconDmaLoadable>(&self, fw: &F) ->
FalconDmaSource::Sysmem(&dma_obj),
FalconMem::Dmem { tag: false },
fw.dmem_load_params(),
- )?;
-
- self.hal.program_brom(self, &fw.brom_params());
-
- // Set `BootVec` to start of non-secure code.
- self.pfalcon
- .write_reg(regs::NV_PFALCON_FALCON_BOOTVEC::zeroed().with_value(fw.boot_addr()));
-
- Ok(())
+ )
}
/// Wait until the falcon CPU is halted.
@@ -742,14 +727,22 @@ pub(crate) fn read_mailboxes(&self) -> (u32, u32) {
(mbox0, mbox1)
}
- /// Start running the loaded firmware.
+ /// Start running `fw`, which must already be loaded into the falcon.
///
/// `mbox0` and `mbox1` are optional parameters to write into the `MBOX0` and `MBOX1` registers
/// prior to running.
///
/// Wait up to two seconds for the firmware to complete, and return its exit status read from
/// the `MBOX0` and `MBOX1` registers.
- pub(crate) fn boot(&self, mbox0: Option<u32>, mbox1: Option<u32>) -> Result<(u32, u32)> {
+ pub(crate) fn boot<F: FalconFirmware<Target = E>>(
+ &self,
+ fw: &F,
+ mbox0: Option<u32>,
+ mbox1: Option<u32>,
+ ) -> Result<(u32, u32)> {
+ self.hal.program_brom(self, &fw.brom_params());
+ self.pfalcon
+ .write_reg(regs::NV_PFALCON_FALCON_BOOTVEC::zeroed().with_value(fw.boot_addr()));
self.write_mailboxes(mbox0, mbox1);
self.start()?;
self.wait_till_halted()?;
diff --git a/drivers/gpu/nova-core/firmware/booter.rs b/drivers/gpu/nova-core/firmware/booter.rs
index aa4458bb3312..a52c965093c9 100644
--- a/drivers/gpu/nova-core/firmware/booter.rs
+++ b/drivers/gpu/nova-core/firmware/booter.rs
@@ -192,6 +192,7 @@ pub(crate) fn run<T>(
sec2_falcon.load(self)?;
let wpr_dma_address = wpr_meta.dma_address();
let (mbox0, mbox1) = sec2_falcon.boot(
+ self,
Some(wpr_dma_address as u32),
Some((wpr_dma_address >> 32) as u32),
)?;
diff --git a/drivers/gpu/nova-core/firmware/fwsec.rs b/drivers/gpu/nova-core/firmware/fwsec.rs
index 7a931f22f629..45b088f30b76 100644
--- a/drivers/gpu/nova-core/firmware/fwsec.rs
+++ b/drivers/gpu/nova-core/firmware/fwsec.rs
@@ -396,7 +396,7 @@ pub(crate) fn run(&self, dev: &Device<device::Bound>, falcon: &Falcon<'_, Gsp>)
.load(self)
.inspect_err(|e| dev_err!(dev, "Failed to load FWSEC firmware: {:?}\n", e))?;
let (mbox0, _) = falcon
- .boot(Some(0), None)
+ .boot(self, Some(0), None)
.inspect_err(|e| dev_err!(dev, "Failed to boot FWSEC firmware: {:?}\n", e))?;
if mbox0 != 0 {
dev_err!(dev, "FWSEC firmware returned error {}\n", mbox0);
diff --git a/drivers/gpu/nova-core/firmware/gen_bootloader.rs b/drivers/gpu/nova-core/firmware/gen_bootloader.rs
index 751335c97e35..cfc1b99c015c 100644
--- a/drivers/gpu/nova-core/firmware/gen_bootloader.rs
+++ b/drivers/gpu/nova-core/firmware/gen_bootloader.rs
@@ -223,13 +223,14 @@ pub(crate) fn run(
.with_mem_type(FalconFbifMemType::Physical)
},
|| {
- falcon.pio_load(&GenericBootloaderLoad {
+ let fw = GenericBootloaderLoad {
bootloader: self,
imem_dst_start,
dmem_desc,
- })?;
+ };
- falcon.boot(Some(mbox0), None)
+ falcon.pio_load(&fw)?;
+ falcon.boot(&fw, Some(mbox0), None)
},
)
}
diff --git a/drivers/gpu/nova-core/gsp/hal/tu102.rs b/drivers/gpu/nova-core/gsp/hal/tu102.rs
index 2139279d40c4..80936194806a 100644
--- a/drivers/gpu/nova-core/gsp/hal/tu102.rs
+++ b/drivers/gpu/nova-core/gsp/hal/tu102.rs
@@ -101,9 +101,11 @@ fn run(&self, ctx: &mut GspBootContext<'_, '_>) -> Result {
// Sentinel value to confirm that Booter Unloader has run.
const MAILBOX_SENTINEL: u32 = 0xff;
- let (mbox0, _) = ctx
- .sec2_falcon
- .boot(Some(MAILBOX_SENTINEL), Some(MAILBOX_SENTINEL))?;
+ let (mbox0, _) = ctx.sec2_falcon.boot(
+ &self.booter_unloader,
+ Some(MAILBOX_SENTINEL),
+ Some(MAILBOX_SENTINEL),
+ )?;
if mbox0 != 0 {
dev_err!(dev, "Booter Unloader returned error 0x{:x}\n", mbox0);
return Err(EINVAL);
--
2.56.1
^ permalink raw reply [flat|nested] 15+ messages in thread
* [PATCH 02/14] gpu: nova-core: use correct offset for imem in `BooterFirmware`
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 ` Eliot Courtney
2026-11-30 9:28 ` [PATCH 03/14] gpu: nova-core: remove some dependencies on FalconDmaLoadTarget Eliot Courtney
` (11 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: Eliot Courtney @ 2026-11-30 9:28 UTC (permalink / raw)
To: Danilo Krummrich, Alice Ryhl, Alexandre Courbot, David Airlie,
Simona Vetter
Cc: John Hubbard, Alistair Popple, Timur Tabi, Zhi Wang, nova-gpu,
dri-devel, linux-kernel, Eliot Courtney
This is zero in all current firmwares but conceptually it should be
`os_code_offset` not zero.
Reviewed-by: Alexandre Courbot <acourbot@nvidia.com>
Signed-off-by: Eliot Courtney <ecourtney@nvidia.com>
---
drivers/gpu/nova-core/firmware/booter.rs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/gpu/nova-core/firmware/booter.rs b/drivers/gpu/nova-core/firmware/booter.rs
index a52c965093c9..7a0163a00285 100644
--- a/drivers/gpu/nova-core/firmware/booter.rs
+++ b/drivers/gpu/nova-core/firmware/booter.rs
@@ -152,7 +152,7 @@ pub(crate) fn new(
(
app0_code_offset,
Some(FalconDmaLoadTarget {
- src_start: 0,
+ src_start: os_code_offset,
dst_start: os_code_offset,
len: os_code_size,
}),
--
2.56.1
^ permalink raw reply [flat|nested] 15+ messages in thread
* [PATCH 03/14] gpu: nova-core: remove some dependencies on FalconDmaLoadTarget
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 ` Eliot Courtney
2026-11-30 9:28 ` [PATCH 04/14] gpu: nova-core: falcon: separate staging data for DMA from its location Eliot Courtney
` (10 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: Eliot Courtney @ 2026-11-30 9:28 UTC (permalink / raw)
To: Danilo Krummrich, Alice Ryhl, Alexandre Courbot, David Airlie,
Simona Vetter
Cc: John Hubbard, Alistair Popple, Timur Tabi, Zhi Wang, nova-gpu,
dri-devel, linux-kernel, Eliot Courtney
In order to remove `FalconDmaLoadTarget`, remove usages of it in
`FwsecFirmwareWithBl` and `BootloaderDmemDescV2`. `FalconDmaLoadTarget`
ends up non-orthogonal with `FalconImage`, `FalconImemSegment`,
`FalconDmemSegment` which are added in a following change. These three
new types take over the job of denoting where code/data uploaded to a
falcon is stored and where it is sent to. This is part of making the
locations of where the falcon data/code is represented separate from how
it is sent to the falcon. `FalconDmaLoadTarget` conflates those two
things.
Reviewed-by: Alexandre Courbot <acourbot@nvidia.com>
Signed-off-by: Eliot Courtney <ecourtney@nvidia.com>
---
drivers/gpu/nova-core/firmware/fwsec/bootloader.rs | 50 ++++++++--------------
drivers/gpu/nova-core/firmware/gen_bootloader.rs | 42 +++++++++---------
2 files changed, 39 insertions(+), 53 deletions(-)
diff --git a/drivers/gpu/nova-core/firmware/fwsec/bootloader.rs b/drivers/gpu/nova-core/firmware/fwsec/bootloader.rs
index 461e5e6f7899..b8695f5868be 100644
--- a/drivers/gpu/nova-core/firmware/fwsec/bootloader.rs
+++ b/drivers/gpu/nova-core/firmware/fwsec/bootloader.rs
@@ -19,7 +19,6 @@
falcon::{
gsp::Gsp,
Falcon,
- FalconDmaLoadable,
FalconFbifTarget, //
},
firmware::{
@@ -28,6 +27,7 @@
BootloaderDmemDescV2,
GenericBootloader, //
},
+ FalconUCodeDesc, //
},
gpu::Chipset,
num::FromSafeCast, //
@@ -52,61 +52,45 @@ pub(crate) fn new(
dev: &'a Device<device::Bound>,
chipset: Chipset,
) -> Result<Self> {
+ // Bootloader-loaded FWSEC is only used with V2.
+ let desc = match &firmware.desc {
+ FalconUCodeDesc::V2(desc) => desc,
+ FalconUCodeDesc::V3(_) => return Err(EINVAL),
+ };
+
let bootloader = GenericBootloader::new(dev, chipset)?;
// `BootloaderDmemDescV2` expects the source to be a mirror image of the destination and
// uses the same offset parameter for both.
//
- // Thus, the start of the source object needs to be padded with the difference between the
- // destination and source offsets.
+ // Thus, the start of the source object needs to be padded with `imem_phys_base`, the IMEM
+ // offset at which the code is loaded.
//
// In practice, this is expected to always be zero but is required for code correctness.
- let (align_padding, firmware_dma) = {
- let align_padding = {
- let imem_sec = firmware.imem_sec_load_params();
-
- imem_sec
- .dst_start
- .checked_sub(imem_sec.src_start)
- .map(usize::from_safe_cast)
- .ok_or(EOVERFLOW)?
- };
+ let align_padding = usize::from_safe_cast(desc.imem_phys_base);
+ let firmware_dma = {
let mut firmware_obj = KVVec::zeroed(align_padding, GFP_KERNEL)?;
firmware_obj.extend_from_slice(firmware.ucode.0.as_slice(), GFP_KERNEL)?;
- (
- align_padding,
- Coherent::from_slice(dev, firmware_obj.as_slice(), GFP_KERNEL)?,
- )
+ Coherent::from_slice(dev, firmware_obj.as_slice(), GFP_KERNEL)?
};
let dmem_desc = {
- let imem_sec = firmware.imem_sec_load_params();
- let imem_ns = firmware.imem_ns_load_params().ok_or(EINVAL)?;
- let dmem = firmware.dmem_load_params();
-
// The bootloader does not have a data destination offset field and copies the data at
- // the start of DMEM, so it can only be used if the destination offset of the firmware
- // is 0.
- if dmem.dst_start != 0 {
+ // the start of DMEM, so it can only be used if `dmem_phys_base` is 0.
+ if desc.dmem_phys_base != 0 {
return Err(EINVAL);
}
- // Start of data section is the added padding + the DMEM `src_start` field.
+ // Start of data section is the added padding + the `dmem_offset` field.
let data_dma_base = firmware_dma
.dma_address()
.checked_add(u64::from_safe_cast(align_padding))
- .and_then(|offset| offset.checked_add(dmem.src_start.into()))
+ .and_then(|offset| offset.checked_add(desc.dmem_offset.into()))
.ok_or(EOVERFLOW)?;
- BootloaderDmemDescV2::new(
- &imem_ns,
- &imem_sec,
- &dmem,
- firmware_dma.dma_address(),
- data_dma_base,
- )
+ BootloaderDmemDescV2::new(desc, firmware_dma.dma_address(), data_dma_base)
};
Ok(Self {
diff --git a/drivers/gpu/nova-core/firmware/gen_bootloader.rs b/drivers/gpu/nova-core/firmware/gen_bootloader.rs
index cfc1b99c015c..5dea98220e9d 100644
--- a/drivers/gpu/nova-core/firmware/gen_bootloader.rs
+++ b/drivers/gpu/nova-core/firmware/gen_bootloader.rs
@@ -22,7 +22,6 @@
gsp::Gsp,
Falcon,
FalconBromParams,
- FalconDmaLoadTarget,
FalconFbifMemType,
FalconFbifTarget,
FalconFirmware,
@@ -30,9 +29,12 @@
FalconPioImemLoadTarget,
FalconPioLoadable, //
},
- firmware::tlv::{
- request_tlv, //
- Tlv,
+ firmware::{
+ tlv::{
+ request_tlv, //
+ Tlv,
+ },
+ FalconUCodeDescV2, //
},
gpu::Chipset,
num::FromSafeCast, //
@@ -91,29 +93,29 @@ impl BootloaderDmemDescV2 {
/// Creates the descriptor of an image whose code is at `code_dma_base` and whose data is at
/// `data_dma_base`.
///
- /// `imem_ns` and `imem_sec` locate the non-secure and secure code in the image, and `dmem`
- /// gives the size of its data. The code DMA object must be a mirror image of the target IMEM
- /// layout, because the bootloader uses the destination offset of each code segment as its
- /// source offset too.
- pub(crate) fn new(
- imem_ns: &FalconDmaLoadTarget,
- imem_sec: &FalconDmaLoadTarget,
- dmem: &FalconDmaLoadTarget,
- code_dma_base: u64,
- data_dma_base: u64,
- ) -> Self {
+ /// The code DMA object must be a mirror image of the target IMEM layout, because the
+ /// bootloader uses the destination offset of each code segment as its source offset too.
+ pub(super) fn new(desc: &FalconUCodeDescV2, code_dma_base: u64, data_dma_base: u64) -> Self {
+ // `imem_sec_base` is the *virtual* start address of the secure IMEM segment, so subtract
+ // `imem_virt_base` to get its physical offset.
+ let imem_sec_start = desc.imem_sec_base.saturating_sub(desc.imem_virt_base);
+
Self {
reserved: [0; 4],
signature: [0; 4],
ctx_dma: Self::FALCON_DMAIDX_PHYS_SYS_NCOH,
code_dma_base,
- non_sec_code_off: imem_ns.dst_start,
- non_sec_code_size: imem_ns.len,
- sec_code_off: imem_sec.dst_start,
- sec_code_size: imem_sec.len,
+ // Non-secure code always starts at offset 0 of the image, so it is loaded at
+ // `imem_phys_base`.
+ non_sec_code_off: desc.imem_phys_base,
+ // `imem_load_size` includes the size of the secure segment, so subtract it to
+ // get the correct amount of data to copy.
+ non_sec_code_size: desc.imem_load_size.saturating_sub(desc.imem_sec_size),
+ sec_code_off: desc.imem_phys_base.saturating_add(imem_sec_start),
+ sec_code_size: desc.imem_sec_size,
code_entry_point: 0,
data_dma_base,
- data_size: dmem.len,
+ data_size: desc.dmem_load_size,
argc: 0,
argv: 0,
}
--
2.56.1
^ permalink raw reply [flat|nested] 15+ messages in thread
* [PATCH 04/14] gpu: nova-core: falcon: separate staging data for DMA from its location
2026-11-30 9:28 [PATCH 00/14] gpu: nova-core: merge `load` and `boot` for falcons, add load+exec handlers Eliot Courtney
` (2 preceding siblings ...)
2026-11-30 9:28 ` [PATCH 03/14] gpu: nova-core: remove some dependencies on FalconDmaLoadTarget Eliot Courtney
@ 2026-11-30 9:28 ` Eliot Courtney
2026-11-30 9:28 ` [PATCH 05/14] gpu: nova-core: falcon: add `FalconImage` for `FalconFirmware` trait Eliot Courtney
` (9 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: Eliot Courtney @ 2026-11-30 9:28 UTC (permalink / raw)
To: Danilo Krummrich, Alice Ryhl, Alexandre Courbot, David Airlie,
Simona Vetter
Cc: John Hubbard, Alistair Popple, Timur Tabi, Zhi Wang, nova-gpu,
dri-devel, linux-kernel, Eliot Courtney
Introduce a new enum `FalconSegmentSource` that holds the source of
each segment to copy to a falcon. This replaces the existing
`FalconDmaSource` enum which mixed the jobs of knowing where the bytes
to copy to the falcon live with how they are copied (DMA).
Since `FalconDmaSource` is removed (to separate how data is sent to a
falcon from where it lives), merge the staging of the data that gets
DMA'd to a falcon with actually performing the copy. This separates the
decision to stage it for DMA from where the data is living.
This is useful for allowing DMA from framebuffer memory and sysmem to
falcon in a unified way.
Reviewed-by: Alexandre Courbot <acourbot@nvidia.com>
Signed-off-by: Eliot Courtney <ecourtney@nvidia.com>
---
drivers/gpu/nova-core/falcon.rs | 128 ++++++++++++++++++++++++----------------
1 file changed, 77 insertions(+), 51 deletions(-)
diff --git a/drivers/gpu/nova-core/falcon.rs b/drivers/gpu/nova-core/falcon.rs
index 7dfe71e4cd49..f5696b48df74 100644
--- a/drivers/gpu/nova-core/falcon.rs
+++ b/drivers/gpu/nova-core/falcon.rs
@@ -12,7 +12,6 @@
DmaAddress, //
},
io::{
- io_project,
poll::read_poll_timeout,
register::Array,
Io,
@@ -140,15 +139,6 @@ pub(crate) enum FalconMem {
Dmem { tag: bool },
}
-/// Where a falcon DMA transfer reads from.
-pub(crate) enum FalconDmaSource<'a> {
- /// A DMA object in system memory.
- Sysmem(&'a Coherent<'a, [u8]>),
- /// GPU framebuffer memory at physical address `base`.
- #[expect(dead_code)]
- Framebuffer { base: u64 },
-}
-
bounded_enum! {
/// Defines the Framebuffer Interface (FBIF) aperture type.
/// This determines the memory type for external memory access during a DMA transfer, which is
@@ -208,6 +198,16 @@ pub(crate) struct FalconDmaLoadTarget {
pub(crate) len: u32,
}
+impl FalconDmaLoadTarget {
+ /// Returns the data that should be copied to the falcon from `blob`.
+ fn data<'a>(&self, blob: &'a [u8]) -> Result<&'a [u8]> {
+ let start = usize::from_safe_cast(self.src_start);
+ let end = start + usize::from_safe_cast(self.len);
+
+ blob.get(start..end).ok_or(EINVAL)
+ }
+}
+
/// Parameters for the falcon boot ROM.
#[derive(Debug, Clone)]
pub(crate) struct FalconBromParams {
@@ -219,6 +219,23 @@ pub(crate) struct FalconBromParams {
pub(crate) ucode_id: u8,
}
+/// Denotes where the bytes of a firmware segment are.
+#[derive(Clone, Copy)]
+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
+ /// from here.
+ base: u64,
+ /// Number of bytes in the segment.
+ len: u32,
+ },
+}
+
/// Trait implemented by falcon firmwares that can be loaded using DMA.
pub(crate) trait FalconDmaLoadable {
/// Returns the firmware data as a slice of bytes.
@@ -545,36 +562,39 @@ pub(crate) fn with_fbif_transcfg<R>(
Ok(result)
}
- /// Perform a DMA write according to `load_offsets` from `src` into the falcon's `target_mem`.
+ /// Perform a DMA write from `src` at `src_offset` into the falcon's `target_mem` at
+ /// `dst_start`.
fn dma_wr(
&self,
- src: FalconDmaSource<'_>,
+ src: FalconSegmentSource<'_>,
target_mem: FalconMem,
- load_offsets: FalconDmaLoadTarget,
+ src_offset: u32,
+ dst_start: u32,
) -> Result {
const DMA_LEN: u32 = cv!(MEM_BLOCK_ALIGNMENT);
- // DMA transfers can only be done in units of 256 bytes. Compute how many such transfers we
- // need to perform.
- let num_transfers = load_offsets.len.div_ceil(DMA_LEN);
-
- let (dma_base, fbif_target) = match src {
- FalconDmaSource::Sysmem(dma_obj) => {
- // Upper limit of transfer is `(num_transfers * DMA_LEN) + load_offsets.src_start`.
- let end_offset = num_transfers
- .checked_mul(DMA_LEN)
- .and_then(|size| size.checked_add(load_offsets.src_start))
- .map(usize::from_safe_cast)
- .ok_or(EOVERFLOW)?;
+ // Declare `dma_obj` here so it lives long enough for transfers to
+ // complete.
+ let dma_obj;
+ let (dma_base, fbif_target, len) = match src {
+ FalconSegmentSource::Sysmem(data) => {
+ dma_obj = self.dma_stage(data, src_offset)?;
(
- io_project!(dma_obj, [try: 0..end_offset]).dma_address(),
+ dma_obj.dma_address(),
FalconFbifTarget::CoherentSysmem,
+ u32::try_from(data.len())?,
)
}
- FalconDmaSource::Framebuffer { base } => (base, FalconFbifTarget::LocalFb),
+ FalconSegmentSource::Framebuffer { base, len } => {
+ (base, FalconFbifTarget::LocalFb, len)
+ }
};
+ // DMA transfers can only be done in units of 256 bytes. Compute how many such transfers we
+ // need to perform.
+ let num_transfers = len.div_ceil(DMA_LEN);
+
if dma_base % DmaAddress::from(DMA_LEN) > 0 {
dev_err!(
self.dev,
@@ -610,12 +630,12 @@ fn dma_wr(
// Perform a transfer of size `DMA_LEN`.
self.pfalcon.write_reg(
regs::NV_PFALCON_FALCON_DMATRFMOFFS::zeroed()
- .try_with_offs(load_offsets.dst_start.checked_add(pos).ok_or(EOVERFLOW)?)?,
+ .try_with_offs(dst_start.checked_add(pos).ok_or(EOVERFLOW)?)?,
);
// The source offset doubles as the virtual address tag for IMEM and tagged DMEM.
self.pfalcon.write_reg(
regs::NV_PFALCON_FALCON_DMATRFFBOFFS::zeroed()
- .with_offs(load_offsets.src_start.checked_add(pos).ok_or(EOVERFLOW)?),
+ .with_offs(src_offset.checked_add(pos).ok_or(EOVERFLOW)?),
);
self.pfalcon.write_reg(cmd);
@@ -634,38 +654,44 @@ fn dma_wr(
Ok(())
}
+ /// Returns a DMA object with `data` at `offset`, padded with zeros up to
+ /// the next multiple of [`MEM_BLOCK_ALIGNMENT`].
+ fn dma_stage(&self, data: &[u8], offset: u32) -> Result<Coherent<'a, [u8]>> {
+ let offset = usize::from_safe_cast(offset);
+
+ // DMA copies are done in chunks of `MEM_BLOCK_ALIGNMENT`, so pad the length
+ // accordingly and fill with `0`.
+ let mut dma_obj = CoherentBox::zeroed_slice(
+ self.dev,
+ offset + data.len().next_multiple_of(MEM_BLOCK_ALIGNMENT),
+ GFP_KERNEL,
+ )?;
+
+ // PANIC: `dma_obj` has at least `offset + data.len()` bytes.
+ dma_obj[offset..offset + data.len()].copy_from_slice(data);
+
+ Ok(dma_obj.into())
+ }
+
/// Perform a DMA load into `IMEM` and `DMEM` of `fw`.
fn dma_load<F: FalconFirmware<Target = E> + FalconDmaLoadable>(&self, fw: &F) -> Result {
- // DMA object with firmware content as the source of the DMA engine.
- let dma_obj = {
- let fw_slice = fw.as_slice();
-
- // DMA copies are done in chunks of `MEM_BLOCK_ALIGNMENT`, so pad the length
- // accordingly and fill with `0`.
- let mut dma_obj = CoherentBox::zeroed_slice(
- self.dev,
- fw_slice.len().next_multiple_of(MEM_BLOCK_ALIGNMENT),
- GFP_KERNEL,
- )?;
-
- // PANIC: `dma_obj` has been created with a length equal to or larger than
- // `fw_slice.len()`, so the range `..fw_slice.len()` is valid.
- dma_obj[..fw_slice.len()].copy_from_slice(fw_slice);
-
- dma_obj.into()
- };
+ let blob = fw.as_slice();
+ let imem_sec = fw.imem_sec_load_params();
+ let dmem = fw.dmem_load_params();
self.dma_reset();
self.dma_wr(
- FalconDmaSource::Sysmem(&dma_obj),
+ FalconSegmentSource::Sysmem(imem_sec.data(blob)?),
FalconMem::ImemSecure,
- fw.imem_sec_load_params(),
+ imem_sec.src_start,
+ imem_sec.dst_start,
)?;
self.dma_wr(
- FalconDmaSource::Sysmem(&dma_obj),
+ FalconSegmentSource::Sysmem(dmem.data(blob)?),
FalconMem::Dmem { tag: false },
- fw.dmem_load_params(),
+ 0,
+ dmem.dst_start,
)
}
--
2.56.1
^ permalink raw reply [flat|nested] 15+ messages in thread
* [PATCH 05/14] gpu: nova-core: falcon: add `FalconImage` for `FalconFirmware` trait
2026-11-30 9:28 [PATCH 00/14] gpu: nova-core: merge `load` and `boot` for falcons, add load+exec handlers Eliot Courtney
` (3 preceding siblings ...)
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 ` Eliot Courtney
2026-11-30 9:28 ` [PATCH 06/14] gpu: nova-core: falcon: load the firmware image in Falcon::boot Eliot Courtney
` (8 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: Eliot Courtney @ 2026-11-30 9:28 UTC (permalink / raw)
To: Danilo Krummrich, Alice Ryhl, Alexandre Courbot, David Airlie,
Simona Vetter
Cc: John Hubbard, Alistair Popple, Timur Tabi, Zhi Wang, nova-gpu,
dri-devel, linux-kernel, Eliot Courtney
Introduce a new struct `FalconImage` which holds each segment (secure
imem, non-secure imem, dmem) that needs to be uploaded to a falcon.
This replaces `FalconDmaLoadable` which mixed the locations/source of
each segment with how it is given to a falcon. This makes it easier to
add falcon firmware loaded from framebuffer memory, which is needed for
r000.
Since this decouples storage of segments from the way to send them, we
can also remove the PIO adapter, separate PIO specific machinery, and
`FalconDmaLoadTarget`.
Reviewed-by: Alexandre Courbot <acourbot@nvidia.com>
Signed-off-by: Eliot Courtney <ecourtney@nvidia.com>
---
drivers/gpu/nova-core/falcon.rs | 317 ++++++++---------------
drivers/gpu/nova-core/firmware.rs | 74 +-----
drivers/gpu/nova-core/firmware/booter.rs | 118 +++++----
drivers/gpu/nova-core/firmware/fwsec.rs | 52 ++--
drivers/gpu/nova-core/firmware/gen_bootloader.rs | 57 ++--
5 files changed, 233 insertions(+), 385 deletions(-)
diff --git a/drivers/gpu/nova-core/falcon.rs b/drivers/gpu/nova-core/falcon.rs
index f5696b48df74..c2fdb9e0f123 100644
--- a/drivers/gpu/nova-core/falcon.rs
+++ b/drivers/gpu/nova-core/falcon.rs
@@ -17,10 +17,6 @@
Io,
Mmio, //
},
- num::{
- Bounded,
- TryIntoBounded, //
- },
prelude::*,
sizes::SZ_4K,
time::Delta,
@@ -132,7 +128,6 @@ pub(crate) enum FalconMem {
/// Secure Instruction Memory.
ImemSecure,
/// Non-Secure Instruction Memory.
- #[expect(unused)]
ImemNonSecure,
/// Data Memory. If `tag` is set, a transfer into DMEM also tags each block with its source
/// offset, which is then the DMEM virtual address of the image.
@@ -186,28 +181,6 @@ pub(crate) trait FalconEngine: Send + Sync + Sized {
fn pfalcon2(io: Bar0<'_>) -> Mmio<'_, PFalcon2Registers>;
}
-/// Represents a portion of the firmware to be loaded into a particular memory (e.g. IMEM or DMEM)
-/// using DMA.
-#[derive(Debug, Clone)]
-pub(crate) struct FalconDmaLoadTarget {
- /// Offset from the start of the source object to copy from.
- pub(crate) src_start: u32,
- /// Offset from the start of the destination memory to copy into.
- pub(crate) dst_start: u32,
- /// Number of bytes to copy.
- pub(crate) len: u32,
-}
-
-impl FalconDmaLoadTarget {
- /// Returns the data that should be copied to the falcon from `blob`.
- fn data<'a>(&self, blob: &'a [u8]) -> Result<&'a [u8]> {
- let start = usize::from_safe_cast(self.src_start);
- let end = start + usize::from_safe_cast(self.len);
-
- blob.get(start..end).ok_or(EINVAL)
- }
-}
-
/// Parameters for the falcon boot ROM.
#[derive(Debug, Clone)]
pub(crate) struct FalconBromParams {
@@ -236,141 +209,36 @@ pub(crate) enum FalconSegmentSource<'a> {
},
}
-/// Trait implemented by falcon firmwares that can be loaded using DMA.
-pub(crate) trait FalconDmaLoadable {
- /// Returns the firmware data as a slice of bytes.
- fn as_slice(&self) -> &[u8];
-
- /// Returns the load parameters for Secure `IMEM`.
- fn imem_sec_load_params(&self) -> FalconDmaLoadTarget;
-
- /// Returns the load parameters for Non-Secure `IMEM`,
- /// used only on Turing and GA100.
- fn imem_ns_load_params(&self) -> Option<FalconDmaLoadTarget>;
-
- /// Returns the load parameters for `DMEM`.
- fn dmem_load_params(&self) -> FalconDmaLoadTarget;
-
- /// Returns an adapter that provides the required parameter to load this firmware using PIO.
- ///
- /// This can only fail if some `u32` fields cannot be converted to `u16`, or if the indices in
- /// the headers are invalid.
- fn try_as_pio_loadable(&self) -> Result<FalconDmaFirmwarePioAdapter<'_, Self>> {
- let new_pio_imem = |params: FalconDmaLoadTarget, secure| {
- let start = usize::from_safe_cast(params.src_start);
- let end = start + usize::from_safe_cast(params.len);
- let data = self.as_slice().get(start..end).ok_or(EINVAL)?;
-
- let dst_start = params.dst_start.try_into_bounded().ok_or(EINVAL)?;
-
- Ok::<_, Error>(FalconPioImemLoadTarget {
- data,
- dst_start,
- secure,
- start_tag: dst_start.shr::<8, 16>().into(),
- })
- };
-
- let imem_sec = new_pio_imem(self.imem_sec_load_params(), true)?;
-
- let imem_ns = if let Some(params) = self.imem_ns_load_params() {
- Some(new_pio_imem(params, false)?)
- } else {
- None
- };
-
- let dmem = {
- let params = self.dmem_load_params();
- let start = usize::from_safe_cast(params.src_start);
- let end = start + usize::from_safe_cast(params.len);
- let data = self.as_slice().get(start..end).ok_or(EINVAL)?;
-
- let dst_start = u16::try_from(params.dst_start).map_err(|_| EINVAL)?;
-
- FalconPioDmemLoadTarget { data, dst_start }
- };
-
- Ok(FalconDmaFirmwarePioAdapter {
- fw: self,
- imem_sec,
- imem_ns,
- dmem,
- })
- }
-}
-
-/// Represents a portion of the firmware to be loaded into IMEM using PIO.
+/// Code to load into `IMEM`.
#[derive(Clone)]
-pub(crate) struct FalconPioImemLoadTarget<'a> {
- pub(crate) data: &'a [u8],
- pub(crate) dst_start: Bounded<u32, 24>,
- pub(crate) secure: bool,
- pub(crate) start_tag: u16,
+pub(crate) struct FalconImemSegment<'a> {
+ /// Where the code is.
+ pub(crate) source: FalconSegmentSource<'a>,
+ /// Offset in `IMEM` at which to load the code.
+ pub(crate) dst_start: u32,
+ /// Virtual address of the code, used for tagging.
+ pub(crate) va: u32,
}
-/// Represents a portion of the firmware to be loaded into DMEM using PIO.
+/// Data to load into falcon's `DMEM`.
#[derive(Clone)]
-pub(crate) struct FalconPioDmemLoadTarget<'a> {
- pub(crate) data: &'a [u8],
- pub(crate) dst_start: u16,
+pub(crate) struct FalconDmemSegment<'a> {
+ /// Where the data is.
+ pub(crate) source: FalconSegmentSource<'a>,
+ /// Offset in falcon's `DMEM` at which to load the data.
+ pub(crate) dst_start: u32,
+ /// Virtual address of the data, used for tagging, or `None` to leave untagged.
+ pub(crate) va: Option<u32>,
}
-/// Trait for providing PIO load parameters of falcon firmwares.
-pub(crate) trait FalconPioLoadable {
- /// Returns the load parameters for Secure `IMEM`, if any.
- fn imem_sec_load_params(&self) -> Option<FalconPioImemLoadTarget<'_>>;
-
- /// Returns the load parameters for Non-Secure `IMEM`, if any.
- fn imem_ns_load_params(&self) -> Option<FalconPioImemLoadTarget<'_>>;
-
- /// Returns the load parameters for `DMEM`.
- fn dmem_load_params(&self) -> FalconPioDmemLoadTarget<'_>;
-}
-
-/// Adapter type that makes any DMA-loadable firmware also loadable via PIO.
-///
-/// Created using [`FalconDmaLoadable::try_as_pio_loadable`].
-pub(crate) struct FalconDmaFirmwarePioAdapter<'a, T: FalconDmaLoadable + ?Sized> {
- /// Reference to the DMA firmware.
- fw: &'a T,
- /// Validated secure IMEM parameters.
- imem_sec: FalconPioImemLoadTarget<'a>,
- /// Validated non-secure IMEM parameters.
- imem_ns: Option<FalconPioImemLoadTarget<'a>>,
- /// Validated DMEM parameters.
- dmem: FalconPioDmemLoadTarget<'a>,
-}
-
-impl<'a, T> FalconPioLoadable for FalconDmaFirmwarePioAdapter<'a, T>
-where
- T: FalconDmaLoadable + ?Sized,
-{
- fn imem_sec_load_params(&self) -> Option<FalconPioImemLoadTarget<'_>> {
- Some(self.imem_sec.clone())
- }
-
- fn imem_ns_load_params(&self) -> Option<FalconPioImemLoadTarget<'_>> {
- self.imem_ns.clone()
- }
-
- fn dmem_load_params(&self) -> FalconPioDmemLoadTarget<'_> {
- self.dmem.clone()
- }
-}
-
-impl<'a, T> FalconFirmware for FalconDmaFirmwarePioAdapter<'a, T>
-where
- T: FalconDmaLoadable + FalconFirmware + ?Sized,
-{
- type Target = <T as FalconFirmware>::Target;
-
- fn brom_params(&self) -> FalconBromParams {
- self.fw.brom_params()
- }
-
- fn boot_addr(&self) -> u32 {
- self.fw.boot_addr()
- }
+/// Firmware image to load into a falcon.
+pub(crate) struct FalconImage<'a> {
+ /// Non-secure code.
+ pub(crate) imem_ns: Option<FalconImemSegment<'a>>,
+ /// Secure code.
+ pub(crate) imem_sec: Option<FalconImemSegment<'a>>,
+ /// Data of the image.
+ pub(crate) dmem: FalconDmemSegment<'a>,
}
/// Trait for a falcon firmware.
@@ -380,6 +248,9 @@ pub(crate) trait FalconFirmware {
/// Engine on which this firmware is to be loaded.
type Target: FalconEngine;
+ /// Returns the image to load into the falcon.
+ fn image(&self) -> Result<FalconImage<'_>>;
+
/// Returns the parameters to write into the BROM registers.
fn brom_params(&self) -> FalconBromParams;
@@ -448,25 +319,32 @@ pub(crate) fn reset(&self) -> Result {
/// Write a slice to Falcon IMEM memory using programmed I/O (PIO).
///
- /// Returns `EINVAL` if `img.len()` is not a multiple of 4.
- fn pio_wr_imem_slice(&self, load_offsets: FalconPioImemLoadTarget<'_>) -> Result {
+ /// Returns `EINVAL` if `data.len()` is not a multiple of 4, and `EOVERFLOW` if
+ /// `dst_start` does not fit in the `offs` field of `IMEMC`.
+ fn pio_wr_imem_slice(
+ &self,
+ data: &[u8],
+ dst_start: u32,
+ secure: bool,
+ start_tag: u16,
+ ) -> Result {
// Rejecting misaligned images here allows us to avoid checking
// inside the loops.
- if load_offsets.data.len() % 4 != 0 {
+ if data.len() % 4 != 0 {
return Err(EINVAL);
}
self.pfalcon.write(
Array::at(Self::PIO_PORT),
regs::NV_PFALCON_FALCON_IMEMC::zeroed()
- .with_secure(load_offsets.secure)
+ .with_secure(secure)
.with_aincw(true)
- .with_offs(load_offsets.dst_start),
+ .try_with_offs(dst_start)?,
);
- for (n, block) in load_offsets.data.chunks(MEM_BLOCK_ALIGNMENT).enumerate() {
+ for (n, block) in data.chunks(MEM_BLOCK_ALIGNMENT).enumerate() {
let n = u16::try_from(n)?;
- let tag: u16 = load_offsets.start_tag.checked_add(n).ok_or(ERANGE)?;
+ let tag: u16 = start_tag.checked_add(n).ok_or(ERANGE)?;
self.pfalcon.write(
Array::at(Self::PIO_PORT),
regs::NV_PFALCON_FALCON_IMEMT::zeroed().with_tag(tag),
@@ -485,11 +363,12 @@ fn pio_wr_imem_slice(&self, load_offsets: FalconPioImemLoadTarget<'_>) -> Result
/// Write a slice to Falcon DMEM memory using programmed I/O (PIO).
///
- /// Returns `EINVAL` if `img.len()` is not a multiple of 4.
- fn pio_wr_dmem_slice(&self, load_offsets: FalconPioDmemLoadTarget<'_>) -> Result {
+ /// Returns `EINVAL` if `data.len()` is not a multiple of 4, and `EOVERFLOW` if
+ /// `dst_start` does not fit in the `offs` field of `DMEMC`.
+ fn pio_wr_dmem_slice(&self, data: &[u8], dst_start: u32) -> Result {
// Rejecting misaligned images here allows us to avoid checking
// inside the loops.
- if load_offsets.data.len() % 4 != 0 {
+ if data.len() % 4 != 0 {
return Err(EINVAL);
}
@@ -497,10 +376,10 @@ fn pio_wr_dmem_slice(&self, load_offsets: FalconPioDmemLoadTarget<'_>) -> Result
Array::at(Self::PIO_PORT),
regs::NV_PFALCON_FALCON_DMEMC::zeroed()
.with_aincw(true)
- .with_offs(load_offsets.dst_start),
+ .try_with_offs(dst_start)?,
);
- for word in load_offsets.data.chunks_exact(4) {
+ for word in data.chunks_exact(4) {
let w = [word[0], word[1], word[2], word[3]];
self.pfalcon.write(
Array::at(Self::PIO_PORT),
@@ -511,27 +390,6 @@ fn pio_wr_dmem_slice(&self, load_offsets: FalconPioDmemLoadTarget<'_>) -> Result
Ok(())
}
- /// Perform a PIO copy into `IMEM` and `DMEM` of `fw`.
- pub(crate) fn pio_load<F: FalconFirmware<Target = E> + FalconPioLoadable>(
- &self,
- fw: &F,
- ) -> Result {
- self.pfalcon.update(regs::NV_PFALCON_FBIF_CTL, |v| {
- v.with_allow_phys_no_ctx(true)
- });
-
- self.pfalcon
- .write_reg(regs::NV_PFALCON_FALCON_DMACTL::zeroed());
-
- if let Some(imem_ns) = fw.imem_ns_load_params() {
- self.pio_wr_imem_slice(imem_ns)?;
- }
- if let Some(imem_sec) = fw.imem_sec_load_params() {
- self.pio_wr_imem_slice(imem_sec)?;
- }
- self.pio_wr_dmem_slice(fw.dmem_load_params())
- }
-
/// Programs FBIF context DMA slot `ctx_dma` with the value that `configure` returns, runs `f`,
/// and restores the slot once `f` has returned `Ok`.
///
@@ -673,26 +531,64 @@ fn dma_stage(&self, data: &[u8], offset: u32) -> Result<Coherent<'a, [u8]>> {
Ok(dma_obj.into())
}
- /// Perform a DMA load into `IMEM` and `DMEM` of `fw`.
- fn dma_load<F: FalconFirmware<Target = E> + FalconDmaLoadable>(&self, fw: &F) -> Result {
- let blob = fw.as_slice();
- let imem_sec = fw.imem_sec_load_params();
- let dmem = fw.dmem_load_params();
+ /// Load `segment` into `IMEM`, as secure code if `secure` is set.
+ fn load_imem(&self, segment: &FalconImemSegment<'_>, secure: bool) -> Result {
+ match (segment.source, self.hal.load_method()) {
+ (FalconSegmentSource::Sysmem(data), LoadMethod::Pio) => self.pio_wr_imem_slice(
+ data,
+ segment.dst_start,
+ secure,
+ u16::try_from(segment.va >> 8)?,
+ ),
+ (source, _) => self.dma_wr(
+ source,
+ if secure {
+ FalconMem::ImemSecure
+ } else {
+ FalconMem::ImemNonSecure
+ },
+ segment.va,
+ segment.dst_start,
+ ),
+ }
+ }
+
+ /// Load `segment` into falcon's `DMEM`.
+ fn load_dmem(&self, segment: &FalconDmemSegment<'_>) -> Result {
+ match (segment.source, self.hal.load_method()) {
+ (FalconSegmentSource::Sysmem(data), LoadMethod::Pio) => {
+ // Tagging not possible if using PIO.
+ if segment.va.is_some() {
+ return Err(EINVAL);
+ }
+
+ self.pio_wr_dmem_slice(data, segment.dst_start)
+ }
+ (source, _) => self.dma_wr(
+ source,
+ FalconMem::Dmem {
+ tag: segment.va.is_some(),
+ },
+ segment.va.unwrap_or(0),
+ segment.dst_start,
+ ),
+ }
+ }
+
+ /// Load a firmware image into Falcon memory, using the preferred method for the current
+ /// chipset.
+ pub(crate) fn load<F: FalconFirmware<Target = E>>(&self, fw: &F) -> Result {
+ let image = fw.image()?;
self.dma_reset();
- self.dma_wr(
- FalconSegmentSource::Sysmem(imem_sec.data(blob)?),
- FalconMem::ImemSecure,
- imem_sec.src_start,
- imem_sec.dst_start,
- )?;
- self.dma_wr(
- FalconSegmentSource::Sysmem(dmem.data(blob)?),
- FalconMem::Dmem { tag: false },
- 0,
- dmem.dst_start,
- )
+ if let Some(segment) = &image.imem_ns {
+ self.load_imem(segment, false)?;
+ }
+ if let Some(segment) = &image.imem_sec {
+ self.load_imem(segment, true)?;
+ }
+ self.load_dmem(&image.dmem)
}
/// Wait until the falcon CPU is halted.
@@ -804,15 +700,6 @@ pub(crate) fn is_riscv_halted(&self) -> Result<bool> {
self.hal.is_riscv_halted(self)
}
- /// Load a firmware image into Falcon memory, using the preferred method for the current
- /// chipset.
- pub(crate) fn load<F: FalconFirmware<Target = E> + FalconDmaLoadable>(&self, fw: &F) -> Result {
- match self.hal.load_method() {
- LoadMethod::Dma => self.dma_load(fw),
- LoadMethod::Pio => self.pio_load(&fw.try_as_pio_loadable()?),
- }
- }
-
/// Write the application version to the OS register.
pub(crate) fn write_os_version(&self, app_version: u32) {
self.pfalcon
diff --git a/drivers/gpu/nova-core/firmware.rs b/drivers/gpu/nova-core/firmware.rs
index 358c9b8db0b8..97d6b1d83967 100644
--- a/drivers/gpu/nova-core/firmware.rs
+++ b/drivers/gpu/nova-core/firmware.rs
@@ -13,10 +13,7 @@
};
use crate::{
- falcon::{
- FalconDmaLoadTarget,
- FalconFirmware, //
- },
+ falcon::FalconFirmware,
gpu,
gsp::boot_firmware_files,
num::IntoSafeCast, //
@@ -148,10 +145,6 @@ fn size(&self) -> usize {
const HDR_SIZE_MASK: u32 = 0xffff0000;
((hdr & HDR_SIZE_MASK) >> HDR_SIZE_SHIFT).into_safe_cast()
}
-
- fn imem_sec_load_params(&self) -> FalconDmaLoadTarget;
- fn imem_ns_load_params(&self) -> Option<FalconDmaLoadTarget>;
- fn dmem_load_params(&self) -> FalconDmaLoadTarget;
}
impl FalconUCodeDescriptor for FalconUCodeDescV2 {
@@ -182,37 +175,6 @@ fn signature_count(&self) -> u8 {
fn signature_versions(&self) -> u16 {
0
}
-
- fn imem_sec_load_params(&self) -> FalconDmaLoadTarget {
- // `imem_sec_base` is the *virtual* start address of the secure IMEM segment, so subtract
- // `imem_virt_base` to get its physical offset.
- let imem_sec_start = self.imem_sec_base.saturating_sub(self.imem_virt_base);
-
- FalconDmaLoadTarget {
- src_start: imem_sec_start,
- dst_start: self.imem_phys_base.saturating_add(imem_sec_start),
- len: self.imem_sec_size,
- }
- }
-
- fn imem_ns_load_params(&self) -> Option<FalconDmaLoadTarget> {
- Some(FalconDmaLoadTarget {
- // Non-secure code always starts at offset 0.
- src_start: 0,
- dst_start: self.imem_phys_base,
- // `imem_load_size` includes the size of the secure segment, so subtract it to
- // get the correct amount of data to copy.
- len: self.imem_load_size.saturating_sub(self.imem_sec_size),
- })
- }
-
- fn dmem_load_params(&self) -> FalconDmaLoadTarget {
- FalconDmaLoadTarget {
- src_start: self.dmem_offset,
- dst_start: self.dmem_phys_base,
- len: self.dmem_load_size,
- }
- }
}
impl FalconUCodeDescriptor for FalconUCodeDescV3 {
@@ -243,29 +205,6 @@ fn signature_count(&self) -> u8 {
fn signature_versions(&self) -> u16 {
self.signature_versions
}
-
- fn imem_sec_load_params(&self) -> FalconDmaLoadTarget {
- FalconDmaLoadTarget {
- // IMEM segment always starts at offset 0.
- src_start: 0,
- dst_start: self.imem_phys_base,
- len: self.imem_load_size,
- }
- }
-
- fn imem_ns_load_params(&self) -> Option<FalconDmaLoadTarget> {
- // Not used on V3 platforms
- None
- }
-
- fn dmem_load_params(&self) -> FalconDmaLoadTarget {
- FalconDmaLoadTarget {
- // DMEM segment starts right after the IMEM one.
- src_start: self.imem_load_size,
- dst_start: self.dmem_phys_base,
- len: self.dmem_load_size,
- }
- }
}
/// Trait implemented by types defining the signed state of a firmware.
@@ -328,6 +267,17 @@ fn no_patch_signature(self) -> FirmwareObject<F, Signed> {
}
}
+impl<F: FalconFirmware> FirmwareObject<F, Signed> {
+ /// Returns the `len` bytes of the firmware that start at offset `start`, or
+ /// `EINVAL` if they are not all within the firmware.
+ fn bytes(&self, start: u32, len: u32) -> Result<&[u8]> {
+ let start: usize = start.into_safe_cast();
+ let len: usize = len.into_safe_cast();
+
+ self.0.get(start..start + len).ok_or(EINVAL)
+ }
+}
+
pub(crate) struct ModInfoBuilder<const N: usize>(firmware::ModInfoBuilder<N>);
impl<const N: usize> ModInfoBuilder<N> {
diff --git a/drivers/gpu/nova-core/firmware/booter.rs b/drivers/gpu/nova-core/firmware/booter.rs
index 7a0163a00285..159d647e4293 100644
--- a/drivers/gpu/nova-core/firmware/booter.rs
+++ b/drivers/gpu/nova-core/firmware/booter.rs
@@ -18,9 +18,11 @@
sec2::Sec2,
Falcon,
FalconBromParams,
- FalconDmaLoadTarget,
- FalconDmaLoadable,
- FalconFirmware, //
+ FalconDmemSegment,
+ FalconFirmware,
+ FalconImage,
+ FalconImemSegment,
+ FalconSegmentSource, //
},
firmware::{
tlv::{
@@ -48,15 +50,21 @@ fn as_ref(&self) -> &[u8] {
impl<'a> FirmwareSignature<BooterFirmware> for BooterSignature<'a> {}
+/// Offset and size in bytes of a section of the Booter image.
+struct BooterSection {
+ offset: u32,
+ size: u32,
+}
+
/// The `Booter` loader firmware, responsible for loading the GSP.
pub(crate) struct BooterFirmware {
- // Load parameters for Secure `IMEM` falcon memory.
- imem_sec_load_target: FalconDmaLoadTarget,
- // Load parameters for Non-Secure `IMEM` falcon memory,
+ // Section of the image to load into secure `IMEM` falcon memory.
+ imem_sec: BooterSection,
+ // Section of the image to load into non-secure `IMEM` falcon memory,
// used only on Turing and GA100
- imem_ns_load_target: Option<FalconDmaLoadTarget>,
- // Load parameters for `DMEM` falcon memory.
- dmem_load_target: FalconDmaLoadTarget,
+ imem_ns: Option<BooterSection>,
+ // Section of the image to load into `DMEM` falcon memory.
+ dmem: BooterSection,
// BROM falcon parameters.
brom_params: FalconBromParams,
// Device-mapped firmware image.
@@ -148,30 +156,20 @@ pub(crate) fn new(
// GA102+. The extraction of the IMEM sections differs between the two
// versions. Unfortunately, the file names are the same, and the headers
// don't indicate the versions. The only way to differentiate is by the Chipset.
- let (imem_sec_dst_start, imem_ns_load_target) = if chipset <= Chipset::GA100 {
- (
- app0_code_offset,
- Some(FalconDmaLoadTarget {
- src_start: os_code_offset,
- dst_start: os_code_offset,
- len: os_code_size,
- }),
- )
- } else {
- (0, None)
- };
+ let imem_ns = (chipset <= Chipset::GA100).then_some(BooterSection {
+ offset: os_code_offset,
+ size: os_code_size,
+ });
Ok(Self {
- imem_sec_load_target: FalconDmaLoadTarget {
- src_start: app0_code_offset,
- dst_start: imem_sec_dst_start,
- len: app0_code_size,
+ imem_sec: BooterSection {
+ offset: app0_code_offset,
+ size: app0_code_size,
},
- imem_ns_load_target,
- dmem_load_target: FalconDmaLoadTarget {
- src_start: os_data_offset,
- dst_start: 0,
- len: os_data_size,
+ imem_ns,
+ dmem: BooterSection {
+ offset: os_data_offset,
+ size: os_data_size,
},
brom_params,
ucode: ucode_signed,
@@ -207,36 +205,50 @@ pub(crate) fn run<T>(
}
}
-impl FalconDmaLoadable for BooterFirmware {
- fn as_slice(&self) -> &[u8] {
- self.ucode.0.as_slice()
- }
-
- fn imem_sec_load_params(&self) -> FalconDmaLoadTarget {
- self.imem_sec_load_target.clone()
- }
-
- fn imem_ns_load_params(&self) -> Option<FalconDmaLoadTarget> {
- self.imem_ns_load_target.clone()
- }
-
- fn dmem_load_params(&self) -> FalconDmaLoadTarget {
- self.dmem_load_target.clone()
- }
-}
-
impl FalconFirmware for BooterFirmware {
type Target = Sec2;
+ fn image(&self) -> Result<FalconImage<'_>> {
+ // Booter code runs at the virtual address equal to its offset in the
+ // image.
+ let imem = |section: &BooterSection, dst_start| {
+ Ok::<_, Error>(FalconImemSegment {
+ source: FalconSegmentSource::Sysmem(
+ self.ucode.bytes(section.offset, section.size)?,
+ ),
+ dst_start,
+ va: section.offset,
+ })
+ };
+
+ // With the non-secure code, both code sections are loaded at their
+ // offsets in the image. Without it, the secure code is loaded at the
+ // start of `IMEM`.
+ let (imem_ns, imem_sec_dst_start) = match &self.imem_ns {
+ Some(ns) => (Some(imem(ns, ns.offset)?), self.imem_sec.offset),
+ None => (None, 0),
+ };
+
+ Ok(FalconImage {
+ imem_ns,
+ imem_sec: Some(imem(&self.imem_sec, imem_sec_dst_start)?),
+ dmem: FalconDmemSegment {
+ source: FalconSegmentSource::Sysmem(
+ self.ucode.bytes(self.dmem.offset, self.dmem.size)?,
+ ),
+ dst_start: 0,
+ va: None,
+ },
+ })
+ }
+
fn brom_params(&self) -> FalconBromParams {
self.brom_params.clone()
}
fn boot_addr(&self) -> u32 {
- if let Some(ns_target) = &self.imem_ns_load_target {
- ns_target.dst_start
- } else {
- self.imem_sec_load_target.src_start
- }
+ // Execution starts in the non-secure code if it is loaded, else in the
+ // secure code.
+ self.imem_ns.as_ref().unwrap_or(&self.imem_sec).offset
}
}
diff --git a/drivers/gpu/nova-core/firmware/fwsec.rs b/drivers/gpu/nova-core/firmware/fwsec.rs
index 45b088f30b76..143f79a559ee 100644
--- a/drivers/gpu/nova-core/firmware/fwsec.rs
+++ b/drivers/gpu/nova-core/firmware/fwsec.rs
@@ -31,9 +31,11 @@
gsp::Gsp,
Falcon,
FalconBromParams,
- FalconDmaLoadTarget,
- FalconDmaLoadable,
- FalconFirmware, //
+ FalconDmemSegment,
+ FalconFirmware,
+ FalconImage,
+ FalconImemSegment,
+ FalconSegmentSource, //
},
firmware::{
FalconUCodeDesc,
@@ -180,27 +182,35 @@ pub(crate) struct FwsecFirmware {
ucode: FirmwareObject<Self, Signed>,
}
-impl FalconDmaLoadable for FwsecFirmware {
- fn as_slice(&self) -> &[u8] {
- self.ucode.0.as_slice()
- }
-
- fn imem_sec_load_params(&self) -> FalconDmaLoadTarget {
- self.desc.imem_sec_load_params()
- }
-
- fn imem_ns_load_params(&self) -> Option<FalconDmaLoadTarget> {
- self.desc.imem_ns_load_params()
- }
-
- fn dmem_load_params(&self) -> FalconDmaLoadTarget {
- self.desc.dmem_load_params()
- }
-}
-
impl FalconFirmware for FwsecFirmware {
type Target = Gsp;
+ fn image(&self) -> Result<FalconImage<'_>> {
+ let desc = match &self.desc {
+ // V2 FWSEC only boots through the generic bootloader.
+ FalconUCodeDesc::V2(_) => return Err(EINVAL),
+ FalconUCodeDesc::V3(desc) => desc,
+ };
+
+ Ok(FalconImage {
+ imem_ns: None,
+ imem_sec: Some(FalconImemSegment {
+ // IMEM segment always starts at offset 0.
+ source: FalconSegmentSource::Sysmem(self.ucode.bytes(0, desc.imem_load_size)?),
+ dst_start: desc.imem_phys_base,
+ va: self.boot_addr(),
+ }),
+ dmem: FalconDmemSegment {
+ // DMEM segment starts right after the IMEM one.
+ source: FalconSegmentSource::Sysmem(
+ self.ucode.bytes(desc.imem_load_size, desc.dmem_load_size)?,
+ ),
+ dst_start: desc.dmem_phys_base,
+ va: None,
+ },
+ })
+ }
+
fn brom_params(&self) -> FalconBromParams {
FalconBromParams {
pkc_data_offset: self.desc.pkc_data_offset(),
diff --git a/drivers/gpu/nova-core/firmware/gen_bootloader.rs b/drivers/gpu/nova-core/firmware/gen_bootloader.rs
index 5dea98220e9d..1095b8acfa78 100644
--- a/drivers/gpu/nova-core/firmware/gen_bootloader.rs
+++ b/drivers/gpu/nova-core/firmware/gen_bootloader.rs
@@ -22,12 +22,13 @@
gsp::Gsp,
Falcon,
FalconBromParams,
+ FalconDmemSegment,
FalconFbifMemType,
FalconFbifTarget,
FalconFirmware,
- FalconPioDmemLoadTarget,
- FalconPioImemLoadTarget,
- FalconPioLoadable, //
+ FalconImage,
+ FalconImemSegment,
+ FalconSegmentSource, //
},
firmware::{
tlv::{
@@ -176,17 +177,6 @@ fn boot_addr(&self) -> u32 {
u32::from(self.start_tag) << 8
}
- /// Returns the PIO parameters that place this bootloader in non-secure IMEM, at byte offset
- /// `dst_start`.
- fn imem_load_params(&self, dst_start: Bounded<u32, 24>) -> FalconPioImemLoadTarget<'_> {
- FalconPioImemLoadTarget {
- data: self.ucode.as_ref(),
- dst_start,
- secure: false,
- start_tag: self.start_tag,
- }
- }
-
/// Runs the bootloader on `falcon` to load and start the image that `dmem_desc` names.
///
/// The bootloader and the descriptor are loaded by PIO, the bootloader in the last blocks of
@@ -231,15 +221,15 @@ pub(crate) fn run(
dmem_desc,
};
- falcon.pio_load(&fw)?;
+ falcon.load(&fw)?;
falcon.boot(&fw, Some(mbox0), None)
},
)
}
}
-/// The generic bootloader together with the descriptor that it reads from DMEM offset 0, as one
-/// firmware that [`Falcon::pio_load`] accepts.
+/// The generic bootloader together with the descriptor that it reads from DMEM
+/// offset 0, as one [`FalconFirmware`].
struct GenericBootloaderLoad<'a> {
bootloader: &'a GenericBootloader,
/// Byte offset in IMEM at which the bootloader's code is loaded.
@@ -250,6 +240,22 @@ struct GenericBootloaderLoad<'a> {
impl FalconFirmware for GenericBootloaderLoad<'_> {
type Target = Gsp;
+ fn image(&self) -> Result<FalconImage<'_>> {
+ Ok(FalconImage {
+ imem_ns: Some(FalconImemSegment {
+ source: FalconSegmentSource::Sysmem(self.bootloader.ucode.as_ref()),
+ dst_start: self.imem_dst_start.get(),
+ va: self.bootloader.boot_addr(),
+ }),
+ imem_sec: None,
+ dmem: FalconDmemSegment {
+ source: FalconSegmentSource::Sysmem(self.dmem_desc.as_bytes()),
+ dst_start: 0,
+ va: None,
+ },
+ })
+ }
+
fn brom_params(&self) -> FalconBromParams {
// The bootloader is unsigned, and the falcon HALs of the chipsets that load it this way
// write no BROM registers, so these values never reach hardware.
@@ -264,20 +270,3 @@ fn boot_addr(&self) -> u32 {
self.bootloader.boot_addr()
}
}
-
-impl FalconPioLoadable for GenericBootloaderLoad<'_> {
- fn imem_sec_load_params(&self) -> Option<FalconPioImemLoadTarget<'_>> {
- None
- }
-
- fn imem_ns_load_params(&self) -> Option<FalconPioImemLoadTarget<'_>> {
- Some(self.bootloader.imem_load_params(self.imem_dst_start))
- }
-
- fn dmem_load_params(&self) -> FalconPioDmemLoadTarget<'_> {
- FalconPioDmemLoadTarget {
- data: self.dmem_desc.as_bytes(),
- dst_start: 0,
- }
- }
-}
--
2.56.1
^ permalink raw reply [flat|nested] 15+ messages in thread
* [PATCH 06/14] gpu: nova-core: falcon: load the firmware image in Falcon::boot
2026-11-30 9:28 [PATCH 00/14] gpu: nova-core: merge `load` and `boot` for falcons, add load+exec handlers Eliot Courtney
` (4 preceding siblings ...)
2026-11-30 9:28 ` [PATCH 05/14] gpu: nova-core: falcon: add `FalconImage` for `FalconFirmware` trait Eliot Courtney
@ 2026-11-30 9:28 ` Eliot Courtney
2026-11-30 9:28 ` [PATCH 07/14] gpu: nova-core: firmware: use `zerocopy` for `BootloaderDmemDescV2` Eliot Courtney
` (7 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: Eliot Courtney @ 2026-11-30 9:28 UTC (permalink / raw)
To: Danilo Krummrich, Alice Ryhl, Alexandre Courbot, David Airlie,
Simona Vetter
Cc: John Hubbard, Alistair Popple, Timur Tabi, Zhi Wang, nova-gpu,
dri-devel, linux-kernel, Eliot Courtney
Remove the separate `load` step for booting falcons. This `load` step
was always paired with `boot` right after. It is simpler to merge these
steps and also statically prevents trying to boot a falcon without
loading the firmware first.
Reviewed-by: Alexandre Courbot <acourbot@nvidia.com>
Signed-off-by: Eliot Courtney <ecourtney@nvidia.com>
---
drivers/gpu/nova-core/falcon.rs | 9 +++++----
drivers/gpu/nova-core/firmware/booter.rs | 1 -
drivers/gpu/nova-core/firmware/fwsec.rs | 3 ---
drivers/gpu/nova-core/firmware/gen_bootloader.rs | 1 -
drivers/gpu/nova-core/gsp/hal/tu102.rs | 1 -
5 files changed, 5 insertions(+), 10 deletions(-)
diff --git a/drivers/gpu/nova-core/falcon.rs b/drivers/gpu/nova-core/falcon.rs
index c2fdb9e0f123..0a375394f71a 100644
--- a/drivers/gpu/nova-core/falcon.rs
+++ b/drivers/gpu/nova-core/falcon.rs
@@ -577,9 +577,7 @@ fn load_dmem(&self, segment: &FalconDmemSegment<'_>) -> Result {
/// Load a firmware image into Falcon memory, using the preferred method for the current
/// chipset.
- pub(crate) fn load<F: FalconFirmware<Target = E>>(&self, fw: &F) -> Result {
- let image = fw.image()?;
-
+ fn load(&self, image: &FalconImage<'_>) -> Result {
self.dma_reset();
if let Some(segment) = &image.imem_ns {
@@ -649,7 +647,7 @@ pub(crate) fn read_mailboxes(&self) -> (u32, u32) {
(mbox0, mbox1)
}
- /// Start running `fw`, which must already be loaded into the falcon.
+ /// Load `fw` into the falcon and start running it.
///
/// `mbox0` and `mbox1` are optional parameters to write into the `MBOX0` and `MBOX1` registers
/// prior to running.
@@ -662,6 +660,9 @@ pub(crate) fn boot<F: FalconFirmware<Target = E>>(
mbox0: Option<u32>,
mbox1: Option<u32>,
) -> Result<(u32, u32)> {
+ fw.image()
+ .and_then(|image| self.load(&image))
+ .inspect_err(|e| dev_err!(self.dev, "Failed to load falcon firmware: {:?}\n", e))?;
self.hal.program_brom(self, &fw.brom_params());
self.pfalcon
.write_reg(regs::NV_PFALCON_FALCON_BOOTVEC::zeroed().with_value(fw.boot_addr()));
diff --git a/drivers/gpu/nova-core/firmware/booter.rs b/drivers/gpu/nova-core/firmware/booter.rs
index 159d647e4293..20935e4de9d1 100644
--- a/drivers/gpu/nova-core/firmware/booter.rs
+++ b/drivers/gpu/nova-core/firmware/booter.rs
@@ -187,7 +187,6 @@ pub(crate) fn run<T>(
wpr_meta: &Coherent<'_, T>,
) -> Result {
sec2_falcon.reset()?;
- sec2_falcon.load(self)?;
let wpr_dma_address = wpr_meta.dma_address();
let (mbox0, mbox1) = sec2_falcon.boot(
self,
diff --git a/drivers/gpu/nova-core/firmware/fwsec.rs b/drivers/gpu/nova-core/firmware/fwsec.rs
index 143f79a559ee..e267ed77d158 100644
--- a/drivers/gpu/nova-core/firmware/fwsec.rs
+++ b/drivers/gpu/nova-core/firmware/fwsec.rs
@@ -402,9 +402,6 @@ pub(crate) fn run(&self, dev: &Device<device::Bound>, falcon: &Falcon<'_, Gsp>)
falcon
.reset()
.inspect_err(|e| dev_err!(dev, "Failed to reset GSP falcon: {:?}\n", e))?;
- falcon
- .load(self)
- .inspect_err(|e| dev_err!(dev, "Failed to load FWSEC firmware: {:?}\n", e))?;
let (mbox0, _) = falcon
.boot(self, Some(0), None)
.inspect_err(|e| dev_err!(dev, "Failed to boot FWSEC firmware: {:?}\n", e))?;
diff --git a/drivers/gpu/nova-core/firmware/gen_bootloader.rs b/drivers/gpu/nova-core/firmware/gen_bootloader.rs
index 1095b8acfa78..a598eb451665 100644
--- a/drivers/gpu/nova-core/firmware/gen_bootloader.rs
+++ b/drivers/gpu/nova-core/firmware/gen_bootloader.rs
@@ -221,7 +221,6 @@ pub(crate) fn run(
dmem_desc,
};
- falcon.load(&fw)?;
falcon.boot(&fw, Some(mbox0), None)
},
)
diff --git a/drivers/gpu/nova-core/gsp/hal/tu102.rs b/drivers/gpu/nova-core/gsp/hal/tu102.rs
index 80936194806a..2c95d178b020 100644
--- a/drivers/gpu/nova-core/gsp/hal/tu102.rs
+++ b/drivers/gpu/nova-core/gsp/hal/tu102.rs
@@ -97,7 +97,6 @@ fn run(&self, ctx: &mut GspBootContext<'_, '_>) -> Result {
}
ctx.sec2_falcon.reset()?;
- ctx.sec2_falcon.load(&self.booter_unloader)?;
// Sentinel value to confirm that Booter Unloader has run.
const MAILBOX_SENTINEL: u32 = 0xff;
--
2.56.1
^ permalink raw reply [flat|nested] 15+ messages in thread
* [PATCH 07/14] gpu: nova-core: firmware: use `zerocopy` for `BootloaderDmemDescV2`
2026-11-30 9:28 [PATCH 00/14] gpu: nova-core: merge `load` and `boot` for falcons, add load+exec handlers Eliot Courtney
` (5 preceding siblings ...)
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 ` Eliot Courtney
2026-11-30 9:28 ` [PATCH 08/14] gpu: nova-core: falcon: factor out the wait for the GSP suspend Eliot Courtney
` (6 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: Eliot Courtney @ 2026-11-30 9:28 UTC (permalink / raw)
To: Danilo Krummrich, Alice Ryhl, Alexandre Courbot, David Airlie,
Simona Vetter
Cc: John Hubbard, Alistair Popple, Timur Tabi, Zhi Wang, nova-gpu,
dri-devel, linux-kernel, Eliot Courtney
This removes an unsafe impl of `AsBytes`.
Signed-off-by: Eliot Courtney <ecourtney@nvidia.com>
---
drivers/gpu/nova-core/firmware/gen_bootloader.rs | 9 +++------
1 file changed, 3 insertions(+), 6 deletions(-)
diff --git a/drivers/gpu/nova-core/firmware/gen_bootloader.rs b/drivers/gpu/nova-core/firmware/gen_bootloader.rs
index a598eb451665..7e53f287ca2a 100644
--- a/drivers/gpu/nova-core/firmware/gen_bootloader.rs
+++ b/drivers/gpu/nova-core/firmware/gen_bootloader.rs
@@ -12,9 +12,9 @@
TryIntoBounded, //
},
prelude::*,
- ptr::Alignable,
- transmute::AsBytes, //
+ ptr::Alignable, //
};
+use zerocopy_derive::Immutable;
use crate::{
falcon::{
@@ -46,7 +46,7 @@
/// This has to be filled by the GPU driver and copied into DMEM at offset
/// [`BootloaderDesc.dmem_load_off`].
#[repr(C, packed)]
-#[derive(Debug, Clone)]
+#[derive(Debug, Clone, IntoBytes, Immutable)]
pub(crate) struct BootloaderDmemDescV2 {
/// Reserved, should always be first element.
reserved: [u32; 4],
@@ -123,9 +123,6 @@ pub(super) fn new(desc: &FalconUCodeDescV2, code_dma_base: u64, data_dma_base: u
}
}
-// SAFETY: This struct doesn't contain uninitialized bytes and doesn't have interior mutability.
-unsafe impl AsBytes 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.
--
2.56.1
^ permalink raw reply [flat|nested] 15+ messages in thread
* [PATCH 08/14] gpu: nova-core: falcon: factor out the wait for the GSP suspend
2026-11-30 9:28 [PATCH 00/14] gpu: nova-core: merge `load` and `boot` for falcons, add load+exec handlers Eliot Courtney
` (6 preceding siblings ...)
2026-11-30 9:28 ` [PATCH 07/14] gpu: nova-core: firmware: use `zerocopy` for `BootloaderDmemDescV2` Eliot Courtney
@ 2026-11-30 9:28 ` Eliot Courtney
2026-11-30 9:28 ` [PATCH 09/14] gpu: nova-core: gsp: factor out the core resume Eliot Courtney
` (5 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: Eliot Courtney @ 2026-11-30 9:28 UTC (permalink / raw)
To: Danilo Krummrich, Alice Ryhl, Alexandre Courbot, David Airlie,
Simona Vetter
Cc: John Hubbard, Alistair Popple, Timur Tabi, Zhi Wang, nova-gpu,
dri-devel, linux-kernel, Eliot Courtney
From: John Hubbard <jhubbard@nvidia.com>
The r000 boot protocol requires the driver to wait for the GSP suspend
bit after each load-and-execute event, as the shutdown path already
does.
In order to make the wait available to the boot sequence, factor it out
of the shutdown path, into a method of the GSP falcon.
No functional changes.
Signed-off-by: John Hubbard <jhubbard@nvidia.com>
Reviewed-by: Eliot Courtney <ecourtney@nvidia.com>
Signed-off-by: Eliot Courtney <ecourtney@nvidia.com>
---
drivers/gpu/nova-core/falcon/gsp.rs | 15 +++++++++++++++
drivers/gpu/nova-core/gsp/boot.rs | 8 +-------
2 files changed, 16 insertions(+), 7 deletions(-)
diff --git a/drivers/gpu/nova-core/falcon/gsp.rs b/drivers/gpu/nova-core/falcon/gsp.rs
index 54247691b53c..2ea28fa53db8 100644
--- a/drivers/gpu/nova-core/falcon/gsp.rs
+++ b/drivers/gpu/nova-core/falcon/gsp.rs
@@ -54,6 +54,21 @@ pub(crate) fn is_processor_suspended(&self) -> bool {
.processor_suspended()
}
+ /// Waits until GSP-RM has suspended the RISC-V core.
+ ///
+ /// # Errors
+ ///
+ /// - `ETIMEDOUT` if the core has not suspended within five seconds.
+ pub(crate) fn wait_for_processor_suspend(&self) -> Result {
+ read_poll_timeout(
+ || Ok(self.is_processor_suspended()),
+ |suspended| *suspended,
+ Delta::from_millis(10),
+ Delta::from_secs(5),
+ )
+ .map(|_| ())
+ }
+
/// Clears the SWGEN0 latch in the GSP falcon.
///
/// While the latch is set, no later message signals the tree, so a caller that consumed a
diff --git a/drivers/gpu/nova-core/gsp/boot.rs b/drivers/gpu/nova-core/gsp/boot.rs
index 9d5da5b165ac..2815fe8b306e 100644
--- a/drivers/gpu/nova-core/gsp/boot.rs
+++ b/drivers/gpu/nova-core/gsp/boot.rs
@@ -97,13 +97,7 @@ fn shutdown_gsp(
cmdq.send_rpc_command(commands::rpc::UnloadingGuestDriver::new(mode))?;
// Wait until GSP signals it is suspended.
- read_poll_timeout(
- || Ok(gsp_falcon.is_processor_suspended()),
- |suspended| *suspended,
- Delta::from_millis(10),
- Delta::from_secs(5),
- )
- .map(|_| ())
+ gsp_falcon.wait_for_processor_suspend()
}
/// Attempts to unload the GSP firmware.
--
2.56.1
^ permalink raw reply [flat|nested] 15+ messages in thread
* [PATCH 09/14] gpu: nova-core: gsp: factor out the core resume
2026-11-30 9:28 [PATCH 00/14] gpu: nova-core: merge `load` and `boot` for falcons, add load+exec handlers Eliot Courtney
` (7 preceding siblings ...)
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 ` Eliot Courtney
2026-11-30 9:28 ` [PATCH 10/14] gpu: nova-core: gsp: fix resume_gsp_rm()'s error messages Eliot Courtney
` (4 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: Eliot Courtney @ 2026-11-30 9:28 UTC (permalink / raw)
To: Danilo Krummrich, Alice Ryhl, Alexandre Courbot, David Airlie,
Simona Vetter
Cc: John Hubbard, Alistair Popple, Timur Tabi, Zhi Wang, nova-gpu,
dri-devel, linux-kernel, Eliot Courtney
From: John Hubbard <jhubbard@nvidia.com>
The r000 boot protocol requires the driver to reset the GSP falcon
before running the binary of a load-and-execute event, and to resume
GSP-RM afterwards. The core reset and the core resume commands of the
CPU sequencer already do both.
In order to make the core resume available outside the sequencer,
factor it out into a module of its own.
No functional changes.
Signed-off-by: John Hubbard <jhubbard@nvidia.com>
[ecourtney: factor out only the resume, `Falcon::boot()` calls `dma_reset()`]
Signed-off-by: Eliot Courtney <ecourtney@nvidia.com>
---
drivers/gpu/nova-core/gsp.rs | 1 +
drivers/gpu/nova-core/gsp/load_exec.rs | 71 ++++++++++++++++++++++++++++++++++
drivers/gpu/nova-core/gsp/sequencer.rs | 42 ++++----------------
3 files changed, 80 insertions(+), 34 deletions(-)
diff --git a/drivers/gpu/nova-core/gsp.rs b/drivers/gpu/nova-core/gsp.rs
index 2f1cdf8b7bec..854062112cf1 100644
--- a/drivers/gpu/nova-core/gsp.rs
+++ b/drivers/gpu/nova-core/gsp.rs
@@ -20,6 +20,7 @@
pub(crate) mod cmdq;
pub(crate) mod commands;
mod fw;
+mod load_exec;
mod logbuffer;
mod nvkv;
mod regs;
diff --git a/drivers/gpu/nova-core/gsp/load_exec.rs b/drivers/gpu/nova-core/gsp/load_exec.rs
new file mode 100644
index 000000000000..68bca8c87a36
--- /dev/null
+++ b/drivers/gpu/nova-core/gsp/load_exec.rs
@@ -0,0 +1,71 @@
+// SPDX-License-Identifier: GPL-2.0
+// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
+
+//! The core resume of the GSP falcon.
+
+use kernel::{
+ device,
+ dma::DmaAddress,
+ prelude::*,
+ time::Delta, //
+};
+
+use crate::falcon::{
+ gsp::Gsp,
+ sec2::Sec2,
+ Falcon, //
+};
+
+/// 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
+/// writes `bootloader_app_version` to its OS register once the resume has completed.
+///
+/// The SEC2 falcon must hold a loaded firmware that has not started.
+///
+/// # Errors
+///
+/// - `ETIMEDOUT` if the resume has not completed within two seconds.
+/// - `EIO` if `MAILBOX0` of the SEC2 falcon is not zero after the resume, or if the RISC-V core of
+/// the GSP falcon is not active.
+///
+/// Errors from the reset of the GSP falcon are propagated as-is.
+pub(super) fn resume_gsp_rm(
+ dev: &device::Device,
+ gsp_falcon: &Falcon<'_, Gsp>,
+ sec2_falcon: &Falcon<'_, Sec2>,
+ libos_dma_address: DmaAddress,
+ bootloader_app_version: u32,
+) -> Result {
+ // Reset the GSP to prepare it for resuming.
+ gsp_falcon.reset()?;
+
+ // Write the libOS DMA address to GSP mailboxes.
+ gsp_falcon.write_mailboxes(
+ Some(libos_dma_address as u32),
+ Some((libos_dma_address >> 32) as u32),
+ );
+
+ // Start the SEC2 falcon which will trigger GSP-RM to resume on the GSP.
+ sec2_falcon.start()?;
+
+ // Poll until GSP-RM reload/resume has completed (up to 2 seconds).
+ gsp_falcon.check_reload_completed(Delta::from_secs(2))?;
+
+ // Verify SEC2 completed successfully by checking its mailbox for errors.
+ let mbox0 = sec2_falcon.read_mailbox0();
+ if mbox0 != 0 {
+ dev_err!(dev, "Sequencer: sec2 errors: {:?}\n", mbox0);
+ return Err(EIO);
+ }
+
+ // Configure GSP with the bootloader version.
+ gsp_falcon.write_os_version(bootloader_app_version);
+
+ // Verify the GSP's RISC-V core is active indicating successful GSP boot.
+ if !gsp_falcon.is_riscv_active() {
+ dev_err!(dev, "Sequencer: RISC-V core is not active\n");
+ return Err(EIO);
+ }
+ Ok(())
+}
diff --git a/drivers/gpu/nova-core/gsp/sequencer.rs b/drivers/gpu/nova-core/gsp/sequencer.rs
index 23b09fb875e9..bd83dd924244 100644
--- a/drivers/gpu/nova-core/gsp/sequencer.rs
+++ b/drivers/gpu/nova-core/gsp/sequencer.rs
@@ -32,6 +32,7 @@
Cmdq, //
},
fw,
+ load_exec,
GspBootContext,
LibosMemoryRegionInitArgument, //
},
@@ -230,40 +231,13 @@ fn run(&self, seq: &GspSequencer<'_>) -> Result {
// At this point, 'SEC2-RTOS' has been loaded into SEC2 by the sequencer
// but neither SEC2-RTOS nor GSP-RM is running yet. This part of the
// sequencer will start both.
-
- // Reset the GSP to prepare it for resuming.
- seq.gsp_falcon.reset()?;
-
- let libos_dma_address = seq.libos.dma_address();
-
- // Write the libOS DMA address to GSP mailboxes.
- seq.gsp_falcon.write_mailboxes(
- Some(libos_dma_address as u32),
- Some((libos_dma_address >> 32) as u32),
- );
-
- // Start the SEC2 falcon which will trigger GSP-RM to resume on the GSP.
- seq.sec2_falcon.start()?;
-
- // Poll until GSP-RM reload/resume has completed (up to 2 seconds).
- seq.gsp_falcon.check_reload_completed(Delta::from_secs(2))?;
-
- // Verify SEC2 completed successfully by checking its mailbox for errors.
- let mbox0 = seq.sec2_falcon.read_mailbox0();
- if mbox0 != 0 {
- dev_err!(seq.dev, "Sequencer: sec2 errors: {:?}\n", mbox0);
- return Err(EIO);
- }
-
- // Configure GSP with the bootloader version.
- seq.gsp_falcon.write_os_version(seq.bootloader_app_version);
-
- // Verify the GSP's RISC-V core is active indicating successful GSP boot.
- if !seq.gsp_falcon.is_riscv_active() {
- dev_err!(seq.dev, "Sequencer: RISC-V core is not active\n");
- return Err(EIO);
- }
- Ok(())
+ load_exec::resume_gsp_rm(
+ seq.dev,
+ seq.gsp_falcon,
+ seq.sec2_falcon,
+ seq.libos.dma_address(),
+ seq.bootloader_app_version,
+ )
}
}
}
--
2.56.1
^ permalink raw reply [flat|nested] 15+ messages in thread
* [PATCH 10/14] gpu: nova-core: gsp: fix resume_gsp_rm()'s error messages
2026-11-30 9:28 [PATCH 00/14] gpu: nova-core: merge `load` and `boot` for falcons, add load+exec handlers Eliot Courtney
` (8 preceding siblings ...)
2026-11-30 9:28 ` [PATCH 09/14] gpu: nova-core: gsp: factor out the core resume Eliot Courtney
@ 2026-11-30 9:28 ` Eliot Courtney
2026-11-30 9:28 ` [PATCH 11/14] gpu: nova-core: falcon: select the BAR2 engine ID for framebuffer DMA Eliot Courtney
` (3 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: Eliot Courtney @ 2026-11-30 9:28 UTC (permalink / raw)
To: Danilo Krummrich, Alice Ryhl, Alexandre Courbot, David Airlie,
Simona Vetter
Cc: John Hubbard, Alistair Popple, Timur Tabi, Zhi Wang, nova-gpu,
dri-devel, linux-kernel, Eliot Courtney
From: John Hubbard <jhubbard@nvidia.com>
resume_gsp_rm()'s error messages have two problems:
* Both messages open with "Sequencer:", which assumes that the function
knows which code is calling it, and that this will never change. This
kind of tight coupling is almost never desirable in well-structured
code.
* One message prints the SEC2 mailbox value in decimal. That needlessly
complicates looking up the error code, given that Open RM documents
those values in hex.
Remove the sequencer's name from both messages and name the GSP-RM
resume instead, and print the SEC2 mailbox value in hexadecimal.
Signed-off-by: John Hubbard <jhubbard@nvidia.com>
Reviewed-by: Eliot Courtney <ecourtney@nvidia.com>
Signed-off-by: Eliot Courtney <ecourtney@nvidia.com>
---
drivers/gpu/nova-core/gsp/load_exec.rs | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/drivers/gpu/nova-core/gsp/load_exec.rs b/drivers/gpu/nova-core/gsp/load_exec.rs
index 68bca8c87a36..ac5eb8b7edd7 100644
--- a/drivers/gpu/nova-core/gsp/load_exec.rs
+++ b/drivers/gpu/nova-core/gsp/load_exec.rs
@@ -55,7 +55,11 @@ pub(super) fn resume_gsp_rm(
// Verify SEC2 completed successfully by checking its mailbox for errors.
let mbox0 = sec2_falcon.read_mailbox0();
if mbox0 != 0 {
- dev_err!(dev, "Sequencer: sec2 errors: {:?}\n", mbox0);
+ dev_err!(
+ dev,
+ "SEC2 reported an error while resuming GSP-RM: {:#x}\n",
+ mbox0
+ );
return Err(EIO);
}
@@ -64,7 +68,7 @@ pub(super) fn resume_gsp_rm(
// Verify the GSP's RISC-V core is active indicating successful GSP boot.
if !gsp_falcon.is_riscv_active() {
- dev_err!(dev, "Sequencer: RISC-V core is not active\n");
+ dev_err!(dev, "GSP RISC-V core is not active after resuming GSP-RM\n");
return Err(EIO);
}
Ok(())
--
2.56.1
^ permalink raw reply [flat|nested] 15+ messages in thread
* [PATCH 11/14] gpu: nova-core: falcon: select the BAR2 engine ID for framebuffer DMA
2026-11-30 9:28 [PATCH 00/14] gpu: nova-core: merge `load` and `boot` for falcons, add load+exec handlers Eliot Courtney
` (9 preceding siblings ...)
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 ` Eliot Courtney
2026-11-30 9:28 ` [PATCH 12/14] gpu: nova-core: gsp: add the r000 load-and-execute HS binary handler Eliot Courtney
` (2 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: Eliot Courtney @ 2026-11-30 9:28 UTC (permalink / raw)
To: Danilo Krummrich, Alice Ryhl, Alexandre Courbot, David Airlie,
Simona Vetter
Cc: John Hubbard, Alistair Popple, Timur Tabi, Zhi Wang, nova-gpu,
dri-devel, linux-kernel, Eliot Courtney
From: John Hubbard <jhubbard@nvidia.com>
When Open RM loads a binary from the framebuffer into a falcon by DMA,
it selects BAR2 as the MMU engine ID of the transfer, in the falcon's
FBIF_TRANSCFG register. Nova-core's definition of the register has no
field for the engine ID, so the DMA transfer code has no way to select
one.
Add the field, and select the BAR2 engine ID for a DMA transfer whose
source is the framebuffer.
Signed-off-by: John Hubbard <jhubbard@nvidia.com>
[ecourtney: match on `FalconSegmentSource`, which replaced `FalconDmaSource`]
[ecourtney: set TRANSCFG target and engine ID together in one `match`]
Signed-off-by: Eliot Courtney <ecourtney@nvidia.com>
---
drivers/gpu/nova-core/falcon.rs | 37 ++++++++++++++++++++++++++-----------
drivers/gpu/nova-core/regs.rs | 2 ++
2 files changed, 28 insertions(+), 11 deletions(-)
diff --git a/drivers/gpu/nova-core/falcon.rs b/drivers/gpu/nova-core/falcon.rs
index 0a375394f71a..fe6a84509d09 100644
--- a/drivers/gpu/nova-core/falcon.rs
+++ b/drivers/gpu/nova-core/falcon.rs
@@ -160,6 +160,19 @@ pub(crate) enum FalconFbifMemType with From<Bounded<u32, 1>> {
}
}
+bounded_enum! {
+ /// MMU engine ID under which the falcon's FBIF issues a DMA transfer.
+ ///
+ /// A kernel driver should select `Bar2Fn0`. (Only GPU firmware selects `Own`.)
+ #[derive(Debug, Copy, Clone)]
+ pub(crate) enum FalconFbifEngineIdFlag with From<Bounded<u32, 1>> {
+ /// The engine ID of PCI function 0's BAR2.
+ Bar2Fn0 = 0,
+ /// The falcon's own engine ID.
+ Own = 1,
+ }
+}
+
const PFALCON_REGION_SIZE: usize = SZ_4K;
const PFALCON2_REGION_SIZE: usize = SZ_4K;
@@ -434,19 +447,13 @@ fn dma_wr(
// Declare `dma_obj` here so it lives long enough for transfers to
// complete.
let dma_obj;
- let (dma_base, fbif_target, len) = match src {
+ let (dma_base, len) = match src {
FalconSegmentSource::Sysmem(data) => {
dma_obj = self.dma_stage(data, src_offset)?;
- (
- dma_obj.dma_address(),
- FalconFbifTarget::CoherentSysmem,
- u32::try_from(data.len())?,
- )
- }
- FalconSegmentSource::Framebuffer { base, len } => {
- (base, FalconFbifTarget::LocalFb, len)
+ (dma_obj.dma_address(), u32::try_from(data.len())?)
}
+ FalconSegmentSource::Framebuffer { base, len } => (base, len),
};
// DMA transfers can only be done in units of 256 bytes. Compute how many such transfers we
@@ -480,8 +487,16 @@ fn dma_wr(
self.pfalcon
.update(regs::NV_PFALCON_FBIF_TRANSCFG::at(0), |v| {
- v.with_target(fbif_target)
- .with_mem_type(FalconFbifMemType::Physical)
+ let v = v.with_mem_type(FalconFbifMemType::Physical);
+
+ match src {
+ FalconSegmentSource::Sysmem(_) => {
+ v.with_target(FalconFbifTarget::CoherentSysmem)
+ }
+ FalconSegmentSource::Framebuffer { .. } => v
+ .with_target(FalconFbifTarget::LocalFb)
+ .with_engine_id_flag(FalconFbifEngineIdFlag::Bar2Fn0),
+ }
});
for pos in (0..num_transfers).map(|i| i * DMA_LEN) {
diff --git a/drivers/gpu/nova-core/regs.rs b/drivers/gpu/nova-core/regs.rs
index dfe7944cf1e7..050054a2b23d 100644
--- a/drivers/gpu/nova-core/regs.rs
+++ b/drivers/gpu/nova-core/regs.rs
@@ -18,6 +18,7 @@
DmaTrfCmdSize,
FalconCoreRev,
FalconCoreRevSubversion,
+ FalconFbifEngineIdFlag,
FalconFbifMemType,
FalconFbifTarget,
FalconMem,
@@ -291,6 +292,7 @@ pub(crate) fn usable_fb_size(self) -> u64 {
}
pub(crate) NV_PFALCON_FBIF_TRANSCFG(u32)[8] @ 0x00000600 {
+ 16:16 engine_id_flag => FalconFbifEngineIdFlag;
2:2 mem_type => FalconFbifMemType;
1:0 target ?=> FalconFbifTarget;
}
--
2.56.1
^ permalink raw reply [flat|nested] 15+ messages in thread
* [PATCH 12/14] gpu: nova-core: gsp: add the r000 load-and-execute HS binary handler
2026-11-30 9:28 [PATCH 00/14] gpu: nova-core: merge `load` and `boot` for falcons, add load+exec handlers Eliot Courtney
` (10 preceding siblings ...)
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
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
13 siblings, 0 replies; 15+ messages in thread
From: Eliot Courtney @ 2026-11-30 9:28 UTC (permalink / raw)
To: Danilo Krummrich, Alice Ryhl, Alexandre Courbot, David Airlie,
Simona Vetter
Cc: John Hubbard, Alistair Popple, Timur Tabi, Zhi Wang, nova-gpu,
dri-devel, linux-kernel, Eliot Courtney
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
^ permalink raw reply [flat|nested] 15+ messages in thread
* [PATCH 13/14] gpu: nova-core: gsp: add the r000 load-and-execute bootloader handler
2026-11-30 9:28 [PATCH 00/14] gpu: nova-core: merge `load` and `boot` for falcons, add load+exec handlers Eliot Courtney
` (11 preceding siblings ...)
2026-11-30 9:28 ` [PATCH 12/14] gpu: nova-core: gsp: add the r000 load-and-execute HS binary handler Eliot Courtney
@ 2026-11-30 9:28 ` Eliot Courtney
2026-11-30 9:28 ` [PATCH 14/14] gpu: nova-core: gsp: add the load-and-execute event dispatcher Eliot Courtney
13 siblings, 0 replies; 15+ messages in thread
From: Eliot Courtney @ 2026-11-30 9:28 UTC (permalink / raw)
To: Danilo Krummrich, Alice Ryhl, Alexandre Courbot, David Airlie,
Simona Vetter
Cc: John Hubbard, Alistair Popple, Timur Tabi, Zhi Wang, nova-gpu,
dri-devel, linux-kernel, Eliot Courtney
From: John Hubbard <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>
[ecourtney: zerocopy derives for `GenericBootloaderParams`, no `unsafe impl`]
[ecourtney: derive `FromBytes` for `BootloaderDmemDescV2`, no `unsafe impl`]
[ecourtney: move MAILBOX0 check and resume to `handle_load_exec_event()`]
[ecourtney: module doc's FBIF sentence moved to the HS binary patch]
[ecourtney: move some methods to be impls of `GspBootContext`]
Signed-off-by: Eliot Courtney <ecourtney@nvidia.com>
---
drivers/gpu/nova-core/firmware/gen_bootloader.rs | 2 +-
drivers/gpu/nova-core/gsp/load_exec.rs | 140 +++++++++++++++++++++++
2 files changed, 141 insertions(+), 1 deletion(-)
diff --git a/drivers/gpu/nova-core/firmware/gen_bootloader.rs b/drivers/gpu/nova-core/firmware/gen_bootloader.rs
index 7e53f287ca2a..b4631cf9e76c 100644
--- a/drivers/gpu/nova-core/firmware/gen_bootloader.rs
+++ b/drivers/gpu/nova-core/firmware/gen_bootloader.rs
@@ -46,7 +46,7 @@
/// This has to be filled by the GPU driver and copied into DMEM at offset
/// [`BootloaderDesc.dmem_load_off`].
#[repr(C, packed)]
-#[derive(Debug, Clone, IntoBytes, Immutable)]
+#[derive(Debug, Clone, FromBytes, IntoBytes, Immutable)]
pub(crate) struct BootloaderDmemDescV2 {
/// Reserved, should always be first element.
reserved: [u32; 4],
diff --git a/drivers/gpu/nova-core/gsp/load_exec.rs b/drivers/gpu/nova-core/gsp/load_exec.rs
index 6d832cb9ec24..4dbb27dc03a1 100644
--- a/drivers/gpu/nova-core/gsp/load_exec.rs
+++ b/drivers/gpu/nova-core/gsp/load_exec.rs
@@ -29,11 +29,16 @@
Falcon,
FalconBromParams,
FalconDmemSegment,
+ FalconFbifTarget,
FalconFirmware,
FalconImage,
FalconImemSegment,
FalconSegmentSource, //
},
+ firmware::gen_bootloader::{
+ BootloaderDmemDescV2,
+ GenericBootloader, //
+ },
gsp::{
cmdq::gmc::MessageFromGsp,
GspBootContext, //
@@ -172,6 +177,88 @@ fn handle_hs_binary(&self, params: &HsBinaryParams) -> Result<u32> {
);
})
}
+
+ /// 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
+ /// returns `MAILBOX0` once the image has halted.
+ ///
+ /// `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.
+ ///
+ /// # 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 and the run of the bootloader are
+ /// propagated as-is.
+ #[expect(dead_code)]
+ fn handle_generic_bootloader(
+ &self,
+ bootloader: Option<&GenericBootloader>,
+ params: &GenericBootloaderParams,
+ ) -> Result<u32> {
+ /// Expected size of the descriptor, in bytes.
+ const DMEM_DESC_SIZE: u32 = cv!(size_of::<BootloaderDmemDescV2>());
+
+ let dev = self.dev();
+ let gsp_falcon = self.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()?;
+
+ self.reset_gsp_falcon_after_suspend()?;
+
+ bootloader
+ .run(
+ gsp_falcon,
+ ¶ms.dmem_desc,
+ fbif_target,
+ FLCN_ERR_BINARY_NOT_STARTED,
+ )
+ .map(|(mbox0, _)| mbox0)
+ .inspect_err(|e| {
+ dev_err!(
+ dev,
+ "Failed to run the generic bootloader: {:?} (mbox0={:#x})\n",
+ e,
+ gsp_falcon.read_mailbox0()
+ );
+ })
+ }
}
/// Payload of a `GMCAPI_CMD_EXEC_HS_BINARY` event, which describes the HS binary to run.
@@ -291,3 +378,56 @@ fn boot_addr(&self) -> u32 {
self.imem.va
}
}
+
+/// Payload of a `GMCAPI_CMD_EXEC_GENERIC_BOOTLOADER` event, which describes the image for the
+/// generic falcon bootloader to run.
+#[repr(C)]
+#[derive(FromBytes, IntoBytes)]
+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),
+ }
+ }
+}
+
+impl MessageFromGsp for GenericBootloaderParams {
+ 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)
+ }
+}
--
2.56.1
^ permalink raw reply [flat|nested] 15+ messages in thread
* [PATCH 14/14] gpu: nova-core: gsp: add the load-and-execute event dispatcher
2026-11-30 9:28 [PATCH 00/14] gpu: nova-core: merge `load` and `boot` for falcons, add load+exec handlers Eliot Courtney
` (12 preceding siblings ...)
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 ` Eliot Courtney
13 siblings, 0 replies; 15+ messages in thread
From: Eliot Courtney @ 2026-11-30 9:28 UTC (permalink / raw)
To: Danilo Krummrich, Alice Ryhl, Alexandre Courbot, David Airlie,
Simona Vetter
Cc: John Hubbard, Alistair Popple, Timur Tabi, Zhi Wang, nova-gpu,
dri-devel, linux-kernel, Eliot Courtney
From: John Hubbard <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>
[ecourtney: check MAILBOX0 and call `resume_gsp_rm()` here, for both events]
[ecourtney: move some methods to be impls of `GspBootContext`]
Signed-off-by: Eliot Courtney <ecourtney@nvidia.com>
---
drivers/gpu/nova-core/gsp/load_exec.rs | 84 ++++++++++++++++++++++++++++++++--
1 file changed, 81 insertions(+), 3 deletions(-)
diff --git a/drivers/gpu/nova-core/gsp/load_exec.rs b/drivers/gpu/nova-core/gsp/load_exec.rs
index 4dbb27dc03a1..b42be7393946 100644
--- a/drivers/gpu/nova-core/gsp/load_exec.rs
+++ b/drivers/gpu/nova-core/gsp/load_exec.rs
@@ -40,7 +40,11 @@
GenericBootloader, //
},
gsp::{
- cmdq::gmc::MessageFromGsp,
+ cmdq::gmc::{
+ GmcMessage,
+ MessageFromGsp, //
+ },
+ fw::GmcCommandId,
GspBootContext, //
},
sbuffer::SBufferIter, //
@@ -113,6 +117,82 @@ pub(super) fn resume_gsp_rm(
}
impl GspBootContext<'_, '_> {
+ /// 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 is followed by [`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 and from the resume of GSP-RM are propagated
+ /// as-is.
+ #[expect(dead_code)]
+ pub(super) fn handle_load_exec_event(
+ &self,
+ bootloader: Option<&GenericBootloader>,
+ libos_dma_address: DmaAddress,
+ bootloader_app_version: u32,
+ event: &GmcMessage<'_>,
+ ) -> Result {
+ let dev = self.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| self.handle_generic_bootloader(bootloader, ¶ms)),
+ ),
+ Ok(id @ GmcCommandId::ExecHsBinary) => (
+ id,
+ HsBinaryParams::read(&mut payload)
+ .and_then(|params| self.handle_hs_binary(¶ms)),
+ ),
+ _ => {
+ dev_err!(dev, "Not a load-and-execute event: {:?}\n", command);
+ return Err(EINVAL);
+ }
+ };
+
+ result
+ .and_then(|mbox0| {
+ if mbox0 == FLCN_ERR_BINARY_NOT_STARTED {
+ dev_err!(
+ dev,
+ "Binary of load-and-execute event {:?} did not start\n",
+ id
+ );
+ } else {
+ dev_dbg!(
+ dev,
+ "Binary of load-and-execute event {:?} halted with mbox0={:#x}\n",
+ id,
+ mbox0
+ );
+ }
+
+ resume_gsp_rm(
+ dev,
+ self.gsp_falcon,
+ self.sec2_falcon,
+ libos_dma_address,
+ bootloader_app_version,
+ )
+ })
+ .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(&self) -> Result {
@@ -157,7 +237,6 @@ fn reset_gsp_falcon_after_suspend(&self) -> Result {
///
/// 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;
@@ -209,7 +288,6 @@ fn handle_hs_binary(&self, params: &HsBinaryParams) -> Result<u32> {
///
/// Errors from the reset of the GSP falcon and the run of the bootloader are
/// propagated as-is.
- #[expect(dead_code)]
fn handle_generic_bootloader(
&self,
bootloader: Option<&GenericBootloader>,
--
2.56.1
^ permalink raw reply [flat|nested] 15+ messages in thread
end of thread, other threads:[~2026-11-30 9:31 UTC | newest]
Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 ` [PATCH 12/14] gpu: nova-core: gsp: add the r000 load-and-execute HS binary handler Eliot Courtney
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
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®