1 /* $NetBSD: conf.c,v 1.7 2002/01/12 13:33:42 manu Exp $ */ 2 3 /* 4 * Copyright (c) 1994, 1995 Charles M. Hannum. All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 3. All advertising materials mentioning features or use of this software 15 * must display the following acknowledgement: 16 * This product includes software developed by Charles Hannum. 17 * 4. The name of the author may not be used to endorse or promote products 18 * derived from this software without specific prior written permission. 19 * 20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 21 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 22 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 23 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 24 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 25 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 29 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 */ 31 32 #include <sys/param.h> 33 #include <sys/systm.h> 34 #include <sys/buf.h> 35 #include <sys/ioctl.h> 36 #include <sys/tty.h> 37 #include <sys/conf.h> 38 #include <sys/vnode.h> 39 40 #include <machine/conf.h> 41 42 #include "wd.h" 43 bdev_decl(wd); 44 bdev_decl(sw); 45 #include "sd.h" 46 bdev_decl(sd); 47 #include "st.h" 48 bdev_decl(st); 49 #include "cd.h" 50 bdev_decl(cd); 51 #include "vnd.h" 52 bdev_decl(vnd); 53 #include "ccd.h" 54 bdev_decl(ccd); 55 #include "raid.h" 56 bdev_decl(raid); 57 #include "md.h" 58 bdev_decl(md); 59 60 struct bdevsw bdevsw[] = 61 { 62 bdev_disk_init(NWD,wd), /* 0: ST506/ESDI/IDE disk */ 63 bdev_swap_init(1,sw), /* 1: swap pseudo-device */ 64 bdev_notdef(), /* 2 (was floppy diskette) */ 65 bdev_notdef(), /* 3 (was QIC-02/QIC-36 tape) */ 66 bdev_disk_init(NSD,sd), /* 4: SCSI disk */ 67 bdev_tape_init(NST,st), /* 5: SCSI tape */ 68 bdev_disk_init(NCD,cd), /* 6: SCSI CD-ROM */ 69 bdev_notdef(), /* 7 (was Mitsumi CD-ROM) */ 70 bdev_lkm_dummy(), /* 8 */ 71 bdev_lkm_dummy(), /* 9 */ 72 bdev_lkm_dummy(), /* 10 */ 73 bdev_lkm_dummy(), /* 11 */ 74 bdev_lkm_dummy(), /* 12 */ 75 bdev_lkm_dummy(), /* 13 */ 76 bdev_disk_init(NVND,vnd), /* 14: vnode disk driver */ 77 bdev_notdef(), /* 15 (was Sony CD-ROM) */ 78 bdev_disk_init(NCCD,ccd), /* 16: concatenated disk driver */ 79 bdev_disk_init(NMD,md), /* 17: memory disk driver */ 80 bdev_disk_init(NRAID,raid), /* 18: RAIDframe disk driver */ 81 }; 82 int nblkdev = sizeof(bdevsw) / sizeof(bdevsw[0]); 83 84 cdev_decl(cn); 85 cdev_decl(ctty); 86 #define mmread mmrw 87 #define mmwrite mmrw 88 cdev_decl(mm); 89 #include "wdog.h" 90 cdev_decl(wdog); 91 cdev_decl(wd); 92 cdev_decl(sw); 93 #include "pty.h" 94 #define ptstty ptytty 95 #define ptsioctl ptyioctl 96 cdev_decl(pts); 97 #define ptctty ptytty 98 #define ptcioctl ptyioctl 99 cdev_decl(ptc); 100 cdev_decl(log); 101 #include "com.h" 102 cdev_decl(com); 103 cdev_decl(fd); 104 cdev_decl(sd); 105 cdev_decl(st); 106 #include "ss.h" 107 cdev_decl(ss); 108 #include "uk.h" 109 cdev_decl(uk); 110 cdev_decl(cd); 111 #include "ch.h" 112 cdev_decl(ch); 113 dev_decl(filedesc,open); 114 #include "bpfilter.h" 115 cdev_decl(bpf); 116 cdev_decl(md); 117 #include "cy.h" 118 cdev_decl(cy); 119 #include "tun.h" 120 cdev_decl(tun); 121 cdev_decl(vnd); 122 #include "audio.h" 123 cdev_decl(audio); 124 cdev_decl(svr4_net); 125 cdev_decl(ccd); 126 cdev_decl(raid); 127 #include "vcoda.h" 128 cdev_decl(vc_nb_); 129 130 #include "esh.h" 131 cdev_decl(esh_fp); 132 #include "scsibus.h" 133 cdev_decl(scsibus); 134 135 #include "ipfilter.h" 136 #include "rnd.h" 137 138 #include "clockctl.h" 139 cdev_decl(clockctl); 140 141 struct cdevsw cdevsw[] = 142 { 143 cdev_cn_init(1,cn), /* 0: virtual console */ 144 cdev_ctty_init(1,ctty), /* 1: controlling terminal */ 145 cdev_mm_init(1,mm), /* 2: /dev/{null,mem,kmem,...} */ 146 cdev_disk_init(NWD,wd), /* 3: ST506/ESDI/IDE disk */ 147 cdev_swap_init(1,sw), /* 4: /dev/drum (swap pseudo-device) */ 148 cdev_tty_init(NPTY,pts), /* 5: pseudo-tty slave */ 149 cdev_ptc_init(NPTY,ptc), /* 6: pseudo-tty master */ 150 cdev_log_init(1,log), /* 7: /dev/klog */ 151 cdev_tty_init(NCOM,com), /* 8: serial port */ 152 cdev_notdef(), /* 9 (was floppy disk) */ 153 cdev_notdef(), /* 10 (was QIC-02/QIC-36 tape) */ 154 cdev_notdef(), /* 11: */ 155 cdev_notdef(), /* 12: (was PC console) */ 156 cdev_disk_init(NSD,sd), /* 13: SCSI disk */ 157 cdev_tape_init(NST,st), /* 14: SCSI tape */ 158 cdev_disk_init(NCD,cd), /* 15: SCSI CD-ROM */ 159 cdev_notdef(), /* 16: (was parallel printer) */ 160 cdev_ch_init(NCH,ch), /* 17: SCSI autochanger */ 161 cdev_disk_init(NCCD,ccd), /* 18: concatenated disk driver */ 162 cdev_scanner_init(NSS,ss), /* 19: SCSI scanner */ 163 cdev_uk_init(NUK,uk), /* 20: SCSI unknown */ 164 cdev_notdef(), /* 21 (was APM) */ 165 cdev_fd_init(1,filedesc), /* 22: file descriptor pseudo-device */ 166 cdev_bpftun_init(NBPFILTER,bpf),/* 23: Berkeley packet filter */ 167 cdev_disk_init(NMD,md), /* 24: memory disk driver */ 168 cdev_notdef(), /* 25 */ 169 cdev_notdef(), /* 26 (was joystick) */ 170 cdev_notdef(), /* 27 (was PC speaker) */ 171 cdev_lkm_init(NLKM,lkm), /* 28: loadable module driver */ 172 cdev_lkm_dummy(), /* 29 */ 173 cdev_lkm_dummy(), /* 30 */ 174 cdev_lkm_dummy(), /* 31 */ 175 cdev_lkm_dummy(), /* 32 */ 176 cdev_lkm_dummy(), /* 33 */ 177 cdev_lkm_dummy(), /* 34 */ 178 cdev_notdef(), /* 35 (was Microsoft mouse) */ 179 cdev_notdef(), /* 36 (was Logitech mouse) */ 180 cdev_notdef(), /* 37 (was PS/2 mouse) */ 181 cdev_notdef(), /* 38 (was Cyclom serial port) */ 182 cdev_notdef(), /* 39 (was Mitsumi CD-ROM) */ 183 cdev_bpftun_init(NTUN,tun), /* 40: network tunnel */ 184 cdev_disk_init(NVND,vnd), /* 41: vnode disk driver */ 185 cdev_audio_init(NAUDIO,audio), /* 42: generic audio I/O */ 186 cdev_notdef(), /* 43 */ 187 cdev_ipf_init(NIPFILTER,ipl), /* 44: ip-filter device */ 188 cdev_notdef(), /* 45 (was planetconnect satlink) */ 189 cdev_rnd_init(NRND,rnd), /* 46: random source pseudo-device */ 190 cdev_vc_nb_init(NVCODA,vc_nb_), /* 47: coda file system psdev */ 191 cdev_scsibus_init(NSCSIBUS,scsibus), /* 48: SCSI bus */ 192 cdev_disk_init(NRAID,raid), /* 49: RAIDframe disk driver */ 193 cdev_esh_init(NESH, esh_fp), /* 50: HIPPI (esh) raw device */ 194 cdev_wdog_init(NWDOG,wdog), /* 51: watchdog timer */ 195 cdev_clockctl_init(NCLOCKCTL, clockctl),/* 52: clockctl pseudo device */ 196 }; 197 int nchrdev = sizeof(cdevsw) / sizeof(cdevsw[0]); 198 199 int mem_no = 2; /* major device number of memory special file */ 200 201 /* 202 * Swapdev is a fake device implemented 203 * in sw.c used only internally to get to swstrategy. 204 * It cannot be provided to the users, because the 205 * swstrategy routine munches the b_dev and b_blkno entries 206 * before calling the appropriate driver. This would horribly 207 * confuse, e.g. the hashing routines. Instead, /dev/drum is 208 * provided as a character (raw) device. 209 */ 210 dev_t swapdev = makedev(1, 0); 211 212 /* 213 * Returns true if dev is /dev/mem or /dev/kmem. 214 */ 215 int 216 iskmemdev(dev) 217 dev_t dev; 218 { 219 220 return (major(dev) == mem_no && (minor(dev) < 2 || minor(dev) == 14)); 221 } 222 223 /* 224 * Returns true if dev is /dev/zero. 225 */ 226 int 227 iszerodev(dev) 228 dev_t dev; 229 { 230 231 return (major(dev) == mem_no && minor(dev) == 12); 232 } 233 234 static int chrtoblktbl[] = { 235 /* XXXX This needs to be dynamic for LKMs. */ 236 /*VCHR*/ /*VBLK*/ 237 /* 0 */ NODEV, 238 /* 1 */ NODEV, 239 /* 2 */ NODEV, 240 /* 3 */ 0, 241 /* 4 */ NODEV, 242 /* 5 */ NODEV, 243 /* 6 */ NODEV, 244 /* 7 */ NODEV, 245 /* 8 */ NODEV, 246 /* 9 */ NODEV, 247 /* 10 */ NODEV, 248 /* 11 */ NODEV, 249 /* 12 */ NODEV, 250 /* 13 */ 4, 251 /* 14 */ 5, 252 /* 15 */ 6, 253 /* 16 */ NODEV, 254 /* 17 */ NODEV, 255 /* 18 */ 16, 256 /* 19 */ NODEV, 257 /* 20 */ NODEV, 258 /* 21 */ NODEV, 259 /* 22 */ NODEV, 260 /* 23 */ NODEV, 261 /* 24 */ 17, 262 /* 25 */ NODEV, 263 /* 26 */ NODEV, 264 /* 27 */ NODEV, 265 /* 28 */ NODEV, 266 /* 29 */ NODEV, 267 /* 30 */ NODEV, 268 /* 31 */ NODEV, 269 /* 32 */ NODEV, 270 /* 33 */ NODEV, 271 /* 34 */ NODEV, 272 /* 35 */ NODEV, 273 /* 36 */ NODEV, 274 /* 37 */ NODEV, 275 /* 38 */ NODEV, 276 /* 39 */ NODEV, 277 /* 40 */ NODEV, 278 /* 41 */ 14, 279 /* 42 */ NODEV, 280 /* 43 */ NODEV, 281 /* 44 */ NODEV, 282 /* 45 */ NODEV, 283 /* 46 */ NODEV, 284 /* 47 */ NODEV, 285 /* 48 */ NODEV, 286 /* 49 */ NODEV, 287 /* 50 */ NODEV, 288 /* 51 */ NODEV, 289 /* 52 */ NODEV, 290 }; 291 292 /* 293 * Convert a character device number to a block device number. 294 */ 295 dev_t 296 chrtoblk(dev) 297 dev_t dev; 298 { 299 int blkmaj; 300 301 if (major(dev) >= nchrdev) 302 return (NODEV); 303 blkmaj = chrtoblktbl[major(dev)]; 304 if (blkmaj == NODEV) 305 return (NODEV); 306 return (makedev(blkmaj, minor(dev))); 307 } 308 309 #include <dev/cons.h> 310 311 #define scicnpollc nullcnpollc 312 cons_decl(sci); 313 cons_decl(com); 314 315 struct consdev constab[] = { 316 #if NSCI > 0 317 cons_init(sci), 318 #endif 319 #if NCOM > 0 320 cons_init(com), 321 #endif 322 { 0 }, 323 }; 324