Skip to contentSkip to conversation

gpu: nova-core: run falcon binaries for the r000 GSP-RM

PATCH New John Hubbard 2 participants 19 messages Nov 20

Subsystems (7)
DRM drivers PCI Rust DRM Rust +3 more subsystems
lore
Share & tools
lore
#0 lore raw

cover gpu: nova-core: run falcon binaries for the r000 GSP-RM

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 [1], 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 BROM and BOOTVEC programming, out of the PIO and DMA load paths
* the core reset and 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).

The series also has one patch that the handlers do not use, and that the rest of the r000 series requires: the PCI domain accessor. The patch is its v2 posting [2] with the Reviewed-by tags from Alex and Gary.

The series applies on drm-rust-next at 0dbf41fd03ab, on top of one build fix that is in v7.4-rc2 and not yet in drm-rust-next:
commit 57d916a3eb76 ("rust: bindings: derive Zeroable for bindgen's opaque array wrappers"). A branch with everything applied:

https://github.com/johnhubbard/linux/tree/nova-core-run-falcon-binaries-v0/

Changes since v3 of the r000 series. The two handlers and the dispatcher come from v3 patches 15, 17 and 18:

* The handlers now use the core reset and 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.

[1] https://lore.kernel.org/all/[email protected]/
[2] https://lore.kernel.org/all/[email protected]/

John Hubbard (9):
rust: pci: add domain_nr() accessor
gpu: nova-core: falcon: factor out the wait for the GSP suspend
gpu: nova-core: falcon: factor out the BROM and BOOTVEC programming
gpu: nova-core: gsp: factor out the core reset and 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               |  46 +-
 drivers/gpu/nova-core/falcon/gsp.rs           |  15 +
 .../gpu/nova-core/firmware/gen_bootloader.rs  |   8 +-
 drivers/gpu/nova-core/gsp.rs                  |   1 +
 drivers/gpu/nova-core/gsp/boot.rs             |   8 +-
 drivers/gpu/nova-core/gsp/load_exec.rs        | 493 ++++++++++++++++++
 drivers/gpu/nova-core/gsp/sequencer.rs        |  48 +-
 drivers/gpu/nova-core/regs.rs                 |   2 +
 drivers/gpu/nova-core/sbuffer.rs              |   1 -
 rust/helpers/pci.c                            |   5 +
 rust/kernel/pci.rs                            |  16 +
 11 files changed, 582 insertions(+), 61 deletions(-)
 create mode 100644 drivers/gpu/nova-core/gsp/load_exec.rs

base-commit: 0dbf41fd03abee01a37a83336ed84cd5812af633
prerequisite-patch-id: dba3141a4ed9123a37958daa1a27e82669d64941

Signature · 1 line
2.56.1
#1 lore raw

PATCH 1/9 rust: pci: add domain_nr() accessor

The nova-core driver has to send the GPU's PCI location to the GPU's firmware as one word that holds the domain, the bus and the device number.

The PCI abstraction has dev_id(), which packs the bus, the device and the function into one value. It has no accessor that reports the domain.

Add an accessor for the domain number.

---
 rust/helpers/pci.c |  5 +++++
 rust/kernel/pci.rs | 16 ++++++++++++++++
 2 files changed, 21 insertions(+)
rust/helpers/pci.c +5 -0
index a8540f90b13c..a1e033531419 100644
@@ -7,6 +7,11 @@ __rust_helper u16 rust_helper_pci_dev_id(struct pci_dev *dev)
 	return PCI_DEVID(dev->bus->number, dev->devfn);
 }
 
