All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Eliot Courtney" <ecourtney@nvidia.com>
To: "Timur Tabi" <ttabi@nvidia.com>,
	"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: Re: [PATCH v5 5/6] gpu: nova-core: skip the IFR header if present
Date: Mon, 20 Apr 2026 15:37:42 +0900	[thread overview]
Message-ID: <DHXRWT0LZNXL.3SZJR0AEB1P6I@nvidia.com> (raw)
In-Reply-To: <20260417191359.1307434-6-ttabi@nvidia.com>

On Sat Apr 18, 2026 at 4:13 AM JST, Timur Tabi wrote:
> 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/vbios.rs | 85 +++++++++++++++++++++++++++++++++-
>  1 file changed, 84 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/nova-core/vbios.rs b/drivers/gpu/nova-core/vbios.rs
> index e726594eb130..6bcfb6c5cf44 100644
> --- a/drivers/gpu/nova-core/vbios.rs
> +++ b/drivers/gpu/nova-core/vbios.rs
> @@ -12,6 +12,8 @@
>          Alignable,
>          Alignment, //
>      },
> +    register,
> +    sizes::SZ_4K,
>      sync::aref::ARef,
>      transmute::FromBytes,
>  };
> @@ -89,13 +91,94 @@ struct VbiosIterator<'a> {
>      last_found: 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;
> +    }
> +}
> +
> +/// 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 some 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 vbios_rom_offset(dev: &device::Device, bar0: &Bar0) -> Result<usize> {
> +    /// IFR signature.
> +    const NV_PBUS_IFR_FMT_FIXED0_SIGNATURE_VALUE: u32 = u32::from_le_bytes(*b"NVGI");
> +    /// ROM directory signature.
> +    const NV_ROM_DIRECTORY_IDENTIFIER: u32 = u32::from_le_bytes(*b"RFRD");
> +    /// 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 = SZ_4K;
> +    /// Offset in the ROM Directory of the PCI Option ROM offset
> +    const PCI_OPTION_ROM_OFFSET: usize = 8;
> +
> +    let signature = bar0.read(NV_PBUS_IFR_FMT_FIXED0).signature();
> +
> +    if signature == NV_PBUS_IFR_FMT_FIXED0_SIGNATURE_VALUE {
> +        let fixed1 = bar0.read(NV_PBUS_IFR_FMT_FIXED1);
> +
> +        match fixed1.version() {
> +            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(usize::from_safe_cast)
> +            }
> +            3 => {
> +                let fixed2 = bar0.read(NV_PBUS_IFR_FMT_FIXED2);
> +                let total_data_size = usize::from(fixed2.total_data_size());
> +                let flash_status_offset =
> +                    usize::from_safe_cast(bar0.try_read32(ROM_OFFSET + total_data_size)?);
> +                let dir_offset = flash_status_offset + 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 + PCI_OPTION_ROM_OFFSET)
> +                    .map(usize::from_safe_cast)
> +            }
> +            _ => {
> +                dev_err!(dev, "unsupported IFR header version {}\n", fixed1.version());
> +                Err(EINVAL)
> +            }
> +        }
> +    } else {
> +        Ok(0)
> +    }
> +}

nit: register! type definitions can be put inside the `vbios_rom_offset`
function since they are only used there. And the function itself might
be better inside `VbiosIterator`. Alex, if you agree, maybe you could do
this on apply but not blocking at all.

Thanks Timur!

Reviewed-by: Eliot Courtney <ecourtney@nvidia.com>


  reply	other threads:[~2026-04-20  6:37 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-17 19:13 [PATCH v5 0/6] gpu: nova-core: add GA100 support Timur Tabi
2026-04-17 19:13 ` [PATCH v5 1/6] gpu: nova-core: use correct fwsignature for GA100 Timur Tabi
2026-04-19 19:34   ` Gary Guo
2026-04-17 19:13 ` [PATCH v5 2/6] gpu: nova-core: do not consider 0xBB77 as a valid PCI ROM header signature Timur Tabi
2026-04-19 19:36   ` Gary Guo
2026-04-17 19:13 ` [PATCH v5 3/6] gpu: nova-core: only boot FRTS if its region is allocated Timur Tabi
2026-04-19 19:36   ` Gary Guo
2026-04-17 19:13 ` [PATCH v5 4/6] gpu: nova-core: add FbHal::frts_size() for GA100 support Timur Tabi
2026-04-19 19:47   ` Gary Guo
2026-04-20  1:28     ` Alexandre Courbot
2026-04-20 10:23       ` Gary Guo
2026-04-20 12:50         ` Alexandre Courbot
2026-04-20 17:51           ` Timur Tabi
2026-04-20 20:27             ` Gary Guo
2026-04-20 21:15               ` Timur Tabi
2026-04-21  1:22                 ` Alexandre Courbot
2026-04-17 19:13 ` [PATCH v5 5/6] gpu: nova-core: skip the IFR header if present Timur Tabi
2026-04-20  6:37   ` Eliot Courtney [this message]
2026-04-17 19:13 ` [PATCH v5 6/6] gpu: nova-core: enable GA100 Timur Tabi
2026-04-19 19:36   ` Gary Guo
2026-04-28 23:41 ` [PATCH v5 0/6] gpu: nova-core: add GA100 support 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=DHXRWT0LZNXL.3SZJR0AEB1P6I@nvidia.com \
    --to=ecourtney@nvidia.com \
    --cc=acourbot@nvidia.com \
    --cc=dakr@kernel.org \
    --cc=gary@garyguo.net \
    --cc=jhubbard@nvidia.com \
    --cc=joelagnelf@nvidia.com \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=ttabi@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.