Re: [PATCH v2 11/11] gpu: nova-core: firmware: tlv: add method to load the file referenced by a TLV
From: Eliot Courtney
Date: Sun Nov 29 2026 - 21:38:26 EST
On Mon Nov 30, 2026 at 12:11 AM JST, Alexandre Courbot wrote:
> From: John Hubbard <jhubbard@xxxxxxxxxx>
>
> The GSP firmware TLV names a separate file in its FILE tag and gives
> that file's length in its SIZE tag. The GSP firmware wrapper reads the
> two tags and loads the file itself, so no other loader can share that
> code.
>
> Move it into the TLV parser as `Tlv::load_file()`, which also fails with
> ENODATA when SIZE is zero.
>
> The r000 ucodes loader will be the second user of this.
>
> Signed-off-by: John Hubbard <jhubbard@xxxxxxxxxx>
> Signed-off-by: Alexandre Courbot <acourbot@xxxxxxxxxx>
> ---
[...]
> /// Requests the GPU firmware TLV `name` suitable for `chipset`.
> pub(crate) fn request_tlv(
> dev: &device::Device,
> chipset: gpu::Chipset,
> name: &str,
> ) -> Result<firmware::Firmware> {
> - let chip_name = chipset.name();
> -
> - let filename = CString::try_from_fmt(fmt!("nvidia/{chip_name}/gsp/{name}.tlv"))?;
> + let filename = gsp_firmware_path(chipset, fmt!("{name}.tlv"))?;
>
> dev_dbg!(dev, "loading firmware image {:?}\n", &filename);
>
> @@ -198,6 +202,36 @@ fn iter(&self) -> TlvIter<'_, 'a> {
> self.iter().find(|b| b.tag == *tag).ok_or(EINVAL)
> }
>
> + /// Loads the file that the `FILE` tag names from `chipset`'s GSP firmware directory.
> + ///
> + /// The `SIZE` tag gives the file's length, and the returned buffer is that long.
> + ///
> + /// # Errors
> + ///
> + /// - `EINVAL` if `FILE` or `SIZE` is absent, or `FILE` does not hold a valid string.
> + /// - `ENODATA` if `SIZE` is zero.
> + /// - `ENOMEM` if the buffer cannot be allocated.
> + ///
> + /// Errors from the firmware request are propagated as-is.
> + pub(crate) fn load_file(
> + &self,
> + dev: &device::Device,
> + chipset: gpu::Chipset,
> + ) -> Result<VVec<u8>> {
> + let file = self.get_string(b"FILE")?;
> + let path = gsp_firmware_path(chipset, fmt!("{file}"))?;
> +
> + let size = usize::from_safe_cast(self.get_u32(b"SIZE")?);
> + if size == 0 {
> + return Err(ENODATA);
> + }
> +
> + let mut data = VVec::zeroed(size, GFP_KERNEL).map_err(|_| ENOMEM)?;
nit: `map_err` is redundant here
Reviewed-by: Eliot Courtney <ecourtney@xxxxxxxxxx>