public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: "Alexandre Courbot" <acourbot@nvidia.com>
To: "Dirk Behme" <dirk.behme@de.bosch.com>
Cc: "Danilo Krummrich" <dakr@kernel.org>,
	"Alice Ryhl" <aliceryhl@google.com>,
	"Daniel Almeida" <daniel.almeida@collabora.com>,
	"Miguel Ojeda" <ojeda@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>,
	"Boqun Feng" <boqun@kernel.org>,
	"Yury Norov" <yury.norov@gmail.com>,
	"John Hubbard" <jhubbard@nvidia.com>,
	"Alistair Popple" <apopple@nvidia.com>,
	"Joel Fernandes" <joelagnelf@nvidia.com>,
	"Timur Tabi" <ttabi@nvidia.com>, "Edwin Peer" <epeer@nvidia.com>,
	"Eliot Courtney" <ecourtney@nvidia.com>,
	"Steven Price" <steven.price@arm.com>,
	rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v7 00/10] rust: add `register!` macro
Date: Wed, 25 Feb 2026 22:50:43 +0900	[thread overview]
Message-ID: <DGO3AXDQKCKO.19VWO463SM0WP@nvidia.com> (raw)
In-Reply-To: <a278ad60-5912-4b9e-8930-6fc9ecedbd16@de.bosch.com>

