gpu: nova-core: process and prepare more firmwares to boot GSP
Subsystems (8)
Alexandre Courbot
maintainerv2 cover gpu: nova-core: process and prepare more firmwares to boot GSP
This series makes more progress on the GSP boot process for Ampere GPUs.
At the end of the previous series [1], we were left with a WPR memory region created by the FRTS firmware, but still far from the GSP running. This series brings us closer to that goal by preparing 3 firmware packages:
* The Booter firmware, which the driver loads and runs on the SEC2 falcon;
* The GSP bootloader, which is loaded by Booter onto the GSP RISC-V core;
* The GSP firmware itself, which is verified and loaded by the GSP bootloader.
There 3 bundles are involved in a rather complex dance that is made necessary by limitations related to the level of privilege required to load code onto the GSP (doing so requires a Heavy Secured signed firmware, which is the role fulfilled by Booter).
The first patch is an addition to FromBytes that makes it able to process the unaligned headers contained in the firmware files by performing a copy. Second patch adds support for a header commonly used in NVIDIA firmware files. Both are relatively simple.
The third patch parses the Booter firmware file, queries the hardware for the right signature to use, and patch it into the firmware blob. This makes Booter ready to load and run.
Fourth patch takes care of preparing the GSP bootloader for execution and fifth one does the same for the GSP firmware, which needs to come with its own device-mapped page table.
Sixth and seventh patches switch to the 570.144 firmware and introduce the layout for its bindings. The raw bindings are stored in a private module, and abstracted/reexported by the parent module as needed. This allows consumer modules to access a safer/nicer form of the bindings than the raw one, and also makes it easier to switch to a different (and potentially incompatible) firmware version in the future.
570.144 has been picked because it is the latest firmware currently in linux-firmware, but as development progresses the plan is to switch to a newer one that is designed with the constraint of upstream in mind. So support for 570.144 will be dropped in the future. Support for multiple firmware versions is not considered at the moment: there is no immediate need for it as the driver is still unstable, and we can think about this point once we approach stability (and have better visibility about the shape of the firmware at that point).
The last patch introduces the first bindings and uses them to compute more framebuffer layout information needed for booting the GSP. A separate patch series will pick up from there to use this information and finally run these firmware blobs.
The base of this series is today's nova-next, but there a few more unmerged dependencies required:
- BorrowedPage, AsPageIter and VmallocPageIter [2]
- Rust infrastructure for sg_table and scatterlist [3]
- FromBytes [4]
- The Alignment series [5]
[1] https://lore.kernel.org/rust-for-linux/[email protected]/
[2] https://lore.kernel.org/rust-for-linux/[email protected]/
[3] https://lore.kernel.org/rust-for-linux/[email protected]/
[4] https://lore.kernel.org/rust-for-linux/[email protected]/
[5] https://lore.kernel.org/rust-for-linux/[email protected]/
---
Changes in v2:
- Add some GSP bindings and use them to compute more FB layout info
needed to boot GSP,
- Use PinInit in GspFirmware to avoid several heap allocations,
- Rename bootloader to gsp_bootloader in Firmware to avoid
confusion with the future Turing falcon bootloader,
- Link to v1: https://lore.kernel.org/r/[email protected]
---
Alexandre Courbot (7):
rust: transmute: add from_bytes_copy method to FromBytes trait
gpu: nova-core: firmware: add support for common firmware header
gpu: nova-core: firmware: process Booter and patch its signature
gpu: nova-core: firmware: process the GSP bootloader
gpu: nova-core: firmware: process and prepare the GSP firmware
gpu: nova-core: firmware: use 570.144 firmware
gpu: nova-core: compute layout of more framebuffer regions required for GSP
Alistair Popple (1):
gpu: nova-core: Add base files for r570.144 firmware bindings
Documentation/gpu/nova/core/todo.rst | 17 -- drivers/gpu/nova-core/falcon.rs | 4 +- drivers/gpu/nova-core/fb.rs | 112 +++++++- drivers/gpu/nova-core/fb/hal.rs | 4 + drivers/gpu/nova-core/fb/hal/ga100.rs | 6 +- drivers/gpu/nova-core/fb/hal/ga102.rs | 14 +- drivers/gpu/nova-core/fb/hal/tu102.rs | 14 + drivers/gpu/nova-core/firmware.rs | 204 +++++++++++++- drivers/gpu/nova-core/firmware/booter.rs | 356 ++++++++++++++++++++++++ drivers/gpu/nova-core/firmware/gsp.rs | 117 ++++++++ drivers/gpu/nova-core/firmware/riscv.rs | 89 ++++++ drivers/gpu/nova-core/gpu.rs | 13 +- drivers/gpu/nova-core/gsp.rs | 7 + drivers/gpu/nova-core/nova_core.rs | 2 + drivers/gpu/nova-core/nvfw.rs | 42 +++ drivers/gpu/nova-core/nvfw/r570_144.rs | 28 ++ drivers/gpu/nova-core/nvfw/r570_144_bindings.rs | 126 +++++++++ rust/kernel/transmute.rs | 17 ++ 18 files changed, 1135 insertions(+), 37 deletions(-)
---
base-commit: 331c24e6ce814af2af74bac648d1ac1708873e9c
change-id: 20250822-nova_firmware-e0ffb492ba35
prerequisite-message-id: <[email protected]>
prerequisite-patch-id: 0e1b1f9a665317ff569a37df6ff49cd1880b04f8
prerequisite-patch-id: 178b864e6d1b88ee299dcc05d1a7a4c89ec7ed51
prerequisite-patch-id: 7f72c4bfd0e5f50b6d2f8ce96751782894a3ba81
prerequisite-patch-id: 62fa6de7d3ae99dc54c092087bd716e6749545fd
prerequisite-patch-id: 3d14d56ca93b0831837aa26b802100a250adeac6
prerequisite-patch-id: 7a12f4b0e7588874ce589b41b70671dc261b9468
prerequisite-patch-id: c44763ec35c4e4431e769df088b98424cbddf7df
prerequisite-message-id: <[email protected]>
prerequisite-patch-id: a9e008c179b1c2fbe76654a191e5018880383d49
prerequisite-patch-id: 363279599349e5efc7069a63b3f0574639e25418
prerequisite-patch-id: 4dd34d858514b7b982f4ebc85103a756205c3219
prerequisite-patch-id: a747e05834cdb8b8f727e1f7c8b110c636cadab8
prerequisite-patch-id: 24833689bdecd3fc7a604e13bfe203ccd2fca6f0
prerequisite-message-id: <[email protected]>
prerequisite-patch-id: 3ddaa5300963f6c069411c6431965a7a48107a8b
prerequisite-change-id: 20250620-num-9420281c02c7:v4
prerequisite-patch-id: 50077433250cad1cf60eb8f85c78e532ac91852e
prerequisite-patch-id: 021a41cd35f09790ec383521ecc9b4c167868732
prerequisite-patch-id: a1ec5698a198d4aad45432b50d42f401e3db6452
prerequisite-patch-id: 8565b054c432bcc9a3a0d0121a934c74ef36d535
prerequisite-patch-id: 19d008deabb88beb441d2398f120ecb426fbdb43
prerequisite-patch-id: 3bc0d2be065a900d224ff8c1bc4450abfe9eb2cc
prerequisite-patch-id: 5b4eb0f71fa2ccf662594819fa79fd932f4f164f
prerequisite-patch-id: 9058ca08cd149444b5f910e4bb4494a890d1a733
prerequisite-patch-id: 8804806f7cc605feddded0804eec8b8362d7b965
prerequisite-patch-id: f999cabde51824432a1bf60817518d1ce189eb76
prerequisite-patch-id: 49e15538e142f2e7dd4f1ba0cf2fd891bd265d36
prerequisite-patch-id: 2ecf9b1e26b5203065bfac4ccf74301b3bb4fbe6
prerequisite-patch-id: 1af6ec7c2ce8503fe476985f59949dcd150ee6bf
prerequisite-patch-id: ac72e72b3affece504bff76b60b88769ff200a2f
prerequisite-patch-id: 7dc0a6da8c9727d27250cf730f8aaf6dd8b3d8c7
prerequisite-patch-id: 31a0a2469de9ac965186098072753dcc749b40fe
prerequisite-patch-id: 7e6d1fc7cf910decf481d135a19b0add38da2b2a
prerequisite-patch-id: c72ab11e9346de71eabfe0e6466636d5ab15a5ba
prerequisite-patch-id: 3f236fdea8c4b33620d0f863fea573b46ab0ded6
prerequisite-patch-id: a8ab42d0c9c3c837bb4cacb02cef585ef163a27e
prerequisite-patch-id: 930a1f26364ed67e0d6b85c96251028fda43c80a
prerequisite-patch-id: f1bc1fd46145a66235ab7475463584e1803882a3
prerequisite-patch-id: 4a2fd7bd8d13dc2feaf68e0dc681546ce2ab3e40
prerequisite-patch-id: dd0df8d299dc0615a88cc0019f38bc09cee31ed7
prerequisite-patch-id: 56a45978f7b956c94ec66eecd4b438706d5174ce
prerequisite-patch-id: e9bceff31bbf653d2641194b97eb1c4e5d8b93ee
Best regards,
Signature · 1 line
Alexandre Courbot <[email protected]>
Alexandre Courbot
maintainerPATCH v2 1/8 rust: transmute: add `from_bytes_copy` method to `FromBytes` trait
FromBytes::from_bytes comes with a few practical limitations:
- It requires the bytes slice to have the same alignment as the returned type, which might not be guaranteed in the case of a byte stream,
- It returns a reference, requiring the returned type to implement Clone if one wants to keep the value for longer than the lifetime of the slice.
To overcome these when needed, add a from_bytes_copy with a default implementation in the trait. from_bytes_copy returns an owned value that is populated using an unaligned read, removing the lifetime constraint and making it usable even on non-aligned byte slices.
--- rust/kernel/transmute.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)
rust/kernel/transmute.rs +17 -0
@@ -78,6 +78,23 @@ fn from_bytes_mut(bytes: &mut [u8]) -> Option<&mut Self>None } } + +/// Creates an owned instance of `Self` by copying `bytes`. +/// +/// As the data is copied into a properly-aligned location, this method can be used even if +/// [`FromBytes::from_bytes`] would return `None` due to incompatible alignment. +fn from_bytes_copy (bytes: &[u8 ]) ->Option <Self > +where +Self :Sized , + { +if bytes.len () ==size_of ::<Self >() { +// SAFETY: `bytes` has the same size as `Self`, and per the invariants of `FromBytes`, +// any byte sequence is a valid value for `Self`. +Some (unsafe { core::ptr::read_unaligned (bytes.as_ptr ().cast ::<Self >()) }) + }else { +None + } + } }macro_rules! impl_frombytes {
Signature · 1 line
2.50.1
Re: [PATCH v2 1/8] rust: transmute: add `from_bytes_copy` method to `FromBytes` trait
Quoted 7 lines · Alexandre Courbot
FromBytes::from_bytescomes with a few practical limitations:- It requires the bytes slice to have the same alignment as the returned type, which might not be guaranteed in the case of a byte stream,
- It returns a reference, requiring the returned type to implementCloneif one wants to keep the value for longer than the lifetime of the slice.
I think that any Sized type that can implement FromBytes also can implement Copy, so I don't feel like the last point is a strong one. But the unaligned byte stream is motivation enough :)
Quoted 7 lines
To overcome these when needed, add a
from_bytes_copywith a default implementation in the trait.from_bytes_copyreturns an owned value that is populated using an unaligned read, removing the lifetime constraint and making it usable even on non-aligned byte slices.Reviewed-by Alice Ryhl <[email protected]>Signed-off-by Alexandre Courbot <[email protected]>
---
Cheers,
Benno
Quoted 3 lines
--- rust/kernel/transmute.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)
Re: [PATCH v2 1/8] rust: transmute: add `from_bytes_copy` method to `FromBytes` trait
In reply to Alexandre CourbotQuoted 24 lines · Alexandre Courbot
FromBytes::from_bytescomes with a few practical limitations:- It requires the bytes slice to have the same alignment as the returned type, which might not be guaranteed in the case of a byte stream,
- It returns a reference, requiring the returned type to implementCloneif one wants to keep the value for longer than the lifetime of the slice.To overcome these when needed, add a
from_bytes_copywith a default implementation in the trait.from_bytes_copyreturns an owned value that is populated using an unaligned read, removing the lifetime constraint and making it usable even on non-aligned byte slices.Reviewed-by Alice Ryhl <[email protected]>Signed-off-by Alexandre Courbot <[email protected]>--- rust/kernel/transmute.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)rust/kernel/transmute.rs +0
-0
rust/kernel/transmute.rs fn from_bytes_mut(bytes: &mut [u8]) -> Option<&mut Self> · line 85
Quoted 8 lines
rust/kernel/transmute.rs +5
-0@@ -78,6 +78,23 @@ fn from_bytes_mut(bytes: &mut [u8]) -> Option<&mut Self>None } } + +/// Creates an owned instance of `Self` by copying `bytes`. +/// +/// As the data is copied into a properly-aligned location, this method can be used even if +/// [`FromBytes::from_bytes`] would return `None` due to incompatible alignment.
Some very minor suggestions:
This wording less precise than it could be: "as the data is copied" can mean either "while it is being copied", or "because it is copied". Also, there should not be a hyphen in "properly aligned".
I'd suggest something like this instead:
/// Unlike [`FromBytes::from_bytes`], which requires aligned input, this
/// method can be used on non-aligned data.rust/kernel/transmute.rs fn from_bytes_mut(bytes: &mut [u8]) -> Option<&mut Self> · line 92
Quoted 7 lines
rust/kernel/transmute.rs +7
-0+fn from_bytes_copy (bytes: &[u8 ]) ->Option <Self > +where +Self :Sized , + { +if bytes.len () ==size_of ::<Self >() { +// SAFETY: `bytes` has the same size as `Self`, and per the invariants of `FromBytes`, +// any byte sequence is a valid value for `Self`.
More wording suggestions. How about this:
// SAFETY: we just verified that `bytes` has the same size as `Self`, and per the
// invariants of `FromBytes`, any byte sequence of the correct length is a valid value
// for `Self`.rust/kernel/transmute.rs fn from_bytes_mut(bytes: &mut [u8]) -> Option<&mut Self> · line 100
Quoted 9 lines
rust/kernel/transmute.rs +5
-0+Some (unsafe { core::ptr::read_unaligned (bytes.as_ptr ().cast ::<Self >()) }) + }else { +None + } + } }macro_rules! impl_frombytes {
I'm unable to find anything wrong with the code itself, and the above are just tiny nits, so whether or not you apply either or both of the above suggestions, please feel free to add:
thanks,
Signature · 1 line
John Hubbard
Alexandre Courbot
maintainerRe: [PATCH v2 1/8] rust: transmute: add `from_bytes_copy` method to `FromBytes` trait
Quoted 36 lines · John Hubbard
Quoted 24 lines · Alexandre Courbot
FromBytes::from_bytescomes with a few practical limitations:- It requires the bytes slice to have the same alignment as the returned type, which might not be guaranteed in the case of a byte stream,
- It returns a reference, requiring the returned type to implementCloneif one wants to keep the value for longer than the lifetime of the slice.To overcome these when needed, add a
from_bytes_copywith a default implementation in the trait.from_bytes_copyreturns an owned value that is populated using an unaligned read, removing the lifetime constraint and making it usable even on non-aligned byte slices.Reviewed-by Alice Ryhl <[email protected]>Signed-off-by Alexandre Courbot <[email protected]>--- rust/kernel/transmute.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)rust/kernel/transmute.rs +0
-0rust/kernel/transmute.rs fn from_bytes_mut(bytes: &mut [u8]) -> Option<&mut Self> · line 85
Quoted 8 lines
rust/kernel/transmute.rs +5
-0@@ -78,6 +78,23 @@ fn from_bytes_mut(bytes: &mut [u8]) -> Option<&mut Self>None } } + +/// Creates an owned instance of `Self` by copying `bytes`. +/// +/// As the data is copied into a properly-aligned location, this method can be used even if +/// [`FromBytes::from_bytes`] would return `None` due to incompatible alignment. Some very minor suggestions:
Quoted 8 lines
This wording less precise than it could be: "as the data is copied" can mean either "while it is being copied", or "because it is copied". Also, there should not be a hyphen in "properly aligned".
I'd suggest something like this instead:
/// Unlike [`FromBytes::from_bytes`], which requires aligned input, this /// method can be used on non-aligned data.
That's much simpler and better. I'll just add "... at the cost of a copy." to not lose this information.
Quoted 9 lines
rust/kernel/transmute.rs fn from_bytes_mut(bytes: &mut [u8]) -> Option<&mut Self> · line 92
Quoted 8 lines
rust/kernel/transmute.rs +7
-0+fn from_bytes_copy (bytes: &[u8 ]) ->Option <Self > +where +Self :Sized , + { +if bytes.len () ==size_of ::<Self >() { +// SAFETY: `bytes` has the same size as `Self`, and per the invariants of `FromBytes`, +// any byte sequence is a valid value for `Self`.
Quoted 5 lines
More wording suggestions. How about this:
// SAFETY: we just verified that `bytes` has the same size as `Self`, and per the // invariants of `FromBytes`, any byte sequence of the correct length is a valid value // for `Self`.
Taken as-is, thanks!
Alexandre Courbot
maintainerRe: [PATCH v2 1/8] rust: transmute: add `from_bytes_copy` method to `FromBytes` trait
In reply to Alexandre CourbotQuoted 8 lines · Alexandre Courbot
FromBytes::from_bytescomes with a few practical limitations:- It requires the bytes slice to have the same alignment as the returned type, which might not be guaranteed in the case of a byte stream,
- It returns a reference, requiring the returned type to implementCloneif one wants to keep the value for longer than the lifetime of the slice.
Quoted 7 lines
To overcome these when needed, add a
from_bytes_copywith a default implementation in the trait.from_bytes_copyreturns an owned value that is populated using an unaligned read, removing the lifetime constraint and making it usable even on non-aligned byte slices.Reviewed-by Alice Ryhl <[email protected]>Signed-off-by Alexandre Courbot <[email protected]>
We got 3 Reviewed-by on this patch - Miguel, are you ok if I merge it together with Christian's from_bytes patch, since they are closely related?
Miguel Ojeda
Acked-byRe: [PATCH v2 1/8] rust: transmute: add `from_bytes_copy` method to `FromBytes` trait
Quoted 4 lines · Alexandre Courbot
We got 3 Reviewed-by on this patch - Miguel, are you ok if I merge it together with Christian's
from_bytespatch, since they are closely related?
If you are taking this series this cycle, then sure!
Thanks!
Cheers,
Miguel
Alexandre Courbot
maintainerRe: [PATCH v2 1/8] rust: transmute: add `from_bytes_copy` method to `FromBytes` trait
Quoted 9 lines · Miguel Ojeda
Quoted 4 lines · Alexandre Courbot
We got 3 Reviewed-by on this patch - Miguel, are you ok if I merge it together with Christian's
from_bytespatch, since they are closely related?If you are taking this series this cycle, then sure!
Acked-by Miguel Ojeda <[email protected]>
Thanks Miguel! Pushed this into nova-next, right after Christian's patch.
Alexandre Courbot
maintainerPATCH v2 2/8 gpu: nova-core: firmware: add support for common firmware header
In reply to Alexandre CourbotSeveral firmware files loaded from userspace feature a common header that describes their payload. Add basic support for it so subsequent patches can leverage it.
--- drivers/gpu/nova-core/firmware.rs | 62 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+)
drivers/gpu/nova-core/firmware.rs +62 -0
@@ -4,11 +4,13 @@//! to be loaded into a given execution unit. use core::marker::PhantomData ; +use core::mem::size_of;use kernel::device;use kernel::firmware;use kernel::prelude::*;use kernel::str::CString ; +use kernel::transmute::FromBytes ;use crate ::dma::DmaObject ;use crate ::falcon::FalconFirmware ;
@@ -150,6 +152,66 @@ fn no_patch_signature(self) -> FirmwareDmaObject<F, Signed> { } } +/// Header common to most firmware files. +#[repr( C )] +#[derive( Debug , Clone )] +struct BinHdr { +/// Magic number, must be `0x10de`. + bin_magic:u32 , +/// Version of the header. + bin_ver:u32 , +/// Size in bytes of the binary (to be ignored). + bin_size:u32 , +/// Offset of the start of the application-specific header. + header_offset:u32 , +/// Offset of the start of the data payload. + data_offset:u32 , +/// Size in bytes of the data payload. + data_size:u32 , +} + +// SAFETY: all bit patterns are valid for this type, and it doesn't use interior mutability. +unsafe impl FromBytes for BinHdr {} + +// A firmware blob starting with a `BinHdr`. +struct BinFirmware <'a> { + hdr:BinHdr , + fw: &'a [u8 ], +} + +#[expect(dead_code)] +impl <'a>BinFirmware <'a> { +/// Interpret `fw` as a firmware image starting with a [`BinHdr`], and returns the +/// corresponding [`BinFirmware`] that can be used to extract its payload. +fn new (fw: &'a firmware::Firmware ) ->Result <Self > { +const BIN_MAGIC :u32 =0x10de ; +let fw = fw.data (); + + fw.get (0 ..size_of ::<BinHdr >()) +// Extract header. + .and_then (BinHdr ::from_bytes_copy) +// Validate header. + .and_then (|hdr| { +if hdr.bin_magic ==BIN_MAGIC { +Some (hdr) + }else { +None + } + }) + .map (|hdr|Self { hdr, fw }) + .ok_or (EINVAL ) + } + +/// Returns the data payload of the firmware, or `None` if the data range is out of bounds of +/// the firmware image. +fn data (&self) ->Option <&[u8 ]> { +let fw_start = self.hdr.data_offsetas usize ; +let fw_size = self.hdr.data_sizeas usize ; + + self.fw.get (fw_start..fw_start + fw_size) + } +} +pub (crate )struct ModInfoBuilder <const N :usize >(firmware::ModInfoBuilder <N >);impl <const N :usize >ModInfoBuilder <N > {
Signature · 1 line
2.50.1
Re: [PATCH v2 2/8] gpu: nova-core: firmware: add support for common firmware header
Quoted 28 lines · Alexandre Courbot
Several firmware files loaded from userspace feature a common header that describes their payload. Add basic support for it so subsequent patches can leverage it.
Signed-off-by Alexandre Courbot <[email protected]>--- drivers/gpu/nova-core/firmware.rs | 62 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+)drivers/gpu/nova-core/firmware.rs +2
-0@@ -4,11 +4,13 @@//! to be loaded into a given execution unit. use core::marker::PhantomData ; +use core::mem::size_of;use kernel::device;use kernel::firmware;use kernel::prelude::*;use kernel::str::CString ; +use kernel::transmute::FromBytes ;use crate ::dma::DmaObject ;use crate ::falcon::FalconFirmware ;
drivers/gpu/nova-core/firmware.rs fn no_patch_signature(self) -> FirmwareDmaObject<F, Signed> { · line 159
Quoted 8 lines
drivers/gpu/nova-core/firmware.rs +5
-0@@ -150,6 +152,66 @@ fn no_patch_signature(self) -> FirmwareDmaObject<F, Signed> { } } +/// Header common to most firmware files. +#[repr( C )] +#[derive( Debug , Clone )] +struct BinHdr { +/// Magic number, must be `0x10de`.
How about:
/// Magic number, required to be equal to BIN_MAGIC
...and see below.
Quoted 18 lines
drivers/gpu/nova-core/firmware.rs +18
-0+ bin_magic: u32, +/// Version of the header. + bin_ver: u32, +/// Size in bytes of the binary (to be ignored). + bin_size: u32, +/// Offset of the start of the application-specific header. + header_offset: u32, +/// Offset of the start of the data payload. + data_offset: u32, +/// Size in bytes of the data payload. + data_size: u32, +} + +// SAFETY: all bit patterns are valid for this type, and it doesn't use interior mutability. +unsafe impl FromBytes for BinHdr {} + +// A firmware blob starting with a `BinHdr`. +struct BinFirmware <'a> {
drivers/gpu/nova-core/firmware.rs fn no_patch_signature(self) -> FirmwareDmaObject<F, Signed> { · line 187
Quoted 10 lines
drivers/gpu/nova-core/firmware.rs +10
-0+ hdr: BinHdr, + fw: &'a [u8], +} + +#[expect(dead_code)] +impl <'a>BinFirmware <'a> { +/// Interpret `fw` as a firmware image starting with a [`BinHdr`], and returns the +/// corresponding [`BinFirmware`] that can be used to extract its payload. +fn new (fw: &'a firmware::Firmware ) ->Result <Self > { +const BIN_MAGIC :u32 =0x10de ;
Let's promote this to approximately file scope and put it just above the BinHdr definition. Then we end up with one definition at the ideal scope, and the comment docs take better care of themselves.
Quoted 14 lines
drivers/gpu/nova-core/firmware.rs +14
-0+let fw = fw.data (); + + fw.get (0 ..size_of ::<BinHdr >()) +// Extract header. + .and_then (BinHdr ::from_bytes_copy) +// Validate header. + .and_then (|hdr| { +if hdr.bin_magic ==BIN_MAGIC { +Some (hdr) + }else { +None + } + }) + .map (|hdr|Self { hdr, fw })
drivers/gpu/nova-core/firmware.rs fn no_patch_signature(self) -> FirmwareDmaObject<F, Signed> { · line 211
Quoted 10 lines
drivers/gpu/nova-core/firmware.rs +10
-0+ .ok_or(EINVAL) + } + +/// Returns the data payload of the firmware, or `None` if the data range is out of bounds of +/// the firmware image. +fn data (&self) ->Option <&[u8 ]> { +let fw_start = self.hdr.data_offsetas usize ; +let fw_size = self.hdr.data_sizeas usize ; + + self.fw.get (fw_start..fw_start + fw_size)
This worries me a bit, because we never checked that these bounds are reasonable: within the range of the firmware, and not overflowing (.checked_add() for example), that sort of thing.
Thoughts?
drivers/gpu/nova-core/firmware.rs fn no_patch_signature(self) -> FirmwareDmaObject<F, Signed> { · line 217
Quoted 7 lines
drivers/gpu/nova-core/firmware.rs +3
-0+ } +} +pub (crate )struct ModInfoBuilder <const N :usize >(firmware::ModInfoBuilder <N >);impl <const N :usize >ModInfoBuilder <N > {
thanks,
Signature · 1 line
John Hubbard
Alexandre Courbot
maintainerRe: [PATCH v2 2/8] gpu: nova-core: firmware: add support for common firmware header
On Wed Aug 27, 2025 at 10:34 AM JST, John Hubbard wrote:
<snip>
Quoted 8 lines
drivers/gpu/nova-core/firmware.rs fn no_patch_signature(self) -> FirmwareDmaObject<F, Signed> { · line 211
Quoted 7 lines
drivers/gpu/nova-core/firmware.rs +7
-0+/// Returns the data payload of the firmware, or `None` if the data range is out of bounds of +/// the firmware image. +fn data (&self) ->Option <&[u8 ]> { +let fw_start = self.hdr.data_offsetas usize ; +let fw_size = self.hdr.data_sizeas usize ; + + self.fw.get (fw_start..fw_start + fw_size)
Quoted 5 lines
This worries me a bit, because we never checked that these bounds are reasonable: within the range of the firmware, and not overflowing (.checked_add() for example), that sort of thing.
Thoughts?
get returns None if the requested slice is out of bounds, so there should be no risk of panicking here.
However, fw_start + fw_size can panic in debug configuration if it overflows. In a release build I believe it will just happily wrap, and get should consequently return None at the invalid range... Although we can also get unlucky and produce a valid, yet incorrect, one.
This is actually something I've been thinking about while writing this series and could not really decide upon: how to deal with operands and functions in Rust that can potentially panic. Using checked operands everywhere is a bit tedious, and even with great care there is no way to guarantee that no panic occurs in a given function.
Panics are a big no-no in the kernel, yet I don't feel like we have the proper tools to ensure they do not happen.
User-space has some crates like no_panic, but even these feel more like hacks than anything else. Something at the compiler level would be nice.
Maybe that would be a good discussion topic for the Plumber Microconference?
Re: [PATCH v2 2/8] gpu: nova-core: firmware: add support for common firmware header
Quoted 10 lines · Alexandre Courbot
On Wed Aug 27, 2025 at 10:34 AM JST, John Hubbard wrote:
<snip>Quoted 8 lines
Quoted 7 lines
drivers/gpu/nova-core/firmware.rs +7
-0+/// Returns the data payload of the firmware, or `None` if the data range is out of bounds of +/// the firmware image. +fn data (&self) ->Option <&[u8 ]> { +let fw_start = self.hdr.data_offsetas usize ; +let fw_size = self.hdr.data_sizeas usize ; + + self.fw.get (fw_start..fw_start + fw_size)
Quoted 8 lines
Quoted 5 lines
This worries me a bit, because we never checked that these bounds are reasonable: within the range of the firmware, and not overflowing (.checked_add() for example), that sort of thing.
Thoughts?
getreturnsNoneif the requested slice is out of bounds, so there should be no risk of panicking here.
I was wondering about the bounds themselves, though. Couldn't they be wrong? (Do we care?)
Quoted 11 lines
However,
fw_start + fw_sizecan panic in debug configuration if it overflows. In a release build I believe it will just happily wrap, andgetshould consequently returnNoneat the invalid range... Although we can also get unlucky and produce a valid, yet incorrect, one.This is actually something I've been thinking about while writing this series and could not really decide upon: how to deal with operands and functions in Rust that can potentially panic. Using
checkedoperands everywhere is a bit tedious, and even with great care there is no way to guarantee that no panic occurs in a given function.
Yes, .checked_add() all over the place is just awful, would like to avoid that for sure.
Quoted 10 lines
Panics are a big no-no in the kernel, yet I don't feel like we have the proper tools to ensure they do not happen.
User-space has some crates like
no_panic, but even these feel more like hacks than anything else. Something at the compiler level would be nice.Maybe that would be a good discussion topic for the Plumber Microconference?
Yes. And maybe even for Kangrejos.
thanks,
Signature · 1 line
John Hubbard
Alexandre Courbot
maintainerRe: [PATCH v2 2/8] gpu: nova-core: firmware: add support for common firmware header
Quoted 15 lines · John Hubbard
Quoted 14 lines · Alexandre Courbot
On Wed Aug 27, 2025 at 10:34 AM JST, John Hubbard wrote:
<snip>Quoted 12 lines
drivers/gpu/nova-core/firmware.rs fn no_patch_signature(self) -> FirmwareDmaObject<F, Signed> { · line 211
Quoted 7 lines
drivers/gpu/nova-core/firmware.rs +7
-0+/// Returns the data payload of the firmware, or `None` if the data range is out of bounds of +/// the firmware image. +fn data (&self) ->Option <&[u8 ]> { +let fw_start = self.hdr.data_offsetas usize ; +let fw_size = self.hdr.data_sizeas usize ; + + self.fw.get (fw_start..fw_start + fw_size)This worries me a bit, because we never checked that these bounds are reasonable: within the range of the firmware, and not overflowing (.checked_add() for example), that sort of thing.
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
Thoughts?
getreturnsNoneif the requested slice is out of bounds, so there should be no risk of panicking here.I was wondering about the bounds themselves, though. Couldn't they be wrong? (Do we care?)
Not sure what you mean by wrong bounds here? Do you mean what if the header data is incorrect?
Re: [PATCH v2 2/8] gpu: nova-core: firmware: add support for common firmware header
On 8/28/25 12:08 AM, Alexandre Courbot wrote:
...
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
This worries me a bit, because we never checked that these bounds are reasonable: within the range of the firmware, and not overflowing (.checked_add() for example), that sort of thing.
Thoughts?
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
getreturnsNoneif the requested slice is out of bounds, so there should be no risk of panicking here.I was wondering about the bounds themselves, though. Couldn't they be wrong? (Do we care?)
Not sure what you mean by wrong bounds here? Do you mean what if the header data is incorrect?
Yes, that's what I meant. And I'm mainly trying to get some perspective about what kinds of checking we should be doing.
In this case, it seems that we don't actually need anything more than what you already have, so we're all good here.
thanks,
Signature · 1 line
John Hubbard
Re: [PATCH v2 2/8] gpu: nova-core: firmware: add support for common firmware header
In reply to Alexandre CourbotQuoted 3 lines · Alexandre Courbot
However,
fw_start + fw_sizecan panic in debug configuration if it overflows. In a release build I believe it will just happily wrap, and
In the kernel, it is a panic in the default configuration, not just a debug one.
We have debug assertions too -- and those are disabled by default, but they are separate from the overflow checking, which is the one enabled by default.
So, any use of those operators is limited to cases where one knows, somehow, that it will not overflow. And e.g. user-controlled inputs cannot use them at all.
So, conceptually, something like this:
- Static assert if the compiler knows it cannot fail.
- Build assert if the optimizer knows it cannot fail.
- Unfallible (like the possibly panicking operators) if the
developer knows it cannot fail.
- Fallible/wrapping/saturating/... if the developer isn't sure or it
simply cannot be known until runtime. User-derived inputs must use this option (or rarely the unsafe one).
- Unsafe if the developer knows it cannot fail and the other options
are not acceptable for some reason. Ideally paired with a debug assertion (the compiler adds these already for many unsafe preconditions).
In the past I requested upstream Rust a way to have a "third mode" ("report and continue") for the operators so that it would wrap (like the non-panicking mode) but allowing us to add a customization point so that we can e.g. WARN_ON_ONCE.
That would be ideal, because it is a nice middle ground that is not as punishing if a developer gets it wrong, especially for "normal users", where panics typically mean lost reports etc. And other kernel users, like cloud operators, can keep the panicking mode.
As for discussing no-panic, sure!
Cheers,
Miguel
Alexandre Courbot
maintainerRe: Implicit panics (was: [PATCH v2 2/8] gpu: nova-core: firmware: add support for common firmware header)
Hi Miguel, sorry for the delay in replying!
Quoted 29 lines · Miguel Ojeda
Quoted 3 lines · Alexandre Courbot
However,
fw_start + fw_sizecan panic in debug configuration if it overflows. In a release build I believe it will just happily wrap, andIn the kernel, it is a panic in the default configuration, not just a debug one.
We have debug assertions too -- and those are disabled by default, but they are separate from the overflow checking, which is the one enabled by default.
So, any use of those operators is limited to cases where one knows, somehow, that it will not overflow. And e.g. user-controlled inputs cannot use them at all.
So, conceptually, something like this:
- Static assert if the compiler knows it cannot fail.
- Build assert if the optimizer knows it cannot fail.
- Unfallible (like the possibly panicking operators) if the
developer knows it cannot fail.
- Fallible/wrapping/saturating/... if the developer isn't sure or it
simply cannot be known until runtime. User-derived inputs must use this option (or rarely the unsafe one).
- Unsafe if the developer knows it cannot fail and the other options
are not acceptable for some reason. Ideally paired with a debug assertion (the compiler adds these already for many unsafe preconditions).
Quoted 4 lines
In the past I requested upstream Rust a way to have a "third mode" ("report and continue") for the operators so that it would wrap (like the non-panicking mode) but allowing us to add a customization point so that we can e.g.
WARN_ON_ONCE.
That would be nice, but also wouldn't cover all the cases where implicit panics can happen, like out-of-bounds slice accesses - we can't have a "report-and-continue" mode for these.
And that's really the elephant in the room IMHO: such panic sites can be introduced implicitly, without the programmer realizing it, potentially resulting in more runtime panics for Rust modules than one might expect from a language whose main selling point is safety. I understand that the previous sentence is a bit fallacious, since such panics indicate bugs in the code that would likely go unnoticed in C (which is arguably worse). But perception matters, and such crashes can be damaging to the reputation of the project.
In user-space, crates like no_panic can provide a compile-time guarantee that a given function cannot panic. I don't know how that would translate to the kernel, but ideally we could have some support from tooling (compiler and/or LSP?) to warn us of sites introduced in the code. After all, since the compiler inserts these panic sites, it should also be able to tell us where they are, allowing us to evaluate (and hopefully remove) them before the code ships to users. Most of them could then be eliminated by constraining inputs or using checked variants.
I am not suggesting we should mandate that ALL Rust kernel code be proven panic-free at compile time, however since I started writing kernel code in Rust, I've often wished I had a simple way to check whether my carefully-crafted function processing user-space data really *is* panic-free.
Quoted 1 line
As for discussing no-panic, sure!
Writing a uC topic proposal for Plumbers right now. :)
Re: Implicit panics (was: [PATCH v2 2/8] gpu: nova-core: firmware: add support for common firmware header)
Quoted 4 lines · Alexandre Courbot
That would be nice, but also wouldn't cover all the cases where implicit panics can happen, like out-of-bounds slice accesses - we can't have a "report-and-continue" mode for these.
In principle, it could cover OOBs (even if it is a bad idea).
Quoted 1 line
But perception matters, and such crashes can be damaging to the reputation of the project.
Yes, we are well aware -- we have had it in our wish list for upstream Rust for a long time.
We are tackling these things as we go -- e.g. we solved the alloc panics and the ball on the report-and-continue mode for overflows started moving.
Part of Rust for Linux is about making Rust the best language for kernel development it can be, after all, and so far upstream Rust has been quite helpful on giving us the features we need -- we meet with them every two weeks, please join if you have time!
(Side note: the "safety" that Rust "sells" isn't really about avoiding panics, although obviously it would be a nice feature to have.)
Quoted 1 line
Writing a uC topic proposal for Plumbers right now. :)
I see it there, thanks! I can briefly mention the topic in Kangrejos, since we will have Rust representation, including from the language team.
I don't think the discussion should focus much on "Do we need this?" but rather more on "What exactly do we want? Would we be OK with a local solution? Do we need/want a global one? Would we be OK with LSP? Would we be OK with no panics after optimizations, e.g. a link time check? Or do we want full support in the language for guaranteed non-panicking functions? Do we need exceptional carve-outs on such checking for particular language constructs?" and so on. And, of course, "Who has time to write an RFC and implement an experiment upstream if an approach is decided".
Getting data on "in practice, how much of an issue it is on the Rust side" would help too -- those with actual users running Rust kernel code probably can tell us something.
What I would personally expect to happen is that, over time, we understand better what are the worst cases we must tackle.
Cheers,
Miguel
Alexandre Courbot
maintainerRe: Implicit panics (was: [PATCH v2 2/8] gpu: nova-core: firmware: add support for common firmware header)
Quoted 17 lines · Miguel Ojeda
Quoted 4 lines · Alexandre Courbot
That would be nice, but also wouldn't cover all the cases where implicit panics can happen, like out-of-bounds slice accesses - we can't have a "report-and-continue" mode for these.
In principle, it could cover OOBs (even if it is a bad idea).
Quoted 1 line
But perception matters, and such crashes can be damaging to the reputation of the project.
Yes, we are well aware -- we have had it in our wish list for upstream Rust for a long time.
We are tackling these things as we go -- e.g. we solved the
allocpanics and the ball on the report-and-continue mode for overflows started moving.
Quoted 7 lines
Part of Rust for Linux is about making Rust the best language for kernel development it can be, after all, and so far upstream Rust has been quite helpful on giving us the features we need -- we meet with them every two weeks, please join if you have time!
(Side note: the "safety" that Rust "sells" isn't really about avoiding panics, although obviously it would be a nice feature to have.)
That's right, these panics are actually the last line of safety to prevent a program for doing something damaging. It is just that the consequences in a regular program are not as heavy as in the kernel.
The only two options are either allowing user-space to crash the kernel through a module with a missing bound check, or letting it tamper with data it is not supposed to access. While the first option is terrible, the second one is unacceptable - so at the end of the day what we likely want is to keep the panic behavior and limit these occurrences as much as possible through information to the programmer.
Build errors on such panic sites insertions, with the option to relax the rule locally if a justifying SAFETY comment is provided? And as you said, what do we do if a panic can be removed through a particular optimization - does it become mandatory to build the kernel? Is it applicable to all architectures and (in the future) all supported compilers?
I suspect it will take more than Plumbers to get to the bottom of this. :)
Quoted 17 lines
Quoted 2 lines
Writing a uC topic proposal for Plumbers right now. :)
I see it there, thanks! I can briefly mention the topic in Kangrejos, since we will have Rust representation, including from the language team.
I don't think the discussion should focus much on "Do we need this?" but rather more on "What exactly do we want? Would we be OK with a local solution? Do we need/want a global one? Would we be OK with LSP? Would we be OK with no panics after optimizations, e.g. a link time check? Or do we want full support in the language for guaranteed non-panicking functions? Do we need exceptional carve-outs on such checking for particular language constructs?" and so on. And, of course, "Who has time to write an RFC and implement an experiment upstream if an approach is decided".
Quoted 6 lines
Getting data on "in practice, how much of an issue it is on the Rust side" would help too -- those with actual users running Rust kernel code probably can tell us something.
What I would personally expect to happen is that, over time, we understand better what are the worst cases we must tackle.
Thanks, these are great directions to explore. I see that some thinking has already been done on this, do we have a bug or tracking issue so I can catch up with the discussions that have already taken place?
Re: Implicit panics (was: [PATCH v2 2/8] gpu: nova-core: firmware: add support for common firmware header)
Quoted 3 lines · Alexandre Courbot
The only two options are either allowing user-space to crash the kernel through a module with a missing bound check, or letting it tamper with
So we are definitely not aiming to allow that on purpose, i.e. I know you said "missing", but just to clarify: they would of course be considered a bug, just like hitting similar facilities in C code.
(In general, if we get into the situation where we can actually crash the kernel from userspace, that is a CVE with the current rules (modulo exceptional cases, e.g. the recent discussion about debugging tools, for instance), regardless of whether it was due to a Rust panic or not.)
The Rust panic is, as you say, the last line of defense, attempting to limit the damage. I think that is worth it for at least some users that want it (like cloud providers) and some parts of the kernel. Sometimes it can be worse, though, i.e. perhaps the OOB or the overflow was not actually a "big issue" "in practice" for a particular case.
I think it will likely depend on the kind of code we are talking about -- not all panics are the same, and not all code is the same. For random modules, for instance, yes, we should definitely prevent developers from writing panics as much as possible (or not at all); the same way we try to prevent them from writing unsafe code -- after all, panicking operations and unsafe code are both an statement that we are sure "something cannot happen".
So the more we prevent APIs that do not need to rely on panicking (nor unsafe code) on drivers etc., the better.
I also think forcing to have no panics at all (i.e. globally) would force us to handle way more truly impossible cases than C does (unsafely so), which isn't great and has downsides too (increased complexity, for one, which can also lead to more bugs). And we don't want to go memory unsafe for all those either (I mean, it could be an option, but I wouldn't recommend it, and it would still be a bug if hit). So for certain cases panicking may be a reasonable option in practice -- that is where I wanted us to get more experience to know how we fare vs. C here and thus the data request.
It will also depend on what upstream Rust can give us (more on that below). For instance, having an enforced way with carve-outs that need to be annotated would at least make it stand out to reviewers and make developers think thrice.
Quoted 3 lines
Thanks, these are great directions to explore. I see that some thinking has already been done on this, do we have a bug or tracking issue so I can catch up with the discussions that have already taken place?
In general, I do my best to track this kind of thing in the issues linked from issue #2 ("Rust features" in this case:
https://github.com/Rust-for-Linux/linux/issues/354), and you can see some pointers for the overflow part. For no panics there is also an entry for a long time, but I don't think there has been any "deep" discussion on it -- I mean between Rust and the kernel (there are of course discussions in upstream Rust, and there also have been in our side in the mailing list). I just added a couple recent pointers, I can look for more.
In that meeting I mentioned with them, I raised this a month or two ago, and I did so today too, and mentioned that you wanted to discuss it in LPC. If you (or e.g. someone from NVIDIA) have time to work on this, including in upstream Rust (e.g. writing an RFC, implementing an experiment...), then please let me know. They are open to the possibility of having a Rust project goal for the next round on no panics (2026H1), so it is a good chance to move things forward. We had today a discussion on potential forms it could take (an attribute on a function, guaranteed or not, escape hatches or not, lints, an enforced comment, Klint, the report-and-continue feature...) and related ongoing efforts (having a nopanic effect, target_feature(enable =...).
I hope that helps, and thanks!
Cheers,
Miguel
Re: Implicit panics
In reply to Alexandre CourbotQuoted 2 lines · Alexandre Courbot
Quoted 1 line · Miguel Ojeda
On Wed, Sep 10, 2025 at 7:45 AM Alexandre Courbot <[email protected]> wrote:
...> Build errors on such panic sites insertions, with the option to relax
Quoted 5 lines
the rule locally if a justifying SAFETY comment is provided? And as you said, what do we do if a panic can be removed through a particular optimization - does it become mandatory to build the kernel? Is it applicable to all architectures and (in the future) all supported compilers?
We have a very solid precedent for that: building the kernel already requires -O2 optimization for *functional* correctness.
So Rust for Linux certainly can specify a certain set of build options that are required--including options that are normally considered optimizations.
thanks,
Signature · 1 line
John Hubbard
Alexandre Courbot
maintainerPATCH v2 3/8 gpu: nova-core: firmware: process Booter and patch its signature
In reply to Alexandre CourbotThe Booter signed firmware is an essential part of bringing up the GSP on Turing and Ampere. It is loaded on the sec2 falcon core and is responsible for loading and running the RISC-V GSP bootloader into the GSP core.
Add support for parsing the Booter firmware loaded from userspace, patch its signatures, and store it into a form that is ready to be loaded and executed on the sec2 falcon.
We do not run it yet, as its own payload (the GSP bootloader and firmware image) still need to be prepared.
--- drivers/gpu/nova-core/falcon.rs | 4 +- drivers/gpu/nova-core/firmware.rs | 25 ++- drivers/gpu/nova-core/firmware/booter.rs | 356 +++++++++++++++++++++++++++++++ drivers/gpu/nova-core/gpu.rs | 11 +- 4 files changed, 386 insertions(+), 10 deletions(-)
drivers/gpu/nova-core/falcon.rs +2 -2
@@ -293,7 +293,7 @@ pub(crate) trait FalconEngine: }/// Represents a portion of the firmware to be loaded into a particular memory (e.g. IMEM or DMEM). -#[derive( Debug )] +#[derive( Debug , Clone )] pub (crate )struct FalconLoadTarget {/// Offset from the start of the source object to copy from. pub (crate ) src_start:u32 ,
@@ -304,7 +304,7 @@ pub(crate) struct FalconLoadTarget { }/// Parameters for the falcon boot ROM. -#[derive( Debug )] +#[derive( Debug , Clone )] pub (crate )struct FalconBromParams {/// Offset in `DMEM`` of the firmware's signature. pub (crate ) pkc_data_offset:u32 ,
drivers/gpu/nova-core/firmware.rs +19 -6
@@ -6,6 +6,7 @@use core::marker::PhantomData ;use core::mem::size_of; +use booter::BooterFirmware ;use kernel::device;use kernel::firmware;use kernel::prelude::*;
@@ -13,10 +14,13 @@use kernel::transmute::FromBytes ;use crate ::dma::DmaObject ; +use crate ::driver::Bar0 ;use crate ::falcon::FalconFirmware ; +use crate ::falcon::{sec2::Sec2 ,Falcon };use crate ::gpu;use crate ::gpu::Chipset ; +pub (crate )mod booter;pub (crate )mod fwsec;pub (crate )const FIRMWARE_VERSION : &str ="535.113.01" ;
@@ -24,14 +28,22 @@/// Structure encapsulating the firmware blobs required for the GPU to operate. #[expect(dead_code)] pub (crate )struct Firmware { - booter_load: firmware::Firmware , - booter_unload: firmware::Firmware , +/// Runs on the sec2 falcon engine to load and start the GSP bootloader. + booter_loader:BooterFirmware , +/// Runs on the sec2 falcon engine to stop and unload a running GSP firmware. + booter_unloader:BooterFirmware , bootloader: firmware::Firmware , gsp: firmware::Firmware , }impl Firmware { -pub (crate )fn new (dev: &device::Device , chipset:Chipset , ver: &str ) ->Result <Firmware > { +pub (crate )fn new ( + dev: &device::Device <device::Bound >, + sec2: &Falcon <Sec2 >, + bar: &Bar0 , + chipset:Chipset , + ver: &str , + ) ->Result <Firmware > {let mut chip_name =CString ::try_from_fmt (fmt! ("{chipset}" ))?; chip_name.make_ascii_lowercase ();let chip_name = &*chip_name;
@@ -42,8 +54,10 @@ pub(crate) fn new(dev: &device::Device, chipset: Chipset, ver: &str) -> Result<F };Ok (Firmware { - booter_load:request ("booter_load" )?, - booter_unload:request ("booter_unload" )?, + booter_loader:request ("booter_load" ) + .and_then (|fw|BooterFirmware ::new (dev, &fw, sec2, bar))?, + booter_unloader:request ("booter_unload" ) + .and_then (|fw|BooterFirmware ::new (dev, &fw, sec2, bar))?, bootloader:request ("bootloader" )?, gsp:request ("gsp" )?, })
@@ -179,7 +193,6 @@ struct BinFirmware<'a> { fw: &'a [u8], } -#[expect(dead_code)] impl <'a>BinFirmware <'a> {/// Interpret `fw` as a firmware image starting with a [`BinHdr`], and returns the /// corresponding [`BinFirmware`] that can be used to extract its payload.
drivers/gpu/nova-core/firmware/booter.rs new file +356 -0
356 lines not on this page · raw message
drivers/gpu/nova-core/gpu.rs +9 -2
@@ -269,7 +269,6 @@ pub(crate) fn new( ) -> Result<impl PinInit<Self>> {let bar = devres_bar.access (pdev.as_ref ())?;let spec =Spec ::new (bar)?; -let fw =Firmware ::new (pdev.as_ref (), spec.chipset,FIRMWARE_VERSION )?; dev_info!( pdev.as_ref(),
@@ -293,7 +292,15 @@ pub(crate) fn new( )?; gsp_falcon.clear_swgen0_intr (bar); -let _sec2_falcon =Falcon ::<Sec2 >::new (pdev.as_ref (), spec.chipset, bar,true )?; +let sec2_falcon =Falcon ::<Sec2 >::new (pdev.as_ref (), spec.chipset, bar,true )?; + +let fw =Firmware ::new ( + pdev.as_ref (), + &sec2_falcon, + bar, + spec.chipset, +FIRMWARE_VERSION , + )?;let fb_layout =FbLayout ::new (spec.chipset, bar)?;dev_dbg! (pdev.as_ref (),"{:#x?}\n" , fb_layout);
Signature · 1 line
2.50.1
Re: [PATCH v2 3/8] gpu: nova-core: firmware: process Booter and patch its signature
On 8/25/25 9:07 PM, Alexandre Courbot wrote:
...
drivers/gpu/nova-core/firmware/booter.rs line 122
Quoted 8 lines
drivers/gpu/nova-core/firmware/booter.rs new file +8
-0+/// Signature parameters, as defined in the firmware. +#[repr( C )] +struct HsSignatureParams { +// Fuse version to use. + fuse_ver:u32 , +// Mask of engine IDs this firmware applies to. + engine_id_mask:u32 , +// ID of the microcode.
Should these three comments use "///" instead of "//" ?
...> +pub(crate) struct BooterFirmware {
Quoted 16 lines
drivers/gpu/nova-core/firmware/booter.rs new file +16
-0+// Load parameters for `IMEM` falcon memory. + imem_load_target: FalconLoadTarget, +// Load parameters for `DMEM` falcon memory. + dmem_load_target: FalconLoadTarget, +// BROM falcon parameters. + brom_params: FalconBromParams, +// Device-mapped firmware image. + ucode: FirmwareDmaObject<Self, Signed>, +} + +impl FirmwareDmaObject <BooterFirmware ,Unsigned > { +fn new_booter (dev: &device::Device <device::Bound >, data: &[u8 ]) ->Result <Self > { +DmaObject ::from_data (dev, data).map (|ucode|Self (ucode,PhantomData )) + } +} +
drivers/gpu/nova-core/firmware/booter.rs line 253
Quoted 10 lines
drivers/gpu/nova-core/firmware/booter.rs new file +10
-0+impl BooterFirmware { +/// Parses the Booter firmware contained in `fw`, and patches the correct signature so it is +/// ready to be loaded and run on `falcon`. +pub (crate )fn new ( + dev: &device::Device <device::Bound >, + fw: &Firmware , + falcon: &Falcon <<Self as FalconFirmware >::Target >, + bar: &Bar0 , + ) ->Result <Self > { +let bin_fw =BinFirmware ::new (fw)?;
A few newlines for a little visual "vertical relief" would be a welcome break from this wall of text. Maybe one before and after each comment+line, just for this one time here, if that's not too excessive:
here> + // The binary firmware embeds a Heavy-Secured firmware.
Quoted 1 line
+ let
hs_fw=HsFirmwareV2::new(&bin_fw)?;
here> + // The Heavy-Secured firmware embeds a firmware load descriptor.
Quoted 1 line
+ let
load_hdr=HsLoadHeaderV2::new(&hs_fw)?;
here> + // Offset in ucode where to patch the signature.
Quoted 1 line
+ let
patch_loc=hs_fw.patch_location()?;
here> + let sig_params = HsSignatureParams::new(&hs_fw)?;
Quoted 8 lines
drivers/gpu/nova-core/firmware/booter.rs new file +8
-0+let brom_params =FalconBromParams { +// `load_hdr.os_data_offset` is an absolute index, but `pkc_data_offset` is from the +// signature patch location. + pkc_data_offset: patch_loc + .checked_sub (load_hdr.os_data_offset) + .ok_or (EINVAL )?, + engine_id_mask: u16::try_from (sig_params.engine_id_mask).map_err (|_|EINVAL )?, + ucode_id: u8::try_from (sig_params.ucode_id).map_err (|_|EINVAL )?,
drivers/gpu/nova-core/firmware/booter.rs line 278
Quoted 10 lines
drivers/gpu/nova-core/firmware/booter.rs new file +10
-0+ }; +let app0 =HsLoadHeaderV2App ::new (&hs_fw,0 )?; + +// Object containing the firmware microcode to be signature-patched. +let ucode = bin_fw + .data () + .ok_or (EINVAL ) + .and_then (|data|FirmwareDmaObject ::<Self ,_ >::new_booter (dev, data))?; + +let ucode_signed = {
This ucode_signed variable is misnamed...
drivers/gpu/nova-core/firmware/booter.rs line 283
Quoted 5 lines
drivers/gpu/nova-core/firmware/booter.rs new file +5
-0+let mut signatures = hs_fw.signatures_iter ()?.peekable (); + +if signatures.peek ().is_none () { +// If there are no signatures, then the firmware is unsigned. + ucode.no_patch_signature ()
...as we can see here. :)
drivers/gpu/nova-core/firmware/booter.rs line 287
Quoted 4 lines
drivers/gpu/nova-core/firmware/booter.rs new file +4
-0+ }else { +// Obtain the version from the fuse register, and extract the corresponding +// signature. + let reg_fuse_version = falcon.signature_reg_fuse_version(
Oh...I don't want to derail this patch review with a pre-existing problem, but let me mention it anyway so I don't forget: .signature_reg_fuse_version() appears to be unnecessarily HAL-ified. I think.
SEC2 boot flow only applies to Turing, Ampere, Ada, and so unless Timur uncovers a Turing-specific signature_reg_fuse_version(), then I think we'd best delete that entire HAL area and call it directly.
Again, nothing to do with this patch, I'm just looking for a quick sanity check on my first reading of this situation.
drivers/gpu/nova-core/firmware/booter.rs line 295
Quoted 8 lines
drivers/gpu/nova-core/firmware/booter.rs new file +8
-0+ bar, + brom_params.engine_id_mask, + brom_params.ucode_id, + )?; + +let signature =match reg_fuse_version { +// `0` means the last signature should be used. +0 => signatures.last (),
Should we provide a global const, to make this concept a little more self-documenting? Approximately:
const FUSE_VERSION_USE_LAST_SIG: u32 = 0;
Quoted 1 line
+ // Otherwise hardware fuse version needs to be substracted to obtain the index.
typo: "s/substracted/subtracted/"
Quoted 9 lines
drivers/gpu/nova-core/firmware/booter.rs new file +9
-0+ reg_fuse_version => { +let Some (idx) = sig_params.fuse_ver.checked_sub (reg_fuse_version)else { +dev_err! (dev,"invalid fuse version for Booter firmware\n" ); +return Err (EINVAL ); + }; + signatures.nth (idxas usize ) + } + } + .ok_or (EINVAL )?;
drivers/gpu/nova-core/firmware/booter.rs line 315
Quoted 10 lines
drivers/gpu/nova-core/firmware/booter.rs new file +10
-0+ + ucode.patch_signature (&signature, patch_locas usize )? + } + }; + +Ok (Self { + imem_load_target:FalconLoadTarget { + src_start: app0.offset, + dst_start:0 , + len: app0.len,
Should we check that app0.offset.checked_add(app0.len) doesn't cause an out of bounds read?
Quoted 27 lines
drivers/gpu/nova-core/firmware/booter.rs new file +27
-0+ }, + dmem_load_target: FalconLoadTarget { + src_start: load_hdr.os_data_offset, + dst_start: 0, + len: load_hdr.os_data_size, + }, + brom_params, + ucode: ucode_signed, + }) + } +} + +impl FalconLoadParams for BooterFirmware { +fn imem_load_params (&self) ->FalconLoadTarget { + self.imem_load_target.clone () + } + +fn dmem_load_params (&self) ->FalconLoadTarget { + self.dmem_load_target.clone () + } + +fn brom_params (&self) ->FalconBromParams { + self.brom_params.clone () + } + +fn boot_addr (&self) ->u32 { + self.imem_load_target.src_start
drivers/gpu/nova-core/firmware/booter.rs line 352
Quoted 10 lines
drivers/gpu/nova-core/firmware/booter.rs new file +10
-0+ } +} + +impl Deref for BooterFirmware { +type Target =DmaObject ; + +fn deref (&self) -> &Self ::Target { + &self.ucode.0 + } +}
OK, so this allows &BooterFirmware to be used where &DmaObject is expected, but it's not immediately obvious that BooterFirmware derefs to its internal DMA object. It feels too clever...
Could we do something a little more obvious instead? Sort of like this:
impl BooterFirmware {
pub(crate) fn dma_object(&self) -> &DmaObject {
&self.ucode.0
}
}...
I'm out of time today, will work on the other half of the series tomorrow.
thanks,
Signature · 1 line
John Hubbard
Alexandre Courbot
maintainerRe: [PATCH v2 3/8] gpu: nova-core: firmware: process Booter and patch its signature
Quoted 12 lines · John Hubbard
On 8/25/25 9:07 PM, Alexandre Courbot wrote:
...drivers/gpu/nova-core/firmware/booter.rs line 122
Quoted 8 lines
drivers/gpu/nova-core/firmware/booter.rs new file +8
-0+/// Signature parameters, as defined in the firmware. +#[repr( C )] +struct HsSignatureParams { +// Fuse version to use. + fuse_ver:u32 , +// Mask of engine IDs this firmware applies to. + engine_id_mask:u32 , +// ID of the microcode. Should these three comments use "///" instead of "//" ?
Absolutely! Thanks.
Quoted 25 lines
...> +pub(crate) struct BooterFirmware {
Quoted 23 lines
drivers/gpu/nova-core/firmware/booter.rs new file +23
-0+// Load parameters for `IMEM` falcon memory. + imem_load_target: FalconLoadTarget, +// Load parameters for `DMEM` falcon memory. + dmem_load_target: FalconLoadTarget, +// BROM falcon parameters. + brom_params: FalconBromParams, +// Device-mapped firmware image. + ucode: FirmwareDmaObject<Self, Signed>, +} + +impl FirmwareDmaObject <BooterFirmware ,Unsigned > { +fn new_booter (dev: &device::Device <device::Bound >, data: &[u8 ]) ->Result <Self > { +DmaObject ::from_data (dev, data).map (|ucode|Self (ucode,PhantomData )) + } +} + +impl BooterFirmware { +/// Parses the Booter firmware contained in `fw`, and patches the correct signature so it is +/// ready to be loaded and run on `falcon`. +pub (crate )fn new ( + dev: &device::Device <device::Bound >, + fw: &Firmware , + falcon: &Falcon<<Self as FalconFirmware>::Target>,
Quoted 8 lines
drivers/gpu/nova-core/firmware/booter.rs line 253
Quoted 3 lines
drivers/gpu/nova-core/firmware/booter.rs new file +3
-0+ bar: &Bar0, + ) -> Result<Self> { +let bin_fw =BinFirmware ::new (fw)?;A few newlines for a little visual "vertical relief" would be a welcome break from this wall of text. Maybe one before and after each comment+line, just for this one time here, if that's not too excessive:
Indeed, that block was a bit too dense. :)
Quoted 29 lines
here> + // The binary firmware embeds a Heavy-Secured firmware.
Quoted 1 line
+ let
hs_fw=HsFirmwareV2::new(&bin_fw)?;here> + // The Heavy-Secured firmware embeds a firmware load descriptor.
Quoted 1 line
+ let
load_hdr=HsLoadHeaderV2::new(&hs_fw)?;here> + // Offset in
ucodewhere to patch the signature.Quoted 1 line
+ let
patch_loc=hs_fw.patch_location()?;here> + let
sig_params=HsSignatureParams::new(&hs_fw)?;Quoted 8 lines
drivers/gpu/nova-core/firmware/booter.rs new file +8
-0+let brom_params =FalconBromParams { +// `load_hdr.os_data_offset` is an absolute index, but `pkc_data_offset` is from the +// signature patch location. + pkc_data_offset: patch_loc + .checked_sub (load_hdr.os_data_offset) + .ok_or (EINVAL )?, + engine_id_mask: u16::try_from (sig_params.engine_id_mask).map_err (|_|EINVAL )?, + ucode_id: u8::try_from (sig_params.ucode_id).map_err (|_|EINVAL )?,drivers/gpu/nova-core/firmware/booter.rs line 278
Quoted 10 lines
drivers/gpu/nova-core/firmware/booter.rs new file +10
-0+ }; +let app0 =HsLoadHeaderV2App ::new (&hs_fw,0 )?; + +// Object containing the firmware microcode to be signature-patched. +let ucode = bin_fw + .data () + .ok_or (EINVAL ) + .and_then (|data|FirmwareDmaObject ::<Self ,_ >::new_booter (dev, data))?; + +let ucode_signed = {This
ucode_signedvariable is misnamed...
Quoted 7 lines
drivers/gpu/nova-core/firmware/booter.rs line 283
Quoted 5 lines
drivers/gpu/nova-core/firmware/booter.rs new file +5
-0+let mut signatures = hs_fw.signatures_iter ()?.peekable (); + +if signatures.peek ().is_none () { +// If there are no signatures, then the firmware is unsigned. + ucode.no_patch_signature ()...as we can see here. :)
Technically it is of type FirmwareDmaObject<Signed> even if we take to last branch. The name is to confirm that we have taken care of the signature step (even if it is unneeded). Not sure what would be a better name for this.
Quoted 10 lines
drivers/gpu/nova-core/firmware/booter.rs line 287
Quoted 5 lines
drivers/gpu/nova-core/firmware/booter.rs new file +4
-0+ }else { +// Obtain the version from the fuse register, and extract the corresponding +// signature. + let reg_fuse_version = falcon.signature_reg_fuse_version(Oh...I don't want to derail this patch review with a pre-existing problem, but let me mention it anyway so I don't forget: .signature_reg_fuse_version() appears to be unnecessarily HAL-ified. I think.
Quoted 6 lines
SEC2 boot flow only applies to Turing, Ampere, Ada, and so unless Timur uncovers a Turing-specific
signature_reg_fuse_version(), then I think we'd best delete that entire HAL area and call it directly.Again, nothing to do with this patch, I'm just looking for a quick sanity check on my first reading of this situation.
Mmm, you're right - on the other hand I don't think I would have added a HAL method unless I saw at least two different implementations in OpenRM, but of course I am not 100% sure. Let's keep this in mind and simplify it if we see it is indeed unneeded down the road.
Quoted 10 lines
drivers/gpu/nova-core/firmware/booter.rs line 295
Quoted 9 lines
drivers/gpu/nova-core/firmware/booter.rs new file +8
-0+ bar, + brom_params.engine_id_mask, + brom_params.ucode_id, + )?; + +let signature =match reg_fuse_version { +// `0` means the last signature should be used. +0 => signatures.last (),
Quoted 4 lines
Should we provide a global const, to make this concept a little more self-documenting? Approximately:
const
FUSE_VERSION_USE_LAST_SIG: u32 = 0;
Good idea.
Quoted 19 lines
Quoted 2 lines
+ // Otherwise hardware fuse version needs to be substracted to obtain the index.
typo: "s/substracted/subtracted/"
Quoted 14 lines
drivers/gpu/nova-core/firmware/booter.rs new file +14
-0+ reg_fuse_version => { +let Some (idx) = sig_params.fuse_ver.checked_sub (reg_fuse_version)else { +dev_err! (dev,"invalid fuse version for Booter firmware\n" ); +return Err (EINVAL ); + }; + signatures.nth (idxas usize ) + } + } + .ok_or (EINVAL )?; + + ucode.patch_signature (&signature, patch_locas usize )? + } + }; +
Quoted 8 lines
drivers/gpu/nova-core/firmware/booter.rs line 315
Quoted 5 lines
drivers/gpu/nova-core/firmware/booter.rs new file +5
-0+Ok (Self { + imem_load_target:FalconLoadTarget { + src_start: app0.offset, + dst_start:0 , + len: app0.len,Should we check that
app0.offset.checked_add(app0.len)doesn't cause an out of bounds read?
If the data is out of bounds, it will be caught when trying to load the firmware into the falcon engine. I am fine with adding a check here as well if you think it it better.
Quoted 44 lines
Quoted 29 lines
drivers/gpu/nova-core/firmware/booter.rs new file +27
-0+ }, + dmem_load_target: FalconLoadTarget { + src_start: load_hdr.os_data_offset, + dst_start: 0, + len: load_hdr.os_data_size, + }, + brom_params, + ucode: ucode_signed, + }) + } +} + +impl FalconLoadParams for BooterFirmware { +fn imem_load_params (&self) ->FalconLoadTarget { + self.imem_load_target.clone () + } + +fn dmem_load_params (&self) ->FalconLoadTarget { + self.dmem_load_target.clone () + } + +fn brom_params (&self) ->FalconBromParams { + self.brom_params.clone () + } + +fn boot_addr (&self) ->u32 { + self.imem_load_target.src_startdrivers/gpu/nova-core/firmware/booter.rs line 352
Quoted 10 lines
drivers/gpu/nova-core/firmware/booter.rs new file +10
-0+ } +} + +impl Deref for BooterFirmware { +type Target =DmaObject ; + +fn deref (&self) -> &Self ::Target { + &self.ucode.0 + } +}OK, so this allows &BooterFirmware to be used where &DmaObject is expected, but it's not immediately obvious that BooterFirmware derefs to its internal DMA object. It feels too clever...
Quoted 7 lines
Could we do something a little more obvious instead? Sort of like this:
impl BooterFirmware { pub(crate) fn dma_object(&self) -> &DmaObject { &self.ucode.0 } }
Deref<Target = DmaObject> is a requirement of FalconFirmware. That being said, we could turn that into a dma_object method of FalconFirmware, which might be a bit clearer about the intent...
Re: [PATCH v2 3/8] gpu: nova-core: firmware: process Booter and patch its signature
Quoted 13 lines · Alexandre Courbot
Quoted 12 lines · John Hubbard
On 8/25/25 9:07 PM, Alexandre Courbot wrote:
...Quoted 1 line
+ let
ucode_signed= {This
ucode_signedvariable is misnamed...Quoted 5 lines
drivers/gpu/nova-core/firmware/booter.rs new file +5
-0+let mut signatures = hs_fw.signatures_iter ()?.peekable (); + +if signatures.peek ().is_none () { +// If there are no signatures, then the firmware is unsigned. + ucode.no_patch_signature ()
Quoted 6 lines
Quoted 1 line
...as we can see here. :)
Technically it is of type
FirmwareDmaObject<Signed>even if we take to last branch. The name is to confirm that we have taken care of the signature step (even if it is unneeded). Not sure what would be a better name for this.
So the <Signed> parameter naming is also awkward, because it refers to non-signed firmware too, I see. So we need to rename both.
Ideas:
a) ucode_maybe_signed, FirmwareDmaObject<MaybeSigned>
b) ucode_validated, FirmwareDmaObject<Validated>
...
Quoted 11 lines
Quoted 7 lines
Could we do something a little more obvious instead? Sort of like this:
impl BooterFirmware { pub(crate) fn dma_object(&self) -> &DmaObject { &self.ucode.0 } }
Deref<Target = DmaObject>is a requirement ofFalconFirmware. That being said, we could turn that into adma_objectmethod ofFalconFirmware, which might be a bit clearer about the intent...
That does seem clearer to me.
thanks,
Signature · 1 line
John Hubbard
Re: [PATCH v2 3/8] gpu: nova-core: firmware: process Booter and patch its signature
In reply to Alexandre CourbotQuoted 14 lines · Alexandre Courbot
+struct HsHeaderV2 {
+ /// Offset to the start of the signatures.
+sig_prod_offset: u32,
+ /// Size in bytes of the signatures.
+sig_prod_size: u32,
+ /// Offset to au32containing the location at which to patch the signature in the microcode
+ /// image.
+patch_loc: u32,
+ /// Offset to au32containing the index of the signature to patch. +patch_sig: u32,
+ /// Start offset to the signature metadata.
+meta_data_offset: u32,
+ /// Size in bytes of the signature metadata.
Quoted 8 lines
+
meta_data_size: u32,
+ /// Offset to au32containing the number of signatures in the signatures section. +num_sig: u32,
+ /// Offset of the application-specific header.
+header_offset: u32,
+ /// Size in bytes of the application-specific header.
+header_size: u32,
+}
You are inconsistent with the names of offset fields in this struct.
patch_loc should be patch_loc_offsetpatch_sig should be patch_sig_offsetnum_sig should be num_sig_offset
Alexandre Courbot
maintainerPATCH v2 4/8 gpu: nova-core: firmware: process the GSP bootloader
In reply to Alexandre CourbotThe GSP bootloader is a small RISC-V firmware that is loaded by Booter onto the GSP core and is in charge of loading, validating, and starting the actual GSP firmware.
It is a regular binary firmware file containing a specific header. Create a type holding the DMA-mapped firmware as well as useful information extracted from the header, and hook it into our firmware structure for later use.
--- drivers/gpu/nova-core/firmware.rs | 7 ++- drivers/gpu/nova-core/firmware/riscv.rs | 89 +++++++++++++++++++++++++++++++++ 2 files changed, 94 insertions(+), 2 deletions(-)
drivers/gpu/nova-core/firmware.rs +5 -2
@@ -12,6 +12,7 @@use kernel::prelude::*;use kernel::str::CString ;use kernel::transmute::FromBytes ; +use riscv::RiscvFirmware ;use crate ::dma::DmaObject ;use crate ::driver::Bar0 ;
@@ -22,6 +23,7 @@pub (crate )mod booter;pub (crate )mod fwsec; +pub (crate )mod riscv;pub (crate )const FIRMWARE_VERSION : &str ="535.113.01" ;
@@ -32,7 +34,8 @@ pub(crate) struct Firmware { booter_loader: BooterFirmware,/// Runs on the sec2 falcon engine to stop and unload a running GSP firmware. booter_unloader: BooterFirmware, - bootloader: firmware::Firmware, +/// GSP bootloader, verifies the GSP firmware before loading and running it. + gsp_bootloader: RiscvFirmware, gsp: firmware::Firmware, }
@@ -58,7 +61,7 @@ pub(crate) fn new( .and_then(|fw| BooterFirmware::new(dev, &fw, sec2, bar))?, booter_unloader: request("booter_unload") .and_then(|fw| BooterFirmware::new(dev, &fw, sec2, bar))?, - bootloader: request("bootloader")?, + gsp_bootloader: request("bootloader").and_then(|fw| RiscvFirmware::new(dev, &fw))?, gsp: request("gsp")?, }) }
drivers/gpu/nova-core/firmware/riscv.rs new file +89 -0
89 lines not on this page · raw message
Signature · 1 line
2.50.1
Re: [PATCH v2 4/8] gpu: nova-core: firmware: process the GSP bootloader
Quoted 9 lines · Alexandre Courbot
The GSP bootloader is a small RISC-V firmware that is loaded by Booter onto the GSP core and is in charge of loading, validating, and starting the actual GSP firmware.
It is a regular binary firmware file containing a specific header. Create a type holding the DMA-mapped firmware as well as useful information extracted from the header, and hook it into our firmware structure for later use.
Quoted 6 lines
Signed-off-by Alexandre Courbot <[email protected]>--- drivers/gpu/nova-core/firmware.rs | 7 ++- drivers/gpu/nova-core/firmware/riscv.rs | 89 +++++++++++++++++++++++++++++++++ 2 files changed, 94 insertions(+), 2 deletions(-)
I've once again failed to find any problems with the code itself, and have instead listed one or two trivial documentation suggestions, below. :)
Quoted 45 lines
drivers/gpu/nova-core/firmware.rs +5
-2@@ -12,6 +12,7 @@use kernel::prelude::*;use kernel::str::CString ;use kernel::transmute::FromBytes ; +use riscv::RiscvFirmware ;use crate ::dma::DmaObject ;use crate ::driver::Bar0 ;@@ -22,6 +23,7 @@pub (crate )mod booter;pub (crate )mod fwsec; +pub (crate )mod riscv;pub (crate )const FIRMWARE_VERSION : &str ="535.113.01" ;@@ -32,7 +34,8 @@ pub(crate) struct Firmware { booter_loader: BooterFirmware,/// Runs on the sec2 falcon engine to stop and unload a running GSP firmware. booter_unloader: BooterFirmware, - bootloader: firmware::Firmware, +/// GSP bootloader, verifies the GSP firmware before loading and running it. + gsp_bootloader: RiscvFirmware, gsp: firmware::Firmware, }@@ -58,7 +61,7 @@ pub(crate) fn new( .and_then(|fw| BooterFirmware::new(dev, &fw, sec2, bar))?, booter_unloader: request("booter_unload") .and_then(|fw| BooterFirmware::new(dev, &fw, sec2, bar))?, - bootloader: request("bootloader")?, + gsp_bootloader: request("bootloader").and_then(|fw| RiscvFirmware::new(dev, &fw))?, gsp: request("gsp")?, }) }drivers/gpu/nova-core/firmware/riscv.rs new file +0
-0
drivers/gpu/nova-core/firmware/riscv.rs line 3
Quoted 3 lines
drivers/gpu/nova-core/firmware/riscv.rs new file +3
-0@@ -0,0 +1,89 @@ +// SPDX-License-Identifier: GPL-2.0 + +//! Support for firmware binaries designed to run on a RISC-V cores. Such firmwares have a
typo: s/cores/core/
Also, as long as we're here: "Such firmwares" is understandable, but "Such firmware files" is better.
Quoted 55 lines
drivers/gpu/nova-core/firmware/riscv.rs new file +55
-0+//! dedicated header. + +use kernel::device; +use kernel::firmware::Firmware ; +use kernel::prelude::*; +use kernel::transmute::FromBytes ; + +use crate ::dma::DmaObject ; +use crate ::firmware::BinFirmware ; + +/// Descriptor for microcode running on a RISC-V core. +#[repr( C )] +#[derive( Debug )] +struct RmRiscvUCodeDesc { + version:u32 , + bootloader_offset:u32 , + bootloader_size:u32 , + bootloader_param_offset:u32 , + bootloader_param_size:u32 , + riscv_elf_offset:u32 , + riscv_elf_size:u32 , + app_version:u32 , + manifest_offset:u32 , + manifest_size:u32 , + monitor_data_offset:u32 , + monitor_data_size:u32 , + monitor_code_offset:u32 , + monitor_code_size:u32 , +} + +// SAFETY: all bit patterns are valid for this type, and it doesn't use interior mutability. +unsafe impl FromBytes for RmRiscvUCodeDesc {} + +impl RmRiscvUCodeDesc { +/// Interprets the header of `bin_fw` as a [`RmRiscvUCodeDesc`] and returns it. +/// +/// Fails if the header pointed at by `bin_fw` is not within the bounds of the firmware image. +fn new (bin_fw: &BinFirmware <'_>) ->Result <Self > { +let offset = bin_fw.hdr.header_offsetas usize ; + + bin_fw + .fw + .get (offset..offset +size_of ::<Self >()) + .and_then (Self ::from_bytes_copy) + .ok_or (EINVAL ) + } +} + +/// A parsed firmware for a RISC-V core, ready to be loaded and run. +#[expect(unused)] +pub (crate )struct RiscvFirmware { +/// Offset at which the code starts in the firmware image. + code_offset:u32 , +/// Offset at which the data starts in the firmware image. + data_offset:u32 ,
drivers/gpu/nova-core/firmware/riscv.rs line 68
Quoted 10 lines
drivers/gpu/nova-core/firmware/riscv.rs new file +10
-0+/// Offset at which the manifest starts in the firmware image. + manifest_offset: u32, +/// Application version. + app_version: u32, +/// Device-mapped firmware image. + ucode: DmaObject, +} + +impl RiscvFirmware { +// Parses the RISC-V firmware image contained in `fw`.
Should this be a "///" comment?
Quoted 12 lines
drivers/gpu/nova-core/firmware/riscv.rs new file +11
-0+pub (crate )fn new (dev: &device::Device <device::Bound >, fw: &Firmware ) ->Result <Self > { +let bin_fw =BinFirmware ::new (fw)?; + +let riscv_desc =RmRiscvUCodeDesc ::new (&bin_fw)?; + +let ucode = { +let start = bin_fw.hdr.data_offsetas usize ; +let len = bin_fw.hdr.data_sizeas usize ; + +DmaObject ::from_data (dev, fw.data ().get (start..start + len).ok_or (EINVAL )?)? + };
drivers/gpu/nova-core/firmware/riscv.rs line 89
Quoted 10 lines
drivers/gpu/nova-core/firmware/riscv.rs new file +10
-0+ +Ok (Self { + ucode, + code_offset: riscv_desc.monitor_code_offset, + data_offset: riscv_desc.monitor_data_offset, + manifest_offset: riscv_desc.manifest_offset, + app_version: riscv_desc.app_version, + }) + } +}
thanks,
Signature · 1 line
John Hubbard
Alexandre Courbot
maintainerPATCH v2 5/8 gpu: nova-core: firmware: process and prepare the GSP firmware
In reply to Alexandre CourbotThe GSP firmware is a binary blob that is verified, loaded, and run by the GSP bootloader. Its presentation is a bit peculiar as the GSP bootloader expects to be given a DMA address to a 3-levels page table mapping the GSP firmware at address 0 of its own address space.
Prepare such a structure containing the DMA-mapped firmware as well as the DMA-mapped page tables, and a way to obtain the DMA handle of the level 0 page table.
As we are performing the required ELF section parsing and radix3 page table building, remove these items from the TODO file.
--- Documentation/gpu/nova/core/todo.rst | 17 ----- drivers/gpu/nova-core/firmware.rs | 110 +++++++++++++++++++++++++++++++- drivers/gpu/nova-core/firmware/gsp.rs | 117 ++++++++++++++++++++++++++++++++++ drivers/gpu/nova-core/gsp.rs | 4 ++ drivers/gpu/nova-core/nova_core.rs | 1 + 5 files changed, 229 insertions(+), 20 deletions(-)
Documentation/gpu/nova/core/todo.rst +0 -17
@@ -229,23 +229,6 @@ Rust abstraction for debugfs APIs. GPU (general) ============= -Parse firmware headers ----------------------- - -Parse ELF headers from the firmware files loaded from the filesystem. - -| Reference: ELF utils -| Complexity: Beginner -| Contact: Abdiel Janulgue - -Build radix3 page table ------------------------ - -Build the radix3 page table to map the firmware. - -| Complexity: Intermediate -| Contact: Abdiel Janulgue - Initial Devinit support -----------------------
drivers/gpu/nova-core/firmware.rs +107 -3
147 lines not on this page · raw message
drivers/gpu/nova-core/firmware/gsp.rs new file +117 -0
117 lines not on this page · raw message
drivers/gpu/nova-core/gsp.rs new file +4 -0
@@ -0,0 +1,4 @@ +// SPDX-License-Identifier: GPL-2.0 + +pub (crate )const GSP_PAGE_SHIFT :usize =12 ; +pub (crate )const GSP_PAGE_SIZE :usize =1 <<GSP_PAGE_SHIFT ;
drivers/gpu/nova-core/nova_core.rs +1 -0
@@ -9,6 +9,7 @@mod firmware;mod gfw;mod gpu; +mod gsp;mod regs;mod util;mod vbios;
Signature · 1 line
2.50.1
Re: [PATCH v2 5/8] gpu: nova-core: firmware: process and prepare the GSP firmware
Quoted 12 lines · Alexandre Courbot
The GSP firmware is a binary blob that is verified, loaded, and run by the GSP bootloader. Its presentation is a bit peculiar as the GSP bootloader expects to be given a DMA address to a 3-levels page table mapping the GSP firmware at address 0 of its own address space.
Prepare such a structure containing the DMA-mapped firmware as well as the DMA-mapped page tables, and a way to obtain the DMA handle of the level 0 page table.
As we are performing the required ELF section parsing and radix3 page table building, remove these items from the TODO file.
Quoted 8 lines
Signed-off-by Alexandre Courbot <[email protected]>--- Documentation/gpu/nova/core/todo.rst | 17 ----- drivers/gpu/nova-core/firmware.rs | 110 +++++++++++++++++++++++++++++++- drivers/gpu/nova-core/firmware/gsp.rs | 117 ++++++++++++++++++++++++++++++++++ drivers/gpu/nova-core/gsp.rs | 4 ++ drivers/gpu/nova-core/nova_core.rs | 1 + 5 files changed, 229 insertions(+), 20 deletions(-)
Code looks good. Or more accurately, it's working on my machine, and I think I understand it, aside from the SG Table internals.
The documentation on the whole "radix 3" aspect is too light though, so I've created some that you can add in if you agree with it.
...
Quoted 1 line
drivers/gpu/nova-core/firmware/gsp.rs +0
-0
...
drivers/gpu/nova-core/firmware/gsp.rs line 14
Quoted 2 lines
drivers/gpu/nova-core/firmware/gsp.rs +2
-0+/// A device-mapped firmware with a set of (also device-mapped) pages tables mapping the firmware +/// to the start of their own address space, also known as a `Radix3` firmware.
I'd like to replace the above two lines with something like this:
/// GSP firmware with 3-level radix page tables for the GSP bootloader.
///
/// The bootloader expects firmware to be mapped starting at address 0 in GSP's virtual address /// space:
///
/// ```text
/// Level 0: 1 page, 1 entry -> points to first level 1 page /// Level 1: Multiple pages/entries -> each entry points to a level 2 page /// Level 2: Multiple pages/entries -> each entry points to a firmware page
/// ```
///
/// Each page is 4KB, each entry is 8 bytes (64-bit DMA address). /// Also known as "Radix3" firmware.
drivers/gpu/nova-core/firmware/gsp.rs line 16
Quoted 2 lines
drivers/gpu/nova-core/firmware/gsp.rs +2
-0+#[pin_data] +pub (crate )struct GspFirmware {
And then a slightly higher-level set of inline comments will help developers, I think:
drivers/gpu/nova-core/firmware/gsp.rs line 20
Quoted 4 lines
drivers/gpu/nova-core/firmware/gsp.rs +4
-0+/// The GSP firmware inside a [`VVec`], device-mapped via a SG table. +#[pin] + fw: SGTable<Owned<VVec<u8>>>, +/// The level 2 page table, mapping [`Self::fw`] at its beginning.
Instead, how about:
/// Level 2 page table(s) whose entries contain DMA addresses of firmware pages.
drivers/gpu/nova-core/firmware/gsp.rs line 23
Quoted 3 lines
drivers/gpu/nova-core/firmware/gsp.rs +3
-0+#[pin] + lvl2: SGTable<Owned<VVec<u8>>>, +/// The level 1 page table, mapping [`Self::lvl2`] at its beginning.
/// Level 1 page table(s) whose entries contain DMA addresses of level 2 pages.
drivers/gpu/nova-core/firmware/gsp.rs line 26
Quoted 3 lines
drivers/gpu/nova-core/firmware/gsp.rs +3
-0+#[pin] + lvl1: SGTable<Owned<VVec<u8>>>, +/// The level 0 page table, mapping [`Self::lvl1`] at its beginning.
/// Level 0 page table (single 4KB page) with one entry: DMA address of first level 1 page.
Quoted 15 lines
drivers/gpu/nova-core/firmware/gsp.rs +15
-0+ lvl0: DmaObject, +/// Size in bytes of the firmware contained in [`Self::fw`]. + pub size: usize, +} + +impl GspFirmware { +/// Maps the GSP firmware image `fw` into `dev`'s address-space, and creates the page tables +/// expected by the GSP bootloader to load it. +pub (crate )fn new <'a>( + dev: &'a device::Device <device::Bound >, + fw: &'a [u8 ], + ) ->impl PinInit <Self ,Error > + 'a { +try_pin_init! (&this inSelf { + fw <- { +// Move the firmware into a vmalloc'd vector and map it into the device address
drivers/gpu/nova-core/firmware/gsp.rs line 51
Quoted 10 lines
drivers/gpu/nova-core/firmware/gsp.rs +10
-0+// space. +VVec ::with_capacity (fw.len (),GFP_KERNEL ) + .and_then (|mut v| { + v.extend_from_slice (fw,GFP_KERNEL )?; +Ok (v) + }) + .map_err (|_|ENOMEM ) + .map (|v|SGTable ::new (dev, v,DataDirection ::ToDevice ,GFP_KERNEL ))? + }, + lvl2 <- {
Why must we use a strange vowel-removal algorithm for these vrbl nms? I'll let you have a few extra characters and you can spell out "level2"...
Quoted 43 lines
drivers/gpu/nova-core/firmware/gsp.rs +43
-0+// Allocate the level 2 page table, map the firmware onto it, and map it into the +// device address space. +// SAFETY: `this` is a valid pointer, and `fw` has been initialized. +let fw_sg_table =unsafe { &(*this.as_ptr ()).fw }; +VVec ::<u8 >::with_capacity ( + fw_sg_table.iter ().count () * core::mem::size_of ::<u64 >(), +GFP_KERNEL , + ) + .map_err (|_|ENOMEM ) + .and_then (|lvl2|map_into_lvl (fw_sg_table, lvl2)) + .map (|lvl2|SGTable ::new (dev, lvl2,DataDirection ::ToDevice ,GFP_KERNEL ))? + }, + lvl1 <- { +// Allocate the level 1 page table, map the level 2 page table onto it, and map it +// into the device address space. +// SAFETY: `this` is a valid pointer, and `lvl2` has been initialized. +let lvl2_sg_table =unsafe { &(*this.as_ptr ()).lvl2 }; +VVec ::<u8 >::with_capacity ( + lvl2_sg_table.iter ().count () * core::mem::size_of ::<u64 >(), +GFP_KERNEL , + ) + .map_err (|_|ENOMEM ) + .and_then (|lvl1|map_into_lvl (lvl2_sg_table, lvl1)) + .map (|lvl1|SGTable ::new (dev, lvl1,DataDirection ::ToDevice ,GFP_KERNEL ))? + }, + lvl0: { + // Allocate the level 0 page table as a device-visible DMA object, and map the + // level 1 page table onto it. + // SAFETY: `this` is a valid pointer, and `lvl1` has been initialized. + let lvl1_sg_table = unsafe { &(*this.as_ptr()).lvl1 }; +let mut lvl0 =DmaObject ::new (dev,GSP_PAGE_SIZE )?; +// SAFETY: we are the only owner of this newly-created object, making races +// impossible. +let lvl0_slice =unsafe { lvl0.as_slice_mut (0 ,GSP_PAGE_SIZE ) }?; + lvl0_slice[0 ..core::mem::size_of ::<u64 >()].copy_from_slice ( +#[allow(clippy::useless_conversion)] + &(u64::from (lvl1_sg_table.iter ().next ().unwrap ().dma_address ())).to_le_bytes (), + ); + + lvl0 + }, + size: fw.len(), + })
drivers/gpu/nova-core/firmware/gsp.rs line 104
Quoted 10 lines
drivers/gpu/nova-core/firmware/gsp.rs +10
-0+ } + +#[expect(unused)] +/// Returns the DMA handle of the level 0 page table. +pub (crate )fn lvl0_dma_handle (&self) ->DmaAddress { + self.lvl0.dma_handle () + } +} + +/// Create a linear mapping the device mapping of the buffer described by `sg_table` into `dst`.
How about this:
/// Build a page table from a scatter-gather list.
///
/// Takes each DMA-mapped region from sg_table and writes page table entries /// for all 4KB pages within that region. For example, a 16KB SG entry becomes /// 4 consecutive page table entries.
Quoted 29 lines
drivers/gpu/nova-core/firmware/gsp.rs +13
-0+fn map_into_lvl (sg_table: &SGTable <Owned <VVec <u8 >>>,mut dst:VVec <u8 >) ->Result <VVec <u8 >> { +for sg_entryin sg_table.iter () { +// Number of pages we need to map. +let num_pages = (sg_entry.dma_len ()as usize ).div_ceil (GSP_PAGE_SIZE ); + +for iin 0 ..num_pages { +let entry = sg_entry.dma_address () + (ias u64 *GSP_PAGE_SIZE as u64 ); + dst.extend_from_slice (&entry.to_le_bytes (),GFP_KERNEL )?; + } + } + +Ok (dst) +}drivers/gpu/nova-core/gsp.rs new file +4
-0@@ -0,0 +1,4 @@ +// SPDX-License-Identifier: GPL-2.0 + +pub (crate )const GSP_PAGE_SHIFT :usize =12 ; +pub (crate )const GSP_PAGE_SIZE :usize =1 <<GSP_PAGE_SHIFT ;drivers/gpu/nova-core/nova_core.rs +0
-0
drivers/gpu/nova-core/nova_core.rs line 15
Quoted 7 lines
drivers/gpu/nova-core/nova_core.rs +1
-0@@ -9,6 +9,7 @@mod firmware;mod gfw;mod gpu; +mod gsp;mod regs;mod util;mod vbios;
thanks,
Signature · 1 line
John Hubbard
Alexandre Courbot
maintainerRe: [PATCH v2 5/8] gpu: nova-core: firmware: process and prepare the GSP firmware
Quoted 42 lines · John Hubbard
Quoted 12 lines · Alexandre Courbot
The GSP firmware is a binary blob that is verified, loaded, and run by the GSP bootloader. Its presentation is a bit peculiar as the GSP bootloader expects to be given a DMA address to a 3-levels page table mapping the GSP firmware at address 0 of its own address space.
Prepare such a structure containing the DMA-mapped firmware as well as the DMA-mapped page tables, and a way to obtain the DMA handle of the level 0 page table.
As we are performing the required ELF section parsing and radix3 page table building, remove these items from the TODO file.
Quoted 8 lines
Signed-off-by Alexandre Courbot <[email protected]>--- Documentation/gpu/nova/core/todo.rst | 17 ----- drivers/gpu/nova-core/firmware.rs | 110 +++++++++++++++++++++++++++++++- drivers/gpu/nova-core/firmware/gsp.rs | 117 ++++++++++++++++++++++++++++++++++ drivers/gpu/nova-core/gsp.rs | 4 ++ drivers/gpu/nova-core/nova_core.rs | 1 + 5 files changed, 229 insertions(+), 20 deletions(-)Code looks good. Or more accurately, it's working on my machine, and I think I understand it, aside from the SG Table internals.
The documentation on the whole "radix 3" aspect is too light though, so I've created some that you can add in if you agree with it.
...
Quoted 1 line
drivers/gpu/nova-core/firmware/gsp.rs +0
-0...
drivers/gpu/nova-core/firmware/gsp.rs line 14
Quoted 2 lines
drivers/gpu/nova-core/firmware/gsp.rs +2
-0+/// A device-mapped firmware with a set of (also device-mapped) pages tables mapping the firmware +/// to the start of their own address space, also known as a `Radix3` firmware. I'd like to replace the above two lines with something like this:
/// GSP firmware with 3-level radix page tables for the GSP bootloader.
///
/// The bootloader expects firmware to be mapped starting at address 0 in GSP's virtual address /// space:
///
/// ```text
Quoted 7 lines
/// Level 0: 1 page, 1 entry -> points to first level 1 page /// Level 1: Multiple pages/entries -> each entry points to a level 2 page /// Level 2: Multiple pages/entries -> each entry points to a firmware page/// ```
///
/// Each page is 4KB, each entry is 8 bytes (64-bit DMA address). /// Also known as "Radix3" firmware.
Thanks, this is perfect!
Quoted 15 lines
drivers/gpu/nova-core/firmware/gsp.rs line 16
Quoted 4 lines
drivers/gpu/nova-core/firmware/gsp.rs +2
-0+#[pin_data] +pub (crate )struct GspFirmware {And then a slightly higher-level set of inline comments will help developers, I think:
drivers/gpu/nova-core/firmware/gsp.rs line 20
Quoted 4 lines
drivers/gpu/nova-core/firmware/gsp.rs +4
-0+/// The GSP firmware inside a [`VVec`], device-mapped via a SG table. +#[pin] + fw: SGTable<Owned<VVec<u8>>>, +/// The level 2 page table, mapping [`Self::fw`] at its beginning. Instead, how about:
Quoted 7 lines
/// Level 2 page table(s) whose entries contain DMA addresses of firmware pages.drivers/gpu/nova-core/firmware/gsp.rs line 23
Quoted 3 lines
drivers/gpu/nova-core/firmware/gsp.rs +3
-0+#[pin] + lvl2: SGTable<Owned<VVec<u8>>>, +/// The level 1 page table, mapping [`Self::lvl2`] at its beginning. /// Level 1 page table(s) whose entries contain DMA addresses of level 2 pages.
Looking good. But isn't it singular "table"? We have one table, with potentialy several pages, but each page is not a table in itself IIUC.
Quoted 27 lines
drivers/gpu/nova-core/firmware/gsp.rs line 26
Quoted 4 lines
drivers/gpu/nova-core/firmware/gsp.rs +3
-0+#[pin] + lvl1: SGTable<Owned<VVec<u8>>>, +/// The level 0 page table, mapping [`Self::lvl1`] at its beginning. /// Level 0 page table (single 4KB page) with one entry: DMA address of first level 1 page.Quoted 20 lines
drivers/gpu/nova-core/firmware/gsp.rs +20
-0+ lvl0: DmaObject, +/// Size in bytes of the firmware contained in [`Self::fw`]. + pub size: usize, +} + +impl GspFirmware { +/// Maps the GSP firmware image `fw` into `dev`'s address-space, and creates the page tables +/// expected by the GSP bootloader to load it. +pub (crate )fn new <'a>( + dev: &'a device::Device <device::Bound >, + fw: &'a [u8 ], + ) ->impl PinInit <Self ,Error > + 'a { +try_pin_init! (&this inSelf { + fw <- { +// Move the firmware into a vmalloc'd vector and map it into the device address +// space. +VVec ::with_capacity (fw.len (),GFP_KERNEL ) + .and_then(|mut v| { + v.extend_from_slice (fw,GFP_KERNEL )?; +Ok (v)
Quoted 8 lines
drivers/gpu/nova-core/firmware/gsp.rs line 51
Quoted 5 lines
drivers/gpu/nova-core/firmware/gsp.rs +5
-0+ }) + .map_err (|_|ENOMEM ) + .map (|v|SGTable ::new (dev, v,DataDirection ::ToDevice ,GFP_KERNEL ))? + }, + lvl2 <- {Why must we use a strange vowel-removal algorithm for these vrbl nms? I'll let you have a few extra characters and you can spell out "level2"...
Yeah, let me spell these fully.
Quoted 57 lines
Quoted 44 lines
drivers/gpu/nova-core/firmware/gsp.rs +43
-0+// Allocate the level 2 page table, map the firmware onto it, and map it into the +// device address space. +// SAFETY: `this` is a valid pointer, and `fw` has been initialized. +let fw_sg_table =unsafe { &(*this.as_ptr ()).fw }; +VVec ::<u8 >::with_capacity ( + fw_sg_table.iter ().count () * core::mem::size_of ::<u64 >(), +GFP_KERNEL , + ) + .map_err (|_|ENOMEM ) + .and_then (|lvl2|map_into_lvl (fw_sg_table, lvl2)) + .map (|lvl2|SGTable ::new (dev, lvl2,DataDirection ::ToDevice ,GFP_KERNEL ))? + }, + lvl1 <- { +// Allocate the level 1 page table, map the level 2 page table onto it, and map it +// into the device address space. +// SAFETY: `this` is a valid pointer, and `lvl2` has been initialized. +let lvl2_sg_table =unsafe { &(*this.as_ptr ()).lvl2 }; +VVec ::<u8 >::with_capacity ( + lvl2_sg_table.iter ().count () * core::mem::size_of ::<u64 >(), +GFP_KERNEL , + ) + .map_err (|_|ENOMEM ) + .and_then (|lvl1|map_into_lvl (lvl2_sg_table, lvl1)) + .map (|lvl1|SGTable ::new (dev, lvl1,DataDirection ::ToDevice ,GFP_KERNEL ))? + }, + lvl0: { + // Allocate the level 0 page table as a device-visible DMA object, and map the + // level 1 page table onto it. + // SAFETY: `this` is a valid pointer, and `lvl1` has been initialized. + let lvl1_sg_table = unsafe { &(*this.as_ptr()).lvl1 }; +let mut lvl0 =DmaObject ::new (dev,GSP_PAGE_SIZE )?; +// SAFETY: we are the only owner of this newly-created object, making races +// impossible. +let lvl0_slice =unsafe { lvl0.as_slice_mut (0 ,GSP_PAGE_SIZE ) }?; + lvl0_slice[0 ..core::mem::size_of ::<u64 >()].copy_from_slice ( +#[allow(clippy::useless_conversion)] + &(u64::from (lvl1_sg_table.iter ().next ().unwrap ().dma_address ())).to_le_bytes (), + ); + + lvl0 + }, + size: fw.len(), + })drivers/gpu/nova-core/firmware/gsp.rs line 104
Quoted 10 lines
drivers/gpu/nova-core/firmware/gsp.rs +10
-0+ } + +#[expect(unused)] +/// Returns the DMA handle of the level 0 page table. +pub (crate )fn lvl0_dma_handle (&self) ->DmaAddress { + self.lvl0.dma_handle () + } +} + +/// Create a linear mapping the device mapping of the buffer described by `sg_table` into `dst`. How about this:
Quoted 5 lines
/// Build a page table from a scatter-gather list.
///
/// Takes each DMA-mapped region fromsg_tableand writes page table entries /// for all 4KB pages within that region. For example, a 16KB SG entry becomes /// 4 consecutive page table entries.
Much better. And I mixed some words in the original message which didn't even make sense to begin with.
Re: [PATCH v2 5/8] gpu: nova-core: firmware: process and prepare the GSP firmware
Quoted 2 lines · Alexandre Courbot
Quoted 1 line · John Hubbard
On 8/25/25 9:07 PM, Alexandre Courbot wrote:
...
Quoted 4 lines
Quoted 1 line
/// Level 1 page table(s) whose entries contain DMA addresses of level 2 pages.Looking good. But isn't it singular "table"? We have one table, with potentialy several pages, but each page is not a table in itself IIUC.
Oops, yes, good catch.
thanks,
Signature · 1 line
John Hubbard
Danilo Krummrich
maintainerRe: [PATCH v2 5/8] gpu: nova-core: firmware: process and prepare the GSP firmware
In reply to Alexandre Courbotdrivers/gpu/nova-core/firmware.rs pub(crate) struct Firmware { · line 127
Quoted 10 lines · Alexandre Courbot
/// Structure encapsulating the firmware blobs required for the GPU to operate. #[expect(dead_code)]
pub(crate) struct Firmware {drivers/gpu/nova-core/firmware.rs +2
-1@@ -36,7 +123,10 @@ pub(crate) struct Firmware { booter_unloader: BooterFirmware,/// GSP bootloader, verifies the GSP firmware before loading and running it. gsp_bootloader: RiscvFirmware, - gsp: firmware::Firmware, +/// GSP firmware. + gsp: Pin<KBox<GspFirmware>>,
Is there a reason why we don't just propagate it through struct Gpu, which uses pin-init already?
You can make Firmware pin_data too and then everything is within the single allocation of struct Gpu.
Alexandre Courbot
maintainerRe: [PATCH v2 5/8] gpu: nova-core: firmware: process and prepare the GSP firmware
Quoted 15 lines · Danilo Krummrich
drivers/gpu/nova-core/firmware.rs pub(crate) struct Firmware { · line 127
Quoted 10 lines · Alexandre Courbot
/// Structure encapsulating the firmware blobs required for the GPU to operate. #[expect(dead_code)]
pub(crate) struct Firmware {drivers/gpu/nova-core/firmware.rs +2
-1@@ -36,7 +123,10 @@ pub(crate) struct Firmware { booter_unloader: BooterFirmware,/// GSP bootloader, verifies the GSP firmware before loading and running it. gsp_bootloader: RiscvFirmware, - gsp: firmware::Firmware, +/// GSP firmware. + gsp: Pin<KBox<GspFirmware>>,Is there a reason why we don't just propagate it through struct Gpu, which uses pin-init already?
Quoted 2 lines
You can make Firmware
pin_datatoo and then everything is within the single allocation of struct Gpu.
I tried doing that at first, and hit the problem that the impl PinInit returned by GspFirmware::new borrows a reference to the GSP firmware binary loaded by Firmware::new - when Firmware::new returns, the firmware gets freed, and the borrow checker complains.
We could move the GSP firmware loading code into the pin_init! of Firmware::new, but now we hit another problem: in Gpu::new the following code is executed:
FbLayout::new(chipset, bar, &fw.gsp_bootloader, &fw.gsp)?
which requires the Firmware instance, which doesn't exist yet as the Gpu object isn't initialized until the end of the method.
So we could move FbLayout, and everything else created by Gpu::new to become members of the Gpu instance. It does make sense actually:
this new method is doing a lot of stuff, such as running FRTS, and with Alistair's series it even runs Booter, the sequencer and so on. Maybe we should move all firmware execution to a separate method that is called by probe after the Gpu is constructed, as right now the Gpu constructor looks like it does a bit more than it should.
... but even when doing that, Firmware::new and FbLayout::new still require a reference to the Bar, and... you get the idea. :)
So I don't think the current design allows us to do that easily or at all, and even if it does, it will be at a significant cost in code clarity. There is also the fact that I am considering making the firmware member of Gpu a trait object: the boot sequence is so different between pre and post-Hopper that I don't think it makes sense to share the same Firmware structure between the two. I would rather see Firmware as an opaque trait object, which provides high-level methods such as "start GSP" behind which the specifics of each GPU family are hidden. If we go with this design, Firmware will become a trait object and so cannot be pinned into Gpu.
This doesn't change my observation that Gpu::new should not IMHO do steps like booting the GSP - it should just acquire the resources it needs, return the pinned GPU object, and then probe can continue the boot sequence. Having the GPU object pinned and constructed early simplifies things quite a bit as the more we progress with boot, the harder it becomes to construct everything in place (and the PinInit closure also becomes more and more complex).
I'm still laying down the general design, but I'm pretty convinced that having Firmware as a trait object is the right way to abstract the differences between GPU families.
Danilo Krummrich
maintainerRe: [PATCH v2 5/8] gpu: nova-core: firmware: process and prepare the GSP firmware
Quoted 16 lines · Alexandre Courbot
Quoted 15 lines · Danilo Krummrich
drivers/gpu/nova-core/firmware.rs pub(crate) struct Firmware { · line 127
Quoted 10 lines · Alexandre Courbot
/// Structure encapsulating the firmware blobs required for the GPU to operate. #[expect(dead_code)] pub(crate) struct Firmware {drivers/gpu/nova-core/firmware.rs +2
-1@@ -36,7 +123,10 @@ pub(crate) struct Firmware { booter_unloader: BooterFirmware,/// GSP bootloader, verifies the GSP firmware before loading and running it. gsp_bootloader: RiscvFirmware, - gsp: firmware::Firmware, +/// GSP firmware. + gsp: Pin<KBox<GspFirmware>>,Is there a reason why we don't just propagate it through struct Gpu, which uses pin-init already?
Quoted 2 lines
Quoted 2 lines
You can make Firmware
pin_datatoo and then everything is within the single allocation of struct Gpu.
Thanks a lot for the write-up below!
Quoted 14 lines
I tried doing that at first, and hit the problem that the
impl PinInitreturned byGspFirmware::newborrows a reference to the GSP firmware binary loaded byFirmware::new- whenFirmware::newreturns, the firmware gets freed, and the borrow checker complains.We could move the GSP firmware loading code into the
pin_init!ofFirmware::new, but now we hit another problem: inGpu::newthe following code is executed:
FbLayout::new(chipset, bar, &fw.gsp_bootloader, &fw.gsp)?which requires the
Firmwareinstance, which doesn't exist yet as theGpuobject isn't initialized until the end of the method.
Quoted 7 lines
So we could move
FbLayout, and everything else created byGpu::newto become members of theGpuinstance. It does make sense actually:
thisnewmethod is doing a lot of stuff, such as running FRTS, and with Alistair's series it even runs Booter, the sequencer and so on. Maybe we should move all firmware execution to a separate method that is called byprobeafter theGpuis constructed, as right now theGpuconstructor looks like it does a bit more than it should.
Absolutely, executing the firmware should be a separate method. Having it in the constructor makes things more difficult.
Quoted 2 lines
... but even when doing that,
Firmware::newandFbLayout::newstill require a reference to theBar, and... you get the idea. :)
Lifetime wise this should be fine, the &Bar out-lives the constructor, since it's lifetime is bound to the &Device<Bound> which lives for the entire duration of probe().
Quoted 19 lines
So I don't think the current design allows us to do that easily or at all, and even if it does, it will be at a significant cost in code clarity. There is also the fact that I am considering making the firmware member of
Gpua trait object: the boot sequence is so different between pre and post-Hopper that I don't think it makes sense to share the sameFirmwarestructure between the two. I would rather seeFirmwareas an opaque trait object, which provides high-level methods such as "start GSP" behind which the specifics of each GPU family are hidden. If we go with this design,Firmwarewill become a trait object and so cannot be pinned intoGpu.This doesn't change my observation that
Gpu::newshould not IMHO do steps like booting the GSP - it should just acquire the resources it needs, return the pinned GPU object, and thenprobecan continue the boot sequence. Having the GPU object pinned and constructed early simplifies things quite a bit as the more we progress with boot, the harder it becomes to construct everything in place (and thePinInitclosure also becomes more and more complex).
Quoted 3 lines
I'm still laying down the general design, but I'm pretty convinced that having
Firmwareas a trait object is the right way to abstract the differences between GPU families.
Makes sense, it's fine with me to keep this in its separate allocation for the purpose of making Firmware an opaque trait object, which sounds reasonable.
But we should really properly separate construction of the GPU structure from firmware boot code execution as you say. And actually move the construction of the GPU object into try_pin_init!().
Alexandre Courbot
maintainerRe: [PATCH v2 5/8] gpu: nova-core: firmware: process and prepare the GSP firmware
Quoted 44 lines · Danilo Krummrich
Quoted 16 lines · Alexandre Courbot
Quoted 15 lines · Danilo Krummrich
drivers/gpu/nova-core/firmware.rs pub(crate) struct Firmware { · line 127
Quoted 10 lines · Alexandre Courbot
/// Structure encapsulating the firmware blobs required for the GPU to operate. #[expect(dead_code)] pub(crate) struct Firmware {drivers/gpu/nova-core/firmware.rs +2
-1@@ -36,7 +123,10 @@ pub(crate) struct Firmware { booter_unloader: BooterFirmware,/// GSP bootloader, verifies the GSP firmware before loading and running it. gsp_bootloader: RiscvFirmware, - gsp: firmware::Firmware, +/// GSP firmware. + gsp: Pin<KBox<GspFirmware>>,Is there a reason why we don't just propagate it through struct Gpu, which uses pin-init already?
Quoted 2 lines
Quoted 2 lines
You can make Firmware
pin_datatoo and then everything is within the single allocation of struct Gpu.Thanks a lot for the write-up below!
Quoted 14 lines
I tried doing that at first, and hit the problem that the
impl PinInitreturned byGspFirmware::newborrows a reference to the GSP firmware binary loaded byFirmware::new- whenFirmware::newreturns, the firmware gets freed, and the borrow checker complains.We could move the GSP firmware loading code into the
pin_init!ofFirmware::new, but now we hit another problem: inGpu::newthe following code is executed:
FbLayout::new(chipset, bar, &fw.gsp_bootloader, &fw.gsp)?which requires the
Firmwareinstance, which doesn't exist yet as theGpuobject isn't initialized until the end of the method.Quoted 7 lines
So we could move
FbLayout, and everything else created byGpu::newto become members of theGpuinstance. It does make sense actually:
thisnewmethod is doing a lot of stuff, such as running FRTS, and with Alistair's series it even runs Booter, the sequencer and so on. Maybe we should move all firmware execution to a separate method that is called byprobeafter theGpuis constructed, as right now theGpuconstructor looks like it does a bit more than it should.
Quoted 8 lines
Absolutely, executing the firmware should be a separate method. Having it in the constructor makes things more difficult.
Quoted 2 lines
... but even when doing that,
Firmware::newandFbLayout::newstill require a reference to theBar, and... you get the idea. :)Lifetime wise this should be fine, the &Bar out-lives the constructor, since it's lifetime is bound to the &Device<Bound> which lives for the entire duration of
probe().
The &Bar is actually obtained inside the constructor (which is passed the Arc<Devres<Bar0>>), so I don't think that would even work without more clever tricks. :)
Quoted 23 lines
Quoted 19 lines
So I don't think the current design allows us to do that easily or at all, and even if it does, it will be at a significant cost in code clarity. There is also the fact that I am considering making the firmware member of
Gpua trait object: the boot sequence is so different between pre and post-Hopper that I don't think it makes sense to share the sameFirmwarestructure between the two. I would rather seeFirmwareas an opaque trait object, which provides high-level methods such as "start GSP" behind which the specifics of each GPU family are hidden. If we go with this design,Firmwarewill become a trait object and so cannot be pinned intoGpu.This doesn't change my observation that
Gpu::newshould not IMHO do steps like booting the GSP - it should just acquire the resources it needs, return the pinned GPU object, and thenprobecan continue the boot sequence. Having the GPU object pinned and constructed early simplifies things quite a bit as the more we progress with boot, the harder it becomes to construct everything in place (and thePinInitclosure also becomes more and more complex).Quoted 3 lines
I'm still laying down the general design, but I'm pretty convinced that having
Firmwareas a trait object is the right way to abstract the differences between GPU families.
Quoted 6 lines
Makes sense, it's fine with me to keep this in its separate allocation for the purpose of making Firmware an opaque trait object, which sounds reasonable.
But we should really properly separate construction of the GPU structure from firmware boot code execution as you say. And actually move the construction of the GPU object into try_pin_init!().
Yes, and I'm glad you agree with this idea as the current design of putting everything inside the GPU is a bit limiting.
Regarding the firmware, I also think this should undergo a redesign - right now we are putting unrelated stuff inside the Firmware structure, and this won't scale well when we start supporting Hopper+ which use a very different way to start the GSP.
I'll give more details in my review of Alistair's series, and hopefully send a v3 with some of these ideas implemented soon.
Alexandre Courbot
maintainerPATCH v2 6/8 gpu: nova-core: firmware: use 570.144 firmware
In reply to Alexandre Courbot570.144 is the latest available into linux-firmware as of this commit, and the one we will use to start development of nova-core. It should eventually be dropped for a newer version before the driver becomes able to do anything useful. The newer firmware is expected to iron out some of the inelegances of 570.144, notably related to packaging.
--- drivers/gpu/nova-core/firmware.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/nova-core/firmware.rs +1 -1
@@ -27,7 +27,7 @@pub (crate )mod gsp;pub (crate )mod riscv; -pub (crate )const FIRMWARE_VERSION : &str ="535.113.01" ; +pub (crate )const FIRMWARE_VERSION : &str ="570.144" ;/// Ad-hoc and temporary module to extract sections from ELF images. ///
Signature · 1 line
2.50.1
Re: [PATCH v2 6/8] gpu: nova-core: firmware: use 570.144 firmware
Quoted 10 lines · Alexandre Courbot
570.144 is the latest available into linux-firmware as of this commit, and the one we will use to start development of nova-core. It should eventually be dropped for a newer version before the driver becomes able to do anything useful. The newer firmware is expected to iron out some of the inelegances of 570.144, notably related to packaging.
Signed-off-by Alexandre Courbot <[email protected]>--- drivers/gpu/nova-core/firmware.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 7 lines
drivers/gpu/nova-core/firmware.rs +0
-0
drivers/gpu/nova-core/firmware.rs line 33
Quoted 8 lines
drivers/gpu/nova-core/firmware.rs +1
-1@@ -27,7 +27,7 @@pub (crate )mod gsp;pub (crate )mod riscv; -pub (crate )const FIRMWARE_VERSION : &str ="535.113.01" ; +pub (crate )const FIRMWARE_VERSION : &str ="570.144" ;/// Ad-hoc and temporary module to extract sections from ELF images. ///
thanks,
Signature · 1 line
John Hubbard
Alexandre Courbot
maintainerPATCH v2 7/8 gpu: nova-core: Add base files for r570.144 firmware bindings
In reply to Alexandre CourbotFrom: Alistair Popple <[email protected]>
Interacting with the GSP currently requires using definitions from C header files. Rust definitions for the types needed for Nova core will be generated using the Rust bindgen tool. This patch adds the base module to allow inclusion of the generated bindings. The generated bindings themselves are added by subsequent patches when they are first used.
Currently we only intend to support a single firmware version, 570.144, with these bindings. Longer term we intend to move to a more stable GSP interface that isn't tied to specific firmware versions.
[[email protected]: adapt the bindings module comment a bit.]
--- drivers/gpu/nova-core/nova_core.rs | 1 + drivers/gpu/nova-core/nvfw.rs | 3 +++ drivers/gpu/nova-core/nvfw/r570_144.rs | 29 +++++++++++++++++++++++++ drivers/gpu/nova-core/nvfw/r570_144_bindings.rs | 1 + 4 files changed, 34 insertions(+)
drivers/gpu/nova-core/nova_core.rs +1 -0
@@ -10,6 +10,7 @@mod gfw;mod gpu;mod gsp; +mod nvfw;mod regs;mod util;mod vbios;
drivers/gpu/nova-core/nvfw.rs new file +3 -0
@@ -0,0 +1,3 @@ +// SPDX-License-Identifier: GPL-2.0 + +mod r570_144;
drivers/gpu/nova-core/nvfw/r570_144.rs new file +29 -0
@@ -0,0 +1,29 @@ +// SPDX-License-Identifier: GPL-2.0 + +//! Firmware bindings. +//! +//! Imports the generated bindings by `bindgen`. +//! +//! This module may not be directly used. Please abstract or re-export the needed symbols in the +//! parent module instead. + +#![cfg_attr(test, allow(deref_nullptr))] +#![cfg_attr(test, allow(unaligned_references))] +#![cfg_attr(test, allow(unsafe_op_in_unsafe_fn))] +#![allow( +dead_code, +unused_imports, +clippy::all, +clippy::undocumented_unsafe_blocks, +clippy::ptr_as_ptr, +clippy::ref_as_ptr, +missing_docs, +non_camel_case_types, +non_upper_case_globals, +non_snake_case, +improper_ctypes, +unreachable_pub, +unsafe_op_in_unsafe_fn +)] +use kernel::ffi; +include! ("r570_144_bindings.rs" );
drivers/gpu/nova-core/nvfw/r570_144_bindings.rs new file +1 -0
@@ -0,0 +1 @@ +// SPDX-License-Identifier: GPL-2.0
Signature · 1 line
2.50.1
Re: [PATCH v2 7/8] gpu: nova-core: Add base files for r570.144 firmware bindings
Quoted 15 lines · Alexandre Courbot
From: Alistair Popple <[email protected]>
Interacting with the GSP currently requires using definitions from C header files. Rust definitions for the types needed for Nova core will be generated using the Rust bindgen tool. This patch adds the base module to allow inclusion of the generated bindings. The generated bindings themselves are added by subsequent patches when they are first used.
Currently we only intend to support a single firmware version, 570.144, with these bindings. Longer term we intend to move to a more stable GSP interface that isn't tied to specific firmware versions.
[[email protected]: adapt the bindings module comment a bit.]
Quoted 9 lines
Signed-off-by Alistair Popple <[email protected]>Signed-off-by Alexandre Courbot <[email protected]>--- drivers/gpu/nova-core/nova_core.rs | 1 + drivers/gpu/nova-core/nvfw.rs | 3 +++ drivers/gpu/nova-core/nvfw/r570_144.rs | 29 +++++++++++++++++++++++++ drivers/gpu/nova-core/nvfw/r570_144_bindings.rs | 1 + 4 files changed, 34 insertions(+)
thanks,
Signature · 1 line
John Hubbard
Quoted 64 lines
drivers/gpu/nova-core/nova_core.rs +1
-0@@ -10,6 +10,7 @@mod gfw;mod gpu;mod gsp; +mod nvfw;mod regs;mod util;mod vbios;drivers/gpu/nova-core/nvfw.rs new file +3
-0@@ -0,0 +1,3 @@ +// SPDX-License-Identifier: GPL-2.0 + +mod r570_144;drivers/gpu/nova-core/nvfw/r570_144.rs new file +29
-0@@ -0,0 +1,29 @@ +// SPDX-License-Identifier: GPL-2.0 + +//! Firmware bindings. +//! +//! Imports the generated bindings by `bindgen`. +//! +//! This module may not be directly used. Please abstract or re-export the needed symbols in the +//! parent module instead. + +#![cfg_attr(test, allow(deref_nullptr))] +#![cfg_attr(test, allow(unaligned_references))] +#![cfg_attr(test, allow(unsafe_op_in_unsafe_fn))] +#![allow( +dead_code, +unused_imports, +clippy::all, +clippy::undocumented_unsafe_blocks, +clippy::ptr_as_ptr, +clippy::ref_as_ptr, +missing_docs, +non_camel_case_types, +non_upper_case_globals, +non_snake_case, +improper_ctypes, +unreachable_pub, +unsafe_op_in_unsafe_fn +)] +use kernel::ffi; +include! ("r570_144_bindings.rs" );drivers/gpu/nova-core/nvfw/r570_144_bindings.rs new file +1
-0@@ -0,0 +1 @@ +// SPDX-License-Identifier: GPL-2.0
Alexandre Courbot
maintainerPATCH v2 8/8 gpu: nova-core: compute layout of more framebuffer regions required for GSP
In reply to Alexandre CourbotCompute more of the required FB layout information to boot the GSP firmware.
This information is dependent on the firmware itself, so first we need to import and abstract the required firmware bindings in the nvfw module.
Then, a new FB HAL method is introduced in fb::hal that uses these bindings and hardware information to compute the correct layout information.
This information is then used in fb and the result made visible in FbLayout.
These 3 things are grouped into the same patch to avoid lots of unused warnings that would be tedious to work around. As they happen in different files, they should not be too difficult to track separately.
--- drivers/gpu/nova-core/fb.rs | 112 ++++++++++++++++++++- drivers/gpu/nova-core/fb/hal.rs | 4 + drivers/gpu/nova-core/fb/hal/ga100.rs | 6 +- drivers/gpu/nova-core/fb/hal/ga102.rs | 14 ++- drivers/gpu/nova-core/fb/hal/tu102.rs | 14 +++ drivers/gpu/nova-core/firmware.rs | 4 +- drivers/gpu/nova-core/firmware/riscv.rs | 2 +- drivers/gpu/nova-core/gpu.rs | 2 +- drivers/gpu/nova-core/gsp.rs | 3 + drivers/gpu/nova-core/nvfw.rs | 39 ++++++++ drivers/gpu/nova-core/nvfw/r570_144.rs | 1 - drivers/gpu/nova-core/nvfw/r570_144_bindings.rs | 125 ++++++++++++++++++++++++ 12 files changed, 317 insertions(+), 9 deletions(-)
drivers/gpu/nova-core/fb.rs +110 -2
@@ -10,7 +10,11 @@use crate ::dma::DmaObject ;use crate ::driver::Bar0 ; +use crate ::firmware::gsp::GspFirmware ; +use crate ::firmware::riscv::RiscvFirmware ;use crate ::gpu::Chipset ; +use crate ::gsp::GSP_HEAP_ALIGNMENT ; +use crate ::nvfw::{self,LibosParams };use crate ::regs;mod hal;
@@ -81,20 +85,80 @@ pub(crate) fn unregister(&self, bar: &Bar0) { } } +/// Heap memory requirements for the GSP firmware. +pub (crate )struct GspFwHeapParams { +/// Libos parameters in effect. +pub libos: &'staticLibosParams , +/// The amount of heap memory used by GSP-RM boot and initialization, up and including the +/// first client subdevice allocation, in bytes. +pub base_rm_size:u64 , +} + +impl GspFwHeapParams { +/// Returns the amount of memory (in bytes) to allocate for the WPR heap for a framebuffer size +/// of `fb_size` (in bytes). +/// +/// Returns `EOVERFLOW` if the computation overflows. +pub (crate )fn wpr_heap_size (&self, fb_size:u64 ) ->Result <u64 > { +let fb_size_gb = fb_size.div_ceil (SZ_1G as u64 ); + +// The WPR heap will contain the following: +let size = +// LIBOS carveout, + self.libos.carveout_size +// RM boot working memory, + + self.base_rm_size +// One RM client, + + u64::from (nvfw::GSP_FW_HEAP_PARAM_CLIENT_ALLOC_SIZE ) + .align_up (GSP_HEAP_ALIGNMENT ) + .ok_or (EOVERFLOW )? +// Overhead for memory management. + + u64::from (nvfw::GSP_FW_HEAP_PARAM_SIZE_PER_GB_FB ) + .checked_mul (fb_size_gb) + .and_then (|heap_size| heap_size.align_up (GSP_HEAP_ALIGNMENT )) + .ok_or (EOVERFLOW )?; + +// Clamp to the supported heap sizes. +Ok (size.clamp ( + self.libos.allowed_heap_size.start, + self.libos.allowed_heap_size.end -1 , + )) + } +} +/// Layout of the GPU framebuffer memory. /// /// Contains ranges of GPU memory reserved for a given purpose during the GSP boot process. #[derive( Debug )] #[expect(dead_code)] pub (crate )struct FbLayout { +/// Range of the framebuffer. Starts at `0`. pub (crate ) fb:Range <u64 >, +/// VGA workspace, small area of reserved memory at the end of the framebuffer. pub (crate ) vga_workspace:Range <u64 >, +/// FRTS range. pub (crate ) frts:Range <u64 >, +/// Memory area containing the GSP bootloader image. +pub (crate ) boot:Range <u64 >, +/// Memory area containing the GSP firmware image. +pub (crate ) elf:Range <u64 >, +/// WPR2 heap. +pub (crate ) wpr2_heap:Range <u64 >, +// WPR2 region range, starting with an instance of `GspFwWprMeta`. +pub (crate ) wpr2:Range <u64 >, +pub (crate ) heap:Range <u64 >, +pub (crate ) vf_partition_count:u8 , }impl FbLayout { -/// Computes the FB layout. -pub (crate )fn new (chipset:Chipset , bar: &Bar0 ) ->Result <Self > { +/// Computes the FB layout for `chipset`, for running the `bl` GSP bootloader and `gsp` GSP +/// firmware. +pub (crate )fn new ( + chipset:Chipset , + bar: &Bar0 , + bl: &RiscvFirmware , + gsp: &GspFirmware , + ) ->Result <Self > {let hal = hal::fb_hal (chipset);let fb = {
@@ -138,10 +202,54 @@ pub(crate) fn new(chipset: Chipset, bar: &Bar0) -> Result<Self> { frts_base..frts_base +FRTS_SIZE }; +let boot = { +const BOOTLOADER_DOWN_ALIGN :Alignment =Alignment ::new (SZ_4K ); +let bootloader_size = bl.ucode.size ()as u64 ; +let bootloader_base = (frts.start - bootloader_size).align_down (BOOTLOADER_DOWN_ALIGN ); + + bootloader_base..bootloader_base + bootloader_size + }; + +let elf = { +const ELF_DOWN_ALIGN :Alignment =Alignment ::new (SZ_64K ); +let elf_size = gsp.sizeas u64 ; +let elf_addr = (boot.start - elf_size).align_down (ELF_DOWN_ALIGN ); + + elf_addr..elf_addr + elf_size + }; + +let wpr2_heap = { +const WPR2_HEAP_DOWN_ALIGN :Alignment =Alignment ::new (SZ_1M ); +let wpr2_heap_size = hal.heap_params ().wpr_heap_size (fb.end)?; +let wpr2_heap_addr = (elf.start - wpr2_heap_size).align_down (WPR2_HEAP_DOWN_ALIGN ); + + wpr2_heap_addr..(elf.start).align_down (WPR2_HEAP_DOWN_ALIGN ) + }; + +let wpr2 = { +const WPR2_DOWN_ALIGN :Alignment =Alignment ::new (SZ_1M ); +let wpr2_addr = (wpr2_heap.start -size_of ::<nvfw::GspFwWprMeta >()as u64 ) + .align_down (WPR2_DOWN_ALIGN ); + + wpr2_addr..frts.end + }; + +let heap = { +const HEAP_SIZE :u64 =SZ_1M as u64 ; + + wpr2.start -HEAP_SIZE ..wpr2.start + }; +Ok (Self { fb, vga_workspace, frts, + boot, + elf, + wpr2_heap, + wpr2, + heap, + vf_partition_count:0 , }) } }
drivers/gpu/nova-core/fb/hal.rs +4 -0
@@ -3,6 +3,7 @@use kernel::prelude::*;use crate ::driver::Bar0 ; +use crate ::fb::GspFwHeapParams ;use crate ::gpu::Chipset ;mod ga100;
@@ -23,6 +24,9 @@ pub(crate) trait FbHal {/// Returns the VRAM size, in bytes. fn vidmem_size (&self, bar: &Bar0 ) ->u64 ; + +/// Returns the heap memory requirements to start the GSP firmware. +fn heap_params (&self) ->GspFwHeapParams ; }/// Returns the HAL corresponding to `chipset`.
drivers/gpu/nova-core/fb/hal/ga100.rs +5 -1
@@ -5,7 +5,7 @@use kernel::prelude::*;use crate ::driver::Bar0 ; -use crate ::fb::hal::FbHal ; +use crate ::fb::hal::{FbHal ,GspFwHeapParams };use crate ::regs;use super ::tu102::FLUSH_SYSMEM_ADDR_SHIFT ;
@@ -51,6 +51,10 @@ fn supports_display(&self, bar: &Bar0) -> bool {fn vidmem_size (&self, bar: &Bar0 ) ->u64 {super ::tu102::vidmem_size_gp102 (bar) } + +fn heap_params (&self) ->GspFwHeapParams { +super ::tu102::heap_params_tu102 () + } }const GA100 :Ga100 =Ga100 ;
drivers/gpu/nova-core/fb/hal/ga102.rs +13 -1
@@ -3,13 +3,21 @@use kernel::prelude::*;use crate ::driver::Bar0 ; -use crate ::fb::hal::FbHal ; +use crate ::fb::hal::{FbHal ,GspFwHeapParams }; +use crate ::nvfw;use crate ::regs;fn vidmem_size_ga102 (bar: &Bar0 ) ->u64 { regs::NV_USABLE_FB_SIZE_IN_MB ::read (bar).usable_fb_size () } +fn heap_params_ga102 () ->GspFwHeapParams { +GspFwHeapParams { + libos: &nvfw::LIBOS3_PARAMS , + ..super ::tu102::heap_params_tu102 () + } +} +struct Ga102 ;impl FbHal for Ga102 {
@@ -30,6 +38,10 @@ fn supports_display(&self, bar: &Bar0) -> bool {fn vidmem_size (&self, bar: &Bar0 ) ->u64 {vidmem_size_ga102 (bar) } + +fn heap_params (&self) ->GspFwHeapParams { +heap_params_ga102 () + } }const GA102 :Ga102 =Ga102 ;
drivers/gpu/nova-core/fb/hal/tu102.rs +14 -0
@@ -2,7 +2,10 @@use crate ::driver::Bar0 ;use crate ::fb::hal::FbHal ; +use crate ::fb::hal::GspFwHeapParams ; +use crate ::nvfw;use crate ::regs; +use kernel::prelude::*;/// Shift applied to the sysmem address before it is written into `NV_PFB_NISO_FLUSH_SYSMEM_ADDR`,
@@ -34,6 +37,13 @@ pub(super) fn vidmem_size_gp102(bar: &Bar0) -> u64 { regs::NV_PFB_PRI_MMU_LOCAL_MEMORY_RANGE ::read (bar).usable_fb_size () } +pub (super )fn heap_params_tu102 () ->GspFwHeapParams { +GspFwHeapParams { + libos: &nvfw::LIBOS2_PARAMS , + base_rm_size: u64::from (nvfw::GSP_FW_HEAP_PARAM_BASE_RM_SIZE_TU10X ), + } +} +struct Tu102 ;impl FbHal for Tu102 {
@@ -52,6 +62,10 @@ fn supports_display(&self, bar: &Bar0) -> bool {fn vidmem_size (&self, bar: &Bar0 ) ->u64 {vidmem_size_gp102 (bar) } + +fn heap_params (&self) ->GspFwHeapParams { +heap_params_tu102 () + } }const TU102 :Tu102 =Tu102 ;
drivers/gpu/nova-core/firmware.rs +2 -2
@@ -122,9 +122,9 @@ pub(crate) struct Firmware {/// Runs on the sec2 falcon engine to stop and unload a running GSP firmware. booter_unloader: BooterFirmware,/// GSP bootloader, verifies the GSP firmware before loading and running it. - gsp_bootloader: RiscvFirmware, + pub gsp_bootloader: RiscvFirmware,/// GSP firmware. - gsp: Pin<KBox<GspFirmware>>, + pub gsp: Pin<KBox<GspFirmware>>,/// GSP signatures, to be passed as parameter to the bootloader for validation. gsp_sigs: DmaObject, }
drivers/gpu/nova-core/firmware/riscv.rs +1 -1
@@ -61,7 +61,7 @@ pub(crate) struct RiscvFirmware {/// Application version. app_version: u32,/// Device-mapped firmware image. - ucode: DmaObject, + pub ucode: DmaObject, }impl RiscvFirmware {
drivers/gpu/nova-core/gpu.rs +1 -1
@@ -302,7 +302,7 @@ pub(crate) fn new( FIRMWARE_VERSION, )?; -let fb_layout =FbLayout ::new (spec.chipset, bar)?; +let fb_layout =FbLayout ::new (spec.chipset, bar, &fw.gsp_bootloader, &fw.gsp)?;dev_dbg! (pdev.as_ref (),"{:#x?}\n" , fb_layout);let bios =Vbios ::new (pdev, bar)?;
drivers/gpu/nova-core/gsp.rs +3 -0
@@ -1,4 +1,7 @@// SPDX-License-Identifier: GPL-2.0 +use kernel::ptr::Alignment ; +pub (crate )const GSP_PAGE_SHIFT :usize =12 ;pub (crate )const GSP_PAGE_SIZE :usize =1 <<GSP_PAGE_SHIFT ; +pub (crate )const GSP_HEAP_ALIGNMENT :Alignment =Alignment ::new (1 <<20 );
drivers/gpu/nova-core/nvfw.rs +39 -0
@@ -1,3 +1,42 @@// SPDX-License-Identifier: GPL-2.0 mod r570_144; + +use core::ops::Range ; + +use kernel::sizes::SZ_1M ; + +/// Heap memory requirements and constraints for a given version of the GSP LIBOS. +pub (crate )struct LibosParams { +/// The base amount of heap required by the GSP operating system, in bytes. +pub (crate ) carveout_size:u64 , +/// The minimum and maximum sizes allowed for the GSP FW heap, in bytes. +pub (crate ) allowed_heap_size:Range <u64 >, +} + +/// Version 2 of the GSP LIBOS (Turing and GA100) +pub (crate )const LIBOS2_PARAMS :LibosParams =LibosParams { + carveout_size: r570_144::GSP_FW_HEAP_PARAM_OS_SIZE_LIBOS2 as u64 , + allowed_heap_size: r570_144::GSP_FW_HEAP_SIZE_OVERRIDE_LIBOS2_MIN_MB as u64 *SZ_1M as u64 + ..r570_144::GSP_FW_HEAP_SIZE_OVERRIDE_LIBOS2_MAX_MB as u64 *SZ_1M as u64 , +}; + +/// Version 3 of the GSP LIBOS (GA102+) +pub (crate )const LIBOS3_PARAMS :LibosParams =LibosParams { + carveout_size: r570_144::GSP_FW_HEAP_PARAM_OS_SIZE_LIBOS3_BAREMETAL as u64 , + allowed_heap_size: r570_144::GSP_FW_HEAP_SIZE_OVERRIDE_LIBOS3_BAREMETAL_MIN_MB as u64 + *SZ_1M as u64 + ..r570_144::GSP_FW_HEAP_SIZE_OVERRIDE_LIBOS3_BAREMETAL_MAX_MB as u64 *SZ_1M as u64 , +}; + +/// Amount of GSP-RM heap memory used during GSP-RM boot and initialization (up to and including +/// the first client subdevice allocation) on Turing/Ampere/Ada. +pub (crate )use r570_144::GSP_FW_HEAP_PARAM_BASE_RM_SIZE_TU10X ; +/// WPR heap usage of a single client channel allocation. +pub (crate )use r570_144::GSP_FW_HEAP_PARAM_CLIENT_ALLOC_SIZE ; +/// Amount of extra WPR heap to reserve per GB of framebuffer memory, in bytes. +pub (crate )use r570_144::GSP_FW_HEAP_PARAM_SIZE_PER_GB_FB ; + +/// Structure passed to the GSP bootloader, containing the framebuffer layout as well as the DMA +/// addresses of the GSP bootloader and firmware. +pub (crate )use r570_144::GspFwWprMeta ;
drivers/gpu/nova-core/nvfw/r570_144.rs +0 -1
@@ -12,7 +12,6 @@#![cfg_attr(test, allow(unsafe_op_in_unsafe_fn))] #![allow( dead_code, - unused_imports, clippy::all, clippy::undocumented_unsafe_blocks, clippy::ptr_as_ptr,
drivers/gpu/nova-core/nvfw/r570_144_bindings.rs +125 -0
126 lines not on this page · raw message
Signature · 1 line
2.50.1
Re: [PATCH v2 8/8] gpu: nova-core: compute layout of more framebuffer regions required for GSP
Quoted 2 lines · Alexandre Courbot
drivers/gpu/nova-core/fb.rs +0
-0
...
drivers/gpu/nova-core/fb.rs pub(crate) fn new(chipset: Chipset, bar: &Bar0) -> Result<Self> { · line 205
Quoted 6 lines
let fb = {drivers/gpu/nova-core/fb.rs +1
-0@@ -138,10 +202,54 @@ pub(crate) fn new(chipset: Chipset, bar: &Bar0) -> Result<Self> { frts_base..frts_base +FRTS_SIZE }; +let boot = {
A few lines earlier, not shown in these diffs because it's not part of this patch, there is a closely related TODO item:
// TODO[NUMM]: replace with `align_down` once it lands.
let frts_base = (vga_workspace.start & !(FRTS_DOWN_ALIGN - 1)) - FRTS_SIZE;...which I think could be optionally fixed now, and added to this patch.
Or it could be done later, in a different patch, but it seems convenient to merge it in as long as we're here, and using .align_down() in this patch.
...
Quoted 16 lines
drivers/gpu/nova-core/nvfw.rs +8
-0@@ -1,3 +1,42 @@// SPDX-License-Identifier: GPL-2.0 mod r570_144; + +use core::ops::Range ; + +use kernel::sizes::SZ_1M ; + +/// Heap memory requirements and constraints for a given version of the GSP LIBOS. +pub (crate )struct LibosParams { +/// The base amount of heap required by the GSP operating system, in bytes.
drivers/gpu/nova-core/nvfw.rs line 21
Quoted 10 lines
drivers/gpu/nova-core/nvfw.rs +10
-0+ pub(crate) carveout_size: u64, +/// The minimum and maximum sizes allowed for the GSP FW heap, in bytes. + pub(crate) allowed_heap_size: Range<u64>, +} + +/// Version 2 of the GSP LIBOS (Turing and GA100) +pub (crate )const LIBOS2_PARAMS :LibosParams =LibosParams { + carveout_size: r570_144::GSP_FW_HEAP_PARAM_OS_SIZE_LIBOS2 as u64 , + allowed_heap_size: r570_144::GSP_FW_HEAP_SIZE_OVERRIDE_LIBOS2_MIN_MB as u64 *SZ_1M as u64 + ..r570_144::GSP_FW_HEAP_SIZE_OVERRIDE_LIBOS2_MAX_MB as u64 *SZ_1M as u64 ,
We only support one version of the firmware. And in the coming months, that one version will have a different version number.
Given those constraints, we should simply remove most (all?) of the "r570_144::" namespace qualifiers in the code, starting here.
That way, we get:
a) A small diff, instead of a huge one, when we update to a new firmware version.
b) Shorter, cleaner symbols everywhere: GSP_FW_HEAP_SIZE_OVERRIDE_LIBOS2_MAX_MB instead of r570_144::GSP_FW_HEAP_SIZE_OVERRIDE_LIBOS2_MAX_MB, for example.
Quoted 11 lines
drivers/gpu/nova-core/nvfw.rs +11
-0+}; + +/// Version 3 of the GSP LIBOS (GA102+) +pub (crate )const LIBOS3_PARAMS :LibosParams =LibosParams { + carveout_size: r570_144::GSP_FW_HEAP_PARAM_OS_SIZE_LIBOS3_BAREMETAL as u64 , + allowed_heap_size: r570_144::GSP_FW_HEAP_SIZE_OVERRIDE_LIBOS3_BAREMETAL_MIN_MB as u64 + *SZ_1M as u64 + ..r570_144::GSP_FW_HEAP_SIZE_OVERRIDE_LIBOS3_BAREMETAL_MAX_MB as u64 *SZ_1M as u64 , +}; + +/// Amount of GSP-RM heap memory used during GSP-RM boot and initialization (up to and including
drivers/gpu/nova-core/nvfw.rs line 42
Quoted 10 lines
drivers/gpu/nova-core/nvfw.rs +10
-0+/// the first client subdevice allocation) on Turing/Ampere/Ada. +pub (crate )use r570_144::GSP_FW_HEAP_PARAM_BASE_RM_SIZE_TU10X ; +/// WPR heap usage of a single client channel allocation. +pub (crate )use r570_144::GSP_FW_HEAP_PARAM_CLIENT_ALLOC_SIZE ; +/// Amount of extra WPR heap to reserve per GB of framebuffer memory, in bytes. +pub (crate )use r570_144::GSP_FW_HEAP_PARAM_SIZE_PER_GB_FB ; + +/// Structure passed to the GSP bootloader, containing the framebuffer layout as well as the DMA +/// addresses of the GSP bootloader and firmware. +pub (crate )use r570_144::GspFwWprMeta ;
thanks,
Signature · 1 line
John Hubbard
Alexandre Courbot
maintainerRe: [PATCH v2 8/8] gpu: nova-core: compute layout of more framebuffer regions required for GSP
Quoted 14 lines · John Hubbard
Quoted 2 lines · Alexandre Courbot
drivers/gpu/nova-core/fb.rs +0
-0...
drivers/gpu/nova-core/fb.rs pub(crate) fn new(chipset: Chipset, bar: &Bar0) -> Result<Self> { · line 205
Quoted 6 lines
let fb = {drivers/gpu/nova-core/fb.rs +1
-0@@ -138,10 +202,54 @@ pub(crate) fn new(chipset: Chipset, bar: &Bar0) -> Result<Self> { frts_base..frts_base +FRTS_SIZE }; +let boot = {A few lines earlier, not shown in these diffs because it's not part of this patch, there is a closely related TODO item:
Quoted 7 lines
// TODO[NUMM]: replace with `align_down` once it lands. let frts_base = (vga_workspace.start & !(FRTS_DOWN_ALIGN - 1)) - FRTS_SIZE;...which I think could be optionally fixed now, and added to this patch.
Or it could be done later, in a different patch, but it seems convenient to merge it in as long as we're here, and using .align_down() in this patch.
This is taken care of by the series adding the Alignment type:
https://lore.kernel.org/rust-for-linux/[email protected]/
Quoted 35 lines
...
Quoted 16 lines
drivers/gpu/nova-core/nvfw.rs +8
-0@@ -1,3 +1,42 @@// SPDX-License-Identifier: GPL-2.0 mod r570_144; + +use core::ops::Range ; + +use kernel::sizes::SZ_1M ; + +/// Heap memory requirements and constraints for a given version of the GSP LIBOS. +pub (crate )struct LibosParams { +/// The base amount of heap required by the GSP operating system, in bytes. drivers/gpu/nova-core/nvfw.rs line 21
Quoted 10 lines
drivers/gpu/nova-core/nvfw.rs +10
-0+ pub(crate) carveout_size: u64, +/// The minimum and maximum sizes allowed for the GSP FW heap, in bytes. + pub(crate) allowed_heap_size: Range<u64>, +} + +/// Version 2 of the GSP LIBOS (Turing and GA100) +pub (crate )const LIBOS2_PARAMS :LibosParams =LibosParams { + carveout_size: r570_144::GSP_FW_HEAP_PARAM_OS_SIZE_LIBOS2 as u64 , + allowed_heap_size: r570_144::GSP_FW_HEAP_SIZE_OVERRIDE_LIBOS2_MIN_MB as u64 *SZ_1M as u64 + ..r570_144::GSP_FW_HEAP_SIZE_OVERRIDE_LIBOS2_MAX_MB as u64 *SZ_1M as u64 ,We only support one version of the firmware. And in the coming months, that one version will have a different version number.
Given those constraints, we should simply remove most (all?) of the "
r570_144::" namespace qualifiers in the code, starting here.
Quoted 7 lines
That way, we get:
a) A small diff, instead of a huge one, when we update to a new firmware version.
b) Shorter, cleaner symbols everywhere:
GSP_FW_HEAP_SIZE_OVERRIDE_LIBOS2_MAX_MBinstead ofr570_144::GSP_FW_HEAP_SIZE_OVERRIDE_LIBOS2_MAX_MB, for example.
nvfw is the module that is supposed to abstract the currently supported firmware version - but in order to provide this abstraction, it needs to refer the items in question. :) I don't see how we could avoid these qualifiers short of having a use r750_144::* which could result into name collisions.
But maybe we can do a module alias to reduce the diff once the version changes:
use r570_144 as fwbindings;
...
pub(crate) const LIBOS2_PARAMS: LibosParams = LibosParams {
carveout_size: fwbindings::GSP_FW_HEAP_PARAM_OS_SIZE_LIBOS2 as u64,Is that what you had in mind?
Re: [PATCH v2 8/8] gpu: nova-core: compute layout of more framebuffer regions required for GSP
Quoted 14 lines · Alexandre Courbot
Quoted 13 lines · John Hubbard
On 8/25/25 9:07 PM, Alexandre Courbot wrote:
...
We only support one version of the firmware. And in the coming months, that one version will have a different version number.Given those constraints, we should simply remove most (all?) of the "
r570_144::" namespace qualifiers in the code, starting here.That way, we get:
a) A small diff, instead of a huge one, when we update to a new firmware version.
Quoted 8 lines
Quoted 2 lines
b) Shorter, cleaner symbols everywhere:
GSP_FW_HEAP_SIZE_OVERRIDE_LIBOS2_MAX_MBinstead of r570_144::GSP_FW_HEAP_SIZE_OVERRIDE_LIBOS2_MAX_MB, for example.
nvfwis the module that is supposed to abstract the currently supported firmware version - but in order to provide this abstraction, it needs to refer the items in question. :) I don't see how we could avoid these qualifiers short of having ause r750_144::*which could result into name collisions.
My idea here was: "what name collisions?". There shouldn't be any. Because again, there is only one firmware version supported at a time.
Quoted 11 lines
But maybe we can do a module alias to reduce the diff once the version changes:
use r570_144 as fwbindings; ... pub(crate) const LIBOS2_PARAMS: LibosParams = LibosParams { carveout_size: fwbindings::GSP_FW_HEAP_PARAM_OS_SIZE_LIBOS2 as u64,Is that what you had in mind?
Not initially, but it would address most of what bothered me here, which is having a particular version number all over everywhere.
thanks,
Signature · 1 line
John Hubbard
On 8/25/25 9:07 PM, Alexandre Courbot wrote:
...
Quoted 7 lines
The base of this series is today's nova-next, but there a few more unmerged dependencies required:
- BorrowedPage, AsPageIter and VmallocPageIter [2]
- Rust infrastructure forsg_tableand scatterlist [3]
- FromBytes [4]
- The Alignment series [5]
Hi Alex!
For future patchsets that have complex and/or lengthy prerequisite patchsets, let's please please make it easier for people to locally apply the series. Very important.
The very nicest experience is by simply providing a link to your git branch that exactly matches the patchset you just posted.
In this particular case, it would also have worked to just say, "this series can be applied by first applying FromBytes [4], to the base commit."
Because that works, and is simpler than hunting down the other three items, which are not actually necessary for git am (although they might be for actual testing).
But the point is that the admin can be made simpler for the reviewers--even those of us who know exactly what you're up to. And we should keep that in mind, especially because there are many more of these situations coming soon.
thanks,
Signature · 1 line
John Hubbard
Alexandre Courbot
maintainerQuoted 22 lines · John Hubbard
On 8/25/25 9:07 PM, Alexandre Courbot wrote:
...Quoted 7 lines
The base of this series is today's nova-next, but there a few more unmerged dependencies required:
- BorrowedPage, AsPageIter and VmallocPageIter [2]
- Rust infrastructure forsg_tableand scatterlist [3]
- FromBytes [4]
- The Alignment series [5]Hi Alex!
For future patchsets that have complex and/or lengthy prerequisite patchsets, let's please please make it easier for people to locally apply the series. Very important.
The very nicest experience is by simply providing a link to your git branch that exactly matches the patchset you just posted.
In this particular case, it would also have worked to just say, "this series can be applied by first applying FromBytes [4], to the base commit."
Quoted 8 lines
Because that works, and is simpler than hunting down the other three items, which are not actually necessary for git am (although they might be for actual testing).
But the point is that the admin can be made simpler for the reviewers--even those of us who know exactly what you're up to. And we should keep that in mind, especially because there are many more of these situations coming soon.
Right, b4 is supposed to be able to help with this as well, but indeed a link to a git tree should be the standard with patchsets requiring such dependencies. :) Will try to keep this in mind.
Quoted 9 lines · Alexandre Courbot
Quoted 6 lines · John Hubbard
On 8/25/25 9:07 PM, Alexandre Courbot wrote:
...
But the point is that the admin can be made simpler for the reviewers--even those of us who know exactly what you're up to. And we should keep that in mind, especially because there are many more of these situations coming soon.Right, b4 is supposed to be able to help with this as well, but indeed a
It really doesn't quite, though.
It is true that "base" (git format-patch --base) helps "b4 am" set things up, but then a subsequent "git am" fails due to missing prerequisites.
b4 isn't set up to go retrieve those, on its own anyway.
thanks,
Signature · 1 line
John Hubbard
Quoted 8 lines · John Hubbard
Quoted 1 line
Right, b4 is supposed to be able to help with this as well, but indeed a
It really doesn't quite, though.
It is true that "base" (git format-patch --base) helps "b4 am" set things up, but then a subsequent "git am" fails due to missing prerequisites.
b4 isn't set up to go retrieve those, on its own anyway.
Sure it is. :)
Try b4 shazam -H on this series.
-K
Quoted 5 lines · Konstantin Ryabitsev
Quoted 4 lines · John Hubbard
Quoted 1 line
Right, b4 is supposed to be able to help with this as well, but indeed a
It really doesn't quite, though.
Quoted 8 lines
Quoted 4 lines
It is true that "base" (git format-patch --base) helps "b4 am" set things up, but then a subsequent "git am" fails due to missing prerequisites.
b4 isn't set up to go retrieve those, on its own anyway.
Sure it is. :)
Try
b4 shazam -Hon this series.
That is nice, I've updated my mental model of what b4 can do now.
It still fails for this particular series, but it at least tries quite thoroughly to get the dependencies.
I think this demonstrates a case of pushing even a very capable tool such as b4, a little too hard, though.
<blueforge> linux-people (nova-next)$ b4 shazam -H "<[email protected]>" Grabbing thread from lore.kernel.org/all/[email protected]/t.mbox.gz
Checking for newer revisions
Grabbing search results from lore.kernel.org
Analyzing 35 messages in the thread
Analyzing 10 code-review messages
Checking attestation on all messages, may take a moment...
---
✗ [PATCH v2 1/8] rust: transmute: add from_bytes_copy method to FromBytes trait
+ Acked-by: Miguel Ojeda <[email protected]> (✓ DKIM/gmail.com)
+ Reviewed-by: John Hubbard <[email protected]> (✗ DKIM/nvidia.com)
+ Reviewed-by: Benno Lossin <[email protected]> (✓ DKIM/kernel.org)
✗ [PATCH v2 2/8] gpu: nova-core: firmware: add support for common firmware header
✗ [PATCH v2 3/8] gpu: nova-core: firmware: process Booter and patch its signature
✗ [PATCH v2 4/8] gpu: nova-core: firmware: process the GSP bootloader
+ Reviewed-by: John Hubbard <[email protected]> (✗ DKIM/nvidia.com)
✗ [PATCH v2 5/8] gpu: nova-core: firmware: process and prepare the GSP firmware
✗ [PATCH v2 6/8] gpu: nova-core: firmware: use 570.144 firmware
+ Reviewed-by: John Hubbard <[email protected]> (✗ DKIM/nvidia.com)
✗ [PATCH v2 7/8] gpu: nova-core: Add base files for r570.144 firmware bindings
+ Reviewed-by: John Hubbard <[email protected]> (✗ DKIM/nvidia.com)
✗ [PATCH v2 8/8] gpu: nova-core: compute layout of more framebuffer regions required for GSP
---
✗ BADSIG: DKIM/nvidia.com
---
Total patches: 8
---
Base: using specified base-commit 331c24e6ce814af2af74bac648d1ac1708873e9c
Deps: looking for dependencies matching 39 patch-ids
Deps: Applying prerequisite patch: [PATCH v5 1/7] rust: page: implement BorrowedPage
Deps: Applying prerequisite patch: [PATCH v5 2/7] rust: alloc: vmalloc: implement Vmalloc::to_page()
Deps: Applying prerequisite patch: [PATCH v5 3/7] rust: alloc: implement VmallocPageIter
Deps: Applying prerequisite patch: [PATCH v5 4/7] rust: page: define trait AsPageIter
Deps: Applying prerequisite patch: [PATCH v5 5/7] rust: alloc: kbox: implement AsPageIter for VBox
Deps: Applying prerequisite patch: [PATCH v2 4/6] rust: alloc: layout: implement ArrayLayout::size()
Deps: Applying prerequisite patch: [PATCH v4 7/7] rust: alloc: kvec: implement AsPageIter for VVec
Deps: Applying prerequisite patch: [PATCH v3 1/5] rust: dma: implement DataDirection
Deps: Applying prerequisite patch: [PATCH v3 2/5] rust: dma: add type alias for bindings::dma_addr_t
Deps: Applying prerequisite patch: [PATCH v3 3/5] rust: scatterlist: Add abstraction for sg_table
Deps: Applying prerequisite patch: [PATCH v3 4/5] samples: rust: dma: add sample code for SGTable
Deps: Applying prerequisite patch: [PATCH 4/4] MAINTAINERS: rust: dma: add scatterlist files
Deps: Applying prerequisite patch: [PATCH v10] rust: transmute: Add methods for FromBytes trait
Deps: Applying prerequisite patch: [PATCH] MAINTAINERS: Add website of Nova GPU driver
Deps: Applying prerequisite patch: [PATCH 2/7] rust: gpu: update ARef and AlwaysRefCounted imports from sync::aref
Deps: Applying prerequisite patch: [PATCH 01/18] gpu: nova-core: register: minor grammar and spelling fixes
Deps: Applying prerequisite patch: [PATCH v2 02/19] gpu: nova-core: register: fix typo
Deps: Applying prerequisite patch: [PATCH v2 04/19] gpu: nova-core: register: improve documentation for basic registers
Deps: Applying prerequisite patch: [PATCH v2 05/19] gpu: nova-core: register: simplify @leaf_accessor rule
Deps: Applying prerequisite patch: [PATCH v2 06/19] gpu: nova-core: register: remove try_ accessors for relative registers
Deps: Applying prerequisite patch: [PATCH 06/18] gpu: nova-core: register: move OFFSET declaration to I/O impl block
Deps: Applying prerequisite patch: [PATCH 07/18] gpu: nova-core: register: fix documentation and indentation
Deps: Applying prerequisite patch: [PATCH v2 09/19] gpu: nova-core: register: add missing doccomments for fixed registers I/O accessors
Deps: Applying prerequisite patch: [PATCH 09/18] gpu: nova-core: register: add fields dispatcher internal rule
Deps: Applying prerequisite patch: [PATCH v2 11/19] gpu: nova-core: register: improve Debug implementation
Deps: Applying prerequisite patch: [PATCH 11/18] gpu: nova-core: register: generate correct Default implementation
Deps: Applying prerequisite patch: [PATCH 12/18] gpu: nova-core: register: split @io rule into fixed and relative versions
Deps: Applying prerequisite patch: [PATCH 13/18] gpu: nova-core: register: use #[inline(always)] for all methods
Deps: Applying prerequisite patch: [PATCH v2 15/19] gpu: nova-core: register: redesign relative registers
Deps: Applying prerequisite patch: [PATCH v2 16/19] gpu: nova-core: falcon: add distinct base address for PFALCON2
Deps: Applying prerequisite patch: [PATCH v2 17/19] gpu: nova-core: register: add support for register arrays
Deps: Applying prerequisite patch: [PATCH v2 18/19] gpu: nova-core: falcon: use register arrays for FUSE registers
Deps: Applying prerequisite patch: [PATCH v2 19/19] gpu: nova-core: register: add support for relative array registers
Deps: Applying prerequisite patch: [PATCH v2] gpu: nova-core: falcon: align DMA transfers to 256 bytes
Deps: Applying prerequisite patch: [PATCH v4 1/2] rust: add Alignment type
Deps: Applying prerequisite patch: [PATCH v3 2/2] gpu: nova-core: use Alignment for alignment-related operations
Magic: Preparing a sparse worktree
Unable to cleanly apply series, see failure log below
---
Applying: rust: page: implement BorrowedPage
Applying: rust: alloc: vmalloc: implement Vmalloc::to_page()
Applying: rust: alloc: implement VmallocPageIter
Applying: rust: page: define trait AsPageIter
Applying: rust: alloc: kbox: implement AsPageIter for VBox
Applying: rust: alloc: layout: implement ArrayLayout::size()
Applying: rust: alloc: kvec: implement AsPageIter for VVec
Applying: rust: dma: implement DataDirection
Applying: rust: dma: add type alias for bindings::dma_addr_t
Patch failed at 0009 rust: dma: add type alias for bindings::dma_addr_t
error: patch failed: drivers/gpu/nova-core/falcon.rs:4
error: drivers/gpu/nova-core/falcon.rs: patch does not apply
hint: Use 'git am --show-current-patch=diff' to see the failed patch
hint: When you have resolved this problem, run "git am --continue".
hint: If you prefer to skip this patch, run "git am --skip" instead.
hint: To restore the original branch and stop patching, run "git am --abort".
hint: Disable this message with "git config set advice.mergeConflict false"
---
Not fetching into FETCH_HEAD
<blueforge> linux-people (nova-next)$ git am --show-current-patch=diff
fatal: Resolve operation not in progress, we are not resuming.
<blueforge> linux-people (nova-next)$
thanks,
Signature · 1 line
John Hubbard