]>
git.saurik.com Git - apple/xnu.git/blob - bsd/dev/i386/conf.c
2 * Copyright (c) 1997-2012 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 dev_t
chrtoblk(dev_t dev
);
49 extern int chrtoblk_set(int cdev
, int bdev
);
50 extern int iskmemdev(dev_t dev
);
52 struct bdevsw bdevsw
[] =
55 * For block devices, every other block of 8 slots is
56 * reserved for Apple. The other slots are available for
57 * the user. This way we can both add new entries without
58 * running into each other. Be sure to fill in Apple's
59 * 8 reserved slots when you jump over us -- we'll do the
63 /* 0 - 7 are reserved for Apple */
74 /* 8 - 15 are reserved to the user */
84 /* 16 - 23 are reserved for Apple */
95 int nblkdev
= sizeof (bdevsw
) / sizeof (bdevsw
[0]);
97 extern struct tty
*km_tty
[];
98 extern d_open_t cnopen
;
99 extern d_close_t cnclose
;
100 extern d_read_t cnread
;
101 extern d_write_t cnwrite
;
102 extern d_ioctl_t cnioctl
;
103 extern d_select_t cnselect
;
104 extern d_open_t kmopen
;
105 extern d_close_t kmclose
;
106 extern d_read_t kmread
;
107 extern d_write_t kmwrite
;
108 extern d_ioctl_t kmioctl
;
109 extern d_open_t sgopen
;
110 extern d_close_t sgclose
;
111 extern d_ioctl_t sgioctl
;
114 extern d_open_t volopen
;
115 extern d_close_t volclose
;
116 extern d_ioctl_t volioctl
;
118 #define volopen eno_opcl
119 #define volclose eno_opcl
120 #define volioctl eno_ioctl
123 extern d_open_t cttyopen
;
124 extern d_close_t cttyclose
;
125 extern d_read_t cttyread
;
126 extern d_write_t cttywrite
;
127 extern d_ioctl_t cttyioctl
;
128 extern d_select_t cttyselect
;
130 extern d_read_t mmread
;
131 extern d_write_t mmwrite
;
132 extern d_ioctl_t mmioctl
;
133 #define mmselect (select_fcn_t *)seltrue
134 #define mmmmap eno_mmap
138 extern struct tty
*pt_tty
[];
139 extern d_open_t ptsopen
;
140 extern d_close_t ptsclose
;
141 extern d_read_t ptsread
;
142 extern d_write_t ptswrite
;
143 extern d_stop_t ptsstop
;
144 extern d_open_t ptcopen
;
145 extern d_close_t ptcclose
;
146 extern d_read_t ptcread
;
147 extern d_write_t ptcwrite
;
148 extern d_select_t ptcselect
;
149 extern d_ioctl_t ptyioctl
;
151 #define ptsopen eno_opcl
152 #define ptsclose eno_opcl
153 #define ptsread eno_rdwrt
154 #define ptswrite eno_rdwrt
155 #define ptsstop nulldev
157 #define ptcopen eno_opcl
158 #define ptcclose eno_opcl
159 #define ptcread eno_rdwrt
160 #define ptcwrite eno_rdwrt
161 #define ptcselect eno_select
162 #define ptyioctl eno_ioctl
165 extern d_open_t logopen
;
166 extern d_close_t logclose
;
167 extern d_read_t logread
;
168 extern d_ioctl_t logioctl
;
169 extern d_select_t logselect
;
170 extern d_open_t fdesc_open
;
171 extern d_read_t fdesc_read
;
172 extern d_write_t fdesc_write
;
173 extern d_ioctl_t fdesc_ioctl
;
174 extern d_select_t fdesc_select
;
176 #define nullopen (d_open_t *)&nulldev
177 #define nullclose (d_close_t *)&nulldev
178 #define nullread (d_read_t *)&nulldev
179 #define nullwrite (d_write_t *)&nulldev
180 #define nullioctl (d_ioctl_t *)&nulldev
181 #define nullselect (d_select_t *)&nulldev
182 #define nullstop (d_stop_t *)&nulldev
183 #define nullreset (d_reset_t *)&nulldev
185 struct cdevsw cdevsw
[] =
188 * For character devices, every other block of 16 slots is
189 * reserved for Apple. The other slots are available for
190 * the user. This way we can both add new entries without
191 * running into each other. Be sure to fill in Apple's
192 * 16 reserved slots when you jump over us -- we'll do the
196 /* 0 - 15 are reserved for Apple */
199 cnopen
, cnclose
, cnread
, cnwrite
, /* 0*/
200 cnioctl
, nullstop
, nullreset
, 0, cnselect
,
201 eno_mmap
, eno_strat
, eno_getc
, eno_putc
, D_TTY
205 cttyopen
, cttyclose
, cttyread
, cttywrite
, /* 2*/
206 cttyioctl
, nullstop
, nullreset
, 0, cttyselect
,
207 eno_mmap
, eno_strat
, eno_getc
, eno_putc
, D_TTY
| D_TRACKCLOSE
210 nullopen
, nullclose
, mmread
, mmwrite
, /* 3*/
211 mmioctl
, nullstop
, nullreset
, 0, mmselect
,
212 mmmmap
, eno_strat
, eno_getc
, eno_putc
, D_DISK
215 ptsopen
, ptsclose
, ptsread
, ptswrite
, /* 4*/
216 ptyioctl
, ptsstop
, nullreset
, pt_tty
, ttselect
,
217 eno_mmap
, eno_strat
, eno_getc
, eno_putc
, D_TTY
220 ptcopen
, ptcclose
, ptcread
, ptcwrite
, /* 5*/
221 ptyioctl
, nullstop
, nullreset
, 0, ptcselect
,
222 eno_mmap
, eno_strat
, eno_getc
, eno_putc
, D_TTY
225 logopen
, logclose
, logread
, eno_rdwrt
, /* 6*/
226 logioctl
, eno_stop
, nullreset
, 0, logselect
,
227 eno_mmap
, eno_strat
, eno_getc
, eno_putc
, 0
235 kmopen
, kmclose
, kmread
, kmwrite
, /*12*/
236 kmioctl
, nullstop
, nullreset
, km_tty
, ttselect
,
237 eno_mmap
, eno_strat
, eno_getc
, eno_putc
, 0
243 /* 16 - 31 are reserved to the user */
261 /* 32 - 47 are reserved to NeXT */
263 fdesc_open
, eno_opcl
, fdesc_read
, fdesc_write
, /*32*/
264 fdesc_ioctl
, eno_stop
, eno_reset
, 0, fdesc_select
,
265 eno_mmap
, eno_strat
, eno_getc
, eno_putc
, 0
271 sgopen
, sgclose
, eno_rdwrt
, eno_rdwrt
, /*33*/
272 sgioctl
, eno_stop
, eno_reset
, 0, eno_select
,
273 eno_mmap
, eno_strat
, eno_getc
, eno_putc
, D_TAPE
285 volopen
, volclose
, eno_rdwrt
, eno_rdwrt
, /*42*/
286 volioctl
, eno_stop
, eno_reset
, 0, (select_fcn_t
*)seltrue
,
287 eno_mmap
, eno_strat
, eno_getc
, eno_putc
, 0
290 int nchrdev
= sizeof (cdevsw
) / sizeof (cdevsw
[0]);
292 uint64_t cdevsw_flags
[sizeof (cdevsw
) / sizeof (cdevsw
[0])];
294 #include <sys/vnode.h> /* for VCHR and VBLK */
296 * return true if a disk
299 isdisk(dev_t dev
, int type
)
301 dev_t maj
= major(dev
);
311 if ((D_TYPEMASK
& bdevsw
[maj
].d_type
) == D_DISK
) {
319 static int chrtoblktab
[] = {
320 /* CHR*/ /* BLK*/ /* CHR*/ /* BLK*/
321 /* 0 */ NODEV
, /* 1 */ NODEV
,
322 /* 2 */ NODEV
, /* 3 */ NODEV
,
323 /* 4 */ NODEV
, /* 5 */ NODEV
,
324 /* 6 */ NODEV
, /* 7 */ NODEV
,
325 /* 8 */ NODEV
, /* 9 */ NODEV
,
326 /* 10 */ NODEV
, /* 11 */ NODEV
,
327 /* 12 */ NODEV
, /* 13 */ NODEV
,
328 /* 14 */ NODEV
, /* 15 */ NODEV
,
329 /* 16 */ NODEV
, /* 17 */ NODEV
,
330 /* 18 */ NODEV
, /* 19 */ NODEV
,
331 /* 20 */ NODEV
, /* 21 */ NODEV
,
332 /* 22 */ NODEV
, /* 23 */ NODEV
,
333 /* 24 */ NODEV
, /* 25 */ NODEV
,
334 /* 26 */ NODEV
, /* 27 */ NODEV
,
335 /* 28 */ NODEV
, /* 29 */ NODEV
,
336 /* 30 */ NODEV
, /* 31 */ NODEV
,
337 /* 32 */ NODEV
, /* 33 */ NODEV
,
338 /* 34 */ NODEV
, /* 35 */ NODEV
,
339 /* 36 */ NODEV
, /* 37 */ NODEV
,
340 /* 38 */ NODEV
, /* 39 */ NODEV
,
341 /* 40 */ NODEV
, /* 41 */ NODEV
,
342 /* 42 */ NODEV
, /* 43 */ NODEV
,
347 * convert chr dev to blk dev
354 if (major(dev
) >= nchrdev
)
356 blkmaj
= chrtoblktab
[major(dev
)];
359 return(makedev(blkmaj
, minor(dev
)));
363 chrtoblk_set(int cdev
, int bdev
)
367 if (bdev
!= NODEV
&& bdev
>= nblkdev
)
369 chrtoblktab
[cdev
] = bdev
;
374 * Returns true if dev is /dev/mem or /dev/kmem.
376 int iskmemdev(dev_t dev
)
378 return (major(dev
) == 3 && minor(dev
) < 2);