Skip to contentSkip to conversation

gpu: nova-core: Boot GSP to RISC-V active

PATCH Applied Alexandre Courbot 2 participants 19 messages Nov 10, 2025 – Nov 14, 2025

Subsystems (5)
DRM drivers RISC-V Rust DRM Rust +1 more subsystems
lore
Share & tools
lore

Alexandre Courbot

author maintainer
#0 lore raw

v9 cover gpu: nova-core: Boot GSP to RISC-V active

This revision features a more adequate method for receiving messages, and some general cleanup. It looks solid to me, and although there are further minor improvements I want to eventually see I think it makes an adequate first milestone.

I am considering merging this before -rc6, so it can make it into 6.19. If there are reasons not to, please scream. :)

A branch including this series and its dependencies is available at [1].

[1] https://github.com/Gnurou/linux/tree/b4/gsp_boot

Changes in v9:
- More doccomments.
- Use the MessageFromGsp trait instead of an arbitrary closure to extract incoming messages from the message queue.
- Split the message receiving method into a non-generic transport layer receive, and the generic part validating and constructing the message.
- Use well-defined types for sending and receiving messages instead of error-prone tuples.
- Link to v8: https://lore.kernel.org/r/[email protected]

Changes in v8:
- Add lots of doccomments.
- Refactor and simplify GSP command sending - now uses a single trait and a single method.
- Leverage the new from_bytes_prefix family of methods to simplify GSP command queue code a bit.
- Simplify RM arguments.
- Split the GspSetSystemInfo and SetRegistry commands into their own patch.
- Add a is_empty method to SBufferIter and use it to detect when a command's variable length payload has not been entirely written.
- Harmonize imports according to new format rules.
- Link to v7: https://lore.kernel.org/r/[email protected]

Changes in v7:
- Remove as conversions by using the features of the num module.
- Add build-time conversion of constant integer values to smaller types.
- Thanks to the two items above, make more functions infallible.
- Remove unneeded nr_ptes member of the Cmdq.
- Use repr(u32) for MsgFunction to simplify it.
- Use from_ref instead of casting references into pointers with as.
- Add message header version type to remove use of magic number.
- Switch some parameters to usize to limit type conversions.
- Add comments for undocumented functions.
- Remove function_number method of GspMsgElement and return invalid function numbers as the error value of function instead.
- Work around the renaming of slice::flatten to slice::as_flattened in Rust 1.80 (thanks Miguel!).
- Fix clippy warning with Rust 1.78.
- Link to v6: https://lore.kernel.org/r/[email protected]/

---
Alexandre Courbot (3):
gpu: nova-core: compute layout of more framebuffer regions required for GSP
gpu: nova-core: num: add functions to safely convert a const value to a smaller type
rust: enable slice_flatten feature and provide it through an extension trait

Alistair Popple (9):
gpu: nova-core: Set correct DMA mask
gpu: nova-core: Create initial Gsp
gpu: nova-core: gsp: Create wpr metadata
gpu: nova-core: Add zeroable trait to bindings
gpu: nova-core: gsp: Add GSP command queue bindings and handling
gpu: nova-core: gsp: Create rmargs
gpu: nova-core: gsp: Add SetSystemInfo command
gpu: nova-core: gsp: Add SetRegistry command
gpu: nova-core: gsp: Boot GSP

Joel Fernandes (3):
gpu: nova-core: Add a slice-buffer (sbuffer) datastructure
gpu: nova-core: falcon: Add support to check if RISC-V is active
gpu: nova-core: falcon: Add support to write firmware version

 drivers/gpu/nova-core/driver.rs                   |  16 +
 drivers/gpu/nova-core/falcon.rs                   |  15 +
 drivers/gpu/nova-core/fb.rs                       |  72 ++-
 drivers/gpu/nova-core/firmware/gsp.rs             |   7 +-
 drivers/gpu/nova-core/firmware/riscv.rs           |  11 +-
 drivers/gpu/nova-core/gpu.rs                      |   2 +-
 drivers/gpu/nova-core/gsp.rs                      | 156 ++++-
 drivers/gpu/nova-core/gsp/boot.rs                 |  85 ++-
 drivers/gpu/nova-core/gsp/cmdq.rs                 | 680 +++++++++++++++++++++
 drivers/gpu/nova-core/gsp/commands.rs             | 129 ++++
 drivers/gpu/nova-core/gsp/fw.rs                   | 608 ++++++++++++++++++-
 drivers/gpu/nova-core/gsp/fw/commands.rs          | 106 ++++
 drivers/gpu/nova-core/gsp/fw/r570_144.rs          |   6 +-
 drivers/gpu/nova-core/gsp/fw/r570_144/bindings.rs | 703 ++++++++++++++++++++++
 drivers/gpu/nova-core/nova_core.rs                |   1 +
 drivers/gpu/nova-core/num.rs                      |  51 ++
 drivers/gpu/nova-core/regs.rs                     |  17 +-
 drivers/gpu/nova-core/sbuffer.rs                  | 228 +++++++
 init/Kconfig                                      |   3 +
 rust/kernel/lib.rs                                |   4 +
 rust/kernel/prelude.rs                            |   3 +
 rust/kernel/slice.rs                              |  49 ++
 22 files changed, 2918 insertions(+), 34 deletions(-)

---
base-commit: 80b3dc0a5a2e51fb2b8f3406f5ee20ad4a652316
change-id: 20251027-gsp_boot-c6bb048a304e

Best regards,

Signature · 1 line
Alexandre Courbot <[email protected]>
author maintainer
#1 lore raw

PATCH v9 1/15 gpu: nova-core: compute layout of more framebuffer regions required for GSP

Compute 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                       |  71 +++++++++++-
 drivers/gpu/nova-core/firmware/gsp.rs             |   4 +-
 drivers/gpu/nova-core/firmware/riscv.rs           |   2 +-
 drivers/gpu/nova-core/gsp.rs                      |   5 +
 drivers/gpu/nova-core/gsp/boot.rs                 |   4 +-
 drivers/gpu/nova-core/gsp/fw.rs                   | 113 ++++++++++++++++++-
 drivers/gpu/nova-core/gsp/fw/r570_144.rs          |   1 -
 drivers/gpu/nova-core/gsp/fw/r570_144/bindings.rs | 125 ++++++++++++++++++++++
 8 files changed, 314 insertions(+), 11 deletions(-)
drivers/gpu/nova-core/fb.rs +67 -4
index a99223f73367..156d9bf1f191 100644
@@ -16,9 +16,14 @@
 use crate::{
     dma::DmaObject,
     driver::Bar0,
+    firmware::gsp::GspFirmware,
     gpu::Chipset,
-    num::usize_as_u64,
-    regs, //
+    gsp,
+    num::{
+        usize_as_u64,
+        FromSafeCast, //
+    },
+    regs,
 };
 
 mod hal;
