Skip to contentSkip to conversation

nova-core: add initial support for gpu timer (v7)

PATCH Applied Dave Airlie 4 participants 10 messages Nov 11 – Nov 13

Subsystems (6)
lore
Share & tools
lore
#0 lore raw

v7 cover nova-core: add initial support for gpu timer (v7)

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.

---
Changes in v7:
- Alexandre's review comments
- fix tu102 non-fatal just print error
- bunch of comments and nits
- Link to v6: https://lore.kernel.org/r/[email protected]

Changes in v6:
- Alexandre's review comment handled
- fsp hal stores in fsp
- register cleanups
- Link to v5: https://lore.kernel.org/r/[email protected]

Changes in v5:
- Alexandre's review comments handled
- reworked registers/workaround logic into fsp
- fixed all the timer register handling to be non-falling.
- Link to v4: https://lore.kernel.org/r/[email protected]

Changes in v4:
- reworked register handling
- used a timerstate.
- Link to v3: https://lore.kernel.org/r/[email protected]

---
Dave Airlie (2):
rust: time: expose as_nanos for clock sources.
gpu: nova-core: add support for GPU timer block. (v7)

 drivers/gpu/nova-core/fsp.rs             |  16 ++++-
 drivers/gpu/nova-core/fsp/hal.rs         |   7 ++-
 drivers/gpu/nova-core/fsp/hal/gh100.rs   |   5 ++
 drivers/gpu/nova-core/fsp/regs.rs        |  31 ++++++++++
 drivers/gpu/nova-core/gpu.rs             |   8 +++
 drivers/gpu/nova-core/nova_core.rs       |   1 +
 drivers/gpu/nova-core/timer.rs           |  40 ++++++++++++
 drivers/gpu/nova-core/timer/hal.rs       |  39 ++++++++++++
 drivers/gpu/nova-core/timer/hal/gh100.rs |  71 +++++++++++++++++++++
 drivers/gpu/nova-core/timer/hal/tu102.rs |  49 +++++++++++++++
 drivers/gpu/nova-core/timer/regs.rs      | 103 +++++++++++++++++++++++++++++++
 rust/kernel/time.rs                      |   3 +-
 12 files changed, 368 insertions(+), 5 deletions(-)

---
base-commit: 7a6bc132f1b51437063c9203e7221067b40a791e
change-id: 20261102-nova-timer-f4b9de3274a1

Best regards,

Signature · 1 line
Dave Airlie <[email protected]>
#1 lore raw

PATCH v7 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.

This is needed for following nova patch.

---
 rust/kernel/time.rs | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
rust/kernel/time.rs +2 -1
index b6a2aab12a50..4409291f3ffa 100644
@@ -215,8 +215,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
maintainer Applied
#2 lore raw

Re: [PATCH v7 1/2] rust: time: expose as_nanos for clock sources.

Quoted 4 lines · Dave Airlie

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.

This is needed for following nova patch.

Applied, thanks!

[1/2] rust: time: expose as_nanos for clock sources.

      commit: b6437dcd8958440fdbf05a957d8fdfb7e44a0b5c

Best regards,

Signature · 1 line
Andreas Hindborg <[email protected]>
maintainer
#3 lore raw

Re: [PATCH v7 1/2] rust: time: expose as_nanos for clock sources.

Quoted 8 lines · Andreas Hindborg
Quoted 4 lines · Dave Airlie

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.

This is needed for following nova patch.

Applied, thanks!

Do you mind if we take this through the DRM tree? Otherwise the subsequent patch in this series has to wait for a cycle.

Thanks,
Danilo

maintainer
#4 lore raw

Re: [PATCH v7 1/2] rust: time: expose as_nanos for clock sources.

Quoted 6 lines · Danilo Krummrich
Quoted 5 lines · Andreas Hindborg
Quoted 3 lines · Dave Airlie

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.

Quoted 6 lines
Quoted 3 lines
Quoted 1 line

