Skip to content

Commit 82ed324

Browse files
ttabiGnurou
authored andcommitted
gpu: nova-core: move some functions into the HAL
A few Falcon methods are actually GPU-specific, so move them into the HAL. Signed-off-by: Timur Tabi <ttabi@nvidia.com> Reviewed-by: John Hubbard <jhubbard@nvidia.com> Reviewed-by: Gary Guo <gary@garyguo.net> Acked-by: Danilo Krummrich <dakr@kernel.org> Link: https://patch.msgid.link/20260122222848.2555890-7-ttabi@nvidia.com Signed-off-by: Alexandre Courbot <acourbot@nvidia.com>
1 parent f650764 commit 82ed324

3 files changed

Lines changed: 54 additions & 42 deletions

File tree

drivers/gpu/nova-core/falcon.rs

Lines changed: 3 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ use kernel::{
1616
prelude::*,
1717
sync::aref::ARef,
1818
time::{
19-
delay::fsleep,
2019
Delta, //
2120
},
2221
};
@@ -398,48 +397,11 @@ impl<E: FalconEngine + 'static> Falcon<E> {
398397
regs::NV_PFALCON_FALCON_DMACTL::default().write(bar, &E::ID);
399398
}
400399

401-
/// Wait for memory scrubbing to complete.
402-
fn reset_wait_mem_scrubbing(&self, bar: &Bar0) -> Result {
403-
// TIMEOUT: memory scrubbing should complete in less than 20ms.
404-
read_poll_timeout(
405-
|| Ok(regs::NV_PFALCON_FALCON_HWCFG2::read(bar, &E::ID)),
406-
|r| r.mem_scrubbing_done(),
407-
Delta::ZERO,
408-
Delta::from_millis(20),
409-
)
410-
.map(|_| ())
411-
}
412-
413-
/// Reset the falcon engine.
414-
fn reset_eng(&self, bar: &Bar0) -> Result {
415-
let _ = regs::NV_PFALCON_FALCON_HWCFG2::read(bar, &E::ID);
416-
417-
// According to OpenRM's `kflcnPreResetWait_GA102` documentation, HW sometimes does not set
418-
// RESET_READY so a non-failing timeout is used.
419-
let _ = read_poll_timeout(
420-
|| Ok(regs::NV_PFALCON_FALCON_HWCFG2::read(bar, &E::ID)),
421-
|r| r.reset_ready(),
422-
Delta::ZERO,
423-
Delta::from_micros(150),
424-
);
425-
426-
regs::NV_PFALCON_FALCON_ENGINE::update(bar, &E::ID, |v| v.set_reset(true));
427-
428-
// TIMEOUT: falcon engine should not take more than 10us to reset.
429-
fsleep(Delta::from_micros(10));
430-
431-
regs::NV_PFALCON_FALCON_ENGINE::update(bar, &E::ID, |v| v.set_reset(false));
432-
433-
self.reset_wait_mem_scrubbing(bar)?;
434-
435-
Ok(())
436-
}
437-
438400
/// Reset the controller, select the falcon core, and wait for memory scrubbing to complete.
439401
pub(crate) fn reset(&self, bar: &Bar0) -> Result {
440-
self.reset_eng(bar)?;
402+
self.hal.reset_eng(bar)?;
441403
self.hal.select_core(self, bar)?;
442-
self.reset_wait_mem_scrubbing(bar)?;
404+
self.hal.reset_wait_mem_scrubbing(bar)?;
443405

444406
regs::NV_PFALCON_FALCON_RM::default()
445407
.set_value(regs::NV_PMC_BOOT_0::read(bar).into())
@@ -674,8 +636,7 @@ impl<E: FalconEngine + 'static> Falcon<E> {
674636
///
675637
/// Returns `true` if the RISC-V core is active, `false` otherwise.
676638
pub(crate) fn is_riscv_active(&self, bar: &Bar0) -> bool {
677-
let cpuctl = regs::NV_PRISCV_RISCV_CPUCTL::read(bar, &E::ID);
678-
cpuctl.active_stat()
639+
self.hal.is_riscv_active(bar)
679640
}
680641

681642
/// Write the application version to the OS register.

drivers/gpu/nova-core/falcon/hal.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,16 @@ pub(crate) trait FalconHal<E: FalconEngine>: Send + Sync {
3737

3838
/// Program the boot ROM registers prior to starting a secure firmware.
3939
fn program_brom(&self, falcon: &Falcon<E>, bar: &Bar0, params: &FalconBromParams) -> Result;
40+
41+
/// Check if the RISC-V core is active.
42+
/// Returns `true` if the RISC-V core is active, `false` otherwise.
43+
fn is_riscv_active(&self, bar: &Bar0) -> bool;
44+
45+
/// Wait for memory scrubbing to complete.
46+
fn reset_wait_mem_scrubbing(&self, bar: &Bar0) -> Result;
47+
48+
/// Reset the falcon engine.
49+
fn reset_eng(&self, bar: &Bar0) -> Result;
4050
}
4151

4252
/// Returns a boxed falcon HAL adequate for `chipset`.

drivers/gpu/nova-core/falcon/hal/ga102.rs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use kernel::{
66
device,
77
io::poll::read_poll_timeout,
88
prelude::*,
9+
time::delay::fsleep,
910
time::Delta, //
1011
};
1112

@@ -117,4 +118,44 @@ impl<E: FalconEngine> FalconHal<E> for Ga102<E> {
117118
fn program_brom(&self, _falcon: &Falcon<E>, bar: &Bar0, params: &FalconBromParams) -> Result {
118119
program_brom_ga102::<E>(bar, params)
119120
}
121+
122+
fn is_riscv_active(&self, bar: &Bar0) -> bool {
123+
let cpuctl = regs::NV_PRISCV_RISCV_CPUCTL::read(bar, &E::ID);
124+
cpuctl.active_stat()
125+
}
126+
127+
fn reset_wait_mem_scrubbing(&self, bar: &Bar0) -> Result {
128+
// TIMEOUT: memory scrubbing should complete in less than 20ms.
129+
read_poll_timeout(
130+
|| Ok(regs::NV_PFALCON_FALCON_HWCFG2::read(bar, &E::ID)),
131+
|r| r.mem_scrubbing_done(),
132+
Delta::ZERO,
133+
Delta::from_millis(20),
134+
)
135+
.map(|_| ())
136+
}
137+
138+
fn reset_eng(&self, bar: &Bar0) -> Result {
139+
let _ = regs::NV_PFALCON_FALCON_HWCFG2::read(bar, &E::ID);
140+
141+
// According to OpenRM's `kflcnPreResetWait_GA102` documentation, HW sometimes does not set
142+
// RESET_READY so a non-failing timeout is used.
143+
let _ = read_poll_timeout(
144+
|| Ok(regs::NV_PFALCON_FALCON_HWCFG2::read(bar, &E::ID)),
145+
|r| r.reset_ready(),
146+
Delta::ZERO,
147+
Delta::from_micros(150),
148+
);
149+
150+
regs::NV_PFALCON_FALCON_ENGINE::update(bar, &E::ID, |v| v.set_reset(true));
151+
152+
// TIMEOUT: falcon engine should not take more than 10us to reset.
153+
fsleep(Delta::from_micros(10));
154+
155+
regs::NV_PFALCON_FALCON_ENGINE::update(bar, &E::ID, |v| v.set_reset(false));
156+
157+
self.reset_wait_mem_scrubbing(bar)?;
158+
159+
Ok(())
160+
}
120161
}

0 commit comments

Comments
 (0)