blob: dcfaa352d34c072fcee570059d5d29d62da4768b [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 *
10 * inX/outX/readX/writeX should not be used by any driver unless it does
11 * ISA or PCI access. Other drivers should use function defined in raw_io.h
12 * or define its own macros on top of these.
13 *
14 * inX(),outX() are for PCI and ISA I/O
15 * readX(),writeX() are for PCI memory
16 * isa_readX(),isa_writeX() are for ISA memory
17 *
18 * moved mem{cpy,set}_*io inside CONFIG_PCI
19 */
20
21#ifndef _IO_H
22#define _IO_H
23
24#ifdef __KERNEL__
25
26#include <linux/config.h>
Al Viroad9ec4f2006-01-12 01:06:24 -080027#include <linux/compiler.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070028#include <asm/raw_io.h>
29#include <asm/virtconvert.h>
30
31
32#ifdef CONFIG_ATARI
33#include <asm/atarihw.h>
34#endif
35
36
37/*
38 * IO/MEM definitions for various ISA bridges
39 */
40
41
42#ifdef CONFIG_Q40
43
44#define q40_isa_io_base 0xff400000
45#define q40_isa_mem_base 0xff800000
46
47#define Q40_ISA_IO_B(ioaddr) (q40_isa_io_base+1+4*((unsigned long)(ioaddr)))
48#define Q40_ISA_IO_W(ioaddr) (q40_isa_io_base+ 4*((unsigned long)(ioaddr)))
49#define Q40_ISA_MEM_B(madr) (q40_isa_mem_base+1+4*((unsigned long)(madr)))
50#define Q40_ISA_MEM_W(madr) (q40_isa_mem_base+ 4*((unsigned long)(madr)))
51
52#define MULTI_ISA 0
53#endif /* Q40 */
54
55/* GG-II Zorro to ISA bridge */
56#ifdef CONFIG_GG2
57
58extern unsigned long gg2_isa_base;
59#define GG2_ISA_IO_B(ioaddr) (gg2_isa_base+1+((unsigned long)(ioaddr)*4))
60#define GG2_ISA_IO_W(ioaddr) (gg2_isa_base+ ((unsigned long)(ioaddr)*4))
61#define GG2_ISA_MEM_B(madr) (gg2_isa_base+1+(((unsigned long)(madr)*4) & 0xfffff))
62#define GG2_ISA_MEM_W(madr) (gg2_isa_base+ (((unsigned long)(madr)*4) & 0xfffff))
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 /* GG2 */
71
72#ifdef CONFIG_AMIGA_PCMCIA
73#include <asm/amigayle.h>
74
75#define AG_ISA_IO_B(ioaddr) ( GAYLE_IO+(ioaddr)+(((ioaddr)&1)*GAYLE_ODD) )
76#define AG_ISA_IO_W(ioaddr) ( GAYLE_IO+(ioaddr) )
77
78#ifndef MULTI_ISA
79#define MULTI_ISA 0
80#else
81#undef MULTI_ISA
82#define MULTI_ISA 1
83#endif
84#endif /* AMIGA_PCMCIA */
85
86
87
88#ifdef CONFIG_ISA
89
90#if MULTI_ISA == 0
91#undef MULTI_ISA
92#endif
93
94#define Q40_ISA (1)
95#define GG2_ISA (2)
96#define AG_ISA (3)
97
98#if defined(CONFIG_Q40) && !defined(MULTI_ISA)
99#define ISA_TYPE Q40_ISA
100#define ISA_SEX 0
101#endif
102#if defined(CONFIG_AMIGA_PCMCIA) && !defined(MULTI_ISA)
103#define ISA_TYPE AG_ISA
104#define ISA_SEX 1
105#endif
106#if defined(CONFIG_GG2) && !defined(MULTI_ISA)
107#define ISA_TYPE GG2_ISA
108#define ISA_SEX 0
109#endif
110
111#ifdef MULTI_ISA
112extern int isa_type;
113extern int isa_sex;
114
115#define ISA_TYPE isa_type
116#define ISA_SEX isa_sex
117#endif
118
119/*
120 * define inline addr translation functions. Normally only one variant will
121 * be compiled in so the case statement will be optimised away
122 */
123
Al Viroad9ec4f2006-01-12 01:06:24 -0800124static inline u8 __iomem *isa_itb(unsigned long addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125{
126 switch(ISA_TYPE)
127 {
128#ifdef CONFIG_Q40
Al Viroad9ec4f2006-01-12 01:06:24 -0800129 case Q40_ISA: return (u8 __iomem *)Q40_ISA_IO_B(addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130#endif
131#ifdef CONFIG_GG2
Al Viroad9ec4f2006-01-12 01:06:24 -0800132 case GG2_ISA: return (u8 __iomem *)GG2_ISA_IO_B(addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133#endif
134#ifdef CONFIG_AMIGA_PCMCIA
Al Viroad9ec4f2006-01-12 01:06:24 -0800135 case AG_ISA: return (u8 __iomem *)AG_ISA_IO_B(addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136#endif
Al Viroad9ec4f2006-01-12 01:06:24 -0800137 default: return NULL; /* avoid warnings, just in case */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138 }
139}
Al Viroad9ec4f2006-01-12 01:06:24 -0800140static inline u16 __iomem *isa_itw(unsigned long addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141{
142 switch(ISA_TYPE)
143 {
144#ifdef CONFIG_Q40
Al Viroad9ec4f2006-01-12 01:06:24 -0800145 case Q40_ISA: return (u16 __iomem *)Q40_ISA_IO_W(addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146#endif
147#ifdef CONFIG_GG2
Al Viroad9ec4f2006-01-12 01:06:24 -0800148 case GG2_ISA: return (u16 __iomem *)GG2_ISA_IO_W(addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149#endif
150#ifdef CONFIG_AMIGA_PCMCIA
Al Viroad9ec4f2006-01-12 01:06:24 -0800151 case AG_ISA: return (u16 __iomem *)AG_ISA_IO_W(addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152#endif
Al Viroad9ec4f2006-01-12 01:06:24 -0800153 default: return NULL; /* avoid warnings, just in case */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154 }
155}
Al Viroad9ec4f2006-01-12 01:06:24 -0800156static inline u8 __iomem *isa_mtb(unsigned long addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157{
158 switch(ISA_TYPE)
159 {
160#ifdef CONFIG_Q40
Al Viroad9ec4f2006-01-12 01:06:24 -0800161 case Q40_ISA: return (u8 __iomem *)Q40_ISA_MEM_B(addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162#endif
163#ifdef CONFIG_GG2
Al Viroad9ec4f2006-01-12 01:06:24 -0800164 case GG2_ISA: return (u8 __iomem *)GG2_ISA_MEM_B(addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165#endif
166#ifdef CONFIG_AMIGA_PCMCIA
Al Viroad9ec4f2006-01-12 01:06:24 -0800167 case AG_ISA: return (u8 __iomem *)addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168#endif
Al Viroad9ec4f2006-01-12 01:06:24 -0800169 default: return NULL; /* avoid warnings, just in case */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170 }
171}
Al Viroad9ec4f2006-01-12 01:06:24 -0800172static inline u16 __iomem *isa_mtw(unsigned long addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173{
174 switch(ISA_TYPE)
175 {
176#ifdef CONFIG_Q40
Al Viroad9ec4f2006-01-12 01:06:24 -0800177 case Q40_ISA: return (u16 __iomem *)Q40_ISA_MEM_W(addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178#endif
179#ifdef CONFIG_GG2
Al Viroad9ec4f2006-01-12 01:06:24 -0800180 case GG2_ISA: return (u16 __iomem *)GG2_ISA_MEM_W(addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181#endif
182#ifdef CONFIG_AMIGA_PCMCIA
Al Viroad9ec4f2006-01-12 01:06:24 -0800183 case AG_ISA: return (u16 __iomem *)addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184#endif
Al Viroad9ec4f2006-01-12 01:06:24 -0800185 default: return NULL; /* avoid warnings, just in case */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186 }
187}
188
189
190#define isa_inb(port) in_8(isa_itb(port))
191#define isa_inw(port) (ISA_SEX ? in_be16(isa_itw(port)) : in_le16(isa_itw(port)))
192#define isa_outb(val,port) out_8(isa_itb(port),(val))
193#define isa_outw(val,port) (ISA_SEX ? out_be16(isa_itw(port),(val)) : out_le16(isa_itw(port),(val)))
194
195#define isa_readb(p) in_8(isa_mtb((unsigned long)(p)))
196#define isa_readw(p) \
197 (ISA_SEX ? in_be16(isa_mtw((unsigned long)(p))) \
198 : in_le16(isa_mtw((unsigned long)(p))))
199#define isa_writeb(val,p) out_8(isa_mtb((unsigned long)(p)),(val))
200#define isa_writew(val,p) \
201 (ISA_SEX ? out_be16(isa_mtw((unsigned long)(p)),(val)) \
202 : out_le16(isa_mtw((unsigned long)(p)),(val)))
203
204static inline void isa_delay(void)
205{
206 switch(ISA_TYPE)
207 {
208#ifdef CONFIG_Q40
209 case Q40_ISA: isa_outb(0,0x80); break;
210#endif
211#ifdef CONFIG_GG2
212 case GG2_ISA: break;
213#endif
214#ifdef CONFIG_AMIGA_PCMCIA
215 case AG_ISA: break;
216#endif
217 default: break; /* avoid warnings */
218 }
219}
220
221#define isa_inb_p(p) ({u8 v=isa_inb(p);isa_delay();v;})
222#define isa_outb_p(v,p) ({isa_outb((v),(p));isa_delay();})
223#define isa_inw_p(p) ({u16 v=isa_inw(p);isa_delay();v;})
224#define isa_outw_p(v,p) ({isa_outw((v),(p));isa_delay();})
225#define isa_inl_p(p) ({u32 v=isa_inl(p);isa_delay();v;})
226#define isa_outl_p(v,p) ({isa_outl((v),(p));isa_delay();})
227
228#define isa_insb(port, buf, nr) raw_insb(isa_itb(port), (u8 *)(buf), (nr))
229#define isa_outsb(port, buf, nr) raw_outsb(isa_itb(port), (u8 *)(buf), (nr))
230
231#define isa_insw(port, buf, nr) \
232 (ISA_SEX ? raw_insw(isa_itw(port), (u16 *)(buf), (nr)) : \
233 raw_insw_swapw(isa_itw(port), (u16 *)(buf), (nr)))
234
235#define isa_outsw(port, buf, nr) \
236 (ISA_SEX ? raw_outsw(isa_itw(port), (u16 *)(buf), (nr)) : \
237 raw_outsw_swapw(isa_itw(port), (u16 *)(buf), (nr)))
238#endif /* CONFIG_ISA */
239
240
241#if defined(CONFIG_ISA) && !defined(CONFIG_PCI)
242#define inb isa_inb
243#define inb_p isa_inb_p
244#define outb isa_outb
245#define outb_p isa_outb_p
246#define inw isa_inw
247#define inw_p isa_inw_p
248#define outw isa_outw
249#define outw_p isa_outw_p
250#define inl isa_inw
251#define inl_p isa_inw_p
252#define outl isa_outw
253#define outl_p isa_outw_p
254#define insb isa_insb
255#define insw isa_insw
256#define outsb isa_outsb
257#define outsw isa_outsw
258#define readb isa_readb
259#define readw isa_readw
260#define writeb isa_writeb
261#define writew isa_writew
262#endif /* CONFIG_ISA */
263
264#if defined(CONFIG_PCI)
265
266#define inl(port) in_le32(port)
267#define outl(val,port) out_le32((port),(val))
268#define readl(addr) in_le32(addr)
269#define writel(val,addr) out_le32((addr),(val))
270
271/* those can be defined for both ISA and PCI - it won't work though */
272#define readb(addr) in_8(addr)
273#define readw(addr) in_le16(addr)
274#define writeb(val,addr) out_8((addr),(val))
275#define writew(val,addr) out_le16((addr),(val))
276
277#define readb_relaxed(addr) readb(addr)
278#define readw_relaxed(addr) readw(addr)
279#define readl_relaxed(addr) readl(addr)
280
281#ifndef CONFIG_ISA
282#define inb(port) in_8(port)
283#define outb(val,port) out_8((port),(val))
284#define inw(port) in_le16(port)
285#define outw(val,port) out_le16((port),(val))
286
287#else
288/*
289 * kernel with both ISA and PCI compiled in, those have
290 * conflicting defs for in/out. Simply consider port < 1024
291 * ISA and everything else PCI. read,write not defined
292 * in this case
293 */
294#define inb(port) ((port)<1024 ? isa_inb(port) : in_8(port))
295#define inb_p(port) ((port)<1024 ? isa_inb_p(port) : in_8(port))
296#define inw(port) ((port)<1024 ? isa_inw(port) : in_le16(port))
297#define inw_p(port) ((port)<1024 ? isa_inw_p(port) : in_le16(port))
298#define inl(port) ((port)<1024 ? isa_inl(port) : in_le32(port))
299#define inl_p(port) ((port)<1024 ? isa_inl_p(port) : in_le32(port))
300
301#define outb(val,port) ((port)<1024 ? isa_outb((val),(port)) : out_8((port),(val)))
302#define outb_p(val,port) ((port)<1024 ? isa_outb_p((val),(port)) : out_8((port),(val)))
303#define outw(val,port) ((port)<1024 ? isa_outw((val),(port)) : out_le16((port),(val)))
304#define outw_p(val,port) ((port)<1024 ? isa_outw_p((val),(port)) : out_le16((port),(val)))
305#define outl(val,port) ((port)<1024 ? isa_outl((val),(port)) : out_le32((port),(val)))
306#define outl_p(val,port) ((port)<1024 ? isa_outl_p((val),(port)) : out_le32((port),(val)))
307#endif
308#endif /* CONFIG_PCI */
309
310#if !defined(CONFIG_ISA) && !defined(CONFIG_PCI) && defined(CONFIG_HP300)
311/*
312 * We need to define dummy functions otherwise drivers/serial/8250.c doesn't link
313 */
314#define inb(port) 0xff
315#define inb_p(port) 0xff
316#define outb(val,port) do { } while (0)
317#define outb_p(val,port) do { } while (0)
318
319/*
320 * These should be valid on any ioremap()ed region
321 */
322#define readb(addr) in_8(addr)
323#define writeb(val,addr) out_8((addr),(val))
324#define readl(addr) in_le32(addr)
325#define writel(val,addr) out_le32((addr),(val))
326#endif
327
328#define mmiowb()
329
Al Viroad9ec4f2006-01-12 01:06:24 -0800330static inline void __iomem *ioremap(unsigned long physaddr, unsigned long size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331{
332 return __ioremap(physaddr, size, IOMAP_NOCACHE_SER);
333}
Al Viroad9ec4f2006-01-12 01:06:24 -0800334static inline void __iomem *ioremap_nocache(unsigned long physaddr, unsigned long size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335{
336 return __ioremap(physaddr, size, IOMAP_NOCACHE_SER);
337}
Al Viroad9ec4f2006-01-12 01:06:24 -0800338static inline void __iomem *ioremap_writethrough(unsigned long physaddr,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339 unsigned long size)
340{
341 return __ioremap(physaddr, size, IOMAP_WRITETHROUGH);
342}
Al Viroad9ec4f2006-01-12 01:06:24 -0800343static inline void __iomem *ioremap_fullcache(unsigned long physaddr,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344 unsigned long size)
345{
346 return __ioremap(physaddr, size, IOMAP_FULL_CACHING);
347}
348
349
350/* m68k caches aren't DMA coherent */
351extern void dma_cache_wback_inv(unsigned long start, unsigned long size);
352extern void dma_cache_wback(unsigned long start, unsigned long size);
353extern void dma_cache_inv(unsigned long start, unsigned long size);
354
355
356#ifndef CONFIG_SUN3
357#define IO_SPACE_LIMIT 0xffff
358#else
359#define IO_SPACE_LIMIT 0x0fffffff
360#endif
361
362#endif /* __KERNEL__ */
363
364#define __ARCH_HAS_NO_PAGE_ZERO_MAPPED 1
365
366/*
367 * Convert a physical pointer to a virtual kernel pointer for /dev/mem
368 * access
369 */
370#define xlate_dev_mem_ptr(p) __va(p)
371
372/*
373 * Convert a virtual cached pointer to an uncached pointer
374 */
375#define xlate_dev_kmem_ptr(p) p
376
377#endif /* _IO_H */