xref: /original-bsd/sys/sparc/sparc/conf.c (revision d364528e)
1 /*
2  * Copyright (c) 1992 The Regents of the University of California.
3  * All rights reserved.
4  *
5  * This software was developed by the Computer Systems Engineering group
6  * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
7  * contributed to Berkeley.
8  *
9  * All advertising materials mentioning features or use of this software
10  * must display the following acknowledgement:
11  *	This product includes software developed by the University of
12  *	California, Lawrence Berkeley Laboratories.
13  *
14  * %sccs.include.redist.c%
15  *
16  *	@(#)conf.c	7.2 (Berkeley) 07/21/92
17  *
18  * from: $Header: conf.c,v 1.12 92/06/17 05:22:00 torek Exp $ (LBL)
19  */
20 
21 #include "sys/param.h"
22 #include "sys/systm.h"
23 #include "sys/buf.h"
24 #include "sys/ioctl.h"
25 #include "sys/tty.h"
26 #include "sys/conf.h"
27 
28 int	rawread		__P((dev_t, struct uio *, int));
29 int	rawwrite	__P((dev_t, struct uio *, int));
30 int	swstrategy	__P((struct buf *));
31 int	ttselect	__P((dev_t, int, struct proc *));
32 
33 #define	dev_type_open(n)	int n __P((dev_t, int, int, struct proc *))
34 #define	dev_type_close(n)	int n __P((dev_t, int, int, struct proc *))
35 #define	dev_type_strategy(n)	int n __P((struct buf *))
36 #define	dev_type_ioctl(n) \
37 	int n __P((dev_t, int, caddr_t, int, struct proc *))
38 
39 /* bdevsw-specific types */
40 /*	dev_type_dump(n)	int n __P((dev_t, daddr_t, caddr_t, int))*/
41 #define	dev_type_dump(n)	int n ()
42 #define	dev_type_size(n)	int n __P((dev_t))
43 
44 /* error/nullop functions */
45 #define	error_open	((dev_type_open((*))) enodev)
46 #define	error_close	((dev_type_close((*))) enodev)
47 #define	error_ioctl	((dev_type_ioctl((*))) enodev)
48 #define	error_dump	((dev_type_dump((*))) enodev)
49 
50 #define	null_open	((dev_type_open((*))) nullop)
51 #define	null_close	((dev_type_close((*))) nullop)
52 
53 #define	dev_decl(n,t)	__CONCAT(dev_type_,t)(__CONCAT(n,t))
54 #define	dev_init(c,n,t) \
55 	(c > 0 ? __CONCAT(n,t) : (__CONCAT(dev_type_,t)((*))) enxio)
56 
57 /* bdevsw-specific initializations */
58 #define	dev_size_init(c,n)	(c > 0 ? __CONCAT(n,size) : 0)
59 
60 #define	bdev_decl(n) \
61 	dev_decl(n,open); dev_decl(n,close); dev_decl(n,strategy); \
62 	dev_decl(n,ioctl); dev_decl(n,dump); dev_decl(n,size)
63 
64 #define	bdev_disk_init(c,n) { \
65 	dev_init(c,n,open), dev_init(c,n,close), \
66 	dev_init(c,n,strategy), dev_init(c,n,ioctl), \
67 	dev_init(c,n,dump), dev_size_init(c,n), 0 }
68 
69 #define	bdev_tape_init(c,n) { \
70 	dev_init(c,n,open), dev_init(c,n,close), \
71 	dev_init(c,n,strategy), dev_init(c,n,ioctl), \
72 	dev_init(c,n,dump), 0, B_TAPE }
73 
74 #define	bdev_swap_init() { \
75 	error_open, error_close, swstrategy, error_ioctl, error_dump, 0, 0 }
76 
77 #define	bdev_notdef()	bdev_tape_init(0,no)
78 bdev_decl(no);	/* dummy declarations */
79 
80 #include "sd.h"
81 
82 bdev_decl(sd);
83 
84 struct bdevsw	bdevsw[] =
85 {
86 	bdev_notdef(),		/* 0 */
87 	bdev_notdef(),		/* 1 */
88 	bdev_notdef(),		/* 2 */
89 	bdev_swap_init(),	/* 3 */
90 	bdev_notdef(),		/* 4 */
91 	bdev_notdef(),		/* 5 */
92 	bdev_notdef(),		/* 6 */
93 	bdev_disk_init(NSD,sd),	/* 7: scsi disk */
94 };
95 
96 int	nblkdev = sizeof (bdevsw) / sizeof (bdevsw[0]);
97 
98 /* cdevsw-specific types */
99 #define	dev_type_read(n)	int n __P((dev_t, struct uio *, int))
100 #define	dev_type_write(n)	int n __P((dev_t, struct uio *, int))
101 #define	dev_type_select(n)	int n __P((dev_t, int, struct proc *))
102 #define	dev_type_map(n)		int n __P(())
103 
104 #define	error_read	((dev_type_read((*))) enodev)
105 #define	error_write	((dev_type_write((*))) enodev)
106 #define	error_select	((dev_type_select((*))) enodev)
107 
108 #define	cdev_decl(n) \
109 	dev_decl(n,open); dev_decl(n,close); dev_decl(n,read); \
110 	dev_decl(n,write); dev_decl(n,ioctl); dev_decl(n,select); \
111 	dev_decl(n,map); dev_decl(n,strategy); \
112 	extern struct tty __CONCAT(n,_tty)[]
113 
114 #define	dev_tty_init(c,n)	(c > 0 ? __CONCAT(n,_tty) : 0)
115 
116 /* open, close, read, write, ioctl, strategy */
117 #define	cdev_disk_init(c,n) { \
118 	dev_init(c,n,open), dev_init(c,n,close), rawread, rawwrite, \
119 	dev_init(c,n,ioctl), 0, 0, 0, seltrue, 0, dev_init(c,n,strategy) }
120 
121 /* open, close, read, write, ioctl, strategy */
122 #define	cdev_tape_init(c,n) { \
123 	dev_init(c,n,open), dev_init(c,n,close), dev_init(c,n,read), \
124 	dev_init(c,n,write), dev_init(c,n,ioctl), 0, 0, 0, seltrue, 0, \
125 	dev_init(c,n,strategy) }
126 
127 /* open, close, read, write, ioctl, tty */
128 #define	cdev_tty_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_init(c,n,ioctl), 0, 0, dev_tty_init(c,n), \
131 	ttselect, 0, 0 }
132 
133 /* open, close, read, write, ioctl, select */
134 #define	cdev_gen_init(c,n) { \
135 	dev_init(c,n,open), dev_init(c,n,close), dev_init(c,n,read), \
136 	dev_init(c,n,write), dev_init(c,n,ioctl), 0, 0, 0, \
137 	dev_init(c,n,select), 0, 0 }
138 
139 /* open, close, ioctl, mmap */
140 #define	cdev_fb_init(c,n) { \
141 	dev_init(c,n,open), dev_init(c,n,close), error_read, error_write, \
142 	dev_init(c,n,ioctl), 0, 0, 0, seltrue, dev_init(c,n,map), 0 }
143 
144 #define	cdev_notdef() { \
145 	error_open, error_close, error_read, error_write, \
146 	error_ioctl, 0, 0, 0, seltrue, 0, 0 }
147 
148 cdev_decl(no);			/* dummy declarations */
149 
150 cdev_decl(cn);
151 /* open, close, read, write, ioctl, select -- XXX should be a tty */
152 extern struct tty cons;
153 #define	cdev_cn_init(c,n) { \
154 	dev_init(c,n,open), dev_init(c,n,close), dev_init(c,n,read), \
155 	dev_init(c,n,write), dev_init(c,n,ioctl), 0, 0, &cons, \
156 	dev_init(c,n,select), 0, 0 }
157 
158 cdev_decl(ctty);
159 /* open, read, write, ioctl, select -- XXX should be a tty */
160 #define	cdev_ctty_init(c,n) { \
161 	dev_init(c,n,open), null_close, dev_init(c,n,read), \
162 	dev_init(c,n,write), dev_init(c,n,ioctl), 0, 0, 0, \
163 	dev_init(c,n,select), 0, 0 }
164 
165 dev_type_read(mmrw);
166 /* read/write */
167 #define	cdev_mm_init(c,n) { \
168 	null_open, null_close, mmrw, mmrw, error_ioctl, 0, 0, 0, \
169 	seltrue, 0, 0 }
170 
171 /* read, write, strategy */
172 #define	cdev_swap_init(c,n) { \
173 	null_open, null_close, rawread, rawwrite, error_ioctl, 0, 0, 0, \
174 	seltrue, 0, dev_init(c,n,strategy) }
175 
176 #include "pty.h"
177 #define	pts_tty		pt_tty
178 #define	ptsioctl	ptyioctl
179 cdev_decl(pts);
180 #define	ptc_tty		pt_tty
181 #define	ptcioctl	ptyioctl
182 cdev_decl(ptc);
183 
184 /* open, close, read, write, ioctl, tty, select */
185 #define	cdev_ptc_init(c,n) { \
186 	dev_init(c,n,open), dev_init(c,n,close), dev_init(c,n,read), \
187 	dev_init(c,n,write), dev_init(c,n,ioctl), 0, 0, dev_tty_init(c,n), \
188 	dev_init(c,n,select), 0, 0 }
189 
190 cdev_decl(log);
191 /* open, close, read, ioctl, select -- XXX should be a generic device */
192 #define	cdev_log_init(c,n) { \
193 	dev_init(c,n,open), dev_init(c,n,close), dev_init(c,n,read), \
194 	error_write, dev_init(c,n,ioctl), 0, 0, 0, dev_init(c,n,select), 0, 0 }
195 
196 dev_type_open(fdopen);
197 /* open */
198 #define	cdev_fd_init(c,n) { \
199 	dev_init(c,n,open), error_close, error_read, error_write, \
200 	error_ioctl, 0, 0, 0, error_select, 0, 0 }
201 
202 #include "zs.h"
203 cdev_decl(zs);
204 
205 cdev_decl(kbd);
206 cdev_decl(ms);
207 cdev_decl(fb);
208 
209 #include "bwtwo.h"
210 cdev_decl(bwtwo);
211 
212 #include "cgthree.h"
213 cdev_decl(cgthree);
214 
215 #include "bsdaudio.h"
216 cdev_decl(audio);
217 
218 #include "bpfilter.h"
219 cdev_decl(bpf);
220 /* open, close, read, write, ioctl, select -- XXX should be generic device */
221 #define	cdev_bpf_init(c,n) { \
222 	dev_init(c,n,open), dev_init(c,n,close), dev_init(c,n,read), \
223 	dev_init(c,n,write), dev_init(c,n,ioctl), 0, 0, 0, \
224 	dev_init(c,n,select), 0, 0 }
225 
226 /* prototype sun-equivalent cdevsw[] */
227 struct cdevsw	cdevsw[] =
228 {
229 	cdev_cn_init(1,cn),		/* 0: virtual console */
230 	cdev_notdef(),			/* 1 */
231 	cdev_ctty_init(1,ctty),		/* 2: controlling terminal */
232 	cdev_mm_init(1,mm),		/* 2: /dev/{null,mem,kmem,...} */
233 	cdev_notdef(),			/* 4 */
234 	cdev_notdef(),			/* 5 */
235 	cdev_notdef(),			/* 6 */
236 	cdev_swap_init(1,sw),		/* 7: /dev/drum (swap pseudo-device) */
237 	cdev_notdef(),			/* 8 */
238 	cdev_notdef(),			/* 9 */
239 	cdev_notdef(),			/* 10 */
240 	cdev_notdef(),			/* 11 */
241 	cdev_tty_init(NZS,zs),		/* 12: zs serial */
242 	cdev_gen_init(1,ms),		/* 13: /dev/mouse */
243 	cdev_notdef(),			/* 14 */
244 	cdev_notdef(),			/* 15: sun /dev/winNNN */
245 	cdev_log_init(1,log),		/* 16: /dev/klog */
246 	cdev_disk_init(NSD,sd),		/* 17: scsi disk */
247 	cdev_notdef(),			/* 18: should be scsi tape */
248 	cdev_notdef(),			/* 19 */
249 	cdev_ptc_init(NPTY,ptc),	/* 20: pseudo-tty master */
250 	cdev_tty_init(NPTY,pts),	/* 21: pseudo-tty slave */
251 	cdev_fb_init(1,fb),		/* 22: /dev/fb indirect driver */
252 	cdev_notdef(),			/* 23 */
253 	cdev_fd_init(1,fd),		/* 24: /dev/std{in,out,err} */
254 	cdev_notdef(),			/* 25 */
255 	cdev_notdef(),			/* 26 */
256 	cdev_fb_init(NBWTWO,bwtwo),	/* 27: /dev/bwtwo */
257 	cdev_notdef(),			/* 28 */
258 	cdev_gen_init(1,kbd),		/* 29: /dev/kbd */
259 	cdev_notdef(),			/* 30 */
260 	cdev_notdef(),			/* 31: should be /dev/cgtwo */
261 	cdev_notdef(),			/* 32: should be /dev/gpone */
262 	cdev_notdef(),			/* 33 */
263 	cdev_notdef(),			/* 34 */
264 	cdev_notdef(),			/* 35 */
265 	cdev_notdef(),			/* 36 */
266 	cdev_notdef(),			/* 37 */
267 	cdev_notdef(),			/* 38 */
268 	cdev_notdef(),			/* 39 */
269 	cdev_notdef(),			/* 40 */
270 	cdev_notdef(),			/* 41 */
271 	cdev_notdef(),			/* 42 */
272 	cdev_notdef(),			/* 43 */
273 	cdev_notdef(),			/* 44 */
274 	cdev_notdef(),			/* 45 */
275 	cdev_notdef(),			/* 46 */
276 	cdev_notdef(),			/* 47 */
277 	cdev_notdef(),			/* 48 */
278 	cdev_notdef(),			/* 49 */
279 	cdev_notdef(),			/* 50 */
280 	cdev_notdef(),			/* 51 */
281 	cdev_notdef(),			/* 52 */
282 	cdev_notdef(),			/* 53 */
283 	cdev_notdef(),			/* 54 */
284 	cdev_fb_init(NCGTHREE,cgthree),	/* 55: /dev/cgthree */
285 	cdev_notdef(),			/* 56 */
286 	cdev_notdef(),			/* 57 */
287 	cdev_notdef(),			/* 58 */
288 	cdev_notdef(),			/* 59 */
289 	cdev_notdef(),			/* 60 */
290 	cdev_notdef(),			/* 61 */
291 	cdev_notdef(),			/* 62 */
292 	cdev_notdef(),			/* 63 */
293 	cdev_notdef(),			/* 64 */
294 	cdev_notdef(),			/* 65 */
295 	cdev_notdef(),			/* 66 */
296 	cdev_notdef(),			/* 67 */
297 	cdev_notdef(),			/* 68 */
298 	cdev_gen_init(NBSDAUDIO,audio),	/* 69: /dev/audio */
299 	cdev_notdef(),			/* 70 */
300 	cdev_notdef(),			/* 71 */
301 	cdev_notdef(),			/* 72 */
302 	cdev_notdef(),			/* 73 */
303 	cdev_notdef(),			/* 74 */
304 	cdev_notdef(),			/* 75 */
305 	cdev_notdef(),			/* 76 */
306 	cdev_notdef(),			/* 77 */
307 	cdev_notdef(),			/* 78 */
308 	cdev_notdef(),			/* 79 */
309 	cdev_notdef(),			/* 80 */
310 	cdev_notdef(),			/* 81 */
311 	cdev_notdef(),			/* 82 */
312 	cdev_notdef(),			/* 83 */
313 	cdev_notdef(),			/* 84 */
314 	cdev_notdef(),			/* 85 */
315 	cdev_notdef(),			/* 86 */
316 	cdev_notdef(),			/* 87 */
317 	cdev_notdef(),			/* 88 */
318 	cdev_notdef(),			/* 89 */
319 	cdev_notdef(),			/* 90 */
320 	cdev_notdef(),			/* 91 */
321 	cdev_notdef(),			/* 92 */
322 	cdev_notdef(),			/* 93 */
323 	cdev_notdef(),			/* 94 */
324 	cdev_notdef(),			/* 95 */
325 	cdev_notdef(),			/* 96 */
326 	cdev_notdef(),			/* 97 */
327 	cdev_notdef(),			/* 98 */
328 	cdev_notdef(),			/* 99 */
329 	cdev_notdef(),			/* 100 */
330 	cdev_notdef(),			/* 101 */
331 	cdev_notdef(),			/* 102 */
332 	cdev_notdef(),			/* 103 */
333 	cdev_notdef(),			/* 104 */
334 	cdev_bpf_init(NBPFILTER,bpf),	/* 105: packet filter */
335 	cdev_notdef(),			/* 106 */
336 	cdev_notdef(),			/* 107 */
337 	cdev_notdef(),			/* 108 */
338 	cdev_notdef(),			/* 109 */
339 };
340 
341 int	nchrdev = sizeof (cdevsw) / sizeof (cdevsw[0]);
342 
343 /*
344  * Swapdev is a fake device implemented
345  * in sw.c used only internally to get to swstrategy.
346  * It cannot be provided to the users, because the
347  * swstrategy routine munches the b_dev and b_blkno entries
348  * before calling the appropriate driver.  This would horribly
349  * confuse, e.g. the hashing routines. Instead, /dev/drum is
350  * provided as a character (raw) device.
351  */
352 dev_t	swapdev = makedev(3, 0);
353