Skip to contentSkip to conversation

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

PATCH Superseded Dave Airlie 2 participants 6 messages Nov 6 – Nov 10

Subsystems (6)

v5 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

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

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 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. (v5)

 drivers/gpu/nova-core/fsp.rs             | 19 ++++++-
 drivers/gpu/nova-core/fsp/hal.rs         |  5 ++
 drivers/gpu/nova-core/fsp/hal/gh100.rs   |  6 ++
 drivers/gpu/nova-core/fsp/regs.rs        | 28 +++++++++
 drivers/gpu/nova-core/gpu.rs             |  8 +++
 drivers/gpu/nova-core/nova_core.rs       |  1 +
 drivers/gpu/nova-core/timer.rs           | 38 +++++++++++++
 drivers/gpu/nova-core/timer/hal.rs       | 31 ++++++++++
 drivers/gpu/nova-core/timer/hal/gh100.rs | 62 ++++++++++++++++++++
 drivers/gpu/nova-core/timer/hal/tu102.rs | 53 +++++++++++++++++
 drivers/gpu/nova-core/timer/regs.rs      | 98 ++++++++++++++++++++++++++++++++
 rust/kernel/time.rs                      |  3 +-
 12 files changed, 348 insertions(+), 4 deletions(-)

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

Best regards,

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

PATCH v5 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
#2 lore raw

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

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.
On gh100 which need a work around to avoid sending it to registers if the FSP firmware is too old.
Otherwise we write the offset to the offset registers.

---
 drivers/gpu/nova-core/fsp.rs             | 19 ++++++-
 drivers/gpu/nova-core/fsp/hal.rs         |  5 ++
 drivers/gpu/nova-core/fsp/hal/gh100.rs   |  6 ++
 drivers/gpu/nova-core/fsp/regs.rs        | 28 +++++++++
 drivers/gpu/nova-core/gpu.rs             |  8 +++
 drivers/gpu/nova-core/nova_core.rs       |  1 +
 drivers/gpu/nova-core/timer.rs           | 38 +++++++++++++
 drivers/gpu/nova-core/timer/hal.rs       | 31 ++++++++++
 drivers/gpu/nova-core/timer/hal/gh100.rs | 62 ++++++++++++++++++++
 drivers/gpu/nova-core/timer/hal/tu102.rs | 53 +++++++++++++++++
 drivers/gpu/nova-core/timer/regs.rs      | 98 ++++++++++++++++++++++++++++++++
 11 files changed, 346 insertions(+), 3 deletions(-)
drivers/gpu/nova-core/fsp.rs +16 -3
index 3a4a10487f33..a2ea50465a55 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>,
+    chipset: Chipset,
 }
 
 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,
+            chipset,
+        })
     }
 
     /// Sends a message to FSP and waits for the response.
@@ -549,4 +555,11 @@ 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 {
+        match hal::fsp_hal(self.chipset) {
+            Some(hal) => hal.is_bug_3957833_affected(bar),
+            None => false,
+        }
+    }
 }
drivers/gpu/nova-core/fsp/hal.rs +5 -0
index eaf5837ac5a8..8bcc8f71cf8f 100644
@@ -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 +6 -0
index 9a8563799da8..538870566b8c 100644
@@ -9,6 +9,7 @@
 use crate::{
     driver::Bar0,
     fsp::hal::FspHal,
+    fsp::regs as fspregs,
     regs, //
 };
 
@@ -33,6 +34,11 @@ 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(fspregs::NV_GFW_FSP_UCODE_VERSION)
+            .is_bug3957833_affected()
+    }
 }
 
 const GH100: Gh100 = Gh100;
