Home | History | Annotate | Line # | Download | only in dev
zsvar.h revision 1.7
      1 /*	$NetBSD: zsvar.h,v 1.7 2003/08/07 16:27:02 agc Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1992, 1993
      5  *	The Regents of the University of California.  All rights reserved.
      6  *
      7  * This software was developed by the Computer Systems Engineering group
      8  * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
      9  * contributed to Berkeley.
     10  *
     11  * All advertising materials mentioning features or use of this software
     12  * must display the following acknowledgement:
     13  *	This product includes software developed by the University of
     14  *	California, Lawrence Berkeley Laboratory.
     15  *
     16  * Redistribution and use in source and binary forms, with or without
     17  * modification, are permitted provided that the following conditions
     18  * are met:
     19  * 1. Redistributions of source code must retain the above copyright
     20  *    notice, this list of conditions and the following disclaimer.
     21  * 2. Redistributions in binary form must reproduce the above copyright
     22  *    notice, this list of conditions and the following disclaimer in the
     23  *    documentation and/or other materials provided with the distribution.
     24  * 3. Neither the name of the University nor the names of its contributors
     25  *    may be used to endorse or promote products derived from this software
     26  *    without specific prior written permission.
     27  *
     28  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     29  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     30  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     31  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     32  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     33  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     34  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     35  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     36  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     37  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     38  * SUCH DAMAGE.
     39  *
     40  *	@(#)zsvar.h	8.1 (Berkeley) 6/11/93
     41  */
     42 
     43 /*
     44  * Copyright (c) 1995 Leo Weppelman (Atari modifications)
     45  *
     46  * This software was developed by the Computer Systems Engineering group
     47  * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
     48  * contributed to Berkeley.
     49  *
     50  * All advertising materials mentioning features or use of this software
     51  * must display the following acknowledgement:
     52  *	This product includes software developed by the University of
     53  *	California, Lawrence Berkeley Laboratory.
     54  *
     55  * Redistribution and use in source and binary forms, with or without
     56  * modification, are permitted provided that the following conditions
     57  * are met:
     58  * 1. Redistributions of source code must retain the above copyright
     59  *    notice, this list of conditions and the following disclaimer.
     60  * 2. Redistributions in binary form must reproduce the above copyright
     61  *    notice, this list of conditions and the following disclaimer in the
     62  *    documentation and/or other materials provided with the distribution.
     63  * 3. All advertising materials mentioning features or use of this software
     64  *    must display the following acknowledgement:
     65  *	This product includes software developed by the University of
     66  *	California, Berkeley and its contributors.
     67  * 4. Neither the name of the University nor the names of its contributors
     68  *    may be used to endorse or promote products derived from this software
     69  *    without specific prior written permission.
     70  *
     71  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     72  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     73  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     74  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     75  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     76  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     77  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     78  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     79  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     80  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     81  * SUCH DAMAGE.
     82  *
     83  *	@(#)zsvar.h	8.1 (Berkeley) 6/11/93
     84  */
     85 
     86 /*
     87  * Register layout is machine-dependent...
     88  */
     89 
     90 struct zschan {
     91 	u_char		zc_xxx0;
     92 	volatile u_char	zc_csr;		/* ctrl,status, and indirect access */
     93 	u_char		zc_xxx1;
     94 	volatile u_char	zc_data;	/* data */
     95 };
     96 
     97 struct zsdevice {
     98 	struct	zschan zs_chan[2];
     99 };
    100 
    101 /*
    102  * Software state, per zs channel.
    103  *
    104  * The zs chip has insufficient buffering, so we provide a software
    105  * buffer using a two-level interrupt scheme.  The hardware (high priority)
    106  * interrupt simply grabs the `cause' of the interrupt and stuffs it into
    107  * a ring buffer.  It then schedules a software interrupt; the latter
    108  * empties the ring as fast as it can, hoping to avoid overflow.
    109  *
    110  * Interrupts can happen because of:
    111  *	- received data;
    112  *	- transmit pseudo-DMA done; and
    113  *	- status change.
    114  * These are all stored together in the (single) ring.  The size of the
    115  * ring is a power of two, to make % operations fast.  Since we need two
    116  * bits to distinguish the interrupt type, and up to 16 for the received
    117  * data plus RR1 status, we use 32 bits per ring entry.
    118  *
    119  * When the value is a character + RR1 status, the character is in the
    120  * upper 8 bits of the RR1 status.
    121  */
    122 #define ZLRB_RING_SIZE		4096		/* ZS line ring buffer size */
    123 #define	ZLRB_RING_MASK		4095		/* mask for same */
    124 
    125 /* 0 is reserved (means "no interrupt") */
    126 #define	ZRING_RINT		1		/* receive data interrupt */
    127 #define	ZRING_XINT		2		/* transmit done interrupt */
    128 #define	ZRING_SINT		3		/* status change interrupt */
    129 
    130 #define	ZRING_TYPE(x)		((x) & 3)
    131 #define	ZRING_VALUE(x)		((x) >> 8)
    132 #define	ZRING_MAKE(t, v)	((t) | (v) << 8)
    133 
    134 struct zs_chanstate {
    135 	struct	zs_chanstate	*cs_next;	/* linked list for zshard() */
    136 	volatile struct zschan	*cs_zc;		/* points to hardware regs */
    137 	int			cs_unit;	/* unit number */
    138 	struct	tty		*cs_ttyp;	/* ### */
    139 
    140 	/*
    141 	 * We must keep a copy of the write registers as they are
    142 	 * mostly write-only and we sometimes need to set and clear
    143 	 * individual bits (e.g., in WR3).  Not all of these are
    144 	 * needed but 16 bytes is cheap and this makes the addressing
    145 	 * simpler.  Unfortunately, we can only write to some registers
    146 	 * when the chip is not actually transmitting, so whenever
    147 	 * we are expecting a `transmit done' interrupt the preg array
    148 	 * is allowed to `get ahead' of the current values.  In a
    149 	 * few places we must change the current value of a register,
    150 	 * rather than (or in addition to) the pending value; for these
    151 	 * cs_creg[] contains the current value.
    152 	 */
    153 	u_char	cs_creg[16];		/* current values */
    154 	u_char	cs_preg[16];		/* pending values */
    155 	u_char	cs_heldchange;		/* change pending (creg != preg) */
    156 	u_char	cs_rr0;			/* last rr0 processed */
    157 
    158 	/* pure software data, per channel */
    159 	char	cs_softcar;		/* software carrier */
    160 	char	cs_xxx;			/* (spare) */
    161 
    162 	/*
    163 	 * The transmit byte count and address are used for pseudo-DMA
    164 	 * output in the hardware interrupt code.  PDMA can be suspended
    165 	 * to get pending changes done; heldtbc is used for this.  It can
    166 	 * also be stopped for ^S; this sets TS_TTSTOP in tp->t_state.
    167 	 */
    168 	int	cs_tbc;			/* transmit byte count */
    169 	caddr_t	cs_tba;			/* transmit buffer address */
    170 	int	cs_heldtbc;		/* held tbc while xmission stopped */
    171 
    172 	/*
    173 	 * Printing an overrun error message often takes long enough to
    174 	 * cause another overrun, so we only print one per second.
    175 	 */
    176 	long	cs_rotime;		/* time of last ring overrun */
    177 	long	cs_fotime;		/* time of last fifo overrun */
    178 
    179 	/*
    180 	 * The ring buffer.
    181 	 */
    182 	u_int		cs_rbget;	/* ring buffer `get' index	*/
    183 	volatile u_int	cs_rbput;	/* ring buffer `put' index	*/
    184 	int		*cs_rbuf;	/* type, value pairs	*/
    185 };
    186 
    187 #define	ZS_CHAN_A	0
    188 #define	ZS_CHAN_B	1
    189 
    190 /*
    191  * Macros to read and write individual registers (except 0) in a channel.
    192  */
    193 #define	ZS_READ(c, r)		((c)->zc_csr = (r), (c)->zc_csr)
    194 #define	ZS_WRITE(c, r, v)	((c)->zc_csr = (r), (c)->zc_csr = (v))
    195 
    196 /*
    197  * Split minor into unit, dialin/dialout & flag nibble.
    198  */
    199 #define	ZS_UNIT(dev)		((minor(dev) >> 4) & 0xf)
    200 #define	ZS_FLAGS(dev)		(minor(dev) & 0xf)
    201 #define	ZS_DIALOUT(dev)		(minor(dev) & 0x80000)
    202