]> git.saurik.com Git - apple/xnu.git/blob - bsd/dev/i386/conf.c
xnu-201.42.3.tar.gz
[apple/xnu.git] / bsd / dev / i386 / conf.c
1 /*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
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.
11 *
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
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
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.
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
44 extern int nulldev();
45
46 struct 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
89 int nblkdev = sizeof (bdevsw) / sizeof (bdevsw[0]);
90
91 extern struct tty *km_tty[];
92 extern int cnopen(),cnclose(),cnread(),cnwrite(),cnioctl(),
93 cnselect(),cngetc(), cnputc(dev_t dev, char c);
94 extern int kmopen(),kmclose(),kmread(),kmwrite(),kmioctl(),
95 kmgetc(), kmputc(dev_t dev, char c);
96 extern int sgopen(),sgclose(), sgioctl();
97
98 #if NVOL > 0
99 extern int volopen(),volclose(),volioctl();
100 #else
101 #define volopen eno_opcl
102 #define volclose eno_opcl
103 #define volioctl eno_ioctl
104 #endif
105
106 extern int cttyopen(), cttyread(), cttywrite(), cttyioctl(), cttyselect();
107
108 extern int mmread(),mmwrite();
109 #define mmselect seltrue
110 #define mmmmap eno_mmap
111
112 #include <pty.h>
113 #if NPTY > 0
114 extern struct tty *pt_tty[];
115 extern int ptsopen(),ptsclose(),ptsread(),ptswrite(),ptsstop(),ptsputc();
116 extern 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
134 extern int logopen(),logclose(),logread(),logioctl(),logselect();
135 extern int fdesc_open(), fdesc_read(), fdesc_write(),
136 fdesc_ioctl(), fdesc_select();
137
138 extern int seltrue();
139
140 struct cdevsw cdevsw[] =
141 {
142 /*
143 * For character devices, every other block of 16 slots is
144 * reserved to NeXT. The other slots are available for
145 * the user. This way we can both add new entries without
146 * running into each other. Be sure to fill in NeXT's
147 * 16 reserved slots when you jump over us -- we'll do the
148 * same for you.
149 */
150
151 /* 0 - 15 are reserved to NeXT */
152
153 {
154 cnopen, cnclose, cnread, cnwrite, /* 0*/
155 cnioctl, nulldev, nulldev, 0, cnselect,
156 eno_mmap, eno_strat, cngetc, cnputc, D_TTY
157 },
158 NO_CDEVICE, /* 1*/
159 {
160 cttyopen, nulldev, cttyread, cttywrite, /* 2*/
161 cttyioctl, nulldev, nulldev, 0, cttyselect,
162 eno_mmap, eno_strat, eno_getc, eno_putc, D_TTY
163 },
164 {
165 nulldev, nulldev, mmread, mmwrite, /* 3*/
166 eno_ioctl, nulldev, nulldev, 0, mmselect,
167 mmmmap, eno_strat, eno_getc, eno_putc, 0
168 },
169 {
170 ptsopen, ptsclose, ptsread, ptswrite, /* 4*/
171 ptyioctl, ptsstop, nulldev, pt_tty, ttselect,
172 eno_mmap, eno_strat, eno_getc, eno_putc, D_TTY
173 },
174 {
175 ptcopen, ptcclose, ptcread, ptcwrite, /* 5*/
176 ptyioctl, nulldev, nulldev, 0, ptcselect,
177 eno_mmap, eno_strat, eno_getc, eno_putc, D_TTY
178 },
179 {
180 logopen, logclose, logread, eno_rdwrt, /* 6*/
181 logioctl, eno_stop, nulldev, 0, logselect,
182 eno_mmap, eno_strat, eno_getc, eno_putc, 0
183 },
184 NO_CDEVICE, /* 7*/
185 NO_CDEVICE, /* 8*/
186 NO_CDEVICE, /* 9*/
187 NO_CDEVICE, /*10*/
188 NO_CDEVICE, /*11*/
189 {
190 kmopen, kmclose, kmread, kmwrite, /*12*/
191 kmioctl, nulldev, nulldev, km_tty, ttselect,
192 eno_mmap, eno_strat, kmgetc, kmputc, 0
193 },
194 NO_CDEVICE, /*13*/
195 NO_CDEVICE, /*14*/
196 NO_CDEVICE, /*15*/
197
198 /* 16 - 31 are reserved to the user */
199 NO_CDEVICE, /*16*/
200 NO_CDEVICE, /*17*/
201 NO_CDEVICE, /*18*/
202 NO_CDEVICE, /*19*/
203 NO_CDEVICE, /*20*/
204 NO_CDEVICE, /*21*/
205 NO_CDEVICE, /*22*/
206 NO_CDEVICE, /*23*/
207 NO_CDEVICE, /*24*/
208 NO_CDEVICE, /*25*/
209 NO_CDEVICE, /*26*/
210 NO_CDEVICE, /*27*/
211 NO_CDEVICE, /*28*/
212 NO_CDEVICE, /*29*/
213 NO_CDEVICE, /*30*/
214 NO_CDEVICE, /*31*/
215
216 /* 32 - 47 are reserved to NeXT */
217 {
218 fdesc_open, eno_opcl, fdesc_read, fdesc_write, /*32*/
219 fdesc_ioctl, eno_stop, eno_reset, 0, fdesc_select,
220 eno_mmap, eno_strat, eno_getc, eno_putc, 0
221 },
222 #if 1
223 NO_CDEVICE,
224 #else
225 {
226 sgopen, sgclose, eno_rdwrt, eno_rdwrt, /*33*/
227 sgioctl, eno_stop, eno_reset, 0, eno_select,
228 eno_mmap, eno_strat, eno_getc, eno_putc, D_TAPE
229 },
230 #endif
231 NO_CDEVICE, /*34*/
232 NO_CDEVICE, /*35*/
233 NO_CDEVICE, /*36*/
234 NO_CDEVICE, /*37*/
235 NO_CDEVICE, /*38*/
236 NO_CDEVICE, /*39*/
237 NO_CDEVICE, /*40*/
238 NO_CDEVICE, /*41*/
239 {
240 volopen, volclose, eno_rdwrt, eno_rdwrt, /*42*/
241 volioctl, eno_stop, eno_reset, 0, seltrue,
242 eno_mmap, eno_strat, eno_getc, eno_putc, 0
243 },
244 };
245 int nchrdev = sizeof (cdevsw) / sizeof (cdevsw[0]);
246
247
248 #include <sys/vnode.h> /* for VCHR and VBLK */
249 /*
250 * return true if a disk
251 */
252 int
253 isdisk(dev, type)
254 dev_t dev;
255 int type;
256 {
257 switch (major(dev)) {
258 case 1: /* fd: floppy */
259 case 6: /* sd: scsi disk */
260 case 3: /* ide: */
261 if (type == VBLK)
262 return(1);
263 break;
264 case 14: /* sd: scsi disk */
265 case 41: /* fd: floppy */
266 if (type == VCHR)
267 return(1);
268 break;
269 }
270 return(0);
271 }
272
273 static 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 */
303 dev_t
304 chrtoblk(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
317 /*
318 * Returns true if dev is /dev/mem or /dev/kmem.
319 */
320 int iskmemdev(dev)
321 dev_t dev;
322 {
323
324 return (major(dev) == 3 && minor(dev) < 2);
325 }