Re: [PATCH v6 03/20] rust: io: restrict untyped IO access and `register!` to `Region`
From: Daniel Almeida
Date: Tue Jul 07 2026 - 20:24:56 EST
> On 6 Jul 2026, at 09:44, Gary Guo <gary@xxxxxxxxxxx> wrote:
>
> Currently the `Io` trait exposes a bunch of untyped IO accesses, but if the
> `Io` region itself is typed, then it might be weird to have
>
> let io: Mmio<u32> = /* ... */;
> io.read8(1);
>
> while not unsound, it is surely strange. Thus, restrict the untyped methods
> and also the register macro to `Region` type only.
>
> Implement it by adding a generic type to `IoLoc` indicating allowed base
> types. This also paves the way to add typed register blocks in the future;
> for example, we could use this mechanism to block driver A's `register!()`
> generated macro from being used on driver B's MMIO. The same mechanism
> could be used for relative IO registers. These are future opportunities,
> and for now restrict everything to require `IoLoc<Region<SIZE>, _>`.
>
> Suggested-by: Alexandre Courbot <acourbot@xxxxxxxxxx>
> Link: https://lore.kernel.org/rust-for-linux/DHLB3RO3OSF5.2R7F27U99BKLN@xxxxxxxxxx/
> Reviewed-by: Alexandre Courbot <acourbot@xxxxxxxxxx>
> Signed-off-by: Gary Guo <gary@xxxxxxxxxxx>
Reviewed-by: Daniel Almeida <daniel.almeida@xxxxxxxxxxxxx>