drivers/gpu/nova-core/fsp/regs.rs new file +28 -0
new file mode 100644
index 000000000000..de69d5bed427
@@ -0,0 +1,28 @@
+// SPDX-License-Identifier: GPL-2.0
+
+use kernel::io::register;
+
+use crate::driver::NovaRegisters;
+
+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(super) NV_GFW_FSP_UCODE_VERSION(u32) @ 0x008f0334 {
+        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_bug3957833_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..cd281460c509 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(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 +38 -0
new file mode 100644
index 000000000000..4c329221c674
@@ -0,0 +1,38 @@
+// SPDX-License-Identifier: GPL-2.0
+
+mod hal;
+mod regs;
+
+use kernel::{
+    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(
+        bar: Bar0<'_>,
+        chipset: Chipset,
+        fsp: Option<&Fsp<'_>>,
+    ) -> Result<TimerState> {
+        Ok(TimerState {
+            sys_timer_offset_ns: hal::timer_hal(chipset).setup(bar, fsp)?,
+        })
+    }
+}
drivers/gpu/nova-core/timer/hal.rs new file +31 -0
new file mode 100644
index 000000000000..c2f2bbcad890
@@ -0,0 +1,31 @@
+// SPDX-License-Identifier: GPL-2.0
+
+use kernel::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, 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 +62 -0

62 lines not on this page · raw message

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

53 lines not on this page · raw message

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

98 lines not on this page · raw message

Signature · 1 line
2.56.0
#3 lore raw

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

Quoted 7 lines · On Fri Nov 6, 2026 at 2:34 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:

Quoted 7 lines

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.
On gh100 which need a work around to avoid sending it to registers

nit: "On gh100 a work around is needed to avoid..." maybe?

Quoted 66 lines

if the FSP firmware is too old.
Otherwise we write the offset to the offset registers.

---
 drivers/gpu/nova-core/fsp.rs             | 19 ++++++-
 drivers/gpu/nova-core/fsp/hal.rs         |  5 ++
 drivers/gpu/nova-core/fsp/hal/gh100.rs   |  6 ++
 drivers/gpu/nova-core/fsp/regs.rs        | 28 +++++++++
 drivers/gpu/nova-core/gpu.rs             |  8 +++
 drivers/gpu/nova-core/nova_core.rs       |  1 +
 drivers/gpu/nova-core/timer.rs           | 38 +++++++++++++
 drivers/gpu/nova-core/timer/hal.rs       | 31 ++++++++++
 drivers/gpu/nova-core/timer/hal/gh100.rs | 62 ++++++++++++++++++++
 drivers/gpu/nova-core/timer/hal/tu102.rs | 53 +++++++++++++++++
 drivers/gpu/nova-core/timer/regs.rs      | 98 ++++++++++++++++++++++++++++++++
 11 files changed, 346 insertions(+), 3 deletions(-)
drivers/gpu/nova-core/fsp.rs +9 -3
index 3a4a10487f33..a2ea50465a55 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>,
+    chipset: Chipset,
 }
 
 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,
+            chipset,
+        })
     }
 
     /// Sends a message to FSP and waits for the response.

drivers/gpu/nova-core/fsp.rs pub(crate) fn boot_fmc( · line 562

Quoted 8 lines
drivers/gpu/nova-core/fsp.rs +5 -0
@@ -549,4 +555,11 @@ 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 {
+        match hal::fsp_hal(self.chipset) {
+            Some(hal) => hal.is_bug_3957833_affected(bar),
+            None => false,

As I mentioned in my other comment, storing the HAL instead of the chipset is technically better, but I'm ok if this is not done just for this single-use method.

Quoted 24 lines
drivers/gpu/nova-core/fsp.rs +2 -0
+        }
+    }
 }
drivers/gpu/nova-core/fsp/hal.rs +5 -0
index eaf5837ac5a8..8bcc8f71cf8f 100644
@@ -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 +0 -0
index 9a8563799da8..538870566b8c 100644

drivers/gpu/nova-core/fsp/hal/gh100.rs line 12

Quoted 4 lines
drivers/gpu/nova-core/fsp/hal/gh100.rs +1 -0
@@ -9,6 +9,7 @@
 use crate::{
     driver::Bar0,
     fsp::hal::FspHal,
+    fsp::regs as fspregs,

Since this is the fsp-local registers module, let's just import fsp::regs::* and use the registers without any module prefix.

drivers/gpu/nova-core/fsp/hal/gh100.rs fn cot_version(&self) -> u16 { · line 40

Quoted 11 lines
drivers/gpu/nova-core/fsp/hal/gh100.rs +4 -0
     regs, //
 };
 
@@ -33,6 +34,11 @@ 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(fspregs::NV_GFW_FSP_UCODE_VERSION)
+            .is_bug3957833_affected()

s/is_bug39/is_bug_39

Quoted 14 lines
drivers/gpu/nova-core/fsp/hal/gh100.rs +1 -0
+    }
 }
 
 const GH100: Gh100 = Gh100;
