[RFC PATCH 2/3] virtio: mmio: endian *fixes* *HACK*

Daniel Palmer daniel at 0x0f.com
Sat Apr 4 03:49:03 CEST 2026


Hi Kuan-Wei,

On Fri, 3 Apr 2026 at 04:43, Kuan-Wei Chiu <visitorckw at gmail.com> wrote:
> >
> > I have a patch for this in my Linux tree too so I sent that:
> > https://lore.kernel.org/lkml/20260314030612.1949420-1-daniel@thingy.jp/T/#mab66837bb90c30916fd0fc066245bdeb9918e96c
> > It would seem our versions of readl(), writel() etc are broken. For
> > Linux the nommu versions are broken, for u-boot it seems they are all
> > broken. By broken I mean they should be expecting a little endian
> > value from the access and then converting to the CPU endian. (I think)
> >
>
> Sorry for the late reply.
>
> So it sounds like we have to fix all the broken readl/writel() in both
> Linux and U-Boot first.
>
> For U-Boot, I think we need the following fix? (totally untested yet)
>
> diff --git a/arch/m68k/include/asm/io.h b/arch/m68k/include/asm/io.h
> index 35ad4a1c044..0106a57a03e 100644
> --- a/arch/m68k/include/asm/io.h
> +++ b/arch/m68k/include/asm/io.h
> @@ -31,10 +31,10 @@
>  #define writew(b,addr)         ((*(volatile u16 *) (addr)) = (b))
>  #define writel(b,addr)         ((*(volatile u32 *) (addr)) = (b))
>  #else
> -#define readw(addr)            in_be16((volatile u16 *)(addr))
> -#define readl(addr)            in_be32((volatile u32 *)(addr))
> -#define writew(b,addr)         out_be16((volatile u16 *)(addr),(b))
> -#define writel(b,addr)         out_be32((volatile u32 *)(addr),(b))
> +#define readw(addr)            in_le16((volatile u16 *)(addr))
> +#define readl(addr)            in_le32((volatile u32 *)(addr))
> +#define writew(b,addr)         out_le16((volatile u16 *)(addr),(b))
> +#define writel(b,addr)         out_le32((volatile u32 *)(addr),(b))
>  #endif
>
>  /*

Doing this might fix virtio but break anything that relies on the
current behaviour. At least in Linux Coldfire has hacks in its io
macros to retain the broken behaviour for certain places but have the
correct behaviour for others (PCI I guess).
Since MMU-abled classic m68k seems to have the correct behaviour in
Linux I think we should split the u-boot io macros into Coldfire and
classic m68k and make classic m68k match Linux. That will avoid
breaking anything in coldfire that uses the io macros and depends on
the current behavior. But I guess we might need to revisit the pieces
you added for the virt machine to make sure they still work.

nommu classic m68k is broken in Linux but I intend to send a patch to
make it match MMU classic m68k.

Cheers,

Daniel


More information about the U-Boot mailing list