Skip to contentSkip to conversation

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

PATCH New Alistair Popple 1 participant 12 messages Oct 17, 2025

Subsystems (6)
DRM drivers Kbuild RISC-V Rust +2 more subsystems
lore
Share & tools
lore
#0 lore raw

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

Changes since v5:

Most of the changes incorporated here are minor documentation and comment fixes based on feedback from Alex. There are still a couple of outstanding comments to address, in particular dealing with the Rust compatiblity changes for slice_flatten as suggested by Miguel.

However I am going to be unable to look at these for a few weeks so Alex has kindly offered to help finish addressing the outstanding comments and will likely post a more refined version of this series shortly. Thanks!

Changes since v4:

The main change for this revision is to derive the Zeroable trait for most of our bindings. The rest of the changes just address relatively minor review comments made for v4 of the series.

This series is still based on a merge of drm-rust-next and drivers-core-testing made by Alex. A complete copy of the tree with these patches applied will be available at
https://github.com/apopple-nvidia/linux/tree/nova-core-for-upstream-v5

Changes since v3:

The main change for v4 is to switch to using the init! macros to ensure all fields on in-place initialised structs get initialised. This will require our bindings to derive the Zeroable trait, however for now I have left this as a TODO with manual implementations for each trait. That is because rebasing the binding changes is a bit of a pain, so I want to give reviewers a change to see if deriving Zeroable for all bindings makes sense or not.

Other changes include addressing most of the outstanding TODOs left in v3 and addressing review comments from v2 and v3. In particular some of the comments by Timur that had not been picked up.

Changes since v2:

The main change since v2 has been to make all firmware bindings completely opaque. It has been made clear this is a pre-requisite for this series to progress upstream as it should make supporting different firmware versions easier in future.

Overall the extra constructors and accessors add a couple of hundred lines of code and a few extra unsafe statements.

Other changes include addressing a bunch of other comments - see the individual patches for further details. There are also still some outstanding comments and TODO's to address which I have not gotten to yet - these will be done in the next version of this series.

Changes since v1:

- Based on feed back from Alex the GSP command queue logic was reworked extensively. This involved creating a new data struct (DmaGspMem) to manage the shared memory areas between CPU and GSP.

- This data structure helps ensure the safety constraints are meet when the CPU is reading/writing the shared memory queues.

- Several other minor comments were addressed, as noted in the individual patches.

This series builds on top of Alex's series[1], most of which has been merged into drm-rust-next, to continue initialising the GSP into a state where it becomes active and it starts communicating with the host. A tree including these patches with the prerequisite patches is available at [2].

It includes patches to initialise several important data structures required to boot the GSP. The biggest change is the implementation of the command/message circular queue used to establish communication between GSP and host in patch 6. Admittedly this patch is rather large - if necessary it could be split into send and receive patches if people prefer.

This is required to configure and boot the GSP. However this series does not get the GSP to a fully active state. Instead it gets it to a state where the GSP sends a message to the host with a sequence of instructions which need running to get to the active state. A subsequent series will implement processing of this message and allow the GSP to get to the fully active state.

A full tree including the prerequisites for this patch series is available at https://github.com/apopple-nvidia/linux/tree/nova-core-for-upstream.

[1] - https://lore.kernel.org/rust-for-linux/[email protected]/
[2] - https://github.com/apopple-nvidia/linux/tree/nova-core-for-upstream-v2

Alistair Popple (8):
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 RM registry and sysinfo bindings and commands
nova-core: gsp: Boot GSP

Joel Fernandes (3):
gpu: nova-core: Add a slice-buffer (sbuffer) datastructure
nova-core: falcon: Add support to check if RISC-V is active
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                   |   1 -
 drivers/gpu/nova-core/firmware/gsp.rs         |   3 +-
 drivers/gpu/nova-core/firmware/riscv.rs       |   9 +-
 drivers/gpu/nova-core/gpu.rs                  |   2 +-
 drivers/gpu/nova-core/gsp.rs                  | 135 +++-
 drivers/gpu/nova-core/gsp/boot.rs             |  76 ++-
 drivers/gpu/nova-core/gsp/cmdq.rs             | 533 ++++++++++++++++
 drivers/gpu/nova-core/gsp/commands.rs         | 117 ++++
 drivers/gpu/nova-core/gsp/fw.rs               | 449 ++++++++++++-
 drivers/gpu/nova-core/gsp/fw/commands.rs      | 100 +++
 drivers/gpu/nova-core/gsp/fw/r570_144.rs      |   1 +
 .../gpu/nova-core/gsp/fw/r570_144/bindings.rs | 592 +++++++++++++++++-
 drivers/gpu/nova-core/nova_core.rs            |   1 +
 drivers/gpu/nova-core/regs.rs                 |  17 +-
 drivers/gpu/nova-core/sbuffer.rs              | 222 +++++++
 scripts/Makefile.build                        |   2 +-
 18 files changed, 2259 insertions(+), 32 deletions(-)
 create mode 100644 drivers/gpu/nova-core/gsp/cmdq.rs
 create mode 100644 drivers/gpu/nova-core/gsp/commands.rs
 create mode 100644 drivers/gpu/nova-core/gsp/fw/commands.rs
 create mode 100644 drivers/gpu/nova-core/sbuffer.rs
