gpu: nova-core: merge `load` and `boot` for falcons
Subsystems (4)
cover gpu: nova-core: merge `load` and `boot` for falcons
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 Coherents (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. It also fixes one (harmless) issue with gsp boot.
Tested boot on TU104, GA104, AD106 and GB205.
This is based on drm-rust-next.
[1]: https://lore.kernel.org/[email protected]
---
Eliot Courtney (7):
gpu: nova-core: falcon: make pfalcon private
gpu: nova-core: gsp: remove unnecessary start of gsp_falcon
gpu: nova-core: falcon: program BROM and BOOTVEC in boot
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: rename FalconDmaLoadTarget to FalconLoadTarget
gpu: nova-core: falcon: load the firmware image in Falcon::boot
drivers/gpu/nova-core/falcon.rs | 442 +++++++++------------ drivers/gpu/nova-core/firmware.rs | 32 +- drivers/gpu/nova-core/firmware/booter.rs | 59 +-- drivers/gpu/nova-core/firmware/fwsec.rs | 47 +-- drivers/gpu/nova-core/firmware/fwsec/bootloader.rs | 9 +- drivers/gpu/nova-core/firmware/gen_bootloader.rs | 69 ++-- drivers/gpu/nova-core/gsp/hal/tu102.rs | 14 +- 7 files changed, 303 insertions(+), 369 deletions(-)
---
base-commit: 4325f4aad9727a6e8e7f10c5d2ebf490470cf938
change-id: 20261125-boot-rework2-3b6e58af67ae
Best regards,
Signature · 1 line
Eliot Courtney <[email protected]>
PATCH 1/7 gpu: nova-core: falcon: make pfalcon private
This can be private, so make it private.
--- drivers/gpu/nova-core/falcon.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/gpu/nova-core/falcon.rs +1 -2
@@ -375,8 +375,7 @@ pub(crate) struct Falcon<'a, E: FalconEngine> { hal: KBox<dyn FalconHal<E>>, dev: &'a device::Device<device::Bound>, bar: Bar0<'a>, -// TODO: make private - pub(crate) pfalcon: Mmio<'a, PFalconRegisters>, + pfalcon: Mmio<'a, PFalconRegisters>, pfalcon2: Mmio<'a, PFalcon2Registers>, }
Signature · 1 line
2.56.1
PATCH 2/7 gpu: nova-core: gsp: remove unnecessary start of `gsp_falcon`
In reply to Eliot CourtneyAt this point we just need to write in the DMA address of libos and that is sufficient for boot. Remove the unnecessary call to boot.
--- drivers/gpu/nova-core/gsp/hal/tu102.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/gpu/nova-core/gsp/hal/tu102.rs +2 -3
@@ -294,11 +294,10 @@ fn boot<'gpu>( gsp_falcon.reset ()?;let libos_dma_address = gsp.libos.dma_address (); -let (mbox0, mbox1) = gsp_falcon.boot ( + gsp_falcon.write_mailboxes (Some (libos_dma_addressas u32 ),Some ((libos_dma_address >>32 )as u32 ), - )?; -dev_dbg! (dev,"GSP MBOX0: {:#x}, MBOX1: {:#x}\n" , mbox0, mbox1); + );dev_dbg! ( dev,
Signature · 1 line
2.56.1
Alexandre Courbot
maintainerRe: [PATCH 2/7] gpu: nova-core: gsp: remove unnecessary start of `gsp_falcon`
Quoted 4 lines · Eliot Courtney
At this point we just need to write in the DMA address of libos and that is sufficient for boot. Remove the unnecessary call to
boot.Signed-off-by Eliot Courtney <[email protected]>
Oof nice catch. We were basically starting this falcon on nothing.
PATCH 3/7 gpu: nova-core: falcon: program BROM and BOOTVEC in `boot`
In reply to Eliot CourtneyMove 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.
--- 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(-)
drivers/gpu/nova-core/falcon.rs +14 -21
@@ -494,7 +494,7 @@ fn pio_wr_dmem_slice(&self, load_offsets: FalconPioDmemLoadTarget<'_>) -> ResultOk (()) } -/// 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 ()?;
drivers/gpu/nova-core/firmware/booter.rs +1 -0
@@ -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_addressas u32 ),Some ((wpr_dma_address >>32 )as u32 ), )?;
drivers/gpu/nova-core/firmware/fwsec.rs +1 -1
@@ -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);
drivers/gpu/nova-core/firmware/gen_bootloader.rs +4 -3
@@ -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 ) }, ) }
drivers/gpu/nova-core/gsp/hal/tu102.rs +5 -3
@@ -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 );
Signature · 1 line
2.56.1
PATCH 4/7 gpu: nova-core: falcon: separate staging data for DMA from its location
In reply to Eliot CourtneyIntroduce 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.
--- drivers/gpu/nova-core/falcon.rs | 126 ++++++++++++++++++++++++---------------- 1 file changed, 75 insertions(+), 51 deletions(-)
drivers/gpu/nova-core/falcon.rs +75 -51
@@ -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 (&'aCoherent <'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,21 @@ 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 of the segment in the framebuffer. + 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 +560,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 +628,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 +652,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, ) }
Signature · 1 line
2.56.1
Alexandre Courbot
maintainerRe: [PATCH 4/7] gpu: nova-core: falcon: separate staging data for DMA from its location
On Thu Nov 26, 2026 at 5:20 PM JST, Eliot Courtney wrote:
<...>
Quoted 21 lines
drivers/gpu/nova-core/falcon.rs +10
-0@@ -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,21 @@ pub(crate) struct FalconBromParams { pub(crate) ucode_id: u8, }
drivers/gpu/nova-core/falcon.rs pub(crate) struct FalconBromParams { · line 231
Quoted 10 lines
drivers/gpu/nova-core/falcon.rs +10
-0+/// 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 of the segment in the framebuffer. + base:u64 ,
That's not technically the base of the segment, there can be zeroed bytes before the segment starts because of tagging as the falcon will add va to base.
Alexandre Courbot
maintainerRe: [PATCH 4/7] gpu: nova-core: falcon: separate staging data for DMA from its location
In reply to Eliot CourtneyOn Thu Nov 26, 2026 at 5:20 PM JST, Eliot Courtney wrote:
<...>
drivers/gpu/nova-core/falcon.rs fn dma_wr( · line 656
Quoted 6 lines
drivers/gpu/nova-core/falcon.rs +2
-0@@ -634,38 +652,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`.
nit: doclink to MEM_BLOCK_ALIGNMENT.
PATCH 5/7 gpu: nova-core: falcon: add `FalconImage` for `FalconFirmware` trait
In reply to Eliot CourtneyIntroduce 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 and separate PIO specific machinery.
--- drivers/gpu/nova-core/falcon.rs | 307 ++++++++------------- drivers/gpu/nova-core/firmware/booter.rs | 43 +-- drivers/gpu/nova-core/firmware/fwsec.rs | 42 +-- drivers/gpu/nova-core/firmware/fwsec/bootloader.rs | 9 +- drivers/gpu/nova-core/firmware/gen_bootloader.rs | 57 ++-- 5 files changed, 190 insertions(+), 268 deletions(-)
drivers/gpu/nova-core/falcon.rs +119 -188
@@ -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.
@@ -234,141 +229,58 @@ 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 ]; +/// Code to load into `IMEM`. +#[derive( Clone )] +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 , +} -/// 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, +impl <'a>FalconImemSegment <'a> { +/// Returns the code of `blob` that `target` describes, to be tagged with `va`. +pub (crate )fn from_blob (blob: &'a [u8 ], target: &FalconDmaLoadTarget , va:u32 ) ->Result <Self > { +Ok (Self { + source:FalconSegmentSource ::Sysmem (target.data (blob)?), + dst_start: target.dst_start, + va, }) } } -/// Represents a portion of the firmware to be loaded into IMEM using PIO. +/// Data to load into falcon's `DMEM`. #[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 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 >, } -/// Represents a portion of the firmware to be loaded into DMEM using PIO. -#[derive( Clone )] -pub (crate )struct FalconPioDmemLoadTarget <'a> { -pub (crate ) data: &'a [u8 ], -pub (crate ) dst_start:u16 , -} - -/// 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: &'aT , -/// 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>FalconDmemSegment <'a> { +/// Returns the data of `blob` that `target` describes (untagged). +pub (crate )fn from_blob (blob: &'a [u8 ], target: &FalconDmaLoadTarget ) ->Result <Self > { +Ok (Self { + source:FalconSegmentSource ::Sysmem (target.data (blob)?), + dst_start: target.dst_start, + va:None , + }) } } -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.
@@ -378,6 +290,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 ;
@@ -446,25 +361,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),
@@ -483,11 +405,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 ); }
@@ -495,10 +418,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 wordin load_offsets.data.chunks_exact (4 ) { +for wordin data.chunks_exact (4 ) {let w = [word[0 ], word[1 ], word[2 ], word[3 ]]; self.pfalcon.write ( Array::at(Self::PIO_PORT),
@@ -509,27 +432,6 @@ fn pio_wr_dmem_slice(&self, load_offsets: FalconPioDmemLoadTarget<'_>) -> ResultOk (()) } -/// 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`. ///
@@ -671,26 +573,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.
@@ -802,15 +742,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
drivers/gpu/nova-core/firmware/booter.rs +23 -20
58 lines not on this page · raw message
drivers/gpu/nova-core/firmware/fwsec.rs +21 -21
57 lines not on this page · raw message
drivers/gpu/nova-core/firmware/fwsec/bootloader.rs +4 -5
@@ -19,7 +19,6 @@ falcon::{ gsp::Gsp, Falcon, - FalconDmaLoadable, FalconFbifTarget, // }, firmware::{
@@ -63,7 +62,7 @@ pub(crate) fn new(// 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 (); +let imem_sec = firmware.desc.imem_sec_load_params (); imem_sec .dst_start
@@ -82,9 +81,9 @@ pub(crate) fn new( };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 (); +let imem_sec = firmware.desc.imem_sec_load_params (); +let imem_ns = firmware.desc.imem_ns_load_params ().ok_or (EINVAL )?; +let dmem = firmware.desc.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
drivers/gpu/nova-core/firmware/gen_bootloader.rs +23 -34
93 lines not on this page · raw message
Signature · 1 line
2.56.1
PATCH 6/7 gpu: nova-core: falcon: rename FalconDmaLoadTarget to FalconLoadTarget
In reply to Eliot CourtneyAfter decoupling the source storage of each segment to upload to a falcon, FalconDmaLoadTarget is no longer DMA specific, so rename it.
--- drivers/gpu/nova-core/falcon.rs | 11 ++++---- drivers/gpu/nova-core/firmware.rs | 32 ++++++++++++------------ drivers/gpu/nova-core/firmware/booter.rs | 16 ++++++------ drivers/gpu/nova-core/firmware/gen_bootloader.rs | 8 +++--- 4 files changed, 33 insertions(+), 34 deletions(-)
drivers/gpu/nova-core/falcon.rs +5 -6
@@ -181,10 +181,9 @@ 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. +/// Represents a portion of the firmware to be loaded into a particular memory (e.g. IMEM or DMEM). #[derive( Debug , Clone )] -pub (crate )struct FalconDmaLoadTarget { +pub (crate )struct FalconLoadTarget {/// 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.
@@ -193,7 +192,7 @@ pub(crate) struct FalconDmaLoadTarget { pub(crate) len: u32, } -impl FalconDmaLoadTarget { +impl FalconLoadTarget {/// 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);
@@ -242,7 +241,7 @@ pub(crate) struct FalconImemSegment<'a> {impl <'a>FalconImemSegment <'a> {/// Returns the code of `blob` that `target` describes, to be tagged with `va`. -pub (crate )fn from_blob (blob: &'a [u8 ], target: &FalconDmaLoadTarget , va:u32 ) ->Result <Self > { +pub (crate )fn from_blob (blob: &'a [u8 ], target: &FalconLoadTarget , va:u32 ) ->Result <Self > {Ok (Self { source:FalconSegmentSource ::Sysmem (target.data (blob)?), dst_start: target.dst_start,
@@ -264,7 +263,7 @@ pub(crate) struct FalconDmemSegment<'a> {impl <'a>FalconDmemSegment <'a> {/// Returns the data of `blob` that `target` describes (untagged). -pub (crate )fn from_blob (blob: &'a [u8 ], target: &FalconDmaLoadTarget ) ->Result <Self > { +pub (crate )fn from_blob (blob: &'a [u8 ], target: &FalconLoadTarget ) ->Result <Self > {Ok (Self { source:FalconSegmentSource ::Sysmem (target.data (blob)?), dst_start: target.dst_start,
drivers/gpu/nova-core/firmware.rs +16 -16
@@ -14,8 +14,8 @@use crate ::{ falcon::{ -FalconDmaLoadTarget , -FalconFirmware ,// +FalconFirmware , +FalconLoadTarget ,// }, gpu, gsp::boot_firmware_files,
@@ -149,9 +149,9 @@ fn size(&self) -> usize { ((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 ; +fn imem_sec_load_params (&self) ->FalconLoadTarget ; +fn imem_ns_load_params (&self) ->Option <FalconLoadTarget >; +fn dmem_load_params (&self) ->FalconLoadTarget ; }impl FalconUCodeDescriptor for FalconUCodeDescV2 {
@@ -183,20 +183,20 @@ fn signature_versions(&self) -> u16 {0 } -fn imem_sec_load_params (&self) ->FalconDmaLoadTarget { +fn imem_sec_load_params (&self) ->FalconLoadTarget {// `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 { +FalconLoadTarget { 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 { +fn imem_ns_load_params (&self) ->Option <FalconLoadTarget > { +Some (FalconLoadTarget {// Non-secure code always starts at offset 0. src_start:0 , dst_start: self.imem_phys_base,
@@ -206,8 +206,8 @@ fn imem_ns_load_params(&self) -> Option<FalconDmaLoadTarget> { }) } -fn dmem_load_params (&self) ->FalconDmaLoadTarget { -FalconDmaLoadTarget { +fn dmem_load_params (&self) ->FalconLoadTarget { +FalconLoadTarget { src_start: self.dmem_offset, dst_start: self.dmem_phys_base, len: self.dmem_load_size,
@@ -244,8 +244,8 @@ fn signature_versions(&self) -> u16 { self.signature_versions } -fn imem_sec_load_params (&self) ->FalconDmaLoadTarget { -FalconDmaLoadTarget { +fn imem_sec_load_params (&self) ->FalconLoadTarget { +FalconLoadTarget {// IMEM segment always starts at offset 0. src_start:0 , dst_start: self.imem_phys_base,
@@ -253,13 +253,13 @@ fn imem_sec_load_params(&self) -> FalconDmaLoadTarget { } } -fn imem_ns_load_params (&self) ->Option <FalconDmaLoadTarget > { +fn imem_ns_load_params (&self) ->Option <FalconLoadTarget > {// Not used on V3 platforms None } -fn dmem_load_params (&self) ->FalconDmaLoadTarget { -FalconDmaLoadTarget { +fn dmem_load_params (&self) ->FalconLoadTarget { +FalconLoadTarget {// DMEM segment starts right after the IMEM one. src_start: self.imem_load_size, dst_start: self.dmem_phys_base,
drivers/gpu/nova-core/firmware/booter.rs +8 -8
@@ -18,11 +18,11 @@ sec2::Sec2, Falcon, FalconBromParams, - FalconDmaLoadTarget, FalconDmemSegment, FalconFirmware, FalconImage, - FalconImemSegment, // + FalconImemSegment, + FalconLoadTarget, // }, firmware::{ tlv::{
@@ -53,12 +53,12 @@ impl<'a> FirmwareSignature<BooterFirmware> for BooterSignature<'a> {}/// 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 , + imem_sec_load_target:FalconLoadTarget ,// Load parameters for Non-Secure `IMEM` falcon memory, // used only on Turing and GA100 - imem_ns_load_target:Option <FalconDmaLoadTarget >, + imem_ns_load_target:Option <FalconLoadTarget >,// Load parameters for `DMEM` falcon memory. - dmem_load_target:FalconDmaLoadTarget , + dmem_load_target:FalconLoadTarget ,// BROM falcon parameters. brom_params:FalconBromParams ,// Device-mapped firmware image.
@@ -153,7 +153,7 @@ pub(crate) fn new(let (imem_sec_dst_start, imem_ns_load_target) =if chipset <=Chipset ::GA100 { ( app0_code_offset, - Some(FalconDmaLoadTarget { + Some(FalconLoadTarget { src_start: 0, dst_start: os_code_offset, len: os_code_size,
@@ -164,13 +164,13 @@ pub(crate) fn new( };Ok (Self { - imem_sec_load_target:FalconDmaLoadTarget { + imem_sec_load_target:FalconLoadTarget { src_start: app0_code_offset, dst_start: imem_sec_dst_start, len: app0_code_size, }, imem_ns_load_target, - dmem_load_target:FalconDmaLoadTarget { + dmem_load_target:FalconLoadTarget { src_start: os_data_offset, dst_start:0 , len: os_data_size,
drivers/gpu/nova-core/firmware/gen_bootloader.rs +4 -4
@@ -22,13 +22,13 @@ gsp::Gsp, Falcon, FalconBromParams, - FalconDmaLoadTarget, FalconDmemSegment, FalconFbifMemType, FalconFbifTarget, FalconFirmware, FalconImage, FalconImemSegment, + FalconLoadTarget, FalconSegmentSource, // }, firmware::tlv::{
@@ -97,9 +97,9 @@ impl BootloaderDmemDescV2 {/// 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 , + imem_ns: &FalconLoadTarget , + imem_sec: &FalconLoadTarget , + dmem: &FalconLoadTarget , code_dma_base:u64 , data_dma_base:u64 , ) ->Self {
Signature · 1 line
2.56.1
PATCH 7/7 gpu: nova-core: falcon: load the firmware image in Falcon::boot
In reply to Eliot CourtneyRemove 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.
--- drivers/gpu/nova-core/falcon.rs | 12 ++++++------ 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, 6 insertions(+), 12 deletions(-)
drivers/gpu/nova-core/falcon.rs +6 -6
@@ -616,11 +616,8 @@ 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 ()?; - +/// Load a firmware image into Falcon memory. +fn load (&self, image: &FalconImage <'_>) ->Result { self.dma_reset ();if let Some (segment) = &image.imem_ns {
@@ -690,7 +687,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.
@@ -703,6 +700,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 ()));
drivers/gpu/nova-core/firmware/booter.rs +0 -1
@@ -191,7 +191,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,
drivers/gpu/nova-core/firmware/fwsec.rs +0 -3
@@ -392,9 +392,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))?;
drivers/gpu/nova-core/firmware/gen_bootloader.rs +0 -1
@@ -219,7 +219,6 @@ pub(crate) fn run( dmem_desc, }; - falcon.load (&fw)?; falcon.boot (&fw,Some (mbox0),None ) }, )
drivers/gpu/nova-core/gsp/hal/tu102.rs +0 -1
@@ -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 ;
Signature · 1 line
2.56.1
Alexandre Courbot
maintainerQuoted 10 lines · Eliot Courtney
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).
[...]
1 and 2 applied to drm-rust-next, thanks!
[1/7] gpu: nova-core: falcon: make pfalcon private
commit: e91da12099a5536c6a1852c6fb7800ef6460103d
[2/7] gpu: nova-core: gsp: remove unnecessary start of `gsp_falcon`
commit: abfb640b2374e26de8ff81d488c39d8254db538e