On Wed Feb 25, 2026 at 8:58 PM JST, Dirk Behme wrote:
> On 24.02.2026 15:21, Alexandre Courbot wrote:
>> New revision addressing the v6 feedback - the use of "location" instead
>> of "reference" in particular reads well both in the code and the
>> comments.
>> 
>> As a reminder, since the previous revision we use the I/O type to
>> perform the actual I/O instead of the register type, which moves us from
>> this access pattern:
>> 
>>      let boot0 = regs::NV_PMC_BOOT_0::read(bar);
>> 
>> to this arguably more natural one:
>> 
>>      let boot0 = bar.read(regs::NV_PMC_BOOT_0);
>> 
>> This revision is based on `driver-core-testing` as of 2026-02-24 with
>> [1] applied. A tree with this series and its dependencies is available
>> at [2].
>> 
>> [1] https://lore.kernel.org/all/20260206-io-v2-0-71dea20a06e6@nvidia.com/
>> [2] https://github.com/Gnurou/linux/tree/b4/register
>> 
>> The first patch enables the `generic_arg_infer` feature, which is
>> required for generic type inference and used in subsequent patches. This
>> feature is stable since rustc 1.89.
>> 
>> The second patch adds `shr` and `shl` methods to `Bounded`. These were
>> suggested by Alice during LPC as a way to avoid the use of the
>> controversial `Bounded::from_expr` in both the bitfield macro and the
>> Nova code. The third patch adds another convenience method to obtain a
>> `bool` from single-bit `Bounded`s, while the fourth patch turns
>> `Bounded::get` into a const method in order to make register setter
>> methods const.
>> 
>> Patches 5 and 6 introduce the `IoLoc` and `IoWrite` types around which
>> I/O accesses are centered. This allows registers to be accessed using
>> the same `read` and `write` methods as primitive types.
>> 
>> Patch 7 adds the `register!` macro and the types it requires.
>> 
>> Patch 8 updates the Rust PCI sample driver to use `register!`, as per
>> its TODO item.
>> 
>> Patch 9 illustrates more extensively how this macro is used by
>> converting nova-core to use it, and removing the local implementation.
>> This patch is to be merged one cycle after the other patches.
>> 
>> Patch 10 is an RFC allowing a shorter write syntax to be used in the
>> case of fixed or relative registers. It doesn't need to be merged
>> immediately, but I think it is a good time to discuss it.
>> 
>> I have also removed Gary's signoff on patches 5 and 7 to make sure it
>> doesn't get merged before he gives it explicitly.
>> 
>> Signed-off-by: Alexandre Courbot <acourbot@nvidia.com>
>> 
>> ---
>> Changes in v7:
>> - Use `RES + SHIFT >= N` instead of `RES >= N - SHIFT` in
>>    `Bounded::shr`.
>> - Rename `IoRef` to `IoLoc` and all related types
>>    accordingly.
>> - Use `Into` trait bounds in both directions on `IoLoc`.
>> - Add RFC patch allowing fixed register values to be used directly with
>>    `write`.
>> - Link to v6: https://patch.msgid.link/20260216-register-v6-0-eec9a4de9e9e@nvidia.com
>> 
>> Changes in v6:
>> - Remove Tested-by tags as the code has considerably changed.
>> - Make `Bounded::get` const so it can be used with registers.
>> - Use the `pin_init::zeroed()` const function instead of defining our
>>    own method.
>> - Generalize all `Io` around the new `IoRef` and `IoWrite` types, and
>>    make registers use these as well.
>> - Use the more natural pattern of having the `Io` type perform the I/O
>>    access instead of the register type.
>> - Convert the whole PCI driver example, and not only the PCI
>>    configuration space.
>> - Rename `Bounded::as_bool` to `Bounded::into_bool`.
>> - Drop `Bounded::into_inner` in favor of making `Bounded::get` const.
>> - Link to v5: https://patch.msgid.link/20260129-register-v5-0-c4587c902514@nvidia.com
>> 
>> Changes in v5:
>> - Rename all setters to `with_*` and `with_const_*`.
>> - Use `, stride = ` to specify the stride of register arrays.
>> - Remove `Deref` requirement on the `RegisterIo` trait and make it
>>    `#[doc(hidden)`.
>> - Simplify the top dispatch rule a bit.
>> - Link to v4: https://patch.msgid.link/20260128-register-v4-0-aee3a33d9649@nvidia.com
>> 
>> Changes in v4:
>> - Add `with_` const field setter methods (removing the need to call
>>    `Bounded::new` for constant field values).
>> - Add `into_inner` const method for `Bounded`.
>> - Add `from_raw` and const `zeroed` method to create initial register
>>    values.
>> - More documentation improvements.
>> - Link to v3: https://patch.msgid.link/20260126-register-v3-0-2328a59d7312@nvidia.com
>> 
>> Changes in v3:
>> - Sort the Rust features list alphabetically.
>> - Rebase on top of latest `driver-core-next` including the new Io trait.
>> - Allow several registers to be defined from the same macro invocation.
>> - Remove references to `bitfield!` macro.
>> - Fix doccomment of `shr` and `shl`.
>> - Use `+` syntax for relative register offsets.
>> - Move register arrays size and stride to after the backing type declaration.
>> - Use regular doccomments to document registers and fields (thanks Gary!).
>> - Remove `Default` implementation and implement the more predictable
>>    `Zeroable` instead.
>> - Improve doccomments a bit.
>> - Link to v2: https://patch.msgid.link/20260121-register-v2-0-79d9b8d5e36a@nvidia.com
>> 
>> Changes in v2:
>> - Remove `bitfield!` and put its rules into `register!` to give it more
>>    time to get reviewed.
>> - Allow output type larger than strictly required for `shr` and `shl` on
>>    `Bounded`.
>> - Enable the `generic_arg_infer` feature, required for rustc < 1.89.
>> - Link to v1: https://patch.msgid.link/20260120-register-v1-0-723a1743b557@nvidia.com
>> 
>> ---
>> Alexandre Courbot (10):
>>        rust: enable the `generic_arg_infer` feature
>>        rust: num: add `shr` and `shl` methods to `Bounded`
>>        rust: num: add `into_bool` method to `Bounded`
>>        rust: num: make Bounded::get const
>>        rust: io: add IoLoc and IoWrite types
>>        rust: io: use generic read/write accessors for primitive accesses
>>        rust: io: add `register!` macro
>>        sample: rust: pci: use `register!` macro
>>        [FOR REFERENCE] gpu: nova-core: use the kernel `register!` macro
>>        RFC: rust: io: allow fixed register values directly in `write`
>> 
>>   drivers/gpu/nova-core/falcon.rs           |  249 +++----
>>   drivers/gpu/nova-core/falcon/gsp.rs       |   23 +-
>>   drivers/gpu/nova-core/falcon/hal/ga102.rs |   65 +-
>>   drivers/gpu/nova-core/falcon/hal/tu102.rs |   11 +-
>>   drivers/gpu/nova-core/falcon/sec2.rs      |   17 +-
>>   drivers/gpu/nova-core/fb.rs               |    6 +-
>>   drivers/gpu/nova-core/fb/hal/ga100.rs     |   40 +-
>>   drivers/gpu/nova-core/fb/hal/ga102.rs     |    7 +-
>>   drivers/gpu/nova-core/fb/hal/tu102.rs     |   22 +-
>>   drivers/gpu/nova-core/gfw.rs              |   11 +-
>>   drivers/gpu/nova-core/gpu.rs              |   36 +-
>>   drivers/gpu/nova-core/gsp/boot.rs         |   11 +-
>>   drivers/gpu/nova-core/gsp/cmdq.rs         |   10 +-
>>   drivers/gpu/nova-core/regs.rs             |  544 ++++++++------
>>   drivers/gpu/nova-core/regs/macros.rs      |  739 -------------------
>>   rust/kernel/io.rs                         |  347 +++++++--
>>   rust/kernel/io/register.rs                | 1135 +++++++++++++++++++++++++++++
>>   rust/kernel/lib.rs                        |    3 +
>>   rust/kernel/num/bounded.rs                |   70 +-
>>   samples/rust/rust_driver_pci.rs           |   84 ++-
>>   scripts/Makefile.build                    |    3 +-
>>   21 files changed, 2118 insertions(+), 1315 deletions(-)
>> ---
>> base-commit: 545225ee0b0b6998c7b6ff888f8497681b8b35c4
>> change-id: 20260117-register-ccaba1d21713
>
>
> I converted my simple aarch64 TMU timer example [1] over to v7 (many 
> thanks helping with that!) and gave it a try: It works like with v2. 
> With that:
>
> Tested-by: Dirk Behme <dirk.behme@de.bosch.com>