+__rust_helper int rust_helper_pci_domain_nr(struct pci_bus *bus)
+{
+	return pci_domain_nr(bus);
+}
+
 __rust_helper resource_size_t
 rust_helper_pci_resource_start(struct pci_dev *pdev, int bar)
 {
rust/kernel/pci.rs +16 -0
index 769d01d23429..60e0d8518266 100644
@@ -408,6 +408,22 @@ pub fn dev_id(&self) -> u16 {
         unsafe { bindings::pci_dev_id(self.as_raw()) }
     }
 
+    /// Returns the PCI domain number of the bus that this device is on.
+    #[inline]
+    pub fn domain_nr(&self) -> u32 {
+        // SAFETY: By its type invariant `self.as_raw` is always a valid pointer to a
+        // `struct pci_dev`, which holds a reference to the `struct pci_bus` that its `bus` field
+        // points to.
+        let domain_nr = unsafe { bindings::pci_domain_nr((*self.as_raw()).bus) };
+
+        debug_assert!(domain_nr >= 0);
+
+        // CAST: `pci_domain_nr()` returns an `int`, but a registered bus never has a negative
+        // domain. A negative value here is a kernel bug rather than a condition for a caller to
+        // handle.
+        domain_nr as u32
+    }
+
     /// Returns the PCI subsystem vendor ID.
     #[inline]
     pub fn subsystem_vendor_id(&self) -> u16 {
Signature · 1 line
2.56.1
#2 lore raw

Re: [PATCH 1/9] rust: pci: add domain_nr() accessor

Sashiko has reviewed this patch and found no issues.
Quoted 4 lines

The nova-core driver has to send the GPU's PCI location to the GPU's firmware as one word that holds the domain, the bus and the device number.

Quoted 8 lines

The PCI abstraction has dev_id(), which packs the bus, the device and the function into one value. It has no accessor that reports the domain.

Add an accessor for the domain number.

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
#3 lore raw

PATCH 2/9 gpu: nova-core: falcon: factor out the wait for the GSP suspend

In reply to John Hubbard

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.

---
 drivers/gpu/nova-core/falcon/gsp.rs | 15 +++++++++++++++
 drivers/gpu/nova-core/gsp/boot.rs   |  8 +-------
 2 files changed, 16 insertions(+), 7 deletions(-)
drivers/gpu/nova-core/falcon/gsp.rs +15 -0
index 54247691b53c..2ea28fa53db8 100644
@@ -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
drivers/gpu/nova-core/gsp/boot.rs +1 -7
index 9d5da5b165ac..2815fe8b306e 100644
@@ -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.
Signature · 1 line
2.56.1
#4 lore raw

Re: [PATCH 2/9] gpu: nova-core: falcon: factor out the wait for the GSP suspend

Sashiko has reviewed this patch and found no issues.
Quoted 10 lines

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.

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
#5 lore raw

PATCH 3/9 gpu: nova-core: falcon: factor out the BROM and BOOTVEC programming

In reply to John Hubbard

The r000 boot protocol requires the driver to program the BROM registers and the BOOTVEC register of the GSP falcon for a binary that GSP-RM has placed in the framebuffer, as the PIO and DMA load paths already do for a firmware image.

In order to make the programming available to a caller that has no firmware image, factor it out of the two load paths, into a falcon method that receives the BROM parameters and the boot address.

No functional changes.

---
 drivers/gpu/nova-core/falcon.rs | 19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)
drivers/gpu/nova-core/falcon.rs +10 -9
index fb4f1cad867e..28c37c82b8a2 100644
@@ -515,10 +515,7 @@ pub(crate) fn pio_load<F: FalconFirmware<Target = E> + FalconPioLoadable>(
         }
         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()));
+        self.program_brom_and_bootvec(&fw.brom_params(), fw.boot_addr());
 
         Ok(())
     }
@@ -676,15 +673,19 @@ fn dma_load<F: FalconFirmware<Target = E> + FalconDmaLoadable>(&self, fw: &F) ->
             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()));
+        self.program_brom_and_bootvec(&fw.brom_params(), fw.boot_addr());
 
         Ok(())
     }
 