@@ -95,14 +100,27 @@ pub(crate) fn unregister(&self, bar: &Bar0) {
 #[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` required to run the `gsp_fw` GSP firmware.
+    pub(crate) fn new(chipset: Chipset, bar: &Bar0, gsp_fw: &GspFirmware) -> Result<Self> {
         let hal = hal::fb_hal(chipset);
 
         let fb = {
@@ -146,10 +164,55 @@ 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 = u64::from_safe_cast(gsp_fw.bootloader.ucode.size());
+            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 = u64::from_safe_cast(gsp_fw.size);
+            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 =
+                gsp::LibosParams::from_chipset(chipset).wpr_heap_size(chipset, 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 - u64::from_safe_cast(size_of::<gsp::GspFwWprMeta>()))
+                .align_down(WPR2_DOWN_ALIGN);
+
+            wpr2_addr..frts.end
+        };
+
+        let heap = {
+            const HEAP_SIZE: u64 = usize_as_u64(SZ_1M);
+
+            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/firmware/gsp.rs +2 -2
index 72766feae36e..471ace238f62 100644
@@ -143,11 +143,11 @@ pub(crate) struct GspFirmware {
     /// Level 0 page table (single 4KB page) with one entry: DMA address of first level 1 page.
     level0: DmaObject,
     /// Size in bytes of the firmware contained in [`Self::fw`].
-    size: usize,
+    pub(crate) size: usize,
     /// Device-mapped GSP signatures matching the GPU's [`Chipset`].
     signatures: DmaObject,
     /// GSP bootloader, verifies the GSP firmware before loading and running it.
-    bootloader: RiscvFirmware,
+    pub(crate) bootloader: RiscvFirmware,
 }
 
 impl GspFirmware {
drivers/gpu/nova-core/firmware/riscv.rs +1 -1
index 270b2c7dc219..3838fab8f1c0 100644
@@ -68,7 +68,7 @@ pub(crate) struct RiscvFirmware {
     /// Application version.
     app_version: u32,
     /// Device-mapped firmware image.
-    ucode: DmaObject,
+    pub(crate) ucode: DmaObject,
 }
 
 impl RiscvFirmware {
drivers/gpu/nova-core/gsp.rs +5 -0
index 64e472e7a9d3..55a1ad90a373 100644
@@ -6,6 +6,11 @@
 
 mod fw;
 
+pub(crate) use fw::{
+    GspFwWprMeta,
+    LibosParams, //
+};
+
 pub(crate) const GSP_PAGE_SHIFT: usize = 12;
 pub(crate) const GSP_PAGE_SIZE: usize = 1 << GSP_PAGE_SHIFT;
 
drivers/gpu/nova-core/gsp/boot.rs +2 -2
index 19dddff929da..979d3391e58c 100644
@@ -127,12 +127,12 @@ pub(crate) fn boot(
 
         let bios = Vbios::new(dev, bar)?;
 
-        let _gsp_fw = KBox::pin_init(
+        let gsp_fw = KBox::pin_init(
             GspFirmware::new(dev, chipset, FIRMWARE_VERSION)?,
             GFP_KERNEL,
         )?;
 
-        let fb_layout = FbLayout::new(chipset, bar)?;
+        let fb_layout = FbLayout::new(chipset, bar, &gsp_fw)?;
         dev_dbg!(dev, "{:#x?}\n", fb_layout);
 
         Self::run_fwsec_frts(dev, gsp_falcon, bar, &bios, &fb_layout)?;
drivers/gpu/nova-core/gsp/fw.rs +112 -1

117 lines not on this page · raw message

drivers/gpu/nova-core/gsp/fw/r570_144.rs +0 -1
index 35cb0370a7c9..82a973cd99c3 100644
@@ -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/gsp/fw/r570_144/bindings.rs +125 -0

126 lines not on this page · raw message

Signature · 1 line
2.51.2
author maintainer
#2 lore raw

PATCH v9 2/15 gpu: nova-core: Set correct DMA mask

In reply to Alexandre Courbot

From: Alistair Popple <[email protected]>

Set the correct DMA mask. Without this DMA will fail on some setups.

---
 drivers/gpu/nova-core/driver.rs | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
drivers/gpu/nova-core/driver.rs +16 -0
index 2509f75eccb9..d91bbc50cde7 100644
@@ -4,6 +4,8 @@
     auxiliary,
     c_str,
     device::Core,
+    dma::Device,
+    dma::DmaMask,
     pci,
     pci::{
         Class,
@@ -25,6 +27,15 @@ pub(crate) struct NovaCore {
 }
 
 const BAR0_SIZE: usize = SZ_16M;
+
+// For now we only support Ampere which can use up to 47-bit DMA addresses.
+//
+// TODO: Add an abstraction for this to support newer GPUs which may support
+// larger DMA addresses. Limiting these GPUs to smaller address widths won't
+// have any adverse affects, unless installed on systems which require larger
+// DMA addresses. These systems should be quite rare.
+const GPU_DMA_BITS: u32 = 47;
+
 pub(crate) type Bar0 = pci::Bar<BAR0_SIZE>;
 
 kernel::pci_device_table!(
@@ -62,6 +73,11 @@ fn probe(pdev: &pci::Device<Core>, _info: &Self::IdInfo) -> Result<Pin<KBox<Self
         pdev.enable_device_mem()?;
         pdev.set_master();
 
+        // SAFETY: No concurrent DMA allocations or mappings can be made because
+        // the device is still being probed and therefore isn't being used by
+        // other threads of execution.
+        unsafe { pdev.dma_set_mask_and_coherent(DmaMask::new::<GPU_DMA_BITS>())? };
+
         let devres_bar = Arc::pin_init(
             pdev.iomap_region_sized::<BAR0_SIZE>(0, c_str!("nova-core/bar0")),
             GFP_KERNEL,
Signature · 1 line
2.51.2
author maintainer
#3 lore raw

PATCH v9 3/15 gpu: nova-core: num: add functions to safely convert a const value to a smaller type

In reply to Alexandre Courbot

There are times where we need to store a constant value defined as a larger type (e.g. through a binding) into a smaller type, knowing that the value will fit. Rust, unfortunately, only provides us with the as operator for that purpose, the use of which is discouraged as it silently strips data.

Extend the num module with functions allowing to perform the conversion infallibly, at compile time.

Example:

    const FOO_VALUE: u32 = 1;

    // `FOO_VALUE` fits into a `u8`, so the conversion is valid.
    let foo = num::u32_to_u8::<{ FOO_VALUE }>();

We are going to use this feature extensively in Nova.

---
 drivers/gpu/nova-core/num.rs | 51 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 51 insertions(+)
drivers/gpu/nova-core/num.rs +51 -0
index 92a91b9e30de..f3740ab6cb9d 100644
@@ -163,3 +163,54 @@ fn into_safe_cast(self) -> T {
         T::from_safe_cast(self)
     }
 }
+
+macro_rules! impl_const_into {
+    ($from:ty => { $($into:ty),* }) => {
+        $(
+        paste! {
+            #[doc = ::core::concat!(
+                "Performs a build-time safe conversion of a [`",
+                ::core::stringify!($from),
+                "`] constant value into a [`",
+                ::core::stringify!($into),
+                "`].")]
+            ///
+            /// This checks at compile-time that the conversion is lossless, and triggers a build
+            /// error if it isn't.
+            ///
+            /// # Examples
+            ///
+            /// ```
+            /// use kernel::num;
+            ///
+            /// // Succeeds because the value of the source fits into the destination's type.
+            #[doc = ::core::concat!(
+                "assert_eq!(num::",
+                ::core::stringify!($from),
+                "_into_",
+                ::core::stringify!($into),
+                "(1",
+                ::core::stringify!($from),
+                "), 1",
+                ::core::stringify!($into),
+                ");")]
+            /// ```
+            #[allow(unused)]
+            pub(crate) const fn [<$from _into_ $into>]<const N: $from>() -> $into {
+                // Make sure that the target type is smaller than the source one.
+                static_assert!($from::BITS >= $into::BITS);
+                // CAST: we statically enforced above that `$from` is larger than `$into`, so the
+                // `as` conversion will be lossless.
+                build_assert!(N >= $into::MIN as $from && N <= $into::MAX as $from);
+
+                N as $into
+            }
+        }
+        )*
+    };
+}
+
+impl_const_into!(usize => { u8, u16, u32 });
+impl_const_into!(u64 => { u8, u16, u32 });
+impl_const_into!(u32 => { u8, u16 });
+impl_const_into!(u16 => { u8 });
Signature · 1 line
2.51.2
Reviewed-by on v9 3/15
#4 lore raw

Re: [PATCH v9 03/15] gpu: nova-core: num: add functions to safely convert a const value to a smaller type

Quoted 52 lines · Alexandre Courbot

There are times where we need to store a constant value defined as a larger type (e.g. through a binding) into a smaller type, knowing that the value will fit. Rust, unfortunately, only provides us with the as operator for that purpose, the use of which is discouraged as it silently strips data.

Extend the num module with functions allowing to perform the conversion infallibly, at compile time.

Example:

    const FOO_VALUE: u32 = 1;

    // `FOO_VALUE` fits into a `u8`, so the conversion is valid.
    let foo = num::u32_to_u8::<{ FOO_VALUE }>();

We are going to use this feature extensively in Nova.

---
 drivers/gpu/nova-core/num.rs | 51 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 51 insertions(+)
drivers/gpu/nova-core/num.rs +21 -0
index 92a91b9e30de..f3740ab6cb9d 100644
@@ -163,3 +163,54 @@ fn into_safe_cast(self) -> T {
         T::from_safe_cast(self)
     }
 }
+
+macro_rules! impl_const_into {
+    ($from:ty => { $($into:ty),* }) => {
+        $(
+        paste! {
+            #[doc = ::core::concat!(
+                "Performs a build-time safe conversion of a [`",
+                ::core::stringify!($from),
+                "`] constant value into a [`",
+                ::core::stringify!($into),
+                "`].")]
+            ///
+            /// This checks at compile-time that the conversion is lossless, and triggers a build
+            /// error if it isn't.
+            ///
+            /// # Examples
+            ///
+            /// ```
+            /// use kernel::num;
+            ///
+            /// // Succeeds because the value of the source fits into the destination's type.

drivers/gpu/nova-core/num.rs fn into_safe_cast(self) -> T { · line 196

Quoted 10 lines
drivers/gpu/nova-core/num.rs +10 -0
+            #[doc = ::core::concat!(
+                "assert_eq!(num::",
+                ::core::stringify!($from),
+                "_into_",
+                ::core::stringify!($into),
+                "(1",
+                ::core::stringify!($from),
+                "), 1",
+                ::core::stringify!($into),
+                ");")]

This expands to e.g. assert_eq!(num::u32_to_u8(1u32), 1u8), i.e. not with a generic parameter.

With that fixed,

Quoted 22 lines
drivers/gpu/nova-core/num.rs +20 -0
+            /// ```
+            #[allow(unused)]
+            pub(crate) const fn [<$from _into_ $into>]<const N: $from>() -> $into {
+                // Make sure that the target type is smaller than the source one.
+                static_assert!($from::BITS >= $into::BITS);
+                // CAST: we statically enforced above that `$from` is larger than `$into`, so the
+                // `as` conversion will be lossless.
+                build_assert!(N >= $into::MIN as $from && N <= $into::MAX as $from);
+
+                N as $into
+            }
+        }
+        )*
+    };
+}
+
+impl_const_into!(usize => { u8, u16, u32 });
+impl_const_into!(u64 => { u8, u16, u32 });
+impl_const_into!(u32 => { u8, u16 });
+impl_const_into!(u16 => { u8 });
author maintainer
#5 lore raw

Re: [PATCH v9 03/15] gpu: nova-core: num: add functions to safely convert a const value to a smaller type

Quoted 57 lines · Mikko Perttunen
Quoted 56 lines · Alexandre Courbot

There are times where we need to store a constant value defined as a larger type (e.g. through a binding) into a smaller type, knowing that the value will fit. Rust, unfortunately, only provides us with the as operator for that purpose, the use of which is discouraged as it silently strips data.

Extend the num module with functions allowing to perform the conversion infallibly, at compile time.

Example:

    const FOO_VALUE: u32 = 1;

    // `FOO_VALUE` fits into a `u8`, so the conversion is valid.
    let foo = num::u32_to_u8::<{ FOO_VALUE }>();

We are going to use this feature extensively in Nova.

---
 drivers/gpu/nova-core/num.rs | 51 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 51 insertions(+)
drivers/gpu/nova-core/num.rs +25 -0
index 92a91b9e30de..f3740ab6cb9d 100644
@@ -163,3 +163,54 @@ fn into_safe_cast(self) -> T {
         T::from_safe_cast(self)
     }
 }
