Skip to content

Commit 61479ae

Browse files
GnurouDanilo Krummrich
authored andcommitted
gpu: nova-core: move Firmware to firmware module
We will extend the firmware methods, so move it to its own module instead to keep gpu.rs focused. Signed-off-by: Alexandre Courbot <[email protected]> Link: https://lore.kernel.org/r/[email protected] [ Don't require a bound device, remove pub visibility from Firmware fields, use FIRMWARE_VERSION consistently. - Danilo ] Signed-off-by: Danilo Krummrich <[email protected]>
1 parent e4bc82a commit 61479ae

File tree

2 files changed

+43
-36
lines changed

2 files changed

+43
-36
lines changed

drivers/gpu/nova-core/firmware.rs

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,49 @@
11
// SPDX-License-Identifier: GPL-2.0
22

3-
use crate::gpu;
3+
//! Contains structures and functions dedicated to the parsing, building and patching of firmwares
4+
//! to be loaded into a given execution unit.
5+
6+
use kernel::device;
47
use kernel::firmware;
8+
use kernel::prelude::*;
9+
use kernel::str::CString;
10+
11+
use crate::gpu;
12+
use crate::gpu::Chipset;
13+
14+
pub(crate) const FIRMWARE_VERSION: &str = "535.113.01";
15+
16+
/// Structure encapsulating the firmware blobs required for the GPU to operate.
17+
#[expect(dead_code)]
18+
pub(crate) struct Firmware {
19+
booter_load: firmware::Firmware,
20+
booter_unload: firmware::Firmware,
21+
bootloader: firmware::Firmware,
22+
gsp: firmware::Firmware,
23+
}
24+
25+
impl Firmware {
26+
pub(crate) fn new(dev: &device::Device, chipset: Chipset, ver: &str) -> Result<Firmware> {
27+
let mut chip_name = CString::try_from_fmt(fmt!("{}", chipset))?;
28+
chip_name.make_ascii_lowercase();
29+
30+
let request = |name_| {
31+
CString::try_from_fmt(fmt!("nvidia/{}/gsp/{}-{}.bin", &*chip_name, name_, ver))
32+
.and_then(|path| firmware::Firmware::request(&path, dev))
33+
};
34+
35+
Ok(Firmware {
36+
booter_load: request("booter_load")?,
37+
booter_unload: request("booter_unload")?,
38+
bootloader: request("bootloader")?,
39+
gsp: request("gsp")?,
40+
})
41+
}
42+
}
543

644
pub(crate) struct ModInfoBuilder<const N: usize>(firmware::ModInfoBuilder<N>);
745

846
impl<const N: usize> ModInfoBuilder<N> {
9-
const VERSION: &'static str = "535.113.01";
10-
1147
const fn make_entry_file(self, chipset: &str, fw: &str) -> Self {
1248
ModInfoBuilder(
1349
self.0
@@ -17,7 +53,7 @@ impl<const N: usize> ModInfoBuilder<N> {
1753
.push("/gsp/")
1854
.push(fw)
1955
.push("-")
20-
.push(Self::VERSION)
56+
.push(FIRMWARE_VERSION)
2157
.push(".bin"),
2258
)
2359
}

drivers/gpu/nova-core/gpu.rs

Lines changed: 3 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
// SPDX-License-Identifier: GPL-2.0
22

3-
use kernel::{
4-
device, devres::Devres, error::code::*, firmware, fmt, pci, prelude::*, str::CString,
5-
};
3+
use kernel::{device, devres::Devres, error::code::*, pci, prelude::*};
64

75
use crate::driver::Bar0;
6+
use crate::firmware::{Firmware, FIRMWARE_VERSION};
87
use crate::regs;
98
use crate::util;
109
use core::fmt;
@@ -157,34 +156,6 @@ impl Spec {
157156
}
158157
}
159158

160-
/// Structure encapsulating the firmware blobs required for the GPU to operate.
161-
#[expect(dead_code)]
162-
pub(crate) struct Firmware {
163-
booter_load: firmware::Firmware,
164-
booter_unload: firmware::Firmware,
165-
bootloader: firmware::Firmware,
166-
gsp: firmware::Firmware,
167-
}
168-
169-
impl Firmware {
170-
fn new(dev: &device::Device, spec: &Spec, ver: &str) -> Result<Firmware> {
171-
let mut chip_name = CString::try_from_fmt(fmt!("{}", spec.chipset))?;
172-
chip_name.make_ascii_lowercase();
173-
174-
let request = |name_| {
175-
CString::try_from_fmt(fmt!("nvidia/{}/gsp/{}-{}.bin", &*chip_name, name_, ver))
176-
.and_then(|path| firmware::Firmware::request(&path, dev))
177-
};
178-
179-
Ok(Firmware {
180-
booter_load: request("booter_load")?,
181-
booter_unload: request("booter_unload")?,
182-
bootloader: request("bootloader")?,
183-
gsp: request("gsp")?,
184-
})
185-
}
186-
}
187-
188159
/// Structure holding the resources required to operate the GPU.
189160
#[pin_data]
190161
pub(crate) struct Gpu {
@@ -201,7 +172,7 @@ impl Gpu {
201172
) -> Result<impl PinInit<Self>> {
202173
let bar = devres_bar.access(pdev.as_ref())?;
203174
let spec = Spec::new(bar)?;
204-
let fw = Firmware::new(pdev.as_ref(), &spec, "535.113.01")?;
175+
let fw = Firmware::new(pdev.as_ref(), spec.chipset, FIRMWARE_VERSION)?;
205176

206177
dev_info!(
207178
pdev.as_ref(),

0 commit comments

Comments
 (0)