Re: [PATCH v6 5/9] rust: io: add IoRef and IoWrite types

From: Alice Ryhl

Date: Mon Feb 16 2026 - 05:36:04 EST


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?

Alice