1 /* $NetBSD: conf.c,v 1.28 2002/03/16 16:56:00 martin Exp $ */ 2 3 /*- 4 * Copyright (c) 1991 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 * @(#)conf.c 7.9 (Berkeley) 5/28/91 36 */ 37 38 #include "opt_compat_svr4.h" 39 40 #include <sys/param.h> 41 #include <sys/systm.h> 42 #include <sys/buf.h> 43 #include <sys/ioctl.h> 44 #include <sys/tty.h> 45 #include <sys/conf.h> 46 #include <sys/vnode.h> 47 48 bdev_decl(sw); 49 #include "fd.h" 50 bdev_decl(fd); 51 #include "sd.h" 52 bdev_decl(sd); 53 #include "cd.h" 54 bdev_decl(cd); 55 #include "ccd.h" 56 bdev_decl(ccd); 57 #include "raid.h" 58 bdev_decl(raid); 59 #include "vnd.h" 60 bdev_decl(vnd); 61 #include "st.h" 62 bdev_decl(st); 63 #include "md.h" 64 bdev_decl(md); 65 66 struct bdevsw bdevsw[] = 67 { 68 bdev_notdef(), /* 0: */ 69 bdev_notdef(), /* 1: */ 70 bdev_disk_init(NFD,fd), /* 2: floppy diskette */ 71 bdev_swap_init(1,sw), /* 3: swap pseudo-device */ 72 bdev_disk_init(NSD,sd), /* 4: SCSI disk */ 73 bdev_tape_init(NST,st), /* 5: SCSI tape */ 74 bdev_disk_init(NVND,vnd), /* 6: vnode disk driver */ 75 bdev_disk_init(NCD,cd), /* 7: SCSI CD-ROM */ 76 bdev_disk_init(NMD,md), /* 8: memory disk */ 77 bdev_lkm_dummy(), /* 9 */ 78 bdev_lkm_dummy(), /* 10 */ 79 bdev_lkm_dummy(), /* 11 */ 80 bdev_lkm_dummy(), /* 12 */ 81 bdev_lkm_dummy(), /* 13 */ 82 bdev_lkm_dummy(), /* 14 */ 83 bdev_disk_init(NCCD,ccd), /* 15: concatenated disk driver */ 84 bdev_disk_init(NRAID,raid), /* 16: RAIDframe disk driver */ 85 }; 86 int nblkdev = sizeof(bdevsw) / sizeof(bdevsw[0]); 87 88 /* open, close, read, write, ioctl, tty, ttpoll */ 89 #define cdev_ite_init(c,n) { \ 90 dev_init(c,n,open), dev_init(c,n,close), dev_init(c,n,read), \ 91 dev_init(c,n,write), dev_init(c,n,ioctl), dev_noimpl(stop,enodev), \ 92 dev_init(c,n,tty), dev_init(c,n,poll), dev_noimpl(mmap,enodev), D_TTY } 93 94 /* open, close, write, ioctl */ 95 #define cdev_par_init(c,n) cdev__ocwi_init(c,n) 96 97 /* open, close, ioctl */ 98 #define cdev_sram_init(c,n) cdev__oci_init(c,n) 99 #define cdev_pow_init(c,n) cdev__oci_init(c,n) 100 #define cdev_bell_init(c,n) cdev__oci_init(c,n) 101 102 #include "isdn.h" 103 #include "isdnctl.h" 104 #include "isdntrc.h" 105 #include "isdnbchan.h" 106 #include "isdntel.h" 107 cdev_decl(isdn); 108 cdev_decl(isdnctl); 109 cdev_decl(isdntrc); 110 cdev_decl(isdnbchan); 111 cdev_decl(isdntel); 112 113 cdev_decl(cn); 114 cdev_decl(ctty); 115 #define mmread mmrw 116 #define mmwrite mmrw 117 cdev_decl(mm); 118 cdev_decl(sw); 119 #include "pty.h" 120 #define ptstty ptytty 121 #define ptsioctl ptyioctl 122 cdev_decl(pts); 123 #define ptctty ptytty 124 #define ptcioctl ptyioctl 125 cdev_decl(ptc); 126 cdev_decl(log); 127 cdev_decl(sd); 128 #include "ss.h" 129 cdev_decl(ss); 130 cdev_decl(cd); 131 #include "grf.h" 132 cdev_decl(grf); 133 #include "par.h" 134 cdev_decl(par); 135 #include "ite.h" 136 cdev_decl(ite); 137 cdev_decl(ccd); 138 cdev_decl(raid); 139 cdev_decl(vnd); 140 cdev_decl(md); 141 cdev_decl(st); 142 cdev_decl(fd); 143 #include "kbd.h" 144 cdev_decl(kbd); 145 #include "ms.h" 146 cdev_decl(ms); 147 dev_decl(filedesc,open); 148 #include "audio.h" 149 cdev_decl(audio); 150 #include "sram.h" 151 cdev_decl(sram); 152 #include "bpfilter.h" 153 cdev_decl(bpf); 154 #include "tun.h" 155 cdev_decl(tun); 156 157 #include "xcom.h" 158 cdev_decl(com); 159 #include "zstty.h" 160 cdev_decl(zs); 161 #include "pow.h" 162 cdev_decl(pow); 163 #include "bell.h" 164 cdev_decl(bell); 165 #include "ch.h" 166 cdev_decl(ch); 167 #include "uk.h" 168 cdev_decl(uk); 169 #include "clockctl.h" 170 cdev_decl(clockctl); 171 #include "ipfilter.h" 172 #include "rnd.h" 173 174 #include "scsibus.h" 175 cdev_decl(scsibus); 176 177 struct cdevsw cdevsw[] = 178 { 179 cdev_cn_init(1,cn), /* 0: virtual console */ 180 cdev_ctty_init(1,ctty), /* 1: controlling terminal */ 181 cdev_mm_init(1,mm), /* 2: /dev/{null,mem,kmem,...} */ 182 cdev_swap_init(1,sw), /* 3: /dev/drum (swap pseudo-device) */ 183 cdev_tty_init(NPTY,pts), /* 4: pseudo-tty slave */ 184 cdev_ptc_init(NPTY,ptc), /* 5: pseudo-tty master */ 185 cdev_log_init(1,log), /* 6: /dev/klog */ 186 cdev_disk_init(NMD,md), /* 7: memory disk */ 187 cdev_disk_init(NSD,sd), /* 8: SCSI disk */ 188 cdev_disk_init(NCD,cd), /* 9: SCSI cdrom */ 189 cdev_grf_init(NGRF,grf), /* 10: frame buffer */ 190 cdev_par_init(NPAR,par), /* 11: parallel interface */ 191 cdev_tty_init(NZSTTY,zs), /* 12: zs serial */ 192 cdev_ite_init(NITE,ite), /* 13: console terminal emulator */ 193 #if NKBD > 0 194 cdev__ocrwip_init(1,kbd), /* 14: /dev/kbd */ 195 #else 196 cdev_notdef(), 197 #endif 198 #if NMS > 0 199 cdev__ocrwip_init(1,ms), /* 15: /dev/mouse */ 200 #else 201 cdev_notdef(), 202 #endif 203 cdev_tty_init(NXCOM,com), /* 16: serial port */ 204 cdev_audio_init(NAUDIO,audio), /* 17: /dev/adpcm /dev/pcm /dev/audio */ 205 cdev_disk_init(NFD,fd), /* 18: floppy disk */ 206 cdev_disk_init(NVND,vnd), /* 19: vnode disk driver */ 207 cdev_tape_init(NST,st), /* 20: SCSI tape */ 208 cdev_fd_init(1,filedesc), /* 21: file descriptor pseudo-dev */ 209 cdev_bpftun_init(NBPFILTER,bpf),/* 22: berkeley packet filter */ 210 cdev_sram_init(NSRAM,sram), /* 23: /dev/sram */ 211 cdev_lkm_init(NLKM,lkm), /* 24: loadable module driver */ 212 cdev_lkm_dummy(), /* 25 */ 213 cdev_lkm_dummy(), /* 26 */ 214 cdev_lkm_dummy(), /* 27 */ 215 cdev_lkm_dummy(), /* 28 */ 216 cdev_lkm_dummy(), /* 29 */ 217 cdev_lkm_dummy(), /* 30 */ 218 cdev_bpftun_init(NTUN,tun), /* 31: network tunnel */ 219 cdev_pow_init(NPOW,pow), /* 32: power switch device */ 220 cdev_bell_init(NBELL,bell), /* 33: opm bell device */ 221 cdev_disk_init(NCCD,ccd), /* 34: concatenated disk driver */ 222 cdev_scanner_init(NSS,ss), /* 35: SCSI scanner */ 223 cdev_ch_init(NCH,ch), /* 36: SCSI changer device */ 224 cdev_uk_init(NUK,uk), /* 37: SCSI unknown device */ 225 cdev_ipf_init(NIPFILTER,ipl), /* 38: IP filter device */ 226 cdev_rnd_init(NRND,rnd), /* 39: random source pseudo-device */ 227 cdev_scsibus_init(NSCSIBUS,scsibus), /* 40: SCSI bus */ 228 cdev_disk_init(NRAID,raid), /* 41: RAIDframe disk driver */ 229 cdev_svr4_net_init(NSVR4_NET,svr4_net), /* 42: svr4 net pseudo-device */ 230 cdev_isdn_init(NISDN, isdn), /* 43: isdn main device */ 231 cdev_isdnctl_init(NISDNCTL, isdnctl), /* 44: isdn control device */ 232 cdev_isdnbchan_init(NISDNBCHAN, isdnbchan), /* 45: isdn raw b-channel access */ 233 cdev_isdntrc_init(NISDNTRC, isdntrc), /* 46: isdn trace device */ 234 cdev_isdntel_init(NISDNTEL, isdntel), /* 47: isdn phone device */ 235 cdev_clockctl_init(NCLOCKCTL, clockctl), /* 48: settimeofday driver */ 236 }; 237 int nchrdev = sizeof(cdevsw) / sizeof(cdevsw[0]); 238 239 int mem_no = 2; /* major device number of memory special file */ 240 241 /* 242 * Swapdev is a fake device implemented 243 * in sw.c used only internally to get to swstrategy. 244 * It cannot be provided to the users, because the 245 * swstrategy routine munches the b_dev and b_blkno entries 246 * before calling the appropriate driver. This would horribly 247 * confuse, e.g. the hashing routines. Instead, /dev/drum is 248 * provided as a character (raw) device. 249 */ 250 dev_t swapdev = makedev(3, 0); 251 252 /* 253 * Returns true if dev is /dev/mem or /dev/kmem. 254 */ 255 int 256 iskmemdev(dev) 257 dev_t dev; 258 { 259 260 return (major(dev) == mem_no && minor(dev) < 2); 261 } 262 263 /* 264 * Returns true if dev is /dev/zero. 265 */ 266 int 267 iszerodev(dev) 268 dev_t dev; 269 { 270 271 return (major(dev) == mem_no && minor(dev) == 12); 272 } 273 274 static int chrtoblktbl[] = { 275 /* CHR*/ /* BLK*/ /* CHR*/ /* BLK*/ 276 /* 0 */ NODEV, /* 1 */ NODEV, 277 /* 2 */ NODEV, /* 3 */ 3, 278 /* 4 */ NODEV, /* 5 */ NODEV, 279 /* 6 */ NODEV, /* 7 */ 8, 280 /* 8 */ 4, /* 9 */ 7, 281 /* 10 */ NODEV, /* 11 */ NODEV, 282 /* 12 */ NODEV, /* 13 */ NODEV, 283 /* 14 */ NODEV, /* 15 */ NODEV, 284 /* 16 */ NODEV, /* 17 */ NODEV, 285 /* 18 */ 2, /* 19 */ 6, 286 /* 20 */ 5, /* 21 */ NODEV, 287 /* 22 */ NODEV, /* 23 */ NODEV, 288 /* 24 */ NODEV, /* 25 */ NODEV, 289 /* 26 */ NODEV, /* 27 */ NODEV, 290 /* 28 */ NODEV, /* 29 */ NODEV, 291 /* 30 */ NODEV, /* 31 */ NODEV, 292 /* 32 */ NODEV, /* 33 */ NODEV, 293 /* 34 */ 15, /* 35 */ NODEV, 294 /* 36 */ NODEV, /* 37 */ NODEV, 295 /* 38 */ NODEV, /* 39 */ NODEV, 296 /* 40 */ NODEV, /* 41 */ 16, 297 /* 42 */ NODEV, /* 43 */ NODEV, 298 /* 44 */ NODEV, /* 45 */ NODEV, 299 /* 46 */ NODEV, /* 47 */ NODEV, 300 /* 48 */ NODEV, 301 }; 302 303 /* 304 * Convert a character device number to a block device number. 305 */ 306 dev_t 307 chrtoblk(dev) 308 dev_t dev; 309 { 310 int blkmaj; 311 312 if (major(dev) >= nchrdev) 313 return (NODEV); 314 blkmaj = chrtoblktbl[major(dev)]; 315 if (blkmaj == NODEV) 316 return (NODEV); 317 return (makedev(blkmaj, minor(dev))); 318 } 319 320 /* 321 * This entire table could be autoconfig()ed but that would mean that 322 * the kernel's idea of the console would be out of sync with that of 323 * the standalone boot. I think it best that they both use the same 324 * known algorithm unless we see a pressing need otherwise. 325 */ 326 #include <dev/cons.h> 327 328 #define itecnpollc nullcnpollc 329 cons_decl(ite); 330 cons_decl(zs); 331 332 struct consdev constab[] = { 333 #if NITE > 0 && NKBD > 0 334 cons_init(ite), 335 #endif 336 #if NZSTTY > 0 337 cons_init(zs), 338 #endif 339 { 0 }, 340 }; 341