xref: /linux/drivers/gpu/nova-core/gsp/hal.rs (revision 43f890d85c03ced99b5ecad5877fb654f0a3f4c4)
1 // SPDX-License-Identifier: GPL-2.0
2 // SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
3 
4 mod ga102;
5 mod gh100;
6 mod tu102;
7 
8 use kernel::{
9     dma::Coherent,
10     prelude::*, //
11 };
12 
13 use crate::{
14     fb::FbLayout,
15     firmware::gsp::GspFirmware,
16     gpu::{
17         Architecture,
18         Chipset, //
19     },
20     gsp::{
21         Gsp,
22         GspBootContext,
23         GspFwWprMeta, //
24     },
25 };
26 
27 /// Trait for types containing the resources and code required to fully reset the GSP.
28 ///
29 /// The GSP unload code might run in a situation where we cannot load firmware dynamically (e.g.
30 /// because we are in shutdown and the file system is not accessible anymore). Thus, the firmware
31 /// required for unloading is prepared at load time, and stored here until it needs to be run.
32 pub(super) trait UnloadBundle: Send {
33     /// Performs the steps required to properly reset the GSP after it has been stopped.
34     fn run(&self, ctx: &mut GspBootContext<'_>) -> Result;
35 }
36 
37 /// Trait implemented by GSP HALs.
38 pub(super) trait GspHal: Send {
39     /// Performs the GSP boot process, loading and running the required firmwares as needed.
40     ///
41     /// Upon success, returns the [`crate::gsp::UnloadBundle`] to use with [`Gsp::unload`], if one
42     /// could be created.
43     fn boot(
44         &self,
45         gsp: &Gsp,
46         ctx: &mut GspBootContext<'_>,
47         fb_layout: &FbLayout,
48         wpr_meta: &Coherent<GspFwWprMeta>,
49     ) -> Result<Option<crate::gsp::UnloadBundle>>;
50 
51     /// Performs HAL-specific post-GSP boot tasks.
52     ///
53     /// This method is called by the GSP boot code after the GSP is confirmed to be running, and
54     /// after the initialization commands have been pushed onto its queue.
55     fn post_boot(
56         &self,
57         _gsp: &Gsp,
58         _ctx: &mut GspBootContext<'_>,
59         _gsp_fw: &GspFirmware,
60     ) -> Result {
61         Ok(())
62     }
63 }
64 
65 /// Returns the names of the firmware files required to boot the GSP of `chipset`, in addition to
66 /// the "bootloader" and "gsp" images required by all chipsets.
67 pub(crate) const fn boot_firmware_files(chipset: Chipset) -> &'static [&'static str] {
68     match chipset.arch() {
69         // Turing chipsets boot the GSP via the SEC2 Booter, and require the FWSEC bootloader.
70         Architecture::Turing => &["booter_load", "booter_unload", "gen_bootloader"],
71         // GA100 also requires the FWSEC bootloader.
72         Architecture::Ampere if matches!(chipset, Chipset::GA100) => {
73             &["booter_load", "booter_unload", "gen_bootloader"]
74         }
75         // Other Ampere chipsets, as well as Ada chipsets, run FWSEC directly.
76         Architecture::Ampere | Architecture::Ada => &["booter_load", "booter_unload"],
77         // Hopper and later chipsets boot the GSP via the FMC image loaded by FSP.
78         Architecture::Hopper | Architecture::BlackwellGB10x | Architecture::BlackwellGB20x => {
79             &["fmc"]
80         }
81     }
82 }
83 
84 /// Returns the GSP HAL to be used for `chipset`.
85 pub(super) fn gsp_hal(chipset: Chipset) -> &'static dyn GspHal {
86     match chipset.arch() {
87         Architecture::Turing => tu102::TU102_HAL,
88         Architecture::Ampere if matches!(chipset, Chipset::GA100) => tu102::TU102_HAL,
89         Architecture::Ampere | Architecture::Ada => ga102::GA102_HAL,
90         Architecture::Hopper | Architecture::BlackwellGB10x | Architecture::BlackwellGB20x => {
91             gh100::GH100_HAL
92         }
93     }
94 }
95