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