Home | History | Annotate | Line # | Download | only in dev
dcm.c revision 1.9
      1  1.1      cgd /*
      2  1.1      cgd  * Copyright (c) 1988 University of Utah.
      3  1.1      cgd  * Copyright (c) 1982, 1986, 1990 The Regents of the University of California.
      4  1.1      cgd  * All rights reserved.
      5  1.1      cgd  *
      6  1.1      cgd  * This code is derived from software contributed to Berkeley by
      7  1.1      cgd  * the Systems Programming Group of the University of Utah Computer
      8  1.1      cgd  * Science Department.
      9  1.1      cgd  *
     10  1.1      cgd  * Redistribution and use in source and binary forms, with or without
     11  1.1      cgd  * modification, are permitted provided that the following conditions
     12  1.1      cgd  * are met:
     13  1.1      cgd  * 1. Redistributions of source code must retain the above copyright
     14  1.1      cgd  *    notice, this list of conditions and the following disclaimer.
     15  1.1      cgd  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.1      cgd  *    notice, this list of conditions and the following disclaimer in the
     17  1.1      cgd  *    documentation and/or other materials provided with the distribution.
     18  1.1      cgd  * 3. All advertising materials mentioning features or use of this software
     19  1.1      cgd  *    must display the following acknowledgement:
     20  1.1      cgd  *	This product includes software developed by the University of
     21  1.1      cgd  *	California, Berkeley and its contributors.
     22  1.1      cgd  * 4. Neither the name of the University nor the names of its contributors
     23  1.1      cgd  *    may be used to endorse or promote products derived from this software
     24  1.1      cgd  *    without specific prior written permission.
     25  1.1      cgd  *
     26  1.1      cgd  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     27  1.1      cgd  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     28  1.1      cgd  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     29  1.1      cgd  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     30  1.1      cgd  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     31  1.1      cgd  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     32  1.1      cgd  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     33  1.1      cgd  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     34  1.1      cgd  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     35  1.1      cgd  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     36  1.1      cgd  * SUCH DAMAGE.
     37  1.1      cgd  *
     38  1.8  mycroft  *	from: Utah Hdr: dcm.c 1.26 91/01/21
     39  1.2      cgd  *	from: @(#)dcm.c	7.14 (Berkeley) 6/27/91
     40  1.9  deraadt  *	$Id: dcm.c,v 1.9 1993/08/29 13:46:32 deraadt Exp $
     41  1.1      cgd  */
     42  1.1      cgd 
     43  1.1      cgd /*
     44  1.1      cgd  * TODO:
     45  1.1      cgd  *	Timeouts
     46  1.1      cgd  *	Test console support.
     47  1.1      cgd  */
     48  1.1      cgd 
     49  1.1      cgd #include "dcm.h"
     50  1.1      cgd #if NDCM > 0
     51  1.1      cgd /*
     52  1.1      cgd  *  98642/MUX
     53  1.1      cgd  */
     54  1.1      cgd #include "sys/param.h"
     55  1.1      cgd #include "sys/systm.h"
     56  1.1      cgd #include "sys/ioctl.h"
     57  1.1      cgd #include "sys/tty.h"
     58  1.1      cgd #include "sys/proc.h"
     59  1.1      cgd #include "sys/conf.h"
     60  1.1      cgd #include "sys/file.h"
     61  1.1      cgd #include "sys/uio.h"
     62  1.1      cgd #include "sys/kernel.h"
     63  1.1      cgd #include "sys/syslog.h"
     64  1.1      cgd #include "sys/time.h"
     65  1.1      cgd 
     66  1.1      cgd #include "device.h"
     67  1.1      cgd #include "dcmreg.h"
     68  1.1      cgd #include "machine/cpu.h"
     69  1.1      cgd #include "../hp300/isr.h"
     70  1.1      cgd 
     71  1.1      cgd #ifndef DEFAULT_BAUD_RATE
     72  1.1      cgd #define DEFAULT_BAUD_RATE 9600
     73  1.1      cgd #endif
     74  1.1      cgd 
     75  1.1      cgd int	ttrstrt();
     76  1.9  deraadt int	dcmprobe(), dcmintr(), dcmparam();
     77  1.9  deraadt void	dcmstart();
     78  1.1      cgd 
     79  1.1      cgd struct	driver dcmdriver = {
     80  1.1      cgd 	dcmprobe, "dcm",
     81  1.1      cgd };
     82  1.1      cgd 
     83  1.1      cgd #define NDCMLINE (NDCM*4)
     84  1.1      cgd 
     85  1.4  deraadt struct	tty *dcm_tty[NDCMLINE];
     86  1.1      cgd struct	modemreg *dcm_modem[NDCMLINE];
     87  1.1      cgd char	mcndlast[NDCMLINE];	/* XXX last modem status for line */
     88  1.1      cgd int	ndcm = NDCMLINE;
     89  1.1      cgd 
     90  1.1      cgd int	dcm_active;
     91  1.1      cgd int	dcmsoftCAR[NDCM];
     92  1.1      cgd struct	dcmdevice *dcm_addr[NDCM];
     93  1.1      cgd struct	isr dcmisr[NDCM];
     94  1.1      cgd 
     95  1.1      cgd struct speedtab dcmspeedtab[] = {
     96  1.1      cgd 	0,	BR_0,
     97  1.1      cgd 	50,	BR_50,
     98  1.1      cgd 	75,	BR_75,
     99  1.1      cgd 	110,	BR_110,
    100  1.1      cgd 	134,	BR_134,
    101  1.1      cgd 	150,	BR_150,
    102  1.1      cgd 	300,	BR_300,
    103  1.1      cgd 	600,	BR_600,
    104  1.1      cgd 	1200,	BR_1200,
    105  1.1      cgd 	1800,	BR_1800,
    106  1.1      cgd 	2400,	BR_2400,
    107  1.1      cgd 	4800,	BR_4800,
    108  1.1      cgd 	9600,	BR_9600,
    109  1.1      cgd 	19200,	BR_19200,
    110  1.1      cgd 	38400,	BR_38400,
    111  1.1      cgd 	-1,	-1
    112  1.1      cgd };
    113  1.1      cgd 
    114  1.1      cgd /* u-sec per character based on baudrate (assumes 1 start/8 data/1 stop bit) */
    115  1.1      cgd #define	DCM_USPERCH(s)	(10000000 / (s))
    116  1.1      cgd 
    117  1.1      cgd /*
    118  1.1      cgd  * Per board interrupt scheme.  16.7ms is the polling interrupt rate
    119  1.1      cgd  * (16.7ms is about 550 baud, 38.4k is 72 chars in 16.7ms).
    120  1.1      cgd  */
    121  1.1      cgd #define DIS_TIMER	0
    122  1.1      cgd #define DIS_PERCHAR	1
    123  1.1      cgd #define DIS_RESET	2
    124  1.1      cgd 
    125  1.1      cgd int	dcmistype = -1;		/* -1 == dynamic, 0 == timer, 1 == perchar */
    126  1.1      cgd int     dcminterval = 5;	/* interval (secs) between checks */
    127  1.1      cgd struct	dcmischeme {
    128  1.1      cgd 	int	dis_perchar;	/* non-zero if interrupting per char */
    129  1.1      cgd 	long	dis_time;	/* last time examined */
    130  1.1      cgd 	int	dis_intr;	/* recv interrupts during last interval */
    131  1.1      cgd 	int	dis_char;	/* characters read during last interval */
    132  1.1      cgd } dcmischeme[NDCM];
    133  1.1      cgd 
    134  1.1      cgd /*
    135  1.1      cgd  * Console support
    136  1.1      cgd  */
    137  1.1      cgd #ifdef DCMCONSOLE
    138  1.1      cgd int	dcmconsole = DCMCONSOLE;
    139  1.1      cgd #else
    140  1.1      cgd int	dcmconsole = -1;
    141  1.1      cgd #endif
    142  1.1      cgd int	dcmconsinit;
    143  1.1      cgd int	dcmdefaultrate = DEFAULT_BAUD_RATE;
    144  1.1      cgd int	dcmconbrdbusy = 0;
    145  1.1      cgd int	dcmmajor;
    146  1.1      cgd extern	struct tty *constty;
    147  1.1      cgd 
    148  1.1      cgd #ifdef KGDB
    149  1.1      cgd /*
    150  1.1      cgd  * Kernel GDB support
    151  1.1      cgd  */
    152  1.1      cgd #include "machine/remote-sl.h"
    153  1.1      cgd 
    154  1.1      cgd extern dev_t kgdb_dev;
    155  1.1      cgd extern int kgdb_rate;
    156  1.1      cgd extern int kgdb_debug_init;
    157  1.1      cgd #endif
    158  1.1      cgd 
    159  1.1      cgd /* #define IOSTATS */
    160  1.1      cgd 
    161  1.1      cgd #ifdef DEBUG
    162  1.1      cgd int	dcmdebug = 0x0;
    163  1.1      cgd #define DDB_SIOERR	0x01
    164  1.1      cgd #define DDB_PARAM	0x02
    165  1.1      cgd #define DDB_INPUT	0x04
    166  1.1      cgd #define DDB_OUTPUT	0x08
    167  1.1      cgd #define DDB_INTR	0x10
    168  1.1      cgd #define DDB_IOCTL	0x20
    169  1.1      cgd #define DDB_INTSCHM	0x40
    170  1.1      cgd #define DDB_MODEM	0x80
    171  1.1      cgd #define DDB_OPENCLOSE	0x100
    172  1.1      cgd #endif
    173  1.1      cgd 
    174  1.1      cgd #ifdef IOSTATS
    175  1.1      cgd #define	DCMRBSIZE	94
    176  1.1      cgd #define DCMXBSIZE	24
    177  1.1      cgd 
    178  1.1      cgd struct	dcmstats {
    179  1.1      cgd 	long	xints;		    /* # of xmit ints */
    180  1.1      cgd 	long	xchars;		    /* # of xmit chars */
    181  1.1      cgd 	long	xempty;		    /* times outq is empty in dcmstart */
    182  1.1      cgd 	long	xrestarts;	    /* times completed while xmitting */
    183  1.1      cgd 	long	rints;		    /* # of recv ints */
    184  1.1      cgd 	long	rchars;		    /* # of recv chars */
    185  1.1      cgd 	long	xsilo[DCMXBSIZE+2]; /* times this many chars xmit on one int */
    186  1.1      cgd 	long	rsilo[DCMRBSIZE+2]; /* times this many chars read on one int */
    187  1.1      cgd } dcmstats[NDCM];
    188  1.1      cgd #endif
    189  1.1      cgd 
    190  1.1      cgd #define UNIT(x)		minor(x)
    191  1.1      cgd #define	BOARD(x)	(((x) >> 2) & 0x3f)
    192  1.1      cgd #define PORT(x)		((x) & 3)
    193  1.1      cgd #define MKUNIT(b,p)	(((b) << 2) | (p))
    194  1.1      cgd 
    195  1.1      cgd /*
    196  1.1      cgd  * Conversion from "HP DCE" to almost-normal DCE: on the 638 8-port mux,
    197  1.1      cgd  * the distribution panel uses "HP DCE" conventions.  If requested via
    198  1.1      cgd  * the device flags, we swap the inputs to something closer to normal DCE,
    199  1.1      cgd  * allowing a straight-through cable to a DTE or a reversed cable
    200  1.1      cgd  * to a DCE (reversing 2-3, 4-5, 8-20 and leaving 6 unconnected;
    201  1.1      cgd  * this gets "DCD" on pin 20 and "CTS" on 4, but doesn't connect
    202  1.1      cgd  * DSR or make RTS work, though).  The following gives the full
    203  1.1      cgd  * details of a cable from this mux panel to a modem:
    204  1.1      cgd  *
    205  1.1      cgd  *		     HP		    modem
    206  1.1      cgd  *		name	pin	pin	name
    207  1.1      cgd  * HP inputs:
    208  1.1      cgd  *		"Rx"	 2	 3	Tx
    209  1.1      cgd  *		CTS	 4	 5	CTS	(only needed for CCTS_OFLOW)
    210  1.1      cgd  *		DCD	20	 8	DCD
    211  1.1      cgd  *		"DSR"	 9	 6	DSR	(unneeded)
    212  1.1      cgd  *		RI	22	22	RI	(unneeded)
    213  1.1      cgd  *
    214  1.1      cgd  * HP outputs:
    215  1.1      cgd  *		"Tx"	 3	 2	Rx
    216  1.1      cgd  *		"DTR"	 6	not connected
    217  1.1      cgd  *		"RTS"	 8	20	DTR
    218  1.1      cgd  *		"SR"	23	 4	RTS	(often not needed)
    219  1.1      cgd  */
    220  1.1      cgd #define	FLAG_STDDCE	0x10	/* map inputs if this bit is set in flags */
    221  1.1      cgd #define hp2dce_in(ibits)	(iconv[(ibits) & 0xf])
    222  1.1      cgd static char iconv[16] = {
    223  1.1      cgd 	0,		MI_DM,		MI_CTS,		MI_CTS|MI_DM,
    224  1.1      cgd 	MI_CD,		MI_CD|MI_DM,	MI_CD|MI_CTS,	MI_CD|MI_CTS|MI_DM,
    225  1.1      cgd 	MI_RI,		MI_RI|MI_DM,	MI_RI|MI_CTS,	MI_RI|MI_CTS|MI_DM,
    226  1.1      cgd 	MI_RI|MI_CD,	MI_RI|MI_CD|MI_DM, MI_RI|MI_CD|MI_CTS,
    227  1.1      cgd 	MI_RI|MI_CD|MI_CTS|MI_DM
    228  1.1      cgd };
    229  1.1      cgd 
    230  1.1      cgd dcmprobe(hd)
    231  1.1      cgd 	register struct hp_device *hd;
    232  1.1      cgd {
    233  1.1      cgd 	register struct dcmdevice *dcm;
    234  1.1      cgd 	register int i;
    235  1.1      cgd 	register int timo = 0;
    236  1.1      cgd 	int s, brd, isconsole, mbits;
    237  1.1      cgd 
    238  1.1      cgd 	dcm = (struct dcmdevice *)hd->hp_addr;
    239  1.1      cgd 	if ((dcm->dcm_rsid & 0x1f) != DCMID)
    240  1.1      cgd 		return (0);
    241  1.1      cgd 	brd = hd->hp_unit;
    242  1.1      cgd 	isconsole = (brd == BOARD(dcmconsole));
    243  1.1      cgd 	/*
    244  1.1      cgd 	 * XXX selected console device (CONSUNIT) as determined by
    245  1.1      cgd 	 * dcmcnprobe does not agree with logical numbering imposed
    246  1.1      cgd 	 * by the config file (i.e. lowest address DCM is not unit
    247  1.1      cgd 	 * CONSUNIT).  Don't recognize this card.
    248  1.1      cgd 	 */
    249  1.1      cgd 	if (isconsole && dcm != dcm_addr[BOARD(dcmconsole)])
    250  1.1      cgd 		return (0);
    251  1.1      cgd 
    252  1.1      cgd 	/*
    253  1.1      cgd 	 * Empirically derived self-test magic
    254  1.1      cgd 	 */
    255  1.1      cgd 	s = spltty();
    256  1.1      cgd 	dcm->dcm_rsid = DCMRS;
    257  1.1      cgd 	DELAY(50000);	/* 5000 is not long enough */
    258  1.1      cgd 	dcm->dcm_rsid = 0;
    259  1.1      cgd 	dcm->dcm_ic = IC_IE;
    260  1.1      cgd 	dcm->dcm_cr = CR_SELFT;
    261  1.1      cgd 	while ((dcm->dcm_ic & IC_IR) == 0)
    262  1.1      cgd 		if (++timo == 20000)
    263  1.1      cgd 			return (0);
    264  1.1      cgd 	DELAY(50000)	/* XXX why is this needed ???? */
    265  1.1      cgd 	while ((dcm->dcm_iir & IIR_SELFT) == 0)
    266  1.1      cgd 		if (++timo == 400000)
    267  1.1      cgd 			return (0);
    268  1.1      cgd 	DELAY(50000)	/* XXX why is this needed ???? */
    269  1.1      cgd 	if (dcm->dcm_stcon != ST_OK) {
    270  1.1      cgd 		if (!isconsole)
    271  1.1      cgd 			printf("dcm%d: self test failed: %x\n",
    272  1.1      cgd 			       brd, dcm->dcm_stcon);
    273  1.1      cgd 		return (0);
    274  1.1      cgd 	}
    275  1.1      cgd 	dcm->dcm_ic = IC_ID;
    276  1.1      cgd 	splx(s);
    277  1.1      cgd 
    278  1.1      cgd 	hd->hp_ipl = DCMIPL(dcm->dcm_ic);
    279  1.1      cgd 	dcm_addr[brd] = dcm;
    280  1.1      cgd 	dcm_active |= 1 << brd;
    281  1.1      cgd 	dcmsoftCAR[brd] = hd->hp_flags;
    282  1.1      cgd 	dcmisr[brd].isr_ipl = hd->hp_ipl;
    283  1.1      cgd 	dcmisr[brd].isr_arg = brd;
    284  1.1      cgd 	dcmisr[brd].isr_intr = dcmintr;
    285  1.1      cgd 	isrlink(&dcmisr[brd]);
    286  1.1      cgd #ifdef KGDB
    287  1.1      cgd 	if (major(kgdb_dev) == dcmmajor && BOARD(kgdb_dev) == brd) {
    288  1.1      cgd 		if (dcmconsole == UNIT(kgdb_dev))
    289  1.1      cgd 			kgdb_dev = NODEV; /* can't debug over console port */
    290  1.1      cgd #ifndef KGDB_CHEAT
    291  1.1      cgd 		/*
    292  1.1      cgd 		 * The following could potentially be replaced
    293  1.1      cgd 		 * by the corresponding code in dcmcnprobe.
    294  1.1      cgd 		 */
    295  1.1      cgd 		else {
    296  1.1      cgd 			(void) dcminit(kgdb_dev, kgdb_rate);
    297  1.1      cgd 			if (kgdb_debug_init) {
    298  1.1      cgd 				printf("dcm%d: ", UNIT(kgdb_dev));
    299  1.1      cgd 				kgdb_connect(1);
    300  1.1      cgd 			} else
    301  1.1      cgd 				printf("dcm%d: kgdb enabled\n", UNIT(kgdb_dev));
    302  1.1      cgd 		}
    303  1.1      cgd 		/* end could be replaced */
    304  1.1      cgd #endif
    305  1.1      cgd 	}
    306  1.1      cgd #endif
    307  1.1      cgd 	if (dcmistype == DIS_TIMER)
    308  1.1      cgd 		dcmsetischeme(brd, DIS_RESET|DIS_TIMER);
    309  1.1      cgd 	else
    310  1.1      cgd 		dcmsetischeme(brd, DIS_RESET|DIS_PERCHAR);
    311  1.1      cgd 
    312  1.1      cgd 	/* load pointers to modem control */
    313  1.1      cgd 	dcm_modem[MKUNIT(brd, 0)] = &dcm->dcm_modem0;
    314  1.1      cgd 	dcm_modem[MKUNIT(brd, 1)] = &dcm->dcm_modem1;
    315  1.1      cgd 	dcm_modem[MKUNIT(brd, 2)] = &dcm->dcm_modem2;
    316  1.1      cgd 	dcm_modem[MKUNIT(brd, 3)] = &dcm->dcm_modem3;
    317  1.1      cgd 	/* set DCD (modem) and CTS (flow control) on all ports */
    318  1.1      cgd 	if (dcmsoftCAR[brd] & FLAG_STDDCE)
    319  1.1      cgd 		mbits = hp2dce_in(MI_CD|MI_CTS);
    320  1.1      cgd 	else
    321  1.1      cgd 		mbits = MI_CD|MI_CTS;
    322  1.1      cgd 	for (i = 0; i < 4; i++)
    323  1.1      cgd 		dcm_modem[MKUNIT(brd, i)]->mdmmsk = mbits;
    324  1.1      cgd 
    325  1.1      cgd 	dcm->dcm_ic = IC_IE;		/* turn all interrupts on */
    326  1.1      cgd 	/*
    327  1.1      cgd 	 * Need to reset baud rate, etc. of next print so reset dcmconsole.
    328  1.1      cgd 	 * Also make sure console is always "hardwired"
    329  1.1      cgd 	 */
    330  1.1      cgd 	if (isconsole) {
    331  1.1      cgd 		dcmconsinit = 0;
    332  1.1      cgd 		dcmsoftCAR[brd] |= (1 << PORT(dcmconsole));
    333  1.1      cgd 	}
    334  1.1      cgd 	return (1);
    335  1.1      cgd }
    336  1.1      cgd 
    337  1.1      cgd /* ARGSUSED */
    338  1.1      cgd #ifdef __STDC__
    339  1.1      cgd dcmopen(dev_t dev, int flag, int mode, struct proc *p)
    340  1.1      cgd #else
    341  1.1      cgd dcmopen(dev, flag, mode, p)
    342  1.1      cgd 	dev_t dev;
    343  1.1      cgd 	int flag, mode;
    344  1.1      cgd 	struct proc *p;
    345  1.1      cgd #endif
    346  1.1      cgd {
    347  1.1      cgd 	register struct tty *tp;
    348  1.1      cgd 	register int unit, brd;
    349  1.1      cgd 	int error = 0, mbits;
    350  1.1      cgd 
    351  1.1      cgd 	unit = UNIT(dev);
    352  1.1      cgd 	brd = BOARD(unit);
    353  1.1      cgd 	if (unit >= NDCMLINE || (dcm_active & (1 << brd)) == 0)
    354  1.1      cgd 		return (ENXIO);
    355  1.7  mycroft 	if(!dcm_tty[unit])
    356  1.7  mycroft 		tp = dcm_tty[unit] = ttymalloc();
    357  1.7  mycroft 	else
    358  1.4  deraadt 		tp = dcm_tty[unit];
    359  1.1      cgd 	tp->t_oproc = dcmstart;
    360  1.1      cgd 	tp->t_param = dcmparam;
    361  1.1      cgd 	tp->t_dev = dev;
    362  1.1      cgd 	if ((tp->t_state & TS_ISOPEN) == 0) {
    363  1.1      cgd 		tp->t_state |= TS_WOPEN;
    364  1.1      cgd 		ttychars(tp);
    365  1.1      cgd 		if (tp->t_ispeed == 0) {
    366  1.1      cgd 			tp->t_iflag = TTYDEF_IFLAG;
    367  1.1      cgd 			tp->t_oflag = TTYDEF_OFLAG;
    368  1.1      cgd 			tp->t_cflag = TTYDEF_CFLAG;
    369  1.1      cgd 			tp->t_lflag = TTYDEF_LFLAG;
    370  1.1      cgd 			tp->t_ispeed = tp->t_ospeed = TTYDEF_SPEED;
    371  1.1      cgd 		}
    372  1.1      cgd 		(void) dcmparam(tp, &tp->t_termios);
    373  1.1      cgd 		ttsetwater(tp);
    374  1.1      cgd 	} else if (tp->t_state&TS_XCLUDE && p->p_ucred->cr_uid != 0)
    375  1.1      cgd 		return (EBUSY);
    376  1.1      cgd 	mbits = MO_ON;
    377  1.1      cgd 	if (dcmsoftCAR[brd] & FLAG_STDDCE)
    378  1.1      cgd 		mbits |= MO_SR;		/* pin 23, could be used as RTS */
    379  1.1      cgd 	(void) dcmmctl(dev, mbits, DMSET);	/* enable port */
    380  1.1      cgd 	if ((dcmsoftCAR[brd] & (1 << PORT(unit))) ||
    381  1.1      cgd 	    (dcmmctl(dev, MO_OFF, DMGET) & MI_CD))
    382  1.1      cgd 		tp->t_state |= TS_CARR_ON;
    383  1.1      cgd #ifdef DEBUG
    384  1.1      cgd 	if (dcmdebug & DDB_MODEM)
    385  1.1      cgd 		printf("dcm%d: dcmopen port %d softcarr %c\n",
    386  1.1      cgd 		       brd, unit, (tp->t_state & TS_CARR_ON) ? '1' : '0');
    387  1.1      cgd #endif
    388  1.1      cgd 	(void) spltty();
    389  1.1      cgd 	while ((flag&O_NONBLOCK) == 0 && (tp->t_cflag&CLOCAL) == 0 &&
    390  1.1      cgd 	    (tp->t_state & TS_CARR_ON) == 0) {
    391  1.1      cgd 		tp->t_state |= TS_WOPEN;
    392  1.7  mycroft 		if (error = ttysleep(tp, (caddr_t)&tp->t_rawq, TTIPRI | PCATCH,
    393  1.1      cgd 		    ttopen, 0))
    394  1.1      cgd 			break;
    395  1.1      cgd 	}
    396  1.1      cgd 	(void) spl0();
    397  1.1      cgd 
    398  1.1      cgd #ifdef DEBUG
    399  1.1      cgd 	if (dcmdebug & DDB_OPENCLOSE)
    400  1.1      cgd 		printf("dcmopen: u %x st %x fl %x\n",
    401  1.1      cgd 			unit, tp->t_state, tp->t_flags);
    402  1.1      cgd #endif
    403  1.1      cgd 	if (error == 0)
    404  1.1      cgd 		error = (*linesw[tp->t_line].l_open)(dev, tp);
    405  1.1      cgd 	return (error);
    406  1.1      cgd }
    407  1.1      cgd 
    408  1.1      cgd /*ARGSUSED*/
    409  1.1      cgd dcmclose(dev, flag, mode, p)
    410  1.1      cgd 	dev_t dev;
    411  1.1      cgd 	int flag, mode;
    412  1.1      cgd 	struct proc *p;
    413  1.1      cgd {
    414  1.1      cgd 	register struct tty *tp;
    415  1.1      cgd 	int unit;
    416  1.1      cgd 
    417  1.1      cgd 	unit = UNIT(dev);
    418  1.4  deraadt 	tp = dcm_tty[unit];
    419  1.1      cgd 	(*linesw[tp->t_line].l_close)(tp, flag);
    420  1.1      cgd 	if (tp->t_cflag&HUPCL || tp->t_state&TS_WOPEN ||
    421  1.1      cgd 	    (tp->t_state&TS_ISOPEN) == 0)
    422  1.1      cgd 		(void) dcmmctl(dev, MO_OFF, DMSET);
    423  1.1      cgd #ifdef DEBUG
    424  1.1      cgd 	if (dcmdebug & DDB_OPENCLOSE)
    425  1.1      cgd 		printf("dcmclose: u %x st %x fl %x\n",
    426  1.1      cgd 			unit, tp->t_state, tp->t_flags);
    427  1.1      cgd #endif
    428  1.1      cgd 	ttyclose(tp);
    429  1.7  mycroft 	ttyfree(tp);
    430  1.4  deraadt 	dcm_tty[unit] = (struct tty *)NULL;
    431  1.1      cgd 	return (0);
    432  1.1      cgd }
    433  1.1      cgd 
    434  1.1      cgd dcmread(dev, uio, flag)
    435  1.1      cgd 	dev_t dev;
    436  1.1      cgd 	struct uio *uio;
    437  1.1      cgd {
    438  1.1      cgd 	register struct tty *tp;
    439  1.1      cgd 
    440  1.4  deraadt 	tp = dcm_tty[UNIT(dev)];
    441  1.1      cgd 	return ((*linesw[tp->t_line].l_read)(tp, uio, flag));
    442  1.1      cgd }
    443  1.1      cgd 
    444  1.1      cgd dcmwrite(dev, uio, flag)
    445  1.1      cgd 	dev_t dev;
    446  1.1      cgd 	struct uio *uio;
    447  1.1      cgd {
    448  1.1      cgd 	int unit = UNIT(dev);
    449  1.1      cgd 	register struct tty *tp;
    450  1.1      cgd 
    451  1.4  deraadt 	tp = dcm_tty[unit];
    452  1.1      cgd 	/*
    453  1.1      cgd 	 * XXX we disallow virtual consoles if the physical console is
    454  1.1      cgd 	 * a serial port.  This is in case there is a display attached that
    455  1.1      cgd 	 * is not the console.  In that situation we don't need/want the X
    456  1.1      cgd 	 * server taking over the console.
    457  1.1      cgd 	 */
    458  1.1      cgd 	if (constty && unit == dcmconsole)
    459  1.1      cgd 		constty = NULL;
    460  1.1      cgd 	return ((*linesw[tp->t_line].l_write)(tp, uio, flag));
    461  1.1      cgd }
    462  1.1      cgd 
    463  1.1      cgd dcmintr(brd)
    464  1.1      cgd 	register int brd;
    465  1.1      cgd {
    466  1.1      cgd 	register struct dcmdevice *dcm = dcm_addr[brd];
    467  1.1      cgd 	register struct dcmischeme *dis;
    468  1.1      cgd 	register int unit = MKUNIT(brd, 0);
    469  1.1      cgd 	register int code, i;
    470  1.1      cgd 	int pcnd[4], mcode, mcnd[4];
    471  1.1      cgd 
    472  1.1      cgd 	/*
    473  1.1      cgd 	 * Do all guarded register accesses right off to minimize
    474  1.1      cgd 	 * block out of hardware.
    475  1.1      cgd 	 */
    476  1.1      cgd 	SEM_LOCK(dcm);
    477  1.1      cgd 	if ((dcm->dcm_ic & IC_IR) == 0) {
    478  1.1      cgd 		SEM_UNLOCK(dcm);
    479  1.1      cgd 		return (0);
    480  1.1      cgd 	}
    481  1.1      cgd 	for (i = 0; i < 4; i++) {
    482  1.1      cgd 		pcnd[i] = dcm->dcm_icrtab[i].dcm_data;
    483  1.1      cgd 		dcm->dcm_icrtab[i].dcm_data = 0;
    484  1.1      cgd 		code = dcm_modem[unit+i]->mdmin;
    485  1.1      cgd 		if (dcmsoftCAR[brd] & FLAG_STDDCE)
    486  1.1      cgd 			code = hp2dce_in(code);
    487  1.1      cgd 		mcnd[i] = code;
    488  1.1      cgd 	}
    489  1.1      cgd 	code = dcm->dcm_iir & IIR_MASK;
    490  1.1      cgd 	dcm->dcm_iir = 0;	/* XXX doc claims read clears interrupt?! */
    491  1.1      cgd 	mcode = dcm->dcm_modemintr;
    492  1.1      cgd 	dcm->dcm_modemintr = 0;
    493  1.1      cgd 	SEM_UNLOCK(dcm);
    494  1.1      cgd 
    495  1.1      cgd #ifdef DEBUG
    496  1.1      cgd 	if (dcmdebug & DDB_INTR) {
    497  1.1      cgd 		printf("dcmintr(%d): iir %x pc %x/%x/%x/%x ",
    498  1.1      cgd 		       brd, code, pcnd[0], pcnd[1], pcnd[2], pcnd[3]);
    499  1.1      cgd 		printf("miir %x mc %x/%x/%x/%x\n",
    500  1.1      cgd 		       mcode, mcnd[0], mcnd[1], mcnd[2], mcnd[3]);
    501  1.1      cgd 	}
    502  1.1      cgd #endif
    503  1.1      cgd 	if (code & IIR_TIMEO)
    504  1.1      cgd 		dcmrint(brd, dcm);
    505  1.1      cgd 	if (code & IIR_PORT0)
    506  1.1      cgd 		dcmpint(unit+0, pcnd[0], dcm);
    507  1.1      cgd 	if (code & IIR_PORT1)
    508  1.1      cgd 		dcmpint(unit+1, pcnd[1], dcm);
    509  1.1      cgd 	if (code & IIR_PORT2)
    510  1.1      cgd 		dcmpint(unit+2, pcnd[2], dcm);
    511  1.1      cgd 	if (code & IIR_PORT3)
    512  1.1      cgd 		dcmpint(unit+3, pcnd[3], dcm);
    513  1.1      cgd 	if (code & IIR_MODM) {
    514  1.1      cgd 		if (mcode == 0 || mcode & 0x1)	/* mcode==0 -> 98642 board */
    515  1.1      cgd 			dcmmint(unit+0, mcnd[0], dcm);
    516  1.1      cgd 		if (mcode & 0x2)
    517  1.1      cgd 			dcmmint(unit+1, mcnd[1], dcm);
    518  1.1      cgd 		if (mcode & 0x4)
    519  1.1      cgd 			dcmmint(unit+2, mcnd[2], dcm);
    520  1.1      cgd 		if (mcode & 0x8)
    521  1.1      cgd 			dcmmint(unit+3, mcnd[3], dcm);
    522  1.1      cgd 	}
    523  1.1      cgd 
    524  1.1      cgd 	dis = &dcmischeme[brd];
    525  1.1      cgd 	/*
    526  1.1      cgd 	 * Chalk up a receiver interrupt if the timer running or one of
    527  1.1      cgd 	 * the ports reports a special character interrupt.
    528  1.1      cgd 	 */
    529  1.1      cgd 	if ((code & IIR_TIMEO) ||
    530  1.1      cgd 	    ((pcnd[0]|pcnd[1]|pcnd[2]|pcnd[3]) & IT_SPEC))
    531  1.1      cgd 		dis->dis_intr++;
    532  1.1      cgd 	/*
    533  1.1      cgd 	 * See if it is time to check/change the interrupt rate.
    534  1.1      cgd 	 */
    535  1.1      cgd 	if (dcmistype < 0 &&
    536  1.1      cgd 	    (i = time.tv_sec - dis->dis_time) >= dcminterval) {
    537  1.1      cgd 		/*
    538  1.1      cgd 		 * If currently per-character and averaged over 70 interrupts
    539  1.1      cgd 		 * per-second (66 is threshold of 600 baud) in last interval,
    540  1.1      cgd 		 * switch to timer mode.
    541  1.1      cgd 		 *
    542  1.1      cgd 		 * XXX decay counts ala load average to avoid spikes?
    543  1.1      cgd 		 */
    544  1.1      cgd 		if (dis->dis_perchar && dis->dis_intr > 70 * i)
    545  1.1      cgd 			dcmsetischeme(brd, DIS_TIMER);
    546  1.1      cgd 		/*
    547  1.1      cgd 		 * If currently using timer and had more interrupts than
    548  1.1      cgd 		 * received characters in the last interval, switch back
    549  1.1      cgd 		 * to per-character.  Note that after changing to per-char
    550  1.1      cgd 		 * we must process any characters already in the queue
    551  1.1      cgd 		 * since they may have arrived before the bitmap was setup.
    552  1.1      cgd 		 *
    553  1.1      cgd 		 * XXX decay counts?
    554  1.1      cgd 		 */
    555  1.1      cgd 		else if (!dis->dis_perchar && dis->dis_intr > dis->dis_char) {
    556  1.1      cgd 			dcmsetischeme(brd, DIS_PERCHAR);
    557  1.1      cgd 			dcmrint(brd, dcm);
    558  1.1      cgd 		}
    559  1.1      cgd 		dis->dis_intr = dis->dis_char = 0;
    560  1.1      cgd 		dis->dis_time = time.tv_sec;
    561  1.1      cgd 	}
    562  1.1      cgd 	return (1);
    563  1.1      cgd }
    564  1.1      cgd 
    565  1.1      cgd /*
    566  1.1      cgd  *  Port interrupt.  Can be two things:
    567  1.1      cgd  *	First, it might be a special character (exception interrupt);
    568  1.1      cgd  *	Second, it may be a buffer empty (transmit interrupt);
    569  1.1      cgd  */
    570  1.1      cgd dcmpint(unit, code, dcm)
    571  1.1      cgd 	int unit, code;
    572  1.1      cgd 	struct dcmdevice *dcm;
    573  1.1      cgd {
    574  1.4  deraadt 	struct tty *tp = dcm_tty[unit];
    575  1.1      cgd 
    576  1.1      cgd 	if (code & IT_SPEC)
    577  1.1      cgd 		dcmreadbuf(unit, dcm, tp);
    578  1.1      cgd 	if (code & IT_TX)
    579  1.1      cgd 		dcmxint(unit, dcm, tp);
    580  1.1      cgd }
    581  1.1      cgd 
    582  1.1      cgd dcmrint(brd, dcm)
    583  1.1      cgd 	int brd;
    584  1.1      cgd 	register struct dcmdevice *dcm;
    585  1.1      cgd {
    586  1.1      cgd 	register int i, unit;
    587  1.1      cgd 	register struct tty *tp;
    588  1.1      cgd 
    589  1.1      cgd 	unit = MKUNIT(brd, 0);
    590  1.4  deraadt 	tp = dcm_tty[unit];
    591  1.1      cgd 	for (i = 0; i < 4; i++, tp++, unit++)
    592  1.1      cgd 		dcmreadbuf(unit, dcm, tp);
    593  1.1      cgd }
    594  1.1      cgd 
    595  1.1      cgd dcmreadbuf(unit, dcm, tp)
    596  1.1      cgd 	int unit;
    597  1.1      cgd 	register struct dcmdevice *dcm;
    598  1.1      cgd 	register struct tty *tp;
    599  1.1      cgd {
    600  1.1      cgd 	int port = PORT(unit);
    601  1.1      cgd 	register struct dcmpreg *pp = dcm_preg(dcm, port);
    602  1.1      cgd 	register struct dcmrfifo *fifo;
    603  1.1      cgd 	register int c, stat;
    604  1.1      cgd 	register unsigned head;
    605  1.1      cgd 	int nch = 0;
    606  1.1      cgd #ifdef IOSTATS
    607  1.1      cgd 	struct dcmstats *dsp = &dcmstats[BOARD(unit)];
    608  1.1      cgd 
    609  1.1      cgd 	dsp->rints++;
    610  1.1      cgd #endif
    611  1.1      cgd 	if ((tp->t_state & TS_ISOPEN) == 0) {
    612  1.1      cgd #ifdef KGDB
    613  1.1      cgd 		if ((makedev(dcmmajor, unit) == kgdb_dev) &&
    614  1.1      cgd 		    (head = pp->r_head & RX_MASK) != (pp->r_tail & RX_MASK) &&
    615  1.1      cgd 		    dcm->dcm_rfifos[3-port][head>>1].data_char == FRAME_END) {
    616  1.1      cgd 			pp->r_head = (head + 2) & RX_MASK;
    617  1.1      cgd 			kgdb_connect(0);	/* trap into kgdb */
    618  1.1      cgd 			return;
    619  1.1      cgd 		}
    620  1.1      cgd #endif /* KGDB */
    621  1.1      cgd 		pp->r_head = pp->r_tail & RX_MASK;
    622  1.1      cgd 		return;
    623  1.1      cgd 	}
    624  1.1      cgd 
    625  1.1      cgd 	head = pp->r_head & RX_MASK;
    626  1.1      cgd 	fifo = &dcm->dcm_rfifos[3-port][head>>1];
    627  1.1      cgd 	/*
    628  1.1      cgd 	 * XXX upper bound on how many chars we will take in one swallow?
    629  1.1      cgd 	 */
    630  1.1      cgd 	while (head != (pp->r_tail & RX_MASK)) {
    631  1.1      cgd 		/*
    632  1.1      cgd 		 * Get character/status and update head pointer as fast
    633  1.1      cgd 		 * as possible to make room for more characters.
    634  1.1      cgd 		 */
    635  1.1      cgd 		c = fifo->data_char;
    636  1.1      cgd 		stat = fifo->data_stat;
    637  1.1      cgd 		head = (head + 2) & RX_MASK;
    638  1.1      cgd 		pp->r_head = head;
    639  1.1      cgd 		fifo = head ? fifo+1 : &dcm->dcm_rfifos[3-port][0];
    640  1.1      cgd 		nch++;
    641  1.1      cgd 
    642  1.1      cgd #ifdef DEBUG
    643  1.1      cgd 		if (dcmdebug & DDB_INPUT)
    644  1.1      cgd 			printf("dcmreadbuf(%d): c%x('%c') s%x f%x h%x t%x\n",
    645  1.1      cgd 			       unit, c&0xFF, c, stat&0xFF,
    646  1.1      cgd 			       tp->t_flags, head, pp->r_tail);
    647  1.1      cgd #endif
    648  1.1      cgd 		/*
    649  1.1      cgd 		 * Check for and handle errors
    650  1.1      cgd 		 */
    651  1.1      cgd 		if (stat & RD_MASK) {
    652  1.1      cgd #ifdef DEBUG
    653  1.1      cgd 			if (dcmdebug & (DDB_INPUT|DDB_SIOERR))
    654  1.1      cgd 				printf("dcmreadbuf(%d): err: c%x('%c') s%x\n",
    655  1.1      cgd 				       unit, stat, c&0xFF, c);
    656  1.1      cgd #endif
    657  1.1      cgd 			if (stat & (RD_BD | RD_FE))
    658  1.1      cgd 				c |= TTY_FE;
    659  1.1      cgd 			else if (stat & RD_PE)
    660  1.1      cgd 				c |= TTY_PE;
    661  1.1      cgd 			else if (stat & RD_OVF)
    662  1.1      cgd 				log(LOG_WARNING,
    663  1.1      cgd 				    "dcm%d: silo overflow\n", unit);
    664  1.1      cgd 			else if (stat & RD_OE)
    665  1.1      cgd 				log(LOG_WARNING,
    666  1.1      cgd 				    "dcm%d: uart overflow\n", unit);
    667  1.1      cgd 		}
    668  1.1      cgd 		(*linesw[tp->t_line].l_rint)(c, tp);
    669  1.1      cgd 	}
    670  1.1      cgd 	dcmischeme[BOARD(unit)].dis_char += nch;
    671  1.1      cgd #ifdef IOSTATS
    672  1.1      cgd 	dsp->rchars += nch;
    673  1.1      cgd 	if (nch <= DCMRBSIZE)
    674  1.1      cgd 		dsp->rsilo[nch]++;
    675  1.1      cgd 	else
    676  1.1      cgd 		dsp->rsilo[DCMRBSIZE+1]++;
    677  1.1      cgd #endif
    678  1.1      cgd }
    679  1.1      cgd 
    680  1.1      cgd dcmxint(unit, dcm, tp)
    681  1.1      cgd 	int unit;
    682  1.1      cgd 	struct dcmdevice *dcm;
    683  1.1      cgd 	register struct tty *tp;
    684  1.1      cgd {
    685  1.1      cgd 	tp->t_state &= ~TS_BUSY;
    686  1.1      cgd 	if (tp->t_state & TS_FLUSH)
    687  1.1      cgd 		tp->t_state &= ~TS_FLUSH;
    688  1.1      cgd 	(*linesw[tp->t_line].l_start)(tp);
    689  1.1      cgd }
    690  1.1      cgd 
    691  1.1      cgd dcmmint(unit, mcnd, dcm)
    692  1.1      cgd 	register int unit;
    693  1.1      cgd 	register struct dcmdevice *dcm;
    694  1.1      cgd         int mcnd;
    695  1.1      cgd {
    696  1.1      cgd 	register struct tty *tp;
    697  1.1      cgd 	int delta;
    698  1.1      cgd 
    699  1.1      cgd #ifdef DEBUG
    700  1.1      cgd 	if (dcmdebug & DDB_MODEM)
    701  1.1      cgd 		printf("dcmmint: port %d mcnd %x mcndlast %x\n",
    702  1.1      cgd 		       unit, mcnd, mcndlast[unit]);
    703  1.1      cgd #endif
    704  1.4  deraadt 	tp = dcm_tty[unit];
    705  1.1      cgd 	delta = mcnd ^ mcndlast[unit];
    706  1.1      cgd 	mcndlast[unit] = mcnd;
    707  1.1      cgd 	if ((delta & MI_CTS) && (tp->t_state & TS_ISOPEN) &&
    708  1.1      cgd 	    (tp->t_flags & CCTS_OFLOW)) {
    709  1.1      cgd 		if (mcnd & MI_CTS) {
    710  1.1      cgd 			tp->t_state &= ~TS_TTSTOP;
    711  1.1      cgd 			ttstart(tp);
    712  1.1      cgd 		} else
    713  1.1      cgd 			tp->t_state |= TS_TTSTOP;	/* inline dcmstop */
    714  1.1      cgd 	}
    715  1.1      cgd 	if (delta & MI_CD) {
    716  1.1      cgd 		if (mcnd & MI_CD)
    717  1.1      cgd 			(void)(*linesw[tp->t_line].l_modem)(tp, 1);
    718  1.1      cgd 		else if ((dcmsoftCAR[BOARD(unit)] & (1 << PORT(unit))) == 0 &&
    719  1.1      cgd 		    (*linesw[tp->t_line].l_modem)(tp, 0) == 0) {
    720  1.1      cgd 			dcm_modem[unit]->mdmout = MO_OFF;
    721  1.1      cgd 			SEM_LOCK(dcm);
    722  1.1      cgd 			dcm->dcm_modemchng |= 1<<(unit & 3);
    723  1.1      cgd 			dcm->dcm_cr |= CR_MODM;
    724  1.1      cgd 			SEM_UNLOCK(dcm);
    725  1.1      cgd 			DELAY(10); /* time to change lines */
    726  1.1      cgd 		}
    727  1.1      cgd 	}
    728  1.1      cgd }
    729  1.1      cgd 
    730  1.1      cgd dcmioctl(dev, cmd, data, flag)
    731  1.1      cgd 	dev_t dev;
    732  1.1      cgd 	caddr_t data;
    733  1.1      cgd {
    734  1.1      cgd 	register struct tty *tp;
    735  1.1      cgd 	register int unit = UNIT(dev);
    736  1.1      cgd 	register struct dcmdevice *dcm;
    737  1.1      cgd 	register int port;
    738  1.1      cgd 	int error, s;
    739  1.1      cgd 
    740  1.1      cgd #ifdef DEBUG
    741  1.1      cgd 	if (dcmdebug & DDB_IOCTL)
    742  1.1      cgd 		printf("dcmioctl: unit %d cmd %x data %x flag %x\n",
    743  1.1      cgd 		       unit, cmd, *data, flag);
    744  1.1      cgd #endif
    745  1.4  deraadt 	tp = dcm_tty[unit];
    746  1.1      cgd 	error = (*linesw[tp->t_line].l_ioctl)(tp, cmd, data, flag);
    747  1.1      cgd 	if (error >= 0)
    748  1.1      cgd 		return (error);
    749  1.1      cgd 	error = ttioctl(tp, cmd, data, flag);
    750  1.1      cgd 	if (error >= 0)
    751  1.1      cgd 		return (error);
    752  1.1      cgd 
    753  1.1      cgd 	port = PORT(unit);
    754  1.1      cgd 	dcm = dcm_addr[BOARD(unit)];
    755  1.1      cgd 	switch (cmd) {
    756  1.1      cgd 	case TIOCSBRK:
    757  1.1      cgd 		/*
    758  1.1      cgd 		 * Wait for transmitter buffer to empty
    759  1.1      cgd 		 */
    760  1.1      cgd 		s = spltty();
    761  1.1      cgd 		while (dcm->dcm_thead[port].ptr != dcm->dcm_ttail[port].ptr)
    762  1.1      cgd 			DELAY(DCM_USPERCH(tp->t_ospeed));
    763  1.1      cgd 		SEM_LOCK(dcm);
    764  1.1      cgd 		dcm->dcm_cmdtab[port].dcm_data |= CT_BRK;
    765  1.1      cgd 		dcm->dcm_cr |= (1 << port);	/* start break */
    766  1.1      cgd 		SEM_UNLOCK(dcm);
    767  1.1      cgd 		splx(s);
    768  1.1      cgd 		break;
    769  1.1      cgd 
    770  1.1      cgd 	case TIOCCBRK:
    771  1.1      cgd 		SEM_LOCK(dcm);
    772  1.1      cgd 		dcm->dcm_cmdtab[port].dcm_data |= CT_BRK;
    773  1.1      cgd 		dcm->dcm_cr |= (1 << port);	/* end break */
    774  1.1      cgd 		SEM_UNLOCK(dcm);
    775  1.1      cgd 		break;
    776  1.1      cgd 
    777  1.1      cgd 	case TIOCSDTR:
    778  1.1      cgd 		(void) dcmmctl(dev, MO_ON, DMBIS);
    779  1.1      cgd 		break;
    780  1.1      cgd 
    781  1.1      cgd 	case TIOCCDTR:
    782  1.1      cgd 		(void) dcmmctl(dev, MO_ON, DMBIC);
    783  1.1      cgd 		break;
    784  1.1      cgd 
    785  1.1      cgd 	case TIOCMSET:
    786  1.1      cgd 		(void) dcmmctl(dev, *(int *)data, DMSET);
    787  1.1      cgd 		break;
    788  1.1      cgd 
    789  1.1      cgd 	case TIOCMBIS:
    790  1.1      cgd 		(void) dcmmctl(dev, *(int *)data, DMBIS);
    791  1.1      cgd 		break;
    792  1.1      cgd 
    793  1.1      cgd 	case TIOCMBIC:
    794  1.1      cgd 		(void) dcmmctl(dev, *(int *)data, DMBIC);
    795  1.1      cgd 		break;
    796  1.1      cgd 
    797  1.1      cgd 	case TIOCMGET:
    798  1.1      cgd 		*(int *)data = dcmmctl(dev, 0, DMGET);
    799  1.1      cgd 		break;
    800  1.1      cgd 
    801  1.1      cgd 	default:
    802  1.1      cgd 		return (ENOTTY);
    803  1.1      cgd 	}
    804  1.1      cgd 	return (0);
    805  1.1      cgd }
    806  1.1      cgd 
    807  1.1      cgd dcmparam(tp, t)
    808  1.1      cgd 	register struct tty *tp;
    809  1.1      cgd 	register struct termios *t;
    810  1.1      cgd {
    811  1.1      cgd 	register struct dcmdevice *dcm;
    812  1.1      cgd 	register int port, mode, cflag = t->c_cflag;
    813  1.1      cgd 	int ospeed = ttspeedtab(t->c_ospeed, dcmspeedtab);
    814  1.1      cgd 
    815  1.1      cgd 	/* check requested parameters */
    816  1.1      cgd         if (ospeed < 0 || (t->c_ispeed && t->c_ispeed != t->c_ospeed))
    817  1.1      cgd                 return (EINVAL);
    818  1.1      cgd         /* and copy to tty */
    819  1.1      cgd         tp->t_ispeed = t->c_ispeed;
    820  1.1      cgd         tp->t_ospeed = t->c_ospeed;
    821  1.1      cgd         tp->t_cflag = cflag;
    822  1.1      cgd 	if (ospeed == 0) {
    823  1.1      cgd 		(void) dcmmctl(UNIT(tp->t_dev), MO_OFF, DMSET);
    824  1.1      cgd 		return (0);
    825  1.1      cgd 	}
    826  1.1      cgd 
    827  1.1      cgd 	mode = 0;
    828  1.1      cgd 	switch (cflag&CSIZE) {
    829  1.1      cgd 	case CS5:
    830  1.1      cgd 		mode = LC_5BITS; break;
    831  1.1      cgd 	case CS6:
    832  1.1      cgd 		mode = LC_6BITS; break;
    833  1.1      cgd 	case CS7:
    834  1.1      cgd 		mode = LC_7BITS; break;
    835  1.1      cgd 	case CS8:
    836  1.1      cgd 		mode = LC_8BITS; break;
    837  1.1      cgd 	}
    838  1.1      cgd 	if (cflag&PARENB) {
    839  1.1      cgd 		if (cflag&PARODD)
    840  1.1      cgd 			mode |= LC_PODD;
    841  1.1      cgd 		else
    842  1.1      cgd 			mode |= LC_PEVEN;
    843  1.1      cgd 	}
    844  1.1      cgd 	if (cflag&CSTOPB)
    845  1.1      cgd 		mode |= LC_2STOP;
    846  1.1      cgd 	else
    847  1.1      cgd 		mode |= LC_1STOP;
    848  1.1      cgd #ifdef DEBUG
    849  1.1      cgd 	if (dcmdebug & DDB_PARAM)
    850  1.1      cgd 		printf("dcmparam(%d): cflag %x mode %x speed %d uperch %d\n",
    851  1.1      cgd 		       UNIT(tp->t_dev), cflag, mode, tp->t_ospeed,
    852  1.1      cgd 		       DCM_USPERCH(tp->t_ospeed));
    853  1.1      cgd #endif
    854  1.1      cgd 
    855  1.1      cgd 	port = PORT(tp->t_dev);
    856  1.1      cgd 	dcm = dcm_addr[BOARD(tp->t_dev)];
    857  1.1      cgd 	/*
    858  1.1      cgd 	 * Wait for transmitter buffer to empty.
    859  1.1      cgd 	 */
    860  1.1      cgd 	while (dcm->dcm_thead[port].ptr != dcm->dcm_ttail[port].ptr)
    861  1.1      cgd 		DELAY(DCM_USPERCH(tp->t_ospeed));
    862  1.1      cgd 	/*
    863  1.1      cgd 	 * Make changes known to hardware.
    864  1.1      cgd 	 */
    865  1.1      cgd 	dcm->dcm_data[port].dcm_baud = ospeed;
    866  1.1      cgd 	dcm->dcm_data[port].dcm_conf = mode;
    867  1.1      cgd 	SEM_LOCK(dcm);
    868  1.1      cgd 	dcm->dcm_cmdtab[port].dcm_data |= CT_CON;
    869  1.1      cgd 	dcm->dcm_cr |= (1 << port);
    870  1.1      cgd 	SEM_UNLOCK(dcm);
    871  1.1      cgd 	/*
    872  1.1      cgd 	 * Delay for config change to take place. Weighted by baud.
    873  1.1      cgd 	 * XXX why do we do this?
    874  1.1      cgd 	 */
    875  1.1      cgd 	DELAY(16 * DCM_USPERCH(tp->t_ospeed));
    876  1.1      cgd 	return (0);
    877  1.1      cgd }
    878  1.1      cgd 
    879  1.9  deraadt void
    880  1.1      cgd dcmstart(tp)
    881  1.1      cgd 	register struct tty *tp;
    882  1.1      cgd {
    883  1.1      cgd 	register struct dcmdevice *dcm;
    884  1.1      cgd 	register struct dcmpreg *pp;
    885  1.1      cgd 	register struct dcmtfifo *fifo;
    886  1.1      cgd 	register char *bp;
    887  1.1      cgd 	register unsigned tail, next;
    888  1.1      cgd 	register int port, nch;
    889  1.1      cgd 	unsigned head;
    890  1.1      cgd 	char buf[16];
    891  1.1      cgd 	int s;
    892  1.1      cgd #ifdef IOSTATS
    893  1.1      cgd 	struct dcmstats *dsp = &dcmstats[BOARD(tp->t_dev)];
    894  1.1      cgd 	int tch = 0;
    895  1.1      cgd #endif
    896  1.1      cgd 
    897  1.1      cgd 	s = spltty();
    898  1.1      cgd #ifdef IOSTATS
    899  1.1      cgd 	dsp->xints++;
    900  1.1      cgd #endif
    901  1.1      cgd #ifdef DEBUG
    902  1.1      cgd 	if (dcmdebug & DDB_OUTPUT)
    903  1.1      cgd 		printf("dcmstart(%d): state %x flags %x outcc %d\n",
    904  1.1      cgd 		       UNIT(tp->t_dev), tp->t_state, tp->t_flags,
    905  1.7  mycroft 		       tp->t_outq.c_cc);
    906  1.1      cgd #endif
    907  1.1      cgd 	if (tp->t_state & (TS_TIMEOUT|TS_BUSY|TS_TTSTOP))
    908  1.1      cgd 		goto out;
    909  1.7  mycroft 	if (tp->t_outq.c_cc <= tp->t_lowat) {
    910  1.1      cgd 		if (tp->t_state&TS_ASLEEP) {
    911  1.1      cgd 			tp->t_state &= ~TS_ASLEEP;
    912  1.7  mycroft 			wakeup((caddr_t)&tp->t_outq);
    913  1.1      cgd 		}
    914  1.2      cgd 		selwakeup(&tp->t_wsel);
    915  1.1      cgd 	}
    916  1.7  mycroft 	if (tp->t_outq.c_cc == 0) {
    917  1.1      cgd #ifdef IOSTATS
    918  1.1      cgd 		dsp->xempty++;
    919  1.1      cgd #endif
    920  1.1      cgd 		goto out;
    921  1.1      cgd 	}
    922  1.1      cgd 
    923  1.1      cgd 	dcm = dcm_addr[BOARD(tp->t_dev)];
    924  1.1      cgd 	port = PORT(tp->t_dev);
    925  1.1      cgd 	pp = dcm_preg(dcm, port);
    926  1.1      cgd 	tail = pp->t_tail & TX_MASK;
    927  1.1      cgd 	next = (tail + 1) & TX_MASK;
    928  1.1      cgd 	head = pp->t_head & TX_MASK;
    929  1.1      cgd 	if (head == next)
    930  1.1      cgd 		goto out;
    931  1.1      cgd 	fifo = &dcm->dcm_tfifos[3-port][tail];
    932  1.1      cgd again:
    933  1.1      cgd 	nch = q_to_b(&tp->t_outq, buf, (head - next) & TX_MASK);
    934  1.1      cgd #ifdef IOSTATS
    935  1.1      cgd 	tch += nch;
    936  1.1      cgd #endif
    937  1.1      cgd #ifdef DEBUG
    938  1.1      cgd 	if (dcmdebug & DDB_OUTPUT)
    939  1.1      cgd 		printf("\thead %x tail %x nch %d\n", head, tail, nch);
    940  1.1      cgd #endif
    941  1.1      cgd 	/*
    942  1.1      cgd 	 * Loop transmitting all the characters we can.
    943  1.1      cgd 	 */
    944  1.1      cgd 	for (bp = buf; --nch >= 0; bp++) {
    945  1.1      cgd 		fifo->data_char = *bp;
    946  1.1      cgd 		pp->t_tail = next;
    947  1.1      cgd 		/*
    948  1.1      cgd 		 * If this is the first character,
    949  1.1      cgd 		 * get the hardware moving right now.
    950  1.1      cgd 		 */
    951  1.1      cgd 		if (bp == buf) {
    952  1.1      cgd 			tp->t_state |= TS_BUSY;
    953  1.1      cgd 			SEM_LOCK(dcm);
    954  1.1      cgd 			dcm->dcm_cmdtab[port].dcm_data |= CT_TX;
    955  1.1      cgd 			dcm->dcm_cr |= (1 << port);
    956  1.1      cgd 			SEM_UNLOCK(dcm);
    957  1.1      cgd 		}
    958  1.1      cgd 		tail = next;
    959  1.1      cgd 		fifo = tail ? fifo+1 : &dcm->dcm_tfifos[3-port][0];
    960  1.1      cgd 		next = (next + 1) & TX_MASK;
    961  1.1      cgd 	}
    962  1.1      cgd 	/*
    963  1.1      cgd 	 * Head changed while we were loading the buffer,
    964  1.1      cgd 	 * go back and load some more if we can.
    965  1.1      cgd 	 */
    966  1.7  mycroft 	if (tp->t_outq.c_cc && head != (pp->t_head & TX_MASK)) {
    967  1.1      cgd #ifdef IOSTATS
    968  1.1      cgd 		dsp->xrestarts++;
    969  1.1      cgd #endif
    970  1.1      cgd 		head = pp->t_head & TX_MASK;
    971  1.1      cgd 		goto again;
    972  1.1      cgd 	}
    973  1.1      cgd 
    974  1.1      cgd 	/*
    975  1.1      cgd 	 * Kick it one last time in case it finished while we were
    976  1.1      cgd 	 * loading the last bunch.
    977  1.1      cgd 	 */
    978  1.1      cgd 	if (bp > &buf[1]) {
    979  1.1      cgd 		tp->t_state |= TS_BUSY;
    980  1.1      cgd 		SEM_LOCK(dcm);
    981  1.1      cgd 		dcm->dcm_cmdtab[port].dcm_data |= CT_TX;
    982  1.1      cgd 		dcm->dcm_cr |= (1 << port);
    983  1.1      cgd 		SEM_UNLOCK(dcm);
    984  1.1      cgd 	}
    985  1.1      cgd #ifdef DEBUG
    986  1.1      cgd 	if (dcmdebug & DDB_INTR)
    987  1.7  mycroft 		printf("dcmstart(%d): head %x tail %x outqcc %d\n",
    988  1.7  mycroft 		       UNIT(tp->t_dev), head, tail, tp->t_outq.c_cc);
    989  1.1      cgd #endif
    990  1.1      cgd out:
    991  1.1      cgd #ifdef IOSTATS
    992  1.1      cgd 	dsp->xchars += tch;
    993  1.1      cgd 	if (tch <= DCMXBSIZE)
    994  1.1      cgd 		dsp->xsilo[tch]++;
    995  1.1      cgd 	else
    996  1.1      cgd 		dsp->xsilo[DCMXBSIZE+1]++;
    997  1.1      cgd #endif
    998  1.1      cgd 	splx(s);
    999  1.1      cgd }
   1000  1.1      cgd 
   1001  1.1      cgd /*
   1002  1.1      cgd  * Stop output on a line.
   1003  1.1      cgd  */
   1004  1.1      cgd dcmstop(tp, flag)
   1005  1.1      cgd 	register struct tty *tp;
   1006  1.1      cgd {
   1007  1.1      cgd 	int s;
   1008  1.1      cgd 
   1009  1.1      cgd 	s = spltty();
   1010  1.1      cgd 	if (tp->t_state & TS_BUSY) {
   1011  1.1      cgd 		/* XXX is there some way to safely stop transmission? */
   1012  1.1      cgd 		if ((tp->t_state&TS_TTSTOP) == 0)
   1013  1.1      cgd 			tp->t_state |= TS_FLUSH;
   1014  1.1      cgd 	}
   1015  1.1      cgd 	splx(s);
   1016  1.1      cgd }
   1017  1.1      cgd 
   1018  1.1      cgd /*
   1019  1.1      cgd  * Modem control
   1020  1.1      cgd  */
   1021  1.1      cgd dcmmctl(dev, bits, how)
   1022  1.1      cgd 	dev_t dev;
   1023  1.1      cgd 	int bits, how;
   1024  1.1      cgd {
   1025  1.1      cgd 	register struct dcmdevice *dcm;
   1026  1.1      cgd 	int s, unit, brd, hit = 0;
   1027  1.1      cgd 
   1028  1.1      cgd 	unit = UNIT(dev);
   1029  1.1      cgd #ifdef DEBUG
   1030  1.1      cgd 	if (dcmdebug & DDB_MODEM)
   1031  1.1      cgd 		printf("dcmmctl(%d) unit %d  bits 0x%x how %x\n",
   1032  1.1      cgd 		       BOARD(unit), unit, bits, how);
   1033  1.1      cgd #endif
   1034  1.1      cgd 
   1035  1.1      cgd 	brd = BOARD(unit);
   1036  1.1      cgd 	dcm = dcm_addr[brd];
   1037  1.1      cgd 	s = spltty();
   1038  1.1      cgd 	switch (how) {
   1039  1.1      cgd 
   1040  1.1      cgd 	case DMSET:
   1041  1.1      cgd 		dcm_modem[unit]->mdmout = bits;
   1042  1.1      cgd 		hit++;
   1043  1.1      cgd 		break;
   1044  1.1      cgd 
   1045  1.1      cgd 	case DMBIS:
   1046  1.1      cgd 		dcm_modem[unit]->mdmout |= bits;
   1047  1.1      cgd 		hit++;
   1048  1.1      cgd 		break;
   1049  1.1      cgd 
   1050  1.1      cgd 	case DMBIC:
   1051  1.1      cgd 		dcm_modem[unit]->mdmout &= ~bits;
   1052  1.1      cgd 		hit++;
   1053  1.1      cgd 		break;
   1054  1.1      cgd 
   1055  1.1      cgd 	case DMGET:
   1056  1.1      cgd 		bits = dcm_modem[unit]->mdmin;
   1057  1.1      cgd 		if (dcmsoftCAR[brd] & FLAG_STDDCE)
   1058  1.1      cgd 			bits = hp2dce_in(bits);
   1059  1.1      cgd 		break;
   1060  1.1      cgd 	}
   1061  1.1      cgd 	if (hit) {
   1062  1.1      cgd 		SEM_LOCK(dcm);
   1063  1.1      cgd 		dcm->dcm_modemchng |= 1<<(unit & 3);
   1064  1.1      cgd 		dcm->dcm_cr |= CR_MODM;
   1065  1.1      cgd 		SEM_UNLOCK(dcm);
   1066  1.1      cgd 		DELAY(10); /* delay until done */
   1067  1.1      cgd 		(void) splx(s);
   1068  1.1      cgd 	}
   1069  1.1      cgd 	return (bits);
   1070  1.1      cgd }
   1071  1.1      cgd 
   1072  1.1      cgd /*
   1073  1.1      cgd  * Set board to either interrupt per-character or at a fixed interval.
   1074  1.1      cgd  */
   1075  1.1      cgd dcmsetischeme(brd, flags)
   1076  1.1      cgd 	int brd, flags;
   1077  1.1      cgd {
   1078  1.1      cgd 	register struct dcmdevice *dcm = dcm_addr[brd];
   1079  1.1      cgd 	register struct dcmischeme *dis = &dcmischeme[brd];
   1080  1.1      cgd 	register int i;
   1081  1.1      cgd 	u_char mask;
   1082  1.1      cgd 	int perchar = flags & DIS_PERCHAR;
   1083  1.1      cgd 
   1084  1.1      cgd #ifdef DEBUG
   1085  1.1      cgd 	if (dcmdebug & DDB_INTSCHM)
   1086  1.1      cgd 		printf("dcmsetischeme(%d, %d): cur %d, ints %d, chars %d\n",
   1087  1.1      cgd 		       brd, perchar, dis->dis_perchar,
   1088  1.1      cgd 		       dis->dis_intr, dis->dis_char);
   1089  1.1      cgd 	if ((flags & DIS_RESET) == 0 && perchar == dis->dis_perchar) {
   1090  1.1      cgd 		printf("dcmsetischeme(%d):  redundent request %d\n",
   1091  1.1      cgd 		       brd, perchar);
   1092  1.1      cgd 		return;
   1093  1.1      cgd 	}
   1094  1.1      cgd #endif
   1095  1.1      cgd 	/*
   1096  1.1      cgd 	 * If perchar is non-zero, we enable interrupts on all characters
   1097  1.1      cgd 	 * otherwise we disable perchar interrupts and use periodic
   1098  1.1      cgd 	 * polling interrupts.
   1099  1.1      cgd 	 */
   1100  1.1      cgd 	dis->dis_perchar = perchar;
   1101  1.1      cgd 	mask = perchar ? 0xf : 0x0;
   1102  1.1      cgd 	for (i = 0; i < 256; i++)
   1103  1.1      cgd 		dcm->dcm_bmap[i].data_data = mask;
   1104  1.1      cgd 	/*
   1105  1.1      cgd 	 * Don't slow down tandem mode, interrupt on flow control
   1106  1.1      cgd 	 * chars for any port on the board.
   1107  1.1      cgd 	 */
   1108  1.1      cgd 	if (!perchar) {
   1109  1.4  deraadt 		register struct tty *tp = dcm_tty[MKUNIT(brd, 0)];
   1110  1.1      cgd 		int c;
   1111  1.1      cgd 
   1112  1.1      cgd 		for (i = 0; i < 4; i++, tp++) {
   1113  1.1      cgd 			if ((c = tp->t_cc[VSTART]) != _POSIX_VDISABLE)
   1114  1.1      cgd 				dcm->dcm_bmap[c].data_data |= (1 << i);
   1115  1.1      cgd 			if ((c = tp->t_cc[VSTOP]) != _POSIX_VDISABLE)
   1116  1.1      cgd 				dcm->dcm_bmap[c].data_data |= (1 << i);
   1117  1.1      cgd 		}
   1118  1.1      cgd 	}
   1119  1.1      cgd 	/*
   1120  1.1      cgd 	 * Board starts with timer disabled so if first call is to
   1121  1.1      cgd 	 * set perchar mode then we don't want to toggle the timer.
   1122  1.1      cgd 	 */
   1123  1.1      cgd 	if (flags == (DIS_RESET|DIS_PERCHAR))
   1124  1.1      cgd 		return;
   1125  1.1      cgd 	/*
   1126  1.1      cgd 	 * Toggle card 16.7ms interrupts (we first make sure that card
   1127  1.1      cgd 	 * has cleared the bit so it will see the toggle).
   1128  1.1      cgd 	 */
   1129  1.1      cgd 	while (dcm->dcm_cr & CR_TIMER)
   1130  1.1      cgd 		;
   1131  1.1      cgd 	SEM_LOCK(dcm);
   1132  1.1      cgd 	dcm->dcm_cr |= CR_TIMER;
   1133  1.1      cgd 	SEM_UNLOCK(dcm);
   1134  1.1      cgd }
   1135  1.1      cgd 
   1136  1.1      cgd /*
   1137  1.1      cgd  * Following are all routines needed for DCM to act as console
   1138  1.1      cgd  */
   1139  1.1      cgd #include "../hp300/cons.h"
   1140  1.1      cgd 
   1141  1.1      cgd dcmcnprobe(cp)
   1142  1.1      cgd 	struct consdev *cp;
   1143  1.1      cgd {
   1144  1.1      cgd 	register struct hp_hw *hw;
   1145  1.1      cgd 	int unit;
   1146  1.1      cgd 
   1147  1.1      cgd 	/* locate the major number */
   1148  1.1      cgd 	for (dcmmajor = 0; dcmmajor < nchrdev; dcmmajor++)
   1149  1.1      cgd 		if (cdevsw[dcmmajor].d_open == dcmopen)
   1150  1.1      cgd 			break;
   1151  1.1      cgd 
   1152  1.1      cgd 	/*
   1153  1.1      cgd 	 * Implicitly assigns the lowest select code DCM card found to be
   1154  1.1      cgd 	 * logical unit 0 (actually CONUNIT).  If your config file does
   1155  1.1      cgd 	 * anything different, you're screwed.
   1156  1.1      cgd 	 */
   1157  1.1      cgd 	for (hw = sc_table; hw->hw_type; hw++)
   1158  1.1      cgd 		if (HW_ISDEV(hw, D_COMMDCM) && !badaddr((short *)hw->hw_kva))
   1159  1.1      cgd 			break;
   1160  1.1      cgd 	if (!HW_ISDEV(hw, D_COMMDCM)) {
   1161  1.1      cgd 		cp->cn_pri = CN_DEAD;
   1162  1.1      cgd 		return;
   1163  1.1      cgd 	}
   1164  1.1      cgd 	unit = CONUNIT;
   1165  1.1      cgd 	dcm_addr[BOARD(CONUNIT)] = (struct dcmdevice *)hw->hw_kva;
   1166  1.1      cgd 
   1167  1.1      cgd 	/* initialize required fields */
   1168  1.1      cgd 	cp->cn_dev = makedev(dcmmajor, unit);
   1169  1.1      cgd 	switch (dcm_addr[BOARD(unit)]->dcm_rsid) {
   1170  1.1      cgd 	case DCMID:
   1171  1.1      cgd 		cp->cn_pri = CN_NORMAL;
   1172  1.1      cgd 		break;
   1173  1.1      cgd 	case DCMID|DCMCON:
   1174  1.1      cgd 		cp->cn_pri = CN_REMOTE;
   1175  1.1      cgd 		break;
   1176  1.1      cgd 	default:
   1177  1.1      cgd 		cp->cn_pri = CN_DEAD;
   1178  1.1      cgd 		return;
   1179  1.1      cgd 	}
   1180  1.1      cgd 	/*
   1181  1.1      cgd 	 * If dcmconsole is initialized, raise our priority.
   1182  1.1      cgd 	 */
   1183  1.1      cgd 	if (dcmconsole == UNIT(unit))
   1184  1.1      cgd 		cp->cn_pri = CN_REMOTE;
   1185  1.1      cgd #ifdef KGDB_CHEAT
   1186  1.1      cgd 	/*
   1187  1.1      cgd 	 * This doesn't currently work, at least not with ite consoles;
   1188  1.1      cgd 	 * the console hasn't been initialized yet.
   1189  1.1      cgd 	 */
   1190  1.1      cgd 	if (major(kgdb_dev) == dcmmajor && BOARD(kgdb_dev) == BOARD(unit)) {
   1191  1.1      cgd 		(void) dcminit(kgdb_dev, kgdb_rate);
   1192  1.1      cgd 		if (kgdb_debug_init) {
   1193  1.1      cgd 			/*
   1194  1.1      cgd 			 * We assume that console is ready for us...
   1195  1.1      cgd 			 * this assumes that a dca or ite console
   1196  1.1      cgd 			 * has been selected already and will init
   1197  1.1      cgd 			 * on the first putc.
   1198  1.1      cgd 			 */
   1199  1.1      cgd 			printf("dcm%d: ", UNIT(kgdb_dev));
   1200  1.1      cgd 			kgdb_connect(1);
   1201  1.1      cgd 		}
   1202  1.1      cgd 	}
   1203  1.1      cgd #endif
   1204  1.1      cgd }
   1205  1.1      cgd 
   1206  1.1      cgd dcmcninit(cp)
   1207  1.1      cgd 	struct consdev *cp;
   1208  1.1      cgd {
   1209  1.1      cgd 	dcminit(cp->cn_dev, dcmdefaultrate);
   1210  1.1      cgd 	dcmconsinit = 1;
   1211  1.1      cgd 	dcmconsole = UNIT(cp->cn_dev);
   1212  1.1      cgd }
   1213  1.1      cgd 
   1214  1.1      cgd dcminit(dev, rate)
   1215  1.1      cgd 	dev_t dev;
   1216  1.1      cgd 	int rate;
   1217  1.1      cgd {
   1218  1.1      cgd 	register struct dcmdevice *dcm = dcm_addr[BOARD(dev)];
   1219  1.1      cgd 	int s, mode, port;
   1220  1.1      cgd 
   1221  1.1      cgd 	port = PORT(dev);
   1222  1.1      cgd 	mode = LC_8BITS | LC_1STOP;
   1223  1.1      cgd 	s = splhigh();
   1224  1.1      cgd 	/*
   1225  1.1      cgd 	 * Wait for transmitter buffer to empty.
   1226  1.1      cgd 	 */
   1227  1.1      cgd 	while (dcm->dcm_thead[port].ptr != dcm->dcm_ttail[port].ptr)
   1228  1.1      cgd 		DELAY(DCM_USPERCH(rate));
   1229  1.1      cgd 	/*
   1230  1.1      cgd 	 * Make changes known to hardware.
   1231  1.1      cgd 	 */
   1232  1.1      cgd 	dcm->dcm_data[port].dcm_baud = ttspeedtab(rate, dcmspeedtab);
   1233  1.1      cgd 	dcm->dcm_data[port].dcm_conf = mode;
   1234  1.1      cgd 	SEM_LOCK(dcm);
   1235  1.1      cgd 	dcm->dcm_cmdtab[port].dcm_data |= CT_CON;
   1236  1.1      cgd 	dcm->dcm_cr |= (1 << port);
   1237  1.1      cgd 	SEM_UNLOCK(dcm);
   1238  1.1      cgd 	/*
   1239  1.1      cgd 	 * Delay for config change to take place. Weighted by baud.
   1240  1.1      cgd 	 * XXX why do we do this?
   1241  1.1      cgd 	 */
   1242  1.1      cgd 	DELAY(16 * DCM_USPERCH(rate));
   1243  1.1      cgd 	splx(s);
   1244  1.1      cgd }
   1245  1.1      cgd 
   1246  1.1      cgd dcmcngetc(dev)
   1247  1.1      cgd 	dev_t dev;
   1248  1.1      cgd {
   1249  1.1      cgd 	register struct dcmdevice *dcm = dcm_addr[BOARD(dev)];
   1250  1.1      cgd 	register struct dcmrfifo *fifo;
   1251  1.1      cgd 	register struct dcmpreg *pp;
   1252  1.1      cgd 	register unsigned head;
   1253  1.1      cgd 	int s, c, stat, port;
   1254  1.1      cgd 
   1255  1.1      cgd 	port = PORT(dev);
   1256  1.1      cgd 	pp = dcm_preg(dcm, port);
   1257  1.1      cgd 	s = splhigh();
   1258  1.1      cgd 	head = pp->r_head & RX_MASK;
   1259  1.1      cgd 	fifo = &dcm->dcm_rfifos[3-port][head>>1];
   1260  1.1      cgd 	while (head == (pp->r_tail & RX_MASK))
   1261  1.1      cgd 		;
   1262  1.1      cgd 	/*
   1263  1.1      cgd 	 * If board interrupts are enabled, just let our received char
   1264  1.1      cgd 	 * interrupt through in case some other port on the board was
   1265  1.1      cgd 	 * busy.  Otherwise we must clear the interrupt.
   1266  1.1      cgd 	 */
   1267  1.1      cgd 	SEM_LOCK(dcm);
   1268  1.1      cgd 	if ((dcm->dcm_ic & IC_IE) == 0)
   1269  1.1      cgd 		stat = dcm->dcm_iir;
   1270  1.1      cgd 	SEM_UNLOCK(dcm);
   1271  1.1      cgd 	c = fifo->data_char;
   1272  1.1      cgd 	stat = fifo->data_stat;
   1273  1.1      cgd 	pp->r_head = (head + 2) & RX_MASK;
   1274  1.1      cgd 	splx(s);
   1275  1.1      cgd 	return (c);
   1276  1.1      cgd }
   1277  1.1      cgd 
   1278  1.1      cgd /*
   1279  1.1      cgd  * Console kernel output character routine.
   1280  1.1      cgd  */
   1281  1.1      cgd dcmcnputc(dev, c)
   1282  1.1      cgd 	dev_t dev;
   1283  1.1      cgd 	int c;
   1284  1.1      cgd {
   1285  1.1      cgd 	register struct dcmdevice *dcm = dcm_addr[BOARD(dev)];
   1286  1.1      cgd 	register struct dcmpreg *pp;
   1287  1.1      cgd 	unsigned tail;
   1288  1.1      cgd 	int s, port, stat;
   1289  1.1      cgd 
   1290  1.1      cgd 	port = PORT(dev);
   1291  1.1      cgd 	pp = dcm_preg(dcm, port);
   1292  1.1      cgd 	s = splhigh();
   1293  1.1      cgd #ifdef KGDB
   1294  1.1      cgd 	if (dev != kgdb_dev)
   1295  1.1      cgd #endif
   1296  1.1      cgd 	if (dcmconsinit == 0) {
   1297  1.1      cgd 		(void) dcminit(dev, dcmdefaultrate);
   1298  1.1      cgd 		dcmconsinit = 1;
   1299  1.1      cgd 	}
   1300  1.1      cgd 	tail = pp->t_tail & TX_MASK;
   1301  1.1      cgd 	while (tail != (pp->t_head & TX_MASK))
   1302  1.1      cgd 		;
   1303  1.1      cgd 	dcm->dcm_tfifos[3-port][tail].data_char = c;
   1304  1.1      cgd 	pp->t_tail = tail = (tail + 1) & TX_MASK;
   1305  1.1      cgd 	SEM_LOCK(dcm);
   1306  1.1      cgd 	dcm->dcm_cmdtab[port].dcm_data |= CT_TX;
   1307  1.1      cgd 	dcm->dcm_cr |= (1 << port);
   1308  1.1      cgd 	SEM_UNLOCK(dcm);
   1309  1.1      cgd 	while (tail != (pp->t_head & TX_MASK))
   1310  1.1      cgd 		;
   1311  1.1      cgd 	/*
   1312  1.1      cgd 	 * If board interrupts are enabled, just let our completion
   1313  1.1      cgd 	 * interrupt through in case some other port on the board
   1314  1.1      cgd 	 * was busy.  Otherwise we must clear the interrupt.
   1315  1.1      cgd 	 */
   1316  1.1      cgd 	if ((dcm->dcm_ic & IC_IE) == 0) {
   1317  1.1      cgd 		SEM_LOCK(dcm);
   1318  1.1      cgd 		stat = dcm->dcm_iir;
   1319  1.1      cgd 		SEM_UNLOCK(dcm);
   1320  1.1      cgd 	}
   1321  1.1      cgd 	splx(s);
   1322  1.1      cgd }
   1323  1.1      cgd #endif
   1324