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