Signature · 1 line
2.50.1
#1 lore raw

PATCH v6 1/11 gpu: nova-core: Set correct DMA mask

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

---

Changes for v5:
- Update SAFETY comment for dma_set_mask_and_coherent()
- Add TODO for using different masks when we support more GPU models

Changes for v4:
- Use a const (GPU_DMA_BITS) instead of a magic number

Changes for v2:
- Update DMA mask to correct value for Ampere/Turing (47 bits)

---
 drivers/gpu/nova-core/driver.rs | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
drivers/gpu/nova-core/driver.rs +16 -0
index edc72052e27a..2407d0ab15e2 100644
@@ -3,6 +3,8 @@
 use kernel::{
     auxiliary, c_str,
     device::Core,
+    dma::Device,
+    dma::DmaMask,
     pci,
     pci::{Class, ClassMask, Vendor},
     prelude::*,
@@ -20,6 +22,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!(
@@ -57,6 +68,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.50.1
#2 lore raw

PATCH v6 2/11 gpu: nova-core: Create initial Gsp

In reply to Alistair Popple

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.

---

Changes for v5:
- Move GSP_HEAP_ALIGNMENT to gsp/fw.rs and add a comment.
- Create a LogBuffer type.
- Use checked_add to ensure PTE values don't overflow.
- Added some type documentation (shamelessly stolen from Nouveau)

Change for v3:
- Clean up the PTE array creation, with much thanks to Alex for doing most it (please let me know if I should put you as co-developer!)

Changes for v2:
- Renamed GspMemOjbects to Gsp as that is what they are
- Rebased on Alex's latest series

---
 drivers/gpu/nova-core/gpu.rs                  |   2 +-
 drivers/gpu/nova-core/gsp.rs                  | 106 ++++++++++++++++--
 drivers/gpu/nova-core/gsp/fw.rs               |  64 ++++++++++-
 .../gpu/nova-core/gsp/fw/r570_144/bindings.rs |  19 ++++
 4 files changed, 179 insertions(+), 12 deletions(-)
drivers/gpu/nova-core/gpu.rs +1 -1
index ea124d1912e7..c1396775e9b6 100644
@@ -197,7 +197,7 @@ pub(crate) fn new<'a>(
 
             sec2_falcon: Falcon::new(pdev.as_ref(), spec.chipset, bar, true)?,
 
-            gsp <- Gsp::new(),
+            gsp <- Gsp::new(pdev)?,
 
             _: { gsp.boot(pdev, bar, spec.chipset, gsp_falcon, sec2_falcon)? },
 
drivers/gpu/nova-core/gsp.rs +99 -7

124 lines not on this page · raw message

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

92 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.50.1
#3 lore raw

PATCH v6 3/11 gpu: nova-core: gsp: Create wpr metadata

In reply to Alistair Popple

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.

---

Changes for v5:
- Make member visibility match the struct visibility (thanks Danilo)

Changes for v3:
- Don't re-export WPR constants (thanks Alex)

Changes for v2:
- Rebased on Alex's latest version

---
 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.rs                  |  4 ++
 drivers/gpu/nova-core/gsp/boot.rs             |  7 +++
 drivers/gpu/nova-core/gsp/fw.rs               | 55 ++++++++++++++++++-
 .../gpu/nova-core/gsp/fw/r570_144/bindings.rs |  2 +
 7 files changed, 71 insertions(+), 7 deletions(-)
drivers/gpu/nova-core/fb.rs +0 -1
index 4d6a1f452183..5580498ba2fb 100644
@@ -87,7 +87,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 3a1cf0607de7..fb0f69d04ef8 100644
@@ -131,7 +131,7 @@ pub(crate) struct GspFirmware {
     /// Size in bytes of the firmware contained in [`Self::fw`].
     pub 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 bootloader: RiscvFirmware,
 }
@@ -216,7 +216,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 04f1283abb72..115b5f5355a1 100644
@@ -55,11 +55,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.rs +4 -0
index f1727173bd42..8cb389c97733 100644
@@ -10,6 +10,8 @@
 use kernel::prelude::*;
 use kernel::transmute::AsBytes;
 
+use crate::fb::FbLayout;
+
 pub(crate) use fw::{GspFwWprMeta, LibosParams};
 
 mod fw;
@@ -103,8 +105,10 @@ pub(crate) fn new(pdev: &pci::Device<device::Bound>) -> Result<impl PinInit<Self
         // kgspSetupLibosInitArgs_IMPL (creates pLibosInitArgs[] array)
         let loginit = LogBuffer::new(dev)?;
         dma_write!(libos[0] = LibosMemoryRegionInitArgument::new("LOGINIT", &loginit.0)?)?;
+
         let logintr = LogBuffer::new(dev)?;
         dma_write!(libos[1] = LibosMemoryRegionInitArgument::new("LOGINTR", &logintr.0)?)?;
+
         let logrm = LogBuffer::new(dev)?;
         dma_write!(libos[2] = LibosMemoryRegionInitArgument::new("LOGRM", &logrm.0)?)?;
 
drivers/gpu/nova-core/gsp/boot.rs +7 -0
index fb22508128c4..6959581c538b 100644
@@ -1,6 +1,8 @@
 // SPDX-License-Identifier: GPL-2.0
 
 use kernel::device;
+use kernel::dma::CoherentAllocation;
+use kernel::dma_write;
 use kernel::pci;
 use kernel::prelude::*;
 
@@ -14,6 +16,7 @@
     FIRMWARE_VERSION,
 };
 use crate::gpu::Chipset;
+use crate::gsp::GspFwWprMeta;
 use crate::regs;
 use crate::vbios::Vbios;
 
@@ -132,6 +135,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 +54 -1

70 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.50.1
#4 lore raw

PATCH v6 4/11 gpu: nova-core: Add a slice-buffer (sbuffer) datastructure

In reply to Alistair Popple

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);

