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