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