From nobody Sun Feb 8 05:40:35 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 Reviewed-by: Joel Fernandes --- 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 From nobody Sun Feb 8 05:40:35 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 D3B7A35A92F; Thu, 18 Dec 2025 15:52:56 +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=1766073176; cv=none; b=uFVF/BI5ASMKK7aMkFZZ5NoQ7e7jVer2rFpgMBX2agGRZ2bSWDB/QmRXI9gtwi8kDMZYO9uKTWhld5gD86Ar8bb7lah9RaWMeJVXLKlkCh/3bx+NX9ubKa4YyY4I12r3Y8WNIZ7omHGS8rQCS8gVuh1/hs6+eM0zTgD5RB7b/ec= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766073176; c=relaxed/simple; bh=gP/NY4VcXW0E9tzTPCUNhKx98dDbfmaXHBU2kHHZSmM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WsSbQfxNKFt9ZRiM0ajMI7U6sqMV9z14hFZO8WwZfbOGrJ91ElDK4RssK6Ru+gLEKumJtnjikq9Gh58eEwyWDoWEE1Xn8gkzrsAhYw11bQauagqEPJbr7eZjc+8kFzkg9yzihgceStrAXqOzyG8k+GTB5CR9ge79J8WpZzP+Zp4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=BkBB5tBA; 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="BkBB5tBA" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 01138C116C6; Thu, 18 Dec 2025 15:52:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1766073176; bh=gP/NY4VcXW0E9tzTPCUNhKx98dDbfmaXHBU2kHHZSmM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BkBB5tBAZy+q0QB7G58o/DIVVEqWtHlvApA7ZlCNKFSoUEZB/enREzDJvK5oEdPLF lX0E0ZJ1rH39QIlitGkG/zbItC7yOx+f99rI65VVCU/4xTI9iKvIrTO/G0RoF55YR0 MH2kdsUoJDIBNFrMUJDsUtbju/g+7WgBYU0fw9YpthJWXEEC9V/BVw4M5ZFkuEjNam MuGgVTKGVbUavh/sp3ZINz0Cu7sogP4V77TLNiCVd8linj5dXmiCAUf0dSx/wF9u2Q c+R41M8hG0VVSYev2iUNxkhxWu2ZdUXbqnG8jkwzTJ1qQjXcqSthMJGIclmNqtrccf 1PGd5OXHDc6iQ== 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 2/4] gpu: nova-core: fw: move appropriate code into pin initializer Date: Thu, 18 Dec 2025 16:50:49 +0100 Message-ID: <20251218155239.25243-3-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" Relocate the code that technically fits in the pin initializer into the initializer itself. While, thanks to pin_init_scope(), it is also possible to keep it as is, moving appropriate code into the initializer has the advantage that it structures the dependencies of fields naturally. For instance, intermediate data that is only needed for a single field goes into the initializer block of this field, making it obvious that it is not needed by anything else. On the other hand, intermediate data that is needed for multiple fields to initialize remains above the initializer, naturally indicating that it is needed my multiple fields. Signed-off-by: Danilo Krummrich Reviewed-by: Joel Fernandes --- drivers/gpu/nova-core/firmware/gsp.rs | 34 ++++++++++++++------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/drivers/gpu/nova-core/firmware/gsp.rs b/drivers/gpu/nova-core/= firmware/gsp.rs index e034268be3c5..da97814cf859 100644 --- a/drivers/gpu/nova-core/firmware/gsp.rs +++ b/drivers/gpu/nova-core/firmware/gsp.rs @@ -159,18 +159,9 @@ pub(crate) fn new<'a>( ver: &'a str, ) -> impl PinInit + 'a { pin_init::pin_init_scope(move || { - let fw =3D super::request_firmware(dev, chipset, "gsp", ver)?; + let firmware =3D super::request_firmware(dev, chipset, "gsp", = ver)?; =20 - let fw_section =3D elf::elf64_section(fw.data(), ".fwimage").o= k_or(EINVAL)?; - - 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 fw_section =3D elf::elf64_section(firmware.data(), ".fwima= ge").ok_or(EINVAL)?; =20 let size =3D fw_section.len(); =20 @@ -183,9 +174,6 @@ pub(crate) fn new<'a>( }) .map_err(|_| ENOMEM)?; =20 - let bl =3D super::request_firmware(dev, chipset, "bootloader",= ver)?; - let bootloader =3D RiscvFirmware::new(dev, &bl)?; - Ok(try_pin_init!(Self { fw <- SGTable::new(dev, fw_vvec, DataDirection::ToDevice, = GFP_KERNEL), level2 <- { @@ -227,8 +215,22 @@ pub(crate) fn new<'a>( DmaObject::from_data(dev, &level0_data)? }, size, - signatures, - bootloader, + signatures: { + let sigs_section =3D match chipset.arch() { + Architecture::Ampere =3D> ".fwsignature_ga10x", + Architecture::Ada =3D> ".fwsignature_ad10x", + _ =3D> return Err(ENOTSUPP), + }; + + elf::elf64_section(firmware.data(), sigs_section) + .ok_or(EINVAL) + .and_then(|data| DmaObject::from_data(dev, data))? + }, + bootloader: { + let bl =3D super::request_firmware(dev, chipset, "boot= loader", ver)?; + + RiscvFirmware::new(dev, &bl)? + }, })) }) } --=20 2.52.0 From nobody Sun Feb 8 05:40:35 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 D2D9435B120; Thu, 18 Dec 2025 15:52:59 +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=1766073179; cv=none; b=BAmnLO4rUEW7wcludUhnN60HrPLfW6pom3WYeRtjzdvksm084ZFkWuDlOtBSZ080lYTGEpsIR6dHlergjH+tIA2iCZPULywoJyklzv5o1keZbRJCIJk7d0HrnVmZnQ0ppuKnq7TejLbPr/1wtiQ+lllozd35qLLru/BBq1N+pBE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766073179; c=relaxed/simple; bh=mAqob5mbv6FapcPS/iSYQO3lcLOl40s89j9fmY+JxAo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QKgUQfApd8QX5FMz+t3TroPfe9O84IEHFbuUygWEnOwOmiznpkv9sHmNLRdDm8jpH+N4m9Op/JuohxGIsPPgZJNAPLd5mdVlBnsakbMe7STSVOCOCSKv5Ek5Ir7vISxoXRs2Gnrn6je13e/PyOI4TJqOV+y4+LHhS3eUY8Tga3w= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=lzH6VXSa; 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="lzH6VXSa" Received: by smtp.kernel.org (Postfix) with ESMTPSA id EA34FC19421; Thu, 18 Dec 2025 15:52:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1766073179; bh=mAqob5mbv6FapcPS/iSYQO3lcLOl40s89j9fmY+JxAo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lzH6VXSaSYuzW+LM5rHFjXy9bUhqsaHVxwYEUqlZwBYk6+ZIauHjc4tYlHr9Yzf3u UfxCd230qworoQfHVYyjcU1dxlgT5x8evbKGdbuIpKO0mMFHWzyIpEjHzriS2K3RTx 6g6DG21lveBY/IrymygKwRMyIcX1svj5Enh3XLqNEdpnQZIIP9KS7FBru+7qEoqVnQ 9s3SpEvxRofLo27TiLo2pB1bPjwNK/SjSsMWDUMg+vudQmJFT/1cHUB47vH1qIeZXK H3/dR48VYxI1bl+QBXRJWaHpp2hKwu7roF/lxc7NxLJ4lXkI9UJ/c1veerQpBtHFaq 4m6nRKTSNUemA== 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 3/4] gpu: nova-core: gsp: get rid of redundant Result in Gsp::new() Date: Thu, 18 Dec 2025 16:50:50 +0100 Message-ID: <20251218155239.25243-4-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 Gsp::new(), utilize pin_init_scope() to get rid of the Result in the returned Result> which is unnecessarily redundant. Signed-off-by: Danilo Krummrich Reviewed-by: Joel Fernandes --- drivers/gpu/nova-core/gpu.rs | 2 +- drivers/gpu/nova-core/gsp.rs | 78 ++++++++++++++++++------------------ 2 files changed, 41 insertions(+), 39 deletions(-) diff --git a/drivers/gpu/nova-core/gpu.rs b/drivers/gpu/nova-core/gpu.rs index 629c9d2dc994..50d76092fbdd 100644 --- a/drivers/gpu/nova-core/gpu.rs +++ b/drivers/gpu/nova-core/gpu.rs @@ -281,7 +281,7 @@ pub(crate) fn new<'a>( =20 sec2_falcon: Falcon::new(pdev.as_ref(), spec.chipset)?, =20 - gsp <- Gsp::new(pdev)?, + gsp <- Gsp::new(pdev), =20 _: { gsp.boot(pdev, bar, spec.chipset, gsp_falcon, sec2_falcon= )? }, =20 diff --git a/drivers/gpu/nova-core/gsp.rs b/drivers/gpu/nova-core/gsp.rs index fb6f74797178..8bc86e1bcac5 100644 --- a/drivers/gpu/nova-core/gsp.rs +++ b/drivers/gpu/nova-core/gsp.rs @@ -119,43 +119,45 @@ pub(crate) struct Gsp { =20 impl Gsp { // Creates an in-place initializer for a `Gsp` manager for `pdev`. - pub(crate) fn new(pdev: &pci::Device) -> Result> { - let dev =3D pdev.as_ref(); - let libos =3D CoherentAllocation:::= :alloc_coherent( - dev, - GSP_PAGE_SIZE / size_of::(), - GFP_KERNEL | __GFP_ZERO, - )?; - - // Initialise the logging structures. The OpenRM equivalents are i= n: - // _kgspInitLibosLoggingStructures (allocates memory for buffers) - // kgspSetupLibosInitArgs_IMPL (creates pLibosInitArgs[] array) - let loginit =3D LogBuffer::new(dev)?; - dma_write!(libos[0] =3D LibosMemoryRegionInitArgument::new("LOGINI= T", &loginit.0))?; - - let logintr =3D LogBuffer::new(dev)?; - dma_write!(libos[1] =3D LibosMemoryRegionInitArgument::new("LOGINT= R", &logintr.0))?; - - let logrm =3D LogBuffer::new(dev)?; - dma_write!(libos[2] =3D LibosMemoryRegionInitArgument::new("LOGRM"= , &logrm.0))?; - - let cmdq =3D Cmdq::new(dev)?; - - let rmargs =3D CoherentAllocation::::alloc_coh= erent( - dev, - 1, - GFP_KERNEL | __GFP_ZERO, - )?; - dma_write!(rmargs[0] =3D fw::GspArgumentsCached::new(&cmdq))?; - dma_write!(libos[3] =3D LibosMemoryRegionInitArgument::new("RMARGS= ", &rmargs))?; - - Ok(try_pin_init!(Self { - libos, - loginit, - logintr, - logrm, - rmargs, - cmdq, - })) + pub(crate) fn new(pdev: &pci::Device) -> impl PinInit + '_ { + pin_init::pin_init_scope(move || { + let dev =3D pdev.as_ref(); + let libos =3D CoherentAllocation::::alloc_coherent( + dev, + GSP_PAGE_SIZE / size_of::(), + GFP_KERNEL | __GFP_ZERO, + )?; + + // Initialise the logging structures. The OpenRM equivalents a= re in: + // _kgspInitLibosLoggingStructures (allocates memory for buffe= rs) + // kgspSetupLibosInitArgs_IMPL (creates pLibosInitArgs[] array) + let loginit =3D LogBuffer::new(dev)?; + dma_write!(libos[0] =3D LibosMemoryRegionInitArgument::new("LO= GINIT", &loginit.0))?; + + let logintr =3D LogBuffer::new(dev)?; + dma_write!(libos[1] =3D LibosMemoryRegionInitArgument::new("LO= GINTR", &logintr.0))?; + + let logrm =3D LogBuffer::new(dev)?; + dma_write!(libos[2] =3D LibosMemoryRegionInitArgument::new("LO= GRM", &logrm.0))?; + + let cmdq =3D Cmdq::new(dev)?; + + let rmargs =3D CoherentAllocation::::alloc= _coherent( + dev, + 1, + GFP_KERNEL | __GFP_ZERO, + )?; + dma_write!(rmargs[0] =3D fw::GspArgumentsCached::new(&cmdq))?; + dma_write!(libos[3] =3D LibosMemoryRegionInitArgument::new("RM= ARGS", &rmargs))?; + + Ok(try_pin_init!(Self { + libos, + loginit, + logintr, + logrm, + rmargs, + cmdq, + })) + }) } } --=20 2.52.0 From nobody Sun Feb 8 05:40:35 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 01E8135B149; Thu, 18 Dec 2025 15:53:02 +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=1766073183; cv=none; b=ZVvvHT6vbmYE4FHiUYL/y+P1fN5GR4w+OIlBu+WfuhG/PkWPIVhI7s5WARNimRCCxvXhwL9VgZuIPG9HQJOSJIcuIAFYXtDjmXdPIYa52fG80nGgLTC6rNfdWo69mgtAdXFYzrIpo0P3egZ+sZQWxXENi/ZWxvcmKU3izYeVWu4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766073183; c=relaxed/simple; bh=Acvk5iLutO8NmjLHTbkDla+2OX0ZkKvT1OUyrVQAsys=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=AiNzmxBirjv0eM/Yr5gaz2XrQ4st/vaN/H2LoCXM1E7Z8u7kw8Id0UHEb7L5RhFdEge+rkPSIHELaZt/j32Tbj57rF0Nm5wHSWumUbpWyeL0al5zLhslTd5mzdzNaIKOtS+TbcEVIAbyCUJlR93vMM7rVZXZ/Iy8u3bCb9ZR3xI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=gJLvBfZN; 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="gJLvBfZN" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E0B29C116B1; Thu, 18 Dec 2025 15:52:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1766073182; bh=Acvk5iLutO8NmjLHTbkDla+2OX0ZkKvT1OUyrVQAsys=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gJLvBfZNu53/I7LNeZPxDrRp/kr1nt6hLbP9EbfgjFWgpEAfRw611pH5sUiY5q/rk C3lh2fx8IIR/2e3zmzdwY+bsS3D2VTH+UYkvfs8vrJ3O31hcYIJJBYUFoPmTt6WEam CRu0dg3Q2YLh0vCQ6g0hsO5qhj+HZAYokXwQfLvF0Fg5AfqJlI395jpGhE6dYG/A0M q6jt8p49hareHf1YkOLa9wBJYtIIogdxUGm7WAZqG+kNaxZK72UwdvtppykKYRFNGe LqNLghldCNLLTKrJ0cdMZiyRCtOAxK+aNsXCl8rOEFA5qeD+Ik9RduPDeLb0z8WXNE uu9B+f0O5IL6A== 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 4/4] gpu: nova-core: gsp: move appropriate code into pin initializer Date: Thu, 18 Dec 2025 16:50:51 +0100 Message-ID: <20251218155239.25243-5-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" Relocate the code that technically fits in the pin initializer into the initializer itself. While, thanks to pin_init_scope(), it is also possible to keep it as is, moving appropriate code into the initializer has the advantage that it structures the dependencies of fields naturally. For instance, intermediate data that is only needed for a single field goes into the initializer block of this field, making it obvious that it is not needed by anything else. On the other hand, intermediate data that is needed for multiple fields to initialize remains above the initializer, naturally indicating that it is needed my multiple fields. Signed-off-by: Danilo Krummrich Reviewed-by: Joel Fernandes --- drivers/gpu/nova-core/gsp.rs | 61 +++++++++++++++++------------------- 1 file changed, 28 insertions(+), 33 deletions(-) diff --git a/drivers/gpu/nova-core/gsp.rs b/drivers/gpu/nova-core/gsp.rs index 8bc86e1bcac5..766fd9905358 100644 --- a/drivers/gpu/nova-core/gsp.rs +++ b/drivers/gpu/nova-core/gsp.rs @@ -122,41 +122,36 @@ impl Gsp { pub(crate) fn new(pdev: &pci::Device) -> impl PinInit + '_ { pin_init::pin_init_scope(move || { let dev =3D pdev.as_ref(); - let libos =3D CoherentAllocation::::alloc_coherent( - dev, - GSP_PAGE_SIZE / size_of::(), - GFP_KERNEL | __GFP_ZERO, - )?; - - // Initialise the logging structures. The OpenRM equivalents a= re in: - // _kgspInitLibosLoggingStructures (allocates memory for buffe= rs) - // kgspSetupLibosInitArgs_IMPL (creates pLibosInitArgs[] array) - let loginit =3D LogBuffer::new(dev)?; - dma_write!(libos[0] =3D LibosMemoryRegionInitArgument::new("LO= GINIT", &loginit.0))?; - - let logintr =3D LogBuffer::new(dev)?; - dma_write!(libos[1] =3D LibosMemoryRegionInitArgument::new("LO= GINTR", &logintr.0))?; - - let logrm =3D LogBuffer::new(dev)?; - dma_write!(libos[2] =3D LibosMemoryRegionInitArgument::new("LO= GRM", &logrm.0))?; - - let cmdq =3D Cmdq::new(dev)?; - - let rmargs =3D CoherentAllocation::::alloc= _coherent( - dev, - 1, - GFP_KERNEL | __GFP_ZERO, - )?; - dma_write!(rmargs[0] =3D fw::GspArgumentsCached::new(&cmdq))?; - dma_write!(libos[3] =3D LibosMemoryRegionInitArgument::new("RM= ARGS", &rmargs))?; =20 Ok(try_pin_init!(Self { - libos, - loginit, - logintr, - logrm, - rmargs, - cmdq, + libos: CoherentAllocation::= ::alloc_coherent( + dev, + GSP_PAGE_SIZE / size_of::(), + GFP_KERNEL | __GFP_ZERO, + )?, + loginit: LogBuffer::new(dev)?, + logintr: LogBuffer::new(dev)?, + logrm: LogBuffer::new(dev)?, + cmdq: Cmdq::new(dev)?, + rmargs: CoherentAllocation::::alloc_co= herent( + dev, + 1, + GFP_KERNEL | __GFP_ZERO, + )?, + _: { + // Initialise the logging structures. The OpenRM equiv= alents are in: + // _kgspInitLibosLoggingStructures (allocates memory f= or buffers) + // kgspSetupLibosInitArgs_IMPL (creates pLibosInitArgs= [] array) + dma_write!( + libos[0] =3D LibosMemoryRegionInitArgument::new("L= OGINIT", &loginit.0) + )?; + dma_write!( + libos[1] =3D LibosMemoryRegionInitArgument::new("L= OGINTR", &logintr.0) + )?; + dma_write!(libos[2] =3D LibosMemoryRegionInitArgument:= :new("LOGRM", &logrm.0))?; + dma_write!(rmargs[0] =3D fw::GspArgumentsCached::new(c= mdq))?; + dma_write!(libos[3] =3D LibosMemoryRegionInitArgument:= :new("RMARGS", rmargs))?; + }, })) }) } --=20 2.52.0