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