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