1 /* $NetBSD: conf.c,v 1.56 2002/04/27 19:29:09 shiba Exp $ */ 2 3 /* 4 * Copyright (c) 1990 The Regents of the University of California. 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 the University of 18 * California, Berkeley and its contributors. 19 * 4. Neither the name of the University nor the names of its contributors 20 * may be used to endorse or promote products derived from this software 21 * without specific prior written permission. 22 * 23 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 29 * OR 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 /*- 36 * Derived a long time ago from 37 * @(#)conf.c 7.9 (Berkeley) 5/28/91 38 */ 39 40 #include "opt_compat_svr4.h" 41 42 #include <sys/param.h> 43 #include <sys/systm.h> 44 #include <sys/buf.h> 45 #include <sys/ioctl.h> 46 #include <sys/tty.h> 47 #include <sys/conf.h> 48 #include <sys/vnode.h> 49 #include <dev/cons.h> 50 51 #include "ccd.h" 52 #include "cd.h" 53 #include "ch.h" 54 #include "fd.h" 55 #include "md.h" 56 #include "raid.h" 57 #include "sd.h" 58 #include "st.h" 59 #include "vcoda.h" 60 #include "vnd.h" 61 #include "wd.h" 62 63 /* No cdev for md */ 64 65 bdev_decl(ccd); 66 bdev_decl(cd); 67 bdev_decl(ch); 68 bdev_decl(fd); 69 bdev_decl(md); 70 bdev_decl(raid); 71 bdev_decl(sd); 72 bdev_decl(st); 73 bdev_decl(sw); 74 bdev_decl(vnd); 75 bdev_decl(wd); 76 77 struct bdevsw bdevsw[] = 78 { 79 bdev_notdef(), /* 0 */ 80 bdev_notdef(), /* 1 */ 81 bdev_notdef(), /* 2 */ 82 bdev_swap_init(1,sw), /* 3: swap pseudo-device */ 83 bdev_disk_init(NSD,sd), /* 4: SCSI disk */ 84 bdev_tape_init(NST,st), /* 5: SCSI tape */ 85 bdev_disk_init(NCD,cd), /* 6: SCSI CD-ROM */ 86 bdev_notdef(), /* 7 */ 87 bdev_disk_init(NVND,vnd), /* 8: vnode disk driver */ 88 bdev_disk_init(NCCD,ccd), /* 9: concatenated disk driver */ 89 bdev_notdef(), /* 10 */ 90 bdev_notdef(), /* 11 */ 91 bdev_notdef(), /* 12 */ 92 bdev_disk_init(NMD,md), /* 13: memory disk -- for install */ 93 bdev_lkm_dummy(), /* 14 */ 94 bdev_lkm_dummy(), /* 15 */ 95 bdev_lkm_dummy(), /* 16 */ 96 bdev_lkm_dummy(), /* 17 */ 97 bdev_lkm_dummy(), /* 18 */ 98 bdev_lkm_dummy(), /* 19 */ 99 bdev_disk_init(NRAID,raid), /* 20: RAIDframe disk driver */ 100 bdev_disk_init(NFD, fd), /* 21: Sony floppy disk */ 101 bdev_disk_init(NWD, wd), /* 22: IDE disk */ 102 }; 103 int nblkdev = sizeof(bdevsw) / sizeof(bdevsw[0]); 104 105 #include "aed.h" 106 #include "asc.h" 107 #include "bpfilter.h" 108 #include "ch.h" 109 #include "grf.h" 110 #include "ite.h" 111 #include "ipfilter.h" 112 #include "pty.h" 113 #include "rnd.h" 114 #include "se.h" 115 #include "ss.h" 116 #include "tun.h" 117 #include "uk.h" 118 #include "wsdisplay.h" 119 #include "wskbd.h" 120 #include "wsmouse.h" 121 #include "wsmux.h" 122 #include "zsc.h" 123 #include "zstty.h" 124 #include "scsibus.h" 125 #include "clockctl.h" 126 127 cdev_decl(aed); 128 cdev_decl(asc); 129 cdev_decl(bpf); 130 cdev_decl(ccd); 131 cdev_decl(ch); 132 cdev_decl(cn); 133 cdev_decl(ctty); 134 cdev_decl(fd); 135 cdev_decl(grf); 136 cdev_decl(ite); 137 cdev_decl(ipl); 138 cdev_decl(kbd); 139 cdev_decl(log); 140 cdev_decl(md); 141 #define mmread mmrw 142 #define mmwrite mmrw 143 cdev_decl(mm); 144 cdev_decl(ms); 145 #define ptcioctl ptyioctl 146 #define ptctty ptytty 147 cdev_decl(ptc); 148 #define ptsioctl ptyioctl 149 #define ptstty ptytty 150 cdev_decl(pts); 151 cdev_decl(raid); 152 cdev_decl(sd); 153 cdev_decl(se); 154 cdev_decl(ss); 155 cdev_decl(st); 156 cdev_decl(sw); 157 cdev_decl(tun); 158 cdev_decl(uk); 159 cdev_decl(vnd); 160 cdev_decl(wskbd); 161 cdev_decl(wsmouse); 162 cdev_decl(wsmux); 163 cdev_decl(wsdisplay); 164 cdev_decl(zs); 165 cdev_decl(zsc); 166 cdev_decl(scsibus); 167 cdev_decl(vc_nb_); 168 cdev_decl(clockctl); 169 cdev_decl(wd); 170 171 dev_decl(filedesc,open); 172 173 struct cdevsw cdevsw[] = 174 { 175 cdev_cn_init(1,cn), /* 0: virtual console */ 176 cdev_ctty_init(1,ctty), /* 1: controlling terminal */ 177 cdev_mm_init(1,mm), /* 2: /dev/{null,mem,kmem,...} */ 178 cdev_swap_init(1,sw), /* 3: /dev/drum (swap pseudo-device) */ 179 cdev_tty_init(NPTY,pts), /* 4: pseudo-tty slave */ 180 cdev_ptc_init(NPTY,ptc), /* 5: pseudo-tty master */ 181 cdev_log_init(1,log), /* 6: /dev/klog */ 182 cdev_notdef(), /* 7 */ 183 cdev_notdef(), /* 8 */ 184 cdev_notdef(), /* 9 */ 185 cdev_fb_init(NGRF,grf), /* 10: grf (frame buffer) emulation */ 186 cdev_tty_init(NITE,ite), /* 11: console terminal emulator*/ 187 cdev_tty_init(NZSTTY,zs), /* 12: 2 mac serial ports -- BG*/ 188 cdev_disk_init(NSD,sd), /* 13: SCSI disk */ 189 cdev_tape_init(NST,st), /* 14: SCSI tape */ 190 cdev_disk_init(NCD,cd), /* 15: SCSI CD-ROM */ 191 cdev_notdef(), /* 16 */ 192 cdev_ch_init(NCH,ch), /* 17: SCSI autochanger */ 193 cdev_notdef(), /* 18 */ 194 cdev_disk_init(NVND,vnd), /* 19: vnode disk driver */ 195 cdev_disk_init(NCCD,ccd), /* 20: concatenated disk driver */ 196 cdev_fd_init(1,filedesc), /* 21: file descriptor pseudo-device */ 197 cdev_bpftun_init(NBPFILTER,bpf),/* 22: Berkeley packet filter */ 198 cdev_mouse_init(NAED,aed), /* 23: ADB event device */ 199 cdev_bpftun_init(NTUN,tun), /* 24: network tunnel */ 200 cdev_lkm_init(NLKM,lkm), /* 25: loadable module driver */ 201 cdev_lkm_dummy(), /* 26 */ 202 cdev_lkm_dummy(), /* 27 */ 203 cdev_lkm_dummy(), /* 28 */ 204 cdev_lkm_dummy(), /* 29 */ 205 cdev_lkm_dummy(), /* 30 */ 206 cdev_lkm_dummy(), /* 31 */ 207 cdev_disk_init(NMD,md), /* 32: memory disk driver */ 208 cdev_scanner_init(NSS,ss), /* 33: SCSI scanner */ 209 cdev_uk_init(NUK,uk), /* 34: SCSI unknown */ 210 cdev_ipf_init(NIPFILTER,ipl), /* 35: ip-filter device */ 211 cdev_audio_init(NASC,asc), /* 36: ASC audio device */ 212 cdev_se_init(NSE, se), /* 37: SCSI ethernet */ 213 cdev_rnd_init(NRND, rnd), /* 38: random source pseudo-device */ 214 cdev_scsibus_init(NSCSIBUS,scsibus), /* 39: SCSI bus */ 215 cdev_mouse_init(NWSKBD, wskbd), /* 40: wscons keyboard driver */ 216 cdev_mouse_init(NWSMOUSE, wsmouse), /* 41: wscons mouse driver */ 217 cdev_disk_init(NRAID,raid), /* 42: RAIDframe disk driver */ 218 cdev_disk_init(NFD,fd), /* 43: Sony floppy disk */ 219 cdev_svr4_net_init(NSVR4_NET,svr4_net), /* 44: svr4 net pseudo-device */ 220 cdev_mouse_init(NWSMUX, wsmux), /* 45: ws multiplexor */ 221 cdev_wsdisplay_init(NWSDISPLAY,wsdisplay), /* 46: frame buffers, etc. */ 222 cdev_vc_nb_init(NVCODA,vc_nb_), /* 47: Venus cache driver (Coda) */ 223 cdev_clockctl_init(NCLOCKCTL, clockctl),/* 48: clockctl pseudo device */ 224 cdev_disk_init(NWD, wd), /* 49: IDE disk */ 225 }; 226 int nchrdev = sizeof(cdevsw) / sizeof(cdevsw[0]); 227 228 int mem_no = 2; /* major device number of memory special file */ 229 230 /* 231 * Swapdev is a fake device implemented 232 * in sw.c used only internally to get to swstrategy. 233 * It cannot be provided to the users, because the 234 * swstrategy routine munches the b_dev and b_blkno entries 235 * before calling the appropriate driver. This would horribly 236 * confuse, e.g. the hashing routines. Instead, /dev/drum is 237 * provided as a character (raw) device. 238 */ 239 dev_t swapdev = makedev(3, 0); 240 241 /* 242 * Returns true if dev is /dev/mem or /dev/kmem. 243 */ 244 int 245 iskmemdev(dev) 246 dev_t dev; 247 { 248 249 return (major(dev) == mem_no && minor(dev) < 2); 250 } 251 252 /* 253 * Returns true if dev is /dev/zero. 254 */ 255 int 256 iszerodev(dev) 257 dev_t dev; 258 { 259 260 return (major(dev) == mem_no && minor(dev) == 12); 261 } 262 263 static int chrtoblktab[] = { 264 /* XXXX This needs to be dynamic for LKMs. */ 265 /*VCHR*/ /*VBLK*/ 266 /* 0 */ NODEV, 267 /* 1 */ NODEV, 268 /* 2 */ NODEV, 269 /* 3 */ 3, 270 /* 4 */ NODEV, 271 /* 5 */ NODEV, 272 /* 6 */ NODEV, 273 /* 7 */ NODEV, 274 /* 8 */ NODEV, 275 /* 9 */ NODEV, 276 /* 10 */ NODEV, 277 /* 11 */ NODEV, 278 /* 12 */ NODEV, 279 /* 13 */ 4, 280 /* 14 */ 5, 281 /* 15 */ 6, 282 /* 16 */ NODEV, 283 /* 17 */ NODEV, 284 /* 18 */ NODEV, 285 /* 19 */ 8, 286 /* 20 */ 9, 287 /* 21 */ NODEV, 288 /* 22 */ NODEV, 289 /* 23 */ NODEV, 290 /* 24 */ NODEV, 291 /* 25 */ NODEV, 292 /* 26 */ NODEV, 293 /* 27 */ NODEV, 294 /* 28 */ NODEV, 295 /* 29 */ NODEV, 296 /* 30 */ NODEV, 297 /* 31 */ NODEV, 298 /* 32 */ 32, 299 /* 33 */ NODEV, 300 /* 34 */ NODEV, 301 /* 35 */ NODEV, 302 /* 36 */ NODEV, 303 /* 37 */ NODEV, 304 /* 38 */ NODEV, 305 /* 39 */ NODEV, 306 /* 40 */ NODEV, 307 /* 41 */ NODEV, 308 /* 42 */ 20, 309 /* 43 */ NODEV, 310 /* 44 */ NODEV, 311 /* 45 */ NODEV, 312 /* 46 */ NODEV, 313 /* 47 */ NODEV, 314 /* 48 */ NODEV, 315 /* 49 */ 22, 316 }; 317 318 dev_t 319 chrtoblk(dev) 320 dev_t dev; 321 { 322 int blkmaj; 323 324 if (major(dev) >= nchrdev) 325 return NODEV; 326 blkmaj = chrtoblktab[major(dev)]; 327 if (blkmaj == NODEV) 328 return NODEV; 329 return (makedev(blkmaj, minor(dev))); 330 } 331 332 #include "akbd.h" 333 #include "macfb.h" 334 #define maccnpollc nullcnpollc 335 cons_decl(mac); 336 #define zscnpollc nullcnpollc 337 cons_decl(zs); 338 339 struct consdev constab[] = { 340 #if NZSTTY > 0 341 cons_init(zs), 342 #endif 343 #if NAKBD > 0 && NMACFB > 0 344 cons_init(mac), 345 #endif 346 { 0 }, 347 }; 348