xref: /original-bsd/sys/i386/i386/conf.c (revision e59fb703)
1 /*-
2  * Copyright (c) 1991 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  *      @(#)conf.c	7.9 (Berkeley) 5/28/91
34  */
35 
36 #include "sys/param.h"
37 #include "sys/systm.h"
38 #include "sys/buf.h"
39 #include "sys/ioctl.h"
40 #include "sys/tty.h"
41 #include "sys/conf.h"
42 
43 int	rawread		__P((dev_t, struct uio *, int));
44 int	rawwrite	__P((dev_t, struct uio *, int));
45 int	swstrategy	__P((struct buf *));
46 int	ttselect	__P((dev_t, int, struct proc *));
47 
48 #define	dev_type_open(n)	int n __P((dev_t, int, int, struct proc *))
49 #define	dev_type_close(n)	int n __P((dev_t, int, int, struct proc *))
50 #define	dev_type_strategy(n)	int n __P((struct buf *))
51 #define	dev_type_ioctl(n) \
52 	int n __P((dev_t, int, caddr_t, int, struct proc *))
53 
54 /* bdevsw-specific types */
55 #define	dev_type_dump(n)	int n __P((dev_t))
56 #define	dev_type_size(n)	int n __P((dev_t))
57 
58 #define	dev_decl(n,t)	__CONCAT(dev_type_,t)(__CONCAT(n,t))
59 #define	dev_init(c,n,t) \
60 	(c > 0 ? __CONCAT(n,t) : (__CONCAT(dev_type_,t)((*))) enxio)
61 
62 /* bdevsw-specific initializations */
63 #define	dev_size_init(c,n)	(c > 0 ? __CONCAT(n,size) : 0)
64 
65 #define	bdev_decl(n) \
66 	dev_decl(n,open); dev_decl(n,close); dev_decl(n,strategy); \
67 	dev_decl(n,ioctl); dev_decl(n,dump); dev_decl(n,size)
68 
69 #define	bdev_disk_init(c,n) { \
70 	dev_init(c,n,open), (dev_type_close((*))) nullop, \
71 	dev_init(c,n,strategy), dev_init(c,n,ioctl), \
72 	dev_init(c,n,dump), dev_size_init(c,n), 0 }
73 
74 #define	bdev_tape_init(c,n) { \
75 	dev_init(c,n,open), dev_init(c,n,close), \
76 	dev_init(c,n,strategy), dev_init(c,n,ioctl), \
77 	dev_init(c,n,dump), 0, B_TAPE }
78 
79 #define	bdev_swap_init() { \
80 	(dev_type_open((*))) enodev, (dev_type_close((*))) enodev, \
81 	swstrategy, (dev_type_ioctl((*))) enodev, \
82 	(dev_type_dump((*))) enodev, 0, 0 }
83 
84 #define	bdev_notdef()	bdev_tape_init(0,no)
85 bdev_decl(no);	/* dummy declarations */
86 
87 #include "wd.h"
88 #include "fd.h"
89 #include "wt.h"
90 #include "xd.h"
91 
92 bdev_decl(wd);
93 bdev_decl(Fd);
94 bdev_decl(wt);
95 bdev_decl(xd);
96 
97 struct bdevsw	bdevsw[] =
98 {
99 	bdev_disk_init(NWD,wd),	/* 0: st506/rll/esdi/ide disk */
100 	bdev_swap_init(),	/* 1: swap pseudo-device */
101 	bdev_disk_init(NFD,Fd),	/* 2: floppy disk */
102 	bdev_tape_init(NWT,wt),	/* 3: QIC-24/60/120/150 cartridge tape */
103 	bdev_disk_init(NXD,xd),	/* 4: temp alt st506/rll/esdi/ide disk */
104 };
105 
106 int	nblkdev = sizeof (bdevsw) / sizeof (bdevsw[0]);
107 
108 /* cdevsw-specific types */
109 #define	dev_type_read(n)	int n __P((dev_t, struct uio *, int))
110 #define	dev_type_write(n)	int n __P((dev_t, struct uio *, int))
111 #define	dev_type_stop(n)	int n __P((struct tty *, int))
112 #define	dev_type_reset(n)	int n __P((int))
113 #define	dev_type_select(n)	int n __P((dev_t, int, struct proc *))
114 #define	dev_type_map(n)	int n __P(())
115 
116 #define	cdev_decl(n) \
117 	dev_decl(n,open); dev_decl(n,close); dev_decl(n,read); \
118 	dev_decl(n,write); dev_decl(n,ioctl); dev_decl(n,stop); \
119 	dev_decl(n,reset); dev_decl(n,select); dev_decl(n,map); \
120 	dev_decl(n,strategy); extern struct tty __CONCAT(n,_tty)[]
121 
122 #define	dev_tty_init(c,n)	(c > 0 ? __CONCAT(n,_tty) : 0)
123 
124 /* open, read, write, ioctl, strategy */
125 #define	cdev_disk_init(c,n) { \
126 	dev_init(c,n,open), (dev_type_close((*))) nullop, dev_init(c,n,read), \
127 	dev_init(c,n,write), dev_init(c,n,ioctl), (dev_type_stop((*))) enodev, \
128 	(dev_type_reset((*))) nullop, 0, seltrue, (dev_type_map((*))) enodev, \
129 	dev_init(c,n,strategy) }
130 
131 /* open, close, read, write, ioctl, strategy */
132 #define	cdev_tape_init(c,n) { \
133 	dev_init(c,n,open), dev_init(c,n,close), dev_init(c,n,read), \
134 	dev_init(c,n,write), dev_init(c,n,ioctl), (dev_type_stop((*))) enodev, \
135 	(dev_type_reset((*))) nullop, 0, seltrue, (dev_type_map((*))) enodev, \
136 	dev_init(c,n,strategy) }
137 
138 /* open, close, read, write, ioctl, stop, tty */
139 #define	cdev_tty_init(c,n) { \
140 	dev_init(c,n,open), dev_init(c,n,close), dev_init(c,n,read), \
141 	dev_init(c,n,write), dev_init(c,n,ioctl), dev_init(c,n,stop), \
142 	(dev_type_reset((*))) nullop, dev_tty_init(c,n), ttselect, \
143 	(dev_type_map((*))) enodev, 0 }
144 
145 #define	cdev_notdef() { \
146 	(dev_type_open((*))) enodev, (dev_type_close((*))) enodev, \
147 	(dev_type_read((*))) enodev, (dev_type_write((*))) enodev, \
148 	(dev_type_ioctl((*))) enodev, (dev_type_stop((*))) enodev, \
149 	(dev_type_reset((*))) nullop, 0, seltrue, \
150 	(dev_type_map((*))) enodev, 0 }
151 
152 cdev_decl(no);			/* dummy declarations */
153 
154 cdev_decl(cn);
155 /* open, close, read, write, ioctl, select -- XXX should be a tty */
156 #define	cdev_cn_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_init(c,n,ioctl), (dev_type_stop((*))) nullop, \
159 	(dev_type_reset((*))) nullop, 0, dev_init(c,n,select), \
160 	(dev_type_map((*))) enodev, 0 }
161 
162 cdev_decl(ctty);
163 /* open, read, write, ioctl, select -- XXX should be a tty */
164 #define	cdev_ctty_init(c,n) { \
165 	dev_init(c,n,open), (dev_type_close((*))) nullop, dev_init(c,n,read), \
166 	dev_init(c,n,write), dev_init(c,n,ioctl), (dev_type_stop((*))) nullop, \
167 	(dev_type_reset((*))) nullop, 0, dev_init(c,n,select), \
168 	(dev_type_map((*))) enodev, 0 }
169 
170 dev_type_read(mmrw);
171 /* read/write */
172 #define	cdev_mm_init(c,n) { \
173 	(dev_type_open((*))) nullop, (dev_type_close((*))) nullop, mmrw, \
174 	mmrw, (dev_type_ioctl((*))) enodev, (dev_type_stop((*))) nullop, \
175 	(dev_type_reset((*))) nullop, 0, seltrue, (dev_type_map((*))) enodev, 0 }
176 
177 /* read, write, strategy */
178 #define	cdev_swap_init(c,n) { \
179 	(dev_type_open((*))) nullop, (dev_type_close((*))) nullop, rawread, \
180 	rawwrite, (dev_type_ioctl((*))) enodev, (dev_type_stop((*))) enodev, \
181 	(dev_type_reset((*))) nullop, 0, (dev_type_select((*))) enodev, \
182 	(dev_type_map((*))) enodev, dev_init(c,n,strategy) }
183 
184 #include "pty.h"
185 #define	pts_tty		pt_tty
186 #define	ptsioctl	ptyioctl
187 cdev_decl(pts);
188 #define	ptc_tty		pt_tty
189 #define	ptcioctl	ptyioctl
190 cdev_decl(ptc);
191 
192 /* open, close, read, write, ioctl, tty, select */
193 #define	cdev_ptc_init(c,n) { \
194 	dev_init(c,n,open), dev_init(c,n,close), dev_init(c,n,read), \
195 	dev_init(c,n,write), dev_init(c,n,ioctl), (dev_type_stop((*))) nullop, \
196 	(dev_type_reset((*))) nullop, dev_tty_init(c,n), dev_init(c,n,select), \
197 	(dev_type_map((*))) enodev, 0 }
198 
199 cdev_decl(log);
200 /* open, close, read, ioctl, select -- XXX should be a generic device */
201 #define	cdev_log_init(c,n) { \
202 	dev_init(c,n,open), dev_init(c,n,close), dev_init(c,n,read), \
203 	(dev_type_write((*))) enodev, dev_init(c,n,ioctl), \
204 	(dev_type_stop((*))) enodev, (dev_type_reset((*))) nullop, 0, \
205 	dev_init(c,n,select), (dev_type_map((*))) enodev, 0 }
206 
207 cdev_decl(wd);
208 cdev_decl(Fd);
209 cdev_decl(xd);
210 cdev_decl(wt);
211 
212 #include "com.h"
213 
214 cdev_decl(com);
215 
216 #include "pc.h"
217 
218 cdev_decl(pc);
219 
220 /* open, close, read, write, ioctl, tty -- XXX should be a tty */
221 extern struct tty pccons;
222 #define	cdev_pc_init(c,n) { \
223 	dev_init(c,n,open), dev_init(c,n,close), dev_init(c,n,read), \
224 	dev_init(c,n,write), dev_init(c,n,ioctl), (dev_type_stop((*))) nullop, \
225 	(dev_type_reset((*))) nullop, &pccons, ttselect, \
226 	(dev_type_map((*))) enodev, 0 }
227 
228 #include "bpfilter.h"
229 cdev_decl(bpf);
230 
231 /* open, close, read, write, ioctl, select -- XXX should be generic device */
232 #define	cdev_bpf_init(c,n) { \
233 	dev_init(c,n,open), dev_init(c,n,close), dev_init(c,n,read), \
234 	dev_init(c,n,write), dev_init(c,n,ioctl), (dev_type_stop((*))) enodev, \
235 	(dev_type_reset((*))) enodev, 0, dev_init(c,n,select), \
236 	(dev_type_map((*))) enodev, 0 }
237 
238 struct cdevsw	cdevsw[] =
239 {
240 	cdev_cn_init(1,cn),		/* 0: virtual console */
241 	cdev_ctty_init(1,ctty),		/* 1: controlling terminal */
242 	cdev_mm_init(1,mm),		/* 2: /dev/{null,mem,kmem,...} */
243 	cdev_disk_init(NWD,wd),		/* 3: st506/rll/esdi/ide disk */
244 	cdev_swap_init(1,sw),		/* 4: /dev/drum (swap pseudo-device) */
245 	cdev_tty_init(NPTY,pts),	/* 5: pseudo-tty slave */
246 	cdev_ptc_init(NPTY,ptc),	/* 6: pseudo-tty master */
247 	cdev_log_init(1,log),		/* 7: /dev/klog */
248 	cdev_tty_init(NCOM,com),	/* 8: serial communications ports */
249 	cdev_disk_init(NFD,Fd),		/* 9: floppy disk */
250 	cdev_tape_init(NWT,wt),		/* 10: QIC-24/60/120/150 cartridge tape */
251 	cdev_disk_init(NXD,xd),		/* 11: temp alt st506/rll/esdi/ide disk */
252 	cdev_pc_init(1,pc),		/* 12: real console */
253 	cdev_notdef(),			/* 13 */
254 	cdev_bpf_init(NBPFILTER,bpf),	/* 14: berkeley packet filter */
255 };
256 
257 int	nchrdev = sizeof (cdevsw) / sizeof (cdevsw[0]);
258 
259 int	mem_no = 2; 	/* major device number of memory special file */
260 
261 /*
262  * Swapdev is a fake device implemented
263  * in sw.c used only internally to get to swstrategy.
264  * It cannot be provided to the users, because the
265  * swstrategy routine munches the b_dev and b_blkno entries
266  * before calling the appropriate driver.  This would horribly
267  * confuse, e.g. the hashing routines. Instead, /dev/drum is
268  * provided as a character (raw) device.
269  */
270 dev_t	swapdev = makedev(1, 0);
271