+    /// Programs the BROM registers with `brom_params` and the `BOOTVEC` register with `boot_addr`.
+    fn program_brom_and_bootvec(&self, brom_params: &FalconBromParams, boot_addr: u32) {
+        self.hal.program_brom(self, brom_params);
+
+        self.pfalcon
+            .write_reg(regs::NV_PFALCON_FALCON_BOOTVEC::zeroed().with_value(boot_addr));
+    }
+
     /// Wait until the falcon CPU is halted.
     pub(crate) fn wait_till_halted(&self) -> Result<()> {
         // TIMEOUT: arbitrarily large value, firmwares should complete in less than 2 seconds.
Signature · 1 line
2.56.1
#6 lore raw

Re: [PATCH 3/9] gpu: nova-core: falcon: factor out the BROM and BOOTVEC programming

Sashiko has reviewed this patch and found no issues.
Quoted 5 lines

The r000 boot protocol requires the driver to program the BROM registers and the BOOTVEC register of the GSP falcon for a binary that GSP-RM has placed in the framebuffer, as the PIO and DMA load paths already do for a firmware image.

Quoted 7 lines

In order to make the programming available to a caller that has no firmware image, factor it out of the two load paths, into a falcon method that receives the BROM parameters and the boot address.

No functional changes.

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
#7 lore raw

PATCH 4/9 gpu: nova-core: gsp: factor out the core reset and the core resume

In reply to John Hubbard

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 reset and the core resume available outside the sequencer, factor them out of it, into a module of their own.

No functional changes.

---
 drivers/gpu/nova-core/gsp.rs           |  1 +
 drivers/gpu/nova-core/gsp/load_exec.rs | 78 ++++++++++++++++++++++++++
 drivers/gpu/nova-core/gsp/sequencer.rs | 48 +++-------------
 3 files changed, 88 insertions(+), 39 deletions(-)
 create mode 100644 drivers/gpu/nova-core/gsp/load_exec.rs
drivers/gpu/nova-core/gsp.rs +1 -0
index 2f1cdf8b7bec..854062112cf1 100644
@@ -20,6 +20,7 @@
 pub(crate) mod cmdq;
 pub(crate) mod commands;
 mod fw;
+mod load_exec;
 mod logbuffer;
 mod nvkv;
 mod regs;
drivers/gpu/nova-core/gsp/load_exec.rs new file +78 -0

78 lines not on this page · raw message

drivers/gpu/nova-core/gsp/sequencer.rs +9 -39

66 lines not on this page · raw message

Signature · 1 line
2.56.1
#8 lore raw

Re: [PATCH 4/9] gpu: nova-core: gsp: factor out the core reset and the core resume

Sashiko has reviewed this patch and found no issues.
Quoted 11 lines

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 reset and the core resume available outside the sequencer, factor them out of it, into a module of their own.

No functional changes.

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4
#9 lore raw

PATCH 5/9 gpu: nova-core: gsp: fix resume_gsp_rm()'s error messages

In reply to John Hubbard

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 that 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.

---
 drivers/gpu/nova-core/gsp/load_exec.rs | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/gpu/nova-core/gsp/load_exec.rs +6 -2
index ccbfcbfe3ce5..bf465ac1151f 100644
@@ -62,7 +62,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);
     }
 
@@ -71,7 +75,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(())
Signature · 1 line
2.56.1
#10 lore raw

Re: [PATCH 5/9] gpu: nova-core: gsp: fix resume_gsp_rm()'s error messages

Sashiko has reviewed this patch and found no issues.
Quoted 7 lines

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 that will never change. This kind of tight coupling is almost never desirable in well-structured code.

Quoted 8 lines

* 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.

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=5
#11 lore raw

PATCH 6/9 gpu: nova-core: falcon: select the BAR2 engine ID for framebuffer DMA

In reply to John Hubbard

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.

---
 drivers/gpu/nova-core/falcon.rs | 24 ++++++++++++++++++++++--
 drivers/gpu/nova-core/regs.rs   |  2 ++
 2 files changed, 24 insertions(+), 2 deletions(-)
drivers/gpu/nova-core/falcon.rs +22 -2
index 28c37c82b8a2..75954856ad7c 100644
@@ -175,6 +175,18 @@ 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;
 
@@ -607,8 +619,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_target(fbif_target)
+                    .with_mem_type(FalconFbifMemType::Physical);
+
+                match src {
+                    FalconDmaSource::Sysmem(_) => v,
+                    FalconDmaSource::Framebuffer { .. } => {
+                        v.with_engine_id_flag(FalconFbifEngineIdFlag::Bar2Fn0)
+                    }
+                }
             });
 
         for pos in (0..num_transfers).map(|i| i * DMA_LEN) {
drivers/gpu/nova-core/regs.rs +2 -0
index dfe7944cf1e7..050054a2b23d 100644
@@ -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;
     }
Signature · 1 line
2.56.1
#12 lore raw

Re: [PATCH 6/9] gpu: nova-core: falcon: select the BAR2 engine ID for framebuffer DMA

Sashiko has reviewed this patch and found no issues.
Quoted 10 lines

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.

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=6
#13 lore raw

PATCH 7/9 gpu: nova-core: gsp: add the r000 load-and-execute HS binary handler

