1 /* $OpenBSD: conf.c,v 1.13 2011/10/06 20:49:28 deraadt Exp $ */ 2 3 /* 4 * Copyright (c) 1992, 1993 5 * The Regents of the University of California. All rights reserved. 6 * 7 * This code is derived from software contributed to Berkeley by 8 * Ralph Campbell. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 3. All advertising materials mentioning features or use of this software 19 * must display the following acknowledgement: 20 * This product includes software developed by the University of 21 * California, Berkeley and its contributors. 22 * 4. Neither the name of the University nor the names of its contributors 23 * may be used to endorse or promote products derived from this software 24 * without specific prior written permission. 25 * 26 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 27 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 29 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 30 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 36 * SUCH DAMAGE. 37 */ 38 39 #include <sys/param.h> 40 #include <sys/systm.h> 41 #include <sys/buf.h> 42 #include <sys/ioctl.h> 43 #include <sys/proc.h> 44 #include <sys/vnode.h> 45 #include <sys/tty.h> 46 47 #include <machine/conf.h> 48 49 /* 50 * Block devices. 51 */ 52 53 #include "vnd.h" 54 #include "sd.h" 55 #include "cd.h" 56 #include "st.h" 57 #include "wd.h" 58 bdev_decl(wd); 59 #include "rd.h" 60 #include "hotplug.h" 61 62 struct bdevsw bdevsw[] = 63 { 64 bdev_disk_init(NSD,sd), /* 0: SCSI disk */ 65 bdev_swap_init(1,sw), /* 1: should be here swap pseudo-dev */ 66 bdev_disk_init(NVND,vnd), /* 2: vnode disk driver */ 67 bdev_disk_init(NCD,cd), /* 3: SCSI CD-ROM */ 68 bdev_disk_init(NWD,wd), /* 4: ST506/ESDI/IDE disk */ 69 bdev_notdef(), /* 5: */ 70 bdev_notdef(), /* 6: was: concatenated disk driver */ 71 bdev_notdef(), /* 7: */ 72 bdev_disk_init(NRD,rd), /* 8: RAM disk (for install) */ 73 bdev_notdef(), /* 9: */ 74 bdev_tape_init(NST,st), /* 10: SCSI tape */ 75 bdev_notdef(), /* 11: */ 76 bdev_notdef(), /* 12: */ 77 bdev_notdef(), /* 13: */ 78 bdev_notdef(), /* 14: */ 79 bdev_notdef(), /* 15: */ 80 }; 81 82 int nblkdev = nitems(bdevsw); 83 84 /* 85 * Character devices. 86 */ 87 88 #define mmread mmrw 89 #define mmwrite mmrw 90 dev_type_read(mmrw); 91 cdev_decl(mm); 92 #include "bio.h" 93 #include "pty.h" 94 cdev_decl(fd); 95 #include "st.h" 96 #include "bpfilter.h" 97 #include "tun.h" 98 #include "apm.h" 99 #include "com.h" 100 cdev_decl(com); 101 #include "lpt.h" 102 cdev_decl(lpt); 103 #include "ch.h" 104 #include "uk.h" 105 cdev_decl(wd); 106 #include "audio.h" 107 #include "video.h" 108 #ifdef NNPFS 109 #include <nnpfs/nnnpfs.h> 110 cdev_decl(nnpfs_dev); 111 #endif 112 #include "ksyms.h" 113 114 #include "wsdisplay.h" 115 #include "wskbd.h" 116 #include "wsmouse.h" 117 #include "wsmux.h" 118 #include "pci.h" 119 cdev_decl(pci); 120 121 #include "inet.h" 122 123 #include "pf.h" 124 #include "systrace.h" 125 126 #include "usb.h" 127 #include "uhid.h" 128 #include "ugen.h" 129 #include "ulpt.h" 130 #include "urio.h" 131 #include "ucom.h" 132 #include "uscanner.h" 133 134 #include "bthub.h" 135 #include "vscsi.h" 136 #include "pppx.h" 137 138 struct cdevsw cdevsw[] = 139 { 140 cdev_cn_init(1,cn), /* 0: virtual console */ 141 cdev_notdef(), /* 1: was /dev/drum */ 142 cdev_ctty_init(1,ctty), /* 2: controlling terminal */ 143 cdev_mm_init(1,mm), /* 3: /dev/{null,mem,kmem,...} */ 144 cdev_tty_init(NPTY,pts), /* 4: pseudo-tty slave */ 145 cdev_ptc_init(NPTY,ptc), /* 5: pseudo-tty master */ 146 cdev_log_init(1,log), /* 6: /dev/klog */ 147 cdev_fd_init(1,filedesc), /* 7: file descriptor pseudo-dev */ 148 cdev_disk_init(NCD,cd), /* 8: SCSI CD */ 149 cdev_disk_init(NSD,sd), /* 9: SCSI disk */ 150 cdev_tape_init(NST,st), /* 10: SCSI tape */ 151 cdev_disk_init(NVND,vnd), /* 11: vnode disk */ 152 cdev_bpf_init(NBPFILTER,bpf), /* 12: berkeley packet filter */ 153 cdev_tun_init(NTUN,tun), /* 13: network tunnel */ 154 cdev_apm_init(NAPM,apm), /* 14: apm */ 155 cdev_notdef(), /* 15: */ 156 cdev_lpt_init(NLPT,lpt), /* 16: Parallel printer interface */ 157 cdev_tty_init(NCOM,com), /* 17: 16C450 serial interface */ 158 cdev_disk_init(NWD,wd), /* 18: ST506/ESDI/IDE disk */ 159 cdev_notdef(), /* 19: */ 160 cdev_notdef(), /* 20: */ 161 cdev_notdef(), /* 21: */ 162 cdev_disk_init(NRD,rd), /* 22: ramdisk device */ 163 cdev_notdef(), /* 23: was: concatenated disk driver */ 164 cdev_notdef(), /* 24: */ 165 cdev_wsdisplay_init(NWSDISPLAY, wsdisplay), /* 25: */ 166 cdev_mouse_init(NWSKBD, wskbd), /* 26: */ 167 cdev_mouse_init(NWSMOUSE, wsmouse), /* 27: */ 168 cdev_mouse_init(NWSMUX, wsmux), /* 28: */ 169 #ifdef USER_PCICONF 170 cdev_pci_init(NPCI,pci), /* 29: PCI user */ 171 #else 172 cdev_notdef(), /* 29 */ 173 #endif 174 cdev_notdef(), /* 30: */ 175 cdev_pf_init(NPF,pf), /* 31: packet filter */ 176 cdev_uk_init(NUK,uk), /* 32: unknown SCSI */ 177 cdev_random_init(1,random), /* 33: random data source */ 178 cdev_notdef(), /* 34: */ 179 cdev_ksyms_init(NKSYMS,ksyms), /* 35: Kernel symbols device */ 180 cdev_ch_init(NCH,ch), /* 36: SCSI autochanger */ 181 cdev_notdef(), /* 37: */ 182 cdev_notdef(), /* 38: */ 183 cdev_notdef(), /* 39: */ 184 cdev_notdef(), /* 40: */ 185 cdev_notdef(), /* 41: */ 186 cdev_notdef(), /* 42: */ 187 cdev_notdef(), /* 33: */ 188 cdev_audio_init(NAUDIO,audio), /* 44: /dev/audio */ 189 cdev_video_init(NVIDEO,video), /* 45: generic video I/O */ 190 cdev_notdef(), /* 46: */ 191 cdev_crypto_init(NCRYPTO,crypto), /* 47: /dev/crypto */ 192 cdev_notdef(), /* 48: */ 193 cdev_bio_init(NBIO,bio), /* 49: ioctl tunnel */ 194 cdev_systrace_init(NSYSTRACE,systrace), /* 50: system call tracing */ 195 #ifdef NNPFS 196 cdev_nnpfs_init(NNNPFS,nnpfs_dev), /* 51: nnpfs communication device */ 197 #else 198 cdev_notdef(), /* 51: */ 199 #endif 200 cdev_ptm_init(NPTY,ptm), /* 52: pseudo-tty ptm device */ 201 cdev_notdef(), /* 53: */ 202 cdev_notdef(), /* 54: */ 203 cdev_notdef(), /* 55: */ 204 cdev_notdef(), /* 56: */ 205 cdev_notdef(), /* 57: */ 206 cdev_notdef(), /* 58: */ 207 cdev_notdef(), /* 59: */ 208 cdev_notdef(), /* 60: */ 209 cdev_usb_init(NUSB,usb), /* 61: USB controller */ 210 cdev_usbdev_init(NUHID,uhid), /* 62: USB generic HID */ 211 cdev_usbdev_init(NUGEN,ugen), /* 63: USB generic driver */ 212 cdev_ulpt_init(NULPT,ulpt), /* 64: USB printers */ 213 cdev_urio_init(NURIO,urio), /* 65: USB Diamond Rio 500 */ 214 cdev_tty_init(NUCOM,ucom), /* 66: USB tty */ 215 cdev_hotplug_init(NHOTPLUG,hotplug), /* 67: devices hotplugging */ 216 cdev_bthub_init(NBTHUB,bthub), /* 68: bluetooth hub */ 217 cdev_vscsi_init(NVSCSI,vscsi), /* 69: vscsi */ 218 cdev_disk_init(1,diskmap), /* 70: disk mapper */ 219 cdev_pppx_init(NPPPX,pppx), /* 71: pppx */ 220 cdev_usbdev_init(NUSCANNER,uscanner), /* 72: USB scanners */ 221 }; 222 223 int nchrdev = nitems(cdevsw); 224 225 /* 226 * Swapdev is a fake device implemented 227 * in sw.c used only internally to get to swstrategy. 228 * It cannot be provided to the users, because the 229 * swstrategy routine munches the b_dev and b_blkno entries 230 * before calling the appropriate driver. This would horribly 231 * confuse, e.g. the hashing routines. Instead, /dev/drum is 232 * provided as a character (raw) device. 233 */ 234 dev_t swapdev = makedev(1, 0); 235 236 /* 237 * Routine that identifies /dev/mem and /dev/kmem. 238 * 239 * A minimal stub routine can always return 0. 240 */ 241 int 242 iskmemdev(dev) 243 dev_t dev; 244 { 245 246 if (major(dev) == 3 && (minor(dev) == 0 || minor(dev) == 1)) 247 return (1); 248 return (0); 249 } 250 251 /* 252 * Returns true if def is /dev/zero 253 */ 254 int 255 iszerodev(dev) 256 dev_t dev; 257 { 258 return (major(dev) == 3 && minor(dev) == 12); 259 } 260 261 dev_t 262 getnulldev() 263 { 264 return(makedev(3, 2)); 265 } 266 267 268 int chrtoblktbl[] = { 269 /* VCHR VBLK */ 270 /* 0 */ NODEV, 271 /* 1 */ NODEV, 272 /* 2 */ NODEV, 273 /* 3 */ NODEV, 274 /* 4 */ NODEV, 275 /* 5 */ NODEV, 276 /* 6 */ NODEV, 277 /* 7 */ NODEV, 278 /* 8 */ 3, /* cd */ 279 /* 9 */ 0, /* sd */ 280 /* 10 */ 10, /* st */ 281 /* 11 */ 2, /* vnd */ 282 /* 12 */ NODEV, 283 /* 13 */ NODEV, 284 /* 14 */ NODEV, 285 /* 15 */ NODEV, 286 /* 16 */ NODEV, 287 /* 17 */ NODEV, 288 /* 18 */ 4, /* wd */ 289 /* 19 */ NODEV, 290 /* 20 */ NODEV, 291 /* 21 */ NODEV, 292 /* 22 */ 8 /* rd */ 293 }; 294 295 int nchrtoblktbl = nitems(chrtoblktbl); 296 297 #include <dev/cons.h> 298 299 cons_decl(ws); 300 cons_decl(com); 301 302 struct consdev constab[] = { 303 #if NWSDISPLAY > 0 304 cons_init(ws), 305 #endif 306 #if NCOM > 0 307 cons_init(com), 308 #endif 309 { 0 }, 310 }; 311