1 /* $NetBSD: conf.c,v 1.52 2002/03/16 16:55:54 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 #include <dev/cons.h> 48 49 #ifdef BANKEDDEVPAGER 50 #include <sys/bankeddev.h> 51 #endif 52 53 #define bdev_md_init(c,n) { \ 54 dev_init(c,n,open), dev_init(c,n,close), dev_init(c,n,strategy), \ 55 dev_init(c,n,ioctl), dev_noimpl(dump,enxio), dev_size_init(c,n), 0 } 56 57 #include "vnd.h" 58 bdev_decl(vnd); 59 #include "md.h" 60 bdev_decl(md); 61 62 #include "fd.h" 63 #include "hdfd.h" 64 #include "fdisa.h" 65 #define NFLOPPY (NFD+NHDFD+NFDISA) 66 bdev_decl(fd); 67 68 bdev_decl(sw); 69 #include "sd.h" 70 bdev_decl(sd); 71 #include "st.h" 72 bdev_decl(st); 73 #include "cd.h" 74 bdev_decl(cd); 75 #include "ccd.h" 76 bdev_decl(ccd); 77 #include "raid.h" 78 bdev_decl(raid); 79 #include "wd.h" 80 bdev_decl(wd); 81 82 struct bdevsw bdevsw[] = 83 { 84 bdev_disk_init(NVND,vnd), /* 0: vnode disk driver */ 85 bdev_md_init(NMD,md), /* 1: memory disk - for install disk */ 86 bdev_disk_init(NFLOPPY,fd), /* 2: floppy disk */ 87 bdev_swap_init(1,sw), /* 3: swap pseudo-device */ 88 bdev_disk_init(NSD,sd), /* 4: SCSI disk */ 89 bdev_tape_init(NST,st), /* 5: SCSI tape */ 90 bdev_disk_init(NCD,cd), /* 6: SCSI CD-ROM */ 91 bdev_lkm_dummy(), /* 7 */ 92 bdev_lkm_dummy(), /* 8 */ 93 bdev_lkm_dummy(), /* 9 */ 94 bdev_lkm_dummy(), /* 10 */ 95 bdev_lkm_dummy(), /* 11 */ 96 bdev_lkm_dummy(), /* 12 */ 97 bdev_disk_init(NCCD,ccd), /* 13: concatenated disk driver */ 98 bdev_disk_init(NWD,wd), /* 14: IDE disk driver */ 99 bdev_disk_init(NRAID,raid), /* 15: RAIDframe disk driver */ 100 }; 101 int nblkdev = sizeof(bdevsw) / sizeof(bdevsw[0]); 102 103 /* open, close, write, ioctl */ 104 #define cdev_lp_init(c,n) cdev__ocwi_init(c,n) 105 106 /* open, close, read, ioctl */ 107 #define cdev_ss_init(c,n) cdev__ocri_init(c,n) 108 109 /* open, close, read, write */ 110 #define cdev_rtc_init(c,n) cdev__ocrw_init(c,n) 111 112 /* open, close, read, write, ioctl, mmap */ 113 #define cdev_et_init(c,n) cdev__ocrwim_init(c,n) 114 #define cdev_leo_init(c,n) cdev__ocrwim_init(c,n) 115 116 #include "isdn.h" 117 #include "isdnctl.h" 118 #include "isdntrc.h" 119 #include "isdnbchan.h" 120 #include "isdntel.h" 121 cdev_decl(isdn); 122 cdev_decl(isdnctl); 123 cdev_decl(isdntrc); 124 cdev_decl(isdnbchan); 125 cdev_decl(isdntel); 126 127 #include "audio.h" 128 #include "bpfilter.h" 129 #include "ch.h" 130 #include "et.h" 131 #include "grfcc.h" 132 #include "grfet.h" 133 #define NGRF (NGRFCC + NGRFET) 134 #include "ipfilter.h" 135 #include "ite.h" 136 #include "kbd.h" 137 #include "lp.h" 138 #include "mouse.h" 139 #include "pty.h" 140 #include "rnd.h" 141 #include "ser.h" 142 #include "ss.h" 143 #include "tun.h" 144 #include "uk.h" 145 #include "vga_pci.h" 146 #include "view.h" 147 #include "wsdisplay.h" 148 #include "zs.h" 149 #include "leo.h" 150 #include "scsibus.h" 151 #include "clockctl.h" 152 153 cdev_decl(audio); 154 cdev_decl(bpf); 155 cdev_decl(ccd); 156 cdev_decl(cd); 157 cdev_decl(ch); 158 cdev_decl(cn); 159 cdev_decl(ctty); 160 cdev_decl(fd); 161 dev_decl(filedesc,open); 162 cdev_decl(grf); 163 cdev_decl(ipl); 164 cdev_decl(ite); 165 cdev_decl(kbd); 166 cdev_decl(log); 167 cdev_decl(lp); 168 #define mmread mmrw 169 #define mmwrite mmrw 170 cdev_decl(mm); 171 cdev_decl(ms); 172 #define ptstty ptytty 173 #define ptsioctl ptyioctl 174 cdev_decl(pts); 175 #define ptctty ptytty 176 #define ptcioctl ptyioctl 177 cdev_decl(ptc); 178 cdev_decl(raid); 179 cdev_decl(rtc); 180 cdev_decl(sd); 181 cdev_decl(ser); 182 cdev_decl(ss); 183 cdev_decl(st); 184 cdev_decl(sw); 185 cdev_decl(tun); 186 cdev_decl(uk); 187 cdev_decl(view); 188 cdev_decl(wd); 189 cdev_decl(wsdisplay); 190 cdev_decl(zs); 191 cdev_decl(et); 192 cdev_decl(leo); 193 cdev_decl(scsibus); 194 cdev_decl(clockctl); 195 196 struct cdevsw cdevsw[] = 197 { 198 cdev_cn_init(1,cn), /* 0: virtual console */ 199 cdev_ctty_init(1,ctty), /* 1: controlling terminal */ 200 cdev_mm_init(1,mm), /* 2: /dev/{null,mem,kmem,...} */ 201 cdev_swap_init(1,sw), /* 3: /dev/drum (swap pseudo-device) */ 202 cdev_tty_init(NPTY,pts), /* 4: pseudo-tty slave */ 203 cdev_ptc_init(NPTY,ptc), /* 5: pseudo-tty master */ 204 cdev_log_init(1,log), /* 6: /dev/klog */ 205 cdev_tty_init(NZS,zs), /* 7: 8530 SCC */ 206 cdev_disk_init(NSD,sd), /* 8: SCSI disk */ 207 cdev_disk_init(NCD,cd), /* 9: SCSI CD-ROM */ 208 cdev_tape_init(NST,st), /* 10: SCSI tape */ 209 cdev_grf_init(NGRF,grf), /* 11: frame buffer */ 210 cdev_tty_init(NITE,ite), /* 12: console terminal emulator */ 211 cdev_view_init(NVIEW,view), /* 13: /dev/view00 /dev/view01, ... */ 212 cdev_mouse_init(NKBD,kbd), /* 14: /dev/kbd */ 213 cdev_mouse_init(NMOUSE,ms), /* 15: /dev/mouse0 /dev/mouse1 */ 214 cdev_disk_init(NFD+NHDFD,fd), /* 16: floppy disk */ 215 cdev_disk_init(NVND,vnd), /* 17: vnode disk driver */ 216 cdev_fd_init(1,filedesc), /* 18: file descriptor pseudo-device */ 217 cdev_bpftun_init(NBPFILTER,bpf),/* 19: Berkeley packet filter */ 218 cdev_lkm_init(NLKM,lkm), /* 20: loadable module driver */ 219 cdev_lkm_dummy(), /* 21 */ 220 cdev_lkm_dummy(), /* 22 */ 221 cdev_lkm_dummy(), /* 23 */ 222 cdev_lkm_dummy(), /* 24 */ 223 cdev_lkm_dummy(), /* 25 */ 224 cdev_lkm_dummy(), /* 26 */ 225 cdev_disk_init(NCCD,ccd), /* 27: concatenated disk driver */ 226 cdev_bpftun_init(NTUN,tun), /* 28: network tunnel */ 227 cdev_lp_init(NLP, lp), /* 29: Centronics */ 228 cdev_ch_init(NCH,ch), /* 30: SCSI autochanger */ 229 cdev_uk_init(NUK,uk), /* 31: SCSI unknown */ 230 cdev_ss_init(NSS,ss), /* 32: SCSI scanner */ 231 cdev_rtc_init(1,rtc), /* 33: RealTimeClock */ 232 cdev_disk_init(NWD,wd), /* 34: IDE disk driver */ 233 cdev_tty_init(NSER,ser), /* 35: 68901 UART */ 234 cdev_ipf_init(NIPFILTER,ipl), /* 36: ip-filter device */ 235 cdev_disk_init(NMD,md), /* 37: memory disk - for install disk */ 236 cdev_rnd_init(NRND,rnd), /* 38: random source pseudo-device */ 237 cdev_leo_init(NLEO,leo), /* 39: Circad Leonardo video */ 238 cdev_et_init(NET,et), /* 40: ET4000 color video */ 239 cdev_wsdisplay_init(NWSDISPLAY, 240 wsdisplay), /* 41: wscons placeholder */ 241 cdev_audio_init(NAUDIO,audio), /* 42 */ 242 cdev_notdef(), /* 43 */ 243 cdev_isdn_init(NISDN, isdn), /* 44: isdn main device */ 244 cdev_isdnctl_init(NISDNCTL, isdnctl), /* 45: isdn control device */ 245 cdev_isdnbchan_init(NISDNBCHAN, isdnbchan), /* 46: isdn raw b-channel access */ 246 cdev_isdntrc_init(NISDNTRC, isdntrc), /* 47: isdn trace device */ 247 cdev_isdntel_init(NISDNTEL, isdntel), /* 48: isdn phone device */ 248 cdev_scsibus_init(NSCSIBUS,scsibus), /* 49: SCSI bus */ 249 cdev_disk_init(NRAID,raid), /* 50: RAIDframe disk driver */ 250 cdev_svr4_net_init(NSVR4_NET,svr4_net), /* 51: svr4 net pseudo-device */ 251 cdev_clockctl_init(NCLOCKCTL, clockctl),/* 52: clockctl pseudo device */ 252 }; 253 int nchrdev = sizeof(cdevsw) / sizeof(cdevsw[0]); 254 255 #ifdef BANKEDDEVPAGER 256 extern int grfbanked_get __P((int, int, int)); 257 extern int grfbanked_set __P((int, int)); 258 extern int grfbanked_cur __P((int)); 259 260 struct bankeddevsw bankeddevsw[sizeof (cdevsw) / sizeof (cdevsw[0])] = { 261 { 0, 0, 0 }, /* 0 */ 262 { 0, 0, 0 }, /* 1 */ 263 { 0, 0, 0 }, /* 2 */ 264 { 0, 0, 0 }, /* 3 */ 265 { 0, 0, 0 }, /* 4 */ 266 { 0, 0, 0 }, /* 5 */ 267 { 0, 0, 0 }, /* 6 */ 268 { 0, 0, 0 }, /* 7 */ 269 { 0, 0, 0 }, /* 8 */ 270 { 0, 0, 0 }, /* 9 */ 271 { grfbanked_get, grfbanked_cur, grfbanked_set }, /* 10 */ 272 /* rest { 0, 0, 0 } */ 273 }; 274 #endif 275 276 int mem_no = 2; /* major device number of memory special file */ 277 278 /* 279 * Swapdev is a fake device implemented 280 * in sw.c used only internally to get to swstrategy. 281 * It cannot be provided to the users, because the 282 * swstrategy routine munches the b_dev and b_blkno entries 283 * before calling the appropriate driver. This would horribly 284 * confuse, e.g. the hashing routines. Instead, /dev/drum is 285 * provided as a character (raw) device. 286 */ 287 dev_t swapdev = makedev(3, 0); 288 289 /* 290 * Returns true if dev is /dev/mem or /dev/kmem. 291 */ 292 int 293 iskmemdev(dev) 294 dev_t dev; 295 { 296 297 return (major(dev) == mem_no && minor(dev) < 2); 298 } 299 300 /* 301 * Returns true if dev is /dev/zero. 302 */ 303 int 304 iszerodev(dev) 305 dev_t dev; 306 { 307 308 return (major(dev) == mem_no && minor(dev) == 12); 309 } 310 311 static int chrtoblktab[] = { 312 /* XXXX This needs to be dynamic for LKMs. */ 313 /*VCHR*/ /*VBLK*/ 314 /* 0 */ NODEV, 315 /* 1 */ NODEV, 316 /* 2 */ NODEV, 317 /* 3 */ NODEV, 318 /* 4 */ NODEV, 319 /* 5 */ NODEV, 320 /* 6 */ NODEV, 321 /* 7 */ NODEV, 322 /* 8 */ 4, 323 /* 9 */ 6, 324 /* 10 */ 5, 325 /* 11 */ NODEV, 326 /* 12 */ NODEV, 327 /* 13 */ NODEV, 328 /* 14 */ NODEV, 329 /* 15 */ NODEV, 330 /* 16 */ 2, 331 /* 17 */ 0, 332 /* 18 */ NODEV, 333 /* 19 */ NODEV, 334 /* 20 */ NODEV, 335 /* 21 */ NODEV, 336 /* 22 */ NODEV, 337 /* 23 */ NODEV, 338 /* 24 */ NODEV, 339 /* 25 */ NODEV, 340 /* 26 */ NODEV, 341 /* 27 */ 13, 342 /* 28 */ NODEV, 343 /* 29 */ NODEV, 344 /* 30 */ NODEV, 345 /* 31 */ NODEV, 346 /* 32 */ NODEV, 347 /* 33 */ NODEV, 348 /* 34 */ 14, 349 /* 35 */ NODEV, 350 /* 36 */ NODEV, 351 /* 37 */ 1, 352 /* 38 */ NODEV, 353 /* 39 */ NODEV, 354 /* 40 */ NODEV, 355 /* 41 */ NODEV, 356 /* 42 */ NODEV, 357 /* 43 */ NODEV, 358 /* 44 */ NODEV, 359 /* 45 */ NODEV, 360 /* 46 */ NODEV, 361 /* 47 */ NODEV, 362 /* 48 */ NODEV, 363 /* 49 */ NODEV, 364 /* 50 */ 15, 365 /* 51 */ NODEV, 366 /* 52 */ NODEV, 367 }; 368 369 /* 370 * Convert a character device number to a block device number. 371 */ 372 dev_t 373 chrtoblk(dev) 374 dev_t dev; 375 { 376 int blkmaj; 377 378 if (major(dev) >= nchrdev) 379 return(NODEV); 380 blkmaj = chrtoblktab[major(dev)]; 381 if (blkmaj == NODEV) 382 return(NODEV); 383 return (makedev(blkmaj, minor(dev))); 384 } 385 386 /* 387 * This entire table could be autoconfig()ed but that would mean that 388 * the kernel's idea of the console would be out of sync with that of 389 * the standalone boot. I think it best that they both use the same 390 * known algorithm unless we see a pressing need otherwise. 391 */ 392 cons_decl(ser); 393 #define itecnpollc nullcnpollc 394 cons_decl(ite); 395 cons_decl(vga); 396 397 struct consdev constab[] = { 398 #if NSER > 0 399 cons_init(ser), 400 #endif 401 #if NITE > 0 402 cons_init(ite), 403 #endif 404 #if NVGA_PCI > 0 405 { dev_init(1,vga,cnprobe), dev_init(1,vga,cninit) }, 406 #endif 407 { 0 }, 408 }; 409