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>
Signed-off-by: John Hubbard <jhubbard@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
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.
On 11/7/25 9:03 PM, Timur Tabi wrote:
> 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 --
Definitely not! However, we do want to use Architecture in places
(register! and bitfield! macros) that expect u8 or u32, and that also
expect to use integer defaults.
So that's why we have to supply it.
thanks,
--
John Hubbard
On Sat Nov 8, 2025 at 2:08 PM JST, John Hubbard wrote:
> On 11/7/25 9:03 PM, Timur Tabi wrote:
>> 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 --
>
> Definitely not! However, we do want to use Architecture in places
> (register! and bitfield! macros) that expect u8 or u32, and that also
> expect to use integer defaults.
>
> So that's why we have to supply it.
To be precise, we need to supply this because of a shortcoming in the
`register`` macro: it doesn't support read-only registers yet, and write
support requires a `Default` implementation for its fields. This is
subject to be fixed in the future but for now we need this little
workaround.
On Sat, 2025-11-08 at 20:45 +0900, Alexandre Courbot wrote: > To be precise, we need to supply this because of a shortcoming in the > `register`` macro: it doesn't support read-only registers yet, and write > support requires a `Default` implementation for its fields. This is > subject to be fixed in the future but for now we need this little > workaround. This definitely feels like something that needs a TODO comment.
On 11/8/25 9:27 AM, Timur Tabi wrote: > On Sat, 2025-11-08 at 20:45 +0900, Alexandre Courbot wrote: >> To be precise, we need to supply this because of a shortcoming in the >> `register`` macro: it doesn't support read-only registers yet, and write >> support requires a `Default` implementation for its fields. This is >> subject to be fixed in the future but for now we need this little >> workaround. > > This definitely feels like something that needs a TODO comment. I've drafted it this way, for the next patchset revision: /// Enum representation of the GPU generation. /// /// TODO: remove the `Default` trait implementation, and the `#[default]` /// attribute, once the register!() macro (which creates Architecture items) no /// longer requires it for read-only fields. thanks, -- John Hubbard
© 2016 - 2025 Red Hat, Inc.