xref: /netbsd/sys/arch/evbsh3/evbsh3/conf.c (revision bf9ec67e)
1 /*	$NetBSD: conf.c,v 1.5 2002/01/12 13:11:08 manu Exp $	*/
2 
3 /*
4  * Copyright (c) 1994, 1995 Charles M. Hannum.  All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  * 3. All advertising materials mentioning features or use of this software
15  *    must display the following acknowledgement:
16  *	This product includes software developed by Charles Hannum.
17  * 4. The name of the author may not be used to endorse or promote products
18  *    derived from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
24  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 #include <sys/param.h>
33 #include <sys/systm.h>
34 #include <sys/buf.h>
35 #include <sys/ioctl.h>
36 #include <sys/tty.h>
37 #include <sys/conf.h>
38 #include <sys/vnode.h>
39 
40 #include <machine/conf.h>
41 
42 #include "wd.h"
43 bdev_decl(wd);
44 bdev_decl(sw);
45 #include "sd.h"
46 bdev_decl(sd);
47 #include "st.h"
48 bdev_decl(st);
49 #include "cd.h"
50 bdev_decl(cd);
51 #include "vnd.h"
52 bdev_decl(vnd);
53 #include "ccd.h"
54 bdev_decl(ccd);
55 #include "raid.h"
56 bdev_decl(raid);
57 #include "md.h"
58 bdev_decl(md);
59 
60 struct bdevsw	bdevsw[] =
61 {
62 	bdev_disk_init(NWD,wd),		/* 0: ST506/ESDI/IDE disk */
63 	bdev_swap_init(1,sw),		/* 1: swap pseudo-device */
64 	bdev_notdef(),			/* 2 (was floppy diskette) */
65 	bdev_notdef(),			/* 3 (was QIC-02/QIC-36 tape) */
66 	bdev_disk_init(NSD,sd),		/* 4: SCSI disk */
67 	bdev_tape_init(NST,st),		/* 5: SCSI tape */
68 	bdev_disk_init(NCD,cd),		/* 6: SCSI CD-ROM */
69 	bdev_notdef(),			/* 7 (was Mitsumi CD-ROM) */
70 	bdev_lkm_dummy(),		/* 8 */
71 	bdev_lkm_dummy(),		/* 9 */
72 	bdev_lkm_dummy(),		/* 10 */
73 	bdev_lkm_dummy(),		/* 11 */
74 	bdev_lkm_dummy(),		/* 12 */
75 	bdev_lkm_dummy(),		/* 13 */
76 	bdev_disk_init(NVND,vnd),	/* 14: vnode disk driver */
77 	bdev_notdef(),			/* 15 (was Sony CD-ROM) */
78 	bdev_disk_init(NCCD,ccd),	/* 16: concatenated disk driver */
79 	bdev_disk_init(NMD,md),		/* 17: memory disk driver */
80 	bdev_disk_init(NRAID,raid),	/* 18: RAIDframe disk driver */
81 };
82 int	nblkdev = sizeof(bdevsw) / sizeof(bdevsw[0]);
83 
84 cdev_decl(cn);
85 cdev_decl(ctty);
86 #define	mmread	mmrw
87 #define	mmwrite	mmrw
88 cdev_decl(mm);
89 #include "wdog.h"
90 cdev_decl(wdog);
91 cdev_decl(wd);
92 cdev_decl(sw);
93 #include "pty.h"
94 #define	ptstty		ptytty
95 #define	ptsioctl	ptyioctl
96 cdev_decl(pts);
97 #define	ptctty		ptytty
98 #define	ptcioctl	ptyioctl
99 cdev_decl(ptc);
100 cdev_decl(log);
101 #include "com.h"
102 cdev_decl(com);
103 #include "sci.h"
104 cdev_decl(sci);
105 #include "scif.h"
106 cdev_decl(scif);
107 cdev_decl(fd);
108 cdev_decl(sd);
109 cdev_decl(st);
110 #include "ss.h"
111 cdev_decl(ss);
112 #include "uk.h"
113 cdev_decl(uk);
114 cdev_decl(cd);
115 #include "ch.h"
116 cdev_decl(ch);
117 dev_decl(filedesc,open);
118 #include "bpfilter.h"
119 cdev_decl(bpf);
120 cdev_decl(md);
121 #include "cy.h"
122 cdev_decl(cy);
123 #include "tun.h"
124 cdev_decl(tun);
125 cdev_decl(vnd);
126 #include "audio.h"
127 cdev_decl(audio);
128 cdev_decl(svr4_net);
129 cdev_decl(ccd);
130 cdev_decl(raid);
131 #include "vcoda.h"
132 cdev_decl(vc_nb_);
133 
134 #include "esh.h"
135 cdev_decl(esh_fp);
136 #include "scsibus.h"
137 cdev_decl(scsibus);
138 
139 #include "ipfilter.h"
140 #include "rnd.h"
141 
142 #include "clockctl.h"
143 cdev_decl(clockctl);
144 
145 struct cdevsw	cdevsw[] =
146 {
147 	cdev_cn_init(1,cn),		/* 0: virtual console */
148 	cdev_ctty_init(1,ctty),		/* 1: controlling terminal */
149 	cdev_mm_init(1,mm),		/* 2: /dev/{null,mem,kmem,...} */
150 	cdev_disk_init(NWD,wd),		/* 3: ST506/ESDI/IDE disk */
151 	cdev_swap_init(1,sw),		/* 4: /dev/drum (swap pseudo-device) */
152 	cdev_tty_init(NPTY,pts),	/* 5: pseudo-tty slave */
153 	cdev_ptc_init(NPTY,ptc),	/* 6: pseudo-tty master */
154 	cdev_log_init(1,log),		/* 7: /dev/klog */
155 	cdev_tty_init(NCOM,com),	/* 8: serial port */
156 	cdev_notdef(),			/* 9 (was floppy disk) */
157 	cdev_tty_init(NSCIF,scif),	/* 10: serial with FIFO */
158 	cdev_tty_init(NSCI,sci),	/* 11: serial */
159 	cdev_notdef(),			/* 12: */
160 	cdev_disk_init(NSD,sd),		/* 13: SCSI disk */
161 	cdev_tape_init(NST,st),		/* 14: SCSI tape */
162 	cdev_disk_init(NCD,cd),		/* 15: SCSI CD-ROM */
163 	cdev_notdef(),			/* 16: */
164 	cdev_ch_init(NCH,ch),		/* 17: SCSI autochanger */
165 	cdev_disk_init(NCCD,ccd),	/* 18: concatenated disk driver */
166 	cdev_scanner_init(NSS,ss),	/* 19: SCSI scanner */
167 	cdev_uk_init(NUK,uk),		/* 20: SCSI unknown */
168 	cdev_notdef(),			/* 21 (was APM) */
169 	cdev_fd_init(1,filedesc),	/* 22: file descriptor pseudo-device */
170 	cdev_bpftun_init(NBPFILTER,bpf),/* 23: Berkeley packet filter */
171 	cdev_disk_init(NMD,md),		/* 24: memory disk driver */
172 	cdev_notdef(),			/* 25 */
173 	cdev_notdef(),			/* 26 (was joystick) */
174 	cdev_notdef(),			/* 27 (was PC speaker) */
175 	cdev_lkm_init(NLKM,lkm),	/* 28: loadable module driver */
176 	cdev_lkm_dummy(),		/* 29 */
177 	cdev_lkm_dummy(),		/* 30 */
178 	cdev_lkm_dummy(),		/* 31 */
179 	cdev_lkm_dummy(),		/* 32 */
180 	cdev_lkm_dummy(),		/* 33 */
181 	cdev_lkm_dummy(),		/* 34 */
182 	cdev_notdef(),			/* 35 (was Microsoft mouse) */
183 	cdev_notdef(),			/* 36 (was Logitech mouse) */
184 	cdev_notdef(),			/* 37 (was PS/2 mouse) */
185 	cdev_notdef(),			/* 38 (was Cyclom serial port) */
186 	cdev_notdef(),			/* 39 (was Mitsumi CD-ROM) */
187 	cdev_bpftun_init(NTUN,tun),	/* 40: network tunnel */
188 	cdev_disk_init(NVND,vnd),	/* 41: vnode disk driver */
189 	cdev_audio_init(NAUDIO,audio),	/* 42: generic audio I/O */
190 	cdev_notdef(),			/* 43 */
191 	cdev_ipf_init(NIPFILTER,ipl),	/* 44: ip-filter device */
192 	cdev_notdef(),			/* 45 (was planetconnect satlink) */
193 	cdev_rnd_init(NRND,rnd),	/* 46: random source pseudo-device */
194 	cdev_vc_nb_init(NVCODA,vc_nb_),	/* 47: coda file system psdev */
195 	cdev_scsibus_init(NSCSIBUS,scsibus), /* 48: SCSI bus */
196 	cdev_disk_init(NRAID,raid),	/* 49: RAIDframe disk driver */
197 	cdev_esh_init(NESH, esh_fp),	/* 50: HIPPI (esh) raw device */
198 	cdev_wdog_init(NWDOG,wdog),	/* 51: watchdog timer */
199 	cdev_clockctl_init(NCLOCKCTL, clockctl),/* 52: clockctl pseudo device */
200 };
201 int	nchrdev = sizeof(cdevsw) / sizeof(cdevsw[0]);
202 
203 int	mem_no = 2; 	/* major device number of memory special file */
204 
205 /*
206  * Swapdev is a fake device implemented
207  * in sw.c used only internally to get to swstrategy.
208  * It cannot be provided to the users, because the
209  * swstrategy routine munches the b_dev and b_blkno entries
210  * before calling the appropriate driver.  This would horribly
211  * confuse, e.g. the hashing routines. Instead, /dev/drum is
212  * provided as a character (raw) device.
213  */
214 dev_t	swapdev = makedev(1, 0);
215 
216 /*
217  * Returns true if dev is /dev/mem or /dev/kmem.
218  */
219 int
220 iskmemdev(dev)
221 	dev_t dev;
222 {
223 
224 	return (major(dev) == mem_no && (minor(dev) < 2 || minor(dev) == 14));
225 }
226 
227 /*
228  * Returns true if dev is /dev/zero.
229  */
230 int
231 iszerodev(dev)
232 	dev_t dev;
233 {
234 
235 	return (major(dev) == mem_no && minor(dev) == 12);
236 }
237 
238 static int chrtoblktbl[] = {
239 	/* XXXX This needs to be dynamic for LKMs. */
240 	/*VCHR*/	/*VBLK*/
241 	/*  0 */	NODEV,
242 	/*  1 */	NODEV,
243 	/*  2 */	NODEV,
244 	/*  3 */	0,
245 	/*  4 */	NODEV,
246 	/*  5 */	NODEV,
247 	/*  6 */	NODEV,
248 	/*  7 */	NODEV,
249 	/*  8 */	NODEV,
250 	/*  9 */	NODEV,
251 	/* 10 */	NODEV,
252 	/* 11 */	NODEV,
253 	/* 12 */	NODEV,
254 	/* 13 */	4,
255 	/* 14 */	5,
256 	/* 15 */	6,
257 	/* 16 */	NODEV,
258 	/* 17 */	NODEV,
259 	/* 18 */	16,
260 	/* 19 */	NODEV,
261 	/* 20 */	NODEV,
262 	/* 21 */	NODEV,
263 	/* 22 */	NODEV,
264 	/* 23 */	NODEV,
265 	/* 24 */	17,
266 	/* 25 */	NODEV,
267 	/* 26 */	NODEV,
268 	/* 27 */	NODEV,
269 	/* 28 */	NODEV,
270 	/* 29 */	NODEV,
271 	/* 30 */	NODEV,
272 	/* 31 */	NODEV,
273 	/* 32 */	NODEV,
274 	/* 33 */	NODEV,
275 	/* 34 */	NODEV,
276 	/* 35 */	NODEV,
277 	/* 36 */	NODEV,
278 	/* 37 */	NODEV,
279 	/* 38 */	NODEV,
280 	/* 39 */	NODEV,
281 	/* 40 */	NODEV,
282 	/* 41 */	14,
283 	/* 42 */	NODEV,
284 	/* 43 */	NODEV,
285 	/* 44 */	NODEV,
286 	/* 45 */	NODEV,
287 	/* 46 */	NODEV,
288 	/* 47 */	NODEV,
289 	/* 48 */	NODEV,
290 	/* 49 */	NODEV,
291 	/* 50 */	NODEV,
292 	/* 51 */	NODEV,
293 	/* 52 */	NODEV,
294 };
295 
296 /*
297  * Convert a character device number to a block device number.
298  */
299 dev_t
300 chrtoblk(dev)
301 	dev_t dev;
302 {
303 	int blkmaj;
304 
305 	if (major(dev) >= nchrdev)
306 		return (NODEV);
307 	blkmaj = chrtoblktbl[major(dev)];
308 	if (blkmaj == NODEV)
309 		return (NODEV);
310 	return (makedev(blkmaj, minor(dev)));
311 }
312 
313 #include <dev/cons.h>
314 
315 #define scicnpollc	nullcnpollc
316 #define scifcnpollc	nullcnpollc
317 cons_decl(sci);
318 cons_decl(scif);
319 cons_decl(com);
320 
321 struct consdev constab[] = {
322 #if NSCI > 0
323 	cons_init(sci),
324 #endif
325 #if NSCIF > 0
326 	cons_init(scif),
327 #endif
328 #if NCOM > 0
329 	cons_init(com),
330 #endif
331 	{ 0 },
332 };
333