[PATCH 5/8] rust: io: register: allow paths for relative register bases
Alexandre Courbot <[email protected]> Tue, 21 Jul 2026 04:00:14 -0700
| Newsgroups | dev.linux.lists.nova-gpu,dev.linux.lists.driver-core,org.freedesktop.lists.dri-devel,org.kernel.vger.linux-kernel,org.kernel.vger.rust-for-linux |
|---|---|
| Message-ID | <[email protected]> |
Relative register bases are currently matched as `ident` fragments, so bases declared in another module must first be imported into the current scope. Add `Base: Offset` and `Base: Alias` forms whose bases are matched as `path` fragments. A colon is used because macro_rules! does not allow a `path` fragment to be followed by `+`. The old form continues to be accepted temporarily so in-tree users can be converted in subsequent patches. Signed-off-by: Alexandre Courbot <[email protected]> --- rust/kernel/io/register.rs | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/rust/kernel/io/register.rs b/rust/kernel/io/register.rs index 62208f52752a..4070fabb00f4 100644 --- a/rust/kernel/io/register.rs +++ b/rust/kernel/io/register.rs @@ -801,6 +801,26 @@ fn into_io_op(self) -> (FixedRegisterLoc<T>, T) { /// ``` #[macro_export] macro_rules! register { + // Deprecated `+` syntax for relative registers and their aliases. + ( + $( + $(#[$attr:meta])* $vis:vis $name:ident ($storage:ty) + $([ $size:expr $(, stride = $stride:expr)? ])? + $(@ $($base:ident +)? $offset:literal)? + $(=> $alias:ident $(+ $alias_offset:ty)? $([$alias_idx:expr])? )? + { $($fields:tt)* } + )* + ) => { + $( + $crate::register!( + @reg $(#[$attr])* $vis $name ($storage) $([$size $(, stride = $stride)?])? + $(@ $($base :)? $offset)? + $(=> $alias $(: $alias_offset)? $([$alias_idx])? )? + { $($fields)* } + ); + )* + }; + // 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. @@ -808,8 +828,8 @@ macro_rules! register { $( $(#[$attr:meta])* $vis:vis $name:ident ($storage:ty) $([ $size:expr $(, stride = $stride:expr)? ])? - $(@ $($base:ident +)? $offset:literal)? - $(=> $alias:ident $(+ $alias_offset:path)? $([$alias_idx:expr])? )? + $(@ $($base:path :)? $offset:literal)? + $(=> $alias:path $(: $alias_offset:path)? $([$alias_idx:expr])? )? { $($fields:tt)* } )* ) => { -- 2.55.0