Annotation of sys/arch/amd64/include/pio.h, Revision 1.1.1.1
1.1 nbrk 1: /* $OpenBSD: pio.h,v 1.1 2004/01/28 01:39:39 mickey Exp $ */
2: /* $NetBSD: pio.h,v 1.2 2003/02/27 11:22:46 fvdl Exp $ */
3:
4: /*-
5: * Copyright (c) 1998 The NetBSD Foundation, Inc.
6: * All rights reserved.
7: *
8: * This code is derived from software contributed to The NetBSD Foundation
9: * by Charles M. Hannum.
10: *
11: * Redistribution and use in source and binary forms, with or without
12: * modification, are permitted provided that the following conditions
13: * are met:
14: * 1. Redistributions of source code must retain the above copyright
15: * notice, this list of conditions and the following disclaimer.
16: * 2. Redistributions in binary form must reproduce the above copyright
17: * notice, this list of conditions and the following disclaimer in the
18: * documentation and/or other materials provided with the distribution.
19: * 3. All advertising materials mentioning features or use of this software
20: * must display the following acknowledgement:
21: * This product includes software developed by the NetBSD
22: * Foundation, Inc. and its contributors.
23: * 4. Neither the name of The NetBSD Foundation nor the names of its
24: * contributors may be used to endorse or promote products derived
25: * from this software without specific prior written permission.
26: *
27: * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
28: * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
29: * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
30: * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
31: * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32: * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33: * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34: * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35: * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36: * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37: * POSSIBILITY OF SUCH DAMAGE.
38: */
39:
40: #ifndef _X86_PIO_H_
41: #define _X86_PIO_H_
42:
43: /*
44: * Functions to provide access to x86 programmed I/O instructions.
45: *
46: * The in[bwl]() and out[bwl]() functions are split into two varieties: one to
47: * use a small, constant, 8-bit port number, and another to use a large or
48: * variable port number. The former can be compiled as a smaller instruction.
49: */
50:
51:
52: #ifdef __OPTIMIZE__
53:
54: #define __use_immediate_port(port) \
55: (__builtin_constant_p((port)) && (port) < 0x100)
56:
57: #else
58:
59: #define __use_immediate_port(port) 0
60:
61: #endif
62:
63:
64: #define inb(port) \
65: (/* CONSTCOND */ __use_immediate_port(port) ? __inbc(port) : __inb(port))
66:
67: static __inline u_int8_t
68: __inbc(unsigned port)
69: {
70: u_int8_t data;
71: __asm __volatile("inb %w1,%0" : "=a" (data) : "id" (port));
72: return data;
73: }
74:
75: static __inline u_int8_t
76: __inb(unsigned port)
77: {
78: u_int8_t data;
79: __asm __volatile("inb %w1,%0" : "=a" (data) : "d" (port));
80: return data;
81: }
82:
83: static __inline void
84: insb(unsigned port, void *addr, int cnt)
85: {
86: void *dummy1;
87: int dummy2;
88: __asm __volatile("cld\n\trepne\n\tinsb" :
89: "=D" (dummy1), "=c" (dummy2) :
90: "d" (port), "0" (addr), "1" (cnt) :
91: "memory");
92: }
93:
94: #define inw(port) \
95: (/* CONSTCOND */ __use_immediate_port(port) ? __inwc(port) : __inw(port))
96:
97: static __inline u_int16_t
98: __inwc(unsigned port)
99: {
100: u_int16_t data;
101: __asm __volatile("inw %w1,%0" : "=a" (data) : "id" (port));
102: return data;
103: }
104:
105: static __inline u_int16_t
106: __inw(unsigned port)
107: {
108: u_int16_t data;
109: __asm __volatile("inw %w1,%0" : "=a" (data) : "d" (port));
110: return data;
111: }
112:
113: static __inline void
114: insw(unsigned port, void *addr, int cnt)
115: {
116: void *dummy1;
117: int dummy2;
118: __asm __volatile("cld\n\trepne\n\tinsw" :
119: "=D" (dummy1), "=c" (dummy2) :
120: "d" (port), "0" (addr), "1" (cnt) :
121: "memory");
122: }
123:
124: #define inl(port) \
125: (/* CONSTCOND */ __use_immediate_port(port) ? __inlc(port) : __inl(port))
126:
127: static __inline u_int32_t
128: __inlc(unsigned port)
129: {
130: u_int32_t data;
131: __asm __volatile("inl %w1,%0" : "=a" (data) : "id" (port));
132: return data;
133: }
134:
135: static __inline u_int32_t
136: __inl(unsigned port)
137: {
138: u_int32_t data;
139: __asm __volatile("inl %w1,%0" : "=a" (data) : "d" (port));
140: return data;
141: }
142:
143: static __inline void
144: insl(unsigned port, void *addr, int cnt)
145: {
146: void *dummy1;
147: int dummy2;
148: __asm __volatile("cld\n\trepne\n\tinsl" :
149: "=D" (dummy1), "=c" (dummy2) :
150: "d" (port), "0" (addr), "1" (cnt) :
151: "memory");
152: }
153:
154: #define outb(port, data) \
155: (/* CONSTCOND */__use_immediate_port(port) ? __outbc(port, data) : \
156: __outb(port, data))
157:
158: static __inline void
159: __outbc(unsigned port, u_int8_t data)
160: {
161: __asm __volatile("outb %0,%w1" : : "a" (data), "id" (port));
162: }
163:
164: static __inline void
165: __outb(unsigned port, u_int8_t data)
166: {
167: __asm __volatile("outb %0,%w1" : : "a" (data), "d" (port));
168: }
169:
170: static __inline void
171: outsb(unsigned port, const void *addr, int cnt)
172: {
173: void *dummy1;
174: int dummy2;
175: __asm __volatile("cld\n\trepne\n\toutsb" :
176: "=S" (dummy1), "=c" (dummy2) :
177: "d" (port), "0" (addr), "1" (cnt));
178: }
179:
180: #define outw(port, data) \
181: (/* CONSTCOND */ __use_immediate_port(port) ? __outwc(port, data) : \
182: __outw(port, data))
183:
184: static __inline void
185: __outwc(unsigned port, u_int16_t data)
186: {
187: __asm __volatile("outw %0,%w1" : : "a" (data), "id" (port));
188: }
189:
190: static __inline void
191: __outw(unsigned port, u_int16_t data)
192: {
193: __asm __volatile("outw %0,%w1" : : "a" (data), "d" (port));
194: }
195:
196: static __inline void
197: outsw(unsigned port, const void *addr, int cnt)
198: {
199: void *dummy1;
200: int dummy2;
201: __asm __volatile("cld\n\trepne\n\toutsw" :
202: "=S" (dummy1), "=c" (dummy2) :
203: "d" (port), "0" (addr), "1" (cnt));
204: }
205:
206: #define outl(port, data) \
207: (/* CONSTCOND */ __use_immediate_port(port) ? __outlc(port, data) : \
208: __outl(port, data))
209:
210: static __inline void
211: __outlc(unsigned port, u_int32_t data)
212: {
213: __asm __volatile("outl %0,%w1" : : "a" (data), "id" (port));
214: }
215:
216: static __inline void
217: __outl(unsigned port, u_int32_t data)
218: {
219: __asm __volatile("outl %0,%w1" : : "a" (data), "d" (port));
220: }
221:
222: static __inline void
223: outsl(unsigned port, const void *addr, int cnt)
224: {
225: void *dummy1;
226: int dummy2;
227: __asm __volatile("cld\n\trepne\n\toutsl" :
228: "=S" (dummy1), "=c" (dummy2) :
229: "d" (port), "0" (addr), "1" (cnt));
230: }
231:
232: #endif /* _X86_PIO_H_ */
CVSweb