Skip to content

Commit cdfe233

Browse files
GnurouDanilo Krummrich
authored andcommitted
gpu: nova-core: expose the offset of each register as a type constant
Although we want to access registers using the provided methods, it is sometimes needed to use their raw offset, for instance when working with a register array. Expose the offset of each register using a type constant to avoid resorting to hardcoded values. Reviewed-by: Lyude Paul <lyude@redhat.com> Signed-off-by: Alexandre Courbot <acourbot@nvidia.com> Link: https://lore.kernel.org/r/20250619-nova-frts-v6-8-ecf41ef99252@nvidia.com Signed-off-by: Danilo Krummrich <dakr@kernel.org>
1 parent 8dd1433 commit cdfe233

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

drivers/gpu/nova-core/regs/macros.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ macro_rules! register {
7878
$($fields:tt)*
7979
}
8080
) => {
81-
register!(@common $name $(, $comment)?);
81+
register!(@common $name @ $offset $(, $comment)?);
8282
register!(@field_accessors $name { $($fields)* });
8383
register!(@io $name @ $offset);
8484
};
@@ -89,7 +89,7 @@ macro_rules! register {
8989
$($fields:tt)*
9090
}
9191
) => {
92-
register!(@common $name $(, $comment)?);
92+
register!(@common $name @ $offset $(, $comment)?);
9393
register!(@field_accessors $name { $($fields)* });
9494
register!(@io$name @ + $offset);
9595
};
@@ -98,14 +98,19 @@ macro_rules! register {
9898

9999
// Defines the wrapper `$name` type, as well as its relevant implementations (`Debug`, `BitOr`,
100100
// and conversion to regular `u32`).
101-
(@common $name:ident $(, $comment:literal)?) => {
101+
(@common $name:ident @ $offset:literal $(, $comment:literal)?) => {
102102
$(
103103
#[doc=$comment]
104104
)?
105105
#[repr(transparent)]
106106
#[derive(Clone, Copy, Default)]
107107
pub(crate) struct $name(u32);
108108

109+
#[allow(dead_code)]
110+
impl $name {
111+
pub(crate) const OFFSET: usize = $offset;
112+
}
113+
109114
// TODO: display the raw hex value, then the value of all the fields. This requires
110115
// matching the fields, which will complexify the syntax considerably...
111116
impl ::core::fmt::Debug for $name {

0 commit comments

Comments
 (0)