diff mbox series

m68k: Fix multiplatform ISA support

Message ID 1622957313-321-1-git-send-email-schmitzmic@gmail.com
State New
Headers show
Series m68k: Fix multiplatform ISA support | expand

Commit Message

Michael Schmitz June 6, 2021, 5:28 a.m. UTC
Current io_mm.h uses address translation and ROM port IO primitives when
port addresses are below 1024, and raw untranslated MMIO IO primitives
else when CONFIG_ATARI_ROM_ISA is set. This is done regardless of the
m68k machine type a multi-platform kernel runs on. As a consequence,
the Q40 IDE driver in multiplatform kernels cannot work.
Conversely, the Atari IDE driver uses wrong address translation if a
multiplatform Q40 and Atari kernel does _not_ set CONFIG_ATARI_ROM_ISA.

Replace MMIO by ISA IO primitives for addresses > 1024 (if isa_type
is ISA_TYPE_ENEC), and change the ISA address translation used for
Atari to a no-op for those addresses.

Switch readb()/writeb() and readw()/writew() to their ISA equivalents
also. Change the address translation functions to return the identity
translation if CONFIG_ATARI_ROM_ISA is not defined, and set MULTI_ISA
for kernels where Q40 and Atari are both configured so this can actually
work (isa_type set to Q40 at compile time else).

Fixes:  84b16b7b0d5c818fadc731a69965dc76dce0c91e
Signed-off-by: Michael Schmitz <schmitzmic@gmail.com>

--
Changes from RFC:

Geert Uytterhoeven;
- drop setup_mm.c patch

Finn Thain:
- Add 'Fixes' tag
- Annotate rationale for MULTI_ISA setting on Atari
- Use fallthrough macro annotation in Atari address translation
---
 arch/m68k/include/asm/io_mm.h | 62 ++++++++++++++++++++++++++-----------------
 1 file changed, 37 insertions(+), 25 deletions(-)

Comments

Geert Uytterhoeven June 7, 2021, 7:49 a.m. UTC | #1
Hi Michael,

On Sun, Jun 6, 2021 at 7:28 AM Michael Schmitz <schmitzmic@gmail.com> wrote:
> Current io_mm.h uses address translation and ROM port IO primitives when
> port addresses are below 1024, and raw untranslated MMIO IO primitives
> else when CONFIG_ATARI_ROM_ISA is set. This is done regardless of the
> m68k machine type a multi-platform kernel runs on. As a consequence,
> the Q40 IDE driver in multiplatform kernels cannot work.
> Conversely, the Atari IDE driver uses wrong address translation if a
> multiplatform Q40 and Atari kernel does _not_ set CONFIG_ATARI_ROM_ISA.
>
> Replace MMIO by ISA IO primitives for addresses > 1024 (if isa_type
> is ISA_TYPE_ENEC), and change the ISA address translation used for
> Atari to a no-op for those addresses.
>
> Switch readb()/writeb() and readw()/writew() to their ISA equivalents
> also. Change the address translation functions to return the identity
> translation if CONFIG_ATARI_ROM_ISA is not defined, and set MULTI_ISA
> for kernels where Q40 and Atari are both configured so this can actually
> work (isa_type set to Q40 at compile time else).

Thanks for your patch!

> Fixes:  84b16b7b0d5c818fadc731a69965dc76dce0c91e

Fixes: 84b16b7b0d5c818f ("m68k/atari: ROM port ISA adapter support")

Hint:

    $ git help fixes
    'fixes' is aliased to 'show --format='Fixes: %h ("%s")' -s'
    $ git fixes 84b16b7b0d5c818fadc731a69965dc76dce0c91e
    Fixes: 84b16b7b0d5c818f ("m68k/atari: ROM port ISA adapter support")

> Signed-off-by: Michael Schmitz <schmitzmic@gmail.com>

> --- a/arch/m68k/include/asm/io_mm.h
> +++ b/arch/m68k/include/asm/io_mm.h
> @@ -113,7 +117,7 @@
>
>  #ifdef MULTI_ISA
>  extern int isa_type;
> -extern int isa_sex;
> +extern int isa_sex;    /* Atari relies on this to be zero-initialized */

Shouldn't that comment be next to its definition in
arch/m68k/kernel/setup_mm.c?


