conf.c revision 1.6 1 /* $NetBSD: conf.c,v 1.6 1996/05/20 01:16:50 chuck Exp $ */
2
3 /*-
4 * Copyright (c) 1991 The Regents of the University of California.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement:
17 * This product includes software developed by the University of
18 * California, Berkeley and its contributors.
19 * 4. Neither the name of the University nor the names of its contributors
20 * may be used to endorse or promote products derived from this software
21 * without specific prior written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * SUCH DAMAGE.
34 *
35 * @(#)conf.c 7.9 (Berkeley) 5/28/91
36 */
37
38 #include <sys/param.h>
39 #include <sys/systm.h>
40 #include <sys/buf.h>
41 #include <sys/ioctl.h>
42 #include <sys/tty.h>
43 #include <sys/conf.h>
44 #include <sys/vnode.h>
45
46 int ttselect __P((dev_t, int, struct proc *));
47
48 #ifdef LKM
49 int lkmenodev();
50 #else
51 #define lkmenodev enodev
52 #endif
53
54 bdev_decl(sw);
55 #include "sd.h"
56 bdev_decl(sd);
57 #include "ccd.h"
58 bdev_decl(ccd);
59 #include "vnd.h"
60 bdev_decl(vnd);
61 #include "st.h"
62 bdev_decl(st);
63 #include "cd.h"
64 bdev_decl(cd);
65 #include "rd.h"
66 bdev_decl(rd);
67
68 struct bdevsw bdevsw[] =
69 {
70 bdev_notdef(), /* 0 */
71 bdev_notdef(), /* 1 */
72 bdev_notdef(), /* 2 */
73 bdev_swap_init(1,sw), /* 3: swap pseudo-device */
74 bdev_disk_init(NSD,sd), /* 4: SCSI disk */
75 bdev_disk_init(NCCD,ccd), /* 5: concatenated disk driver */
76 bdev_disk_init(NVND,vnd), /* 6: vnode disk driver */
77 bdev_tape_init(NST,st), /* 7: SCSI tape */
78 bdev_disk_init(NCD,cd), /* 8: SCSI CD-ROM */
79 bdev_disk_init(NRD,rd), /* 9: RAM disk - for install tape */
80 bdev_lkm_dummy(), /* 10 */
81 bdev_lkm_dummy(), /* 11 */
82 bdev_lkm_dummy(), /* 12 */
83 bdev_lkm_dummy(), /* 13 */
84 bdev_lkm_dummy(), /* 14 */
85 bdev_lkm_dummy(), /* 15 */
86 };
87
88 int nblkdev = sizeof (bdevsw) / sizeof (bdevsw[0]);
89
90 cdev_decl(cn);
91 cdev_decl(ctty);
92 #define mmread mmrw
93 #define mmwrite mmrw
94 cdev_decl(mm);
95 cdev_decl(sw);
96
97 #include "pty.h"
98 #define ptstty ptytty
99 #define ptsioctl ptyioctl
100 cdev_decl(pts);
101 #define ptctty ptytty
102 #define ptcioctl ptyioctl
103 cdev_decl(ptc);
104
105 cdev_decl(log);
106 cdev_decl(fd);
107
108 #include "zstty.h"
109 cdev_decl(zs);
110
111 cdev_decl(sd);
112 cdev_decl(cd);
113 cdev_decl(st);
114 cdev_decl(vnd);
115 cdev_decl(ccd);
116
117 dev_decl(filedesc,open);
118
119 #include "bpfilter.h"
120 cdev_decl(bpf);
121
122 #include "tun.h"
123 cdev_decl(tun);
124 #ifdef LKM
125 #define NLKM 1
126 #else
127 #define NLKM 0
128 #endif
129 cdev_decl(lkm);
130
131 struct cdevsw cdevsw[] =
132 {
133 cdev_cn_init(1,cn), /* 0: virtual console */
134 cdev_ctty_init(1,ctty), /* 1: controlling terminal */
135 cdev_mm_init(1,mm), /* 2: /dev/{null,mem,kmem,...} */
136 cdev_swap_init(1,sw), /* 3: /dev/drum (swap pseudo-device) */
137 cdev_tty_init(NPTY,pts), /* 4: pseudo-tty slave */
138 cdev_ptc_init(NPTY,ptc), /* 5: pseudo-tty master */
139 cdev_log_init(1,log), /* 6: /dev/klog */
140 cdev_notdef(), /* 7 */
141 cdev_disk_init(NSD,sd), /* 8: SCSI disk */
142 cdev_notdef(), /* 9 */
143 cdev_notdef(), /* 10 */
144 cdev_notdef(), /* 11: parallel interface */
145 cdev_tty_init(NZSTTY,zs), /* 12: SCC serial ports */
146 cdev_notdef(), /* 13 */
147 cdev_notdef(), /* 14 */
148 cdev_notdef(), /* 15 */
149 cdev_notdef(), /* 16 */
150 cdev_disk_init(NCCD,ccd), /* 17: concatenated disk driver */
151 cdev_disk_init(NCD,cd), /* 18: SCSI CD-ROM */
152 cdev_disk_init(NVND,vnd), /* 19: vnode disk */
153 cdev_tape_init(NST,st), /* 20: SCSI tape */
154 cdev_fd_init(1,filedesc), /* 21: file descriptor pseudo-dev */
155 cdev_bpftun_init(NBPFILTER,bpf),/* 22: berkeley packet filter */
156 cdev_bpftun_init(NTUN,tun), /* 23: network tunnel */
157 cdev_lkm_init(NLKM,lkm), /* 24: loadable module driver */
158 cdev_lkm_dummy(), /* 25 */
159 cdev_lkm_dummy(), /* 26 */
160 cdev_lkm_dummy(), /* 27 */
161 cdev_lkm_dummy(), /* 28 */
162 cdev_lkm_dummy(), /* 29 */
163 cdev_lkm_dummy(), /* 30 */
164 };
165
166 int nchrdev = sizeof (cdevsw) / sizeof (cdevsw[0]);
167
168 int mem_no = 2; /* major device number of memory special file */
169
170 /*
171 * Swapdev is a fake device implemented
172 * in sw.c used only internally to get to swstrategy.
173 * It cannot be provided to the users, because the
174 * swstrategy routine munches the b_dev and b_blkno entries
175 * before calling the appropriate driver. This would horribly
176 * confuse, e.g. the hashing routines. Instead, /dev/drum is
177 * provided as a character (raw) device.
178 */
179 dev_t swapdev = makedev(3, 0);
180
181 /*
182 * Returns true if dev is /dev/mem or /dev/kmem.
183 */
184 iskmemdev(dev)
185 dev_t dev;
186 {
187
188 return (major(dev) == mem_no && minor(dev) < 2);
189 }
190
191 /*
192 * Returns true if dev is /dev/zero.
193 */
194 iszerodev(dev)
195 dev_t dev;
196 {
197
198 return (major(dev) == mem_no && minor(dev) == 12);
199 }
200
201 /*
202 * Returns true if dev is a disk device.
203 */
204 isdisk(dev, type)
205 dev_t dev;
206 int type;
207 {
208
209 /* XXXX This needs to be dynamic for LKMs. */
210 switch (major(dev)) {
211 case 1:
212 case 2:
213 case 4:
214 case 6:
215 case 15:
216 return (type == VBLK);
217 case 8:
218 case 9:
219 case 10:
220 case 17:
221 case 19:
222 return (type == VCHR);
223 default:
224 return (0);
225 }
226 }
227
228 static int chrtoblktbl[] = {
229 /* XXXX This needs to be dynamic for LKMs. */
230 /*VCHR*/ /*VBLK*/
231 /* 0 */ NODEV,
232 /* 1 */ NODEV,
233 /* 2 */ NODEV,
234 /* 3 */ NODEV,
235 /* 4 */ NODEV,
236 /* 5 */ NODEV,
237 /* 6 */ NODEV,
238 /* 7 */ NODEV,
239 /* 8 */ 4,
240 /* 9 */ 7,
241 /* 10 */ NODEV,
242 /* 11 */ NODEV,
243 /* 12 */ NODEV,
244 /* 13 */ NODEV,
245 /* 14 */ NODEV,
246 /* 15 */ NODEV,
247 /* 16 */ NODEV,
248 /* 17 */ 15,
249 /* 18 */ NODEV,
250 /* 19 */ 6,
251 /* 20 */ NODEV,
252 /* 21 */ NODEV,
253 /* 22 */ NODEV,
254 };
255
256 /*
257 * Convert a character device number to a block device number.
258 */
259 chrtoblk(dev)
260 dev_t dev;
261 {
262 int blkmaj;
263
264 if (major(dev) >= nchrdev)
265 return (NODEV);
266 blkmaj = chrtoblktbl[major(dev)];
267 if (blkmaj == NODEV)
268 return (NODEV);
269 return (makedev(blkmaj, minor(dev)));
270 }
271
272 /*
273 * This entire table could be autoconfig()ed but that would mean that
274 * the kernel's idea of the console would be out of sync with that of
275 * the standalone boot. I think it best that they both use the same
276 * known algorithm unless we see a pressing need otherwise.
277 */
278 #include <dev/cons.h>
279
280 #define zsc_pcccngetc zscngetc
281 #define zsc_pcccnputc zscnputc
282 #define zsc_pcccnpollc nullcnpollc
283 #include "zsc_pcc.h"
284 cons_decl(zsc_pcc);
285
286 struct consdev constab[] = {
287 #if NZSC_PCC > 0
288 cons_init(zsc_pcc),
289 #endif
290 { 0 },
291 };
292