pio.h revision 1.1.6.2 1 /* $NetBSD: pio.h,v 1.1.6.2 2000/11/20 20:23:01 bouyer Exp $ */
2 /* $OpenBSD: pio.h,v 1.1 1997/10/13 10:53:47 pefo Exp $ */
3
4 /*
5 * Copyright (c) 1997 Per Fogelstrom, Opsycon AB and RTMX Inc, USA.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement:
17 * This product includes software developed under OpenBSD by
18 * Per Fogelstrom Opsycon AB for RTMX Inc, North Carolina, USA.
19 * 4. The name of the author may not be used to endorse or promote products
20 * derived from this software without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
23 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
24 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
26 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * SUCH DAMAGE.
33 *
34 */
35
36 #ifndef _MACHINE_PIO_H_
37 #define _MACHINE_PIO_H_
38
39 /*
40 * I/O macros.
41 */
42
43 static __inline void __outb __P((volatile u_int8_t *, u_int8_t));
44 static __inline void __outw __P((volatile u_int16_t *, u_int16_t));
45 static __inline void __outl __P((volatile u_int32_t *, u_int32_t));
46 static __inline void __outwrb __P((volatile u_int16_t *, u_int16_t));
47 static __inline void __outlrb __P((volatile u_int32_t *, u_int32_t));
48 static __inline u_int8_t __inb __P((volatile u_int8_t *));
49 static __inline u_int16_t __inw __P((volatile u_int16_t *));
50 static __inline u_int32_t __inl __P((volatile u_int32_t *));
51 static __inline u_int16_t __inwrb __P((volatile u_int16_t *));
52 static __inline u_int32_t __inlrb __P((volatile u_int32_t *));
53
54 static __inline void
55 __outb(a,v)
56 volatile u_int8_t *a;
57 u_int8_t v;
58 {
59 *a = v;
60 __asm__ volatile("eieio; sync");
61 }
62
63 static __inline void
64 __outw(a,v)
65 volatile u_int16_t *a;
66 u_int16_t v;
67 {
68 *a = v;
69 __asm__ volatile("eieio; sync");
70 }
71
72 static __inline void
73 __outl(a,v)
74 volatile u_int32_t *a;
75 u_int32_t v;
76 {
77 *a = v;
78 __asm__ volatile("eieio; sync");
79 }
80
81 static __inline void
82 __outwrb(a,v)
83 volatile u_int16_t *a;
84 u_int16_t v;
85 {
86 __asm__ volatile("sthbrx %0, 0, %1" :: "r"(v), "r"(a));
87 __asm__ volatile("eieio; sync");
88 }
89
90 static __inline void
91 __outlrb(a,v)
92 volatile u_int32_t *a;
93 u_int32_t v;
94 {
95 __asm__ volatile("stwbrx %0, 0, %1" :: "r"(v), "r"(a));
96 __asm__ volatile("eieio; sync");
97 }
98
99 static __inline u_int8_t
100 __inb(a)
101 volatile u_int8_t *a;
102 {
103 u_int8_t _v_;
104
105 _v_ = *a;
106 __asm__ volatile("eieio; sync");
107 return _v_;
108 }
109
110 static __inline u_int16_t
111 __inw(a)
112 volatile u_int16_t *a;
113 {
114 u_int16_t _v_;
115
116 _v_ = *a;
117 __asm__ volatile("eieio; sync");
118 return _v_;
119 }
120
121 static __inline u_int32_t
122 __inl(a)
123 volatile u_int32_t *a;
124 {
125 u_int32_t _v_;
126
127 _v_ = *a;
128 __asm__ volatile("eieio; sync");
129 return _v_;
130 }
131
132 static __inline u_int16_t
133 __inwrb(a)
134 volatile u_int16_t *a;
135 {
136 u_int16_t _v_;
137
138 __asm__ volatile("lhbrx %0, 0, %1" : "=r"(_v_) : "r"(a));
139 __asm__ volatile("eieio; sync");
140 return _v_;
141 }
142
143 static __inline u_int32_t
144 __inlrb(a)
145 volatile u_int32_t *a;
146 {
147 u_int32_t _v_;
148
149 __asm__ volatile("lwbrx %0, 0, %1" : "=r"(_v_) : "r"(a));
150 __asm__ volatile("eieio; sync");
151 return _v_;
152 }
153
154 #define outb(a,v) (__outb((volatile u_int8_t *)(a), v))
155 #define out8(a,v) outb(a,v)
156 #define outw(a,v) (__outw((volatile u_int16_t *)(a), v))
157 #define out16(a,v) outw(a,v)
158 #define outl(a,v) (__outl((volatile u_int32_t *)(a), v))
159 #define out32(a,v) outl(a,v)
160 #define inb(a) (__inb((volatile u_int8_t *)(a)))
161 #define in8(a) inb(a)
162 #define inw(a) (__inw((volatile u_int16_t *)(a)))
163 #define in16(a) inw(a)
164 #define inl(a) (__inl((volatile u_int32_t *)(a)))
165 #define in32(a) inl(a)
166
167 #define out8rb(a,v) outb(a,v)
168 #define outwrb(a,v) (__outwrb((volatile u_int16_t *)(a), v))
169 #define out16rb(a,v) outwrb(a,v)
170 #define outlrb(a,v) (__outlrb((volatile u_int32_t *)(a), v))
171 #define out32rb(a,v) outlrb(a,v)
172 #define in8rb(a) inb(a)
173 #define inwrb(a) (__inwrb((volatile u_int16_t *)(a)))
174 #define in16rb(a) inwrb(a)
175 #define inlrb(a) (__inlrb((volatile u_int32_t *)(a)))
176 #define in32rb(a) inlrb(a)
177
178
179 static __inline void __outsb __P((volatile u_int8_t *,
180 const u_int8_t *, size_t));
181 static __inline void __outsw __P((volatile u_int16_t *,
182 const u_int16_t *, size_t));
183 static __inline void __outsl __P((volatile u_int32_t *,
184 const u_int32_t *, size_t));
185 static __inline void __outswrb __P((volatile u_int16_t *,
186 const u_int16_t *, size_t));
187 static __inline void __outslrb __P((volatile u_int32_t *,
188 const u_int32_t *, size_t));
189 static __inline void __insb __P((volatile u_int8_t *, u_int8_t *, size_t));
190 static __inline void __insw __P((volatile u_int16_t *, u_int16_t *, size_t));
191 static __inline void __insl __P((volatile u_int32_t *, u_int32_t *, size_t));
192 static __inline void __inswrb __P((volatile u_int16_t *, u_int16_t *, size_t));
193 static __inline void __inslrb __P((volatile u_int32_t *, u_int32_t *, size_t));
194
195 static __inline void
196 __outsb(a,s,c)
197 volatile u_int8_t *a;
198 const u_int8_t *s;
199 size_t c;
200 {
201 while (c--)
202 *a = *s++;
203 __asm__ volatile("eieio; sync");
204 }
205
206 static __inline void
207 __outsw(a,s,c)
208 volatile u_int16_t *a;
209 const u_int16_t *s;
210 size_t c;
211 {
212 while (c--)
213 *a = *s++;
214 __asm__ volatile("eieio; sync");
215 }
216
217 static __inline void
218 __outsl(a,s,c)
219 volatile u_int32_t *a;
220 const u_int32_t *s;
221 size_t c;
222 {
223 while (c--)
224 *a = *s++;
225 __asm__ volatile("eieio; sync");
226 }
227
228 static __inline void
229 __outswrb(a,s,c)
230 volatile u_int16_t *a;
231 const u_int16_t *s;
232 size_t c;
233 {
234 while (c--)
235 __asm__ volatile("sthbrx %0, 0, %1" :: "r"(*s++), "r"(a));
236 __asm__ volatile("eieio; sync");
237 }
238
239 static __inline void
240 __outslrb(a,s,c)
241 volatile u_int32_t *a;
242 const u_int32_t *s;
243 size_t c;
244 {
245 while (c--)
246 __asm__ volatile("stwbrx %0, 0, %1" :: "r"(*s++), "r"(a));
247 __asm__ volatile("eieio; sync");
248 }
249
250 static __inline void
251 __insb(a,d,c)
252 volatile u_int8_t *a;
253 u_int8_t *d;
254 size_t c;
255 {
256 while (c--)
257 *d++ = *a;
258 __asm__ volatile("eieio; sync");
259 }
260
261 static __inline void
262 __insw(a,d,c)
263 volatile u_int16_t *a;
264 u_int16_t *d;
265 size_t c;
266 {
267 while (c--)
268 *d++ = *a;
269 __asm__ volatile("eieio; sync");
270 }
271
272 static __inline void
273 __insl(a,d,c)
274 volatile u_int32_t *a;
275 u_int32_t *d;
276 size_t c;
277 {
278 while (c--)
279 *d++ = *a;
280 __asm__ volatile("eieio; sync");
281 }
282
283 static __inline void
284 __inswrb(a,d,c)
285 volatile u_int16_t *a;
286 u_int16_t *d;
287 size_t c;
288 {
289 while (c--)
290 __asm__ volatile("lhbrx %0, 0, %1" : "=r"(*d++) : "r"(a));
291 __asm__ volatile("eieio; sync");
292 }
293
294 static __inline void
295 __inslrb(a,d,c)
296 volatile u_int32_t *a;
297 u_int32_t *d;
298 size_t c;
299 {
300 while (c--)
301 __asm__ volatile("lwbrx %0, 0, %1" : "=r"(*d++) : "r"(a));
302 __asm__ volatile("eieio; sync");
303 }
304
305 #define outsb(a,s,c) (__outsb((volatile u_int8_t *)(a), s, c))
306 #define outs8(a,s,c) outsb(a,s,c)
307 #define outsw(a,s,c) (__outsw((volatile u_int16_t *)(a), s, c))
308 #define outs16(a,s,c) outsw(a,s,c)
309 #define outsl(a,s,c) (__outsl((volatile u_int32_t *)(a), s, c))
310 #define outs32(a,s,c) outsl(a,s,c)
311 #define insb(a,d,c) (__insb((volatile u_int8_t *)(a), d, c))
312 #define ins8(a,d,c) insb(a,d,c)
313 #define insw(a,d,c) (__insw((volatile u_int16_t *)(a), d, c))
314 #define ins16(a,d,c) insw(a,d,c)
315 #define insl(a,d,c) (__insl((volatile u_int32_t *)(a), d, c))
316 #define ins32(a,d,c) insl(a,d,c)
317
318 #define outs8rb(a,s,c) outsb(a,s,c)
319 #define outswrb(a,s,c) (__outswrb((volatile u_int16_t *)(a), s, c))
320 #define outs16rb(a,s,c) outswrb(a,s,c)
321 #define outslrb(a,s,c) (__outslrb((volatile u_int32_t *)(a), s, c))
322 #define outs32rb(a,s,c) outslrb(a,s,c)
323 #define ins8rb(a,d,c) insb(a,d,c)
324 #define inswrb(a,d,c) (__inswrb((volatile u_int16_t *)(a), d, c))
325 #define ins16rb(a,d,c) inswrb(a,d,c)
326 #define inslrb(a,d,c) (__inslrb((volatile u_int32_t *)(a), d, c))
327 #define ins32rb(a,d,c) inslrb(a,d,c)
328
329 #endif /*_MACHINE_PIO_H_*/
330