Skip to contentSkip to conversation

gpu: nova-core: switch to the r000 GSP firmware

PATCH In review Alexandre Courbot 4 participants 22 messages Dec 3

Subsystems (7)
lore
Share & tools
lore

Alexandre Courbot

author maintainer
#0 lore raw

cover gpu: nova-core: switch to the r000 GSP firmware

This series completes the work started from John's r000 series [1] and switches nova-core from the r570 GSP firmware to the ABI-stable r000 firmware interface (used by OpenRM 6xx and later).

Because the driver boots a single firmware format, the incompatible parts of the protocol (queue pointers in BAR0 registers, MCTP/NVDM element headers, GSP_INIT/GSP_SUSPEND GMC commands, load-and-execute events, ucodes and state monitor buffers) must switch together. To keep that switch commit as small and reviewable as possible, everything that can either run on r570 or be compiled ahead of time is landed first, and the removal of r570-only code is performed in follow-up patches:

- Patches 1-6 add the remaining r000 building blocks (GSP_INIT with SR-IOV VF info, GSP_SUSPEND, and the ucodes loader).
- Patches 7-11 prepare existing code and bindings for the switch while remaining compatible with r570.
- Patch 12 performs the atomic switch to the r000 GSP firmware.
- Patches 13-15 delete the now-unused r570 code (GSP sequencer, r570 RPC commands, and r570 bindings).

The tree right before patch 12 has been tested to boot on r570, and patch 12 onwards has been tested to boot on r615 across Turing, Ampere, and Blackwell.

Based on drm-rust-next.

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

---
Alexandre Courbot (3):
gpu: nova-core: gsp: nvkv: add const constructor for Key
gpu: nova-core: gsp: re-export PowerStateLevel from gsp::commands
gpu: nova-core: gsp: zero-initialize FMC boot parameter structs

John Hubbard (11):
gpu: nova-core: gsp: add the GSP_INIT command and its reply
gpu: nova-core: gsp: add the GSP_SUSPEND request
gpu: nova-core: firmware: add the ucodes firmware loader
gpu: nova-core: gsp: define GSP_MSG_QUEUE_ELEMENT_SIZE_MAX without bindings
gpu: nova-core: fb: increase Blackwell reserved memory sizes for r000
gpu: nova-core: gsp: drain the message queue while waiting for GSP suspend
gpu: nova-core: firmware: add r000 GSP bindings
gpu: nova-core: switch to the r000 GSP firmware
gpu: nova-core: gsp: delete the GSP sequencer
gpu: nova-core: gsp: delete the r570 RPC commands
gpu: nova-core: firmware: delete the r570 bindings

Zhi Wang (1):
gpu: nova-core: gsp: populate VF information in GSP_INIT

 Documentation/gpu/nova/core/falcon.rst             |    2 +-
 Documentation/gpu/nova/core/interrupts.rst         |   30 +-
 drivers/gpu/nova-core/fb/hal/gb100.rs              |   23 +-
 drivers/gpu/nova-core/fb/hal/gb202.rs              |    4 +-
 drivers/gpu/nova-core/firmware.rs                  |    7 +-
 drivers/gpu/nova-core/firmware/ucodes.rs           |   65 ++
 drivers/gpu/nova-core/fsp.rs                       |    3 +-
 drivers/gpu/nova-core/gsp.rs                       |    9 +-
 drivers/gpu/nova-core/gsp/boot.rs                  |   72 +-
 drivers/gpu/nova-core/gsp/cmdq.rs                  |  366 ++++---
 drivers/gpu/nova-core/gsp/cmdq/gmc.rs              |   21 +-
 drivers/gpu/nova-core/gsp/cmdq/rpc.rs              |   42 +-
 drivers/gpu/nova-core/gsp/cmdq/rpc/continuation.rs |   10 +-
 drivers/gpu/nova-core/gsp/commands.rs              |    7 +-
 drivers/gpu/nova-core/gsp/commands/gmc.rs          |  174 ++++
 drivers/gpu/nova-core/gsp/commands/rpc.rs          |  284 ------
 drivers/gpu/nova-core/gsp/fw.rs                    |  530 ++--------
 drivers/gpu/nova-core/gsp/fw/commands.rs           |  473 ++++-----
 drivers/gpu/nova-core/gsp/fw/r000_00/bindings.rs   |  385 +++++++
 drivers/gpu/nova-core/gsp/fw/r570_144.rs           |   31 -
 drivers/gpu/nova-core/gsp/fw/r570_144/bindings.rs  | 1060 --------------------
 drivers/gpu/nova-core/gsp/hal.rs                   |   13 -
 drivers/gpu/nova-core/gsp/hal/tu102.rs             |   12 -
 drivers/gpu/nova-core/gsp/load_exec.rs             |    1 -
 drivers/gpu/nova-core/gsp/nvkv.rs                  |    9 +-
 drivers/gpu/nova-core/gsp/sequencer.rs             |  353 -------
 drivers/gpu/nova-core/sbuffer.rs                   |    1 +
 27 files changed, 1266 insertions(+), 2721 deletions(-)

---
base-commit: d9da44362d77bcbf1f5bfd2ba1c514e776fdb07c
change-id: 20261202-b4-r000-switch-c9c3cd685b09

Best regards,

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

PATCH 1/15 gpu: nova-core: gsp: nvkv: add const constructor for Key

It is useful to be able to build keys as constants, which the From implementation does not allow. Add a const new constructor and use it where relevant.

---
 drivers/gpu/nova-core/gsp/nvkv.rs | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
drivers/gpu/nova-core/gsp/nvkv.rs +7 -2
index f81a9e60d89c..20015b5b0509 100644
@@ -50,17 +50,22 @@ impl<T, const KEY_ID: KeyId, As> Key<T, KEY_ID, As> {
     /// The maximum size in bytes we allow to materialize on the stack while
     /// encoding or decoding a [`Key`]. This is checked at compile time.
     const MAX_STACK_SIZE: usize = 32;
+
+    /// Create a new [`Key`] from `value`.
+    pub(crate) const fn new(value: T) -> Self {
+        Self(value, PhantomData)
+    }
 }
 
 impl<T, const KEY_ID: KeyId, As> From<T> for Key<T, KEY_ID, As> {
     fn from(value: T) -> Self {
-        Self(value, PhantomData)
+        Self::new(value)
     }
 }
 
 impl<'a, T, const KEY_ID: KeyId, As, const N: usize> From<&'a [T; N]> for Key<&'a [T], KEY_ID, As> {
     fn from(value: &'a [T; N]) -> Self {
-        Self(&value[..], PhantomData)
+        Self::new(&value[..])
     }
 }
 
Signature · 1 line
2.56.1
author maintainer
#2 lore raw

PATCH 2/15 gpu: nova-core: gsp: add the GSP_INIT command and its reply

In reply to Alexandre Courbot

From: John Hubbard <[email protected]>

The r000 boot protocol replaces the system-info, registry and static-info RPC commands with one GMC command, GSP_INIT, whose payload is an NVKV stream of key-value pairs. GSP-RM answers it once it has finished starting, with the static GPU configuration.

Nova-core has the NVKV codec and the GSP_INIT schemas. It has no code that fills the request schema in from the PCI device, and no code that decodes the reply into the static configuration type that the boot sequence returns.

Add the GSP_INIT command, whose variable payload is the encoded request, and decode its reply into the static configuration type, so that the rest of the driver reads the same configuration whichever firmware reported it.

The request carries the registry keys that the r570 registry command sends, and it reports the architecture that the kernel is built for.

[acourbot: declare `REGISTRY_ENTRIES` as const `Key`s.]
[acourbot: avoid double-copy in `read`.]
[acourbot: use `CStr` in `RegKey::new`.]
[acourbot: return fixed-size arrays from `GspInitResponse`.]
---
 drivers/gpu/nova-core/gsp/commands.rs     |   3 +
 drivers/gpu/nova-core/gsp/commands/gmc.rs | 133 +++++++++++++++++++++++++
 drivers/gpu/nova-core/gsp/fw/commands.rs  | 155 +++++++++++++++++++++++++++---
 3 files changed, 279 insertions(+), 12 deletions(-)
drivers/gpu/nova-core/gsp/commands.rs +3 -0
index 91f63f704e55..b48cf30978cf 100644
@@ -1,6 +1,9 @@
 // SPDX-License-Identifier: GPL-2.0
 // SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
 
+// The r570 firmware does not use GMC.
+#[expect(dead_code)]
+pub(crate) mod gmc;
 pub(crate) mod rpc;
 
 use core::{
drivers/gpu/nova-core/gsp/commands/gmc.rs new file +133 -0

133 lines not on this page · raw message

drivers/gpu/nova-core/gsp/fw/commands.rs +143 -12

196 lines not on this page · raw message

Signature · 1 line
2.56.1
#3 lore raw

Re: [PATCH 02/15] gpu: nova-core: gsp: add the GSP_INIT command and its reply

Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Medium] gpu: nova-core: non-yielding 15s udelay busy-wait polling GspInit completion --

Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Medium] gpu: nova-core: non-yielding 15s udelay busy-wait polling GspInit completion
--

commit d8fe3c10d1e002df6f79291965859f48b65d0fb0
Author: John Hubbard <[email protected]>

gpu: nova-core: gsp: add the GSP_INIT command and its reply

This commit adds the GMC GSP_INIT command, which encodes system information and registry keys into an NVKV payload for GSP-RM, and decodes the NVKV reply into GspStaticInfo.

Quoted 6 lines
drivers/gpu/nova-core/gsp/commands/gmc.rs new file +0 -0
new file mode 100644
index 0000000000000..f74ada78f7ace
@@ -0,0 +1,133 @@

[ ... ]

drivers/gpu/nova-core/gsp/commands/gmc.rs line 76

Quoted 6 lines
drivers/gpu/nova-core/gsp/commands/gmc.rs new file +6 -0
+impl CommandToGsp for GspInit {
+    const COMMAND: GmcCommandId = GmcCommandId::GspInit;
+    /// Largest reply that the driver accepts, in bytes.
+    const MAX_REPLY_SIZE: u32 = 48 * 1024;
+    /// `GspInit` can take longer than 5 seconds to complete on some SKUs.
+    const COMPLETION_TIMEOUT: Delta = Delta::from_secs(15);

[Severity: Medium]
Can waiting up to 15 seconds for GspInit spin a CPU in a non-yielding udelay() loop?

CmdqInner::await_gmc_reply() passes COMPLETION_TIMEOUT down to CmdqInner::wait_for_msg(), which polls via read_poll_timeout() with Delta::from_micros(1). fsleep() turns delays <= 10 us into udelay(), and read_poll_timeout() does not call cond_resched() inside the loop.

On slower SKUs where GspInit takes more than 5 seconds (or if GSP-RM stalls until timeout), a CONFIG_PREEMPT_NONE or CONFIG_PREEMPT_VOLUNTARY kernel will monopolize a CPU for the entire wait, starving runnable tasks and delaying RCU quiescent states.

Using a sleep delta above 10 us in CmdqInner::wait_for_msg(), or letting long-running commands like GspInit select a sleeping poll interval, would avoid spinning the CPU during this wait.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
author maintainer
#4 lore raw

PATCH 3/15 gpu: nova-core: gsp: populate VF information in GSP_INIT

In reply to Alexandre Courbot

From: Zhi Wang <[email protected]>

GSP firmware requires the VF BAR layout to route interrupts and doorbell events to individual virtual functions.

When vGPU mode is enabled, read the VF topology from the typed PCI SR-IOV extended capability and populate the existing NVKV VF information schema in GSP_INIT.

[acourbot: also add `RMSetSriovMode` regkey here.]
[acourbot: avoid double-match of `VgpuState`.]
[acourbot: use `bitfield!` for `VfInfo::flags`.]
[acourbot: document more returned errors.]
---
 drivers/gpu/nova-core/gsp/commands/gmc.rs | 13 +++++--
 drivers/gpu/nova-core/gsp/fw/commands.rs  | 65 ++++++++++++++++++++++++++++---
 2 files changed, 70 insertions(+), 8 deletions(-)
drivers/gpu/nova-core/gsp/commands/gmc.rs +10 -3
index f74ada78f7ac..f0a0a6798d6b 100644
@@ -37,6 +37,7 @@
         },
     },
     sbuffer::SBufferIter,
