00001 #ifndef _ASM_IO_H
00002 #define _ASM_IO_H
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 #ifdef SLOW_IO_BY_JUMPING
00037 #define __SLOW_DOWN_IO __asm__ __volatile__("jmp 1f\n1:\tjmp 1f\n1:")
00038 #else
00039 #define __SLOW_DOWN_IO __asm__ __volatile__("outb %al,$0x80")
00040 #endif
00041
00042 #ifdef REALLY_SLOW_IO
00043 #define SLOW_DOWN_IO { __SLOW_DOWN_IO; __SLOW_DOWN_IO; __SLOW_DOWN_IO; __SLOW_DOWN_IO; }
00044 #else
00045 #define SLOW_DOWN_IO __SLOW_DOWN_IO
00046 #endif
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056 #define __OUT1(s,x) \
00057 extern inline void __out##s(unsigned x value, unsigned short port) {
00058
00059 #define __OUT2(s,s1,s2) \
00060 __asm__ __volatile__ ("out" #s " %" s1 "0,%" s2 "1"
00061
00062 #define __OUT(s,s1,x) \
00063 __OUT1(s,x) __OUT2(s,s1,"w") : : "a" (value), "d" (port)); } \
00064 __OUT1(s##c,x) __OUT2(s,s1,"") : : "a" (value), "i" (port)); } \
00065 __OUT1(s##_p,x) __OUT2(s,s1,"w") : : "a" (value), "d" (port)); SLOW_DOWN_IO; } \
00066 __OUT1(s##c_p,x) __OUT2(s,s1,"") : : "a" (value), "i" (port)); SLOW_DOWN_IO; }
00067
00068 #define __IN1(s) \
00069 extern inline unsigned int __in##s(unsigned short port) { unsigned int _v;
00070
00071 #define __IN2(s,s1,s2) \
00072 __asm__ __volatile__ ("in" #s " %" s2 "1,%" s1 "0"
00073
00074 #define __IN(s,s1,i...) \
00075 __IN1(s) __IN2(s,s1,"w") : "=a" (_v) : "d" (port) ,##i ); return _v; } \
00076 __IN1(s##c) __IN2(s,s1,"") : "=a" (_v) : "i" (port) ,##i ); return _v; } \
00077 __IN1(s##_p) __IN2(s,s1,"w") : "=a" (_v) : "d" (port) ,##i ); SLOW_DOWN_IO; return _v; } \
00078 __IN1(s##c_p) __IN2(s,s1,"") : "=a" (_v) : "i" (port) ,##i ); SLOW_DOWN_IO; return _v; }
00079
00080 #define __INS(s) \
00081 extern inline void ins##s(unsigned short port, void * addr, unsigned long count) \
00082 { __asm__ __volatile__ ("cld ; rep ; ins" #s \
00083 : "=D" (addr), "=c" (count) : "d" (port),"0" (addr),"1" (count)); }
00084
00085 #define __OUTS(s) \
00086 extern inline void outs##s(unsigned short port, const void * addr, unsigned long count) \
00087 { __asm__ __volatile__ ("cld ; rep ; outs" #s \
00088 : "=S" (addr), "=c" (count) : "d" (port),"0" (addr),"1" (count)); }
00089
00090 __IN(b,"b","0" (0))
00091 __IN(w,"w","0" (0))
00092 __IN(l,"")
00093
00094 __OUT(b,"b",char)
00095 __OUT(w,"w",short)
00096 __OUT(l,,int)
00097
00098 __INS(b)
00099 __INS(w)
00100 __INS(l)
00101
00102 __OUTS(b)
00103 __OUTS(w)
00104 __OUTS(l)
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115 #define outb(val,port) \
00116 ((__builtin_constant_p((port)) && (port) < 256) ? \
00117 __outbc((val),(port)) : \
00118 __outb((val),(port)))
00119
00120 #define inb(port) \
00121 ((__builtin_constant_p((port)) && (port) < 256) ? \
00122 __inbc(port) : \
00123 __inb(port))
00124
00125 #define outb_p(val,port) \
00126 ((__builtin_constant_p((port)) && (port) < 256) ? \
00127 __outbc_p((val),(port)) : \
00128 __outb_p((val),(port)))
00129
00130 #define inb_p(port) \
00131 ((__builtin_constant_p((port)) && (port) < 256) ? \
00132 __inbc_p(port) : \
00133 __inb_p(port))
00134
00135 #define outw(val,port) \
00136 ((__builtin_constant_p((port)) && (port) < 256) ? \
00137 __outwc((val),(port)) : \
00138 __outw((val),(port)))
00139
00140 #define inw(port) \
00141 ((__builtin_constant_p((port)) && (port) < 256) ? \
00142 __inwc(port) : \
00143 __inw(port))
00144
00145 #define outw_p(val,port) \
00146 ((__builtin_constant_p((port)) && (port) < 256) ? \
00147 __outwc_p((val),(port)) : \
00148 __outw_p((val),(port)))
00149
00150 #define inw_p(port) \
00151 ((__builtin_constant_p((port)) && (port) < 256) ? \
00152 __inwc_p(port) : \
00153 __inw_p(port))
00154
00155 #define outl(val,port) \
00156 ((__builtin_constant_p((port)) && (port) < 256) ? \
00157 __outlc((val),(port)) : \
00158 __outl((val),(port)))
00159
00160 #define inl(port) \
00161 ((__builtin_constant_p((port)) && (port) < 256) ? \
00162 __inlc(port) : \
00163 __inl(port))
00164
00165 #define outl_p(val,port) \
00166 ((__builtin_constant_p((port)) && (port) < 256) ? \
00167 __outlc_p((val),(port)) : \
00168 __outl_p((val),(port)))
00169
00170 #define inl_p(port) \
00171 ((__builtin_constant_p((port)) && (port) < 256) ? \
00172 __inlc_p(port) : \
00173 __inl_p(port))
00174
00175 #endif