public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/5] rust: add `register!` macro
@ 2026-01-21  7:23 Alexandre Courbot
  2026-01-21  7:23 ` [PATCH v2 1/5] rust: enable the `generic_arg_infer` feature Alexandre Courbot
                   ` (5 more replies)
  0 siblings, 6 replies; 25+ messages in thread
From: Alexandre Courbot @ 2026-01-21  7:23 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
  Cc: Yury Norov, John Hubbard, Alistair Popple, Joel Fernandes,
	Timur Tabi, Edwin Peer, Eliot Courtney, Dirk Behme, Steven Price,
	rust-for-linux, linux-kernel, Alexandre Courbot

Add an improved version of nova-core's `register!` macro to the `kernel`
crate for all drivers to use.

This is not a direct move from `nova-core`, but rather a new
introduction to facilitate code review and introduce features that are
missing in the nova-core versions. Differences notably include:

- Use of `Bounded` to prevent any data truncation when manipulating
  bitfields,
- Extended documentation,
- Doccomments now build and run,
- Supports visibility and different storage sizes.

The `bitfield!` macro of nova-core has for the moment been wrapped into
`register!`, as a set of private rules, to allow `register!` to be
merged first while `bitfield!` undergoes review during the next cycle.
Thus, some of the code from v1 (including `bitfield!`'s doccomments and
Kunit tests) are kept for later.

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. Third patch adds another convenience method to obtain a
`bool` from single-bit `Bounded`s.

Patch 4 adds the `register!` macro. Since it falls under
`rust/kernel/io` it is covered by the corresponding MAINTAINERS entry so
I refrained from adding one just for this file, especially since the
bitfield-related parts will eventually move and what remains is very
tightly related to I/O.

The last patch illustrates 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.

Previous work to extract the macros was done in the partially-merged
[1]. The current series can be considered a reboot with more features
and the `bitfield!` macro being postponed.

This patchset is based on `driver-core-next`.

Note that it also need `rust-fixes` to avoid an `unused_unsafe` warning.

[1] https://lore.kernel.org/all/20251003154748.1687160-1-joelagnelf@nvidia.com/

Signed-off-by: Alexandre Courbot <acourbot@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 (5):
      rust: enable the `generic_arg_infer` feature
      rust: num: add `shr` and `shl` methods to `Bounded`
      rust: num: add `as_bool` method to `Bounded<_, 1>`
      rust: io: add `register!` macro
      [FOR REFERENCE] gpu: nova-core: use the kernel `register!` macro

 drivers/gpu/nova-core/falcon.rs           |  127 ++-
 drivers/gpu/nova-core/falcon/gsp.rs       |   10 +-
 drivers/gpu/nova-core/falcon/hal/ga102.rs |    5 +-
 drivers/gpu/nova-core/falcon/sec2.rs      |   13 +-
 drivers/gpu/nova-core/fb/hal/ga100.rs     |    9 +-
 drivers/gpu/nova-core/gpu.rs              |   24 +-
 drivers/gpu/nova-core/gsp/cmdq.rs         |    2 +-
 drivers/gpu/nova-core/regs.rs             |  265 +++----
 drivers/gpu/nova-core/regs/macros.rs      |  721 -----------------
 rust/kernel/io.rs                         |    1 +
 rust/kernel/io/register.rs                | 1198 +++++++++++++++++++++++++++++
 rust/kernel/lib.rs                        |    3 +
 rust/kernel/num/bounded.rs                |   61 ++
 scripts/Makefile.build                    |    3 +-
 14 files changed, 1485 insertions(+), 957 deletions(-)
---
base-commit: c259cd7ea3c9ad369c473ba2385d82e3432088b1
change-id: 20260117-register-ccaba1d21713

Best regards,
-- 
Alexandre Courbot <acourbot@nvidia.com>


^ permalink raw reply	[flat|nested] 25+ messages in thread

end of thread, other threads:[~2026-01-26 11:46 UTC | newest]

Thread overview: 25+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-01-21  7:23 [PATCH v2 0/5] rust: add `register!` macro Alexandre Courbot
2026-01-21  7:23 ` [PATCH v2 1/5] rust: enable the `generic_arg_infer` feature Alexandre Courbot
2026-01-21 11:48   ` Gary Guo
2026-01-21  7:23 ` [PATCH v2 2/5] rust: num: add `shr` and `shl` methods to `Bounded` Alexandre Courbot
2026-01-21 14:12   ` Gary Guo
2026-01-26  3:23     ` Alexandre Courbot
2026-01-26  3:28       ` Miguel Ojeda
2026-01-21 17:49   ` kernel test robot
2026-01-21  7:23 ` [PATCH v2 3/5] rust: num: add `as_bool` method to `Bounded<_, 1>` Alexandre Courbot
2026-01-21 14:13   ` Gary Guo
2026-01-21  7:23 ` [PATCH v2 4/5] rust: io: add `register!` macro Alexandre Courbot
2026-01-21 13:13   ` Alexandre Courbot
2026-01-21 14:15   ` Gary Guo
2026-01-26  3:23     ` Alexandre Courbot
2026-01-21 14:50   ` Gary Guo
2026-01-21 16:15     ` Miguel Ojeda
2026-01-26  4:31       ` John Hubbard
2026-01-26  4:33         ` John Hubbard
2026-01-26  3:24     ` Alexandre Courbot
2026-01-26  6:57       ` Alexandre Courbot
2026-01-26  7:45       ` Alexandre Courbot
2026-01-26 11:46         ` Alexandre Courbot
2026-01-21 21:39   ` kernel test robot
2026-01-21  7:23 ` [PATCH FOR REFERENCE v2 5/5] gpu: nova-core: use the kernel " Alexandre Courbot
2026-01-21  9:16 ` [PATCH v2 0/5] rust: add " Dirk Behme

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox