mirror of
https://github.com/torvalds/linux.git
synced 2026-05-23 06:31:58 +02:00
gpu: nova-core: register: generate correct Default implementation
The `Default` implementation of a register should be the aggregate of the default values of all its fields, and not simply be zeroed. Reviewed-by: Daniel Almeida <daniel.almeida@collabora.com> Reviewed-by: Lyude Paul <lyude@redhat.com> Link: https://lore.kernel.org/r/20250718-nova-regs-v2-12-7b6a762aa1cd@nvidia.com Signed-off-by: Alexandre Courbot <acourbot@nvidia.com>
This commit is contained in:
parent
6ecd6b73e0
commit
3fa145bef5
|
|
@ -112,14 +112,14 @@ macro_rules! register {
|
||||||
|
|
||||||
// All rules below are helpers.
|
// All rules below are helpers.
|
||||||
|
|
||||||
// Defines the wrapper `$name` type, as well as its relevant implementations (`Debug`, `BitOr`,
|
// Defines the wrapper `$name` type, as well as its relevant implementations (`Debug`,
|
||||||
// and conversion to the value type) and field accessor methods.
|
// `Default`, `BitOr`, and conversion to the value type) and field accessor methods.
|
||||||
(@core $name:ident $(, $comment:literal)? { $($fields:tt)* }) => {
|
(@core $name:ident $(, $comment:literal)? { $($fields:tt)* }) => {
|
||||||
$(
|
$(
|
||||||
#[doc=$comment]
|
#[doc=$comment]
|
||||||
)?
|
)?
|
||||||
#[repr(transparent)]
|
#[repr(transparent)]
|
||||||
#[derive(Clone, Copy, Default)]
|
#[derive(Clone, Copy)]
|
||||||
pub(crate) struct $name(u32);
|
pub(crate) struct $name(u32);
|
||||||
|
|
||||||
impl ::core::ops::BitOr for $name {
|
impl ::core::ops::BitOr for $name {
|
||||||
|
|
@ -162,6 +162,7 @@ fn from(reg: $name) -> u32 {
|
||||||
)*
|
)*
|
||||||
});
|
});
|
||||||
register!(@debug $name { $($field;)* });
|
register!(@debug $name { $($field;)* });
|
||||||
|
register!(@default $name { $($field;)* });
|
||||||
};
|
};
|
||||||
|
|
||||||
// Defines all the field getter/methods methods for `$name`.
|
// Defines all the field getter/methods methods for `$name`.
|
||||||
|
|
@ -321,6 +322,25 @@ fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Generates the `Default` implementation for `$name`.
|
||||||
|
(@default $name:ident { $($field:ident;)* }) => {
|
||||||
|
/// Returns a value for the register where all fields are set to their default value.
|
||||||
|
impl ::core::default::Default for $name {
|
||||||
|
fn default() -> Self {
|
||||||
|
#[allow(unused_mut)]
|
||||||
|
let mut value = Self(Default::default());
|
||||||
|
|
||||||
|
::kernel::macros::paste!(
|
||||||
|
$(
|
||||||
|
value.[<set_ $field>](Default::default());
|
||||||
|
)*
|
||||||
|
);
|
||||||
|
|
||||||
|
value
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
// Generates the IO accessors for a fixed offset register.
|
// Generates the IO accessors for a fixed offset register.
|
||||||
(@io $name:ident @ $offset:expr) => {
|
(@io $name:ident @ $offset:expr) => {
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user