1 /*- 2 * Copyright (c) 1997 Per Fogelstrom, Opsycon AB and RTMX Inc, USA. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 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. 18 * 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 29 * SUCH DAMAGE. 30 * 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 $ 33 * $FreeBSD$ 34 */ 35 36 #ifndef _MACHINE_PIO_H_ 37 #define _MACHINE_PIO_H_ 38 /* 39 * I/O macros. 40 */ 41 42 #define powerpc_iomb() __asm __volatile("eieio" : : : "memory") 43 44 static __inline void 45 __outb(volatile u_int8_t *a, u_int8_t v) 46 { 47 *a = v; 48 powerpc_iomb(); 49 } 50 51 static __inline void 52 __outw(volatile u_int16_t *a, u_int16_t v) 53 { 54 *a = v; 55 powerpc_iomb(); 56 } 57 58 static __inline void 59 __outl(volatile u_int32_t *a, u_int32_t v) 60 { 61 *a = v; 62 powerpc_iomb(); 63 } 64 65 static __inline void 66 __outll(volatile u_int64_t *a, u_int64_t v) 67 { 68 *a = v; 69 powerpc_iomb(); 70 } 71 72 static __inline void 73 __outwrb(volatile u_int16_t *a, u_int16_t v) 74 { 75 __asm__ volatile("sthbrx %0, 0, %1" :: "r"(v), "r"(a)); 76 powerpc_iomb(); 77 } 78 79 static __inline void 80 __outlrb(volatile u_int32_t *a, u_int32_t v) 81 { 82 __asm__ volatile("stwbrx %0, 0, %1" :: "r"(v), "r"(a)); 83 powerpc_iomb(); 84 } 85 86 static __inline u_int8_t 87 __inb(volatile u_int8_t *a) 88 { 89 u_int8_t _v_; 90 91 _v_ = *a; 92 powerpc_iomb(); 93 return _v_; 94 } 95 96 static __inline u_int16_t 97 __inw(volatile u_int16_t *a) 98 { 99 u_int16_t _v_; 100 101 _v_ = *a; 102 powerpc_iomb(); 103 return _v_; 104 } 105 106 static __inline u_int32_t 107 __inl(volatile u_int32_t *a) 108 { 109 u_int32_t _v_; 110 111 _v_ = *a; 112 powerpc_iomb(); 113 return _v_; 114 } 115 116 static __inline u_int64_t 117 __inll(volatile u_int64_t *a) 118 { 119 u_int64_t _v_; 120 121 _v_ = *a; 122 powerpc_iomb(); 123 return _v_; 124 } 125 126 static __inline u_int16_t 127 __inwrb(volatile u_int16_t *a) 128 { 129 u_int16_t _v_; 130 131 __asm__ volatile("lhbrx %0, 0, %1" : "=r"(_v_) : "r"(a)); 132 powerpc_iomb(); 133 return _v_; 134 } 135 136 static __inline u_int32_t 137 __inlrb(volatile u_int32_t *a) 138 { 139 u_int32_t _v_; 140 141 __asm__ volatile("lwbrx %0, 0, %1" : "=r"(_v_) : "r"(a)); 142 powerpc_iomb(); 143 return _v_; 144 } 145 146 #define outb(a,v) (__outb((volatile u_int8_t *)(a), v)) 147 #define out8(a,v) outb(a,v) 148 #define outw(a,v) (__outw((volatile u_int16_t *)(a), v)) 149 #define out16(a,v) outw(a,v) 150 #define outl(a,v) (__outl((volatile u_int32_t *)(a), v)) 151 #define out32(a,v) outl(a,v) 152 #define outll(a,v) (__outll((volatile u_int64_t *)(a), v)) 153 #define out64(a,v) outll(a,v) 154 #define inb(a) (__inb((volatile u_int8_t *)(a))) 155 #define in8(a) inb(a) 156 #define inw(a) (__inw((volatile u_int16_t *)(a))) 157 #define in16(a) inw(a) 158 #define inl(a) (__inl((volatile u_int32_t *)(a))) 159 #define in32(a) inl(a) 160 #define inll(a) (__inll((volatile u_int64_t *)(a))) 161 #define in64(a) inll(a) 162 163 #define out8rb(a,v) outb(a,v) 164 #define outwrb(a,v) (__outwrb((volatile u_int16_t *)(a), v)) 165 #define out16rb(a,v) outwrb(a,v) 166 #define outlrb(a,v) (__outlrb((volatile u_int32_t *)(a), v)) 167 #define out32rb(a,v) outlrb(a,v) 168 #define in8rb(a) inb(a) 169 #define inwrb(a) (__inwrb((volatile u_int16_t *)(a))) 170 #define in16rb(a) inwrb(a) 171 #define inlrb(a) (__inlrb((volatile u_int32_t *)(a))) 172 #define in32rb(a) inlrb(a) 173 174 175 static __inline void 176 __outsb(volatile u_int8_t *a, const u_int8_t *s, size_t c) 177 { 178 while (c--) 179 *a = *s++; 180 powerpc_iomb(); 181 } 182 183 static __inline void 184 __outsw(volatile u_int16_t *a, const u_int16_t *s, size_t c) 185 { 186 while (c--) 187 *a = *s++; 188 powerpc_iomb(); 189 } 190 191 static __inline void 192 __outsl(volatile u_int32_t *a, const u_int32_t *s, size_t c) 193 { 194 while (c--) 195 *a = *s++; 196 powerpc_iomb(); 197 } 198 199 static __inline void 200 __outsll(volatile u_int64_t *a, const u_int64_t *s, size_t c) 201 { 202 while (c--) 203 *a = *s++; 204 powerpc_iomb(); 205 } 206 207 static __inline void 208 __outswrb(volatile u_int16_t *a, const u_int16_t *s, size_t c) 209 { 210 while (c--) 211 __asm__ volatile("sthbrx %0, 0, %1" :: "r"(*s++), "r"(a)); 212 powerpc_iomb(); 213 } 214 215 static __inline void 216 __outslrb(volatile u_int32_t *a, const u_int32_t *s, size_t c) 217 { 218 while (c--) 219 __asm__ volatile("stwbrx %0, 0, %1" :: "r"(*s++), "r"(a)); 220 powerpc_iomb(); 221 } 222 223 static __inline void 224 __insb(volatile u_int8_t *a, u_int8_t *d, size_t c) 225 { 226 while (c--) 227 *d++ = *a; 228 powerpc_iomb(); 229 } 230 231 static __inline void 232 __insw(volatile u_int16_t *a, u_int16_t *d, size_t c) 233 { 234 while (c--) 235 *d++ = *a; 236 powerpc_iomb(); 237 } 238 239 static __inline void 240 __insl(volatile u_int32_t *a, u_int32_t *d, size_t c) 241 { 242 while (c--) 243 *d++ = *a; 244 powerpc_iomb(); 245 } 246 247 static __inline void 248 __insll(volatile u_int64_t *a, u_int64_t *d, size_t c) 249 { 250 while (c--) 251 *d++ = *a; 252 powerpc_iomb(); 253 } 254 255 static __inline void 256 __inswrb(volatile u_int16_t *a, u_int16_t *d, size_t c) 257 { 258 while (c--) 259 __asm__ volatile("lhbrx %0, 0, %1" : "=r"(*d++) : "r"(a)); 260 powerpc_iomb(); 261 } 262 263 static __inline void 264 __inslrb(volatile u_int32_t *a, u_int32_t *d, size_t c) 265 { 266 while (c--) 267 __asm__ volatile("lwbrx %0, 0, %1" : "=r"(*d++) : "r"(a)); 268 powerpc_iomb(); 269 } 270 271 #define outsb(a,s,c) (__outsb((volatile u_int8_t *)(a), s, c)) 272 #define outs8(a,s,c) outsb(a,s,c) 273 #define outsw(a,s,c) (__outsw((volatile u_int16_t *)(a), s, c)) 274 #define outs16(a,s,c) outsw(a,s,c) 275 #define outsl(a,s,c) (__outsl((volatile u_int32_t *)(a), s, c)) 276 #define outs32(a,s,c) outsl(a,s,c) 277 #define outsll(a,s,c) (__outsll((volatile u_int64_t *)(a), s, c)) 278 #define outs64(a,s,c) outsll(a,s,c) 279 #define insb(a,d,c) (__insb((volatile u_int8_t *)(a), d, c)) 280 #define ins8(a,d,c) insb(a,d,c) 281 #define insw(a,d,c) (__insw((volatile u_int16_t *)(a), d, c)) 282 #define ins16(a,d,c) insw(a,d,c) 283 #define insl(a,d,c) (__insl((volatile u_int32_t *)(a), d, c)) 284 #define ins32(a,d,c) insl(a,d,c) 285 #define insll(a,d,c) (__insll((volatile u_int64_t *)(a), d, c)) 286 #define ins64(a,d,c) insll(a,d,c) 287 288 #define outs8rb(a,s,c) outsb(a,s,c) 289 #define outswrb(a,s,c) (__outswrb((volatile u_int16_t *)(a), s, c)) 290 #define outs16rb(a,s,c) outswrb(a,s,c) 291 #define outslrb(a,s,c) (__outslrb((volatile u_int32_t *)(a), s, c)) 292 #define outs32rb(a,s,c) outslrb(a,s,c) 293 #define ins8rb(a,d,c) insb(a,d,c) 294 #define inswrb(a,d,c) (__inswrb((volatile u_int16_t *)(a), d, c)) 295 #define ins16rb(a,d,c) inswrb(a,d,c) 296 #define inslrb(a,d,c) (__inslrb((volatile u_int32_t *)(a), d, c)) 297 #define ins32rb(a,d,c) inslrb(a,d,c) 298 299 #endif /*_MACHINE_PIO_H_*/ 300