Re: [PATCH v6 5/9] rust: io: add IoRef and IoWrite types
From: Alexandre Courbot
Date: Fri Feb 20 2026 - 09:46:56 EST
On Fri Feb 20, 2026 at 5:18 PM JST, Alice Ryhl wrote:
> On Fri, Feb 20, 2026 at 03:38:46PM +0900, Alexandre Courbot wrote:
>> On Mon Feb 16, 2026 at 7:52 PM JST, Alexandre Courbot wrote:
>> > On Mon Feb 16, 2026 at 7:35 PM JST, Alice Ryhl wrote:
>> >> On Mon, Feb 16, 2026 at 06:36:29PM +0900, Alexandre Courbot wrote:
>> >>> On Mon Feb 16, 2026 at 6:01 PM JST, Alice Ryhl wrote:
>> >>> > On Mon, Feb 16, 2026 at 05:04:41PM +0900, Alexandre Courbot wrote:
>> >>> >> I/O accesses are defined by the following properties:
>> >>> >>
>> >>> >> - For reads, a start address, a width, and a type to interpret the read
>> >>> >> value as,
>> >>> >> - For writes, the same as above, and a value to write.
>> >>> >>
>> >>> >> Introduce the `IoRef` trait, which allows implementing types to specify
>> >>> >> the address a type expects to be accessed at, as well as the width of
>> >>> >> the access, and the user-facing type used to perform the access.
>> >>> >>
>> >>> >> This allows read operations to be made generic with the `read` method
>> >>> >> over an `IoRef` argument.
>> >>> >>
>> >>> >> Write operations need a value to write on top of the `IoRef`: fulfill
>> >>> >> that purpose with the `IoWrite`, which is the combination of an `IoRef`
>> >>> >> and a value of the type it expects. This allows write operations to be
>> >>> >> made generic with the `write` method over a single `IoWrite` argument.
>> >>> >>
>> >>> >> The main purpose of these new entities is to allow register types to be
>> >>> >> written using these generic `read` and `write` methods of `Io`.
>> >>> >>
>> >>> >> Co-developed-by: Gary Guo <gary@xxxxxxxxxxx>
>> >>> >> Signed-off-by: Gary Guo <gary@xxxxxxxxxxx>
>> >>> >> Signed-off-by: Alexandre Courbot <acourbot@xxxxxxxxxx>
>> >>> >> ---
>> >>> >> rust/kernel/io.rs | 243 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
>> >>> >> 1 file changed, 243 insertions(+)
>> >>> >>
>> >>> >> diff --git a/rust/kernel/io.rs b/rust/kernel/io.rs
>> >>> >> index b150743ffa4f..6da8593f7858 100644
>> >>> >> --- a/rust/kernel/io.rs
>> >>> >> +++ b/rust/kernel/io.rs
>> >>> >> @@ -173,6 +173,160 @@ pub trait IoCapable<T> {
>> >>> >> unsafe fn io_write(&self, value: T, address: usize);
>> >>> >> }
>> >>> >>
>> >>> >> +/// Reference to an I/O location, describing the offset, width, and return type of an access.
>> >>> >
>> >>> > In the next patch you implement this for usize, but here you say it's a
>> >>> > reference to an I/O location. I'm pretty sure usize is not a reference
>> >>> > to an I/O location.
>> >>>
>> >>> Methods like `read_u8` use a `usize` to reference the location we want
>> >>> to read, so aren't they in that context?
>> >>
>> >> Oh .. I wouldn't use the word "reference" like that. How about "index"
>> >> instead?
>> >
>> > "index" looks more accurate indeed for something that is not a pointer
>> > type.
>>
>> Actually this creates a bit of confusion in `register.rs`, where we have
>> arrays of registers, which `RegisterArrayRef` was built using the index
>> of a particular register within that array. If we rename `IoRef` to
>> `IoIndex` and transitively `RegisterArrayRef` to `RegisterArrayIndex`,
>> we now have an index that takes an index...
>>
>> Besides `IoRef` is more than just an index - it is also an access width,
>> and a type to convert that access from/to. Would `IoSpec` and
>> `specification` be acceptable?
>
> Not using "index" make sense to me, but I don't really understand how
> "spec" fits in either. How about "place" or "location"?
Well it's a specification of how to access an I/O area... kind of.
"Location" sounds good too, and abbreviates nicely to "Loc", let me see
how that looks in practice.