From nobody Sun Feb 8 08:22:36 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F1FE335971C; Thu, 18 Dec 2025 15:52:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766073174; cv=none; b=GqNMJCzmDr+nvBno9bTCFXnBiRk4FwDUdyyz/ctOUV7ddrI6jZ5xa9fo4201DgMM812j+izPA0DirB4HUGV2nDt2BCZnuDwL+yZgiaUbZPvNW5WVn1S0DqcOKPPJ6K3EVquL/afZcAUJp56CRZJIp/yBOoREqrbFbYFsTFwFnQA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766073174; c=relaxed/simple; bh=GFVUOVKa2M6EOtqWngqafppHGGm/d16c6jpiQqgpjDA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=tZghnsb/KbDkacyK0S6WEeM8ktWnPqf7SkZ+t/eR9iz7nGnvtqdBYK9riAgwQPm/QAfiV7GTASG+4vulR2rVlQcdcrt2L8vUTl/ZfNuSFJ3X0GQhEKGClRr+TuXzbcOXoZYRVANAemUgr0MgIm6HlTp36mMygVtsOL2NWMf/svw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=JeH0CZuG; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="JeH0CZuG" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0B709C116B1; Thu, 18 Dec 2025 15:52:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1766073173; bh=GFVUOVKa2M6EOtqWngqafppHGGm/d16c6jpiQqgpjDA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JeH0CZuGQjhERkwiquP4qrS9JnZLgv3b4mkgKdmOohRXvHYzucfzFZtNR9NRnJxxM qD+vvbR9KqbT/tEOfg85yZkxEFkdkDoNyXMquaFmnCABkTj4l/wOfQyFKKC+DlpHFJ whZGQhZG514KqvaiNOyOYn5WRvyeoVNusG5cSFPUGbfoCCeXkXzPmTPUnukbL7c59N R/9Um15qo3+uJBOFW440IJwoWIzeytNus1mi0lZQ97OxIzv2mbuAIYL1+zcEKYskvC geVaY6XabTefuKSILW58qoffLy2RBqmko7zecyZvanUtWlJxlmEDo1xA9GFoMI19aF f4BF5OBne1epA== From: Danilo Krummrich To: acourbot@nvidia.com, jhubbard@nvidia.com, apopple@nvidia.com, joelagnelf@nvidia.com, aliceryhl@google.com, lossin@kernel.org Cc: nouveau@lists.freedesktop.org, dri-devel@lists.freedesktop.org, rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Danilo Krummrich Subject: [PATCH 1/4] gpu: nova-core: fw: get rid of redundant Result in GspFirmware::new() Date: Thu, 18 Dec 2025 16:50:48 +0100 Message-ID: <20251218155239.25243-2-dakr@kernel.org> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20251218155239.25243-1-dakr@kernel.org> References: <20251218155239.25243-1-dakr@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" In GspFirmware::new(), utilize pin_init_scope() to get rid of the Result in the returned Result> which is unnecessarily redundant. Signed-off-by: Danilo Krummrich --- drivers/gpu/nova-core/firmware/gsp.rs | 132 +++++++++++++------------- drivers/gpu/nova-core/gsp/boot.rs | 5 +- 2 files changed, 68 insertions(+), 69 deletions(-) diff --git a/drivers/gpu/nova-core/firmware/gsp.rs b/drivers/gpu/nova-core/= firmware/gsp.rs index 0549805282ab..e034268be3c5 100644 --- a/drivers/gpu/nova-core/firmware/gsp.rs +++ b/drivers/gpu/nova-core/firmware/gsp.rs @@ -153,82 +153,84 @@ pub(crate) struct GspFirmware { impl GspFirmware { /// Loads the GSP firmware binaries, map them into `dev`'s address-spa= ce, and creates the page /// tables expected by the GSP bootloader to load it. - pub(crate) fn new<'a, 'b>( + pub(crate) fn new<'a>( dev: &'a device::Device, chipset: Chipset, - ver: &'b str, - ) -> Result + 'a> { - let fw =3D super::request_firmware(dev, chipset, "gsp", ver)?; + ver: &'a str, + ) -> impl PinInit + 'a { + pin_init::pin_init_scope(move || { + let fw =3D super::request_firmware(dev, chipset, "gsp", ver)?; =20 - let fw_section =3D elf::elf64_section(fw.data(), ".fwimage").ok_or= (EINVAL)?; + let fw_section =3D elf::elf64_section(fw.data(), ".fwimage").o= k_or(EINVAL)?; =20 - let sigs_section =3D match chipset.arch() { - Architecture::Ampere =3D> ".fwsignature_ga10x", - Architecture::Ada =3D> ".fwsignature_ad10x", - _ =3D> return Err(ENOTSUPP), - }; - let signatures =3D elf::elf64_section(fw.data(), sigs_section) - .ok_or(EINVAL) - .and_then(|data| DmaObject::from_data(dev, data))?; + let sigs_section =3D match chipset.arch() { + Architecture::Ampere =3D> ".fwsignature_ga10x", + Architecture::Ada =3D> ".fwsignature_ad10x", + _ =3D> return Err(ENOTSUPP), + }; + let signatures =3D elf::elf64_section(fw.data(), sigs_section) + .ok_or(EINVAL) + .and_then(|data| DmaObject::from_data(dev, data))?; =20 - let size =3D fw_section.len(); + let size =3D fw_section.len(); =20 - // Move the firmware into a vmalloc'd vector and map it into the d= evice address - // space. - let fw_vvec =3D VVec::with_capacity(fw_section.len(), GFP_KERNEL) - .and_then(|mut v| { - v.extend_from_slice(fw_section, GFP_KERNEL)?; - Ok(v) - }) - .map_err(|_| ENOMEM)?; + // Move the firmware into a vmalloc'd vector and map it into t= he device address + // space. + let fw_vvec =3D VVec::with_capacity(fw_section.len(), GFP_KERN= EL) + .and_then(|mut v| { + v.extend_from_slice(fw_section, GFP_KERNEL)?; + Ok(v) + }) + .map_err(|_| ENOMEM)?; =20 - let bl =3D super::request_firmware(dev, chipset, "bootloader", ver= )?; - let bootloader =3D RiscvFirmware::new(dev, &bl)?; + let bl =3D super::request_firmware(dev, chipset, "bootloader",= ver)?; + let bootloader =3D RiscvFirmware::new(dev, &bl)?; =20 - Ok(try_pin_init!(Self { - fw <- SGTable::new(dev, fw_vvec, DataDirection::ToDevice, GFP_= KERNEL), - level2 <- { - // Allocate the level 2 page table, map the firmware onto = it, and map it into the - // device address space. - VVec::::with_capacity( - fw.iter().count() * core::mem::size_of::(), - GFP_KERNEL, - ) - .map_err(|_| ENOMEM) - .and_then(|level2| map_into_lvl(&fw, level2)) - .map(|level2| SGTable::new(dev, level2, DataDirection::ToD= evice, GFP_KERNEL))? - }, - level1 <- { - // Allocate the level 1 page table, map the level 2 page t= able onto it, and map it - // into the device address space. - VVec::::with_capacity( - level2.iter().count() * core::mem::size_of::(), - GFP_KERNEL, - ) - .map_err(|_| ENOMEM) - .and_then(|level1| map_into_lvl(&level2, level1)) - .map(|level1| SGTable::new(dev, level1, DataDirection::ToD= evice, GFP_KERNEL))? - }, - level0: { - // Allocate the level 0 page table as a device-visible DMA= object, and map the - // level 1 page table onto it. + Ok(try_pin_init!(Self { + fw <- SGTable::new(dev, fw_vvec, DataDirection::ToDevice, = GFP_KERNEL), + level2 <- { + // Allocate the level 2 page table, map the firmware o= nto it, and map it into + // the device address space. + VVec::::with_capacity( + fw.iter().count() * core::mem::size_of::(), + GFP_KERNEL, + ) + .map_err(|_| ENOMEM) + .and_then(|level2| map_into_lvl(&fw, level2)) + .map(|level2| SGTable::new(dev, level2, DataDirection:= :ToDevice, GFP_KERNEL))? + }, + level1 <- { + // Allocate the level 1 page table, map the level 2 pa= ge table onto it, and map + // it into the device address space. + VVec::::with_capacity( + level2.iter().count() * core::mem::size_of::(= ), + GFP_KERNEL, + ) + .map_err(|_| ENOMEM) + .and_then(|level1| map_into_lvl(&level2, level1)) + .map(|level1| SGTable::new(dev, level1, DataDirection:= :ToDevice, GFP_KERNEL))? + }, + level0: { + // Allocate the level 0 page table as a device-visible= DMA object, and map the + // level 1 page table onto it. =20 - // Level 0 page table data. - let mut level0_data =3D kvec![0u8; GSP_PAGE_SIZE]?; + // Level 0 page table data. + let mut level0_data =3D kvec![0u8; GSP_PAGE_SIZE]?; =20 - // Fill level 1 page entry. - let level1_entry =3D level1.iter().next().ok_or(EINVAL)?; - let level1_entry_addr =3D level1_entry.dma_address(); - let dst =3D &mut level0_data[..size_of_val(&level1_entry_a= ddr)]; - dst.copy_from_slice(&level1_entry_addr.to_le_bytes()); + // Fill level 1 page entry. + let level1_entry =3D level1.iter().next().ok_or(EINVAL= )?; + let level1_entry_addr =3D level1_entry.dma_address(); + let dst =3D &mut level0_data[..size_of_val(&level1_ent= ry_addr)]; + dst.copy_from_slice(&level1_entry_addr.to_le_bytes()); =20 - // Turn the level0 page table into a [`DmaObject`]. - DmaObject::from_data(dev, &level0_data)? - }, - size, - signatures, - bootloader, - })) + // Turn the level0 page table into a [`DmaObject`]. + DmaObject::from_data(dev, &level0_data)? + }, + size, + signatures, + bootloader, + })) + }) } =20 /// Returns the DMA handle of the radix3 level 0 page table. diff --git a/drivers/gpu/nova-core/gsp/boot.rs b/drivers/gpu/nova-core/gsp/= boot.rs index 54937606b5b0..a53d80620468 100644 --- a/drivers/gpu/nova-core/gsp/boot.rs +++ b/drivers/gpu/nova-core/gsp/boot.rs @@ -139,10 +139,7 @@ pub(crate) fn boot( =20 let bios =3D Vbios::new(dev, bar)?; =20 - let gsp_fw =3D KBox::pin_init( - GspFirmware::new(dev, chipset, FIRMWARE_VERSION)?, - GFP_KERNEL, - )?; + let gsp_fw =3D KBox::pin_init(GspFirmware::new(dev, chipset, FIRMW= ARE_VERSION), GFP_KERNEL)?; =20 let fb_layout =3D FbLayout::new(chipset, bar, &gsp_fw)?; dev_dbg!(dev, "{:#x?}\n", fb_layout); --=20 2.52.0