]> git.ipfire.org Git - thirdparty/linux.git/commit
rust: io: add `register!` macro
authorAlexandre Courbot <acourbot@nvidia.com>
Sat, 14 Mar 2026 01:06:17 +0000 (10:06 +0900)
committerDanilo Krummrich <dakr@kernel.org>
Tue, 17 Mar 2026 19:04:11 +0000 (20:04 +0100)
commit20ba6a1dbcb957152f6d858015b3a3311dd6da49
tree2a5f28ab4eddf4f401e55b34dade8e11673b42c3
parent147b41ba23d63f43ed34e6940417a5506e323370
rust: io: add `register!` macro

Add a macro for defining hardware register types with I/O accessors.

Each register field is represented as a `Bounded` of the appropriate bit
width, ensuring field values are never silently truncated.

Fields can optionally be converted to/from custom types, either fallibly
or infallibly.

The address of registers can be direct, relative, or indexed, supporting
most of the patterns in which registers are arranged.

Suggested-by: Danilo Krummrich <dakr@kernel.org>
Link: https://lore.kernel.org/all/20250306222336.23482-6-dakr@kernel.org/
Co-developed-by: Gary Guo <gary@garyguo.net>
Signed-off-by: Gary Guo <gary@garyguo.net>
Signed-off-by: Alexandre Courbot <acourbot@nvidia.com>
Link: https://patch.msgid.link/20260314-register-v9-7-86805b2f7e9d@nvidia.com
[ * Improve wording and formatting of doc-comments,
  * Import build_assert!(),
  * Add missing inline annotations,
  * Call static_assert!() with absolute path,
  * Use expect instead of allow.

    - Danilo ]
Signed-off-by: Danilo Krummrich <dakr@kernel.org>
rust/kernel/io.rs
rust/kernel/io/register.rs [new file with mode: 0644]