xref: /openbmc/linux/arch/m68k/include/asm/io_mm.h (revision 7f1005dd)
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 #ifdef CONFIG_ATARI
30 #define atari_readb   raw_inb
31 #define atari_writeb  raw_outb
32 
33 #define atari_inb_p   raw_inb
34 #define atari_outb_p  raw_outb
35 #endif
36 
37 
38 /*
39  * IO/MEM definitions for various ISA bridges
40  */
41 
42 
43 #ifdef CONFIG_Q40
44 
45 #define q40_isa_io_base  0xff400000
46 #define q40_isa_mem_base 0xff800000
47 
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)))
52 
53 #define MULTI_ISA 0
54 #endif /* Q40 */
55 
56 #ifdef CONFIG_AMIGA_PCMCIA
57 #include <asm/amigayle.h>
58 
59 #define AG_ISA_IO_B(ioaddr) ( GAYLE_IO+(ioaddr)+(((ioaddr)&1)*GAYLE_ODD) )
60 #define AG_ISA_IO_W(ioaddr) ( GAYLE_IO+(ioaddr) )
61 
62 #ifndef MULTI_ISA
63 #define MULTI_ISA 0
64 #else
65 #undef MULTI_ISA
66 #define MULTI_ISA 1
67 #endif
68 #endif /* AMIGA_PCMCIA */
69 
70 #ifdef CONFIG_ATARI_ROM_ISA
71 
72 #define enec_isa_read_base  0xfffa0000
73 #define enec_isa_write_base 0xfffb0000
74 
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))
79 
80 #ifndef MULTI_ISA
81 #define MULTI_ISA 0
82 #else
83 #undef MULTI_ISA
84 #define MULTI_ISA 1
85 #endif
86 #endif /* ATARI_ROM_ISA */
87 
88 
89 #if defined(CONFIG_ISA) || defined(CONFIG_ATARI_ROM_ISA)
90 
91 #if MULTI_ISA == 0
92 #undef MULTI_ISA
93 #endif
94 
95 #define ISA_TYPE_Q40  (1)
96 #define ISA_TYPE_AG   (2)
97 #define ISA_TYPE_ENEC (3)
98 
99 #if defined(CONFIG_Q40) && !defined(MULTI_ISA)
100 #define ISA_TYPE ISA_TYPE_Q40
101 #define ISA_SEX  0
102 #endif
103 #if defined(CONFIG_AMIGA_PCMCIA) && !defined(MULTI_ISA)
104 #define ISA_TYPE ISA_TYPE_AG
105 #define ISA_SEX  1
106 #endif
107 #if defined(CONFIG_ATARI_ROM_ISA) && !defined(MULTI_ISA)
108 #define ISA_TYPE ISA_TYPE_ENEC
109 #define ISA_SEX  0
110 #endif
111 
112 #ifdef MULTI_ISA
113 extern int isa_type;
114 extern int isa_sex;
115 
116 #define ISA_TYPE isa_type
117 #define ISA_SEX  isa_sex
118 #endif
119 
120 /*
121  * define inline addr translation functions. Normally only one variant will
122  * be compiled in so the case statement will be optimised away
123  */
124 
125 static inline u8 __iomem *isa_itb(unsigned long addr)
126 {
127   switch(ISA_TYPE)
128     {
129 #ifdef CONFIG_Q40
130     case ISA_TYPE_Q40: return (u8 __iomem *)Q40_ISA_IO_B(addr);
131 #endif
132 #ifdef CONFIG_AMIGA_PCMCIA
133     case ISA_TYPE_AG: return (u8 __iomem *)AG_ISA_IO_B(addr);
134 #endif
135 #ifdef CONFIG_ATARI_ROM_ISA
136     case ISA_TYPE_ENEC: return (u8 __iomem *)ENEC_ISA_IO_B(addr);
137 #endif
138     default: return NULL; /* avoid warnings, just in case */
139     }
140 }
141 static inline u16 __iomem *isa_itw(unsigned long addr)
142 {
143   switch(ISA_TYPE)
144     {
145 #ifdef CONFIG_Q40
146     case ISA_TYPE_Q40: return (u16 __iomem *)Q40_ISA_IO_W(addr);
147 #endif
148 #ifdef CONFIG_AMIGA_PCMCIA
149     case ISA_TYPE_AG: return (u16 __iomem *)AG_ISA_IO_W(addr);
150 #endif
151 #ifdef CONFIG_ATARI_ROM_ISA
152     case ISA_TYPE_ENEC: return (u16 __iomem *)ENEC_ISA_IO_W(addr);
153 #endif
154     default: return NULL; /* avoid warnings, just in case */
155     }
156 }
157 static inline u32 __iomem *isa_itl(unsigned long addr)
158 {
159   switch(ISA_TYPE)
160     {
161 #ifdef CONFIG_AMIGA_PCMCIA
162     case ISA_TYPE_AG: return (u32 __iomem *)AG_ISA_IO_W(addr);
163 #endif
164     default: return 0; /* avoid warnings, just in case */
165     }
166 }
167 static inline u8 __iomem *isa_mtb(unsigned long addr)
168 {
169   switch(ISA_TYPE)
170     {
171 #ifdef CONFIG_Q40
172     case ISA_TYPE_Q40: return (u8 __iomem *)Q40_ISA_MEM_B(addr);
173 #endif
174 #ifdef CONFIG_AMIGA_PCMCIA
175     case ISA_TYPE_AG: return (u8 __iomem *)addr;
176 #endif
177 #ifdef CONFIG_ATARI_ROM_ISA
178     case ISA_TYPE_ENEC: return (u8 __iomem *)ENEC_ISA_MEM_B(addr);
179 #endif
180     default: return NULL; /* avoid warnings, just in case */
181     }
182 }
183 static inline u16 __iomem *isa_mtw(unsigned long addr)
184 {
185   switch(ISA_TYPE)
186     {
187 #ifdef CONFIG_Q40
188     case ISA_TYPE_Q40: return (u16 __iomem *)Q40_ISA_MEM_W(addr);
189 #endif
190 #ifdef CONFIG_AMIGA_PCMCIA
191     case ISA_TYPE_AG: return (u16 __iomem *)addr;
192 #endif
193 #ifdef CONFIG_ATARI_ROM_ISA
194     case ISA_TYPE_ENEC: return (u16 __iomem *)ENEC_ISA_MEM_W(addr);
195 #endif
196     default: return NULL; /* avoid warnings, just in case */
197     }
198 }
199 
200 
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)))
207 
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)))
216 
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)))
222 
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)))
227 
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)))
236 
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 */
246 
247 static inline void isa_delay(void)
248 {
249   switch(ISA_TYPE)
250     {
251 #ifdef CONFIG_Q40
252     case ISA_TYPE_Q40: isa_outb(0,0x80); break;
253 #endif
254 #ifdef CONFIG_AMIGA_PCMCIA
255     case ISA_TYPE_AG: break;
256 #endif
257 #ifdef CONFIG_ATARI_ROM_ISA
258     case ISA_TYPE_ENEC: break;
259 #endif
260     default: break; /* avoid warnings */
261     }
262 }
263 
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();})
270 
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))
273 
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)))
277 
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)))
281 
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))
285 
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))
289 
290 
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(); })
296 
297 #define isa_rom_insb(port, buf, nr) raw_rom_insb(isa_itb(port), (u8 *)(buf), (nr))
298 
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)))
302 
303 #define isa_rom_outsb(port, buf, nr) raw_rom_outsb(isa_itb(port), (u8 *)(buf), (nr))
304 
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 */
309 
310 #endif  /* CONFIG_ISA || CONFIG_ATARI_ROM_ISA */
311 
312 
313 #if defined(CONFIG_ISA) && !defined(CONFIG_ATARI_ROM_ISA)
314 #define inb     isa_inb
315 #define inb_p   isa_inb_p
316 #define outb    isa_outb
317 #define outb_p  isa_outb_p
318 #define inw     isa_inw
319 #define inw_p   isa_inw_p
320 #define outw    isa_outw
321 #define outw_p  isa_outw_p
322 #define inl     isa_inl
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 */
337 
338 #ifdef CONFIG_ATARI_ROM_ISA
339 /*
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
343  * below.
344  */
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))
349 #define inl		isa_inl
350 #define inl_p		isa_inl_p
351 
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
358 
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
365 
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 */
371 
372 #define readl(addr)      in_le32(addr)
373 #define writel(val,addr) out_le32((addr),(val))
374 
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))
381 
382 #ifndef CONFIG_SUN3
383 #define IO_SPACE_LIMIT 0xffff
384 #else
385 #define IO_SPACE_LIMIT 0x0fffffff
386 #endif
387 
388 #endif /* __KERNEL__ */
389 
390 #define __ARCH_HAS_NO_PAGE_ZERO_MAPPED		1
391 
392 /*
393  * Convert a physical pointer to a virtual kernel pointer for /dev/mem
394  * access
395  */
396 #define xlate_dev_mem_ptr(p)	__va(p)
397 
398 #define readb_relaxed(addr)	readb(addr)
399 #define readw_relaxed(addr)	readw(addr)
400 #define readl_relaxed(addr)	readl(addr)
401 
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)
405 
406 #endif /* _M68K_IO_MM_H */
407