blob: 0fb3468000e719e0e7e5f58e97ae229a2e7a6378 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * linux/include/asm-m68k/io.h
3 *
4 * 4/1/00 RZ: - rewritten to avoid clashes between ISA/PCI and other
5 * IO access
6 * - added Q40 support
7 * - added skeleton for GG-II and Amiga PCMCIA
8 * 2/3/01 RZ: - moved a few more defs into raw_io.h
9 *
Adrian Bunk2171a192008-10-13 21:59:00 +020010 * inX/outX should not be used by any driver unless it does
11 * ISA access. Other drivers should use function defined in raw_io.h
Linus Torvalds1da177e2005-04-16 15:20:36 -070012 * or define its own macros on top of these.
13 *
Adrian Bunk2171a192008-10-13 21:59:00 +020014 * inX(),outX() are for ISA I/O
Linus Torvalds1da177e2005-04-16 15:20:36 -070015 * isa_readX(),isa_writeX() are for ISA memory
Linus Torvalds1da177e2005-04-16 15:20:36 -070016 */
17
18#ifndef _IO_H
19#define _IO_H
20
21#ifdef __KERNEL__
22
Al Viroad9ec4f2006-01-12 01:06:24 -080023#include <linux/compiler.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070024#include <asm/raw_io.h>
25#include <asm/virtconvert.h>
26
Al Virof9569e12007-07-20 04:32:58 +010027#include <asm-generic/iomap.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070028
29#ifdef CONFIG_ATARI
30#include <asm/atarihw.h>
31#endif
32
33
34/*
35 * IO/MEM definitions for various ISA bridges
36 */
37
38
39#ifdef CONFIG_Q40
40
41#define q40_isa_io_base 0xff400000
42#define q40_isa_mem_base 0xff800000
43
44#define Q40_ISA_IO_B(ioaddr) (q40_isa_io_base+1+4*((unsigned long)(ioaddr)))
45#define Q40_ISA_IO_W(ioaddr) (q40_isa_io_base+ 4*((unsigned long)(ioaddr)))
46#define Q40_ISA_MEM_B(madr) (q40_isa_mem_base+1+4*((unsigned long)(madr)))
47#define Q40_ISA_MEM_W(madr) (q40_isa_mem_base+ 4*((unsigned long)(madr)))
48
49#define MULTI_ISA 0
50#endif /* Q40 */
51
Linus Torvalds1da177e2005-04-16 15:20:36 -070052#ifdef CONFIG_AMIGA_PCMCIA
53#include <asm/amigayle.h>
54
55#define AG_ISA_IO_B(ioaddr) ( GAYLE_IO+(ioaddr)+(((ioaddr)&1)*GAYLE_ODD) )
56#define AG_ISA_IO_W(ioaddr) ( GAYLE_IO+(ioaddr) )
57
58#ifndef MULTI_ISA
59#define MULTI_ISA 0
60#else
61#undef MULTI_ISA
62#define MULTI_ISA 1
63#endif
64#endif /* AMIGA_PCMCIA */
65
66
67
68#ifdef CONFIG_ISA
69
70#if MULTI_ISA == 0
71#undef MULTI_ISA
72#endif
73
Geert Uytterhoeven52de1142008-05-18 20:47:21 +020074#define ISA_TYPE_Q40 (1)
Christian Dietrich808fa622010-08-04 14:41:34 +020075#define ISA_TYPE_AG (2)
Linus Torvalds1da177e2005-04-16 15:20:36 -070076
77#if defined(CONFIG_Q40) && !defined(MULTI_ISA)
Geert Uytterhoeven52de1142008-05-18 20:47:21 +020078#define ISA_TYPE ISA_TYPE_Q40
Linus Torvalds1da177e2005-04-16 15:20:36 -070079#define ISA_SEX 0
80#endif
81#if defined(CONFIG_AMIGA_PCMCIA) && !defined(MULTI_ISA)
Geert Uytterhoeven52de1142008-05-18 20:47:21 +020082#define ISA_TYPE ISA_TYPE_AG
Linus Torvalds1da177e2005-04-16 15:20:36 -070083#define ISA_SEX 1
84#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070085
86#ifdef MULTI_ISA
87extern int isa_type;
88extern int isa_sex;
89
90#define ISA_TYPE isa_type
91#define ISA_SEX isa_sex
92#endif
93
94/*
95 * define inline addr translation functions. Normally only one variant will
96 * be compiled in so the case statement will be optimised away
97 */
98
Al Viroad9ec4f2006-01-12 01:06:24 -080099static inline u8 __iomem *isa_itb(unsigned long addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100{
101 switch(ISA_TYPE)
102 {
103#ifdef CONFIG_Q40
Geert Uytterhoeven52de1142008-05-18 20:47:21 +0200104 case ISA_TYPE_Q40: return (u8 __iomem *)Q40_ISA_IO_B(addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106#ifdef CONFIG_AMIGA_PCMCIA
Geert Uytterhoeven52de1142008-05-18 20:47:21 +0200107 case ISA_TYPE_AG: return (u8 __iomem *)AG_ISA_IO_B(addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108#endif
Al Viroad9ec4f2006-01-12 01:06:24 -0800109 default: return NULL; /* avoid warnings, just in case */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110 }
111}
Al Viroad9ec4f2006-01-12 01:06:24 -0800112static inline u16 __iomem *isa_itw(unsigned long addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113{
114 switch(ISA_TYPE)
115 {
116#ifdef CONFIG_Q40
Geert Uytterhoeven52de1142008-05-18 20:47:21 +0200117 case ISA_TYPE_Q40: return (u16 __iomem *)Q40_ISA_IO_W(addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119#ifdef CONFIG_AMIGA_PCMCIA
Geert Uytterhoeven52de1142008-05-18 20:47:21 +0200120 case ISA_TYPE_AG: return (u16 __iomem *)AG_ISA_IO_W(addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121#endif
Al Viroad9ec4f2006-01-12 01:06:24 -0800122 default: return NULL; /* avoid warnings, just in case */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123 }
124}
Al Virof9569e12007-07-20 04:32:58 +0100125static inline u32 __iomem *isa_itl(unsigned long addr)
126{
127 switch(ISA_TYPE)
128 {
129#ifdef CONFIG_AMIGA_PCMCIA
Geert Uytterhoeven52de1142008-05-18 20:47:21 +0200130 case ISA_TYPE_AG: return (u32 __iomem *)AG_ISA_IO_W(addr);
Al Virof9569e12007-07-20 04:32:58 +0100131#endif
132 default: return 0; /* avoid warnings, just in case */
133 }
134}
Al Viroad9ec4f2006-01-12 01:06:24 -0800135static inline u8 __iomem *isa_mtb(unsigned long addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136{
137 switch(ISA_TYPE)
138 {
139#ifdef CONFIG_Q40
Geert Uytterhoeven52de1142008-05-18 20:47:21 +0200140 case ISA_TYPE_Q40: return (u8 __iomem *)Q40_ISA_MEM_B(addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142#ifdef CONFIG_AMIGA_PCMCIA
Geert Uytterhoeven52de1142008-05-18 20:47:21 +0200143 case ISA_TYPE_AG: return (u8 __iomem *)addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144#endif
Al Viroad9ec4f2006-01-12 01:06:24 -0800145 default: return NULL; /* avoid warnings, just in case */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146 }
147}
Al Viroad9ec4f2006-01-12 01:06:24 -0800148static inline u16 __iomem *isa_mtw(unsigned long addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149{
150 switch(ISA_TYPE)
151 {
152#ifdef CONFIG_Q40
Geert Uytterhoeven52de1142008-05-18 20:47:21 +0200153 case ISA_TYPE_Q40: return (u16 __iomem *)Q40_ISA_MEM_W(addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155#ifdef CONFIG_AMIGA_PCMCIA
Geert Uytterhoeven52de1142008-05-18 20:47:21 +0200156 case ISA_TYPE_AG: return (u16 __iomem *)addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157#endif
Al Viroad9ec4f2006-01-12 01:06:24 -0800158 default: return NULL; /* avoid warnings, just in case */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159 }
160}
161
162
163#define isa_inb(port) in_8(isa_itb(port))
164#define isa_inw(port) (ISA_SEX ? in_be16(isa_itw(port)) : in_le16(isa_itw(port)))
Al Virof9569e12007-07-20 04:32:58 +0100165#define isa_inl(port) (ISA_SEX ? in_be32(isa_itl(port)) : in_le32(isa_itl(port)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166#define isa_outb(val,port) out_8(isa_itb(port),(val))
167#define isa_outw(val,port) (ISA_SEX ? out_be16(isa_itw(port),(val)) : out_le16(isa_itw(port),(val)))
Al Virof9569e12007-07-20 04:32:58 +0100168#define isa_outl(val,port) (ISA_SEX ? out_be32(isa_itl(port),(val)) : out_le32(isa_itl(port),(val)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169
170#define isa_readb(p) in_8(isa_mtb((unsigned long)(p)))
171#define isa_readw(p) \
172 (ISA_SEX ? in_be16(isa_mtw((unsigned long)(p))) \
173 : in_le16(isa_mtw((unsigned long)(p))))
174#define isa_writeb(val,p) out_8(isa_mtb((unsigned long)(p)),(val))
175#define isa_writew(val,p) \
176 (ISA_SEX ? out_be16(isa_mtw((unsigned long)(p)),(val)) \
177 : out_le16(isa_mtw((unsigned long)(p)),(val)))
178
179static inline void isa_delay(void)
180{
181 switch(ISA_TYPE)
182 {
183#ifdef CONFIG_Q40
Geert Uytterhoeven52de1142008-05-18 20:47:21 +0200184 case ISA_TYPE_Q40: isa_outb(0,0x80); break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186#ifdef CONFIG_AMIGA_PCMCIA
Geert Uytterhoeven52de1142008-05-18 20:47:21 +0200187 case ISA_TYPE_AG: break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188#endif
189 default: break; /* avoid warnings */
190 }
191}
192
193#define isa_inb_p(p) ({u8 v=isa_inb(p);isa_delay();v;})
194#define isa_outb_p(v,p) ({isa_outb((v),(p));isa_delay();})
195#define isa_inw_p(p) ({u16 v=isa_inw(p);isa_delay();v;})
196#define isa_outw_p(v,p) ({isa_outw((v),(p));isa_delay();})
197#define isa_inl_p(p) ({u32 v=isa_inl(p);isa_delay();v;})
198#define isa_outl_p(v,p) ({isa_outl((v),(p));isa_delay();})
199
200#define isa_insb(port, buf, nr) raw_insb(isa_itb(port), (u8 *)(buf), (nr))
201#define isa_outsb(port, buf, nr) raw_outsb(isa_itb(port), (u8 *)(buf), (nr))
202
203#define isa_insw(port, buf, nr) \
204 (ISA_SEX ? raw_insw(isa_itw(port), (u16 *)(buf), (nr)) : \
205 raw_insw_swapw(isa_itw(port), (u16 *)(buf), (nr)))
206
207#define isa_outsw(port, buf, nr) \
208 (ISA_SEX ? raw_outsw(isa_itw(port), (u16 *)(buf), (nr)) : \
209 raw_outsw_swapw(isa_itw(port), (u16 *)(buf), (nr)))
Al Virof9569e12007-07-20 04:32:58 +0100210
211#define isa_insl(port, buf, nr) \
212 (ISA_SEX ? raw_insl(isa_itl(port), (u32 *)(buf), (nr)) : \
213 raw_insw_swapw(isa_itw(port), (u16 *)(buf), (nr)<<1))
214
215#define isa_outsl(port, buf, nr) \
216 (ISA_SEX ? raw_outsl(isa_itl(port), (u32 *)(buf), (nr)) : \
217 raw_outsw_swapw(isa_itw(port), (u16 *)(buf), (nr)<<1))
218
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220#define inb isa_inb
221#define inb_p isa_inb_p
222#define outb isa_outb
223#define outb_p isa_outb_p
224#define inw isa_inw
225#define inw_p isa_inw_p
226#define outw isa_outw
227#define outw_p isa_outw_p
Al Virof9569e12007-07-20 04:32:58 +0100228#define inl isa_inl
229#define inl_p isa_inl_p
230#define outl isa_outl
231#define outl_p isa_outl_p
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232#define insb isa_insb
233#define insw isa_insw
Al Virof9569e12007-07-20 04:32:58 +0100234#define insl isa_insl
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235#define outsb isa_outsb
236#define outsw isa_outsw
Al Virof9569e12007-07-20 04:32:58 +0100237#define outsl isa_outsl
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238#define readb isa_readb
239#define readw isa_readw
240#define writeb isa_writeb
241#define writew isa_writew
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242
Adrian Bunk2171a192008-10-13 21:59:00 +0200243#else /* CONFIG_ISA */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245/*
Al Virof9569e12007-07-20 04:32:58 +0100246 * We need to define dummy functions for GENERIC_IOMAP support.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247 */
Al Virof9569e12007-07-20 04:32:58 +0100248#define inb(port) 0xff
249#define inb_p(port) 0xff
250#define outb(val,port) ((void)0)
251#define outb_p(val,port) ((void)0)
252#define inw(port) 0xffff
Thorsten Glaser779b7e62010-10-03 18:48:51 +0000253#define inw_p(port) 0xffff
Al Virof9569e12007-07-20 04:32:58 +0100254#define outw(val,port) ((void)0)
Thorsten Glaser779b7e62010-10-03 18:48:51 +0000255#define outw_p(val,port) ((void)0)
Al Virof9569e12007-07-20 04:32:58 +0100256#define inl(port) 0xffffffffUL
Thorsten Glaser779b7e62010-10-03 18:48:51 +0000257#define inl_p(port) 0xffffffffUL
Al Virof9569e12007-07-20 04:32:58 +0100258#define outl(val,port) ((void)0)
Thorsten Glaser779b7e62010-10-03 18:48:51 +0000259#define outl_p(val,port) ((void)0)
Al Virof9569e12007-07-20 04:32:58 +0100260
261#define insb(port,buf,nr) ((void)0)
262#define outsb(port,buf,nr) ((void)0)
263#define insw(port,buf,nr) ((void)0)
264#define outsw(port,buf,nr) ((void)0)
265#define insl(port,buf,nr) ((void)0)
266#define outsl(port,buf,nr) ((void)0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267
268/*
269 * These should be valid on any ioremap()ed region
270 */
271#define readb(addr) in_8(addr)
272#define writeb(val,addr) out_8((addr),(val))
Al Virof9569e12007-07-20 04:32:58 +0100273#define readw(addr) in_le16(addr)
274#define writew(val,addr) out_le16((addr),(val))
Adrian Bunk2171a192008-10-13 21:59:00 +0200275
276#endif /* CONFIG_ISA */
277
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278#define readl(addr) in_le32(addr)
279#define writel(val,addr) out_le32((addr),(val))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280
281#define mmiowb()
282
Al Viroad9ec4f2006-01-12 01:06:24 -0800283static inline void __iomem *ioremap(unsigned long physaddr, unsigned long size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284{
285 return __ioremap(physaddr, size, IOMAP_NOCACHE_SER);
286}
Al Viroad9ec4f2006-01-12 01:06:24 -0800287static inline void __iomem *ioremap_nocache(unsigned long physaddr, unsigned long size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288{
289 return __ioremap(physaddr, size, IOMAP_NOCACHE_SER);
290}
Al Viroad9ec4f2006-01-12 01:06:24 -0800291static inline void __iomem *ioremap_writethrough(unsigned long physaddr,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292 unsigned long size)
293{
294 return __ioremap(physaddr, size, IOMAP_WRITETHROUGH);
295}
Al Viroad9ec4f2006-01-12 01:06:24 -0800296static inline void __iomem *ioremap_fullcache(unsigned long physaddr,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297 unsigned long size)
298{
299 return __ioremap(physaddr, size, IOMAP_FULL_CACHING);
300}
301
Al Virof9569e12007-07-20 04:32:58 +0100302static inline void memset_io(volatile void __iomem *addr, unsigned char val, int count)
303{
304 __builtin_memset((void __force *) addr, val, count);
305}
306static inline void memcpy_fromio(void *dst, const volatile void __iomem *src, int count)
307{
308 __builtin_memcpy(dst, (void __force *) src, count);
309}
310static inline void memcpy_toio(volatile void __iomem *dst, const void *src, int count)
311{
312 __builtin_memcpy((void __force *) dst, src, count);
313}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314
315#ifndef CONFIG_SUN3
316#define IO_SPACE_LIMIT 0xffff
317#else
318#define IO_SPACE_LIMIT 0x0fffffff
319#endif
320
321#endif /* __KERNEL__ */
322
323#define __ARCH_HAS_NO_PAGE_ZERO_MAPPED 1
324
325/*
326 * Convert a physical pointer to a virtual kernel pointer for /dev/mem
327 * access
328 */
329#define xlate_dev_mem_ptr(p) __va(p)
330
331/*
332 * Convert a virtual cached pointer to an uncached pointer
333 */
334#define xlate_dev_kmem_ptr(p) p
335
336#endif /* _IO_H */