This is needed for following nova patch.

Applied, thanks!

Do you mind if we take this through the DRM tree? Otherwise the subsequent patch in this series has to wait for a cycle.

No it is fine, I can drop it from my tree. I asked on v6 what you wanted, either way is fine :)

Best regards,
Andreas Hindborg

maintainer
#5 lore raw

Re: [PATCH v7 1/2] rust: time: expose as_nanos for clock sources.

Quoted 10 lines · Andreas Hindborg
Quoted 8 lines · Danilo Krummrich
Quoted 7 lines · Andreas Hindborg
Quoted 4 lines · Dave Airlie

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.

This is needed for following nova patch.

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

Applied, thanks!

Do you mind if we take this through the DRM tree? Otherwise the subsequent patch in this series has to wait for a cycle.

No it is fine, I can drop it from my tree. I asked on v6 what you wanted, either way is fine :)

Great, thanks!

#6 lore raw

Re: [PATCH v7 1/2] rust: time: expose as_nanos for clock sources.

Quoted 14 lines · Danilo Krummrich
Quoted 12 lines · Andreas Hindborg
Quoted 10 lines · Danilo Krummrich
Quoted 8 lines · Andreas Hindborg
Quoted 4 lines · Dave Airlie

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.

This is needed for following nova patch.

Applied, thanks!

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

Do you mind if we take this through the DRM tree? Otherwise the subsequent patch in this series has to wait for a cycle.

No it is fine, I can drop it from my tree. I asked on v6 what you wanted, either way is fine :)

Great, thanks!

I've pushed this to drm-rust-next.

Dave.

#7 lore raw

PATCH v7 2/2 gpu: nova-core: add support for GPU timer block. (v7)

In reply to Dave Airlie

This 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 is for hopper+
This is the gh100 path from open-gpu, where the secure system timer is read, the offset is calculated.
The offset is written to hw offset registers, except on the original gh100 where a workaround is needed for older FSP versions.

---
 drivers/gpu/nova-core/fsp.rs             |  16 ++++-
 drivers/gpu/nova-core/fsp/hal.rs         |   7 ++-
 drivers/gpu/nova-core/fsp/hal/gh100.rs   |   5 ++
 drivers/gpu/nova-core/fsp/regs.rs        |  31 ++++++++++
 drivers/gpu/nova-core/gpu.rs             |   8 +++
 drivers/gpu/nova-core/nova_core.rs       |   1 +
 drivers/gpu/nova-core/timer.rs           |  40 ++++++++++++
 drivers/gpu/nova-core/timer/hal.rs       |  39 ++++++++++++
 drivers/gpu/nova-core/timer/hal/gh100.rs |  71 +++++++++++++++++++++
 drivers/gpu/nova-core/timer/hal/tu102.rs |  49 +++++++++++++++
 drivers/gpu/nova-core/timer/regs.rs      | 103 +++++++++++++++++++++++++++++++
 11 files changed, 366 insertions(+), 4 deletions(-)
drivers/gpu/nova-core/fsp.rs +13 -3
index 3a4a10487f33..74cbbe3996c6 100644
@@ -50,10 +50,11 @@
         NvdmHeader,
         NvdmType, //
     },
-    regs, //
+    regs as bootregs, //
 };
 
 mod hal;
+mod regs;
 
 /// PRC message sub-command.
 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
@@ -389,6 +390,7 @@ pub(crate) fn boot_params(&self) -> &Coherent<'_, GspFmcBootParams> {
 pub(crate) struct Fsp<'a> {
     falcon: Falcon<'a, FspEngine>,
     fmc_fw: GspFmcFirmware<'a>,
