xref: /linux/drivers/gpu/nova-core/gsp/hal.rs (revision 23d66dbab84e8518943563df2ced14aaab28b77a)
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         boot::BootUnloadGuard,
28         Gsp,
29         GspBootContext,
30         GspFwWprMeta, //
31     },
32 };
33 
34 /// Trait for types containing the resources and code required to fully reset the GSP.
35 ///
36 /// The GSP unload code might run in a situation where we cannot load firmware dynamically (e.g.
37 /// because we are in shutdown and the file system is not accessible anymore). Thus, the firmware
38 /// required for unloading is prepared at load time, and stored here until it needs to be run.
39 pub(super) trait UnloadBundle: Send {
40     /// Performs the steps required to properly reset the GSP after it has been stopped.
41     fn run(
42         &self,
43         dev: &device::Device<device::Bound>,
44         bar: Bar0<'_>,
45         gsp_falcon: &Falcon<'_, GspEngine>,
46         sec2_falcon: &Falcon<'_, Sec2>,
47     ) -> Result;
48 }
49 
50 /// Trait implemented by GSP HALs.
51 pub(super) trait GspHal: Send {
52     /// Performs the GSP boot process, loading and running the required firmwares as needed.
53     ///
54     /// Upon success, returns a guard that runs the GSP unload sequence if GSP boot does not
55     /// complete.
56     fn boot<'a>(
57         &self,
58         gsp: &'a Gsp,
59         ctx: &GspBootContext<'a>,
60         fb_layout: &FbLayout,
61         wpr_meta: &Coherent<GspFwWprMeta>,
62     ) -> Result<BootUnloadGuard<'a>>;
63 
64     /// Performs HAL-specific post-GSP boot tasks.
65     ///
66     /// This method is called by the GSP boot code after the GSP is confirmed to be running, and
67     /// after the initialization commands have been pushed onto its queue.
68     fn post_boot(&self, _gsp: &Gsp, _ctx: &GspBootContext<'_>, _gsp_fw: &GspFirmware) -> Result {
69         Ok(())
70     }
71 }
72 
73 /// Returns the GSP HAL to be used for `chipset`.
74 pub(super) fn gsp_hal(chipset: Chipset) -> &'static dyn GspHal {
75     match chipset.arch() {
76         Architecture::Turing | Architecture::Ampere | Architecture::Ada => tu102::TU102_HAL,
77         Architecture::Hopper | Architecture::BlackwellGB10x | Architecture::BlackwellGB20x => {
78             gh100::GH100_HAL
79         }
80     }
81 }
82