Files
erofs-linux/drivers/gpu/nova-core/util.rs
T
Alexandre Courbot b345c917d7 gpu: nova-core: add Chipset::name() method
There are a few cases where we need the lowercase name of a given
chipset, notably to resolve firmware files paths for dynamic loading or
to build the module information.

So far, we relied on a static `NAMES` array for the latter, and some
CString hackery for the former.

Replace both with a new `name` const method that returns the lowercase
name of a chipset instance. We can generate it using the `paste!` macro.

Using this method removes the need to create a `CString` when loading
firmware, and lets us remove a couple of utility functions that now have
no user.

Acked-by: Danilo Krummrich <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Alexandre Courbot <[email protected]>
2025-09-13 23:17:24 +09:00

28 lines
844 B
Rust

// 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);
}
}
}