drivers/gpu/nova-core/fsp/regs.rs new file +4 -0
new file mode 100644
index 000000000000..de69d5bed427
@@ -0,0 +1,28 @@
+// SPDX-License-Identifier: GPL-2.0
+
+use kernel::io::register;
+

drivers/gpu/nova-core/fsp/regs.rs line 14

Quoted 10 lines
drivers/gpu/nova-core/fsp/regs.rs new file +10 -0
+use crate::driver::NovaRegisters;
+
+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(super) NV_GFW_FSP_UCODE_VERSION(u32) @ 0x008f0334 {
+        11:0 full;
+    }

I'd like our register definitions to reflect the aliasing of the comment (which is also represented by OpenRM). So we would start by defining the actual NV_PFSP_FALCON_COMMON_SCRATCH_GROUP_3 (which is an array of 4 registers per OpenRM):

    pub(super) NV_PFSP_FALCON_COMMON_SCRATCH_GROUP_3(u32)[4] @ 0x008f0330 {
        31:0 val;
    }

And then define NV_GFW_FSP_UCODE_VERSION as an alias to the register at index 1.

    /// FSP ucode version, written by the FSP during boot.
    pub(super) NV_GFW_FSP_UCODE_VERSION(u32) => NV_PFSP_FALCON_COMMON_SCRATCH_GROUP_3[1] {
        11:0 full;
    }

That way we can reduce the comment to the information that is not obvious from the declaration. I'd also drop the references to the non-defined fields, unless you want to add them - it is possible to define overlapping fields, but since the code doesn't use them we can do without for now.

<...>

Quoted 10 lines
drivers/gpu/nova-core/timer/hal/gh100.rs new file +4 -0
new file mode 100644
index 000000000000..49e348c89e52
@@ -0,0 +1,62 @@
+// SPDX-License-Identifier: GPL-2.0
+
+use super::TimerHal;
+

drivers/gpu/nova-core/timer/hal/gh100.rs line 14

Quoted 10 lines
drivers/gpu/nova-core/timer/hal/gh100.rs new file +10 -0
+use kernel::{
+    io::Io,
+    prelude::*,
+    time::*, //
+};
+
+use crate::{
+    driver::Bar0,
+    fsp::Fsp,
+    timer::regs, //

Here as well, let's bring the whole timer::regs::gh100::* since we are in the GH100 HAL, this will make the code more concise and easier to read.

Quoted 23 lines
drivers/gpu/nova-core/timer/hal/gh100.rs new file +23 -0
+};
+
+/// Timer HAL for Hopper and Blackwell.
+struct Gh100;
+
+fn sec_timer_read(bar: Bar0<'_>) -> u64 {
+    let mut hi2 = bar.read(regs::gh100::NV_PGC6_SCI_SEC_TIMER_TIME_1);
+    loop {
+        let lo = bar.read(regs::gh100::NV_PGC6_SCI_SEC_TIMER_TIME_0);
+        let hi = bar.read(regs::gh100::NV_PGC6_SCI_SEC_TIMER_TIME_1);
+        if hi == hi2 {
+            return u64::from(u32::from(hi)) << 32 | u64::from(u32::from(lo));
+        }
+        hi2 = bar.read(regs::gh100::NV_PGC6_SCI_SEC_TIMER_TIME_1);
+    }
+}
+
+fn sys_timer_offset(bar: Bar0<'_>, fsp: &Fsp<'_>, time_ns: u64) -> Result<u64> {
+    let sec_timer_ns = sec_timer_read(bar);
+
+    let sys_timer_offset_ns = time_ns.wrapping_sub(sec_timer_ns);
+
+    if !fsp.is_bug_3957833_affected(bar) {

drivers/gpu/nova-core/timer/hal/gh100.rs line 47

Quoted 10 lines
drivers/gpu/nova-core/timer/hal/gh100.rs new file +10 -0
+        bar.write_reg(regs::gh100::NV_PGC6_SCI_SYS_TIMER_OFFSET_1::from_nsec(
+            sys_timer_offset_ns,
+        ));
+        bar.write_reg(
+            regs::gh100::NV_PGC6_SCI_SYS_TIMER_OFFSET_0::from_nsec(sys_timer_offset_ns)
+                .with_update(true),
+        );
+    }
+    Ok(sys_timer_offset_ns)
+}