> @@ -135,9 +139,11 @@ static inline u8 __iomem *isa_itb(unsigned long addr)
>      case ISA_TYPE_AG: return (u8 __iomem *)AG_ISA_IO_B(addr);
>  #endif
>  #ifdef CONFIG_ATARI_ROM_ISA
> -    case ISA_TYPE_ENEC: return (u8 __iomem *)ENEC_ISA_IO_B(addr);
> +    case ISA_TYPE_ENEC: if (addr < 1024)
> +                               return (u8 __iomem *)ENEC_ISA_IO_B(addr);
> +                       fallthrough; /* not ROM port? fallback below! */
>  #endif
> -    default: return NULL; /* avoid warnings, just in case */
> +    default: return (u8 __iomem *)(addr); /* avoid warnings, just in case */
>      }

Moving the default out of the switch() statement, as suggested by Finn,
would make this more future-proof, as any case (not just the last one)
can fall through to the default, using break.

Gr{oetje,eeting}s,

                        Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

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
Michael Schmitz June 7, 2021, 8:17 a.m. UTC | #2
Hi Geert,

thanks for your review!

Am 07.06.2021 um 19:49 schrieb Geert Uytterhoeven:
> Hi Michael,
>
> On Sun, Jun 6, 2021 at 7:28 AM Michael Schmitz <schmitzmic@gmail.com> wrote:
>> Current io_mm.h uses address translation and ROM port IO primitives when
>> port addresses are below 1024, and raw untranslated MMIO IO primitives
>> else when CONFIG_ATARI_ROM_ISA is set. This is done regardless of the
>> m68k machine type a multi-platform kernel runs on. As a consequence,
>> the Q40 IDE driver in multiplatform kernels cannot work.
>> Conversely, the Atari IDE driver uses wrong address translation if a
>> multiplatform Q40 and Atari kernel does _not_ set CONFIG_ATARI_ROM_ISA.
>>
>> Replace MMIO by ISA IO primitives for addresses > 1024 (if isa_type
>> is ISA_TYPE_ENEC), and change the ISA address translation used for
>> Atari to a no-op for those addresses.
>>
>> Switch readb()/writeb() and readw()/writew() to their ISA equivalents
>> also. Change the address translation functions to return the identity
>> translation if CONFIG_ATARI_ROM_ISA is not defined, and set MULTI_ISA
>> for kernels where Q40 and Atari are both configured so this can actually
>> work (isa_type set to Q40 at compile time else).
>
> Thanks for your patch!
>
>> Fixes:  84b16b7b0d5c818fadc731a69965dc76dce0c91e
>
> Fixes: 84b16b7b0d5c818f ("m68k/atari: ROM port ISA adapter support")
>
> Hint:
>
>     $ git help fixes
>     'fixes' is aliased to 'show --format='Fixes: %h ("%s")' -s'
>     $ git fixes 84b16b7b0d5c818fadc731a69965dc76dce0c91e
>     Fixes: 84b16b7b0d5c818f ("m68k/atari: ROM port ISA adapter support")

Thanks, I'll change that.

>> Signed-off-by: Michael Schmitz <schmitzmic@gmail.com>
>
>> --- a/arch/m68k/include/asm/io_mm.h
>> +++ b/arch/m68k/include/asm/io_mm.h
>> @@ -113,7 +117,7 @@
>>
>>  #ifdef MULTI_ISA
>>  extern int isa_type;
>> -extern int isa_sex;
>> +extern int isa_sex;    /* Atari relies on this to be zero-initialized */
>
> Shouldn't that comment be next to its definition in
> arch/m68k/kernel/setup_mm.c?

I ended up dropping changes to that file, and would rather omit the 
comment here than touching setup_mm.c just for the sake of adding a 
comment.

We might omit the isa_sex = 0 stuff in setup_mm.c altogether, OTOH ...

>
>> @@ -135,9 +139,11 @@ static inline u8 __iomem *isa_itb(unsigned long addr)
>>      case ISA_TYPE_AG: return (u8 __iomem *)AG_ISA_IO_B(addr);
>>  #endif
>>  #ifdef CONFIG_ATARI_ROM_ISA
>> -    case ISA_TYPE_ENEC: return (u8 __iomem *)ENEC_ISA_IO_B(addr);
>> +    case ISA_TYPE_ENEC: if (addr < 1024)
>> +                               return (u8 __iomem *)ENEC_ISA_IO_B(addr);
>> +                       fallthrough; /* not ROM port? fallback below! */
>>  #endif
>> -    default: return NULL; /* avoid warnings, just in case */
>> +    default: return (u8 __iomem *)(addr); /* avoid warnings, just in case */
>>      }
>
> Moving the default out of the switch() statement, as suggested by Finn,
> would make this more future-proof, as any case (not just the last one)
> can fall through to the default, using break.

OK, I take that to indicate the default may be changed in that way, and 
will move it outside the switch().

Cheers,

	Michael


>
> Gr{oetje,eeting}s,
>
>                         Geert
>
> --
> Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org
>
> 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
>
diff mbox series

