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