Re: [PATCH 2/8] rust: io: generalize `Mmio` to arbitrary type

Gary Guo
2026-04-05T23:21:31Z

On Sun Apr 5, 2026 at 3:55 PM BST, Alexandre Courbot wrote:
> On Tue Mar 24, 2026 at 12:37 AM JST, Gary Guo wrote:
>> From: Gary Guo <gary@garyguo.net>
>>
>> Currently, `io::Mmio` always represent an untyped region of a compile-time
>> known minimum size, which is roughly equivalent to `void __iomem*` (but
>> with bound checks). However, it is useful to also be to represent I/O
>> memory of a specific type, e.g. `u32 __iomem*` or `struct foo __iomem*`.
>>
>> Thus, make `Mmio` generic on arbitrary `T`, where `T` is a sized type, or a
>> DST that implements `KnownSize`. Similar to the `MmioRaw` change, the
>> existing behaviour is preserved in the form of `Mmio<Region<SIZE>>`. This
>> change brings the MMIO closer to the DMA coherent allocation types that we
>> have, which is already typed.
>
> You probably noticed, but the regular `read8`, `read16` remain available
> irrespective of the `T` parameter, allowing the `Mmio` to be accessed
> using both the structured type and arbitrary primitives with an offset.
> I cannot find a reason to label this as unsound, but it might be
> confusing as it makes projection an additional capability on top of the
> existing raw I/O methods. This might be worth mentioning in the
> documentation, or maybe the primitive accessors should only be made
> available to `Io<Region>`?

Perhaps I could add a new `UntypedIo` trait which is implemented on
`Region`? And I can restrict these methods to be only usable for it.

I would actually prefer to just remove them, and say you should either access
via projections, or via register macro.

Best,
Gary

>
>>
>> To be able to implement `IoKnownSize`, add a `MIN_SIZE` constant to
>> `KnownSize` trait to represent compile-time known minimum size of a
>> specific type.