gpu: nova-core: replace `Duration` with `Delta`
Subsystems (3)
Alexandre Courbot
maintainerPATCH 1/1 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]>
--- drivers/gpu/nova-core/falcon.rs | 12 ++++++------ drivers/gpu/nova-core/falcon/hal/ga102.rs | 4 ++-- drivers/gpu/nova-core/gfw.rs | 5 ++--- drivers/gpu/nova-core/util.rs | 8 +++----- 4 files changed, 13 insertions(+), 16 deletions(-)
drivers/gpu/nova-core/falcon.rs +6 -6
@@ -3,11 +3,11 @@//! Falcon microprocessor base support use core::ops::Deref ; -use core::time::Duration ;use hal::FalconHal ;use kernel::bindings;use kernel::device;use kernel::prelude::*; +use kernel::time::Delta ;use kernel::types::ARef ;use crate ::dma::DmaObject ;
@@ -334,7 +334,7 @@ pub(crate) fn new(/// Wait for memory scrubbing to complete. fn reset_wait_mem_scrubbing (&self, bar: &Bar0 ) ->Result {// TIMEOUT: memory scrubbing should complete in less than 20ms. - util::wait_on (Duration ::from_millis (20 ), || { + util::wait_on (Delta ::from_millis (20 ), || {if regs::NV_PFALCON_FALCON_HWCFG2 ::read (bar,E ::BASE ).mem_scrubbing_done () {Some (()) }else {
@@ -349,7 +349,7 @@ fn reset_eng(&self, bar: &Bar0) -> Result {// According to OpenRM's `kflcnPreResetWait_GA102` documentation, HW sometimes does not set // RESET_READY so a non-failing timeout is used. - let _ = util::wait_on(Duration::from_micros(150), || { + let _ = util::wait_on(Delta::from_micros(150), || { let r = regs::NV_PFALCON_FALCON_HWCFG2::read(bar, E::BASE); if r.reset_ready() { Some(())
@@ -362,7 +362,7 @@ fn reset_eng(&self, bar: &Bar0) -> Result {// TODO[DLAY]: replace with udelay() or equivalent once available. // TIMEOUT: falcon engine should not take more than 10us to reset. -let _:Result = util::wait_on (Duration ::from_micros (10 ), ||None ); +let _:Result = util::wait_on (Delta ::from_micros (10 ), ||None ); regs::NV_PFALCON_FALCON_ENGINE ::alter (bar,E ::BASE , |v| v.set_reset (false ));
@@ -453,7 +453,7 @@ fn dma_wr<F: FalconFirmware<Target = E>>(// Wait for the transfer to complete. // TIMEOUT: arbitrarily large value, no DMA transfer to the falcon's small memories // should ever take that long. - util::wait_on (Duration ::from_secs (2 ), || { + util::wait_on (Delta ::from_secs (2 ), || {let r = regs::NV_PFALCON_FALCON_DMATRFCMD ::read (bar,E ::BASE );if r.idle () {Some (())
@@ -523,7 +523,7 @@ pub(crate) fn boot( }// TIMEOUT: arbitrarily large value, firmwares should complete in less than 2 seconds. - util::wait_on (Duration ::from_secs (2 ), || { + util::wait_on (Delta ::from_secs (2 ), || {let r = regs::NV_PFALCON_FALCON_CPUCTL ::read (bar,E ::BASE );if r.halted () {Some (())
drivers/gpu/nova-core/falcon/hal/ga102.rs +2 -2
@@ -1,10 +1,10 @@// SPDX-License-Identifier: GPL-2.0 use core::marker::PhantomData ; -use core::time::Duration ;use kernel::device;use kernel::prelude::*; +use kernel::time::Delta ;use crate ::driver::Bar0 ;use crate ::falcon::{
@@ -23,7 +23,7 @@ fn select_core_ga102<E: FalconEngine>(bar: &Bar0) -> Result { .write(bar, E::BASE);// TIMEOUT: falcon core should take less than 10ms to report being enabled. - util::wait_on (Duration ::from_millis (10 ), || { + util::wait_on (Delta ::from_millis (10 ), || {let r = regs::NV_PRISCV_RISCV_BCR_CTRL ::read (bar,E ::BASE );if r.valid () {Some (())
drivers/gpu/nova-core/gfw.rs +2 -3
@@ -6,10 +6,9 @@//! the GPU is considered unusable until this step is completed, so we must wait on it before //! performing driver initialization. -use core::time::Duration ; -use kernel::bindings;use kernel::prelude::*; +use kernel::time::Delta ;use crate ::driver::Bar0 ;use crate ::regs;
@@ -19,7 +18,7 @@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 (Duration ::from_secs (4 ), || { + 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)
drivers/gpu/nova-core/util.rs +3 -5
@@ -1,9 +1,7 @@// SPDX-License-Identifier: GPL-2.0 -use core::time::Duration ; -use kernel::prelude::*; -use kernel::time::Instant ; +use kernel::time::{Delta ,Instant };pub (crate )const fn to_lowercase_bytes <const N :usize >(s: &str ) -> [u8 ;N ] {let src = s.as_bytes ();
@@ -34,7 +32,7 @@ pub(crate) const fn const_bytes_to_str(bytes: &[u8]) -> &str {/// /// 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:Duration , cond:F ) ->Result <R > { +pub (crate )fn wait_on <R ,F :Fn () ->Option <R >>(timeout:Delta , cond:F ) ->Result <R > {let start_time =Instant ::now ();loop {
@@ -42,7 +40,7 @@ pub(crate) fn wait_on<R, F: Fn() -> Option<R>>(timeout: Duration, cond: F) -> Rereturn Ok (ret); } -if start_time.elapsed ().as_nanos () > timeout.as_nanos ()as i64 { +if start_time.elapsed ().as_nanos () > timeout.as_nanos () {return Err (ETIMEDOUT ); } }
---
base-commit: 3606620b316c29e3de8ff87b40828c722086a9c9
change-id: 20250624-nova-delta-f2fecb58be8d
Best regards,
Signature · 1 line
Alexandre Courbot <[email protected]>
Quoted 5 lines · Alexandre Courbot
The kernel's
Deltatype was not available when thewait_onfunction was introduced. Now that it is, switch to it as it is more compact thanDurationand cannot panic.Signed-off-by Alexandre Courbot <[email protected]>
Applied to nova-next, thanks!