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 is_riscv_halted(&self, _falcon: &Falcon<'_, E>) -> Result<bool> { 59 Err(ENOTSUPP) 60 } 61 62 fn reset_wait_mem_scrubbing(&self, falcon: &Falcon<'_, E>) -> Result { 63 // TIMEOUT: memory scrubbing should complete in less than 10ms. 64 read_poll_timeout( 65 || Ok(falcon.bar.read(regs::NV_PFALCON_FALCON_DMACTL::of::<E>())), 66 |r| r.mem_scrubbing_done(), 67 Delta::ZERO, 68 Delta::from_millis(10), 69 ) 70 .map(|_| ()) 71 } 72 73 fn reset_eng(&self, falcon: &Falcon<'_, E>) -> Result { 74 regs::NV_PFALCON_FALCON_ENGINE::reset_engine::<E>(falcon.bar); 75 self.reset_wait_mem_scrubbing(falcon)?; 76 77 Ok(()) 78 } 79 80 fn load_method(&self) -> LoadMethod { 81 LoadMethod::Pio 82 } 83 } 84