xref: /linux/drivers/gpu/nova-core/gsp/hal.rs (revision ebf164beb9aedac6627d5a2a7da0d1a5807161c3)
1 // SPDX-License-Identifier: GPL-2.0
2 // SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
3 
4 mod gh100;
5 mod tu102;
6 
7 use kernel::{
8     device,
9     dma::Coherent,
10     prelude::*, //
11 };
12 
13 use crate::{
14     driver::Bar0,
15     falcon::{
16         gsp::Gsp as GspEngine,
17         sec2::Sec2,
18         Falcon, //
19     },
20     fb::FbLayout,
21     firmware::gsp::GspFirmware,
22     gpu::{
23         Architecture,
24         Chipset, //
25     },
26     gsp::{
27         Gsp,
28         GspBootContext,
29         GspFwWprMeta, //
30     },
31 };
32 
33 /// Trait for types containing the resources and code required to fully reset the GSP.
34 ///
35 /// The GSP unload code might run in a situation where we cannot load firmware dynamically (e.g.
36 /// because we are in shutdown and the file system is not accessible anymore). Thus, the firmware
37 /// required for unloading is prepared at load time, and stored here until it needs to be run.
38 pub(super) trait UnloadBundle: Send {
39     /// Performs the steps required to properly reset the GSP after it has been stopped.
40     fn run(
41         &self,
42         dev: &device::Device<device::Bound>,
43         bar: Bar0<'_>,
44         gsp_falcon: &Falcon<'_, GspEngine>,
45         sec2_falcon: &Falcon<'_, Sec2>,
46     ) -> Result;
47 }
48 
49 /// Trait implemented by GSP HALs.
50 pub(super) trait GspHal: Send {
51     /// Performs the GSP boot process, loading and running the required firmwares as needed.
52     ///
53     /// Upon success, returns the [`crate::gsp::UnloadBundle`] to use with [`Gsp::unload`], if one
54     /// could be created.
55     fn boot(
56         &self,
57         gsp: &Gsp,
58         ctx: &GspBootContext<'_>,
59         fb_layout: &FbLayout,
60         wpr_meta: &Coherent<GspFwWprMeta>,
61     ) -> Result<Option<crate::gsp::UnloadBundle>>;
62 
63     /// Performs HAL-specific post-GSP boot tasks.
64     ///
65     /// This method is called by the GSP boot code after the GSP is confirmed to be running, and
66     /// after the initialization commands have been pushed onto its queue.
67     fn post_boot(&self, _gsp: &Gsp, _ctx: &GspBootContext<'_>, _gsp_fw: &GspFirmware) -> Result {
68         Ok(())
69     }
70 }
71 
72 /// Returns the GSP HAL to be used for `chipset`.
73 pub(super) fn gsp_hal(chipset: Chipset) -> &'static dyn GspHal {
74     match chipset.arch() {
75         Architecture::Turing | Architecture::Ampere | Architecture::Ada => tu102::TU102_HAL,
76         Architecture::Hopper | Architecture::BlackwellGB10x | Architecture::BlackwellGB20x => {
77             gh100::GH100_HAL
78         }
79     }
80 }
81