[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <DG232UE5TCK2.3FQARVQKDTUIL@garyguo.net>
Date: Fri, 30 Jan 2026 17:01:31 +0000
From: "Gary Guo" <gary@...yguo.net>
To: "Danilo Krummrich" <dakr@...nel.org>, "Gary Guo" <gary@...yguo.net>
Cc: "Alexandre Courbot" <acourbot@...dia.com>, "Alice Ryhl"
<aliceryhl@...gle.com>, "Daniel Almeida" <daniel.almeida@...labora.com>,
"Miguel Ojeda" <ojeda@...nel.org>, "Boqun Feng" <boqun.feng@...il.com>,
Björn Roy Baron <bjorn3_gh@...tonmail.com>, "Benno Lossin"
<lossin@...nel.org>, "Andreas Hindborg" <a.hindborg@...nel.org>, "Trevor
Gross" <tmgross@...ch.edu>, "Yury Norov" <yury.norov@...il.com>, "John
Hubbard" <jhubbard@...dia.com>, "Alistair Popple" <apopple@...dia.com>,
"Joel Fernandes" <joelagnelf@...dia.com>, "Timur Tabi" <ttabi@...dia.com>,
"Edwin Peer" <epeer@...dia.com>, "Eliot Courtney" <ecourtney@...dia.com>,
"Dirk Behme" <dirk.behme@...bosch.com>, "Steven Price"
<steven.price@....com>, <rust-for-linux@...r.kernel.org>,
<linux-kernel@...r.kernel.org>
Subject: Re: [PATCH v4 5/7] rust: io: add `register!` macro
On Fri Jan 30, 2026 at 4:44 PM GMT, Danilo Krummrich wrote:
> On Fri Jan 30, 2026 at 5:14 PM CET, Gary Guo wrote:
>> On Fri Jan 30, 2026 at 6:55 AM GMT, Alexandre Courbot wrote:
>>> No, I'm starting to believe that the fundamental issue is that the
>>> register interface does its I/O backwards, and that design issue is only
>>> exacerbated by the recent I/O redesign. I.e. instead of doing
>>>
>>> regs::NV_PMC_BOOT_0::read(bar);
>>>
>>> We should really do
>>>
>>> bar.read_reg::<regs::NV_PMC_BOOT_0>();
>>>
>>> Because that way we can use deref coercion.
>>>
>>> That's quite a big redesign though, which means I don't believe
>>> `register!` can make it this cycle... I'll give it a try though.
>>
>> Hmm, that's unfortunate, but I think this is indeed a big design change that we
>> should iron out before merging...
>>
>> I think you're right that if we put the methods on `Io` then all of the deref
>> issue would just went away.
>
> I already discussed this with Alex offline and I think we should not take this
> direction just because of the Deref issue, as we can easily overcome this with
> using AsRef (or a custom trait).
`AsRef` won't work for `Io` which is a trait, unlike `Device` which is a type. A
custom trait might work but that's more complex than what Alex purposed.
I'm quite fond of the `io.read_reg(REGISTER_REF)` API suggested. It looks quite
uniform with other I/O acceessor methods, except typed and with constant
offsets.
>
> Whereas the downside of bar.read_reg() is that you end up with a more
> inconsistent and complicated API for drivers.
>
> For instance, with the API as is you can do things like:
>
> register!(NV_PFALCON_FALCON_ENGINE @ PFalconBase[0x000003c0] {
> 0:0 reset as bool;
> });
>
> impl NV_PFALCON_FALCON_ENGINE {
> pub(crate) fn reset_engine<E: FalconEngine>(bar: &Bar0) {
> Self::update(bar, &E::ID, |r| r.set_reset(true));
>
> // TIMEOUT: falcon engine should not take more than 10us to reset.
> time::delay::fsleep(time::Delta::from_micros(10));
>
> Self::update(bar, &E::ID, |r| r.set_reset(false));
> }
> }
The only benefit of this compared to the newly proposed API is that you can use
`Self`. It's not too bad to have (hypothetical API)
pub(crate) fn reset_engine<E: FalconEngine>(bar: &Bar0) {
bar.update_reg(NV_PFALCON_FALCON_ENGINE(&E::ID), |r| r.set_reset(true));
// TIMEOUT: falcon engine should not take more than 10us to reset.
time::delay::fsleep(time::Delta::from_micros(10));
bar.update_reg(NV_PFALCON_FALCON_ENGINE(&E::ID), |r| r.set_reset(true));
}
I also think in most cases these helper function won't be implemented on the
register, so you're not saving much by having the ability to refer to `Self`.
For example, in this case you could implement it on `FalconEngine`.
Best,
Gary
>
> and then use this from the driver code like this:
>
> impl<E: FalconEngine> FalconHal<E> for Tu102<E> {
> fn do_stuff(&self, bar: &Bar0) {
> //...
>
> regs::NV_PFALCON_FALCON_ENGINE::reset_engine::<E>(bar);
>
> //...
> }
> }
>
> Having to implement AsRef (or a custom trait) for the corresponding I/O backend
> implementations is a pretty minor inconvinience compared to the simplicity the
> current API provides to drivers.
Powered by blists - more mailing lists