1 #ifndef _ASM_IO_H
2 #define _ASM_IO_H
3
4
5
6
7
8
9
10
11
12
13
14
15 #ifdef SLOW_IO_BY_JUMPING
16 #define __SLOW_DOWN_IO __asm__ __volatile__("jmp 1f\n1:\tjmp 1f\n1:")
17 #else
18 #define __SLOW_DOWN_IO __asm__ __volatile__("outb %al,$0x80")
19 #endif
20
21 #ifdef REALLY_SLOW_IO
22 #define SLOW_DOWN_IO { __SLOW_DOWN_IO; __SLOW_DOWN_IO; __SLOW_DOWN_IO; __SLOW_DOWN_IO; }
23 #else
24 #define SLOW_DOWN_IO __SLOW_DOWN_IO
25 #endif
26
27
28
29
30
31 #define __OUT1(s,x) \
32 extern inline void __out##s(unsigned x value, unsigned short port) {
33
34 #define __OUT2(s,s1,s2) \
35 __asm__ __volatile__ ("out" #s " %" s1 "0,%" s2 "1"
36
37 #define __OUT(s,s1,x) \
38 __OUT1(s,x) __OUT2(s,s1,"w") : : "a" (value), "d" (port)); } \
39 __OUT1(s##c,x) __OUT2(s,s1,"") : : "a" (value), "i" (port)); } \
40 __OUT1(s##_p,x) __OUT2(s,s1,"w") : : "a" (value), "d" (port)); SLOW_DOWN_IO; } \
41 __OUT1(s##c_p,x) __OUT2(s,s1,"") : : "a" (value), "i" (port)); SLOW_DOWN_IO; }
42
43 #define __IN1(s) \
44 extern inline unsigned int __in##s(unsigned short port) { unsigned int _v;
45
46 #define __IN2(s,s1,s2) \
47 __asm__ __volatile__ ("in" #s " %" s2 "1,%" s1 "0"
48
49 #define __IN(s,s1,i...) \
50 __IN1(s) __IN2(s,s1,"w") : "=a" (_v) : "d" (port) ,##i ); return _v; } \
51 __IN1(s##c) __IN2(s,s1,"") : "=a" (_v) : "i" (port) ,##i ); return _v; } \
52 __IN1(s##_p) __IN2(s,s1,"w") : "=a" (_v) : "d" (port) ,##i ); SLOW_DOWN_IO; return _v; } \
53 __IN1(s##c_p) __IN2(s,s1,"") : "=a" (_v) : "i" (port) ,##i ); SLOW_DOWN_IO; return _v; }
54
55 __IN(b,"b","0" (0))
56 __IN(w,"w","0" (0))
57 __IN(l,"")
58
59 __OUT(b,"b",char)
60 __OUT(w,"w",short)
61 __OUT(l,,int)
62
63
64
65
66
67
68 #define outb(val,port) \
69 ((__builtin_constant_p((port)) && (port) < 256) ? \
70 __outbc((val),(port)) : \
71 __outb((val),(port)))
72
73 #define inb(port) \
74 ((__builtin_constant_p((port)) && (port) < 256) ? \
75 __inbc(port) : \
76 __inb(port))
77
78 #define outb_p(val,port) \
79 ((__builtin_constant_p((port)) && (port) < 256) ? \
80 __outbc_p((val),(port)) : \
81 __outb_p((val),(port)))
82
83 #define inb_p(port) \
84 ((__builtin_constant_p((port)) && (port) < 256) ? \
85 __inbc_p(port) : \
86 __inb_p(port))
87
88 #define outw(val,port) \
89 ((__builtin_constant_p((port)) && (port) < 256) ? \
90 __outwc((val),(port)) : \
91 __outw((val),(port)))
92
93 #define inw(port) \
94 ((__builtin_constant_p((port)) && (port) < 256) ? \
95 __inwc(port) : \
96 __inw(port))
97
98 #define outw_p(val,port) \
99 ((__builtin_constant_p((port)) && (port) < 256) ? \
100 __outwc_p((val),(port)) : \
101 __outw_p((val),(port)))
102
103 #define inw_p(port) \
104 ((__builtin_constant_p((port)) && (port) < 256) ? \
105 __inwc_p(port) : \
106 __inw_p(port))
107
108 #define outl(val,port) \
109 ((__builtin_constant_p((port)) && (port) < 256) ? \
110 __outlc((val),(port)) : \
111 __outl((val),(port)))
112
113 #define inl(port) \
114 ((__builtin_constant_p((port)) && (port) < 256) ? \
115 __inlc(port) : \
116 __inl(port))
117
118 #define outl_p(val,port) \
119 ((__builtin_constant_p((port)) && (port) < 256) ? \
120 __outlc_p((val),(port)) : \
121 __outl_p((val),(port)))
122
123 #define inl_p(port) \
124 ((__builtin_constant_p((port)) && (port) < 256) ? \
125 __inlc_p(port) : \
126 __inl_p(port))
127
128 #endif