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