// SPDX-License-Identifier: GPL-2.012use kernel::prelude::*;34use crate::driver::Bar0;5use crate::falcon::{Falcon, FalconBromParams, FalconEngine};6use crate::gpu::Chipset;78mod ga102;910/// Hardware Abstraction Layer for Falcon cores.11///12/// Implements chipset-specific low-level operations. The trait is generic against [`FalconEngine`]13/// so its `BASE` parameter can be used in order to avoid runtime bound checks when accessing14/// registers.15pub(crate) trait FalconHal<E: FalconEngine>: Sync {16/// Activates the Falcon core if the engine is a risvc/falcon dual engine.17fn select_core(&self, _falcon: &Falcon<E>, _bar: &Bar0) -> Result {18Ok(())19}2021/// Returns the fused version of the signature to use in order to run a HS firmware on this22/// falcon instance. `engine_id_mask` and `ucode_id` are obtained from the firmware header.23fn signature_reg_fuse_version(24&self,25falcon: &Falcon<E>,26bar: &Bar0,27engine_id_mask: u16,28ucode_id: u8,29) -> Result<u32>;3031/// Program the boot ROM registers prior to starting a secure firmware.32fn program_brom(&self, falcon: &Falcon<E>, bar: &Bar0, params: &FalconBromParams) -> Result;33}3435/// Returns a boxed falcon HAL adequate for `chipset`.36///37/// We use a heap-allocated trait object instead of a statically defined one because the38/// generic `FalconEngine` argument makes it difficult to define all the combinations39/// statically.40pub(super) fn falcon_hal<E: FalconEngine + 'static>(41chipset: Chipset,42) -> Result<KBox<dyn FalconHal<E>>> {43use Chipset::*;4445let hal = match chipset {46GA102 | GA103 | GA104 | GA106 | GA107 => {47KBox::new(ga102::Ga102::<E>::new(), GFP_KERNEL)? as KBox<dyn FalconHal<E>>48}49_ => return Err(ENOTSUPP),50};5152Ok(hal)53}545556