On Mon Nov 30, 2026 at 12:11 AM JST, Alexandre Courbot wrote:
> From: John Hubbard <[email protected]>
>
> 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 <[email protected]>
> Signed-off-by: Alexandre Courbot <[email protected]>
> ---

[...]

>  /// 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 <[email protected]>

Reply via email to