Home | History | Annotate | Line # | Download | only in include
pio.h revision 1.2
      1 /*	$NetBSD: pio.h,v 1.2 1997/11/27 10:18:51 sakamoto 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  * I/O macros.
     40  */
     41 
     42 static __inline void
     43 __outb(a,v)
     44 	volatile u_int8_t *a;
     45 	int v;
     46 {
     47 	*a = v;
     48 	__asm__ volatile("eieio; sync");
     49 }
     50 
     51 static __inline void
     52 __outw(a,v)
     53 	volatile u_int16_t *a;
     54 	u_int16_t v;
     55 {
     56 	*a = v;
     57 	__asm__ volatile("eieio; sync");
     58 }
     59 
     60 static __inline void
     61 __outl(a,v)
     62 	volatile u_int32_t *a;
     63 	int v;
     64 {
     65 	*a = v;
     66 	__asm__ volatile("eieio; sync");
     67 }
     68 
     69 static __inline void
     70 __outwrb(a,v)
     71 	volatile u_int16_t *a;
     72 	u_int16_t v;
     73 {
     74 	u_int32_t _p_ = (u_int32_t)a;
     75 
     76 	__asm__ volatile("sthbrx %0, 0, %1" :: "r"(v), "r"(_p_));
     77 	__asm__ volatile("eieio; sync");
     78 }
     79 
     80 static __inline void
     81 __outlrb(a,v)
     82 	volatile u_int32_t *a;
     83 	u_int32_t v;
     84 {
     85 	u_int32_t _p_ = (u_int32_t)a;
     86 
     87 	__asm__ volatile("stwbrx %0, 0, %1" :: "r"(v), "r"(_p_));
     88 	__asm__ volatile("eieio; sync");
     89 }
     90 
     91 static __inline u_int8_t
     92 __inb(a)
     93 	volatile u_int8_t *a;
     94 {
     95 	u_int8_t _v_;
     96 
     97 	_v_ = *a;
     98 	__asm__ volatile("eieio; sync");
     99 	return _v_;
    100 }
    101 
    102 static __inline u_int16_t
    103 __inw(a)
    104 	volatile u_int16_t *a;
    105 {
    106 	u_int16_t _v_;
    107 
    108 	_v_ = *a;
    109 	__asm__ volatile("eieio; sync");
    110 	return _v_;
    111 }
    112 
    113 static __inline u_int32_t
    114 __inl(a)
    115 	volatile u_int32_t *a;
    116 {
    117 	u_int32_t _v_;
    118 
    119 	_v_ = *a;
    120 	__asm__ volatile("eieio; sync");
    121 	return _v_;
    122 }
    123 
    124 static __inline u_int16_t
    125 __inwrb(a)
    126 	volatile u_int16_t *a;
    127 {
    128 	u_int16_t _v_;
    129 	u_int32_t _p_ = (u_int32_t)a;
    130 
    131 	__asm__ volatile("lhbrx %0, 0, %1" : "=r"(_v_) : "r"(_p_));
    132 	__asm__ volatile("eieio; sync");
    133 	return _v_;
    134 }
    135 
    136 static __inline u_int32_t
    137 __inlrb(a)
    138 	volatile u_int32_t *a;
    139 {
    140 	u_int32_t _v_;
    141 	u_int32_t _p_ = (u_int32_t)a;
    142 
    143 	__asm__ volatile("lwbrx %0, 0, %1" : "=r"(_v_) : "r"(_p_));
    144 	__asm__ volatile("eieio; sync");
    145 	return _v_;
    146 }
    147 
    148 
    149 #define	outb(a,v)	(__outb((volatile u_int8_t *)(a), v))
    150 #define	out8(a,v)	outb(a,v)
    151 #define	outw(a,v)	(__outw((volatile u_int16_t *)(a), v))
    152 #define	out16(a,v)	outw(a,v)
    153 #define	outl(a,v)	(__outl((volatile u_int32_t *)(a), v))
    154 #define	out32(a,v)	outl(a,v)
    155 #define	inb(a)		(__inb((volatile u_int8_t *)(a)))
    156 #define	in8(a)		inb(a)
    157 #define	inw(a)		(__inw((volatile u_int16_t *)(a)))
    158 #define	in16(a)		inw(a)
    159 #define	inl(a)		(__inl((volatile u_int32_t *)(a)))
    160 #define	in32(a)		inl(a)
    161 
    162 #define	out8rb(a,v)	outb(a,v)
    163 #define	outwrb(a,v)	(__outwrb((volatile u_int16_t *)(a), v))
    164 #define	out16rb(a,v)	outwrb(a,v)
    165 #define	outlrb(a,v)	(__outlrb((volatile u_int32_t *)(a), v))
    166 #define	out32rb(a,v)	outlrb(a,v)
    167 #define	in8rb(a)	inb(a)
    168 #define	inwrb(a)	(__inwrb((volatile u_int16_t *)(a)))
    169 #define	in16rb(a)	inwrb(a)
    170 #define	inlrb(a)	(__inlrb((volatile u_int32_t *)(a)))
    171 #define	in32rb(a)	inlrb(a)
    172 
    173 #endif /*_MACHINE_PIO_H_*/
    174