From: "Danilo Krummrich" <dakr@kernel.org>
To: "Alexandre Courbot" <acourbot@nvidia.com>
Cc: "Alice Ryhl" <aliceryhl@google.com>,
"Daniel Almeida" <daniel.almeida@collabora.com>,
"Miguel Ojeda" <ojeda@kernel.org>, "Gary Guo" <gary@garyguo.net>,
"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
"Benno Lossin" <lossin@kernel.org>,
"Andreas Hindborg" <a.hindborg@kernel.org>,
"Trevor Gross" <tmgross@umich.edu>,
"Boqun Feng" <boqun@kernel.org>,
"Yury Norov" <yury.norov@gmail.com>,
"John Hubbard" <jhubbard@nvidia.com>,
"Alistair Popple" <apopple@nvidia.com>,
"Joel Fernandes" <joelagnelf@nvidia.com>,
"Timur Tabi" <ttabi@nvidia.com>, "Edwin Peer" <epeer@nvidia.com>,
"Eliot Courtney" <ecourtney@nvidia.com>,
"Dirk Behme" <dirk.behme@de.bosch.com>,
"Steven Price" <steven.price@arm.com>,
rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v8 07/10] rust: io: introduce `IntoIoVal` trait and single-argument `write_val`
Date: Thu, 12 Mar 2026 16:54:09 +0100 [thread overview]
Message-ID: <DH0XBLXZD81K.22SWIZ1ZAOW1@kernel.org> (raw)
In-Reply-To: <DH0UR584E7YD.1A41R0UEVJK1D@nvidia.com>
On Thu Mar 12, 2026 at 2:53 PM CET, Alexandre Courbot wrote:
> On Wed Mar 11, 2026 at 11:56 PM JST, Danilo Krummrich wrote:
>> And yes, I am aware that the above wording around the difference between
>> regs::NV_PFALCON_FALCON_RM::of::<E>() and WithBase::of::<E>() is at least a bit
>> vague technically, but my point is about how this appears to users.
>>
>> In any case, the fact that you can write WithBase::of::<E>() as a location
>> argument in the first place proves that `reg` is not *only* a value.
>
> But that is only true in the case of registers.
Agree with this and all the above. But - and this is why I wrote "my point is
about how this appears to users" - users use this API with registers only and
except for the FIFO use-case, which is not implemented yet, it is obvious to
users that part of the location comes from the value type.
I'm not saying that this is a problem. Actually, quite the opposite.
When I proposed the register!() macro, one of the problems I wanted to solve was
that people can't read from a certain location and accidentally treat it as
something semantically different.
Or in other words, if you want to read register A, you shouldn't be able to
accidentally read from B and treat it as A.
> The I/O module can and does cover things other than registers - currently
> primitive values, but we might want to extend that in future (don't ask me
> with what, but I don't see a reason to close the possibility :)).
Neither do I. :)
But, as mentioned above, we should be aware that people notice that for
registers part of the location information comes from the value type (except for
the FIFO case of course) and registers are the thing that people deal with most.
Other use-cases such as I/O memcpy, etc. will be accssible through other APIs,
such as IoSlice, or more generally, IoView.
Having that said, my point is that considering the use-cases it also makes sense
to think about how this API will be perceived.
And from this context something like bar.write((), reg) looks pretty odd.
>> Is this really less confusing than an additional bar.write_reg(reg) that just
>> works with any register?
>
> I don't think it is less or more confusing, in the end they are really
> equivalent.
From your point of view being an expert on the I/O and register!()
implementation details, but please also consider the above.
Also, look at the Tyr patches for instance, they exclusively use write_val().
> What I would like to avoid is having register-specific functions spill
> into the `io` module. I mean, I am not strictly opposed to it if we
> reach the conclusion that it is more convenient to users - in this case
> we could add an `impl Io` block in `register.rs` and add a `write_reg`
> method (and possibly a `read` variant returning the full position
> information?). But if we can just use the same 2 methods everywhere,
> that's better IMHO.
Just leave it in the io module I'd say, register access is probably the most
essential part of I/O, I think there is no need to factor it out.
>>> which is exactly the same length as the `write_val` equivalent - it's
>>> just that you need to remember that `()` can be used in this case. But
>>> if you can remember that your register type can be used with
>>> `write_val`, then why not this? This actually makes me doubt that
>>> `write_val` is needed at all, and if we get rid of it, then we have a
>>> symmetric API.
>>
>> Still not symmetric, and I also don't think we will have a lot of fun explaining
>> people why they have to call it as bar.write((), reg). :(
>>
>> OOC, how would you explain it when the question is raised without arguing with
>> implementation details?
>
> This seems to indicate that instead of a `Io::write_val` method in `io.rs`,
> we might need a `Io::write_reg` method in `register.rs` that is
> dedicated to writing unambiguous registers exclusively. How does that
> sound to you?
I don't see it adds any value to factor it out with an extention trait, rename
to write_reg() seems fine.
Additionally, I'd like to leave it open for the future to add read_reg() method
returning a generic (loc, val) tuple dereferencing to the value in case we see a
repetition of the following pattern.
let reg = bar.read(regs::NV_PFALCON_FALCON_RM::of::<E>());
// modify reg
bar.write(WithBase::of::<E>(), reg)
The reason is the same as mentioned above. In most cases drivers don't want to
switch the base location between a read and a write, i.e. write the value from A
to B.
The most common case is to read from A and write back to A. For instance,
talking to the Tyr folks, they told me that for the array registers they will
have, they will never have the case that they want to write a register value
from A to B.
So, I still think it would be good to provide an option for drivers to prevent
any mistakes in the first place.
Now, obviously this would require that we also provide register accessors that
take a mutable reference for this to work, but that doesn't seem like a big
deal.
I also don't think we have to do this now, but I'd like to have something like
this in the future.
For now s/write_val/write_reg/ and we should be good to go. :)
next prev parent reply other threads:[~2026-03-12 15:54 UTC|newest]
Thread overview: 57+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-09 15:13 [PATCH v8 00/10] rust: add `register!` macro Alexandre Courbot
2026-03-09 15:13 ` [PATCH v8 01/10] rust: enable the `generic_arg_infer` feature Alexandre Courbot
2026-03-11 0:13 ` Yury Norov
2026-03-11 6:16 ` Miguel Ojeda
2026-03-09 15:13 ` [PATCH v8 02/10] rust: num: add `shr` and `shl` methods to `Bounded` Alexandre Courbot
2026-03-11 0:26 ` Yury Norov
2026-03-09 15:14 ` [PATCH v8 03/10] rust: num: add `into_bool` method " Alexandre Courbot
2026-03-11 0:29 ` Yury Norov
2026-03-09 15:14 ` [PATCH v8 04/10] rust: num: make Bounded::get const Alexandre Courbot
2026-03-09 15:14 ` [PATCH v8 05/10] rust: io: add IoLoc type and generic I/O accessors Alexandre Courbot
2026-03-10 15:15 ` Danilo Krummrich
2026-03-09 15:14 ` [PATCH v8 06/10] rust: io: use generic read/write accessors for primitive accesses Alexandre Courbot
2026-03-09 15:29 ` Gary Guo
2026-03-10 1:57 ` Alexandre Courbot
2026-03-10 1:59 ` Alexandre Courbot
2026-03-10 2:04 ` Gary Guo
2026-03-10 15:17 ` Danilo Krummrich
2026-03-09 15:14 ` [PATCH v8 07/10] rust: io: introduce `IntoIoVal` trait and single-argument `write_val` Alexandre Courbot
2026-03-09 15:30 ` Gary Guo
2026-03-10 2:05 ` Alexandre Courbot
2026-03-10 16:34 ` Danilo Krummrich
2026-03-10 22:33 ` Gary Guo
2026-03-11 13:25 ` Danilo Krummrich
2026-03-11 13:42 ` Alexandre Courbot
2026-03-11 13:28 ` Alexandre Courbot
2026-03-11 14:56 ` Danilo Krummrich
2026-03-11 15:42 ` Gary Guo
2026-03-11 16:22 ` Danilo Krummrich
2026-03-11 17:16 ` Gary Guo
2026-03-12 13:53 ` Alexandre Courbot
2026-03-12 15:54 ` Danilo Krummrich [this message]
2026-03-14 1:19 ` Alexandre Courbot
2026-03-09 15:14 ` [PATCH v8 08/10] rust: io: add `register!` macro Alexandre Courbot
2026-03-10 16:39 ` Danilo Krummrich
2026-03-09 15:14 ` [PATCH v8 09/10] sample: rust: pci: use " Alexandre Courbot
2026-03-09 15:14 ` [PATCH FOR REFERENCE v8 10/10] gpu: nova-core: use the kernel " Alexandre Courbot
2026-03-09 15:43 ` Joel Fernandes
2026-03-09 17:34 ` John Hubbard
2026-03-09 17:51 ` Joel Fernandes
2026-03-09 18:01 ` John Hubbard
2026-03-09 18:28 ` Gary Guo
2026-03-09 18:34 ` John Hubbard
2026-03-09 18:42 ` Danilo Krummrich
2026-03-09 18:47 ` John Hubbard
2026-03-09 18:42 ` Gary Guo
2026-03-09 18:50 ` John Hubbard
2026-03-09 18:04 ` Danilo Krummrich
2026-03-09 18:06 ` John Hubbard
2026-03-10 2:18 ` Alexandre Courbot
2026-03-09 18:05 ` [PATCH v8 00/10] rust: add " John Hubbard
2026-03-09 21:08 ` Daniel Almeida
2026-03-10 17:20 ` Danilo Krummrich
2026-03-11 13:01 ` Alexandre Courbot
2026-03-11 13:07 ` Danilo Krummrich
2026-03-11 13:35 ` Alexandre Courbot
2026-03-11 13:38 ` Danilo Krummrich
2026-03-12 2:23 ` Alexandre Courbot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=DH0XBLXZD81K.22SWIZ1ZAOW1@kernel.org \
--to=dakr@kernel.org \
--cc=a.hindborg@kernel.org \
--cc=acourbot@nvidia.com \
--cc=aliceryhl@google.com \
--cc=apopple@nvidia.com \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun@kernel.org \
--cc=daniel.almeida@collabora.com \
--cc=dirk.behme@de.bosch.com \
--cc=ecourtney@nvidia.com \
--cc=epeer@nvidia.com \
--cc=gary@garyguo.net \
--cc=jhubbard@nvidia.com \
--cc=joelagnelf@nvidia.com \
--cc=linux-kernel@vger.kernel.org \
--cc=lossin@kernel.org \
--cc=ojeda@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=steven.price@arm.com \
--cc=tmgross@umich.edu \
--cc=ttabi@nvidia.com \
--cc=yury.norov@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox