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
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)
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:"
36 #define __SLOW_DOWN_IO "\noutb %%al,$0x80"
40 #define __FULL_SLOW_DOWN_IO __SLOW_DOWN_IO __SLOW_DOWN_IO __SLOW_DOWN_IO __SLOW_DOWN_IO
42 #define __FULL_SLOW_DOWN_IO __SLOW_DOWN_IO
46 * Talk about misusing macros..
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));} \
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; } \
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)); }
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
81 #define RETURN_TYPE unsigned short
84 #define RETURN_TYPE unsigned int
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
)
115 return __pa(address
);
117 return __io_phys(address
);
121 extern inline void * phys_to_virt(unsigned long address
)
124 return __va(address
);
126 return __io_virt(address
);
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
)
191 if (readb(io_addr
) != *signature
)
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__ */