public inbox for rust-for-linux@vger.kernel.org
 help / color / mirror / Atom feed
From: "Alexandre Courbot" <acourbot@nvidia.com>
To: "Danilo Krummrich" <dakr@kernel.org>
Cc: "Timur Tabi" <ttabi@nvidia.com>,
	"Joel Fernandes" <joelagnelf@nvidia.com>,
	<nouveau@lists.freedesktop.org>, <rust-for-linux@vger.kernel.org>
Subject: Re: [PATCH v6 11/11] gpu: nova-core: add PIO support for loading firmware images
Date: Sat, 17 Jan 2026 10:55:33 +0900	[thread overview]
Message-ID: <DFQHO4129L0Y.2RND2QTLDSTWZ@nvidia.com> (raw)
In-Reply-To: <DFQBHVTTHZY8.13ASLCJ3FJP81@kernel.org>

On Sat Jan 17, 2026 at 6:05 AM JST, Danilo Krummrich wrote:
<snip>
>> +                    regs::NV_PFALCON_FALCON_IMEMT::default()
>> +                        .set_tag(tag)
>> +                        .write(bar, &E::ID, port);
>> +                    for word in block.chunks_exact(4) {
>> +                        let w = [word[0], word[1], word[2], word[3]];
>> +                        regs::NV_PFALCON_FALCON_IMEMD::default()
>> +                            .set_data(u32::from_le_bytes(w))
>> +                            .write(bar, &E::ID, port);
>> +                    }
>> +                    tag += 1;
>> +                }
>> +            }
>> +            FalconMem::Dmem => {
>> +                regs::NV_PFALCON_FALCON_DMEMC::default()
>> +                    .set_aincw(true)
>> +                    .set_offs(mem_base)
>> +                    .write(bar, &E::ID, port);
>> +
>> +                for block in img.chunks(256) {
>> +                    for word in block.chunks_exact(4) {
>> +                        let w = [word[0], word[1], word[2], word[3]];
>> +                        regs::NV_PFALCON_FALCON_DMEMD::default()
>> +                            .set_data(u32::from_le_bytes(w))
>> +                            .write(bar, &E::ID, port);
>> +                    }
>> +                }
>> +            }
>> +        }
>> +
>> +        Ok(())
>> +    }
>> +
>> +    fn pio_wr<F: FalconFirmware<Target = E>>(
>> +        &self,
>> +        bar: &Bar0,
>> +        fw: &F,
>> +        target_mem: FalconMem,
>> +        load_offsets: &FalconLoadTarget,
>> +        port: u8,
>> +        tag: u16,
>> +    ) -> Result {
>> +        let start = usize::from_safe_cast(load_offsets.src_start);
>> +        let len = usize::from_safe_cast(load_offsets.len);
>> +        let mem_base = u16::try_from(load_offsets.dst_start)?;
>> +
>> +        // SAFETY: we are the only user of the firmware image at this stage
>> +        let data = unsafe { fw.as_slice(start, len).map_err(|_| EINVAL)? };
>
> Why do we need the firmware image to be backed by a DMA object at this point
> when you load the firmware image through PIO anyways?

When we request the firmware, we don't know whether it is going to be
loaded via DMA or PIO. DMA does require a DMA object though, so the safe
route is to always create one and access its slice if it turns out we
will be doing PIO.

Another way would be to put the firmware into a vector and create a DMA
object on-demand in `dma_load`, but that's a more important refactoring
that we can probably keep for after this patchset should we want to do
it.

>> +}
>> +
>>  /// The FWSEC microcode, extracted from the BIOS and to be run on the GSP falcon.
>>  ///
>>  /// It is responsible for e.g. carving out the WPR2 region as the first step of the GSP bootflow.
>> @@ -221,6 +286,8 @@ pub(crate) struct FwsecFirmware {
>>      desc: FalconUCodeDesc,
>>      /// GPU-accessible DMA object containing the firmware.
>>      ucode: FirmwareDmaObject<Self, Signed>,
>> +    /// Generic bootloader
>> +    gen_bootloader: Option<GenericBootloader>,
>
> I'm not convinced this is a good idea. We probably want a HAL here and have
> different FwsecFirmware types:
>
> One with a DMA object and one with a system memory object when the architecture
> uses PIO. In the latter case the object can have a GenericBootloader field, i.e.
> this also gets us rid of the Option and all the subsequent 'if chipset <
> Chipset::GA102' checks and 'match gbl_fw' matches below.

Yeah that's basically what I have in mind as well - the FW type using
the generic bootloader could wrap the regular FwsecFirmware as its
purpose is simply to load it. I'm trying to put together some code to
that effect but it looks like it would work and would also remove the
special-case code in the PIO loader.

  reply	other threads:[~2026-01-17  1:56 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-14 19:29 [PATCH v6 00/11] gpu: nova-core: add Turing support Timur Tabi
2026-01-14 19:29 ` [PATCH v6 01/11] gpu: nova-core: rename Imem to ImemSecure Timur Tabi
2026-01-14 19:29 ` [PATCH v6 02/11] gpu: nova-core: add ImemNonSecure section infrastructure Timur Tabi
2026-01-22 12:52   ` Gary Guo
2026-01-22 19:00     ` Timur Tabi
2026-01-14 19:29 ` [PATCH v6 03/11] gpu: nova-core: support header parsing on Turing/GA100 Timur Tabi
2026-01-14 19:29 ` [PATCH v6 04/11] gpu: nova-core: add support for Turing/GA100 fwsignature Timur Tabi
2026-01-14 19:29 ` [PATCH v6 05/11] gpu: nova-core: add NV_PFALCON_FALCON_DMATRFCMD::with_falcon_mem() Timur Tabi
2026-01-14 19:29 ` [PATCH v6 06/11] gpu: nova-core: move some functions into the HAL Timur Tabi
2026-01-16 19:55   ` Danilo Krummrich
2026-01-16 20:08     ` John Hubbard
2026-01-16 20:11       ` Danilo Krummrich
2026-01-16 20:15         ` John Hubbard
2026-01-16 20:21           ` Danilo Krummrich
2026-01-16 20:27             ` John Hubbard
2026-01-14 19:29 ` [PATCH v6 07/11] gpu: nova-core: Add basic Turing HAL Timur Tabi
2026-01-14 19:29 ` [PATCH v6 08/11] gpu: nova-core: add Falcon HAL method supports_dma() Timur Tabi
2026-01-16  1:53   ` Alexandre Courbot
2026-01-16  3:00     ` Timur Tabi
2026-01-14 19:29 ` [PATCH v6 09/11] gpu: nova-core: add FalconUCodeDescV2 support Timur Tabi
2026-01-16  3:11   ` Alexandre Courbot
2026-01-16  3:23   ` Alexandre Courbot
2026-01-16 20:09     ` Danilo Krummrich
2026-01-14 19:29 ` [PATCH v6 10/11] gpu: nova-core: align LibosMemoryRegionInitArgument size to page size Timur Tabi
2026-01-14 19:29 ` [PATCH v6 11/11] gpu: nova-core: add PIO support for loading firmware images Timur Tabi
2026-01-16 15:22   ` Alexandre Courbot
2026-01-16 21:05   ` Danilo Krummrich
2026-01-17  1:55     ` Alexandre Courbot [this message]
2026-01-21  0:25     ` 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=DFQHO4129L0Y.2RND2QTLDSTWZ@nvidia.com \
    --to=acourbot@nvidia.com \
    --cc=dakr@kernel.org \
    --cc=joelagnelf@nvidia.com \
    --cc=nouveau@lists.freedesktop.org \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox