[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <DCP5K0R9YB31.2VFUFEFOHV8LR@nvidia.com>
Date: Wed, 10 Sep 2025 22:25:24 +0900
From: "Alexandre Courbot" <acourbot@...dia.com>
To: "Joel Fernandes" <joelagnelf@...dia.com>, "Alexandre Courbot"
<acourbot@...dia.com>
Cc: <linux-kernel@...r.kernel.org>, <dri-devel@...ts.freedesktop.org>,
<dakr@...nel.org>, "Alistair Popple" <apopple@...dia.com>, "Miguel Ojeda"
<ojeda@...nel.org>, "Alex Gaynor" <alex.gaynor@...il.com>, "Boqun Feng"
<boqun.feng@...il.com>, "Gary Guo" <gary@...yguo.net>,
<bjorn3_gh@...tonmail.com>, "Benno Lossin" <lossin@...nel.org>, "Andreas
Hindborg" <a.hindborg@...nel.org>, "Alice Ryhl" <aliceryhl@...gle.com>,
"Trevor Gross" <tmgross@...ch.edu>, "David Airlie" <airlied@...il.com>,
"Simona Vetter" <simona@...ll.ch>, "Maarten Lankhorst"
<maarten.lankhorst@...ux.intel.com>, "Maxime Ripard" <mripard@...nel.org>,
"Thomas Zimmermann" <tzimmermann@...e.de>, "John Hubbard"
<jhubbard@...dia.com>, "Timur Tabi" <ttabi@...dia.com>,
<joel@...lfernandes.org>, "Elle Rhumsaa" <elle@...thered-steel.dev>,
"Daniel Almeida" <daniel.almeida@...labora.com>,
<nouveau@...ts.freedesktop.org>, <rust-for-linux@...r.kernel.org>
Subject: Re: [PATCH v2 1/4] nova-core: bitstruct: Move bitfield-specific
code from register! into new macro
On Wed Sep 10, 2025 at 3:55 AM JST, Joel Fernandes wrote:
> On Tue, Sep 09, 2025 at 11:37:15AM +0900, Alexandre Courbot wrote:
>> On Tue Sep 9, 2025 at 2:16 AM JST, Joel Fernandes wrote:
>> > Hi Alex,
>> >
>> > On 9/7/2025 11:12 PM, Alexandre Courbot wrote:
>> >> On Thu Sep 4, 2025 at 6:54 AM JST, Joel Fernandes wrote:
>> >>> The bitfield-specific into new macro. This will be used to define
>> >>> structs with bitfields, similar to C language.
>> >>>
>> >>> Signed-off-by: Joel Fernandes <joelagnelf@...dia.com>
>> >>> ---
>> >>> drivers/gpu/nova-core/bitstruct.rs | 271 +++++++++++++++++++++++++++
>> >>> drivers/gpu/nova-core/nova_core.rs | 3 +
>> >>> drivers/gpu/nova-core/regs/macros.rs | 247 +-----------------------
>> >>> 3 files changed, 282 insertions(+), 239 deletions(-)
>> >>> create mode 100644 drivers/gpu/nova-core/bitstruct.rs
>> >>>
>> >>> diff --git a/drivers/gpu/nova-core/bitstruct.rs b/drivers/gpu/nova-core/bitstruct.rs
>> >>> new file mode 100644
>> >>> index 000000000000..1dd9edab7d07
>> >>> --- /dev/null
>> >>> +++ b/drivers/gpu/nova-core/bitstruct.rs
>> >>> @@ -0,0 +1,271 @@
>> >>> +// SPDX-License-Identifier: GPL-2.0
>> >>> +//
>> >>> +// bitstruct.rs — Bitfield library for Rust structures
>> >>> +//
>> >>> +// A library that provides support for defining bit fields in Rust
>> >>> +// structures. Also used from things that need bitfields like register macro.
>> >>> +///
>> >>> +/// # Syntax
>> >>> +///
>> >>> +/// ```rust
>> >>> +/// bitstruct! {
>> >>> +/// struct ControlReg {
>> >>
>> >> The `struct` naming here looks a bit confusing to me - as of this patch,
>> >> this is a u32, right? And eventually these types will be limited to primitive types,
>> >> so why not just `ControlReg: u32 {` ?
>> >
>> > This is done in a later patch. This patch is only code movement, in later patch
>> > we add precisely the syntax you're describing when we add storage types, and
>> > update the register! macro. In this patch bitstruct is only u32.
>>
>> My point was, is the `struct` keyword needed at all? Isn't it a bit
>> confusing since these types are technically not Rust structs?
>
> Now that bitstruct has changed to bitfield, I would really insist on leaving
> 'struct' in there.
>
> So it will look like this:
>
> //! bitfield! {
> //! struct ControlReg {
> //! 3:0 mode as u8 ?=> Mode;
> //! 7 state as bool => State;
> //! }
> //! }
>
> Sounds reasonable?
I was about to write "but it not a struct", and then I remembered that
the body of the macro does this:
pub(crate) struct $name(u32);
... so there goes my argument. :') Just one more thing below.
>
>> I agree the `: u32` can be introduced later, the original `register!`
>> macro did not specify any type information so there is indeed no reason
>> to add it in this patch.
>
> Yep.
When you introduce the types, can you change the syntax from `: u32` to
`(u32)`? That way the declaration becomes
bitfield! {
struct ControlReg(u32) {
...
}
}
... which at least looks like a valid declaration for a Rust struct
that wraps a primitive type. Same for registers, if possible.
Powered by blists - more mailing lists