+
+macro_rules! impl_const_into {
+    ($from:ty => { $($into:ty),* }) => {
+        $(
+        paste! {
+            #[doc = ::core::concat!(
+                "Performs a build-time safe conversion of a [`",
+                ::core::stringify!($from),
+                "`] constant value into a [`",
+                ::core::stringify!($into),
+                "`].")]
+            ///
+            /// This checks at compile-time that the conversion is lossless, and triggers a build
+            /// error if it isn't.
+            ///
+            /// # Examples
+            ///
+            /// ```
+            /// use kernel::num;
+            ///
+            /// // Succeeds because the value of the source fits into the destination's type.
+            #[doc = ::core::concat!(
+                "assert_eq!(num::",
+                ::core::stringify!($from),
+                "_into_",
Quoted 8 lines

drivers/gpu/nova-core/num.rs fn into_safe_cast(self) -> T { · line 196

Quoted 6 lines
drivers/gpu/nova-core/num.rs +6 -0
+                ::core::stringify!($into),
+                "(1",
+                ::core::stringify!($from),
+                "), 1",
+                ::core::stringify!($into),
+                ");")]

This expands to e.g. assert_eq!(num::u32_to_u8(1u32), 1u8), i.e. not with a generic parameter.

Ah, nice catch, thanks! I missed that because the doccomments are not built yet for code outside of kernel.

Fixing it by taking the example from the non-Nova RFC [1] of this patch.

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

author maintainer
#6 lore raw

PATCH v9 4/15 gpu: nova-core: Create initial Gsp

In reply to Alexandre Courbot

From: Alistair Popple <[email protected]>

The GSP requires several areas of memory to operate. Each of these have their own simple embedded page tables. Set these up and map them for DMA to/from GSP using CoherentAllocation's. Return the DMA handle describing where each of these regions are for future use when booting GSP.

---
 drivers/gpu/nova-core/gpu.rs                      |   2 +-
 drivers/gpu/nova-core/gsp.rs                      | 129 ++++++++++++++++++++--
 drivers/gpu/nova-core/gsp/fw.rs                   |  60 ++++++++++
 drivers/gpu/nova-core/gsp/fw/r570_144/bindings.rs |  19 ++++
 4 files changed, 200 insertions(+), 10 deletions(-)
drivers/gpu/nova-core/gpu.rs +1 -1
index 802e71e4f97d..03dae437bc37 100644
@@ -231,7 +231,7 @@ pub(crate) fn new<'a>(
 
             sec2_falcon: Falcon::new(pdev.as_ref(), spec.chipset)?,
 
-            gsp <- Gsp::new(),
+            gsp <- Gsp::new(pdev)?,
 
             _: { gsp.boot(pdev, bar, spec.chipset, gsp_falcon, sec2_falcon)? },
 
drivers/gpu/nova-core/gsp.rs +120 -9

144 lines not on this page · raw message

drivers/gpu/nova-core/gsp/fw.rs +60 -0

74 lines not on this page · raw message

drivers/gpu/nova-core/gsp/fw/r570_144/bindings.rs +19 -0
index 0407000cca22..6a14cc324391 100644
@@ -124,3 +124,22 @@ fn default() -> Self {
         }
     }
 }