So I know we discussed that on v4, but this function is named like it just returns a value, whereas it also might program some registers. Can we mirror what tu102 does and extract the if fsp.is_bug... block into another function that setup calls?

Your argument was that resume might need to do the same thing, but it seems to me that resume would just call setup again anyway.

drivers/gpu/nova-core/timer/hal/gh100.rs line 51

Quoted 4 lines
drivers/gpu/nova-core/timer/hal/gh100.rs new file +4 -0
+
+impl TimerHal for Gh100 {
+    fn setup(&self, bar: Bar0<'_>, fsp: Option<&Fsp<'_>>) -> Result<u64> {
+        // The open drivers uses wall clock time here not monotonic

This module calls it "open drivers", tu102 says "The RM"... Let's call it "OpenRM" in both. :)

drivers/gpu/nova-core/timer/hal/gh100.rs line 57

Quoted 6 lines
drivers/gpu/nova-core/timer/hal/gh100.rs new file +6 -0
+        let sys_time_ns = Instant::<RealTime>::now().as_nanos();
+
+        // fsp is required on gh100 - return error if not available.
+        let fsp = fsp.ok_or(EINVAL)?;
+
+        sys_timer_offset(bar, fsp, sys_time_ns as u64)

as statements require a CAST: comment that explains why they are safe.

In this particular case I am not sure what we are supposed to expect, as an Instant<RealTime> is not supposed to be negative anyway. So I suppose that could be the CAST: comment.

Quoted 17 lines
drivers/gpu/nova-core/timer/hal/gh100.rs new file +5 -0
+    }
+}
+
+const GH100: Gh100 = Gh100;
+pub(super) const GH100_HAL: &dyn TimerHal = &GH100;
drivers/gpu/nova-core/timer/hal/tu102.rs new file +6 -0
new file mode 100644
index 000000000000..629d744a4b12
@@ -0,0 +1,53 @@
+// SPDX-License-Identifier: GPL-2.0
+
+use super::TimerHal;
+
+use kernel::{
+    io::Io,

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

Quoted 10 lines
drivers/gpu/nova-core/timer/hal/tu102.rs new file +10 -0
+    prelude::*,
+    time::*, //
+};
+
+use crate::{
+    driver::Bar0,
+    fsp::Fsp,
+    timer::regs, //
+};
+struct Tu102;

For symmetry, let's grant this a comment like its gh100 counterpart.

Quoted 4 lines
drivers/gpu/nova-core/timer/hal/tu102.rs new file +4 -0
+
+// this code will be used in the gb10b hal eventually
+#[expect(dead_code)]
+fn timer_read(bar: Bar0<'_>) -> u64 {

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

Quoted 10 lines
drivers/gpu/nova-core/timer/hal/tu102.rs new file +10 -0
+    let mut hi2 = bar.read(regs::NV_PTIMER_TIME_1);
+    loop {
+        let lo = bar.read(regs::NV_PTIMER_TIME_0);
+        let hi = bar.read(regs::NV_PTIMER_TIME_1);
+        if hi == hi2 {
+            return u64::from(u32::from(hi)) << 32 | u64::from(u32::from(lo));
+        }
+        hi2 = bar.read(regs::NV_PTIMER_TIME_1);
+    }
+}

Usually we try to not introduce dead code proactively, especially if the user is not in sight. Can we introduce that alongside the gb10b code that makes use of it?

