Skip to content

Commit 4d98033

Browse files
johnhubbardGnurou
authored andcommitted
gpu: nova-core: make Architecture behave as a u8 type
This allows Architecture to be passed into register!() and bitfield!() macro calls. That in turn requires a default implementation for Architecture. This simplifies transforming BOOT0 (and later, BOOT42) register values into GPU architectures. Cc: Danilo Krummrich <dakr@kernel.org> Cc: Timur Tabi <ttabi@nvidia.com> Suggested-by: Alexandre Courbot <acourbot@nvidia.com> Reviewed-by: Joel Fernandes <joelagnelf@nvidia.com> Signed-off-by: John Hubbard <jhubbard@nvidia.com> Signed-off-by: Alexandre Courbot <acourbot@nvidia.com> Message-ID: <20251115010923.1192144-3-jhubbard@nvidia.com>
1 parent df6137e commit 4d98033

1 file changed

Lines changed: 14 additions & 1 deletion

File tree

drivers/gpu/nova-core/gpu.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,14 @@ impl fmt::Display for Chipset {
122122
}
123123

124124
/// Enum representation of the GPU generation.
125-
#[derive(fmt::Debug)]
125+
///
126+
/// TODO: remove the `Default` trait implementation, and the `#[default]`
127+
/// attribute, once the register!() macro (which creates Architecture items) no
128+
/// longer requires it for read-only fields.
129+
#[derive(fmt::Debug, Default, Copy, Clone)]
130+
#[repr(u8)]
126131
pub(crate) enum Architecture {
132+
#[default]
127133
Turing = 0x16,
128134
Ampere = 0x17,
129135
Ada = 0x19,
@@ -142,6 +148,13 @@ impl TryFrom<u8> for Architecture {
142148
}
143149
}
144150

151+
impl From<Architecture> for u8 {
152+
fn from(value: Architecture) -> Self {
153+
// CAST: `Architecture` is `repr(u8)`, so this cast is always lossless.
154+
value as u8
155+
}
156+
}
157+
145158
pub(crate) struct Revision {
146159
major: u8,
147160
minor: u8,

0 commit comments

Comments
 (0)