xref: /csrg-svn/sys/sparc/dev/zsvar.h (revision 63318)
155108Storek /*
2*63318Sbostic  * Copyright (c) 1992, 1993
3*63318Sbostic  *	The Regents of the University of California.  All rights reserved.
455108Storek  *
555108Storek  * This software was developed by the Computer Systems Engineering group
655108Storek  * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
755108Storek  * contributed to Berkeley.
855108Storek  *
955499Sbostic  * All advertising materials mentioning features or use of this software
1055499Sbostic  * must display the following acknowledgement:
1155499Sbostic  *	This product includes software developed by the University of
1259193Storek  *	California, Lawrence Berkeley Laboratory.
1355499Sbostic  *
1455108Storek  * %sccs.include.redist.c%
1555108Storek  *
16*63318Sbostic  *	@(#)zsvar.h	8.1 (Berkeley) 06/11/93
1755108Storek  *
1859193Storek  * from: $Header: zsvar.h,v 1.7 92/11/26 01:28:04 torek Exp $ (LBL)
1955108Storek  */
2055108Storek 
2155108Storek /*
2255108Storek  * Software state, per zs channel.
2355108Storek  *
2459193Storek  * The zs chip has insufficient buffering, so we provide a software
2559193Storek  * buffer using a two-level interrupt scheme.  The hardware (high priority)
2659193Storek  * interrupt simply grabs the `cause' of the interrupt and stuffs it into
2759193Storek  * a ring buffer.  It then schedules a software interrupt; the latter
2859193Storek  * empties the ring as fast as it can, hoping to avoid overflow.
2959193Storek  *
3059193Storek  * Interrupts can happen because of:
3159193Storek  *	- received data;
3259193Storek  *	- transmit pseudo-DMA done; and
3359193Storek  *	- status change.
3459193Storek  * These are all stored together in the (single) ring.  The size of the
3559193Storek  * ring is a power of two, to make % operations fast.  Since we need two
3659193Storek  * bits to distinguish the interrupt type, and up to 16 for the received
3759193Storek  * data plus RR1 status, we use 32 bits per ring entry.
3859193Storek  *
3959193Storek  * When the value is a character + RR1 status, the character is in the
4059193Storek  * upper 8 bits of the RR1 status.
4155108Storek  */
4259193Storek #define ZLRB_RING_SIZE 256		/* ZS line ring buffer size */
4359193Storek #define	ZLRB_RING_MASK 255		/* mask for same */
4455108Storek 
4559193Storek /* 0 is reserved (means "no interrupt") */
4659193Storek #define	ZRING_RINT	1		/* receive data interrupt */
4759193Storek #define	ZRING_XINT	2		/* transmit done interrupt */
4859193Storek #define	ZRING_SINT	3		/* status change interrupt */
4959193Storek 
5059193Storek #define	ZRING_TYPE(x)	((x) & 3)
5159193Storek #define	ZRING_VALUE(x)	((x) >> 8)
5259193Storek #define	ZRING_MAKE(t, v)	((t) | (v) << 8)
5359193Storek 
5455108Storek struct zs_chanstate {
5555108Storek 	struct	zs_chanstate *cs_next;	/* linked list for zshard() */
5655108Storek 	volatile struct zschan *cs_zc;	/* points to hardware regs */
5755108Storek 	int	cs_unit;		/* unit number */
5855108Storek 	struct	tty *cs_ttyp;		/* ### */
5955108Storek 
6055108Storek 	/*
6155108Storek 	 * We must keep a copy of the write registers as they are
6255108Storek 	 * mostly write-only and we sometimes need to set and clear
6355108Storek 	 * individual bits (e.g., in WR3).  Not all of these are
6455108Storek 	 * needed but 16 bytes is cheap and this makes the addressing
6555108Storek 	 * simpler.  Unfortunately, we can only write to some registers
6655108Storek 	 * when the chip is not actually transmitting, so whenever
6759193Storek 	 * we are expecting a `transmit done' interrupt the preg array
6855108Storek 	 * is allowed to `get ahead' of the current values.  In a
6955108Storek 	 * few places we must change the current value of a register,
7055108Storek 	 * rather than (or in addition to) the pending value; for these
7155108Storek 	 * cs_creg[] contains the current value.
7255108Storek 	 */
7355108Storek 	u_char	cs_creg[16];		/* current values */
7455108Storek 	u_char	cs_preg[16];		/* pending values */
7555108Storek 	u_char	cs_heldchange;		/* change pending (creg != preg) */
7659193Storek 	u_char	cs_rr0;			/* last rr0 processed */
7755108Storek 
7859193Storek 	/* pure software data, per channel */
7959193Storek 	char	cs_softcar;		/* software carrier */
8059193Storek 	char	cs_conk;		/* is console keyboard, decode L1-A */
8159193Storek 	char	cs_brkabort;		/* abort (as if via L1-A) on BREAK */
8259193Storek 	char	cs_kgdb;		/* enter debugger on frame char */
8359193Storek 	char	cs_consio;		/* port does /dev/console I/O */
8459193Storek 	char	cs_xxx;			/* (spare) */
8559193Storek 	int	cs_speed;		/* default baud rate (from ROM) */
8659193Storek 
8755108Storek 	/*
8855108Storek 	 * The transmit byte count and address are used for pseudo-DMA
8955108Storek 	 * output in the hardware interrupt code.  PDMA can be suspended
9055108Storek 	 * to get pending changes done; heldtbc is used for this.  It can
9155108Storek 	 * also be stopped for ^S; this sets TS_TTSTOP in tp->t_state.
9255108Storek 	 */
9355108Storek 	int	cs_tbc;			/* transmit byte count */
9455108Storek 	caddr_t	cs_tba;			/* transmit buffer address */
9555108Storek 	int	cs_heldtbc;		/* held tbc while xmission stopped */
9655108Storek 
9755108Storek 	/*
9855108Storek 	 * Printing an overrun error message often takes long enough to
9955108Storek 	 * cause another overrun, so we only print one per second.
10055108Storek 	 */
10155108Storek 	long	cs_rotime;		/* time of last ring overrun */
10255108Storek 	long	cs_fotime;		/* time of last fifo overrun */
10355108Storek 
10455108Storek 	/*
10559193Storek 	 * The ring buffer.
10655108Storek 	 */
10759193Storek 	u_int	cs_rbget;		/* ring buffer `get' index */
10859193Storek 	volatile u_int cs_rbput;	/* ring buffer `put' index */
10959193Storek 	int	cs_rbuf[ZLRB_RING_SIZE];/* type, value pairs */
11055108Storek };
11155108Storek 
11255108Storek /*
11355108Storek  * Macros to read and write individual registers (except 0) in a channel.
11455108Storek  *
11555108Storek  * On the SparcStation the 1.6 microsecond recovery time is
11655108Storek  * handled in hardware.
11755108Storek  */
11855108Storek #define	ZS_READ(c, r)		((c)->zc_csr = (r), (c)->zc_csr)
11955108Storek #define	ZS_WRITE(c, r, v)	((c)->zc_csr = (r), (c)->zc_csr = (v))
120