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