From: Alexandre Courbot <acourbot@nvidia.com>
To: "Danilo Krummrich" <dakr@kernel.org>,
"Alice Ryhl" <aliceryhl@google.com>,
"Daniel Almeida" <daniel.almeida@collabora.com>,
"Miguel Ojeda" <ojeda@kernel.org>,
"Boqun Feng" <boqun@kernel.org>, "Gary Guo" <gary@garyguo.net>,
"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
"Benno Lossin" <lossin@kernel.org>,
"Andreas Hindborg" <a.hindborg@kernel.org>,
"Trevor Gross" <tmgross@umich.edu>,
"Tamir Duberstein" <tamird@kernel.org>,
"Onur Özkan" <work@onurozkan.dev>
Cc: John Hubbard <jhubbard@nvidia.com>,
Alistair Popple <apopple@nvidia.com>,
Timur Tabi <ttabi@nvidia.com>,
Eliot Courtney <ecourtney@nvidia.com>,
Zhi Wang <zhiw@nvidia.com>,
driver-core@lists.linux.dev, rust-for-linux@vger.kernel.org,
linux-kernel@vger.kernel.org, nova-gpu@lists.linux.dev,
dri-devel@lists.freedesktop.org,
Alexandre Courbot <acourbot@nvidia.com>
Subject: [PATCH 4/8] rust: io: register: use path fragment in relative internal rules
Date: Tue, 21 Jul 2026 04:00:13 -0700 [thread overview]
Message-ID: <20260721-registers_fix-v1-4-3711b2317e1f@nvidia.com> (raw)
In-Reply-To: <20260721-registers_fix-v1-0-3711b2317e1f@nvidia.com>
The base of a relative register is a type, but its current fragment is
`ident`. This prevents referencing bases that are e.g. declared in
another module.
The `path` fragment is more accurate to represent relative register
bases, but bases are currently followed by `+`, which is forbidden right
after `path` fragments.
`:` is another separator that can carry the desired semantics, and is
legal to follow a `path` fragment. Thus, replace the `+` separator with
`:` in the internal rules so we can change the fragment for relative
register bases to `path`.
The public rule still uses the `+` notation and an `ident` fragment, so
there is no user-facing change yet; only a minor replumbing of the
internals to better support the new syntax introduced in the next patch.
Signed-off-by: Alexandre Courbot <acourbot@nvidia.com>
---
rust/kernel/io/register.rs | 23 ++++++++++++-----------
1 file changed, 12 insertions(+), 11 deletions(-)
diff --git a/rust/kernel/io/register.rs b/rust/kernel/io/register.rs
index 1e0e23e4233f..62208f52752a 100644
--- a/rust/kernel/io/register.rs
+++ b/rust/kernel/io/register.rs
@@ -816,8 +816,8 @@ macro_rules! register {
$(
$crate::register!(
@reg $(#[$attr])* $vis $name ($storage) $([$size $(, stride = $stride)?])?
- $(@ $($base +)? $offset)?
- $(=> $alias $(+ $alias_offset)? $([$alias_idx])? )?
+ $(@ $($base :)? $offset)?
+ $(=> $alias $(: $alias_offset)? $([$alias_idx])? )?
{ $($fields)* }
);
)*
@@ -850,7 +850,7 @@ macro_rules! register {
// Creates a register at a relative offset from a base address provider.
(
- @reg $(#[$attr:meta])* $vis:vis $name:ident ($storage:ty) @ $base:ident + $offset:literal
+ @reg $(#[$attr:meta])* $vis:vis $name:ident ($storage:ty) @ $base:path : $offset:literal
{ $($fields:tt)* }
) => {
$crate::register!(@bitfield $(#[$attr])* $vis struct $name($storage) { $($fields)* });
@@ -860,7 +860,7 @@ macro_rules! register {
// Creates an alias register of relative offset register `alias` with its own fields.
(
- @reg $(#[$attr:meta])* $vis:vis $name:ident ($storage:ty) => $base:ident + $alias:path
+ @reg $(#[$attr:meta])* $vis:vis $name:ident ($storage:ty) => $base:path : $alias:path
{ $($fields:tt)* }
) => {
$crate::register!(@bitfield $(#[$attr])* $vis struct $name($storage) { $($fields)* });
@@ -916,7 +916,7 @@ macro_rules! register {
(
@reg $(#[$attr:meta])* $vis:vis $name:ident ($storage:ty)
[ $size:expr, stride = $stride:expr ]
- @ $base:ident + $offset:literal { $($fields:tt)* }
+ @ $base:path : $offset:literal { $($fields:tt)* }
) => {
$crate::build_assert::static_assert!(::core::mem::size_of::<$storage>() <= $stride);
@@ -928,11 +928,12 @@ macro_rules! register {
// Shortcut for contiguous array of relative registers (stride == size of element).
(
@reg $(#[$attr:meta])* $vis:vis $name:ident ($storage:ty) [ $size:expr ]
- @ $base:ident + $offset:literal { $($fields:tt)* }
+ @ $base:path : $offset:literal { $($fields:tt)* }
) => {
$crate::register!(
- $(#[$attr])* $vis $name($storage) [ $size, stride = ::core::mem::size_of::<$storage>() ]
- @ $base + $offset { $($fields)* }
+ @reg $(#[$attr])* $vis $name($storage)
+ [ $size, stride = ::core::mem::size_of::<$storage>() ]
+ @ $base : $offset { $($fields)* }
);
};
@@ -940,7 +941,7 @@ macro_rules! register {
// fields.
(
@reg $(#[$attr:meta])* $vis:vis $name:ident ($storage:ty)
- => $base:ident + $alias:path [ $idx:expr ] { $($fields:tt)* }
+ => $base:path : $alias:path [ $idx:expr ] { $($fields:tt)* }
) => {
$crate::build_assert::static_assert!(
$idx < <$alias as $crate::io::register::RegisterArray>::SIZE
@@ -987,7 +988,7 @@ impl $crate::io::register::FixedRegister for $name {}
};
// Implementations of relative registers.
- (@io_relative $name:ident @ $base:ident) => {
+ (@io_relative $name:ident @ $base:path) => {
impl $crate::io::register::WithBase for $name {
type BaseFamily = $base;
}
@@ -1007,7 +1008,7 @@ impl $crate::io::register::RegisterArray for $name {
// Implementations of relative array registers.
(
- @io_relative_array $name:ident [ $size:expr, stride = $stride:expr ] @ $base:ident
+ @io_relative_array $name:ident [ $size:expr, stride = $stride:expr ] @ $base:path
) => {
impl $crate::io::register::WithBase for $name {
type BaseFamily = $base;
--
2.55.0
next prev parent reply other threads:[~2026-07-21 11:01 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-21 11:00 [PATCH 0/8] rust: io: register: allow paths for relative register bases Alexandre Courbot
2026-07-21 11:00 ` [PATCH 1/8] rust: io: register: dispatch fixed array shortcut internally Alexandre Courbot
2026-07-21 14:17 ` Gary Guo
2026-07-21 14:24 ` Gary Guo
2026-07-21 11:00 ` [PATCH 2/8] rust: io: register: remove unused rule arguments Alexandre Courbot
2026-07-21 11:00 ` [PATCH 3/8] rust: io: register: use path fragment for alias destination Alexandre Courbot
2026-07-21 11:00 ` Alexandre Courbot [this message]
2026-07-21 11:41 ` [PATCH 4/8] rust: io: register: use path fragment in relative internal rules Alexandre Courbot
2026-07-21 11:00 ` [PATCH 5/8] rust: io: register: allow paths for relative register bases Alexandre Courbot
2026-07-21 11:00 ` [PATCH 6/8] rust: io: register: use new relative base syntax in doc and examples Alexandre Courbot
2026-07-21 11:00 ` [PATCH 7/8] gpu: nova-core: convert relative registers to new syntax Alexandre Courbot
2026-07-21 11:00 ` [PATCH 8/8] rust: io: register: remove deprecated relative register rule Alexandre Courbot
2026-07-21 14:34 ` [PATCH 0/8] rust: io: register: allow paths for relative register bases Gary Guo
2026-07-21 15:02 ` Alexandre Courbot
2026-07-21 15:06 ` Gary Guo
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260721-registers_fix-v1-4-3711b2317e1f@nvidia.com \
--to=acourbot@nvidia.com \
--cc=a.hindborg@kernel.org \
--cc=aliceryhl@google.com \
--cc=apopple@nvidia.com \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun@kernel.org \
--cc=dakr@kernel.org \
--cc=daniel.almeida@collabora.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=driver-core@lists.linux.dev \
--cc=ecourtney@nvidia.com \
--cc=gary@garyguo.net \
--cc=jhubbard@nvidia.com \
--cc=linux-kernel@vger.kernel.org \
--cc=lossin@kernel.org \
--cc=nova-gpu@lists.linux.dev \
--cc=ojeda@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=tamird@kernel.org \
--cc=tmgross@umich.edu \
--cc=ttabi@nvidia.com \
--cc=work@onurozkan.dev \
--cc=zhiw@nvidia.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®