public inbox for rust-for-linux@vger.kernel.org
 help / color / mirror / Atom feed
From: Timur Tabi <ttabi@nvidia.com>
To: Danilo Krummrich <dakr@kernel.org>,
	Alexandre Courbot <acourbot@nvidia.com>,
	John Hubbard <jhubbard@nvidia.com>, Gary Guo <gary@garyguo.net>,
	Joel Fernandes <joelagnelf@nvidia.com>,
	Eliot Courtney <ecourtney@nvidia.com>,
	<rust-for-linux@vger.kernel.org>
Subject: [PATCH v3 5/6] gpu: nova-core: skip the IFR header if present
Date: Wed, 15 Apr 2026 19:26:18 -0500	[thread overview]
Message-ID: <20260416002619.900779-6-ttabi@nvidia.com> (raw)
In-Reply-To: <20260416002619.900779-1-ttabi@nvidia.com>

The GPU's ROM may begin with an Init-from-ROM (IFR) header that precedes
the PCI Expansion ROM images (VBIOS).  When present, the PROM shadow
method must parse this header to determine the offset where the PCI ROM
images actually begin, and adjust all subsequent reads accordingly.

On most GPUs this is not needed because the IFR microcode has already
applied the ROM offset so that PROM reads transparently skip the header.
On GA100, for whatever reason, the IFR offset is not applied to PROM
reads.  Therefore, the search for the PCI expansion must skip the IFR
header, if found.

Signed-off-by: Timur Tabi <ttabi@nvidia.com>
---
 drivers/gpu/nova-core/regs.rs  | 21 ++++++++++++
 drivers/gpu/nova-core/vbios.rs | 61 +++++++++++++++++++++++++++++++++-
 2 files changed, 81 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/nova-core/regs.rs b/drivers/gpu/nova-core/regs.rs
index 2f171a4ff9ba..0880d52e4527 100644
--- a/drivers/gpu/nova-core/regs.rs
+++ b/drivers/gpu/nova-core/regs.rs
@@ -537,4 +537,25 @@ pub(crate) mod ga100 {
             0:0     display_disabled => bool;
         }
     }
+
+    // IFR Header in VBIOS
+
+    register! {
+        pub(crate) NV_PBUS_IFR_FMT_FIXED0(u32) @ 0x300000 {
+            31:0    signature;
+        }
+    }
+
+    register! {
+        pub(crate) NV_PBUS_IFR_FMT_FIXED1(u32) @ 0x300004 {
+            30:16   fixed_data_size;
+            15:8    version => u8;
+        }
+    }
+
+    register! {
+        pub(crate) NV_PBUS_IFR_FMT_FIXED2(u32) @ 0x300008 {
+            19:0 total_data_size;
+        }
+    }
 }
diff --git a/drivers/gpu/nova-core/vbios.rs b/drivers/gpu/nova-core/vbios.rs
index e726594eb130..f8ddbd9c4b43 100644
--- a/drivers/gpu/nova-core/vbios.rs
+++ b/drivers/gpu/nova-core/vbios.rs
@@ -25,6 +25,7 @@
         FalconUCodeDescV3, //
     },
     num::FromSafeCast,
+    regs::ga100, //
 };
 
 /// The offset of the VBIOS ROM in the BAR0 space.
@@ -89,13 +90,71 @@ struct VbiosIterator<'a> {
     last_found: bool,
 }
 
