]> git.saurik.com Git - apple/xnu.git/blob - bsd/dev/i386/pio.h
xnu-792.12.6.tar.gz
[apple/xnu.git] / bsd / dev / i386 / pio.h
1 /*
2 * Copyright (c) 2006 Apple Computer, Inc. All Rights Reserved.
3 *
4 * @APPLE_LICENSE_OSREFERENCE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the
10 * License may not be used to create, or enable the creation or
11 * redistribution of, unlawful or unlicensed copies of an Apple operating
12 * system, or to circumvent, violate, or enable the circumvention or
13 * violation of, any terms of an Apple operating system software license
14 * agreement.
15 *
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
18 * file.
19 *
20 * The Original Code and all software distributed under the License are
21 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
22 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
23 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
25 * Please see the License for the specific language governing rights and
26 * limitations under the License.
27 *
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
29 */
30 /*
31 * @OSF_COPYRIGHT@
32 */
33 /*
34 * HISTORY
35 *
36 * Revision 1.2 1998/09/30 21:20:45 wsanchez
37 * Merged in IntelMerge1 (mburg: Intel support)
38 *
39 * Revision 1.1.2.1 1998/09/30 18:18:50 mburg
40 * Changes for Intel port
41 *
42 * Revision 1.1.1.1 1998/03/07 02:25:38 wsanchez
43 * Import of OSF Mach kernel (~mburg)
44 *
45 * Revision 1.1.8.2 1996/07/31 09:46:36 paire
46 * Merged with nmk20b7_shared (1.1.11.2 -> 1.1.11.1)
47 * [96/06/10 paire]
48 *
49 * Revision 1.1.11.2 1996/06/13 12:38:25 bernadat
50 * Do not use inline macros when MACH_ASSERT is configured.
51 * [96/05/24 bernadat]
52 *
53 * Revision 1.1.11.1 1996/05/14 13:50:23 paire
54 * Added new linl and loutl __inline__.
55 * Added conditional compilation for [l]{in|oub}[bwl]() __inline__.
56 * [95/11/24 paire]
57 *
58 * Revision 1.1.8.1 1994/09/23 02:00:28 ezf
59 * change marker to not FREE
60 * [1994/09/22 21:25:52 ezf]
61 *
62 * Revision 1.1.4.5 1993/08/09 19:40:41 dswartz
63 * Add ANSI prototypes - CR#9523
64 * [1993/08/06 17:45:57 dswartz]
65 *
66 * Revision 1.1.4.4 1993/06/11 15:17:37 jeffc
67 * CR9176 - ANSI C violations: inb/outb macros must be changed from
68 * ({ ... }) to inline functions, with proper type definitions. Callers
69 * must pass proper types to these functions: 386 I/O port addresses
70 * are unsigned shorts (not pointers).
71 * [1993/06/10 14:26:10 jeffc]
72 *
73 * Revision 1.1.4.3 1993/06/07 22:09:28 jeffc
74 * CR9176 - ANSI C violations: trailing tokens on CPP
75 * directives, extra semicolons after decl_ ..., asm keywords
76 * [1993/06/07 19:00:26 jeffc]
77 *
78 * Revision 1.1.4.2 1993/06/04 15:28:45 jeffc
79 * CR9176 - ANSI problems -
80 * Added casts to get macros to take caddr_t as an I/O space address.
81 * [1993/06/04 13:45:55 jeffc]
82 *
83 * Revision 1.1 1992/09/30 02:25:51 robert
84 * Initial revision
85 *
86 * $EndLog$
87 */
88 /* CMU_HIST */
89 /*
90 * Revision 2.5 91/05/14 16:14:20 mrt
91 * Correcting copyright
92 *
93 * Revision 2.4 91/02/05 17:13:56 mrt
94 * Changed to new Mach copyright
95 * [91/02/01 17:37:08 mrt]
96 *
97 * Revision 2.3 90/12/20 16:36:37 jeffreyh
98 * changes for __STDC__
99 * [90/12/07 jeffreyh]
100 *
101 * Revision 2.2 90/11/26 14:48:41 rvb
102 * Pulled from 2.5
103 * [90/11/22 10:09:38 rvb]
104 *
105 * [90/08/14 mg32]
106 *
107 * Now we know how types are factor in.
108 * Cleaned up a bunch: eliminated ({ for output and flushed unused
109 * output variables.
110 * [90/08/14 rvb]
111 *
112 * This is how its done in gcc:
113 * Created.
114 * [90/03/26 rvb]
115 *
116 */
117 /* CMU_ENDHIST */
118 /*
119 * Mach Operating System
120 * Copyright (c) 1991,1990 Carnegie Mellon University
121 * All Rights Reserved.
122 *
123 * Permission to use, copy, modify and distribute this software and its
124 * documentation is hereby granted, provided that both the copyright
125 * notice and this permission notice appear in all copies of the
126 * software, derivative works or modified versions, and any portions
127 * thereof, and that both notices appear in supporting documentation.
128 *
129 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
130 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
131 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
132 *
133 * Carnegie Mellon requests users of this software to return to
134 *
135 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
136 * School of Computer Science
137 * Carnegie Mellon University
138 * Pittsburgh PA 15213-3890
139 *
140 * any improvements or extensions that they make and grant Carnegie Mellon
141 * the rights to redistribute these changes.
142 */
143 /*
144 */
145 #ifndef I386_PIO_H
146 #define I386_PIO_H
147
148 typedef unsigned short i386_ioport_t;
149
150 /* read a longword */
151 extern unsigned long inl(
152 i386_ioport_t port);
153 /* read a shortword */
154 extern unsigned short inw(
155 i386_ioport_t port);
156 /* read a byte */
157 extern unsigned char inb(
158 i386_ioport_t port);
159 /* write a longword */
160 extern void outl(
161 i386_ioport_t port,
162 unsigned long datum);
163 /* write a word */
164 extern void outw(
165 i386_ioport_t port,
166 unsigned short datum);
167 /* write a longword */
168 extern void outb(
169 i386_ioport_t port,
170 unsigned char datum);
171
172 /* input an array of longwords */
173 extern void linl(
174 i386_ioport_t port,
175 int * data,
176 int count);
177 /* output an array of longwords */
178 extern void loutl(
179 i386_ioport_t port,
180 int * data,
181 int count);
182
183 /* input an array of words */
184 extern void linw(
185 i386_ioport_t port,
186 int * data,
187 int count);
188 /* output an array of words */
189 extern void loutw(
190 i386_ioport_t port,
191 int * data,
192 int count);
193
194 /* input an array of bytes */
195 extern void linb(
196 i386_ioport_t port,
197 char * data,
198 int count);
199 /* output an array of bytes */
200 extern void loutb(
201 i386_ioport_t port,
202 char * data,
203 int count);
204
205 extern __inline__ unsigned long inl(
206 i386_ioport_t port)
207 {
208 unsigned long datum;
209 __asm__ volatile("inl %1, %0" : "=a" (datum) : "d" (port));
210 return(datum);
211 }
212
213 extern __inline__ unsigned short inw(
214 i386_ioport_t port)
215 {
216 unsigned short datum;
217 __asm__ volatile(".byte 0x66; inl %1, %0" : "=a" (datum) : "d" (port));
218 return(datum);
219 }
220
221 extern __inline__ unsigned char inb(
222 i386_ioport_t port)
223 {
224 unsigned char datum;
225 __asm__ volatile("inb %1, %0" : "=a" (datum) : "d" (port));
226 return(datum);
227 }
228
229 extern __inline__ void outl(
230 i386_ioport_t port,
231 unsigned long datum)
232 {
233 __asm__ volatile("outl %0, %1" : : "a" (datum), "d" (port));
234 }
235
236 extern __inline__ void outw(
237 i386_ioport_t port,
238 unsigned short datum)
239 {
240 __asm__ volatile(".byte 0x66; outl %0, %1" : : "a" (datum), "d" (port));
241 }
242
243 extern __inline__ void outb(
244 i386_ioport_t port,
245 unsigned char datum)
246 {
247 __asm__ volatile("outb %0, %1" : : "a" (datum), "d" (port));
248 }
249
250 #endif /* I386_PIO_H */