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