xref: /netbsd/sys/arch/atari/atari/conf.c (revision 242656c7)
1 /*	$NetBSD: conf.c,v 1.42 2001/01/05 13:09:16 martin 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 #include <dev/cons.h>
48 
49 #ifdef BANKEDDEVPAGER
50 #include <sys/bankeddev.h>
51 #endif
52 
53 #define	bdev_md_init(c,n) { \
54 	dev_init(c,n,open), dev_init(c,n,close), dev_init(c,n,strategy), \
55 	dev_init(c,n,ioctl), (dev_type_dump((*))) enxio, dev_size_init(c,n), 0 }
56 
57 #include "vnd.h"
58 bdev_decl(vnd);
59 #include "md.h"
60 bdev_decl(md);
61 #include "fd.h"
62 #include "hdfd.h"
63 bdev_decl(fd);
64 bdev_decl(sw);
65 #include "sd.h"
66 bdev_decl(sd);
67 #include "st.h"
68 bdev_decl(st);
69 #include "cd.h"
70 bdev_decl(cd);
71 #include "ccd.h"
72 bdev_decl(ccd);
73 #include "raid.h"
74 bdev_decl(raid);
75 #include "wd.h"
76 bdev_decl(wd);
77 
78 struct bdevsw	bdevsw[] =
79 {
80 	bdev_disk_init(NVND,vnd),	/* 0: vnode disk driver */
81 	bdev_md_init(NMD,md),		/* 1: memory disk - for install disk */
82 	bdev_disk_init(NFD+NHDFD,fd),	/* 2: floppy disk */
83 	bdev_swap_init(1,sw),		/* 3: swap pseudo-device */
84 	bdev_disk_init(NSD,sd),		/* 4: SCSI disk */
85 	bdev_tape_init(NST,st),		/* 5: SCSI tape */
86 	bdev_disk_init(NCD,cd),		/* 6: SCSI CD-ROM */
87 	bdev_lkm_dummy(),		/* 7 */
88 	bdev_lkm_dummy(),		/* 8 */
89 	bdev_lkm_dummy(),		/* 9 */
90 	bdev_lkm_dummy(),		/* 10 */
91 	bdev_lkm_dummy(),		/* 11 */
92 	bdev_lkm_dummy(),		/* 12 */
93 	bdev_disk_init(NCCD,ccd),	/* 13: concatenated disk driver */
94 	bdev_disk_init(NWD,wd),		/* 14: IDE disk driver */
95 	bdev_disk_init(NRAID,raid),	/* 15: RAIDframe disk driver */
96 };
97 int	nblkdev = sizeof(bdevsw) / sizeof(bdevsw[0]);
98 
99 /* open, close, ioctl, poll, mmap -- XXX should be a map device */
100 #define	cdev_grf_init(c,n) { \
101 	dev_init(c,n,open), dev_init(c,n,close), (dev_type_read((*))) nullop, \
102 	(dev_type_write((*))) nullop, dev_init(c,n,ioctl), \
103 	(dev_type_stop((*))) enodev, (dev_type_tty((*))) nullop, \
104 	dev_init(c,n,poll), dev_init(c,n,mmap) }
105 
106 /* open, close, ioctl, poll, mmap -- XXX should be a map device */
107 #define	cdev_view_init(c,n) { \
108 	dev_init(c,n,open), dev_init(c,n,close), (dev_type_read((*))) nullop, \
109 	(dev_type_write((*))) nullop, dev_init(c,n,ioctl), \
110 	(dev_type_stop((*))) enodev, (dev_type_tty((*))) nullop, \
111 	dev_init(c,n,poll), dev_init(c,n,mmap) }
112 
113 /* open, close, write, ioctl */
114 #define	cdev_lp_init(c,n) { \
115 	dev_init(c,n,open), dev_init(c,n,close), \
116 	(dev_type_read((*))) enodev, dev_init(c,n,write), \
117 	dev_init(c,n,ioctl), (dev_type_stop((*))) enodev, \
118 	0, seltrue, (dev_type_mmap((*))) enodev, 0}
119 
120 /* open, close, read, ioctl */
121 #define	cdev_ss_init(c,n) { \
122 	dev_init(c,n,open), dev_init(c,n,close), dev_init(c,n,read), \
123 	(dev_type_write((*))) enodev, dev_init(c,n,ioctl), \
124 	(dev_type_stop((*))) enodev, 0, seltrue, \
125 	(dev_type_mmap((*))) enodev }
126 
127 /* open, close, read, write */
128 #define	cdev_rtc_init(c,n) { \
129 	dev_init(c,n,open), dev_init(c,n,close), dev_init(c,n,read), \
130 	dev_init(c,n,write),(dev_type_ioctl((*))) enodev, \
131 	(dev_type_stop((*))) enodev, 0, seltrue, \
132 	(dev_type_mmap((*))) enodev }
133 
134 /* open, close, read, write, ioctl, mmap */
135 #define cdev_et_init(c,n) { \
136 	dev_init(c,n,open), dev_init(c,n,close), dev_init(c,n,read), \
137 	dev_init(c,n,write), dev_init(c,n,ioctl), \
138 	(dev_type_stop((*))) enodev, 0, seltrue, \
139 	dev_init(c,n,mmap) }
140 
141 /* open, close, ioctl */
142 #define cdev_i4bctl_init(c,n) { \
143 	dev_init(c,n,open), dev_init(c,n,close), (dev_type_read((*))) enodev, \
144 	(dev_type_write((*))) enodev, dev_init(c,n,ioctl), \
145 	(dev_type_stop((*))) enodev, 0, seltrue, \
146 	(dev_type_mmap((*))) enodev }
147 
148 /* open, close, read, write */
149 #define	cdev_i4brbch_init(c,n) { \
150 	dev_init(c,n,open), dev_init(c,n,close), dev_init(c,n,read), \
151 	dev_init(c,n,write), (dev_type_ioctl((*))) enodev, \
152 	(dev_type_stop((*))) enodev, \
153 	0, dev_init(c,n,poll), (dev_type_mmap((*))) enodev }
154 
155 /* open, close, read, write */
156 #define	cdev_i4btel_init(c,n) { \
157 	dev_init(c,n,open), dev_init(c,n,close), dev_init(c,n,read), \
158 	dev_init(c,n,write), (dev_type_ioctl((*))) enodev, \
159 	(dev_type_stop((*))) enodev, \
160 	0, dev_init(c,n,poll), (dev_type_mmap((*))) enodev, D_TTY }
161 
162 /* open, close, read, ioctl */
163 #define cdev_i4btrc_init(c,n) { \
164 	dev_init(c,n,open), dev_init(c,n,close), dev_init(c,n,read), \
165 	(dev_type_write((*))) enodev, dev_init(c,n,ioctl), \
166 	(dev_type_stop((*))) enodev, 0, (dev_type_poll((*))) enodev, \
167 	(dev_type_mmap((*))) enodev }
168 
169 /* open, close, read, poll, ioctl */
170 #define cdev_i4b_init(c,n) { \
171 	dev_init(c,n,open), dev_init(c,n,close), dev_init(c,n,read), \
172 	(dev_type_write((*))) enodev, dev_init(c,n,ioctl), \
173 	(dev_type_stop((*))) enodev, 0, dev_init(c,n,poll), \
174 	(dev_type_mmap((*))) enodev }
175 
176 #include "i4b.h"
177 #include "i4bctl.h"
178 #include "i4btrc.h"
179 #include "i4brbch.h"
180 #include "i4btel.h"
181 cdev_decl(i4b);
182 cdev_decl(i4bctl);
183 cdev_decl(i4btrc);
184 cdev_decl(i4brbch);
185 cdev_decl(i4btel);
186 
187 /* open, close, read, write, ioctl, mmap */
188 #define cdev_leo_init(c,n) { \
189        dev_init(c,n,open), dev_init(c,n,close), dev_init(c,n,read), \
190        dev_init(c,n,write), dev_init(c,n,ioctl), \
191        (dev_type_stop((*))) enodev, 0, seltrue, \
192        dev_init(c,n,mmap) }
193 
194 #include "audio.h"
195 #include "bpfilter.h"
196 #include "ch.h"
197 #include "et.h"
198 #include "grfcc.h"
199 #include "grfet.h"
200 #define	NGRF	(NGRFCC + NGRFET)
201 #include "ipfilter.h"
202 #include "ite.h"
203 #include "kbd.h"
204 #include "lp.h"
205 #include "mouse.h"
206 #include "pty.h"
207 #include "rnd.h"
208 #include "ser.h"
209 #include "ss.h"
210 #include "tun.h"
211 #include "uk.h"
212 #include "view.h"
213 #include "zs.h"
214 #include "leo.h"
215 #include "scsibus.h"
216 
217 cdev_decl(audio);
218 cdev_decl(bpf);
219 cdev_decl(ccd);
220 cdev_decl(cd);
221 cdev_decl(ch);
222 cdev_decl(cn);
223 cdev_decl(ctty);
224 cdev_decl(fd);
225  dev_decl(filedesc,open);
226 cdev_decl(grf);
227 cdev_decl(ipl);
228 cdev_decl(ite);
229 cdev_decl(kbd);
230 cdev_decl(log);
231 cdev_decl(lp);
232 #define	mmread	mmrw
233 #define	mmwrite	mmrw
234 cdev_decl(mm);
235 cdev_decl(ms);
236 #define	ptstty		ptytty
237 #define	ptsioctl	ptyioctl
238 cdev_decl(pts);
239 #define	ptctty		ptytty
240 #define	ptcioctl	ptyioctl
241 cdev_decl(ptc);
242 cdev_decl(raid);
243 cdev_decl(rtc);
244 cdev_decl(sd);
245 cdev_decl(ser);
246 cdev_decl(ss);
247 cdev_decl(st);
248 cdev_decl(sw);
249 cdev_decl(tun);
250 cdev_decl(uk);
251 cdev_decl(view);
252 cdev_decl(wd);
253 cdev_decl(zs);
254 cdev_decl(et);
255 cdev_decl(leo);
256 cdev_decl(scsibus);
257 
258 struct cdevsw	cdevsw[] =
259 {
260 	cdev_cn_init(1,cn),		/* 0: virtual console */
261 	cdev_ctty_init(1,ctty),		/* 1: controlling terminal */
262 	cdev_mm_init(1,mm),		/* 2: /dev/{null,mem,kmem,...} */
263 	cdev_swap_init(1,sw),		/* 3: /dev/drum (swap pseudo-device) */
264 	cdev_tty_init(NPTY,pts),	/* 4: pseudo-tty slave	*/
265 	cdev_ptc_init(NPTY,ptc),	/* 5: pseudo-tty master */
266 	cdev_log_init(1,log),		/* 6: /dev/klog */
267 	cdev_tty_init(NZS,zs),		/* 7: 8530 SCC */
268 	cdev_disk_init(NSD,sd),		/* 8: SCSI disk */
269 	cdev_disk_init(NCD,cd),		/* 9: SCSI CD-ROM */
270 	cdev_tape_init(NST,st),		/* 10: SCSI tape */
271 	cdev_grf_init(NGRF,grf),	/* 11: frame buffer */
272 	cdev_tty_init(NITE,ite),	/* 12: console terminal emulator */
273 	cdev_view_init(NVIEW,view),	/* 13: /dev/view00 /dev/view01, ... */
274 	cdev_mouse_init(NKBD,kbd),	/* 14: /dev/kbd	*/
275 	cdev_mouse_init(NMOUSE,ms),	/* 15: /dev/mouse0 /dev/mouse1 */
276 	cdev_disk_init(NFD+NHDFD,fd),	/* 16: floppy disk */
277 	cdev_disk_init(NVND,vnd),	/* 17: vnode disk driver */
278 	cdev_fd_init(1,filedesc),	/* 18: file descriptor pseudo-device */
279 	cdev_bpftun_init(NBPFILTER,bpf),/* 19: Berkeley packet filter */
280 	cdev_lkm_init(NLKM,lkm),	/* 20: loadable module driver */
281 	cdev_lkm_dummy(),		/* 21 */
282 	cdev_lkm_dummy(),		/* 22 */
283 	cdev_lkm_dummy(),		/* 23 */
284 	cdev_lkm_dummy(),		/* 24 */
285 	cdev_lkm_dummy(),		/* 25 */
286 	cdev_lkm_dummy(),		/* 26 */
287 	cdev_disk_init(NCCD,ccd),	/* 27: concatenated disk driver */
288 	cdev_bpftun_init(NTUN,tun),	/* 28: network tunnel */
289 	cdev_lp_init(NLP, lp),		/* 29: Centronics */
290 	cdev_ch_init(NCH,ch),		/* 30: SCSI autochanger	*/
291 	cdev_uk_init(NUK,uk),		/* 31: SCSI unknown	*/
292 	cdev_ss_init(NSS,ss),		/* 32: SCSI scanner	*/
293 	cdev_rtc_init(1,rtc),		/* 33: RealTimeClock	*/
294 	cdev_disk_init(NWD,wd),		/* 34: IDE disk driver	*/
295 	cdev_tty_init(NSER,ser),	/* 35: 68901 UART	*/
296 	cdev_ipf_init(NIPFILTER,ipl),	/* 36: ip-filter device */
297 	cdev_disk_init(NMD,md),		/* 37: memory disk - for install disk */
298 	cdev_rnd_init(NRND,rnd),	/* 38: random source pseudo-device */
299   	cdev_leo_init(NLEO,leo),	/* 39: Circad Leonardo video */
300 	cdev_et_init(NET,et),		/* 40: ET4000 color video */
301         cdev_notdef(),			/* 41: wscons placeholder	*/
302   	cdev_audio_init(NAUDIO,audio),	/* 42 */
303   	cdev_notdef(),			/* 43 */
304 	cdev_i4b_init(NI4B, i4b),		/* 44: i4b main device */
305 	cdev_i4bctl_init(NI4BCTL, i4bctl),	/* 45: i4b control device */
306 	cdev_i4brbch_init(NI4BRBCH, i4brbch),	/* 46: i4b raw b-channel access */
307 	cdev_i4btrc_init(NI4BTRC, i4btrc),	/* 47: i4b trace device */
308 	cdev_i4btel_init(NI4BTEL, i4btel),	/* 48: i4b phone device */
309 	cdev_scsibus_init(NSCSIBUS,scsibus), /* 49: SCSI bus */
310 	cdev_disk_init(NRAID,raid),	/* 50: RAIDframe disk driver */
311 	cdev_svr4_net_init(NSVR4_NET,svr4_net), /* 51: svr4 net pseudo-device */
312 };
313 int	nchrdev = sizeof(cdevsw) / sizeof(cdevsw[0]);
314 
315 #ifdef BANKEDDEVPAGER
316 extern int grfbanked_get __P((int, int, int));
317 extern int grfbanked_set __P((int, int));
318 extern int grfbanked_cur __P((int));
319 
320 struct bankeddevsw bankeddevsw[sizeof (cdevsw) / sizeof (cdevsw[0])] = {
321   { 0, 0, 0 },						/* 0 */
322   { 0, 0, 0 },						/* 1 */
323   { 0, 0, 0 },						/* 2 */
324   { 0, 0, 0 },						/* 3 */
325   { 0, 0, 0 },						/* 4 */
326   { 0, 0, 0 },						/* 5 */
327   { 0, 0, 0 },						/* 6 */
328   { 0, 0, 0 },						/* 7 */
329   { 0, 0, 0 },						/* 8 */
330   { 0, 0, 0 },						/* 9 */
331   { grfbanked_get, grfbanked_cur, grfbanked_set },	/* 10 */
332   /* rest { 0, 0, 0 } */
333 };
334 #endif
335 
336 int	mem_no = 2; 	/* major device number of memory special file */
337 
338 /*
339  * Swapdev is a fake device implemented
340  * in sw.c used only internally to get to swstrategy.
341  * It cannot be provided to the users, because the
342  * swstrategy routine munches the b_dev and b_blkno entries
343  * before calling the appropriate driver.  This would horribly
344  * confuse, e.g. the hashing routines. Instead, /dev/drum is
345  * provided as a character (raw) device.
346  */
347 dev_t	swapdev = makedev(3, 0);
348 
349 /*
350  * Returns true if dev is /dev/mem or /dev/kmem.
351  */
352 int
353 iskmemdev(dev)
354 	dev_t dev;
355 {
356 
357 	return (major(dev) == mem_no && minor(dev) < 2);
358 }
359 
360 /*
361  * Returns true if dev is /dev/zero.
362  */
363 int
364 iszerodev(dev)
365 	dev_t dev;
366 {
367 
368 	return (major(dev) == mem_no && minor(dev) == 12);
369 }
370 
371 static int chrtoblktab[] = {
372 	/* XXXX This needs to be dynamic for LKMs. */
373 	/*VCHR*/	/*VBLK*/
374 	/*  0 */	NODEV,
375 	/*  1 */	NODEV,
376 	/*  2 */	NODEV,
377 	/*  3 */	NODEV,
378 	/*  4 */	NODEV,
379 	/*  5 */	NODEV,
380 	/*  6 */	NODEV,
381 	/*  7 */	NODEV,
382 	/*  8 */	4,
383 	/*  9 */	6,
384 	/* 10 */	5,
385 	/* 11 */	NODEV,
386 	/* 12 */	NODEV,
387 	/* 13 */	NODEV,
388 	/* 14 */	NODEV,
389 	/* 15 */	NODEV,
390 	/* 16 */	2,
391 	/* 17 */	0,
392 	/* 18 */	NODEV,
393 	/* 19 */	NODEV,
394 	/* 20 */	NODEV,
395 	/* 21 */	NODEV,
396 	/* 22 */	NODEV,
397 	/* 23 */	NODEV,
398 	/* 24 */	NODEV,
399 	/* 25 */	NODEV,
400 	/* 26 */	NODEV,
401 	/* 27 */	13,
402 	/* 28 */	NODEV,
403 	/* 29 */	NODEV,
404 	/* 30 */	NODEV,
405 	/* 31 */	NODEV,
406 	/* 32 */	NODEV,
407 	/* 33 */	NODEV,
408 	/* 34 */	14,
409 	/* 35 */	NODEV,
410 	/* 36 */	NODEV,
411 	/* 37 */	1,
412 	/* 38 */	NODEV,
413 	/* 39 */	NODEV,
414 	/* 40 */	NODEV,
415 	/* 41 */	NODEV,
416 	/* 42 */	NODEV,
417 	/* 43 */	NODEV,
418 	/* 44 */	NODEV,
419 	/* 45 */	NODEV,
420 	/* 46 */	NODEV,
421 	/* 47 */	NODEV,
422 	/* 48 */	NODEV,
423 	/* 49 */	NODEV,
424 	/* 50 */	15,
425 };
426 
427 /*
428  * Convert a character device number to a block device number.
429  */
430 dev_t
431 chrtoblk(dev)
432 	dev_t dev;
433 {
434 	int blkmaj;
435 
436 	if (major(dev) >= nchrdev)
437 		return(NODEV);
438 	blkmaj = chrtoblktab[major(dev)];
439 	if (blkmaj == NODEV)
440 		return(NODEV);
441 	return (makedev(blkmaj, minor(dev)));
442 }
443 
444 /*
445  * This entire table could be autoconfig()ed but that would mean that
446  * the kernel's idea of the console would be out of sync with that of
447  * the standalone boot.  I think it best that they both use the same
448  * known algorithm unless we see a pressing need otherwise.
449  */
450 cons_decl(ser);
451 #define	itecnpollc	nullcnpollc
452 cons_decl(ite);
453 
454 struct	consdev constab[] = {
455 #if NSER > 0
456 	cons_init(ser),
457 #endif
458 #if NITE > 0
459 	cons_init(ite),
460 #endif
461 	{ 0 },
462 };
463