John Hubbard
2025-Nov-08 04:39 UTC
[PATCH v6 3/4] 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 at kernel.org>
Cc: Timur Tabi <ttabi at nvidia.com>
Suggested-by: Alexandre Courbot <acourbot at nvidia.com>
Signed-off-by: John Hubbard <jhubbard at nvidia.com>
---
drivers/gpu/nova-core/gpu.rs | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)
diff --git a/drivers/gpu/nova-core/gpu.rs b/drivers/gpu/nova-core/gpu.rs
index acf564fee9c8..94a6054bab95 100644
--- a/drivers/gpu/nova-core/gpu.rs
+++ b/drivers/gpu/nova-core/gpu.rs
@@ -122,8 +122,10 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>)
-> fmt::Result {
}
/// Enum representation of the GPU generation.
-#[derive(fmt::Debug)]
+#[derive(fmt::Debug, Default, Copy, Clone)]
+#[repr(u8)]
pub(crate) enum Architecture {
+ #[default]
Turing = 0x16,
Ampere = 0x17,
Ada = 0x19,
@@ -142,6 +144,13 @@ fn try_from(value: u8) -> Result<Self> {
}
}
+impl From<Architecture> for u8 {
+ fn from(value: Architecture) -> Self {
+ // CAST: `Architecture` is `repr(u8)`, so this cast is always lossless.
+ value as u8
+ }
+}
+
pub(crate) struct Revision {
pub(crate) major: u8,
pub(crate) minor: u8,
--
2.51.2
Timur Tabi
2025-Nov-08 05:03 UTC
[PATCH v6 3/4] gpu: nova-core: make Architecture behave as a u8 type
On Fri, 2025-11-07 at 20:39 -0800, John Hubbard wrote:> ?/// Enum representation of the GPU generation. > -#[derive(fmt::Debug)] > +#[derive(fmt::Debug, Default, Copy, Clone)] > +#[repr(u8)] > ?pub(crate) enum Architecture { > +??? #[default] > ???? Turing = 0x16, > ???? Ampere = 0x17, > ???? Ada = 0x19, > @@ -142,6 +144,13 @@ fn try_from(value: u8) -> Result<Self> { > ???? } > ?}Does it make sense to designate a default Architecture? Turing is not a fallback for Ampere -- you can't boot an Ampere with Turing's HAL. Also, we don't even make Turing cards any more, so over time, Turing will be less and less common.