1 /* $OpenBSD: conf.c,v 1.59 2022/09/02 20:06:55 miod Exp $ */
2 /* $NetBSD: conf.c,v 1.10 2002/04/19 01:04:38 wiz Exp $ */
3
4 /*
5 * Copyright (c) 1994-1998 Mark Brinicombe.
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. All advertising materials mentioning features or use of this software
17 * must display the following acknowledgement:
18 * This product includes software developed by Mark Brinicombe
19 * for the NetBSD Project.
20 * 4. The name of the company nor the name of the author may be used to
21 * endorse or promote products derived from this software without specific
22 * prior written permission.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
25 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
26 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
27 * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
28 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
29 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
30 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * SUCH DAMAGE.
35 *
36 * RiscBSD kernel project
37 *
38 * conf.c
39 *
40 * Character and Block Device configuration
41 * Console configuration
42 *
43 * Defines the structures [bc]devsw
44 *
45 * Created : 17/09/94
46 */
47
48 #include <sys/param.h>
49 #include <sys/systm.h>
50 #include <sys/tty.h>
51 #include <sys/conf.h>
52
53 /*
54 * From this point, these need to be MI foo.h files.
55 */
56
57 /*
58 * Standard MI devices (e.g. ones in dev/ic)
59 */
60 #include "com.h" /* NS164x0 serial ports */
61
62 /*
63 * Standard pseudo-devices
64 */
65 #include "bpfilter.h"
66 #include "dt.h"
67 #include "pf.h"
68 #include "pty.h"
69 #include "tun.h"
70 #include "ksyms.h"
71 #include "kstat.h"
72
73 /*
74 * APM interface
75 */
76 #ifdef CONF_HAVE_APM
77 #include "apm.h"
78 #else
79 #define NAPM 0
80 #endif
81
82 /*
83 * Disk/Filesystem pseudo-devices
84 */
85 #include "rd.h" /* memory disk driver */
86 #include "vnd.h" /* vnode disk driver */
87
88 /*
89 * WD/ATA devices
90 */
91 #include "wd.h"
92 bdev_decl(wd);
93
94 #ifdef USER_PCICONF
95 #include "pci.h"
96 cdev_decl(pci);
97 #endif
98
99 /*
100 * SCSI/ATAPI devices
101 */
102 #include "sd.h"
103 #include "st.h"
104 #include "cd.h"
105 #include "ch.h"
106 #include "uk.h"
107 #include "bio.h"
108
109 /*
110 * Audio devices
111 */
112 #include "audio.h"
113 #include "video.h"
114 #include "midi.h"
115
116 /*
117 * USB devices
118 */
119 #include "usb.h"
120 #include "ucom.h"
121 #include "ugen.h"
122 #include "uhid.h"
123 #include "fido.h"
124 #include "ujoy.h"
125 #include "ulpt.h"
126
127 /*
128 * WSCONS devices
129 */
130 #include "wsdisplay.h"
131 /*
132 #include "wsfont.h"
133 */
134 #include "wskbd.h"
135 #include "wsmouse.h"
136 #include "wsmux.h"
137 cdev_decl(wskbd);
138 cdev_decl(wsmouse);
139
140 #include "lpt.h"
141
142 #include "radio.h"
143 cdev_decl(radio);
144
145 #include <arm/conf.h>
146
147 /* Block devices */
148
149 struct bdevsw bdevsw[] = {
150 bdev_notdef(), /* 0: */
151 bdev_swap_init(1, sw), /* 1: swap pseudo-device */
152 bdev_notdef(), /* 2: */
153 bdev_notdef(), /* 3: */
154 bdev_notdef(), /* 4: */
155 bdev_notdef(), /* 5: */
156 bdev_notdef(), /* 6: */
157 bdev_notdef(), /* 7: */
158 bdev_notdef(), /* 8: */
159 bdev_notdef(), /* 9: */
160 bdev_notdef(), /* 10: */
161 bdev_notdef(), /* 11: */
162 bdev_notdef(), /* 12: */
163 bdev_notdef(), /* 13: */
164 bdev_notdef(), /* 14: */
165 bdev_notdef(), /* 15: */
166 bdev_disk_init(NWD,wd), /* 16: Internal IDE disk */
167 bdev_notdef(), /* 17: */
168 bdev_disk_init(NRD,rd), /* 18: memory disk */
169 bdev_disk_init(NVND,vnd), /* 19: vnode disk driver */
170 bdev_notdef(), /* 20: */
171 bdev_notdef(), /* 21: was: concatenated disk driver */
172 bdev_notdef(), /* 22: */
173 bdev_notdef(), /* 23: */
174 bdev_disk_init(NSD,sd), /* 24: SCSI disk */
175 bdev_notdef(), /* 25: was: SCSI tape */
176 bdev_disk_init(NCD,cd), /* 26: SCSI cdrom */
177 bdev_notdef(), /* 27: */
178 bdev_notdef(), /* 28: */
179 bdev_notdef(), /* 29: */
180 bdev_notdef(), /* 30: */
181 bdev_notdef(), /* 31: */
182 bdev_notdef(), /* 32: */
183 bdev_notdef(), /* 33: */
184 bdev_notdef(), /* 34: */
185 bdev_notdef(), /* 35: */
186 bdev_notdef(), /* 36: */
187 bdev_notdef(), /* 37: */
188 bdev_notdef(), /* 38: */
189 bdev_notdef(), /* 39: */
190 bdev_notdef(), /* 40: */
191 bdev_notdef(), /* 41: */
192 bdev_notdef(), /* 42: */
193 bdev_notdef(), /* 43: */
194 bdev_notdef(), /* 44: */
195 bdev_notdef(), /* 45: */
196 bdev_notdef(), /* 46: */
197 bdev_notdef(), /* 47: */
198 bdev_notdef(), /* 48: */
199 bdev_notdef(), /* 49: */
200 bdev_notdef(), /* 50: */
201 bdev_notdef(), /* 51: */
202 bdev_notdef(), /* 52: */
203 bdev_notdef(), /* 53: */
204 bdev_notdef(), /* 54: */
205 bdev_notdef(), /* 55: */
206 bdev_notdef(), /* 56: */
207 bdev_notdef(), /* 57: */
208 bdev_notdef(), /* 58: */
209 bdev_notdef(), /* 59: */
210 bdev_notdef(), /* 60: */
211 bdev_notdef(), /* 61: */
212 bdev_notdef(), /* 62: */
213 bdev_notdef(), /* 63: */
214 bdev_notdef(), /* 64: */
215 bdev_notdef(), /* 65: */
216 bdev_notdef(), /* 66: */
217 bdev_notdef(), /* 67: */
218 bdev_notdef(), /* 68: */
219 bdev_notdef(), /* 69: */
220 bdev_notdef(), /* 70: */
221 bdev_notdef(), /* 71 was: RAIDframe disk driver */
222 bdev_notdef(), /* 72: */
223 bdev_notdef(), /* 73: */
224 bdev_notdef(), /* 74: */
225 bdev_notdef(), /* 75: */
226 bdev_notdef(), /* 76: */
227 bdev_notdef(), /* 77: */
228 bdev_notdef(), /* 78: */
229 bdev_notdef(), /* 79: */
230 bdev_notdef(), /* 80: */
231 bdev_notdef(), /* 81: */
232 bdev_notdef(), /* 82: */
233 bdev_notdef(), /* 83: */
234 bdev_notdef(), /* 84: */
235 bdev_notdef(), /* 85: */
236 bdev_notdef(), /* 86: */
237 bdev_notdef(), /* 87: */
238 bdev_notdef(), /* 88: */
239 bdev_notdef(), /* 89: */
240 bdev_notdef(), /* 90: */
241 bdev_notdef(), /* 91: */
242 bdev_notdef(), /* 93: */
243 bdev_notdef(), /* 94: */
244 bdev_notdef(), /* 95: */
245 bdev_notdef(), /* 96: */
246 bdev_notdef(), /* 97: */
247 };
248
249 #include "hotplug.h"
250 #include "vscsi.h"
251 #include "pppx.h"
252 #include "fuse.h"
253 #include "openprom.h"
254
255 #ifdef CONF_HAVE_GPIO
256 #include "gpio.h"
257 #else
258 #define NGPIO 0
259 #endif
260
261 #ifdef CONF_HAVE_SPKR
262 #include "spkr.h"
263 #else
264 #define NSPKR 0
265 #endif
266
267 struct cdevsw cdevsw[] = {
268 cdev_cn_init(1,cn), /* 0: virtual console */
269 cdev_ctty_init(1,ctty), /* 1: controlling terminal */
270 cdev_mm_init(1,mm), /* 2: /dev/{null,mem,kmem,...} */
271 cdev_notdef(), /* 3 was /dev/drum */
272 cdev_tty_init(NPTY,pts), /* 4: pseudo-tty slave */
273 cdev_ptc_init(NPTY,ptc), /* 5: pseudo-tty master */
274 cdev_log_init(1,log), /* 6: /dev/klog */
275 cdev_fd_init(1,filedesc), /* 7: file descriptor pseudo-device */
276 cdev_ksyms_init(NKSYMS,ksyms), /* 8: Kernel symbols device */
277 cdev_lpt_init(NLPT,lpt), /* 9: parallel printer */
278 cdev_notdef(), /* 10: */
279 cdev_notdef(), /* 11: */
280 cdev_tty_init(NCOM,com), /* 12: serial port */
281 cdev_gpio_init(NGPIO,gpio), /* 13: GPIO interface */
282 cdev_notdef(), /* 14 was alternate serial port */
283 cdev_notdef(), /* 15: */
284 cdev_disk_init(NWD,wd), /* 16: ST506/ESDI/IDE disk */
285 cdev_notdef(), /* 17: */
286 cdev_disk_init(NRD,rd), /* 18: ram disk driver */
287 cdev_disk_init(NVND,vnd), /* 19: vnode disk driver */
288 cdev_notdef(), /* 20: */
289 cdev_notdef(), /* 21: was: concatenated disk driver */
290 cdev_bpf_init(NBPFILTER,bpf), /* 22: Berkeley packet filter */
291 cdev_notdef(), /* 23: */
292 cdev_disk_init(NSD,sd), /* 24: SCSI disk */
293 cdev_tape_init(NST,st), /* 25: SCSI tape */
294 cdev_disk_init(NCD,cd), /* 26: SCSI CD-ROM */
295 cdev_ch_init(NCH,ch), /* 27: SCSI autochanger */
296 cdev_uk_init(NUK,uk), /* 28: SCSI unknown */
297 cdev_notdef(), /* 29: */
298 cdev_dt_init(NDT,dt), /* 30: dynamic tracer */
299 cdev_notdef(), /* 31: */
300 cdev_notdef(), /* 32: */
301 cdev_tun_init(NTUN,tun), /* 33: network tunnel */
302 cdev_apm_init(NAPM,apm), /* 34: APM interface */
303 cdev_notdef(), /* 35: was LKM */
304 cdev_audio_init(NAUDIO,audio), /* 36: generic audio I/O */
305 cdev_hotplug_init(NHOTPLUG,hotplug), /* 37: devices hot plugging*/
306 cdev_video_init(NVIDEO,video), /* 38: generic video I/O */
307 cdev_notdef(), /* 39: reserved */
308 cdev_random_init(1,random), /* 40: random generator */
309 cdev_notdef(), /* 41: reserved */
310 cdev_notdef(), /* 42: reserved */
311 cdev_notdef(), /* 43: reserved */
312 cdev_notdef(), /* 44: reserved */
313 cdev_notdef(), /* 45: reserved */
314 cdev_pf_init(NPF,pf), /* 46: packet filter */
315 cdev_notdef(), /* 47: was: /dev/crypto */
316 cdev_notdef(), /* 48: reserved */
317 cdev_notdef(), /* 49: reserved */
318 cdev_notdef(), /* 50: reserved */
319 cdev_kstat_init(NKSTAT,kstat), /* 51: kernel statistics */
320 cdev_bio_init(NBIO,bio), /* 52: ioctl tunnel */
321 cdev_notdef(), /* 53: reserved */
322 cdev_notdef(), /* 54 was FOOTBRIDGE console */
323 cdev_notdef(), /* 55: Reserved for bypass device */
324 cdev_notdef(), /* 56: reserved */
325 cdev_midi_init(NMIDI,midi), /* 57: MIDI I/O */
326 cdev_notdef(), /* 58 was: sequencer I/O */
327 cdev_notdef(), /* 59: reserved */
328 cdev_wsdisplay_init(NWSDISPLAY,wsdisplay), /* 60: frame buffers, etc.*/
329 cdev_mouse_init(NWSKBD,wskbd), /* 61: keyboards */
330 cdev_mouse_init(NWSMOUSE,wsmouse), /* 62: mice */
331 cdev_mouse_init(NWSMUX,wsmux), /* 63: ws multiplexor */
332 cdev_usb_init(NUSB,usb), /* 64: USB controller */
333 cdev_usbdev_init(NUHID,uhid), /* 65: USB generic HID */
334 cdev_ulpt_init(NULPT,ulpt), /* 66: USB printer */
335 cdev_notdef(), /* 67: was urio */
336 cdev_tty_init(NUCOM,ucom), /* 68: USB tty */
337 cdev_notdef(), /* 69: was USB scanners */
338 cdev_usbdev_init(NUGEN,ugen), /* 70: USB generic driver */
339 cdev_notdef(), /* 71 was: RAIDframe disk driver */
340 cdev_notdef(), /* 72: reserved */
341 cdev_notdef(), /* 73: reserved */
342 cdev_notdef(), /* 74: reserved */
343 cdev_notdef(), /* 75: reserved */
344 cdev_notdef(), /* 76: reserved */
345 cdev_fuse_init(NFUSE,fuse), /* 77: fuse */
346 cdev_notdef(), /* 78: removed device */
347 cdev_notdef(), /* 79: removed device */
348 cdev_notdef(), /* 80: removed device */
349 cdev_notdef(), /* 81: removed device */
350 cdev_openprom_init(NOPENPROM,openprom), /* 82: /dev/openprom */
351 cdev_notdef(), /* 83: removed device */
352 cdev_notdef(), /* 84: removed device */
353 cdev_notdef(), /* 85: removed device */
354 cdev_notdef(), /* 86: removed device */
355 cdev_notdef(), /* 87: removed device */
356 #ifdef USER_PCICONF
357 cdev_pci_init(NPCI,pci), /* 88: PCI user */
358 #else
359 cdev_notdef(),
360 #endif
361 cdev_notdef(), /* 89: removed device */
362 cdev_notdef(), /* 90: removed device */
363 cdev_notdef(), /* 91: removed device */
364 cdev_notdef(), /* 92: removed device */
365 cdev_notdef(), /* 93: removed device */
366 cdev_notdef(), /* 94: removed device */
367 cdev_notdef(), /* 95: removed device */
368 cdev_notdef(), /* 96: removed device */
369 cdev_radio_init(NRADIO,radio), /* 97: generic radio I/O */
370 cdev_ptm_init(NPTY,ptm), /* 98: pseudo-tty ptm device */
371 cdev_spkr_init(NSPKR,spkr), /* 99: PC speaker */
372 cdev_vscsi_init(NVSCSI,vscsi), /* 100: vscsi */
373 cdev_notdef(),
374 cdev_disk_init(1,diskmap), /* 102: disk mapper */
375 cdev_pppx_init(NPPPX,pppx), /* 103: pppx */
376 cdev_tun_init(NTUN,tap), /* 104: Ethernet tap */
377 cdev_notdef(), /* 105: was switch(4) */
378 cdev_fido_init(NFIDO,fido), /* 106: FIDO/U2F security key */
379 cdev_pppx_init(NPPPX,pppac), /* 107: PPP Access Concentrator */
380 cdev_ujoy_init(NUJOY,ujoy), /* 108: USB joystick/gamecontroller */
381 };
382
383 int nblkdev = nitems(bdevsw);
384 int nchrdev = nitems(cdevsw);
385
386 int mem_no = 2; /* major device number of memory special file */
387
388 /*
389 * Swapdev is a fake device implemented
390 * in sw.c used only internally to get to swstrategy.
391 * It cannot be provided to the users, because the
392 * swstrategy routine munches the b_dev and b_blkno entries
393 * before calling the appropriate driver. This would horribly
394 * confuse, e.g. the hashing routines. Instead, /dev/drum is
395 * provided as a character (raw) device.
396 */
397 dev_t swapdev = makedev(1, 0);
398
399 /*
400 * Returns true if dev is /dev/mem or /dev/kmem.
401 */
402 int
iskmemdev(dev_t dev)403 iskmemdev(dev_t dev)
404 {
405 return (major(dev) == mem_no && minor(dev) < 2);
406 }
407
408 /*
409 * Returns true if dev is /dev/zero.
410 */
411 int
iszerodev(dev_t dev)412 iszerodev(dev_t dev)
413 {
414 return (major(dev) == mem_no && minor(dev) == 3);
415 }
416
417
418 const int chrtoblktbl[] = {
419 /*VCHR*/ /*VBLK*/
420 /* 0 */ NODEV,
421 /* 1 */ NODEV,
422 /* 2 */ NODEV,
423 /* 3 */ NODEV,
424 /* 4 */ NODEV,
425 /* 5 */ NODEV,
426 /* 6 */ NODEV,
427 /* 7 */ NODEV,
428 /* 8 */ NODEV,
429 /* 9 */ NODEV,
430 /* 10 */ NODEV,
431 /* 11 */ NODEV,
432 /* 12 */ NODEV,
433 /* 13 */ NODEV,
434 /* 14 */ NODEV,
435 /* 15 */ NODEV,
436 /* 16 */ 16, /* wd */
437 /* 17 */ NODEV,
438 /* 18 */ 18, /* rd */
439 /* 19 */ 19, /* vnd */
440 /* 20 */ NODEV,
441 /* 21 */ NODEV,
442 /* 22 */ NODEV,
443 /* 23 */ NODEV,
444 /* 24 */ 24, /* sd */
445 /* 25 */ NODEV,
446 /* 26 */ 26, /* cd */
447 };
448 const int nchrtoblktbl = nitems(chrtoblktbl);
449
450 dev_t
getnulldev(void)451 getnulldev(void)
452 {
453 return makedev(mem_no, 2);
454 }
455