nova-core: run FWSEC-FRTS to perform first stage of GSP initialization
Subsystems (8)
Alexandre Courbot
maintainerv6 cover nova-core: run FWSEC-FRTS to perform first stage of GSP initialization
Hi everyone,
After discussion, and since the num module seems to be taking more time to reach consensus than the rest of this series, I have split it into its own patch series and use ad-hoc code in Nova (only a handful of places thankfully) for now that will be replaced by the num patch series. This will also allow it to maybe get more attention as it was until now buried inside a loosely-related patch series.
This also includes an important fix for a bug discovered by Ben Skeggs in the falcon code: the bit indicating the completion of memory scrubbing was interpreted incorrectly, which created a race condition that could result in a failure to boot the GSP. :O
Other than that, a few more minor refinements took place, but nothing that changes this series considerably. The last patch tries to organize the increasing number of TODO items we have in the code; until they can be addressed, it would be nice to understand which task in todo.rst they correspond to, so I took the freedom to annotate them all to that effect.
Usual disclaimer: this series currently only successfully probes Ampere GPUs, and does not allow the GPU to do anything useful yet. Upon successful probe, the driver will only display the range of the WPR2 region constructed by FWSEC-FRTS with debug priority:
[ 95.436000] NovaCore 0000:01:00.0: WPR2: 0xffc00000-0xffce0000 [ 95.436002] NovaCore 0000:01:00.0: GPU instance built
This series is based on v6.16-rc1 with no other dependencies.
There are bits of documentation still missing, these are addressed by Joel in his own documentation patch series [1]. I'll also double-check and send follow-up patches if anything is still missing after that.
[1] https://lore.kernel.org/rust-for-linux/[email protected]/
---
Changes in v6:
- Add dma_handle_with_offset method to CoherentAllocation.
- Move the num module into its own patchset and use ad-hoc code for now.
- Add new items (and remove obsolete ones) to the TODO tag TODO
entries in the code with their corresponding task in the list.
- Add TIMEOUT: comments wherever a timeout is used.
- Fix bug while waiting for falcon mem scrubbing to finish (thanks Ben Skeggs!)
- Pass the firwmare object instead of its DMA handle in dma_wr.
- Fix safety statements in fwsec.rs.
- Move FWSEC boot code to FwsecFirmware and a helper function of
Gpu to simplify Gpu::new.
- Add helper methods to NV_PFB_PRI_MMU_WPR2_ADDR_* to obtain the exact address.
- Fix build errors and warnings with Rust 1.78.
- Link to v5: https://lore.kernel.org/r/[email protected]
Changes in v5:
- Rebased on top of 6.16-rc1.
- Improve invariants of CoherentAllocation related to the new size method.
- Use SZ_* consts when redefining BAR0 size.
- Split VBIOS patch into 3 patches (Joel)
- Convert all Result<()> into Result.
- Use ::cast<T>() instead of as to convert pointer types.
- Use KBox instead of Arc for falcon HALs.
- Do not use get_ prefix on methods that do not increase reference count.
- Replace arbitrary immediate values with proper constants.
- Use EIO to indicate firmware errors.
- Use inspect_err to be more verbose on which step of the FWSEC setup failed.
- Move sysmem flush page into its own type and add its registration to the FB HAL.
- Turn HAL getters into standalone functions.
- Patch FWSEC command at construction time.
- Force the signing stage (or an explicit non-signing state transition) on the firmware DMA objects.
- Link to v4: https://lore.kernel.org/r/[email protected]
Changes in v4:
- Improve documentation of falcon security modes (thanks Joel!)
- Add the definition of the size of CoherentAllocation as one of its invariants.
- Better document GFW boot progress, registers and use wait_on() helper, and move it to gfw module instead of devinit.
- Add missing TODOs for workarounds waiting to be replaced by in-flight R4L features.
- Register macro: add the offset of the register as a type constant, and allow register aliases for registers which can be interpreted differently depending on context.
- Rework the num module using only macros (to allow use of overflowing ops), and add the PowerOfTwo type.
- Add a proper HAL to the fb module.
- Move HAL builders to impl blocks of Chipset.
- Add proper types and traits for signatures.
- Proactively split FalconFirmware into distinct traits to ease management of v2 vs v3 FWSEC headers that will be needed for Turing support.
- Link to v3:
https://lore.kernel.org/r/[email protected]
Changes in v3:
- Rebased on top of latest nova-next.
- Use the new Devres::access() and remove the now unneeded with_bar!() macro.
- Dropped rust: devres: allow to borrow a reference to the resource's Device as it is not needed anymore.
- Fixed more erroneous uses of ERANGE error.
- Optimized alignment computations of the FB layout a bit.
- Link to v2: https://lore.kernel.org/r/[email protected]
Changes in v2:
- Rebased on latest nova-next.
- Fixed all clippy warnings.
- Added count and size methods to CoherentAllocation.
- Added method to obtain a reference to the Device from a Devres (this is super convenient).
- Split DmaObject into its own patch and added Deref implementation.
- Squashed field names from [3] into "extract FWSEC from BIOS".
- Fixed erroneous use of ERANGE error.
- Reworked register!() macro towards a more intuitive syntax, moved
its helper macros into internal rules to avoid polluting the macro namespace.
- Renamed all registers to capital snake case to better match OpenRM.
- Removed declarations for registers that are not used yet.
- Added more documentation for items not covered by Joel's documentation patches.
- Removed timer device and replaced it with a helper function using Ktime. This also made [4] unneeded so it is dropped.
- Unregister the sysmem flush page upon device destruction.
- ... probably more that I forgot. >_<
- Link to v1: https://lore.kernel.org/r/[email protected]
[3] https://lore.kernel.org/all/[email protected]/
[4] https://lore.kernel.org/lkml/[email protected]/
---
Alexandre Courbot (21):
rust: dma: fix comment
rust: dma: expose the count and size of CoherentAllocation
rust: dma: add dma_handle_with_offset method to CoherentAllocation
rust: make ETIMEDOUT error available
rust: sizes: add constants up to SZ_2G
gpu: nova-core: use absolute paths in register!() macro
gpu: nova-core: add delimiter for helper rules in register!() macro
gpu: nova-core: expose the offset of each register as a type constant
gpu: nova-core: allow register aliases
gpu: nova-core: increase BAR0 size to 16MB
gpu: nova-core: add helper function to wait on condition
gpu: nova-core: wait for GFW_BOOT completion
gpu: nova-core: add DMA object struct
gpu: nova-core: register sysmem flush page
gpu: nova-core: add falcon register definitions and base code
gpu: nova-core: firmware: add ucode descriptor used by FWSEC-FRTS
gpu: nova-core: compute layout of the FRTS region
gpu: nova-core: add types for patching firmware binaries
gpu: nova-core: extract FWSEC from BIOS and patch it to run FWSEC-FRTS
gpu: nova-core: load and run FWSEC-FRTS
gpu: nova-core: update and annotate TODO list
Joel Fernandes (3):
gpu: nova-core: vbios: Add base support for VBIOS construction and iteration
gpu: nova-core: vbios: Add support to look up PMU table in FWSEC
gpu: nova-core: vbios: Add support for FWSEC ucode extraction
Documentation/gpu/nova/core/todo.rst | 107 +-- drivers/gpu/nova-core/dma.rs | 58 ++ drivers/gpu/nova-core/driver.rs | 6 +- drivers/gpu/nova-core/falcon.rs | 554 ++++++++++++++ drivers/gpu/nova-core/falcon/gsp.rs | 24 + drivers/gpu/nova-core/falcon/hal.rs | 54 ++ drivers/gpu/nova-core/falcon/hal/ga102.rs | 119 +++ drivers/gpu/nova-core/falcon/sec2.rs | 10 + drivers/gpu/nova-core/fb.rs | 136 ++++ drivers/gpu/nova-core/fb/hal.rs | 39 + drivers/gpu/nova-core/fb/hal/ga100.rs | 57 ++ drivers/gpu/nova-core/fb/hal/ga102.rs | 36 + drivers/gpu/nova-core/fb/hal/tu102.rs | 58 ++ drivers/gpu/nova-core/firmware.rs | 108 +++ drivers/gpu/nova-core/firmware/fwsec.rs | 423 +++++++++++ drivers/gpu/nova-core/gfw.rs | 41 + drivers/gpu/nova-core/gpu.rs | 132 +++- drivers/gpu/nova-core/nova_core.rs | 5 + drivers/gpu/nova-core/regs.rs | 288 +++++++ drivers/gpu/nova-core/regs/macros.rs | 65 +- drivers/gpu/nova-core/util.rs | 28 + drivers/gpu/nova-core/vbios.rs | 1157 +++++++++++++++++++++++++++++ rust/kernel/dma.rs | 48 +- rust/kernel/error.rs | 1 + rust/kernel/sizes.rs | 24 + 25 files changed, 3504 insertions(+), 74 deletions(-)
---
base-commit: 19272b37aa4f83ca52bdf9c16d5d81bdd1354494
change-id: 20250417-nova-frts-96ef299abe2c
Best regards,
Signature · 1 line
Alexandre Courbot <[email protected]>
Alexandre Courbot
maintainerPATCH v6 1/24 rust: dma: fix comment
A word was apparently missing in this sentence.
--- rust/kernel/dma.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
rust/kernel/dma.rs +1 -1
@@ -212,7 +212,7 @@ pub fn start_ptr_mut(&mut self) -> *mut T { self.cpu_addr } -/// Returns a DMA handle which may given to the device as the DMA address base of +/// Returns a DMA handle which may be given to the device as the DMA address base of /// the region. pub fn dma_handle (&self) -> bindings::dma_addr_t { self.dma_handle
Signature · 1 line
2.49.0
Re: [PATCH v6 01/24] rust: dma: fix comment
Quoted 3 lines · Alexandre Courbot
A word was apparently missing in this sentence.
Signed-off-by Alexandre Courbot <[email protected]>
Applied to alloc-next, thanks!
[ Slightly expand commit subject and add 'Fixes:' tag. - Danilo ]
Alexandre Courbot
maintainerPATCH v6 2/24 rust: dma: expose the count and size of CoherentAllocation
In reply to Alexandre CourbotThese properties are very useful to have (and to be used by nova-core) and should be accessible.
--- rust/kernel/dma.rs | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-)
rust/kernel/dma.rs +26 -6
@@ -114,9 +114,11 @@ pub mod attrs {/// /// # Invariants /// -/// For the lifetime of an instance of [`CoherentAllocation`], the `cpu_addr` is a valid pointer -/// to an allocated region of consistent memory and `dma_handle` is the DMA address base of -/// the region. +/// - For the lifetime of an instance of [`CoherentAllocation`], the `cpu_addr` is a valid pointer +/// to an allocated region of consistent memory and `dma_handle` is the DMA address base of the +/// region. +/// - The size in bytes of the allocation is equal to `size_of::<T> * count`. +/// - `size_of::<T> * count` fits into a `usize`. // TODO // // DMA allocations potentially carry device resources (e.g.IOMMU mappings), hence for soundness
@@ -179,9 +181,12 @@ pub fn alloc_attrs(if ret.is_null () {return Err (ENOMEM ); } -// INVARIANT: We just successfully allocated a coherent region which is accessible for -// `count` elements, hence the cpu address is valid. We also hold a refcounted reference -// to the device. +// INVARIANT: +// - We just successfully allocated a coherent region which is accessible for +// `count` elements, hence the cpu address is valid. We also hold a refcounted reference +// to the device. +// - The allocated `size` is equal to `size_of::<T> * count`. +// - The allocated `size` fits into a `usize`. Ok (Self { dev: dev.into (), dma_handle,
@@ -201,6 +206,21 @@ pub fn alloc_coherent(CoherentAllocation ::alloc_attrs (dev, count, gfp_flags,Attrs (0 )) } +/// Returns the number of elements `T` in this allocation. +/// +/// Note that this is not the size of the allocation in bytes, which is provided by +/// [`Self::size`]. +pub fn count (&self) ->usize { + self.count + } + +/// Returns the size in bytes of this allocation. +pub fn size (&self) ->usize { +// INVARIANT: The type invariant of `Self` guarantees that `size_of::<T> * count` fits into +// a `usize`. + self.count * core::mem::size_of ::<T >() + } +/// Returns the base address to the allocated region in the CPU's virtual address space. pub fn start_ptr (&self) -> *const T { self.cpu_addr
Signature · 1 line
2.49.0
Re: [PATCH v6 02/24] rust: dma: expose the count and size of CoherentAllocation
Quoted 4 lines · Alexandre Courbot
These properties are very useful to have (and to be used by nova-core) and should be accessible.
Signed-off-by Alexandre Courbot <[email protected]>
Applied to alloc-next, thanks!
[ Slightly extend the commit message. - Danilo ]
Alexandre Courbot
maintainerPATCH v6 3/24 rust: dma: add dma_handle_with_offset method to CoherentAllocation
In reply to Alexandre CourbotSometimes one may want to obtain a DMA handle starting at a given offset. This can be done by adding said offset to the result of dma_handle(), but doing so on the client side carries the risk that the operation will go outside the bounds of the allocation.
Thus, add a dma_handle_with_offset method that adds the desired offset after checking that it is still valid.
--- rust/kernel/dma.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
rust/kernel/dma.rs +14 -0
@@ -238,6 +238,20 @@ pub fn dma_handle(&self) -> bindings::dma_addr_t { self.dma_handle } +/// Returns a DMA handle starting at `offset` (in units of `T`) which may be given to the +/// device as the DMA address base of the region. +/// +/// Returns `EINVAL` if `offset` is not within the bounds of the allocation. +pub fn dma_handle_with_offset (&self, offset:usize ) ->Result <bindings::dma_addr_t > { +if offset >= self.count { +Err (EINVAL ) + }else { +// INVARIANT: The type invariant of `Self` guarantees that `size_of::<T> * count` fits +// into a `usize`, and `offset` is inferior to `count`. +Ok (self.dma_handle + (offset * core::mem::size_of ::<T >())as bindings::dma_addr_t ) + } + } +/// Returns a pointer to an element from the region with bounds checking. `offset` is in /// units of `T`, not the number of bytes. ///
Signature · 1 line
2.49.0
Re: [PATCH v6 03/24] rust: dma: add dma_handle_with_offset method to CoherentAllocation
Quoted 9 lines · Alexandre Courbot
Sometimes one may want to obtain a DMA handle starting at a given offset. This can be done by adding said offset to the result of
dma_handle(), but doing so on the client side carries the risk that the operation will go outside the bounds of the allocation.Thus, add a
dma_handle_with_offsetmethod that adds the desired offset after checking that it is still valid.Signed-off-by Alexandre Courbot <[email protected]>
Applied to alloc-next, thanks!
Alexandre Courbot
maintainerPATCH v6 4/24 rust: make ETIMEDOUT error available
In reply to Alexandre CourbotWe will use this error in the nova-core driver.
--- rust/kernel/error.rs | 1 + 1 file changed, 1 insertion(+)
rust/kernel/error.rs +1 -0
@@ -65,6 +65,7 @@ macro_rules! declare_err {declare_err! (EDOM ,"Math argument out of domain of func." );declare_err! (ERANGE ,"Math result not representable." );declare_err! (EOVERFLOW ,"Value too large for defined data type." ); +declare_err! (ETIMEDOUT ,"Connection timed out." );declare_err! (ERESTARTSYS ,"Restart the system call." );declare_err! (ERESTARTNOINTR ,"System call was interrupted by a signal and will be restarted." );declare_err! (ERESTARTNOHAND ,"Restart if no handler." );
Signature · 1 line
2.49.0
Re: [PATCH v6 04/24] rust: make ETIMEDOUT error available
Quoted 5 lines · Alexandre Courbot
We will use this error in the nova-core driver.
Reviewed-by Benno Lossin <[email protected]>Signed-off-by Alexandre Courbot <[email protected]>
Cheers,
Miguel
Alexandre Courbot
maintainerPATCH v6 5/24 rust: sizes: add constants up to SZ_2G
In reply to Alexandre Courbotnova-core will need to use SZ_1M, so make the remaining constants available.
--- rust/kernel/sizes.rs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+)
rust/kernel/sizes.rs +24 -0
@@ -24,3 +24,27 @@pub const SZ_256K :usize = bindings::SZ_256K as usize ;/// 0x00080000 pub const SZ_512K :usize = bindings::SZ_512K as usize ; +/// 0x00100000 +pub const SZ_1M :usize = bindings::SZ_1M as usize ; +/// 0x00200000 +pub const SZ_2M :usize = bindings::SZ_2M as usize ; +/// 0x00400000 +pub const SZ_4M :usize = bindings::SZ_4M as usize ; +/// 0x00800000 +pub const SZ_8M :usize = bindings::SZ_8M as usize ; +/// 0x01000000 +pub const SZ_16M :usize = bindings::SZ_16M as usize ; +/// 0x02000000 +pub const SZ_32M :usize = bindings::SZ_32M as usize ; +/// 0x04000000 +pub const SZ_64M :usize = bindings::SZ_64M as usize ; +/// 0x08000000 +pub const SZ_128M :usize = bindings::SZ_128M as usize ; +/// 0x10000000 +pub const SZ_256M :usize = bindings::SZ_256M as usize ; +/// 0x20000000 +pub const SZ_512M :usize = bindings::SZ_512M as usize ; +/// 0x40000000 +pub const SZ_1G :usize = bindings::SZ_1G as usize ; +/// 0x80000000 +pub const SZ_2G :usize = bindings::SZ_2G as usize ;
Signature · 1 line
2.49.0
Re: [PATCH v6 05/24] rust: sizes: add constants up to SZ_2G
Quoted 6 lines · Alexandre Courbot
nova-core will need to use
SZ_1M, so make the remaining constants available.Reviewed-by Boqun Feng <[email protected]>Signed-off-by Alexandre Courbot <[email protected]>
Cheers,
Miguel
Alexandre Courbot
maintainerPATCH v6 6/24 gpu: nova-core: use absolute paths in register!() macro
In reply to Alexandre CourbotFix the paths that were not absolute to prevent a potential local module from being picked up.
--- drivers/gpu/nova-core/regs/macros.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/gpu/nova-core/regs/macros.rs +6 -6
@@ -114,7 +114,7 @@ fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result { } } -impl core::ops::BitOr for $name { +impl ::core::ops::BitOr for $name {type Output =Self ;fn bitor (self, rhs:Self ) ->Self ::Output {
@@ -161,7 +161,7 @@ impl $name { (@check_field_bounds $hi:tt:$lo:tt $field:ident as bool) => {#[allow(clippy::eq_op)] const _: () = { - kernel::build_assert!( + ::kernel::build_assert!( $hi == $lo,concat! ("boolean field `" ,stringify! ($field),"` covers more than one bit" ) );
@@ -172,7 +172,7 @@ impl $name { (@check_field_bounds $hi:tt:$lo:tt $field:ident as $type:tt) => {#[allow(clippy::eq_op)] const _: () = { - kernel::build_assert!( + ::kernel::build_assert!( $hi >= $lo,concat! ("field `" ,stringify! ($field),"`'s MSB is smaller than its LSB" ) );
@@ -234,7 +234,7 @@ impl $name { @leaf_accessor $name:ident $hi:tt:$lo:tt $field:ident as $type:ty { $process:expr } $to_type:ty => $res_type:ty $(, $comment:literal)?; ) => { - kernel::macros::paste!( + ::kernel::macros::paste!(const [<$field:upper>]: ::core::ops::RangeInclusive <u8 > = $lo..=$hi;const [<$field:upper _MASK>]:u32 = ((((1 << $hi) -1 ) <<1 ) +1 ) - ((1 << $lo) -1 );const [<$field:upper_SHIFT >]:u32 =Self ::[<$field:upper _MASK>].trailing_zeros ();
@@ -246,7 +246,7 @@ impl $name { )?#[inline] pub (crate )fn $field(self) -> $res_type { - kernel::macros::paste!( + ::kernel::macros::paste!(const MASK :u32 = $name::[<$field:upper _MASK>];const SHIFT :u32 = $name::[<$field:upper_SHIFT >]; );
@@ -255,7 +255,7 @@ pub(crate) fn $field(self) -> $res_type { $process(field) } - kernel::macros::paste!( + ::kernel::macros::paste!( $( #[doc="Sets the value of this field:"] #[doc=$comment]
Signature · 1 line
2.49.0
Alexandre Courbot
maintainerPATCH v6 7/24 gpu: nova-core: add delimiter for helper rules in register!() macro
In reply to Alexandre CourbotThis macro is pretty complex, and most rules are just helper, so add a delimiter to indicate when users only interested in using it can stop reading.
--- drivers/gpu/nova-core/regs/macros.rs | 2 ++ 1 file changed, 2 insertions(+)
drivers/gpu/nova-core/regs/macros.rs +2 -0
@@ -94,6 +94,8 @@ macro_rules! register {register! (@io$name @ + $offset); }; +// All rules below are helpers. +// Defines the wrapper `$name` type, as well as its relevant implementations (`Debug`, `BitOr`, // and conversion to regular `u32`). (@common $name:ident $(, $comment:literal)?) => {
Signature · 1 line
2.49.0
Alexandre Courbot
maintainerPATCH v6 8/24 gpu: nova-core: expose the offset of each register as a type constant
In reply to Alexandre CourbotAlthough we want to access registers using the provided methods, it is sometimes needed to use their raw offset, for instance when working with a register array.
Expose the offset of each register using a type constant to avoid resorting to hardcoded values.
--- drivers/gpu/nova-core/regs/macros.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-)
drivers/gpu/nova-core/regs/macros.rs +8 -3
@@ -78,7 +78,7 @@ macro_rules! register { $($fields:tt)* } ) => { -register! (@common $name $(, $comment)?); +register! (@common $name @ $offset $(, $comment)?);register! (@field_accessors $name { $($fields)* });register! (@io $name @ $offset); };
@@ -89,7 +89,7 @@ macro_rules! register { $($fields:tt)* } ) => { -register! (@common $name $(, $comment)?); +register! (@common $name @ $offset $(, $comment)?);register! (@field_accessors $name { $($fields)* });register! (@io$name @ + $offset); };
@@ -98,7 +98,7 @@ macro_rules! register {// Defines the wrapper `$name` type, as well as its relevant implementations (`Debug`, `BitOr`, // and conversion to regular `u32`). - (@common $name:ident $(, $comment:literal)?) => { + (@common $name:ident @ $offset:literal $(, $comment:literal)?) => { $( #[doc=$comment] )?
@@ -106,6 +106,11 @@ macro_rules! register {#[derive( Clone , Copy , Default )] pub(crate) struct $name(u32); +#[allow(dead_code)] +impl $name { +pub (crate )const OFFSET :usize = $offset; + } +// TODO: display the raw hex value, then the value of all the fields. This requires // matching the fields, which will complexify the syntax considerably... impl ::core::fmt::Debug for $name {
Signature · 1 line
2.49.0
Alexandre Courbot
maintainerPATCH v6 9/24 gpu: nova-core: allow register aliases
In reply to Alexandre CourbotSome registers (notably scratch registers) don't have a definitive purpose, but need to be interpreted differently depending on context.
Expand the register!() macro to support a syntax indicating that a register type should be at the same offset as another one, but under a different name, and with different fields and documentation.
--- drivers/gpu/nova-core/regs/macros.rs | 40 ++++++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-)
drivers/gpu/nova-core/regs/macros.rs +38 -2
@@ -71,6 +71,20 @@/// pr_info!("CPU CTL: {:#x}", cpuctl); /// cpuctl.set_start(true).write(&bar, CPU_BASE); /// ``` +/// +/// It is also possible to create a alias register by using the `=> ALIAS` syntax. This is useful +/// for cases where a register's interpretation depends on the context: +/// +/// ```no_run +/// register!(SCRATCH_0 @ 0x0000100, "Scratch register 0" { +/// 31:0 value as u32, "Raw value"; +/// +/// register!(SCRATCH_0_BOOT_STATUS => SCRATCH_0, "Boot status of the firmware" { +/// 0:0 completed as bool, "Whether the firmware has completed booting"; +/// ``` +/// +/// In this example, `SCRATCH_0_BOOT_STATUS` uses the same I/O address as `SCRATCH_0`, while also +/// providing its own `completed` method. macro_rules! register {// Creates a register at a fixed offset of the MMIO space. (
@@ -83,6 +97,17 @@ macro_rules! register {register! (@io $name @ $offset); }; +// Creates a alias register of fixed offset register `alias` with its own fields. + ( + $name:ident => $alias:ident $(, $comment:literal)? { + $($fields:tt)* + } + ) => { +register! (@common $name @ $alias::OFFSET $(, $comment)?); +register! (@field_accessors $name { $($fields)* }); +register! (@io $name @ $alias::OFFSET ); + }; +// Creates a register at a relative offset from a base address. ( $name:ident @ + $offset:literal $(, $comment:literal)? {
@@ -94,11 +119,22 @@ macro_rules! register {register! (@io$name @ + $offset); }; +// Creates a alias register of relative offset register `alias` with its own fields. + ( + $name:ident => + $alias:ident $(, $comment:literal)? { + $($fields:tt)* + } + ) => { +register! (@common $name @ $alias::OFFSET $(, $comment)?); +register! (@field_accessors $name { $($fields)* }); +register! (@io $name @ + $alias::OFFSET ); + }; +// All rules below are helpers. // Defines the wrapper `$name` type, as well as its relevant implementations (`Debug`, `BitOr`, // and conversion to regular `u32`). - (@common $name:ident @ $offset:literal $(, $comment:literal)?) => { + (@common $name:ident @ $offset:expr $(, $comment:literal)?) => { $( #[doc=$comment] )?
@@ -280,7 +316,7 @@ pub(crate) fn [<set_ $field>](mut self, value: $to_type) -> Self { };// Creates the IO accessors for a fixed offset register. - (@io $name:ident @ $offset:literal) => { + (@io $name:ident @ $offset:expr) => {#[allow(dead_code)] impl $name {#[inline]
Signature · 1 line
2.49.0
Alexandre Courbot
maintainerPATCH v6 10/24 gpu: nova-core: increase BAR0 size to 16MB
In reply to Alexandre CourbotThe Turing+ register address space spans over that range, so increase it as future patches will access more registers.
--- drivers/gpu/nova-core/driver.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/nova-core/driver.rs +2 -2
@@ -1,6 +1,6 @@// SPDX-License-Identifier: GPL-2.0 -use kernel::{auxiliary, bindings, c_str, device::Core , pci, prelude::*}; +use kernel::{auxiliary, bindings, c_str, device::Core , pci, prelude::*, sizes::SZ_16M };use crate ::gpu::Gpu ;
@@ -11,7 +11,7 @@ pub(crate) struct NovaCore { _reg: auxiliary::Registration, } -const BAR0_SIZE :usize =8 ; +const BAR0_SIZE :usize =SZ_16M ;pub (crate )type Bar0 = pci::Bar <BAR0_SIZE >; kernel::pci_device_table!(
Signature · 1 line
2.49.0
Alexandre Courbot
maintainerPATCH v6 11/24 gpu: nova-core: add helper function to wait on condition
In reply to Alexandre CourbotWhile programming the hardware, we frequently need to busy-wait until a condition (like a given bit of a register to switch value) happens.
Add a basic wait_on helper function to wait on such conditions expressed as a closure, with a timeout argument.
This is temporary as we will switch to read_poll_timeout [1] once it is available.
[1] https://lore.kernel.org/lkml/[email protected]/
--- drivers/gpu/nova-core/util.rs | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+)
drivers/gpu/nova-core/util.rs +29 -0
@@ -1,5 +1,10 @@// SPDX-License-Identifier: GPL-2.0 +use core::time::Duration ; + +use kernel::prelude::*; +use kernel::time::Instant ; +pub (crate )const fn to_lowercase_bytes <const N :usize >(s: &str ) -> [u8 ;N ] {let src = s.as_bytes ();let mut dst = [0 ;N ];
@@ -19,3 +24,27 @@ pub(crate) const fn const_bytes_to_str(bytes: &[u8]) -> &str { Err(_) => kernel::build_error!("Bytes are not valid UTF-8."), } } + +/// Wait until `cond` is true or `timeout` elapsed. +/// +/// When `cond` evaluates to `Some`, its return value is returned. +/// +/// `Err(ETIMEDOUT)` is returned if `timeout` has been reached without `cond` evaluating to +/// `Some`. +/// +/// TODO: replace with `read_poll_timeout` once it is available. +/// (https://lore.kernel.org/lkml/[email protected]/) +#[expect(dead_code)] +pub (crate )fn wait_on <R ,F :Fn () ->Option <R >>(timeout:Duration , cond:F ) ->Result <R > { +let start_time =Instant ::now (); + +loop { +if let Some (ret) =cond () { +return Ok (ret); + } + +if start_time.elapsed ().as_nanos () > timeout.as_nanos ()as i64 { +return Err (ETIMEDOUT ); + } + } +}
Signature · 1 line
2.49.0
Alexandre Courbot
maintainerPATCH v6 12/24 gpu: nova-core: wait for GFW_BOOT completion
In reply to Alexandre CourbotUpon reset, the GPU executes the GFW (GPU Firmware) in order to initialize its base parameters such as clocks. The driver must ensure that this step is completed before using the hardware.
--- drivers/gpu/nova-core/gfw.rs | 41 ++++++++++++++++++++++++++++++++++++++ drivers/gpu/nova-core/gpu.rs | 5 +++++ drivers/gpu/nova-core/nova_core.rs | 1 + drivers/gpu/nova-core/regs.rs | 25 +++++++++++++++++++++++ drivers/gpu/nova-core/util.rs | 1 - 5 files changed, 72 insertions(+), 1 deletion(-)
drivers/gpu/nova-core/gfw.rs new file +41 -0
@@ -0,0 +1,41 @@ +// SPDX-License-Identifier: GPL-2.0 + +//! GPU Firmware (GFW) support. +//! +//! Upon reset, the GPU runs some firmware code from the BIOS to setup its core parameters. Most of +//! the GPU is considered unusable until this step is completed, so we must wait on it before +//! performing driver initialization. + +use core::time::Duration ; + +use kernel::bindings; +use kernel::prelude::*; + +use crate ::driver::Bar0 ; +use crate ::regs; +use crate ::util; + +/// Wait until `GFW` (GPU Firmware) completes, or a 4 seconds timeout elapses. +pub (crate )fn wait_gfw_boot_completion (bar: &Bar0 ) ->Result { +// TIMEOUT: arbitrarily large value. GFW starts running immediately after the GPU is put out of +// reset, and should complete in less time than that. + util::wait_on (Duration ::from_secs (4 ), || { +// Check that FWSEC has lowered its protection level before reading the GFW_BOOT +// status. +let gfw_booted = regs::NV_PGC6_AON_SECURE_SCRATCH_GROUP_05_PRIV_LEVEL_MASK ::read (bar) + .read_protection_level0 () + && regs::NV_PGC6_AON_SECURE_SCRATCH_GROUP_05_0_GFW_BOOT ::read (bar).completed (); + +if gfw_booted { +Some (()) + }else { +// Avoid busy-looping. +// SAFETY: msleep should be safe to call with any parameter. +// TODO: replace with [1] once it merges. +// [1] https://lore.kernel.org/rust-for-linux/[email protected]/ +unsafe { bindings::msleep (1 ) }; + +None + } + }) +}
drivers/gpu/nova-core/gpu.rs +5 -0
@@ -4,6 +4,7 @@use crate ::driver::Bar0 ;use crate ::firmware::{Firmware ,FIRMWARE_VERSION }; +use crate ::gfw;use crate ::regs;use crate ::util;use core::fmt;
@@ -182,6 +183,10 @@ pub(crate) fn new( spec.revision ); +// We must wait for GFW_BOOT completion before doing any significant setup on the GPU. + gfw::wait_gfw_boot_completion (bar) + .inspect_err (|_|dev_err! (pdev.as_ref (),"GFW boot did not complete" ))?; + Ok(pin_init!(Self { spec, bar: devres_bar,
drivers/gpu/nova-core/nova_core.rs +1 -0
@@ -4,6 +4,7 @@mod driver;mod firmware; +mod gfw;mod gpu;mod regs;mod util;
drivers/gpu/nova-core/regs.rs +25 -0
@@ -37,3 +37,28 @@ pub(crate) fn chipset(self) -> Result<Chipset> { .and_then(Chipset::try_from) } } + +/* PGC6 */ + +register! (NV_PGC6_AON_SECURE_SCRATCH_GROUP_05_PRIV_LEVEL_MASK @0x00118128 { +0 :0 read_protection_level0as bool ,"Set after FWSEC lowers its protection level" ; +}); + +// TODO: This is an array of registers. +register! (NV_PGC6_AON_SECURE_SCRATCH_GROUP_05 @0x00118234 { +31 :0 valueas u32 ; +}); + +register! ( +NV_PGC6_AON_SECURE_SCRATCH_GROUP_05_0_GFW_BOOT =>NV_PGC6_AON_SECURE_SCRATCH_GROUP_05 , +"Scratch group 05 register 0 used as GFW boot progress indicator" { +7 :0 progressas u8 ,"Progress of GFW boot (0xff means completed)" ; + } +); + +impl NV_PGC6_AON_SECURE_SCRATCH_GROUP_05_0_GFW_BOOT { +/// Returns `true` if GFW boot is completed. +pub (crate )fn completed (self) ->bool { + self.progress () ==0xff + } +}
drivers/gpu/nova-core/util.rs +0 -1
@@ -34,7 +34,6 @@ pub(crate) const fn const_bytes_to_str(bytes: &[u8]) -> &str {/// /// TODO: replace with `read_poll_timeout` once it is available. /// (https://lore.kernel.org/lkml/[email protected]/) -#[expect(dead_code)] pub (crate )fn wait_on <R ,F :Fn () ->Option <R >>(timeout:Duration , cond:F ) ->Result <R > {let start_time =Instant ::now ();
Signature · 1 line
2.49.0
Alexandre Courbot
maintainerPATCH v6 13/24 gpu: nova-core: add DMA object struct
In reply to Alexandre CourbotSince we will need to allocate lots of distinct memory chunks to be shared between GPU and CPU, introduce a type dedicated to that. It is a light wrapper around CoherentAllocation.
--- drivers/gpu/nova-core/dma.rs | 61 ++++++++++++++++++++++++++++++++++++++ drivers/gpu/nova-core/nova_core.rs | 1 + 2 files changed, 62 insertions(+)
drivers/gpu/nova-core/dma.rs new file +61 -0
@@ -0,0 +1,61 @@ +// SPDX-License-Identifier: GPL-2.0 + +//! Simple DMA object wrapper. + +// To be removed when all code is used. +#![expect(dead_code)] + +use core::ops::{Deref ,DerefMut }; + +use kernel::device; +use kernel::dma::CoherentAllocation ; +use kernel::page::PAGE_SIZE ; +use kernel::prelude::*; + +pub (crate )struct DmaObject { + dma:CoherentAllocation <u8 >, +} + +impl DmaObject { +pub (crate )fn new (dev: &device::Device <device::Bound >, len:usize ) ->Result <Self > { +let len = core::alloc::Layout ::from_size_align (len,PAGE_SIZE ) + .map_err (|_|EINVAL )? + .pad_to_align () + .size (); +let dma =CoherentAllocation ::alloc_coherent (dev, len,GFP_KERNEL | __GFP_ZERO)?; + +Ok (Self { dma }) + } + +pub (crate )fn from_data (dev: &device::Device <device::Bound >, data: &[u8 ]) ->Result <Self > { +Self ::new (dev, data.len ()).map (|mut dma_obj| { +// TODO: replace with `CoherentAllocation::write()` once available. +// SAFETY: +// - `dma_obj`'s size is at least `data.len()`. +// - We have just created this object and there is no other user at this stage. +unsafe { + core::ptr::copy_nonoverlapping ( + data.as_ptr (), + dma_obj.dma.start_ptr_mut (), + data.len (), + ); + } + + dma_obj + }) + } +} + +impl Deref for DmaObject { +type Target =CoherentAllocation <u8 >; + +fn deref (&self) -> &Self ::Target { + &self.dma + } +} + +impl DerefMut for DmaObject { +fn deref_mut (&mut self) -> &mut Self ::Target { + &mut self.dma + } +}
drivers/gpu/nova-core/nova_core.rs +1 -0
@@ -2,6 +2,7 @@//! Nova Core GPU Driver +mod dma;mod driver;mod firmware;mod gfw;
Signature · 1 line
2.49.0
Alexandre Courbot
maintainerPATCH v6 14/24 gpu: nova-core: register sysmem flush page
In reply to Alexandre CourbotReserve a page of system memory so sysmembar can perform a read on it if a system write occurred since the last flush. Do this early as it can be required to e.g. reset the GPU falcons.
Chipsets capabilities differ in that respect, so this commit also introduces the FB HAL.
--- drivers/gpu/nova-core/fb.rs | 66 +++++++++++++++++++++++++++++++++++ drivers/gpu/nova-core/fb/hal.rs | 31 ++++++++++++++++ drivers/gpu/nova-core/fb/hal/ga100.rs | 45 ++++++++++++++++++++++++ drivers/gpu/nova-core/fb/hal/tu102.rs | 42 ++++++++++++++++++++++ drivers/gpu/nova-core/gpu.rs | 25 +++++++++++-- drivers/gpu/nova-core/nova_core.rs | 1 + drivers/gpu/nova-core/regs.rs | 10 ++++++ 7 files changed, 218 insertions(+), 2 deletions(-)
drivers/gpu/nova-core/fb.rs new file +66 -0
@@ -0,0 +1,66 @@ +// SPDX-License-Identifier: GPL-2.0 + +use kernel::prelude::*; +use kernel::types::ARef ; +use kernel::{dev_warn, device}; + +use crate ::dma::DmaObject ; +use crate ::driver::Bar0 ; +use crate ::gpu::Chipset ; + +mod hal; + +/// Type holding the sysmem flush memory page, a page of memory to be written into the +/// `NV_PFB_NISO_FLUSH_SYSMEM_ADDR*` registers and used to maintain memory coherency. +/// +/// Users are responsible for manually calling [`Self::unregister`] before dropping this object, or +/// the page might remain in use even after it has been freed. +pub (crate )struct SysmemFlush { +/// Chipset we are operating on. + chipset:Chipset , + device:ARef <device::Device >, +/// Keep the page alive as long as we need it. + page:DmaObject , +} + +impl SysmemFlush { +/// Allocate a memory page and register it as the sysmem flush page. +pub (crate )fn register ( + dev: &device::Device <device::Bound >, + bar: &Bar0 , + chipset:Chipset , + ) ->Result <Self > { +let page =DmaObject ::new (dev, kernel::bindings::PAGE_SIZE )?; + + hal::fb_hal (chipset).write_sysmem_flush_page (bar, page.dma_handle ())?; + +Ok (Self { + chipset, + device: dev.into (), + page, + }) + } + +/// Unregister the managed sysmem flush page. +/// +/// Users must make sure to call this method before dropping the object. +pub (crate )fn unregister (self, bar: &Bar0 ) { +let hal = hal::fb_hal (self.chipset); + +if hal.read_sysmem_flush_page (bar) == self.page.dma_handle () { +let _ = hal.write_sysmem_flush_page (bar,0 ).inspect_err (|e| { +dev_warn! ( + &self.device, +"failed to unregister sysmem flush page: {:?}" , + e + ) + }); + }else { +// Another page has been registered after us for some reason - warn as this is a bug. +dev_warn! ( + &self.device, +"attempt to unregister a sysmem flush page that is not active\n" + ); + } + } +}
drivers/gpu/nova-core/fb/hal.rs new file +31 -0
@@ -0,0 +1,31 @@ +// SPDX-License-Identifier: GPL-2.0 + +use kernel::prelude::*; + +use crate ::driver::Bar0 ; +use crate ::gpu::Chipset ; + +mod ga100; +mod tu102; + +pub (crate )trait FbHal { +/// Returns the address of the currently-registered sysmem flush page. +fn read_sysmem_flush_page (&self, bar: &Bar0 ) ->u64 ; + +/// Register `addr` as the address of the sysmem flush page. +/// +/// This might fail if the address is too large for the receiving register. +fn write_sysmem_flush_page (&self, bar: &Bar0 , addr:u64 ) ->Result ; +} + +/// Returns the HAL corresponding to `chipset`. +pub (super )fn fb_hal (chipset:Chipset ) -> &'staticdyn FbHal { +use Chipset ::*; + +match chipset { +TU102 |TU104 |TU106 |TU117 |TU116 => tu102::TU102_HAL , +GA100 |GA102 |GA103 |GA104 |GA106 |GA107 |AD102 |AD103 |AD104 |AD106 |AD107 => { + ga100::GA100_HAL + } + } +}
drivers/gpu/nova-core/fb/hal/ga100.rs new file +45 -0
45 lines not on this page · raw message
drivers/gpu/nova-core/fb/hal/tu102.rs new file +42 -0
42 lines not on this page · raw message
drivers/gpu/nova-core/gpu.rs +23 -2
@@ -3,6 +3,7 @@use kernel::{device, devres::Devres , error::code::*, pci, prelude::*};use crate ::driver::Bar0 ; +use crate ::fb::SysmemFlush ;use crate ::firmware::{Firmware ,FIRMWARE_VERSION };use crate ::gfw;use crate ::regs;
@@ -158,12 +159,28 @@ fn new(bar: &Bar0) -> Result<Spec> { }/// Structure holding the resources required to operate the GPU. -#[pin_data] +#[pin_data( PinnedDrop )] pub (crate )struct Gpu { spec:Spec ,/// MMIO mapping of PCI BAR 0 bar:Devres <Bar0 >, fw:Firmware , +/// System memory page required for flushing all pending GPU-side memory writes done through +/// PCIE into system memory. +/// +/// We use an `Option` so we can take the object during `drop`. It is not accessed otherwise. + sysmem_flush:Option <SysmemFlush >, +} + +#[pinned_drop] +impl PinnedDrop for Gpu { +fn drop (mut self:Pin <&mut Self >) { +// Unregister the sysmem flush page before we release it. +let _ = self + .sysmem_flush + .take () + .map (|sysmem_flush| self.bar.try_access_with (|b| sysmem_flush.unregister (b))); + } }impl Gpu {
@@ -187,10 +204,14 @@ pub(crate) fn new( gfw::wait_gfw_boot_completion (bar) .inspect_err (|_|dev_err! (pdev.as_ref (),"GFW boot did not complete" ))?; +// System memory page required for sysmembar to properly flush into system memory. +let sysmem_flush =SysmemFlush ::register (pdev.as_ref (), bar, spec.chipset)?; +Ok (pin_init! (Self { spec, bar: devres_bar, - fw + fw, + sysmem_flush:Some (sysmem_flush), })) } }
drivers/gpu/nova-core/nova_core.rs +1 -0
@@ -4,6 +4,7 @@mod dma;mod driver; +mod fb;mod firmware;mod gfw;mod gpu;
drivers/gpu/nova-core/regs.rs +10 -0
@@ -38,6 +38,16 @@ pub(crate) fn chipset(self) -> Result<Chipset> { } } +/* PFB */ + +register! (NV_PFB_NISO_FLUSH_SYSMEM_ADDR @0x00100c10 { +31 :0 adr_39_08as u32 ; +}); + +register! (NV_PFB_NISO_FLUSH_SYSMEM_ADDR_HI @0x00100c40 { +23 :0 adr_63_40as u32 ; +}); +/* PGC6 */ register! (NV_PGC6_AON_SECURE_SCRATCH_GROUP_05_PRIV_LEVEL_MASK @0x00118128 {
Signature · 1 line
2.49.0
Alexandre Courbot
maintainerPATCH v6 15/24 gpu: nova-core: add falcon register definitions and base code
In reply to Alexandre CourbotBooting the GSP on Ampere requires an intricate dance between the GSP and SEC2 falcons, where the GSP starts by running the FWSEC firmware to create the WPR2 region , and then SEC2 loads the actual RISC-V firmware into the GSP.
Add the common Falcon code and HAL for Ampere GPUs, and instantiate the GSP and SEC2 Falcons that will be required to perform that dance and boot the GSP.
Thanks to Ben Skeggs for pointing out an important bug in the memory scrubbing code that could lead to a race condition and ultimately a failure to boot the GSP!
--- drivers/gpu/nova-core/falcon.rs | 551 ++++++++++++++++++++++++++++++ drivers/gpu/nova-core/falcon/gsp.rs | 24 ++ drivers/gpu/nova-core/falcon/hal.rs | 54 +++ drivers/gpu/nova-core/falcon/hal/ga102.rs | 119 +++++++ drivers/gpu/nova-core/falcon/sec2.rs | 10 + drivers/gpu/nova-core/gpu.rs | 11 + drivers/gpu/nova-core/nova_core.rs | 1 + drivers/gpu/nova-core/regs.rs | 146 ++++++++ 8 files changed, 916 insertions(+)
drivers/gpu/nova-core/falcon.rs new file +551 -0
@@ -0,0 +1,551 @@ +// SPDX-License-Identifier: GPL-2.0 + +//! Falcon microprocessor base support + +// To be removed when all code is used. +#![expect(dead_code)] + +use core::ops::Deref ; +use core::time::Duration ; +use hal::FalconHal ; +use kernel::bindings; +use kernel::device; +use kernel::prelude::*; +use kernel::types::ARef ; + +use crate ::dma::DmaObject ; +use crate ::driver::Bar0 ; +use crate ::gpu::Chipset ; +use crate ::regs; +use crate ::util; + +pub (crate )mod gsp; +mod hal; +pub (crate )mod sec2; + +/// Revision number of a falcon core, used in the [`crate::regs::NV_PFALCON_FALCON_HWCFG1`] +/// register. +#[repr( u8 )] +#[derive( Debug , Default , Copy , Clone , PartialEq , Eq , PartialOrd , Ord )] +pub (crate )enum FalconCoreRev { +#[default] +Rev1 =1 , +Rev2 =2 , +Rev3 =3 , +Rev4 =4 , +Rev5 =5 , +Rev6 =6 , +Rev7 =7 , +} + +impl TryFrom <u8 >for FalconCoreRev { +type Error =Error ; + +fn try_from (value:u8 ) ->Result <Self > { +use FalconCoreRev ::*; + +let rev =match value { +1 =>Rev1 , +2 =>Rev2 , +3 =>Rev3 , +4 =>Rev4 , +5 =>Rev5 , +6 =>Rev6 , +7 =>Rev7 , + _ =>return Err (EINVAL ), + }; + +Ok (rev) + } +} + +/// Revision subversion number of a falcon core, used in the +/// [`crate::regs::NV_PFALCON_FALCON_HWCFG1`] register. +#[repr( u8 )] +#[derive( Debug , Default , Copy , Clone , PartialEq , Eq , PartialOrd , Ord )] +pub (crate )enum FalconCoreRevSubversion { +#[default] +Subversion0 =0 , +Subversion1 =1 , +Subversion2 =2 , +Subversion3 =3 , +} + +impl TryFrom <u8 >for FalconCoreRevSubversion { +type Error =Error ; + +fn try_from (value:u8 ) ->Result <Self > { +use FalconCoreRevSubversion ::*; + +let sub_version =match value &0b11 { +0 =>Subversion0 , +1 =>Subversion1 , +2 =>Subversion2 , +3 =>Subversion3 , + _ =>return Err (EINVAL ), + }; + +Ok (sub_version) + } +} + +/// Security model of a falcon core, used in the [`crate::regs::NV_PFALCON_FALCON_HWCFG1`] +/// register. +#[repr( u8 )] +#[derive( Debug , Default , Copy , Clone )] +pub (crate )enum FalconSecurityModel { +/// Non-Secure: runs unsigned code without privileges. +#[default] +None =0 , +/// Low-Secure: runs code with some privileges. Can only be entered from `Heavy` mode, which +/// will typically validate the LS code through some signature. +Light =2 , +/// High-Secure: runs signed code with full privileges. Signature is validated by boot ROM. +Heavy =3 , +} + +impl TryFrom <u8 >for FalconSecurityModel { +type Error =Error ; + +fn try_from (value:u8 ) ->Result <Self > { +use FalconSecurityModel ::*; + +let sec_model =match value { +0 =>None , +2 =>Light , +3 =>Heavy , + _ =>return Err (EINVAL ), + }; + +Ok (sec_model) + } +} + +/// Signing algorithm for a given firmware, used in the [`crate::regs::NV_PFALCON2_FALCON_MOD_SEL`] +/// register. +#[repr( u8 )] +#[derive( Debug , Default , Copy , Clone , PartialEq , Eq )] +pub (crate )enum FalconModSelAlgo { +/// RSA3K. +#[default] +Rsa3k =1 , +} + +impl TryFrom <u8 >for FalconModSelAlgo { +type Error =Error ; + +fn try_from (value:u8 ) ->Result <Self > { +match value { +1 =>Ok (FalconModSelAlgo ::Rsa3k ), + _ =>Err (EINVAL ), + } + } +} + +/// Valid values for the `size` field of the [`crate::regs::NV_PFALCON_FALCON_DMATRFCMD`] register. +#[repr( u8 )] +#[derive( Debug , Default , Copy , Clone , PartialEq , Eq )] +pub (crate )enum DmaTrfCmdSize { +/// 256 bytes transfer. +#[default] +Size256B =0x6 , +} + +impl TryFrom <u8 >for DmaTrfCmdSize { +type Error =Error ; + +fn try_from (value:u8 ) ->Result <Self > { +match value { +0x6 =>Ok (Self ::Size256B ), + _ =>Err (EINVAL ), + } + } +} + +/// Currently active core on a dual falcon/riscv (Peregrine) controller. +#[derive( Debug , Clone , Copy , PartialEq , Eq , Default )] +pub (crate )enum PeregrineCoreSelect { +/// Falcon core is active. +#[default] +Falcon =0 , +/// RISC-V core is active. +Riscv =1 , +} + +impl From <bool >for PeregrineCoreSelect { +fn from (value:bool ) ->Self { +match value { +false =>PeregrineCoreSelect ::Falcon , +true =>PeregrineCoreSelect ::Riscv , + } + } +} + +/// Different types of memory present in a falcon core. +#[derive( Debug , Clone , Copy , PartialEq , Eq )] +pub (crate )enum FalconMem { +/// Instruction Memory. +Imem , +/// Data Memory. +Dmem , +} + +/// Target/source of a DMA transfer to/from falcon memory. +#[derive( Debug , Clone , Default )] +pub (crate )enum FalconFbifTarget { +/// VRAM. +#[default] +LocalFb =0 , +/// Coherent system memory. +CoherentSysmem =1 , +/// Non-coherent system memory. +NoncoherentSysmem =2 , +} + +impl TryFrom <u8 >for FalconFbifTarget { +type Error =Error ; + +fn try_from (value:u8 ) ->Result <Self > { +let res =match value { +0 =>Self ::LocalFb , +1 =>Self ::CoherentSysmem , +2 =>Self ::NoncoherentSysmem , + _ =>return Err (EINVAL ), + }; + +Ok (res) + } +} + +/// Type of memory addresses to use. +#[derive( Debug , Clone , Default )] +pub (crate )enum FalconFbifMemType { +/// Virtual memory addresses. +#[default] +Virtual =0 , +/// Physical memory addresses. +Physical =1 , +} + +/// Conversion from a single-bit register field. +impl From <bool >for FalconFbifMemType { +fn from (value:bool ) ->Self { +match value { +false =>Self ::Virtual , +true =>Self ::Physical , + } + } +} + +/// Trait defining the parameters of a given Falcon instance. +pub (crate )trait FalconEngine :Sync { +/// Base I/O address for the falcon, relative from which its registers are accessed. +const BASE :usize ; +} + +/// Represents a portion of the firmware to be loaded into a particular memory (e.g. IMEM or DMEM). +#[derive( Debug )] +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. +pub (crate ) dst_start:u32 , +/// Number of bytes to copy. +pub (crate ) len:u32 , +} + +/// Parameters for the falcon boot ROM. +#[derive( Debug )] +pub (crate )struct FalconBromParams { +/// Offset in `DMEM`` of the firmware's signature. +pub (crate ) pkc_data_offset:u32 , +/// Mask of engines valid for this firmware. +pub (crate ) engine_id_mask:u16 , +/// ID of the ucode used to infer a fuse register to validate the signature. +pub (crate ) ucode_id:u8 , +} + +/// Trait for providing load parameters of falcon firmwares. +pub (crate )trait FalconLoadParams { +/// Returns the load parameters for `IMEM`. +fn imem_load_params (&self) ->FalconLoadTarget ; + +/// Returns the load parameters for `DMEM`. +fn dmem_load_params (&self) ->FalconLoadTarget ; + +/// Returns the parameters to write into the BROM registers. +fn brom_params (&self) ->FalconBromParams ; + +/// Returns the start address of the firmware. +fn boot_addr (&self) ->u32 ; +} + +/// Trait for a falcon firmware. +/// +/// A falcon firmware can be loaded on a given engine, and is presented in the form of a DMA +/// object. +pub (crate )trait FalconFirmware :FalconLoadParams +Deref <Target =DmaObject > { +/// Engine on which this firmware is to be loaded. +type Target :FalconEngine ; +} + +/// Contains the base parameters common to all Falcon instances. +pub (crate )struct Falcon <E :FalconEngine > { + hal:KBox <dyn FalconHal <E >>, + dev:ARef <device::Device >, +} + +impl <E :FalconEngine + 'static>Falcon <E > { +/// Create a new falcon instance. +/// +/// `need_riscv` is set to `true` if the caller expects the falcon to be a dual falcon/riscv +/// controller. +pub (crate )fn new ( + dev: &device::Device , + chipset:Chipset , + bar: &Bar0 , + need_riscv:bool , + ) ->Result <Self > { +let hwcfg1 = regs::NV_PFALCON_FALCON_HWCFG1 ::read (bar,E ::BASE ); +// Check that the revision and security model contain valid values. +let _ = hwcfg1.core_rev ()?; +let _ = hwcfg1.security_model ()?; + +if need_riscv { +let hwcfg2 = regs::NV_PFALCON_FALCON_HWCFG2 ::read (bar,E ::BASE ); +if !hwcfg2.riscv () { +dev_err! ( + dev, +"riscv support requested on a controller that does not support it\n" + ); +return Err (EINVAL ); + } + } + +Ok (Self { + hal: hal::falcon_hal (chipset)?, + dev: dev.into (), + }) + } + +/// Wait for memory scrubbing to complete. +fn reset_wait_mem_scrubbing (&self, bar: &Bar0 ) ->Result { +// TIMEOUT: memory scrubbing should complete in less than 20ms. + util::wait_on (Duration ::from_millis (20 ), || { +if regs::NV_PFALCON_FALCON_HWCFG2 ::read (bar,E ::BASE ).mem_scrubbing_done () { +Some (()) + }else { +None + } + }) + } + +/// Reset the falcon engine. +fn reset_eng (&self, bar: &Bar0 ) ->Result { +let _ = regs::NV_PFALCON_FALCON_HWCFG2 ::read (bar,E ::BASE ); + +// According to OpenRM's `kflcnPreResetWait_GA102` documentation, HW sometimes does not set +// RESET_READY so a non-failing timeout is used. +let _ = util::wait_on (Duration ::from_micros (150 ), || { +let r = regs::NV_PFALCON_FALCON_HWCFG2 ::read (bar,E ::BASE ); +if r.reset_ready () { +Some (()) + }else { +None + } + }); + + regs::NV_PFALCON_FALCON_ENGINE ::alter (bar,E ::BASE , |v| v.set_reset (true )); + +// TODO: replace with udelay() or equivalent once available. +// TIMEOUT: falcon engine should not take more than 10us to reset. +let _:Result = util::wait_on (Duration ::from_micros (10 ), ||None ); + + regs::NV_PFALCON_FALCON_ENGINE ::alter (bar,E ::BASE , |v| v.set_reset (false )); + + self.reset_wait_mem_scrubbing (bar)?; + +Ok (()) + } + +/// Reset the controller, select the falcon core, and wait for memory scrubbing to complete. +pub (crate )fn reset (&self, bar: &Bar0 ) ->Result { + self.reset_eng (bar)?; + self.hal.select_core (self, bar)?; + self.reset_wait_mem_scrubbing (bar)?; + + regs::NV_PFALCON_FALCON_RM ::default () + .set_value (regs::NV_PMC_BOOT_0 ::read (bar).into ()) + .write (bar,E ::BASE ); + +Ok (()) + } + +/// Perform a DMA write according to `load_offsets` from `dma_handle` into the falcon's +/// `target_mem`. +/// +/// `sec` is set if the loaded firmware is expected to run in secure mode. +fn dma_wr <F :FalconFirmware <Target =E >>( + &self, + bar: &Bar0 , + fw: &F , + target_mem:FalconMem , + load_offsets:FalconLoadTarget , + sec:bool , + ) ->Result { +const DMA_LEN :u32 =256 ; + +// For IMEM, we want to use the start offset as a virtual address tag for each page, since +// code addresses in the firmware (and the boot vector) are virtual. +// +// For DMEM we can fold the start offset into the DMA handle. +let (src_start, dma_start) =match target_mem { +FalconMem ::Imem => (load_offsets.src_start, fw.dma_handle ()), +FalconMem ::Dmem => ( +0 , + fw.dma_handle_with_offset (load_offsets.src_startas usize )?, + ), + }; +if dma_start %DMA_LEN as bindings::dma_addr_t >0 { +dev_err! ( + self.dev, +"DMA transfer start addresses must be a multiple of {}" , +DMA_LEN + ); +return Err (EINVAL ); + } +if load_offsets.len %DMA_LEN >0 { +dev_err! ( + self.dev, +"DMA transfer length must be a multiple of {}" , +DMA_LEN + ); +return Err (EINVAL ); + } + +// Set up the base source DMA address. + + regs::NV_PFALCON_FALCON_DMATRFBASE ::default () + .set_base ((dma_start >>8 )as u32 ) + .write (bar,E ::BASE ); + regs::NV_PFALCON_FALCON_DMATRFBASE1 ::default () + .set_base ((dma_start >>40 )as u16 ) + .write (bar,E ::BASE ); + +let cmd = regs::NV_PFALCON_FALCON_DMATRFCMD ::default () + .set_size (DmaTrfCmdSize ::Size256B ) + .set_imem (target_mem ==FalconMem ::Imem ) + .set_sec (if sec {1 }else {0 }); + +for posin (0 ..load_offsets.len).step_by (DMA_LEN as usize ) { +// Perform a transfer of size `DMA_LEN`. + regs::NV_PFALCON_FALCON_DMATRFMOFFS ::default () + .set_offs (load_offsets.dst_start + pos) + .write (bar,E ::BASE ); + regs::NV_PFALCON_FALCON_DMATRFFBOFFS ::default () + .set_offs (src_start + pos) + .write (bar,E ::BASE ); + cmd.write (bar,E ::BASE ); + +// Wait for the transfer to complete. +// TIMEOUT: arbitrarily large value, no DMA transfer to the falcon's small memories +// should ever take that long. + util::wait_on (Duration ::from_secs (2 ), || { +let r = regs::NV_PFALCON_FALCON_DMATRFCMD ::read (bar,E ::BASE ); +if r.idle () { +Some (()) + }else { +None + } + })?; + } + +Ok (()) + } + +/// Perform a DMA load into `IMEM` and `DMEM` of `fw`, and prepare the falcon to run it. +pub (crate )fn dma_load <F :FalconFirmware <Target =E >>(&self, bar: &Bar0 , fw: &F ) ->Result { + regs::NV_PFALCON_FBIF_CTL ::alter (bar,E ::BASE , |v| v.set_allow_phys_no_ctx (true )); + regs::NV_PFALCON_FALCON_DMACTL ::default ().write (bar,E ::BASE ); + regs::NV_PFALCON_FBIF_TRANSCFG ::alter (bar,E ::BASE , |v| { + v.set_target (FalconFbifTarget ::CoherentSysmem ) + .set_mem_type (FalconFbifMemType ::Physical ) + }); + + self.dma_wr (bar, fw,FalconMem ::Imem , fw.imem_load_params (),true )?; + self.dma_wr (bar, fw,FalconMem ::Dmem , fw.dmem_load_params (),true )?; + + self.hal.program_brom (self, bar, &fw.brom_params ())?; + +// Set `BootVec` to start of non-secure code. + regs::NV_PFALCON_FALCON_BOOTVEC ::default () + .set_value (fw.boot_addr ()) + .write (bar,E ::BASE ); + +Ok (()) + } + +/// Runs the loaded firmware and waits for its completion. +/// +/// `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, + bar: &Bar0 , + mbox0:Option <u32 >, + mbox1:Option <u32 >, + ) ->Result <(u32 ,u32 )> { +if let Some (mbox0) = mbox0 { + regs::NV_PFALCON_FALCON_MAILBOX0 ::default () + .set_value (mbox0) + .write (bar,E ::BASE ); + } + +if let Some (mbox1) = mbox1 { + regs::NV_PFALCON_FALCON_MAILBOX1 ::default () + .set_value (mbox1) + .write (bar,E ::BASE ); + } + +match regs::NV_PFALCON_FALCON_CPUCTL ::read (bar,E ::BASE ).alias_en () { +true => regs::NV_PFALCON_FALCON_CPUCTL_ALIAS ::default () + .set_startcpu (true ) + .write (bar,E ::BASE ), +false => regs::NV_PFALCON_FALCON_CPUCTL ::default () + .set_startcpu (true ) + .write (bar,E ::BASE ), + } + +// TIMEOUT: arbitrarily large value, firmwares should complete in less than 2 seconds. + util::wait_on (Duration ::from_secs (2 ), || { +let r = regs::NV_PFALCON_FALCON_CPUCTL ::read (bar,E ::BASE ); +if r.halted () { +Some (()) + }else { +None + } + })?; + +let (mbox0, mbox1) = ( + regs::NV_PFALCON_FALCON_MAILBOX0 ::read (bar,E ::BASE ).value (), + regs::NV_PFALCON_FALCON_MAILBOX1 ::read (bar,E ::BASE ).value (), + ); + +Ok ((mbox0, mbox1)) + } + +/// Returns the fused version of the signature to use in order to run a HS firmware on this +/// falcon instance. `engine_id_mask` and `ucode_id` are obtained from the firmware header. +pub (crate )fn signature_reg_fuse_version ( + &self, + bar: &Bar0 , + engine_id_mask:u16 , + ucode_id:u8 , + ) ->Result <u32 > { + self.hal + .signature_reg_fuse_version (self, bar, engine_id_mask, ucode_id) + } +}
drivers/gpu/nova-core/falcon/gsp.rs new file +24 -0
@@ -0,0 +1,24 @@ +// SPDX-License-Identifier: GPL-2.0 + +use crate ::{ + driver::Bar0 , + falcon::{Falcon ,FalconEngine }, + regs, +}; + +/// Type specifying the `Gsp` falcon engine. Cannot be instantiated. +pub (crate )struct Gsp (()); + +impl FalconEngine for Gsp { +const BASE :usize =0x00110000 ; +} + +impl Falcon <Gsp > { +/// Clears the SWGEN0 bit in the Falcon's IRQ status clear register to +/// allow GSP to signal CPU for processing new messages in message queue. +pub (crate )fn clear_swgen0_intr (&self, bar: &Bar0 ) { + regs::NV_PFALCON_FALCON_IRQSCLR ::default () + .set_swgen0 (true ) + .write (bar,Gsp ::BASE ); + } +}
drivers/gpu/nova-core/falcon/hal.rs new file +54 -0
54 lines not on this page · raw message
drivers/gpu/nova-core/falcon/hal/ga102.rs new file +119 -0
119 lines not on this page · raw message
drivers/gpu/nova-core/falcon/sec2.rs new file +10 -0
@@ -0,0 +1,10 @@ +// SPDX-License-Identifier: GPL-2.0 + +use crate ::falcon::FalconEngine ; + +/// Type specifying the `Sec2` falcon engine. Cannot be instantiated. +pub (crate )struct Sec2 (()); + +impl FalconEngine for Sec2 { +const BASE :usize =0x00840000 ; +}
drivers/gpu/nova-core/gpu.rs +11 -0
@@ -3,6 +3,7 @@use kernel::{device, devres::Devres , error::code::*, pci, prelude::*};use crate ::driver::Bar0 ; +use crate ::falcon::{gsp::Gsp , sec2::Sec2 ,Falcon };use crate ::fb::SysmemFlush ;use crate ::firmware::{Firmware ,FIRMWARE_VERSION };use crate ::gfw;
@@ -207,6 +208,16 @@ pub(crate) fn new(// System memory page required for sysmembar to properly flush into system memory. let sysmem_flush =SysmemFlush ::register (pdev.as_ref (), bar, spec.chipset)?; +let gsp_falcon =Falcon ::<Gsp >::new ( + pdev.as_ref (), + spec.chipset, + bar, + spec.chipset >Chipset ::GA100 , + )?; + gsp_falcon.clear_swgen0_intr (bar); + +let _sec2_falcon =Falcon ::<Sec2 >::new (pdev.as_ref (), spec.chipset, bar,true )?; + Ok(pin_init!(Self { spec, bar: devres_bar,
drivers/gpu/nova-core/nova_core.rs +1 -0
@@ -4,6 +4,7 @@mod dma;mod driver; +mod falcon;mod fb;mod firmware;mod gfw;
drivers/gpu/nova-core/regs.rs +146 -0
155 lines not on this page · raw message
Signature · 1 line
2.49.0
Alexandre Courbot
maintainerPATCH v6 16/24 gpu: nova-core: firmware: add ucode descriptor used by FWSEC-FRTS
In reply to Alexandre CourbotFWSEC-FRTS is the first firmware we need to run on the GSP falcon in order to initiate the GSP boot process. Introduce the structure that describes it.
--- drivers/gpu/nova-core/firmware.rs | 45 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+)
drivers/gpu/nova-core/firmware.rs +45 -0
@@ -41,6 +41,51 @@ pub(crate) fn new(dev: &device::Device, chipset: Chipset, ver: &str) -> Result<F } } +/// Structure used to describe some firmwares, notably FWSEC-FRTS. +#[repr( C )] +#[derive( Debug , Clone )] +pub (crate )struct FalconUCodeDescV3 { +/// Header defined by `NV_BIT_FALCON_UCODE_DESC_HEADER_VDESC*` in OpenRM. + hdr:u32 , +/// Stored size of the ucode after the header. + stored_size:u32 , +/// Offset in `DMEM` at which the signature is expected to be found. +pub (crate ) pkc_data_offset:u32 , +/// Offset after the code segment at which the app headers are located. +pub (crate ) interface_offset:u32 , +/// Base address at which to load the code segment into `IMEM`. +pub (crate ) imem_phys_base:u32 , +/// Size in bytes of the code to copy into `IMEM`. +pub (crate ) imem_load_size:u32 , +/// Virtual `IMEM` address (i.e. `tag`) at which the code should start. +pub (crate ) imem_virt_base:u32 , +/// Base address at which to load the data segment into `DMEM`. +pub (crate ) dmem_phys_base:u32 , +/// Size in bytes of the data to copy into `DMEM`. +pub (crate ) dmem_load_size:u32 , +/// Mask of the falcon engines on which this firmware can run. +pub (crate ) engine_id_mask:u16 , +/// ID of the ucode used to infer a fuse register to validate the signature. +pub (crate ) ucode_id:u8 , +/// Number of signatures in this firmware. +pub (crate ) signature_count:u8 , +/// Versions of the signatures, used to infer a valid signature to use. +pub (crate ) signature_versions:u16 , + _reserved:u16 , +} + +// To be removed once that code is used. +#[expect(dead_code)] +impl FalconUCodeDescV3 { +/// Returns the size in bytes of the header. +pub (crate )fn size (&self) ->usize { +const HDR_SIZE_SHIFT :u32 =16 ; +const HDR_SIZE_MASK :u32 =0xffff0000 ; + + ((self.hdr &HDR_SIZE_MASK ) >>HDR_SIZE_SHIFT )as usize + } +} +pub (crate )struct ModInfoBuilder <const N :usize >(firmware::ModInfoBuilder <N >);impl <const N :usize >ModInfoBuilder <N > {
Signature · 1 line
2.49.0
Alexandre Courbot
maintainerPATCH v6 17/24 gpu: nova-core: vbios: Add base support for VBIOS construction and iteration
In reply to Alexandre CourbotFrom: Joel Fernandes <[email protected]>
Add support for navigating the VBIOS images required for extracting ucode data for GSP to boot. Later patches will build on this.
Debug log messages will show the BIOS images:
[102141.013287] NovaCore: Found BIOS image at offset 0x0, size: 0xfe00, type: PciAt [102141.080692] NovaCore: Found BIOS image at offset 0xfe00, size: 0x14800, type: Efi [102141.098443] NovaCore: Found BIOS image at offset 0x24600, size: 0x5600, type: FwSec [102141.415095] NovaCore: Found BIOS image at offset 0x29c00, size: 0x60800, type: FwSec
[applied feedback from Alex Courbot and Timur Tabi]
[applied changes related to code reorg, prints etc from Danilo Krummrich] [[email protected]: fix clippy warnings, read_more() function]
--- drivers/gpu/nova-core/firmware.rs | 4 +- drivers/gpu/nova-core/gpu.rs | 4 + drivers/gpu/nova-core/nova_core.rs | 1 + drivers/gpu/nova-core/vbios.rs | 681 +++++++++++++++++++++++++++++++++++++ 4 files changed, 688 insertions(+), 2 deletions(-)
drivers/gpu/nova-core/firmware.rs +2 -2
@@ -44,6 +44,7 @@ pub(crate) fn new(dev: &device::Device, chipset: Chipset, ver: &str) -> Result<F/// Structure used to describe some firmwares, notably FWSEC-FRTS. #[repr( C )] #[derive( Debug , Clone )] +#[allow(dead_code)] // Temporary, will be removed in later patch. pub (crate )struct FalconUCodeDescV3 {/// Header defined by `NV_BIT_FALCON_UCODE_DESC_HEADER_VDESC*` in OpenRM. hdr:u32 ,
@@ -74,10 +75,9 @@ pub(crate) struct FalconUCodeDescV3 { _reserved: u16, } -// To be removed once that code is used. -#[expect(dead_code)] impl FalconUCodeDescV3 {/// Returns the size in bytes of the header. +#[expect(dead_code)] // Temporary, will be removed in later patch. pub (crate )fn size (&self) ->usize {const HDR_SIZE_SHIFT :u32 =16 ;const HDR_SIZE_MASK :u32 =0xffff0000 ;
drivers/gpu/nova-core/gpu.rs +4 -0
@@ -9,6 +9,7 @@use crate ::gfw;use crate ::regs;use crate ::util; +use crate ::vbios::Vbios ;use core::fmt;macro_rules! define_chipset {
@@ -218,6 +219,9 @@ pub(crate) fn new(let _sec2_falcon =Falcon ::<Sec2 >::new (pdev.as_ref (), spec.chipset, bar,true )?; +// Will be used in a later patch when fwsec firmware is needed. +let _bios =Vbios ::new (pdev, bar)?; + Ok(pin_init!(Self { spec, bar: devres_bar,
drivers/gpu/nova-core/nova_core.rs +1 -0
@@ -11,6 +11,7 @@mod gpu;mod regs;mod util; +mod vbios;pub (crate )const MODULE_NAME : &kernel::str::CStr = <LocalModule as kernel::ModuleMetadata >::NAME ;
drivers/gpu/nova-core/vbios.rs new file +681 -0
681 lines not on this page · raw message
Signature · 1 line
2.49.0
Alexandre Courbot
maintainerPATCH v6 18/24 gpu: nova-core: vbios: Add support to look up PMU table in FWSEC
In reply to Alexandre CourbotFrom: Joel Fernandes <[email protected]>
The PMU table in the FWSEC image has to be located to locate the start of the Falcon ucode in the same or another FWSEC image. Add support for the same.
--- drivers/gpu/nova-core/vbios.rs | 179 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 177 insertions(+), 2 deletions(-)
drivers/gpu/nova-core/vbios.rs +177 -2
@@ -330,6 +330,111 @@ fn image_size_bytes(&self) -> usize { } } +/// BIOS Information Table (BIT) Header +/// This is the head of the BIT table, that is used to locate the Falcon data. +/// The BIT table (with its header) is in the PciAtBiosImage and the falcon data +/// it is pointing to is in the FwSecBiosImage. +#[derive( Debug , Clone , Copy )] +#[expect(dead_code)] +struct BitHeader { +/// 0h: BIT Header Identifier (BMP=0x7FFF/BIT=0xB8FF) + id:u16 , +/// 2h: BIT Header Signature ("BIT\0") + signature: [u8 ;4 ], +/// 6h: Binary Coded Decimal Version, ex: 0x0100 is 1.00. + bcd_version:u16 , +/// 8h: Size of BIT Header (in bytes) + header_size:u8 , +/// 9h: Size of BIT Tokens (in bytes) + token_size:u8 , +/// 10h: Number of token entries that follow + token_entries:u8 , +/// 11h: BIT Header Checksum + checksum:u8 , +} + +impl BitHeader { +fn new (data: &[u8 ]) ->Result <Self > { +if data.len () <12 { +return Err (EINVAL ); + } + +let mut signature = [0u8 ;4 ]; + signature.copy_from_slice (&data[2 ..6 ]); + +// Check header ID and signature +let id = u16::from_le_bytes ([data[0 ], data[1 ]]); +if id !=0xB8FF || &signature !=b"BIT\0" { +return Err (EINVAL ); + } + +Ok (BitHeader { + id, + signature, + bcd_version: u16::from_le_bytes ([data[6 ], data[7 ]]), + header_size: data[8 ], + token_size: data[9 ], + token_entries: data[10 ], + checksum: data[11 ], + }) + } +} + +/// BIT Token Entry: Records in the BIT table followed by the BIT header +#[derive( Debug , Clone , Copy )] +#[expect(dead_code)] +struct BitToken { +/// 00h: Token identifier + id:u8 , +/// 01h: Version of the token data + data_version:u8 , +/// 02h: Size of token data in bytes + data_size:u16 , +/// 04h: Offset to the token data + data_offset:u16 , +} + +// Define the token ID for the Falcon data +const BIT_TOKEN_ID_FALCON_DATA :u8 =0x70 ; + +impl BitToken { +/// Find a BIT token entry by BIT ID in a PciAtBiosImage +fn from_id (image: &PciAtBiosImage , token_id:u8 ) ->Result <Self > { +let header = &image.bit_header; + +// Offset to the first token entry +let tokens_start = image.bit_offset + header.header_sizeas usize ; + +for iin 0 ..header.token_entriesas usize { +let entry_offset = tokens_start + (i * header.token_sizeas usize ); + +// Make sure we don't go out of bounds +if entry_offset + header.token_sizeas usize > image.base.data.len () { +return Err (EINVAL ); + } + +// Check if this token has the requested ID +if image.base.data[entry_offset] == token_id { +return Ok (BitToken { + id: image.base.data[entry_offset], + data_version: image.base.data[entry_offset +1 ], + data_size: u16::from_le_bytes ([ + image.base.data[entry_offset +2 ], + image.base.data[entry_offset +3 ], + ]), + data_offset: u16::from_le_bytes ([ + image.base.data[entry_offset +4 ], + image.base.data[entry_offset +5 ], + ]), + }); + } + } + +// Token not found +Err (ENOENT ) + } +} +/// PCI ROM Expansion Header as defined in PCI Firmware Specification. /// This is header is at the beginning of every image in the set of /// images in the ROM. It contains a pointer to the PCI Data Structure
@@ -575,7 +680,8 @@ fn new(pdev: &pci::Device, data: &[u8]) -> Result<Self> {struct PciAtBiosImage { base:BiosImageBase , -// PCI-AT-specific fields can be added here in the future. + bit_header:BitHeader , + bit_offset:usize , }struct EfiBiosImage {
@@ -599,7 +705,7 @@ impl TryFrom<BiosImageBase> for BiosImage {fn try_from (base:BiosImageBase ) ->Result <Self > {match base.pcir.code_type { -0x00 =>Ok (BiosImage ::PciAt (PciAtBiosImage { base })), +0x00 =>Ok (BiosImage ::PciAt (base.try_into ()?)),0x03 =>Ok (BiosImage ::Efi (EfiBiosImage { base })),0x70 =>Ok (BiosImage ::Nbsi (NbsiBiosImage { base })),0xE0 =>Ok (BiosImage ::FwSec (FwSecBiosImage { base })),
@@ -679,3 +785,72 @@ fn new(pdev: &pci::Device, data: &[u8]) -> Result<Self> { }) } } + +/// The PciAt BIOS image is typically the first BIOS image type found in the +/// BIOS image chain. It contains the BIT header and the BIT tokens. +impl PciAtBiosImage { +/// Find a byte pattern in a slice +fn find_byte_pattern (haystack: &[u8 ], needle: &[u8 ]) ->Result <usize > { + haystack + .windows (needle.len ()) + .position (|window| window == needle) + .ok_or (EINVAL ) + } + +/// Find the BIT header in the PciAtBiosImage +fn find_bit_header (data: &[u8 ]) ->Result <(BitHeader ,usize )> { +let bit_pattern = [0xff ,0xb8 ,b'B' ,b'I' ,b'T' ,0x00 ]; +let bit_offset =Self ::find_byte_pattern (data, &bit_pattern)?; +let bit_header =BitHeader ::new (&data[bit_offset..])?; + +Ok ((bit_header, bit_offset)) + } + +/// Get a BIT token entry from the BIT table in the PciAtBiosImage +fn get_bit_token (&self, token_id:u8 ) ->Result <BitToken > { +BitToken ::from_id (self, token_id) + } + +/// Find the Falcon data pointer structure in the PciAtBiosImage +/// This is just a 4 byte structure that contains a pointer to the +/// Falcon data in the FWSEC image. +fn falcon_data_ptr (&self, pdev: &pci::Device ) ->Result <u32 > { +let token = self.get_bit_token (BIT_TOKEN_ID_FALCON_DATA )?; + +// Make sure we don't go out of bounds +if token.data_offsetas usize +4 > self.base.data.len () { +return Err (EINVAL ); + } + +// read the 4 bytes at the offset specified in the token +let offset = token.data_offsetas usize ; +let bytes: [u8 ;4 ] = self.base.data[offset..offset +4 ].try_into ().map_err (|_| { +dev_err! (pdev.as_ref (),"Failed to convert data slice to array" ); +EINVAL + })?; + +let data_ptr = u32::from_le_bytes (bytes); + +if (data_ptras usize ) < self.base.data.len () { +dev_err! (pdev.as_ref (),"Falcon data pointer out of bounds\n" ); +return Err (EINVAL ); + } + +Ok (data_ptr) + } +} + +impl TryFrom <BiosImageBase >for PciAtBiosImage { +type Error =Error ; + +fn try_from (base:BiosImageBase ) ->Result <Self > { +let data_slice = &base.data; +let (bit_header, bit_offset) =PciAtBiosImage ::find_bit_header (data_slice)?; + +Ok (PciAtBiosImage { + base, + bit_header, + bit_offset, + }) + } +}
Signature · 1 line
2.49.0
Alexandre Courbot
maintainerPATCH v6 19/24 gpu: nova-core: vbios: Add support for FWSEC ucode extraction
In reply to Alexandre CourbotFrom: Joel Fernandes <[email protected]>
Using the support for navigating the VBIOS, add support to extract vBIOS ucode data required for GSP to boot. The main data extracted from the vBIOS is the FWSEC-FRTS firmware which runs on the GSP processor. This firmware runs in high secure mode, and sets up the WPR2 (Write protected region) before the Booter runs on the SEC2 processor.
Tested on my Ampere GA102 and boot is successful.
[applied changes by Alex Courbot for fwsec signatures] [[email protected]: remove now-unneeded Devres acquisition]
--- drivers/gpu/nova-core/firmware.rs | 2 - drivers/gpu/nova-core/vbios.rs | 307 ++++++++++++++++++++++++++++++++++++-- 2 files changed, 298 insertions(+), 11 deletions(-)
drivers/gpu/nova-core/firmware.rs +0 -2
@@ -44,7 +44,6 @@ pub(crate) fn new(dev: &device::Device, chipset: Chipset, ver: &str) -> Result<F/// Structure used to describe some firmwares, notably FWSEC-FRTS. #[repr( C )] #[derive( Debug , Clone )] -#[allow(dead_code)] // Temporary, will be removed in later patch. pub (crate )struct FalconUCodeDescV3 {/// Header defined by `NV_BIT_FALCON_UCODE_DESC_HEADER_VDESC*` in OpenRM. hdr:u32 ,
@@ -77,7 +76,6 @@ pub(crate) struct FalconUCodeDescV3 {impl FalconUCodeDescV3 {/// Returns the size in bytes of the header. -#[expect(dead_code)] // Temporary, will be removed in later patch. pub (crate )fn size (&self) ->usize {const HDR_SIZE_SHIFT :u32 =16 ;const HDR_SIZE_MASK :u32 =0xffff0000 ;
drivers/gpu/nova-core/vbios.rs +298 -9
357 lines not on this page · raw message
Signature · 1 line
2.49.0
Alexandre Courbot
maintainerPATCH v6 20/24 gpu: nova-core: compute layout of the FRTS region
In reply to Alexandre CourbotFWSEC-FRTS is run with the desired address of the FRTS region as parameter, which we need to compute depending on some hardware parameters.
Do this in a FbLayout structure, that will be later extended to describe more memory regions used to boot the GSP.
--- drivers/gpu/nova-core/fb.rs | 70 ++++++++++++++++++++++++++++++++ drivers/gpu/nova-core/fb/hal.rs | 12 +++++- drivers/gpu/nova-core/fb/hal/ga100.rs | 12 ++++++ drivers/gpu/nova-core/fb/hal/ga102.rs | 36 +++++++++++++++++ drivers/gpu/nova-core/fb/hal/tu102.rs | 16 ++++++++ drivers/gpu/nova-core/gpu.rs | 4 ++ drivers/gpu/nova-core/regs.rs | 76 +++++++++++++++++++++++++++++++++++ 7 files changed, 224 insertions(+), 2 deletions(-)
drivers/gpu/nova-core/fb.rs +70 -0
@@ -1,12 +1,16 @@// SPDX-License-Identifier: GPL-2.0 +use core::ops::Range ; +use kernel::prelude::*; +use kernel::sizes::*;use kernel::types::ARef ;use kernel::{dev_warn, device};use crate ::dma::DmaObject ;use crate ::driver::Bar0 ;use crate ::gpu::Chipset ; +use crate ::regs;mod hal;
@@ -64,3 +68,69 @@ pub(crate) fn unregister(self, bar: &Bar0) { } } } + +/// Layout of the GPU framebuffer memory. +/// +/// Contains ranges of GPU memory reserved for a given purpose during the GSP bootup process. +#[derive( Debug )] +#[expect(dead_code)] +pub (crate )struct FbLayout { +pub (crate ) fb:Range <u64 >, +pub (crate ) vga_workspace:Range <u64 >, +pub (crate ) frts:Range <u64 >, +} + +impl FbLayout { +/// Computes the FB layout. +pub (crate )fn new (chipset:Chipset , bar: &Bar0 ) ->Result <Self > { +let hal = hal::fb_hal (chipset); + +let fb = { +let fb_size = hal.vidmem_size (bar); + +0 ..fb_size + }; + +let vga_workspace = { +let vga_base = { +const NV_PRAMIN_SIZE :u64 =SZ_1M as u64 ; +let base = fb.end -NV_PRAMIN_SIZE ; + +if hal.supports_display (bar) { +match regs::NV_PDISP_VGA_WORKSPACE_BASE ::read (bar).vga_workspace_addr () { +Some (addr) => { +if addr < base { +const VBIOS_WORKSPACE_SIZE :u64 =SZ_128K as u64 ; + +// Point workspace address to end of framebuffer. + fb.end -VBIOS_WORKSPACE_SIZE + }else { + addr + } + } +None => base, + } + }else { + base + } + }; + + vga_base..fb.end + }; + +let frts = { +const FRTS_DOWN_ALIGN :u64 =SZ_128K as u64 ; +const FRTS_SIZE :u64 =SZ_1M as u64 ; +// TODO: replace with `align_down` once it lands. +let frts_base = (vga_workspace.start & !(FRTS_DOWN_ALIGN -1 )) -FRTS_SIZE ; + + frts_base..frts_base +FRTS_SIZE + }; + +Ok (Self { + fb, + vga_workspace, + frts, + }) + } +}
drivers/gpu/nova-core/fb/hal.rs +10 -2
@@ -6,6 +6,7 @@use crate ::gpu::Chipset ;mod ga100; +mod ga102;mod tu102;pub (crate )trait FbHal {
@@ -16,6 +17,12 @@ pub(crate) trait FbHal {/// /// This might fail if the address is too large for the receiving register. fn write_sysmem_flush_page (&self, bar: &Bar0 , addr:u64 ) ->Result ; + +/// Returns `true` is display is supported. +fn supports_display (&self, bar: &Bar0 ) ->bool ; + +/// Returns the VRAM size, in bytes. +fn vidmem_size (&self, bar: &Bar0 ) ->u64 ; }/// Returns the HAL corresponding to `chipset`.
@@ -24,8 +31,9 @@ pub(super) fn fb_hal(chipset: Chipset) -> &'static dyn FbHal {match chipset {TU102 |TU104 |TU106 |TU117 |TU116 => tu102::TU102_HAL , -GA100 |GA102 |GA103 |GA104 |GA106 |GA107 |AD102 |AD103 |AD104 |AD106 |AD107 => { - ga100::GA100_HAL +GA100 => ga100::GA100_HAL , +GA102 |GA103 |GA104 |GA106 |GA107 |AD102 |AD103 |AD104 |AD106 |AD107 => { + ga102::GA102_HAL } } }
drivers/gpu/nova-core/fb/hal/ga100.rs +12 -0
@@ -25,6 +25,10 @@ pub(super) fn write_sysmem_flush_page_ga100(bar: &Bar0, addr: u64) { .write(bar); } +pub (super )fn display_enabled_ga100 (bar: &Bar0 ) ->bool { + !regs::ga100::NV_FUSE_STATUS_OPT_DISPLAY ::read (bar).display_disabled () +} +/// Shift applied to the sysmem address before it is written into /// `NV_PFB_NISO_FLUSH_SYSMEM_ADDR_HI`, const FLUSH_SYSMEM_ADDR_SHIFT_HI :u32 =40 ;
@@ -39,6 +43,14 @@ fn write_sysmem_flush_page(&self, bar: &Bar0, addr: u64) -> Result {Ok (()) } + +fn supports_display (&self, bar: &Bar0 ) ->bool { +display_enabled_ga100 (bar) + } + +fn vidmem_size (&self, bar: &Bar0 ) ->u64 { +super ::tu102::vidmem_size_gp102 (bar) + } }const GA100 :Ga100 =Ga100 ;
drivers/gpu/nova-core/fb/hal/ga102.rs new file +36 -0
@@ -0,0 +1,36 @@ +// SPDX-License-Identifier: GPL-2.0 + +use kernel::prelude::*; + +use crate ::driver::Bar0 ; +use crate ::fb::hal::FbHal ; +use crate ::regs; + +fn vidmem_size_ga102 (bar: &Bar0 ) ->u64 { + regs::NV_USABLE_FB_SIZE_IN_MB ::read (bar).usable_fb_size () +} + +struct Ga102 ; + +impl FbHal for Ga102 { +fn read_sysmem_flush_page (&self, bar: &Bar0 ) ->u64 { +super ::ga100::read_sysmem_flush_page_ga100 (bar) + } + +fn write_sysmem_flush_page (&self, bar: &Bar0 , addr:u64 ) ->Result { +super ::ga100::write_sysmem_flush_page_ga100 (bar, addr); + +Ok (()) + } + +fn supports_display (&self, bar: &Bar0 ) ->bool { +super ::ga100::display_enabled_ga100 (bar) + } + +fn vidmem_size (&self, bar: &Bar0 ) ->u64 { +vidmem_size_ga102 (bar) + } +} + +const GA102 :Ga102 =Ga102 ; +pub (super )const GA102_HAL : &dyn FbHal = &GA102 ;
drivers/gpu/nova-core/fb/hal/tu102.rs +16 -0
@@ -26,6 +26,14 @@ pub(super) fn write_sysmem_flush_page_gm107(bar: &Bar0, addr: u64) -> Result { } } +pub (super )fn display_enabled_gm107 (bar: &Bar0 ) ->bool { + !regs::gm107::NV_FUSE_STATUS_OPT_DISPLAY ::read (bar).display_disabled () +} + +pub (super )fn vidmem_size_gp102 (bar: &Bar0 ) ->u64 { + regs::NV_PFB_PRI_MMU_LOCAL_MEMORY_RANGE ::read (bar).usable_fb_size () +} +struct Tu102 ;impl FbHal for Tu102 {
@@ -36,6 +44,14 @@ fn read_sysmem_flush_page(&self, bar: &Bar0) -> u64 {fn write_sysmem_flush_page (&self, bar: &Bar0 , addr:u64 ) ->Result {write_sysmem_flush_page_gm107 (bar, addr) } + +fn supports_display (&self, bar: &Bar0 ) ->bool { +display_enabled_gm107 (bar) + } + +fn vidmem_size (&self, bar: &Bar0 ) ->u64 { +vidmem_size_gp102 (bar) + } }const TU102 :Tu102 =Tu102 ;
drivers/gpu/nova-core/gpu.rs +4 -0
@@ -4,6 +4,7 @@use crate ::driver::Bar0 ;use crate ::falcon::{gsp::Gsp , sec2::Sec2 ,Falcon }; +use crate ::fb::FbLayout ;use crate ::fb::SysmemFlush ;use crate ::firmware::{Firmware ,FIRMWARE_VERSION };use crate ::gfw;
@@ -219,6 +220,9 @@ pub(crate) fn new(let _sec2_falcon =Falcon ::<Sec2 >::new (pdev.as_ref (), spec.chipset, bar,true )?; +let fb_layout =FbLayout ::new (spec.chipset, bar)?; +dev_dbg! (pdev.as_ref (),"{:#x?}\n" , fb_layout); +// Will be used in a later patch when fwsec firmware is needed. let _bios =Vbios ::new (pdev, bar)?;
drivers/gpu/nova-core/regs.rs +76 -0
91 lines not on this page · raw message
Signature · 1 line
2.49.0
Alexandre Courbot
maintainerPATCH v6 21/24 gpu: nova-core: add types for patching firmware binaries
In reply to Alexandre CourbotSome of the firmwares need to be patched at load-time with a signature. Add a couple of types and traits that sub-modules can use to implement this behavior, while ensuring that the correct kind of signature is applied to the firmware.
--- drivers/gpu/nova-core/firmware.rs | 64 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+)
drivers/gpu/nova-core/firmware.rs +64 -0
@@ -3,11 +3,15 @@//! Contains structures and functions dedicated to the parsing, building and patching of firmwares //! to be loaded into a given execution unit. +use core::marker::PhantomData ; +use kernel::device;use kernel::firmware;use kernel::prelude::*;use kernel::str::CString ; +use crate ::dma::DmaObject ; +use crate ::falcon::FalconFirmware ;use crate ::gpu;use crate ::gpu::Chipset ;
@@ -84,6 +88,66 @@ pub(crate) fn size(&self) -> usize { } } +/// Trait implemented by types defining the signed state of a firmware. +trait SignedState {} + +/// Type indicating that the firmware must be signed before it can be used. +struct Unsigned ; +impl SignedState for Unsigned {} + +/// Type indicating that the firmware is signed and ready to be loaded. +struct Signed ; +impl SignedState for Signed {} + +/// A [`DmaObject`] containing a specific microcode ready to be loaded into a falcon. +/// +/// This is module-local and meant for sub-modules to use internally. +/// +/// After construction, a firmware is [`Unsigned`], and must generally be patched with a signature +/// before it can be loaded (with an exception for development hardware). The +/// [`Self::patch_signature`] and [`Self::no_patch_signature`] methods are used to transition the +/// firmware to its [`Signed`] state. +struct FirmwareDmaObject <F :FalconFirmware ,S :SignedState >(DmaObject ,PhantomData <(F ,S )>); + +/// Trait for signatures to be patched directly into a given firmware. +/// +/// This is module-local and meant for sub-modules to use internally. +trait FirmwareSignature <F :FalconFirmware >:AsRef <[u8 ]> {} + +#[expect(unused)] +impl <F :FalconFirmware >FirmwareDmaObject <F ,Unsigned > { +/// Patches the firmware at offset `sig_base_img` with `signature`. +fn patch_signature <S :FirmwareSignature <F >>( +mut self, + signature: &S , + sig_base_img:usize , + ) ->Result <FirmwareDmaObject <F ,Signed >> { +let signature_bytes = signature.as_ref (); +if sig_base_img + signature_bytes.len () > self.0 .size () { +return Err (EINVAL ); + } + +// SAFETY: we are the only user of this object, so there cannot be any race. +let dst =unsafe { self.0 .start_ptr_mut ().add (sig_base_img) }; + +// SAFETY: `signature` and `dst` are valid, properly aligned, and do not overlap. +unsafe { + core::ptr::copy_nonoverlapping (signature_bytes.as_ptr (), dst, signature_bytes.len ()) + }; + +Ok (FirmwareDmaObject (self.0 ,PhantomData )) + } + +/// Mark the firmware as signed without patching it. +/// +/// This method is used to explicitly confirm that we do not need to sign the firmware, while +/// allowing us to continue as if it was. This is typically only needed for development +/// hardware. +fn no_patch_signature (self) ->FirmwareDmaObject <F ,Signed > { +FirmwareDmaObject (self.0 ,PhantomData ) + } +} +pub (crate )struct ModInfoBuilder <const N :usize >(firmware::ModInfoBuilder <N >);impl <const N :usize >ModInfoBuilder <N > {
Signature · 1 line
2.49.0
Alexandre Courbot
maintainerPATCH v6 22/24 gpu: nova-core: extract FWSEC from BIOS and patch it to run FWSEC-FRTS
In reply to Alexandre CourbotThe FWSEC firmware needs to be extracted from the VBIOS and patched with the desired command, as well as the right signature. Do this so we are ready to load and run this firmware into the GSP falcon and create the FRTS region.
[[email protected]: give better names to FalconAppifHdrV1's fields]
--- drivers/gpu/nova-core/dma.rs | 3 - drivers/gpu/nova-core/firmware.rs | 3 +- drivers/gpu/nova-core/firmware/fwsec.rs | 398 ++++++++++++++++++++++++++++++++ drivers/gpu/nova-core/gpu.rs | 15 +- drivers/gpu/nova-core/vbios.rs | 30 ++- 5 files changed, 434 insertions(+), 15 deletions(-)
drivers/gpu/nova-core/dma.rs +0 -3
@@ -2,9 +2,6 @@//! Simple DMA object wrapper. -// To be removed when all code is used. -#![expect(dead_code)] -use core::ops::{Deref ,DerefMut };use kernel::device;
drivers/gpu/nova-core/firmware.rs +2 -1
@@ -15,6 +15,8 @@use crate ::gpu;use crate ::gpu::Chipset ; +pub (crate )mod fwsec; +pub (crate )const FIRMWARE_VERSION : &str ="535.113.01" ;/// Structure encapsulating the firmware blobs required for the GPU to operate.
@@ -114,7 +116,6 @@ impl SignedState for Signed {}/// This is module-local and meant for sub-modules to use internally. trait FirmwareSignature <F :FalconFirmware >:AsRef <[u8 ]> {} -#[expect(unused)] impl <F :FalconFirmware >FirmwareDmaObject <F ,Unsigned > {/// Patches the firmware at offset `sig_base_img` with `signature`. fn patch_signature<S: FirmwareSignature<F>>(
drivers/gpu/nova-core/firmware/fwsec.rs new file +398 -0
398 lines not on this page · raw message
drivers/gpu/nova-core/gpu.rs +13 -2
@@ -6,6 +6,7 @@use crate ::falcon::{gsp::Gsp , sec2::Sec2 ,Falcon };use crate ::fb::FbLayout ;use crate ::fb::SysmemFlush ; +use crate ::firmware::fwsec::{FwsecCommand ,FwsecFirmware };use crate ::firmware::{Firmware ,FIRMWARE_VERSION };use crate ::gfw;use crate ::regs;
@@ -223,8 +224,18 @@ pub(crate) fn new(let fb_layout =FbLayout ::new (spec.chipset, bar)?;dev_dbg! (pdev.as_ref (),"{:#x?}\n" , fb_layout); -// Will be used in a later patch when fwsec firmware is needed. -let _bios =Vbios ::new (pdev, bar)?; +let bios =Vbios ::new (pdev, bar)?; + +let _fwsec_frts =FwsecFirmware ::new ( + pdev.as_ref (), + &gsp_falcon, + bar, + &bios, +FwsecCommand ::Frts { + frts_addr: fb_layout.frts.start, + frts_size: fb_layout.frts.end - fb_layout.frts.start, + }, + )?; Ok(pin_init!(Self { spec,
drivers/gpu/nova-core/vbios.rs +21 -9
@@ -2,10 +2,8 @@//! VBIOS extraction and parsing. -// To be removed when all code is used. -#![expect(dead_code)] -use crate ::driver::Bar0 ; +use crate ::firmware::fwsec::Bcrt30Rsa3kSignature ;use crate ::firmware::FalconUCodeDescV3 ;use core::convert::TryFrom ;use kernel::device;
@@ -1124,15 +1122,18 @@ pub(crate) fn ucode(&self, dev: &device::Device, desc: &FalconUCodeDescV3) -> Re }/// Get the signatures as a byte slice -pub (crate )fn sigs (&self, dev: &device::Device , desc: &FalconUCodeDescV3 ) ->Result <&[u8 ]> { -const SIG_SIZE :usize =96 *4 ; - +pub (crate )fn sigs ( + &self, + dev: &device::Device , + desc: &FalconUCodeDescV3 , + ) ->Result <&[Bcrt30Rsa3kSignature ]> {// The signatures data follows the descriptor let sigs_data_offset = self.falcon_ucode_offset + core::mem::size_of ::<FalconUCodeDescV3 >(); -let size = desc.signature_countas usize *SIG_SIZE ; +let sigs_size = + desc.signature_countas usize * core::mem::size_of ::<Bcrt30Rsa3kSignature >();// Make sure the data is within bounds -if sigs_data_offset + size > self.base.data.len () { +if sigs_data_offset + sigs_size > self.base.data.len () {dev_err! ( dev,"fwsec signatures data not contained within BIOS bounds\n"
@@ -1140,6 +1141,17 @@ pub(crate) fn sigs(&self, dev: &device::Device, desc: &FalconUCodeDescV3) -> Resreturn Err (ERANGE ); } -Ok (&self.base.data[sigs_data_offset..sigs_data_offset + size]) +// SAFETY: we checked that `data + sigs_data_offset + (signature_count * +// sizeof::<Bcrt30Rsa3kSignature>()` is within the bounds of `data`. +Ok (unsafe { + core::slice::from_raw_parts ( + self.base + .data + .as_ptr () + .add (sigs_data_offset) + .cast ::<Bcrt30Rsa3kSignature >(), + desc.signature_countas usize , + ) + }) } }
Signature · 1 line
2.49.0
Alexandre Courbot
maintainerPATCH v6 23/24 gpu: nova-core: load and run FWSEC-FRTS
In reply to Alexandre CourbotWith all the required pieces in place, load FWSEC-FRTS onto the GSP falcon, run it, and check that it successfully carved out the WPR2 region out of framebuffer memory.
--- drivers/gpu/nova-core/falcon.rs | 3 -- drivers/gpu/nova-core/firmware/fwsec.rs | 25 +++++++++ drivers/gpu/nova-core/gpu.rs | 90 +++++++++++++++++++++++++++++---- drivers/gpu/nova-core/regs.rs | 31 ++++++++++++ 4 files changed, 136 insertions(+), 13 deletions(-)
drivers/gpu/nova-core/falcon.rs +0 -3
@@ -2,9 +2,6 @@//! Falcon microprocessor base support -// To be removed when all code is used. -#![expect(dead_code)] -use core::ops::Deref ;use core::time::Duration ;use hal::FalconHal ;
drivers/gpu/nova-core/firmware/fwsec.rs +25 -0
@@ -395,4 +395,29 @@ pub(crate) fn new( ucode: ucode_signed, }) } + +/// Loads the FWSEC firmware into `falcon` and execute it. +pub (crate )fn run ( + &self, + dev: &Device <device::Bound >, + falcon: &Falcon <Gsp >, + bar: &Bar0 , + ) ->Result <()> { +// Reset falcon, load the firmware, and run it. + falcon + .reset (bar) + .inspect_err (|e|dev_err! (dev,"Failed to reset GSP falcon: {:?}\n" , e))?; + falcon + .dma_load (bar, self) + .inspect_err (|e|dev_err! (dev,"Failed to load FWSEC firmware: {:?}\n" , e))?; +let (mbox0, _) = falcon + .boot (bar,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); +Err (EIO ) + }else { +Ok (()) + } + } }
drivers/gpu/nova-core/gpu.rs +80 -10
102 lines not on this page · raw message
drivers/gpu/nova-core/regs.rs +31 -0
@@ -42,6 +42,13 @@ pub(crate) fn chipset(self) -> Result<Chipset> { } } +/* PBUS */ + +// TODO: this is an array of registers. +register! (NV_PBUS_SW_SCRATCH_0E @0x00001438 { +31 :16 frts_err_codeas u16 ; +}); +/* PFB */ register! (NV_PFB_NISO_FLUSH_SYSMEM_ADDR @0x00100c10 {
@@ -73,6 +80,30 @@ pub(crate) fn usable_fb_size(self) -> u64 { } } +register! (NV_PFB_PRI_MMU_WPR2_ADDR_LO @0x001fa824 { +31 :4 lo_valas u32 ,"Bits 12..40 of the lower (inclusive) bound of the WPR2 region" ; +}); + +impl NV_PFB_PRI_MMU_WPR2_ADDR_LO { +/// Returns the lower (inclusive) bound of the WPR2 region. +pub (crate )fn lower_bound (self) ->u64 { + (self.lo_val ()as u64 ) <<12 + } +} + +register! (NV_PFB_PRI_MMU_WPR2_ADDR_HI @0x001fa828 { +31 :4 hi_valas u32 ,"Bits 12..40 of the higher (exclusive) bound of the WPR2 region" ; +}); + +impl NV_PFB_PRI_MMU_WPR2_ADDR_HI { +/// Returns the higher (exclusive) bound of the WPR2 region. +/// +/// A value of zero means the WPR2 region is not set. +pub (crate )fn higher_bound (self) ->u64 { + (self.hi_val ()as u64 ) <<12 + } +} +/* PGC6 */ register! (NV_PGC6_AON_SECURE_SCRATCH_GROUP_05_PRIV_LEVEL_MASK @0x00118128 {
Signature · 1 line
2.49.0
Alexandre Courbot
maintainerPATCH v6 24/24 gpu: nova-core: update and annotate TODO list
In reply to Alexandre CourbotA few new dependencies are required to remove some of the TODO items:
- A way to safely convert from byte slices to types implementing FromBytes,
- A way to obtain slices and write into a CoherentAllocation,
- Several improvements to the register!() macro,
- Alignment operations to powers of two, and an equivalent to the C fls,
- Support for xa_alloc in the XAlloc bindings.
Some items have also become obsolete:
- The auxiliary bus abstractions have been implemented and are in use,
- The ELF utilities are not considered for being part of the core kernel bindings anymore.
- VBIOS, falcon and GPU timer have been completed.
We now have quite a few TODO entries in the code, so annotate them with a 4 letter code representing the corresponding task in todo.rst. This allows to easily find which part of the code corresponds to a given entry (and conversely).
--- Documentation/gpu/nova/core/todo.rst | 107 ++++++++++++++++-------------- drivers/gpu/nova-core/dma.rs | 2 +- drivers/gpu/nova-core/driver.rs | 2 +- drivers/gpu/nova-core/falcon.rs | 8 ++- drivers/gpu/nova-core/falcon/hal/ga102.rs | 10 +-- drivers/gpu/nova-core/fb.rs | 2 +- drivers/gpu/nova-core/firmware/fwsec.rs | 6 +- drivers/gpu/nova-core/gfw.rs | 2 +- drivers/gpu/nova-core/gpu.rs | 2 +- drivers/gpu/nova-core/regs.rs | 8 +-- drivers/gpu/nova-core/regs/macros.rs | 2 +- drivers/gpu/nova-core/util.rs | 2 +- drivers/gpu/nova-core/vbios.rs | 2 +- 13 files changed, 84 insertions(+), 71 deletions(-)
Documentation/gpu/nova/core/todo.rst +57 -50
@@ -14,14 +14,17 @@ Tasks may have the following fields: - ``Contact``: The person that can be contacted for further information about the task. +A task might have `[ABCD]` code after its name. This code can be used to grep +into the code for `TODO` entries related to it. + Enablement (Rust) ================= Tasks that are not directly related to nova-core, but are preconditions in terms of required APIs. -FromPrimitive API ------------------ +FromPrimitive API [FPRI] +------------------------ Sometimes the need arises to convert a number to a value of an enum or a structure.
@@ -41,8 +44,27 @@ automatically generates the corresponding mappings between a value and a number. | Complexity: Beginner | Link: https://docs.rs/num/latest/num/trait.FromPrimitive.html -Generic register abstraction ----------------------------- +Conversion from byte slices for types implementing FromBytes [TRSM] +------------------------------------------------------------------- + +We retrieve several structures from byte streams coming from the BIOS or loaded +firmware. At the moment converting the bytes slice into the proper type require +an inelegant `unsafe` operation; this will go away once `FromBytes` implements +a proper `from_bytes` method. + +| Complexity: Beginner + +CoherentAllocation improvements [COHA] +-------------------------------------- + +`CoherentAllocation` needs a safe way to write into the allocation, and to +obtain slices within the allocation. + +| Complexity: Beginner +| Contact: Abdiel Janulgue + +Generic register abstraction [REGA] +----------------------------------- Work out how register constants and structures can be automatically generated through generalized macros.
@@ -102,16 +124,40 @@ Usage: let boot0 = Boot0::read(&bar); pr_info!("Revision: {}\n", boot0.revision()); -Note: a work-in-progress implementation currently resides in +A work-in-progress implementation currently resides in `drivers/gpu/nova-core/regs/macros.rs` and is used in nova-core. It would be nice to improve it (possibly using proc macros) and move it to the `kernel` crate so it can be used by other components as well. +Features desired before this happens: + +* Relative register with build-time base address validation, +* Arrays of registers with build-time index validation, +* Make I/O optional I/O (for field values that are not registers), +* Support other sizes than `u32`, +* Allow visibility control for registers and individual fields, +* Use Rust slice syntax to express fields ranges. + | Complexity: Advanced | Contact: Alexandre Courbot -Delay / Sleep abstractions --------------------------- +Numerical operations [NUMM] +--------------------------- + +Nova uses integer operations that are not part of the standard library (or not +implemented in an optimized way for the kernel). These include: + +- Aligning up and down to a power of two, +- The "Find Last Set Bit" (`fls` function of the C part of the kernel) + operation. + +A `num` core kernel module is being designed to provide these operations. + +| Complexity: Intermediate +| Contact: Alexandre Courbot + +Delay / Sleep abstractions [DLAY] +--------------------------------- Rust abstractions for the kernel's delay() and sleep() functions.
@@ -159,18 +205,6 @@ mailing list yet. | Complexity: Intermediate | Contact: Abdiel Janulgue -ELF utils ---------- - -Rust implementation of ELF header representation to retrieve section header -tables, names, and data from an ELF-formatted images. - -There is preceding work from Abdiel Janulgue, which hasn't made it to the -mailing list yet. - -| Complexity: Beginner -| Contact: Abdiel Janulgue - PCI MISC APIs -------------
@@ -179,12 +213,11 @@ capability, MSI API abstractions. | Complexity: Beginner -Auxiliary bus abstractions --------------------------- +XArray bindings [XARR] +---------------------- -Rust abstraction for the auxiliary bus APIs. - -This is needed to connect nova-core to the nova-drm driver. +We need bindings for `xa_alloc`/`xa_alloc_cyclic` in order to generate the +auxiliary device IDs. | Complexity: Intermediate
@@ -216,15 +249,6 @@ Build the radix3 page table to map the firmware. | Complexity: Intermediate | Contact: Abdiel Janulgue -vBIOS support -------------- - -Parse the vBIOS and probe the structures required for driver initialization. - -| Contact: Dave Airlie -| Reference: Vec extensions -| Complexity: Intermediate - Initial Devinit support -----------------------
@@ -234,23 +258,6 @@ configuration. | Contact: Dave Airlie | Complexity: Beginner -Boot Falcon controller ----------------------- - -Infrastructure to load and execute falcon (sec2) firmware images; handle the -GSP falcon processor and fwsec loading. - -| Complexity: Advanced -| Contact: Dave Airlie - -GPU Timer support ------------------ - -Support for the GPU's internal timer peripheral. - -| Complexity: Beginner -| Contact: Dave Airlie - MMU / PT management -------------------
drivers/gpu/nova-core/dma.rs +1 -1
@@ -26,7 +26,7 @@ pub(crate) fn new(dev: &device::Device<device::Bound>, len: usize) -> Result<Selpub (crate )fn from_data (dev: &device::Device <device::Bound >, data: &[u8 ]) ->Result <Self > {Self ::new (dev, data.len ()).map (|mut dma_obj| { -// TODO: replace with `CoherentAllocation::write()` once available. +// TODO[COHA]: replace with `CoherentAllocation::write()` once available. // SAFETY: // - `dma_obj`'s size is at least `data.len()`. // - We have just created this object and there is no other user at this stage.
drivers/gpu/nova-core/driver.rs +1 -1
@@ -42,7 +42,7 @@ fn probe(pdev: &pci::Device<Core>, _info: &Self::IdInfo) -> Result<Pin<KBox<Self _reg: auxiliary::Registration::new( pdev.as_ref (),c_str! ("nova-drm" ), -0 ,// TODO: Once it lands, use XArray; for now we don't use the ID. +0 ,// TODO[XARR]: Once it lands, use XArray; for now we don't use the ID. crate ::MODULE_NAME )?, }),
drivers/gpu/nova-core/falcon.rs +7 -1
@@ -35,6 +35,7 @@ pub(crate) enum FalconCoreRev { Rev7 = 7, } +// TODO[FPRI]: replace with `FromPrimitive`. impl TryFrom <u8 >for FalconCoreRev {type Error =Error ;
@@ -68,6 +69,7 @@ pub(crate) enum FalconCoreRevSubversion { Subversion3 = 3, } +// TODO[FPRI]: replace with `FromPrimitive`. impl TryFrom <u8 >for FalconCoreRevSubversion {type Error =Error ;
@@ -101,6 +103,7 @@ pub(crate) enum FalconSecurityModel { Heavy = 3, } +// TODO[FPRI]: replace with `FromPrimitive`. impl TryFrom <u8 >for FalconSecurityModel {type Error =Error ;
@@ -128,6 +131,7 @@ pub(crate) enum FalconModSelAlgo { Rsa3k = 1, } +// TODO[FPRI]: replace with `FromPrimitive`. impl TryFrom <u8 >for FalconModSelAlgo {type Error =Error ;
@@ -148,6 +152,7 @@ pub(crate) enum DmaTrfCmdSize { Size256B = 0x6, } +// TODO[FPRI]: replace with `FromPrimitive`. impl TryFrom <u8 >for DmaTrfCmdSize {type Error =Error ;
@@ -199,6 +204,7 @@ pub(crate) enum FalconFbifTarget { NoncoherentSysmem = 2, } +// TODO[FPRI]: replace with `FromPrimitive`. impl TryFrom <u8 >for FalconFbifTarget {type Error =Error ;
@@ -354,7 +360,7 @@ fn reset_eng(&self, bar: &Bar0) -> Result { regs::NV_PFALCON_FALCON_ENGINE ::alter (bar,E ::BASE , |v| v.set_reset (true )); -// TODO: replace with udelay() or equivalent once available. +// TODO[DLAY]: replace with udelay() or equivalent once available. // TIMEOUT: falcon engine should not take more than 10us to reset. let _:Result = util::wait_on (Duration ::from_micros (10 ), ||None );
drivers/gpu/nova-core/falcon/hal/ga102.rs +5 -5
@@ -42,10 +42,10 @@ fn signature_reg_fuse_version_ga102( engine_id_mask: u16, ucode_id: u8, ) -> Result<u32> { -// TODO: The ucode fuse versions are contained in the FUSE_OPT_FPF_<ENGINE>_UCODE<X>_VERSION -// registers, which are an array. Our register definition macros do not allow us to manage them -// properly, so we need to hardcode their addresses for now. Clean this up once we support -// register arrays. +// TODO[REGA]: The ucode fuse versions are contained in the +// FUSE_OPT_FPF_<ENGINE>_UCODE<X>_VERSION registers, which are an array. Our register +// definition macros do not allow us to manage them properly, so we need to hardcode their +// addresses for now. Clean this up once we support register arrays. // Each engine has 16 ucode version registers numbered from 1 to 16. if ucode_id ==0 || ucode_id >16 {
@@ -69,7 +69,7 @@ fn signature_reg_fuse_version_ga102(let reg_fuse_version = bar.read32 (reg_fuse_base + ((ucode_id -1 )as usize * core::mem::size_of ::<u32 >())); -// TODO: replace with `last_set_bit` once it lands. +// TODO[NUMM]: replace with `last_set_bit` once it lands. Ok (u32::BITS - reg_fuse_version.leading_zeros ()) }
drivers/gpu/nova-core/fb.rs +1 -1
@@ -121,7 +121,7 @@ pub(crate) fn new(chipset: Chipset, bar: &Bar0) -> Result<Self> {let frts = {const FRTS_DOWN_ALIGN :u64 =SZ_128K as u64 ;const FRTS_SIZE :u64 =SZ_1M as u64 ; -// TODO: replace with `align_down` once it lands. +// TODO[NUMM]: replace with `align_down` once it lands. let frts_base = (vga_workspace.start & !(FRTS_DOWN_ALIGN -1 )) -FRTS_SIZE ; frts_base..frts_base +FRTS_SIZE
drivers/gpu/nova-core/firmware/fwsec.rs +3 -3
@@ -150,8 +150,8 @@ impl FirmwareSignature<FwsecFirmware> for Bcrt30Rsa3kSignature {}/// Callers must ensure that the region of memory returned is not written for as long as the /// returned reference is alive. /// -/// TODO: Remove this and `transmute_mut` once `CoherentAllocation::as_slice` is available and we -/// have a way to transmute objects implementing FromBytes, e.g.: +/// TODO[TRSM][COHA]: Remove this and `transmute_mut` once `CoherentAllocation::as_slice` is +/// available and we have a way to transmute objects implementing FromBytes, e.g.: /// https://lore.kernel.org/lkml/[email protected]/ unsafe fn transmute <'a, 'b,T :Sized +FromBytes >( fw: &'a DmaObject,
@@ -218,7 +218,7 @@ fn dmem_load_params(&self) -> FalconLoadTarget {FalconLoadTarget { src_start: self.desc.imem_load_size, dst_start: self.desc.dmem_phys_base, -// TODO: replace with `align_up` once it lands. +// TODO[NUMM]: replace with `align_up` once it lands. len: self .desc .dmem_load_size
drivers/gpu/nova-core/gfw.rs +1 -1
@@ -31,7 +31,7 @@ pub(crate) fn wait_gfw_boot_completion(bar: &Bar0) -> Result { }else {// Avoid busy-looping. // SAFETY: msleep should be safe to call with any parameter. -// TODO: replace with [1] once it merges. +// TODO[DLAY]: replace with [1] once it merges. // [1] https://lore.kernel.org/rust-for-linux/[email protected]/ unsafe { bindings::msleep (1 ) };
drivers/gpu/nova-core/gpu.rs +1 -1
@@ -37,7 +37,7 @@ impl Chipset { ]; } -// TODO replace with something like derive(FromPrimitive) +// TODO[FPRI]: replace with something like derive(FromPrimitive) impl TryFrom <u32 >for Chipset {type Error = kernel::error::Error ;
drivers/gpu/nova-core/regs.rs +4 -4
@@ -44,7 +44,7 @@ pub(crate) fn chipset(self) -> Result<Chipset> {/* PBUS */ -// TODO: this is an array of registers. +// TODO[REGA]: this is an array of registers. register! (NV_PBUS_SW_SCRATCH_0E @0x00001438 {31 :16 frts_err_codeas u16 ; });
@@ -110,7 +110,7 @@ pub(crate) fn higher_bound(self) -> u64 { 0:0 read_protection_level0 as bool, "Set after FWSEC lowers its protection level"; }); -// TODO: This is an array of registers. +// TODO[REGA]: This is an array of registers. register! (NV_PGC6_AON_SECURE_SCRATCH_GROUP_05 @0x00118234 {31 :0 valueas u32 ; });
@@ -272,7 +272,7 @@ pub(crate) fn mem_scrubbing_done(self) -> bool { 0:0 reset as bool; }); -// TODO: this is an array of registers. +// TODO[REGA]: this is an array of registers. register! (NV_PFALCON_FBIF_TRANSCFG @ +0x00000600 {1 :0 targetas u8 ?=>FalconFbifTarget ;2 :2 mem_typeas bool =>FalconFbifMemType ;
@@ -294,7 +294,7 @@ pub(crate) fn mem_scrubbing_done(self) -> bool { 31:0 value as u32; }); -// TODO: this is an array of registers. +// TODO[REGA]: this is an array of registers. register! (NV_PFALCON2_FALCON_BROM_PARAADDR @ +0x00001210 {31 :0 valueas u32 ; });
drivers/gpu/nova-core/regs/macros.rs +1 -1
@@ -147,7 +147,7 @@ impl $name {pub (crate )const OFFSET :usize = $offset; } -// TODO: display the raw hex value, then the value of all the fields. This requires +// TODO[REGA]: display the raw hex value, then the value of all the fields. This requires // matching the fields, which will complexify the syntax considerably... impl ::core::fmt::Debug for $name {fn fmt (&self, f: &mut ::core::fmt::Formatter <'_>) -> ::core::fmt::Result {
drivers/gpu/nova-core/util.rs +1 -1
@@ -32,7 +32,7 @@ pub(crate) const fn const_bytes_to_str(bytes: &[u8]) -> &str {/// `Err(ETIMEDOUT)` is returned if `timeout` has been reached without `cond` evaluating to /// `Some`. /// -/// TODO: replace with `read_poll_timeout` once it is available. +/// TODO[DLAY]: replace with `read_poll_timeout` once it is available. /// (https://lore.kernel.org/lkml/[email protected]/) pub (crate )fn wait_on <R ,F :Fn () ->Option <R >>(timeout:Duration , cond:F ) ->Result <R > {let start_time =Instant ::now ();
drivers/gpu/nova-core/vbios.rs +1 -1
@@ -175,7 +175,7 @@ fn next(&mut self) -> Option<Self::Item> {// Advance to next image (aligned to 512 bytes) self.current_offset += image_size; -// TODO: replace with `align_up` once it lands. +// TODO[NUMM]: replace with `align_up` once it lands. self.current_offset = self.current_offset.next_multiple_of (512 );Some (Ok (full_image))
Signature · 1 line
2.49.0
On Thu, Jun 19, 2025 at 10:23:44PM +0900, Alexandre Courbot wrote:
Applied to nova-next, thanks!
Quoted 10 lines
Alexandre Courbot (21):
rust: make ETIMEDOUT error available
rust: sizes: add constants up toSZ_2G
gpu: nova-core: use absolute paths in register!() macro
gpu: nova-core: add delimiter for helper rules in register!() macro
gpu: nova-core: expose the offset of each register as a type constant
gpu: nova-core: allow register aliases
gpu: nova-core: increase BAR0 size to 16MB
gpu: nova-core: add helper function to wait on condition
gpu: nova-core: wait forGFW_BOOTcompletion
[ Slightly adjust comments in wait_gfw_boot_completion(). - Danilo ]
Quoted 2 lines
gpu: nova-core: add DMA object struct
gpu: nova-core: register sysmem flush page
[ * Use kernel::page::PAGE_SIZE instead of kernel::bindings::PAGE_SIZE.
* Get rid of the Option for SysmemFlush.
* Slightly reword SysmemFlush doc-comments.
- Danilo ]
Quoted 3 lines
gpu: nova-core: add falcon register definitions and base code
gpu: nova-core: firmware: add ucode descriptor used by FWSEC-FRTS
gpu: nova-core: compute layout of the FRTS region
[ In doc-comment of FbLayout s/bootup process/boot process/ - Danilo ]
Quoted 7 lines
gpu: nova-core: add types for patching firmware binaries
gpu: nova-core: extract FWSEC from BIOS and patch it to run FWSEC-FRTS
gpu: nova-core: load and run FWSEC-FRTS
gpu: nova-core: update and annotate TODO listJoel Fernandes (3):
gpu: nova-core: vbios: Add base support for VBIOS construction and iteration
[ Replace extend_with() and copy_from_slice() with extend_from_slice();
re-format and use markdown in comments. - Danilo ]
Quoted 1 line
gpu: nova-core: vbios: Add support to look up PMU table in FWSEC
[ Re-format and use markdown in comments. - Danilo ]
Quoted 1 line
gpu: nova-core: vbios: Add support for FWSEC ucode extraction
[ Re-format and use markdown in comments. - Danilo ]
There's one thing that would be nice to fix subsequently, which is properly resetting the GPU. Currently, it needs a power cycle to be able to probe successfully after unbinding the driver.
- Danilo
Alexandre Courbot
maintainerQuoted 3 lines · Danilo Krummrich
There's one thing that would be nice to fix subsequently, which is properly resetting the GPU. Currently, it needs a power cycle to be able to probe successfully after unbinding the driver.
Yes, what I usually do is the following after unloading Nova:
echo 1 | sudo tee /sys/bus/pci/devices/0000:01:00.0/reset
and this allows it to probe again. Maybe we want to add some equivalent programmatically in the driver probe function?
Quoted 11 lines · Alexandre Courbot
Quoted 3 lines · Danilo Krummrich
There's one thing that would be nice to fix subsequently, which is properly resetting the GPU. Currently, it needs a power cycle to be able to probe successfully after unbinding the driver.
Yes, what I usually do is the following after unloading Nova:
echo 1 | sudo tee /sys/bus/pci/devices/0000:01:00.0/resetand this allows it to probe again. Maybe we want to add some equivalent programmatically in the driver probe function?
At this point, we are only getting things up to a certain very early stage. And so we have to reset like this in order to try again.
But I'm not sure that will be the case, once we have more code in place to go further.
So maybe hold off on this for a few weeks or so?
thanks,
Signature · 1 line
John Hubbard
Danilo Krummrich
maintainerQuoted 11 lines · Alexandre Courbot
Quoted 3 lines · Danilo Krummrich
There's one thing that would be nice to fix subsequently, which is properly resetting the GPU. Currently, it needs a power cycle to be able to probe successfully after unbinding the driver.
Yes, what I usually do is the following after unloading Nova:
echo 1 | sudo tee /sys/bus/pci/devices/0000:01:00.0/resetand this allows it to probe again. Maybe we want to add some equivalent programmatically in the driver probe function?
Probably -- how are things implemented on the GPU side of things? Is the GPU firmware surviving a FLR?
Alexandre Courbot
maintainerQuoted 8 lines · Danilo Krummrich
Quoted 7 lines · Alexandre Courbot
Quoted 3 lines · Danilo Krummrich
There's one thing that would be nice to fix subsequently, which is properly resetting the GPU. Currently, it needs a power cycle to be able to probe successfully after unbinding the driver.
Yes, what I usually do is the following after unloading Nova:
Quoted 7 lines
Quoted 4 lines
echo 1 | sudo tee /sys/bus/pci/devices/0000:01:00.0/resetand this allows it to probe again. Maybe we want to add some equivalent programmatically in the driver probe function?
Probably -- how are things implemented on the GPU side of things? Is the GPU firmware surviving a FLR?
After a FLR all firmware is cleared and the WPR2 region is wiped, meaning GPU initialization has to be done again from the very beginning.