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