m68k: nommu: Fix behaviour of io macros on non-CF
Subsystems (2)
RFC PATCH 1/1 m68k: nommu: Fix behaviour of io macros on non-CF
Currently for 68000 readl() and friends are broken in that they return the value from the bus as-is but should be reading a little endian value and swapping it to big endian.
This was found using virtio-mmio on a 68000 virt machine. virtio-mmio is little endian even if the emulated machine is big endian. This works for MMU m68k because the io macros do what is expected there, but if the kernel was built for nommu it breaks.
Potentially this will break some stuff for nommu non-CF m68k users but since there are probably 2 or 3 of us in the world I think we can work it out.
--- arch/m68k/include/asm/io_no.h | 9 --------- 1 file changed, 9 deletions(-)
arch/m68k/include/asm/io_no.h +0 -9
@@ -96,15 +96,6 @@ static inline void writel(u32 value, volatile void __iomem *addr) __raw_writel(swab32(value), addr); } -#else - -#define readb __raw_readb -#define readw __raw_readw -#define readl __raw_readl -#define writeb __raw_writeb -#define writew __raw_writew -#define writel __raw_writel -#endif /* IOMEMBASE */ #if defined(CONFIG_PCI )
Signature · 1 line
2.51.0
Quoted 9 lines · Daniel Palmer
Currently for 68000
readl()and friends are broken in that they return the value from the bus as-is but should be reading a little endian value and swapping it to big endian.This was found using virtio-mmio on a 68000 virt machine. virtio-mmio is little endian even if the emulated machine is big endian. This works for MMU m68k because the io macros do what is expected there, but if the kernel was built for nommu it breaks.
Quoted 8 lines
Potentially this will break some stuff for nommu non-CF m68k users but since there are probably 2 or 3 of us in the world I think we can work it out.
Suggested-by Arnd Bergmann <[email protected]>Link:
https://lore.kernel.org/lkml/[email protected]/Signed-off-by Daniel Palmer <[email protected]>
It looks like the non-swapping readl() on nommu-m68k predates the git history, but apparently the coldfire version was fixed in 4d5303787627 ("m68k: fix read/write multi-byte IO for PCI on ColdFire") to behave like everything else, and dragonball appears does not support ISA or PCI buses, so it never used them.
Arnd
Geert Uytterhoeven
maintainerHi Arnd,
Quoted 19 lines · Arnd Bergmann
Quoted 9 lines · Daniel Palmer
Currently for 68000
readl()and friends are broken in that they return the value from the bus as-is but should be reading a little endian value and swapping it to big endian.This was found using virtio-mmio on a 68000 virt machine. virtio-mmio is little endian even if the emulated machine is big endian. This works for MMU m68k because the io macros do what is expected there, but if the kernel was built for nommu it breaks.
Quoted 8 lines
Potentially this will break some stuff for nommu non-CF m68k users but since there are probably 2 or 3 of us in the world I think we can work it out.
Suggested-by Arnd Bergmann <[email protected]>Link:
https://lore.kernel.org/lkml/[email protected]/Signed-off-by Daniel Palmer <[email protected]>
Quoted 8 lines
Reviewed-by Arnd Bergmann <[email protected]>It looks like the non-swapping
readl()on nommu-m68k predates the git history, but apparently the coldfire version was fixed in4d5303787627("m68k: fix read/write multi-byte IO for PCI on ColdFire") to behave like everything else, and dragonball appears does not support ISA or PCI buses, so it never used them.
Correct. readl() and friends were introduced when it was deemed better to use accessor functions instead of dereferencing volatile pointers directly (which is what several m68k drivers are still doing), but before it was decided that readl() is little endian for PCI everywhere (there was no PCI on m68k at that point in time). And of course that was long before the introduction of ioread32be()...
Gr{oetje,eeting}s,
Geert
Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected] In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds
Greg Ungerer
maintainerHi Daniel,
Quoted 30 lines · Daniel Palmer
Currently for 68000
readl()and friends are broken in that they return the value from the bus as-is but should be reading a little endian value and swapping it to big endian.This was found using virtio-mmio on a 68000 virt machine. virtio-mmio is little endian even if the emulated machine is big endian. This works for MMU m68k because the io macros do what is expected there, but if the kernel was built for nommu it breaks.
Potentially this will break some stuff for nommu non-CF m68k users but since there are probably 2 or 3 of us in the world I think we can work it out.
Suggested-by Arnd Bergmann <[email protected]>Signed-off-by Daniel Palmer <[email protected]>--- arch/m68k/include/asm/io_no.h | 9 --------- 1 file changed, 9 deletions(-)arch/m68k/include/asm/io_no.h +0
-2@@ -96,15 +96,6 @@ static inline void writel(u32 value, volatile void __iomem *addr)__raw_writel (swab32 (value), addr); } -#else -
arch/m68k/include/asm/io_no.h static inline void writel(u32 value, volatile void __iomem *addr) · line 101
Quoted 10 lines
arch/m68k/include/asm/io_no.h +0
-7-#define readb __raw_readb -#define readw __raw_readw -#define readl __raw_readl -#define writeb __raw_writeb -#define writew __raw_writew -#define writel __raw_writel -#endif /* IOMEMBASE */ #if defined(CONFIG_PCI )
This change, in this form at least, breaks most of the non-MMU ColdFire targets. Try compiling any of m5208evb, m5249evb, m5272c3, m5275evb, m5307c3 or m5407c3 defconfigs and you get build failures. Targets that do not have a PCI bus and so do not define IOMEMBASE will fail, which is most of them.
Maybe something like this might be better. I think this ends up giving you the same result for 68000 nommu targets.
arch/m68k/include/asm/io_no.h +1 -1
@@ -33,7 +33,6 @@#include <asm/byteorder.h> #include <asm/coldfire.h> #include <asm/mcfsim.h> -#endif /* CONFIG_COLDFIRE */ #if defined(IOMEMBASE )/*
@@ -126,6 +125,7 @@ static inline void writel(u32 value, volatile void __iomem *addr)#define PCI_IOBASE ((void __iomem *) PCI_IO_PA)#define PCI_SPACE_LIMIT PCI_IO_MASK#endif /* CONFIG_PCI */ +#endif /* CONFIG_COLDFIRE */ #include <asm/kmap.h> #include <asm/virtconvert.h>
Regards
Greg
Hi Greg,
Quoted 4 lines · Greg Ungerer
This change, in this form at least, breaks most of the non-MMU ColdFire targets. Try compiling any of m5208evb, m5249evb, m5272c3, m5275evb, m5307c3 or m5407c3 defconfigs and you get build failures. Targets that do not have a PCI bus and so do not define IOMEMBASE will fail, which is most of them.
Oof, that's the second time I broke coldfire this week (I broke it trying to make virtio work for m68k in u-boot too). Your patch works for my mc68000 virt and dragonball builds. I will build/boot test nommu CF in QEMU.
Thanks,
Daniel
Quoted 6 lines · Daniel Palmer
Quoted 4 lines · Greg Ungerer
This change, in this form at least, breaks most of the non-MMU ColdFire targets. Try compiling any of m5208evb, m5249evb, m5272c3, m5275evb, m5307c3 or m5407c3 defconfigs and you get build failures. Targets that do not have a PCI bus and so do not define IOMEMBASE will fail, which is most of them.
Indeed, I had assumed that coldfire just uses the regular semantics here since it has PCI support, but I see now that it actually relies on both the big-endian access and on passing a physical address as an integer instead of an '__iomem' pointer into writel(), which is something we should probably fix.
Quoted 4 lines
Oof, that's the second time I broke coldfire this week (I broke it trying to make virtio work for m68k in u-boot too). Your patch works for my mc68000 virt and dragonball builds. I will build/boot test nommu CF in QEMU.
Right, this is hopefully fine as a quick fix.
In order to have coldfire behave more like other targets (now including 68000/68328), I would suggest removing the custom readl/writel helpers for coldfire as well, and changing the few callers to something else. A new set of helpers that takes a phys_addr_t would work, or possibly just using the existing __raw_readl()/__raw_writel() or ioread32be()/iowrite32be() where appropriate, see the patch below for the arch/m68k portion of that.
There are other coldfire specific drivers (fec, spi, ...) that would need a similar change.
Arnd
arch/m68k/coldfire/intc-5249.c +5 -5
@@ -20,22 +20,22 @@static void intc2_irq_gpio_mask (struct irq_data *d) {u32 imr; - imr =readl (MCFSIM2_GPIOINTENABLE ); + imr =__raw_readl (MCFSIM2_GPIOINTENABLE ); imr &= ~(0x1 << (d->irq -MCF_IRQ_GPIO0 )); -writel (imr,MCFSIM2_GPIOINTENABLE ); +__raw_writel (imr,MCFSIM2_GPIOINTENABLE ); }static void intc2_irq_gpio_unmask (struct irq_data *d) {u32 imr; - imr =readl (MCFSIM2_GPIOINTENABLE ); + imr =__raw_readl (MCFSIM2_GPIOINTENABLE ); imr |= (0x1 << (d->irq -MCF_IRQ_GPIO0 )); -writel (imr,MCFSIM2_GPIOINTENABLE ); +__raw_writel (imr,MCFSIM2_GPIOINTENABLE ); }static void intc2_irq_gpio_ack (struct irq_data *d) { -writel (0x1 << (d->irq -MCF_IRQ_GPIO0 ),MCFSIM2_GPIOINTCLEAR ); +__raw_writel (0x1 << (d->irq -MCF_IRQ_GPIO0 ),MCFSIM2_GPIOINTCLEAR ); }static struct irq_chip intc2_irq_gpio_chip = {
arch/m68k/coldfire/intc-525x.c +6 -6
@@ -20,7 +20,7 @@static void intc2_irq_gpio_mask (struct irq_data *d) { -u32 imr =readl (MCFSIM2_GPIOINTENABLE ); +u32 imr =__raw_readl (MCFSIM2_GPIOINTENABLE );u32 type =irqd_get_trigger_type (d);int irq = d->irq -MCF_IRQ_GPIO0 ;
@@ -28,12 +28,12 @@ static void intc2_irq_gpio_mask(struct irq_data *d) imr &= ~(0x001 << irq);if (type &IRQ_TYPE_EDGE_FALLING ) imr &= ~(0x100 << irq); -writel (imr,MCFSIM2_GPIOINTENABLE ); +__raw_writel (imr,MCFSIM2_GPIOINTENABLE ); }static void intc2_irq_gpio_unmask (struct irq_data *d) { -u32 imr =readl (MCFSIM2_GPIOINTENABLE ); +u32 imr =__raw_readl (MCFSIM2_GPIOINTENABLE );u32 type =irqd_get_trigger_type (d);int irq = d->irq -MCF_IRQ_GPIO0 ;
@@ -41,7 +41,7 @@ static void intc2_irq_gpio_unmask(struct irq_data *d) imr |= (0x001 << irq);if (type &IRQ_TYPE_EDGE_FALLING ) imr |= (0x100 << irq); -writel (imr,MCFSIM2_GPIOINTENABLE ); +__raw_writel (imr,MCFSIM2_GPIOINTENABLE ); }static void intc2_irq_gpio_ack (struct irq_data *d)
@@ -54,7 +54,7 @@ static void intc2_irq_gpio_ack(struct irq_data *d) imr |= (0x001 << irq);if (type &IRQ_TYPE_EDGE_FALLING ) imr |= (0x100 << irq); -writel (imr,MCFSIM2_GPIOINTCLEAR ); +__raw_writel (imr,MCFSIM2_GPIOINTCLEAR ); }static int intc2_irq_gpio_set_type (struct irq_data *d,unsigned int f)
@@ -77,7 +77,7 @@ static int __init mcf_intc2_init(void)int irq;/* set the interrupt base for the second interrupt controller */ -writel (MCFINTC2_VECBASE ,MCFINTC2_INTBASE ); +__raw_writel (MCFINTC2_VECBASE ,MCFINTC2_INTBASE );/* GPIO interrupt sources */ for (irq =MCF_IRQ_GPIO0 ; (irq <=MCF_IRQ_GPIO6 ); irq++) {
arch/m68k/coldfire/intc-5272.c +10 -10
@@ -86,7 +86,7 @@ static void intc_irq_mask(struct irq_data *d)u32 v; irq -=MCFINT_VECBASE ; v =0x8 << intc_irqmap[irq].index; -writel (v, intc_irqmap[irq].icr); +__raw_writel (v, intc_irqmap[irq].icr); } }
@@ -98,7 +98,7 @@ static void intc_irq_unmask(struct irq_data *d)u32 v; irq -=MCFINT_VECBASE ; v =0xd << intc_irqmap[irq].index; -writel (v, intc_irqmap[irq].icr); +__raw_writel (v, intc_irqmap[irq].icr); } }
@@ -111,10 +111,10 @@ static void intc_irq_ack(struct irq_data *d) irq -=MCFINT_VECBASE ;if (intc_irqmap[irq].ack) {u32 v; - v =readl (intc_irqmap[irq].icr); + v =__raw_readl (intc_irqmap[irq].icr); v &= (0x7 << intc_irqmap[irq].index); v |= (0x8 << intc_irqmap[irq].index); -writel (v, intc_irqmap[irq].icr); +__raw_writel (v, intc_irqmap[irq].icr); } } }
@@ -127,12 +127,12 @@ static int intc_irq_set_type(struct irq_data *d, unsigned int type) irq -=MCFINT_VECBASE ;if (intc_irqmap[irq].ack) {u32 v; - v =readl (MCFSIM_PITR ); + v =__raw_readl (MCFSIM_PITR );if (type ==IRQ_TYPE_EDGE_FALLING ) v &= ~(0x1 << (32 - irq));else v |= (0x1 << (32 - irq)); -writel (v,MCFSIM_PITR ); +__raw_writel (v,MCFSIM_PITR ); } }return 0 ;
@@ -163,10 +163,10 @@ void __init init_IRQ(void)int irq, edge;/* Mask all interrupt sources */ -writel (0x88888888 ,MCFSIM_ICR1 ); -writel (0x88888888 ,MCFSIM_ICR2 ); -writel (0x88888888 ,MCFSIM_ICR3 ); -writel (0x88888888 ,MCFSIM_ICR4 ); +__raw_writel (0x88888888 ,MCFSIM_ICR1 ); +__raw_writel (0x88888888 ,MCFSIM_ICR2 ); +__raw_writel (0x88888888 ,MCFSIM_ICR3 ); +__raw_writel (0x88888888 ,MCFSIM_ICR4 );for (irq =0 ; (irq <NR_IRQS ); irq++) {irq_set_chip (irq, &intc_irq_chip);
arch/m68k/coldfire/m5249.c +6 -6
@@ -94,10 +94,10 @@ static void __init m5249_i2c_init(void)mcf_mapirq2imr (MCF_IRQ_I2C0 ,MCFINTC_I2C );/* second I2C controller is completely different */ - r =readl (MCFINTC2_INTPRI_REG (MCF_IRQ_I2C1 )); + r =__raw_readl (MCFINTC2_INTPRI_REG (MCF_IRQ_I2C1 )); r &= ~MCFINTC2_INTPRI_BITS (0xf ,MCF_IRQ_I2C1 ); r |=MCFINTC2_INTPRI_BITS (0x5 ,MCF_IRQ_I2C1 ); -writel (r,MCFINTC2_INTPRI_REG (MCF_IRQ_I2C1 )); +__raw_writel (r,MCFINTC2_INTPRI_REG (MCF_IRQ_I2C1 ));#endif /* CONFIG_I2C_IMX */ }
@@ -110,11 +110,11 @@ static void __init m5249_smc91x_init(void)u32 gpio;/* Set the GPIO line as interrupt source for smc91x device */ - gpio =readl (MCFSIM2_GPIOINTENABLE ); -writel (gpio |0x40 ,MCFSIM2_GPIOINTENABLE ); + gpio =__raw_readl (MCFSIM2_GPIOINTENABLE ); +__raw_writel (gpio |0x40 ,MCFSIM2_GPIOINTENABLE ); - gpio =readl (MCFINTC2_INTPRI5 ); - writel(gpio | 0x04000000, MCFINTC2_INTPRI5); + gpio =__raw_readl (MCFINTC2_INTPRI5 ); + __raw_writel(gpio | 0x04000000, MCFINTC2_INTPRI5); }#endif /* CONFIG_M5249C3 */
arch/m68k/coldfire/m525x.c +4 -4
@@ -44,9 +44,9 @@ static void __init m525x_qspi_init(void)#if IS_ENABLED (CONFIG_SPI_COLDFIRE_QSPI )/* set the GPIO function for the qspi cs gpios */ /* FIXME: replace with pinmux/pinctl support */ -u32 f =readl (MCFSIM2_GPIOFUNC ); +u32 f =__raw_readl (MCFSIM2_GPIOFUNC ); f |= (1 <<MCFQSPI_CS2 ) | (1 <<MCFQSPI_CS1 ) | (1 <<MCFQSPI_CS0 ); -writel (f,MCFSIM2_GPIOFUNC ); +__raw_writel (f,MCFSIM2_GPIOFUNC );/* QSPI irq setup */ writeb(MCFSIM_ICR_AUTOVEC | MCFSIM_ICR_LEVEL4 | MCFSIM_ICR_PRI0,
@@ -66,10 +66,10 @@ static void __init m525x_i2c_init(void)mcf_mapirq2imr (MCF_IRQ_I2C0 ,MCFINTC_I2C );/* second I2C controller is completely different */ - r =readl (MCFINTC2_INTPRI_REG (MCF_IRQ_I2C1 )); + r =__raw_readl (MCFINTC2_INTPRI_REG (MCF_IRQ_I2C1 )); r &= ~MCFINTC2_INTPRI_BITS (0xf ,MCF_IRQ_I2C1 ); r |=MCFINTC2_INTPRI_BITS (0x5 ,MCF_IRQ_I2C1 ); -writel (r,MCFINTC2_INTPRI_REG (MCF_IRQ_I2C1 )); +__raw_writel (r,MCFINTC2_INTPRI_REG (MCF_IRQ_I2C1 ));#endif /* IS_ENABLED(CONFIG_I2C_IMX) */ }
arch/m68k/coldfire/m5272.c +4 -4
@@ -55,13 +55,13 @@ static void __init m5272_uarts_init(void)u32 v;/* Enable the output lines for the serial ports */ - v =readl (MCFSIM_PBCNT ); + v =__raw_readl (MCFSIM_PBCNT ); v = (v & ~0x000000ff ) |0x00000055 ; -writel (v,MCFSIM_PBCNT ); +__raw_writel (v,MCFSIM_PBCNT ); - v =readl (MCFSIM_PDCNT ); + v =__raw_readl (MCFSIM_PDCNT ); v = (v & ~0x000003fc ) |0x000002a8 ; -writel (v,MCFSIM_PDCNT ); +__raw_writel (v,MCFSIM_PDCNT ); }/***************************************************************************/
arch/m68k/coldfire/m53xx.c +35 -35
181 lines not on this page · raw message
arch/m68k/coldfire/m54xx.c +2 -2
@@ -67,9 +67,9 @@ static void __init m54xx_i2c_init(void)u32 r;/* set the fec/i2c/irq pin assignment register for i2c */ - r =readl (MCF_PAR_FECI2CIRQ ); + r =__raw_readl (MCF_PAR_FECI2CIRQ ); r |=MCF_PAR_FECI2CIRQ_SDA |MCF_PAR_FECI2CIRQ_SCL ; -writel (r,MCF_PAR_FECI2CIRQ ); +__raw_writel (r,MCF_PAR_FECI2CIRQ );#endif /* IS_ENABLED(CONFIG_I2C_IMX) */ }
arch/m68k/include/asm/io_no.h +0 -52
58 lines not on this page · raw message
Greg Ungerer
maintainerHi Arnd,
Quoted 8 lines · Arnd Bergmann
Quoted 6 lines · Daniel Palmer
Quoted 4 lines · Greg Ungerer
This change, in this form at least, breaks most of the non-MMU ColdFire targets. Try compiling any of m5208evb, m5249evb, m5272c3, m5275evb, m5307c3 or m5407c3 defconfigs and you get build failures. Targets that do not have a PCI bus and so do not define IOMEMBASE will fail, which is most of them.
Quoted 5 lines
Indeed, I had assumed that coldfire just uses the regular semantics here since it has PCI support, but I see now that it actually relies on both the big-endian access and on passing a physical address as an integer instead of an '
__iomem' pointer intowritel(), which is something we should probably fix.
Yeah, it feels like a real kludge.
Quoted 7 lines
Quoted 4 lines
Oof, that's the second time I broke coldfire this week (I broke it trying to make virtio work for m68k in u-boot too). Your patch works for my mc68000 virt and dragonball builds. I will build/boot test nommu CF in QEMU.
Right, this is hopefully fine as a quick fix.
Quoted 8 lines
In order to have coldfire behave more like other targets (now including 68000/68328), I would suggest removing the custom readl/writel helpers for coldfire as well, and changing the few callers to something else. A new set of helpers that takes a
phys_addr_twould work, or possibly just using the existing __raw_readl()/__raw_writel() or ioread32be()/iowrite32be() where appropriate, see the patch below for thearch/m68kportion of that.
I like the idea of a specific set if internal register read/write helpers. I would like to move in that direction.
Quoted 2 lines
There are other coldfire specific drivers (fec, spi, ...) that would need a similar change.
Right, and this is really the work that needs to be done first before we will be able to remove the io_no.h specific readl/write code. This is what I see:
Drivers that are used on ColdFire targets that use some of readb/readw/readl and writeb/writew/writel:
drivers/net/ethernet/freescale/fec*
drivers/net/ethernet/smsc/smc9x.[hc]
drivers/net/ethernet/davicom/dm9000.c
drivers/spi/spi-coldfire-qspi.c
Obviously spi-coldfire-qspi.c is ColdFire specific, so easy to change and not affect anything else. The FEC ethernet driver is widely used on ARM and ColdFire, though the change to a register reading helper looks pretty strait forward but will be a largish patch. Changing the smc91x driver looks easy enough, the ColdFire multi-byte access macros in the header are specific to ColdFire. Need to give some thought to changes to the dm9000 driver.
Drivers that are used on ColdFire that use only 8-bit readb and writeb:
drivers/tty/serial/mcf.c
drivers/i2c/busses/i2c-imx.c
We could ignore these for now I guess, since readb and writeb will always work the same. Though it might be nice to clean them up with proper helpers. mcf.c is only used on ColdFire so won't affect anything else.
Drivers that are used on ColdFire that use iowrite32/iowrite32be:
drivers/net/can/flexcan/flexcan-core.c
Although this driver has support for differentiating big and little endian access I think for ColdFire it is relying on the kludgy overrides in io_no.h to actually work right. So will need a fix too.
Did I miss any?
Regards
Greg
Quoted 18 lines · Greg Ungerer
Quoted 4 lines · Arnd Bergmann
On Tue, Apr 14, 2026, at 14:55, Daniel Palmer wrote:
There are other coldfire specific drivers (fec, spi, ...) that would need a similar change.
Right, and this is really the work that needs to be done first before we will be able to remove the
io_no.hspecific readl/write code. This is what I see:Drivers that are used on ColdFire targets that use some of readb/readw/readl and writeb/writew/writel:
drivers/net/ethernet/freescale/fec*
drivers/net/ethernet/smsc/smc9x.[hc]
drivers/net/ethernet/davicom/dm9000.c
drivers/spi/spi-coldfire-qspi.c
Quoted 6 lines
Obviously
spi-coldfire-qspi.cis ColdFire specific, so easy to change and not affect anything else.The FEC ethernet driver is widely used on
ARM and ColdFire, though the change to a register reading helper looks pretty strait forward but will be a largish patch.
Agreed.
Quoted 2 lines
Changing the smc91x driver looks easy enough, the ColdFire multi-byte access macros in the header are specific to ColdFire.
smc91x is a bit weird because this uses a readw() loop for byte streams but ioread16be() for register accesses. I think what is going on here is that this is in fact a little-endian device, and ioread16be() ends up working because this does a byteswap on coldfire while readl() does not. With the normal io.h semantics, these should be readsw() or ioread16_rep() for the bytestream and readw() or ioread16() for the LE register instead, same as the #else path in the header.
Quoted 2 lines
Need to give some thought to changes
to the dm9000 driver.
The dm9000.c driver should not need any changes, as it only deals with 8-bit registers and iowrite32_rep()/ioread32_rep() byte stream transfers, but no 16-bit or 32-bit register accesses, so no byteswap is needed here.
Quoted 8 lines
Drivers that are used on ColdFire that use only 8-bit readb and writeb:
drivers/tty/serial/mcf.c
drivers/i2c/busses/i2c-imx.cWe could ignore these for now I guess, since readb and writeb will always work the same. Though it might be nice to clean them up with proper helpers.
mcf.cis only used on ColdFire so won't affect anything else.
Right
Quoted 7 lines
Drivers that are used on ColdFire that use iowrite32/iowrite32be:
drivers/net/can/flexcan/flexcan-core.cAlthough this driver has support for differentiating big and little endian access I think for ColdFire it is relying on the kludgy overrides in
io_no.hto actually work right. So will need a fix too.
Makes sense. So the FLEXCAN_QUIRK_DEFAULT_BIG_ENDIAN flag should be flipped at the same time as flipping the endianess of iowrite32be()/iowrite32().
Quoted 1 line
Did I miss any?
I test-built all the defconfigs, with readX/writeX/ioreadXX/iowriteXX commented out and found three more for mcf5441x:
drivers/mmc/host/sdhci-esdhc-mcf.c
-> needs to be flipped to explicit big-endian accessors
drivers/dma/mcf-edma-main.c
-> same, but confusingly this also has edma_readl()/edma_writel()
helpers that try to handle this. As far as I can tell, this is currently broken because coldfire sets edma->big_endian=true but then uses ioread32be() that appears to flip the BE register contents to LE. I'm either missing something here, or the upstream version never worked.
drivers/spi/spi-fsl-dspi.c
-> this one uses regmap_mmio without specifying an endianess,
so this should get the default LE helpers everywhere, which would be wrong on coldfire after the change. I think the correct solution here is to set explict endianess in the regmap setup for coldfire.
Arnd
Greg Ungerer
maintainerHi Arnd,
Quoted 19 lines · Arnd Bergmann
Quoted 17 lines · Greg Ungerer
Quoted 4 lines · Arnd Bergmann
On Tue, Apr 14, 2026, at 14:55, Daniel Palmer wrote:
There are other coldfire specific drivers (fec, spi, ...) that would need a similar change.
Right, and this is really the work that needs to be done first before we will be able to remove the
io_no.hspecific readl/write code. This is what I see:Drivers that are used on ColdFire targets that use some of readb/readw/readl and writeb/writew/writel:
drivers/net/ethernet/freescale/fec*
drivers/net/ethernet/smsc/smc9x.[hc]
drivers/net/ethernet/davicom/dm9000.c
drivers/spi/spi-coldfire-qspi.c
Quoted 8 lines
Quoted 6 lines
Obviously
spi-coldfire-qspi.cis ColdFire specific, so easy to change and not affect anything else.The FEC ethernet driver is widely used on
ARM and ColdFire, though the change to a register reading helper looks pretty strait forward but will be a largish patch.Agreed.
I am testing a change for this one now.
Quoted 12 lines
Quoted 2 lines
Changing the smc91x driver looks easy enough, the ColdFire multi-byte access macros in the header are specific to ColdFire.
smc91x is a bit weird because this uses a
readw()loop for byte streams butioread16be()for register accesses. I think what is going on here is that this is in fact a little-endian device, andioread16be()ends up working because this does a byteswap on coldfire whilereadl()does not. With the normalio.hsemantics, these should bereadsw()orioread16_rep()for the bytestream andreadw()orioread16()for the LE register instead, same as the #else path in the header.
I will create a patch for this one too.
Quoted 6 lines
Quoted 3 lines
Need to give some thought to changes
to the dm9000 driver.
Thedm9000.cdriver should not need any changes, as it onlydeals with 8-bit registers and iowrite32_rep()/ioread32_rep() byte stream transfers, but no 16-bit or 32-bit register accesses, so no byteswap is needed here.
Ah, yes, that is right. Nothing to do here then ;-)
Quoted 15 lines
Quoted 8 lines
Drivers that are used on ColdFire that use only 8-bit readb and writeb:
drivers/tty/serial/mcf.c
drivers/i2c/busses/i2c-imx.cWe could ignore these for now I guess, since readb and writeb will always work the same. Though it might be nice to clean them up with proper helpers.
mcf.cis only used on ColdFire so won't affect anything else.Right
Quoted 4 lines
Drivers that are used on ColdFire that use iowrite32/iowrite32be:
drivers/net/can/flexcan/flexcan-core.c
Quoted 7 lines
Quoted 3 lines
Although this driver has support for differentiating big and little endian access I think for ColdFire it is relying on the kludgy overrides in
io_no.hto actually work right. So will need a fix too.Makes sense. So the
FLEXCAN_QUIRK_DEFAULT_BIG_ENDIANflag should be flipped at the same time as flipping the endianess of iowrite32be()/iowrite32().
I will do this one too.
Quoted 18 lines
Quoted 1 line
Did I miss any?
I test-built all the defconfigs, with readX/writeX/ioreadXX/iowriteXX commented out and found three more for mcf5441x:
drivers/mmc/host/sdhci-esdhc-mcf.c-> needs to be flipped to explicit big-endian accessors
drivers/dma/mcf-edma-main.c-> same, but confusingly this also has edma_readl()/edma_writel()
helpers that try to handle this. As far as I can tell, this is currently broken because coldfire sets edma->big_endian=true but then usesioread32be()that appears to flip the BE register contents to LE. I'm either missing something here, or the upstream version never worked.
Quoted 7 lines
drivers/spi/spi-fsl-dspi.c-> this one uses
regmap_mmiowithout specifying an endianess,
so this should get the default LE helpers everywhere, which would be wrong on coldfire after the change. I think the correct solution here is to set explict endianess in the regmap setup for coldfire.
Good catch, thanks. I will look at these too.
I have some changes I am testing to do a blanket change of the arch specific code to use newly create IO access functions too. Simple enough (like your example patch) but of course it does cause of bit of churn.
Regards
Greg
Quoted 5 lines · Greg Ungerer
I have some changes I am testing to do a blanket change of the arch specific code to use newly create IO access functions too. Simple enough (like your example patch) but of course it does cause of bit of churn.
Sounds good, yes. The hardest part I think is going to be the shared drivers that currently rely on the flipped meaning of readl()/ioread32be() like the regmap. These may need to get an atomic patch that flips around the users at the same time as removing the flipped readl().
Arnd