2 * Copyright (c) 1997 Per Fogelstrom, Opsycon AB and RTMX Inc, USA.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * 3. All advertising materials mentioning features or use of this software
13 * must display the following acknowledgement:
14 * This product includes software developed under OpenBSD by
15 * Per Fogelstrom Opsycon AB for RTMX Inc, North Carolina, USA.
16 * 4. The name of the author may not be used to endorse or promote products
17 * derived from this software without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
20 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
23 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * $NetBSD: pio.h,v 1.1 1998/05/15 10:15:54 tsubai Exp $
32 * $OpenBSD: pio.h,v 1.1 1997/10/13 10:53:47 pefo Exp $
36 #ifndef _MACHINE_PIO_H_
37 #define _MACHINE_PIO_H_
43 __outb(volatile u_int8_t *a, u_int8_t v)
46 __asm__ volatile("eieio; sync");
50 __outw(volatile u_int16_t *a, u_int16_t v)
53 __asm__ volatile("eieio; sync");
57 __outl(volatile u_int32_t *a, u_int32_t v)
60 __asm__ volatile("eieio; sync");
64 __outwrb(volatile u_int16_t *a, u_int16_t v)
66 __asm__ volatile("sthbrx %0, 0, %1" :: "r"(v), "r"(a));
67 __asm__ volatile("eieio; sync");
71 __outlrb(volatile u_int32_t *a, u_int32_t v)
73 __asm__ volatile("stwbrx %0, 0, %1" :: "r"(v), "r"(a));
74 __asm__ volatile("eieio; sync");
77 static __inline u_int8_t
78 __inb(volatile u_int8_t *a)
83 __asm__ volatile("eieio; sync");
87 static __inline u_int16_t
88 __inw(volatile u_int16_t *a)
93 __asm__ volatile("eieio; sync");
97 static __inline u_int32_t
98 __inl(volatile u_int32_t *a)
103 __asm__ volatile("eieio; sync");
107 static __inline u_int16_t
108 __inwrb(volatile u_int16_t *a)
112 __asm__ volatile("lhbrx %0, 0, %1" : "=r"(_v_) : "r"(a));
113 __asm__ volatile("eieio; sync");
117 static __inline u_int32_t
118 __inlrb(volatile u_int32_t *a)
122 __asm__ volatile("lwbrx %0, 0, %1" : "=r"(_v_) : "r"(a));
123 __asm__ volatile("eieio; sync");
127 #define outb(a,v) (__outb((volatile u_int8_t *)(a), v))
128 #define out8(a,v) outb(a,v)
129 #define outw(a,v) (__outw((volatile u_int16_t *)(a), v))
130 #define out16(a,v) outw(a,v)
131 #define outl(a,v) (__outl((volatile u_int32_t *)(a), v))
132 #define out32(a,v) outl(a,v)
133 #define inb(a) (__inb((volatile u_int8_t *)(a)))
134 #define in8(a) inb(a)
135 #define inw(a) (__inw((volatile u_int16_t *)(a)))
136 #define in16(a) inw(a)
137 #define inl(a) (__inl((volatile u_int32_t *)(a)))
138 #define in32(a) inl(a)
140 #define out8rb(a,v) outb(a,v)
141 #define outwrb(a,v) (__outwrb((volatile u_int16_t *)(a), v))
142 #define out16rb(a,v) outwrb(a,v)
143 #define outlrb(a,v) (__outlrb((volatile u_int32_t *)(a), v))
144 #define out32rb(a,v) outlrb(a,v)
145 #define in8rb(a) inb(a)
146 #define inwrb(a) (__inwrb((volatile u_int16_t *)(a)))
147 #define in16rb(a) inwrb(a)
148 #define inlrb(a) (__inlrb((volatile u_int32_t *)(a)))
149 #define in32rb(a) inlrb(a)
153 __outsb(volatile u_int8_t *a, const u_int8_t *s, size_t c)
157 __asm__ volatile("eieio; sync");
161 __outsw(volatile u_int16_t *a, const u_int16_t *s, size_t c)
165 __asm__ volatile("eieio; sync");
169 __outsl(volatile u_int32_t *a, const u_int32_t *s, size_t c)
173 __asm__ volatile("eieio; sync");
177 __outswrb(volatile u_int16_t *a, const u_int16_t *s, size_t c)
180 __asm__ volatile("sthbrx %0, 0, %1" :: "r"(*s++), "r"(a));
181 __asm__ volatile("eieio; sync");
185 __outslrb(volatile u_int32_t *a, const u_int32_t *s, size_t c)
188 __asm__ volatile("stwbrx %0, 0, %1" :: "r"(*s++), "r"(a));
189 __asm__ volatile("eieio; sync");
193 __insb(volatile u_int8_t *a, u_int8_t *d, size_t c)
197 __asm__ volatile("eieio; sync");
201 __insw(volatile u_int16_t *a, u_int16_t *d, size_t c)
205 __asm__ volatile("eieio; sync");
209 __insl(volatile u_int32_t *a, u_int32_t *d, size_t c)
213 __asm__ volatile("eieio; sync");
217 __inswrb(volatile u_int16_t *a, u_int16_t *d, size_t c)
220 __asm__ volatile("lhbrx %0, 0, %1" : "=r"(*d++) : "r"(a));
221 __asm__ volatile("eieio; sync");
225 __inslrb(volatile u_int32_t *a, u_int32_t *d, size_t c)
228 __asm__ volatile("lwbrx %0, 0, %1" : "=r"(*d++) : "r"(a));
229 __asm__ volatile("eieio; sync");
232 #define outsb(a,s,c) (__outsb((volatile u_int8_t *)(a), s, c))
233 #define outs8(a,s,c) outsb(a,s,c)
234 #define outsw(a,s,c) (__outsw((volatile u_int16_t *)(a), s, c))
235 #define outs16(a,s,c) outsw(a,s,c)
236 #define outsl(a,s,c) (__outsl((volatile u_int32_t *)(a), s, c))
237 #define outs32(a,s,c) outsl(a,s,c)
238 #define insb(a,d,c) (__insb((volatile u_int8_t *)(a), d, c))
239 #define ins8(a,d,c) insb(a,d,c)
240 #define insw(a,d,c) (__insw((volatile u_int16_t *)(a), d, c))
241 #define ins16(a,d,c) insw(a,d,c)
242 #define insl(a,d,c) (__insl((volatile u_int32_t *)(a), d, c))
243 #define ins32(a,d,c) insl(a,d,c)
245 #define outs8rb(a,s,c) outsb(a,s,c)
246 #define outswrb(a,s,c) (__outswrb((volatile u_int16_t *)(a), s, c))
247 #define outs16rb(a,s,c) outswrb(a,s,c)
248 #define outslrb(a,s,c) (__outslrb((volatile u_int32_t *)(a), s, c))
249 #define outs32rb(a,s,c) outslrb(a,s,c)
250 #define ins8rb(a,d,c) insb(a,d,c)
251 #define inswrb(a,d,c) (__inswrb((volatile u_int16_t *)(a), d, c))
252 #define ins16rb(a,d,c) inswrb(a,d,c)
253 #define inslrb(a,d,c) (__inslrb((volatile u_int32_t *)(a), d, c))
254 #define ins32rb(a,d,c) inslrb(a,d,c)
256 #endif /*_MACHINE_PIO_H_*/