1 /* SPDX-License-Identifier: GPL-2.0 */
3 * linux/include/asm-m68k/io.h
5 * 4/1/00 RZ: - rewritten to avoid clashes between ISA/PCI and other
8 * - added skeleton for GG-II and Amiga PCMCIA
9 * 2/3/01 RZ: - moved a few more defs into raw_io.h
11 * inX/outX should not be used by any driver unless it does
12 * ISA access. Other drivers should use function defined in raw_io.h
13 * or define its own macros on top of these.
15 * inX(),outX() are for ISA I/O
16 * isa_readX(),isa_writeX() are for ISA memory
24 #include <linux/compiler.h>
25 #include <asm/raw_io.h>
26 #include <asm/virtconvert.h>
30 #define atari_readb raw_inb
31 #define atari_writeb raw_outb
33 #define atari_inb_p raw_inb
34 #define atari_outb_p raw_outb
39 * IO/MEM definitions for various ISA bridges
45 #define q40_isa_io_base 0xff400000
46 #define q40_isa_mem_base 0xff800000
48 #define Q40_ISA_IO_B(ioaddr) (q40_isa_io_base+1+4*((unsigned long)(ioaddr)))
49 #define Q40_ISA_IO_W(ioaddr) (q40_isa_io_base+ 4*((unsigned long)(ioaddr)))
50 #define Q40_ISA_MEM_B(madr) (q40_isa_mem_base+1+4*((unsigned long)(madr)))
51 #define Q40_ISA_MEM_W(madr) (q40_isa_mem_base+ 4*((unsigned long)(madr)))
56 #ifdef CONFIG_AMIGA_PCMCIA
57 #include <asm/amigayle.h>
59 #define AG_ISA_IO_B(ioaddr) ( GAYLE_IO+(ioaddr)+(((ioaddr)&1)*GAYLE_ODD) )
60 #define AG_ISA_IO_W(ioaddr) ( GAYLE_IO+(ioaddr) )
68 #endif /* AMIGA_PCMCIA */
70 #ifdef CONFIG_ATARI_ROM_ISA
72 #define enec_isa_read_base 0xfffa0000
73 #define enec_isa_write_base 0xfffb0000
75 #define ENEC_ISA_IO_B(ioaddr) (enec_isa_read_base+((((unsigned long)(ioaddr))&0x7F)<<9))
76 #define ENEC_ISA_IO_W(ioaddr) (enec_isa_read_base+((((unsigned long)(ioaddr))&0x7F)<<9))
77 #define ENEC_ISA_MEM_B(madr) (enec_isa_read_base+((((unsigned long)(madr))&0x7F)<<9))
78 #define ENEC_ISA_MEM_W(madr) (enec_isa_read_base+((((unsigned long)(madr))&0x7F)<<9))
86 #endif /* ATARI_ROM_ISA */
89 #if defined(CONFIG_ISA) || defined(CONFIG_ATARI_ROM_ISA)
95 #define ISA_TYPE_Q40 (1)
96 #define ISA_TYPE_AG (2)
97 #define ISA_TYPE_ENEC (3)
99 #if defined(CONFIG_Q40) && !defined(MULTI_ISA)
100 #define ISA_TYPE ISA_TYPE_Q40
103 #if defined(CONFIG_AMIGA_PCMCIA) && !defined(MULTI_ISA)
104 #define ISA_TYPE ISA_TYPE_AG
107 #if defined(CONFIG_ATARI_ROM_ISA) && !defined(MULTI_ISA)
108 #define ISA_TYPE ISA_TYPE_ENEC
116 #define ISA_TYPE isa_type
117 #define ISA_SEX isa_sex
121 * define inline addr translation functions. Normally only one variant will
122 * be compiled in so the case statement will be optimised away
125 static inline u8 __iomem *isa_itb(unsigned long addr)
130 case ISA_TYPE_Q40: return (u8 __iomem *)Q40_ISA_IO_B(addr);
132 #ifdef CONFIG_AMIGA_PCMCIA
133 case ISA_TYPE_AG: return (u8 __iomem *)AG_ISA_IO_B(addr);
135 #ifdef CONFIG_ATARI_ROM_ISA
136 case ISA_TYPE_ENEC: return (u8 __iomem *)ENEC_ISA_IO_B(addr);
138 default: return NULL; /* avoid warnings, just in case */
141 static inline u16 __iomem *isa_itw(unsigned long addr)
146 case ISA_TYPE_Q40: return (u16 __iomem *)Q40_ISA_IO_W(addr);
148 #ifdef CONFIG_AMIGA_PCMCIA
149 case ISA_TYPE_AG: return (u16 __iomem *)AG_ISA_IO_W(addr);
151 #ifdef CONFIG_ATARI_ROM_ISA
152 case ISA_TYPE_ENEC: return (u16 __iomem *)ENEC_ISA_IO_W(addr);
154 default: return NULL; /* avoid warnings, just in case */
157 static inline u32 __iomem *isa_itl(unsigned long addr)
161 #ifdef CONFIG_AMIGA_PCMCIA
162 case ISA_TYPE_AG: return (u32 __iomem *)AG_ISA_IO_W(addr);
164 default: return 0; /* avoid warnings, just in case */
167 static inline u8 __iomem *isa_mtb(unsigned long addr)
172 case ISA_TYPE_Q40: return (u8 __iomem *)Q40_ISA_MEM_B(addr);
174 #ifdef CONFIG_AMIGA_PCMCIA
175 case ISA_TYPE_AG: return (u8 __iomem *)addr;
177 #ifdef CONFIG_ATARI_ROM_ISA
178 case ISA_TYPE_ENEC: return (u8 __iomem *)ENEC_ISA_MEM_B(addr);
180 default: return NULL; /* avoid warnings, just in case */
183 static inline u16 __iomem *isa_mtw(unsigned long addr)
188 case ISA_TYPE_Q40: return (u16 __iomem *)Q40_ISA_MEM_W(addr);
190 #ifdef CONFIG_AMIGA_PCMCIA
191 case ISA_TYPE_AG: return (u16 __iomem *)addr;
193 #ifdef CONFIG_ATARI_ROM_ISA
194 case ISA_TYPE_ENEC: return (u16 __iomem *)ENEC_ISA_MEM_W(addr);
196 default: return NULL; /* avoid warnings, just in case */
201 #define isa_inb(port) in_8(isa_itb(port))
202 #define isa_inw(port) (ISA_SEX ? in_be16(isa_itw(port)) : in_le16(isa_itw(port)))
203 #define isa_inl(port) (ISA_SEX ? in_be32(isa_itl(port)) : in_le32(isa_itl(port)))
204 #define isa_outb(val,port) out_8(isa_itb(port),(val))
205 #define isa_outw(val,port) (ISA_SEX ? out_be16(isa_itw(port),(val)) : out_le16(isa_itw(port),(val)))
206 #define isa_outl(val,port) (ISA_SEX ? out_be32(isa_itl(port),(val)) : out_le32(isa_itl(port),(val)))
208 #define isa_readb(p) in_8(isa_mtb((unsigned long)(p)))
209 #define isa_readw(p) \
210 (ISA_SEX ? in_be16(isa_mtw((unsigned long)(p))) \
211 : in_le16(isa_mtw((unsigned long)(p))))
212 #define isa_writeb(val,p) out_8(isa_mtb((unsigned long)(p)),(val))
213 #define isa_writew(val,p) \
214 (ISA_SEX ? out_be16(isa_mtw((unsigned long)(p)),(val)) \
215 : out_le16(isa_mtw((unsigned long)(p)),(val)))
217 #ifdef CONFIG_ATARI_ROM_ISA
218 #define isa_rom_inb(port) rom_in_8(isa_itb(port))
219 #define isa_rom_inw(port) \
220 (ISA_SEX ? rom_in_be16(isa_itw(port)) \
221 : rom_in_le16(isa_itw(port)))
223 #define isa_rom_outb(val, port) rom_out_8(isa_itb(port), (val))
224 #define isa_rom_outw(val, port) \
225 (ISA_SEX ? rom_out_be16(isa_itw(port), (val)) \
226 : rom_out_le16(isa_itw(port), (val)))
228 #define isa_rom_readb(p) rom_in_8(isa_mtb((unsigned long)(p)))
229 #define isa_rom_readw(p) \
230 (ISA_SEX ? rom_in_be16(isa_mtw((unsigned long)(p))) \
231 : rom_in_le16(isa_mtw((unsigned long)(p))))
232 #define isa_rom_readw_swap(p) \
233 (ISA_SEX ? rom_in_le16(isa_mtw((unsigned long)(p))) \
234 : rom_in_be16(isa_mtw((unsigned long)(p))))
235 #define isa_rom_readw_raw(p) rom_in_be16(isa_mtw((unsigned long)(p)))
237 #define isa_rom_writeb(val, p) rom_out_8(isa_mtb((unsigned long)(p)), (val))
238 #define isa_rom_writew(val, p) \
239 (ISA_SEX ? rom_out_be16(isa_mtw((unsigned long)(p)), (val)) \
240 : rom_out_le16(isa_mtw((unsigned long)(p)), (val)))
241 #define isa_rom_writew_swap(val, p) \
242 (ISA_SEX ? rom_out_le16(isa_mtw((unsigned long)(p)), (val)) \
243 : rom_out_be16(isa_mtw((unsigned long)(p)), (val)))
244 #define isa_rom_writew_raw(val, p) rom_out_be16(isa_mtw((unsigned long)(p)), (val))
245 #endif /* CONFIG_ATARI_ROM_ISA */
247 static inline void isa_delay(void)
252 case ISA_TYPE_Q40: isa_outb(0,0x80); break;
254 #ifdef CONFIG_AMIGA_PCMCIA
255 case ISA_TYPE_AG: break;
257 #ifdef CONFIG_ATARI_ROM_ISA
258 case ISA_TYPE_ENEC: break;
260 default: break; /* avoid warnings */
264 #define isa_inb_p(p) ({u8 v=isa_inb(p);isa_delay();v;})
265 #define isa_outb_p(v,p) ({isa_outb((v),(p));isa_delay();})
266 #define isa_inw_p(p) ({u16 v=isa_inw(p);isa_delay();v;})
267 #define isa_outw_p(v,p) ({isa_outw((v),(p));isa_delay();})
268 #define isa_inl_p(p) ({u32 v=isa_inl(p);isa_delay();v;})
269 #define isa_outl_p(v,p) ({isa_outl((v),(p));isa_delay();})
271 #define isa_insb(port, buf, nr) raw_insb(isa_itb(port), (u8 *)(buf), (nr))
272 #define isa_outsb(port, buf, nr) raw_outsb(isa_itb(port), (u8 *)(buf), (nr))
274 #define isa_insw(port, buf, nr) \
275 (ISA_SEX ? raw_insw(isa_itw(port), (u16 *)(buf), (nr)) : \
276 raw_insw_swapw(isa_itw(port), (u16 *)(buf), (nr)))
278 #define isa_outsw(port, buf, nr) \
279 (ISA_SEX ? raw_outsw(isa_itw(port), (u16 *)(buf), (nr)) : \
280 raw_outsw_swapw(isa_itw(port), (u16 *)(buf), (nr)))
282 #define isa_insl(port, buf, nr) \
283 (ISA_SEX ? raw_insl(isa_itl(port), (u32 *)(buf), (nr)) : \
284 raw_insw_swapw(isa_itw(port), (u16 *)(buf), (nr)<<1))
286 #define isa_outsl(port, buf, nr) \
287 (ISA_SEX ? raw_outsl(isa_itl(port), (u32 *)(buf), (nr)) : \
288 raw_outsw_swapw(isa_itw(port), (u16 *)(buf), (nr)<<1))
291 #ifdef CONFIG_ATARI_ROM_ISA
292 #define isa_rom_inb_p(p) ({ u8 _v = isa_rom_inb(p); isa_delay(); _v; })
293 #define isa_rom_inw_p(p) ({ u16 _v = isa_rom_inw(p); isa_delay(); _v; })
294 #define isa_rom_outb_p(v, p) ({ isa_rom_outb((v), (p)); isa_delay(); })
295 #define isa_rom_outw_p(v, p) ({ isa_rom_outw((v), (p)); isa_delay(); })
297 #define isa_rom_insb(port, buf, nr) raw_rom_insb(isa_itb(port), (u8 *)(buf), (nr))
299 #define isa_rom_insw(port, buf, nr) \
300 (ISA_SEX ? raw_rom_insw(isa_itw(port), (u16 *)(buf), (nr)) : \
301 raw_rom_insw_swapw(isa_itw(port), (u16 *)(buf), (nr)))
303 #define isa_rom_outsb(port, buf, nr) raw_rom_outsb(isa_itb(port), (u8 *)(buf), (nr))
305 #define isa_rom_outsw(port, buf, nr) \
306 (ISA_SEX ? raw_rom_outsw(isa_itw(port), (u16 *)(buf), (nr)) : \
307 raw_rom_outsw_swapw(isa_itw(port), (u16 *)(buf), (nr)))
308 #endif /* CONFIG_ATARI_ROM_ISA */
310 #endif /* CONFIG_ISA || CONFIG_ATARI_ROM_ISA */
313 #if defined(CONFIG_ISA) && !defined(CONFIG_ATARI_ROM_ISA)
315 #define inb_p isa_inb_p
316 #define outb isa_outb
317 #define outb_p isa_outb_p
319 #define inw_p isa_inw_p
320 #define outw isa_outw
321 #define outw_p isa_outw_p
323 #define inl_p isa_inl_p
324 #define outl isa_outl
325 #define outl_p isa_outl_p
326 #define insb isa_insb
327 #define insw isa_insw
328 #define insl isa_insl
329 #define outsb isa_outsb
330 #define outsw isa_outsw
331 #define outsl isa_outsl
332 #define readb isa_readb
333 #define readw isa_readw
334 #define writeb isa_writeb
335 #define writew isa_writew
336 #endif /* CONFIG_ISA && !CONFIG_ATARI_ROM_ISA */
338 #ifdef CONFIG_ATARI_ROM_ISA
340 * kernel with both ROM port ISA and IDE compiled in, those have
341 * conflicting defs for in/out. Simply consider port < 1024
342 * ROM port ISA and everything else regular ISA for IDE. read,write defined
345 #define inb(port) ((port) < 1024 ? isa_rom_inb(port) : in_8(port))
346 #define inb_p(port) ((port) < 1024 ? isa_rom_inb_p(port) : in_8(port))
347 #define inw(port) ((port) < 1024 ? isa_rom_inw(port) : in_le16(port))
348 #define inw_p(port) ((port) < 1024 ? isa_rom_inw_p(port) : in_le16(port))
350 #define inl_p isa_inl_p
352 #define outb(val, port) ((port) < 1024 ? isa_rom_outb((val), (port)) : out_8((port), (val)))
353 #define outb_p(val, port) ((port) < 1024 ? isa_rom_outb_p((val), (port)) : out_8((port), (val)))
354 #define outw(val, port) ((port) < 1024 ? isa_rom_outw((val), (port)) : out_le16((port), (val)))
355 #define outw_p(val, port) ((port) < 1024 ? isa_rom_outw_p((val), (port)) : out_le16((port), (val)))
356 #define outl isa_outl
357 #define outl_p isa_outl_p
359 #define insb(port, buf, nr) ((port) < 1024 ? isa_rom_insb((port), (buf), (nr)) : isa_insb((port), (buf), (nr)))
360 #define insw(port, buf, nr) ((port) < 1024 ? isa_rom_insw((port), (buf), (nr)) : isa_insw((port), (buf), (nr)))
361 #define insl isa_insl
362 #define outsb(port, buf, nr) ((port) < 1024 ? isa_rom_outsb((port), (buf), (nr)) : isa_outsb((port), (buf), (nr)))
363 #define outsw(port, buf, nr) ((port) < 1024 ? isa_rom_outsw((port), (buf), (nr)) : isa_outsw((port), (buf), (nr)))
364 #define outsl isa_outsl
366 #define readb(addr) in_8(addr)
367 #define writeb(val, addr) out_8((addr), (val))
368 #define readw(addr) in_le16(addr)
369 #define writew(val, addr) out_le16((addr), (val))
370 #endif /* CONFIG_ATARI_ROM_ISA */
372 #define readl(addr) in_le32(addr)
373 #define writel(val,addr) out_le32((addr),(val))
375 #define readsb(port, buf, nr) raw_insb((port), (u8 *)(buf), (nr))
376 #define readsw(port, buf, nr) raw_insw((port), (u16 *)(buf), (nr))
377 #define readsl(port, buf, nr) raw_insl((port), (u32 *)(buf), (nr))
378 #define writesb(port, buf, nr) raw_outsb((port), (u8 *)(buf), (nr))
379 #define writesw(port, buf, nr) raw_outsw((port), (u16 *)(buf), (nr))
380 #define writesl(port, buf, nr) raw_outsl((port), (u32 *)(buf), (nr))
383 #define IO_SPACE_LIMIT 0xffff
385 #define IO_SPACE_LIMIT 0x0fffffff
388 #endif /* __KERNEL__ */
390 #define __ARCH_HAS_NO_PAGE_ZERO_MAPPED 1
393 * Convert a physical pointer to a virtual kernel pointer for /dev/mem
396 #define xlate_dev_mem_ptr(p) __va(p)
398 #define readb_relaxed(addr) readb(addr)
399 #define readw_relaxed(addr) readw(addr)
400 #define readl_relaxed(addr) readl(addr)
402 #define writeb_relaxed(b, addr) writeb(b, addr)
403 #define writew_relaxed(b, addr) writew(b, addr)
404 #define writel_relaxed(b, addr) writel(b, addr)
406 #endif /* _M68K_IO_MM_H */