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

Alexandre Courbot
2026-04-06T04:00:19Z

On Mon Apr 6, 2026 at 8:21 AM JST, Gary Guo wrote:
> 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.

I am pretty sure there would still be users for more C-like accessors
over an `Region` - although we should discourage their use, removing
them entirely seems a bit drastic to me.

How about an extension trait of `Io` for when `Io::Type` is a region?
This makes the feature unavailable unless the trait is explicitly
imported - just the right level of friction imho.