xref: /netbsd-src/sys/arch/mac68k/mac68k/conf.c (revision ce0bb6e8d2e560ecacbe865a848624f94498063b)
1 /*	$NetBSD: conf.c,v 1.25 1995/04/12 14:59:19 briggs Exp $	*/
2 
3 /*
4  * Copyright (c) 1990 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 /*-
36  * Copyright (C) 1993	Allen K. Briggs, Chris P. Caputo,
37  *			Michael L. Finch, Bradley A. Grantham, and
38  *			Lawrence A. Kesteloot
39  * All rights reserved.
40  *
41  * Redistribution and use in source and binary forms, with or without
42  * modification, are permitted provided that the following conditions
43  * are met:
44  * 1. Redistributions of source code must retain the above copyright
45  *    notice, this list of conditions and the following disclaimer.
46  * 2. Redistributions in binary form must reproduce the above copyright
47  *    notice, this list of conditions and the following disclaimer in the
48  *    documentation and/or other materials provided with the distribution.
49  * 3. All advertising materials mentioning features or use of this software
50  *    must display the following acknowledgement:
51  *	This product includes software developed by the Alice Group.
52  * 4. The names of the Alice Group or any of its members may not be used
53  *    to endorse or promote products derived from this software without
54  *    specific prior written permission.
55  *
56  * THIS SOFTWARE IS PROVIDED BY THE ALICE GROUP ``AS IS'' AND ANY EXPRESS OR
57  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
58  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
59  * IN NO EVENT SHALL THE ALICE GROUP BE LIABLE FOR ANY DIRECT, INDIRECT,
60  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
61  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
62  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
63  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
64  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
65  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
66  *
67  */
68 /*-
69  * Derived a long time ago from
70  *      @(#)conf.c	7.9 (Berkeley) 5/28/91
71  */
72 
73 #include <sys/param.h>
74 #include <sys/systm.h>
75 #include <sys/buf.h>
76 #include <sys/ioctl.h>
77 #include <sys/tty.h>
78 #include <sys/conf.h>
79 #include <sys/vnode.h>
80 #include <dev/cons.h>
81 
82 int	rawread		__P((dev_t, struct uio *, int));
83 int	rawwrite	__P((dev_t, struct uio *, int));
84 void	swstrategy	__P((struct buf *));
85 int	ttselect	__P((dev_t, int, struct proc *));
86 
87 #include "st.h"
88 bdev_decl(st);
89 #include "sd.h"
90 bdev_decl(sd);
91 #include "cd.h"
92 bdev_decl(cd);
93 #include "ch.h"
94 bdev_decl(ch);
95 #include "vnd.h"
96 bdev_decl(vnd);
97 
98 #ifdef LKM
99 int	lkmenodev();
100 #else
101 #define lkmenodev	enodev
102 #endif
103 
104 struct bdevsw	bdevsw[] =
105 {
106 	bdev_notdef(),         		/* 0 */
107 	bdev_notdef(),			/* 1 */
108 	bdev_notdef(),         		/* 2 */
109 	bdev_swap_init(),		/* 3: swap pseudo-device */
110 	bdev_disk_init(NSD,sd),		/* 4: SCSI disk */
111 	bdev_tape_init(NST,st),		/* 5: SCSI tape */
112 	bdev_disk_init(NCD,cd),		/* 6: SCSI CD-ROM */
113 	bdev_notdef(),        	 	/* 7 */
114 	bdev_disk_init(NVND,vnd),	/* 8: vnode disk driver */
115 	bdev_notdef(),			/* 9 */
116 	bdev_lkm_dummy(),		/* 10 */
117 	bdev_lkm_dummy(),		/* 11 */
118 	bdev_lkm_dummy(),		/* 12 */
119 	bdev_lkm_dummy(),		/* 13 */
120 	bdev_lkm_dummy(),		/* 14 */
121 	bdev_lkm_dummy(),		/* 15 */
122 };
123 int	nblkdev = sizeof(bdevsw) / sizeof(bdevsw[0]);
124 
125 /* open, close, ioctl, select, mmap -- XXX should be a map device */
126 #define	cdev_grf_init(c,n) { \
127 	dev_init(c,n,open), dev_init(c,n,close), (dev_type_read((*))) nullop, \
128 	(dev_type_write((*))) nullop, dev_init(c,n,ioctl), \
129 	(dev_type_stop((*))) enodev, (dev_type_reset((*))) nullop, 0, \
130 	dev_init(c,n,select), dev_init(c,n,mmap), 0 }
131 
132 cdev_decl(cn);
133 cdev_decl(ctty);
134 
135 #include "ite.h"
136 cdev_decl(ite);
137 #define mmread	mmrw
138 #define mmwrite	mmrw
139 cdev_decl(mm);
140 #include "pty.h"
141 #define	pts_tty		pt_tty
142 #define	ptsioctl	ptyioctl
143 cdev_decl(pts);
144 #define	ptc_tty		pt_tty
145 #define	ptcioctl	ptyioctl
146 cdev_decl(ptc);
147 cdev_decl(log);
148 cdev_decl(st);
149 cdev_decl(sd);
150 cdev_decl(fd);
151 #include "grf.h"
152 cdev_decl(grf);
153 #define NADB 1 /* #include "adb.h" */
154 cdev_decl(adb);
155 #include "ser.h"
156 cdev_decl(ser);
157 cdev_decl(cd);
158 cdev_decl(vnd);
159 #include "bpfilter.h"
160 cdev_decl(bpf);
161 #include "tun.h"
162 cdev_decl(tun);
163 
164 #ifdef LKM
165 #define NLKM	1
166 #else
167 #define NLKM	0
168 #endif
169 
170 cdev_decl(lkm);
171 
172 struct cdevsw	cdevsw[] =
173 {
174 	cdev_cn_init(1,cn),		/* 0: virtual console */
175 	cdev_ctty_init(1,ctty),		/* 1: controlling terminal */
176 	cdev_mm_init(1,mm),		/* 2: /dev/{null,mem,kmem,...} */
177 	cdev_swap_init(1,sw),		/* 3: /dev/drum (swap pseudo-device) */
178 	cdev_tty_init(NPTY,pts),	/* 4: pseudo-tty slave */
179 	cdev_ptc_init(NPTY,ptc),	/* 5: pseudo-tty master */
180 	cdev_log_init(1,log),		/* 6: /dev/klog */
181 	cdev_notdef(),			/* 7 */
182 	cdev_notdef(),			/* 8 */
183 	cdev_notdef(),			/* 9 */
184 	cdev_grf_init(1,grf),		/* 10: frame buffer */
185 	cdev_tty_init(NITE,ite),	/* 11: console terminal emulator */
186 	cdev_tty_init(NSER,ser),	/* 12: 2 mac serial ports -- BG*/
187 	cdev_disk_init(NSD,sd),		/* 13: SCSI disk */
188 	cdev_tape_init(NST,st),		/* 14: SCSI tape */
189 	cdev_disk_init(NCD,cd),		/* 15: SCSI CD-ROM */
190 	cdev_notdef(),			/* 16 */
191 /*	cdev_disk_init(NCH,ch),		 17: SCSI autochanger */
192 	cdev_notdef(),			/* 17: until we find chstrategy... */
193 	cdev_notdef(),			/* 18 */
194 	cdev_disk_init(NVND,vnd),	/* 19: vnode disk driver */
195 	cdev_notdef(),			/* 20 */
196 	cdev_fd_init(1,fd),		/* 21: file descriptor pseudo-device */
197 	cdev_bpftun_init(NBPFILTER,bpf),/* 22: Berkeley packet filter */
198 	cdev_mouse_init(NADB,adb),	/* 23: ADB event interface */
199 	cdev_bpftun_init(NTUN,tun),	/* 24: network tunnel */
200 	cdev_lkm_init(NLKM,lkm),	/* 25: loadable module driver */
201 	cdev_lkm_dummy(),		/* 26 */
202 	cdev_lkm_dummy(),		/* 27 */
203 	cdev_lkm_dummy(),		/* 28 */
204 	cdev_lkm_dummy(),		/* 29 */
205 	cdev_lkm_dummy(),		/* 30 */
206 	cdev_lkm_dummy(),		/* 31 */
207 };
208 int	nchrdev = sizeof(cdevsw) / sizeof(cdevsw[0]);
209 
210 int	mem_no = 2; 	/* major device number of memory special file */
211 
212 /*
213  * Swapdev is a fake device implemented
214  * in sw.c used only internally to get to swstrategy.
215  * It cannot be provided to the users, because the
216  * swstrategy routine munches the b_dev and b_blkno entries
217  * before calling the appropriate driver.  This would horribly
218  * confuse, e.g. the hashing routines. Instead, /dev/drum is
219  * provided as a character (raw) device.
220  */
221 dev_t	swapdev = makedev(3, 0);
222 
223 /*
224  * Returns true if dev is /dev/mem or /dev/kmem.
225  */
226 int
227 iskmemdev(dev)
228 	dev_t	dev;
229 {
230 
231 	return (major(dev) == mem_no && minor(dev) < 2);
232 }
233 
234 /*
235  * Returns true if dev is /dev/zero.
236  */
237 iszerodev(dev)
238 	dev_t	dev;
239 {
240 
241 	return (major(dev) == mem_no && minor(dev) == 12);
242 }
243 
244 static int chrtoblktab[] = {
245 	/* XXXX This needs to be dynamic for LKMs. */
246 	/*VCHR*/	/*VBLK*/
247 	/*  0 */	NODEV,
248 	/*  1 */	NODEV,
249 	/*  2 */	NODEV,
250 	/*  3 */	3,
251 	/*  4 */	NODEV,
252 	/*  5 */	NODEV,
253 	/*  6 */	NODEV,
254 	/*  7 */	NODEV,
255 	/*  8 */	NODEV,
256 	/*  9 */	NODEV,
257 	/* 10 */	NODEV,
258 	/* 11 */	NODEV,
259 	/* 12 */	NODEV,
260 	/* 13 */	4,
261 	/* 14 */	5,
262 	/* 15 */	6,
263 	/* 16 */	NODEV,
264 	/* 17 */	NODEV,
265 	/* 18 */	NODEV,
266 	/* 19 */	8,
267 	/* 20 */	NODEV,
268 	/* 21 */	NODEV,
269 	/* 22 */	NODEV,
270 	/* 23 */	NODEV,
271 	/* 24 */	NODEV,
272 	/* 25 */	NODEV,
273 	/* 26 */	NODEV,
274 	/* 27 */	NODEV,
275 	/* 28 */	NODEV,
276 	/* 29 */	NODEV,
277 	/* 30 */	NODEV,
278 	/* 31 */	NODEV,
279 };
280 
281 chrtoblk(dev)
282 	dev_t	dev;
283 {
284 	int	blkmaj;
285 
286 	if (major(dev) >= nchrdev)
287 		return NODEV;
288 	blkmaj = chrtoblktab[major(dev)];
289 	if (blkmaj == NODEV)
290 		return NODEV;
291 	return (makedev(blkmaj, minor(dev)));
292 }
293 
294 #define itecnpollc	nullcnpollc
295 cons_decl(ite);
296 #define sercnpollc	nullcnpollc
297 cons_decl(ser);
298 
299 struct	consdev constab[] = {
300 #if NITE > 0
301 	cons_init(ite),
302 #endif
303 #if NSER > 0
304 	cons_init(ser),
305 #endif
306 	{ 0 },
307 };
308