Skip to content

Commit e66aaaf

Browse files
GnurouDanilo Krummrich
authored andcommitted
gpu: nova-core: allow register aliases
Some registers (notably scratch registers) don't have a definitive purpose, but need to be interpreted differently depending on context. Expand the register!() macro to support a syntax indicating that a register type should be at the same offset as another one, but under a different name, and with different fields and documentation. Signed-off-by: Alexandre Courbot <acourbot@nvidia.com> Link: https://lore.kernel.org/r/20250619-nova-frts-v6-9-ecf41ef99252@nvidia.com Signed-off-by: Danilo Krummrich <dakr@kernel.org>
1 parent cdfe233 commit e66aaaf

1 file changed

Lines changed: 38 additions & 2 deletions

File tree

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

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,20 @@
7171
/// pr_info!("CPU CTL: {:#x}", cpuctl);
7272
/// cpuctl.set_start(true).write(&bar, CPU_BASE);
7373
/// ```
74+
///
75+
/// It is also possible to create a alias register by using the `=> ALIAS` syntax. This is useful
76+
/// for cases where a register's interpretation depends on the context:
77+
///
78+
/// ```no_run
79+
/// register!(SCRATCH_0 @ 0x0000100, "Scratch register 0" {
80+
/// 31:0 value as u32, "Raw value";
81+
///
82+
/// register!(SCRATCH_0_BOOT_STATUS => SCRATCH_0, "Boot status of the firmware" {
83+
/// 0:0 completed as bool, "Whether the firmware has completed booting";
84+
/// ```
85+
///
86+
/// In this example, `SCRATCH_0_BOOT_STATUS` uses the same I/O address as `SCRATCH_0`, while also
87+
/// providing its own `completed` method.
7488
macro_rules! register {
7589
// Creates a register at a fixed offset of the MMIO space.
7690
(
@@ -83,6 +97,17 @@ macro_rules! register {
8397
register!(@io $name @ $offset);
8498
};
8599

100+
// Creates a alias register of fixed offset register `alias` with its own fields.
101+
(
102+
$name:ident => $alias:ident $(, $comment:literal)? {
103+
$($fields:tt)*
104+
}
105+
) => {
106+
register!(@common $name @ $alias::OFFSET $(, $comment)?);
107+
register!(@field_accessors $name { $($fields)* });
108+
register!(@io $name @ $alias::OFFSET);
109+
};
110+
86111
// Creates a register at a relative offset from a base address.
87112
(
88113
$name:ident @ + $offset:literal $(, $comment:literal)? {
@@ -94,11 +119,22 @@ macro_rules! register {
94119
register!(@io$name @ + $offset);
95120
};
96121

122+
// Creates a alias register of relative offset register `alias` with its own fields.
123+
(
124+
$name:ident => + $alias:ident $(, $comment:literal)? {
125+
$($fields:tt)*
126+
}
127+
) => {
128+
register!(@common $name @ $alias::OFFSET $(, $comment)?);
129+
register!(@field_accessors $name { $($fields)* });
130+
register!(@io $name @ + $alias::OFFSET);
131+
};
132+
97133
// All rules below are helpers.
98134

99135
// Defines the wrapper `$name` type, as well as its relevant implementations (`Debug`, `BitOr`,
100136
// and conversion to regular `u32`).
101-
(@common $name:ident @ $offset:literal $(, $comment:literal)?) => {
137+
(@common $name:ident @ $offset:expr $(, $comment:literal)?) => {
102138
$(
103139
#[doc=$comment]
104140
)?
@@ -280,7 +316,7 @@ macro_rules! register {
280316
};
281317

282318
// Creates the IO accessors for a fixed offset register.
283-
(@io $name:ident @ $offset:literal) => {
319+
(@io $name:ident @ $offset:expr) => {
284320
#[allow(dead_code)]
285321
impl $name {
286322
#[inline]

0 commit comments

Comments
 (0)