* [PATCH v2 0/3] rust: io: register: a few fixups
@ 2026-07-24 11:37 Alexandre Courbot
2026-07-24 11:37 ` [PATCH v2 1/3] rust: io: register: dispatch shortcut rules internally Alexandre Courbot
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Alexandre Courbot @ 2026-07-24 11:37 UTC (permalink / raw)
To: Danilo Krummrich, Alice Ryhl, Daniel Almeida, Miguel Ojeda,
Boqun Feng, Gary Guo, Björn Roy Baron, Benno Lossin,
Andreas Hindborg, Trevor Gross, Tamir Duberstein, Onur Özkan
Cc: John Hubbard, Alistair Popple, Timur Tabi, Eliot Courtney,
Zhi Wang, driver-core, rust-for-linux, linux-kernel, nova-gpu,
dri-devel, Alexandre Courbot
These patches implement a few fixes to the register macro, notably
removing unused arguments from internal rules, and using the `path`
fragment instead of `ident` when defining a register alias, since the
aliased register is a type.
It is considerably stripped down from the first revision; the original
goal of the series was to fix an inconsistency with the way relative
registers are defined, but since these are likely to go away soon [1],
this part has been dropped and only these minor fixes remain.
This series applies on top of drm-rust-next.
[1] https://lore.kernel.org/all/20260721-typed_register-v1-0-452d72b60262@garyguo.net/
Signed-off-by: Alexandre Courbot <acourbot@nvidia.com>
---
Changes in v2:
- Move a missed conversion of an internal rule to patch 1.
- Remove all patches related to relative registers.
- Link to v1: https://patch.msgid.link/20260721-registers_fix-v1-0-3711b2317e1f@nvidia.com
---
Alexandre Courbot (3):
rust: io: register: dispatch shortcut rules internally
rust: io: register: remove unused rule arguments
rust: io: register: use path fragment for alias destination
rust/kernel/io/register.rs | 40 +++++++++++++++++++++-------------------
1 file changed, 21 insertions(+), 19 deletions(-)
---
base-commit: 6dcbb4b1320fa91fee349462a52bb69135f2e45e
change-id: 20260418-registers_fix-7a67ebef9ba0
Best regards,
--
Alexandre Courbot <acourbot@nvidia.com>
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v2 1/3] rust: io: register: dispatch shortcut rules internally
2026-07-24 11:37 [PATCH v2 0/3] rust: io: register: a few fixups Alexandre Courbot
@ 2026-07-24 11:37 ` Alexandre Courbot
2026-07-24 11:37 ` [PATCH v2 2/3] rust: io: register: remove unused rule arguments Alexandre Courbot
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Alexandre Courbot @ 2026-07-24 11:37 UTC (permalink / raw)
To: Danilo Krummrich, Alice Ryhl, Daniel Almeida, Miguel Ojeda,
Boqun Feng, Gary Guo, Björn Roy Baron, Benno Lossin,
Andreas Hindborg, Trevor Gross, Tamir Duberstein, Onur Özkan
Cc: John Hubbard, Alistair Popple, Timur Tabi, Eliot Courtney,
Zhi Wang, driver-core, rust-for-linux, linux-kernel, nova-gpu,
dri-devel, Alexandre Courbot
A couple of shortcut rules redispatch an already normalized declaration
through the public register! entry point. This is unneeded - the public
rule should only be invoked by users.
Dispatch directly to the appropriate internal @reg rule instead.
Signed-off-by: Alexandre Courbot <acourbot@nvidia.com>
Reviewed-by: Gary Guo <gary@garyguo.net>
---
rust/kernel/io/register.rs | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/rust/kernel/io/register.rs b/rust/kernel/io/register.rs
index 80e638a892d7..e9ee8c2b60e7 100644
--- a/rust/kernel/io/register.rs
+++ b/rust/kernel/io/register.rs
@@ -888,7 +888,8 @@ macro_rules! register {
{ $($fields:tt)* }
) => {
$crate::register!(
- $(#[$attr])* $vis $name($storage) [ $size, stride = ::core::mem::size_of::<$storage>() ]
+ @reg $(#[$attr])* $vis $name($storage)
+ [ $size, stride = ::core::mem::size_of::<$storage>() ]
@ $offset { $($fields)* }
);
};
@@ -932,7 +933,8 @@ macro_rules! register {
@ $base:ident + $offset:literal { $($fields:tt)* }
) => {
$crate::register!(
- $(#[$attr])* $vis $name($storage) [ $size, stride = ::core::mem::size_of::<$storage>() ]
+ @reg $(#[$attr])* $vis $name($storage)
+ [ $size, stride = ::core::mem::size_of::<$storage>() ]
@ $base + $offset { $($fields)* }
);
};
--
2.55.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH v2 2/3] rust: io: register: remove unused rule arguments
2026-07-24 11:37 [PATCH v2 0/3] rust: io: register: a few fixups Alexandre Courbot
2026-07-24 11:37 ` [PATCH v2 1/3] rust: io: register: dispatch shortcut rules internally Alexandre Courbot
@ 2026-07-24 11:37 ` Alexandre Courbot
2026-07-24 11:37 ` [PATCH v2 3/3] rust: io: register: use path fragment for alias destination Alexandre Courbot
2026-08-03 20:46 ` [PATCH v2 0/3] rust: io: register: a few fixups Danilo Krummrich
3 siblings, 0 replies; 5+ messages in thread
From: Alexandre Courbot @ 2026-07-24 11:37 UTC (permalink / raw)
To: Danilo Krummrich, Alice Ryhl, Daniel Almeida, Miguel Ojeda,
Boqun Feng, Gary Guo, Björn Roy Baron, Benno Lossin,
Andreas Hindborg, Trevor Gross, Tamir Duberstein, Onur Özkan
Cc: John Hubbard, Alistair Popple, Timur Tabi, Eliot Courtney,
Zhi Wang, driver-core, rust-for-linux, linux-kernel, nova-gpu,
dri-devel, Alexandre Courbot
A few arguments passed to internal rules are never used and just add
unneeded complexity. Remove them to simplify the rules a bit.
Signed-off-by: Alexandre Courbot <acourbot@nvidia.com>
---
rust/kernel/io/register.rs | 27 ++++++++++++---------------
1 file changed, 12 insertions(+), 15 deletions(-)
diff --git a/rust/kernel/io/register.rs b/rust/kernel/io/register.rs
index e9ee8c2b60e7..32cab54aafff 100644
--- a/rust/kernel/io/register.rs
+++ b/rust/kernel/io/register.rs
@@ -832,7 +832,7 @@ macro_rules! register {
) => {
$crate::register!(@bitfield $(#[$attr])* $vis struct $name($storage) { $($fields)* });
$crate::register!(@io_base $name($storage) @ $offset);
- $crate::register!(@io_fixed $(#[$attr])* $vis $name($storage));
+ $crate::register!(@io_fixed $(#[$attr])* $vis $name);
};
// Creates an alias register of fixed offset register `alias` with its own fields.
@@ -845,7 +845,7 @@ macro_rules! register {
@io_base $name($storage) @
<$alias as $crate::io::register::Register>::OFFSET
);
- $crate::register!(@io_fixed $(#[$attr])* $vis $name($storage));
+ $crate::register!(@io_fixed $(#[$attr])* $vis $name);
};
// Creates a register at a relative offset from a base address provider.
@@ -855,7 +855,7 @@ macro_rules! register {
) => {
$crate::register!(@bitfield $(#[$attr])* $vis struct $name($storage) { $($fields)* });
$crate::register!(@io_base $name($storage) @ $offset);
- $crate::register!(@io_relative $vis $name($storage) @ $base);
+ $crate::register!(@io_relative $name @ $base);
};
// Creates an alias register of relative offset register `alias` with its own fields.
@@ -867,7 +867,7 @@ macro_rules! register {
$crate::register!(
@io_base $name($storage) @ <$alias as $crate::io::register::Register>::OFFSET
);
- $crate::register!(@io_relative $vis $name($storage) @ $base);
+ $crate::register!(@io_relative $name @ $base);
};
// Creates an array of registers at a fixed offset of the MMIO space.
@@ -879,7 +879,7 @@ macro_rules! register {
$crate::register!(@bitfield $(#[$attr])* $vis struct $name($storage) { $($fields)* });
$crate::register!(@io_base $name($storage) @ $offset);
- $crate::register!(@io_array $vis $name($storage) [ $size, stride = $stride ]);
+ $crate::register!(@io_array $name [ $size, stride = $stride ]);
};
// Shortcut for contiguous array of registers (stride == size of element).
@@ -909,7 +909,7 @@ macro_rules! register {
<$alias as $crate::io::register::Register>::OFFSET
+ $idx * <$alias as $crate::io::register::RegisterArray>::STRIDE
);
- $crate::register!(@io_fixed $(#[$attr])* $vis $name($storage));
+ $crate::register!(@io_fixed $(#[$attr])* $vis $name);
};
// Creates an array of registers at a relative offset from a base address provider.
@@ -922,9 +922,7 @@ macro_rules! register {
$crate::register!(@bitfield $(#[$attr])* $vis struct $name($storage) { $($fields)* });
$crate::register!(@io_base $name($storage) @ $offset);
- $crate::register!(
- @io_relative_array $vis $name($storage) [ $size, stride = $stride ] @ $base + $offset
- );
+ $crate::register!(@io_relative_array $name [ $size, stride = $stride ] @ $base);
};
// Shortcut for contiguous array of relative registers (stride == size of element).
@@ -955,7 +953,7 @@ macro_rules! register {
<$alias as $crate::io::register::Register>::OFFSET +
$idx * <$alias as $crate::io::register::RegisterArray>::STRIDE
);
- $crate::register!(@io_relative $vis $name($storage) @ $base);
+ $crate::register!(@io_relative $name @ $base);
};
// Generates the bitfield for the register.
@@ -981,7 +979,7 @@ impl $crate::io::register::Register for $name {
};
// Implementations of fixed registers.
- (@io_fixed $(#[$attr:meta])* $vis:vis $name:ident ($storage:ty)) => {
+ (@io_fixed $(#[$attr:meta])* $vis:vis $name:ident) => {
impl $crate::io::register::FixedRegister for $name {}
$(#[$attr])*
@@ -990,7 +988,7 @@ impl $crate::io::register::FixedRegister for $name {}
};
// Implementations of relative registers.
- (@io_relative $vis:vis $name:ident ($storage:ty) @ $base:ident) => {
+ (@io_relative $name:ident @ $base:ident) => {
impl $crate::io::register::WithBase for $name {
type BaseFamily = $base;
}
@@ -999,7 +997,7 @@ impl $crate::io::register::RelativeRegister for $name {}
};
// Implementations of register arrays.
- (@io_array $vis:vis $name:ident ($storage:ty) [ $size:expr, stride = $stride:expr ]) => {
+ (@io_array $name:ident [ $size:expr, stride = $stride:expr ]) => {
impl $crate::io::register::Array for $name {}
impl $crate::io::register::RegisterArray for $name {
@@ -1010,8 +1008,7 @@ impl $crate::io::register::RegisterArray for $name {
// Implementations of relative array registers.
(
- @io_relative_array $vis:vis $name:ident ($storage:ty) [ $size:expr, stride = $stride:expr ]
- @ $base:ident + $offset:literal
+ @io_relative_array $name:ident [ $size:expr, stride = $stride:expr ] @ $base:ident
) => {
impl $crate::io::register::WithBase for $name {
type BaseFamily = $base;
--
2.55.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH v2 3/3] rust: io: register: use path fragment for alias destination
2026-07-24 11:37 [PATCH v2 0/3] rust: io: register: a few fixups Alexandre Courbot
2026-07-24 11:37 ` [PATCH v2 1/3] rust: io: register: dispatch shortcut rules internally Alexandre Courbot
2026-07-24 11:37 ` [PATCH v2 2/3] rust: io: register: remove unused rule arguments Alexandre Courbot
@ 2026-07-24 11:37 ` Alexandre Courbot
2026-08-03 20:46 ` [PATCH v2 0/3] rust: io: register: a few fixups Danilo Krummrich
3 siblings, 0 replies; 5+ messages in thread
From: Alexandre Courbot @ 2026-07-24 11:37 UTC (permalink / raw)
To: Danilo Krummrich, Alice Ryhl, Daniel Almeida, Miguel Ojeda,
Boqun Feng, Gary Guo, Björn Roy Baron, Benno Lossin,
Andreas Hindborg, Trevor Gross, Tamir Duberstein, Onur Özkan
Cc: John Hubbard, Alistair Popple, Timur Tabi, Eliot Courtney,
Zhi Wang, driver-core, rust-for-linux, linux-kernel, nova-gpu,
dri-devel, Alexandre Courbot
The destination of an alias is always another register, i.e. a `struct`
type. Replace the `ident` fragment with a `path` one in the internal
rules: `path` is more accurate, and allows referencing registers using a
qualified path instead of only identifiers visible from the current
module.
This covers all aliases, except the relative register ones which are to
be removed soon.
The public rule cannot be updated yet because a `+` can still be matched
after the alias; add a TODO item to update it after relative registers
are removed.
Signed-off-by: Alexandre Courbot <acourbot@nvidia.com>
---
rust/kernel/io/register.rs | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/rust/kernel/io/register.rs b/rust/kernel/io/register.rs
index 32cab54aafff..c945eb149cd7 100644
--- a/rust/kernel/io/register.rs
+++ b/rust/kernel/io/register.rs
@@ -804,6 +804,9 @@ macro_rules! register {
// Entry point for the macro, allowing multiple registers to be defined in one call.
// It matches all possible register declaration patterns to dispatch them to corresponding
// `@reg` rule that defines a single register.
+ //
+ // TODO: change `alias:ident` to `alias:path` once relative registers are replaced by I/O
+ // projections.
(
$(
$(#[$attr:meta])* $vis:vis $name:ident ($storage:ty)
@@ -837,7 +840,7 @@ macro_rules! register {
// Creates an alias register of fixed offset register `alias` with its own fields.
(
- @reg $(#[$attr:meta])* $vis:vis $name:ident ($storage:ty) => $alias:ident
+ @reg $(#[$attr:meta])* $vis:vis $name:ident ($storage:ty) => $alias:path
{ $($fields:tt)* }
) => {
$crate::register!(@bitfield $(#[$attr])* $vis struct $name($storage) { $($fields)* });
@@ -896,7 +899,7 @@ macro_rules! register {
// Creates an alias of register `idx` of array of registers `alias` with its own fields.
(
- @reg $(#[$attr:meta])* $vis:vis $name:ident ($storage:ty) => $alias:ident [ $idx:expr ]
+ @reg $(#[$attr:meta])* $vis:vis $name:ident ($storage:ty) => $alias:path [ $idx:expr ]
{ $($fields:tt)* }
) => {
$crate::build_assert::static_assert!(
--
2.55.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH v2 0/3] rust: io: register: a few fixups
2026-07-24 11:37 [PATCH v2 0/3] rust: io: register: a few fixups Alexandre Courbot
` (2 preceding siblings ...)
2026-07-24 11:37 ` [PATCH v2 3/3] rust: io: register: use path fragment for alias destination Alexandre Courbot
@ 2026-08-03 20:46 ` Danilo Krummrich
3 siblings, 0 replies; 5+ messages in thread
From: Danilo Krummrich @ 2026-08-03 20:46 UTC (permalink / raw)
To: Alexandre Courbot
Cc: Danilo Krummrich, Alice Ryhl, Daniel Almeida, Miguel Ojeda,
Boqun Feng, Gary Guo, Björn Roy Baron, Benno Lossin,
Andreas Hindborg, Trevor Gross, Tamir Duberstein, Onur Özkan,
John Hubbard, Alistair Popple, Timur Tabi, Eliot Courtney,
Zhi Wang, driver-core, rust-for-linux, linux-kernel, nova-gpu,
dri-devel
On Fri, 24 Jul 2026 20:37:03 +0900, Alexandre Courbot wrote:
> [PATCH v2 0/3] rust: io: register: a few fixups
Applied, thanks!
Branch: driver-core-testing
Tree: git://git.kernel.org/pub/scm/linux/kernel/git/driver-core/driver-core.git
[1/3] rust: io: register: dispatch shortcut rules internally
commit: ebb314763f97
[2/3] rust: io: register: remove unused rule arguments
commit: 78e9b4389231
[3/3] rust: io: register: use path fragment for alias destination
commit: 2230d3882850
The patches will appear in the next linux-next integration (typically within 24
hours on weekdays).
The patches are in the driver-core-testing branch and will be promoted to
driver-core-next after validation.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-08-03 20:46 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-24 11:37 [PATCH v2 0/3] rust: io: register: a few fixups Alexandre Courbot
2026-07-24 11:37 ` [PATCH v2 1/3] rust: io: register: dispatch shortcut rules internally Alexandre Courbot
2026-07-24 11:37 ` [PATCH v2 2/3] rust: io: register: remove unused rule arguments Alexandre Courbot
2026-07-24 11:37 ` [PATCH v2 3/3] rust: io: register: use path fragment for alias destination Alexandre Courbot
2026-08-03 20:46 ` [PATCH v2 0/3] rust: io: register: a few fixups Danilo Krummrich
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).