]> git.saurik.com Git - apple/xnu.git/blob - bsd/dev/ppc/conf.c
ba13fc3ee874bfe3bbe8b1da8832b9530d3726f2
[apple/xnu.git] / bsd / dev / ppc / conf.c
1 /*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
7 *
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
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
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.
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
47 extern int nulldev();
48
49 struct 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
92 int nblkdev = sizeof (bdevsw) / sizeof (bdevsw[0]);
93
94 extern struct tty *km_tty[];
95 extern int consopen(), consclose(), consread(), conswrite(), consioctl(),
96 consselect(), cons_getc(), cons_putc();
97 extern int kmopen(),kmclose(),kmread(),kmwrite(),kmioctl(),
98 kmgetc(), kmputc(dev_t dev, char c);
99
100 extern int cttyopen(), cttyread(), cttywrite(), cttyioctl(), cttyselect();
101
102 extern int mmread(),mmwrite();
103 #define mmselect seltrue
104
105 #if 1
106 #define NPTY 32
107 #else /* 1 */
108 #include <pty.h>
109 #endif /* 1 */
110 #if NPTY > 0
111 extern struct tty *pt_tty[];
112 extern int ptsopen(),ptsclose(),ptsread(),ptswrite(),ptsstop(),ptsputc();
113 extern int ptcopen(),ptcclose(),ptcread(),ptcwrite(),ptcselect(),
114 ptyioctl();
115 #else
116 #define ptsopen eno_opcl
117 #define ptsclose eno_opcl
118 #define ptsread eno_rdwrt
119 #define ptswrite eno_rdwrt
120 #define ptsstop nulldev
121 #define ptsputc nulldev
122
123 #define ptcopen eno_opcl
124 #define ptcclose eno_opcl
125 #define ptcread eno_rdwrt
126 #define ptcwrite eno_rdwrt
127 #define ptcselect eno_select
128 #define ptyioctl eno_ioctl
129 #endif
130
131 extern int logopen(),logclose(),logread(),logioctl(),logselect();
132 extern int seltrue();
133
134 struct cdevsw cdevsw[] =
135 {
136 /*
137 * For character devices, every other block of 16 slots is
138 * reserved to NeXT. The other slots are available for
139 * the user. This way we can both add new entries without
140 * running into each other. Be sure to fill in NeXT's
141 * 16 reserved slots when you jump over us -- we'll do the
142 * same for you.
143 */
144
145 /* 0 - 15 are reserved to NeXT */
146
147 {
148 consopen, consclose, consread, conswrite, /* 0*/
149 consioctl, nulldev, nulldev, 0, consselect,
150 eno_mmap, eno_strat, cons_getc, cons_putc, D_TTY
151 },
152 NO_CDEVICE, /* 1*/
153 {
154 cttyopen, nulldev, cttyread, cttywrite, /* 2*/
155 cttyioctl, nulldev, nulldev, 0, cttyselect,
156 eno_mmap, eno_strat, eno_getc, eno_putc, D_TTY
157 },
158 {
159 nulldev, nulldev, mmread, mmwrite, /* 3*/
160 eno_ioctl, nulldev, nulldev, 0, mmselect,
161 eno_mmap, eno_strat, eno_getc, eno_putc, 0
162 },
163 {
164 ptsopen, ptsclose, ptsread, ptswrite, /* 4*/
165 ptyioctl, ptsstop, nulldev, pt_tty, ttselect,
166 eno_mmap, eno_strat, eno_getc, eno_putc, D_TTY
167 },
168 {
169 ptcopen, ptcclose, ptcread, ptcwrite, /* 5*/
170 ptyioctl, nulldev, nulldev, 0, ptcselect,
171 eno_mmap, eno_strat, eno_getc, eno_putc, D_TTY
172 },
173 {
174 logopen, logclose, logread, eno_rdwrt, /* 6*/
175 logioctl, eno_stop, nulldev, 0, logselect,
176 eno_mmap, eno_strat, eno_getc, eno_putc, 0
177 },
178 NO_CDEVICE, /* 7*/
179 NO_CDEVICE, /* 8*/
180 NO_CDEVICE, /* 9*/
181 NO_CDEVICE, /*10*/
182 NO_CDEVICE, /*11*/
183 {
184 kmopen, kmclose, kmread, kmwrite, /*12*/
185 kmioctl, nulldev, nulldev, km_tty, ttselect,
186 eno_mmap, eno_strat, kmgetc, kmputc, 0
187 },
188 NO_CDEVICE, /*13*/
189 NO_CDEVICE, /*14*/
190 NO_CDEVICE, /*15*/
191
192 /* 16 - 31 are reserved to the user */
193 NO_CDEVICE, /*16*/
194 NO_CDEVICE, /*17*/
195 NO_CDEVICE, /*18*/
196 NO_CDEVICE, /*19*/
197 NO_CDEVICE, /*20*/
198 NO_CDEVICE, /*21*/
199 NO_CDEVICE, /*22*/
200 NO_CDEVICE, /*23*/
201 NO_CDEVICE, /*24*/
202 NO_CDEVICE, /*25*/
203 NO_CDEVICE, /*26*/
204 NO_CDEVICE, /*27*/
205 NO_CDEVICE, /*28*/
206 NO_CDEVICE, /*29*/
207 NO_CDEVICE, /*30*/
208 NO_CDEVICE, /*31*/
209
210 /* 32 - 47 are reserved to NeXT */
211 NO_CDEVICE, /*32*/
212 NO_CDEVICE, /*33*/
213 NO_CDEVICE, /*34*/
214 NO_CDEVICE, /*35*/
215 NO_CDEVICE, /*36*/
216 /* 37 used to be for nvram */
217 NO_CDEVICE, /*37*/
218 NO_CDEVICE, /*38*/
219 NO_CDEVICE, /*39*/
220 NO_CDEVICE, /*40*/
221 /* 41 used to be for fd */
222 NO_CDEVICE, /*41*/
223 NO_CDEVICE, /*42*/
224 };
225 int nchrdev = sizeof (cdevsw) / sizeof (cdevsw[0]);
226
227
228 #include <sys/vnode.h> /* for VCHR and VBLK */
229 /*
230 * return true if a disk
231 */
232 int
233 isdisk(dev, type)
234 dev_t dev;
235 int type;
236 {
237 dev_t maj = major(dev);
238
239 switch (type) {
240 case VCHR:
241 maj = chrtoblk(maj);
242 if (maj == NODEV) {
243 break;
244 }
245 /* FALL THROUGH */
246 case VBLK:
247 if (bdevsw[maj].d_type == D_DISK) {
248 return (1);
249 }
250 break;
251 }
252 return(0);
253 }
254
255 static int chrtoblktab[] = {
256 /* CHR*/ /* BLK*/ /* CHR*/ /* BLK*/
257 /* 0 */ NODEV, /* 1 */ NODEV,
258 /* 2 */ NODEV, /* 3 */ NODEV,
259 /* 4 */ NODEV, /* 5 */ NODEV,
260 /* 6 */ NODEV, /* 7 */ NODEV,
261 /* 8 */ NODEV, /* 9 */ NODEV,
262 /* 10 */ NODEV, /* 11 */ NODEV,
263 /* 12 */ NODEV, /* 13 */ NODEV,
264 /* 14 */ 6, /* 15 */ NODEV,
265 /* 16 */ NODEV, /* 17 */ NODEV,
266 /* 18 */ NODEV, /* 19 */ NODEV,
267 /* 20 */ NODEV, /* 21 */ NODEV,
268 /* 22 */ NODEV, /* 23 */ NODEV,
269 /* 24 */ NODEV, /* 25 */ NODEV,
270 /* 26 */ NODEV, /* 27 */ NODEV,
271 /* 28 */ NODEV, /* 29 */ NODEV,
272 /* 30 */ NODEV, /* 31 */ NODEV,
273 /* 32 */ NODEV, /* 33 */ NODEV,
274 /* 34 */ NODEV, /* 35 */ NODEV,
275 /* 36 */ NODEV, /* 37 */ NODEV,
276 /* 38 */ NODEV, /* 39 */ NODEV,
277 /* 40 */ NODEV, /* 41 */ 1,
278 /* 42 */ NODEV, /* 43 */ NODEV,
279 /* 44 */ NODEV,
280 };
281
282 /*
283 * convert chr dev to blk dev
284 */
285 dev_t
286 chrtoblk(dev)
287 dev_t dev;
288 {
289 int blkmaj;
290
291 if (major(dev) >= nchrdev)
292 return(NODEV);
293 blkmaj = chrtoblktab[major(dev)];
294 if (blkmaj == NODEV)
295 return(NODEV);
296 return(makedev(blkmaj, minor(dev)));
297 }
298
299 int
300 chrtoblk_set(int cdev, int bdev)
301 {
302 if (cdev >= nchrdev)
303 return (NODEV);
304 if (bdev != NODEV && bdev >= nblkdev)
305 return (NODEV);
306 chrtoblktab[cdev] = bdev;
307 return 0;
308 }
309
310 /*
311 * Returns true if dev is /dev/mem or /dev/kmem.
312 */
313 int iskmemdev(dev)
314 dev_t dev;
315 {
316
317 return (major(dev) == 3 && minor(dev) < 2);
318 }