blob: d8c503ccb32fd227367636f85fe049b8f6245dc1 [file] [log] [blame]
wdenk2262cfe2002-11-18 00:14:45 +00001#ifndef _ASM_IO_H
2#define _ASM_IO_H
3
4#include <linux/config.h>
5
6/*
7 * This file contains the definitions for the x86 IO instructions
8 * inb/inw/inl/outb/outw/outl and the "string versions" of the same
9 * (insb/insw/insl/outsb/outsw/outsl). You can also use "pausing"
10 * versions of the single-IO instructions (inb_p/inw_p/..).
11 *
12 * This file is not meant to be obfuscating: it's just complicated
13 * to (a) handle it all in a way that makes gcc able to optimize it
14 * as well as possible and (b) trying to avoid writing the same thing
15 * over and over again with slight variations and possibly making a
16 * mistake somewhere.
17 */
18
19/*
20 * Thanks to James van Artsdalen for a better timing-fix than
21 * the two short jumps: using outb's to a nonexistent port seems
22 * to guarantee better timings even on fast machines.
23 *
24 * On the other hand, I'd like to be sure of a non-existent port:
25 * I feel a bit unsafe about using 0x80 (should be safe, though)
26 *
27 * Linus
28 */
29
30 /*
31 * Bit simplified and optimized by Jan Hubicka
32 * Support of BIGMEM added by Gerhard Wichert, Siemens AG, July 1999.
33 *
34 * isa_memset_io, isa_memcpy_fromio, isa_memcpy_toio added,
35 * isa_read[wl] and isa_write[wl] fixed
36 * - Arnaldo Carvalho de Melo <acme@conectiva.com.br>
37 */
38
39#define IO_SPACE_LIMIT 0xffff
40
41
42#ifdef __KERNEL__
43
44
45/*
46 * readX/writeX() are used to access memory mapped devices. On some
47 * architectures the memory mapped IO stuff needs to be accessed
48 * differently. On the x86 architecture, we just read/write the
49 * memory location directly.
50 */
51
52#define readb(addr) (*(volatile unsigned char *) (addr))
53#define readw(addr) (*(volatile unsigned short *) (addr))
54#define readl(addr) (*(volatile unsigned int *) (addr))
55#define __raw_readb readb
56#define __raw_readw readw
57#define __raw_readl readl
58
59#define writeb(b,addr) (*(volatile unsigned char *) (addr) = (b))
60#define writew(b,addr) (*(volatile unsigned short *) (addr) = (b))
61#define writel(b,addr) (*(volatile unsigned int *) (addr) = (b))
62#define __raw_writeb writeb
63#define __raw_writew writew
64#define __raw_writel writel
65
66#define memset_io(a,b,c) memset((a),(b),(c))
67#define memcpy_fromio(a,b,c) memcpy((a),(b),(c))
68#define memcpy_toio(a,b,c) memcpy((a),(b),(c))
69
70/*
71 * ISA space is 'always mapped' on a typical x86 system, no need to
72 * explicitly ioremap() it. The fact that the ISA IO space is mapped
73 * to PAGE_OFFSET is pure coincidence - it does not mean ISA values
74 * are physical addresses. The following constant pointer can be
75 * used as the IO-area pointer (it can be iounmapped as well, so the
76 * analogy with PCI is quite large):
77 */
78#define isa_readb(a) readb((a))
79#define isa_readw(a) readw((a))
80#define isa_readl(a) readl((a))
81#define isa_writeb(b,a) writeb(b,(a))
82#define isa_writew(w,a) writew(w,(a))
83#define isa_writel(l,a) writel(l,(a))
84#define isa_memset_io(a,b,c) memset_io((a),(b),(c))
85#define isa_memcpy_fromio(a,b,c) memcpy_fromio((a),(b),(c))
86#define isa_memcpy_toio(a,b,c) memcpy_toio((a),(b),(c))
87
88
89
90static inline int check_signature(unsigned long io_addr,
91 const unsigned char *signature, int length)
92{
93 int retval = 0;
94 do {
95 if (readb(io_addr) != *signature)
96 goto out;
97 io_addr++;
98 signature++;
99 length--;
100 } while (length);
101 retval = 1;
102out:
103 return retval;
104}
105
106/**
107 * isa_check_signature - find BIOS signatures
108 * @io_addr: mmio address to check
109 * @signature: signature block
110 * @length: length of signature
111 *
112 * Perform a signature comparison with the ISA mmio address io_addr.
113 * Returns 1 on a match.
114 *
115 * This function is deprecated. New drivers should use ioremap and
116 * check_signature.
117 */
118
119
120static inline int isa_check_signature(unsigned long io_addr,
121 const unsigned char *signature, int length)
122{
123 int retval = 0;
124 do {
125 if (isa_readb(io_addr) != *signature)
126 goto out;
127 io_addr++;
128 signature++;
129 length--;
130 } while (length);
131 retval = 1;
132out:
133 return retval;
134}
135
136#endif /* __KERNEL__ */
137
138#ifdef SLOW_IO_BY_JUMPING
139#define __SLOW_DOWN_IO "\njmp 1f\n1:\tjmp 1f\n1:"
140#else
141#define __SLOW_DOWN_IO "\noutb %%al,$0x80"
142#endif
143
144#ifdef REALLY_SLOW_IO
145#define __FULL_SLOW_DOWN_IO __SLOW_DOWN_IO __SLOW_DOWN_IO __SLOW_DOWN_IO __SLOW_DOWN_IO
146#else
147#define __FULL_SLOW_DOWN_IO __SLOW_DOWN_IO
148#endif
149
150
151/*
152 * Talk about misusing macros..
153 */
154#define __OUT1(s,x) \
155static inline void out##s(unsigned x value, unsigned short port) {
156
157#define __OUT2(s,s1,s2) \
158__asm__ __volatile__ ("out" #s " %" s1 "0,%" s2 "1"
159
160
161#define __OUT(s,s1,x) \
162__OUT1(s,x) __OUT2(s,s1,"w") : : "a" (value), "Nd" (port)); } \
163__OUT1(s##_p,x) __OUT2(s,s1,"w") __FULL_SLOW_DOWN_IO : : "a" (value), "Nd" (port));}
164
165#define __IN1(s) \
166static inline RETURN_TYPE in##s(unsigned short port) { RETURN_TYPE _v;
167
168#define __IN2(s,s1,s2) \
169__asm__ __volatile__ ("in" #s " %" s2 "1,%" s1 "0"
170
171#define __IN(s,s1,i...) \
172__IN1(s) __IN2(s,s1,"w") : "=a" (_v) : "Nd" (port) ,##i ); return _v; } \
173__IN1(s##_p) __IN2(s,s1,"w") __FULL_SLOW_DOWN_IO : "=a" (_v) : "Nd" (port) ,##i ); return _v; }
174
175#define __INS(s) \
176static inline void ins##s(unsigned short port, void * addr, unsigned long count) \
177{ __asm__ __volatile__ ("rep ; ins" #s \
178: "=D" (addr), "=c" (count) : "d" (port),"0" (addr),"1" (count)); }
179
180#define __OUTS(s) \
181static inline void outs##s(unsigned short port, const void * addr, unsigned long count) \
182{ __asm__ __volatile__ ("rep ; outs" #s \
183: "=S" (addr), "=c" (count) : "d" (port),"0" (addr),"1" (count)); }
184
185#define RETURN_TYPE unsigned char
186__IN(b,"")
187#undef RETURN_TYPE
188#define RETURN_TYPE unsigned short
189__IN(w,"")
190#undef RETURN_TYPE
191#define RETURN_TYPE unsigned int
192__IN(l,"")
193#undef RETURN_TYPE
194
195__OUT(b,"b",char)
196__OUT(w,"w",short)
197__OUT(l,,int)
198
199__INS(b)
200__INS(w)
201__INS(l)
202
203__OUTS(b)
204__OUTS(w)
205__OUTS(l)
206
207#endif