]> git.saurik.com Git - apple/xnu.git/blame - bsd/dev/i386/conf.c
xnu-344.49.tar.gz
[apple/xnu.git] / bsd / dev / i386 / conf.c
CommitLineData
1c79356b
A
1/*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
43866e37 6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
1c79356b 7 *
43866e37
A
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * file.
14 *
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
1c79356b
A
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
43866e37
A
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
1c79356b
A
22 *
23 * @APPLE_LICENSE_HEADER_END@
24 */
25/*
26 * Copyright (c) 1997 by Apple Computer, Inc., all rights reserved
27 * Copyright (c) 1993 NeXT Computer, Inc.
28 *
29 * UNIX Device switch tables.
30 *
31 * HISTORY
32 *
33 * 30 July 1997 Umesh Vaishampayan (umeshv@apple.com)
34 * enabled file descriptor pseudo-device.
35 * 18 June 1993 ? at NeXT
36 * Cleaned up a lot of stuff in this file.
37 */
38
39#include <sys/param.h>
40#include <sys/systm.h>
41#include <sys/buf.h>
42#include <sys/ioctl.h>
43#include <sys/tty.h>
44#include <sys/conf.h>
45
46
47extern int nulldev();
48
49struct bdevsw bdevsw[] =
50{
51 /*
52 * For block devices, every other block of 8 slots is
53 * reserved to NeXT. The other slots are available for
54 * the user. This way we can both add new entries without
55 * running into each other. Be sure to fill in NeXT's
56 * 8 reserved slots when you jump over us -- we'll do the
57 * same for you.
58 */
59
60 /* 0 - 7 are reserved to NeXT */
61
62 NO_BDEVICE, /* 0*/
63 NO_BDEVICE, /* 1*/
64 NO_BDEVICE, /* 2*/
65 NO_BDEVICE, /* 3*/
66 NO_BDEVICE, /* 4*/
67 NO_BDEVICE, /* 5*/
68 NO_BDEVICE, /* 6*/
69 NO_BDEVICE, /* 7*/
70
71 /* 8 - 15 are reserved to the user */
72 NO_BDEVICE, /* 8*/
73 NO_BDEVICE, /* 9*/
74 NO_BDEVICE, /*10*/
75 NO_BDEVICE, /*11*/
76 NO_BDEVICE, /*12*/
77 NO_BDEVICE, /*13*/
78 NO_BDEVICE, /*14*/
79 NO_BDEVICE, /*15*/
80
81 /* 16 - 23 are reserved to NeXT */
82 NO_BDEVICE, /*16*/
83 NO_BDEVICE, /*17*/
84 NO_BDEVICE, /*18*/
85 NO_BDEVICE, /*18*/
86 NO_BDEVICE, /*20*/
87 NO_BDEVICE, /*21*/
88 NO_BDEVICE, /*22*/
89 NO_BDEVICE, /*23*/
90};
91
92int nblkdev = sizeof (bdevsw) / sizeof (bdevsw[0]);
93
94extern struct tty *km_tty[];
95extern int cnopen(),cnclose(),cnread(),cnwrite(),cnioctl(),
96 cnselect(),cngetc(), cnputc(dev_t dev, char c);
97extern int kmopen(),kmclose(),kmread(),kmwrite(),kmioctl(),
98 kmgetc(), kmputc(dev_t dev, char c);
99extern int sgopen(),sgclose(), sgioctl();
100
101#if NVOL > 0
102extern int volopen(),volclose(),volioctl();
103#else
104#define volopen eno_opcl
105#define volclose eno_opcl
106#define volioctl eno_ioctl
107#endif
108
109extern int cttyopen(), cttyread(), cttywrite(), cttyioctl(), cttyselect();
110
111extern int mmread(),mmwrite();
112#define mmselect seltrue
113#define mmmmap eno_mmap
114
115#include <pty.h>
116#if NPTY > 0
117extern struct tty *pt_tty[];
118extern int ptsopen(),ptsclose(),ptsread(),ptswrite(),ptsstop(),ptsputc();
119extern int ptcopen(),ptcclose(),ptcread(),ptcwrite(),ptcselect(),
120 ptyioctl();
121#else
122#define ptsopen eno_opcl
123#define ptsclose eno_opcl
124#define ptsread eno_rdwrt
125#define ptswrite eno_rdwrt
126#define ptsstop nulldev
127#define ptsputc nulldev
128
129#define ptcopen eno_opcl
130#define ptcclose eno_opcl
131#define ptcread eno_rdwrt
132#define ptcwrite eno_rdwrt
133#define ptcselect eno_select
134#define ptyioctl eno_ioctl
135#endif
136
137extern int logopen(),logclose(),logread(),logioctl(),logselect();
138extern int fdesc_open(), fdesc_read(), fdesc_write(),
139 fdesc_ioctl(), fdesc_select();
140
141extern int seltrue();
142
143struct cdevsw cdevsw[] =
144{
145 /*
146 * For character devices, every other block of 16 slots is
147 * reserved to NeXT. The other slots are available for
148 * the user. This way we can both add new entries without
149 * running into each other. Be sure to fill in NeXT's
150 * 16 reserved slots when you jump over us -- we'll do the
151 * same for you.
152 */
153
154 /* 0 - 15 are reserved to NeXT */
155
156 {
157 cnopen, cnclose, cnread, cnwrite, /* 0*/
158 cnioctl, nulldev, nulldev, 0, cnselect,
159 eno_mmap, eno_strat, cngetc, cnputc, D_TTY
160 },
161 NO_CDEVICE, /* 1*/
162 {
163 cttyopen, nulldev, cttyread, cttywrite, /* 2*/
164 cttyioctl, nulldev, nulldev, 0, cttyselect,
165 eno_mmap, eno_strat, eno_getc, eno_putc, D_TTY
166 },
167 {
168 nulldev, nulldev, mmread, mmwrite, /* 3*/
169 eno_ioctl, nulldev, nulldev, 0, mmselect,
170 mmmmap, eno_strat, eno_getc, eno_putc, 0
171 },
172 {
173 ptsopen, ptsclose, ptsread, ptswrite, /* 4*/
174 ptyioctl, ptsstop, nulldev, pt_tty, ttselect,
175 eno_mmap, eno_strat, eno_getc, eno_putc, D_TTY
176 },
177 {
178 ptcopen, ptcclose, ptcread, ptcwrite, /* 5*/
179 ptyioctl, nulldev, nulldev, 0, ptcselect,
180 eno_mmap, eno_strat, eno_getc, eno_putc, D_TTY
181 },
182 {
183 logopen, logclose, logread, eno_rdwrt, /* 6*/
184 logioctl, eno_stop, nulldev, 0, logselect,
185 eno_mmap, eno_strat, eno_getc, eno_putc, 0
186 },
187 NO_CDEVICE, /* 7*/
188 NO_CDEVICE, /* 8*/
189 NO_CDEVICE, /* 9*/
190 NO_CDEVICE, /*10*/
191 NO_CDEVICE, /*11*/
192 {
193 kmopen, kmclose, kmread, kmwrite, /*12*/
194 kmioctl, nulldev, nulldev, km_tty, ttselect,
195 eno_mmap, eno_strat, kmgetc, kmputc, 0
196 },
197 NO_CDEVICE, /*13*/
198 NO_CDEVICE, /*14*/
199 NO_CDEVICE, /*15*/
200
201 /* 16 - 31 are reserved to the user */
202 NO_CDEVICE, /*16*/
203 NO_CDEVICE, /*17*/
204 NO_CDEVICE, /*18*/
205 NO_CDEVICE, /*19*/
206 NO_CDEVICE, /*20*/
207 NO_CDEVICE, /*21*/
208 NO_CDEVICE, /*22*/
209 NO_CDEVICE, /*23*/
210 NO_CDEVICE, /*24*/
211 NO_CDEVICE, /*25*/
212 NO_CDEVICE, /*26*/
213 NO_CDEVICE, /*27*/
214 NO_CDEVICE, /*28*/
215 NO_CDEVICE, /*29*/
216 NO_CDEVICE, /*30*/
217 NO_CDEVICE, /*31*/
218
219 /* 32 - 47 are reserved to NeXT */
220 {
221 fdesc_open, eno_opcl, fdesc_read, fdesc_write, /*32*/
222 fdesc_ioctl, eno_stop, eno_reset, 0, fdesc_select,
223 eno_mmap, eno_strat, eno_getc, eno_putc, 0
224 },
225#if 1
226 NO_CDEVICE,
227#else
228 {
229 sgopen, sgclose, eno_rdwrt, eno_rdwrt, /*33*/
230 sgioctl, eno_stop, eno_reset, 0, eno_select,
231 eno_mmap, eno_strat, eno_getc, eno_putc, D_TAPE
232 },
233#endif
234 NO_CDEVICE, /*34*/
235 NO_CDEVICE, /*35*/
236 NO_CDEVICE, /*36*/
237 NO_CDEVICE, /*37*/
238 NO_CDEVICE, /*38*/
239 NO_CDEVICE, /*39*/
240 NO_CDEVICE, /*40*/
241 NO_CDEVICE, /*41*/
242 {
243 volopen, volclose, eno_rdwrt, eno_rdwrt, /*42*/
244 volioctl, eno_stop, eno_reset, 0, seltrue,
245 eno_mmap, eno_strat, eno_getc, eno_putc, 0
246 },
247};
248int nchrdev = sizeof (cdevsw) / sizeof (cdevsw[0]);
249
250
251#include <sys/vnode.h> /* for VCHR and VBLK */
252/*
253 * return true if a disk
254 */
255int
256isdisk(dev, type)
257 dev_t dev;
258 int type;
259{
9bccf70c
A
260 dev_t maj = major(dev);
261
262 switch (type) {
263 case VCHR:
264 maj = chrtoblk(maj);
265 if (maj == NODEV) {
266 break;
267 }
268 /* FALL THROUGH */
269 case VBLK:
270 if (bdevsw[maj].d_type == D_DISK) {
271 return (1);
272 }
1c79356b
A
273 break;
274 }
275 return(0);
276}
277
278static int chrtoblktab[] = {
279 /* CHR*/ /* BLK*/ /* CHR*/ /* BLK*/
280 /* 0 */ NODEV, /* 1 */ NODEV,
281 /* 2 */ NODEV, /* 3 */ NODEV,
282 /* 4 */ NODEV, /* 5 */ NODEV,
283 /* 6 */ NODEV, /* 7 */ NODEV,
284 /* 8 */ NODEV, /* 9 */ NODEV,
285 /* 10 */ NODEV, /* 11 */ NODEV,
286 /* 12 */ NODEV, /* 13 */ NODEV,
287 /* 14 */ 6, /* 15 */ NODEV,
288 /* 16 */ NODEV, /* 17 */ NODEV,
289 /* 18 */ NODEV, /* 19 */ NODEV,
290 /* 20 */ NODEV, /* 21 */ NODEV,
291 /* 22 */ NODEV, /* 23 */ NODEV,
292 /* 24 */ NODEV, /* 25 */ NODEV,
293 /* 26 */ NODEV, /* 27 */ NODEV,
294 /* 28 */ NODEV, /* 29 */ NODEV,
295 /* 30 */ NODEV, /* 31 */ NODEV,
296 /* 32 */ NODEV, /* 33 */ NODEV,
297 /* 34 */ NODEV, /* 35 */ NODEV,
298 /* 36 */ NODEV, /* 37 */ NODEV,
299 /* 38 */ NODEV, /* 39 */ NODEV,
300 /* 40 */ NODEV, /* 41 */ 1,
301 /* 42 */ NODEV, /* 43 */ NODEV,
302 /* 44 */ NODEV,
303};
304
305/*
306 * convert chr dev to blk dev
307 */
308dev_t
309chrtoblk(dev)
310 dev_t dev;
311{
312 int blkmaj;
313
314 if (major(dev) >= nchrdev)
315 return(NODEV);
316 blkmaj = chrtoblktab[major(dev)];
317 if (blkmaj == NODEV)
318 return(NODEV);
319 return(makedev(blkmaj, minor(dev)));
320}
321
9bccf70c
A
322int
323chrtoblk_set(int cdev, int bdev)
324{
325 if (cdev >= nchrdev)
326 return (-1);
327 if (bdev != NODEV && bdev >= nblkdev)
328 return (-1);
329 chrtoblktab[cdev] = bdev;
330 return 0;
331}
332
1c79356b
A
333/*
334 * Returns true if dev is /dev/mem or /dev/kmem.
335 */
336int iskmemdev(dev)
337 dev_t dev;
338{
339
340 return (major(dev) == 3 && minor(dev) < 2);
341}