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