1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * linux/include/asm-m68k/io.h
4  *
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
10  *
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.
14  *
15  *    inX(),outX()              are for ISA I/O
16  *    isa_readX(),isa_writeX()  are for ISA memory
17  */
18 
19 #ifndef _M68K_IO_MM_H
20 #define _M68K_IO_MM_H
21 
22 #ifdef __KERNEL__
23 
24 #include <linux/compiler.h>
25 #include <asm/raw_io.h>
26 #include <asm/virtconvert.h>
27 #include <asm/kmap.h>
28 
29 #include <asm-generic/iomap.h>
30 
31 #ifdef CONFIG_ATARI
32 #define atari_readb   raw_inb
33 #define atari_writeb  raw_outb
34 
35 #define atari_inb_p   raw_inb
36 #define atari_outb_p  raw_outb
37 #endif
38 
39 
40 /*
41  * IO/MEM definitions for various ISA bridges
42  */
43 
44 
45 #ifdef CONFIG_Q40
46 
47 #define q40_isa_io_base  0xff400000
48 #define q40_isa_mem_base 0xff800000
49 
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)))
54 
55 #define MULTI_ISA 0
56 #endif /* Q40 */
57 
58 #ifdef CONFIG_AMIGA_PCMCIA
59 #include <asm/amigayle.h>
60 
61 #define AG_ISA_IO_B(ioaddr) ( GAYLE_IO+(ioaddr)+(((ioaddr)&1)*GAYLE_ODD) )
62 #define AG_ISA_IO_W(ioaddr) ( GAYLE_IO+(ioaddr) )
63 
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 */
71 
72 #ifdef CONFIG_ATARI_ROM_ISA
73 
74 #define enec_isa_read_base  0xfffa0000
75 #define enec_isa_write_base 0xfffb0000
76 
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))
81 
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 */
89 
90 
91 #if defined(CONFIG_ISA) || defined(CONFIG_ATARI_ROM_ISA)
92 
93 #if MULTI_ISA == 0
94 #undef MULTI_ISA
95 #endif
96 
97 #define ISA_TYPE_Q40  (1)
98 #define ISA_TYPE_AG   (2)
99 #define ISA_TYPE_ENEC (3)
100 
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
113 
114 #ifdef MULTI_ISA
115 extern int isa_type;
116 extern int isa_sex;
117 
118 #define ISA_TYPE isa_type
119 #define ISA_SEX  isa_sex
120 #endif
121 
122 /*
123  * define inline addr translation functions. Normally only one variant will
124  * be compiled in so the case statement will be optimised away
125  */
126 
isa_itb(unsigned long addr)127 static inline u8 __iomem *isa_itb(unsigned long addr)
128 {
129   switch(ISA_TYPE)
130     {
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 */
141     }
142 }
isa_itw(unsigned long addr)143 static inline u16 __iomem *isa_itw(unsigned long addr)
144 {
145   switch(ISA_TYPE)
146     {
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 */
157     }
158 }
isa_itl(unsigned long addr)159 static inline u32 __iomem *isa_itl(unsigned long addr)
160 {
161   switch(ISA_TYPE)
162     {
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 */
167     }
168 }
isa_mtb(unsigned long addr)169 static inline u8 __iomem *isa_mtb(unsigned long addr)
170 {
171   switch(ISA_TYPE)
172     {
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 */
183     }
184 }
isa_mtw(unsigned long addr)185 static inline u16 __iomem *isa_mtw(unsigned long addr)
186 {
187   switch(ISA_TYPE)
188     {
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 */
199     }
200 }
201 
202 
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)))
209 
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)))
218 
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)))
224 
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)))
229 
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)))
238 
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 */
248 
isa_delay(void)249 static inline void isa_delay(void)
250 {
251   switch(ISA_TYPE)
252     {
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 */
263     }
264 }
265 
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();})
272 
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))
275 
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)))
279 
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)))
283 
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))
287 
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))
291 
292 
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(); })
298 
299 #define isa_rom_insb(port, buf, nr) raw_rom_insb(isa_itb(port), (u8 *)(buf), (nr))
300 
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)))
304 
305 #define isa_rom_outsb(port, buf, nr) raw_rom_outsb(isa_itb(port), (u8 *)(buf), (nr))
306 
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 */
311 
312 #endif  /* CONFIG_ISA || CONFIG_ATARI_ROM_ISA */
313 
314 
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 */
339 
340 #ifdef CONFIG_ATARI_ROM_ISA
341 /*
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.
346  */
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
353 
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
360 
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
367 
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 */
373 
374 #define readl(addr)      in_le32(addr)
375 #define writel(val,addr) out_le32((addr),(val))
376 
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))
383 
384 #ifndef CONFIG_SUN3
385 #define IO_SPACE_LIMIT 0xffff
386 #else
387 #define IO_SPACE_LIMIT 0x0fffffff
388 #endif
389 
390 #endif /* __KERNEL__ */
391 
392 #define __ARCH_HAS_NO_PAGE_ZERO_MAPPED		1
393 
394 /*
395  * Convert a physical pointer to a virtual kernel pointer for /dev/mem
396  * access
397  */
398 #define xlate_dev_mem_ptr(p)	__va(p)
399 
400 #define readb_relaxed(addr)	readb(addr)
401 #define readw_relaxed(addr)	readw(addr)
402 #define readl_relaxed(addr)	readl(addr)
403 
404 #define writeb_relaxed(b, addr)	writeb(b, addr)
405 #define writew_relaxed(b, addr)	writew(b, addr)
406 #define writel_relaxed(b, addr)	writel(b, addr)
407 
408 #endif /* _M68K_IO_MM_H */
409