[PATCH 16/16] gpu: nova-core: load and run FWSEC-FRTS

Alexandre Courbot
2025-04-20T12:20:52Z

With all the required pieces in place, load FWSEC-FRTS onto the GSP
falcon, run it, and check that it completed successfully by carving out
the WPR2 region out of framebuffer memory.

Signed-off-by: Alexandre Courbot <acourbot@nvidia.com>
---
drivers/gpu/nova-core/falcon.rs | 3 ---
drivers/gpu/nova-core/gpu.rs | 59 ++++++++++++++++++++++++++++++++++++++++-
drivers/gpu/nova-core/regs.rs | 15 +++++++++++
drivers/gpu/nova-core/vbios.rs | 3 ---
4 files changed, 73 insertions(+), 7 deletions(-)

diff --git a/drivers/gpu/nova-core/falcon.rs b/drivers/gpu/nova-core/falcon.rs
index 71f374445ff3277eac628e183942c79f557366d5..f90bb739cb9864d88e3427c7ec76953c69ec2c67 100644
--- a/drivers/gpu/nova-core/falcon.rs
+++ b/drivers/gpu/nova-core/falcon.rs
@@ -2,9 +2,6 @@

//! Falcon microprocessor base support

-// To be removed when all code is used.
-#![allow(dead_code)]
-
use core::hint::unreachable_unchecked;
use core::time::Duration;
use hal::FalconHal;
diff --git a/drivers/gpu/nova-core/gpu.rs b/drivers/gpu/nova-core/gpu.rs
index 5d15a99f8d1eec3c2e1f6d119eb521361733c709..4d03a0b11b6411e22a652183e975f6889446ed46 100644
--- a/drivers/gpu/nova-core/gpu.rs
+++ b/drivers/gpu/nova-core/gpu.rs
@@ -250,7 +250,7 @@ pub(crate) fn new(
let fb_layout = FbLayout::new(spec.chipset, &bar)?;
dev_dbg!(pdev.as_ref(), "{:#x?}\n", fb_layout);

- let _fwsec_frts = FwsecFirmware::new(
+ let fwsec_frts = FwsecFirmware::new(
&gsp_falcon,
pdev.as_ref(),
&bar,
@@ -261,6 +261,63 @@ pub(crate) fn new(
},
)?;

+ // Check that the WPR2 region does not already exists - if it does, the GPU needs to be
+ // reset.
+ if with_bar!(bar, |b| regs::PfbPriMmuWpr2AddrHi::read(b).hi_val())? != 0 {
+ dev_err!(
+ pdev.as_ref(),
+ "WPR2 region already exists - GPU needs to be reset to proceed\n"
+ );
+ return Err(EBUSY);
+ }
+
+ // Reset falcon, load FWSEC-FRTS, and run it.
+ gsp_falcon.reset(&bar, &timer)?;
+ gsp_falcon.dma_load(&bar, &timer, &fwsec_frts)?;
+ let (mbox0, _) = gsp_falcon.boot(&bar, &timer, Some(0), None)?;
+ if mbox0 != 0 {
+ dev_err!(pdev.as_ref(), "FWSEC firmware returned error {}\n", mbox0);
+ return Err(EINVAL);
+ }
+
+ // SCRATCH_E contains FWSEC-FRTS' error code, if any.
+ let frts_status = with_bar!(bar, |b| regs::PbusSwScratche::read(b).frts_err_code())?;
+ if frts_status != 0 {
+ dev_err!(
+ pdev.as_ref(),
+ "FWSEC-FRTS returned with error code {:#x}",
+ frts_status
+ );
+ return Err(EINVAL);
+ }
+
+ // Check the WPR2 has been created as we requested.
+ let (wpr2_lo, wpr2_hi) = with_bar!(bar, |b| {
+ (
+ (regs::PfbPriMmuWpr2AddrLo::read(b).lo_val() as u64) << 12,
+ (regs::PfbPriMmuWpr2AddrHi::read(b).hi_val() as u64) << 12,
+ )
+ })?;
+ if wpr2_hi == 0 {
+ dev_err!(
+ pdev.as_ref(),
+ "WPR2 region not created after running FWSEC-FRTS\n"
+ );
+
+ return Err(ENOTTY);
+ } else if wpr2_lo != fb_layout.frts.start {
+ dev_err!(
+ pdev.as_ref(),
+ "WPR2 region created at unexpected address {:#x} ; expected {:#x}\n",
+ wpr2_lo,
+ fb_layout.frts.start,
+ );
+ return Err(EINVAL);
+ }
+
+ dev_info!(pdev.as_ref(), "WPR2: {:#x}-{:#x}\n", wpr2_lo, wpr2_hi);
+ dev_info!(pdev.as_ref(), "GPU instance built\n");
+
Ok(pin_init!(Self {
spec,
bar,
diff --git a/drivers/gpu/nova-core/regs.rs b/drivers/gpu/nova-core/regs.rs
index 3954542fdd77debd8f96d111ddd231d72dbf5b5a..eae5b7c13155d2da39f47661024ae52390e04366 100644
--- a/drivers/gpu/nova-core/regs.rs
+++ b/drivers/gpu/nova-core/regs.rs
@@ -18,6 +18,13 @@
28:20 chipset => try_into Chipset, "chipset model"
);

+/* PBUS */
+
+register!(PbusSwScratche@0x00001438;
+ 15:0 sb_err_code => as u16;
+ 31:16 frts_err_code => as u16;
+);
+
/* PTIMER */

register!(PtimerTime0@0x00009400;
@@ -44,6 +51,14 @@
30:30 ecc_mode_enabled => as_bit bool;
);

+register!(PfbPriMmuWpr2AddrLo@0x001fa824;
+ 31:4 lo_val => as u32
+);
+
+register!(PfbPriMmuWpr2AddrHi@0x001fa828;
+ 31:4 hi_val => as u32
+);
+
/* GC6 */

register!(Pgc6AonSecureScratchGroup05PrivLevelMask@0x00118128;
diff --git a/drivers/gpu/nova-core/vbios.rs b/drivers/gpu/nova-core/vbios.rs
index 534107b708cab0eb8d0accf7daa5718edf030358..74735c083d472ce955d6d3afaabd46a8d354c792 100644
--- a/drivers/gpu/nova-core/vbios.rs
+++ b/drivers/gpu/nova-core/vbios.rs
@@ -1,8 +1,5 @@
// SPDX-License-Identifier: GPL-2.0

-// To be removed when all code is used.
-#![allow(dead_code)]
-
//! VBIOS extraction and parsing.

use crate::driver::Bar0;

--
2.49.0