Make HZ_TO_STD macro name lowercase.
[linux-2.6/linux-mips.git] / include / asm-i386 / io.h
blob7a4e9facc0d4b11e1dcd161c6314020da44cda53
1 #ifndef _ASM_IO_H
2 #define _ASM_IO_H
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/..).
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.
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.
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)
25 * Linus
29 * Bit simplified and optimized by Jan Hubicka
30 * Support of BIGMEM added by Gerhard Wichert, Siemens AG, July 1999.
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>
37 #ifdef SLOW_IO_BY_JUMPING
38 #define __SLOW_DOWN_IO "\njmp 1f\n1:\tjmp 1f\n1:"
39 #else
40 #define __SLOW_DOWN_IO "\noutb %%al,$0x80"
41 #endif
43 #ifdef REALLY_SLOW_IO
44 #define __FULL_SLOW_DOWN_IO __SLOW_DOWN_IO __SLOW_DOWN_IO __SLOW_DOWN_IO __SLOW_DOWN_IO
45 #else
46 #define __FULL_SLOW_DOWN_IO __SLOW_DOWN_IO
47 #endif
50 * Talk about misusing macros..
52 #define __OUT1(s,x) \
53 extern inline void out##s(unsigned x value, unsigned short port) {
55 #define __OUT2(s,s1,s2) \
56 __asm__ __volatile__ ("out" #s " %" s1 "0,%" s2 "1"
58 #define __OUT(s,s1,x) \
59 __OUT1(s,x) __OUT2(s,s1,"w") : : "a" (value), "Nd" (port)); } \
60 __OUT1(s##_p,x) __OUT2(s,s1,"w") __FULL_SLOW_DOWN_IO : : "a" (value), "Nd" (port));} \
62 #define __IN1(s) \
63 extern inline RETURN_TYPE in##s(unsigned short port) { RETURN_TYPE _v;
65 #define __IN2(s,s1,s2) \
66 __asm__ __volatile__ ("in" #s " %" s2 "1,%" s1 "0"
68 #define __IN(s,s1,i...) \
69 __IN1(s) __IN2(s,s1,"w") : "=a" (_v) : "Nd" (port) ,##i ); return _v; } \
70 __IN1(s##_p) __IN2(s,s1,"w") __FULL_SLOW_DOWN_IO : "=a" (_v) : "Nd" (port) ,##i ); return _v; } \
72 #define __INS(s) \
73 extern inline void ins##s(unsigned short port, void * addr, unsigned long count) \
74 { __asm__ __volatile__ ("rep ; ins" #s \
75 : "=D" (addr), "=c" (count) : "d" (port),"0" (addr),"1" (count)); }
77 #define __OUTS(s) \
78 extern inline void outs##s(unsigned short port, const void * addr, unsigned long count) \
79 { __asm__ __volatile__ ("rep ; outs" #s \
80 : "=S" (addr), "=c" (count) : "d" (port),"0" (addr),"1" (count)); }
82 #define RETURN_TYPE unsigned char
83 __IN(b,"")
84 #undef RETURN_TYPE
85 #define RETURN_TYPE unsigned short
86 __IN(w,"")
87 #undef RETURN_TYPE
88 #define RETURN_TYPE unsigned int
89 __IN(l,"")
90 #undef RETURN_TYPE
92 __OUT(b,"b",char)
93 __OUT(w,"w",short)
94 __OUT(l,,int)
96 __INS(b)
97 __INS(w)
98 __INS(l)
100 __OUTS(b)
101 __OUTS(w)
102 __OUTS(l)
104 #define IO_SPACE_LIMIT 0xffff
106 #ifdef __KERNEL__
108 #include <linux/vmalloc.h>
111 * Temporary debugging check to catch old code using
112 * unmapped ISA addresses. Will be removed in 2.4.
114 #if 1
115 extern void *__io_virt_debug(unsigned long x, const char *file, int line);
116 extern unsigned long __io_phys_debug(unsigned long x, const char *file, int line);
117 #define __io_virt(x) __io_virt_debug((unsigned long)(x), __FILE__, __LINE__)
118 //#define __io_phys(x) __io_phys_debug((unsigned long)(x), __FILE__, __LINE__)
119 #else
120 #define __io_virt(x) ((void *)(x))
121 //#define __io_phys(x) __pa(x)
122 #endif
125 * Change virtual addresses to physical addresses and vv.
126 * These are pretty trivial
128 extern inline unsigned long virt_to_phys(volatile void * address)
130 return __pa(address);
133 extern inline void * phys_to_virt(unsigned long address)
135 return __va(address);
138 extern void * __ioremap(unsigned long offset, unsigned long size, unsigned long flags);
140 extern inline void * ioremap (unsigned long offset, unsigned long size)
142 return __ioremap(offset, size, 0);
146 * This one maps high address device memory and turns off caching for that area.
147 * it's useful if some control registers are in such an area and write combining
148 * or read caching is not desirable:
150 extern inline void * ioremap_nocache (unsigned long offset, unsigned long size)
152 return __ioremap(offset, size, _PAGE_PCD);
155 extern void iounmap(void *addr);
158 * IO bus memory addresses are also 1:1 with the physical address
160 #define virt_to_bus virt_to_phys
161 #define bus_to_virt phys_to_virt
164 * readX/writeX() are used to access memory mapped devices. On some
165 * architectures the memory mapped IO stuff needs to be accessed
166 * differently. On the x86 architecture, we just read/write the
167 * memory location directly.
170 #define readb(addr) (*(volatile unsigned char *) __io_virt(addr))
171 #define readw(addr) (*(volatile unsigned short *) __io_virt(addr))
172 #define readl(addr) (*(volatile unsigned int *) __io_virt(addr))
173 #define __raw_readb readb
174 #define __raw_readw readw
175 #define __raw_readl readl
177 #define writeb(b,addr) (*(volatile unsigned char *) __io_virt(addr) = (b))
178 #define writew(b,addr) (*(volatile unsigned short *) __io_virt(addr) = (b))
179 #define writel(b,addr) (*(volatile unsigned int *) __io_virt(addr) = (b))
180 #define __raw_writeb writeb
181 #define __raw_writew writew
182 #define __raw_writel writel
184 #define memset_io(a,b,c) memset(__io_virt(a),(b),(c))
185 #define memcpy_fromio(a,b,c) memcpy((a),__io_virt(b),(c))
186 #define memcpy_toio(a,b,c) memcpy(__io_virt(a),(b),(c))
189 * ISA space is 'always mapped' on a typical x86 system, no need to
190 * explicitly ioremap() it. The fact that the ISA IO space is mapped
191 * to PAGE_OFFSET is pure coincidence - it does not mean ISA values
192 * are physical addresses. The following constant pointer can be
193 * used as the IO-area pointer (it can be iounmapped as well, so the
194 * analogy with PCI is quite large):
196 #define __ISA_IO_base ((char *)(PAGE_OFFSET))
198 #define isa_readb(a) readb(__ISA_IO_base + (a))
199 #define isa_readw(a) readw(__ISA_IO_base + (a))
200 #define isa_readl(a) readl(__ISA_IO_base + (a))
201 #define isa_writeb(b,a) writeb(b,__ISA_IO_base + (a))
202 #define isa_writew(w,a) writew(w,__ISA_IO_base + (a))
203 #define isa_writel(l,a) writel(l,__ISA_IO_base + (a))
204 #define isa_memset_io(a,b,c) memset_io(__ISA_IO_base + (a),(b),(c))
205 #define isa_memcpy_fromio(a,b,c) memcpy_fromio((a),__ISA_IO_base + (b),(c))
206 #define isa_memcpy_toio(a,b,c) memcpy_toio(__ISA_IO_base + (a),(b),(c))
210 * Again, i386 does not require mem IO specific function.
213 #define eth_io_copy_and_sum(a,b,c,d) eth_copy_and_sum((a),__io_virt(b),(c),(d))
214 #define isa_eth_io_copy_and_sum(a,b,c,d) eth_copy_and_sum((a),__io_virt(__ISA_IO_base + (b)),(c),(d))
216 static inline int check_signature(unsigned long io_addr,
217 const unsigned char *signature, int length)
219 int retval = 0;
220 do {
221 if (readb(io_addr) != *signature)
222 goto out;
223 io_addr++;
224 signature++;
225 length--;
226 } while (length);
227 retval = 1;
228 out:
229 return retval;
232 static inline int isa_check_signature(unsigned long io_addr,
233 const unsigned char *signature, int length)
235 int retval = 0;
236 do {
237 if (isa_readb(io_addr) != *signature)
238 goto out;
239 io_addr++;
240 signature++;
241 length--;
242 } while (length);
243 retval = 1;
244 out:
245 return retval;
248 /* Nothing to do */
250 #define dma_cache_inv(_start,_size) do { } while (0)
251 #define dma_cache_wback(_start,_size) do { } while (0)
252 #define dma_cache_wback_inv(_start,_size) do { } while (0)
254 #endif /* __KERNEL__ */
256 #endif