1#ifndef _ASM_IO_H
2#define _ASM_IO_H
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37#define IO_SPACE_LIMIT 0xffff
38
39
40#ifdef __KERNEL__
41
42
43
44
45
46
47
48
49
50#define readb(addr) (*(volatile unsigned char *) (addr))
51#define readw(addr) (*(volatile unsigned short *) (addr))
52#define readl(addr) (*(volatile unsigned int *) (addr))
53#define __raw_readb readb
54#define __raw_readw readw
55#define __raw_readl readl
56
57#define writeb(b,addr) (*(volatile unsigned char *) (addr) = (b))
58#define writew(b,addr) (*(volatile unsigned short *) (addr) = (b))
59#define writel(b,addr) (*(volatile unsigned int *) (addr) = (b))
60#define __raw_writeb writeb
61#define __raw_writew writew
62#define __raw_writel writel
63
64#define memset_io(a,b,c) memset((a),(b),(c))
65#define memcpy_fromio(a,b,c) memcpy((a),(b),(c))
66#define memcpy_toio(a,b,c) memcpy((a),(b),(c))
67
68
69
70
71
72
73
74
75
76#define isa_readb(a) readb((a))
77#define isa_readw(a) readw((a))
78#define isa_readl(a) readl((a))
79#define isa_writeb(b,a) writeb(b,(a))
80#define isa_writew(w,a) writew(w,(a))
81#define isa_writel(l,a) writel(l,(a))
82#define isa_memset_io(a,b,c) memset_io((a),(b),(c))
83#define isa_memcpy_fromio(a,b,c) memcpy_fromio((a),(b),(c))
84#define isa_memcpy_toio(a,b,c) memcpy_toio((a),(b),(c))
85
86
87static inline int check_signature(unsigned long io_addr,
88 const unsigned char *signature, int length)
89{
90 int retval = 0;
91 do {
92 if (readb(io_addr) != *signature)
93 goto out;
94 io_addr++;
95 signature++;
96 length--;
97 } while (length);
98 retval = 1;
99out:
100 return retval;
101}
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117static inline int isa_check_signature(unsigned long io_addr,
118 const unsigned char *signature, int length)
119{
120 int retval = 0;
121 do {
122 if (isa_readb(io_addr) != *signature)
123 goto out;
124 io_addr++;
125 signature++;
126 length--;
127 } while (length);
128 retval = 1;
129out:
130 return retval;
131}
132
133#endif
134
135#ifdef SLOW_IO_BY_JUMPING
136#define __SLOW_DOWN_IO "\njmp 1f\n1:\tjmp 1f\n1:"
137#else
138#define __SLOW_DOWN_IO "\noutb %%al,$0x80"
139#endif
140
141#ifdef REALLY_SLOW_IO
142#define __FULL_SLOW_DOWN_IO __SLOW_DOWN_IO __SLOW_DOWN_IO __SLOW_DOWN_IO __SLOW_DOWN_IO
143#else
144#define __FULL_SLOW_DOWN_IO __SLOW_DOWN_IO
145#endif
146
147
148
149
150
151#define __OUT1(s,x) \
152static inline void out##s(unsigned x value, unsigned short port) {
153
154#define __OUT2(s,s1,s2) \
155__asm__ __volatile__ ("out" #s " %" s1 "0,%" s2 "1"
156
157
158#define __OUT(s,s1,x) \
159__OUT1(s,x) __OUT2(s,s1,"w") : : "a" (value), "Nd" (port)); } \
160__OUT1(s##_p,x) __OUT2(s,s1,"w") __FULL_SLOW_DOWN_IO : : "a" (value), "Nd" (port));}
161
162#define __IN1(s) \
163static inline RETURN_TYPE in##s(unsigned short port) { RETURN_TYPE _v;
164
165#define __IN2(s,s1,s2) \
166__asm__ __volatile__ ("in" #s " %" s2 "1,%" s1 "0"
167
168#define __IN(s,s1,i...) \
169__IN1(s) __IN2(s,s1,"w") : "=a" (_v) : "Nd" (port) ,##i ); return _v; } \
170__IN1(s##_p) __IN2(s,s1,"w") __FULL_SLOW_DOWN_IO : "=a" (_v) : "Nd" (port) ,##i ); return _v; }
171
172#define __INS(s) \
173static inline void ins##s(unsigned short port, void * addr, unsigned long count) \
174{ __asm__ __volatile__ ("rep ; ins" #s \
175: "=D" (addr), "=c" (count) : "d" (port),"0" (addr),"1" (count)); }
176
177#define __OUTS(s) \
178static inline void outs##s(unsigned short port, const void * addr, unsigned long count) \
179{ __asm__ __volatile__ ("rep ; outs" #s \
180: "=S" (addr), "=c" (count) : "d" (port),"0" (addr),"1" (count)); }
181
182#define RETURN_TYPE unsigned char
183__IN(b,"")
184#undef RETURN_TYPE
185#define RETURN_TYPE unsigned short
186__IN(w,"")
187#undef RETURN_TYPE
188#define RETURN_TYPE unsigned int
189__IN(l,"")
190#undef RETURN_TYPE
191
192__OUT(b,"b",char)
193__OUT(w,"w",short)
194__OUT(l,,int)
195
196__INS(b)
197__INS(w)
198__INS(l)
199
200__OUTS(b)
201__OUTS(w)
202__OUTS(l)
203
204static inline void sync(void)
205{
206}
207
208
209
210
211
212
213#define MAP_NOCACHE (0)
214#define MAP_WRCOMBINE (0)
215#define MAP_WRBACK (0)
216#define MAP_WRTHROUGH (0)
217
218static inline void *
219map_physmem(phys_addr_t paddr, unsigned long len, unsigned long flags)
220{
221 return (void *)paddr;
222}
223
224
225
226
227static inline void unmap_physmem(void *vaddr, unsigned long flags)
228{
229
230}
231
232static inline phys_addr_t virt_to_phys(void * vaddr)
233{
234 return (phys_addr_t)(vaddr);
235}
236
237#endif
238