Quoted 4 lines
drivers/gpu/nova-core/timer/hal/tu102.rs new file +4 -0
+
+fn set_time(bar: Bar0<'_>, time_ns: u64) -> Result {
+    if !bar.read(regs::NV_PTIMER_TIME_PRIV_LEVEL_MASK).level0() {
+        return Err(EINVAL);

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

Quoted 10 lines
drivers/gpu/nova-core/timer/hal/tu102.rs new file +10 -0
+    }
+    bar.write_reg(regs::NV_PTIMER_TIME_1::from_nsec(time_ns));
+    bar.write_reg(regs::NV_PTIMER_TIME_0::from_nsec(time_ns));
+    Ok(())
+}
+
+impl TimerHal for Tu102 {
+    fn setup(&self, bar: Bar0<'_>, _fsp: Option<&Fsp<'_>>) -> Result<u64> {
+        // The RM uses wall clock time here (osGetSystemTime -> ktime_get_real), so the GPU time
+        // matches the host's real time, e.g. for timestamp correlation in userspace.

nit: s/The RM/OpenRM.

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

Quoted 3 lines
drivers/gpu/nova-core/timer/hal/tu102.rs new file +3 -0
+        let sys_time_ns = Instant::<RealTime>::now().as_nanos();
+
+        set_time(bar, sys_time_ns as u64)?;

Same here, this needs a CAST: comment.

Quoted 21 lines
drivers/gpu/nova-core/timer/hal/tu102.rs new file +6 -0
+        Ok(0_u64)
+    }
+}
+
+const TU102: Tu102 = Tu102;
+pub(super) const TU102_HAL: &dyn TimerHal = &TU102;
drivers/gpu/nova-core/timer/regs.rs new file +9 -0
new file mode 100644
index 000000000000..89dd478a37be
@@ -0,0 +1,98 @@
+// SPDX-License-Identifier: GPL-2.0
+
+use kernel::io::register;
+use kernel::num::Bounded;
+
+use crate::driver::NovaRegisters;
+use pin_init::Zeroable;
+
+/// Field value for the NSEC field (31:5) of the `_0` registers: `nsec[31:5]`.

drivers/gpu/nova-core/timer/regs.rs line 19

Quoted 10 lines
drivers/gpu/nova-core/timer/regs.rs new file +10 -0
+///
+/// The GPU timer counts nanoseconds with 32 ns granularity, so `nsec[4:0]` is dropped.
+fn nsec_lo(nsec: u64) -> Bounded<u32, 27> {
+    Bounded::<u32, 32>::from(nsec as u32).shr::<5, _>()
+}
+
+/// Field value for the NSEC field (28:0) of the `_1` registers: `nsec[60:32]`.
+///
+/// The GPU timer is 61 bits wide, so `nsec[63:61]` is not representable and is
+/// truncated — the same bits the hardware discards on a raw register write.

Non-ascii character (em dash) in the comment.

Regarding the truncated MSBs in nsec_hi, I *think* it is ok to truncate them indeed, as the value written would still be a valid anchor value for the GPU. It also shouldn't manifest itself until 2043 or so for chips < GH100, unless someone decides to mess with their system clock.

I guess this issue is the reason why GH100+ are storing a delta instead of an absolute value.

#4 lore raw

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

Quoted 83 lines · Alexandre Courbot
Quoted 7 lines · On Fri Nov 6, 2026 at 2:34 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:

Quoted 7 lines

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.
On gh100 which need a work around to avoid sending it to registers

nit: "On gh100 a work around is needed to avoid..." maybe?

Quoted 64 lines

if the FSP firmware is too old.
Otherwise we write the offset to the offset registers.

---
 drivers/gpu/nova-core/fsp.rs             | 19 ++++++-
 drivers/gpu/nova-core/fsp/hal.rs         |  5 ++
 drivers/gpu/nova-core/fsp/hal/gh100.rs   |  6 ++
 drivers/gpu/nova-core/fsp/regs.rs        | 28 +++++++++
 drivers/gpu/nova-core/gpu.rs             |  8 +++
 drivers/gpu/nova-core/nova_core.rs       |  1 +
 drivers/gpu/nova-core/timer.rs           | 38 +++++++++++++
 drivers/gpu/nova-core/timer/hal.rs       | 31 ++++++++++
 drivers/gpu/nova-core/timer/hal/gh100.rs | 62 ++++++++++++++++++++
 drivers/gpu/nova-core/timer/hal/tu102.rs | 53 +++++++++++++++++
 drivers/gpu/nova-core/timer/regs.rs      | 98 ++++++++++++++++++++++++++++++++
 11 files changed, 346 insertions(+), 3 deletions(-)
drivers/gpu/nova-core/fsp.rs +9 -3
index 3a4a10487f33..a2ea50465a55 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>,
+    chipset: Chipset,
 }
 
 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,
+            chipset,
+        })
     }
 
Quoted 14 lines

drivers/gpu/nova-core/fsp.rs pub(crate) fn boot_fmc( · line 562

Quoted 10 lines
drivers/gpu/nova-core/fsp.rs +5 -0
     /// Sends a message to FSP and waits for the response.
@@ -549,4 +555,11 @@ 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 {
+        match hal::fsp_hal(self.chipset) {
+            Some(hal) => hal.is_bug_3957833_affected(bar),
+            None => false,

As I mentioned in my other comment, storing the HAL instead of the chipset is technically better, but I'm ok if this is not done just for this single-use method.

Okay I've done it for v6, there are places we don't do this already, but I'll do it for fsp.

Quoted 13 lines
Quoted 13 lines
drivers/gpu/nova-core/fsp.rs +13 -0
+fn sys_timer_offset(bar: Bar0<'_>, fsp: &Fsp<'_>, time_ns: u64) -> Result<u64> {
+    let sec_timer_ns = sec_timer_read(bar);
+
+    let sys_timer_offset_ns = time_ns.wrapping_sub(sec_timer_ns);
+
+    if !fsp.is_bug_3957833_affected(bar) {
+        bar.write_reg(regs::gh100::NV_PGC6_SCI_SYS_TIMER_OFFSET_1::from_nsec(
+            sys_timer_offset_ns,
+        ));
+        bar.write_reg(
+            regs::gh100::NV_PGC6_SCI_SYS_TIMER_OFFSET_0::from_nsec(sys_timer_offset_ns)
+                .with_update(true),
+        );
Quoted 8 lines

drivers/gpu/nova-core/fsp.rs

Quoted 3 lines
drivers/gpu/nova-core/fsp.rs +3 -0
+    }
+    Ok(sys_timer_offset_ns)
+}

So I know we discussed that on v4, but this function is named like it just returns a value, whereas it also might program some registers. Can we mirror what tu102 does and extract the if fsp.is_bug... block into another function that setup calls?

No, this gives the workaround too much recognition. I've renamed this function to set_sys_timer_offset,
That is the point of this function, to calculate and set the system timer offset in hardware. Broken hardware
should not direct the function's focus, working hardware calculates and programs the registers.

Quoted 8 lines

Regarding the truncated MSBs in nsec_hi, I *think* it is ok to truncate them indeed, as the value written would still be a valid anchor value for the GPU. It also shouldn't manifest itself until 2043 or so for chips < GH100, unless someone decides to mess with their system clock.

I guess this issue is the reason why GH100+ are storing a delta instead of an absolute value.

For v6, I've done everything else asked,

For how the timer hw works, I unfortunately can't know this, because it isn't documented in public docs, if you guys want to pursue this internally, I can only do what OpenRM does.

Also are we okay using OpenRM? like I know there was some issues in the past, maybe we need to have a proper way to reference the NVIDIA open-gpu-kernel-drivers.

Dave.

#5 lore raw

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

Quoted 142 lines · David Airlie
Quoted 83 lines · Alexandre Courbot
Quoted 7 lines · On Fri Nov 6, 2026 at 2:34 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:

Quoted 7 lines

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.
On gh100 which need a work around to avoid sending it to registers

nit: "On gh100 a work around is needed to avoid..." maybe?

Quoted 64 lines

if the FSP firmware is too old.
Otherwise we write the offset to the offset registers.

---
 drivers/gpu/nova-core/fsp.rs             | 19 ++++++-
 drivers/gpu/nova-core/fsp/hal.rs         |  5 ++
 drivers/gpu/nova-core/fsp/hal/gh100.rs   |  6 ++
 drivers/gpu/nova-core/fsp/regs.rs        | 28 +++++++++
 drivers/gpu/nova-core/gpu.rs             |  8 +++
 drivers/gpu/nova-core/nova_core.rs       |  1 +
 drivers/gpu/nova-core/timer.rs           | 38 +++++++++++++
 drivers/gpu/nova-core/timer/hal.rs       | 31 ++++++++++
 drivers/gpu/nova-core/timer/hal/gh100.rs | 62 ++++++++++++++++++++
 drivers/gpu/nova-core/timer/hal/tu102.rs | 53 +++++++++++++++++
 drivers/gpu/nova-core/timer/regs.rs      | 98 ++++++++++++++++++++++++++++++++
 11 files changed, 346 insertions(+), 3 deletions(-)
drivers/gpu/nova-core/fsp.rs +9 -3
index 3a4a10487f33..a2ea50465a55 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>,
+    chipset: Chipset,
 }
 
 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,
+            chipset,
+        })
     }
 