Patch

diff --git a/arch/m68k/include/asm/io_mm.h b/arch/m68k/include/asm/io_mm.h
index d41fa48..f6b487b 100644
--- a/arch/m68k/include/asm/io_mm.h
+++ b/arch/m68k/include/asm/io_mm.h
@@ -52,7 +52,11 @@ 
 #define Q40_ISA_MEM_B(madr)  (q40_isa_mem_base+1+4*((unsigned long)(madr)))
 #define Q40_ISA_MEM_W(madr)  (q40_isa_mem_base+  4*((unsigned long)(madr)))
 
+#ifdef CONFIG_ATARI
+#define MULTI_ISA 1	/* Need MULTI_ISA if Atari drivers (IDE) present !! */
+#else
 #define MULTI_ISA 0
+#endif /* Atari */
 #endif /* Q40 */
 
 #ifdef CONFIG_AMIGA_PCMCIA
@@ -113,7 +117,7 @@ 
 
 #ifdef MULTI_ISA
 extern int isa_type;
-extern int isa_sex;
+extern int isa_sex;	/* Atari relies on this to be zero-initialized */
 
 #define ISA_TYPE isa_type
 #define ISA_SEX  isa_sex
@@ -135,9 +139,11 @@  static inline u8 __iomem *isa_itb(unsigned long addr)
     case ISA_TYPE_AG: return (u8 __iomem *)AG_ISA_IO_B(addr);
 #endif
 #ifdef CONFIG_ATARI_ROM_ISA
-    case ISA_TYPE_ENEC: return (u8 __iomem *)ENEC_ISA_IO_B(addr);
+    case ISA_TYPE_ENEC: if (addr < 1024)
+				return (u8 __iomem *)ENEC_ISA_IO_B(addr);
+			fallthrough; /* not ROM port? fallback below! */
 #endif
-    default: return NULL; /* avoid warnings, just in case */
+    default: return (u8 __iomem *)(addr); /* avoid warnings, just in case */
     }
 }
 static inline u16 __iomem *isa_itw(unsigned long addr)
@@ -151,9 +157,11 @@  static inline u16 __iomem *isa_itw(unsigned long addr)
     case ISA_TYPE_AG: return (u16 __iomem *)AG_ISA_IO_W(addr);
 #endif
 #ifdef CONFIG_ATARI_ROM_ISA
-    case ISA_TYPE_ENEC: return (u16 __iomem *)ENEC_ISA_IO_W(addr);
+    case ISA_TYPE_ENEC: if (addr < 1024)
+				return (u16 __iomem *)ENEC_ISA_IO_W(addr);
+			fallthrough; /* not ROM port? fallback below! */
 #endif
-    default: return NULL; /* avoid warnings, just in case */
+    default: return (u16 __iomem *)(addr); /* avoid warnings, just in case */
     }
 }
 static inline u32 __iomem *isa_itl(unsigned long addr)
@@ -177,9 +185,11 @@  static inline u8 __iomem *isa_mtb(unsigned long addr)
     case ISA_TYPE_AG: return (u8 __iomem *)addr;
 #endif
 #ifdef CONFIG_ATARI_ROM_ISA
-    case ISA_TYPE_ENEC: return (u8 __iomem *)ENEC_ISA_MEM_B(addr);
+    case ISA_TYPE_ENEC: if (addr < 1024)
+				return (u8 __iomem *)ENEC_ISA_MEM_B(addr);
+			fallthrough; /* not ROM port? fallback below! */
 #endif
-    default: return NULL; /* avoid warnings, just in case */
+    default: return (u8 __iomem *)(addr); /* avoid warnings, just in case */
     }
 }
 static inline u16 __iomem *isa_mtw(unsigned long addr)
@@ -193,9 +203,11 @@  static inline u16 __iomem *isa_mtw(unsigned long addr)
     case ISA_TYPE_AG: return (u16 __iomem *)addr;
 #endif
 #ifdef CONFIG_ATARI_ROM_ISA
-    case ISA_TYPE_ENEC: return (u16 __iomem *)ENEC_ISA_MEM_W(addr);
+    case ISA_TYPE_ENEC: if (addr < 1024)
+				return (u16 __iomem *)ENEC_ISA_MEM_W(addr);
+			fallthrough; /* not ROM port? fallback below! */
 #endif
-    default: return NULL; /* avoid warnings, just in case */
+    default: return (u16 __iomem *)(addr); /* avoid warnings, just in case */
     }
 }
 
@@ -344,31 +356,31 @@  static inline void isa_delay(void)
  * ROM port ISA and everything else regular ISA for IDE. read,write defined
  * below.
  */
