| 1 | /*	$OpenBSD: pio.h,v 1.9 2002/09/15 09:01:59 deraadt Exp $ */ |
| 2 | |
| 3 | /* |
| 4 | * Copyright (c) 1997 Per Fogelstrom, Opsycon AB and RTMX Inc, USA. |
| 5 | * |
| 6 | * Redistribution and use in source and binary forms, with or without |
| 7 | * modification, are permitted provided that the following conditions |
| 8 | * are met: |
| 9 | * 1. Redistributions of source code must retain the above copyright |
| 10 | * notice, this list of conditions and the following disclaimer. |
| 11 | * 2. Redistributions in binary form must reproduce the above copyright |
| 12 | * notice, this list of conditions and the following disclaimer in the |
| 13 | * documentation and/or other materials provided with the distribution. |
| 14 | * 3. All advertising materials mentioning features or use of this software |
| 15 | * must display the following acknowledgement: |
| 16 | *	This product includes software developed under OpenBSD by |
| 17 | *	Per Fogelstrom Opsycon AB for RTMX Inc, North Carolina, USA. |
| 18 | * 4. The name of the author may not be used to endorse or promote products |
| 19 | * derived from this software without specific prior written permission. |
| 20 | * |
| 21 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS |
| 22 | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 23 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY |
| 25 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 26 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
| 27 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 28 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
| 29 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
| 30 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 31 | * SUCH DAMAGE. |
| 32 | * |
| 33 | */ |
| 34 | |
| 35 | #ifndef _POWERPC_PIO_H_ |
| 36 | #define _POWERPC_PIO_H_ |
| 37 | /* |
| 38 | * I/O macros. |
| 39 | */ |
| 40 | void *mapiodev(paddr_t pa, psize_t len); |
| 41 | void unmapiodev(void * va, psize_t len); |
| 42 | |
| 43 | static __inline void |
| 44 | __outb(volatile u_int8_t *a, int v) |
| 45 | { |
| 46 | 	*a = v; |
| 47 | 	__asm__ volatile("eieio"); |
| 48 | } |
| 49 | |
| 50 | static __inline void |
| 51 | __outw(volatile u_int16_t *a, u_int16_t v) |
| 52 | { |
| 53 | 	*a = v; |
| 54 | 	__asm__ volatile("eieio"); |
| 55 | } |
| 56 | |
| 57 | static __inline void |
| 58 | __outl(volatile u_int32_t *a, int v) |
| 59 | { |
| 60 | 	*a = v; |
| 61 | 	__asm__ volatile("eieio"); |
| 62 | } |
| 63 | |
| 64 | static __inline void |
| 65 | __outwrb(volatile u_int16_t *a, u_int16_t v) |
| 66 | { |
| 67 | 	u_int32_t _p_ = (u_int32_t)a; |
| 68 | |
| 69 | 	__asm__ volatile("sthbrx %0, 0, %1" :: "r"(v), "r"(_p_)); |
| 70 | 	__asm__ volatile("eieio"); |
| 71 | } |
| 72 | |
| 73 | static __inline void |
| 74 | __outlrb(volatile u_int32_t *a, u_int32_t v) |
| 75 | { |
| 76 | 	u_int32_t _p_ = (u_int32_t)a; |
| 77 | |
| 78 | 	__asm__ volatile("stwbrx %0, 0, %1" :: "r"(v), "r"(_p_)); |
| 79 | 	__asm__ volatile("eieio"); |
| 80 | } |
| 81 | |
| 82 | static __inline u_int8_t |
| 83 | __inb(volatile u_int8_t *a) |
| 84 | { |
| 85 | 	u_int8_t _v_; |
| 86 | |
| 87 | 	__asm__ volatile("eieio"); |
| 88 | 	_v_ = *a; |
| 89 | 	return _v_; |
| 90 | } |
| 91 | |
| 92 | static __inline u_int16_t |
| 93 | __inw(volatile u_int16_t *a) |
| 94 | { |
| 95 | 	u_int16_t _v_; |
| 96 | |
| 97 | 	__asm__ volatile("eieio"); |
| 98 | 	_v_ = *a; |
| 99 | 	return _v_; |
| 100 | } |
| 101 | |
| 102 | static __inline u_int32_t |
| 103 | __inl(volatile u_int32_t *a) |
| 104 | { |
| 105 | 	u_int32_t _v_; |
| 106 | |
| 107 | 	__asm__ volatile("eieio"); |
| 108 | 	_v_ = *a; |
| 109 | 	return _v_; |
| 110 | } |
| 111 | |
| 112 | static __inline u_int16_t |
| 113 | __inwrb(volatile u_int16_t *a) |
| 114 | { |
| 115 | 	u_int16_t _v_; |
| 116 | 	u_int32_t _p_ = (u_int32_t)a; |
| 117 | |
| 118 | 	__asm__ volatile("eieio"); |
| 119 | 	__asm__ volatile("lhbrx %0, 0, %1" : "=r"(_v_) : "r"(_p_)); |
| 120 | 	return _v_; |
| 121 | } |
| 122 | |
| 123 | static __inline u_int32_t |
| 124 | __inlrb(volatile u_int32_t *a) |
| 125 | { |
| 126 | 	u_int32_t _v_; |
| 127 | 	u_int32_t _p_ = (u_int32_t)a; |
| 128 | |
| 129 | 	__asm__ volatile("eieio"); |
| 130 | 	__asm__ volatile("lwbrx %0, 0, %1" : "=r"(_v_) : "r"(_p_)); |
| 131 | 	return _v_; |
| 132 | } |
| 133 | |
| 134 | |
| 135 | #define	outb(a,v)	(__outb((volatile u_int8_t *)(a), v)) |
| 136 | #define	out8(a,v)	outb(a,v) |
| 137 | #define	outw(a,v)	(__outw((volatile u_int16_t *)(a), v)) |
| 138 | #define	out16(a,v)	outw(a,v) |
| 139 | #define	outl(a,v)	(__outl((volatile u_int32_t *)(a), v)) |
| 140 | #define	out32(a,v)	outl(a,v) |
| 141 | #define	inb(a)		(__inb((volatile u_int8_t *)(a))) |
| 142 | #define	in8(a)		inb(a) |
| 143 | #define	inw(a)		(__inw((volatile u_int16_t *)(a))) |
| 144 | #define	in16(a)		inw(a) |
| 145 | #define	inl(a)		(__inl((volatile u_int32_t *)(a))) |
| 146 | #define	in32(a)		inl(a) |
| 147 | |
| 148 | #define	out8rb(a,v)	outb(a,v) |
| 149 | #define	outwrb(a,v)	(__outwrb((volatile u_int16_t *)(a), v)) |
| 150 | #define	out16rb(a,v)	outwrb(a,v) |
| 151 | #define	outlrb(a,v)	(__outlrb((volatile u_int32_t *)(a), v)) |
| 152 | #define	out32rb(a,v)	outlrb(a,v) |
| 153 | #define	in8rb(a)	inb(a) |
| 154 | #define	inwrb(a)	(__inwrb((volatile u_int16_t *)(a))) |
| 155 | #define	in16rb(a)	inwrb(a) |
| 156 | #define	inlrb(a)	(__inlrb((volatile u_int32_t *)(a))) |
| 157 | #define	in32rb(a)	inlrb(a) |
| 158 | |
| 159 | #ifdef DEBUG_SPEC |
| 160 | static __inline void |
| 161 | __flash_led(bits, count) |
| 162 | 	int bits; |
| 163 | { |
| 164 | 	int i, v = 0; |
| 165 | |
| 166 | 	if(bits == 0) { |
| 167 | 		v = 1; bits = 3; |
| 168 | 	} |
| 169 | 	bits &= 3; |
| 170 | 	count += count; |
| 171 | 	v |= (*(volatile u_int8_t *)(MPC106_V_ISA_IO_SPACE + 0x01f4)) & ~3; |
| 172 | 	while(count--) { |
| 173 | 		v ^= bits; |
| 174 | 		for(i = 100000; i > 0; i--) |
| 175 | 			*(volatile u_int8_t *)(MPC106_V_ISA_IO_SPACE + 0x01f4) = v; |
| 176 | 	} |
| 177 | 	*(u_int8_t *)(MPC106_V_ISA_IO_SPACE + 0x01f4) &= ~3; |
| 178 | } |
| 179 | #endif /* DEBUG */ |
| 180 | |
| 181 | #endif /*_POWERPC_PIO_H_*/ |