]>
git.saurik.com Git - apple/xnu.git/blob - bsd/dev/i386/conf.c
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_OSREFERENCE_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
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
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
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.
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
31 * Copyright (c) 1997 by Apple Computer, Inc., all rights reserved
32 * Copyright (c) 1993 NeXT Computer, Inc.
34 * UNIX Device switch tables.
38 * 30 July 1997 Umesh Vaishampayan (umeshv@apple.com)
39 * enabled file descriptor pseudo-device.
40 * 18 June 1993 ? at NeXT
41 * Cleaned up a lot of stuff in this file.
44 #include <sys/param.h>
45 #include <sys/systm.h>
46 #include <sys/ioctl.h>
50 /* Prototypes that should be elsewhere: */
51 extern int isdisk(dev_t dev
, int type
);
52 extern dev_t
chrtoblk(dev_t dev
);
53 extern int chrtoblk_set(int cdev
, int bdev
);
54 extern int iskmemdev(dev_t dev
);
56 struct bdevsw bdevsw
[] =
59 * For block devices, every other block of 8 slots is
60 * reserved to NeXT. The other slots are available for
61 * the user. This way we can both add new entries without
62 * running into each other. Be sure to fill in NeXT's
63 * 8 reserved slots when you jump over us -- we'll do the
67 /* 0 - 7 are reserved to NeXT */
78 /* 8 - 15 are reserved to the user */
88 /* 16 - 23 are reserved to NeXT */
99 int nblkdev
= sizeof (bdevsw
) / sizeof (bdevsw
[0]);
101 extern struct tty
*km_tty
[];
102 extern d_open_t cnopen
;
103 extern d_close_t cnclose
;
104 extern d_read_t cnread
;
105 extern d_write_t cnwrite
;
106 extern d_ioctl_t cnioctl
;
107 extern d_select_t cnselect
;
108 extern d_getc_t cngetc
;
109 extern d_putc_t cnputc
;
110 extern d_open_t kmopen
;
111 extern d_close_t kmclose
;
112 extern d_read_t kmread
;
113 extern d_write_t kmwrite
;
114 extern d_ioctl_t kmioctl
;
115 extern d_getc_t kmgetc
;
116 extern d_putc_t kmputc
;
117 extern d_open_t sgopen
;
118 extern d_close_t sgclose
;
119 extern d_ioctl_t sgioctl
;
122 extern d_open_t volopen
;
123 extern d_close_t volclose
;
124 extern d_ioctl_t volioctl
;
126 #define volopen eno_opcl
127 #define volclose eno_opcl
128 #define volioctl eno_ioctl
131 extern d_open_t cttyopen
;
132 extern d_read_t cttyread
;
133 extern d_write_t cttywrite
;
134 extern d_ioctl_t cttyioctl
;
135 extern d_select_t cttyselect
;
137 extern d_read_t mmread
;
138 extern d_write_t mmwrite
;
139 extern d_ioctl_t mmioctl
;
140 #define mmselect (select_fcn_t *)seltrue
141 #define mmmmap eno_mmap
145 extern struct tty
*pt_tty
[];
146 extern d_open_t ptsopen
;
147 extern d_close_t ptsclose
;
148 extern d_read_t ptsread
;
149 extern d_write_t ptswrite
;
150 extern d_stop_t ptsstop
;
151 extern d_putc_t ptsputc
;
152 extern d_open_t ptcopen
;
153 extern d_close_t ptcclose
;
154 extern d_read_t ptcread
;
155 extern d_write_t ptcwrite
;
156 extern d_select_t ptcselect
;
157 extern d_ioctl_t ptyioctl
;
159 #define ptsopen eno_opcl
160 #define ptsclose eno_opcl
161 #define ptsread eno_rdwrt
162 #define ptswrite eno_rdwrt
163 #define ptsstop nulldev
164 #define ptsputc nulldev
166 #define ptcopen eno_opcl
167 #define ptcclose eno_opcl
168 #define ptcread eno_rdwrt
169 #define ptcwrite eno_rdwrt
170 #define ptcselect eno_select
171 #define ptyioctl eno_ioctl
174 extern d_open_t logopen
;
175 extern d_close_t logclose
;
176 extern d_read_t logread
;
177 extern d_ioctl_t logioctl
;
178 extern d_select_t logselect
;
179 extern d_open_t fdesc_open
;
180 extern d_read_t fdesc_read
;
181 extern d_write_t fdesc_write
;
182 extern d_ioctl_t fdesc_ioctl
;
183 extern d_select_t fdesc_select
;
185 #define nullopen (d_open_t *)&nulldev
186 #define nullclose (d_close_t *)&nulldev
187 #define nullread (d_read_t *)&nulldev
188 #define nullwrite (d_write_t *)&nulldev
189 #define nullioctl (d_ioctl_t *)&nulldev
190 #define nullselect (d_select_t *)&nulldev
191 #define nullstop (d_stop_t *)&nulldev
192 #define nullreset (d_reset_t *)&nulldev
194 struct cdevsw cdevsw
[] =
197 * For character devices, every other block of 16 slots is
198 * reserved to NeXT. The other slots are available for
199 * the user. This way we can both add new entries without
200 * running into each other. Be sure to fill in NeXT's
201 * 16 reserved slots when you jump over us -- we'll do the
205 /* 0 - 15 are reserved to NeXT */
208 cnopen
, cnclose
, cnread
, cnwrite
, /* 0*/
209 cnioctl
, nullstop
, nullreset
, 0, cnselect
,
210 eno_mmap
, eno_strat
, cngetc
, cnputc
, D_TTY
214 cttyopen
, nullclose
, cttyread
, cttywrite
, /* 2*/
215 cttyioctl
, nullstop
, nullreset
, 0, cttyselect
,
216 eno_mmap
, eno_strat
, eno_getc
, eno_putc
, D_TTY
219 nullopen
, nullclose
, mmread
, mmwrite
, /* 3*/
220 mmioctl
, nullstop
, nullreset
, 0, mmselect
,
221 mmmmap
, eno_strat
, eno_getc
, eno_putc
, D_DISK
224 ptsopen
, ptsclose
, ptsread
, ptswrite
, /* 4*/
225 ptyioctl
, ptsstop
, nullreset
, pt_tty
, ttselect
,
226 eno_mmap
, eno_strat
, eno_getc
, eno_putc
, D_TTY
229 ptcopen
, ptcclose
, ptcread
, ptcwrite
, /* 5*/
230 ptyioctl
, nullstop
, nullreset
, 0, ptcselect
,
231 eno_mmap
, eno_strat
, eno_getc
, eno_putc
, D_TTY
234 logopen
, logclose
, logread
, eno_rdwrt
, /* 6*/
235 logioctl
, eno_stop
, nullreset
, 0, logselect
,
236 eno_mmap
, eno_strat
, eno_getc
, eno_putc
, 0
244 kmopen
, kmclose
, kmread
, kmwrite
, /*12*/
245 kmioctl
, nullstop
, nullreset
, km_tty
, ttselect
,
246 eno_mmap
, eno_strat
, kmgetc
, kmputc
, 0
252 /* 16 - 31 are reserved to the user */
270 /* 32 - 47 are reserved to NeXT */
272 fdesc_open
, eno_opcl
, fdesc_read
, fdesc_write
, /*32*/
273 fdesc_ioctl
, eno_stop
, eno_reset
, 0, fdesc_select
,
274 eno_mmap
, eno_strat
, eno_getc
, eno_putc
, 0
280 sgopen
, sgclose
, eno_rdwrt
, eno_rdwrt
, /*33*/
281 sgioctl
, eno_stop
, eno_reset
, 0, eno_select
,
282 eno_mmap
, eno_strat
, eno_getc
, eno_putc
, D_TAPE
294 volopen
, volclose
, eno_rdwrt
, eno_rdwrt
, /*42*/
295 volioctl
, eno_stop
, eno_reset
, 0, (select_fcn_t
*)seltrue
,
296 eno_mmap
, eno_strat
, eno_getc
, eno_putc
, 0
299 int nchrdev
= sizeof (cdevsw
) / sizeof (cdevsw
[0]);
302 #include <sys/vnode.h> /* for VCHR and VBLK */
304 * return true if a disk
307 isdisk(dev_t dev
, int type
)
309 dev_t maj
= major(dev
);
319 if (bdevsw
[maj
].d_type
== D_DISK
) {
327 static int chrtoblktab
[] = {
328 /* CHR*/ /* BLK*/ /* CHR*/ /* BLK*/
329 /* 0 */ NODEV
, /* 1 */ NODEV
,
330 /* 2 */ NODEV
, /* 3 */ NODEV
,
331 /* 4 */ NODEV
, /* 5 */ NODEV
,
332 /* 6 */ NODEV
, /* 7 */ NODEV
,
333 /* 8 */ NODEV
, /* 9 */ NODEV
,
334 /* 10 */ NODEV
, /* 11 */ NODEV
,
335 /* 12 */ NODEV
, /* 13 */ NODEV
,
336 /* 14 */ 6, /* 15 */ NODEV
,
337 /* 16 */ NODEV
, /* 17 */ NODEV
,
338 /* 18 */ NODEV
, /* 19 */ NODEV
,
339 /* 20 */ NODEV
, /* 21 */ NODEV
,
340 /* 22 */ NODEV
, /* 23 */ NODEV
,
341 /* 24 */ NODEV
, /* 25 */ NODEV
,
342 /* 26 */ NODEV
, /* 27 */ NODEV
,
343 /* 28 */ NODEV
, /* 29 */ NODEV
,
344 /* 30 */ NODEV
, /* 31 */ NODEV
,
345 /* 32 */ NODEV
, /* 33 */ NODEV
,
346 /* 34 */ NODEV
, /* 35 */ NODEV
,
347 /* 36 */ NODEV
, /* 37 */ NODEV
,
348 /* 38 */ NODEV
, /* 39 */ NODEV
,
349 /* 40 */ NODEV
, /* 41 */ 1,
350 /* 42 */ NODEV
, /* 43 */ NODEV
,
355 * convert chr dev to blk dev
362 if (major(dev
) >= nchrdev
)
364 blkmaj
= chrtoblktab
[major(dev
)];
367 return(makedev(blkmaj
, minor(dev
)));
371 chrtoblk_set(int cdev
, int bdev
)
375 if (bdev
!= NODEV
&& bdev
>= nblkdev
)
377 chrtoblktab
[cdev
] = bdev
;
382 * Returns true if dev is /dev/mem or /dev/kmem.
384 int iskmemdev(dev_t dev
)
386 return (major(dev
) == 3 && minor(dev
) < 2);