+    vgpu::VgpuState, //
 };
 
 /// The `GSP_INIT` command, which carries the system information and registry keys to GSP-RM.
@@ -52,10 +53,16 @@ impl GspInit {
     ///
     /// # Errors
     ///
-    /// - `ENOMEM` if the request or the encoder buffer cannot be allocated.
-    pub(crate) fn new(pdev: &pci::Device<device::Bound>, chipset: Chipset) -> Result<Self> {
+    /// - `ENOMEM` if the encoder buffer cannot be allocated.
+    ///
+    /// Errors from [`GspInitRequest::new`] are propagated as-is.
+    pub(crate) fn new(
+        pdev: &pci::Device<device::Bound>,
+        chipset: Chipset,
+        vgpu_state: VgpuState,
+    ) -> Result<Self> {
         let mut encoder = Encoder::new();
-        GspInitRequest::new(pdev, chipset)?.encode(&mut encoder)?;
+        GspInitRequest::new(pdev, chipset, vgpu_state)?.encode(&mut encoder)?;
 
         Ok(Self {
             payload: encoder.finish(),
drivers/gpu/nova-core/gsp/fw/commands.rs +60 -5

104 lines not on this page · raw message

Signature · 1 line
2.56.1
maintainer
#5 lore raw

Re: [PATCH 03/15] gpu: nova-core: gsp: populate VF information in GSP_INIT

Hi Alex,

Quoted 27 lines · Alexandre Courbot

From: Zhi Wang <[email protected]>

GSP firmware requires the VF BAR layout to route interrupts and doorbell events to individual virtual functions.

When vGPU mode is enabled, read the VF topology from the typed PCI SR-IOV extended capability and populate the existing NVKV VF information schema in GSP_INIT.

[acourbot: also add `RMSetSriovMode` regkey here.]
[acourbot: avoid double-match of `VgpuState`.]
[acourbot: use `bitfield!` for `VfInfo::flags`.]
[acourbot: document more returned errors.]
---
 drivers/gpu/nova-core/gsp/commands/gmc.rs | 13 +++++--
 drivers/gpu/nova-core/gsp/fw/commands.rs  | 65 ++++++++++++++++++++++++++++---
 2 files changed, 70 insertions(+), 8 deletions(-)
drivers/gpu/nova-core/gsp/commands/gmc.rs +0 -0
index f74ada78f7ac..f0a0a6798d6b 100644

drivers/gpu/nova-core/gsp/commands/gmc.rs line 40

Quoted 4 lines
drivers/gpu/nova-core/gsp/commands/gmc.rs +1 -0
@@ -37,6 +37,7 @@
         },
     },
     sbuffer::SBufferIter,
+    vgpu::VgpuState, //

It looks like you have a spurious comment here?

Maxime

#6 lore raw

Re: [PATCH 03/15] gpu: nova-core: gsp: populate VF information in GSP_INIT

Quoted 2 lines · Maxime Ripard

It looks like you have a spurious comment here?

It is a workaround to get rustfmt to do what we want, which avoids merge conflicts; please see:

https://docs.kernel.org/rust/coding-guidelines.html#imports

(We are trying to get that feature stabilized in rustfmt; we may get it for the next Debian Stable; otherwise, the next one)

I hope that helps!

Cheers,
Miguel

maintainer
#7 lore raw

Re: [PATCH 03/15] gpu: nova-core: gsp: populate VF information in GSP_INIT

Quoted 7 lines · Miguel Ojeda
Quoted 2 lines · Maxime Ripard

It looks like you have a spurious comment here?

It is a workaround to get rustfmt to do what we want, which avoids merge conflicts; please see:

Quoted 6 lines

https://docs.kernel.org/rust/coding-guidelines.html#imports

(We are trying to get that feature stabilized in rustfmt; we may get it for the next Debian Stable; otherwise, the next one)

I hope that helps!

Yeah, it does. Sorry for the noise :)

Maxime

author maintainer
#8 lore raw

PATCH 4/15 gpu: nova-core: gsp: re-export PowerStateLevel from gsp::commands

In reply to Alexandre Courbot

PowerStateLevel is currently re-exported from gsp::commands::rpc, while the upcoming GSP_SUSPEND GMC command will take it as well.

Re-export PowerStateLevel from gsp::commands alongside GspStaticInfo so both command protocols and their callers can share it.

No functional change.

---
 drivers/gpu/nova-core/gsp/boot.rs         | 15 +++++++--------
 drivers/gpu/nova-core/gsp/commands.rs     |  2 ++
 drivers/gpu/nova-core/gsp/commands/rpc.rs |  7 ++++---
 3 files changed, 13 insertions(+), 11 deletions(-)
drivers/gpu/nova-core/gsp/boot.rs +7 -8
index 09ad11ac74cb..2904f1ac7459 100644
@@ -16,7 +16,10 @@
     firmware::gsp::GspFirmware,
     gsp::{
         cmdq::Cmdq,
-        commands, //
+        commands::{
+            self,
+            PowerStateLevel, //
+        },
     },
 };
 
@@ -98,7 +101,7 @@ pub(crate) fn boot(
     fn shutdown_gsp(
         cmdq: &Cmdq<'_>,
         gsp_falcon: &Falcon<'_, Gsp>,
-        mode: commands::rpc::PowerStateLevel,
+        mode: PowerStateLevel,
     ) -> Result {
         // Command to shut the GSP down.
         cmdq.send_rpc_command(commands::rpc::UnloadingGuestDriver::new(mode))?;
@@ -118,12 +121,8 @@ pub(crate) fn unload(
         let dev = ctx.dev();
 
         // Shut down the GSP. Keep going even in case of error.
-        let mut res = Self::shutdown_gsp(
-            &self.cmdq,
-            ctx.gsp_falcon,
-            commands::rpc::PowerStateLevel::Level0,
-        )
-        .inspect_err(|e| dev_err!(dev, "GSP shutdown failed: {:?}\n", e));
+        let mut res = Self::shutdown_gsp(&self.cmdq, ctx.gsp_falcon, PowerStateLevel::Level0)
+            .inspect_err(|e| dev_err!(dev, "GSP shutdown failed: {:?}\n", e));
 
         // Run the unload bundle to reset the GSP so it can be booted again.
         if let Some(unload_bundle) = unload_bundle {
drivers/gpu/nova-core/gsp/commands.rs +2 -0
index b48cf30978cf..4ffcb4133e02 100644
@@ -14,6 +14,8 @@
 
 use kernel::prelude::*;
 
+pub(crate) use crate::gsp::fw::commands::PowerStateLevel;
+
 /// The static GPU configuration, which GSP-RM reports in reply to
 /// [`GetGspStaticInfo`](rpc::GetGspStaticInfo).
 pub struct GspStaticInfo {
drivers/gpu/nova-core/gsp/commands/rpc.rs +4 -3
index ab6d1114cead..084214d69f1f 100644
@@ -27,7 +27,10 @@
             Cmdq,
             NoReply, //
         },
-        commands::GspStaticInfo,
+        commands::{
+            GspStaticInfo,
+            PowerStateLevel, //
+        },
         fw::{
             self,
             MsgFunction, //
@@ -240,8 +243,6 @@ fn read(
     }
 }
 
-pub(crate) use fw::commands::PowerStateLevel;
-
 /// The `UnloadingGuestDriver` command, used to shut down the GSP.
 ///
 /// Only used within the `gsp` module.
Signature · 1 line
2.56.1
author maintainer
#9 lore raw

PATCH 5/15 gpu: nova-core: gsp: add the GSP_SUSPEND request

In reply to Alexandre Courbot

From: John Hubbard <[email protected]>

The r000 firmware suspends GSP-RM on a GSP_SUSPEND request, a GMC command whose payload is one word of flags. GSP-RM sends no response on the message queue, and reports the completed suspend in the GSP falcon's MAILBOX0 register instead.

[acourbot: set GMCAPI_GSP_SUSPEND_FLAGS_HIBERNATE for Level7.]
[acourbot: use bitfield and drop the FromBytes/AsBytes impls.]
---
 drivers/gpu/nova-core/gsp/commands/gmc.rs | 42 ++++++++++++++++++++++++++++---
 drivers/gpu/nova-core/gsp/fw/commands.rs  | 19 ++++++++++++++
 2 files changed, 57 insertions(+), 4 deletions(-)
drivers/gpu/nova-core/gsp/commands/gmc.rs +38 -4
index f0a0a6798d6b..cec66b80c489 100644
@@ -16,12 +16,19 @@
 use crate::{
     gpu::Chipset,
     gsp::{
-        cmdq::gmc::{
-            CommandToGsp,
-            MessageFromGsp, //
+        cmdq::{
+            gmc::{
+                CommandToGsp,
+                MessageFromGsp, //
+            },
+            NoReply, //
+        },
+        commands::{
+            GspStaticInfo,
+            PowerStateLevel, //
         },
-        commands::GspStaticInfo,
         fw::{
+            self,
             commands::{
                 GspInitRequest,
                 GspInitResponseSchema, //
@@ -101,6 +108,33 @@ fn init_variable_payload(
     }
 }
 
+/// The `GSP_SUSPEND` command, which suspends GSP-RM.
+///
+/// GSP-RM sends no reply on the message queue. It reports the completed suspend in the GSP
+/// falcon's `MAILBOX0` register instead.
+pub(crate) struct GspSuspend {
+    level: PowerStateLevel,
+}
+
+impl GspSuspend {
+    /// Creates a `GSP_SUSPEND` command for the given [`PowerStateLevel`].
+    pub(crate) fn new(level: PowerStateLevel) -> Self {
+        Self { level }
+    }
+}
+
+impl CommandToGsp for GspSuspend {
+    const COMMAND: GmcCommandId = GmcCommandId::GspSuspend;
+    type Command = u64;
+    type Reply = NoReply;
+    const MAX_REPLY_SIZE: u32 = 0;
+    type InitError = Infallible;
+
+    fn init(&self) -> impl Init<Self::Command, Self::InitError> {
+        u64::from(fw::commands::GspSuspendFlags::from(self.level))
+    }
+}
+
 impl MessageFromGsp for GspStaticInfo {
     type InitError = Error;
 
drivers/gpu/nova-core/gsp/fw/commands.rs +19 -0
index 791a336bce16..2dae9f19b6c6 100644
@@ -276,6 +276,25 @@ pub(crate) fn is_power_transition(self) -> bool {
     }
 }
 
+bitfield! {
+    /// Flags of the `GSP_SUSPEND` GMC command.
+    pub(crate) struct GspSuspendFlags(u64) {
+        /// GSP is being suspended as part of a power management transition (S3, hibernate, etc.)
+        /// rather than a full unload.
+        0:0 pm_transition => bool;
+        /// Hibernate (suspend to disk).
+        2:2 hibernate => bool;
+    }
+}
+
+impl From<PowerStateLevel> for GspSuspendFlags {
+    fn from(level: PowerStateLevel) -> Self {
+        Self::zeroed()
+            .with_pm_transition(level.is_power_transition())
+            .with_hibernate(level == PowerStateLevel::Level7)
+    }
+}
+
 /// Payload of the `UnloadingGuestDriver` command and message.
 #[repr(transparent)]
 #[derive(Clone, Copy, Debug, Zeroable)]
Signature · 1 line
2.56.1
author maintainer
#10 lore raw

PATCH 6/15 gpu: nova-core: firmware: add the ucodes firmware loader

In reply to Alexandre Courbot

From: John Hubbard <[email protected]>

The r000 GSP firmware includes a ucodes image, microcode that GSP-RM loads at init time from a buffer that the driver maps for it. The image is described by a TLV whose FILE tag names a separate file and whose SIZE tag gives that file's length, which is the convention that the GSP firmware image already uses.

Add the ucodes loader on top of the TLV parser. The loader maps the image through a radix3 page table, as the GSP firmware image is mapped, and the image is required on every chipset that nova-core supports.

This is part of the r000 support, and dead code until the switch.

---
 drivers/gpu/nova-core/firmware.rs        |  1 +
 drivers/gpu/nova-core/firmware/ucodes.rs | 66 ++++++++++++++++++++++++++++++++
 2 files changed, 67 insertions(+)
drivers/gpu/nova-core/firmware.rs +1 -0
index 97d6b1d83967..7b216dff1d30 100644
@@ -27,6 +27,7 @@
 pub(crate) mod radix3;
 pub(crate) mod riscv;
 pub(crate) mod tlv;
+pub(crate) mod ucodes;
 
 /// Structure used to describe some firmwares, notably FWSEC-FRTS.
 #[repr(C)]
drivers/gpu/nova-core/firmware/ucodes.rs new file +66 -0

66 lines not on this page · raw message

Signature · 1 line
2.56.1
author maintainer
#11 lore raw

PATCH 7/15 gpu: nova-core: gsp: define GSP_MSG_QUEUE_ELEMENT_SIZE_MAX without bindings

In reply to Alexandre Courbot

From: John Hubbard <[email protected]>

The r570 bindings define GSP_MSG_QUEUE_ELEMENT_SIZE_MAX as 64 KiB (16 GSP pages). Starting with r000, GSP-RM no longer hardcodes this limit in its headers and instead expects the driver to configure it at boot via MESSAGE_QUEUE_INIT_ARGUMENTS.queueElementSizeMax, which both sides then enforce on sent and received queue elements.

Define GSP_MSG_QUEUE_ELEMENT_SIZE_MAX directly as GSP_PAGE_SIZE * 16 so we don't depend on the r570 bindings.

No functional change.

---
 drivers/gpu/nova-core/gsp/fw.rs | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/gpu/nova-core/gsp/fw.rs +3 -2
index 927c6548fbdd..b08f0834ca91 100644
@@ -68,8 +68,9 @@
 };
 
 /// Maximum size of a single GSP message queue element in bytes.
-pub(crate) const GSP_MSG_QUEUE_ELEMENT_SIZE_MAX: usize =
-    cv!(bindings::GSP_MSG_QUEUE_ELEMENT_SIZE_MAX);
+///
+/// GSP-RM receives this value at boot and allocates a heap staging buffer of that size.
+pub(crate) const GSP_MSG_QUEUE_ELEMENT_SIZE_MAX: usize = GSP_PAGE_SIZE * 16;
 
 /// Empty type to group methods related to heap parameters for running the GSP firmware.
 enum GspFwHeapParams {}
Signature · 1 line
2.56.1
author maintainer
#12 lore raw

PATCH 8/15 gpu: nova-core: fb: increase Blackwell reserved memory sizes for r000

In reply to Alexandre Courbot

From: John Hubbard <[email protected]>

The r000 GSP firmware requires larger framebuffer reservations on Blackwell than r570:

* On GB10x and GB20x, the PMU backing store grows from 8 MiB to 0x950000 bytes and the PMU surfaces grow by 256 KiB.
* On GB20x, the non-WPR heap grows from 2 MiB + 128 KiB to 3 MiB.

Reserve the larger regions ahead of the r000 switch, as the r570 firmware also accepts larger carveouts.

---
 drivers/gpu/nova-core/fb/hal/gb100.rs | 23 +++++++++++++++++++++--
 drivers/gpu/nova-core/fb/hal/gb202.rs |  4 ++--
 2 files changed, 23 insertions(+), 4 deletions(-)
drivers/gpu/nova-core/fb/hal/gb100.rs +21 -2
index 37b2ae762df4..34e9f08581fc 100644
@@ -78,9 +78,28 @@ fn write_sysmem_flush_page_gb100(hshub0: Mmio<'_, regs::Hshub0Registers>, addr:
     hshub0.write_reg(regs::NV_PFB_HSHUB_EG_PCIE_FLUSH_SYSMEM_ADDR_LO::zeroed().with_adr(addr_lo));
 }
 
-// This PMU reservation size is r570-specific.
+/// Size of the PMU backing store (9 MiB + 320 KiB).
+const PMU_BACKING_STORE_SIZE: usize = (SZ_1M * 9) + SZ_64K * 5;
+
+/// Size of the PMU surfaces.
+const PMU_SURFACES_SIZE: usize = SZ_16M + SZ_256K;
+
+/// Miscellaneous PMU memory.
+const PMU_MISC_SIZE: usize = SZ_4K;
+
+/// Alignment of the PMU reserved region.
+const PMU_RESERVED_MEMORY_ALIGNMENT: Alignment = Alignment::SZ_128K;
+
+/// PMU region above FRTS: the backing store, the surfaces and the miscellaneous memory, aligned to
+/// [`PMU_RESERVED_MEMORY_ALIGNMENT`].
+const PMU_RESERVED_SIZE: usize = const_align_up(
+    PMU_BACKING_STORE_SIZE + PMU_SURFACES_SIZE + PMU_MISC_SIZE,
+    PMU_RESERVED_MEMORY_ALIGNMENT,
+)
+.unwrap();
+
 pub(super) const fn pmu_reserved_size_gb100() -> u32 {
-    cv!(const_align_up(SZ_8M + SZ_16M + SZ_4K, Alignment::SZ_128K).unwrap())
+    cv!(PMU_RESERVED_SIZE)
 }
 
 impl FbHal for Gb100 {
drivers/gpu/nova-core/fb/hal/gb202.rs +2 -2
index 4341ecf36188..40ea8e6b8a7d 100644
@@ -73,8 +73,8 @@ fn pmu_reserved_size(&self) -> u32 {
 
     fn non_wpr_heap_size(&self) -> u64 {
         // Non-WPR heap for GB20x (see Open RM: kgspGetNonWprHeapSize, GB202+).
-        // This size is r570-specific.
-        u64::SZ_2M + u64::SZ_128K
+        // This size is r000-specific.
+        3 * u64::SZ_1M
     }
 
     fn frts_size(&self) -> u64 {
Signature · 1 line
2.56.1
author maintainer
#13 lore raw

PATCH 9/15 gpu: nova-core: gsp: drain the message queue while waiting for GSP suspend

In reply to Alexandre Courbot

From: John Hubbard <[email protected]>

Unlike r570's UnloadingGuestDriver RPC, which GSP-RM answers only once it is ready to suspend, r000's GSP_SUSPEND command has no reply, and GSP-RM posts messages while tearing down. Because the GSP event interrupt is already unregistered before unload(), nothing drains the queue during the wait for the RISC-V core to suspend.

Drain the message queue on each poll iteration of shutdown_gsp(). On r570, drain() returns immediately when no message is pending and consumes any trailing events posted after the UnloadingGuestDriver reply.

---
 drivers/gpu/nova-core/gsp/boot.rs | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)
drivers/gpu/nova-core/gsp/boot.rs +13 -2
index 2904f1ac7459..fb474e5984a8 100644
@@ -106,8 +106,19 @@ fn shutdown_gsp(
         // Command to shut the GSP down.
         cmdq.send_rpc_command(commands::rpc::UnloadingGuestDriver::new(mode))?;
 
-        // Wait until GSP signals it is suspended.
-        gsp_falcon.wait_for_processor_suspend()
+        // Wait until GSP signals it is suspended. GSP-RM posts messages while it suspends, and the
+        // GSP event interrupt is already freed, so this poll drains them.
+        read_poll_timeout(
+            || {
+                cmdq.drain()?;
+
+                Ok(gsp_falcon.is_processor_suspended())
+            },
+            |suspended| *suspended,
+            Delta::from_millis(10),
+            Delta::from_secs(5),
+        )
+        .map(|_| ())
     }
 
     /// Attempts to unload the GSP firmware.
Signature · 1 line
2.56.1
#14 lore raw

Re: [PATCH 09/15] gpu: nova-core: gsp: drain the message queue while waiting for GSP suspend

Thank you for your contribution! Sashiko AI review found 3 potential issues to consider: - [Medium] gpu: nova-core: cmdq.drain() error aborts GSP suspend wait in shutdown_gsp() - [Medium] gpu…

Thank you for your contribution! Sashiko AI review found 3 potential issues to consider:
- [Medium] gpu: nova-core: cmdq.drain() error aborts GSP suspend wait in shutdown_gsp()
- [Medium] gpu: nova-core: unbounded cmdq.drain() bypasses shutdown_gsp() timeout
- [Low] gpu: nova-core: drain before suspend check in shutdown_gsp() misses events
--

commit 5a7f5b0b34f6ff35ede1c640685237ffd7e41f84
Author: John Hubbard <[email protected]>

gpu: nova-core: gsp: drain the message queue while waiting for GSP suspend

This patch replaces wait_for_processor_suspend() in Gsp::shutdown_gsp() with a read_poll_timeout() loop that calls cmdq.drain() on each poll iteration while waiting for the GSP RISC-V core to suspend.

Quoted 5 lines
drivers/gpu/nova-core/gsp/boot.rs +0 -0
index 2904f1ac74593..fb474e5984a80 100644

drivers/gpu/nova-core/gsp/boot.rs fn shutdown_gsp( · line 113

Quoted 10 lines
drivers/gpu/nova-core/gsp/boot.rs +5 -2
@@ -106,8 +106,19 @@ fn shutdown_gsp(
         // Command to shut the GSP down.
         cmdq.send_rpc_command(commands::rpc::UnloadingGuestDriver::new(mode))?;
 
-        // Wait until GSP signals it is suspended.
-        gsp_falcon.wait_for_processor_suspend()
+        // Wait until GSP signals it is suspended. GSP-RM posts messages while it suspends, and the
+        // GSP event interrupt is already freed, so this poll drains them.
+        read_poll_timeout(
+            || {
+                cmdq.drain()?;

[Severity: Medium]
Can an error from cmdq.drain() abort the suspend wait before the GSP stops?

read_poll_timeout() exits immediately when the closure returns Err. If a malformed message is stuck at the queue head (as left by GspInterrupt::handle_threaded() after disabling the event IRQ), cmdq.drain() returns Err(EIO) and skips waiting for is_processor_suspended().

Gsp::unload() then immediately runs unload_bundle to reset the falcon while GSP-RM is still tearing down. If unload_bundle is None, GspResources::drop() frees the coherent DMA buffers while the GSP may still be performing DMA.

Logging the first drain error, skipping further drains, and continuing to poll is_processor_suspended() until suspend or timeout would avoid this.

drivers/gpu/nova-core/gsp/boot.rs fn shutdown_gsp( · line 115

Quoted 2 lines
drivers/gpu/nova-core/gsp/boot.rs +2 -0
+
+                Ok(gsp_falcon.is_processor_suspended())

[Severity: Low]
Does draining before checking is_processor_suspended() miss trailing events posted just before the GSP suspends?

CPU GSP-RM
cmdq.drain() (queue empty)
post final teardown message set processor_suspended
is_processor_suspended() == true
read_poll_timeout() returns <-- final message never drained

Because Gsp::unload() resets the falcon right after without another drain, final diagnostic messages logged by RpcMessage::log() can be lost. Checking is_processor_suspended() before cmdq.drain() (or draining once more after read_poll_timeout() returns) closes this window.

drivers/gpu/nova-core/gsp/boot.rs fn shutdown_gsp( · line 121

Quoted 6 lines
drivers/gpu/nova-core/gsp/boot.rs +6 -0
+            },
+            |suspended| *suspended,
+            Delta::from_millis(10),
+            Delta::from_secs(5),
+        )
+        .map(|_| ())

[Severity: Medium]
Can cmdq.drain() spin indefinitely here and bypass the 5-second timeout?

CmdqInner::drain() loops with Delta::ZERO until the queue is empty, advancing cpu_read_ptr on each message with no deadline, message cap, or reschedule point. read_poll_timeout() only checks the timeout after the closure returns.

If malfunctioning GSP firmware keeps posting messages during suspend, shutdown_gsp() hangs forever, preventing Gsp::unload() from running unload_bundle and risking a CPU soft lockup on non-preemptible kernels.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=9
author maintainer
#15 lore raw

PATCH 10/15 gpu: nova-core: gsp: zero-initialize FMC boot parameter structs

In reply to Alexandre Courbot

Use Zeroable::init_zeroed() for the remaining fields of GspAcrBootGspRmParams and GspRmParams instead of naming bindgen padding fields, as the r000 bindings replace those padding fields with reserved and zero-defaulted fields.

No functional change.

---
 drivers/gpu/nova-core/gsp/fw.rs | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/nova-core/gsp/fw.rs +2 -2
index b08f0834ca91..74e642e11afc 100644
@@ -1263,7 +1263,7 @@ fn new(target: GspDmaTarget, wpr_meta_addr: u64) -> impl Init<Self> {
             bIsGspRmBoot: 1,
             wprCarveoutOffset: 0,
             wprCarveoutSize: 0,
-            __bindgen_padding_0: Default::default(),
+            ..Zeroable::init_zeroed()
         });
 
         params
@@ -1277,7 +1277,7 @@ fn new(target: GspDmaTarget, libos_addr: u64) -> impl Init<Self> {
         let params = init!(Self {
             target: target as u32,
             bootArgsOffset: libos_addr,
-            __bindgen_padding_0: Default::default(),
+            ..Zeroable::init_zeroed()
         });
 
         params
Signature · 1 line
2.56.1
author maintainer
#16 lore raw

PATCH 11/15 gpu: nova-core: firmware: add r000 GSP bindings

In reply to Alexandre Courbot

From: John Hubbard <[email protected]>

Add the generated r000 GSP firmware bindings required to switch the driver from r570 to r000: heap parameters, RPC header and function/event codes, WPR metadata, LibOS memory region arguments, msgq TX header, GSP startup arguments and FMC boot parameters.

Nothing uses these definitions until the switch to r000.

---
 drivers/gpu/nova-core/gsp/fw/r000_00/bindings.rs | 385 +++++++++++++++++++++++
 1 file changed, 385 insertions(+)
drivers/gpu/nova-core/gsp/fw/r000_00/bindings.rs +385 -0
index 959e397c26aa..2d25cc39b323 100644
@@ -73,6 +73,23 @@ fn eq(&self, _other: &__BindgenUnionField<T>) -> bool {
     }
 }
 impl<T> ::core::cmp::Eq for __BindgenUnionField<T> {}
+pub const NV2080_CTRL_GPU_SET_POWER_STATE_GPU_LEVEL_0: u32 = 0;
+pub const NV2080_CTRL_GPU_SET_POWER_STATE_GPU_LEVEL_3: u32 = 3;
+pub const NV2080_CTRL_GPU_SET_POWER_STATE_GPU_LEVEL_7: u32 = 7;
+pub const NV_VGPU_MSG_SIGNATURE_VALID: u32 = 1129337430;
+pub const GSP_FW_HEAP_PARAM_OS_SIZE_LIBOS2: u32 = 0;
+pub const GSP_FW_HEAP_PARAM_OS_SIZE_LIBOS3_BAREMETAL: u32 = 23068672;
+pub const GSP_FW_HEAP_PARAM_BASE_RM_SIZE_TU10X: u32 = 8388608;
+pub const GSP_FW_HEAP_PARAM_BASE_RM_SIZE_GH100: u32 = 18874368;
+pub const GSP_FW_HEAP_PARAM_SIZE_PER_GB: u32 = 98304;
+pub const GSP_FW_HEAP_PARAM_CLIENT_ALLOC_SIZE: u32 = 100663296;
+pub const GSP_FW_HEAP_SIZE_VGPU_DEFAULT: u32 = 609222656;
+pub const GSP_FW_HEAP_SIZE_OVERRIDE_LIBOS2_MIN_MB: u32 = 64;
+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;
@@ -81,6 +98,277 @@ impl<T> ::core::cmp::Eq for __BindgenUnionField<T> {}
 pub type u16_ = __u16;
 pub type u32_ = __u32;
 pub type u64_ = __u64;
+pub const NV_VGPU_MSG_FUNCTION_NOP: _bindgen_ty_2 = 0;
+pub const NV_VGPU_MSG_FUNCTION_SET_GUEST_SYSTEM_INFO: _bindgen_ty_2 = 1;
+pub const NV_VGPU_MSG_FUNCTION_ALLOC_ROOT: _bindgen_ty_2 = 2;
+pub const NV_VGPU_MSG_FUNCTION_ALLOC_DEVICE: _bindgen_ty_2 = 3;
+pub const NV_VGPU_MSG_FUNCTION_ALLOC_MEMORY: _bindgen_ty_2 = 4;
+pub const NV_VGPU_MSG_FUNCTION_ALLOC_CTX_DMA: _bindgen_ty_2 = 5;
+pub const NV_VGPU_MSG_FUNCTION_ALLOC_CHANNEL_DMA: _bindgen_ty_2 = 6;
+pub const NV_VGPU_MSG_FUNCTION_MAP_MEMORY: _bindgen_ty_2 = 7;
+pub const NV_VGPU_MSG_FUNCTION_BIND_CTX_DMA: _bindgen_ty_2 = 8;
+pub const NV_VGPU_MSG_FUNCTION_ALLOC_OBJECT: _bindgen_ty_2 = 9;
+pub const NV_VGPU_MSG_FUNCTION_FREE: _bindgen_ty_2 = 10;
+pub const NV_VGPU_MSG_FUNCTION_LOG: _bindgen_ty_2 = 11;
+pub const NV_VGPU_MSG_FUNCTION_UNLOADING_GUEST_DRIVER: _bindgen_ty_2 = 47;
+pub const NV_VGPU_MSG_FUNCTION_GET_STATIC_INFO: _bindgen_ty_2 = 51;
+pub const NV_VGPU_MSG_FUNCTION_GET_GSP_STATIC_INFO: _bindgen_ty_2 = 65;
+pub const NV_VGPU_MSG_FUNCTION_CONTINUATION_RECORD: _bindgen_ty_2 = 71;
+pub const NV_VGPU_MSG_FUNCTION_GSP_SET_SYSTEM_INFO: _bindgen_ty_2 = 72;
+pub const NV_VGPU_MSG_FUNCTION_SET_REGISTRY: _bindgen_ty_2 = 73;
+pub const NV_VGPU_MSG_FUNCTION_GSP_INIT_POST_OBJGPU: _bindgen_ty_2 = 74;
+pub const NV_VGPU_MSG_FUNCTION_GSP_RM_CONTROL: _bindgen_ty_2 = 76;
+pub type _bindgen_ty_2 = ffi::c_uint;
+pub const NV_VGPU_MSG_EVENT_GSP_INIT_DONE: _bindgen_ty_3 = 4097;
+pub const NV_VGPU_MSG_EVENT_POST_EVENT: _bindgen_ty_3 = 4099;
+pub const NV_VGPU_MSG_EVENT_RC_TRIGGERED: _bindgen_ty_3 = 4100;
+pub const NV_VGPU_MSG_EVENT_MMU_FAULT_QUEUED: _bindgen_ty_3 = 4101;
+pub const NV_VGPU_MSG_EVENT_OS_ERROR_LOG: _bindgen_ty_3 = 4102;
+pub const NV_VGPU_MSG_EVENT_UCODE_LIBOS_PRINT: _bindgen_ty_3 = 4108;
+pub const NV_VGPU_MSG_EVENT_GSP_LOCKDOWN_NOTICE: _bindgen_ty_3 = 4124;
+pub const NV_VGPU_MSG_EVENT_GSP_POST_NOCAT_RECORD: _bindgen_ty_3 = 4128;
+pub type _bindgen_ty_3 = ffi::c_uint;
+#[repr(C)]
+#[derive(Debug, Default, Copy, Clone, MaybeZeroable)]
+pub struct MESSAGE_QUEUE_INIT_ARGUMENTS {
+    pub flags: u64_,
+    pub sharedMemPhysAddr: u64_,
+    pub cmdQueueOffset: u64_,
+    pub statQueueOffset: u64_,
+    pub queueElementHdrSize: u32_,
+    pub queueElementSizeMin: u32_,
+    pub queueElementSizeMax: u32_,
+    pub queueHeaderAlign: u32_,
+    pub queueElementAlign: u32_,
+    pub pageTableEntryCount: u32_,
+    pub reserved: [u8_; 8usize],
+}
+#[repr(C)]
+#[derive(Debug, Default, Copy, Clone, MaybeZeroable)]
+pub struct GSP_SR_INIT_ARGUMENTS {
+    pub oldLevel: u32_,
+    pub flags: u32_,
+    pub reserved: [u8_; 8usize],
+}
+#[repr(C)]
+#[derive(Debug, Default, Copy, Clone, MaybeZeroable)]
+pub struct GSP_ARGUMENTS_CACHED {
+    pub magic: u32_,
+    pub size: u16_,
+    pub reserved: [u8_; 2usize],
+    pub flags: u64_,
+    pub messageQueueInitArguments: MESSAGE_QUEUE_INIT_ARGUMENTS,
+    pub srInitArguments: GSP_SR_INIT_ARGUMENTS,
+    pub reserved2: [u8_; 4usize],
+    pub gpuInstance: u32_,
+    pub profilerArgs: GSP_ARGUMENTS_CACHED__bindgen_ty_1,
+    pub sysmemHeapArgs: GSP_ARGUMENTS_CACHED__bindgen_ty_2,
+    pub rmStateMonitorBufferArgs: GSP_ARGUMENTS_CACHED__bindgen_ty_3,
+    pub bindataArgs: GSP_ARGUMENTS_CACHED__bindgen_ty_4,
+    pub vbiosOverrideArgs: GSP_ARGUMENTS_CACHED__bindgen_ty_5,
+}
+#[repr(C)]
+#[derive(Debug, Default, Copy, Clone, MaybeZeroable)]
+pub struct GSP_ARGUMENTS_CACHED__bindgen_ty_1 {
+    pub pa: u64_,
+    pub size: u64_,
+}
+#[repr(C)]
+#[derive(Debug, Default, Copy, Clone, MaybeZeroable)]
+pub struct GSP_ARGUMENTS_CACHED__bindgen_ty_2 {
+    pub pa: u64_,
+    pub size: u64_,
+}
+#[repr(C)]
+#[derive(Debug, Default, Copy, Clone, MaybeZeroable)]
+pub struct GSP_ARGUMENTS_CACHED__bindgen_ty_3 {
+    pub pa: u64_,
+    pub size: u64_,
+}
+#[repr(C)]
+#[derive(Debug, Default, Copy, Clone, MaybeZeroable)]
+pub struct GSP_ARGUMENTS_CACHED__bindgen_ty_4 {
+    pub radix3: u64_,
+    pub size: u64_,
+}
+#[repr(C)]
+#[derive(Debug, Default, Copy, Clone, MaybeZeroable)]
+pub struct GSP_ARGUMENTS_CACHED__bindgen_ty_5 {
+    pub pa: u64_,
+    pub size: u64_,
+}
+#[repr(C)]
+#[derive(Copy, Clone, MaybeZeroable)]
+pub union rpc_message_rpc_union_field_v03_00 {
+    pub spare: u32_,
+    pub cpuRmGfid: u32_,
+}
+impl Default for rpc_message_rpc_union_field_v03_00 {
+    fn default() -> Self {
+        let mut s = ::core::mem::MaybeUninit::<Self>::uninit();
+        unsafe {
+            ::core::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
+            s.assume_init()
+        }
+    }
+}
+pub type rpc_message_rpc_union_field_v = rpc_message_rpc_union_field_v03_00;
+#[repr(C)]
+#[derive(MaybeZeroable)]
+pub struct rpc_message_header_v03_00 {
+    pub header_version: u32_,
+    pub signature: u32_,
+    pub length: u32_,
+    pub function: u32_,
+    pub rpc_result: u32_,
+    pub rpc_result_private: u32_,
+    pub sequence: u32_,
+    pub u: rpc_message_rpc_union_field_v,
+    pub rpc_message_data: __IncompleteArrayField<u8_>,
+}
+impl Default for rpc_message_header_v03_00 {
+    fn default() -> Self {
+        let mut s = ::core::mem::MaybeUninit::<Self>::uninit();
+        unsafe {
+            ::core::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
+            s.assume_init()
+        }
+    }
+}
+pub type rpc_message_header_v = rpc_message_header_v03_00;
+#[repr(C)]
+#[derive(Copy, Clone, MaybeZeroable)]
+pub struct GspFwWprMeta {
+    pub magic: u64_,
+    pub revision: u64_,
+    pub sysmemAddrOfRadix3Elf: u64_,
+    pub sizeOfRadix3Elf: u64_,
+    pub sysmemAddrOfBootloader: u64_,
+    pub sizeOfBootloader: u64_,
+    pub bootloaderCodeOffset: u64_,
+    pub bootloaderDataOffset: u64_,
+    pub bootloaderManifestOffset: u64_,
+    pub __bindgen_anon_1: GspFwWprMeta__bindgen_ty_1,
+    pub gspFwRsvdStart: u64_,
+    pub nonWprHeapOffset: u64_,
+    pub nonWprHeapSize: u64_,
+    pub gspFwWprStart: u64_,
+    pub gspFwHeapOffset: u64_,
+    pub gspFwHeapSize: u64_,
+    pub gspFwOffset: u64_,
+    pub bootBinOffset: u64_,
+    pub frtsOffset: u64_,
+    pub frtsSize: u64_,
+    pub gspFwWprEnd: u64_,
+    pub fbSize: u64_,
+    pub vgaWorkspaceOffset: u64_,
+    pub vgaWorkspaceSize: u64_,
+    pub bootCount: u64_,
+    pub __bindgen_anon_2: GspFwWprMeta__bindgen_ty_2,
+    pub gspFwHeapVfPartitionCount: u8_,
+    pub flags: u8_,
+    pub pagingConfig: u16_,
+    pub pmuReservedSize: u32_,
+    pub verified: u64_,
+}
+#[repr(C)]
+#[derive(Copy, Clone, MaybeZeroable)]
+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, MaybeZeroable)]
+pub struct GspFwWprMeta__bindgen_ty_1__bindgen_ty_1 {
+    pub sysmemAddrOfSignature: u64_,
+    pub sizeOfSignature: u64_,
+}
+#[repr(C)]
+#[derive(Debug, Default, Copy, Clone, MaybeZeroable)]
+pub struct GspFwWprMeta__bindgen_ty_1__bindgen_ty_2 {
+    pub gspFwHeapFreeListWprOffset: u32_,
+    pub unused0: u32_,
+    pub unused1: u64_,
+}
+impl Default for GspFwWprMeta__bindgen_ty_1 {
+    fn default() -> Self {
+        let mut s = ::core::mem::MaybeUninit::<Self>::uninit();
+        unsafe {
+            ::core::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
+            s.assume_init()
+        }
+    }
+}
+#[repr(C)]
+#[derive(Copy, Clone, MaybeZeroable)]
+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, MaybeZeroable)]
+pub struct GspFwWprMeta__bindgen_ty_2__bindgen_ty_1 {
+    pub partitionRpcAddr: u64_,
+    pub partitionRpcRequestOffset: u16_,
+    pub partitionRpcReplyOffset: u16_,
+    pub elfCodeOffset: u32_,
+    pub elfDataOffset: u32_,
+    pub elfCodeSize: u32_,
+    pub elfDataSize: u32_,
+    pub lsUcodeVersion: u32_,
+}
+#[repr(C)]
+#[derive(Debug, Default, Copy, Clone, MaybeZeroable)]
+pub struct GspFwWprMeta__bindgen_ty_2__bindgen_ty_2 {
+    pub partitionRpcPadding: [u32_; 4usize],
+    pub sysmemAddrOfCrashReportQueue: u64_,
+    pub sizeOfCrashReportQueue: u32_,
+    pub lsUcodeVersionPadding: [u32_; 1usize],
+}
+impl Default for GspFwWprMeta__bindgen_ty_2 {
+    fn default() -> Self {
+        let mut s = ::core::mem::MaybeUninit::<Self>::uninit();
+        unsafe {
+            ::core::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
+            s.assume_init()
+        }
+    }
+}
+impl Default for GspFwWprMeta {
+    fn default() -> Self {
+        let mut s = ::core::mem::MaybeUninit::<Self>::uninit();
+        unsafe {
+            ::core::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
+            s.assume_init()
+        }
+    }
+}
+pub type LibosAddress = u64_;
+pub const LibosMemoryRegionKind_LIBOS_MEMORY_REGION_CONTIGUOUS: LibosMemoryRegionKind = 1;
+pub type LibosMemoryRegionKind = ffi::c_uint;
+pub const LibosMemoryRegionLoc_LIBOS_MEMORY_REGION_LOC_SYSMEM: LibosMemoryRegionLoc = 1;
+pub type LibosMemoryRegionLoc = ffi::c_uint;
+#[repr(C)]
+#[derive(Debug, Default, Copy, Clone, MaybeZeroable)]
+pub struct LibosMemoryRegionInitArgument {
+    pub id8: LibosAddress,
+    pub pa: LibosAddress,
+    pub size: LibosAddress,
+    pub kind: u8_,
+    pub loc: u8_,
+    pub __bindgen_padding_0: [u8; 6usize],
+}
+#[repr(C)]
+#[derive(Debug, Default, Copy, Clone, MaybeZeroable)]
+pub struct msgqTxHeader {
+    pub versionMajor: u16_,
+    pub versionMinor: u16_,
+    pub size: u32_,
+    pub msgSize: u32_,
+    pub msgCount: u32_,
+    pub entryOff: u32_,
+    pub reserved: [u32_; 3usize],
+}
 #[repr(C)]
 #[derive(Debug, Default, Copy, Clone, MaybeZeroable)]
 pub struct GSP_MSG_QUEUE_ENCRYPTION_TAG {
@@ -205,3 +493,100 @@ fn default() -> Self {
 pub const GMCAPI_COMMANDS_GMCAPI_CMD_MMU_FAULT_QUEUED: GMCAPI_COMMANDS = 262145;
 pub const GMCAPI_COMMANDS_GMCAPI_CMD_INVALID: GMCAPI_COMMANDS = 4294967295;
 pub type GMCAPI_COMMANDS = ffi::c_uint;
+pub const GSP_DMA_TARGET_GSP_DMA_TARGET_LOCAL_FB: GSP_DMA_TARGET = 0;
+pub const GSP_DMA_TARGET_GSP_DMA_TARGET_COHERENT_SYSTEM: GSP_DMA_TARGET = 1;
+pub const GSP_DMA_TARGET_GSP_DMA_TARGET_NONCOHERENT_SYSTEM: GSP_DMA_TARGET = 2;
+pub type GSP_DMA_TARGET = ffi::c_uint;
+#[repr(C)]
+#[derive(Debug, Default, Copy, Clone, MaybeZeroable)]
+pub struct GSP_FMC_INIT_PARAMS {
+    pub regkeys: u32_,
+    pub reserved: u32_,
+}
+#[repr(C)]
+#[derive(Debug, Copy, Clone, MaybeZeroable)]
+pub struct GSP_ACR_BOOT_GSP_RM_PARAMS {
+    pub target: GSP_DMA_TARGET,
+    pub gspRmDescSize: u32_,
+    pub gspRmDescOffset: u64_,
+    pub wprCarveoutOffset: u64_,
+    pub wprCarveoutSize: u32_,
+    pub bIsGspRmBoot: u8_,
+    pub bInstInSysMode: u8_,
+    pub bIcuEnabled: u8_,
+    pub bScrubCbcSr: u8_,
+}
+impl Default for GSP_ACR_BOOT_GSP_RM_PARAMS {
+    fn default() -> Self {
+        let mut s = ::core::mem::MaybeUninit::<Self>::uninit();
+        unsafe {
+            ::core::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
+            s.assume_init()
+        }
+    }
+}
+#[repr(C)]
+#[derive(Debug, Copy, Clone, MaybeZeroable)]
+pub struct GSP_RM_PARAMS {
+    pub target: GSP_DMA_TARGET,
+    pub reserved: u32_,
+    pub bootArgsOffset: u64_,
+}
+impl Default for GSP_RM_PARAMS {
+    fn default() -> Self {
+        let mut s = ::core::mem::MaybeUninit::<Self>::uninit();
+        unsafe {
+            ::core::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
+            s.assume_init()
+        }
+    }
+}
+#[repr(C)]
+#[derive(Debug, Copy, Clone, MaybeZeroable)]
+pub struct GSP_SPDM_PARAMS {
+    pub target: GSP_DMA_TARGET,
+    pub payloadBufferSize: u32_,
+    pub payloadBufferOffset: u64_,
+}
+impl Default for GSP_SPDM_PARAMS {
+    fn default() -> Self {
+        let mut s = ::core::mem::MaybeUninit::<Self>::uninit();
+        unsafe {
+            ::core::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
+            s.assume_init()
+        }
+    }
+}
+#[repr(C)]
+#[derive(Debug, Default, Copy, Clone, MaybeZeroable)]
+pub struct GSP_RM_MEM_PARAMS {
+    pub flushSysmemAddrValLo: u32_,
+    pub flushSysmemAddrValHi: u32_,
+}
+#[repr(C)]
+#[derive(Debug, Copy, Clone, MaybeZeroable)]
+pub struct GSP_FMC_BOOT_PARAMS {
+    pub magic: u32_,
+    pub size: u16_,
+    pub reserved0: u16_,
+    pub reserved1: [u64_; 3usize],
+    pub initParams: GSP_FMC_INIT_PARAMS,
+    pub reserved2: [u64_; 3usize],
+    pub bootGspRmParams: GSP_ACR_BOOT_GSP_RM_PARAMS,
+    pub reserved3: [u64_; 4usize],
+    pub gspRmParams: GSP_RM_PARAMS,
+    pub reserved4: [u64_; 2usize],
+    pub gspSpdmParams: GSP_SPDM_PARAMS,
+    pub reserved5: [u64_; 2usize],
+    pub gspRmMemParams: GSP_RM_MEM_PARAMS,
+    pub reserved6: [u64_; 7usize],
+}
+impl Default for GSP_FMC_BOOT_PARAMS {
+    fn default() -> Self {
+        let mut s = ::core::mem::MaybeUninit::<Self>::uninit();
+        unsafe {
+            ::core::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
+            s.assume_init()
+        }
+    }
+}
Signature · 1 line
2.56.1
author maintainer
#17 lore raw

PATCH 12/15 gpu: nova-core: switch to the r000 GSP firmware

In reply to Alexandre Courbot

From: John Hubbard <[email protected]>

The r000 GSP firmware is not compatible with the r570 firmware that nova-core boots:

* Every queue element opens with the r000 queue element header, and the queue pointers are in BAR0 registers, where r570 keeps them in shared memory.

* The GSP_INIT and GSP_SUSPEND commands replace the four RPC commands that the r570 boot and shutdown paths send, and the reply to GSP_INIT replaces the init-done event.

* Load-and-execute GMC events replace the command sequences that the r570 GSP-RM sends for the GSP sequencer to run.

* GSP-RM requires two more buffers at boot: the ucodes image and the state monitor buffer.

The driver loads one firmware, so a driver that handles some of these differences and not the others boots neither firmware.

Switch the bindings, the message queue, the boot sequence and the shutdown path to r000 together. Mark the post-boot HAL hook and r570 RPC commands module as dead code until follow-up patches delete them.

Keep the RPC send and reply paths, and mark them as dead code. The driver sends no RPC command, but the r000 GSP-RM still accepts RPC commands once it is up.

[acourbot: deslop and split.]
[acourbot: zero the driver's queue pointer registers on cmdq construction.]
[acourbot: do not drop unread GSP messages when the ring is full.]
---
 Documentation/gpu/nova/core/falcon.rst             |   2 +-
 Documentation/gpu/nova/core/interrupts.rst         |  30 +-
 drivers/gpu/nova-core/firmware.rs                  |   6 +-
 drivers/gpu/nova-core/firmware/ucodes.rs           |   1 -
 drivers/gpu/nova-core/gsp.rs                       |   8 +-
 drivers/gpu/nova-core/gsp/boot.rs                  |  44 ++-
 drivers/gpu/nova-core/gsp/cmdq.rs                  | 366 ++++++++++-----------
 drivers/gpu/nova-core/gsp/cmdq/gmc.rs              |  21 +-
 drivers/gpu/nova-core/gsp/cmdq/rpc.rs              |  42 +--
 drivers/gpu/nova-core/gsp/cmdq/rpc/continuation.rs |  10 +-
 drivers/gpu/nova-core/gsp/commands.rs              |   6 +-
 drivers/gpu/nova-core/gsp/fw.rs                    | 299 +++++++----------
 drivers/gpu/nova-core/gsp/fw/commands.rs           |   2 +-
 drivers/gpu/nova-core/gsp/hal.rs                   |   1 +
 drivers/gpu/nova-core/gsp/load_exec.rs             |   1 -
 15 files changed, 394 insertions(+), 445 deletions(-)
Documentation/gpu/nova/core/falcon.rst +1 -1
index 33137082eb6c..c48984dcc482 100644
@@ -85,7 +85,7 @@ On an Ampere GPU, for example, the boot verification flow is:
      component to load the SEC2-RTOS ucode onto the SEC2. The CPU cannot load
      LS code, and GSP-RM must run in LS mode. To overcome this, the GSP is
      temporarily made to run HS ucode (which is itself loaded by the CPU via
-     the nova-core driver using a "GSP-provided sequencer") which then loads
+     the nova-core driver on a "load-and-execute" event) which then loads
      the SEC2-RTOS ucode onto the SEC2 in LS mode. The GSP then resumes
      running its own GSP-RM LS ucode.
 
Documentation/gpu/nova/core/interrupts.rst +15 -15
index 13a087b960c0..27fa21f4b10f 100644
@@ -448,10 +448,10 @@ thread to drain the queue::
 A halt and a posted message can be pending together, so the top half services
 every cause that the status reports.
 
-A drain fails when a message's framing or checksum is bad (see "Draining the
-GSP-to-CPU queue"). The message stays at the queue head, so every later drain
-would fail the same way, and the IRQ thread disables vector 155 and logs the
-failure, which leaves the queue unserviced until the device is reset.
+A drain fails when a message's framing is bad (see "Draining the GSP-to-CPU
+queue"). The message stays at the queue head, so every later drain would fail
+the same way, and the IRQ thread disables vector 155 and logs the failure,
+which leaves the queue unserviced until the device is reset.
 
 The handler, the self-test, and the rest of the driver read BAR0 through one
 shared mapping. nova-core unregisters an interrupt handler when the device
@@ -566,8 +566,9 @@ unloads the GSP.
 Draining the GSP-to-CPU queue
 -----------------------------
 
-The queue carries command replies and unsolicited events, and a message's
-function code says which it is.
+The queue carries RPC and GMC messages, selected by the element header's NVDM
+type. For RPC messages, a message's function code says whether it is a command
+reply or an unsolicited event:
 
 * A function code that matches the awaited reply: the message is decoded and
   returned to the caller that sent the command.
@@ -578,17 +579,16 @@ function code says which it is.
   receive trace at debug level already records every message's arrival with
   its sequence number, function code, and length.
 
-The sequence number takes no part in the match, because the GSP does not echo
-the command's sequence number on every reply. On r570 the reply to
-``UnloadingGuestDriver`` carries sequence 0.
+GMC replies match on command ID and sequence number, and GMC events arriving
+during a wait go to the caller's handler; unclaimed replies and unknown command
+IDs are logged at warning level, and other GMC events are dropped.
 
-The read pointer advances past every message that passes framing and checksum
-validation, whether it matched or was an event.
+The RPC sequence number takes no part in the match.
 
-A message's length is inside the region that the checksum covers, so once the
-framing or the checksum fails there is no trustworthy length with which to skip
-the message. Such a message stays at the queue head, and every later receive
-fails on it with ``EIO`` until the device is reset.
+The read pointer advances past every valid element, whether it matched or was
+an event. An element that fails framing or message-header validation, or
+carries an unsupported NVDM type, stays at the queue head and every later
+receive fails with ``EIO`` until the device is reset.
 
 The polling path and the IRQ thread both read the queue under the command-queue
 mutex. Replies and events share one queue and one read pointer, so one lock is
drivers/gpu/nova-core/firmware.rs +5 -1
index 7b216dff1d30..cea56411a3e2 100644
@@ -300,7 +300,11 @@ const fn make_entry_chipset(self, chipset: gpu::Chipset) -> Self {
         let mut this = self
             .make_entry_file(name, "gsp_bootloader.tlv")
             .make_entry_file(name, "gsp.tlv")
-            .make_entry_file(name, "gsp.bin");
+            .make_entry_file(name, "gsp.bin")
+            .make_entry_file(name, "ucodes.tlv")
+            // The metadata's FILE tag gives the image's real file name at run time. This static
+            // entry names the usual one.
+            .make_entry_file(name, "ucodes.bin");
 
         // Add the firmware files specific to the GSP boot method of `chipset`.
         let boot_files = boot_firmware_files(chipset);
drivers/gpu/nova-core/firmware/ucodes.rs +0 -1
index 153bb5172903..283a5e4fc1fc 100644
@@ -27,7 +27,6 @@ pub(crate) struct UcodesImage<'a> {
     radix3: Pin<KBox<Radix3<'a>>>,
 }
 
-#[expect(dead_code)]
 impl<'a> UcodesImage<'a> {
     /// Loads the ucodes image that the `ucodes` metadata file names, and maps it for `dev`.
     ///
drivers/gpu/nova-core/gsp.rs +6 -2
index d36dd6e9cd2c..05c1aa9d2159 100644
@@ -164,8 +164,12 @@ pub(crate) fn new(
             // kgspSetupLibosInitArgs_IMPL (creates pLibosInitArgs[] array)
             Ok(try_pin_init!(Self {
                 cmdq <- Cmdq::new(dev, bar),
-                rmargs: Coherent::init(dev, GFP_KERNEL, GspArgumentsPadded::new(&cmdq))?,
                 rm_state_monitor: Coherent::zeroed(dev, GFP_KERNEL)?,
+                rmargs: Coherent::init(
+                    dev,
+                    GFP_KERNEL,
+                    GspArgumentsPadded::new(&cmdq, rm_state_monitor),
+                )?,
                 libos: {
                     let mut libos = LibosWriter::new(dev)?;
                     log_buffers.init_arguments(&mut libos)?;
@@ -185,6 +189,6 @@ pub(crate) fn new(
 pub(crate) struct BootResult<'a> {
     /// The unload bundle for [`Gsp::unload`], if one could be built.
     pub(crate) unload_bundle: Option<UnloadBundle<'a>>,
-    /// The static GPU configuration as reported by GSP-RM.
+    /// The static GPU configuration, as decoded from the `GSP_INIT` reply.
     pub(crate) static_info: commands::GspStaticInfo,
 }
drivers/gpu/nova-core/gsp/boot.rs +26 -18

75 lines not on this page · raw message

drivers/gpu/nova-core/gsp/cmdq.rs +176 -190

635 lines not on this page · raw message

drivers/gpu/nova-core/gsp/cmdq/gmc.rs +13 -8
index 8de8e93ddd7f..0ddd319e15b7 100644
@@ -29,11 +29,12 @@
         fw::{
             GmcApiHeader,
             GmcCommandId,
-            GspMsgElement, //
+            QueueElementHeader, //
         },
         GSP_PAGE_SIZE,
     },
-    sbuffer::SBufferIter,
+    mctp::NvdmType,
+    sbuffer::SBufferIter, //
 };
 
 /// Trait implemented by types representing a GMC command to send to the GSP.
@@ -115,6 +116,8 @@ impl<C> CommandElement for GmcCommandElement<C>
     C: CommandToGsp,
     Error: From<C::InitError>,
 {
+    const NVDM_TYPE: NvdmType = NvdmType::GmcApi;
+
     fn size(&self) -> usize {
         size_of::<GmcApiHeader>() + self.0.size()
     }
@@ -123,14 +126,14 @@ fn write(&self, dev: &device::Device, seq: u32, dst: &mut GspCommand<'_>) -> Res
         // Ensure that the command and its headers are not larger than one page, which is part of
         // the GMC API contract.
         const_assert!(
-            size_of::<GspMsgElement>() + size_of::<GmcApiHeader>() + size_of::<C::Command>()
+            size_of::<QueueElementHeader>() + size_of::<GmcApiHeader>() + size_of::<C::Command>()
                 <= GSP_PAGE_SIZE
         );
 
         let command = &self.0;
         let payload_size = command.size();
         // Extract the areas for the GMC API header and the command itself. Per the `const_assert!`
-        // above, the GSP message header, the GMC API header and the command header together are
+        // above, the queue element header, the GMC API header and the command header together are
         // guaranteed to fit entirely into a single page, so it's ok to only look at
         // `dst.contents.0` here.
         let (header, contents) = GmcApiHeader::from_bytes_mut_prefix(dst.contents.0).ok_or(EIO)?;
@@ -209,14 +212,16 @@ impl<'a> GmcMessage<'a> {
     /// - `EIO` if the element is shorter than the GMC API header, or than the payload length
     ///   advertised by the GMC API header.
     pub(super) fn parse(dev: &device::Device, element: GspMessage<'a>) -> Result<GmcMessage<'a>> {
-        static_assert!(size_of::<GspMsgElement>() + size_of::<GmcApiHeader>() <= GSP_PAGE_SIZE);
+        static_assert!(
+            size_of::<QueueElementHeader>() + size_of::<GmcApiHeader>() <= GSP_PAGE_SIZE
+        );
 
         let GspMessage {
             contents: (slice_1, slice_2),
             ..
         } = element;
 
-        // Per the `static_assert!` above, the GSP message header and the GMC API header together
+        // Per the `static_assert!` above, the queue element header and the GMC API header together
         // are guaranteed to fit entirely into a single page, so it's ok to only look at `slice_1`
         // here.
         let (gmc_header, slice_1) = GmcApiHeader::from_bytes_prefix(slice_1).ok_or(EIO)?;
@@ -304,7 +309,7 @@ impl Cmdq<'_> {
     ///   arrive while waiting.
     /// - `EIO` if the variable payload requested by the command has not been entirely
     ///   written to by its [`CommandToGsp::init_variable_payload`] method, or if a message fails
-    ///   framing or checksum validation.
+    ///   framing validation.
     ///
     /// Error codes returned by the command and reply initializers, and by `on_event`, are
     /// propagated as-is.
@@ -379,7 +384,7 @@ fn send_gmc_command<C>(&mut self, command: C) -> Result<u32>
     ///
     /// - `ETIMEDOUT` if the reply does not arrive before the deadline, however many other messages
     ///   arrive while waiting.
-    /// - `EIO` if a message fails framing or checksum validation.
+    /// - `EIO` if a message fails framing validation.
     ///
     /// Error codes returned by [`MessageFromGsp::read`] and by `on_event` are propagated as-is.
     fn await_gmc_reply<C: CommandToGsp>(
drivers/gpu/nova-core/gsp/cmdq/rpc.rs +23 -19

91 lines not on this page · raw message

drivers/gpu/nova-core/gsp/cmdq/rpc/continuation.rs +7 -3
index 9ef19f28de97..c4e169429969 100644
@@ -13,15 +13,19 @@
 
 use crate::{
     gsp::fw::{
-        GspMsgElement,
         MsgFunction,
+        QueueElementHeader,
+        RpcMessageHeader,
         GSP_MSG_QUEUE_ELEMENT_SIZE_MAX, //
     },
     sbuffer::SBufferIter,
 };
 
-/// Maximum command size that fits in a single queue element.
-const MAX_CMD_SIZE: usize = GSP_MSG_QUEUE_ELEMENT_SIZE_MAX - size_of::<GspMsgElement>();
+/// Maximum command size that fits in a single queue element, after the queue element header and
+/// the RPC header.
+const MAX_CMD_SIZE: usize = GSP_MSG_QUEUE_ELEMENT_SIZE_MAX
+    - size_of::<QueueElementHeader>()
+    - size_of::<RpcMessageHeader>();
 
 /// Acts as an iterator over the continuation records for a split command.
 pub(super) struct ContinuationRecords {
drivers/gpu/nova-core/gsp/commands.rs +2 -4
index 4ffcb4133e02..df920e3d8322 100644
@@ -1,9 +1,8 @@
 // SPDX-License-Identifier: GPL-2.0
 // SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
 
-// The r570 firmware does not use GMC.
-#[expect(dead_code)]
 pub(crate) mod gmc;
+#[expect(dead_code)]
 pub(crate) mod rpc;
 
 use core::{
@@ -16,8 +15,7 @@
 
 pub(crate) use crate::gsp::fw::commands::PowerStateLevel;
 
-/// The static GPU configuration, which GSP-RM reports in reply to
-/// [`GetGspStaticInfo`](rpc::GetGspStaticInfo).
+/// The static GPU configuration, which GSP-RM reports in reply to [`GspInit`](gmc::GspInit).
 pub struct GspStaticInfo {
     gpu_name: [u8; Self::MAX_GPU_NAME_LEN],
     gpu_short_name: [u8; Self::MAX_GPU_NAME_LEN],
drivers/gpu/nova-core/gsp/fw.rs +118 -181

539 lines not on this page · raw message

drivers/gpu/nova-core/gsp/fw/commands.rs +1 -1
index 2dae9f19b6c6..f83a04bc0816 100644
@@ -38,7 +38,7 @@
     vgpu::VgpuState, //
 };
 
-use super::bindings;
+use super::r570_144 as bindings;
 
 /// Payload of the `GspSetSystemInfo` command.
 #[repr(transparent)]
drivers/gpu/nova-core/gsp/hal.rs +1 -0
index a0117d6d16a2..caf249f37445 100644
@@ -46,6 +46,7 @@ fn boot<'gpu>(
     ///
     /// This method is called by the GSP boot code after the GSP is confirmed to be running, and
     /// after the initialization commands have been pushed onto its queue.
+    #[expect(dead_code)]
     fn post_boot(
         &self,
         _gsp: &Gsp<'_>,
drivers/gpu/nova-core/gsp/load_exec.rs +0 -1
index a32b13c361ad..7d379eb13e02 100644
@@ -137,7 +137,6 @@ impl GspBootContext<'_, '_> {
     ///
     /// Errors from the handlers and from the resume of GSP-RM are propagated
     /// as-is.
-    #[expect(dead_code)]
     pub(super) fn handle_load_exec_event(
         &self,
         libos_dma_address: DmaAddress,
Signature · 1 line
2.56.1
#18 lore raw
Thank you for your contribution! Sashiko AI review found 5 potential issues to consider: - [High] nova-core: missing element_len check in wait_for_msg() causes panic - [Medium] gpu: nova-core: 1us…

Thank you for your contribution! Sashiko AI review found 5 potential issues to consider:
- [High] nova-core: missing element_len check in wait_for_msg() causes panic
- [Medium] gpu: nova-core: 1us BAR0 MMIO busy-wait polling storm in cmdq
- [Medium] nova-core: wait_for_msg() does not bound element_len() against readable area
- [Medium] gpu: nova-core: unfulfilled expect(dead_code) in nvkv/encode.rs
- [Low] gpu: nova-core: dma_mb(Full) used instead of mb(Full) for MMIO ordering
--

commit b84d5985668cf177648c64b977c82247b207c333
Author: John Hubbard <[email protected]>

gpu: nova-core: switch to the r000 GSP firmware

This commit switches nova-core's GSP bindings, message queue transport, boot sequence, and shutdown path from the r570 firmware interface to r000, moving queue pointers to BAR0 registers and replacing the r570 boot and shutdown RPC commands with GMC commands.

Quoted 4 lines
drivers/gpu/nova-core/gsp/boot.rs +0 -0
index fb474e5984a80..763dbe1f8fdb4 100644

[ ... ]

Quoted 9 lines
drivers/gpu/nova-core/gsp/boot.rs +0 -5
@@ -82,14 +85,19 @@ pub(crate) fn boot(
 
         dev_dbg!(pdev, "RISC-V active? {}\n", gsp_falcon.is_riscv_active(),);
 
-        hal.post_boot(&self, ctx, &gsp_fw)?;
-
-        // Wait until GSP is fully initialized.
-        commands::rpc::wait_gsp_init_done(&self.cmdq)?;
-

drivers/gpu/nova-core/gsp/boot.rs pub(crate) fn boot( · line 96

Quoted 10 lines
drivers/gpu/nova-core/gsp/boot.rs +7 -1
+        // GSP-RM answers `GSP_INIT` once it has finished starting, which includes the
+        // load-and-execute events that it raises along the way.
+        let libos_dma_address = self.libos.dma_address();
+        let bootloader_app_version = gsp_fw.bootloader.app_version;
         let static_info = self
             .cmdq
-            .send_rpc_command(commands::rpc::GetGspStaticInfo)?;
+            .send_gmc_command(GspInit::new(pdev, chipset, ctx.vgpu.state())?, |event| {
+                ctx.handle_load_exec_event(libos_dma_address, bootloader_app_version, event)
+            })?

[Severity: Medium]
Does calling GspInit::new() here make all non-test items in drivers/gpu/nova-core/gsp/nvkv/encode.rs live, leaving its module-level #![cfg_attr(not(CONFIG_KUNIT = "y"), expect(dead_code))] attribute unfulfilled?

When CONFIG_KUNIT is n or m (including allmodconfig), rustc emits an unfulfilled_lint_expectations warning that fails the build under CONFIG_WERROR=y. Removing that attribute from nvkv/encode.rs resolves it.

Quoted 4 lines
drivers/gpu/nova-core/gsp/cmdq.rs +0 -0
index 10f6ddcf3eb52..f6bede6a77e7a 100644

[ ... ]

Quoted 16 lines
drivers/gpu/nova-core/gsp/cmdq.rs +4 -6
@@ -328,76 +332,73 @@ fn allocate_command(&mut self, size: usize, timeout: Delta) -> Result<GspCommand
         })
     }
 
-    // Returns the index of the memory page the GSP will write the next message to.
-    //
-    // # Invariants
-    //
-    // - The returned value is within `0..MSGQ_NUM_PAGES`.
+    /// Returns the GSP's count of posted messages.
     fn gsp_write_ptr(&self) -> u32 {
-        let ptr = MsgqTxHeader::write_ptr(io_project!(self.mem, .gspq.tx)) % MSGQ_NUM_PAGES;
+        // ORDERING: `readl` ends in a read barrier, which orders this read before the data reads
+        // that follow it.
+        let ptr = u32::from(self.bar.read(regs::NV_PGSP_MSGQ_HEAD::at(0)).val());
 

drivers/gpu/nova-core/gsp/cmdq.rs fn allocate_command(&mut self, size: usize, timeout: Delta) -> Result<GspCommand · line 348

Quoted 10 lines
drivers/gpu/nova-core/gsp/cmdq.rs +5 -2
-        // ORDERING: LOAD->LOAD ordering needed to order `gsp_write_ptr` read before data read.
-        dma_mb(Read);
+        // Ignore out-of-range reads (e.g. a register zeroed while GSP-RM is suspended).
+        if ptr.wrapping_sub(self.cpu_read_ptr) > MSGQ_NUM_PAGES {
+            return self.last_gsp_write_ptr.get();
+        }
 
+        self.last_gsp_write_ptr.set(ptr);
         ptr
     }

[Severity: Medium]
Does moving gsp_write_ptr() and gsp_read_ptr() from coherent RAM to BAR0 MMIO reads turn the 1-microsecond read_poll_timeout() loops in wait_for_msg() and allocate_command() into a non-sleeping MMIO polling storm?

fsleep() uses udelay() for intervals up to 10 microseconds, so Delta::from_micros(1) busy-spins without yielding while issuing non-posted BAR0 readl() transactions for up to 15 seconds during GspInit boot and 5 seconds on other waits. On PREEMPT_NONE or PREEMPT_VOLUNTARY kernels this pegs the calling CPU at 100% while flooding the GPU BAR0 interface.

In addition, allocate_command() calls driver_write_area() immediately after read_poll_timeout() succeeds on driver_write_area_size(), issuing a redundant BAR0 read and barrier on every command send.

Quoted 9 lines
drivers/gpu/nova-core/gsp/cmdq.rs +4 -2
+    /// Returns the GSP's count of consumed commands.
     fn gsp_read_ptr(&self) -> u32 {
-        let ptr = MsgqRxHeader::read_ptr(io_project!(self.mem, .gspq.rx)) % MSGQ_NUM_PAGES;
+        let ptr = u32::from(self.bar.read(regs::NV_PGSP_QUEUE_TAIL::at(0)).address());
 
-        // ORDERING: LOAD->STORE ordering needed to order `gsp_read_ptr` read before data write.
+        // ORDERING: the data writes that follow must not pass this read. `readl` orders only the
+        // reads that follow it, so the writes need a full barrier.
         dma_mb(Full);

[ ... ]

Quoted 16 lines
drivers/gpu/nova-core/gsp/cmdq.rs +5 -8
+    /// Releases `elem_count` more elements of the message queue to the GSP.
     fn advance_cpu_read_ptr(&mut self, elem_count: u32) {
-        // ORDERING: LOAD->STORE ordering needed to order `cpu_read_ptr` write after data read.
-        dma_mb(Full);
+        self.cpu_read_ptr = self.cpu_read_ptr.wrapping_add(elem_count);
 
-        let rx = io_project!(self.mem, .cpuq.rx);
-        let rptr = MsgqRxHeader::read_ptr(rx).wrapping_add(elem_count) % MSGQ_NUM_PAGES;
-        MsgqRxHeader::set_read_ptr(rx, rptr)
-    }
+        // ORDERING: the data reads must complete before this write releases the slots to the GSP.
+        // `writel` orders only the writes before it, so the reads need a full barrier.
+        dma_mb(Full);
 
-    // Returns the index of the memory page the CPU can write the next command to.
-    //

drivers/gpu/nova-core/gsp/cmdq.rs fn allocate_command(&mut self, size: usize, timeout: Delta) -> Result<GspCommand · line 403

Quoted 10 lines
drivers/gpu/nova-core/gsp/cmdq.rs +4 -5
-    // # Invariants
-    //
-    // - The returned value is within `0..MSGQ_NUM_PAGES`.
-    fn cpu_write_ptr(&self) -> u32 {
-        MsgqTxHeader::write_ptr(io_project!(self.mem, .cpuq.tx)) % MSGQ_NUM_PAGES
+        self.bar.write(
+            Array::at(0),
+            regs::NV_PGSP_MSGQ_TAIL::zeroed().with_val(self.cpu_read_ptr),
+        );
     }

[Severity: Low]
Should gsp_read_ptr() and advance_cpu_read_ptr() use mb(Full) instead of dma_mb(Full) now that the pointers live in BAR0 MMIO registers?

Per Documentation/memory-barriers.txt, dma_*() barriers do not guarantee ordering with MMIO accesses. While dma_mb() currently falls back to mb() or an equivalent barrier on supported architectures, using mb(Full) matches the kernel barrier contract.

[ ... ]

Quoted 28 lines
drivers/gpu/nova-core/gsp/cmdq.rs +7 -16
@@ -643,23 +618,23 @@ fn wait_for_msg(&self, timeout: Delta) -> Result<GspMessage<'_>> {
         }
         .map(|(slice_1, slice_2)| (slice_1.as_flattened(), slice_2.as_flattened()))?;
 
-        // Extract the `GspMsgElement`.
-        let (header, slice_1) = GspMsgElement::from_bytes_prefix(slice_1).ok_or(EIO)?;
-
-        // Validate checksum after truncating the message to its exact length.
-        if Cmdq::calculate_checksum(
-            SBufferIter::new_reader([header.as_bytes(), slice_1, slice_2])
-                .take(header.msg_length()),
-        ) != 0
-        {
-            dev_err!(&self.dev, "GSP receive: bad checksum\n");
-            return Err(EIO);
-        }
+        // Extract the `QueueElementHeader`.
+        let (header, slice_1) = QueueElementHeader::ref_from_prefix(slice_1).map_err(|_| EIO)?;
 
-        Ok(GspMessage {
-            header,
-            contents: (slice_1, slice_2),
-        })
+        header.validate().inspect_err(|_| {
+            dev_err!(&self.dev, "GSP receive: bad queue element header\n");
+        })?;
+
+        // Cut the message slices down to the length that the queue element header declares.

drivers/gpu/nova-core/gsp/cmdq.rs fn wait_for_msg(&self, timeout: Delta) -> Result<GspMessage<'_>> { · line 638

Quoted 10 lines
drivers/gpu/nova-core/gsp/cmdq.rs +9 -0
+        let contents =
+            trim_message_slice((slice_1, slice_2), header.message_len()).inspect_err(|_| {
+                dev_err!(
+                    &self.dev,
+                    "GSP receive: read area shorter than the message\n"
+                );
+            })?;
+
+        Ok(GspMessage { header, contents })
     }

[Severity: High]
Can a GSP queue element whose mctp_payload_size spans more slots than are currently readable panic the kernel in driver_read_area()?

QueueElementHeader::validate() allows element_len() to exceed size_of::<QueueElementHeader>() + message_len() up to 16 pages, and wait_for_msg() only bounds message_len() via trim_message_slice(). If 1 slot is readable (NV_PGSP_MSGQ_HEAD == 1) and a message has nvdm_payload_size == 64 with mctp_payload_size == 8192 (element_count() == 2), consume_element() advances cpu_read_ptr to 2 past both NV_PGSP_MSGQ_HEAD and last_gsp_write_ptr.

On the next driver_read_area() call, gsp_write_ptr() sees the wrapped difference exceed MSGQ_NUM_PAGES and falls back to last_gsp_write_ptr (1), so gspq_readable_slots() underflows to u32::MAX and io_project!(self.mem, .gspq.msgq.data[panic: ..before_len]) panics out of bounds. Verifying that header.element_len() fits in the readable area in wait_for_msg() prevents this.

[ ... ]

drivers/gpu/nova-core/gsp/cmdq.rs fn consume_element<R>( · line 662

Quoted 10 lines
drivers/gpu/nova-core/gsp/cmdq.rs +1 -5
@@ -683,14 +659,25 @@ fn consume_element<R>(
         f: impl FnOnce(GspParsedMessage<'_>) -> R,
     ) -> Result<R> {
         let message = self.wait_for_msg(timeout)?;
-        let elem_count = u32::try_from(message.header.msg_length().div_ceil(GSP_PAGE_SIZE))
-            .map_err(|_| {
-                dev_err!(&self.dev, "GSP receive: message length overflow\n");
-                EIO
-            })?;
+        let elem_count = message.header.element_count();

[Severity: Medium]
Can advancing cpu_read_ptr by element_count() here without first checking element_len() against the readable slots underflow gspq_readable_slots() and panic in driver_read_area() instead of returning EIO?

Because wait_for_msg() only validates message_len() against the readable slices and QueueElementHeader is borrowed in place from coherent DMA memory via ref_from_prefix() across validate(), message_len(), element_count(), and nvdm_type(), a misframed or concurrently modified header can cause advance_cpu_read_ptr() to overtake last_gsp_write_ptr. Copying the 24-byte QueueElementHeader by value, validating element_len() against the readable area, and clamping gspq_readable_slots() to MSGQ_NUM_PAGES eliminates this panic path.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=12
author maintainer
#19 lore raw

PATCH 13/15 gpu: nova-core: gsp: delete the GSP sequencer

In reply to Alexandre Courbot

From: John Hubbard <[email protected]>

With the switch to the r000 GSP firmware, load-and-execute GMC events replaced the command sequences that the r570 GSP-RM sent for the GSP sequencer to run, leaving the sequencer module unused.

Delete the GSP sequencer module along with its firmware wrapper types, RPC event variant, and the post_boot HAL hook. Also mark SBufferIter::flush_into_kvec as dead code now that its last caller is gone.

---
 drivers/gpu/nova-core/gsp.rs           |   1 -
 drivers/gpu/nova-core/gsp/fw.rs        | 275 -------------------------
 drivers/gpu/nova-core/gsp/hal.rs       |  14 --
 drivers/gpu/nova-core/gsp/hal/tu102.rs |  12 --
 drivers/gpu/nova-core/gsp/sequencer.rs | 353 ---------------------------------
 drivers/gpu/nova-core/sbuffer.rs       |   1 +
 6 files changed, 1 insertion(+), 655 deletions(-)
drivers/gpu/nova-core/gsp.rs +0 -1
index 05c1aa9d2159..a43e76609485 100644
@@ -24,7 +24,6 @@
 mod logbuffer;
 mod nvkv;
 mod regs;
-mod sequencer;
 
 use logbuffer::LogBuffers;
 pub(crate) use logbuffer::RetainedLogs;
drivers/gpu/nova-core/gsp/fw.rs +0 -275

293 lines not on this page · raw message

drivers/gpu/nova-core/gsp/hal.rs +0 -14
index caf249f37445..49f5752cc71a 100644
@@ -41,20 +41,6 @@ fn boot<'gpu>(
         ctx: &mut GspBootContext<'_, 'gpu>,
         gsp_fw: &GspFirmware<'gpu>,
     ) -> Result<Option<super::UnloadBundle<'gpu>>>;
-
-    /// Performs HAL-specific post-GSP boot tasks.
-    ///
-    /// This method is called by the GSP boot code after the GSP is confirmed to be running, and
-    /// after the initialization commands have been pushed onto its queue.
-    #[expect(dead_code)]
-    fn post_boot(
-        &self,
-        _gsp: &Gsp<'_>,
-        _ctx: &mut GspBootContext<'_, '_>,
-        _gsp_fw: &GspFirmware<'_>,
-    ) -> Result {
-        Ok(())
-    }
 }
 
 /// Returns the names of the firmware files required to boot the GSP of `chipset`, in addition to
drivers/gpu/nova-core/gsp/hal/tu102.rs +0 -12
index 2c95d178b020..8742910aa623 100644
@@ -40,7 +40,6 @@
             UnloadBundle, //
         },
         regs,
-        sequencer::GspSequencer,
         Gsp,
         GspBootContext,
         GspFwWprMeta, //
@@ -313,17 +312,6 @@ fn boot<'gpu>(
 
         Ok(unload_guard.dismiss())
     }
-
-    fn post_boot(
-        &self,
-        gsp: &Gsp<'_>,
-        ctx: &mut GspBootContext<'_, '_>,
-        gsp_fw: &GspFirmware<'_>,
-    ) -> Result {
-        GspSequencer::run(&gsp.cmdq, ctx, &gsp.libos, gsp_fw.bootloader.app_version)?;
-
-        Ok(())
-    }
 }
 
 /// The TU102 HAL requires the use of the FWSEC bootloader.
drivers/gpu/nova-core/gsp/sequencer.rs deleted +0 -353

353 lines not on this page · raw message

drivers/gpu/nova-core/sbuffer.rs +1 -0
index b8c01104c255..b6e77788c338 100644
@@ -164,6 +164,7 @@ pub(crate) fn read_exact(&mut self, mut dst: &mut [u8]) -> Result {
     /// Read all the remaining data into a [`KVec`].
     ///
     /// `self` will be empty after this operation.
+    #[expect(dead_code)]
     pub(crate) fn flush_into_kvec(&mut self, flags: kernel::alloc::Flags) -> Result<KVec<u8>> {
         let mut buf = KVec::<u8>::new();
 
Signature · 1 line
2.56.1
author maintainer
#20 lore raw

PATCH 14/15 gpu: nova-core: gsp: delete the r570 RPC commands

In reply to Alexandre Courbot

From: John Hubbard <[email protected]>

With the switch to the r000 GSP firmware, the GSP_INIT and GSP_SUSPEND GMC commands replaced the four RPC commands that the r570 boot and shutdown paths sent (SetSystemInfo, SetRegistry, GetGspStaticInfo and UnloadingGuestDriver), and the reply to GSP_INIT replaced the init-done event.

Delete the unused r570 RPC commands module and its firmware payload wrappers.

---
 drivers/gpu/nova-core/gsp/commands.rs     |   2 -
 drivers/gpu/nova-core/gsp/commands/rpc.rs | 285 ------------------------------
 drivers/gpu/nova-core/gsp/fw/commands.rs  | 250 +-------------------------
 3 files changed, 3 insertions(+), 534 deletions(-)
drivers/gpu/nova-core/gsp/commands.rs +0 -2
index df920e3d8322..cf522a90eae4 100644
@@ -2,8 +2,6 @@
 // SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
 
 pub(crate) mod gmc;
-#[expect(dead_code)]
-pub(crate) mod rpc;
 
 use core::{
     ffi::FromBytesUntilNulError,
drivers/gpu/nova-core/gsp/commands/rpc.rs deleted +0 -285

285 lines not on this page · raw message

drivers/gpu/nova-core/gsp/fw/commands.rs +3 -247

273 lines not on this page · raw message

Signature · 1 line
2.56.1
author maintainer
#21 lore raw

PATCH 15/15 gpu: nova-core: firmware: delete the r570 bindings

In reply to Alexandre Courbot

From: John Hubbard <[email protected]>

The driver no longer refers to the r570 bindings, but their module is still declared, and its generated definitions are still compiled.

Delete the r570 bindings module, along with the last comment that names r570.

---
 drivers/gpu/nova-core/fsp.rs                      |    3 +-
 drivers/gpu/nova-core/gsp/fw.rs                   |    1 -
 drivers/gpu/nova-core/gsp/fw/r570_144.rs          |   31 -
 drivers/gpu/nova-core/gsp/fw/r570_144/bindings.rs | 1060 ---------------------
 4 files changed, 2 insertions(+), 1093 deletions(-)
drivers/gpu/nova-core/fsp.rs +2 -1
index ea08cd58346f..5976a1730981 100644
@@ -259,7 +259,8 @@ fn frts_vidmem_offset(hal: &dyn hal::FspHal, fb_info: &FbSizes) -> Result<u64> {
         // As per OpenRM's `kfspPrepareBootCommands_GH100`.
         if fb_info.pmu_reserved_size != 0 {
             offset = (offset + u64::from(fb_info.pmu_reserved_size))
-                // The 2 MiB alignment is r570-specific.
+                // This must be aligned to WPR alignment (128 KiB) and be at least 128 KiB in size.
+                // 2 MiB satisfies both.
                 .align_up(Alignment::SZ_2M)
                 .ok_or(EINVAL)?;
         }
drivers/gpu/nova-core/gsp/fw.rs +0 -1
index c5ed5d47918a..48e0ea6aaea9 100644
@@ -3,7 +3,6 @@
 
 pub(crate) mod commands;
 mod r000_00;
-mod r570_144;
 
 // Alias to avoid repeating the version number with every use.
 use r000_00 as bindings;
drivers/gpu/nova-core/gsp/fw/r570_144.rs deleted +0 -31
deleted file mode 100644
index 2e6f0d298756..000000000000
@@ -1,31 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0
-
-//! Firmware bindings.
-//!
-//! Imports the generated bindings by `bindgen`.
-//!
-//! This module may not be directly used. Please abstract or re-export the needed symbols in the
-//! parent module instead.
-
-#![allow(
-    dead_code,
-    clippy::all,
-    clippy::undocumented_unsafe_blocks,
-    clippy::ptr_as_ptr,
-    clippy::ref_as_ptr,
-    missing_docs,
-    non_camel_case_types,
-    non_upper_case_globals,
-    non_snake_case,
-    improper_ctypes,
-    unreachable_pub,
-    unsafe_op_in_unsafe_fn
-)]
-use kernel::ffi;
-use pin_init::MaybeZeroable;
-
-include!("r570_144/bindings.rs");
-
-// SAFETY: This type has a size of zero, so its inclusion into another type should not affect their
-// ability to implement `Zeroable`.
-unsafe impl<T> kernel::prelude::Zeroable for __IncompleteArrayField<T> {}
drivers/gpu/nova-core/gsp/fw/r570_144/bindings.rs deleted +0 -1060

1,060 lines not on this page · raw message

Signature · 1 line
2.56.1