+pub type LibosAddress = u64_;
+pub const LibosMemoryRegionKind_LIBOS_MEMORY_REGION_NONE: LibosMemoryRegionKind = 0;
+pub const LibosMemoryRegionKind_LIBOS_MEMORY_REGION_CONTIGUOUS: LibosMemoryRegionKind = 1;
+pub const LibosMemoryRegionKind_LIBOS_MEMORY_REGION_RADIX3: LibosMemoryRegionKind = 2;
+pub type LibosMemoryRegionKind = ffi::c_uint;
+pub const LibosMemoryRegionLoc_LIBOS_MEMORY_REGION_LOC_NONE: LibosMemoryRegionLoc = 0;
+pub const LibosMemoryRegionLoc_LIBOS_MEMORY_REGION_LOC_SYSMEM: LibosMemoryRegionLoc = 1;
+pub const LibosMemoryRegionLoc_LIBOS_MEMORY_REGION_LOC_FB: LibosMemoryRegionLoc = 2;
+pub type LibosMemoryRegionLoc = ffi::c_uint;
+#[repr(C)]
+#[derive(Debug, Default, Copy, Clone)]
+pub struct LibosMemoryRegionInitArgument {
+    pub id8: LibosAddress,
+    pub pa: LibosAddress,
+    pub size: LibosAddress,
+    pub kind: u8_,
+    pub loc: u8_,
+    pub __bindgen_padding_0: [u8; 6usize],
+}
Signature · 1 line
2.51.2
author maintainer
#7 lore raw

PATCH v9 5/15 gpu: nova-core: gsp: Create wpr metadata

In reply to Alexandre Courbot

From: Alistair Popple <[email protected]>

The GSP requires some pieces of metadata to boot. These are passed in a struct which the GSP transfers via DMA. Create this struct and get a handle to it for future use when booting the GSP.

---
 drivers/gpu/nova-core/fb.rs                       |  1 -
 drivers/gpu/nova-core/firmware/gsp.rs             |  3 +-
 drivers/gpu/nova-core/firmware/riscv.rs           |  6 +--
 drivers/gpu/nova-core/gsp/boot.rs                 |  7 +++
 drivers/gpu/nova-core/gsp/fw.rs                   | 61 ++++++++++++++++++++++-
 drivers/gpu/nova-core/gsp/fw/r570_144/bindings.rs |  2 +
 6 files changed, 73 insertions(+), 7 deletions(-)
drivers/gpu/nova-core/fb.rs +0 -1
index 156d9bf1f191..3c9cf151786c 100644
@@ -98,7 +98,6 @@ pub(crate) fn unregister(&self, bar: &Bar0) {
 ///
 /// 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>,
drivers/gpu/nova-core/firmware/gsp.rs +1 -2
index 471ace238f62..0549805282ab 100644
@@ -145,7 +145,7 @@ pub(crate) struct GspFirmware {
     /// Size in bytes of the firmware contained in [`Self::fw`].
     pub(crate) size: usize,
     /// Device-mapped GSP signatures matching the GPU's [`Chipset`].
-    signatures: DmaObject,
+    pub(crate) signatures: DmaObject,
     /// GSP bootloader, verifies the GSP firmware before loading and running it.
     pub(crate) bootloader: RiscvFirmware,
 }
@@ -231,7 +231,6 @@ pub(crate) fn new<'a, 'b>(
         }))
     }
 
-    #[expect(unused)]
     /// Returns the DMA handle of the radix3 level 0 page table.
     pub(crate) fn radix3_dma_handle(&self) -> DmaAddress {
         self.level0.dma_handle()
drivers/gpu/nova-core/firmware/riscv.rs +3 -3
index 3838fab8f1c0..7d82fb9876e8 100644
@@ -60,11 +60,11 @@ fn new(bin_fw: &BinFirmware<'_>) -> Result<Self> {
 #[expect(unused)]
 pub(crate) struct RiscvFirmware {
     /// Offset at which the code starts in the firmware image.
-    code_offset: u32,
+    pub(crate) code_offset: u32,
     /// Offset at which the data starts in the firmware image.
-    data_offset: u32,
+    pub(crate) data_offset: u32,
     /// Offset at which the manifest starts in the firmware image.
-    manifest_offset: u32,
+    pub(crate) manifest_offset: u32,
     /// Application version.
     app_version: u32,
     /// Device-mapped firmware image.
drivers/gpu/nova-core/gsp/boot.rs +7 -0
index 979d3391e58c..5ea53250bf37 100644
@@ -2,6 +2,8 @@
 
 use kernel::{
     device,
+    dma::CoherentAllocation,
+    dma_write,
     pci,
     prelude::*, //
 };
@@ -27,6 +29,7 @@
         FIRMWARE_VERSION, //
     },
     gpu::Chipset,
+    gsp::GspFwWprMeta,
     regs,
     vbios::Vbios,
 };
@@ -146,6 +149,10 @@ pub(crate) fn boot(
             bar,
         )?;
 
+        let wpr_meta =
+            CoherentAllocation::<GspFwWprMeta>::alloc_coherent(dev, 1, GFP_KERNEL | __GFP_ZERO)?;
+        dma_write!(wpr_meta[0] = GspFwWprMeta::new(&gsp_fw, &fb_layout))?;
+
         Ok(())
     }
 }
drivers/gpu/nova-core/gsp/fw.rs +60 -1

79 lines not on this page · raw message

drivers/gpu/nova-core/gsp/fw/r570_144/bindings.rs +2 -0
index 6a14cc324391..392b25dc6991 100644
@@ -9,6 +9,8 @@
 pub const GSP_FW_HEAP_SIZE_OVERRIDE_LIBOS2_MAX_MB: u32 = 256;
 pub const GSP_FW_HEAP_SIZE_OVERRIDE_LIBOS3_BAREMETAL_MIN_MB: u32 = 88;
 pub const GSP_FW_HEAP_SIZE_OVERRIDE_LIBOS3_BAREMETAL_MAX_MB: u32 = 280;
+pub const GSP_FW_WPR_META_REVISION: u32 = 1;
+pub const GSP_FW_WPR_META_MAGIC: i64 = -2577556379034558285;
 pub type __u8 = ffi::c_uchar;
 pub type __u16 = ffi::c_ushort;
 pub type __u32 = ffi::c_uint;
Signature · 1 line
2.51.2
author maintainer
#8 lore raw

PATCH v9 6/15 gpu: nova-core: Add a slice-buffer (sbuffer) datastructure

In reply to Alexandre Courbot

From: Joel Fernandes <[email protected]>

A data structure that can be used to write across multiple slices which may be out of order in memory. This lets SBuffer user correctly and safely write out of memory order, without error-prone tracking of pointers/offsets.

    let mut buf1 = [0u8; 3];
    let mut buf2 = [0u8; 5];
    let mut sbuffer = SBuffer::new([&mut buf1[..], &mut buf2[..]]);

    let data = b"hello";
    let result = sbuffer.write(data);
---
 drivers/gpu/nova-core/nova_core.rs |   1 +
 drivers/gpu/nova-core/sbuffer.rs   | 232 +++++++++++++++++++++++++++++++++++++
 2 files changed, 233 insertions(+)
drivers/gpu/nova-core/nova_core.rs +1 -0
index 9180ec9c27ef..c1121e7c64c5 100644
@@ -15,6 +15,7 @@
 mod gsp;
 mod num;
 mod regs;
+mod sbuffer;
 mod vbios;
 
 pub(crate) const MODULE_NAME: &kernel::str::CStr = <LocalModule as kernel::ModuleMetadata>::NAME;
drivers/gpu/nova-core/sbuffer.rs new file +232 -0

232 lines not on this page · raw message

Signature · 1 line
2.51.2
author maintainer
#9 lore raw

PATCH v9 7/15 gpu: nova-core: Add zeroable trait to bindings

In reply to Alexandre Courbot

From: Alistair Popple <[email protected]>

Derive the Zeroable trait for existing bindgen generated bindings. This is safe because all bindgen generated types are simple integer types for which any bit pattern, including all zeros, is valid.

---
 drivers/gpu/nova-core/gsp/fw/r570_144.rs          |  5 ++++-
 drivers/gpu/nova-core/gsp/fw/r570_144/bindings.rs | 16 ++++++++--------
 2 files changed, 12 insertions(+), 9 deletions(-)
