Skip to contentSkip to conversation

gpu: nova-core: boot GSP with vGPU enabled

RFC Superseded Zhi Wang 1 participant 11 messages Mar 13

Subsystems (8)

v2 of 5 Superseded Latest is v5 →

lore
Share & tools
lore

Zhi Wang

author
#0 lore raw

v2 cover gpu: nova-core: boot GSP with vGPU enabled

Booting up GSP with vGPU enabled is part of the first milestone (M1) together with rust fwctl abstraction [1] and nova-core fwctl driver [2] for upstream vGPU support, allowing us to validate the basic GSP boot flow with vGPU enabled, upload vGPU types even before the remaining nova-core dependencies are ready.

This RFC v2 series is rebased on top of john/nova-core-blackwell-v6 (linux 7.0.0-rc1) [3], with the ExtSriovCapability abstraction extracted into a separate upstream patch [4] based on Garry's WIP work. It also adds FSP PRC protocol support for querying vGPU mode on Blackwell+ architectures, along with documentation for the FSP/PRC interface.

Besides the mailing list review, all the patches of M1 will be maintained and iterated on the zhi/vgpu-m1-staging branch [5] before all the dependencies are solved.

v2:

- Adopt early-return style (Dirk).
- Add #ifndef CONFIG_PCI_IOV helper to fix compilation when CONFIG_PCI_IOV is disabled, per (Alex).
- Change return type from Result<i32> to Result<u16> to match the PCI spec field width, avoiding try_from at call sites.
- GspVfInfo changed to tuple struct (Alex).
- Use unconditional constructor with Option wrapping instead of bool parameter. (Alex)
- Use full initialization expression instead of mutating a zeroed value.
- Use .chain() pattern in GspSetSystemInfo::init() for optional vGPU info. (Alex)
- Eliminate all magic numbers: add vf_bar_is_64bit() and read_vf_bar64_addr() to ExtSriovCapability using PCI bindings constants (PCI_BASE_ADDRESS_MEM_TYPE_MASK, etc.).
- Use KVec<RegistryEntry> for dynamic registry entry construction instead of hardcoded array (Timur, Joel, Alexandre).
- Replace magic numbers 32/48 with named binding constants MAX_PARTITIONS_WITH_GFID_32VM / MAX_PARTITIONS_WITH_GFID from OpenRM (Alex).
- Use read_poll_timeout() instead of single read for scrubber completion check (Joel).
- Use dev instead of pdev.as_ref() in dev_dbg! (Dirk).
- Change scrubber trigger condition from vgpu_requested to fb_layout.wpr2_heap.len() > SZ_256M, checking actual heap size instead of vGPU flag. (Alex).

- New patches:

- Factor out common FSP message header, return response buffer to caller, add PRC protocol support for reading vGPU mode from FSP on Blackwell+,
- Add FSP/PRC protocol documentation. (Suggested by Joel)
- The [!UPSTREAM] config space access patch from v1 is replaced by the ExtSriovCapability abstraction submitted separately [4].

Dependencies Status
=============================

[1] rust: introduce abstractions for fwctl v3              - In review
[2] gpu: nova-core: add fwctl driver                       - In review
[4] rust: pci: add extended capability and SR-IOV support  - RFC
[6] I/O projection API (Gary Guo)                          - WIP
[7] gsp: add continuation record support v6                - In review
[8] gsp: add locking to Cmdq v4                            - In review
[9] gsp: add RM control command infrastructure             - In review

[1] https://lore.kernel.org/rust-for-linux/[email protected]/
[2] https://lore.kernel.org/rust-for-linux/[email protected]/
[3] https://github.com/johnhubbard/linux/tree/nova-core-blackwell-v6
[4] https://lore.kernel.org/rust-for-linux/[email protected]/
[5] https://github.com/zhiwang-nvidia/nova-core/tree/zhi/vgpu-m1-staging
[6] https://github.com/nbdd0121/linux/tree/io_projection
[7] https://lore.kernel.org/nouveau/[email protected]/
[8] https://lore.kernel.org/nouveau/[email protected]/
[9] https://lore.kernel.org/nouveau/[email protected]/

Zhi Wang (10):
rust: pci: expose sriov_get_totalvfs() helper
gpu: nova-core: factor out common FSP message header
gpu: nova-core: return FSP response buffer to caller
gpu: nova-core: read vGPU mode from FSP via PRC protocol
gpu: nova-core: add FSP and PRC protocol documentation
gpu: nova-core: introduce vgpu_support module param
gpu: nova-core: populate GSP_VF_INFO when vGPU is enabled
gpu: nova-core: set RMSetSriovMode when NVIDIA vGPU is enabled
gpu: nova-core: reserve a larger GSP WPR2 heap when vGPU is enabled
gpu: nova-core: load the scrubber ucode when vGPU support is enabled

 Documentation/gpu/nova/core/fsp.rst           | 135 ++++++++++
 Documentation/gpu/nova/index.rst              |   1 +
 drivers/gpu/nova-core/fb.rs                   |  21 +-
 drivers/gpu/nova-core/firmware.rs             |   3 +-
 drivers/gpu/nova-core/firmware/booter.rs      |   2 +
 drivers/gpu/nova-core/fsp.rs                  | 231 +++++++++++++++---
 drivers/gpu/nova-core/gpu.rs                  |  48 +++-
 drivers/gpu/nova-core/gsp.rs                  |  32 ++-
 drivers/gpu/nova-core/gsp/boot.rs             | 133 +++++++---
 drivers/gpu/nova-core/gsp/commands.rs         | 105 +++++---
 drivers/gpu/nova-core/gsp/fw.rs               |  90 ++++++-
 drivers/gpu/nova-core/gsp/fw/commands.rs      |  12 +-
 .../gpu/nova-core/gsp/fw/r570_144/bindings.rs |   4 +
 drivers/gpu/nova-core/mctp.rs                 |   2 +
 drivers/gpu/nova-core/nova_core.rs            |  15 ++
 drivers/gpu/nova-core/regs.rs                 |  12 +
 drivers/gpu/nova-core/vgpu.rs                 |  37 +++
 rust/helpers/pci.c                            |   7 +
 rust/kernel/pci.rs                            |  14 ++
 19 files changed, 797 insertions(+), 107 deletions(-)
 create mode 100644 Documentation/gpu/nova/core/fsp.rst
 create mode 100644 drivers/gpu/nova-core/vgpu.rs
Signature · 1 line
2.51.0
author
#1 lore raw

RFC v2 1/10 rust: pci: expose sriov_get_totalvfs() helper

Add a wrapper for the pci_sriov_get_totalvfs() helper, allowing drivers to query the number of total SR-IOV virtual functions a PCI device supports.

Cc Dirk Behme <[email protected]>
Cc Alexandre Courbot <[email protected]>
---
 rust/helpers/pci.c |  7 +++++++
 rust/kernel/pci.rs | 14 ++++++++++++++
 2 files changed, 21 insertions(+)
rust/helpers/pci.c +7 -0
index 5043c9909d44..a3072fbe2871 100644
@@ -29,6 +29,13 @@ __rust_helper u32 rust_helper_pci_ext_cap_next(u32 header)
 	return PCI_EXT_CAP_NEXT(header);
 }
 