An internal conversion of gsp.rs to use this resulted in a nice -ve delta:
gsp.rs: 37 insertions(+), 99 deletions(-)

---

Changes for v5:
- Typos
- s/ETOOSMALL/EINVAL/
- Add documentation
- Fix up examples

Changes for v3:
- Addressed minor review comment from Lyude

---
 drivers/gpu/nova-core/nova_core.rs |   1 +
 drivers/gpu/nova-core/sbuffer.rs   | 225 +++++++++++++++++++++++++++++
 2 files changed, 226 insertions(+)
 create mode 100644 drivers/gpu/nova-core/sbuffer.rs
drivers/gpu/nova-core/nova_core.rs +1 -0
index fffcaee2249f..a6feeba6254c 100644
@@ -11,6 +11,7 @@
 mod gpu;
 mod gsp;
 mod regs;
+mod sbuffer;
 mod util;
 mod vbios;
 
drivers/gpu/nova-core/sbuffer.rs new file +225 -0

225 lines not on this page · raw message

Signature · 1 line
2.50.1
#5 lore raw

PATCH v6 5/11 gpu: nova-core: Add zeroable trait to bindings

In reply to Alistair Popple

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.

---

Changes for v5:
- New for v5

---
 drivers/gpu/nova-core/gsp/fw/r570_144.rs         |  1 +
 .../gpu/nova-core/gsp/fw/r570_144/bindings.rs    | 16 ++++++++--------
 2 files changed, 9 insertions(+), 8 deletions(-)
drivers/gpu/nova-core/gsp/fw/r570_144.rs +1 -0
index 82a973cd99c3..4f5c65ac1eb9 100644
@@ -25,4 +25,5 @@
     unsafe_op_in_unsafe_fn
 )]
 use kernel::ffi;
+use kernel::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.50.1
#6 lore raw

PATCH v6 6/11 gpu: nova-core: gsp: Add GSP command queue bindings and handling

In reply to Alistair Popple

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.

---

Changes for v6:
- Squahsed the bindings in as these are standalone and it eases dealing with some unused linter errors.

Changes for v4:
- Use read_poll_timeout() instead of wait_on()
- Switch to using init! (Thanks Alex for figuring out the required workarounds)
- Pass the enum type into the RPC bindings instead of a raw u32
- Fixup the TODOs for extracting/allocating the send command regions
- Split the sending functions into one taking just a command struct and another taking a command struct with extra payload

Changes for v3:
- Reduce the receive payloads to the correct size
- Use opaque bindings
- Clean up of the command queue PTE creation
- Add an enum for the GSP functions
- Rename GspCommandToGsp and GspMessageFromGsp
- Rename GspCmdq
- Add function to notify GSP of updated queue pointers
- Inline driver area access functions
- Fixup receive area calculations

Changes for v2:
- Rebased on Alex's latest series

---
 drivers/gpu/nova-core/gsp.rs                  |   7 +
 drivers/gpu/nova-core/gsp/cmdq.rs             | 517 ++++++++++++++++++
 drivers/gpu/nova-core/gsp/fw.rs               | 275 ++++++++++
 .../gpu/nova-core/gsp/fw/r570_144/bindings.rs | 409 ++++++++++++++
 drivers/gpu/nova-core/regs.rs                 |   4 +
 drivers/gpu/nova-core/sbuffer.rs              |   2 -
 scripts/Makefile.build                        |   2 +-
 7 files changed, 1213 insertions(+), 3 deletions(-)
 create mode 100644 drivers/gpu/nova-core/gsp/cmdq.rs
drivers/gpu/nova-core/gsp.rs +7 -0
index 8cb389c97733..31eeaf76526a 100644
@@ -11,6 +11,7 @@
 use kernel::transmute::AsBytes;
 
 use crate::fb::FbLayout;
+use crate::gsp::cmdq::Cmdq;
 
 pub(crate) use fw::{GspFwWprMeta, LibosParams};
 
@@ -18,6 +19,8 @@
 
 use fw::LibosMemoryRegionInitArgument;
 
+pub(crate) mod cmdq;
+
 pub(crate) const GSP_PAGE_SHIFT: usize = 12;
 pub(crate) const GSP_PAGE_SIZE: usize = 1 << GSP_PAGE_SHIFT;
 
@@ -31,6 +34,7 @@ pub(crate) struct Gsp {
     loginit: LogBuffer,
     logintr: LogBuffer,
     logrm: LogBuffer,
+    pub(crate) cmdq: Cmdq,
 }
 
 #[repr(C)]
@@ -112,11 +116,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 +517 -0

517 lines not on this page · raw message

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

296 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 206dab2e1335..0585699ae951 100644
@@ -71,6 +71,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 -2
index 39c973ee3e10..acde73132ba0 100644
@@ -49,7 +49,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]>,
@@ -71,7 +70,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]>,
scripts/Makefile.build +1 -1
index d0ee33a487be..4ac6304332b6 100644
@@ -317,7 +317,7 @@ $(obj)/%.lst: $(obj)/%.c FORCE
 #
 # Please see https://github.com/Rust-for-Linux/linux/issues/2 for details on
 # the unstable features in use.
-rust_allowed_features := asm_const,asm_goto,arbitrary_self_types,lint_reasons,offset_of_nested,raw_ref_op,used_with_arg
+rust_allowed_features := asm_const,asm_goto,arbitrary_self_types,lint_reasons,offset_of_nested,raw_ref_op,used_with_arg,slice_flatten
 
 # `--out-dir` is required to avoid temporaries being created by `rustc` in the
 # current working directory, which may be not accessible in the out-of-tree
Signature · 1 line
2.50.1
#7 lore raw

PATCH v6 7/11 gpu: nova-core: gsp: Create rmargs

In reply to Alistair Popple

Initialise the GSP resource manager arguments (rmargs) which provide 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.

---

Changes for v5:
- Derive Zeroable trait

Changes for v2:
- Rebased on Alex's latest series

---
 drivers/gpu/nova-core/gsp.rs      | 17 ++++++++++
 drivers/gpu/nova-core/gsp/cmdq.rs | 24 ++++++++++++--
 drivers/gpu/nova-core/gsp/fw.rs   | 54 +++++++++++++++++++++++++++++++
 3 files changed, 92 insertions(+), 3 deletions(-)
drivers/gpu/nova-core/gsp.rs +17 -0
index 31eeaf76526a..f08bb0924edb 100644
@@ -17,6 +17,7 @@
 
 mod fw;
 
+use fw::GspArgumentsCached;
 use fw::LibosMemoryRegionInitArgument;
 
 pub(crate) mod cmdq;
