From: Alexandre Courbot <acourbot@nvidia.com>
To: "Danilo Krummrich" <dakr@kernel.org>,
"Alice Ryhl" <aliceryhl@google.com>,
"David Airlie" <airlied@gmail.com>,
"Simona Vetter" <simona@ffwll.ch>,
"Miguel Ojeda" <ojeda@kernel.org>,
"Boqun Feng" <boqun@kernel.org>, "Gary Guo" <gary@garyguo.net>,
"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
"Benno Lossin" <lossin@kernel.org>,
"Andreas Hindborg" <a.hindborg@kernel.org>,
"Trevor Gross" <tmgross@umich.edu>,
"Daniel Almeida" <daniel.almeida@collabora.com>,
"Tamir Duberstein" <tamird@kernel.org>,
"Onur Özkan" <work@onurozkan.dev>,
"Maarten Lankhorst" <maarten.lankhorst@linux.intel.com>,
"Maxime Ripard" <mripard@kernel.org>,
"Thomas Zimmermann" <tzimmermann@suse.de>,
"Jonathan Corbet" <corbet@lwn.net>,
"Shuah Khan" <skhan@linuxfoundation.org>,
"Randy Dunlap" <rdunlap@infradead.org>
Cc: John Hubbard <jhubbard@nvidia.com>,
Alistair Popple <apopple@nvidia.com>,
Timur Tabi <ttabi@nvidia.com>,
Eliot Courtney <ecourtney@nvidia.com>,
Zhi Wang <zhiw@nvidia.com>, Alok Kumar <alkumar@nvidia.com>,
nova-gpu@lists.linux.dev, dri-devel@lists.freedesktop.org,
rust-for-linux@vger.kernel.org, linux-doc@vger.kernel.org,
linux-kernel@vger.kernel.org,
Alexandre Courbot <acourbot@nvidia.com>
Subject: [PATCH 02/15] gpu: nova-core: gsp: add the GSP_INIT command and its reply
Date: Thu, 03 Dec 2026 21:09:19 +0900 [thread overview]
Message-ID: <20261203-b4-r000-switch-v1-2-b1463ec6dae2@nvidia.com> (raw)
In-Reply-To: <20261203-b4-r000-switch-v1-0-b1463ec6dae2@nvidia.com>
From: John Hubbard <jhubbard@nvidia.com>
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.
Signed-off-by: John Hubbard <jhubbard@nvidia.com>
[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`.]
Co-developed-by: Alexandre Courbot <acourbot@nvidia.com>
Signed-off-by: Alexandre Courbot <acourbot@nvidia.com>
---
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(-)
diff --git a/drivers/gpu/nova-core/gsp/commands.rs b/drivers/gpu/nova-core/gsp/commands.rs
index 91f63f704e55..b48cf30978cf 100644
--- a/drivers/gpu/nova-core/gsp/commands.rs
+++ b/drivers/gpu/nova-core/gsp/commands.rs
@@ -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::{
diff --git a/drivers/gpu/nova-core/gsp/commands/gmc.rs b/drivers/gpu/nova-core/gsp/commands/gmc.rs
new file mode 100644
index 000000000000..f74ada78f7ac
--- /dev/null
+++ b/drivers/gpu/nova-core/gsp/commands/gmc.rs
@@ -0,0 +1,133 @@
+// SPDX-License-Identifier: GPL-2.0
+// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
+
+//! GMC (GPU Management Controller) API commands.
+
+use core::convert::Infallible;
+
+use kernel::{
+ device,
+ pci,
+ prelude::*,
+ time::Delta,
+ transmute::AsBytes, //
+};
+
+use crate::{
+ gpu::Chipset,
+ gsp::{
+ cmdq::gmc::{
+ CommandToGsp,
+ MessageFromGsp, //
+ },
+ commands::GspStaticInfo,
+ fw::{
+ commands::{
+ GspInitRequest,
+ GspInitResponseSchema, //
+ },
+ GmcCommandId, //
+ },
+ nvkv::{
+ Decoder,
+ Encodable,
+ Encoder,
+ Schema,
+ UnknownKeyPolicy, //
+ },
+ },
+ sbuffer::SBufferIter,
+};
+
+/// The `GSP_INIT` command, which carries the system information and registry keys to GSP-RM.
+///
+/// GSP-RM answers it with the static GPU configuration once it has finished starting.
+pub(crate) struct GspInit {
+ /// The NVKV-encoded request.
+ payload: KVVec<u64>,
+}
+
+impl GspInit {
+ /// Builds the request for `pdev`.
+ ///
+ /// # 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> {
+ let mut encoder = Encoder::new();
+ GspInitRequest::new(pdev, chipset)?.encode(&mut encoder)?;
+
+ Ok(Self {
+ payload: encoder.finish(),
+ })
+ }
+
+ /// Returns the request as the bytes that the GSP reads.
+ fn payload_bytes(&self) -> &[u8] {
+ AsBytes::as_bytes(self.payload.as_slice())
+ }
+}
+
+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);
+ type Command = ();
+ type Reply = GspStaticInfo;
+ type InitError = Infallible;
+
+ fn init(&self) -> impl Init<Self::Command, Self::InitError> {
+ pin_init::init_zeroed()
+ }
+
+ fn variable_payload_len(&self) -> usize {
+ self.payload_bytes().len()
+ }
+
+ fn init_variable_payload(
+ &self,
+ dst: &mut SBufferIter<core::array::IntoIter<&mut [u8], 2>>,
+ ) -> Result {
+ dst.write_all(self.payload_bytes())
+ }
+}
+
+impl MessageFromGsp for GspStaticInfo {
+ type InitError = Error;
+
+ /// Decodes the `GSP_INIT` reply, an NVKV stream, into the static configuration.
+ ///
+ /// # Errors
+ ///
+ /// - `EINVAL` if the payload is not a whole number of NVKV words, if the stream is malformed
+ /// or omits a required key, or if GSP-RM reported no framebuffer region.
+ /// - `ENOMEM` if the words or the decoded regions cannot be allocated.
+ fn read(payload: &mut SBufferIter<core::array::IntoIter<&[u8], 2>>) -> Result<Self> {
+ let mut words = KVVec::new();
+ while !payload.is_empty() {
+ let mut word = [0u8; size_of::<u64>()];
+ payload.read_exact(&mut word)?;
+ words.push(u64::from_le_bytes(word), GFP_KERNEL)?;
+ }
+
+ let decoder = Decoder::new(&words, UnknownKeyPolicy::Ignore);
+ let mut schema = KBox::init(GspInitResponseSchema::init(), GFP_KERNEL)?;
+ let reply = KBox::try_init(decoder.decode(&mut *schema)?, GFP_KERNEL)?;
+
+ let mut usable_fb_regions = KVec::new();
+ for region in reply.usable_fb_regions() {
+ usable_fb_regions.push(region, GFP_KERNEL)?;
+ }
+
+ Ok(GspStaticInfo {
+ gpu_name: reply.gpu_name(),
+ gpu_short_name: reply.gpu_short_name(),
+ gpu_gid: reply.gpu_gid(),
+ bar1_pde_base: reply.bar1_pde_base(),
+ usable_fb_regions,
+ total_fb_end: reply.total_fb_end().ok_or(EINVAL)?,
+ })
+ }
+}
diff --git a/drivers/gpu/nova-core/gsp/fw/commands.rs b/drivers/gpu/nova-core/gsp/fw/commands.rs
index 76f8d4a75562..c7f544775ce9 100644
--- a/drivers/gpu/nova-core/gsp/fw/commands.rs
+++ b/drivers/gpu/nova-core/gsp/fw/commands.rs
@@ -331,6 +331,25 @@ fn from(value: HostArch) -> Self {
}
}
+impl HostArch {
+ /// Returns the variant that names the architecture for which this kernel is built.
+ fn host() -> Self {
+ if cfg!(target_arch = "x86_64") {
+ Self::X86_64
+ } else if cfg!(target_arch = "aarch64") {
+ Self::Aarch64
+ } else if cfg!(all(target_arch = "powerpc64", target_endian = "little")) {
+ Self::Ppc64le
+ } else if cfg!(target_arch = "arm") {
+ Self::Arm
+ } else if cfg!(target_arch = "riscv64") {
+ Self::Riscv64
+ } else {
+ Self::None
+ }
+ }
+}
+
nvkv_encode! {
/// A GSP registry entry.
struct RegKey {
@@ -339,6 +358,18 @@ struct RegKey {
}
}
+impl RegKey {
+ /// Creates a registry entry.
+ ///
+ /// GSP-RM counts the NUL terminator in the encoded name length.
+ const fn new(key_name: &'static CStr, key_value: u32) -> Self {
+ Self {
+ key_name: Key::new(key_name.to_bytes_with_nul()),
+ key_value: Key::new(key_value),
+ }
+ }
+}
+
impl Encodable for KVVec<RegKey> {
fn encode(&self, encoder: &mut Encoder) -> Result {
for regkey in self {
@@ -362,10 +393,7 @@ struct VfInfo {
nvkv_encode! {
/// Payload of the `GSP_INIT` command.
- // TODO: expect() doesn't work here before rustc 1.97.0
- // https://github.com/rust-lang/rust/pull/154377
- #[allow(dead_code)]
- struct GspInitRequest {
+ pub(crate) struct GspInitRequest {
pci_device_id: Key<u32, 0x0001>,
pci_sub_device_id: Key<u32, 0x0002>,
pci_revision_id: Key<u32, 0x0003>,
@@ -406,15 +434,55 @@ fn new(dev: &pci::Device<device::Bound>) -> Self {
}
}
+/// Registry entries that the driver sends to GSP-RM on every boot.
+const REGISTRY_ENTRIES: [RegKey; 3] = [
+ // Enables PCI secondary bus reset.
+ RegKey::new(c"RMSecBusResetEnable", 1),
+ // Makes GSP-RM preserve PCI configuration registers across any PCI reset.
+ RegKey::new(c"RMForcePcieConfigSave", 1),
+ // Lets GSP-RM boot when the PCI device id is absent from its product name database.
+ RegKey::new(c"RMDevidCheckIgnore", 1),
+];
+
+impl GspInitRequest {
+ /// Creates the request for `dev`.
+ ///
+ /// The registry keys are [`REGISTRY_ENTRIES`].
+ ///
+ /// # Errors
+ ///
+ /// - `ENOMEM` if the registry list cannot be allocated.
+ pub(crate) fn new(dev: &pci::Device<device::Bound>, chipset: Chipset) -> Result<Self> {
+ let mut regkeys = KVVec::new();
+ for entry in REGISTRY_ENTRIES {
+ regkeys.push(entry, GFP_KERNEL)?;
+ }
+
+ let mirror = chipset.pci_config_mirror_range();
+ let device_id = (u32::from(dev.device_id()) << 16) | u32::from(dev.vendor_id().as_raw());
+ let sub_device_id =
+ (u32::from(dev.subsystem_device_id()) << 16) | u32::from(dev.subsystem_vendor_id());
+
+ Ok(Self {
+ pci_device_id: device_id.into(),
+ pci_sub_device_id: sub_device_id.into(),
+ pci_revision_id: u32::from(dev.revision_id()).into(),
+ pci_config_mirror_base: mirror.start.into(),
+ pci_config_mirror_size: (mirror.end - mirror.start).into(),
+ host_arch: HostArch::host().into(),
+ bus_device_func: u64::from(DomainBusDevice::new(dev)).into(),
+ regkeys,
+ vf_info: None,
+ })
+ }
+}
+
// Decode:
// Should decode with UnknownKeyPolicy::Ignore.
nvkv_decode! {
/// Schema for the `GSP_INIT` response.
- // TODO: expect() doesn't work here before rustc 1.97.0
- // https://github.com/rust-lang/rust/pull/154377
- #[allow(dead_code)]
- struct GspInitResponseSchema => GspInitResponse {
+ pub(crate) struct GspInitResponseSchema => GspInitResponse {
gpu_name: TruncatingArray<u8, { GspStaticInfo::MAX_GPU_NAME_LEN }, 0x2000>,
gpu_short_name: TruncatingArray<u8, { GspStaticInfo::MAX_GPU_NAME_LEN }, 0x2001>,
gpu_gid: TruncatingArray<u8, { GspStaticInfo::GID_LEN }, 0x2002>,
@@ -425,10 +493,7 @@ struct GspInitResponseSchema => GspInitResponse {
}
/// Payload of the `GSP_INIT` response.
-// TODO: expect() doesn't work here before rustc 1.97.0
-// https://github.com/rust-lang/rust/pull/154377
-#[allow(dead_code)]
-struct GspInitResponse {
+pub(crate) struct GspInitResponse {
gpu_name: ArrayVec<u8, { GspStaticInfo::MAX_GPU_NAME_LEN }>,
gpu_short_name: ArrayVec<u8, { GspStaticInfo::MAX_GPU_NAME_LEN }>,
gpu_gid: ArrayVec<u8, { GspStaticInfo::GID_LEN }>,
@@ -437,6 +502,72 @@ struct GspInitResponse {
vmmu_segment_size: u64,
}
+/// Copies `src` to the start of a zero-initialized array.
+fn zero_padded_array<const N: usize>(src: &ArrayVec<u8, N>) -> [u8; N] {
+ let mut dst = [0u8; N];
+ // PANIC: `src.len()` never exceeds `N` per the invariant of `ArrayVec`.
+ dst[..src.len()].copy_from_slice(src);
+ dst
+}
+
+impl GspInitResponse {
+ /// Tag of a general-purpose region. Any other tag marks a region that GSP-RM reserves for the
+ /// use that the tag names.
+ const FB_REGION_TAG_NONE: u32 = 0;
+
+ /// Returns the GPU name, zero-padded to [`GspStaticInfo::MAX_GPU_NAME_LEN`] bytes.
+ pub(crate) fn gpu_name(&self) -> [u8; GspStaticInfo::MAX_GPU_NAME_LEN] {
+ zero_padded_array(&self.gpu_name)
+ }
+
+ /// Returns the short GPU name, zero-padded to [`GspStaticInfo::MAX_GPU_NAME_LEN`] bytes.
+ pub(crate) fn gpu_short_name(&self) -> [u8; GspStaticInfo::MAX_GPU_NAME_LEN] {
+ zero_padded_array(&self.gpu_short_name)
+ }
+
+ /// Returns the SHA-1 based GPU identifier (GID), zero-padded to [`GspStaticInfo::GID_LEN`]
+ /// bytes.
+ pub(crate) fn gpu_gid(&self) -> [u8; GspStaticInfo::GID_LEN] {
+ zero_padded_array(&self.gpu_gid)
+ }
+
+ /// Returns an iterator over the FB regions from which the driver may allocate: the
+ /// general-purpose regions that are not protected and that support both compression and
+ /// isochronous access.
+ pub(crate) fn usable_fb_regions(&self) -> impl Iterator<Item = Range<u64>> + '_ {
+ self.fb_regions.iter().filter_map(|region| {
+ if region.limit >= region.base
+ && region.tag == Self::FB_REGION_TAG_NONE
+ && !region.flags.protected()
+ && region.flags.support_compressed()
+ && region.flags.support_iso()
+ {
+ region.limit.checked_add(1).map(|end| region.base..end)
+ } else {
+ None
+ }
+ })
+ }
+
+ /// Returns the exclusive end of the FB physical address space, which spans every region
+ /// including the ones that [`Self::usable_fb_regions`] leaves out.
+ ///
+ /// Returns `None` if no region that GSP-RM reported has a limit at or above its base.
+ pub(crate) fn total_fb_end(&self) -> Option<u64> {
+ self.fb_regions
+ .iter()
+ .filter(|region| region.limit >= region.base)
+ .map(|region| region.limit)
+ .max()?
+ .checked_add(1)
+ }
+
+ /// Returns the BAR1 page directory entry base address.
+ pub(crate) fn bar1_pde_base(&self) -> u64 {
+ self.bar1_pde_base
+ }
+}
+
nvkv_decode! {
/// Schema for one FB region of the `GSP_INIT` response.
struct FbRegionSchema => FbRegion {
--
2.56.1
next prev parent reply other threads:[~2026-12-03 12:09 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-03 12:09 [PATCH 00/15] gpu: nova-core: switch to the r000 GSP firmware Alexandre Courbot
2026-12-03 12:09 ` [PATCH 01/15] gpu: nova-core: gsp: nvkv: add const constructor for Key Alexandre Courbot
2026-12-03 12:09 ` Alexandre Courbot [this message]
2026-12-03 12:09 ` [PATCH 03/15] gpu: nova-core: gsp: populate VF information in GSP_INIT Alexandre Courbot
2026-12-03 14:03 ` Maxime Ripard
2026-12-03 14:32 ` Miguel Ojeda
2026-12-03 14:38 ` Maxime Ripard
2026-12-03 12:09 ` [PATCH 04/15] gpu: nova-core: gsp: re-export PowerStateLevel from gsp::commands Alexandre Courbot
2026-12-03 12:09 ` [PATCH 05/15] gpu: nova-core: gsp: add the GSP_SUSPEND request Alexandre Courbot
2026-12-03 12:09 ` [PATCH 06/15] gpu: nova-core: firmware: add the ucodes firmware loader Alexandre Courbot
2026-12-03 12:09 ` [PATCH 07/15] gpu: nova-core: gsp: define GSP_MSG_QUEUE_ELEMENT_SIZE_MAX without bindings Alexandre Courbot
2026-12-03 12:09 ` [PATCH 08/15] gpu: nova-core: fb: increase Blackwell reserved memory sizes for r000 Alexandre Courbot
2026-12-03 12:09 ` [PATCH 09/15] gpu: nova-core: gsp: drain the message queue while waiting for GSP suspend Alexandre Courbot
2026-12-03 12:09 ` [PATCH 10/15] gpu: nova-core: gsp: zero-initialize FMC boot parameter structs Alexandre Courbot
2026-12-03 12:09 ` [PATCH 11/15] gpu: nova-core: firmware: add r000 GSP bindings Alexandre Courbot
2026-12-03 12:09 ` [PATCH 12/15] gpu: nova-core: switch to the r000 GSP firmware Alexandre Courbot
2026-12-03 12:09 ` [PATCH 13/15] gpu: nova-core: gsp: delete the GSP sequencer Alexandre Courbot
2026-12-03 12:09 ` [PATCH 14/15] gpu: nova-core: gsp: delete the r570 RPC commands Alexandre Courbot
2026-12-03 12:09 ` [PATCH 15/15] gpu: nova-core: firmware: delete the r570 bindings Alexandre Courbot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261203-b4-r000-switch-v1-2-b1463ec6dae2@nvidia.com \
--to=acourbot@nvidia.com \
--cc=a.hindborg@kernel.org \
--cc=airlied@gmail.com \
--cc=aliceryhl@google.com \
--cc=alkumar@nvidia.com \
--cc=apopple@nvidia.com \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun@kernel.org \
--cc=corbet@lwn.net \
--cc=dakr@kernel.org \
--cc=daniel.almeida@collabora.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=ecourtney@nvidia.com \
--cc=gary@garyguo.net \
--cc=jhubbard@nvidia.com \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lossin@kernel.org \
--cc=maarten.lankhorst@linux.intel.com \
--cc=mripard@kernel.org \
--cc=nova-gpu@lists.linux.dev \
--cc=ojeda@kernel.org \
--cc=rdunlap@infradead.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=simona@ffwll.ch \
--cc=skhan@linuxfoundation.org \
--cc=tamird@kernel.org \
--cc=tmgross@umich.edu \
--cc=ttabi@nvidia.com \
--cc=tzimmermann@suse.de \
--cc=work@onurozkan.dev \
--cc=zhiw@nvidia.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox