1 /* $NetBSD: conf.c,v 1.42 1997/03/24 18:20:10 scottr 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 <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 #include <dev/cons.h> 48 49 #include "ccd.h" 50 #include "cd.h" 51 #include "ch.h" 52 #include "md.h" 53 #include "sd.h" 54 #include "st.h" 55 #include "vnd.h" 56 /* No cdev for md */ 57 58 bdev_decl(ccd); 59 bdev_decl(cd); 60 bdev_decl(ch); 61 bdev_decl(md); 62 bdev_decl(sd); 63 bdev_decl(st); 64 bdev_decl(sw); 65 bdev_decl(vnd); 66 67 struct bdevsw bdevsw[] = 68 { 69 bdev_notdef(), /* 0 */ 70 bdev_notdef(), /* 1 */ 71 bdev_notdef(), /* 2 */ 72 bdev_swap_init(1,sw), /* 3: swap pseudo-device */ 73 bdev_disk_init(NSD,sd), /* 4: SCSI disk */ 74 bdev_tape_init(NST,st), /* 5: SCSI tape */ 75 bdev_disk_init(NCD,cd), /* 6: SCSI CD-ROM */ 76 bdev_notdef(), /* 7 */ 77 bdev_disk_init(NVND,vnd), /* 8: vnode disk driver */ 78 bdev_disk_init(NCCD,ccd), /* 9: concatenated disk driver */ 79 bdev_notdef(), /* 10 */ 80 bdev_notdef(), /* 11 */ 81 bdev_notdef(), /* 12 */ 82 bdev_disk_init(NMD,md), /* 13: memory disk -- for install */ 83 bdev_lkm_dummy(), /* 14 */ 84 bdev_lkm_dummy(), /* 15 */ 85 bdev_lkm_dummy(), /* 16 */ 86 bdev_lkm_dummy(), /* 17 */ 87 bdev_lkm_dummy(), /* 18 */ 88 bdev_lkm_dummy(), /* 19 */ 89 }; 90 int nblkdev = sizeof(bdevsw) / sizeof(bdevsw[0]); 91 92 #define NADB 1 /* #include "adb.h" */ 93 #include "asc.h" 94 #include "bpfilter.h" 95 #include "ch.h" 96 #include "grf.h" 97 #include "ipfilter.h" 98 #include "ite.h" 99 #include "pty.h" 100 #include "se.h" 101 #include "ss.h" 102 #include "tun.h" 103 #include "uk.h" 104 #include "zsc.h" 105 #include "zstty.h" 106 107 cdev_decl(adb); 108 cdev_decl(asc); 109 cdev_decl(bpf); 110 cdev_decl(ccd); 111 cdev_decl(ch); 112 cdev_decl(cn); 113 cdev_decl(ctty); 114 cdev_decl(fd); 115 cdev_decl(grf); 116 cdev_decl(ipl); 117 cdev_decl(ite); 118 cdev_decl(log); 119 cdev_decl(md); 120 #define mmread mmrw 121 #define mmwrite mmrw 122 cdev_decl(mm); 123 #define ptcioctl ptyioctl 124 #define ptctty ptytty 125 cdev_decl(ptc); 126 #define ptsioctl ptyioctl 127 #define ptstty ptytty 128 cdev_decl(pts); 129 cdev_decl(sd); 130 cdev_decl(se); 131 cdev_decl(ss); 132 cdev_decl(st); 133 cdev_decl(sw); 134 cdev_decl(tun); 135 cdev_decl(uk); 136 cdev_decl(vnd); 137 cdev_decl(zs); 138 cdev_decl(zsc); 139 140 dev_decl(filedesc,open); 141 142 struct cdevsw cdevsw[] = 143 { 144 cdev_cn_init(1,cn), /* 0: virtual console */ 145 cdev_ctty_init(1,ctty), /* 1: controlling terminal */ 146 cdev_mm_init(1,mm), /* 2: /dev/{null,mem,kmem,...} */ 147 cdev_swap_init(1,sw), /* 3: /dev/drum (swap pseudo-device) */ 148 cdev_tty_init(NPTY,pts), /* 4: pseudo-tty slave */ 149 cdev_ptc_init(NPTY,ptc), /* 5: pseudo-tty master */ 150 cdev_log_init(1,log), /* 6: /dev/klog */ 151 cdev_notdef(), /* 7 */ 152 cdev_notdef(), /* 8 */ 153 cdev_notdef(), /* 9 */ 154 cdev_fb_init(NGRF,grf), /* 10: frame buffer */ 155 cdev_tty_init(NITE,ite), /* 11: console terminal emulator */ 156 cdev_tty_init(NZSTTY,zs), /* 12: 2 mac serial ports -- BG*/ 157 cdev_disk_init(NSD,sd), /* 13: SCSI disk */ 158 cdev_tape_init(NST,st), /* 14: SCSI tape */ 159 cdev_disk_init(NCD,cd), /* 15: SCSI CD-ROM */ 160 cdev_notdef(), /* 16 */ 161 cdev_ch_init(NCH,ch), /* 17: SCSI autochanger */ 162 cdev_notdef(), /* 18 */ 163 cdev_disk_init(NVND,vnd), /* 19: vnode disk driver */ 164 cdev_disk_init(NCCD,ccd), /* 20: concatenated disk driver */ 165 cdev_fd_init(1,filedesc), /* 21: file descriptor pseudo-device */ 166 cdev_bpftun_init(NBPFILTER,bpf),/* 22: Berkeley packet filter */ 167 cdev_mouse_init(NADB,adb), /* 23: ADB event interface */ 168 cdev_bpftun_init(NTUN,tun), /* 24: network tunnel */ 169 cdev_lkm_init(NLKM,lkm), /* 25: loadable module driver */ 170 cdev_lkm_dummy(), /* 26 */ 171 cdev_lkm_dummy(), /* 27 */ 172 cdev_lkm_dummy(), /* 28 */ 173 cdev_lkm_dummy(), /* 29 */ 174 cdev_lkm_dummy(), /* 30 */ 175 cdev_lkm_dummy(), /* 31 */ 176 cdev_disk_init(NMD,md), /* 32: memory disk driver */ 177 cdev_scanner_init(NSS,ss), /* 33: SCSI scanner */ 178 cdev_uk_init(NUK,uk), /* 34: SCSI unknown */ 179 cdev_ipf_init(NIPFILTER,ipl), /* 35: ip-filter device */ 180 cdev_audio_init(NASC,asc), /* 36: ASC audio device */ 181 cdev_se_init(NSE, se), /* 37: SCSI ethernet */ 182 }; 183 int nchrdev = sizeof(cdevsw) / sizeof(cdevsw[0]); 184 185 int mem_no = 2; /* major device number of memory special file */ 186 187 /* 188 * Swapdev is a fake device implemented 189 * in sw.c used only internally to get to swstrategy. 190 * It cannot be provided to the users, because the 191 * swstrategy routine munches the b_dev and b_blkno entries 192 * before calling the appropriate driver. This would horribly 193 * confuse, e.g. the hashing routines. Instead, /dev/drum is 194 * provided as a character (raw) device. 195 */ 196 dev_t swapdev = makedev(3, 0); 197 198 /* 199 * Returns true if dev is /dev/mem or /dev/kmem. 200 */ 201 int 202 iskmemdev(dev) 203 dev_t dev; 204 { 205 206 return (major(dev) == mem_no && minor(dev) < 2); 207 } 208 209 /* 210 * Returns true if dev is /dev/zero. 211 */ 212 int 213 iszerodev(dev) 214 dev_t dev; 215 { 216 217 return (major(dev) == mem_no && minor(dev) == 12); 218 } 219 220 static int chrtoblktab[] = { 221 /* XXXX This needs to be dynamic for LKMs. */ 222 /*VCHR*/ /*VBLK*/ 223 /* 0 */ NODEV, 224 /* 1 */ NODEV, 225 /* 2 */ NODEV, 226 /* 3 */ 3, 227 /* 4 */ NODEV, 228 /* 5 */ NODEV, 229 /* 6 */ NODEV, 230 /* 7 */ NODEV, 231 /* 8 */ NODEV, 232 /* 9 */ NODEV, 233 /* 10 */ NODEV, 234 /* 11 */ NODEV, 235 /* 12 */ NODEV, 236 /* 13 */ 4, 237 /* 14 */ 5, 238 /* 15 */ 6, 239 /* 16 */ NODEV, 240 /* 17 */ NODEV, 241 /* 18 */ NODEV, 242 /* 19 */ 8, 243 /* 20 */ 9, 244 /* 21 */ NODEV, 245 /* 22 */ NODEV, 246 /* 23 */ NODEV, 247 /* 24 */ NODEV, 248 /* 25 */ NODEV, 249 /* 26 */ NODEV, 250 /* 27 */ NODEV, 251 /* 28 */ NODEV, 252 /* 29 */ NODEV, 253 /* 30 */ NODEV, 254 /* 31 */ NODEV, 255 }; 256 257 dev_t 258 chrtoblk(dev) 259 dev_t dev; 260 { 261 int blkmaj; 262 263 if (major(dev) >= nchrdev) 264 return NODEV; 265 blkmaj = chrtoblktab[major(dev)]; 266 if (blkmaj == NODEV) 267 return NODEV; 268 return (makedev(blkmaj, minor(dev))); 269 } 270 271 #define itecnpollc nullcnpollc 272 cons_decl(ite); 273 #define zscnpollc nullcnpollc 274 cons_decl(zs); 275 276 struct consdev constab[] = { 277 #if NITE > 0 278 cons_init(ite), 279 #endif 280 #if NZSTTY > 0 281 cons_init(zs), 282 #endif 283 { 0 }, 284 }; 285