NVIDIA GPU driver infrastructure
 help / color / mirror / Atom feed
* [PATCH] gpu: nova-core: use a single try_pin_init!() block in probe()
@ 2026-09-27 14:44 Danilo Krummrich
  2026-09-28  0:23 ` Alexandre Courbot
                   ` (3 more replies)
  0 siblings, 4 replies; 13+ messages in thread
From: Danilo Krummrich @ 2026-09-27 14:44 UTC (permalink / raw)
  To: dakr, acourbot, aliceryhl, gary; +Cc: nova-gpu, dri-devel

Just like in Gpu::new() a single try_pin_init!() block makes the code
more readable.

Besides that, it prepares the code for a proper PCI device enable guard
that we will get soon.

Signed-off-by: Danilo Krummrich <dakr@kernel.org>
---
 drivers/gpu/nova-core/driver.rs | 105 ++++++++++++++++----------------
 1 file changed, 54 insertions(+), 51 deletions(-)

diff --git a/drivers/gpu/nova-core/driver.rs b/drivers/gpu/nova-core/driver.rs
index bdaed5408a00..623d59dcde6e 100644
--- a/drivers/gpu/nova-core/driver.rs
+++ b/drivers/gpu/nova-core/driver.rs
@@ -100,57 +100,60 @@ fn probe<'bound>(
         pdev: &'bound pci::Device<Core<'_>>,
         _info: Option<&'bound Self::IdInfo>,
     ) -> impl PinInit<Self::Data<'bound>, Error> + 'bound {
-        pin_init::pin_init_scope(move || {
-            dev_dbg!(pdev, "Probe Nova Core GPU driver.\n");
-
-            pdev.enable_device_mem()?;
-            pdev.set_master();
-
-            Ok(try_pin_init!(NovaCore {
-                bar: pdev.iomap_region_sized::<BAR0_SIZE>(0, c"nova-core/bar0")?,
-                bar1: {
-                    let bar1_idx = bar1_resource_index(pdev)?;
-                    pdev.iomap_region(bar1_idx, c"nova-core/bar1")?
-                },
-                // TODO: Use self-referential pin-init syntax once available.
-                gpu <- Gpu::new(
-                    pdev,
-                    // SAFETY: `bar` is initialized above, pinned, and outlives `gpu`.
-                    unsafe { &*core::ptr::from_ref(bar) },
-                    // SAFETY: `bar1` is initialized above, pinned, and outlives `gpu`.
-                    unsafe { &*core::ptr::from_ref(bar1) },
-                ).pin_chain(|_gpu| {
-                    #[cfg(CONFIG_NOVA_CORE_SELFTESTS)]
-                    _gpu.run_selftests(pdev);
-                    Ok(())
-                }),
-                _reg: {
-                    // TODO: Use `&gpu` self-referential pin-init syntax once available.
-                    //
-                    // SAFETY: `gpu` is initialized before this expression is evaluated
-                    // (`try_pin_init!()` initializes fields in initializer order), lives at
-                    // a pinned stable address, and is dropped after `_reg` (struct field
-                    // drop order).
-                    let gpu = unsafe {
-                        Pin::new_unchecked(&*core::ptr::from_ref(gpu.as_ref().get_ref()))
-                    };
-
-                    // SAFETY: `NovaCore` is dropped when the device is unbound;
-                    // i.e. `mem::forget()` is never called on it.
-                    unsafe {
-                        auxiliary::Registration::new_with_lt(
-                            pdev.as_ref(),
-                            c"nova-drm",
-                            // TODO[XARR]: Use XArray or perhaps IDA for proper ID
-                            // allocation/recycling. For now, use a simple atomic counter that
-                            // never recycles IDs.
-                            AUXILIARY_ID_COUNTER.fetch_add(1, Relaxed),
-                            crate::MODULE_NAME,
-                            NovaCoreApi { gpu, pdev },
-                        )?
-                    }
-                },
-            }))
+        dev_dbg!(pdev, "Probe Nova Core GPU driver.\n");
+
+        try_pin_init!(NovaCore {
+            _: {
+                pdev.enable_device_mem()?;
+                pdev.set_master();
+            },
+
+            bar: pdev.iomap_region_sized::<BAR0_SIZE>(0, c"nova-core/bar0")?,
+
+            bar1: {
+                let bar1_idx = bar1_resource_index(pdev)?;
+                pdev.iomap_region(bar1_idx, c"nova-core/bar1")?
+            },
+
+            // TODO: Use self-referential pin-init syntax once available.
+            gpu <- Gpu::new(
+                pdev,
+                // SAFETY: `bar` is initialized above, pinned, and outlives `gpu`.
+                unsafe { &*core::ptr::from_ref(bar) },
+                // SAFETY: `bar1` is initialized above, pinned, and outlives `gpu`.
+                unsafe { &*core::ptr::from_ref(bar1) },
+            ).pin_chain(|_gpu| {
+                #[cfg(CONFIG_NOVA_CORE_SELFTESTS)]
+                _gpu.run_selftests(pdev);
+                Ok(())
+            }),
+
+            _reg: {
+                // TODO: Use `&gpu` self-referential pin-init syntax once available.
+                //
+                // SAFETY: `gpu` is initialized before this expression is evaluated
+                // (`try_pin_init!()` initializes fields in initializer order), lives at
+                // a pinned stable address, and is dropped after `_reg` (struct field
+                // drop order).
+                let gpu = unsafe {
+                    Pin::new_unchecked(&*core::ptr::from_ref(gpu.as_ref().get_ref()))
+                };
+
+                // SAFETY: `NovaCore` is dropped when the device is unbound;
+                // i.e. `mem::forget()` is never called on it.
+                unsafe {
+                    auxiliary::Registration::new_with_lt(
+                        pdev.as_ref(),
+                        c"nova-drm",
+                        // TODO[XARR]: Use XArray or perhaps IDA for proper ID
+                        // allocation/recycling. For now, use a simple atomic counter that
+                        // never recycles IDs.
+                        AUXILIARY_ID_COUNTER.fetch_add(1, Relaxed),
+                        crate::MODULE_NAME,
+                        NovaCoreApi { gpu, pdev },
+                    )?
+                }
+            },
         })
     }
 }

base-commit: 10a6623a24a85708650efad7be15182289403cd7
-- 
2.55.0


^ permalink raw reply related	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2026-09-29 20:43 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-27 14:44 [PATCH] gpu: nova-core: use a single try_pin_init!() block in probe() Danilo Krummrich
2026-09-28  0:23 ` Alexandre Courbot
2026-09-28 13:48   ` Danilo Krummrich
2026-09-29 20:31     ` John Hubbard
2026-09-29 20:43       ` Danilo Krummrich
2026-09-28  4:17 ` Eliot Courtney
2026-09-28 11:36 ` Gary Guo
2026-09-28 12:00   ` Danilo Krummrich
2026-09-28 12:10     ` Gary Guo
2026-09-28 12:15       ` Danilo Krummrich
2026-09-28 13:53         ` Gary Guo
2026-09-28 13:56           ` Danilo Krummrich
2026-09-29 19:12 ` Danilo Krummrich

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox