]>
git.saurik.com Git - apple/xnu.git/blob - bsd/dev/i386/conf.c
2 * Copyright (c) 1997-2006 Apple Computer, Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
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 License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
29 * Copyright (c) 1993 NeXT Computer, Inc.
31 * UNIX Device switch tables.
35 * 30 July 1997 Umesh Vaishampayan (umeshv@apple.com)
36 * enabled file descriptor pseudo-device.
37 * 18 June 1993 ? at NeXT
38 * Cleaned up a lot of stuff in this file.
41 #include <sys/param.h>
42 #include <sys/systm.h>
43 #include <sys/ioctl.h>
47 /* Prototypes that should be elsewhere: */
48 extern int isdisk(dev_t dev
, int type
);
49 extern dev_t
chrtoblk(dev_t dev
);
50 extern int chrtoblk_set(int cdev
, int bdev
);
51 extern int iskmemdev(dev_t dev
);
53 struct bdevsw bdevsw
[] =
56 * For block devices, every other block of 8 slots is
57 * reserved for Apple. The other slots are available for
58 * the user. This way we can both add new entries without
59 * running into each other. Be sure to fill in Apple's
60 * 8 reserved slots when you jump over us -- we'll do the
64 /* 0 - 7 are reserved for Apple */
75 /* 8 - 15 are reserved to the user */
85 /* 16 - 23 are reserved for Apple */
96 int nblkdev
= sizeof (bdevsw
) / sizeof (bdevsw
[0]);
98 extern struct tty
*km_tty
[];
99 extern d_open_t cnopen
;
100 extern d_close_t cnclose
;
101 extern d_read_t cnread
;
102 extern d_write_t cnwrite
;
103 extern d_ioctl_t cnioctl
;
104 extern d_select_t cnselect
;
105 extern d_getc_t cngetc
;
106 extern d_putc_t cnputc
;
107 extern d_open_t kmopen
;
108 extern d_close_t kmclose
;
109 extern d_read_t kmread
;
110 extern d_write_t kmwrite
;
111 extern d_ioctl_t kmioctl
;
112 extern d_getc_t kmgetc
;
113 extern d_putc_t kmputc
;
114 extern d_open_t sgopen
;
115 extern d_close_t sgclose
;
116 extern d_ioctl_t sgioctl
;
119 extern d_open_t volopen
;
120 extern d_close_t volclose
;
121 extern d_ioctl_t volioctl
;
123 #define volopen eno_opcl
124 #define volclose eno_opcl
125 #define volioctl eno_ioctl
128 extern d_open_t cttyopen
;
129 extern d_read_t cttyread
;
130 extern d_write_t cttywrite
;
131 extern d_ioctl_t cttyioctl
;
132 extern d_select_t cttyselect
;
134 extern d_read_t mmread
;
135 extern d_write_t mmwrite
;
136 extern d_ioctl_t mmioctl
;
137 #define mmselect (select_fcn_t *)seltrue
138 #define mmmmap eno_mmap
142 extern struct tty
*pt_tty
[];
143 extern d_open_t ptsopen
;
144 extern d_close_t ptsclose
;
145 extern d_read_t ptsread
;
146 extern d_write_t ptswrite
;
147 extern d_stop_t ptsstop
;
148 extern d_putc_t ptsputc
;
149 extern d_open_t ptcopen
;
150 extern d_close_t ptcclose
;
151 extern d_read_t ptcread
;
152 extern d_write_t ptcwrite
;
153 extern d_select_t ptcselect
;
154 extern d_ioctl_t ptyioctl
;
156 #define ptsopen eno_opcl
157 #define ptsclose eno_opcl
158 #define ptsread eno_rdwrt
159 #define ptswrite eno_rdwrt
160 #define ptsstop nulldev
161 #define ptsputc nulldev
163 #define ptcopen eno_opcl
164 #define ptcclose eno_opcl
165 #define ptcread eno_rdwrt
166 #define ptcwrite eno_rdwrt
167 #define ptcselect eno_select
168 #define ptyioctl eno_ioctl
171 extern d_open_t logopen
;
172 extern d_close_t logclose
;
173 extern d_read_t logread
;
174 extern d_ioctl_t logioctl
;
175 extern d_select_t logselect
;
176 extern d_open_t fdesc_open
;
177 extern d_read_t fdesc_read
;
178 extern d_write_t fdesc_write
;
179 extern d_ioctl_t fdesc_ioctl
;
180 extern d_select_t fdesc_select
;
182 #define nullopen (d_open_t *)&nulldev
183 #define nullclose (d_close_t *)&nulldev
184 #define nullread (d_read_t *)&nulldev
185 #define nullwrite (d_write_t *)&nulldev
186 #define nullioctl (d_ioctl_t *)&nulldev
187 #define nullselect (d_select_t *)&nulldev
188 #define nullstop (d_stop_t *)&nulldev
189 #define nullreset (d_reset_t *)&nulldev
191 struct cdevsw cdevsw
[] =
194 * For character devices, every other block of 16 slots is
195 * reserved for Apple. The other slots are available for
196 * the user. This way we can both add new entries without
197 * running into each other. Be sure to fill in Apple's
198 * 16 reserved slots when you jump over us -- we'll do the
202 /* 0 - 15 are reserved for Apple */
205 cnopen
, cnclose
, cnread
, cnwrite
, /* 0*/
206 cnioctl
, nullstop
, nullreset
, 0, cnselect
,
207 eno_mmap
, eno_strat
, cngetc
, cnputc
, D_TTY
211 cttyopen
, nullclose
, cttyread
, cttywrite
, /* 2*/
212 cttyioctl
, nullstop
, nullreset
, 0, cttyselect
,
213 eno_mmap
, eno_strat
, eno_getc
, eno_putc
, D_TTY
216 nullopen
, nullclose
, mmread
, mmwrite
, /* 3*/
217 mmioctl
, nullstop
, nullreset
, 0, mmselect
,
218 mmmmap
, eno_strat
, eno_getc
, eno_putc
, D_DISK
221 ptsopen
, ptsclose
, ptsread
, ptswrite
, /* 4*/
222 ptyioctl
, ptsstop
, nullreset
, pt_tty
, ttselect
,
223 eno_mmap
, eno_strat
, eno_getc
, eno_putc
, D_TTY
226 ptcopen
, ptcclose
, ptcread
, ptcwrite
, /* 5*/
227 ptyioctl
, nullstop
, nullreset
, 0, ptcselect
,
228 eno_mmap
, eno_strat
, eno_getc
, eno_putc
, D_TTY
231 logopen
, logclose
, logread
, eno_rdwrt
, /* 6*/
232 logioctl
, eno_stop
, nullreset
, 0, logselect
,
233 eno_mmap
, eno_strat
, eno_getc
, eno_putc
, 0
241 kmopen
, kmclose
, kmread
, kmwrite
, /*12*/
242 kmioctl
, nullstop
, nullreset
, km_tty
, ttselect
,
243 eno_mmap
, eno_strat
, kmgetc
, kmputc
, 0
249 /* 16 - 31 are reserved to the user */
267 /* 32 - 47 are reserved to NeXT */
269 fdesc_open
, eno_opcl
, fdesc_read
, fdesc_write
, /*32*/
270 fdesc_ioctl
, eno_stop
, eno_reset
, 0, fdesc_select
,
271 eno_mmap
, eno_strat
, eno_getc
, eno_putc
, 0
277 sgopen
, sgclose
, eno_rdwrt
, eno_rdwrt
, /*33*/
278 sgioctl
, eno_stop
, eno_reset
, 0, eno_select
,
279 eno_mmap
, eno_strat
, eno_getc
, eno_putc
, D_TAPE
291 volopen
, volclose
, eno_rdwrt
, eno_rdwrt
, /*42*/
292 volioctl
, eno_stop
, eno_reset
, 0, (select_fcn_t
*)seltrue
,
293 eno_mmap
, eno_strat
, eno_getc
, eno_putc
, 0
296 int nchrdev
= sizeof (cdevsw
) / sizeof (cdevsw
[0]);
299 #include <sys/vnode.h> /* for VCHR and VBLK */
301 * return true if a disk
304 isdisk(dev_t dev
, int type
)
306 dev_t maj
= major(dev
);
316 if (bdevsw
[maj
].d_type
== D_DISK
) {
324 static int chrtoblktab
[] = {
325 /* CHR*/ /* BLK*/ /* CHR*/ /* BLK*/
326 /* 0 */ NODEV
, /* 1 */ NODEV
,
327 /* 2 */ NODEV
, /* 3 */ NODEV
,
328 /* 4 */ NODEV
, /* 5 */ NODEV
,
329 /* 6 */ NODEV
, /* 7 */ NODEV
,
330 /* 8 */ NODEV
, /* 9 */ NODEV
,
331 /* 10 */ NODEV
, /* 11 */ NODEV
,
332 /* 12 */ NODEV
, /* 13 */ NODEV
,
333 /* 14 */ 6, /* 15 */ NODEV
,
334 /* 16 */ NODEV
, /* 17 */ NODEV
,
335 /* 18 */ NODEV
, /* 19 */ NODEV
,
336 /* 20 */ NODEV
, /* 21 */ NODEV
,
337 /* 22 */ NODEV
, /* 23 */ NODEV
,
338 /* 24 */ NODEV
, /* 25 */ NODEV
,
339 /* 26 */ NODEV
, /* 27 */ NODEV
,
340 /* 28 */ NODEV
, /* 29 */ NODEV
,
341 /* 30 */ NODEV
, /* 31 */ NODEV
,
342 /* 32 */ NODEV
, /* 33 */ NODEV
,
343 /* 34 */ NODEV
, /* 35 */ NODEV
,
344 /* 36 */ NODEV
, /* 37 */ NODEV
,
345 /* 38 */ NODEV
, /* 39 */ NODEV
,
346 /* 40 */ NODEV
, /* 41 */ 1,
347 /* 42 */ NODEV
, /* 43 */ NODEV
,
352 * convert chr dev to blk dev
359 if (major(dev
) >= nchrdev
)
361 blkmaj
= chrtoblktab
[major(dev
)];
364 return(makedev(blkmaj
, minor(dev
)));
368 chrtoblk_set(int cdev
, int bdev
)
372 if (bdev
!= NODEV
&& bdev
>= nblkdev
)
374 chrtoblktab
[cdev
] = bdev
;
379 * Returns true if dev is /dev/mem or /dev/kmem.
381 int iskmemdev(dev_t dev
)
383 return (major(dev
) == 3 && minor(dev
) < 2);