xref: /netbsd-src/sys/arch/mac68k/mac68k/conf.c (revision 4b30c543a0b21e3ba94f2c569e9a82b4fdb2075f)
1 /*
2  * Copyright (c) 1990 The Regents of the University of California.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  * 3. All advertising materials mentioning features or use of this software
14  *    must display the following acknowledgement:
15  *	This product includes software developed by the University of
16  *	California, Berkeley and its contributors.
17  * 4. Neither the name of the University nor the names of its contributors
18  *    may be used to endorse or promote products derived from this software
19  *    without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31  * SUCH DAMAGE.
32 */
33 /*-
34  * Copyright (C) 1993	Allen K. Briggs, Chris P. Caputo,
35  *			Michael L. Finch, Bradley A. Grantham, and
36  *			Lawrence A. Kesteloot
37  * All rights reserved.
38  *
39  * Redistribution and use in source and binary forms, with or without
40  * modification, are permitted provided that the following conditions
41  * are met:
42  * 1. Redistributions of source code must retain the above copyright
43  *    notice, this list of conditions and the following disclaimer.
44  * 2. Redistributions in binary form must reproduce the above copyright
45  *    notice, this list of conditions and the following disclaimer in the
46  *    documentation and/or other materials provided with the distribution.
47  * 3. All advertising materials mentioning features or use of this software
48  *    must display the following acknowledgement:
49  *	This product includes software developed by the Alice Group.
50  * 4. The names of the Alice Group or any of its members may not be used
51  *    to endorse or promote products derived from this software without
52  *    specific prior written permission.
53  *
54  * THIS SOFTWARE IS PROVIDED BY THE ALICE GROUP ``AS IS'' AND ANY EXPRESS OR
55  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
56  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
57  * IN NO EVENT SHALL THE ALICE GROUP BE LIABLE FOR ANY DIRECT, INDIRECT,
58  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
59  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
60  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
61  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
62  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
63  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
64  *
65  */
66 #ident "$Id: conf.c,v 1.1.1.1 1993/09/29 06:09:18 briggs Exp $"
67 /*-
68  *      @(#)conf.c	7.9 (Berkeley) 5/28/91
69  */
70 /*
71    ALICE
72       BG 06/02/92,23:25:54
73          I have modified this file to correspond loosely to our requirements.
74          We need to go back through and check on a few things:
75             1) can we get rid of the _notdef()'s?
76             2) should we keep all the devices I left here?  (e.g. cd...)
77             3) did I put the new devices in the right places?
78  */
79 
80 #include "sys/param.h"
81 #include "sys/systm.h"
82 #include "sys/buf.h"
83 #include "sys/ioctl.h"
84 #include "sys/tty.h"
85 #include "sys/conf.h"
86 
87 int	rawread		__P((dev_t, struct uio *, int));
88 int	rawwrite	__P((dev_t, struct uio *, int));
89 int	swstrategy	__P((struct buf *));
90 int	ttselect	__P((dev_t, int, struct proc *));
91 
92 #define	dev_type_open(n)	int n __P((dev_t, int, int, struct proc *))
93 #define	dev_type_close(n)	int n __P((dev_t, int, int, struct proc *))
94 #define	dev_type_strategy(n)	int n __P((struct buf *))
95 #define	dev_type_ioctl(n) \
96 	int n __P((dev_t, int, caddr_t, int, struct proc *))
97 
98 /* bdevsw-specific types */
99 #define	dev_type_dump(n)	int n __P((dev_t))
100 #define	dev_type_size(n)	int n __P((dev_t))
101 
102 #define	dev_decl(n,t)	__CONCAT(dev_type_,t)(__CONCAT(n,t))
103 
104 #define	dev_init(c,n,t) \
105 	((c > 0) ? __CONCAT(n,t) : (__CONCAT(dev_type_,t)((*))) enxio)
106 
107 /* bdevsw-specific initializations */
108 #define	dev_size_init(c,n)	(c > 0 ? __CONCAT(n,size) : 0)
109 
110 #define	bdev_decl(n) \
111 	dev_decl(n,open); dev_decl(n,close); dev_decl(n,strategy); \
112 	dev_decl(n,ioctl); dev_decl(n,dump); dev_decl(n,size)
113 
114 #define	bdev_disk_init(c,n) { \
115 	dev_init(c,n,open), (dev_type_close((*))) nullop, \
116 	dev_init(c,n,strategy), dev_init(c,n,ioctl), \
117 	dev_init(c,n,dump), dev_size_init(c,n), 0 }
118 
119 #define	bdev_cd_init(c,n) { \
120 	dev_init(c,n,open), (dev_type_close((*))) nullop, \
121 	dev_init(c,n,strategy), dev_init(c,n,ioctl), \
122 	(dev_type_dump((*))) enodev, dev_size_init(c,n), 0 }
123 
124 #define	bdev_tape_init(c,n) { \
125 	dev_init(c,n,open), dev_init(c,n,close), \
126 	dev_init(c,n,strategy), dev_init(c,n,ioctl), \
127 	(dev_type_dump((*))) enodev, 0, B_TAPE }
128 
129 #define	bdev_swap_init() { \
130 	(dev_type_open((*))) enodev, (dev_type_close((*))) enodev, \
131 	swstrategy, (dev_type_ioctl((*))) enodev, \
132 	(dev_type_dump((*))) enodev, 0, 0 }
133 
134 #define	bdev_notdef()	bdev_tape_init(0,no)
135 bdev_decl(no);	/* dummy declarations */
136 
137 /* 06/02/92,23:14:37 BG -- I deleted ct.h and rd.h, we won't even adapt 'em */
138 #include "st.h"
139 #include "sd.h"
140 #include "cd.h"
141 #define NVN 0 /*#include "vn.h"*/
142 
143 bdev_decl(st);
144 bdev_decl(sd);
145 bdev_decl(cd);
146 bdev_decl(vn);
147 
148 /* 06/02/92,23:15:39 BG -- deleted ct and rd, defined as notdef, I don't know */
149 /*  what entirely removing them would do... */
150 struct bdevsw	bdevsw[] =
151 {
152 	bdev_notdef(),         	/* 0: cs80 cartridge tape */
153 	bdev_notdef(),		/* 1 */
154 	bdev_notdef(),         	/* 2: hpib disk */
155 	bdev_swap_init(),	/* 3: swap pseudo-device */
156 	bdev_disk_init(NSD,sd),	/* 4: scsi disk */
157 	bdev_cd_init(NCD,cd),	/* 5: scsi CD driver */
158 	bdev_notdef(),		/* 6: vnode disk driver (swap to files) */
159 	bdev_tape_init(NST,st),	/* 7: scsi tape */
160 };
161 
162 int	nblkdev = sizeof (bdevsw) / sizeof (bdevsw[0]);
163 
164 /* cdevsw-specific types */
165 #define	dev_type_read(n)	int n __P((dev_t, struct uio *, int))
166 #define	dev_type_write(n)	int n __P((dev_t, struct uio *, int))
167 #define	dev_type_stop(n)	int n __P((struct tty *, int))
168 #define	dev_type_reset(n)	int n __P((int))
169 #define	dev_type_select(n)	int n __P((dev_t, int, struct proc *))
170 #define	dev_type_map(n)	int n __P(())
171 
172 #define	cdev_decl(n) \
173 	dev_decl(n,open); dev_decl(n,close); dev_decl(n,read); \
174 	dev_decl(n,write); dev_decl(n,ioctl); dev_decl(n,stop); \
175 	dev_decl(n,reset); dev_decl(n,select); dev_decl(n,map); \
176 	dev_decl(n,strategy); extern struct tty __CONCAT(n,_tty)[]
177 
178 #define	dev_tty_init(c,n)	(c > 0 ? __CONCAT(n,_tty) : 0)
179 
180 /* open, read, write, ioctl, strategy */
181 #define	cdev_disk_init(c,n) { \
182 	dev_init(c,n,open), (dev_type_close((*))) nullop, dev_init(c,raw,read), \
183 	dev_init(c,raw,write), dev_init(c,n,ioctl), (dev_type_stop((*))) enodev, \
184 	(dev_type_reset((*))) nullop, 0, seltrue, (dev_type_map((*))) enodev, \
185 	dev_init(c,n,strategy) }
186 
187 /* open, close, read, write, ioctl, strategy */
188 #define	cdev_tape_init(c,n) { \
189 	dev_init(c,n,open), dev_init(c,n,close), \
190 	(dev_type_read((*))) enodev, (dev_type_write((*))) enodev, \
191 	dev_init(c,n,ioctl), (dev_type_stop((*))) enodev, \
192 	(dev_type_reset((*))) nullop, 0, seltrue, (dev_type_map((*))) enodev, \
193 	dev_init(c,n,strategy) }
194 
195 /* open, close, read, write, ioctl, stop, tty */
196 #define	cdev_tty_init(c,n) { \
197 	dev_init(c,n,open), dev_init(c,n,close), dev_init(c,n,read), \
198 	dev_init(c,n,write), dev_init(c,n,ioctl), dev_init(c,n,stop), \
199 	(dev_type_reset((*))) nullop, dev_tty_init(c,n), ttselect, \
200 	(dev_type_map((*))) enodev, 0 }
201 
202 #define	cdev_notdef() { \
203 	(dev_type_open((*))) enodev, (dev_type_close((*))) enodev, \
204 	(dev_type_read((*))) enodev, (dev_type_write((*))) enodev, \
205 	(dev_type_ioctl((*))) enodev, (dev_type_stop((*))) enodev, \
206 	(dev_type_reset((*))) nullop, 0, seltrue, \
207 	(dev_type_map((*))) enodev, 0 }
208 
209 cdev_decl(no);			/* dummy declarations */
210 
211 cdev_decl(con);
212 /* 06/02/92,23:17:34 BG -- this will be LAK's console driver, if I understand */
213 /*  the difference between cn and ctty correctly. */
214 /* open, close, read, write, ioctl, select -- XXX should be a tty */
215 #define	cdev_con_init(c,n) { \
216 	dev_init(c,n,open), dev_init(c,n,close), dev_init(c,n,read), \
217 	dev_init(c,n,write), dev_init(c,n,ioctl), (dev_type_stop((*))) nullop, \
218 	(dev_type_reset((*))) nullop, 0, dev_init(c,n,select), \
219 	(dev_type_map((*))) enodev, 0 }
220 
221 cdev_decl(ctty);
222 /* open, read, write, ioctl, select -- XXX should be a tty */
223 #define	cdev_ctty_init(c,n) { \
224 	dev_init(c,n,open), (dev_type_close((*))) nullop, dev_init(c,n,read), \
225 	dev_init(c,n,write), dev_init(c,n,ioctl), (dev_type_stop((*))) nullop, \
226 	(dev_type_reset((*))) nullop, 0, dev_init(c,n,select), \
227 	(dev_type_map((*))) enodev, 0 }
228 
229 dev_type_read(mmrw);
230 /* read/write */
231 #define	cdev_mm_init(c,n) { \
232 	(dev_type_open((*))) nullop, (dev_type_close((*))) nullop, mmrw, \
233 	mmrw, (dev_type_ioctl((*))) enodev, (dev_type_stop((*))) nullop, \
234 	(dev_type_reset((*))) nullop, 0, seltrue, (dev_type_map((*))) enodev, 0 }
235 
236 /* read, write, strategy */
237 #define	cdev_swap_init(c,n) { \
238 	(dev_type_open((*))) nullop, (dev_type_close((*))) nullop, rawread, \
239 	rawwrite, (dev_type_ioctl((*))) enodev, (dev_type_stop((*))) enodev, \
240 	(dev_type_reset((*))) nullop, 0, (dev_type_select((*))) enodev, \
241 	(dev_type_map((*))) enodev, dev_init(c,n,strategy) }
242 
243 #include "pty.h"
244 #define	pts_tty		pt_tty
245 #define	ptsioctl	ptyioctl
246 cdev_decl(pts);
247 #define	ptc_tty		pt_tty
248 #define	ptcioctl	ptyioctl
249 cdev_decl(ptc);
250 
251 /* open, close, read, write, ioctl, tty, select */
252 #define	cdev_ptc_init(c,n) { \
253 	dev_init(c,n,open), dev_init(c,n,close), dev_init(c,n,read), \
254 	dev_init(c,n,write), dev_init(c,n,ioctl), (dev_type_stop((*))) nullop, \
255 	(dev_type_reset((*))) nullop, dev_tty_init(c,n), dev_init(c,n,select), \
256 	(dev_type_map((*))) enodev, 0 }
257 
258 cdev_decl(log);
259 /* open, close, read, ioctl, select -- XXX should be a generic device */
260 #define	cdev_log_init(c,n) { \
261 	dev_init(c,n,open), dev_init(c,n,close), dev_init(c,n,read), \
262 	(dev_type_write((*))) enodev, dev_init(c,n,ioctl), \
263 	(dev_type_stop((*))) enodev, (dev_type_reset((*))) nullop, 0, \
264 	dev_init(c,n,select), (dev_type_map((*))) enodev, 0 }
265 
266 cdev_decl(st);
267 cdev_decl(sd);
268 
269 /* 06/02/92,23:18:17 BG -- I removed rd, ct, grf, ppi, dca, ite, dcm, and I */
270 /*  made hil into kbd (keyboard) */
271 /* MF i want grf back !!*/
272 
273 /* frame buffer guy */
274 cdev_decl(grf);
275 /* open, close, ioctl, select, map -- XXX should be a map device */
276 #define	cdev_grf_init(c,n) { \
277 	dev_init(c,n,open), dev_init(c,n,close), (dev_type_read((*))) nullop, \
278 	(dev_type_write((*))) nullop, dev_init(c,n,ioctl), \
279 	(dev_type_stop((*))) enodev, (dev_type_reset((*))) nullop, 0, \
280 	dev_init(c,n,select), dev_init(c,n,map), 0 }
281 
282 cdev_decl(kbd);
283 /* open, close, read, ioctl, select, map -- XXX should be a map device */
284 #define	cdev_kbd_init(c,n) { \
285 	dev_init(c,n,open), dev_init(c,n,close), dev_init(c,n,read), \
286 	(dev_type_write((*))) nullop, dev_init(c,n,ioctl), \
287 	(dev_type_stop((*))) enodev, (dev_type_reset((*))) nullop, 0, \
288 	dev_init(c,n,select), dev_init(c,n,map), 0 }
289 
290 /* 06/02/92,23:21:56 BG -- this was dcm, we will make it ser (serial ports) */
291 #define NSER 2
292 /* #include "ser.h" */
293 cdev_decl(ser);
294 
295 cdev_decl(cd);
296 
297 #define NCLOCK 0 /* #include "clock.h" */
298 cdev_decl(clock);
299 /* open, close, ioctl, map -- XXX should be a map device */
300 #define	cdev_clock_init(c,n) { \
301 	dev_init(c,n,open), dev_init(c,n,close), (dev_type_read((*))) nullop, \
302 	(dev_type_write((*))) nullop, dev_init(c,n,ioctl), \
303 	(dev_type_stop((*))) enodev, (dev_type_reset((*))) nullop, 0, \
304 	(dev_type_select((*))) nullop, dev_init(c,n,map), 0 }
305 
306 cdev_decl(vn);
307 /* open, read, write, ioctl -- XXX should be a disk */
308 #define	cdev_vn_init(c,n) { \
309 	dev_init(c,n,open), (dev_type_close((*))) nullop, dev_init(c,n,read), \
310 	dev_init(c,n,write), dev_init(c,n,ioctl), (dev_type_stop((*))) enodev, \
311 	(dev_type_reset((*))) nullop, 0, seltrue, (dev_type_map((*))) enodev, \
312 	0 }
313 
314 dev_type_open(fdopen);
315 /* open */
316 #define	cdev_fd_init(c,n) { \
317 	dev_init(c,n,open), (dev_type_close((*))) enodev, \
318 	(dev_type_read((*))) enodev, (dev_type_write((*))) enodev, \
319 	(dev_type_ioctl((*))) enodev, (dev_type_stop((*))) enodev, \
320 	(dev_type_reset((*))) enodev, 0, (dev_type_select((*))) enodev, \
321 	(dev_type_map((*))) enodev, 0 }
322 
323 #include "bpfilter.h"
324 cdev_decl(bpf);
325 /* open, close, read, write, ioctl, select -- XXX should be generic device */
326 #define	cdev_bpf_init(c,n) { \
327 	dev_init(c,n,open), dev_init(c,n,close), dev_init(c,n,read), \
328 	dev_init(c,n,write), dev_init(c,n,ioctl), (dev_type_stop((*))) enodev, \
329 	(dev_type_reset((*))) enodev, 0, dev_init(c,n,select), \
330 	(dev_type_map((*))) enodev, 0 }
331 
332 
333 struct cdevsw	cdevsw[] =
334 {
335 	cdev_con_init(9,con),		/* 0: virtual console */
336 	cdev_ctty_init(1,ctty),		/* 1: controlling terminal */
337 	cdev_mm_init(1,mm),		/* 2: /dev/{null,mem,kmem,...} */
338 	cdev_swap_init(1,sw),		/* 3: /dev/drum (swap pseudo-device) */
339 	cdev_tty_init(NPTY,pts),	/* 4: pseudo-tty slave */
340 	cdev_ptc_init(NPTY,ptc),	/* 5: pseudo-tty master */
341 	cdev_log_init(1,log),		/* 6: /dev/klog */
342 	cdev_notdef(),			/* 7: was cs80 cartridge tape */
343 	cdev_disk_init(NSD,sd),		/* 8: scsi disk */
344 	cdev_notdef(),			/* 9: was hpib disk */
345 	cdev_grf_init(1,grf),		/* 10: was frame buffer */
346 	cdev_notdef(),			/* 11: was printer/plotter interface */
347 	cdev_tty_init(NSER,ser),	/* 12: 2 macII serial ports -- BG*/
348 	cdev_notdef(),			/* 13: was built-in single-port serial*/
349 	cdev_notdef(),			/* 14: was console terminal emulator */
350 	cdev_kbd_init(0,kbd),		/* 15: ADB keyboard -- BG -- BARF*/
351 	cdev_notdef(),			/* 16 */
352 	cdev_disk_init(NCD,cd),		/* 17: concatenated disk */
353 	cdev_clock_init(NCLOCK,clock),	/* 18: mapped clock */
354 	cdev_vn_init(NVN,vn),		/* 19: vnode disk */
355 	cdev_tape_init(NST,st),		/* 20: exabyte tape */
356 	cdev_fd_init(1,fd),		/* 21: file descriptor pseudo-dev */
357 	cdev_bpf_init(NBPFILTER,bpf),	/* 22: berkeley packet filter */
358 };
359 
360 int	nchrdev = sizeof (cdevsw) / sizeof (cdevsw[0]);
361 
362 int	mem_no = 2; 	/* major device number of memory special file */
363 
364 /*
365  * Swapdev is a fake device implemented
366  * in sw.c used only internally to get to swstrategy.
367  * It cannot be provided to the users, because the
368  * swstrategy routine munches the b_dev and b_blkno entries
369  * before calling the appropriate driver.  This would horribly
370  * confuse, e.g. the hashing routines. Instead, /dev/drum is
371  * provided as a character (raw) device.
372  */
373 dev_t	swapdev = makedev(3, 0);
374