@@ -35,6 +36,7 @@ pub(crate) struct Gsp {
     logintr: LogBuffer,
     logrm: LogBuffer,
     pub(crate) cmdq: Cmdq,
+    rmargs: CoherentAllocation<GspArgumentsCached>,
 }
 
 #[repr(C)]
@@ -118,11 +120,26 @@ 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!(libos[3] = LibosMemoryRegionInitArgument::new("RMARGS", &rmargs)?)?;
+
+        dma_write!(
+            rmargs[0] = fw::GspArgumentsCached::new(
+                fw::MessageQueueInitArguments::new(&cmdq),
+                fw::GspSrInitArguments::new()
+            )
+        )?;
+
         Ok(try_pin_init!(Self {
             libos,
             loginit,
             logintr,
             logrm,
+            rmargs,
             cmdq,
         }))
     }
drivers/gpu/nova-core/gsp/cmdq.rs +21 -3
index 42973c52cb03..5589bb333c16 100644
@@ -5,7 +5,7 @@
 use core::sync::atomic::Ordering;
 
 use kernel::device;
-use kernel::dma::CoherentAllocation;
+use kernel::dma::{CoherentAllocation, DmaAddress};
 use kernel::dma_write;
 use kernel::io::poll::read_poll_timeout;
 use kernel::prelude::*;
@@ -283,10 +283,25 @@ pub(crate) struct Cmdq {
     dev: ARef<device::Device>,
     seq: u32,
     gsp_mem: DmaGspMem,
-    pub _nr_ptes: u32,
 }
 
 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;
+
     pub(crate) fn new(dev: &device::Device<device::Bound>) -> Result<Cmdq> {
         let gsp_mem = DmaGspMem::new(dev)?;
         let nr_ptes = size_of::<GspMem>() >> GSP_PAGE_SHIFT;
@@ -296,7 +311,6 @@ pub(crate) fn new(dev: &device::Device<device::Bound>) -> Result<Cmdq> {
             dev: dev.into(),
             seq: 0,
             gsp_mem,
-            _nr_ptes: nr_ptes as u32,
         })
     }
 
@@ -514,4 +528,8 @@ pub(crate) fn receive_msg_from_gsp<M: MessageFromGsp, R>(
             .advance_cpu_read_ptr(msg_header.length().div_ceil(GSP_PAGE_SIZE as u32));
         result
     }
+
+    pub(crate) fn dma_handle(&self) -> DmaAddress {
+        self.gsp_mem.0.dma_handle()
+    }
 }
drivers/gpu/nova-core/gsp/fw.rs +54 -0

63 lines not on this page · raw message

Signature · 1 line
2.50.1
#8 lore raw

PATCH v6 8/11 gpu: nova-core: gsp: Add RM registry and sysinfo bindings and commands

In reply to Alistair Popple

Add the RM registry and system information commands that enable the host driver to configure GSP firmware parameters during initialization.

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

Also add the system info command, which provides required hardware information to the GSP. These commands use the GSP command queue infrastructure to issue commands to the GSP which is read during GSP boot.

---

Changes for v6:
- Merge the bindings in to address some unused linter errors.

Changes for v4:
- Use init! macros
- Update to use send_gsp_command_with_payload() for the registry
- Add RMDevidCheckIgnore registry setting (thanks Timur)

Changes for v3:
- Use MsgFunction enum
- Rename GspCmdq to Cmdq
- Rename GspCommandToGsp to CommandToGsp
- Rename GspMessageFromGsp to MessageFromGsp
- Split bindings into separate patch

Changes for v2:
- Rebased on Alex's latest tree

---
 drivers/gpu/nova-core/gsp.rs                  |   1 +
 drivers/gpu/nova-core/gsp/boot.rs             |   6 +-
 drivers/gpu/nova-core/gsp/cmdq.rs             |   2 -
 drivers/gpu/nova-core/gsp/commands.rs         | 117 ++++++++++++++
 drivers/gpu/nova-core/gsp/fw.rs               |   1 +
 drivers/gpu/nova-core/gsp/fw/commands.rs      | 100 ++++++++++++
 .../gpu/nova-core/gsp/fw/r570_144/bindings.rs | 148 ++++++++++++++++++
 drivers/gpu/nova-core/sbuffer.rs              |   1 -
 8 files changed, 372 insertions(+), 4 deletions(-)
 create mode 100644 drivers/gpu/nova-core/gsp/commands.rs
 create mode 100644 drivers/gpu/nova-core/gsp/fw/commands.rs
