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>
29 #include <asm-generic/iomap.h>
32 #include <asm/atarihw.h>
37 * IO/MEM definitions for various ISA bridges
43 #define q40_isa_io_base 0xff400000
44 #define q40_isa_mem_base 0xff800000
46 #define Q40_ISA_IO_B(ioaddr) (q40_isa_io_base+1+4*((unsigned long)(ioaddr)))
47 #define Q40_ISA_IO_W(ioaddr) (q40_isa_io_base+ 4*((unsigned long)(ioaddr)))
48 #define Q40_ISA_MEM_B(madr) (q40_isa_mem_base+1+4*((unsigned long)(madr)))
49 #define Q40_ISA_MEM_W(madr) (q40_isa_mem_base+ 4*((unsigned long)(madr)))
54 #ifdef CONFIG_AMIGA_PCMCIA
55 #include <asm/amigayle.h>
57 #define AG_ISA_IO_B(ioaddr) ( GAYLE_IO+(ioaddr)+(((ioaddr)&1)*GAYLE_ODD) )
58 #define AG_ISA_IO_W(ioaddr) ( GAYLE_IO+(ioaddr) )
66 #endif /* AMIGA_PCMCIA */
68 #ifdef CONFIG_ATARI_ROM_ISA
70 #define enec_isa_read_base 0xfffa0000
71 #define enec_isa_write_base 0xfffb0000
73 #define ENEC_ISA_IO_B(ioaddr) (enec_isa_read_base+((((unsigned long)(ioaddr))&0x7F)<<9))
74 #define ENEC_ISA_IO_W(ioaddr) (enec_isa_read_base+((((unsigned long)(ioaddr))&0x7F)<<9))
75 #define ENEC_ISA_MEM_B(madr) (enec_isa_read_base+((((unsigned long)(madr))&0x7F)<<9))
76 #define ENEC_ISA_MEM_W(madr) (enec_isa_read_base+((((unsigned long)(madr))&0x7F)<<9))
84 #endif /* ATARI_ROM_ISA */
87 #if defined(CONFIG_ISA) || defined(CONFIG_ATARI_ROM_ISA)
93 #define ISA_TYPE_Q40 (1)
94 #define ISA_TYPE_AG (2)
95 #define ISA_TYPE_ENEC (3)
97 #if defined(CONFIG_Q40) && !defined(MULTI_ISA)
98 #define ISA_TYPE ISA_TYPE_Q40
101 #if defined(CONFIG_AMIGA_PCMCIA) && !defined(MULTI_ISA)
102 #define ISA_TYPE ISA_TYPE_AG
105 #if defined(CONFIG_ATARI_ROM_ISA) && !defined(MULTI_ISA)
106 #define ISA_TYPE ISA_TYPE_ENEC
114 #define ISA_TYPE isa_type
115 #define ISA_SEX isa_sex
119 * define inline addr translation functions. Normally only one variant will
120 * be compiled in so the case statement will be optimised away
123 static inline u8 __iomem *isa_itb(unsigned long addr)
128 case ISA_TYPE_Q40: return (u8 __iomem *)Q40_ISA_IO_B(addr);
130 #ifdef CONFIG_AMIGA_PCMCIA
131 case ISA_TYPE_AG: return (u8 __iomem *)AG_ISA_IO_B(addr);
133 #ifdef CONFIG_ATARI_ROM_ISA
134 case ISA_TYPE_ENEC: return (u8 __iomem *)ENEC_ISA_IO_B(addr);
136 default: return NULL; /* avoid warnings, just in case */
139 static inline u16 __iomem *isa_itw(unsigned long addr)
144 case ISA_TYPE_Q40: return (u16 __iomem *)Q40_ISA_IO_W(addr);
146 #ifdef CONFIG_AMIGA_PCMCIA
147 case ISA_TYPE_AG: return (u16 __iomem *)AG_ISA_IO_W(addr);
149 #ifdef CONFIG_ATARI_ROM_ISA
150 case ISA_TYPE_ENEC: return (u16 __iomem *)ENEC_ISA_IO_W(addr);
152 default: return NULL; /* avoid warnings, just in case */
155 static inline u32 __iomem *isa_itl(unsigned long addr)
159 #ifdef CONFIG_AMIGA_PCMCIA
160 case ISA_TYPE_AG: return (u32 __iomem *)AG_ISA_IO_W(addr);
162 default: return 0; /* avoid warnings, just in case */
165 static inline u8 __iomem *isa_mtb(unsigned long addr)
170 case ISA_TYPE_Q40: return (u8 __iomem *)Q40_ISA_MEM_B(addr);
172 #ifdef CONFIG_AMIGA_PCMCIA
173 case ISA_TYPE_AG: return (u8 __iomem *)addr;
175 #ifdef CONFIG_ATARI_ROM_ISA
176 case ISA_TYPE_ENEC: return (u8 __iomem *)ENEC_ISA_MEM_B(addr);
178 default: return NULL; /* avoid warnings, just in case */
181 static inline u16 __iomem *isa_mtw(unsigned long addr)
186 case ISA_TYPE_Q40: return (u16 __iomem *)Q40_ISA_MEM_W(addr);
188 #ifdef CONFIG_AMIGA_PCMCIA
189 case ISA_TYPE_AG: return (u16 __iomem *)addr;
191 #ifdef CONFIG_ATARI_ROM_ISA
192 case ISA_TYPE_ENEC: return (u16 __iomem *)ENEC_ISA_MEM_W(addr);
194 default: return NULL; /* avoid warnings, just in case */
199 #define isa_inb(port) in_8(isa_itb(port))
200 #define isa_inw(port) (ISA_SEX ? in_be16(isa_itw(port)) : in_le16(isa_itw(port)))
201 #define isa_inl(port) (ISA_SEX ? in_be32(isa_itl(port)) : in_le32(isa_itl(port)))
202 #define isa_outb(val,port) out_8(isa_itb(port),(val))
203 #define isa_outw(val,port) (ISA_SEX ? out_be16(isa_itw(port),(val)) : out_le16(isa_itw(port),(val)))
204 #define isa_outl(val,port) (ISA_SEX ? out_be32(isa_itl(port),(val)) : out_le32(isa_itl(port),(val)))
206 #define isa_readb(p) in_8(isa_mtb((unsigned long)(p)))
207 #define isa_readw(p) \
208 (ISA_SEX ? in_be16(isa_mtw((unsigned long)(p))) \
209 : in_le16(isa_mtw((unsigned long)(p))))
210 #define isa_writeb(val,p) out_8(isa_mtb((unsigned long)(p)),(val))
211 #define isa_writew(val,p) \
212 (ISA_SEX ? out_be16(isa_mtw((unsigned long)(p)),(val)) \
213 : out_le16(isa_mtw((unsigned long)(p)),(val)))
215 #ifdef CONFIG_ATARI_ROM_ISA
216 #define isa_rom_inb(port) rom_in_8(isa_itb(port))
217 #define isa_rom_inw(port) \
218 (ISA_SEX ? rom_in_be16(isa_itw(port)) \
219 : rom_in_le16(isa_itw(port)))
221 #define isa_rom_outb(val, port) rom_out_8(isa_itb(port), (val))
222 #define isa_rom_outw(val, port) \
223 (ISA_SEX ? rom_out_be16(isa_itw(port), (val)) \
224 : rom_out_le16(isa_itw(port), (val)))
226 #define isa_rom_readb(p) rom_in_8(isa_mtb((unsigned long)(p)))
227 #define isa_rom_readw(p) \
228 (ISA_SEX ? rom_in_be16(isa_mtw((unsigned long)(p))) \
229 : rom_in_le16(isa_mtw((unsigned long)(p))))
230 #define isa_rom_readw_swap(p) \
231 (ISA_SEX ? rom_in_le16(isa_mtw((unsigned long)(p))) \
232 : rom_in_be16(isa_mtw((unsigned long)(p))))
233 #define isa_rom_readw_raw(p) rom_in_be16(isa_mtw((unsigned long)(p)))
235 #define isa_rom_writeb(val, p) rom_out_8(isa_mtb((unsigned long)(p)), (val))
236 #define isa_rom_writew(val, p) \
237 (ISA_SEX ? rom_out_be16(isa_mtw((unsigned long)(p)), (val)) \
238 : rom_out_le16(isa_mtw((unsigned long)(p)), (val)))
239 #define isa_rom_writew_swap(val, p) \
240 (ISA_SEX ? rom_out_le16(isa_mtw((unsigned long)(p)), (val)) \
241 : rom_out_be16(isa_mtw((unsigned long)(p)), (val)))
242 #define isa_rom_writew_raw(val, p) rom_out_be16(isa_mtw((unsigned long)(p)), (val))
243 #endif /* CONFIG_ATARI_ROM_ISA */
245 static inline void isa_delay(void)
250 case ISA_TYPE_Q40: isa_outb(0,0x80); break;
252 #ifdef CONFIG_AMIGA_PCMCIA
253 case ISA_TYPE_AG: break;
255 #ifdef CONFIG_ATARI_ROM_ISA
256 case ISA_TYPE_ENEC: break;
258 default: break; /* avoid warnings */
262 #define isa_inb_p(p) ({u8 v=isa_inb(p);isa_delay();v;})
263 #define isa_outb_p(v,p) ({isa_outb((v),(p));isa_delay();})
264 #define isa_inw_p(p) ({u16 v=isa_inw(p);isa_delay();v;})
265 #define isa_outw_p(v,p) ({isa_outw((v),(p));isa_delay();})
266 #define isa_inl_p(p) ({u32 v=isa_inl(p);isa_delay();v;})
267 #define isa_outl_p(v,p) ({isa_outl((v),(p));isa_delay();})
269 #define isa_insb(port, buf, nr) raw_insb(isa_itb(port), (u8 *)(buf), (nr))
270 #define isa_outsb(port, buf, nr) raw_outsb(isa_itb(port), (u8 *)(buf), (nr))
272 #define isa_insw(port, buf, nr) \
273 (ISA_SEX ? raw_insw(isa_itw(port), (u16 *)(buf), (nr)) : \
274 raw_insw_swapw(isa_itw(port), (u16 *)(buf), (nr)))
276 #define isa_outsw(port, buf, nr) \
277 (ISA_SEX ? raw_outsw(isa_itw(port), (u16 *)(buf), (nr)) : \
278 raw_outsw_swapw(isa_itw(port), (u16 *)(buf), (nr)))
280 #define isa_insl(port, buf, nr) \
281 (ISA_SEX ? raw_insl(isa_itl(port), (u32 *)(buf), (nr)) : \
282 raw_insw_swapw(isa_itw(port), (u16 *)(buf), (nr)<<1))
284 #define isa_outsl(port, buf, nr) \
285 (ISA_SEX ? raw_outsl(isa_itl(port), (u32 *)(buf), (nr)) : \
286 raw_outsw_swapw(isa_itw(port), (u16 *)(buf), (nr)<<1))
289 #ifdef CONFIG_ATARI_ROM_ISA
290 #define isa_rom_inb_p(p) ({ u8 _v = isa_rom_inb(p); isa_delay(); _v; })
291 #define isa_rom_inw_p(p) ({ u16 _v = isa_rom_inw(p); isa_delay(); _v; })
292 #define isa_rom_outb_p(v, p) ({ isa_rom_outb((v), (p)); isa_delay(); })
293 #define isa_rom_outw_p(v, p) ({ isa_rom_outw((v), (p)); isa_delay(); })
295 #define isa_rom_insb(port, buf, nr) raw_rom_insb(isa_itb(port), (u8 *)(buf), (nr))
297 #define isa_rom_insw(port, buf, nr) \
298 (ISA_SEX ? raw_rom_insw(isa_itw(port), (u16 *)(buf), (nr)) : \
299 raw_rom_insw_swapw(isa_itw(port), (u16 *)(buf), (nr)))
301 #define isa_rom_outsb(port, buf, nr) raw_rom_outsb(isa_itb(port), (u8 *)(buf), (nr))
303 #define isa_rom_outsw(port, buf, nr) \
304 (ISA_SEX ? raw_rom_outsw(isa_itw(port), (u16 *)(buf), (nr)) : \
305 raw_rom_outsw_swapw(isa_itw(port), (u16 *)(buf), (nr)))
306 #endif /* CONFIG_ATARI_ROM_ISA */
308 #endif /* CONFIG_ISA || CONFIG_ATARI_ROM_ISA */
311 #if defined(CONFIG_ISA) && !defined(CONFIG_ATARI_ROM_ISA)
313 #define inb_p isa_inb_p
314 #define outb isa_outb
315 #define outb_p isa_outb_p
317 #define inw_p isa_inw_p
318 #define outw isa_outw
319 #define outw_p isa_outw_p
321 #define inl_p isa_inl_p
322 #define outl isa_outl
323 #define outl_p isa_outl_p
324 #define insb isa_insb
325 #define insw isa_insw
326 #define insl isa_insl
327 #define outsb isa_outsb
328 #define outsw isa_outsw
329 #define outsl isa_outsl
330 #define readb isa_readb
331 #define readw isa_readw
332 #define writeb isa_writeb
333 #define writew isa_writew
334 #endif /* CONFIG_ISA && !CONFIG_ATARI_ROM_ISA */
336 #ifdef CONFIG_ATARI_ROM_ISA
338 * kernel with both ROM port ISA and IDE compiled in, those have
339 * conflicting defs for in/out. Simply consider port < 1024
340 * ROM port ISA and everything else regular ISA for IDE. read,write defined
343 #define inb(port) ((port) < 1024 ? isa_rom_inb(port) : in_8(port))
344 #define inb_p(port) ((port) < 1024 ? isa_rom_inb_p(port) : in_8(port))
345 #define inw(port) ((port) < 1024 ? isa_rom_inw(port) : in_le16(port))
346 #define inw_p(port) ((port) < 1024 ? isa_rom_inw_p(port) : in_le16(port))
348 #define inl_p isa_inl_p
350 #define outb(val, port) ((port) < 1024 ? isa_rom_outb((val), (port)) : out_8((port), (val)))
351 #define outb_p(val, port) ((port) < 1024 ? isa_rom_outb_p((val), (port)) : out_8((port), (val)))
352 #define outw(val, port) ((port) < 1024 ? isa_rom_outw((val), (port)) : out_le16((port), (val)))
353 #define outw_p(val, port) ((port) < 1024 ? isa_rom_outw_p((val), (port)) : out_le16((port), (val)))
354 #define outl isa_outl
355 #define outl_p isa_outl_p
357 #define insb(port, buf, nr) ((port) < 1024 ? isa_rom_insb((port), (buf), (nr)) : isa_insb((port), (buf), (nr)))
358 #define insw(port, buf, nr) ((port) < 1024 ? isa_rom_insw((port), (buf), (nr)) : isa_insw((port), (buf), (nr)))
359 #define insl isa_insl
360 #define outsb(port, buf, nr) ((port) < 1024 ? isa_rom_outsb((port), (buf), (nr)) : isa_outsb((port), (buf), (nr)))
361 #define outsw(port, buf, nr) ((port) < 1024 ? isa_rom_outsw((port), (buf), (nr)) : isa_outsw((port), (buf), (nr)))
362 #define outsl isa_outsl
364 #define readb(addr) in_8(addr)
365 #define writeb(val, addr) out_8((addr), (val))
366 #define readw(addr) in_le16(addr)
367 #define writew(val, addr) out_le16((addr), (val))
368 #endif /* CONFIG_ATARI_ROM_ISA */
370 #define readl(addr) in_le32(addr)
371 #define writel(val,addr) out_le32((addr),(val))
373 #define readsb(port, buf, nr) raw_insb((port), (u8 *)(buf), (nr))
374 #define readsw(port, buf, nr) raw_insw((port), (u16 *)(buf), (nr))
375 #define readsl(port, buf, nr) raw_insl((port), (u32 *)(buf), (nr))
376 #define writesb(port, buf, nr) raw_outsb((port), (u8 *)(buf), (nr))
377 #define writesw(port, buf, nr) raw_outsw((port), (u16 *)(buf), (nr))
378 #define writesl(port, buf, nr) raw_outsl((port), (u32 *)(buf), (nr))
381 #define IO_SPACE_LIMIT 0xffff
383 #define IO_SPACE_LIMIT 0x0fffffff
386 #endif /* __KERNEL__ */
388 #define __ARCH_HAS_NO_PAGE_ZERO_MAPPED 1
391 * Convert a physical pointer to a virtual kernel pointer for /dev/mem
394 #define xlate_dev_mem_ptr(p) __va(p)
397 * Convert a virtual cached pointer to an uncached pointer
399 #define xlate_dev_kmem_ptr(p) p
401 #define readb_relaxed(addr) readb(addr)
402 #define readw_relaxed(addr) readw(addr)
403 #define readl_relaxed(addr) readl(addr)
405 #define writeb_relaxed(b, addr) writeb(b, addr)
406 #define writew_relaxed(b, addr) writew(b, addr)
407 #define writel_relaxed(b, addr) writel(b, addr)
409 #endif /* _M68K_IO_MM_H */