+    hal: &'static dyn hal::FspHal,
 }
 
 impl<'a> Fsp<'a> {
@@ -428,7 +430,7 @@ fn wait_secure_boot(
 
         read_poll_timeout(
             || Ok(hal.fsp_boot_status(bar)),
-            |&status| status == regs::NV_THERM_I2CS_SCRATCH_FSP_BOOT_COMPLETE_STATUS_SUCCESS,
+            |&status| status == bootregs::NV_THERM_I2CS_SCRATCH_FSP_BOOT_COMPLETE_STATUS_SUCCESS,
             Delta::from_millis(10),
             Delta::from_millis(FSP_SECURE_BOOT_TIMEOUT_MS),
         )
@@ -436,7 +438,11 @@ fn wait_secure_boot(
             dev_err!(dev, "FSP secure boot completion error: {:?}\n", e);
         })?;
 
-        Ok(Fsp { falcon, fmc_fw })
+        Ok(Fsp {
+            falcon,
+            fmc_fw,
+            hal,
+        })
     }
 
     /// Sends a message to FSP and waits for the response.
@@ -549,4 +555,8 @@ pub(crate) fn boot_fmc(
         dev_dbg!(dev, "FSP Chain of Trust completed successfully\n");
         Ok(())
     }
+
+    pub(crate) fn is_bug_3957833_affected(&self, bar: Bar0<'_>) -> bool {
+        self.hal.is_bug_3957833_affected(bar)
+    }
 }
drivers/gpu/nova-core/fsp/hal.rs +6 -1
index eaf5837ac5a8..f2de7cc296ce 100644
@@ -13,7 +13,7 @@
 mod gb202;
 mod gh100;
 
