projects/linux·blob master · refs

88 lines · 3.3 KiB

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