// SPDX-License-Identifier: GPL-2.012use kernel::prelude::*;34use crate::{5driver::Bar0,6falcon::{7Falcon,8FalconBromParams,9FalconEngine, //10},11gpu::Chipset,12};1314mod ga102;1516/// Hardware Abstraction Layer for Falcon cores.17///18/// Implements chipset-specific low-level operations. The trait is generic against [`FalconEngine`]19/// so its `BASE` parameter can be used in order to avoid runtime bound checks when accessing20/// registers.21pub(crate) trait FalconHal<E: FalconEngine>: Send + Sync {22/// Activates the Falcon core if the engine is a risvc/falcon dual engine.23fn select_core(&self, _falcon: &Falcon<E>, _bar: &Bar0) -> Result {24Ok(())25}2627/// Returns the fused version of the signature to use in order to run a HS firmware on this28/// falcon instance. `engine_id_mask` and `ucode_id` are obtained from the firmware header.29fn signature_reg_fuse_version(30&self,31falcon: &Falcon<E>,32bar: &Bar0,33engine_id_mask: u16,34ucode_id: u8,35) -> Result<u32>;3637/// Program the boot ROM registers prior to starting a secure firmware.38fn program_brom(&self, falcon: &Falcon<E>, bar: &Bar0, params: &FalconBromParams) -> Result;39}4041/// Returns a boxed falcon HAL adequate for `chipset`.42///43/// We use a heap-allocated trait object instead of a statically defined one because the44/// generic `FalconEngine` argument makes it difficult to define all the combinations45/// statically.46pub(super) fn falcon_hal<E: FalconEngine + 'static>(47chipset: Chipset,48) -> Result<KBox<dyn FalconHal<E>>> {49use Chipset::*;5051let hal = match chipset {52GA102 | GA103 | GA104 | GA106 | GA107 | AD102 | AD103 | AD104 | AD106 | AD107 => {53KBox::new(ga102::Ga102::<E>::new(), GFP_KERNEL)? as KBox<dyn FalconHal<E>>54}55_ => return Err(ENOTSUPP),56};5758Ok(hal)59}606162