1 $NetBSD: patch-af,v 1.1 2008/08/02 16:46:56 dholland Exp $
3 diff -urpN /dev/null x86_pio.h
4 --- /dev/null 1969-12-31 19:00:00.000000000 -0500
5 +++ x86_pio.h 2008-08-02 12:15:47.000000000 -0400
7 +/* $NetBSD: patch-af,v 1.1 2008/08/02 16:46:56 dholland Exp $ */
10 + * Copyright (c) 1998 The NetBSD Foundation, Inc.
11 + * All rights reserved.
13 + * This code is derived from software contributed to The NetBSD Foundation
14 + * by Charles M. Hannum.
16 + * Redistribution and use in source and binary forms, with or without
17 + * modification, are permitted provided that the following conditions
19 + * 1. Redistributions of source code must retain the above copyright
20 + * notice, this list of conditions and the following disclaimer.
21 + * 2. Redistributions in binary form must reproduce the above copyright
22 + * notice, this list of conditions and the following disclaimer in the
23 + * documentation and/or other materials provided with the distribution.
24 + * 3. All advertising materials mentioning features or use of this software
25 + * must display the following acknowledgement:
26 + * This product includes software developed by the NetBSD
27 + * Foundation, Inc. and its contributors.
28 + * 4. Neither the name of The NetBSD Foundation nor the names of its
29 + * contributors may be used to endorse or promote products derived
30 + * from this software without specific prior written permission.
32 + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
33 + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
34 + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
35 + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
36 + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
37 + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
38 + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
39 + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
40 + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
41 + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
42 + * POSSIBILITY OF SUCH DAMAGE.
49 + * Functions to provide access to x86 programmed I/O instructions.
51 + * The in[bwl]() and out[bwl]() functions are split into two varieties: one to
52 + * use a small, constant, 8-bit port number, and another to use a large or
53 + * variable port number. The former can be compiled as a smaller instruction.
59 +#define __use_immediate_port(port) \
60 + (__builtin_constant_p((port)) && (port) < 0x100)
64 +#define __use_immediate_port(port) 0
70 + (/* CONSTCOND */ __use_immediate_port(port) ? __inbc(port) : __inb(port))
72 +static __inline u_int8_t
73 +__inbc(unsigned port)
76 + __asm volatile("inb %w1,%0" : "=a" (data) : "id" (port));
80 +static __inline u_int8_t
84 + __asm volatile("inb %w1,%0" : "=a" (data) : "d" (port));
89 +insb(unsigned port, void *addr, int cnt)
93 + __asm volatile("cld\n\trep\n\tinsb" :
94 + "=D" (dummy1), "=c" (dummy2) :
95 + "d" (port), "0" (addr), "1" (cnt) :
100 + (/* CONSTCOND */ __use_immediate_port(port) ? __inwc(port) : __inw(port))
102 +static __inline u_int16_t
103 +__inwc(unsigned port)
106 + __asm volatile("inw %w1,%0" : "=a" (data) : "id" (port));
110 +static __inline u_int16_t
111 +__inw(unsigned port)
114 + __asm volatile("inw %w1,%0" : "=a" (data) : "d" (port));
118 +static __inline void
119 +insw(unsigned port, void *addr, int cnt)
123 + __asm volatile("cld\n\trep\n\tinsw" :
124 + "=D" (dummy1), "=c" (dummy2) :
125 + "d" (port), "0" (addr), "1" (cnt) :
130 + (/* CONSTCOND */ __use_immediate_port(port) ? __inlc(port) : __inl(port))
132 +static __inline u_int32_t
133 +__inlc(unsigned port)
136 + __asm volatile("inl %w1,%0" : "=a" (data) : "id" (port));
140 +static __inline u_int32_t
141 +__inl(unsigned port)
144 + __asm volatile("inl %w1,%0" : "=a" (data) : "d" (port));
148 +static __inline void
149 +insl(unsigned port, void *addr, int cnt)
153 + __asm volatile("cld\n\trep\n\tinsl" :
154 + "=D" (dummy1), "=c" (dummy2) :
155 + "d" (port), "0" (addr), "1" (cnt) :
159 +#define outb(port, data) \
160 + (/* CONSTCOND */__use_immediate_port(port) ? __outbc(port, data) : \
161 + __outb(port, data))
163 +static __inline void
164 +__outbc(unsigned port, u_int8_t data)
166 + __asm volatile("outb %0,%w1" : : "a" (data), "id" (port));
169 +static __inline void
170 +__outb(unsigned port, u_int8_t data)
172 + __asm volatile("outb %0,%w1" : : "a" (data), "d" (port));
175 +static __inline void
176 +outsb(unsigned port, const void *addr, int cnt)
180 + __asm volatile("cld\n\trep\n\toutsb" :
181 + "=S" (dummy1), "=c" (dummy2) :
182 + "d" (port), "0" (addr), "1" (cnt));
185 +#define outw(port, data) \
186 + (/* CONSTCOND */ __use_immediate_port(port) ? __outwc(port, data) : \
187 + __outw(port, data))
189 +static __inline void
190 +__outwc(unsigned port, u_int16_t data)
192 + __asm volatile("outw %0,%w1" : : "a" (data), "id" (port));
195 +static __inline void
196 +__outw(unsigned port, u_int16_t data)
198 + __asm volatile("outw %0,%w1" : : "a" (data), "d" (port));
201 +static __inline void
202 +outsw(unsigned port, const void *addr, int cnt)
206 + __asm volatile("cld\n\trep\n\toutsw" :
207 + "=S" (dummy1), "=c" (dummy2) :
208 + "d" (port), "0" (addr), "1" (cnt));
211 +#define outl(port, data) \
212 + (/* CONSTCOND */ __use_immediate_port(port) ? __outlc(port, data) : \
213 + __outl(port, data))
215 +static __inline void
216 +__outlc(unsigned port, u_int32_t data)
218 + __asm volatile("outl %0,%w1" : : "a" (data), "id" (port));
221 +static __inline void
222 +__outl(unsigned port, u_int32_t data)
224 + __asm volatile("outl %0,%w1" : : "a" (data), "d" (port));
227 +static __inline void
228 +outsl(unsigned port, const void *addr, int cnt)
232 + __asm volatile("cld\n\trep\n\toutsl" :
233 + "=S" (dummy1), "=c" (dummy2) :
234 + "d" (port), "0" (addr), "1" (cnt));
237 +#endif /* _X86_PIO_H_ */