xref: /linux/drivers/gpu/nova-core/falcon/hal/tu102.rs (revision 5ea5880764cbb164afb17a62e76ca75dc371409d)
1 // SPDX-License-Identifier: GPL-2.0
2 
3 use core::marker::PhantomData;
4 
5 use kernel::{
6     io::{
7         poll::read_poll_timeout,
8         register::WithBase,
9         Io, //
10     },
11     prelude::*,
12     time::Delta, //
13 };
14 
15 use crate::{
16     driver::Bar0,
17     falcon::{
18         hal::LoadMethod,
19         Falcon,
20         FalconBromParams,
21         FalconEngine, //
22     },
23     regs, //
24 };
25 
26 use super::FalconHal;
27 
28 pub(super) struct Tu102<E: FalconEngine>(PhantomData<E>);
29 
30 impl<E: FalconEngine> Tu102<E> {
31     pub(super) fn new() -> Self {
32         Self(PhantomData)
33     }
34 }
35 
36 impl<E: FalconEngine> FalconHal<E> for Tu102<E> {
37     fn select_core(&self, _falcon: &Falcon<E>, _bar: &Bar0) -> Result {
38         Ok(())
39     }
40 
41     fn signature_reg_fuse_version(
42         &self,
43         _falcon: &Falcon<E>,
44         _bar: &Bar0,
45         _engine_id_mask: u16,
46         _ucode_id: u8,
47     ) -> Result<u32> {
48         Ok(0)
49     }
50 
51     fn program_brom(&self, _falcon: &Falcon<E>, _bar: &Bar0, _params: &FalconBromParams) -> Result {
52         Ok(())
53     }
54 
55     fn is_riscv_active(&self, bar: &Bar0) -> bool {
56         bar.read(regs::NV_PRISCV_RISCV_CORE_SWITCH_RISCV_STATUS::of::<E>())
57             .active_stat()
58     }
59 
60     fn reset_wait_mem_scrubbing(&self, bar: &Bar0) -> Result {
61         // TIMEOUT: memory scrubbing should complete in less than 10ms.
62         read_poll_timeout(
63             || Ok(bar.read(regs::NV_PFALCON_FALCON_DMACTL::of::<E>())),
64             |r| r.mem_scrubbing_done(),
65             Delta::ZERO,
66             Delta::from_millis(10),
67         )
68         .map(|_| ())
69     }
70 
71     fn reset_eng(&self, bar: &Bar0) -> Result {
72         regs::NV_PFALCON_FALCON_ENGINE::reset_engine::<E>(bar);
73         self.reset_wait_mem_scrubbing(bar)?;
74 
75         Ok(())
76     }
77 
78     fn load_method(&self) -> LoadMethod {
79         LoadMethod::Pio
80     }
81 }
82