Skip to content

Commit 4092e1b

Browse files
GnurouDanilo Krummrich
authored andcommitted
gpu: nova-core: replace Duration with Delta
The kernel's `Delta` type was not available when the `wait_on` function was introduced. Now that it is, switch to it as it is more compact than `Duration` and cannot panic. Signed-off-by: Alexandre Courbot <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Danilo Krummrich <[email protected]>
1 parent d612799 commit 4092e1b

File tree

4 files changed

+13
-16
lines changed

4 files changed

+13
-16
lines changed

drivers/gpu/nova-core/falcon.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
//! Falcon microprocessor base support
44
55
use core::ops::Deref;
6-
use core::time::Duration;
76
use hal::FalconHal;
87
use kernel::bindings;
98
use kernel::device;
109
use kernel::prelude::*;
10+
use kernel::time::Delta;
1111
use kernel::types::ARef;
1212

1313
use crate::dma::DmaObject;
@@ -353,7 +353,7 @@ impl<E: FalconEngine + 'static> Falcon<E> {
353353
/// Wait for memory scrubbing to complete.
354354
fn reset_wait_mem_scrubbing(&self, bar: &Bar0) -> Result {
355355
// TIMEOUT: memory scrubbing should complete in less than 20ms.
356-
util::wait_on(Duration::from_millis(20), || {
356+
util::wait_on(Delta::from_millis(20), || {
357357
if regs::NV_PFALCON_FALCON_HWCFG2::read(bar, E::BASE).mem_scrubbing_done() {
358358
Some(())
359359
} else {
@@ -368,7 +368,7 @@ impl<E: FalconEngine + 'static> Falcon<E> {
368368

369369
// According to OpenRM's `kflcnPreResetWait_GA102` documentation, HW sometimes does not set
370370
// RESET_READY so a non-failing timeout is used.
371-
let _ = util::wait_on(Duration::from_micros(150), || {
371+
let _ = util::wait_on(Delta::from_micros(150), || {
372372
let r = regs::NV_PFALCON_FALCON_HWCFG2::read(bar, E::BASE);
373373
if r.reset_ready() {
374374
Some(())
@@ -381,7 +381,7 @@ impl<E: FalconEngine + 'static> Falcon<E> {
381381

382382
// TODO[DLAY]: replace with udelay() or equivalent once available.
383383
// TIMEOUT: falcon engine should not take more than 10us to reset.
384-
let _: Result = util::wait_on(Duration::from_micros(10), || None);
384+
let _: Result = util::wait_on(Delta::from_micros(10), || None);
385385

386386
regs::NV_PFALCON_FALCON_ENGINE::alter(bar, E::BASE, |v| v.set_reset(false));
387387

@@ -472,7 +472,7 @@ impl<E: FalconEngine + 'static> Falcon<E> {
472472
// Wait for the transfer to complete.
473473
// TIMEOUT: arbitrarily large value, no DMA transfer to the falcon's small memories
474474
// should ever take that long.
475-
util::wait_on(Duration::from_secs(2), || {
475+
util::wait_on(Delta::from_secs(2), || {
476476
let r = regs::NV_PFALCON_FALCON_DMATRFCMD::read(bar, E::BASE);
477477
if r.idle() {
478478
Some(())
@@ -542,7 +542,7 @@ impl<E: FalconEngine + 'static> Falcon<E> {
542542
}
543543

544544
// TIMEOUT: arbitrarily large value, firmwares should complete in less than 2 seconds.
545-
util::wait_on(Duration::from_secs(2), || {
545+
util::wait_on(Delta::from_secs(2), || {
546546
let r = regs::NV_PFALCON_FALCON_CPUCTL::read(bar, E::BASE);
547547
if r.halted() {
548548
Some(())

drivers/gpu/nova-core/falcon/hal/ga102.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
// SPDX-License-Identifier: GPL-2.0
22

33
use core::marker::PhantomData;
4-
use core::time::Duration;
54

65
use kernel::device;
76
use kernel::prelude::*;
7+
use kernel::time::Delta;
88

99
use crate::driver::Bar0;
1010
use crate::falcon::{
@@ -23,7 +23,7 @@ fn select_core_ga102<E: FalconEngine>(bar: &Bar0) -> Result {
2323
.write(bar, E::BASE);
2424

2525
// TIMEOUT: falcon core should take less than 10ms to report being enabled.
26-
util::wait_on(Duration::from_millis(10), || {
26+
util::wait_on(Delta::from_millis(10), || {
2727
let r = regs::NV_PRISCV_RISCV_BCR_CTRL::read(bar, E::BASE);
2828
if r.valid() {
2929
Some(())

drivers/gpu/nova-core/gfw.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,9 @@
66
//! the GPU is considered unusable until this step is completed, so we must wait on it before
77
//! performing driver initialization.
88
9-
use core::time::Duration;
10-
119
use kernel::bindings;
1210
use kernel::prelude::*;
11+
use kernel::time::Delta;
1312

1413
use crate::driver::Bar0;
1514
use crate::regs;
@@ -19,7 +18,7 @@ use crate::util;
1918
pub(crate) fn wait_gfw_boot_completion(bar: &Bar0) -> Result {
2019
// TIMEOUT: arbitrarily large value. GFW starts running immediately after the GPU is put out of
2120
// reset, and should complete in less time than that.
22-
util::wait_on(Duration::from_secs(4), || {
21+
util::wait_on(Delta::from_secs(4), || {
2322
// Check that FWSEC has lowered its protection level before reading the GFW_BOOT
2423
// status.
2524
let gfw_booted = regs::NV_PGC6_AON_SECURE_SCRATCH_GROUP_05_PRIV_LEVEL_MASK::read(bar)

drivers/gpu/nova-core/util.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
// SPDX-License-Identifier: GPL-2.0
22

3-
use core::time::Duration;
4-
53
use kernel::prelude::*;
6-
use kernel::time::Instant;
4+
use kernel::time::{Delta, Instant};
75

86
pub(crate) const fn to_lowercase_bytes<const N: usize>(s: &str) -> [u8; N] {
97
let src = s.as_bytes();
@@ -34,15 +32,15 @@ pub(crate) const fn const_bytes_to_str(bytes: &[u8]) -> &str {
3432
///
3533
/// TODO[DLAY]: replace with `read_poll_timeout` once it is available.
3634
/// (https://lore.kernel.org/lkml/[email protected]/)
37-
pub(crate) fn wait_on<R, F: Fn() -> Option<R>>(timeout: Duration, cond: F) -> Result<R> {
35+
pub(crate) fn wait_on<R, F: Fn() -> Option<R>>(timeout: Delta, cond: F) -> Result<R> {
3836
let start_time = Instant::now();
3937

4038
loop {
4139
if let Some(ret) = cond() {
4240
return Ok(ret);
4341
}
4442

45-
if start_time.elapsed().as_nanos() > timeout.as_nanos() as i64 {
43+
if start_time.elapsed().as_nanos() > timeout.as_nanos() {
4644
return Err(ETIMEDOUT);
4745
}
4846
}

0 commit comments

Comments
 (0)