⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dhu.c

📁 <B>Digital的Unix操作系统VAX 4.2源码</B>
💻 C
📖 第 1 页 / 共 4 页
字号:
#ifndef lintstatic char *sccsid = "@(#)dhu.c	4.2	(ULTRIX)	11/9/90";#endif lint/************************************************************************ *									* *			Copyright (c) 1985-1988 by			* *		Digital Equipment Corporation, Maynard, MA		* *			All rights reserved.				* *									* *   This software is furnished under a license and may be used and	* *   copied  only  in accordance with the terms of such license and	* *   with the  inclusion  of  the  above  copyright  notice.   This	* *   software  or  any	other copies thereof may not be provided or	* *   otherwise made available to any other person.  No title to and	* *   ownership of the software is hereby transferred.			* *									* *   This software is  derived	from  software	received  from	the	* *   University    of	California,   Berkeley,   and	from   Bell	* *   Laboratories.  Use, duplication, or disclosure is	subject  to	* *   restrictions  under  license  agreements  with  University  of	* *   California and with AT&T.						* *									* *   The information in this software is subject to change  without	* *   notice  and should not be construed as a commitment by Digital	* *   Equipment Corporation.						* *									* *   Digital assumes no responsibility for the use  or	reliability	* *   of its software on equipment which is not supplied by Digital.	* *									* ************************************************************************//* * dhu.c * * Modification history * * DH(QUV)11/CX(ABY)(8,16) terminal driver * *  4-Apr-84 - Larry Cohen * *	Sleep in close to ensure DTR stays down for at least one *	second - only if modem line.  Open delays until close *	finishes in this case. -001 * * 16-Jan-86 - Larry Cohen * *	Add full DEC standard 52 support. * * 10-Mar-86 - Tim Burke * *	Modified probe routine to wait for dhu self-test to complete. * * 18-Mar-86 - jaw * *	br/cvec changed to NOT use registers. * * 14-Apr-86 - jaw * *	Remove MAXNUBA references.....use NUBA only! * * 26-Apr-86 - ricky palmer * *	Added new DEVIOCGET ioctl request code. V2.0 * * 13-Jun-86 - jaw * *	Fix to uba reset and drivers. * * 11-Jul-86 - ricky palmer * *	Added adpt and nexus fields to DEVIOCGET code. * * 05-Aug-86 - Tim Burke * *	Modify dhurint to save present time in timestamp when *	carrier drops. * * 25-Aug-86 - Tim Burke * *	Fixes to Decstd52 modem control to close up line on false call, and *	insure that remaining processes are terminated. * * 26-Aug-86 - rsp (Ricky Palmer) * *	Cleaned up devioctl code to (1) zero out devget structure *	upon entry and (2) use strlen instead of fixed storage *	for bcopy's. * *  4-Dec-86 - Tim Burke *	 *	Bug fix to modem control.  In dhu_tty_drop routine, clear the stopped *	state to prevent modem lines from hanging on close.  Also removed a *	#define DHUDEBUG which shouldn't be here. * * 15-Dec-86 - Tim Burke * *	When a break occurs, (interpreted as a framing error) set the variable *	c to be the interrupt character.  There was a problem here due to the *	fact that sign extension is done which causes unwanted side affects. To *	solve this bug, the character is stripped to 8 bits. * *	Fix DEVIOGET to return propper modem status information. * *  9-Jan-87 - Tim Burke * *	Bug fix to TIOCMODEM to clear modem flags if signals are not up. * * 22-Jan-87 - Tim Burke * *	Bug fix in dhuclose to prevent lines from hanging after another line has *	closed.  The problem is a result of not setting the correct line number *	in the csr and masking interrupts. * * 28-Jan-87 - Tim Burke * *	Added the capability to ignore the "DSR" modem signal.  This is being *	done to allow modems that do not follow DEC Standard 52 to still  *	function as they would have prior to the addition of DECSTD52 code *	into the drivers.  If the driver is setup to ignore "DSR" then it will *	not be following DECSTD52.  To follow DECSTD52 set dhudsr to "1", to *	ignore "DSR" set dhudsr to be "0"; * * 23-Feb-87 - Tim Burke * *	Added full System V TERMIO functionality to terminal subsystem. * * * 10-Mar-87 - rsp (Ricky Palmer) * *	Added devioctl support for CX series of controllers. * *  1-Sept-87 - Tim Burke * *	Put a timer in dhustart to prevent possible system hang if the DMA *	start bit doesn't clear due to hardware failure. * *  2-Sept-87 - Tim Burke * *	Added support for hardware auto flow control on the outgoing side.  This *	will provide quick response to start/stop characters which will reduce *	buffer overflow on the receiving device. * *  7-Sep-87 - rsp * *      Added code in DEVIOCGET to "&" in LINEMASK with unit to *      correctly determine line number. * *  1-Dec-87 - Tim Burke * *	Added support for both System V termio(7) and POSIX termios(7).  These *	changes also include support for 8-bit canonical processing.  Changes *	involve: * *	- Default settings on first open depend on mode of open.  For termio *	  opens the defaults are "RAW" style, while non-termio opens default *	  to the traditional "cooked" style. *	- The driver now represents its terminal attributes and special  *	  characters in the POSIX termios data structure.  This contrasts the *	  original approach of storing attributes and special chars in the *	  t_flags, ltchars and tchars. *	- New termio ioctls: TCSANOW, TCSADRAIN, TCSADFLUSH, TCSETA, TESETAW, *	  TCSETAF.	 *	- Addition of LPASS8 to local mode word for 8-bit canonical support. * * 24-Mar-88 - Tim Burke * *	In attach routine, determine the number of lines on this board so that *	the installation process knows how many lines to create.  (8 or 16) * * 16-May-88 - Tim Burke * * 	Call param routine for setting of local mode word because it can  * 	affect bit size and parity. * * 5-Aug-88 - Tim Burke * *	Return the 2 character sequence 0377, 0377 upon receipt of a valid *	0377 character only when PARMRK is set under the termio line disc. * * 18-Aug-88 - Tim Burke * *	If PARMRK is set and a BREAK occurs, return '\0377','\0','\0'. * * 02-Sep-88 - Tim Burke * *	Return EINVAL instead of ENOTTY for POSIX programs on invalid ioctls. * * 25-Jan-89 - Randall Brown * *	Changed cd_drop to look at LNOHANG.  Changed close routine to look *	at HUPCL. * * 24-May-89 - Randall Brown * *	Added support to run on MIPSFAIR systems. * * 12-Jun-89 - dws * *	Added trusted support. * * 21-Jul-89 - Randall Brown * *	Moved default open and default close code to tty.c and call it *	using tty_def_open() and tty_def_close().  In the close routine, *	don't clear the baudrate so that subsequent opens will keep the *	present attributes.  This only applies to a Berkeley environment. * * 15-Aug-89 - Randall Brown * *	Changed all references of TCSADFLUSH to TCSAFLUSH  * * 31-Oct-89 - Randall Brown * *	Added the support to allow the device to determine if baudrate is  *	supported before it is set in the tty data structures. * */#include "dhu.h"#if NDHU > 0  || defined(BINARY)#include "../data/dhu_data.c"int dhudebug = 0;int dhucdtime = 2;char dhu_speeds[] = {	0, 0, 01, 02, 03, 04, 0, 05,	06, 07, 010, 012, 013, 015, 016, 0	};short dhu_valid_speeds = 0x7fbd; /* 0,1,1,1, 1,1,1,1, 1,0,1,1, 1,1,0,1 *//* * Definition of the driver for the auto-configuration program. */int	dhuprobe(), dhuattach(), dhurint(), dhuxint(), dhubaudrate();int	dhu_cd_drop(), dhu_dsr_check(), dhu_cd_down(), dhu_tty_drop();struct	timeval dhuzerotime = {0,0};u_short dhustd[] = { 0 };struct	uba_driver dhudriver =	{ dhuprobe, 0, dhuattach, 0, dhustd, "dhu", dhuinfo };/* * dhu_self_test is used to hold the self test codes until they are saved * in the attach routine. */int 	dhu_self_test[DHU_NUM_ERR_CODES];int	dhustart(), ttrstrt();#ifndef MODEM_CD#define MODEM_CD   0x01#define MODEM_DSR  0x02#define MODEM_CTS  0x04#define MODEM_DSR_START  0x08#endif#define LINEMASK 0x0f	/* mask of higher bits of csr to get a line # *//* * The clist space is mapped by the driver onto each UNIBUS. * The UBACVT macro converts a clist space address for unibus uban * into an i/o space address for the DMA routine. */#define UBACVT(x, uban) 	(cbase[uban] + ((x)-(char *)cfree))/*  * this macro needs to be defined in a header file */#ifdef mips#define	WBFLUSH()	wbflush()#else vax#define WBFLUSH()	;#endif vax/* * Routine for configuration to force a dhu to interrupt. * Set to transmit at 9600 baud, and cause a transmitter interrupt. *//*ARGSUSED*/dhuprobe(reg)	caddr_t reg;{	register struct dhudevice *dhuaddr = (struct dhudevice *)reg;	int totaldelay; 		/* Self-test timeout counter */	int i;#ifdef lint	if (ndhu11 == 0) ndhu11 = 1;	dhurint(0); dhuxint(0);#endif#ifdef DHUDEBUG	if(dhudebug)		printf("dhuprobe\n");#endif DHUDEBUG	/*	 * If a self test is not being done, start one up.  Wait for the	 * self-test (to a max of 4 sec.) to complete before interrupting.	 */	if ((dhuaddr->csr.low & DHU_MRESET) == 0) {	    dhuaddr->csr.low |= DHU_MRESET;	    WBFLUSH();	}	totaldelay = 0;	while ( (dhuaddr->csr.low & DHU_MRESET) && ( totaldelay <= 70) ){	    totaldelay++;	    DELAY(50000);	}	if (dhuaddr->csr.low & DHU_MRESET)	    printf("Warning: DHU device failed to exit self-test\n");	else if (dhuaddr->csr.high & DHU_DIAGFAIL)	    printf("Warning: DHU self-test failure\n");	else {	    for (i = 0; i < DHU_NUM_ERR_CODES; i++) {		dhu_self_test[i] = dhuaddr->run.rbuf;#ifdef DHUDEBUG		if (dhudebug) {		    printf("dhu_self_test[%d] = %x\n", i, dhu_self_test[i]);		}#endif DHUDEBUG		if (dhu_self_test[i] >= 0) { /* data valid bit not set */		    printf("Warning: DHU device failed to return all error codes\n");		}	    }	}	/*	 * Setup for DMA transfer.  This device does not do programmed I/O	 * because it would generate too many interrupts for the system to	 * handle (particularly on Qbus microvaxen with dhv devices).	 */	dhuaddr->csr.low = 0;  /* transmit on channel 0 */	WBFLUSH();	dhuaddr->csr.high |= DHU_XIE; /* enable transmit interrupts */	dhuaddr->tbuffad1 = 0;	dhuaddr->tbuffcnt = 0;	dhuaddr->lpr = dhu_speeds[B9600] << 12 | DHU_BITS7 | DHU_PENABLE;	dhuaddr->tbuffad2.high |= DHU_XEN;	dhuaddr->tbuffad2.low |= DHU_START;	WBFLUSH();	DELAY(100000);		/* wait 1/10'th of a sec for interrupt */	{ char temp = dhuaddr->csr.high; /* clear transmit action */ }	dhuaddr->csr.high = 0;	 /* disable transmit interrupts */	WBFLUSH();	if (cvec && cvec != 0x200) /* check to see if interrupt occurred */		cvec -= 4;	   /* point to first interrupt vector (recv)*/	return (sizeof (struct dhudevice));}/* * Routine called to attach a dhu. */dhuattach(ui)	struct uba_device *ui;{	register struct dhudevice *addr;	int i;#ifdef DHUDEBUG	if(dhudebug)		printf("dhuattach %x, %d\n", ui->ui_flags, ui->ui_unit);#endif DHUDEBUG	dhusoftCAR[ui->ui_unit] = ui->ui_flags;	dhudefaultCAR[ui->ui_unit] = ui->ui_flags;	/*	 * On a Q-bus system the device could be either 8 or 16 lines.	 * Presently if the board does not do modem control it must	 * be a 16 line board.	 */	if (ui->ui_hd->uba_type & (UBAUVI|UBAUVII)) {		addr = (struct dhudevice *)ui->ui_addr;		if (addr->fun.fs.stat & DHU_MDL) 			dhu_lines[ui->ui_unit] = 16;		else			dhu_lines[ui->ui_unit] = 8;	}	/*	 * For the unibus the 16 line dhu is the only game in town.	 */	else		dhu_lines[ui->ui_unit] = 16;		/*	 * Save the self test codes received in the probe routine in to	 * the softc structure.	 */	for (i = 0; i < DHU_NUM_ERR_CODES; i++) {	    dhu_softc[ui->ui_unit].sc_self_test[i] = dhu_self_test[i];	}}/* * Open a DHU11 line, mapping the clist onto the uba if this * is the first dhu on this uba.  Turn on this dhu if this is * the first use of it.  Also wait for carrier. *//*ARGSUSED*/dhuopen(dev, flag)	dev_t dev;{	register struct tty *tp;	register int unit, dhu;	register struct dhudevice *addr;	register struct uba_device *ui;	int s;	int inuse;  /*hold state of inuse bit while blocked waiting for carr*/	unit = minor(dev);	dhu = unit >> 4;	if (unit >= nNDHU*16 || (ui = dhuinfo[dhu])== 0 || ui->ui_alive == 0)		return (ENXIO);	tp = &dhu11[unit];	if (tp->t_state&TS_XCLUDE && u.u_uid!=0)		return (EBUSY);#ifdef DHUDEBUG	if (dhudebug)		mprintf("dhuopen:  line=%d, state=%x, pid=%d, flag=(x)%x\n", unit,			tp->t_state, u.u_procp->p_pid,flag);#endif	while (tp->t_state&TS_CLOSING) /* let DTR stay down for awhile */		sleep((caddr_t)&tp->t_rawq, TTIPRI);	addr = (struct dhudevice *)ui->ui_addr;	tp->t_addr = (caddr_t)addr;	tp->t_oproc = dhustart;	tp->t_baudrate = dhubaudrate;	tp->t_state |= TS_WOPEN;	/*	 * While setting up state for this uba and this dhu,	 * block uba resets which can clear the state.	 */	s = spltty();	while (tty_ubinfo[ui->ui_ubanum] == -1)		/* need this lock because uballoc can sleep */		sleep(&tty_ubinfo[ui->ui_ubanum], TTIPRI);	if (tty_ubinfo[ui->ui_ubanum] == 0) {		tty_ubinfo[ui->ui_ubanum] = -1;		tty_ubinfo[ui->ui_ubanum] =		    uballoc(ui->ui_ubanum, (caddr_t)cfree,			nclist*sizeof(struct cblock), 0);		wakeup(&tty_ubinfo[ui->ui_ubanum]);	}	if (ui->ui_hd->uba_type & UBAUVI)		cbase[ui->ui_ubanum] =		    tty_ubinfo[ui->ui_ubanum]&0x3fffff;	else		cbase[ui->ui_ubanum] =		    tty_ubinfo[ui->ui_ubanum]&0x3ffff;	splx(s);	if ((tp->t_state&TS_ISOPEN) == 0) {	    dhumodem[unit] = MODEM_DSR_START; /* prevents spurious startups */	}	tty_def_open(tp, dev, flag, (dhusoftCAR[dhu]&(1<<(unit&LINEMASK))));	dhuparam(unit);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -