Skip to contentSkip to conversation

gpu: nova-core: replace wait_on with kernel equivalents

PATCH In review Alexandre Courbot 2 participants 2 messages Oct 20, 2025

Subsystems (7)
lore
Share & tools
lore

Alexandre Courbot

author maintainer
#0 lore raw

PATCH 1/1 gpu: nova-core: replace wait_on with kernel equivalents

wait_on was a temporary helper function waiting for a kernel crate equivalent.

Now that read_poll_timeout and fsleep are available, use them and remove wait_on.

---
 Documentation/gpu/nova/core/todo.rst      | 11 ------
 drivers/gpu/nova-core/falcon.rs           | 62 ++++++++++++++-----------------
 drivers/gpu/nova-core/falcon/hal/ga102.rs | 16 ++++----
 drivers/gpu/nova-core/gfw.rs              | 36 ++++++++----------
 drivers/gpu/nova-core/nova_core.rs        |  1 -
 drivers/gpu/nova-core/util.rs             | 27 --------------
 6 files changed, 51 insertions(+), 102 deletions(-)
Documentation/gpu/nova/core/todo.rst +0 -11
index 0972cb905f7a..c55c7bedbfdf 100644
@@ -153,17 +153,6 @@ A `num` core kernel module is being designed to provide these operations.
 | Complexity: Intermediate
 | Contact: Alexandre Courbot
 
-Delay / Sleep abstractions [DLAY]
----------------------------------
-
-Rust abstractions for the kernel's delay() and sleep() functions.
-
-FUJITA Tomonori plans to work on abstractions for read_poll_timeout_atomic()
-(and friends) [1].
-
-| Complexity: Beginner
-| Link: https://lore.kernel.org/netdev/[email protected]/ [1]
-
 IRQ abstractions
 ----------------
 
drivers/gpu/nova-core/falcon.rs +28 -34

104 lines not on this page · raw message

drivers/gpu/nova-core/falcon/hal/ga102.rs +7 -9
index 0b1cbe7853b3..f2ae9537321d 100644
@@ -3,6 +3,7 @@
 use core::marker::PhantomData;
 
 use kernel::device;
+use kernel::io::poll::read_poll_timeout;
 use kernel::prelude::*;
 use kernel::time::Delta;
 
@@ -11,7 +12,6 @@
     Falcon, FalconBromParams, FalconEngine, FalconModSelAlgo, PeregrineCoreSelect,
 };
 use crate::regs;
-use crate::util;
 
 use super::FalconHal;
 
@@ -23,14 +23,12 @@ fn select_core_ga102<E: FalconEngine>(bar: &Bar0) -> Result {
             .write(bar, &E::ID);
 
         // TIMEOUT: falcon core should take less than 10ms to report being enabled.
-        util::wait_on(Delta::from_millis(10), || {
-            let r = regs::NV_PRISCV_RISCV_BCR_CTRL::read(bar, &E::ID);
-            if r.valid() {
-                Some(())
-            } else {
-                None
-            }
-        })?;
+        read_poll_timeout(
+            || Ok(regs::NV_PRISCV_RISCV_BCR_CTRL::read(bar, &E::ID)),
+            |r| r.valid(),
+            Delta::ZERO,
+            Delta::from_millis(10),
+        )?;
     }
 
     Ok(())
drivers/gpu/nova-core/gfw.rs +16 -20
index 8ac1ed187199..23c28c2a3793 100644
@@ -18,13 +18,12 @@
 //!
 //! Note that the devinit sequence also needs to run during suspend/resume.
 
-use kernel::bindings;
+use kernel::io::poll::read_poll_timeout;
 use kernel::prelude::*;
 use kernel::time::Delta;
 
 use crate::driver::Bar0;
 use crate::regs;
-use crate::util;
 
 /// Wait for the `GFW` (GPU firmware) boot completion signal (`GFW_BOOT`), or a 4 seconds timeout.
 ///
@@ -50,22 +49,19 @@ pub(crate) fn wait_gfw_boot_completion(bar: &Bar0) -> Result {
     //
     // TIMEOUT: arbitrarily large value. GFW starts running immediately after the GPU is put out of
     // reset, and should complete in less time than that.
-    util::wait_on(Delta::from_secs(4), || {
-        // Check that FWSEC has lowered its protection level before reading the GFW_BOOT status.
-        let gfw_booted = regs::NV_PGC6_AON_SECURE_SCRATCH_GROUP_05_PRIV_LEVEL_MASK::read(bar)
-            .read_protection_level0()
-            && regs::NV_PGC6_AON_SECURE_SCRATCH_GROUP_05_0_GFW_BOOT::read(bar).completed();
-
-        if gfw_booted {
-            Some(())
-        } else {
-            // TODO[DLAY]: replace with [1] once it merges.
-            // [1] https://lore.kernel.org/rust-for-linux/[email protected]/
-            //
-            // SAFETY: `msleep()` is safe to call with any parameter.
-            unsafe { bindings::msleep(1) };
-
-            None
-        }
-    })
+    read_poll_timeout(
+        || {
+            Ok(
+                // Check that FWSEC has lowered its protection level before reading the GFW_BOOT
+                // status.
+                regs::NV_PGC6_AON_SECURE_SCRATCH_GROUP_05_PRIV_LEVEL_MASK::read(bar)
+                    .read_protection_level0()
+                    && regs::NV_PGC6_AON_SECURE_SCRATCH_GROUP_05_0_GFW_BOOT::read(bar).completed(),
+            )
+        },
+        |&gfw_booted| gfw_booted,
+        Delta::from_millis(1),
+        Delta::from_secs(4),
+    )
+    .map(|_| ())
 }
drivers/gpu/nova-core/nova_core.rs +0 -1
index fffcaee2249f..db062e31a5e2 100644
@@ -11,7 +11,6 @@
 mod gpu;
 mod gsp;
 mod regs;
-mod util;
 mod vbios;
 
 pub(crate) const MODULE_NAME: &kernel::str::CStr = <LocalModule as kernel::ModuleMetadata>::NAME;
drivers/gpu/nova-core/util.rs deleted +0 -27
deleted file mode 100644
index bf35f00cb732..000000000000
@@ -1,27 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0
-
-use kernel::prelude::*;
-use kernel::time::{Delta, Instant, Monotonic};
-
-/// Wait until `cond` is true or `timeout` elapsed.
-///
-/// When `cond` evaluates to `Some`, its return value is returned.
-///
-/// `Err(ETIMEDOUT)` is returned if `timeout` has been reached without `cond` evaluating to
-/// `Some`.
-///
-/// TODO[DLAY]: replace with `read_poll_timeout` once it is available.
-/// (https://lore.kernel.org/lkml/[email protected]/)
-pub(crate) fn wait_on<R, F: Fn() -> Option<R>>(timeout: Delta, cond: F) -> Result<R> {
-    let start_time = Instant::<Monotonic>::now();
-
-    loop {
-        if let Some(ret) = cond() {
-            return Ok(ret);
-        }
-
-        if start_time.elapsed().as_nanos() > timeout.as_nanos() {
-            return Err(ETIMEDOUT);
-        }
-    }
-}

---
base-commit: 1d5cffebd930d61588c32198f85fbe541ab97b8f
change-id: 20251020-nova_wait_on-b5b975894ab4

Best regards,

Signature · 1 line
Alexandre Courbot <[email protected]>