Quoted 14 lines

drivers/gpu/nova-core/fsp.rs pub(crate) fn boot_fmc( · line 562

Quoted 10 lines
drivers/gpu/nova-core/fsp.rs +5 -0
     /// Sends a message to FSP and waits for the response.
@@ -549,4 +555,11 @@ 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 {
+        match hal::fsp_hal(self.chipset) {
+            Some(hal) => hal.is_bug_3957833_affected(bar),
+            None => false,

As I mentioned in my other comment, storing the HAL instead of the chipset is technically better, but I'm ok if this is not done just for this single-use method.

Okay I've done it for v6, there are places we don't do this already, but I'll do it for fsp.

Quoted 13 lines
Quoted 13 lines
drivers/gpu/nova-core/fsp.rs +13 -0
+fn sys_timer_offset(bar: Bar0<'_>, fsp: &Fsp<'_>, time_ns: u64) -> Result<u64> {
+    let sec_timer_ns = sec_timer_read(bar);
+
+    let sys_timer_offset_ns = time_ns.wrapping_sub(sec_timer_ns);
+
+    if !fsp.is_bug_3957833_affected(bar) {
+        bar.write_reg(regs::gh100::NV_PGC6_SCI_SYS_TIMER_OFFSET_1::from_nsec(
+            sys_timer_offset_ns,
+        ));
+        bar.write_reg(
+            regs::gh100::NV_PGC6_SCI_SYS_TIMER_OFFSET_0::from_nsec(sys_timer_offset_ns)
+                .with_update(true),
+        );
Quoted 8 lines

drivers/gpu/nova-core/fsp.rs

Quoted 3 lines
drivers/gpu/nova-core/fsp.rs +3 -0
+    }
+    Ok(sys_timer_offset_ns)
+}

So I know we discussed that on v4, but this function is named like it just returns a value, whereas it also might program some registers. Can we mirror what tu102 does and extract the if fsp.is_bug... block into another function that setup calls?

No, this gives the workaround too much recognition. I've renamed this function to set_sys_timer_offset,
That is the point of this function, to calculate and set the system timer offset in hardware. Broken hardware
should not direct the function's focus, working hardware calculates and programs the registers.

Quoted 8 lines

Regarding the truncated MSBs in nsec_hi, I *think* it is ok to truncate them indeed, as the value written would still be a valid anchor value for the GPU. It also shouldn't manifest itself until 2043 or so for chips < GH100, unless someone decides to mess with their system clock.

I guess this issue is the reason why GH100+ are storing a delta instead of an absolute value.

For v6, I've done everything else asked,

Quoted 7 lines

For how the timer hw works, I unfortunately can't know this, because it isn't documented in public docs, if you guys want to pursue this internally, I can only do what OpenRM does.

Also are we okay using OpenRM? like I know there was some issues in the past, maybe we need to have a proper way to reference the NVIDIA open-gpu-kernel-drivers.

I do recognize I have sometimes ambivalent feelings on the topic of whether we should follow OpenRM or not. :)

When in doubt as we currently are, I think the case for following OpenRM is that doing so at least guarantees we won't do worse than it does, and it has the benefit of being battle-tested.

I've tried to find out more about how the timer registers work. It appears that the GH100 SEC_TIMER starts at 0 from power-on, so unless people mess with their system clock it should always be smaller than it, hence subtracting it should not wrap.

Now if it *does* wrap for some unfortunate reason, we would still get a valid timer value by adding SEC_TIMER + OFFSET modulo 61 bits, which supports the case for wrapping - it just needs to be documented as otherwise it can be pretty confusing.

Then there is the year 2043 issue because the timer values are 61 bits. It affects both the TU102 and GH100 HALs. I guess software relying on timestamps will have to adjust for that, but from the perspective of programming the registers I don't think we can do much better than masking.