nova-core: add initial support for gpu timer (v3)
Subsystems (6)
v3 cover nova-core: add initial support for gpu timer (v3)
The GPU has a timer, one of the pieces of information we need to pass into GSP init later is the timer offset.
This series just adds support for setting up the timer on Turing+, with hals for Turing and Hopper.
Right now it calculates the value to send to GSP but the code to send it will be added later.
For some hardware variants sending a proper value is required for GSP init to succeed.
v2 changes on second patch.
v3 fix the WAR to be hopper only (Sashiko)
---
Dave Airlie (2):
rust: time: expose as_nanos for clock sources.
gpu: nova-core: add support for GPU timer block. (v3)
drivers/gpu/nova-core/gpu.rs | 5 ++ drivers/gpu/nova-core/nova_core.rs | 1 + drivers/gpu/nova-core/timer.rs | 33 +++++++++++ drivers/gpu/nova-core/timer/hal.rs | 27 +++++++++ drivers/gpu/nova-core/timer/hal/gh100.rs | 94 ++++++++++++++++++++++++++++++++ drivers/gpu/nova-core/timer/hal/tu102.rs | 55 +++++++++++++++++++ drivers/gpu/nova-core/timer/regs.rs | 64 ++++++++++++++++++++++ rust/kernel/time.rs | 3 +- 8 files changed, 281 insertions(+), 1 deletion(-)
---
base-commit: 3497a403264b094ebd61b8b755165d56e7d9dc37
change-id: 20261102-nova-timer-f4b9de3274a1
Best regards,
Signature · 1 line
Dave Airlie <[email protected]>
PATCH v3 1/2 rust: time: expose as_nanos for clock sources.
The nouveau C driver does ktime_to_ns(ktime_get()) to program the cpu ns into some hw/fw, so allow this method for rust drivers.
--- rust/kernel/time.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
rust/kernel/time.rs +2 -1
@@ -211,8 +211,9 @@ pub fn elapsed(&self) -> Delta {Self ::now () - *self } +/// Return the raw nanoseconds values since the epoch of clock `C`. #[inline] -pub (crate )fn as_nanos (&self) ->i64 { +pub fn as_nanos (&self) ->i64 { self.inner }
Signature · 1 line
2.56.0
PATCH v3 2/2 gpu: nova-core: add support for GPU timer block. (v3)
In reply to Dave AirlieThis is needed to calculate the system timer offset that is passed to GSP init.
2 HALs exist:
a) tu102 is the gv100 path from open-gpu, the priv level is checked and the cpu time is written to the gpu timer. no offset is used.
b) gh100 as two variants, gh100 and gb100.
This is the gh100 path from open-gpu, where the secure system timer is read, the offset is calculated.
On gh100 which need a work around we avoid sending it to registers other we write the offset to registers.
The gb100 path just avoids the war.
The value is also stored to send to GSP.
--- drivers/gpu/nova-core/gpu.rs | 5 ++ drivers/gpu/nova-core/nova_core.rs | 1 + drivers/gpu/nova-core/timer.rs | 33 +++++++++++ drivers/gpu/nova-core/timer/hal.rs | 27 +++++++++ drivers/gpu/nova-core/timer/hal/gh100.rs | 94 ++++++++++++++++++++++++++++++++ drivers/gpu/nova-core/timer/hal/tu102.rs | 55 +++++++++++++++++++ drivers/gpu/nova-core/timer/regs.rs | 64 ++++++++++++++++++++++ 7 files changed, 279 insertions(+)
drivers/gpu/nova-core/gpu.rs +5 -0
@@ -53,6 +53,7 @@ GpuMm, VramAddress, // }, + timer::Timer, vgpu::VgpuManager, // };
@@ -331,6 +332,8 @@ struct GspResources<'gpu> {// TODO: use different resource types for each boot method, and make the relevant Gsp methods // generic against them. fsp: Option<Fsp<'gpu>>, + /// Timer instance - contains system timer offset + timer: Timer,/// vGPU state detected before GSP boot. vgpu: VgpuManager,/// GSP runtime data.
@@ -497,6 +500,8 @@ pub(crate) fn new<'a>( fsp: Fsp::try_new(dev, bar, spec.chipset)?, + timer: Timer::new(bar, spec.chipset)?, + vgpu: VgpuManager::new(pdev, spec.chipset, fsp.as_mut()), gsp <- Gsp::new(pdev, bar),
drivers/gpu/nova-core/nova_core.rs +1 -0
@@ -27,6 +27,7 @@mod sbuffer;#[cfg( CONFIG_NOVA_CORE_SELFTESTS )] mod selftest; +mod timer;mod vbios;mod vgpu;
drivers/gpu/nova-core/timer.rs new file +33 -0
@@ -0,0 +1,33 @@ +// SPDX-License-Identifier: GPL-2.0 + +mod hal; +mod regs; + +use kernel::{ + prelude::*,// +}; + +use crate ::{ + driver::Bar0 , + gpu::Chipset ,// +}; + +// struct that just holds the sys timer offset +// after initialising the GPU timer block. +pub (crate )struct Timer { + sys_timer_offset_ns:i64 , +} + +impl Timer { +pub (crate )fn new (bar:Bar0 <'_>, chipset:Chipset ) ->Result <Self > { +Ok (Self { + sys_timer_offset_ns: hal::timer_hal (chipset).init (bar)?, + }) + } + +// this value will be passed to GspInitRequest SYS_TIMER_OFFSET_NS +#[expect(dead_code)] +pub (crate )fn sys_timer_offset_ns (&self) ->i64 { + self.sys_timer_offset_ns + } +}
drivers/gpu/nova-core/timer/hal.rs new file +27 -0
@@ -0,0 +1,27 @@ +// SPDX-License-Identifier: GPL-2.0 + +use kernel::prelude::*; + +use crate ::{ + driver::Bar0 , + gpu::{ +Architecture , +Chipset ,// + }, +}; + +mod gh100; +mod tu102; + +pub (super )trait TimerHal { +/// return system timer offset ns +fn init (&self, bar:Bar0 <'_>) ->Result <i64 >; +} + +pub (super )fn timer_hal (chipset:Chipset ) -> &'staticdyn TimerHal { +match chipset.arch () { +Architecture ::Turing |Architecture ::Ampere |Architecture ::Ada => tu102::TU102_HAL , +Architecture ::Hopper => gh100::GH100_HAL , +Architecture ::BlackwellGB10x |Architecture ::BlackwellGB20x => gh100::GB100_HAL , + } +}
drivers/gpu/nova-core/timer/hal/gh100.rs new file +94 -0
94 lines not on this page · raw message
drivers/gpu/nova-core/timer/hal/tu102.rs new file +55 -0
55 lines not on this page · raw message
drivers/gpu/nova-core/timer/regs.rs new file +64 -0
64 lines not on this page · raw message
Signature · 1 line
2.56.0
Danilo Krummrich
maintainerRe: [PATCH v3 2/2] gpu: nova-core: add support for GPU timer block. (v3)
drivers/gpu/nova-core/timer.rs line 19
Quoted 5 lines · On Tue Nov 3, 2026 at 1:33 AM CET, Dave Airlie via B4 Relay wrote:
drivers/gpu/nova-core/timer.rs new file +5
-0+// struct that just holds the sys timer offset +// after initialising the GPU timer block. +pub (crate )struct Timer { + sys_timer_offset_ns:i64 , +}
I feel like this should actually be TimerState, as it is not really a timer (instance) representation in the sense of carrying the HAL and providing methods to interact with the hardware (which we do not intend).
I'd suggest making Timer a unit struct and giving it an init() function, i.e. something like this:
struct Timer;
struct TimerState {
sys_timer_offset_ns: i64,
}
impl Timer {
/// Initialize the GPU's system timer.
pub(crate) fn init(bar: Bar0<'_>, chipset: Chipset) -> Result<TimerState>;
}drivers/gpu/nova-core/timer.rs line 28
Quoted 9 lines
drivers/gpu/nova-core/timer.rs new file +9
-0+ +impl Timer { +pub (crate )fn new (bar:Bar0 <'_>, chipset:Chipset ) ->Result <Self > { +Ok (Self { + sys_timer_offset_ns: hal::timer_hal (chipset).init (bar)?, + }) + } + +// this value will be passed to GspInitRequest SYS_TIMER_OFFSET_NS
NIT: This should describe what the returned value represents, although in this specific case it may also still make sense to give a hint how it is used.
Please use intra-doc links and markdown where it makes sense.
Quoted 18 lines
drivers/gpu/nova-core/timer.rs new file +5
-0+#[expect(dead_code)] +pub (crate )fn sys_timer_offset_ns (&self) ->i64 { + self.sys_timer_offset_ns + } +}drivers/gpu/nova-core/timer/hal.rs new file +7
-0@@ -0,0 +1,27 @@ +// SPDX-License-Identifier: GPL-2.0 + +use kernel::prelude::*; + +use crate ::{ + driver::Bar0 , + gpu::{
drivers/gpu/nova-core/timer/hal.rs line 17
Quoted 10 lines
drivers/gpu/nova-core/timer/hal.rs new file +10
-0+ Architecture, + Chipset, // + }, +}; + +mod gh100; +mod tu102; + +pub (super )trait TimerHal { +/// return system timer offset ns
NIT:
/// Initialize the GPU's system timer. /// /// Returns the system timer offset in nanoseconds.
Quoted 40 lines
drivers/gpu/nova-core/timer/hal.rs new file +10
-0+fn init (&self, bar:Bar0 <'_>) ->Result <i64 >; +} + +pub (super )fn timer_hal (chipset:Chipset ) -> &'staticdyn TimerHal { +match chipset.arch () { +Architecture ::Turing |Architecture ::Ampere |Architecture ::Ada => tu102::TU102_HAL , +Architecture ::Hopper => gh100::GH100_HAL , +Architecture ::BlackwellGB10x |Architecture ::BlackwellGB20x => gh100::GB100_HAL , + } +}drivers/gpu/nova-core/timer/hal/gh100.rs new file +24
-0@@ -0,0 +1,94 @@ +// SPDX-License-Identifier: GPL-2.0 + +use super ::TimerHal ; + +use kernel::{ + io::Io , + prelude::*, + time::*,// +}; + +use crate ::{ + driver::Bar0 , + timer::regs,// +}; + +/// Timer HAL for Hopper and Blackwell. +struct Gh100 { +/// `true` on Hopper, the only architecture where the FSP ucode can predate the fix for +/// bug 3957833 and hence the sys timer offset must not be programmed. Blackwell FSP +/// always includes the fix. + fsp_bug3957833_war:bool , +} + +/// FSP ucode version from which on the fix for bug 3957833 is included.
drivers/gpu/nova-core/timer/hal/gh100.rs line 34
Quoted 10 lines
drivers/gpu/nova-core/timer/hal/gh100.rs new file +10
-0+const FSP_BUG_3957833_FIX_VERSION :u32 =0x44c ; + +impl Gh100 { +/// kfspRequiresBug3957833WAR_HAL: returns `true` if the FSP ucode predates the fix for +/// bug 3957833 and hence the sys timer offset must not be programmed. The RM implements +/// the version check for GH100 only; for all later chips it defaults to `false`. +fn requires_bug3957833_war (&self, bar:Bar0 <'_>) ->bool { + self.fsp_bug3957833_war + && bar.read (regs::gh100::NV_GFW_FSP_UCODE_VERSION ).full ().get () + <FSP_BUG_3957833_FIX_VERSION
I'd move this into regs.rs and make it a method of NV_GFW_FSP_UCODE_VERSION, e.g.
impl NV_GFW_FSP_UCODE_VERSION {
pub(crate) fn is_bug_3957833_affected(self) -> bool {
const FSP_BUG_3957833_FIX_VERSION: u32 = 0x44c;
self.full().get() < FSP_BUG_3957833_FIX_VERSION
}
}so you can just call
bar.read(regs::gh100::NV_GFW_FSP_UCODE_VERSION).is_bug_3957833_affected()
This also keeps FSP_BUG_3957833_FIX_VERSION local to regs.rs and gets us rid of this HAL function.
drivers/gpu/nova-core/timer/hal/gh100.rs line 37
Quoted 3 lines
drivers/gpu/nova-core/timer/hal/gh100.rs new file +3
-0+ } + +fn timer_time (&self, bar:Bar0 <'_>, time_ns:i64 ) ->Result <i64 > {
Can't we just use unsigned for the argument and return type? None of those are ever expected to be negative, no?
The invariant for the argument to be non-negative comes from Instant, so I'd convert before calling into timer_time(). This should avoid the corresponding as casts below.
Quoted 4 lines
drivers/gpu/nova-core/timer/hal/gh100.rs new file +4
-0+let mut sec_hi2 = u32::from (bar.read (regs::gh100::NV_PGC6_SCI_SEC_TIMER_TIME_1 )); +let sec_timer_ns:u64 ; +loop { +let sec_lo = u32::from (bar.read (regs::gh100::NV_PGC6_SCI_SEC_TIMER_TIME_0 ));
drivers/gpu/nova-core/timer/hal/gh100.rs line 51
Quoted 10 lines
drivers/gpu/nova-core/timer/hal/gh100.rs new file +10
-0+let sec_hi = u32::from (bar.read (regs::gh100::NV_PGC6_SCI_SEC_TIMER_TIME_1 )); +if sec_hi == sec_hi2 { + sec_timer_ns = u64::from (sec_hi) <<32 | u64::from (sec_lo); +break ; + } + sec_hi2 = u32::from (bar.read (regs::gh100::NV_PGC6_SCI_SEC_TIMER_TIME_1 )); + } + +// The system and the GPU timer are both free-running with unrelated epochs, so the +// difference can be negative. Both operands are < 2^62, hence this cannot overflow.
I think we accumulated a bunch of those comments in nova-core, I think it would be nice to consider whether we want a prefix for this, similar to TIMEOUT or CALC. Maybe OVERFLOW? But this can be a follow-up of course.
On the other hand, this is a fallible method already, so I'd just go with checked_sub().
Quoted 10 lines
drivers/gpu/nova-core/timer/hal/gh100.rs new file +10
-0+let sys_timer_offset_ns = time_ns - sec_timer_nsas i64 ; + +// The offset is passed to the GSP as an unsigned value and, like in the RM's +// tmrSetCurrentTime_GH100, is required to be non-negative. With wall clock time this +// can only fail if the system clock is set behind the GPU power-on time. +if sys_timer_offset_ns <0 { +return Err (EINVAL ); + } + +if !self.requires_bug3957833_war (bar) {
drivers/gpu/nova-core/timer/hal/gh100.rs line 71
Quoted 10 lines
drivers/gpu/nova-core/timer/hal/gh100.rs new file +10
-0+let offset_ns = sys_timer_offset_nsas u64 ; + bar.write_reg ( + regs::gh100::NV_PGC6_SCI_SYS_TIMER_OFFSET_1 ::zeroed () + .try_with_nsec (((offset_ns >>32 ) &0x1fff_ffff )as u32 )?, + ); + bar.write_reg ( + regs::gh100::NV_PGC6_SCI_SYS_TIMER_OFFSET_0 ::zeroed () + .try_with_nsec (((offset_ns >>5 ) &0x7ff_ffff )as u32 )? + .with_update (true ), + );
This looks similar to NV_TLB_FLUSH_PDB_LO::from_pdb_addr(). I think we should do this in the register impl:
impl NV_PGC6_SCI_SYS_TIMER_OFFSET_1 {
/// Creates a register value from bits 60:32 of the offset.
pub(crate) fn from_offset_ns(offset_ns: u64) -> Self {
let nsec = Bounded::<u32, 29>::from_expr(
((offset_ns >> 32) & 0x1fff_ffff) as u32,
);
Self::zeroed().with_nsec(nsec)
}
}drivers/gpu/nova-core/timer/hal/gh100.rs line 82
Quoted 11 lines
drivers/gpu/nova-core/timer/hal/gh100.rs new file +11
-0+// FSP PRI space; the timer is its only consumer so far. +register! { + base:NovaRegisters ; + +/// FSP ucode version, encoded as `major.minor` in bits 11:8 and 7:0, written by the FSP +/// during boot. (`NV_PFSP_FALCON_COMMON_SCRATCH_GROUP_3(1)` in the hardware headers.) +pub (crate )NV_GFW_FSP_UCODE_VERSION (u32 ) @0x008f0334 { +11 :0 full; + } + } +}
Hm...I feel like it should go into fsp/regs.rs regardless.
Re: [PATCH v3 2/2] gpu: nova-core: add support for GPU timer block. (v3)
Quoted 7 lines
I feel like this should actually be TimerState, as it is not really a timer (instance) representation in the sense of carrying the HAL and providing methods to interact with the hardware (which we do not intend).
I'd suggest making Timer a unit struct and giving it an
init()function, i.e. something like this:
Thanks, looks cleaner, sent out in v4.
Quoted 4 lines
Quoted 1 line
+ // this value will be passed to GspInitRequest
SYS_TIMER_OFFSET_NSNIT: This should describe what the returned value represents, although in this specific case it may also still make sense to give a hint how it is used.
In theory the value doesn't represent anything, since it's hal dependant, at this
point it should be an opaque value we give to GSP in SYS_TIMER_OFFSET_NS field.
Quoted 33 lines
Please use intra-doc links and markdown where it makes sense.
Quoted 18 lines
drivers/gpu/nova-core/timer.rs new file +5
-0+#[expect(dead_code)] +pub (crate )fn sys_timer_offset_ns (&self) ->i64 { + self.sys_timer_offset_ns + } +}drivers/gpu/nova-core/timer/hal.rs new file +7
-0@@ -0,0 +1,27 @@ +// SPDX-License-Identifier: GPL-2.0 + +use kernel::prelude::*; + +use crate ::{ + driver::Bar0 , + gpu::{drivers/gpu/nova-core/timer/hal.rs line 17
Quoted 10 lines
drivers/gpu/nova-core/timer/hal.rs new file +10
-0+ Architecture, + Chipset, // + }, +}; + +mod gh100; +mod tu102; + +pub (super )trait TimerHal { +/// return system timer offset ns NIT:
Quoted 3 lines
/// Initialize the GPU's system timer.
///
/// Returns the system timer offset in nanoseconds.Just realised I missed this one in v4.
Quoted 13 lines
drivers/gpu/nova-core/timer/hal.rs line 18
Quoted 1 line
drivers/gpu/nova-core/timer/hal.rs new file +1
-0+ < FSP_BUG_3957833_FIX_VERSIONI'd move this into
regs.rsand make it a method ofNV_GFW_FSP_UCODE_VERSION, e.g.impl NV_GFW_FSP_UCODE_VERSION { pub(crate) fn is_bug_3957833_affected(self) -> bool { const FSP_BUG_3957833_FIX_VERSION: u32 = 0x44c; self.full().get() < FSP_BUG_3957833_FIX_VERSION } }
Quoted 6 lines
so you can just call
bar.read(regs::gh100::NV_GFW_FSP_UCODE_VERSION).is_bug_3957833_affected()This also keeps
FSP_BUG_3957833_FIX_VERSIONlocal toregs.rsand gets us rid of this HAL function.
I don't think we can get rid of the hal function, since GH100 vs GB100 need different behaviour, which is
just setting war flag.
Quoted 3 lines
Can't we just use unsigned for the argument and return type? None of those are ever expected to be negative, no?
No, I think I got lost in what rust needed to avoid crashing the machine, so I just stayed on the side of least likely to overflow.
I've reworked it in v4 back to what I had in the first place with checked_sub.
Quoted 12 lines
I think we accumulated a bunch of those comments in nova-core, I think it would be nice to consider whether we want a prefix for this, similar to TIMEOUT or CALC. Maybe OVERFLOW? But this can be a follow-up of course.
On the other hand, this is a fallible method already, so I'd just go with
checked_sub().This looks similar to
NV_TLB_FLUSH_PDB_LO::from_pdb_addr(). I think we should do this in the register impl:
Quoted 10 lines
impl NV_PGC6_SCI_SYS_TIMER_OFFSET_1 {
/// Creates a register value from bits 60:32 of the offset.
pub(crate) fn from_offset_ns(offset_ns: u64) -> Self {
let nsec = Bounded::<u32, 29>::from_expr(
((offset_ns >> 32) & 0x1fff_ffff) as u32,
);
Self::zeroed().with_nsec(nsec)
}
}Done in v4.
Quoted 4 lines
Quoted 4 lines
drivers/gpu/nova-core/timer/hal.rs new file +4
-0+register! { + base:NovaRegisters ; + +/// FSP ucode version, encoded as `major.minor` in bits 11:8 and 7:0, written by the FSP
Quoted 8 lines
drivers/gpu/nova-core/timer/hal.rs
Quoted 6 lines
drivers/gpu/nova-core/timer/hal.rs new file +6
-0+/// during boot. (`NV_PFSP_FALCON_COMMON_SCRATCH_GROUP_3(1)` in the hardware headers.) + pub(crate) NV_GFW_FSP_UCODE_VERSION(u32) @ 0x008f0334 { + 11:0 full; + } + } +}Hm...I feel like it should go into
fsp/regs.rsregardless.
Moved in v4.
Dave.