conf.c revision 1.18 1 /* $NetBSD: conf.c,v 1.18 1999/04/19 21:23:00 kleink 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 "opt_compat_svr4.h"
39
40 #include <sys/param.h>
41 #include <sys/systm.h>
42 #include <sys/buf.h>
43 #include <sys/ioctl.h>
44 #include <sys/tty.h>
45 #include <sys/conf.h>
46 #include <sys/vnode.h>
47
48 bdev_decl(sw);
49 #include "sd.h"
50 bdev_decl(sd);
51 #include "ccd.h"
52 bdev_decl(ccd);
53 #include "raid.h"
54 bdev_decl(raid);
55 #include "vnd.h"
56 bdev_decl(vnd);
57 #include "st.h"
58 bdev_decl(st);
59 #include "cd.h"
60 bdev_decl(cd);
61 #include "md.h"
62 bdev_decl(md);
63
64 struct bdevsw bdevsw[] =
65 {
66 bdev_notdef(), /* 0 */
67 bdev_notdef(), /* 1 */
68 bdev_notdef(), /* 2 */
69 bdev_swap_init(1,sw), /* 3: swap pseudo-device */
70 bdev_disk_init(NSD,sd), /* 4: SCSI disk */
71 bdev_disk_init(NCCD,ccd), /* 5: concatenated disk driver */
72 bdev_disk_init(NVND,vnd), /* 6: vnode disk driver */
73 bdev_tape_init(NST,st), /* 7: SCSI tape */
74 bdev_disk_init(NCD,cd), /* 8: SCSI CD-ROM */
75 bdev_disk_init(NMD,md), /* 9: memory disk - for install tape */
76 bdev_lkm_dummy(), /* 10 */
77 bdev_lkm_dummy(), /* 11 */
78 bdev_lkm_dummy(), /* 12 */
79 bdev_lkm_dummy(), /* 13 */
80 bdev_lkm_dummy(), /* 14 */
81 bdev_lkm_dummy(), /* 15 */
82 bdev_disk_init(NRAID,raid), /* 16: RAIDframe disk driver */
83 };
84
85 int nblkdev = sizeof (bdevsw) / sizeof (bdevsw[0]);
86
87 cdev_decl(cn);
88 cdev_decl(ctty);
89 #define mmread mmrw
90 #define mmwrite mmrw
91 cdev_decl(mm);
92 cdev_decl(sw);
93
94 #include "pty.h"
95 #define ptstty ptytty
96 #define ptsioctl ptyioctl
97 cdev_decl(pts);
98 #define ptctty ptytty
99 #define ptcioctl ptyioctl
100 cdev_decl(ptc);
101
102 cdev_decl(log);
103 cdev_decl(fd);
104
105 #include "zstty.h"
106 cdev_decl(zs);
107
108 #include "clmpcc.h"
109 cdev_decl(clmpcc);
110
111 cdev_decl(cd);
112 #include "ch.h"
113 cdev_decl(ch);
114 cdev_decl(sd);
115 #include "ss.h"
116 cdev_decl(ss);
117 cdev_decl(st);
118 #include "uk.h"
119 cdev_decl(uk);
120
121 cdev_decl(md);
122 cdev_decl(vnd);
123 cdev_decl(ccd);
124 cdev_decl(raid);
125
126 dev_decl(filedesc,open);
127
128 #include "bpfilter.h"
129 cdev_decl(bpf);
130
131 #include "tun.h"
132 cdev_decl(tun);
133
134 #include "lpt.h"
135 cdev_decl(lpt);
136 /* open, close, write, ioctl */
137 #define cdev_lpt_init(c,n) { \
138 dev_init(c,n,open), dev_init(c,n,close), (dev_type_read((*)))enodev, \
139 dev_init(c,n,write), dev_init(c,n,ioctl), (dev_type_stop((*)))enodev, \
140 0, seltrue, (dev_type_mmap((*))) enodev, 0}
141
142 #include "ipfilter.h"
143 #include "rnd.h"
144
145 #include "scsibus.h"
146 cdev_decl(scsibus);
147
148 struct cdevsw cdevsw[] =
149 {
150 cdev_cn_init(1,cn), /* 0: virtual console */
151 cdev_ctty_init(1,ctty), /* 1: controlling terminal */
152 cdev_mm_init(1,mm), /* 2: /dev/{null,mem,kmem,...} */
153 cdev_swap_init(1,sw), /* 3: /dev/drum (swap pseudo-device) */
154 cdev_tty_init(NPTY,pts), /* 4: pseudo-tty slave */
155 cdev_ptc_init(NPTY,ptc), /* 5: pseudo-tty master */
156 cdev_log_init(1,log), /* 6: /dev/klog */
157 cdev_ipf_init(NIPFILTER,ipl), /* 7: ip-filter device */
158 cdev_disk_init(NSD,sd), /* 8: SCSI disk */
159 cdev_notdef(), /* 9 */
160 cdev_notdef(), /* 10 */
161 cdev_lpt_init(NLPT,lpt), /* 11: parallel interface */
162 cdev_tty_init(NZSTTY,zs), /* 12: SCC serial ports */
163 cdev_tty_init(NCLMPCC,clmpcc), /* 13: CD2401 serial ports */
164 cdev_notdef(), /* 14 */
165 cdev_notdef(), /* 15 */
166 cdev_notdef(), /* 16 */
167 cdev_disk_init(NCCD,ccd), /* 17: concatenated disk driver */
168 cdev_disk_init(NCD,cd), /* 18: SCSI CD-ROM */
169 cdev_disk_init(NVND,vnd), /* 19: vnode disk */
170 cdev_tape_init(NST,st), /* 20: SCSI tape */
171 cdev_fd_init(1,filedesc), /* 21: file descriptor pseudo-dev */
172 cdev_bpftun_init(NBPFILTER,bpf),/* 22: berkeley packet filter */
173 cdev_bpftun_init(NTUN,tun), /* 23: network tunnel */
174 cdev_lkm_init(NLKM,lkm), /* 24: loadable module driver */
175 cdev_lkm_dummy(), /* 25 */
176 cdev_lkm_dummy(), /* 26 */
177 cdev_lkm_dummy(), /* 27 */
178 cdev_lkm_dummy(), /* 28 */
179 cdev_lkm_dummy(), /* 29 */
180 cdev_lkm_dummy(), /* 30 */
181 cdev_ch_init(NCH,ch), /* 31: SCSI autochanger */
182 cdev_disk_init(NMD,md), /* 32: memory disk driver */
183 cdev_scanner_init(NSS,ss), /* 33: SCSI scanner */
184 cdev_uk_init(NUK,uk), /* 34: SCSI unknown */
185 cdev_rnd_init(NRND,rnd), /* 35: random source pseudo-device */
186 cdev_scsibus_init(NSCSIBUS,scsibus), /* 36: SCSI bus */
187 cdev_disk_init(NRAID,raid) /* 37: RAIDframe disk driver */
188 cdev_svr4_net_init(NSVR4_NET,svr4_net), /* 38: svr4 net pseudo-device */
189 };
190
191 int nchrdev = sizeof (cdevsw) / sizeof (cdevsw[0]);
192
193 int mem_no = 2; /* major device number of memory special file */
194
195 /*
196 * Swapdev is a fake device implemented
197 * in sw.c used only internally to get to swstrategy.
198 * It cannot be provided to the users, because the
199 * swstrategy routine munches the b_dev and b_blkno entries
200 * before calling the appropriate driver. This would horribly
201 * confuse, e.g. the hashing routines. Instead, /dev/drum is
202 * provided as a character (raw) device.
203 */
204 dev_t swapdev = makedev(3, 0);
205
206 /*
207 * Returns true if dev is /dev/mem or /dev/kmem.
208 */
209 iskmemdev(dev)
210 dev_t dev;
211 {
212
213 return (major(dev) == mem_no && minor(dev) < 2);
214 }
215
216 /*
217 * Returns true if dev is /dev/zero.
218 */
219 iszerodev(dev)
220 dev_t dev;
221 {
222
223 return (major(dev) == mem_no && minor(dev) == 12);
224 }
225
226 static int chrtoblktbl[] = {
227 /* XXXX This needs to be dynamic for LKMs. */
228 /*VCHR*/ /*VBLK*/
229 /* 0 */ NODEV,
230 /* 1 */ NODEV,
231 /* 2 */ NODEV,
232 /* 3 */ 3, /* sw */
233 /* 4 */ NODEV,
234 /* 5 */ NODEV,
235 /* 6 */ NODEV,
236 /* 7 */ NODEV,
237 /* 8 */ 4, /* sd */
238 /* 9 */ NODEV,
239 /* 10 */ NODEV,
240 /* 11 */ NODEV,
241 /* 12 */ NODEV,
242 /* 13 */ NODEV,
243 /* 14 */ NODEV,
244 /* 15 */ NODEV,
245 /* 16 */ NODEV,
246 /* 17 */ 5, /* ccd */
247 /* 18 */ 8, /* cd */
248 /* 19 */ 6, /* vnd */
249 /* 20 */ 7, /* st */
250 /* 21 */ NODEV,
251 /* 22 */ NODEV,
252 /* 23 */ NODEV,
253 /* 24 */ NODEV,
254 /* 25 */ NODEV,
255 /* 26 */ NODEV,
256 /* 27 */ NODEV,
257 /* 28 */ NODEV,
258 /* 29 */ NODEV,
259 /* 30 */ NODEV,
260 /* 31 */ NODEV,
261 /* 32 */ 9, /* md */
262 /* 33 */ NODEV,
263 /* 34 */ NODEV,
264 /* 35 */ NODEV,
265 /* 36 */ NODEV,
266 /* 37 */ 16, /* RAIDframe */
267 };
268
269 /*
270 * Convert a character device number to a block device number.
271 */
272 dev_t
273 chrtoblk(dev)
274 dev_t dev;
275 {
276 int blkmaj;
277
278 if (major(dev) >= nchrdev
279 || major(dev) >= (sizeof(chrtoblktbl) / sizeof(chrtoblktbl[0])))
280 return (NODEV);
281 blkmaj = chrtoblktbl[major(dev)];
282 if (blkmaj == NODEV)
283 return (NODEV);
284 return (makedev(blkmaj, minor(dev)));
285 }
286
287 /*
288 * This entire table could be autoconfig()ed but that would mean that
289 * the kernel's idea of the console would be out of sync with that of
290 * the standalone boot. I think it best that they both use the same
291 * known algorithm unless we see a pressing need otherwise.
292 */
293 #include <dev/cons.h>
294
295 #define zsc_pcccngetc zscngetc
296 #define zsc_pcccnputc zscnputc
297 #define zsc_pcccnpollc nullcnpollc
298 #include "zsc_pcc.h"
299 cons_decl(zsc_pcc);
300
301 #define clmpcccnpollc nullcnpollc
302 #include "clmpcc_pcctwo.h"
303 cons_decl(clmpcc);
304
305
306 struct consdev constab[] = {
307 #if NZSC_PCC > 0
308 cons_init(zsc_pcc),
309 #endif
310 #if NCLMPCC_PCCTWO > 0
311 cons_init(clmpcc),
312 #endif
313 { 0 },
314 };
315