-pub(super) trait FspHal {
+pub(super) trait FspHal: Sync {
     /// Returns the secure boot status from the architecture-specific `NV_THERM_I2CS_SCRATCH` register.
     fn fsp_boot_status(&self, bar: Bar0<'_>) -> u32;
 
@@ -23,6 +23,11 @@ pub(super) trait FspHal {
     // TODO: consider moving this into the TLV firmware metadata when ready
     /// Returns the size reserved at the end of the framebuffer, in bytes.
     fn fb_end_reserved_size(&self) -> u64;
+
+    /// Return if the bug 3957833 is affected
+    fn is_bug_3957833_affected(&self, _bar: Bar0<'_>) -> bool {
+        false
+    }
 }
 
 /// Returns the FSP HAL, or `None` if the architecture doesn't support FSP.
drivers/gpu/nova-core/fsp/hal/gh100.rs +5 -0
index 9a8563799da8..7f6c8e404f30 100644
@@ -9,6 +9,7 @@
 use crate::{
     driver::Bar0,
     fsp::hal::FspHal,
+    fsp::regs::*,
     regs, //
 };
 
@@ -33,6 +34,10 @@ fn cot_version(&self) -> u16 {
     fn fb_end_reserved_size(&self) -> u64 {
         u64::SZ_2M
     }
+
+    fn is_bug_3957833_affected(&self, bar: Bar0<'_>) -> bool {
+        bar.read(NV_GFW_FSP_UCODE_VERSION).is_bug_3957833_affected()
+    }
 }
 
 const GH100: Gh100 = Gh100;
drivers/gpu/nova-core/fsp/regs.rs new file +31 -0
new file mode 100644
index 000000000000..d04c48ac8e5f
@@ -0,0 +1,31 @@
+// SPDX-License-Identifier: GPL-2.0
+
+use kernel::io::register;
+
+use crate::driver::NovaRegisters;
+
+register! {
+    base: NovaRegisters;
+
+    pub(super) NV_PFSP_FALCON_COMMON_SCRATCH_GROUP_3(u32)[4] @ 0x008f0330 {
+        31:0 val;
+    }
+
+    /// FSP ucode version
+    pub(super) NV_GFW_FSP_UCODE_VERSION(u32) => NV_PFSP_FALCON_COMMON_SCRATCH_GROUP_3[1] {
+        11:0 full;
+    }
+}
+
+impl NV_GFW_FSP_UCODE_VERSION {
+    /// OpenRM kfspRequiresBug3957833WAR_HAL:
+    /// returns `true` if the FSP ucode predates the fix for
+    /// bug 3957833 and hence the sys timer offset must not be programmed.
+    /// Can only be true on GH100 with older FSP.
+    pub(super) fn is_bug_3957833_affected(self) -> bool {
+        /// FSP ucode version from which on the fix for bug 3957833 is included.
+        const FSP_BUG_3957833_FIX_VERSION: u32 = 0x44c;
+
+        self.full() < FSP_BUG_3957833_FIX_VERSION
+    }
+}
drivers/gpu/nova-core/gpu.rs +8 -0
index ac5305d7ff5e..39dcf28068b7 100644
@@ -53,6 +53,10 @@
         GpuMm,
         VramAddress, //
     },
+    timer::{
+        Timer,
+        TimerState, //
+    },
     vgpu::VgpuManager, //
 };
 
@@ -331,6 +335,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 state - contains system timer offset
+    timer: TimerState,
     /// vGPU state detected before GSP boot.
     vgpu: VgpuManager,
     /// GSP runtime data.
@@ -497,6 +503,8 @@ pub(crate) fn new<'a>(
 
                 fsp: Fsp::try_new(dev, bar, spec.chipset)?,
 
+                timer: Timer::setup(dev, bar, spec.chipset, fsp.as_ref())?,
+
                 vgpu: VgpuManager::new(pdev, spec.chipset, fsp.as_mut()),
 
                 gsp <- Gsp::new(pdev, bar),
drivers/gpu/nova-core/nova_core.rs +1 -0
index a8f6dc22057b..ee59d81e5105 100644
@@ -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 +40 -0
new file mode 100644
index 000000000000..ea751a9578d0
@@ -0,0 +1,40 @@
+// SPDX-License-Identifier: GPL-2.0
+
+mod hal;
+mod regs;
+
+use kernel::{
+    device,
+    prelude::*, //
+};
+
+use crate::{
+    driver::Bar0,
+    fsp::Fsp,
+    gpu::Chipset, //
+};
+
+pub(crate) struct Timer;
+
+/// Struct that holds the sys timer offset value
+/// after initialising the GPU timer block.
+pub(crate) struct TimerState {
+    /// This value is to be passed to GspInit SYS_TIMER_OFFSET_NS
+    /// It is considered an opaque value, passed from timer hal to GSP.
+    #[expect(dead_code)]
+    pub(crate) sys_timer_offset_ns: u64,
+}
+
+impl Timer {
+    /// Setup the GPU timer hardware
+    pub(crate) fn setup(
+        dev: &device::Device<device::Bound>,
+        bar: Bar0<'_>,
+        chipset: Chipset,
+        fsp: Option<&Fsp<'_>>,
+    ) -> Result<TimerState> {
+        Ok(TimerState {
+            sys_timer_offset_ns: hal::timer_hal(chipset).setup(dev, bar, fsp)?,
+        })
+    }
+}
drivers/gpu/nova-core/timer/hal.rs new file +39 -0
new file mode 100644
index 000000000000..f036bc5d43bd
@@ -0,0 +1,39 @@
+// SPDX-License-Identifier: GPL-2.0
+
+use kernel::{
+    device,
+    prelude::*, //
+};
+
+use crate::{
+    driver::Bar0,
+    fsp::Fsp,
+    gpu::{
+        Architecture,
+        Chipset, //
+    },
+};
+
+mod gh100;
+mod tu102;
+
+pub(super) trait TimerHal {
+    /// Setup the GPU's system timer.
+    ///
+    /// Returns the value to program into GspInitRequest.
+    fn setup(
+        &self,
+        dev: &device::Device<device::Bound>,
+        bar: Bar0<'_>,
+        fsp: Option<&Fsp<'_>>,
+    ) -> Result<u64>;
+}
+
+pub(super) fn timer_hal(chipset: Chipset) -> &'static dyn TimerHal {
+    match chipset.arch() {
+        Architecture::Turing | Architecture::Ampere | Architecture::Ada => tu102::TU102_HAL,
+        Architecture::Hopper | Architecture::BlackwellGB10x | Architecture::BlackwellGB20x => {
+            gh100::GH100_HAL
+        }
+    }
+}
drivers/gpu/nova-core/timer/hal/gh100.rs new file +71 -0