In reply to John Hubbard

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.

---
 drivers/gpu/nova-core/falcon.rs        |   5 +-
 drivers/gpu/nova-core/gsp/load_exec.rs | 203 ++++++++++++++++++++++++-
 drivers/gpu/nova-core/sbuffer.rs       |   1 -
 3 files changed, 199 insertions(+), 10 deletions(-)
drivers/gpu/nova-core/falcon.rs +2 -3
index 75954856ad7c..459a0a88146a 100644
@@ -145,7 +145,6 @@ 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 },
 }
 
@@ -563,7 +562,7 @@ pub(crate) fn with_fbif_transcfg<R>(
     }
 
     /// Perform a DMA write according to `load_offsets` from `src` into the falcon's `target_mem`.
-    fn dma_wr(
+    pub(crate) fn dma_wr(
         &self,
         src: FalconDmaSource<'_>,
         target_mem: FalconMem,
@@ -699,7 +698,7 @@ fn dma_load<F: FalconFirmware<Target = E> + FalconDmaLoadable>(&self, fw: &F) ->
     }
 
     /// Programs the BROM registers with `brom_params` and the `BOOTVEC` register with `boot_addr`.
-    fn program_brom_and_bootvec(&self, brom_params: &FalconBromParams, boot_addr: u32) {
+    pub(crate) fn program_brom_and_bootvec(&self, brom_params: &FalconBromParams, boot_addr: u32) {
         self.hal.program_brom(self, brom_params);
 
         self.pfalcon
drivers/gpu/nova-core/gsp/load_exec.rs +197 -6

221 lines not on this page · raw message

drivers/gpu/nova-core/sbuffer.rs +0 -1
index 3a41d224c77a..b8c01104c255 100644
@@ -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()) {
Signature · 1 line
2.56.1
#14 lore raw

Re: [PATCH 7/9] gpu: nova-core: gsp: add the r000 load-and-execute HS binary handler

Sashiko has reviewed this patch and found no issues.
Quoted 19 lines

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.

Quoted 7 lines

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

Add the handler, which performs steps 4 through 8.

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=7
#15 lore raw

PATCH 8/9 gpu: nova-core: gsp: add the r000 load-and-execute bootloader handler

In reply to John Hubbard

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.

---
 .../gpu/nova-core/firmware/gen_bootloader.rs  |   8 +-
 drivers/gpu/nova-core/gsp/load_exec.rs        | 164 +++++++++++++++++-
 2 files changed, 170 insertions(+), 2 deletions(-)
drivers/gpu/nova-core/firmware/gen_bootloader.rs +7 -1
index 751335c97e35..8d8c94cc19ee 100644
@@ -13,7 +13,10 @@
     },
     prelude::*,
     ptr::Alignable,
-    transmute::AsBytes, //
+    transmute::{
+        AsBytes,
+        FromBytes, //
+    },
 };
 
 use crate::{
@@ -123,6 +126,9 @@ pub(crate) fn new(
 // SAFETY: This struct doesn't contain uninitialized bytes and doesn't have interior mutability.
 unsafe impl AsBytes for BootloaderDmemDescV2 {}
 
+// SAFETY: This struct only contains integer types for which all bit patterns are valid.
+unsafe impl FromBytes for BootloaderDmemDescV2 {}
+
 /// The generic falcon bootloader image and its IMEM load parameters.
 pub(crate) struct GenericBootloader {
     /// Bootloader code, zero-padded to a whole number of falcon memory blocks.
drivers/gpu/nova-core/gsp/load_exec.rs +163 -1

187 lines not on this page · raw message

Signature · 1 line
2.56.1
#16 lore raw

Re: [PATCH 8/9] gpu: nova-core: gsp: add the r000 load-and-execute bootloader handler

Sashiko has reviewed this patch and found no issues.
Quoted 18 lines

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.

Quoted 7 lines

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

Add the handler, which performs steps 3 through 8.

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=8
#17 lore raw

PATCH 9/9 gpu: nova-core: gsp: add the load-and-execute event dispatcher

In reply to John Hubbard

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.

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

Re: [PATCH 9/9] gpu: nova-core: gsp: add the load-and-execute event dispatcher

Sashiko has reviewed this patch and found no issues.
Quoted 5 lines

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.

Quoted 7 lines

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.

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=9