drivers/gpu/nova-core/gsp.rs +1 -0
index f08bb0924edb..73576558815a 100644
@@ -21,6 +21,7 @@
 use fw::LibosMemoryRegionInitArgument;
 
 pub(crate) mod cmdq;
+pub(crate) mod commands;
 
 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 +5 -1
index 6959581c538b..592c9b37e852 100644
@@ -16,6 +16,7 @@
     FIRMWARE_VERSION,
 };
 use crate::gpu::Chipset;
+use crate::gsp::commands::{build_registry, set_system_info};
 use crate::gsp::GspFwWprMeta;
 use crate::regs;
 use crate::vbios::Vbios;
@@ -105,7 +106,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,
@@ -139,6 +140,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)?)?;
 
+        set_system_info(&mut self.cmdq, pdev, bar)?;
+        build_registry(&mut self.cmdq, bar)?;
+
         Ok(())
     }
 }
drivers/gpu/nova-core/gsp/cmdq.rs +0 -2
index 5589bb333c16..2938706d7e38 100644
@@ -330,7 +330,6 @@ fn notify_gsp(bar: &Bar0) {
             .write(bar);
     }
 
-    #[expect(unused)]
     pub(crate) fn send_gsp_command<M, E>(&mut self, bar: &Bar0, init: impl Init<M, E>) -> Result
     where
         M: CommandToGsp,
@@ -342,7 +341,6 @@ pub(crate) fn send_gsp_command<M, E>(&mut self, bar: &Bar0, init: impl Init<M, E
         self.send_gsp_command_base_with_payload(bar, 0, init, |_| Ok(()))
     }
 
-    #[expect(unused)]
     pub(crate) fn send_gsp_command_with_payload<M, E>(
         &mut self,
         bar: &Bar0,
drivers/gpu/nova-core/gsp/commands.rs new file +117 -0

117 lines not on this page · raw message

drivers/gpu/nova-core/gsp/fw.rs +1 -0
index f862422714db..d7e0c2229e62 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 +100 -0

100 lines not on this page · raw message

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

160 lines not on this page · raw message

drivers/gpu/nova-core/sbuffer.rs +0 -1
index acde73132ba0..4d7cbc4bd060 100644
@@ -193,7 +193,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.50.1
#9 lore raw

PATCH v6 9/11 nova-core: falcon: Add support to check if RISC-V is active

In reply to Alistair Popple

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.

---

Changes for v4:
- Return bool instead of Result<bool> from is_riscv_active() as it can't fail (thanks Timur).
- Update register definitions to correct Falcon
- Switch register definition order

---
 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 734ac0fbfb49..185ed6d1cfb8 100644
@@ -506,4 +506,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 0585699ae951..3bd1bddb16bb 100644
@@ -324,7 +324,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.50.1
#10 lore raw

PATCH v6 10/11 nova-core: falcon: Add support to write firmware version

In reply to Alistair Popple

From: Joel Fernandes <[email protected]>

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

---

Changes for v5:
- Make it infallible

---
 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 185ed6d1cfb8..c871fd061987 100644
@@ -515,4 +515,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 3bd1bddb16bb..6eda5c44c599 100644
@@ -215,6 +215,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.50.1
#11 lore raw

PATCH v6 11/11 nova-core: gsp: Boot GSP

In reply to Alistair Popple

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.

---

Changes for v4:
- Switch wait_on to read_poll_timeout

Changes for v3:
- Fixed minor nit from John
- Added booter load error thanks to Timur's suggestion

Changes for v2:
- Rebased on Alex's latest tree

---
 drivers/gpu/nova-core/falcon.rs         |  2 -
 drivers/gpu/nova-core/firmware/riscv.rs |  3 +-
 drivers/gpu/nova-core/gsp/boot.rs       | 63 ++++++++++++++++++++++++-
 3 files changed, 63 insertions(+), 5 deletions(-)
drivers/gpu/nova-core/falcon.rs +0 -2
index c871fd061987..98ad75b93ea2 100644
@@ -510,14 +510,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 115b5f5355a1..98be14263366 100644
@@ -52,7 +52,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,
@@ -61,7 +60,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 app_version: u32,
     /// Device-mapped firmware image.
     pub ucode: DmaObject,
 }
drivers/gpu/nova-core/gsp/boot.rs +62 -1

83 lines not on this page · raw message

Signature · 1 line
2.50.1