From: Matteo Kloiber <kernel@matt3o12.de>
To: Danilo Krummrich <dakr@kernel.org>,
Alexandre Courbot <acourbot@nvidia.com>,
Alice Ryhl <aliceryhl@google.com>,
Abdiel Janulgue <abdiel.janulgue@gmail.com>,
Robin Murphy <robin.murphy@arm.com>,
Andreas Hindborg <a.hindborg@kernel.org>,
Gary Guo <gary@garyguo.net>
Cc: "Daniel Almeida" <daniel.almeida@collabora.com>,
"Miguel Ojeda" <ojeda@kernel.org>,
"David Airlie" <airlied@gmail.com>,
"Simona Vetter" <simona@ffwll.ch>,
"Bjorn Helgaas" <bhelgaas@google.com>,
"Krzysztof Wilczyński" <kwilczynski@kernel.org>,
"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
rust-for-linux@vger.kernel.org, driver-core@lists.linux.dev,
dri-devel@lists.freedesktop.org, nova-gpu@lists.linux.dev,
linux-kernel@vger.kernel.org,
"Matteo Kloiber" <kernel@matt3o12.de>
Subject: [RFC PATCH 2/3] gpu: nova-core: build Gpu inside pin_init_scope
Date: Mon, 23 Nov 2026 21:39:25 +0100 [thread overview]
Message-ID: <20261123203926.1787169-3-kernel@matt3o12.de> (raw)
In-Reply-To: <20261123203926.1787169-1-kernel@matt3o12.de>
Gpu::new() sets the DMA mask and maximum segment size from inside the
try_pin_init!() initializer, after Tree::new(). A follow-up change
replaces these setters with a DMA configuration step that returns a
handle, and that handle must be available to several fields of the
initializer.
Wrap the initializer in pin_init_scope(), compute the chip spec before
it, and set the DMA parameters right after the spec is known. This
keeps the reindentation out of the follow-up change.
No functional change, except that the DMA parameters are now set
before Tree::new() instead of after it.
Signed-off-by: Matteo Kloiber <kernel@matt3o12.de>
---
drivers/gpu/nova-core/gpu.rs | 233 ++++++++++++++++++-----------------
1 file changed, 118 insertions(+), 115 deletions(-)
diff --git a/drivers/gpu/nova-core/gpu.rs b/drivers/gpu/nova-core/gpu.rs
index 8ab1687847ff..993f1512c391 100644
--- a/drivers/gpu/nova-core/gpu.rs
+++ b/drivers/gpu/nova-core/gpu.rs
@@ -455,142 +455,145 @@ pub(crate) fn new<'a>(
) -> impl PinInit<Self, Error> + use<'gpu, 'a> {
let dev = pdev.as_ref();
- try_pin_init!(Self {
- spec: Spec::new(dev, bar).inspect(|spec| {
- dev_info!(dev,"NVIDIA ({})\n", spec);
- })?,
+ pin_init::pin_init_scope(move || {
+ let spec = Spec::new(dev, bar).inspect(|spec| {
+ dev_info!(dev, "NVIDIA ({})\n", spec);
+ })?;
+ let dma_mask = hal::gpu_hal(spec.chipset).dma_mask();
+ // SAFETY: `Gpu` owns all DMA allocations for this device, and we are
+ // still constructing it, so no concurrent DMA allocations can exist.
+ unsafe { pdev.dma_set_mask_and_coherent(dma_mask)? };
+
+ // Nova walks SG segments to build page tables, so their length is
+ // irrelevant to the device.
+ //
+ // SAFETY: `Gpu` owns all DMA allocations for this device, and we are
+ // still constructing it, so no concurrent DMA allocations can exist.
+ unsafe { pdev.dma_set_max_seg_size(u32::MAX) };
+
+ Ok(try_pin_init!(Self {
+ spec,
+
+ tree: Tree::new(pdev, bar, spec.chipset, irq::gsp::GSP_SUBTREE.into())?,
+
+ _: {
+ // We must wait for GFW_BOOT completion before doing any significant setup on
+ // the GPU.
+ Self::wait_gfw_boot_completion(dev, bar, spec.chipset)?;
+ },
- tree: Tree::new(pdev, bar, spec.chipset, irq::gsp::GSP_SUBTREE.into())?,
+ // Initialize this early because `gsp_resources` depends on it.
+ sysmem_flush: SysmemFlush::register(dev, bar, spec.chipset)?,
- _: {
- let dma_mask = hal::gpu_hal(spec.chipset).dma_mask();
+ gsp_resources <- try_pin_init!(GspResources {
+ device: pdev,
- // SAFETY: `Gpu` owns all DMA allocations for this device, and we are
- // still constructing it, so no concurrent DMA allocations can exist.
- unsafe { pdev.dma_set_mask_and_coherent(dma_mask)? };
+ spec: *spec,
- // Nova walks SG segments to build page tables, so their length is
- // irrelevant to the device.
- //
- // SAFETY: `Gpu` owns all DMA allocations for this device, and we are
- // still constructing it, so no concurrent DMA allocations can exist.
- unsafe { pdev.dma_set_max_seg_size(u32::MAX) };
+ bar,
- // We must wait for GFW_BOOT completion before doing any significant setup on the GPU.
- Self::wait_gfw_boot_completion(dev, bar, spec.chipset)?;
- },
+ gsp_falcon: Falcon::new(dev, spec.chipset, bar)?,
- // Initialize this early because `gsp_resources` depends on it.
- sysmem_flush: SysmemFlush::register(dev, bar, spec.chipset)?,
+ sec2_falcon: Falcon::new(dev, spec.chipset, bar)?,
- gsp_resources <- try_pin_init!(GspResources {
- device: pdev,
+ fsp: Fsp::try_new(dev, bar, spec.chipset)?,
- spec: *spec,
+ timer: Timer::setup(dev, bar, spec.chipset, fsp.as_ref())?,
- bar,
+ vgpu: VgpuManager::new(pdev, spec.chipset, fsp.as_mut()),
- gsp_falcon: Falcon::new(dev, spec.chipset, bar)?,
+ gsp <- Gsp::new(pdev, bar),
- sec2_falcon: Falcon::new(dev, spec.chipset, bar)?,
+ // This member must be initialized last, so the `UnloadBundle` can never be
+ // dropped from outside of the constructed `GspResources`, ensuring that the
+ // unload sequence is properly run in case of failure.
+ unload_bundle: gsp.boot(GspBootContext {
+ pdev,
+ bar,
+ chipset: spec.chipset,
+ gsp_falcon,
+ sec2_falcon,
+ fsp: fsp.as_mut(),
+ vgpu,
+ })?,
+ }),
- fsp: Fsp::try_new(dev, bar, spec.chipset)?,
+ _: {
+ irq::gsp::quiesce(tree.get_ref(), &gsp_resources.gsp_falcon);
+ },
- timer: Timer::setup(dev, bar, spec.chipset, fsp.as_ref())?,
+ // SAFETY: The registration is owned by `Gpu`, which is dropped when the device is
+ // unbound, so the registration's `Drop` runs.
+ _gsp_subtree <- unsafe {
+ GspSubtree::new(
+ pdev,
+ tree.get_ref(),
+ &gsp_resources.get_ref().gsp_falcon,
+ &gsp_resources.get_ref().gsp.cmdq,
+ )
+ },
- vgpu: VgpuManager::new(pdev, spec.chipset, fsp.as_mut()),
+ // No interrupt announces the messages that the GSP posted during boot, before the
+ // SWGEN0 latch was cleared.
+ _: {
+ gsp_resources.gsp.cmdq.drain()?;
+ },
- gsp <- Gsp::new(pdev, bar),
+ gsp_static_info: {
+ // Obtain and display basic GPU information.
+ let info = gsp_resources.gsp.get_static_info()?;
+ match info.gpu_name() {
+ Ok(name) => dev_info!(dev, "GPU name: {}\n", name),
+ Err(e) => dev_warn!(dev, "GPU name unavailable: {:?}\n", e),
+ }
- // This member must be initialized last, so the `UnloadBundle` can never be dropped
- // from outside of the constructed `GspResources`, ensuring that the unload sequence
- // is properly run in case of failure.
- unload_bundle: gsp.boot(GspBootContext {
- pdev,
- bar,
- chipset: spec.chipset,
- gsp_falcon,
- sec2_falcon,
- fsp: fsp.as_mut(),
- vgpu,
- })?,
- }),
-
- _: {
- irq::gsp::quiesce(tree.get_ref(), &gsp_resources.gsp_falcon);
- },
-
- // SAFETY: The registration is owned by `Gpu`, which is dropped when the device is
- // unbound, so the registration's `Drop` runs.
- _gsp_subtree <- unsafe {
- GspSubtree::new(
- pdev,
- tree.get_ref(),
- &gsp_resources.get_ref().gsp_falcon,
- &gsp_resources.get_ref().gsp.cmdq,
- )
- },
-
- // No interrupt announces the messages that the GSP posted during boot, before the
- // SWGEN0 latch was cleared.
- _: {
- gsp_resources.gsp.cmdq.drain()?;
- },
-
- gsp_static_info: {
- // Obtain and display basic GPU information.
- let info = gsp_resources.gsp.get_static_info()?;
- match info.gpu_name() {
- Ok(name) => dev_info!(dev, "GPU name: {}\n", name),
- Err(e) => dev_warn!(dev, "GPU name unavailable: {:?}\n", e),
- }
+ if !info.usable_fb_regions.is_empty() {
+ dev_dbg!(dev, "Usable FB regions:\n");
+ for region in &info.usable_fb_regions {
+ dev_dbg!(dev, " - {:#x?}\n", region);
+ }
- if !info.usable_fb_regions.is_empty() {
- dev_dbg!(dev, "Usable FB regions:\n");
- for region in &info.usable_fb_regions {
- dev_dbg!(dev, " - {:#x?}\n", region);
+ dev_dbg!(
+ dev,
+ "Total usable VRAM: {} MiB\n",
+ info.vram_size() / u64::SZ_1M
+ );
}
- dev_dbg!(
- dev,
- "Total usable VRAM: {} MiB\n",
- info.vram_size() / u64::SZ_1M
- );
- }
-
- info
- },
+ info
+ },
- // Create GPU memory manager owning memory management resources.
- mm: {
- let usable_vram = gsp_static_info.usable_fb_regions.first().ok_or(ENODEV)?;
- let buddy_params = GpuBuddyParams {
- base_offset: usable_vram.start,
- size: usable_vram.end - usable_vram.start,
- chunk_size: Alignment::SZ_4K,
- };
+ // Create GPU memory manager owning memory management resources.
+ mm: {
+ let usable_vram = gsp_static_info.usable_fb_regions.first().ok_or(ENODEV)?;
+ let buddy_params = GpuBuddyParams {
+ base_offset: usable_vram.start,
+ size: usable_vram.end - usable_vram.start,
+ chunk_size: Alignment::SZ_4K,
+ };
+
+ GpuMm::new(
+ bar,
+ gsp_resources.spec.chipset,
+ buddy_params,
+ VramAddress::from_raw(gsp_static_info.total_fb_end),
+ )?
+ },
- GpuMm::new(
- bar,
- gsp_resources.spec.chipset,
- buddy_params,
- VramAddress::from_raw(gsp_static_info.total_fb_end),
- )?
- },
-
- // Create BAR1 user interface for CPU access to GPU virtual memory.
- bar_user <- {
- let pdb_addr = VramAddress::from_raw(gsp_static_info.bar1_pde_base);
- let bar1_idx = crate::driver::bar1_resource_index(pdev)?;
- let bar1_size = pdev.resource_len(bar1_idx)?;
-
- BarUser::new(
- pdb_addr,
- gsp_resources.spec.chipset,
- bar1_size,
- bar1,
- )
- },
+ // Create BAR1 user interface for CPU access to GPU virtual memory.
+ bar_user <- {
+ let pdb_addr = VramAddress::from_raw(gsp_static_info.bar1_pde_base);
+ let bar1_idx = crate::driver::bar1_resource_index(pdev)?;
+ let bar1_size = pdev.resource_len(bar1_idx)?;
+
+ BarUser::new(
+ pdb_addr,
+ gsp_resources.spec.chipset,
+ bar1_size,
+ bar1,
+ )
+ },
+ }))
})
}
--
2.51.2
next prev parent reply other threads:[~2026-11-23 20:39 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-23 20:39 [RFC PATCH 0/3] rust: dma: require device configuration before DMA Matteo Kloiber
2026-11-23 20:39 ` [RFC PATCH 1/3] rust: pci, platform: pass InitTokens to probe() Matteo Kloiber
2026-11-23 20:39 ` Matteo Kloiber [this message]
2026-11-23 20:39 ` [RFC PATCH 3/3] rust: dma: require device configuration before DMA Matteo Kloiber
2026-11-23 20:52 ` sashiko-bot
2026-11-23 23:49 ` [RFC PATCH 0/3] " Danilo Krummrich
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=20261123203926.1787169-3-kernel@matt3o12.de \
--to=kernel@matt3o12.de \
--cc=a.hindborg@kernel.org \
--cc=abdiel.janulgue@gmail.com \
--cc=acourbot@nvidia.com \
--cc=airlied@gmail.com \
--cc=aliceryhl@google.com \
--cc=bhelgaas@google.com \
--cc=dakr@kernel.org \
--cc=daniel.almeida@collabora.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=driver-core@lists.linux.dev \
--cc=gary@garyguo.net \
--cc=gregkh@linuxfoundation.org \
--cc=kwilczynski@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=nova-gpu@lists.linux.dev \
--cc=ojeda@kernel.org \
--cc=robin.murphy@arm.com \
--cc=rust-for-linux@vger.kernel.org \
--cc=simona@ffwll.ch \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.