Skip to content

Commit e4bc82a

Browse files
GnurouDanilo Krummrich
authored andcommitted
gpu: nova-core: fix layout of NV_PMC_BOOT_0
The layout of NV_PMC_BOOT_0 has two small issues: - The "chipset" field, while useful to identify a chip, is actually an aggregate of two distinct fields named "architecture" and "implementation". - The "architecture" field is split, with its MSB being at a different location than the rest of its bits. Redefine the register layout to match its actual definition as provided by OpenRM and expose the fully-constructed "architecture" field through our own "Architecture" type. The "chipset" pseudo-field is also useful to have, so keep providing it. Signed-off-by: Alexandre Courbot <[email protected]> Link: https://lore.kernel.org/r/[email protected] [ Use Result from kernel::prelude. - Danilo ] Signed-off-by: Danilo Krummrich <[email protected]>
1 parent c3f2226 commit e4bc82a

File tree

2 files changed

+39
-5
lines changed

2 files changed

+39
-5
lines changed

drivers/gpu/nova-core/gpu.rs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,22 @@ impl fmt::Display for Chipset {
101101
/// Enum representation of the GPU generation.
102102
#[derive(fmt::Debug)]
103103
pub(crate) enum Architecture {
104-
Turing,
105-
Ampere,
106-
Ada,
104+
Turing = 0x16,
105+
Ampere = 0x17,
106+
Ada = 0x19,
107+
}
108+
109+
impl TryFrom<u8> for Architecture {
110+
type Error = Error;
111+
112+
fn try_from(value: u8) -> Result<Self> {
113+
match value {
114+
0x16 => Ok(Self::Turing),
115+
0x17 => Ok(Self::Ampere),
116+
0x19 => Ok(Self::Ada),
117+
_ => Err(ENODEV),
118+
}
119+
}
107120
}
108121

109122
pub(crate) struct Revision {

drivers/gpu/nova-core/regs.rs

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,33 @@
77
#[macro_use]
88
mod macros;
99

10-
use crate::gpu::Chipset;
10+
use crate::gpu::{Architecture, Chipset};
11+
use kernel::prelude::*;
1112

1213
/* PMC */
1314

1415
register!(NV_PMC_BOOT_0 @ 0x00000000, "Basic revision information about the GPU" {
1516
3:0 minor_revision as u8, "Minor revision of the chip";
1617
7:4 major_revision as u8, "Major revision of the chip";
17-
28:20 chipset as u32 ?=> Chipset, "Chipset model";
18+
8:8 architecture_1 as u8, "MSB of the architecture";
19+
23:20 implementation as u8, "Implementation version of the architecture";
20+
28:24 architecture_0 as u8, "Lower bits of the architecture";
1821
});
22+
23+
impl NV_PMC_BOOT_0 {
24+
/// Combines `architecture_0` and `architecture_1` to obtain the architecture of the chip.
25+
pub(crate) fn architecture(self) -> Result<Architecture> {
26+
Architecture::try_from(
27+
self.architecture_0() | (self.architecture_1() << Self::ARCHITECTURE_0.len()),
28+
)
29+
}
30+
31+
/// Combines `architecture` and `implementation` to obtain a code unique to the chipset.
32+
pub(crate) fn chipset(self) -> Result<Chipset> {
33+
self.architecture()
34+
.map(|arch| {
35+
((arch as u32) << Self::IMPLEMENTATION.len()) | self.implementation() as u32
36+
})
37+
.and_then(Chipset::try_from)
38+
}
39+
}

0 commit comments

Comments
 (0)