* added 0.99 linux version
[mascara-docs.git] / i386 / linux / linux-2.3.21 / include / asm-i386 / io.h
blob906fca475d8484f7b829af2f7fba288a162ffc29
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.
33 #ifdef SLOW_IO_BY_JUMPING
34 #define __SLOW_DOWN_IO "\njmp 1f\n1:\tjmp 1f\n1:"
35 #else
36 #define __SLOW_DOWN_IO "\noutb %%al,$0x80"
37 #endif
39 #ifdef REALLY_SLOW_IO
40 #define __FULL_SLOW_DOWN_IO __SLOW_DOWN_IO __SLOW_DOWN_IO __SLOW_DOWN_IO __SLOW_DOWN_IO
41 #else
42 #define __FULL_SLOW_DOWN_IO __SLOW_DOWN_IO
43 #endif
46 * Talk about misusing macros..
48 #define __OUT1(s,x) \
49 extern inline void out##s(unsigned x value, unsigned short port) {
51 #define __OUT2(s,s1,s2) \
52 __asm__ __volatile__ ("out" #s " %" s1 "0,%" s2 "1"
54 #define __OUT(s,s1,x) \
55 __OUT1(s,x) __OUT2(s,s1,"w") : : "a" (value), "Nd" (port)); } \
56 __OUT1(s##_p,x) __OUT2(s,s1,"w") __FULL_SLOW_DOWN_IO : : "a" (value), "Nd" (port));} \
58 #define __IN1(s) \
59 extern inline RETURN_TYPE in##s(unsigned short port) { RETURN_TYPE _v;
61 #define __IN2(s,s1,s2) \
62 __asm__ __volatile__ ("in" #s " %" s2 "1,%" s1 "0"
64 #define __IN(s,s1,i...) \
65 __IN1(s) __IN2(s,s1,"w") : "=a" (_v) : "Nd" (port) ,##i ); return _v; } \
66 __IN1(s##_p) __IN2(s,s1,"w") __FULL_SLOW_DOWN_IO : "=a" (_v) : "Nd" (port) ,##i ); return _v; } \
68 #define __INS(s) \
69 extern inline void ins##s(unsigned short port, void * addr, unsigned long count) \
70 { __asm__ __volatile__ ("cld ; rep ; ins" #s \
71 : "=D" (addr), "=c" (count) : "d" (port),"0" (addr),"1" (count)); }
73 #define __OUTS(s) \
74 extern inline void outs##s(unsigned short port, const void * addr, unsigned long count) \
75 { __asm__ __volatile__ ("cld ; rep ; outs" #s \
76 : "=S" (addr), "=c" (count) : "d" (port),"0" (addr),"1" (count)); }
78 #define RETURN_TYPE unsigned char
79 __IN(b,"")
80 #undef RETURN_TYPE
81 #define RETURN_TYPE unsigned short
82 __IN(w,"")
83 #undef RETURN_TYPE
84 #define RETURN_TYPE unsigned int
85 __IN(l,"")
86 #undef RETURN_TYPE
88 __OUT(b,"b",char)
89 __OUT(w,"w",short)
90 __OUT(l,,int)
92 __INS(b)
93 __INS(w)
94 __INS(l)
96 __OUTS(b)
97 __OUTS(w)
98 __OUTS(l)
100 #ifdef __KERNEL__
102 #include <linux/config.h>
103 #include <linux/vmalloc.h>
104 #include <asm/page.h>
106 #define __io_virt(x) ((void *)(PAGE_OFFSET | (unsigned long)(x)))
107 #define __io_phys(x) ((unsigned long)(x) & ~PAGE_OFFSET)
109 * Change virtual addresses to physical addresses and vv.
110 * These are pretty trivial
112 extern inline unsigned long virt_to_phys(volatile void * address)
114 #ifdef CONFIG_BIGMEM
115 return __pa(address);
116 #else
117 return __io_phys(address);
118 #endif
121 extern inline void * phys_to_virt(unsigned long address)
123 #ifdef CONFIG_BIGMEM
124 return __va(address);
125 #else
126 return __io_virt(address);
127 #endif
130 extern void * __ioremap(unsigned long offset, unsigned long size, unsigned long flags);
132 extern inline void * ioremap (unsigned long offset, unsigned long size)
134 return __ioremap(offset, size, 0);
138 * This one maps high address device memory and turns off caching for that area.
139 * it's useful if some control registers are in such an area and write combining
140 * or read caching is not desirable:
142 extern inline void * ioremap_nocache (unsigned long offset, unsigned long size)
144 return __ioremap(offset, size, _PAGE_PCD);
147 extern void iounmap(void *addr);
150 * IO bus memory addresses are also 1:1 with the physical address
152 #define virt_to_bus virt_to_phys
153 #define bus_to_virt phys_to_virt
156 * readX/writeX() are used to access memory mapped devices. On some
157 * architectures the memory mapped IO stuff needs to be accessed
158 * differently. On the x86 architecture, we just read/write the
159 * memory location directly.
162 #define readb(addr) (*(volatile unsigned char *) __io_virt(addr))
163 #define readw(addr) (*(volatile unsigned short *) __io_virt(addr))
164 #define readl(addr) (*(volatile unsigned int *) __io_virt(addr))
165 #define __raw_readb readb
166 #define __raw_readw readw
167 #define __raw_readl readl
169 #define writeb(b,addr) (*(volatile unsigned char *) __io_virt(addr) = (b))
170 #define writew(b,addr) (*(volatile unsigned short *) __io_virt(addr) = (b))
171 #define writel(b,addr) (*(volatile unsigned int *) __io_virt(addr) = (b))
172 #define __raw_writeb writeb
173 #define __raw_writew writew
174 #define __raw_writel writel
176 #define memset_io(a,b,c) memset(__io_virt(a),(b),(c))
177 #define memcpy_fromio(a,b,c) memcpy((a),__io_virt(b),(c))
178 #define memcpy_toio(a,b,c) memcpy(__io_virt(a),(b),(c))
181 * Again, i386 does not require mem IO specific function.
184 #define eth_io_copy_and_sum(a,b,c,d) eth_copy_and_sum((a),__io_virt(b),(c),(d))
186 static inline int check_signature(unsigned long io_addr,
187 const unsigned char *signature, int length)
189 int retval = 0;
190 do {
191 if (readb(io_addr) != *signature)
192 goto out;
193 io_addr++;
194 signature++;
195 length--;
196 } while (length);
197 retval = 1;
198 out:
199 return retval;
202 /* Nothing to do */
204 #define dma_cache_inv(_start,_size) do { } while (0)
205 #define dma_cache_wback(_start,_size) do { } while (0)
206 #define dma_cache_wback_inv(_start,_size) do { } while (0)
208 #endif /* __KERNEL__ */
210 #endif