-#define inb(port)	((port) < 1024 ? isa_rom_inb(port) : in_8(port))
-#define inb_p(port)	((port) < 1024 ? isa_rom_inb_p(port) : in_8(port))
-#define inw(port)	((port) < 1024 ? isa_rom_inw(port) : in_le16(port))
-#define inw_p(port)	((port) < 1024 ? isa_rom_inw_p(port) : in_le16(port))
+#define inb(port)	(((port) < 1024 && ISA_TYPE == ISA_TYPE_ENEC) ? isa_rom_inb(port) : isa_inb(port))
+#define inb_p(port)	(((port) < 1024 && ISA_TYPE == ISA_TYPE_ENEC) ? isa_rom_inb_p(port) : isa_inb_p(port))
+#define inw(port)	(((port) < 1024 && ISA_TYPE == ISA_TYPE_ENEC) ? isa_rom_inw(port) : isa_inw(port))
+#define inw_p(port)	(((port) < 1024 && ISA_TYPE == ISA_TYPE_ENEC) ? isa_rom_inw_p(port) : isa_inw_p(port))
 #define inl		isa_inl
 #define inl_p		isa_inl_p
 
-#define outb(val, port)	((port) < 1024 ? isa_rom_outb((val), (port)) : out_8((port), (val)))
-#define outb_p(val, port) ((port) < 1024 ? isa_rom_outb_p((val), (port)) : out_8((port), (val)))
-#define outw(val, port)	((port) < 1024 ? isa_rom_outw((val), (port)) : out_le16((port), (val)))
-#define outw_p(val, port) ((port) < 1024 ? isa_rom_outw_p((val), (port)) : out_le16((port), (val)))
+#define outb(val, port)	(((port) < 1024 && ISA_TYPE == ISA_TYPE_ENEC) ? isa_rom_outb((val), (port)) : isa_outb((val), (port)))
+#define outb_p(val, port) (((port) < 1024 && ISA_TYPE == ISA_TYPE_ENEC) ? isa_rom_outb_p((val), (port)) : isa_outb_p((val), (port)))
+#define outw(val, port)	(((port) < 1024 && ISA_TYPE == ISA_TYPE_ENEC) ? isa_rom_outw((val), (port)) : isa_outw((val), (port)))
+#define outw_p(val, port) (((port) < 1024 && ISA_TYPE == ISA_TYPE_ENEC) ? isa_rom_outw_p((val), (port)) : isa_outw_p((val), (port)))
 #define outl		isa_outl
 #define outl_p		isa_outl_p
 
-#define insb(port, buf, nr)	((port) < 1024 ? isa_rom_insb((port), (buf), (nr)) : isa_insb((port), (buf), (nr)))
-#define insw(port, buf, nr)	((port) < 1024 ? isa_rom_insw((port), (buf), (nr)) : isa_insw((port), (buf), (nr)))
+#define insb(port, buf, nr)	(((port) < 1024 && ISA_TYPE == ISA_TYPE_ENEC) ? isa_rom_insb((port), (buf), (nr)) : isa_insb((port), (buf), (nr)))
+#define insw(port, buf, nr)	(((port) < 1024 && ISA_TYPE == ISA_TYPE_ENEC) ? isa_rom_insw((port), (buf), (nr)) : isa_insw((port), (buf), (nr)))
 #define insl			isa_insl
-#define outsb(port, buf, nr)	((port) < 1024 ? isa_rom_outsb((port), (buf), (nr)) : isa_outsb((port), (buf), (nr)))
-#define outsw(port, buf, nr)	((port) < 1024 ? isa_rom_outsw((port), (buf), (nr)) : isa_outsw((port), (buf), (nr)))
+#define outsb(port, buf, nr)	(((port) < 1024 && ISA_TYPE == ISA_TYPE_ENEC) ? isa_rom_outsb((port), (buf), (nr)) : isa_outsb((port), (buf), (nr)))
+#define outsw(port, buf, nr)	(((port) < 1024 && ISA_TYPE == ISA_TYPE_ENEC) ? isa_rom_outsw((port), (buf), (nr)) : isa_outsw((port), (buf), (nr)))
 #define outsl			isa_outsl
 
-#define readb(addr)		in_8(addr)
-#define writeb(val, addr)	out_8((addr), (val))
-#define readw(addr)		in_le16(addr)
-#define writew(val, addr)	out_le16((addr), (val))
+#define readb   isa_readb
+#define readw   isa_readw
+#define writeb  isa_writeb
+#define writew  isa_writew
 #endif /* CONFIG_ATARI_ROM_ISA */
 
 #define readl(addr)      in_le32(addr)