[PATCH 06/15] gpu: nova-core: firmware: add the ucodes firmware loader
From: Alexandre Courbot
Date: Thu Dec 03 2026 - 07:12:37 EST
From: John Hubbard <jhubbard@xxxxxxxxxx>
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.
Signed-off-by: John Hubbard <jhubbard@xxxxxxxxxx>
Reviewed-by: Timur Tabi <ttabi@xxxxxxxxxx>
Signed-off-by: Alexandre Courbot <acourbot@xxxxxxxxxx>
---
drivers/gpu/nova-core/firmware.rs | 1 +
drivers/gpu/nova-core/firmware/ucodes.rs | 66 ++++++++++++++++++++++++++++++++
2 files changed, 67 insertions(+)
diff --git a/drivers/gpu/nova-core/firmware.rs b/drivers/gpu/nova-core/firmware.rs
index 97d6b1d83967..7b216dff1d30 100644
--- a/drivers/gpu/nova-core/firmware.rs
+++ b/drivers/gpu/nova-core/firmware.rs
@@ -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)]
diff --git a/drivers/gpu/nova-core/firmware/ucodes.rs b/drivers/gpu/nova-core/firmware/ucodes.rs
new file mode 100644
index 000000000000..153bb5172903
--- /dev/null
+++ b/drivers/gpu/nova-core/firmware/ucodes.rs
@@ -0,0 +1,66 @@
+// SPDX-License-Identifier: GPL-2.0
+// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
+
+//! Loading of the ucodes image, the bindata blob of microcode that GSP-RM loads during
+//! initialization.
+
+use kernel::{
+ device,
+ dma::DmaAddress,
+ prelude::*, //
+};
+
+use crate::{
+ firmware::{
+ radix3::Radix3,
+ tlv::{
+ request_tlv,
+ Tlv, //
+ },
+ },
+ gpu::Chipset,
+};
+
+/// The ucodes image, mapped for GSP-RM through a radix3 page table.
+pub(crate) struct UcodesImage<'a> {
+ /// The image and the page table that maps it.
+ 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`.
+ ///
+ /// # Errors
+ ///
+ /// - `ENOENT` if the metadata file is not installed.
+ /// - `EINVAL` if the metadata is malformed.
+ /// - `ENOMEM` if the page table cannot be allocated.
+ ///
+ /// Errors from [`Tlv::load_file`] are propagated as-is.
+ pub(crate) fn new(dev: &'a device::Device<device::Bound>, chipset: Chipset) -> Result<Self> {
+ let firmware = request_tlv(dev, chipset, "ucodes")?;
+ let tlv = Tlv::new(firmware.data())?;
+ let image = tlv.load_file(dev, chipset)?;
+
+ dev_dbg!(
+ dev,
+ "loaded ucodes firmware v{}\n",
+ tlv.get_string(b"VERS")?
+ );
+
+ Ok(Self {
+ radix3: KBox::pin_init(Radix3::new(dev, image), GFP_KERNEL)?,
+ })
+ }
+
+ /// Returns the DMA address of the level 0 page of the page table that maps the image.
+ pub(crate) fn radix3_dma_address(&self) -> DmaAddress {
+ self.radix3.dma_address()
+ }
+
+ /// Returns the size of the image in bytes.
+ pub(crate) fn size(&self) -> usize {
+ self.radix3.size()
+ }
+}
--
2.56.1