1 /* $NetBSD: conf.c,v 1.6 2002/03/24 18:13:01 uch 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 #include "gdrom.h" 60 bdev_decl(gdrom); 61 62 struct bdevsw bdevsw[] = 63 { 64 bdev_disk_init(NWD,wd), /* 0: ST506/ESDI/IDE disk */ 65 bdev_swap_init(1,sw), /* 1: swap pseudo-device */ 66 bdev_notdef(), /* 2 */ 67 bdev_notdef(), /* 3 */ 68 bdev_disk_init(NSD,sd), /* 4: SCSI disk */ 69 bdev_tape_init(NST,st), /* 5: SCSI tape */ 70 bdev_disk_init(NCD,cd), /* 6: SCSI CD-ROM */ 71 bdev_notdef(), /* 7 */ 72 bdev_lkm_dummy(), /* 8 */ 73 bdev_lkm_dummy(), /* 9 */ 74 bdev_lkm_dummy(), /* 10 */ 75 bdev_lkm_dummy(), /* 11 */ 76 bdev_lkm_dummy(), /* 12 */ 77 bdev_lkm_dummy(), /* 13 */ 78 bdev_disk_init(NVND,vnd), /* 14: vnode disk driver */ 79 bdev_notdef(), /* 15 */ 80 bdev_disk_init(NCCD,ccd), /* 16: concatenated disk driver */ 81 bdev_disk_init(NMD,md), /* 17: memory disk driver */ 82 bdev_disk_init(NRAID,raid), /* 18: RAIDframe disk driver */ 83 bdev_disk_init(NGDROM,gdrom), /* 19: GDROM */ 84 }; 85 int nblkdev = sizeof(bdevsw) / sizeof(bdevsw[0]); 86 87 cdev_decl(cn); 88 cdev_decl(ctty); 89 #define mmread mmrw 90 #define mmwrite mmrw 91 cdev_decl(mm); 92 #include "wdog.h" 93 cdev_decl(wdog); 94 cdev_decl(wd); 95 cdev_decl(sw); 96 #include "pty.h" 97 #define ptstty ptytty 98 #define ptsioctl ptyioctl 99 cdev_decl(pts); 100 #define ptctty ptytty 101 #define ptcioctl ptyioctl 102 cdev_decl(ptc); 103 cdev_decl(log); 104 #include "scif.h" 105 cdev_decl(scif); 106 cdev_decl(sd); 107 cdev_decl(st); 108 #include "ss.h" 109 cdev_decl(ss); 110 #include "uk.h" 111 cdev_decl(uk); 112 cdev_decl(cd); 113 #include "ch.h" 114 cdev_decl(ch); 115 dev_decl(filedesc,open); 116 #include "bpfilter.h" 117 cdev_decl(bpf); 118 cdev_decl(md); 119 #include "cy.h" 120 cdev_decl(cy); 121 #include "tun.h" 122 cdev_decl(tun); 123 cdev_decl(vnd); 124 #include "audio.h" 125 cdev_decl(audio); 126 cdev_decl(svr4_net); 127 cdev_decl(ccd); 128 cdev_decl(raid); 129 #include "vcoda.h" 130 cdev_decl(vc_nb_); 131 132 #include "esh.h" 133 cdev_decl(esh_fp); 134 #include "scsibus.h" 135 cdev_decl(scsibus); 136 137 #include "pvr.h" 138 #include "mkbd.h" 139 140 #include "ipfilter.h" 141 #include "rnd.h" 142 143 #include "wsdisplay.h" 144 cdev_decl(wsdisplay); 145 #include "wskbd.h" 146 cdev_decl(wskbd); 147 #include "wsmouse.h" 148 cdev_decl(wsmouse); 149 #include "wsmux.h" 150 cdev_decl(wsmux); 151 152 cdev_decl(gdrom); 153 #include "maple.h" 154 cdev_decl(maple); 155 156 #include "clockctl.h" 157 cdev_decl(clockctl); 158 159 struct cdevsw cdevsw[] = 160 { 161 cdev_cn_init(1,cn), /* 0: virtual console */ 162 cdev_ctty_init(1,ctty), /* 1: controlling terminal */ 163 cdev_mm_init(1,mm), /* 2: /dev/{null,mem,kmem,...} */ 164 cdev_disk_init(NWD,wd), /* 3: ST506/ESDI/IDE disk */ 165 cdev_swap_init(1,sw), /* 4: /dev/drum (swap pseudo-device) */ 166 cdev_tty_init(NPTY,pts), /* 5: pseudo-tty slave */ 167 cdev_ptc_init(NPTY,ptc), /* 6: pseudo-tty master */ 168 cdev_log_init(1,log), /* 7: /dev/klog */ 169 cdev_notdef(), /* 8 */ 170 cdev_notdef(), /* 9 */ 171 cdev_tty_init(NSCIF,scif), /* 10: serial with FIFO */ 172 cdev_notdef(), /* 11: */ 173 cdev_notdef(), /* 12: */ 174 cdev_disk_init(NSD,sd), /* 13: SCSI disk */ 175 cdev_tape_init(NST,st), /* 14: SCSI tape */ 176 cdev_disk_init(NCD,cd), /* 15: SCSI CD-ROM */ 177 cdev_notdef(), /* 16: */ 178 cdev_ch_init(NCH,ch), /* 17: SCSI autochanger */ 179 cdev_disk_init(NCCD,ccd), /* 18: concatenated disk driver */ 180 cdev_scanner_init(NSS,ss), /* 19: SCSI scanner */ 181 cdev_uk_init(NUK,uk), /* 20: SCSI unknown */ 182 cdev_notdef(), /* 21 */ 183 cdev_fd_init(1,filedesc), /* 22: file descriptor pseudo-device */ 184 cdev_bpftun_init(NBPFILTER,bpf),/* 23: Berkeley packet filter */ 185 cdev_disk_init(NMD,md), /* 24: memory disk driver */ 186 cdev_notdef(), /* 25 */ 187 cdev_notdef(), /* 26 */ 188 cdev_notdef(), /* 27 */ 189 cdev_lkm_init(NLKM,lkm), /* 28: loadable module driver */ 190 cdev_lkm_dummy(), /* 29 */ 191 cdev_lkm_dummy(), /* 30 */ 192 cdev_lkm_dummy(), /* 31 */ 193 cdev_lkm_dummy(), /* 32 */ 194 cdev_lkm_dummy(), /* 33 */ 195 cdev_lkm_dummy(), /* 34 */ 196 cdev_notdef(), /* 35 */ 197 cdev_notdef(), /* 36 */ 198 cdev_notdef(), /* 37 */ 199 cdev_notdef(), /* 38 */ 200 cdev_notdef(), /* 39 */ 201 cdev_bpftun_init(NTUN,tun), /* 40: network tunnel */ 202 cdev_disk_init(NVND,vnd), /* 41: vnode disk driver */ 203 cdev_audio_init(NAUDIO,audio), /* 42: generic audio I/O */ 204 cdev_notdef(), /* 43 */ 205 cdev_ipf_init(NIPFILTER,ipl), /* 44: ip-filter device */ 206 cdev_notdef(), /* 45 */ 207 cdev_rnd_init(NRND,rnd), /* 46: random source pseudo-device */ 208 cdev_vc_nb_init(NVCODA,vc_nb_), /* 47: coda file system psdev */ 209 cdev_scsibus_init(NSCSIBUS,scsibus), /* 48: SCSI bus */ 210 cdev_disk_init(NRAID,raid), /* 49: RAIDframe disk driver */ 211 cdev_esh_init(NESH, esh_fp), /* 50: HIPPI (esh) raw device */ 212 cdev_wdog_init(NWDOG,wdog), /* 51: watchdog timer */ 213 214 cdev_wsdisplay_init(NWSDISPLAY, wsdisplay), /* 52: frame buffers, etc. */ 215 cdev_mouse_init(NWSKBD, wskbd), /* 53: keyboards */ 216 cdev_mouse_init(NWSMOUSE, wsmouse), /* 54: mice */ 217 cdev_svr4_net_init(NSVR4_NET,svr4_net), /* 55: svr4 net pseudo-device */ 218 cdev_mouse_init(NWSMUX, wsmux), /* 56: ws multiplexor */ 219 cdev_disk_init(NGDROM,gdrom), /* 57: GDROM */ 220 cdev__oci_init(NMAPLE, maple), /* 58: Maple bus */ 221 cdev_clockctl_init(NCLOCKCTL, clockctl),/* 59: clockctl pseudo device */ 222 }; 223 int nchrdev = sizeof(cdevsw) / sizeof(cdevsw[0]); 224 225 int mem_no = 2; /* major device number of memory special file */ 226 227 /* 228 * Swapdev is a fake device implemented 229 * in sw.c used only internally to get to swstrategy. 230 * It cannot be provided to the users, because the 231 * swstrategy routine munches the b_dev and b_blkno entries 232 * before calling the appropriate driver. This would horribly 233 * confuse, e.g. the hashing routines. Instead, /dev/drum is 234 * provided as a character (raw) device. 235 */ 236 dev_t swapdev = makedev(1, 0); 237 238 /* 239 * Returns true if dev is /dev/mem or /dev/kmem. 240 */ 241 int 242 iskmemdev(dev) 243 dev_t dev; 244 { 245 246 return (major(dev) == mem_no && (minor(dev) < 2 || minor(dev) == 14)); 247 } 248 249 /* 250 * Returns true if dev is /dev/zero. 251 */ 252 int 253 iszerodev(dev) 254 dev_t dev; 255 { 256 257 return (major(dev) == mem_no && minor(dev) == 12); 258 } 259 260 static int chrtoblktbl[] = { 261 /* XXXX This needs to be dynamic for LKMs. */ 262 /*VCHR*/ /*VBLK*/ 263 /* 0 */ NODEV, 264 /* 1 */ NODEV, 265 /* 2 */ NODEV, 266 /* 3 */ 0, 267 /* 4 */ NODEV, 268 /* 5 */ NODEV, 269 /* 6 */ NODEV, 270 /* 7 */ NODEV, 271 /* 8 */ NODEV, 272 /* 9 */ NODEV, 273 /* 10 */ NODEV, 274 /* 11 */ NODEV, 275 /* 12 */ NODEV, 276 /* 13 */ 4, 277 /* 14 */ 5, 278 /* 15 */ 6, 279 /* 16 */ NODEV, 280 /* 17 */ NODEV, 281 /* 18 */ 16, 282 /* 19 */ NODEV, 283 /* 20 */ NODEV, 284 /* 21 */ NODEV, 285 /* 22 */ NODEV, 286 /* 23 */ NODEV, 287 /* 24 */ 17, 288 /* 25 */ NODEV, 289 /* 26 */ NODEV, 290 /* 27 */ NODEV, 291 /* 28 */ NODEV, 292 /* 29 */ NODEV, 293 /* 30 */ NODEV, 294 /* 31 */ NODEV, 295 /* 32 */ NODEV, 296 /* 33 */ NODEV, 297 /* 34 */ NODEV, 298 /* 35 */ NODEV, 299 /* 36 */ NODEV, 300 /* 37 */ NODEV, 301 /* 38 */ NODEV, 302 /* 39 */ NODEV, 303 /* 40 */ NODEV, 304 /* 41 */ 14, 305 /* 42 */ NODEV, 306 /* 43 */ NODEV, 307 /* 44 */ NODEV, 308 /* 45 */ NODEV, 309 /* 46 */ NODEV, 310 /* 47 */ NODEV, 311 /* 48 */ NODEV, 312 /* 49 */ NODEV, 313 /* 50 */ NODEV, 314 /* 51 */ NODEV, 315 /* 52 */ NODEV, 316 /* 53 */ NODEV, 317 /* 54 */ NODEV, 318 /* 55 */ NODEV, 319 /* 56 */ NODEV, 320 /* 57 */ 19, 321 /* 58 */ NODEV, 322 /* 59 */ NODEV, 323 }; 324 325 /* 326 * Convert a character device number to a block device number. 327 */ 328 dev_t 329 chrtoblk(dev) 330 dev_t dev; 331 { 332 int blkmaj; 333 334 if (major(dev) >= nchrdev) 335 return (NODEV); 336 blkmaj = chrtoblktbl[major(dev)]; 337 if (blkmaj == NODEV) 338 return (NODEV); 339 return (makedev(blkmaj, minor(dev))); 340 } 341 342 #include <dev/cons.h> 343 344 #define scifcnpollc nullcnpollc 345 346 #if NPVR > 0 347 #if NWSKBD > 0 348 #define pvrcngetc wskbd_cngetc 349 #else /* NWSKBD > 0 */ 350 static int 351 pvrcngetc(dev_t dev) 352 { 353 return 0; 354 } 355 #endif /* NWSKBD > 0 */ 356 357 #define pvrcnputc wsdisplay_cnputc 358 #define pvrcnpollc nullcnpollc 359 #endif /* NPVR > 0 */ 360 361 cons_decl(scif); 362 cons_decl(pvr); 363 364 struct consdev constab[] = { 365 #if NPVR > 0 366 cons_init(pvr), 367 #endif 368 #if NSCIF > 0 369 cons_init(scif), 370 #endif 371 { 0 }, 372 }; 373