+#ifndef CONFIG_PCI_IOV
+__rust_helper int rust_helper_pci_sriov_get_totalvfs(struct pci_dev *dev)
+{
+	return pci_sriov_get_totalvfs(dev);
+}
+#endif
+
 #ifndef CONFIG_PCI_MSI
 __rust_helper int rust_helper_pci_alloc_irq_vectors(struct pci_dev *dev,
 						    unsigned int min_vecs,
rust/kernel/pci.rs +14 -0
index fc9c8e2077b2..c787f62b7f53 100644
@@ -450,6 +450,20 @@ pub fn pci_class(&self) -> Class {
         // SAFETY: `self.as_raw` is a valid pointer to a `struct pci_dev`.
         Class::from_raw(unsafe { (*self.as_raw()).class })
     }
+
+    /// Returns total number of VFs, or `Err(ENODEV)` if none available.
+    pub fn sriov_get_totalvfs(&self) -> Result<u16> {
+        // SAFETY: `self.as_raw()` is a valid pointer to a `struct pci_dev`.
+        let vfs = unsafe { bindings::pci_sriov_get_totalvfs(self.as_raw()) };
+
+        if vfs == 0 {
+            return Err(ENODEV);
+        }
+
+        // `pci_sriov_get_totalvfs` reads from the SR-IOV total_VFs field (u16
+        // in the PCI spec), so non-zero values always fit in u16.
+        Ok(vfs.try_into()?)
+    }
 }
 
 impl Device<device::Core> {
Signature · 1 line
2.51.0
author
#2 lore raw

RFC v2 2/10 gpu: nova-core: factor out common FSP message header

In reply to Zhi Wang

FSP supports multiple protocols (COT, PRC) with different message types, all sharing the same MCTP and NVDM header format.

Extract common headers into FspMessageHeader with a new() constructor that builds standard MCTP/NVDM headers using the bitfield types. Rename FspMessage to FspCotMessage for clarity. The COT message construction is simplified to FspMessageHeader::new(NVDM_TYPE_COT).

---
 drivers/gpu/nova-core/fsp.rs | 46 ++++++++++++++++++++++++++----------
 1 file changed, 33 insertions(+), 13 deletions(-)
drivers/gpu/nova-core/fsp.rs +33 -13
index 1bd2ce997d4a..477ed719b757 100644
@@ -189,24 +189,46 @@ struct NvdmPayloadCot {
     gsp_boot_args_sysmem_offset: u64,
 }
 
-/// Complete FSP message structure with MCTP and NVDM headers.
+/// Common MCTP and NVDM headers shared by all FSP messages.
 #[repr(C, packed)]
 #[derive(Clone, Copy)]
-struct FspMessage {
+struct FspMessageHeader {
     mctp_header: u32,
     nvdm_header: u32,
+}
+
+// SAFETY: FspMessageHeader is a packed C struct with only integral fields.
+unsafe impl AsBytes for FspMessageHeader {}
+
+// SAFETY: FspMessageHeader is a packed C struct with only integral fields.
+unsafe impl FromBytes for FspMessageHeader {}
+
+impl FspMessageHeader {
+    /// Construct a standard FSP message header for the given NVDM type.
+    fn new(nvdm_type: NvdmType) -> Self {
+        Self {
+            mctp_header: MctpHeader::single_packet().raw(),
+            nvdm_header: NvdmHeader::new(nvdm_type).raw(),
+        }
+    }
+}
+
+/// Complete FSP COT (Chain of Trust) message structure.
+#[repr(C, packed)]
+#[derive(Clone, Copy)]
+struct FspCotMessage {
+    header: FspMessageHeader,
     cot: NvdmPayloadCot,
 }
 
-// SAFETY: FspMessage is a packed C struct with only integral fields.
-unsafe impl AsBytes for FspMessage {}
+// SAFETY: FspCotMessage is a packed C struct with only integral fields.
+unsafe impl AsBytes for FspCotMessage {}
 
 /// Complete FSP response structure with MCTP and NVDM headers.
 #[repr(C, packed)]
 #[derive(Clone, Copy)]
 struct FspResponse {
-    mctp_header: u32,
-    nvdm_header: u32,
+    header: FspMessageHeader,
     response: NvdmPayloadCommandResponse,
 }
 
@@ -222,7 +244,7 @@ pub(crate) trait MessageToFsp: AsBytes {
     const NVDM_TYPE: u32;
 }
 
-impl MessageToFsp for FspMessage {
+impl MessageToFsp for FspCotMessage {
     const NVDM_TYPE: u32 = NvdmType::Cot as u32;
 }
 
@@ -405,10 +427,8 @@ pub(crate) fn boot_fmc(
         let frts_size: u32 = if !args.resume { SZ_1M as u32 } else { 0 };
 
         let msg = KBox::new(
-            FspMessage {
-                mctp_header: MctpHeader::single_packet().raw(),
-                nvdm_header: NvdmHeader::new(NvdmType::Cot).raw(),
-
+            FspCotMessage {
+                header: FspMessageHeader::new(NvdmType::Cot),
                 cot: NvdmPayloadCot {
                     version: args.chipset.fsp_cot_version().ok_or(ENOTSUPP)?.raw(),
                     size: u16::try_from(core::mem::size_of::<NvdmPayloadCot>())
@@ -469,8 +489,8 @@ fn send_sync_fsp<M>(
 
         let response = FspResponse::from_bytes(&response_buf[..]).ok_or(EIO)?;
 
-        let mctp_header: MctpHeader = response.mctp_header.into();
-        let nvdm_header: NvdmHeader = response.nvdm_header.into();
+        let mctp_header: MctpHeader = response.header.mctp_header.into();
+        let nvdm_header: NvdmHeader = response.header.nvdm_header.into();
         let command_nvdm_type = response.response.command_nvdm_type;
         let error_code = response.response.error_code;
 
Signature · 1 line
2.51.0
author
#3 lore raw

RFC v2 3/10 gpu: nova-core: return FSP response buffer to caller

In reply to Zhi Wang

Change send_sync_fsp() to return the raw response buffer after validating the common MCTP/NVDM headers and error code. This allows callers to perform protocol-specific parsing on the response payload, which is needed for the upcoming PRC protocol support.

For the existing COT caller, the response buffer is unused.

---
 drivers/gpu/nova-core/fsp.rs | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
drivers/gpu/nova-core/fsp.rs +6 -4
index 477ed719b757..69e48b655879 100644
@@ -454,12 +454,13 @@ pub(crate) fn boot_fmc(
     }
 
     /// Send message to FSP and wait for response.
+    /// Returns the raw response buffer for protocol-specific parsing.
     fn send_sync_fsp<M>(
         dev: &device::Device<device::Bound>,
         bar: &crate::driver::Bar0,
         fsp_falcon: &crate::falcon::Falcon<crate::falcon::fsp::Fsp>,
         msg: &M,
-    ) -> Result
+    ) -> Result<KVec<u8>>
     where
         M: MessageToFsp,
     {
@@ -482,12 +483,13 @@ fn send_sync_fsp<M>(
         response_buf.resize(packet_size, 0, GFP_KERNEL)?;
         fsp_falcon.recv_msg(bar, &mut response_buf, packet_size)?;
 
-        if response_buf.len() < core::mem::size_of::<FspResponse>() {
+        let min_size = core::mem::size_of::<FspResponse>();
+        if response_buf.len() < min_size {
             dev_err!(dev, "FSP response too small: {}\n", response_buf.len());
             return Err(EIO);
         }
 
-        let response = FspResponse::from_bytes(&response_buf[..]).ok_or(EIO)?;
+        let response = FspResponse::from_bytes(&response_buf[..min_size]).ok_or(EIO)?;
 
         let mctp_header: MctpHeader = response.header.mctp_header.into();
         let nvdm_header: NvdmHeader = response.header.nvdm_header.into();
@@ -532,6 +534,6 @@ fn send_sync_fsp<M>(
             return Err(EIO);
         }
 
-        Ok(())
+        Ok(response_buf)
     }
 }
Signature · 1 line
2.51.0
author
#4 lore raw

RFC v2 4/10 gpu: nova-core: read vGPU mode from FSP via PRC protocol

In reply to Zhi Wang

Add support for querying the vGPU mode configuration from FSP using the PRC (Product Reconfiguration Control) protocol. PRC is an API system exposed through FSP's Management Partition that allows querying device configuration "knobs" without firmware updates.

Add a VgpuMode enum that validates the raw PRC response value, returning an error for unexpected values.

---
 drivers/gpu/nova-core/fsp.rs  | 175 +++++++++++++++++++++++++++++++---
 drivers/gpu/nova-core/mctp.rs |   2 +
 2 files changed, 165 insertions(+), 12 deletions(-)
drivers/gpu/nova-core/fsp.rs +163 -12
index 69e48b655879..e342bbf733b3 100644
@@ -23,12 +23,18 @@
     },
 };
 
-use crate::regs;
-
-use crate::mctp::{
-    MctpHeader,
-    NvdmHeader,
-    NvdmType, //
+use crate::{
+    driver::Bar0,
+    falcon::{
+        fsp::Fsp as FspEngine,
+        Falcon, //
+    },
+    mctp::{
+        MctpHeader,
+        NvdmHeader,
+        NvdmType, //
+    },
+    regs,
 };
 
 /// FSP Chain of Trust protocol version.
@@ -55,6 +61,23 @@ pub(crate) const fn raw(self) -> u16 {
 /// FSP secure boot completion timeout in milliseconds.
 const FSP_SECURE_BOOT_TIMEOUT_MS: i64 = 4000;
 
+/// PRC (Product Reconfiguration Control) protocol constants.
+///
+/// PRC is an API system exposed through FSP's Management Partition that allows
+/// querying and modifying device configuration "knobs" without firmware updates.
+/// Each knob is identified by a unique object ID and controls a specific device
+/// behavior (e.g., vGPU mode, ECC, confidential computing).
+mod prc {
+    /// Sub-command to read a PRC knob value.
+    pub(super) const SUBCMD_READ: u8 = 0x0c;
+
+    /// PRC object ID for vGPU mode configuration (knob ID 41).
+    pub(super) const OBJECT_VGPU_MODE: u8 = 0x29;
+
+    /// Request the active knob value (currently effective this boot).
+    pub(super) const FLAG_ACTIVE: u8 = 1 << 1;
+}
+
 /// GSP FMC initialization parameters.
 #[repr(C)]
 #[derive(Debug, Clone, Copy, Default)]
@@ -171,7 +194,61 @@ struct NvdmPayloadCommandResponse {
     error_code: u32,
 }
 
-/// NVDM (NVIDIA Device Management) COT (Chain of Trust) payload structure.
+// SAFETY: NvdmPayloadCommandResponse is a packed C struct with only integral fields.
+unsafe impl FromBytes for NvdmPayloadCommandResponse {}
+
+/// vGPU operating mode as reported by FSP via the PRC protocol.
+#[derive(Debug, Clone, Copy, PartialEq, Eq)]
+pub(crate) enum VgpuMode {
+    /// vGPU support is disabled on this GPU.
+    Disabled = 0,
+    /// vGPU support is enabled on this GPU.
+    Enabled = 1,
+}
+
+impl TryFrom<u16> for VgpuMode {
+    type Error = kernel::error::Error;
+
+    fn try_from(value: u16) -> Result<Self> {
+        match value {
+            0 => Ok(VgpuMode::Disabled),
+            1 => Ok(VgpuMode::Enabled),
+            _ => Err(EINVAL),
+        }
+    }
+}
+
+/// PRC message payload.
+///
+/// Sent to FSP to query or modify a device configuration knob.
+/// The response includes the common FSP response header followed by
+/// a [`NvdmPayloadPrcResponse`] with the knob's current state value.
+#[repr(C, packed)]
+#[derive(Clone, Copy)]
+struct NvdmPayloadPrc {
+    sub_message_id: u8,
+    flags: u8,
+    object_id: u8,
+    reserved: u8,
+}
+
+// SAFETY: NvdmPayloadPrc is a packed C struct with only integral fields.
+unsafe impl AsBytes for NvdmPayloadPrc {}
+
+/// PRC response payload containing the knob state value.
+#[repr(C, packed)]
+#[derive(Clone, Copy)]
+struct NvdmPayloadPrcResponse {
+    value_low: u8,
+    value_high: u8,
+    reserved1: u8,
+    reserved2: u8,
+}
+
+// SAFETY: NvdmPayloadPrcResponse is a packed C struct with only integral fields.
+unsafe impl FromBytes for NvdmPayloadPrcResponse {}
+
+/// NVDM (NVIDIA Vendor Defined Message) COT (Chain of Trust) payload structure.
 /// This is the main message payload sent to FSP for Chain of Trust.
 #[repr(C, packed)]
 #[derive(Clone, Copy)]
@@ -224,6 +301,17 @@ struct FspCotMessage {
 // SAFETY: FspCotMessage is a packed C struct with only integral fields.
 unsafe impl AsBytes for FspCotMessage {}
 
+/// Complete FSP PRC message.
+#[repr(C, packed)]
+#[derive(Clone, Copy)]
+struct FspPrcMessage {
+    header: FspMessageHeader,
+    prc: NvdmPayloadPrc,
+}
+
+// SAFETY: FspPrcMessage is a packed C struct with only integral fields.
+unsafe impl AsBytes for FspPrcMessage {}
+
 /// Complete FSP response structure with MCTP and NVDM headers.
 #[repr(C, packed)]
 #[derive(Clone, Copy)]
@@ -235,6 +323,18 @@ struct FspResponse {
 // SAFETY: FspResponse is a packed C struct with only integral fields.
 unsafe impl FromBytes for FspResponse {}
 
+/// Complete FSP PRC response including the knob state payload.
+#[repr(C, packed)]
+#[derive(Clone, Copy)]
+struct FspPrcResponse {
+    header: FspMessageHeader,
+    response: NvdmPayloadCommandResponse,
+    prc_data: NvdmPayloadPrcResponse,
+}
+
+// SAFETY: FspPrcResponse is a packed C struct with only integral fields.
+unsafe impl FromBytes for FspPrcResponse {}
+
 /// Trait implemented by types representing a message to send to FSP.
 ///
 /// This provides [`Fsp::send_sync_fsp`] with the information it needs to send
@@ -305,17 +405,68 @@ pub(crate) fn boot_params_dma_handle(&self) -> u64 {
     }
 }
 
+impl MessageToFsp for FspPrcMessage {
+    const NVDM_TYPE: u32 = NvdmType::Prc as u32;
+}
+
 /// FSP interface for Hopper/Blackwell GPUs.
 pub(crate) struct Fsp;
 
 impl Fsp {
+    /// Read vGPU mode from FSP using the PRC protocol.
+    ///
+    /// Queries FSP's Management Partition for the active vGPU mode knob value.
+    /// Returns [`VgpuMode::Enabled`] if vGPU support is active on this GPU,
+    /// [`VgpuMode::Disabled`] otherwise.
+    pub(crate) fn read_vgpu_mode(
+        dev: &device::Device<device::Bound>,
+        bar: &Bar0,
+        fsp_falcon: &Falcon<FspEngine>,
+    ) -> Result<VgpuMode> {
+        let msg = KBox::new(
+            FspPrcMessage {
+                header: FspMessageHeader::new(NvdmType::Prc),
+                prc: NvdmPayloadPrc {
+                    sub_message_id: prc::SUBCMD_READ,
+                    flags: prc::FLAG_ACTIVE,
+                    object_id: prc::OBJECT_VGPU_MODE,
+                    reserved: 0,
+                },
+            },
+            GFP_KERNEL,
+        )?;
+
+        let response_buf = Self::send_sync_fsp(dev, bar, fsp_falcon, &*msg)?;
+
+        let prc_resp_size = core::mem::size_of::<FspPrcResponse>();
+        if response_buf.len() < prc_resp_size {
+            dev_err!(
+                dev,
+                "PRC response too small: {} bytes (expected {})\n",
+                response_buf.len(),
+                prc_resp_size
+            );
+            return Err(EIO);
+        }
+
+        let prc_response =
+            FspPrcResponse::from_bytes(&response_buf[..prc_resp_size]).ok_or(EIO)?;
+
+        let raw_value = u16::from(prc_response.prc_data.value_low)
+            | (u16::from(prc_response.prc_data.value_high) << 8);
+
+        VgpuMode::try_from(raw_value).inspect_err(|_| {
+            dev_err!(dev, "unexpected vGPU mode value: {:#x}\n", raw_value);
+        })
+    }
+
     /// Wait for FSP secure boot completion.
     ///
     /// Polls the thermal scratch register until FSP signals boot completion
     /// or timeout occurs.
     pub(crate) fn wait_secure_boot(
         dev: &device::Device<device::Bound>,
-        bar: &crate::driver::Bar0,
+        bar: &Bar0,
         arch: crate::gpu::Architecture,
     ) -> Result {
         debug_assert!(
@@ -403,8 +554,8 @@ pub(crate) fn extract_fmc_signatures(
     /// to FSP, and waits for the response.
     pub(crate) fn boot_fmc(
         dev: &device::Device<device::Bound>,
-        bar: &crate::driver::Bar0,
-        fsp_falcon: &crate::falcon::Falcon<crate::falcon::fsp::Fsp>,
+        bar: &Bar0,
+        fsp_falcon: &Falcon<FspEngine>,
         args: &FmcBootArgs<'_>,
     ) -> Result {
         dev_dbg!(dev, "Starting FSP boot sequence for {}\n", args.chipset);
@@ -457,8 +608,8 @@ pub(crate) fn boot_fmc(
     /// Returns the raw response buffer for protocol-specific parsing.
     fn send_sync_fsp<M>(
         dev: &device::Device<device::Bound>,
-        bar: &crate::driver::Bar0,
-        fsp_falcon: &crate::falcon::Falcon<crate::falcon::fsp::Fsp>,
+        bar: &Bar0,
+        fsp_falcon: &Falcon<FspEngine>,
         msg: &M,
     ) -> Result<KVec<u8>>
     where
drivers/gpu/nova-core/mctp.rs +2 -0
index c4e36a46fd69..5c53e156d482 100644
@@ -10,6 +10,8 @@
 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
 #[repr(u32)]
 pub(crate) enum NvdmType {
+    /// PRC (Product Reconfiguration Control) message.
+    Prc = 0x13,
     /// Chain of Trust boot message.
     Cot = 0x14,
     /// FSP command response.
Signature · 1 line
2.51.0
author
#5 lore raw

RFC v2 5/10 gpu: nova-core: add FSP and PRC protocol documentation

In reply to Zhi Wang

Add documentation for the Falcon Security Processor (FSP) interface covering the simplified Hopper/Blackwell boot flow, the Chain of Trust (COT) message protocol, the MCTP/NVDM message format, and the Product Reconfiguration Control (PRC) protocol used to query device configuration knobs such as vGPU mode.

---
 Documentation/gpu/nova/core/fsp.rst | 135 ++++++++++++++++++++++++++++
 Documentation/gpu/nova/index.rst    |   1 +
 2 files changed, 136 insertions(+)
 create mode 100644 Documentation/gpu/nova/core/fsp.rst
Documentation/gpu/nova/core/fsp.rst new file +135 -0
new file mode 100644
index 000000000000..dedad680b20e
@@ -0,0 +1,135 @@
+.. SPDX-License-Identifier: GPL-2.0
+
+===============================================
+FSP (Falcon Security Processor) and Secure Boot
+===============================================
+This document describes the role of the FSP in the GPU boot sequence on
+Hopper and Blackwell GPUs, It also provides a brief overview of the PRC
+(Product Reconfiguration Control) protocol used to query device
+configuration through FSP.
+
+What is FSP?
+============
+The Falcon Security Processor (FSP) is the GPU's Internal Root of Trust
+(IROT). It is a dedicated security processor that boots from immutable ROM
+(Boot ROM) inside the GPU and is responsible for establishing the Chain of
+Trust before any other firmware is allowed to run.
+
+FSP runs independently of the host CPU and starts executing as soon as the
+GPU is powered on. By the time the nova-core driver is loaded, FSP has
+already completed its own secure boot and is ready to accept commands from
+the driver.
+
+Simplified boot flow (Hopper/Blackwell)
+=======================================
+Starting with Hopper, the boot flow is significantly simplified compared to
+earlier GPU generations like Ampere.
+
+On an Ampere GPU, the boot verification chain involves multiple Falcon
+engines and multiple ucode stages (see falcon.rst for details)::
+
+     Hardware BROM (SEC2)
+          -> HS Booter (SEC2)
+               -> LS GSP-RM (GSP)
+
+The driver must extract ucode from VBIOS, manage SEC2 and GSP, and
+orchestrate the Booter to load GSP-RM. This involves FWSEC-FRTS, devinit,
+and the Booter stages.
+
+On Hopper/Blackwell GPUs, FSP replaces this multi-stage process with a
+single message-driven interface::
+
+     FSP (hardware root of trust, boots from ROM)
+          -> FMC (Falcon Microcontroller, verified by FSP)
+               -> GSP-RM (verified and loaded by FMC)
+
+The driver only needs to:
+
+1. Wait for FSP to complete its own secure boot (polling a scratch register).
+2. Send a Chain of Trust (COT) message to FSP with the FMC firmware location,
+   cryptographic signatures, and GSP boot parameters.
+3. FSP authenticates the FMC firmware and boots it, FMC in turn loads GSP-RM.
+
+There is no SEC2 involvement, no Booter ucode, and no FWSEC-FRTS stage. The
+entire secure boot is driven by a single FSP message exchange.
+
+Chain of Trust (COT) protocol
+=============================
+The Chain of Trust establishes a cryptographically enforced boot sequence,
+ensuring the GPU reaches a known, trusted state.
+
+The driver communicates with FSP using a message queue (Falcon MSGQ
+interface). Each message consists of an MCTP (Management Component Transport
+Protocol) transport header and an NVDM (NVIDIA Vendor Defined Message) header,
+followed by a protocol-specific payload.
+
+For Chain of Trust, the payload includes:
+
+- The system memory address of the FMC firmware image.
+- Cryptographic material: a SHA-384 hash, RSA-3K public key, and RSA-3K
+  signature extracted from the FMC ELF firmware.
+- FRTS (Firmware Runtime Services) region information (vidmem offset and size).
+- The system memory address of the GSP boot arguments structure.
+
+FSP verifies the signature against the provided public key and hash, and if
+verification succeeds, boots the FMC. The FMC then authenticates and launches
+GSP-RM.
+
+The message flow is::
+
+     nova-core                          FSP
+        |                                |
+        |  1. Poll scratch register      |
+        |  (wait for FSP boot complete)  |
+        |                                |
+        |  2. COT message  ------------> |
+        |     (FMC addr, signatures,     |
+        |      boot params)              |
+        |                                |
+        |                                |--- Verify FMC signature
+        |                                |--- Boot FMC
+        |                                |--- FMC loads GSP-RM
+        |                                |
+        |  3. COT response <------------ |
+        |     (success/error)            |
+        |                                |
+
+FSP message format
+==================
+All FSP messages share a common header format consisting of two 32-bit words:
+
+MCTP header (Management Component Transport Protocol):
+
+- Bit 31: SOM (Start of Message)
+- Bit 30: EOM (End of Message)
+- Bits 29:28: Packet sequence number
+- Bits 23:16: Source Endpoint ID
+
+NVDM header (NVIDIA Vendor Defined Message):
+
+- Bits 6:0: MCTP message type (0x7e = vendor-defined PCI)
+- Bits 23:8: PCI vendor ID (0x10de = NVIDIA)
+- Bits 31:24: NVDM type (0x14 = COT, 0x13 = PRC, 0x15 = FSP response)
+
+PRC (Product Reconfiguration Control) protocol
+===============================================
+PRC is an API system exposed through FSP's Management Partition that allows
+querying and modifying device configuration without firmware updates.
+
+Configuration parameters are called "knobs". Each knob has a unique object
+ID and controls a specific device behavior. Examples include vGPU mode, ECC
+enable, confidential computing mode, and NVLINK configuration.
+
+The nova-core driver uses PRC to read the vGPU mode knob (object ID 0x29)
+during early boot, before firmware loading, to determine whether the GPU
+should operate in vGPU mode.
+
+The PRC message format follows the same MCTP/NVDM header structure as COT,
+with NVDM type 0x13. The payload contains:
+
+- A sub-command (e.g., 0x0c for read).
+- Flags indicating which value to read (bit 0 = persistent, bit 1 = active).
+- The knob object ID.
+
+The response includes the common FSP response header (with error status)
+followed by the knob's 16-bit state value.
Documentation/gpu/nova/index.rst +1 -0
index e39cb3163581..1783513cbd05 100644
@@ -30,5 +30,6 @@ vGPU manager VFIO driver and the nova-drm driver.
    core/todo
    core/vbios
    core/devinit
+   core/fsp
    core/fwsec
    core/falcon
Signature · 1 line
2.51.0
author
#6 lore raw

RFC v2 6/10 gpu: nova-core: introduce vgpu_support module param

In reply to Zhi Wang

Introduce a kernel module param to set vGPU support in nova-core.

vgpu_support = 1 (default): automatic

The driver automatically enables or disables vGPU support based on if the GPU advertises SRIOV caps.

vgpu_support = 0: disabled

Explicitly disables vGPU support. The driver will not enable vGPU support regardless.

---
 drivers/gpu/nova-core/gpu.rs       | 37 +++++++++++++++++--
 drivers/gpu/nova-core/gsp.rs       | 25 +++++++++++++
 drivers/gpu/nova-core/gsp/boot.rs  | 59 +++++++++++++++++-------------
 drivers/gpu/nova-core/nova_core.rs | 15 ++++++++
 drivers/gpu/nova-core/vgpu.rs      | 37 +++++++++++++++++++
 5 files changed, 143 insertions(+), 30 deletions(-)
 create mode 100644 drivers/gpu/nova-core/vgpu.rs
drivers/gpu/nova-core/gpu.rs +33 -4
index e9d07750fafe..e1c16e1b9ec4 100644
@@ -23,8 +23,12 @@
     fb::SysmemFlush,
     fsp::FspCotVersion,
     gfw,
-    gsp::Gsp,
+    gsp::{
+        Gsp,
+        GspBootContext, //
+    },
     regs,
+    vgpu::Vgpu, //
 };
 
 macro_rules! define_chipset {
@@ -180,6 +184,16 @@ pub(crate) enum Architecture {
 }
 
 impl Architecture {
+    /// Whether this architecture uses SEC2 for GSP boot (vs FSP Chain of Trust).
+    pub(crate) const fn uses_sec2_boot(&self) -> bool {
+        matches!(self, Self::Turing | Self::Ampere | Self::Ada)
+    }
+
+    /// Whether this architecture supports vGPU.
+    pub(crate) const fn supports_vgpu(&self) -> bool {
+        matches!(self, Self::Ada | Self::Blackwell)
+    }
+
     /// Returns the DMA mask supported by this architecture.
     ///
     /// Hopper and Blackwell support 52-bit DMA addresses, while earlier architectures
@@ -313,7 +327,7 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
 pub(crate) struct Gpu {
     spec: Spec,
     /// MMIO mapping of PCI BAR 0
-    bar: Arc<Devres<Bar0>>,
+    pub bar: Arc<Devres<Bar0>>,
     /// System memory page required for flushing all pending GPU-side memory writes done through
     /// PCIE into system memory, via sysmembar (A GPU-initiated HW memory-barrier operation).
     sysmem_flush: SysmemFlush,
@@ -323,7 +337,8 @@ pub(crate) struct Gpu {
     sec2_falcon: Falcon<Sec2Falcon>,
     /// GSP runtime data. Temporarily an empty placeholder.
     #[pin]
-    gsp: Gsp,
+    pub(crate) gsp: Gsp,
+    vgpu: Vgpu,
 }
 
 impl Gpu {
@@ -351,6 +366,8 @@ pub(crate) fn new<'a>(
                     }
                 },
 
+                vgpu: Vgpu::new(pdev, chipset)?,
+
                 sysmem_flush: SysmemFlush::register(pdev.as_ref(), bar, chipset)?,
 
                 gsp_falcon: Falcon::new(
@@ -363,7 +380,19 @@ pub(crate) fn new<'a>(
 
                 gsp <- Gsp::new(pdev),
 
-                _: { gsp.boot(pdev, bar, chipset, gsp_falcon, sec2_falcon)? },
+                _: {
+                    let mut ctx = GspBootContext {
+                        pdev,
+                        bar,
+                        chipset,
+                        gsp_falcon,
+                        sec2_falcon,
+                        fsp_falcon: None,
+                        vgpu_requested: vgpu.vgpu_requested,
+                    };
+                    gsp.boot(&mut ctx)?;
+                    vgpu.vgpu_enabled = ctx.vgpu_requested;
+                },
 
                 bar: devres_bar,
                 spec,
drivers/gpu/nova-core/gsp.rs +25 -0
index 1756ab4732e7..9435c7430dfe 100644
@@ -31,6 +31,14 @@
 };
 
 use crate::{
+    driver::Bar0,
+    falcon::{
+        fsp::Fsp as FspFalcon,
+        gsp::Gsp as GspFalcon,
+        sec2::Sec2 as Sec2Falcon,
+        Falcon, //
+    },
+    gpu::Chipset,
     gsp::cmdq::Cmdq,
     gsp::fw::{
         GspArgumentsPadded,
@@ -45,6 +53,23 @@
 /// Number of GSP pages to use in a RM log buffer.
 const RM_LOG_BUFFER_NUM_PAGES: usize = 0x10;
 
+/// Common context for the GSP boot process.
+pub(crate) struct GspBootContext<'a> {
+    pub(crate) pdev: &'a pci::Device<device::Bound>,
+    pub(crate) bar: &'a Bar0,
+    pub(crate) chipset: Chipset,
+    pub(crate) gsp_falcon: &'a Falcon<GspFalcon>,
+    pub(crate) sec2_falcon: &'a Falcon<Sec2Falcon>,
+    pub(crate) fsp_falcon: Option<Falcon<FspFalcon>>,
+    pub(crate) vgpu_requested: bool,
+}
+
+impl GspBootContext<'_> {
+    pub(crate) fn dev(&self) -> &device::Device<device::Bound> {
+        self.pdev.as_ref()
+    }
+}
+
 /// Array of page table entries, as understood by the GSP bootloader.
 #[repr(C)]
 struct PteArray<const NUM_ENTRIES: usize>([u64; NUM_ENTRIES]);
drivers/gpu/nova-core/gsp/boot.rs +33 -26

123 lines not on this page · raw message

drivers/gpu/nova-core/nova_core.rs +15 -0
index c554ec544ddd..bccdbb412dd0 100644
@@ -27,6 +27,7 @@
 mod regs;
 mod sbuffer;
 mod vbios;
+mod vgpu;
 
 pub(crate) const MODULE_NAME: &core::ffi::CStr = <LocalModule as kernel::ModuleMetadata>::NAME;
 
@@ -75,6 +76,20 @@ fn init(module: &'static kernel::ThisModule) -> impl PinInit<Self, Error> {
     description: "Nova Core GPU driver",
     license: "GPL v2",
     firmware: [],
+    params: {
+        // vgpu_support = 1 (default): automatic
+        //
+        // The driver automatically enables or disables vGPU support based on if the GPU
+        // advertises SRIOV caps.
+        //
+        // vgpu_support = 0: disabled
+        //
+        // Explicitly disables vGPU support. The driver will not enable vGPU support regardless.
+        vgpu_support: u32 {
+            default: 1,
+            description: "Enable vGPU support - (1 = auto (default), 0 = disable)",
+        },
+    },
 }
 
 kernel::module_firmware!(firmware::ModInfoBuilder);
drivers/gpu/nova-core/vgpu.rs new file +37 -0
new file mode 100644
index 000000000000..d35081a088cf
@@ -0,0 +1,37 @@
+// SPDX-License-Identifier: GPL-2.0
+
+use kernel::{
+    device,
+    pci,
+    prelude::*, //
+};
+
+use crate::{
+    gpu::Chipset,
+    module_parameters, //
+};
+
+pub(crate) struct Vgpu {
+    pub(crate) vgpu_requested: bool,
+    pub(crate) vgpu_enabled: bool,
+    pub total_vfs: u16,
+}
+
+impl Vgpu {
+    pub(crate) fn new(pdev: &pci::Device<device::Bound>, chipset: Chipset) -> Result<Vgpu> {
+        let total_vfs = if chipset.arch().supports_vgpu() {
+            match *module_parameters::vgpu_support.value() {
+                0 => 0,
+                _ => pdev.sriov_get_totalvfs().unwrap_or(0),
+            }
+        } else {
+            0
+        };
+
+        Ok(Vgpu {
+            vgpu_requested: total_vfs > 0,
+            vgpu_enabled: false,
+            total_vfs,
+        })
+    }
+}
Signature · 1 line
2.51.0
author
#7 lore raw

RFC v2 7/10 gpu: nova-core: populate GSP_VF_INFO when vGPU is enabled

In reply to Zhi Wang

GSP firmware needs to know the VF BAR offsets to correctly calculate the VF events.

The VF BAR information is stored in GSP_VF_INFO, which needs to be initialized and uploaded together with the GSP_SYSTEM_INFO.

Populate GSP_VF_INFO when nova-core uploads the GSP_SYSTEM_INFO if NVIDIA vGPU is enabled.

Cc Joel Fernandes <[email protected]>
Cc John Hubbard <[email protected]>
Cc Alexandre Courbot <[email protected]>
---
 drivers/gpu/nova-core/gsp/boot.rs        | 15 ++++++++--
 drivers/gpu/nova-core/gsp/commands.rs    | 16 ++++++++--
 drivers/gpu/nova-core/gsp/fw.rs          | 38 ++++++++++++++++++++++++
 drivers/gpu/nova-core/gsp/fw/commands.rs | 12 +++++++-
 4 files changed, 74 insertions(+), 7 deletions(-)
drivers/gpu/nova-core/gsp/boot.rs +12 -3
index 4238df5c8104..921d5e892f8a 100644
@@ -41,7 +41,10 @@
     gpu::Chipset,
     gsp::{
         commands,
-        fw::LibosMemoryRegionInitArgument,
+        fw::{
+            GspVfInfo,
+            LibosMemoryRegionInitArgument, //
+        },
         sequencer::{
             GspSequencer,
             GspSequencerParams, //
@@ -349,11 +352,17 @@ pub(crate) fn boot(
         let wpr_meta = Coherent::<GspFwWprMeta>::zeroed(dev, GFP_KERNEL)?;
         io_write!(wpr_meta, , GspFwWprMeta::new(&gsp_fw, &fb_layout));
 
+        let vf_info = if ctx.vgpu_requested {
+            Some(GspVfInfo::new(ctx.pdev)?)
+        } else {
+            None
+        };
+
         // Architecture-specific boot path
         if arch.uses_sec2_boot() {
             // SEC2 path: send commands before GSP reset/boot (original order).
             self.cmdq
-                .send_command_no_wait(bar, commands::SetSystemInfo::new(pdev, chipset))?;
+                .send_command_no_wait(bar, commands::SetSystemInfo::new(pdev, chipset, vf_info))?;
             self.cmdq
                 .send_command_no_wait(bar, commands::SetRegistry::new())?;
 
@@ -395,7 +404,7 @@ pub(crate) fn boot(
         // For FSP path, send commands after GSP becomes active.
         if !arch.uses_sec2_boot() {
             self.cmdq
-                .send_command_no_wait(bar, commands::SetSystemInfo::new(pdev, chipset))?;
+                .send_command_no_wait(bar, commands::SetSystemInfo::new(pdev, chipset, vf_info))?;
             self.cmdq
                 .send_command_no_wait(bar, commands::SetRegistry::new())?;
         }
drivers/gpu/nova-core/gsp/commands.rs +13 -3
index d31ee782ff8b..0445d05990e7 100644
@@ -29,6 +29,7 @@
         },
         fw::{
             commands::*,
+            GspVfInfo,
             MsgFunction, //
         },
     },
@@ -39,12 +40,21 @@
 pub(crate) struct SetSystemInfo<'a> {
     pdev: &'a pci::Device<device::Bound>,
     chipset: Chipset,
+    vf_info: Option<GspVfInfo>,
 }
 
 impl<'a> SetSystemInfo<'a> {
     /// Creates a new `GspSetSystemInfo` command using the parameters of `pdev`.
-    pub(crate) fn new(pdev: &'a pci::Device<device::Bound>, chipset: Chipset) -> Self {
-        Self { pdev, chipset }
+    pub(crate) fn new(
+        pdev: &'a pci::Device<device::Bound>,
+        chipset: Chipset,
+        vf_info: Option<GspVfInfo>,
+    ) -> Self {
+        Self {
+            pdev,
+            chipset,
+            vf_info,
+        }
     }
 }
 
@@ -55,7 +65,7 @@ impl<'a> CommandToGsp for SetSystemInfo<'a> {
     type InitError = Error;
 
     fn init(&self) -> impl Init<Self::Command, Self::InitError> {
-        GspSetSystemInfo::init(self.pdev, self.chipset)
+        GspSetSystemInfo::init(self.pdev, self.chipset, self.vf_info)
     }
 }
 
drivers/gpu/nova-core/gsp/fw.rs +38 -0
index e5f8db74a677..6d56b9b920fb 100644
@@ -10,7 +10,9 @@
 use core::ops::Range;
 
 use kernel::{
+    device,
     dma::Coherent,
+    pci,
     prelude::*,
     ptr::{
         Alignable,
@@ -1309,3 +1311,39 @@ fn new(cmdq: &Cmdq) -> Self {
         })
     }
 }
+
+/// VF information — `gspVFInfo` in `GspSetSystemInfo`.
+///
+/// Populated from the PCI SR-IOV extended capability when vGPU support
+/// is enabled.
+#[derive(Clone, Copy, Zeroable)]
+#[repr(transparent)]
+pub(crate) struct GspVfInfo(pub(crate) bindings::GSP_VF_INFO);
+
+impl GspVfInfo {
+    /// Reads SR-IOV capability data from the PCI extended configuration
+    /// space and builds the VF information required by GSP firmware.
+    pub(crate) fn new(pdev: &pci::Device<device::Bound>) -> Result<GspVfInfo> {
+        let total_vfs = pdev.sriov_get_totalvfs()?;
+
+        let cfg = pdev.config_space_extended()?;
+        let sriov = pci::ExtSriovCapability::find(&cfg)?;
+
+        Ok(GspVfInfo(bindings::GSP_VF_INFO {
+            totalVFs: u32::from(total_vfs),
+            firstVFOffset: u32::from(kernel::io_read!(sriov, .vf_offset)),
+            FirstVFBar0Address: u64::from(kernel::io_read!(sriov, .vf_bar[0]?)),
+            b64bitBar1: u8::from(sriov.vf_bar_is_64bit(1)?),
+            FirstVFBar1Address: sriov.read_vf_bar64_addr(1)?,
+            b64bitBar2: u8::from(sriov.vf_bar_is_64bit(3)?),
+            FirstVFBar2Address: sriov.read_vf_bar64_addr(3)?,
+            ..Zeroable::zeroed()
+        }))
+    }
+}
+
+// SAFETY: Padding is explicit and does not contain uninitialized data.
+unsafe impl AsBytes for GspVfInfo {}
+
+// SAFETY: This struct only contains integer types for which all bit patterns are valid.
+unsafe impl FromBytes for GspVfInfo {}
drivers/gpu/nova-core/gsp/fw/commands.rs +11 -1
index c9822fcbc499..3edd451e531b 100644
@@ -15,7 +15,10 @@
         Architecture,
         Chipset, //
     },
-    gsp::GSP_PAGE_SIZE, //
+    gsp::{
+        fw::GspVfInfo,
+        GSP_PAGE_SIZE, //
+    },
 };
 
 use super::bindings;
@@ -33,6 +36,7 @@ impl GspSetSystemInfo {
     pub(crate) fn init<'a>(
         dev: &'a pci::Device<device::Bound>,
         chipset: Chipset,
+        vf_info: Option<GspVfInfo>,
     ) -> impl Init<Self, Error> + 'a {
         type InnerGspSystemInfo = bindings::GspSystemInfo;
         let init_inner = try_init!(InnerGspSystemInfo {
@@ -57,6 +61,12 @@ pub(crate) fn init<'a>(
             bIsPrimary: 0,
             bPreserveVideoMemoryAllocations: 0,
             ..Zeroable::init_zeroed()
+        })
+        .chain(move |si| {
+            if let Some(vf) = vf_info {
+                si.gspVFInfo = vf.0;
+            }
+            Ok(())
         });
 
         try_init!(GspSetSystemInfo {
Signature · 1 line
2.51.0
author
#8 lore raw

RFC v2 8/10 gpu: nova-core: set RMSetSriovMode when NVIDIA vGPU is enabled

In reply to Zhi Wang

The registry object "RMSetSriovMode" is required to be set when vGPU is enabled.

Set "RMSetSriovMode" to 1 when nova-core is loading the GSP firmware and initialize the GSP registry objects, if vGPU is enabled.

Cc Timur Tabi <[email protected]>
Cc Joel Fernandes <[email protected]>
Cc Alexandre Courbot <[email protected]>
---
 drivers/gpu/nova-core/gsp/boot.rs     |  4 +-
 drivers/gpu/nova-core/gsp/commands.rs | 89 +++++++++++++++++----------
 drivers/gpu/nova-core/gsp/fw.rs       | 44 +++++++++++++
 3 files changed, 104 insertions(+), 33 deletions(-)
drivers/gpu/nova-core/gsp/boot.rs +2 -2
index 921d5e892f8a..ed8729041d46 100644
@@ -364,7 +364,7 @@ pub(crate) fn boot(
             self.cmdq
                 .send_command_no_wait(bar, commands::SetSystemInfo::new(pdev, chipset, vf_info))?;
             self.cmdq
-                .send_command_no_wait(bar, commands::SetRegistry::new())?;
+                .send_command_no_wait(bar, commands::SetRegistry::new(ctx.vgpu_requested)?)?;
 
             Self::boot_via_sec2(
                 dev,
@@ -406,7 +406,7 @@ pub(crate) fn boot(
             self.cmdq
                 .send_command_no_wait(bar, commands::SetSystemInfo::new(pdev, chipset, vf_info))?;
             self.cmdq
-                .send_command_no_wait(bar, commands::SetRegistry::new())?;
+                .send_command_no_wait(bar, commands::SetRegistry::new(ctx.vgpu_requested)?)?;
         }
 
         // SEC2-based architectures need to run the GSP sequencer
drivers/gpu/nova-core/gsp/commands.rs +58 -31

124 lines not on this page · raw message

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

59 lines not on this page · raw message

Signature · 1 line
2.51.0
author
#9 lore raw

RFC v2 9/10 gpu: nova-core: reserve a larger GSP WPR2 heap when vGPU is enabled

In reply to Zhi Wang

To support the maximum vGPUs on devices that support vGPU, a larger WPR2 heap size is required. On Ada with vGPU supported, the size should be set to at least 581MB.

When vGPU support is enabled:
- Reserve a larger WPR2 heap size of 581MB.
- Set vf_partition_count to MAX_PARTITIONS_WITH_GFID_32VM (32) to support the maximum number of virtual functions in the WPR2 meta, or MAX_PARTITIONS_WITH_GFID (48) when total VFs exceeds 32.

When vGPU support is not enabled, the original heap size calculation and partition count of 0 are preserved.

Cc Alexandre Courbot <[email protected]>
---
 drivers/gpu/nova-core/fb.rs                   | 21 +++++++++++++++----
 drivers/gpu/nova-core/gpu.rs                  | 13 +++++++++++-
 drivers/gpu/nova-core/gsp.rs                  |  7 ++++++-
 drivers/gpu/nova-core/gsp/boot.rs             |  2 +-
 drivers/gpu/nova-core/gsp/fw.rs               |  6 ++++++
 .../gpu/nova-core/gsp/fw/r570_144/bindings.rs |  4 ++++
 drivers/gpu/nova-core/vgpu.rs                 |  2 +-
 7 files changed, 47 insertions(+), 8 deletions(-)
drivers/gpu/nova-core/fb.rs +17 -4
index 1a84a15581a4..2228b6b08699 100644
@@ -181,7 +181,15 @@ pub(crate) struct FbLayout {
 
 impl FbLayout {
     /// Computes the FB layout for `chipset` required to run the `gsp_fw` GSP firmware.
-    pub(crate) fn new(chipset: Chipset, bar: &Bar0, gsp_fw: &GspFirmware) -> Result<Self> {
+    ///
+    /// When `vf_partition_count` is non-zero, a larger WPR2 heap is reserved to support
+    /// vGPU virtual functions: 1370 MiB for 48 partitions, 581 MiB for 32 or fewer.
+    pub(crate) fn new(
+        chipset: Chipset,
+        bar: &Bar0,
+        gsp_fw: &GspFirmware,
+        vf_partition_count: u8,
+    ) -> Result<Self> {
         let hal = hal::fb_hal(chipset);
 
         let fb = {
@@ -243,8 +251,13 @@ pub(crate) fn new(chipset: Chipset, bar: &Bar0, gsp_fw: &GspFirmware) -> Result<
 
         let wpr2_heap = {
             const WPR2_HEAP_DOWN_ALIGN: Alignment = Alignment::new::<SZ_1M>();
-            let wpr2_heap_size =
-                gsp::LibosParams::from_chipset(chipset).wpr_heap_size(chipset, fb.end)?;
+            let wpr2_heap_size = if vf_partition_count == 0 {
+                gsp::LibosParams::from_chipset(chipset).wpr_heap_size(chipset, fb.end)?
+            } else if vf_partition_count > gsp::MAX_PARTITIONS_WITH_GFID_32VM {
+                gsp::GSP_FW_HEAP_SIZE_VGPU_48VMS
+            } else {
+                gsp::GSP_FW_HEAP_SIZE_VGPU_DEFAULT
+            };
             let wpr2_heap_addr = (elf.start - wpr2_heap_size).align_down(WPR2_HEAP_DOWN_ALIGN);
 
             FbRange(wpr2_heap_addr..(elf.start).align_down(WPR2_HEAP_DOWN_ALIGN))
@@ -272,7 +285,7 @@ pub(crate) fn new(chipset: Chipset, bar: &Bar0, gsp_fw: &GspFirmware) -> Result<
             wpr2_heap,
             wpr2,
             heap,
-            vf_partition_count: 0,
+            vf_partition_count,
         })
     }
 }
drivers/gpu/nova-core/gpu.rs +12 -1
index e1c16e1b9ec4..e254ddca0fa4 100644
@@ -25,7 +25,9 @@
     gfw,
     gsp::{
         Gsp,
-        GspBootContext, //
+        GspBootContext,
+        MAX_PARTITIONS_WITH_GFID,
+        MAX_PARTITIONS_WITH_GFID_32VM, //
     },
     regs,
     vgpu::Vgpu, //
@@ -389,6 +391,15 @@ pub(crate) fn new<'a>(
                         sec2_falcon,
                         fsp_falcon: None,
                         vgpu_requested: vgpu.vgpu_requested,
+                        vf_partition_count: if vgpu.vgpu_requested {
+                            if vgpu.total_vfs > u16::from(MAX_PARTITIONS_WITH_GFID_32VM) {
+                                MAX_PARTITIONS_WITH_GFID
+                            } else {
+                                MAX_PARTITIONS_WITH_GFID_32VM
+                            }
+                        } else {
+                            0
+                        },
                     };
                     gsp.boot(&mut ctx)?;
                     vgpu.vgpu_enabled = ctx.vgpu_requested;
drivers/gpu/nova-core/gsp.rs +6 -1
index 9435c7430dfe..528f37e581c7 100644
@@ -26,8 +26,12 @@
 mod sequencer;
 
 pub(crate) use fw::{
+    GSP_FW_HEAP_SIZE_VGPU_48VMS,
+    GSP_FW_HEAP_SIZE_VGPU_DEFAULT,
     GspFwWprMeta,
-    LibosParams, //
+    LibosParams,
+    MAX_PARTITIONS_WITH_GFID,
+    MAX_PARTITIONS_WITH_GFID_32VM, //
 };
 
 use crate::{
@@ -62,6 +66,7 @@ pub(crate) struct GspBootContext<'a> {
     pub(crate) sec2_falcon: &'a Falcon<Sec2Falcon>,
     pub(crate) fsp_falcon: Option<Falcon<FspFalcon>>,
     pub(crate) vgpu_requested: bool,
+    pub(crate) vf_partition_count: u8,
 }
 
 impl GspBootContext<'_> {
drivers/gpu/nova-core/gsp/boot.rs +1 -1
index ed8729041d46..86b7a7aa8f5a 100644
@@ -346,7 +346,7 @@ pub(crate) fn boot(
         let dev = ctx.dev();
         let gsp_fw = KBox::pin_init(GspFirmware::new(dev, chipset, FIRMWARE_VERSION), GFP_KERNEL)?;
 
-        let fb_layout = FbLayout::new(chipset, bar, &gsp_fw)?;
+        let fb_layout = FbLayout::new(chipset, bar, &gsp_fw, ctx.vf_partition_count)?;
         dev_dbg!(dev, "{:#x?}\n", fb_layout);
 
         let wpr_meta = Coherent::<GspFwWprMeta>::zeroed(dev, GFP_KERNEL)?;
drivers/gpu/nova-core/gsp/fw.rs +6 -0
index ca01ac3af9c6..b46ab6b921e3 100644
@@ -454,6 +454,12 @@ enum GspFwHeapParams {}
 /// Minimum required alignment for the GSP heap.
 const GSP_HEAP_ALIGNMENT: Alignment = Alignment::new::<{ 1 << 20 }>();
 
+// vGPU constants from the bindings, re-exported for use by fb.rs and gpu.rs.
+pub(crate) const GSP_FW_HEAP_SIZE_VGPU_DEFAULT: u64 = bindings::GSP_FW_HEAP_SIZE_VGPU_DEFAULT as u64;
+pub(crate) const GSP_FW_HEAP_SIZE_VGPU_48VMS: u64 = bindings::GSP_FW_HEAP_SIZE_VGPU_48VMS as u64;
+pub(crate) const MAX_PARTITIONS_WITH_GFID: u8 = bindings::MAX_PARTITIONS_WITH_GFID;
+pub(crate) const MAX_PARTITIONS_WITH_GFID_32VM: u8 = bindings::MAX_PARTITIONS_WITH_GFID_32VM;
+
 // These constants override the generated bindings for architecture-specific heap sizing.
 // See Open RM: kgspCalculateGspFwHeapSize and related functions.
 //
drivers/gpu/nova-core/gsp/fw/r570_144/bindings.rs +4 -0
index 354ee2cfa295..1273152266ad 100644
@@ -40,6 +40,10 @@ fn fmt(&self, fmt: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
 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_HEAP_SIZE_VGPU_DEFAULT: u32 = 581 << 20;
+pub const GSP_FW_HEAP_SIZE_VGPU_48VMS: u32 = 1370 << 20;
+pub const MAX_PARTITIONS_WITH_GFID: u8 = 48;
+pub const MAX_PARTITIONS_WITH_GFID_32VM: u8 = 32;
 pub const GSP_FW_WPR_META_REVISION: u32 = 1;
 pub const GSP_FW_WPR_META_MAGIC: i64 = -2577556379034558285;
 pub const REGISTRY_TABLE_ENTRY_TYPE_DWORD: u32 = 1;
drivers/gpu/nova-core/vgpu.rs +1 -1
index d35081a088cf..5736eaa79654 100644
@@ -14,7 +14,7 @@
 pub(crate) struct Vgpu {
     pub(crate) vgpu_requested: bool,
     pub(crate) vgpu_enabled: bool,
-    pub total_vfs: u16,
+    pub(crate) total_vfs: u16,
 }
 
 impl Vgpu {
Signature · 1 line
2.51.0
author
#10 lore raw

RFC v2 10/10 gpu: nova-core: load the scrubber ucode when vGPU support is enabled

In reply to Zhi Wang

To support the maximum vGPUs on the device that support vGPU, a larger WPR2 heap size is required. By setting the WPR2 heap size larger than 256MB the scrubber ucode image is required to scrub the FB memory before any other ucode image is executed.

If not, the GSP firmware hangs when booting.

When the WPR2 heap exceeds 256MB, execute the scrubber ucode image to scrub the FB memory before executing any other ucode images.

Cc Dirk Behme <[email protected]>
Cc Joel Fernandes <[email protected]>
Cc Alexandre Courbot <[email protected]>
---
 drivers/gpu/nova-core/firmware.rs        |  3 +-
 drivers/gpu/nova-core/firmware/booter.rs |  2 +
 drivers/gpu/nova-core/gsp/boot.rs        | 53 ++++++++++++++++++++++++
 drivers/gpu/nova-core/gsp/fw.rs          |  2 +-
 drivers/gpu/nova-core/regs.rs            | 12 ++++++
 5 files changed, 70 insertions(+), 2 deletions(-)
drivers/gpu/nova-core/firmware.rs +2 -1
index ab5889fa6a56..d13615864198 100644
@@ -437,7 +437,8 @@ const fn make_entry_chipset(self, chipset: gpu::Chipset) -> Self {
             .make_entry_file(name, "booter_load")
             .make_entry_file(name, "booter_unload")
             .make_entry_file(name, "bootloader")
-            .make_entry_file(name, "gsp");
+            .make_entry_file(name, "gsp")
+            .make_entry_file(name, "scrubber");
 
         if chipset.needs_fwsec_bootloader() {
             this.make_entry_file(name, "gen_bootloader")
drivers/gpu/nova-core/firmware/booter.rs +2 -0
index 04a887bea888..8642957923a2 100644
@@ -284,6 +284,7 @@ fn new_booter(data: &[u8]) -> Result<Self> {
 
 #[derive(Copy, Clone, Debug, PartialEq)]
 pub(crate) enum BooterKind {
+    Scrubber,
     Loader,
     #[expect(unused)]
     Unloader,
@@ -301,6 +302,7 @@ pub(crate) fn new(
         bar: &Bar0,
     ) -> Result<Self> {
         let fw_name = match kind {
+            BooterKind::Scrubber => "scrubber",
             BooterKind::Loader => "booter_load",
             BooterKind::Unloader => "booter_unload",
         };
drivers/gpu/nova-core/gsp/boot.rs +53 -0

82 lines not on this page · raw message

drivers/gpu/nova-core/gsp/fw.rs +1 -1
index b46ab6b921e3..30d82501faba 100644
@@ -7,7 +7,7 @@
 // Alias to avoid repeating the version number with every use.
 use r570_144 as bindings;
 
-use core::ops::Range;
+use core::{fmt, ops::Range};
 
 use kernel::{
     device,
drivers/gpu/nova-core/regs.rs +12 -0
index 8d424dd23a5a..5692114c710c 100644
@@ -216,6 +216,18 @@ pub(crate) fn higher_bound(self) -> u64 {
     26:26   boot_stage_3_handoff as bool;
 });
 
+// BSI secure scratch 15: scrubber handoff status.
+register!(NV_PGC6_BSI_SECURE_SCRATCH_15 @ 0x001180fc {
+    31:29   scrubber_handoff as u8;
+});
+
+impl NV_PGC6_BSI_SECURE_SCRATCH_15 {
+    /// Returns `true` if scrubber has completed.
+    pub(crate) fn scrubber_completed(self) -> bool {
+        self.scrubber_handoff() >= 0x3
+    }
+}
+
 // Privilege level mask register. It dictates whether the host CPU has privilege to access the
 // `PGC6_AON_SECURE_SCRATCH_GROUP_05` register (which it needs to read GFW_BOOT).
 register!(NV_PGC6_AON_SECURE_SCRATCH_GROUP_05_PRIV_LEVEL_MASK @ 0x00118128,
Signature · 1 line
2.51.0