+/// IFR signature: ASCII "NVGI" as a little-endian u32.
+const NV_PBUS_IFR_FMT_FIXED0_SIGNATURE_VALUE: u32 = 0x4947564E;
+/// ROM directory signature: ASCII "RFRD" as a little-endian u32.
+const NV_ROM_DIRECTORY_IDENTIFIER: u32 = 0x44524652;
+/// Offset of the NV_PMGR_ROM_ADDR_OFFSET register in IFR Extended section
+const IFR_SW_EXT_ROM_ADDR_OFFSET: usize = 4;
+/// Size of Redundant Firmware Flash Status section
+const RFW_FLASH_STATUS_SIZE: usize = 4096;
+
+/// Return the byte offset where the PCI Expansion ROM images begin in the GPU's ROM.
+///
+/// The GPU's ROM may begin with an Init-from-ROM (IFR) header that precedes
+/// the PCI Expansion ROM images (VBIOS).  When present, the PROM shadow
+/// method must parse this header to determine the offset where the PCI ROM
+/// images actually begin, and adjust all subsequent reads accordingly.
+///
+/// On most GPUs this is not needed because the IFR microcode has already
+/// applied the ROM offset so that PROM reads transparently skip the header.
+/// On GA100, for whatever reason, the IFR offset is not applied to PROM
+/// reads.  Therefore, the search for the PCI expansion must skip the IFR
+/// header, if found.
+fn current_offset(dev: &device::Device, bar0: &Bar0) -> Result<usize> {
+    let signature = bar0.read(ga100::NV_PBUS_IFR_FMT_FIXED0).signature();
+
+    if signature == NV_PBUS_IFR_FMT_FIXED0_SIGNATURE_VALUE {
+        let fixed1 = bar0.read(ga100::NV_PBUS_IFR_FMT_FIXED1);
+
+        match fixed1.version() {
+            // Note: We do not actually expect to see v1 or v2 on these GPUs
+            1 | 2 => {
+                let fixed_data_size = usize::from(fixed1.fixed_data_size());
+                let pmgr_rom_addr_offset = fixed_data_size + IFR_SW_EXT_ROM_ADDR_OFFSET;
+                bar0.try_read32(ROM_OFFSET + pmgr_rom_addr_offset)
+                    .map(|v| v as usize)
+            }
+            3 => {
+                let fixed2 = bar0.read(ga100::NV_PBUS_IFR_FMT_FIXED2);
+                let total_data_size = usize::from(fixed2.total_data_size());
+                let dir_offset =
+                    bar0.try_read32(ROM_OFFSET + total_data_size)? as usize + RFW_FLASH_STATUS_SIZE;
+                let dir_sig = bar0.try_read32(ROM_OFFSET + dir_offset)?;
+                if dir_sig != NV_ROM_DIRECTORY_IDENTIFIER {
+                    dev_err!(dev, "could not find IFR ROM directory\n");
+                    return Err(EINVAL);
+                }
+                bar0.try_read32(ROM_OFFSET + dir_offset + 8)
+                    .map(|v| v as usize)
+            }
+            _ => {
+                dev_err!(dev, "unsupported IFR header version {}\n", fixed1.version());
+                Err(EINVAL)
+            }
+        }
+    } else {
+        Ok(0)
+    }
+}
+
 impl<'a> VbiosIterator<'a> {
     fn new(dev: &'a device::Device, bar0: &'a Bar0) -> Result<Self> {
         Ok(Self {
             dev,
             bar0,
             data: KVec::new(),
-            current_offset: 0,
+            current_offset: current_offset(dev, bar0)?,
             last_found: false,
         })
     }
-- 
2.53.0


  parent reply	other threads:[~2026-04-16  0:26 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-16  0:26 [PATCH v3 0/6] gpu: nova-core: add GA100 support Timur Tabi
2026-04-16  0:26 ` [PATCH v3 1/6] gpu: nova-core: use correct fwsignature for GA100 Timur Tabi
2026-04-16  0:26 ` [PATCH v3 2/6] gpu: nova-core: do not consider 0xBB77 as a valid PCI ROM header signature Timur Tabi
2026-04-16  0:26 ` [PATCH v3 3/6] gpu: nova-core: only boot FRTS if its region is allocated Timur Tabi
2026-04-16  0:26 ` [PATCH v3 4/6] gpu: nova-core: add FbHal::frts_size() for GA100 support Timur Tabi
2026-04-16  0:26 ` Timur Tabi [this message]
2026-04-16  1:21   ` [PATCH v3 5/6] gpu: nova-core: skip the IFR header if present John Hubbard
2026-04-16  1:24     ` Timur Tabi
2026-04-16  1:32       ` John Hubbard
2026-04-16  1:34         ` John Hubbard
2026-04-16 16:03           ` Timur Tabi
2026-04-16  0:26 ` [PATCH v3 6/6] gpu: nova-core: enable GA100 Timur Tabi

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=20260416002619.900779-6-ttabi@nvidia.com \
    --to=ttabi@nvidia.com \
    --cc=acourbot@nvidia.com \
    --cc=dakr@kernel.org \
    --cc=ecourtney@nvidia.com \
    --cc=gary@garyguo.net \
    --cc=jhubbard@nvidia.com \
    --cc=joelagnelf@nvidia.com \
    --cc=rust-for-linux@vger.kernel.org \
    /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