treewide: remove redundant IS_ERR() before error code check
[linux/fpc-iii.git] / arch / m68k / include / asm / io_mm.h
blob819f611dccf28ee2bd27551eacc74305c70b3845
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3 * linux/include/asm-m68k/io.h
5 * 4/1/00 RZ: - rewritten to avoid clashes between ISA/PCI and other
6 * IO access
7 * - added Q40 support
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
19 #ifndef _M68K_IO_MM_H
20 #define _M68K_IO_MM_H
22 #ifdef __KERNEL__
24 #include <linux/compiler.h>
25 #include <asm/raw_io.h>
26 #include <asm/virtconvert.h>
27 #include <asm/kmap.h>
29 #include <asm-generic/iomap.h>
31 #ifdef CONFIG_ATARI
32 #define atari_readb raw_inb
33 #define atari_writeb raw_outb
35 #define atari_inb_p raw_inb
36 #define atari_outb_p raw_outb
37 #endif
41 * IO/MEM definitions for various ISA bridges
45 #ifdef CONFIG_Q40
47 #define q40_isa_io_base 0xff400000
48 #define q40_isa_mem_base 0xff800000
50 #define Q40_ISA_IO_B(ioaddr) (q40_isa_io_base+1+4*((unsigned long)(ioaddr)))
51 #define Q40_ISA_IO_W(ioaddr) (q40_isa_io_base+ 4*((unsigned long)(ioaddr)))
52 #define Q40_ISA_MEM_B(madr) (q40_isa_mem_base+1+4*((unsigned long)(madr)))
53 #define Q40_ISA_MEM_W(madr) (q40_isa_mem_base+ 4*((unsigned long)(madr)))
55 #define MULTI_ISA 0
56 #endif /* Q40 */
58 #ifdef CONFIG_AMIGA_PCMCIA
59 #include <asm/amigayle.h>
61 #define AG_ISA_IO_B(ioaddr) ( GAYLE_IO+(ioaddr)+(((ioaddr)&1)*GAYLE_ODD) )
62 #define AG_ISA_IO_W(ioaddr) ( GAYLE_IO+(ioaddr) )
64 #ifndef MULTI_ISA
65 #define MULTI_ISA 0
66 #else
67 #undef MULTI_ISA
68 #define MULTI_ISA 1
69 #endif
70 #endif /* AMIGA_PCMCIA */
72 #ifdef CONFIG_ATARI_ROM_ISA
74 #define enec_isa_read_base 0xfffa0000
75 #define enec_isa_write_base 0xfffb0000
77 #define ENEC_ISA_IO_B(ioaddr) (enec_isa_read_base+((((unsigned long)(ioaddr))&0x7F)<<9))
78 #define ENEC_ISA_IO_W(ioaddr) (enec_isa_read_base+((((unsigned long)(ioaddr))&0x7F)<<9))
79 #define ENEC_ISA_MEM_B(madr) (enec_isa_read_base+((((unsigned long)(madr))&0x7F)<<9))
80 #define ENEC_ISA_MEM_W(madr) (enec_isa_read_base+((((unsigned long)(madr))&0x7F)<<9))
82 #ifndef MULTI_ISA
83 #define MULTI_ISA 0
84 #else
85 #undef MULTI_ISA
86 #define MULTI_ISA 1
87 #endif
88 #endif /* ATARI_ROM_ISA */
91 #if defined(CONFIG_ISA) || defined(CONFIG_ATARI_ROM_ISA)
93 #if MULTI_ISA == 0
94 #undef MULTI_ISA
95 #endif
97 #define ISA_TYPE_Q40 (1)
98 #define ISA_TYPE_AG (2)
99 #define ISA_TYPE_ENEC (3)
101 #if defined(CONFIG_Q40) && !defined(MULTI_ISA)
102 #define ISA_TYPE ISA_TYPE_Q40
103 #define ISA_SEX 0
104 #endif
105 #if defined(CONFIG_AMIGA_PCMCIA) && !defined(MULTI_ISA)
106 #define ISA_TYPE ISA_TYPE_AG
107 #define ISA_SEX 1
108 #endif
109 #if defined(CONFIG_ATARI_ROM_ISA) && !defined(MULTI_ISA)
110 #define ISA_TYPE ISA_TYPE_ENEC
111 #define ISA_SEX 0
112 #endif
114 #ifdef MULTI_ISA
115 extern int isa_type;
116 extern int isa_sex;
118 #define ISA_TYPE isa_type
119 #define ISA_SEX isa_sex
120 #endif
123 * define inline addr translation functions. Normally only one variant will
124 * be compiled in so the case statement will be optimised away
127 static inline u8 __iomem *isa_itb(unsigned long addr)
129 switch(ISA_TYPE)
131 #ifdef CONFIG_Q40
132 case ISA_TYPE_Q40: return (u8 __iomem *)Q40_ISA_IO_B(addr);
133 #endif
134 #ifdef CONFIG_AMIGA_PCMCIA
135 case ISA_TYPE_AG: return (u8 __iomem *)AG_ISA_IO_B(addr);
136 #endif
137 #ifdef CONFIG_ATARI_ROM_ISA
138 case ISA_TYPE_ENEC: return (u8 __iomem *)ENEC_ISA_IO_B(addr);
139 #endif
140 default: return NULL; /* avoid warnings, just in case */
143 static inline u16 __iomem *isa_itw(unsigned long addr)
145 switch(ISA_TYPE)
147 #ifdef CONFIG_Q40
148 case ISA_TYPE_Q40: return (u16 __iomem *)Q40_ISA_IO_W(addr);
149 #endif
150 #ifdef CONFIG_AMIGA_PCMCIA
151 case ISA_TYPE_AG: return (u16 __iomem *)AG_ISA_IO_W(addr);
152 #endif
153 #ifdef CONFIG_ATARI_ROM_ISA
154 case ISA_TYPE_ENEC: return (u16 __iomem *)ENEC_ISA_IO_W(addr);
155 #endif
156 default: return NULL; /* avoid warnings, just in case */
159 static inline u32 __iomem *isa_itl(unsigned long addr)
161 switch(ISA_TYPE)
163 #ifdef CONFIG_AMIGA_PCMCIA
164 case ISA_TYPE_AG: return (u32 __iomem *)AG_ISA_IO_W(addr);
165 #endif
166 default: return 0; /* avoid warnings, just in case */
169 static inline u8 __iomem *isa_mtb(unsigned long addr)
171 switch(ISA_TYPE)
173 #ifdef CONFIG_Q40
174 case ISA_TYPE_Q40: return (u8 __iomem *)Q40_ISA_MEM_B(addr);
175 #endif
176 #ifdef CONFIG_AMIGA_PCMCIA
177 case ISA_TYPE_AG: return (u8 __iomem *)addr;
178 #endif
179 #ifdef CONFIG_ATARI_ROM_ISA
180 case ISA_TYPE_ENEC: return (u8 __iomem *)ENEC_ISA_MEM_B(addr);
181 #endif
182 default: return NULL; /* avoid warnings, just in case */
185 static inline u16 __iomem *isa_mtw(unsigned long addr)
187 switch(ISA_TYPE)
189 #ifdef CONFIG_Q40
190 case ISA_TYPE_Q40: return (u16 __iomem *)Q40_ISA_MEM_W(addr);
191 #endif
192 #ifdef CONFIG_AMIGA_PCMCIA
193 case ISA_TYPE_AG: return (u16 __iomem *)addr;
194 #endif
195 #ifdef CONFIG_ATARI_ROM_ISA
196 case ISA_TYPE_ENEC: return (u16 __iomem *)ENEC_ISA_MEM_W(addr);
197 #endif
198 default: return NULL; /* avoid warnings, just in case */
203 #define isa_inb(port) in_8(isa_itb(port))
204 #define isa_inw(port) (ISA_SEX ? in_be16(isa_itw(port)) : in_le16(isa_itw(port)))
205 #define isa_inl(port) (ISA_SEX ? in_be32(isa_itl(port)) : in_le32(isa_itl(port)))
206 #define isa_outb(val,port) out_8(isa_itb(port),(val))
207 #define isa_outw(val,port) (ISA_SEX ? out_be16(isa_itw(port),(val)) : out_le16(isa_itw(port),(val)))
208 #define isa_outl(val,port) (ISA_SEX ? out_be32(isa_itl(port),(val)) : out_le32(isa_itl(port),(val)))
210 #define isa_readb(p) in_8(isa_mtb((unsigned long)(p)))
211 #define isa_readw(p) \
212 (ISA_SEX ? in_be16(isa_mtw((unsigned long)(p))) \
213 : in_le16(isa_mtw((unsigned long)(p))))
214 #define isa_writeb(val,p) out_8(isa_mtb((unsigned long)(p)),(val))
215 #define isa_writew(val,p) \
216 (ISA_SEX ? out_be16(isa_mtw((unsigned long)(p)),(val)) \
217 : out_le16(isa_mtw((unsigned long)(p)),(val)))
219 #ifdef CONFIG_ATARI_ROM_ISA
220 #define isa_rom_inb(port) rom_in_8(isa_itb(port))
221 #define isa_rom_inw(port) \
222 (ISA_SEX ? rom_in_be16(isa_itw(port)) \
223 : rom_in_le16(isa_itw(port)))
225 #define isa_rom_outb(val, port) rom_out_8(isa_itb(port), (val))
226 #define isa_rom_outw(val, port) \
227 (ISA_SEX ? rom_out_be16(isa_itw(port), (val)) \
228 : rom_out_le16(isa_itw(port), (val)))
230 #define isa_rom_readb(p) rom_in_8(isa_mtb((unsigned long)(p)))
231 #define isa_rom_readw(p) \
232 (ISA_SEX ? rom_in_be16(isa_mtw((unsigned long)(p))) \
233 : rom_in_le16(isa_mtw((unsigned long)(p))))
234 #define isa_rom_readw_swap(p) \
235 (ISA_SEX ? rom_in_le16(isa_mtw((unsigned long)(p))) \
236 : rom_in_be16(isa_mtw((unsigned long)(p))))
237 #define isa_rom_readw_raw(p) rom_in_be16(isa_mtw((unsigned long)(p)))
239 #define isa_rom_writeb(val, p) rom_out_8(isa_mtb((unsigned long)(p)), (val))
240 #define isa_rom_writew(val, p) \
241 (ISA_SEX ? rom_out_be16(isa_mtw((unsigned long)(p)), (val)) \
242 : rom_out_le16(isa_mtw((unsigned long)(p)), (val)))
243 #define isa_rom_writew_swap(val, p) \
244 (ISA_SEX ? rom_out_le16(isa_mtw((unsigned long)(p)), (val)) \
245 : rom_out_be16(isa_mtw((unsigned long)(p)), (val)))
246 #define isa_rom_writew_raw(val, p) rom_out_be16(isa_mtw((unsigned long)(p)), (val))
247 #endif /* CONFIG_ATARI_ROM_ISA */
249 static inline void isa_delay(void)
251 switch(ISA_TYPE)
253 #ifdef CONFIG_Q40
254 case ISA_TYPE_Q40: isa_outb(0,0x80); break;
255 #endif
256 #ifdef CONFIG_AMIGA_PCMCIA
257 case ISA_TYPE_AG: break;
258 #endif
259 #ifdef CONFIG_ATARI_ROM_ISA
260 case ISA_TYPE_ENEC: break;
261 #endif
262 default: break; /* avoid warnings */
266 #define isa_inb_p(p) ({u8 v=isa_inb(p);isa_delay();v;})
267 #define isa_outb_p(v,p) ({isa_outb((v),(p));isa_delay();})
268 #define isa_inw_p(p) ({u16 v=isa_inw(p);isa_delay();v;})
269 #define isa_outw_p(v,p) ({isa_outw((v),(p));isa_delay();})
270 #define isa_inl_p(p) ({u32 v=isa_inl(p);isa_delay();v;})
271 #define isa_outl_p(v,p) ({isa_outl((v),(p));isa_delay();})
273 #define isa_insb(port, buf, nr) raw_insb(isa_itb(port), (u8 *)(buf), (nr))
274 #define isa_outsb(port, buf, nr) raw_outsb(isa_itb(port), (u8 *)(buf), (nr))
276 #define isa_insw(port, buf, nr) \
277 (ISA_SEX ? raw_insw(isa_itw(port), (u16 *)(buf), (nr)) : \
278 raw_insw_swapw(isa_itw(port), (u16 *)(buf), (nr)))
280 #define isa_outsw(port, buf, nr) \
281 (ISA_SEX ? raw_outsw(isa_itw(port), (u16 *)(buf), (nr)) : \
282 raw_outsw_swapw(isa_itw(port), (u16 *)(buf), (nr)))
284 #define isa_insl(port, buf, nr) \
285 (ISA_SEX ? raw_insl(isa_itl(port), (u32 *)(buf), (nr)) : \
286 raw_insw_swapw(isa_itw(port), (u16 *)(buf), (nr)<<1))
288 #define isa_outsl(port, buf, nr) \
289 (ISA_SEX ? raw_outsl(isa_itl(port), (u32 *)(buf), (nr)) : \
290 raw_outsw_swapw(isa_itw(port), (u16 *)(buf), (nr)<<1))
293 #ifdef CONFIG_ATARI_ROM_ISA
294 #define isa_rom_inb_p(p) ({ u8 _v = isa_rom_inb(p); isa_delay(); _v; })
295 #define isa_rom_inw_p(p) ({ u16 _v = isa_rom_inw(p); isa_delay(); _v; })
296 #define isa_rom_outb_p(v, p) ({ isa_rom_outb((v), (p)); isa_delay(); })
297 #define isa_rom_outw_p(v, p) ({ isa_rom_outw((v), (p)); isa_delay(); })
299 #define isa_rom_insb(port, buf, nr) raw_rom_insb(isa_itb(port), (u8 *)(buf), (nr))
301 #define isa_rom_insw(port, buf, nr) \
302 (ISA_SEX ? raw_rom_insw(isa_itw(port), (u16 *)(buf), (nr)) : \
303 raw_rom_insw_swapw(isa_itw(port), (u16 *)(buf), (nr)))
305 #define isa_rom_outsb(port, buf, nr) raw_rom_outsb(isa_itb(port), (u8 *)(buf), (nr))
307 #define isa_rom_outsw(port, buf, nr) \
308 (ISA_SEX ? raw_rom_outsw(isa_itw(port), (u16 *)(buf), (nr)) : \
309 raw_rom_outsw_swapw(isa_itw(port), (u16 *)(buf), (nr)))
310 #endif /* CONFIG_ATARI_ROM_ISA */
312 #endif /* CONFIG_ISA || CONFIG_ATARI_ROM_ISA */
315 #if defined(CONFIG_ISA) && !defined(CONFIG_ATARI_ROM_ISA)
316 #define inb isa_inb
317 #define inb_p isa_inb_p
318 #define outb isa_outb
319 #define outb_p isa_outb_p
320 #define inw isa_inw
321 #define inw_p isa_inw_p
322 #define outw isa_outw
323 #define outw_p isa_outw_p
324 #define inl isa_inl
325 #define inl_p isa_inl_p
326 #define outl isa_outl
327 #define outl_p isa_outl_p
328 #define insb isa_insb
329 #define insw isa_insw
330 #define insl isa_insl
331 #define outsb isa_outsb
332 #define outsw isa_outsw
333 #define outsl isa_outsl
334 #define readb isa_readb
335 #define readw isa_readw
336 #define writeb isa_writeb
337 #define writew isa_writew
338 #endif /* CONFIG_ISA && !CONFIG_ATARI_ROM_ISA */
340 #ifdef CONFIG_ATARI_ROM_ISA
342 * kernel with both ROM port ISA and IDE compiled in, those have
343 * conflicting defs for in/out. Simply consider port < 1024
344 * ROM port ISA and everything else regular ISA for IDE. read,write defined
345 * below.
347 #define inb(port) ((port) < 1024 ? isa_rom_inb(port) : in_8(port))
348 #define inb_p(port) ((port) < 1024 ? isa_rom_inb_p(port) : in_8(port))
349 #define inw(port) ((port) < 1024 ? isa_rom_inw(port) : in_le16(port))
350 #define inw_p(port) ((port) < 1024 ? isa_rom_inw_p(port) : in_le16(port))
351 #define inl isa_inl
352 #define inl_p isa_inl_p
354 #define outb(val, port) ((port) < 1024 ? isa_rom_outb((val), (port)) : out_8((port), (val)))
355 #define outb_p(val, port) ((port) < 1024 ? isa_rom_outb_p((val), (port)) : out_8((port), (val)))
356 #define outw(val, port) ((port) < 1024 ? isa_rom_outw((val), (port)) : out_le16((port), (val)))
357 #define outw_p(val, port) ((port) < 1024 ? isa_rom_outw_p((val), (port)) : out_le16((port), (val)))
358 #define outl isa_outl
359 #define outl_p isa_outl_p
361 #define insb(port, buf, nr) ((port) < 1024 ? isa_rom_insb((port), (buf), (nr)) : isa_insb((port), (buf), (nr)))
362 #define insw(port, buf, nr) ((port) < 1024 ? isa_rom_insw((port), (buf), (nr)) : isa_insw((port), (buf), (nr)))
363 #define insl isa_insl
364 #define outsb(port, buf, nr) ((port) < 1024 ? isa_rom_outsb((port), (buf), (nr)) : isa_outsb((port), (buf), (nr)))
365 #define outsw(port, buf, nr) ((port) < 1024 ? isa_rom_outsw((port), (buf), (nr)) : isa_outsw((port), (buf), (nr)))
366 #define outsl isa_outsl
368 #define readb(addr) in_8(addr)
369 #define writeb(val, addr) out_8((addr), (val))
370 #define readw(addr) in_le16(addr)
371 #define writew(val, addr) out_le16((addr), (val))
372 #endif /* CONFIG_ATARI_ROM_ISA */
374 #define readl(addr) in_le32(addr)
375 #define writel(val,addr) out_le32((addr),(val))
377 #define readsb(port, buf, nr) raw_insb((port), (u8 *)(buf), (nr))
378 #define readsw(port, buf, nr) raw_insw((port), (u16 *)(buf), (nr))
379 #define readsl(port, buf, nr) raw_insl((port), (u32 *)(buf), (nr))
380 #define writesb(port, buf, nr) raw_outsb((port), (u8 *)(buf), (nr))
381 #define writesw(port, buf, nr) raw_outsw((port), (u16 *)(buf), (nr))
382 #define writesl(port, buf, nr) raw_outsl((port), (u32 *)(buf), (nr))
384 #ifndef CONFIG_SUN3
385 #define IO_SPACE_LIMIT 0xffff
386 #else
387 #define IO_SPACE_LIMIT 0x0fffffff
388 #endif
390 #endif /* __KERNEL__ */
392 #define __ARCH_HAS_NO_PAGE_ZERO_MAPPED 1
395 * Convert a physical pointer to a virtual kernel pointer for /dev/mem
396 * access
398 #define xlate_dev_mem_ptr(p) __va(p)
401 * Convert a virtual cached pointer to an uncached pointer
403 #define xlate_dev_kmem_ptr(p) p
405 #define readb_relaxed(addr) readb(addr)
406 #define readw_relaxed(addr) readw(addr)
407 #define readl_relaxed(addr) readl(addr)
409 #define writeb_relaxed(b, addr) writeb(b, addr)
410 #define writew_relaxed(b, addr) writew(b, addr)
411 #define writel_relaxed(b, addr) writel(b, addr)
413 #endif /* _M68K_IO_MM_H */