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) {} 52 53 fn is_riscv_active(&self, bar: Bar0<'_>) -> bool { 54 bar.read(regs::NV_PRISCV_RISCV_CORE_SWITCH_RISCV_STATUS::of::<E>()) 55 .active_stat() 56 } 57 58 fn reset_wait_mem_scrubbing(&self, bar: Bar0<'_>) -> Result { 59 // TIMEOUT: memory scrubbing should complete in less than 10ms. 60 read_poll_timeout( 61 || Ok(bar.read(regs::NV_PFALCON_FALCON_DMACTL::of::<E>())), 62 |r| r.mem_scrubbing_done(), 63 Delta::ZERO, 64 Delta::from_millis(10), 65 ) 66 .map(|_| ()) 67 } 68 69 fn reset_eng(&self, bar: Bar0<'_>) -> Result { 70 regs::NV_PFALCON_FALCON_ENGINE::reset_engine::<E>(bar); 71 self.reset_wait_mem_scrubbing(bar)?; 72 73 Ok(()) 74 } 75 76 fn load_method(&self) -> LoadMethod { 77 LoadMethod::Pio 78 } 79 } 80