Really appreciated! And I think we are finally converging, so hopefully
no more big refactoring ahead. :) Still, please let me know if you saw
anything that looked off during the conversion.

  reply	other threads:[~2026-02-25 13:50 UTC|newest]

Thread overview: 64+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-02-24 14:21 [PATCH v7 00/10] rust: add `register!` macro Alexandre Courbot
2026-02-24 14:21 ` [PATCH v7 01/10] rust: enable the `generic_arg_infer` feature Alexandre Courbot
2026-02-24 14:21 ` [PATCH v7 02/10] rust: num: add `shr` and `shl` methods to `Bounded` Alexandre Courbot
2026-02-24 14:21 ` [PATCH v7 03/10] rust: num: add `into_bool` method " Alexandre Courbot
2026-02-24 14:21 ` [PATCH v7 04/10] rust: num: make Bounded::get const Alexandre Courbot
2026-02-27 12:33   ` Gary Guo
2026-02-24 14:21 ` [PATCH v7 05/10] rust: io: add IoLoc and IoWrite types Alexandre Courbot
2026-02-27 18:02   ` Gary Guo
2026-02-27 18:16     ` Danilo Krummrich
2026-02-28  0:33     ` Alexandre Courbot
2026-03-01 15:11       ` Gary Guo
2026-03-02  1:44         ` Alexandre Courbot
2026-03-02 12:53           ` Gary Guo
2026-03-02 13:12             ` Danilo Krummrich
2026-03-02 13:39               ` Gary Guo
2026-03-03  8:14                 ` Alexandre Courbot
2026-03-03  8:31                   ` Alexandre Courbot
2026-03-03 14:55                     ` Alexandre Courbot
2026-03-03 15:05                       ` Gary Guo
2026-03-04 16:18                       ` Danilo Krummrich
2026-03-04 18:39                         ` Gary Guo
2026-03-04 18:58                           ` Gary Guo
2026-03-04 19:19                             ` John Hubbard
2026-03-04 19:53                               ` Danilo Krummrich
2026-03-04 19:57                                 ` John Hubbard
2026-03-04 20:05                                 ` Gary Guo
2026-03-04 19:38                             ` Danilo Krummrich
2026-03-04 19:48                               ` Gary Guo
2026-03-04 20:37                                 ` Danilo Krummrich
2026-03-04 21:13                                   ` Gary Guo
2026-03-04 21:38                                     ` Danilo Krummrich
2026-03-04 21:42                                       ` Danilo Krummrich
2026-03-04 22:15                                       ` Gary Guo
2026-03-04 22:22                                         ` Danilo Krummrich
2026-03-06  5:37                                         ` Alexandre Courbot
2026-03-06  7:47                                           ` Alexandre Courbot
2026-03-06 10:42                                           ` Gary Guo
2026-03-06 11:10                                             ` Alexandre Courbot
2026-03-06 11:35                                               ` Gary Guo
2026-03-06 12:50                                                 ` Alexandre Courbot
2026-03-06 13:20                                                   ` Gary Guo
2026-03-06 14:32                                                     ` Alexandre Courbot
2026-03-06 14:52                                                       ` Alexandre Courbot
2026-03-06 15:10                                                       ` Alexandre Courbot
2026-03-06 15:35                                                         ` Alexandre Courbot
2026-03-06 15:35                                                       ` Gary Guo
2026-03-07  0:05                                                         ` Alexandre Courbot
2026-03-07 21:10                                                           ` Gary Guo
2026-03-07 21:40                                                             ` Danilo Krummrich
2026-03-08 11:43                                                               ` Alexandre Courbot
2026-03-08 11:35                                                             ` Alexandre Courbot
2026-03-04 18:53                         ` Gary Guo
2026-03-04 22:19   ` Gary Guo
2026-03-05 11:02     ` Alexandre Courbot
2026-02-24 14:21 ` [PATCH v7 06/10] rust: io: use generic read/write accessors for primitive accesses Alexandre Courbot
2026-02-27 18:04   ` Gary Guo
2026-02-24 14:21 ` [PATCH v7 07/10] rust: io: add `register!` macro Alexandre Courbot
2026-02-24 14:21 ` [PATCH v7 08/10] sample: rust: pci: use " Alexandre Courbot
2026-02-24 14:21 ` [PATCH FOR REFERENCE v7 09/10] gpu: nova-core: use the kernel " Alexandre Courbot
2026-02-24 14:21 ` [PATCH v7 10/10] RFC: rust: io: allow fixed register values directly in `write` Alexandre Courbot
2026-02-25 11:58 ` [PATCH v7 00/10] rust: add `register!` macro Dirk Behme
2026-02-25 13:50   ` Alexandre Courbot [this message]
2026-02-26 12:01     ` Dirk Behme
2026-02-27 23:30       ` Alexandre Courbot

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=DGO3AXDQKCKO.19VWO463SM0WP@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=dirk.behme@de.bosch.com \
    --cc=ecourtney@nvidia.com \
    --cc=epeer@nvidia.com \
    --cc=gary@garyguo.net \
    --cc=jhubbard@nvidia.com \
    --cc=joelagnelf@nvidia.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lossin@kernel.org \
    --cc=ojeda@kernel.org \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=steven.price@arm.com \
    --cc=tmgross@umich.edu \
    --cc=ttabi@nvidia.com \
    --cc=yury.norov@gmail.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