[RFC PATCH 2/3] virtio: mmio: endian *fixes* *HACK*
Kuan-Wei Chiu
visitorckw at gmail.com
Thu Apr 2 21:43:27 CEST 2026
Hi Daniel,
On Sat, Mar 14, 2026 at 05:53:17PM +0900, Daniel Palmer wrote:
> Hi all,
>
> On Tue, 10 Mar 2026 at 23:01, Daniel Palmer <daniel at thingy.jp> wrote:
> >
> > From: Daniel Palmer <daniel at 0x0f.com>
> >
> > This is an attempt to *fix* virtio mmio on the QEMU m68k virt machine.
> > As far as I can tell all of the registers in the virtio mmio regions
> > should be little endian so after reading them they need to be converted
> > to big endian for the code to work on them? other parts of the code
> > are also doing endian conversion so I'm not sure.
> >
> > Or QEMU is incorrectly giving big endian register values?
> > ---
>
> 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
/*
Regards,
Kuan-Wei
More information about the U-Boot
mailing list