71 lines not on this page · raw message

drivers/gpu/nova-core/timer/hal/tu102.rs new file +49 -0

49 lines not on this page · raw message

drivers/gpu/nova-core/timer/regs.rs new file +103 -0

103 lines not on this page · raw message

Signature · 1 line
2.56.0
maintainer Reviewed-by on v7 2/2
#8 lore raw

Re: [PATCH v7 2/2] gpu: nova-core: add support for GPU timer block. (v7)

Quoted 10 lines · On Wed Nov 11, 2026 at 2:23 PM JST, Dave Airlie via B4 Relay wrote:

From: Dave Airlie <[email protected]>

This 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.

Quoted 7 lines

b) gh100 is for hopper+
This is the gh100 path from open-gpu, where the secure system timer is read, the offset is calculated.
The offset is written to hw offset registers, except on the original gh100 where a workaround is needed for older FSP versions.

One last nit (which can be addressed upon applying) below.

<...>

Quoted 39 lines
drivers/gpu/nova-core/timer/hal/tu102.rs new file +33 -0
new file mode 100644
index 000000000000..93fe17990ec8
@@ -0,0 +1,49 @@
+// SPDX-License-Identifier: GPL-2.0
+
+use super::TimerHal;
+
+use kernel::{
+    device,
+    io::Io,
+    prelude::*,
+    time::*, //
+};
+
+use crate::{
+    driver::Bar0,
+    fsp::Fsp,
+    timer::regs::*, //
+};
+
+/// Timer HAL for Turing, Ampere, Ada
+struct Tu102;
+
+fn set_time(bar: Bar0<'_>, time_ns: u64) -> Result {
+    if !bar.read(NV_PTIMER_TIME_PRIV_LEVEL_MASK).level0() {
+        return Err(EINVAL);
+    }
+    bar.write_reg(NV_PTIMER_TIME_1::from_nsec(time_ns));
+    bar.write_reg(NV_PTIMER_TIME_0::from_nsec(time_ns));
+    Ok(())
+}
+
+impl TimerHal for Tu102 {
+    fn setup(
+        &self,
+        dev: &device::Device<device::Bound>,

drivers/gpu/nova-core/timer/hal/tu102.rs line 43

Quoted 10 lines
drivers/gpu/nova-core/timer/hal/tu102.rs new file +10 -0
+        bar: Bar0<'_>,
+        _fsp: Option<&Fsp<'_>>,
+    ) -> Result<u64> {
+        // The OpenRM driver uses wall clock time here not monotonic
+        let sys_time_ns = Instant::<RealTime>::now().as_nanos();
+
+        // CAST: realtime system time can't be negative.
+        // not setting the timer isn't fatal, just log.
+        let _ = set_time(bar, sys_time_ns as u64)
+            .inspect_err(|e| dev_err!(dev, "timer block failed to initialise: {:?}", e));

Missing \n at the end of the error message.

#9 lore raw

Re: [PATCH v7 2/2] gpu: nova-core: add support for GPU timer block. (v7)

Quoted 18 lines · Alexandre Courbot
Quoted 16 lines · On Wed Nov 11, 2026 at 2:23 PM JST, Dave Airlie via B4 Relay wrote:

From: Dave Airlie <[email protected]>

This 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 is for hopper+
This is the gh100 path from open-gpu, where the secure system timer is read, the offset is calculated.
The offset is written to hw offset registers, except on the original gh100 where a workaround is needed for older FSP versions.

Quoted 5 lines
Quoted 1 line

One last nit (which can be addressed upon applying) below.

Thanks, fixed the nit and pushed to drm-rust-next.

Dave.