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