Home | History | Annotate | Line # | Download | only in include
pio.h revision 1.7
      1 /*	$NetBSD: pio.h,v 1.7 2012/01/30 23:34:58 matt 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 _POWERPC_PIO_H_
     37 #define _POWERPC_PIO_H_
     38 /*
     39  * I/O macros.
     40  */
     41 
     42 static __inline void __outb(volatile uint8_t *a, uint8_t v);
     43 static __inline void __outw(volatile uint16_t *a, uint16_t v);
     44 static __inline void __outl(volatile uint32_t *a, uint32_t v);
     45 static __inline void __outwrb(volatile uint16_t *a, uint16_t v);
     46 static __inline void __outlrb(volatile uint32_t *a, uint32_t v);
     47 static __inline uint8_t __inb(volatile uint8_t *a);
     48 static __inline uint16_t __inw(volatile uint16_t *a);
     49 static __inline uint32_t __inl(volatile uint32_t *a);
     50 static __inline uint16_t __inwrb(volatile uint16_t *a);
     51 static __inline uint32_t __inlrb(volatile uint32_t *a);
     52 static __inline void __outsb(volatile uint8_t *, const uint8_t *, size_t);
     53 static __inline void __outsw(volatile uint16_t *, const uint16_t *, size_t);
     54 static __inline void __outsl(volatile uint32_t *, const uint32_t *, size_t);
     55 static __inline void __outswrb(volatile uint16_t *, const uint16_t *, size_t);
     56 static __inline void __outslrb(volatile uint32_t *, const uint32_t *, size_t);
     57 static __inline void __insb(volatile uint8_t *, uint8_t *, size_t);
     58 static __inline void __insw(volatile uint16_t *, uint16_t *, size_t);
     59 static __inline void __insl(volatile uint32_t *, uint32_t *, size_t);
     60 static __inline void __inswrb(volatile uint16_t *, uint16_t *, size_t);
     61 static __inline void __inslrb(volatile uint32_t *, uint32_t *, size_t);
     62 
     63 static __inline void
     64 __outb(volatile uint8_t *a, uint8_t v)
     65 {
     66 	*a = v;
     67 	__asm volatile("eieio; sync");
     68 }
     69 
     70 static __inline void
     71 __outw(volatile uint16_t *a, uint16_t v)
     72 {
     73 	*a = v;
     74 	__asm volatile("eieio; sync");
     75 }
     76 
     77 static __inline void
     78 __outl(volatile uint32_t *a, uint32_t v)
     79 {
     80 	*a = v;
     81 	__asm volatile("eieio; sync");
     82 }
     83 
     84 static __inline void
     85 __outwrb(volatile uint16_t *a, uint16_t v)
     86 {
     87 	__asm volatile("sthbrx %0, 0, %1" :: "r"(v), "r"(a));
     88 	__asm volatile("eieio; sync");
     89 }
     90 
     91 static __inline void
     92 __outlrb(volatile uint32_t *a, uint32_t v)
     93 {
     94 	__asm volatile("stwbrx %0, 0, %1" :: "r"(v), "r"(a));
     95 	__asm volatile("eieio; sync");
     96 }
     97 
     98 static __inline uint8_t
     99 __inb(volatile uint8_t *a)
    100 {
    101 	uint8_t _v_;
    102 
    103 	_v_ = *a;
    104 	__asm volatile("eieio; sync");
    105 	return _v_;
    106 }
    107 
    108 static __inline uint16_t
    109 __inw(volatile uint16_t *a)
    110 {
    111 	uint16_t _v_;
    112 
    113 	_v_ = *a;
    114 	__asm volatile("eieio; sync");
    115 	return _v_;
    116 }
    117 
    118 static __inline uint32_t
    119 __inl(volatile uint32_t *a)
    120 {
    121 	uint32_t _v_;
    122 
    123 	_v_ = *a;
    124 	__asm volatile("eieio; sync");
    125 	return _v_;
    126 }
    127 
    128 static __inline uint16_t
    129 __inwrb(volatile uint16_t *a)
    130 {
    131 	uint16_t _v_;
    132 
    133 	__asm volatile("lhbrx %0, 0, %1" : "=r"(_v_) : "r"(a));
    134 	__asm volatile("eieio; sync");
    135 	return _v_;
    136 }
    137 
    138 static __inline uint32_t
    139 __inlrb(volatile uint32_t *a)
    140 {
    141 	uint32_t _v_;
    142 
    143 	__asm volatile("lwbrx %0, 0, %1" : "=r"(_v_) : "r"(a));
    144 	__asm volatile("eieio; sync");
    145 	return _v_;
    146 }
    147 
    148 #define	outb(a,v)	(__outb((volatile uint8_t *)(a), v))
    149 #define	out8(a,v)	outb(a,v)
    150 #define	outw(a,v)	(__outw((volatile uint16_t *)(a), v))
    151 #define	out16(a,v)	outw(a,v)
    152 #define	outl(a,v)	(__outl((volatile uint32_t *)(a), v))
    153 #define	out32(a,v)	outl(a,v)
    154 #define	inb(a)		(__inb((volatile uint8_t *)(a)))
    155 #define	in8(a)		inb(a)
    156 #define	inw(a)		(__inw((volatile uint16_t *)(a)))
    157 #define	in16(a)		inw(a)
    158 #define	inl(a)		(__inl((volatile uint32_t *)(a)))
    159 #define	in32(a)		inl(a)
    160 
    161 #define	out8rb(a,v)	outb(a,v)
    162 #define	outwrb(a,v)	(__outwrb((volatile uint16_t *)(a), v))
    163 #define	out16rb(a,v)	outwrb(a,v)
    164 #define	outlrb(a,v)	(__outlrb((volatile uint32_t *)(a), v))
    165 #define	out32rb(a,v)	outlrb(a,v)
    166 #define	in8rb(a)	inb(a)
    167 #define	inwrb(a)	(__inwrb((volatile uint16_t *)(a)))
    168 #define	in16rb(a)	inwrb(a)
    169 #define	inlrb(a)	(__inlrb((volatile uint32_t *)(a)))
    170 #define	in32rb(a)	inlrb(a)
    171 
    172 
    173 static __inline void
    174 __outsb(volatile uint8_t *a, const uint8_t *s, size_t c)
    175 {
    176 	while (c--)
    177 		*a = *s++;
    178 	__asm volatile("eieio; sync");
    179 }
    180 
    181 static __inline void
    182 __outsw(volatile uint16_t *a, const uint16_t *s, size_t c)
    183 {
    184 	while (c--)
    185 		*a = *s++;
    186 	__asm volatile("eieio; sync");
    187 }
    188 
    189 static __inline void
    190 __outsl(volatile uint32_t *a, const uint32_t *s, size_t c)
    191 {
    192 	while (c--)
    193 		*a = *s++;
    194 	__asm volatile("eieio; sync");
    195 }
    196 
    197 static __inline void
    198 __outswrb(volatile uint16_t *a, const uint16_t *s, size_t c)
    199 {
    200 	while (c--)
    201 		__asm volatile("sthbrx %0, 0, %1" :: "r"(*s++), "r"(a));
    202 	__asm volatile("eieio; sync");
    203 }
    204 
    205 static __inline void
    206 __outslrb(volatile uint32_t *a, const uint32_t *s, size_t c)
    207 {
    208 	while (c--)
    209 		__asm volatile("stwbrx %0, 0, %1" :: "r"(*s++), "r"(a));
    210 	__asm volatile("eieio; sync");
    211 }
    212 
    213 static __inline void
    214 __insb(volatile uint8_t *a, uint8_t *d, size_t c)
    215 {
    216 	while (c--)
    217 		*d++ = *a;
    218 	__asm volatile("eieio; sync");
    219 }
    220 
    221 static __inline void
    222 __insw(volatile uint16_t *a, uint16_t *d, size_t c)
    223 {
    224 	while (c--)
    225 		*d++ = *a;
    226 	__asm volatile("eieio; sync");
    227 }
    228 
    229 static __inline void
    230 __insl(volatile uint32_t *a, uint32_t *d, size_t c)
    231 {
    232 	while (c--)
    233 		*d++ = *a;
    234 	__asm volatile("eieio; sync");
    235 }
    236 
    237 static __inline void
    238 __inswrb(volatile uint16_t *a, uint16_t *d, size_t c)
    239 {
    240 	while (c--)
    241 		__asm volatile("lhbrx %0, 0, %1" : "=r"(*d++) : "r"(a));
    242 	__asm volatile("eieio; sync");
    243 }
    244 
    245 static __inline void
    246 __inslrb(volatile uint32_t *a, uint32_t *d, size_t c)
    247 {
    248 	while (c--)
    249 		__asm volatile("lwbrx %0, 0, %1" : "=r"(*d++) : "r"(a));
    250 	__asm volatile("eieio; sync");
    251 }
    252 
    253 #define	outsb(a,s,c)	(__outsb((volatile uint8_t *)(a), s, c))
    254 #define	outs8(a,s,c)	outsb(a,s,c)
    255 #define	outsw(a,s,c)	(__outsw((volatile uint16_t *)(a), s, c))
    256 #define	outs16(a,s,c)	outsw(a,s,c)
    257 #define	outsl(a,s,c)	(__outsl((volatile uint32_t *)(a), s, c))
    258 #define	outs32(a,s,c)	outsl(a,s,c)
    259 #define	insb(a,d,c)	(__insb((volatile uint8_t *)(a), d, c))
    260 #define	ins8(a,d,c)	insb(a,d,c)
    261 #define	insw(a,d,c)	(__insw((volatile uint16_t *)(a), d, c))
    262 #define	ins16(a,d,c)	insw(a,d,c)
    263 #define	insl(a,d,c)	(__insl((volatile uint32_t *)(a), d, c))
    264 #define	ins32(a,d,c)	insl(a,d,c)
    265 
    266 #define	outs8rb(a,s,c)	outsb(a,s,c)
    267 #define	outswrb(a,s,c)	(__outswrb((volatile uint16_t *)(a), s, c))
    268 #define	outs16rb(a,s,c)	outswrb(a,s,c)
    269 #define	outslrb(a,s,c)	(__outslrb((volatile uint32_t *)(a), s, c))
    270 #define	outs32rb(a,s,c)	outslrb(a,s,c)
    271 #define	ins8rb(a,d,c)	insb(a,d,c)
    272 #define	inswrb(a,d,c)	(__inswrb((volatile uint16_t *)(a), d, c))
    273 #define	ins16rb(a,d,c)	inswrb(a,d,c)
    274 #define	inslrb(a,d,c)	(__inslrb((volatile uint32_t *)(a), d, c))
    275 #define	ins32rb(a,d,c)	inslrb(a,d,c)
    276 
    277 #endif /*_POWERPC_PIO_H_*/
    278