drivers/gpu/nova-core/gsp/fw/r570_144.rs +4 -1
index 82a973cd99c3..048234d1a9d1 100644
@@ -24,5 +24,8 @@
     unreachable_pub,
     unsafe_op_in_unsafe_fn
 )]
-use kernel::ffi;
+use kernel::{
+    ffi,
+    prelude::Zeroable, //
+};
 include!("r570_144/bindings.rs");
drivers/gpu/nova-core/gsp/fw/r570_144/bindings.rs +8 -8
index 392b25dc6991..f7b38978c5f8 100644
@@ -20,7 +20,7 @@
 pub type u32_ = __u32;
 pub type u64_ = __u64;
 #[repr(C)]
-#[derive(Copy, Clone)]
+#[derive(Copy, Clone, Zeroable)]
 pub struct GspFwWprMeta {
     pub magic: u64_,
     pub revision: u64_,
@@ -55,19 +55,19 @@ pub struct GspFwWprMeta {
     pub verified: u64_,
 }
 #[repr(C)]
-#[derive(Copy, Clone)]
+#[derive(Copy, Clone, Zeroable)]
 pub union GspFwWprMeta__bindgen_ty_1 {
     pub __bindgen_anon_1: GspFwWprMeta__bindgen_ty_1__bindgen_ty_1,
     pub __bindgen_anon_2: GspFwWprMeta__bindgen_ty_1__bindgen_ty_2,
 }
 #[repr(C)]
-#[derive(Debug, Default, Copy, Clone)]
+#[derive(Debug, Default, Copy, Clone, Zeroable)]
 pub struct GspFwWprMeta__bindgen_ty_1__bindgen_ty_1 {
     pub sysmemAddrOfSignature: u64_,
     pub sizeOfSignature: u64_,
 }
 #[repr(C)]
-#[derive(Debug, Default, Copy, Clone)]
+#[derive(Debug, Default, Copy, Clone, Zeroable)]
 pub struct GspFwWprMeta__bindgen_ty_1__bindgen_ty_2 {
     pub gspFwHeapFreeListWprOffset: u32_,
     pub unused0: u32_,
@@ -83,13 +83,13 @@ fn default() -> Self {
     }
 }
 #[repr(C)]
-#[derive(Copy, Clone)]
+#[derive(Copy, Clone, Zeroable)]
 pub union GspFwWprMeta__bindgen_ty_2 {
     pub __bindgen_anon_1: GspFwWprMeta__bindgen_ty_2__bindgen_ty_1,
     pub __bindgen_anon_2: GspFwWprMeta__bindgen_ty_2__bindgen_ty_2,
 }
 #[repr(C)]
-#[derive(Debug, Default, Copy, Clone)]
+#[derive(Debug, Default, Copy, Clone, Zeroable)]
 pub struct GspFwWprMeta__bindgen_ty_2__bindgen_ty_1 {
     pub partitionRpcAddr: u64_,
     pub partitionRpcRequestOffset: u16_,
@@ -101,7 +101,7 @@ pub struct GspFwWprMeta__bindgen_ty_2__bindgen_ty_1 {
     pub lsUcodeVersion: u32_,
 }
 #[repr(C)]
-#[derive(Debug, Default, Copy, Clone)]
+#[derive(Debug, Default, Copy, Clone, Zeroable)]
 pub struct GspFwWprMeta__bindgen_ty_2__bindgen_ty_2 {
     pub partitionRpcPadding: [u32_; 4usize],
     pub sysmemAddrOfCrashReportQueue: u64_,
@@ -136,7 +136,7 @@ fn default() -> Self {
 pub const LibosMemoryRegionLoc_LIBOS_MEMORY_REGION_LOC_FB: LibosMemoryRegionLoc = 2;
 pub type LibosMemoryRegionLoc = ffi::c_uint;
 #[repr(C)]
-#[derive(Debug, Default, Copy, Clone)]
+#[derive(Debug, Default, Copy, Clone, Zeroable)]
 pub struct LibosMemoryRegionInitArgument {
     pub id8: LibosAddress,
     pub pa: LibosAddress,
Signature · 1 line
2.51.2
author maintainer
#10 lore raw

PATCH v9 8/15 rust: enable slice_flatten feature and provide it through an extension trait

In reply to Alexandre Courbot

In Rust 1.80, the previously unstable slice::flatten family of methods have been stabilized and renamed to slice::as_flattened.

This creates an issue as we want to use as_flattened, but need to support the MSRV (which at the moment is Rust 1.78) where it is named flatten.

Solve this by enabling the slice_flatten feature, and providing an as_flattened implementation through an extension trait for compiler versions where it is not available.

The trait is then exported from the prelude, making the as_flattened family of methods transparently available for all supported compiler versions.

This extension trait can be removed once the MSRV passes 1.80.

---
 init/Kconfig           |  3 +++
 rust/kernel/lib.rs     |  4 ++++
 rust/kernel/prelude.rs |  3 +++
 rust/kernel/slice.rs   | 49 +++++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 59 insertions(+)
init/Kconfig +3 -0
index cab3ad28ca49..7da93c9cccc3 100644
@@ -147,6 +147,9 @@ config LD_CAN_USE_KEEP_IN_OVERLAY
 	# https://github.com/llvm/llvm-project/pull/130661
 	def_bool LD_IS_BFD || LLD_VERSION >= 210000
 
+config RUSTC_HAS_SLICE_AS_FLATTENED
+	def_bool RUSTC_VERSION >= 108000
+
 config RUSTC_HAS_COERCE_POINTEE
 	def_bool RUSTC_VERSION >= 108400
 
rust/kernel/lib.rs +4 -0
index 3dd7bebe7888..2581a356d114 100644
@@ -21,6 +21,9 @@
 #![feature(inline_const)]
 #![feature(pointer_is_aligned)]
 //
+// Stable since Rust 1.80.0.
+#![feature(slice_flatten)]
+//
 // Stable since Rust 1.81.0.
 #![feature(lint_reasons)]
 //
@@ -128,6 +131,7 @@
 pub mod security;
 pub mod seq_file;
 pub mod sizes;
+pub mod slice;
 mod static_assert;
 #[doc(hidden)]
 pub mod std_vendor;
rust/kernel/prelude.rs +3 -0
index 198d09a31449..9ee8acc563de 100644
@@ -51,3 +51,6 @@
 pub use super::current;
 
 pub use super::uaccess::UserPtr;
+
+#[cfg(not(CONFIG_RUSTC_HAS_SLICE_AS_FLATTENED))]
+pub use super::slice::AsFlattened;
rust/kernel/slice.rs new file +49 -0

49 lines not on this page · raw message

Signature · 1 line
2.51.2
author maintainer
#11 lore raw

PATCH v9 9/15 gpu: nova-core: gsp: Add GSP command queue bindings and handling

In reply to Alexandre Courbot

From: Alistair Popple <[email protected]>

This commit introduces core infrastructure for handling GSP command and message queues in the nova-core driver. The command queue system enables bidirectional communication between the host driver and GSP firmware through a remote message passing interface.

The interface is based on passing serialised data structures over a ring buffer with separate transmit and receive queues. Commands are sent by writing to the CPU transmit queue and waiting for completion via the receive queue.

To ensure safety mutable or immutable (depending on whether it is a send or receive operation) references are taken on the command queue when allocating the message to write/read to. This ensures message memory remains valid and the command queue can't be mutated whilst an operation is in progress.

Currently this is only used by the probe() routine and therefore can only used by a single thread of execution. Locking to enable safe access from multiple threads will be introduced in a future series when that becomes necessary.

---
 drivers/gpu/nova-core/gsp.rs                      |   7 +
 drivers/gpu/nova-core/gsp/cmdq.rs                 | 656 ++++++++++++++++++++++
 drivers/gpu/nova-core/gsp/fw.rs                   | 335 ++++++++++-
 drivers/gpu/nova-core/gsp/fw/r570_144/bindings.rs | 409 ++++++++++++++
 drivers/gpu/nova-core/regs.rs                     |   4 +
 drivers/gpu/nova-core/sbuffer.rs                  |   3 -
 6 files changed, 1410 insertions(+), 4 deletions(-)
drivers/gpu/nova-core/gsp.rs +7 -0
index ec053395694b..f9819a04bb40 100644
@@ -14,6 +14,7 @@
     transmute::AsBytes, //
 };
 
+pub(crate) mod cmdq;
 mod fw;
 
 pub(crate) use fw::{
@@ -22,6 +23,7 @@
 };
 
 use crate::{
+    gsp::cmdq::Cmdq,
     gsp::fw::LibosMemoryRegionInitArgument,
     num, //
 };
@@ -104,6 +106,8 @@ pub(crate) struct Gsp {
     logintr: LogBuffer,
     /// RM log buffer.
     logrm: LogBuffer,
+    /// Command queue.
+    pub(crate) cmdq: Cmdq,
 }
 
 impl Gsp {
@@ -128,11 +132,14 @@ pub(crate) fn new(pdev: &pci::Device<device::Bound>) -> Result<impl PinInit<Self
         let logrm = LogBuffer::new(dev)?;
         dma_write!(libos[2] = LibosMemoryRegionInitArgument::new("LOGRM", &logrm.0))?;
 
+        let cmdq = Cmdq::new(dev)?;
+
         Ok(try_pin_init!(Self {
             libos,
             loginit,
             logintr,
             logrm,
+            cmdq,
         }))
     }
 }
drivers/gpu/nova-core/gsp/cmdq.rs new file +656 -0

656 lines not on this page · raw message

drivers/gpu/nova-core/gsp/fw.rs +334 -1

359 lines not on this page · raw message

drivers/gpu/nova-core/gsp/fw/r570_144/bindings.rs +409 -0

429 lines not on this page · raw message

drivers/gpu/nova-core/regs.rs +4 -0
index 934003cab8a8..41fdda8a0748 100644
@@ -86,6 +86,10 @@ pub(crate) fn chipset(self) -> Result<Chipset> {
     30:30   ecc_mode_enabled as bool;
 });
 
+register!(NV_PGSP_QUEUE_HEAD @ 0x00110c00 {
+    31:0    address as u32;
+});
+
 impl NV_PFB_PRI_MMU_LOCAL_MEMORY_RANGE {
     /// Returns the usable framebuffer size, in bytes.
     pub(crate) fn usable_fb_size(self) -> u64 {
drivers/gpu/nova-core/sbuffer.rs +0 -3
index f0cecbcb81be..25e3ad665cac 100644
@@ -50,7 +50,6 @@ impl<'a, I> SBufferIter<I>
     /// let sum: u8 = sbuffer.sum();
     /// assert_eq!(sum, 45);
     /// ```
-    #[expect(unused)]
     pub(crate) fn new_reader(slices: impl IntoIterator<IntoIter = I>) -> Self
     where
         I: Iterator<Item = &'a [u8]>,
@@ -72,7 +71,6 @@ pub(crate) fn new_reader(slices: impl IntoIterator<IntoIter = I>) -> Self
     /// assert_eq!(buf2, [5, 6, 7, 8, 9]);
     ///
     /// ```
-    #[expect(unused)]
     pub(crate) fn new_writer(slices: impl IntoIterator<IntoIter = I>) -> Self
     where
         I: Iterator<Item = &'a mut [u8]>,
@@ -131,7 +129,6 @@ fn get_slice_internal(
     }
 
     /// Returns whether this buffer still has data available.
-    #[expect(unused)]
     pub(crate) fn is_empty(&self) -> bool {
         self.cur_slice.is_none()
     }
Signature · 1 line
2.51.2
author maintainer
#12 lore raw

PATCH v9 10/15 gpu: nova-core: gsp: Create rmargs

In reply to Alexandre Courbot

From: Alistair Popple <[email protected]>

Initialise the GSP resource manager arguments (rmargs) which provides initialisation parameters to the GSP firmware during boot. The rmargs structure contains arguments to configure the GSP message/command queue location.

These are mapped for coherent DMA and added to the libos data structure for access when booting GSP.

---
 drivers/gpu/nova-core/gsp.rs      | 18 ++++++++++++++--
 drivers/gpu/nova-core/gsp/cmdq.rs | 27 +++++++++++++++++++++++-
 drivers/gpu/nova-core/gsp/fw.rs   | 44 ++++++++++++++++++++++++++++++++++++++-
 3 files changed, 85 insertions(+), 4 deletions(-)
drivers/gpu/nova-core/gsp.rs +16 -2
index f9819a04bb40..609f8e5f2dcc 100644
@@ -24,8 +24,11 @@
 
 use crate::{
     gsp::cmdq::Cmdq,
-    gsp::fw::LibosMemoryRegionInitArgument,
-    num, //
+    gsp::fw::{
+        GspArgumentsCached,
+        LibosMemoryRegionInitArgument, //
+    },
+    num,
 };
 
 pub(crate) const GSP_PAGE_SHIFT: usize = 12;
@@ -108,6 +111,8 @@ pub(crate) struct Gsp {
     logrm: LogBuffer,
     /// Command queue.
     pub(crate) cmdq: Cmdq,
+    /// RM arguments.
+    rmargs: CoherentAllocation<GspArgumentsCached>,
 }
 
 impl Gsp {
@@ -134,11 +139,20 @@ pub(crate) fn new(pdev: &pci::Device<device::Bound>) -> Result<impl PinInit<Self
 
         let cmdq = Cmdq::new(dev)?;
 
+        let rmargs = CoherentAllocation::<GspArgumentsCached>::alloc_coherent(
+            dev,
+            1,
+            GFP_KERNEL | __GFP_ZERO,
+        )?;
+        dma_write!(rmargs[0] = fw::GspArgumentsCached::new(&cmdq))?;
+        dma_write!(libos[3] = LibosMemoryRegionInitArgument::new("RMARGS", &rmargs))?;
+
         Ok(try_pin_init!(Self {
             libos,
             loginit,
             logintr,
             logrm,
+            rmargs,
             cmdq,
         }))
     }
drivers/gpu/nova-core/gsp/cmdq.rs +26 -1
index c00d9fa9b79b..295903c28922 100644
@@ -11,7 +11,10 @@
 
 use kernel::{
     device,
-    dma::CoherentAllocation,
+    dma::{
+        CoherentAllocation,
+        DmaAddress, //
+    },
     dma_write,
     io::poll::read_poll_timeout,
     prelude::*,
@@ -33,6 +36,7 @@
             MsgqTxHeader, //
         },
         PteArray,
+        GSP_PAGE_SHIFT,
         GSP_PAGE_SIZE, //
     },
     num,
@@ -429,6 +433,22 @@ pub(crate) struct Cmdq {
 }
 
 impl Cmdq {
+    /// Offset of the data after the PTEs.
+    const POST_PTE_OFFSET: usize = core::mem::offset_of!(GspMem, cpuq);
+
+    /// Offset of command queue ring buffer.
+    pub(crate) const CMDQ_OFFSET: usize = core::mem::offset_of!(GspMem, cpuq)
+        + core::mem::offset_of!(Msgq, msgq)
+        - Self::POST_PTE_OFFSET;
+
+    /// Offset of message queue ring buffer.
+    pub(crate) const STATQ_OFFSET: usize = core::mem::offset_of!(GspMem, gspq)
+        + core::mem::offset_of!(Msgq, msgq)
+        - Self::POST_PTE_OFFSET;
+
+    /// Number of page table entries for the GSP shared region.
+    pub(crate) const NUM_PTES: usize = size_of::<GspMem>() >> GSP_PAGE_SHIFT;
+
     /// Creates a new command queue for `dev`.
     pub(crate) fn new(dev: &device::Device<device::Bound>) -> Result<Cmdq> {
         let gsp_mem = DmaGspMem::new(dev)?;
@@ -653,4 +673,9 @@ pub(crate) fn receive_msg<M: MessageFromGsp>(&mut self, timeout: Delta) -> Resul
 
         result
     }
+
+    /// Returns the DMA handle of the command queue's shared memory region.
+    pub(crate) fn dma_handle(&self) -> DmaAddress {
+        self.gsp_mem.0.dma_handle()
+    }
 }
drivers/gpu/nova-core/gsp/fw.rs +43 -1

53 lines not on this page · raw message

Signature · 1 line
2.51.2
author maintainer
#13 lore raw

PATCH v9 11/15 gpu: nova-core: gsp: Add SetSystemInfo command

In reply to Alexandre Courbot

From: Alistair Popple <[email protected]>

Add support for sending the SetSystemInfo command, which provides required hardware information to the GSP and is critical to its initialization.

---
 drivers/gpu/nova-core/gsp.rs                      |   1 +
 drivers/gpu/nova-core/gsp/boot.rs                 |  10 +-
 drivers/gpu/nova-core/gsp/cmdq.rs                 |   1 -
 drivers/gpu/nova-core/gsp/commands.rs             |  37 ++++++
 drivers/gpu/nova-core/gsp/fw.rs                   |   1 +
 drivers/gpu/nova-core/gsp/fw/commands.rs          |  56 +++++++++
 drivers/gpu/nova-core/gsp/fw/r570_144/bindings.rs | 132 ++++++++++++++++++++++
 7 files changed, 235 insertions(+), 3 deletions(-)
drivers/gpu/nova-core/gsp.rs +1 -0
index 609f8e5f2dcc..e40354c47608 100644
@@ -15,6 +15,7 @@
 };
 
 pub(crate) mod cmdq;
+pub(crate) mod commands;
 mod fw;
 
 pub(crate) use fw::{
drivers/gpu/nova-core/gsp/boot.rs +8 -2
index 5ea53250bf37..56c9950b742c 100644
@@ -29,7 +29,10 @@
         FIRMWARE_VERSION, //
     },
     gpu::Chipset,
-    gsp::GspFwWprMeta,
+    gsp::{
+        commands,
+        GspFwWprMeta, //
+    },
     regs,
     vbios::Vbios,
 };
@@ -119,7 +122,7 @@ fn run_fwsec_frts(
     ///
     /// Upon return, the GSP is up and running, and its runtime object given as return value.
     pub(crate) fn boot(
-        self: Pin<&mut Self>,
+        mut self: Pin<&mut Self>,
         pdev: &pci::Device<device::Bound>,
         bar: &Bar0,
         chipset: Chipset,
@@ -153,6 +156,9 @@ pub(crate) fn boot(
             CoherentAllocation::<GspFwWprMeta>::alloc_coherent(dev, 1, GFP_KERNEL | __GFP_ZERO)?;
         dma_write!(wpr_meta[0] = GspFwWprMeta::new(&gsp_fw, &fb_layout))?;
 
+        self.cmdq
+            .send_command(bar, commands::SetSystemInfo::new(pdev))?;
+
         Ok(())
     }
 }
drivers/gpu/nova-core/gsp/cmdq.rs +0 -1
index 295903c28922..c0f3218f2980 100644
@@ -489,7 +489,6 @@ fn notify_gsp(bar: &Bar0) {
     ///   written to by its [`CommandToGsp::init_variable_payload`] method.
     ///
     /// Error codes returned by the command initializers are propagated as-is.
-    #[expect(unused)]
     pub(crate) fn send_command<M>(&mut self, bar: &Bar0, command: M) -> Result
     where
         M: CommandToGsp,
drivers/gpu/nova-core/gsp/commands.rs new file +37 -0
new file mode 100644
index 000000000000..305045e25693
@@ -0,0 +1,37 @@
+// SPDX-License-Identifier: GPL-2.0
+
+use kernel::{
+    device,
+    pci,
+    prelude::*, //
+};
+
+use crate::gsp::{
+    cmdq::CommandToGsp,
+    fw::{
+        commands::GspSetSystemInfo,
+        MsgFunction, //
+    },
+};
+
+/// The `GspSetSystemInfo` command.
+pub(crate) struct SetSystemInfo<'a> {
+    pdev: &'a pci::Device<device::Bound>,
+}
+
+impl<'a> SetSystemInfo<'a> {
+    /// Creates a new `GspSetSystemInfo` command using the parameters of `pdev`.
+    pub(crate) fn new(pdev: &'a pci::Device<device::Bound>) -> Self {
+        Self { pdev }
+    }
+}
+
+impl<'a> CommandToGsp for SetSystemInfo<'a> {
+    const FUNCTION: MsgFunction = MsgFunction::GspSetSystemInfo;
+    type Command = GspSetSystemInfo;
+    type InitError = Error;
+
+    fn init(&self) -> impl Init<Self::Command, Self::InitError> {
+        GspSetSystemInfo::init(self.pdev)
+    }
+}
drivers/gpu/nova-core/gsp/fw.rs +1 -0
index b083a6a5754c..cacdfb2d4810 100644
@@ -1,5 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0
 
+pub(crate) mod commands;
 mod r570_144;
 
 // Alias to avoid repeating the version number with every use.
drivers/gpu/nova-core/gsp/fw/commands.rs new file +56 -0

56 lines not on this page · raw message

drivers/gpu/nova-core/gsp/fw/r570_144/bindings.rs +132 -0

138 lines not on this page · raw message

Signature · 1 line
2.51.2
author maintainer
#14 lore raw

PATCH v9 12/15 gpu: nova-core: gsp: Add SetRegistry command

In reply to Alexandre Courbot

From: Alistair Popple <[email protected]>

Add support for sending the SetRegistry command, which is critical to GSP initialization.

The RM registry is serialized into a packed format and sent via the command queue. For now only three parameters which are required to boot GSP are hardcoded. In the future a kernel module parameter will be added to enable other parameters to be added.

---
 drivers/gpu/nova-core/gsp/boot.rs                 |   1 +
 drivers/gpu/nova-core/gsp/commands.rs             | 104 ++++++++++++++++++++--
 drivers/gpu/nova-core/gsp/fw/commands.rs          |  50 +++++++++++
 drivers/gpu/nova-core/gsp/fw/r570_144/bindings.rs |  16 ++++
 drivers/gpu/nova-core/sbuffer.rs                  |   1 -
 5 files changed, 165 insertions(+), 7 deletions(-)
drivers/gpu/nova-core/gsp/boot.rs +1 -0
index 56c9950b742c..770731c3eb89 100644
@@ -158,6 +158,7 @@ pub(crate) fn boot(
 
         self.cmdq
             .send_command(bar, commands::SetSystemInfo::new(pdev))?;
+        self.cmdq.send_command(bar, commands::SetRegistry::new())?;
 
         Ok(())
     }
drivers/gpu/nova-core/gsp/commands.rs +98 -6

118 lines not on this page · raw message

drivers/gpu/nova-core/gsp/fw/commands.rs +50 -0

53 lines not on this page · raw message

drivers/gpu/nova-core/gsp/fw/r570_144/bindings.rs +16 -0
index 1251b0c313ce..32933874ff97 100644
@@ -649,6 +649,22 @@ pub struct LibosMemoryRegionInitArgument {
     pub __bindgen_padding_0: [u8; 6usize],
 }
 #[repr(C)]
+#[derive(Debug, Default, Copy, Clone)]
+pub struct PACKED_REGISTRY_ENTRY {
+    pub nameOffset: u32_,
+    pub type_: u8_,
+    pub __bindgen_padding_0: [u8; 3usize],
+    pub data: u32_,
+    pub length: u32_,
+}
+#[repr(C)]
+#[derive(Debug, Default)]
+pub struct PACKED_REGISTRY_TABLE {
+    pub size: u32_,
+    pub numEntries: u32_,
+    pub entries: __IncompleteArrayField<PACKED_REGISTRY_ENTRY>,
+}
+#[repr(C)]
 #[derive(Debug, Default, Copy, Clone, Zeroable)]
 pub struct msgqTxHeader {
     pub version: u32_,
drivers/gpu/nova-core/sbuffer.rs +0 -1
index 25e3ad665cac..7a5947b8be19 100644
@@ -199,7 +199,6 @@ fn get_slice_mut(&mut self, len: usize) -> Option<&'a mut [u8]> {
 
     /// Ideally we would implement [`Write`], but it is not available in `core`.
     /// So mimic `std::io::Write::write_all`.
-    #[expect(unused)]
     pub(crate) fn write_all(&mut self, mut src: &[u8]) -> Result {
         while !src.is_empty() {
             match self.get_slice_mut(src.len()) {
Signature · 1 line
2.51.2
author maintainer
#15 lore raw

PATCH v9 13/15 gpu: nova-core: falcon: Add support to check if RISC-V is active

In reply to Alexandre Courbot

From: Joel Fernandes <[email protected]>

Add definition for RISCV_CPUCTL register and use it in a new falcon API to check if the RISC-V core of a Falcon is active. It is required by the sequencer to know if the GSP's RISCV processor is active.

---
 drivers/gpu/nova-core/falcon.rs | 9 +++++++++
 drivers/gpu/nova-core/regs.rs   | 7 ++++++-
 2 files changed, 15 insertions(+), 1 deletion(-)
drivers/gpu/nova-core/falcon.rs +9 -0
index fe5b3256d972..4c1f36073533 100644
@@ -612,4 +612,13 @@ pub(crate) fn signature_reg_fuse_version(
         self.hal
             .signature_reg_fuse_version(self, bar, engine_id_mask, ucode_id)
     }
+
+    /// Check if the RISC-V core is active.
+    ///
+    /// Returns `true` if the RISC-V core is active, `false` otherwise.
+    #[expect(unused)]
+    pub(crate) fn is_riscv_active(&self, bar: &Bar0) -> bool {
+        let cpuctl = regs::NV_PRISCV_RISCV_CPUCTL::read(bar, &E::ID);
+        cpuctl.active_stat()
+    }
 }
drivers/gpu/nova-core/regs.rs +6 -1
index 41fdda8a0748..5d5ba766cd61 100644
@@ -339,7 +339,12 @@ pub(crate) fn mem_scrubbing_done(self) -> bool {
 
 // PRISCV
 
-register!(NV_PRISCV_RISCV_BCR_CTRL @ PFalconBase[0x00001668] {
+register!(NV_PRISCV_RISCV_CPUCTL @ PFalcon2Base[0x00000388] {
+    0:0     halted as bool;
+    7:7     active_stat as bool;
+});
+
+register!(NV_PRISCV_RISCV_BCR_CTRL @ PFalcon2Base[0x00000668] {
     0:0     valid as bool;
     4:4     core_select as bool => PeregrineCoreSelect;
     8:8     br_fetch as bool;
Signature · 1 line
2.51.2
author maintainer
#16 lore raw

PATCH v9 14/15 gpu: nova-core: falcon: Add support to write firmware version

In reply to Alexandre Courbot

From: Joel Fernandes <[email protected]>

This will be needed by both the GSP boot code as well as GSP resume code in the sequencer.

---
 drivers/gpu/nova-core/falcon.rs | 8 ++++++++
 drivers/gpu/nova-core/regs.rs   | 6 ++++++
 2 files changed, 14 insertions(+)
drivers/gpu/nova-core/falcon.rs +8 -0
index 4c1f36073533..31904e1d804b 100644
@@ -621,4 +621,12 @@ pub(crate) fn is_riscv_active(&self, bar: &Bar0) -> bool {
         let cpuctl = regs::NV_PRISCV_RISCV_CPUCTL::read(bar, &E::ID);
         cpuctl.active_stat()
     }
+
+    /// Write the application version to the OS register.
+    #[expect(dead_code)]
+    pub(crate) fn write_os_version(&self, bar: &Bar0, app_version: u32) {
+        regs::NV_PFALCON_FALCON_OS::default()
+            .set_value(app_version)
+            .write(bar, &E::ID);
+    }
 }
drivers/gpu/nova-core/regs.rs +6 -0
index 5d5ba766cd61..274e53a1a44d 100644
@@ -230,6 +230,12 @@ pub(crate) fn vga_workspace_addr(self) -> Option<u64> {
     31:0    value as u32;
 });
 
+// Used to store version information about the firmware running
+// on the Falcon processor.
+register!(NV_PFALCON_FALCON_OS @ PFalconBase[0x00000080] {
+    31:0    value as u32;
+});
+
 register!(NV_PFALCON_FALCON_RM @ PFalconBase[0x00000084] {
     31:0    value as u32;
 });
Signature · 1 line
2.51.2
author maintainer
#17 lore raw

PATCH v9 15/15 gpu: nova-core: gsp: Boot GSP

In reply to Alexandre Courbot

From: Alistair Popple <[email protected]>

Boot the GSP to the RISC-V active state. Completing the boot requires running the CPU sequencer which will be added in a future commit.

---
 drivers/gpu/nova-core/falcon.rs         |  2 -
 drivers/gpu/nova-core/firmware/riscv.rs |  3 +-
 drivers/gpu/nova-core/gsp/boot.rs       | 65 ++++++++++++++++++++++++++++++++-
 3 files changed, 64 insertions(+), 6 deletions(-)
drivers/gpu/nova-core/falcon.rs +0 -2
index 31904e1d804b..05b124acbfc1 100644
@@ -616,14 +616,12 @@ pub(crate) fn signature_reg_fuse_version(
     /// Check if the RISC-V core is active.
     ///
     /// Returns `true` if the RISC-V core is active, `false` otherwise.
-    #[expect(unused)]
     pub(crate) fn is_riscv_active(&self, bar: &Bar0) -> bool {
         let cpuctl = regs::NV_PRISCV_RISCV_CPUCTL::read(bar, &E::ID);
         cpuctl.active_stat()
     }
 
     /// Write the application version to the OS register.
-    #[expect(dead_code)]
     pub(crate) fn write_os_version(&self, bar: &Bar0, app_version: u32) {
         regs::NV_PFALCON_FALCON_OS::default()
             .set_value(app_version)
drivers/gpu/nova-core/firmware/riscv.rs +1 -2
index 7d82fb9876e8..28dfef63657a 100644
@@ -57,7 +57,6 @@ fn new(bin_fw: &BinFirmware<'_>) -> Result<Self> {
 }
 
 /// 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.
     pub(crate) code_offset: u32,
@@ -66,7 +65,7 @@ pub(crate) struct RiscvFirmware {
     /// Offset at which the manifest starts in the firmware image.
     pub(crate) manifest_offset: u32,
     /// Application version.
-    app_version: u32,
+    pub(crate) app_version: u32,
     /// Device-mapped firmware image.
     pub(crate) ucode: DmaObject,
 }
drivers/gpu/nova-core/gsp/boot.rs +63 -2

84 lines not on this page · raw message

Signature · 1 line
2.51.2
author maintainer Applied
#18 lore raw
In reply to Alexandre Courbot
Quoted 11 lines · Alexandre Courbot

This revision features a more adequate method for receiving messages, and some general cleanup. It looks solid to me, and although there are further minor improvements I want to eventually see I think it makes an adequate first milestone.

I am considering merging this before -rc6, so it can make it into 6.19. If there are reasons not to, please scream. :)

A branch including this series and its dependencies is available at [1].

[1] https://github.com/Gnurou/linux/tree/b4/gsp_boot

Pushed to drm-rust-next after fixing the last issue spotted by Mikko - thanks everyone!