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 falcon::{ 17 hal::LoadMethod, 18 Falcon, 19 FalconBromParams, 20 FalconEngine, // 21 }, 22 regs, // 23 }; 24 25 use super::FalconHal; 26 27 pub(super) struct Tu102<E: FalconEngine>(PhantomData<E>); 28 29 impl<E: FalconEngine> Tu102<E> { 30 pub(super) fn new() -> Self { 31 Self(PhantomData) 32 } 33 } 34 35 impl<E: FalconEngine> FalconHal<E> for Tu102<E> { 36 fn select_core(&self, _falcon: &Falcon<'_, E>) -> Result { 37 Ok(()) 38 } 39 40 fn signature_reg_fuse_version( 41 &self, 42 _falcon: &Falcon<'_, E>, 43 _engine_id_mask: u16, 44 _ucode_id: u8, 45 ) -> Result<u32> { 46 Ok(0) 47 } 48 49 fn program_brom(&self, _falcon: &Falcon<'_, E>, _params: &FalconBromParams) {} 50 51 fn is_riscv_active(&self, falcon: &Falcon<'_, E>) -> bool { 52 falcon 53 .bar 54 .read(regs::NV_PRISCV_RISCV_CORE_SWITCH_RISCV_STATUS::of::<E>()) 55 .active_stat() 56 } 57 58 fn reset_wait_mem_scrubbing(&self, falcon: &Falcon<'_, E>) -> Result { 59 // TIMEOUT: memory scrubbing should complete in less than 10ms. 60 read_poll_timeout( 61 || Ok(falcon.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, falcon: &Falcon<'_, E>) -> Result { 70 regs::NV_PFALCON_FALCON_ENGINE::reset_engine::<E>(falcon.bar); 71 self.reset_wait_mem_scrubbing(falcon)?; 72 73 Ok(()) 74 } 75 76 fn load_method(&self) -> LoadMethod { 77 LoadMethod::Pio 78 } 79 } 80