nova-core: add initial support for gpu timer (v2)
Subsystems (6)
cover nova-core: add initial support for gpu timer (v2)
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.
---
Dave Airlie (2):
rust: time: expose as_nanos for clock sources.
gpu: nova-core: add support for GPU timer block. (v2)
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 | 28 ++++++++++++ drivers/gpu/nova-core/timer/hal/gh100.rs | 76 ++++++++++++++++++++++++++++++++ drivers/gpu/nova-core/timer/hal/tu102.rs | 56 +++++++++++++++++++++++ drivers/gpu/nova-core/timer/regs.rs | 64 +++++++++++++++++++++++++++ rust/kernel/time.rs | 3 +- 8 files changed, 265 insertions(+), 1 deletion(-)
---
base-commit: 3497a403264b094ebd61b8b755165d56e7d9dc37
change-id: 20261102-nova-timer-f4b9de3274a1
Best regards,
Signature · 1 line
Dave Airlie <[email protected]>
PATCH 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 2/2 gpu: nova-core: add support for GPU timer block. (v2)
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 is the gh100 path from open-gpu, where the secure system timer is read, the offset is calculated and on everything where it works the offset gets written to secure registers, and also sent to GSP.
---
v2: kill the read API for now, it would be internal to the timer
as we just want to read once at startup on gb10b. Drop the cpu timer wrapper.
don't store chipset and remove the pin stuff
Move registers into timer.
add support for GH100 WAR properly
do i64 calcs to avoid overflow and copy RM code closer.
--- 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 | 28 ++++++++++++ drivers/gpu/nova-core/timer/hal/gh100.rs | 76 ++++++++++++++++++++++++++++++++ drivers/gpu/nova-core/timer/hal/tu102.rs | 56 +++++++++++++++++++++++ drivers/gpu/nova-core/timer/regs.rs | 64 +++++++++++++++++++++++++++ 7 files changed, 263 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 +28 -0
@@ -0,0 +1,28 @@ +// 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 |Architecture ::BlackwellGB10x |Architecture ::BlackwellGB20x => { + gh100::GH100_HAL + } + } +}
drivers/gpu/nova-core/timer/hal/gh100.rs new file +76 -0
76 lines not on this page · raw message
drivers/gpu/nova-core/timer/hal/tu102.rs new file +56 -0
56 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
[email protected]
AI reviewRe: [PATCH 2/2] gpu: nova-core: add support for GPU timer block. (v2)
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [High] gpu: nova-core: GH100 FSP bug 3957833 WAR applied to Blackwell in timer_time() --
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] gpu: nova-core: GH100 FSP bug 3957833 WAR applied to Blackwell in timer_time() --
commit fd289ae7ae729480f9ef4d6e43c04d6aa8f3dbe4
Author: Dave Airlie <[email protected]>
gpu: nova-core: add support for GPU timer block. (v2)
This commit adds GPU timer block initialization for nova-core to compute and program the system timer offset passed to GSP initialization, with HAL implementations for TU102 (Turing/Ampere/Ada) and GH100 (Hopper/Blackwell).
Quoted 6 lines
drivers/gpu/nova-core/timer/hal.rs new file +0
-0@@ -0,0 +1,28 @@
[ ... ]
Quoted 14 lines
drivers/gpu/nova-core/timer/hal.rs new file +8
-0+pub (super )fn timer_hal (chipset:Chipset ) -> &'staticdyn 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 +0
-0@@ -0,0 +1,76 @@
[ ... ]
Quoted 10 lines
drivers/gpu/nova-core/timer/hal/gh100.rs new file +10
-0+/// FSP ucode version from which on the fix for bug 3957833 is included. +const FSP_BUG_3957833_FIX_VERSION :u32 =0x44c ; + +/// kfspRequiresBug3957833WAR_HAL: returns `true` if the FSP ucode predates the fix for bug +/// 3957833 and hence the sys timer offset must not be programmed. +fn fsp_requires_bug3957833_war (bar:Bar0 <'_>) ->bool { + bar.read (regs::gh100::NV_GFW_FSP_UCODE_VERSION ).full ().get () <FSP_BUG_3957833_FIX_VERSION +} + +fn timer_time (bar:Bar0 <'_>, time_ns:i64 ) ->Result <i64 > {
[ ... ]
Quoted 4 lines
drivers/gpu/nova-core/timer/hal/gh100.rs new file +4
-0+if !fsp_requires_bug3957833_war (bar) { +let offset_ns = sys_timer_offset_nsas u64 ; + bar.write_reg ( + regs::gh100::NV_PGC6_SCI_SYS_TIMER_OFFSET_1::zeroed()
drivers/gpu/nova-core/timer/hal/gh100.rs line 64
Quoted 10 lines
drivers/gpu/nova-core/timer/hal/gh100.rs new file +10
-0+ .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 ), + ); + } +Ok (sys_timer_offset_ns) +}
[Severity: High]
Should fsp_requires_bug3957833_war() in drivers/gpu/nova-core/timer/hal/gh100.rs be restricted to Hopper (GH100) rather than also running on Blackwell?
In drivers/gpu/nova-core/timer/hal.rs, timer_hal() routes Architecture::Hopper, Architecture::BlackwellGB10x, and Architecture::BlackwellGB20x to gh100::GH100_HAL:
Gpu::new()
-> Timer::new()
-> hal::timer_hal(chipset).init(bar)
-> Gh100::init()
-> timer_time()
-> fsp_requires_bug3957833_war()In OpenRM, kfspRequiresBug3957833WAR_HAL is an FSP HAL method implemented only for GH100 (comparing GH100's FSP ucode version against 0x44c) and stubbed to return false on Blackwell, which has separate FSP firmware version numbering.
When running on Blackwell (BlackwellGB10x or BlackwellGB20x), if the value in NV_GFW_FSP_UCODE_VERSION is below 0x44c, won't timer_time() falsely trigger the GH100 workaround and skip programming NV_PGC6_SCI_SYS_TIMER_OFFSET_1 and NV_PGC6_SCI_SYS_TIMER_OFFSET_0?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2