public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/6] rust: add `bitfield!` and `register!` macros
@ 2026-01-20  6:17 Alexandre Courbot
  2026-01-20  6:17 ` [PATCH 1/6] rust: num: add `shr` and `shl` methods to `Bounded` Alexandre Courbot
                   ` (6 more replies)
  0 siblings, 7 replies; 56+ messages in thread
From: Alexandre Courbot @ 2026-01-20  6:17 UTC (permalink / raw)
  To: Miguel Ojeda, Boqun Feng, Gary Guo, Björn Roy Baron,
	Benno Lossin, Andreas Hindborg, Alice Ryhl, Trevor Gross,
	Danilo Krummrich, Yury Norov
  Cc: John Hubbard, Alistair Popple, Joel Fernandes, Timur Tabi,
	Edwin Peer, Eliot Courtney, Daniel Almeida, Dirk Behme,
	Steven Price, rust-for-linux, linux-kernel, Alexandre Courbot

Add an improved version of nova-core's `bitfield!` and `register!`
macros 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,
- `register!` supports visibility and different storage sizes.

These updates basically turn a register into a bitfield extended with
some controlled I/O. This is reflected in the syntax of the macros,
which are mostly identical save for the additional `@` parameter of
`register!` and the fact that the `struct` keyword is omitted in the
latter, i.e:

  bitfield! {
      pub struct Foo(u32) {
        ...
      }
    }

vs

  register! {
      pub FOO(u32) @ 0x00000100 {
        ...
      }
    }

The use of `struct` in `register!` looks superfluous to me, but we can
of course add it if consistency between the two macros is deemed more
important.

The first commit 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. Second commit adds another convenience method to obtain a
`bool` from single-bit `Bounded`s.

Patches 3-5 add the `bitfield!` and `register!` macros.

The last patch illustrates how these macros are used by converting
nova-core to them, 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 the inclusion
of the KUNIT tests from the previous effort.

This patchset is based on `rust-fixes`, but should apply equally well on
`rust-next`.

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

Signed-off-by: Alexandre Courbot <acourbot@nvidia.com>

---
Alexandre Courbot (5):
      rust: num: add `shr` and `shl` methods to `Bounded`
      rust: num: add `as_bool` method to `Bounded<_, 1>`
      rust: add `bitfield!` macro
      rust: io: add `register!` macro
      [FOR REFERENCE] gpu: nova-core: use the kernel `register!` and `bitfield!` macros

Joel Fernandes (1):
      rust: bitfield: Add KUNIT tests for bitfield

 drivers/gpu/nova-core/bitfield.rs                  | 330 ---------
 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/gsp/fw.rs                    |   5 +-
 drivers/gpu/nova-core/nova_core.rs                 |   3 -
 drivers/gpu/nova-core/regs.rs                      | 265 +++----
 rust/kernel/bitfield.rs                            | 821 +++++++++++++++++++++
 rust/kernel/io.rs                                  |   1 +
 .../regs/macros.rs => rust/kernel/io/register.rs   | 561 +++++++++-----
 rust/kernel/lib.rs                                 |   1 +
 rust/kernel/num/bounded.rs                         |  61 ++
 16 files changed, 1490 insertions(+), 748 deletions(-)
---
base-commit: 2af6ad09fc7dfe9b3610100983cccf16998bf34d
change-id: 20260117-register-ccaba1d21713

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


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

end of thread, other threads:[~2026-01-29 15:13 UTC | newest]

Thread overview: 56+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-01-20  6:17 [PATCH 0/6] rust: add `bitfield!` and `register!` macros Alexandre Courbot
2026-01-20  6:17 ` [PATCH 1/6] rust: num: add `shr` and `shl` methods to `Bounded` Alexandre Courbot
2026-01-20  8:44   ` Alice Ryhl
2026-01-20 12:53     ` Alexandre Courbot
2026-01-20 16:12   ` kernel test robot
2026-01-21  8:15   ` Yury Norov
2026-01-21 10:10     ` Alice Ryhl
2026-01-20  6:17 ` [PATCH 2/6] rust: num: add `as_bool` method to `Bounded<_, 1>` Alexandre Courbot
2026-01-20  8:45   ` Alice Ryhl
2026-01-20  6:17 ` [PATCH 3/6] rust: add `bitfield!` macro Alexandre Courbot
2026-01-20 11:45   ` Dirk Behme
2026-01-20 12:37     ` Miguel Ojeda
2026-01-20 12:47       ` Dirk Behme
2026-01-20 13:08         ` Miguel Ojeda
2026-01-20 13:20           ` Alexandre Courbot
2026-01-20 21:02             ` Miguel Ojeda
2026-01-20 12:51     ` Alexandre Courbot
2026-01-21  9:16   ` Yury Norov
2026-01-26 13:35     ` Alexandre Courbot
2026-01-27  2:55       ` Yury Norov
2026-01-27  3:25         ` Joel Fernandes
2026-01-27  4:49           ` Yury Norov
2026-01-27 10:41             ` Alexandre Courbot
2026-01-27 10:55               ` Miguel Ojeda
2026-01-28  5:27               ` Yury Norov
2026-01-28 14:12                 ` Alexandre Courbot
2026-01-28 18:05                   ` Yury Norov
2026-01-29 13:40                     ` Alexandre Courbot
2026-01-29 15:12                       ` Miguel Ojeda
2026-01-27 11:00             ` Joel Fernandes
2026-01-27 15:02           ` Gary Guo
2026-01-28  1:23             ` Alexandre Courbot
2026-01-28  4:33               ` Yury Norov
2026-01-28 14:02                 ` Alexandre Courbot
2026-01-28 18:12                   ` Yury Norov
2026-01-27  9:57         ` Alexandre Courbot
2026-01-27 21:03           ` John Hubbard
2026-01-27 21:10             ` Gary Guo
2026-01-27 21:22               ` John Hubbard
2026-01-28  1:28               ` Alexandre Courbot
2026-01-28  1:41                 ` John Hubbard
2026-01-20  6:17 ` [PATCH 4/6] rust: bitfield: Add KUNIT tests for bitfield Alexandre Courbot
2026-01-20  6:17 ` [PATCH 5/6] rust: io: add `register!` macro Alexandre Courbot
2026-01-20  6:17 ` [PATCH FOR REFERENCE 6/6] gpu: nova-core: use the kernel `register!` and `bitfield!` macros Alexandre Courbot
2026-01-20 13:14 ` [PATCH 0/6] rust: add `bitfield!` and `register!` macros Miguel Ojeda
2026-01-20 13:38   ` Danilo Krummrich
2026-01-20 13:50     ` Miguel Ojeda
2026-01-20 14:18       ` Danilo Krummrich
2026-01-20 14:57         ` Miguel Ojeda
2026-01-20 15:27           ` Danilo Krummrich
2026-01-20 15:48             ` Miguel Ojeda
2026-01-20 20:01               ` Danilo Krummrich
2026-01-20 20:31                 ` Miguel Ojeda
2026-01-21  5:57                   ` Yury Norov
2026-01-21  6:55                     ` Alexandre Courbot
2026-01-26 14:03                     ` Joel Fernandes

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