Home | History | Annotate | Line # | Download | only in mvme68k
conf.c revision 1.2
      1 /*	$NetBSD: conf.c,v 1.2 1995/08/17 17:40:54 thorpej 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 <sys/param.h>
     39 #include <sys/systm.h>
     40 #include <sys/buf.h>
     41 #include <sys/ioctl.h>
     42 #include <sys/tty.h>
     43 #include <sys/conf.h>
     44 #include <sys/vnode.h>
     45 
     46 int	ttselect	__P((dev_t, int, struct proc *));
     47 
     48 #ifdef LKM
     49 int	lkmenodev();
     50 #else
     51 #define	lkmenodev	enodev
     52 #endif
     53 
     54 #include "vnd.h"
     55 bdev_decl(vnd);
     56 bdev_decl(sw);
     57 #include "sd.h"
     58 bdev_decl(sd);
     59 #include "cd.h"
     60 bdev_decl(cd);
     61 #include "st.h"
     62 bdev_decl(st);
     63 #include "ccd.h"
     64 bdev_decl(ccd);
     65 
     66 struct bdevsw	bdevsw[] =
     67 {
     68 	bdev_notdef(),			/* 0 */
     69 	bdev_notdef(),			/* 1 */
     70 	bdev_notdef(),			/* 2 */
     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_notdef(),			/* 8 */
     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 };
     85 
     86 int	nblkdev = sizeof (bdevsw) / sizeof (bdevsw[0]);
     87 
     88 cdev_decl(cn);
     89 cdev_decl(ctty);
     90 #define mmread  mmrw
     91 #define mmwrite mmrw
     92 cdev_decl(mm);
     93 cdev_decl(sw);
     94 
     95 #include "pty.h"
     96 #define ptstty		ptytty
     97 #define	ptsioctl	ptyioctl
     98 cdev_decl(pts);
     99 #define ptctty		ptytty
    100 #define	ptcioctl	ptyioctl
    101 cdev_decl(ptc);
    102 
    103 cdev_decl(log);
    104 cdev_decl(fd);
    105 
    106 #include "zs.h"
    107 cdev_decl(zs);
    108 
    109 cdev_decl(sd);
    110 cdev_decl(cd);
    111 cdev_decl(st);
    112 cdev_decl(vnd);
    113 cdev_decl(ccd);
    114 
    115 #include "bpfilter.h"
    116 cdev_decl(bpf);
    117 
    118 #include "tun.h"
    119 cdev_decl(tun);
    120 #ifdef LKM
    121 #define NLKM 1
    122 #else
    123 #define NLKM 0
    124 #endif
    125 cdev_decl(lkm);
    126 
    127 struct cdevsw	cdevsw[] =
    128 {
    129 	cdev_cn_init(1,cn),		/* 0: virtual console */
    130 	cdev_ctty_init(1,ctty),		/* 1: controlling terminal */
    131 	cdev_mm_init(1,mm),		/* 2: /dev/{null,mem,kmem,...} */
    132 	cdev_swap_init(1,sw),		/* 3: /dev/drum (swap pseudo-device) */
    133 	cdev_tty_init(NPTY,pts),	/* 4: pseudo-tty slave */
    134 	cdev_ptc_init(NPTY,ptc),	/* 5: pseudo-tty master */
    135 	cdev_log_init(1,log),		/* 6: /dev/klog */
    136 	cdev_notdef(),			/* 7 */
    137 	cdev_disk_init(NSD,sd),		/* 8: SCSI disk */
    138 	cdev_disk_init(NCD,cd),		/* 9: SCSI CD-ROM */
    139 	cdev_notdef(),			/* 10 */
    140 	cdev_notdef(),			/* 11: parallel interface */
    141 	cdev_tty_init(NZS,zs),		/* 12: SCC serial ports */
    142 	cdev_notdef(),			/* 13 */
    143 	cdev_notdef(),			/* 14 */
    144 	cdev_notdef(),			/* 15 */
    145 	cdev_notdef(),			/* 16 */
    146 	cdev_disk_init(NCCD,ccd),	/* 17: concatenated disk driver */
    147 	cdev_notdef(),			/* 18 */
    148 	cdev_disk_init(NVND,vnd),	/* 19: vnode disk */
    149 	cdev_tape_init(NST,st),		/* 20: SCSI tape */
    150 	cdev_fd_init(1,fd),		/* 21: file descriptor pseudo-dev */
    151 	cdev_bpftun_init(NBPFILTER,bpf),/* 22: berkeley packet filter */
    152 	cdev_bpftun_init(NTUN,tun),	/* 23: network tunnel */
    153 	cdev_lkm_init(NLKM,lkm),	/* 24: loadable module driver */
    154 	cdev_lkm_dummy(),		/* 25 */
    155 	cdev_lkm_dummy(),		/* 26 */
    156 	cdev_lkm_dummy(),		/* 27 */
    157 	cdev_lkm_dummy(),		/* 28 */
    158 	cdev_lkm_dummy(),		/* 29 */
    159 	cdev_lkm_dummy(),		/* 30 */
    160 };
    161 
    162 int	nchrdev = sizeof (cdevsw) / sizeof (cdevsw[0]);
    163 
    164 int	mem_no = 2; 	/* major device number of memory special file */
    165 
    166 /*
    167  * Swapdev is a fake device implemented
    168  * in sw.c used only internally to get to swstrategy.
    169  * It cannot be provided to the users, because the
    170  * swstrategy routine munches the b_dev and b_blkno entries
    171  * before calling the appropriate driver.  This would horribly
    172  * confuse, e.g. the hashing routines. Instead, /dev/drum is
    173  * provided as a character (raw) device.
    174  */
    175 dev_t	swapdev = makedev(3, 0);
    176 
    177 /*
    178  * Returns true if dev is /dev/mem or /dev/kmem.
    179  */
    180 iskmemdev(dev)
    181 	dev_t dev;
    182 {
    183 
    184 	return (major(dev) == mem_no && minor(dev) < 2);
    185 }
    186 
    187 /*
    188  * Returns true if dev is /dev/zero.
    189  */
    190 iszerodev(dev)
    191 	dev_t dev;
    192 {
    193 
    194 	return (major(dev) == mem_no && minor(dev) == 12);
    195 }
    196 
    197 /*
    198  * Returns true if dev is a disk device.
    199  */
    200 isdisk(dev, type)
    201 	dev_t dev;
    202 	int type;
    203 {
    204 
    205 	/* XXXX This needs to be dynamic for LKMs. */
    206 	switch (major(dev)) {
    207 	case 1:
    208 	case 2:
    209 	case 4:
    210 	case 6:
    211 	case 15:
    212 		return (type == VBLK);
    213 	case 8:
    214 	case 9:
    215 	case 10:
    216 	case 17:
    217 	case 19:
    218 		return (type == VCHR);
    219 	default:
    220 		return (0);
    221 	}
    222 }
    223 
    224 static int chrtoblktbl[] = {
    225 	/* XXXX This needs to be dynamic for LKMs. */
    226 	/*VCHR*/	/*VBLK*/
    227 	/*  0 */	NODEV,
    228 	/*  1 */	NODEV,
    229 	/*  2 */	NODEV,
    230 	/*  3 */	NODEV,
    231 	/*  4 */	NODEV,
    232 	/*  5 */	NODEV,
    233 	/*  6 */	NODEV,
    234 	/*  7 */	NODEV,
    235 	/*  8 */	4,
    236 	/*  9 */	7,
    237 	/* 10 */	NODEV,
    238 	/* 11 */	NODEV,
    239 	/* 12 */	NODEV,
    240 	/* 13 */	NODEV,
    241 	/* 14 */	NODEV,
    242 	/* 15 */	NODEV,
    243 	/* 16 */	NODEV,
    244 	/* 17 */	15,
    245 	/* 18 */	NODEV,
    246 	/* 19 */	6,
    247 	/* 20 */	NODEV,
    248 	/* 21 */	NODEV,
    249 	/* 22 */	NODEV,
    250 };
    251 
    252 /*
    253  * Convert a character device number to a block device number.
    254  */
    255 chrtoblk(dev)
    256 	dev_t dev;
    257 {
    258 	int blkmaj;
    259 
    260 	if (major(dev) >= nchrdev)
    261 		return (NODEV);
    262 	blkmaj = chrtoblktbl[major(dev)];
    263 	if (blkmaj == NODEV)
    264 		return (NODEV);
    265 	return (makedev(blkmaj, minor(dev)));
    266 }
    267 
    268 /*
    269  * This entire table could be autoconfig()ed but that would mean that
    270  * the kernel's idea of the console would be out of sync with that of
    271  * the standalone boot.  I think it best that they both use the same
    272  * known algorithm unless we see a pressing need otherwise.
    273  */
    274 #include <dev/cons.h>
    275 
    276 #define zscnpollc      nullcnpollc
    277 cons_decl(zs);
    278 
    279 struct	consdev constab[] = {
    280 #if NZS > 0
    281 	cons_init(zs),
    282 #endif
    283 	{ 0 },
    284 };
    285