com.c revision 1.113.2.2 1 1.113.2.2 thorpej /* $NetBSD: com.c,v 1.113.2.2 1997/10/16 00:04:07 thorpej Exp $ */
2 1.113.2.2 thorpej
3 1.113.2.2 thorpej /*-
4 1.113.2.2 thorpej * Copyright (c) 1993, 1994, 1995, 1996, 1997
5 1.113.2.2 thorpej * Charles M. Hannum. All rights reserved.
6 1.113.2.2 thorpej *
7 1.113.2.2 thorpej * Interrupt processing and hardware flow control partly based on code from
8 1.113.2.2 thorpej * Onno van der Linden and Gordon Ross.
9 1.113.2.2 thorpej *
10 1.113.2.2 thorpej * Redistribution and use in source and binary forms, with or without
11 1.113.2.2 thorpej * modification, are permitted provided that the following conditions
12 1.113.2.2 thorpej * are met:
13 1.113.2.2 thorpej * 1. Redistributions of source code must retain the above copyright
14 1.113.2.2 thorpej * notice, this list of conditions and the following disclaimer.
15 1.113.2.2 thorpej * 2. Redistributions in binary form must reproduce the above copyright
16 1.113.2.2 thorpej * notice, this list of conditions and the following disclaimer in the
17 1.113.2.2 thorpej * documentation and/or other materials provided with the distribution.
18 1.113.2.2 thorpej * 3. All advertising materials mentioning features or use of this software
19 1.113.2.2 thorpej * must display the following acknowledgement:
20 1.113.2.2 thorpej * This product includes software developed by Charles M. Hannum.
21 1.113.2.2 thorpej * 4. The name of the author may not be used to endorse or promote products
22 1.113.2.2 thorpej * derived from this software without specific prior written permission.
23 1.113.2.2 thorpej *
24 1.113.2.2 thorpej * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
25 1.113.2.2 thorpej * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
26 1.113.2.2 thorpej * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
27 1.113.2.2 thorpej * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
28 1.113.2.2 thorpej * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
29 1.113.2.2 thorpej * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30 1.113.2.2 thorpej * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31 1.113.2.2 thorpej * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32 1.113.2.2 thorpej * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
33 1.113.2.2 thorpej * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 1.113.2.2 thorpej */
35 1.113.2.2 thorpej
36 1.113.2.2 thorpej /*
37 1.113.2.2 thorpej * Copyright (c) 1991 The Regents of the University of California.
38 1.113.2.2 thorpej * All rights reserved.
39 1.113.2.2 thorpej *
40 1.113.2.2 thorpej * Redistribution and use in source and binary forms, with or without
41 1.113.2.2 thorpej * modification, are permitted provided that the following conditions
42 1.113.2.2 thorpej * are met:
43 1.113.2.2 thorpej * 1. Redistributions of source code must retain the above copyright
44 1.113.2.2 thorpej * notice, this list of conditions and the following disclaimer.
45 1.113.2.2 thorpej * 2. Redistributions in binary form must reproduce the above copyright
46 1.113.2.2 thorpej * notice, this list of conditions and the following disclaimer in the
47 1.113.2.2 thorpej * documentation and/or other materials provided with the distribution.
48 1.113.2.2 thorpej * 3. All advertising materials mentioning features or use of this software
49 1.113.2.2 thorpej * must display the following acknowledgement:
50 1.113.2.2 thorpej * This product includes software developed by the University of
51 1.113.2.2 thorpej * California, Berkeley and its contributors.
52 1.113.2.2 thorpej * 4. Neither the name of the University nor the names of its contributors
53 1.113.2.2 thorpej * may be used to endorse or promote products derived from this software
54 1.113.2.2 thorpej * without specific prior written permission.
55 1.113.2.2 thorpej *
56 1.113.2.2 thorpej * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
57 1.113.2.2 thorpej * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
58 1.113.2.2 thorpej * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
59 1.113.2.2 thorpej * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
60 1.113.2.2 thorpej * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
61 1.113.2.2 thorpej * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
62 1.113.2.2 thorpej * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
63 1.113.2.2 thorpej * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
64 1.113.2.2 thorpej * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
65 1.113.2.2 thorpej * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
66 1.113.2.2 thorpej * SUCH DAMAGE.
67 1.113.2.2 thorpej *
68 1.113.2.2 thorpej * @(#)com.c 7.5 (Berkeley) 5/16/91
69 1.113.2.2 thorpej */
70 1.113.2.2 thorpej
71 1.113.2.2 thorpej /*
72 1.113.2.2 thorpej * COM driver, uses National Semiconductor NS16450/NS16550AF UART
73 1.113.2.2 thorpej */
74 1.113.2.2 thorpej #include <sys/param.h>
75 1.113.2.2 thorpej #include <sys/systm.h>
76 1.113.2.2 thorpej #include <sys/ioctl.h>
77 1.113.2.2 thorpej #include <sys/select.h>
78 1.113.2.2 thorpej #include <sys/tty.h>
79 1.113.2.2 thorpej #include <sys/proc.h>
80 1.113.2.2 thorpej #include <sys/user.h>
81 1.113.2.2 thorpej #include <sys/conf.h>
82 1.113.2.2 thorpej #include <sys/file.h>
83 1.113.2.2 thorpej #include <sys/uio.h>
84 1.113.2.2 thorpej #include <sys/kernel.h>
85 1.113.2.2 thorpej #include <sys/syslog.h>
86 1.113.2.2 thorpej #include <sys/types.h>
87 1.113.2.2 thorpej #include <sys/device.h>
88 1.113.2.2 thorpej
89 1.113.2.2 thorpej #include <machine/intr.h>
90 1.113.2.2 thorpej #include <machine/bus.h>
91 1.113.2.2 thorpej
92 1.113.2.2 thorpej #include <dev/ic/comreg.h>
93 1.113.2.2 thorpej #include <dev/ic/comvar.h>
94 1.113.2.2 thorpej #include <dev/ic/ns16550reg.h>
95 1.113.2.2 thorpej #ifdef COM_HAYESP
96 1.113.2.2 thorpej #include <dev/ic/hayespreg.h>
97 1.113.2.2 thorpej #endif
98 1.113.2.2 thorpej #define com_lcr com_cfcr
99 1.113.2.2 thorpej #include <dev/cons.h>
100 1.113.2.2 thorpej
101 1.113.2.2 thorpej #include "com.h"
102 1.113.2.2 thorpej
103 1.113.2.2 thorpej #ifdef COM_HAYESP
104 1.113.2.2 thorpej int comprobeHAYESP __P((bus_space_handle_t hayespioh, struct com_softc *sc));
105 1.113.2.2 thorpej #endif
106 1.113.2.2 thorpej
107 1.113.2.2 thorpej #if defined(DDB) || defined(KGDB)
108 1.113.2.2 thorpej static void com_enable_debugport __P((struct com_softc *));
109 1.113.2.2 thorpej #endif
110 1.113.2.2 thorpej void com_attach_subr __P((struct com_softc *sc));
111 1.113.2.2 thorpej void comdiag __P((void *));
112 1.113.2.2 thorpej int comspeed __P((long, long));
113 1.113.2.2 thorpej static u_char cflag2lcr __P((tcflag_t));
114 1.113.2.2 thorpej int comparam __P((struct tty *, struct termios *));
115 1.113.2.2 thorpej void comstart __P((struct tty *));
116 1.113.2.2 thorpej void comstop __P((struct tty *, int));
117 1.113.2.2 thorpej #ifdef __GENERIC_SOFT_INTERRUPTS
118 1.113.2.2 thorpej void comsoft __P((void *));
119 1.113.2.2 thorpej #else
120 1.113.2.2 thorpej #ifndef alpha
121 1.113.2.2 thorpej void comsoft __P((void));
122 1.113.2.2 thorpej #else
123 1.113.2.2 thorpej void comsoft __P((void *));
124 1.113.2.2 thorpej #endif
125 1.113.2.2 thorpej #endif
126 1.113.2.2 thorpej int comhwiflow __P((struct tty *, int));
127 1.113.2.2 thorpej
128 1.113.2.2 thorpej void com_loadchannelregs __P((struct com_softc *));
129 1.113.2.2 thorpej void com_hwiflow __P((struct com_softc *));
130 1.113.2.2 thorpej void com_break __P((struct com_softc *, int));
131 1.113.2.2 thorpej void com_modem __P((struct com_softc *, int));
132 1.113.2.2 thorpej void com_iflush __P((struct com_softc *));
133 1.113.2.2 thorpej
134 1.113.2.2 thorpej int com_common_getc __P((bus_space_tag_t, bus_space_handle_t));
135 1.113.2.2 thorpej void com_common_putc __P((bus_space_tag_t, bus_space_handle_t, int));
136 1.113.2.2 thorpej
137 1.113.2.2 thorpej /* XXX: These belong elsewhere */
138 1.113.2.2 thorpej cdev_decl(com);
139 1.113.2.2 thorpej bdev_decl(com);
140 1.113.2.2 thorpej
141 1.113.2.2 thorpej int comcngetc __P((dev_t));
142 1.113.2.2 thorpej void comcnputc __P((dev_t, int));
143 1.113.2.2 thorpej void comcnpollc __P((dev_t, int));
144 1.113.2.2 thorpej
145 1.113.2.2 thorpej #define integrate static inline
146 1.113.2.2 thorpej integrate void comrxint __P((struct com_softc *, struct tty *));
147 1.113.2.2 thorpej integrate void comtxint __P((struct com_softc *, struct tty *));
148 1.113.2.2 thorpej integrate void commsrint __P((struct com_softc *, struct tty *));
149 1.113.2.2 thorpej integrate void com_schedrx __P((struct com_softc *));
150 1.113.2.2 thorpej
151 1.113.2.2 thorpej struct cfdriver com_cd = {
152 1.113.2.2 thorpej NULL, "com", DV_TTY
153 1.113.2.2 thorpej };
154 1.113.2.2 thorpej
155 1.113.2.2 thorpej static int comconsaddr;
156 1.113.2.2 thorpej static bus_space_tag_t comconstag;
157 1.113.2.2 thorpej static bus_space_handle_t comconsioh;
158 1.113.2.2 thorpej static int comconsattached;
159 1.113.2.2 thorpej static int comconsrate;
160 1.113.2.2 thorpej static tcflag_t comconscflag;
161 1.113.2.2 thorpej
162 1.113.2.2 thorpej static u_char tiocm_xxx2mcr __P((int));
163 1.113.2.2 thorpej
164 1.113.2.2 thorpej #ifndef __GENERIC_SOFT_INTERRUPTS
165 1.113.2.2 thorpej #ifdef alpha
166 1.113.2.2 thorpej volatile int com_softintr_scheduled;
167 1.113.2.2 thorpej #endif
168 1.113.2.2 thorpej #endif
169 1.113.2.2 thorpej
170 1.113.2.2 thorpej #ifdef KGDB
171 1.113.2.2 thorpej #include <sys/kgdb.h>
172 1.113.2.2 thorpej
173 1.113.2.2 thorpej static int com_kgdb_addr;
174 1.113.2.2 thorpej static bus_space_tag_t com_kgdb_iot;
175 1.113.2.2 thorpej static bus_space_handle_t com_kgdb_ioh;
176 1.113.2.2 thorpej static int com_kgdb_attached;
177 1.113.2.2 thorpej
178 1.113.2.2 thorpej int com_kgdb_getc __P((void *));
179 1.113.2.2 thorpej void com_kgdb_putc __P((void *, int));
180 1.113.2.2 thorpej #endif /* KGDB */
181 1.113.2.2 thorpej
182 1.113.2.2 thorpej #define COMUNIT(x) (minor(x))
183 1.113.2.2 thorpej
184 1.113.2.2 thorpej int
185 1.113.2.2 thorpej comspeed(speed, frequency)
186 1.113.2.2 thorpej long speed, frequency;
187 1.113.2.2 thorpej {
188 1.113.2.2 thorpej #define divrnd(n, q) (((n)*2/(q)+1)/2) /* divide and round off */
189 1.113.2.2 thorpej
190 1.113.2.2 thorpej int x, err;
191 1.113.2.2 thorpej
192 1.113.2.2 thorpej #if 0
193 1.113.2.2 thorpej if (speed == 0)
194 1.113.2.2 thorpej return (0);
195 1.113.2.2 thorpej #endif
196 1.113.2.2 thorpej if (speed <= 0)
197 1.113.2.2 thorpej return (-1);
198 1.113.2.2 thorpej x = divrnd(frequency / 16, speed);
199 1.113.2.2 thorpej if (x <= 0)
200 1.113.2.2 thorpej return (-1);
201 1.113.2.2 thorpej err = divrnd(frequency * 1000 / 16, speed * x) - 1000;
202 1.113.2.2 thorpej if (err < 0)
203 1.113.2.2 thorpej err = -err;
204 1.113.2.2 thorpej if (err > COM_TOLERANCE)
205 1.113.2.2 thorpej return (-1);
206 1.113.2.2 thorpej return (x);
207 1.113.2.2 thorpej
208 1.113.2.2 thorpej #undef divrnd(n, q)
209 1.113.2.2 thorpej }
210 1.113.2.2 thorpej
211 1.113.2.2 thorpej #ifdef COM_DEBUG
212 1.113.2.2 thorpej int com_debug = 0;
213 1.113.2.2 thorpej
214 1.113.2.2 thorpej void comstatus __P((struct com_softc *, char *));
215 1.113.2.2 thorpej void
216 1.113.2.2 thorpej comstatus(sc, str)
217 1.113.2.2 thorpej struct com_softc *sc;
218 1.113.2.2 thorpej char *str;
219 1.113.2.2 thorpej {
220 1.113.2.2 thorpej struct tty *tp = sc->sc_tty;
221 1.113.2.2 thorpej
222 1.113.2.2 thorpej printf("%s: %s %sclocal %sdcd %sts_carr_on %sdtr %stx_stopped\n",
223 1.113.2.2 thorpej sc->sc_dev.dv_xname, str,
224 1.113.2.2 thorpej ISSET(tp->t_cflag, CLOCAL) ? "+" : "-",
225 1.113.2.2 thorpej ISSET(sc->sc_msr, MSR_DCD) ? "+" : "-",
226 1.113.2.2 thorpej ISSET(tp->t_state, TS_CARR_ON) ? "+" : "-",
227 1.113.2.2 thorpej ISSET(sc->sc_mcr, MCR_DTR) ? "+" : "-",
228 1.113.2.2 thorpej sc->sc_tx_stopped ? "+" : "-");
229 1.113.2.2 thorpej
230 1.113.2.2 thorpej printf("%s: %s %scrtscts %scts %sts_ttstop %srts %xrx_flags\n",
231 1.113.2.2 thorpej sc->sc_dev.dv_xname, str,
232 1.113.2.2 thorpej ISSET(tp->t_cflag, CRTSCTS) ? "+" : "-",
233 1.113.2.2 thorpej ISSET(sc->sc_msr, MSR_CTS) ? "+" : "-",
234 1.113.2.2 thorpej ISSET(tp->t_state, TS_TTSTOP) ? "+" : "-",
235 1.113.2.2 thorpej ISSET(sc->sc_mcr, MCR_RTS) ? "+" : "-",
236 1.113.2.2 thorpej sc->sc_rx_flags);
237 1.113.2.2 thorpej }
238 1.113.2.2 thorpej #endif
239 1.113.2.2 thorpej
240 1.113.2.2 thorpej int
241 1.113.2.2 thorpej comprobe1(iot, ioh, iobase)
242 1.113.2.2 thorpej bus_space_tag_t iot;
243 1.113.2.2 thorpej bus_space_handle_t ioh;
244 1.113.2.2 thorpej int iobase;
245 1.113.2.2 thorpej {
246 1.113.2.2 thorpej
247 1.113.2.2 thorpej /* force access to id reg */
248 1.113.2.2 thorpej bus_space_write_1(iot, ioh, com_lcr, 0);
249 1.113.2.2 thorpej bus_space_write_1(iot, ioh, com_iir, 0);
250 1.113.2.2 thorpej if (bus_space_read_1(iot, ioh, com_iir) & 0x38)
251 1.113.2.2 thorpej return (0);
252 1.113.2.2 thorpej
253 1.113.2.2 thorpej return (1);
254 1.113.2.2 thorpej }
255 1.113.2.2 thorpej
256 1.113.2.2 thorpej #ifdef COM_HAYESP
257 1.113.2.2 thorpej int
258 1.113.2.2 thorpej comprobeHAYESP(hayespioh, sc)
259 1.113.2.2 thorpej bus_space_handle_t hayespioh;
260 1.113.2.2 thorpej struct com_softc *sc;
261 1.113.2.2 thorpej {
262 1.113.2.2 thorpej char val, dips;
263 1.113.2.2 thorpej int combaselist[] = { 0x3f8, 0x2f8, 0x3e8, 0x2e8 };
264 1.113.2.2 thorpej bus_space_tag_t iot = sc->sc_iot;
265 1.113.2.2 thorpej
266 1.113.2.2 thorpej /*
267 1.113.2.2 thorpej * Hayes ESP cards have two iobases. One is for compatibility with
268 1.113.2.2 thorpej * 16550 serial chips, and at the same ISA PC base addresses. The
269 1.113.2.2 thorpej * other is for ESP-specific enhanced features, and lies at a
270 1.113.2.2 thorpej * different addressing range entirely (0x140, 0x180, 0x280, or 0x300).
271 1.113.2.2 thorpej */
272 1.113.2.2 thorpej
273 1.113.2.2 thorpej /* Test for ESP signature */
274 1.113.2.2 thorpej if ((bus_space_read_1(iot, hayespioh, 0) & 0xf3) == 0)
275 1.113.2.2 thorpej return (0);
276 1.113.2.2 thorpej
277 1.113.2.2 thorpej /*
278 1.113.2.2 thorpej * ESP is present at ESP enhanced base address; unknown com port
279 1.113.2.2 thorpej */
280 1.113.2.2 thorpej
281 1.113.2.2 thorpej /* Get the dip-switch configurations */
282 1.113.2.2 thorpej bus_space_write_1(iot, hayespioh, HAYESP_CMD1, HAYESP_GETDIPS);
283 1.113.2.2 thorpej dips = bus_space_read_1(iot, hayespioh, HAYESP_STATUS1);
284 1.113.2.2 thorpej
285 1.113.2.2 thorpej /* Determine which com port this ESP card services: bits 0,1 of */
286 1.113.2.2 thorpej /* dips is the port # (0-3); combaselist[val] is the com_iobase */
287 1.113.2.2 thorpej if (sc->sc_iobase != combaselist[dips & 0x03])
288 1.113.2.2 thorpej return (0);
289 1.113.2.2 thorpej
290 1.113.2.2 thorpej printf(": ESP");
291 1.113.2.2 thorpej
292 1.113.2.2 thorpej /* Check ESP Self Test bits. */
293 1.113.2.2 thorpej /* Check for ESP version 2.0: bits 4,5,6 == 010 */
294 1.113.2.2 thorpej bus_space_write_1(iot, hayespioh, HAYESP_CMD1, HAYESP_GETTEST);
295 1.113.2.2 thorpej val = bus_space_read_1(iot, hayespioh, HAYESP_STATUS1); /* Clear reg1 */
296 1.113.2.2 thorpej val = bus_space_read_1(iot, hayespioh, HAYESP_STATUS2);
297 1.113.2.2 thorpej if ((val & 0x70) < 0x20) {
298 1.113.2.2 thorpej printf("-old (%o)", val & 0x70);
299 1.113.2.2 thorpej /* we do not support the necessary features */
300 1.113.2.2 thorpej return (0);
301 1.113.2.2 thorpej }
302 1.113.2.2 thorpej
303 1.113.2.2 thorpej /* Check for ability to emulate 16550: bit 8 == 1 */
304 1.113.2.2 thorpej if ((dips & 0x80) == 0) {
305 1.113.2.2 thorpej printf(" slave");
306 1.113.2.2 thorpej /* XXX Does slave really mean no 16550 support?? */
307 1.113.2.2 thorpej return (0);
308 1.113.2.2 thorpej }
309 1.113.2.2 thorpej
310 1.113.2.2 thorpej /*
311 1.113.2.2 thorpej * If we made it this far, we are a full-featured ESP v2.0 (or
312 1.113.2.2 thorpej * better), at the correct com port address.
313 1.113.2.2 thorpej */
314 1.113.2.2 thorpej
315 1.113.2.2 thorpej SET(sc->sc_hwflags, COM_HW_HAYESP);
316 1.113.2.2 thorpej printf(", 1024 byte fifo\n");
317 1.113.2.2 thorpej return (1);
318 1.113.2.2 thorpej }
319 1.113.2.2 thorpej #endif
320 1.113.2.2 thorpej
321 1.113.2.2 thorpej #if defined(DDB) || defined(KGDB)
322 1.113.2.2 thorpej static void
323 1.113.2.2 thorpej com_enable_debugport(sc)
324 1.113.2.2 thorpej struct com_softc *sc;
325 1.113.2.2 thorpej {
326 1.113.2.2 thorpej int s;
327 1.113.2.2 thorpej
328 1.113.2.2 thorpej /* Turn on line break interrupt, set carrier. */
329 1.113.2.2 thorpej s = splserial();
330 1.113.2.2 thorpej sc->sc_ier = IER_ERXRDY;
331 1.113.2.2 thorpej bus_space_write_1(sc->sc_iot, sc->sc_ioh, com_ier, sc->sc_ier);
332 1.113.2.2 thorpej SET(sc->sc_mcr, MCR_DTR | MCR_RTS);
333 1.113.2.2 thorpej bus_space_write_1(sc->sc_iot, sc->sc_ioh, com_mcr, sc->sc_mcr);
334 1.113.2.2 thorpej splx(s);
335 1.113.2.2 thorpej }
336 1.113.2.2 thorpej #endif
337 1.113.2.2 thorpej
338 1.113.2.2 thorpej void
339 1.113.2.2 thorpej com_attach_subr(sc)
340 1.113.2.2 thorpej struct com_softc *sc;
341 1.113.2.2 thorpej {
342 1.113.2.2 thorpej int iobase = sc->sc_iobase;
343 1.113.2.2 thorpej bus_space_tag_t iot = sc->sc_iot;
344 1.113.2.2 thorpej bus_space_handle_t ioh = sc->sc_ioh;
345 1.113.2.2 thorpej #ifdef COM_HAYESP
346 1.113.2.2 thorpej int hayesp_ports[] = { 0x140, 0x180, 0x280, 0x300, 0 };
347 1.113.2.2 thorpej int *hayespp;
348 1.113.2.2 thorpej #endif
349 1.113.2.2 thorpej
350 1.113.2.2 thorpej if (iot == comconstag && iobase == comconsaddr) {
351 1.113.2.2 thorpej comconsattached = 1;
352 1.113.2.2 thorpej
353 1.113.2.2 thorpej /* Make sure the console is always "hardwired". */
354 1.113.2.2 thorpej delay(1000); /* wait for output to finish */
355 1.113.2.2 thorpej SET(sc->sc_hwflags, COM_HW_CONSOLE);
356 1.113.2.2 thorpej SET(sc->sc_swflags, TIOCFLAG_SOFTCAR);
357 1.113.2.2 thorpej }
358 1.113.2.2 thorpej
359 1.113.2.2 thorpej #ifdef COM_HAYESP
360 1.113.2.2 thorpej /* Look for a Hayes ESP board. */
361 1.113.2.2 thorpej for (hayespp = hayesp_ports; *hayespp != 0; hayespp++) {
362 1.113.2.2 thorpej bus_space_handle_t hayespioh;
363 1.113.2.2 thorpej
364 1.113.2.2 thorpej #define HAYESP_NPORTS 8 /* XXX XXX XXX ??? ??? ??? */
365 1.113.2.2 thorpej if (bus_space_map(iot, *hayespp, HAYESP_NPORTS, 0, &hayespioh))
366 1.113.2.2 thorpej continue;
367 1.113.2.2 thorpej if (comprobeHAYESP(hayespioh, sc)) {
368 1.113.2.2 thorpej sc->sc_hayespioh = hayespioh;
369 1.113.2.2 thorpej sc->sc_fifolen = 1024;
370 1.113.2.2 thorpej
371 1.113.2.2 thorpej /* Set 16550 compatibility mode */
372 1.113.2.2 thorpej bus_space_write_1(iot, hayespioh, HAYESP_CMD1, HAYESP_SETMODE);
373 1.113.2.2 thorpej bus_space_write_1(iot, hayespioh, HAYESP_CMD2,
374 1.113.2.2 thorpej HAYESP_MODE_FIFO|HAYESP_MODE_RTS|
375 1.113.2.2 thorpej HAYESP_MODE_SCALE);
376 1.113.2.2 thorpej
377 1.113.2.2 thorpej /* Set RTS/CTS flow control */
378 1.113.2.2 thorpej bus_space_write_1(iot, hayespioh, HAYESP_CMD1, HAYESP_SETFLOWTYPE);
379 1.113.2.2 thorpej bus_space_write_1(iot, hayespioh, HAYESP_CMD2, HAYESP_FLOW_RTS);
380 1.113.2.2 thorpej bus_space_write_1(iot, hayespioh, HAYESP_CMD2, HAYESP_FLOW_CTS);
381 1.113.2.2 thorpej
382 1.113.2.2 thorpej /* Set flow control levels */
383 1.113.2.2 thorpej bus_space_write_1(iot, hayespioh, HAYESP_CMD1, HAYESP_SETRXFLOW);
384 1.113.2.2 thorpej bus_space_write_1(iot, hayespioh, HAYESP_CMD2,
385 1.113.2.2 thorpej HAYESP_HIBYTE(HAYESP_RXHIWMARK));
386 1.113.2.2 thorpej bus_space_write_1(iot, hayespioh, HAYESP_CMD2,
387 1.113.2.2 thorpej HAYESP_LOBYTE(HAYESP_RXHIWMARK));
388 1.113.2.2 thorpej bus_space_write_1(iot, hayespioh, HAYESP_CMD2,
389 1.113.2.2 thorpej HAYESP_HIBYTE(HAYESP_RXLOWMARK));
390 1.113.2.2 thorpej bus_space_write_1(iot, hayespioh, HAYESP_CMD2,
391 1.113.2.2 thorpej HAYESP_LOBYTE(HAYESP_RXLOWMARK));
392 1.113.2.2 thorpej
393 1.113.2.2 thorpej break;
394 1.113.2.2 thorpej }
395 1.113.2.2 thorpej bus_space_unmap(iot, hayespioh, HAYESP_NPORTS);
396 1.113.2.2 thorpej }
397 1.113.2.2 thorpej /* No ESP; look for other things. */
398 1.113.2.2 thorpej if (*hayespp == 0) {
399 1.113.2.2 thorpej #endif
400 1.113.2.2 thorpej
401 1.113.2.2 thorpej sc->sc_fifolen = 1;
402 1.113.2.2 thorpej /* look for a NS 16550AF UART with FIFOs */
403 1.113.2.2 thorpej bus_space_write_1(iot, ioh, com_fifo,
404 1.113.2.2 thorpej FIFO_ENABLE | FIFO_RCV_RST | FIFO_XMT_RST | FIFO_TRIGGER_14);
405 1.113.2.2 thorpej delay(100);
406 1.113.2.2 thorpej if (ISSET(bus_space_read_1(iot, ioh, com_iir), IIR_FIFO_MASK)
407 1.113.2.2 thorpej == IIR_FIFO_MASK)
408 1.113.2.2 thorpej if (ISSET(bus_space_read_1(iot, ioh, com_fifo), FIFO_TRIGGER_14)
409 1.113.2.2 thorpej == FIFO_TRIGGER_14) {
410 1.113.2.2 thorpej SET(sc->sc_hwflags, COM_HW_FIFO);
411 1.113.2.2 thorpej printf(": ns16550a, working fifo\n");
412 1.113.2.2 thorpej sc->sc_fifolen = 16;
413 1.113.2.2 thorpej } else
414 1.113.2.2 thorpej printf(": ns16550, broken fifo\n");
415 1.113.2.2 thorpej else
416 1.113.2.2 thorpej printf(": ns8250 or ns16450, no fifo\n");
417 1.113.2.2 thorpej bus_space_write_1(iot, ioh, com_fifo, 0);
418 1.113.2.2 thorpej #ifdef COM_HAYESP
419 1.113.2.2 thorpej }
420 1.113.2.2 thorpej #endif
421 1.113.2.2 thorpej
422 1.113.2.2 thorpej if (!ISSET(sc->sc_hwflags, COM_HW_NOIEN))
423 1.113.2.2 thorpej SET(sc->sc_mcr, MCR_IENABLE);
424 1.113.2.2 thorpej
425 1.113.2.2 thorpej if (ISSET(sc->sc_hwflags, COM_HW_CONSOLE)) {
426 1.113.2.2 thorpej int maj;
427 1.113.2.2 thorpej
428 1.113.2.2 thorpej /* locate the major number */
429 1.113.2.2 thorpej for (maj = 0; maj < nchrdev; maj++)
430 1.113.2.2 thorpej if (cdevsw[maj].d_open == comopen)
431 1.113.2.2 thorpej break;
432 1.113.2.2 thorpej
433 1.113.2.2 thorpej cn_tab->cn_dev = makedev(maj, sc->sc_dev.dv_unit);
434 1.113.2.2 thorpej #ifdef DDB
435 1.113.2.2 thorpej com_enable_debugport(sc);
436 1.113.2.2 thorpej #endif
437 1.113.2.2 thorpej printf("%s: console\n", sc->sc_dev.dv_xname);
438 1.113.2.2 thorpej }
439 1.113.2.2 thorpej
440 1.113.2.2 thorpej #ifdef KGDB
441 1.113.2.2 thorpej /*
442 1.113.2.2 thorpej * Allow kgdb to "take over" this port. If this is
443 1.113.2.2 thorpej * the kgdb device, it has exclusive use.
444 1.113.2.2 thorpej */
445 1.113.2.2 thorpej if (iot == com_kgdb_iot && iobase == com_kgdb_addr) {
446 1.113.2.2 thorpej com_kgdb_attached = 1;
447 1.113.2.2 thorpej
448 1.113.2.2 thorpej SET(sc->sc_hwflags, COM_HW_KGDB);
449 1.113.2.2 thorpej com_enable_debugport(sc);
450 1.113.2.2 thorpej printf("%s: kgdb\n", sc->sc_dev.dv_xname);
451 1.113.2.2 thorpej }
452 1.113.2.2 thorpej #endif
453 1.113.2.2 thorpej
454 1.113.2.2 thorpej #ifdef __GENERIC_SOFT_INTERRUPTS
455 1.113.2.2 thorpej sc->sc_si = softintr_establish(IPL_SOFTSERIAL, comsoft, sc);
456 1.113.2.2 thorpej #endif
457 1.113.2.2 thorpej }
458 1.113.2.2 thorpej
459 1.113.2.2 thorpej int
460 1.113.2.2 thorpej comopen(dev, flag, mode, p)
461 1.113.2.2 thorpej dev_t dev;
462 1.113.2.2 thorpej int flag, mode;
463 1.113.2.2 thorpej struct proc *p;
464 1.113.2.2 thorpej {
465 1.113.2.2 thorpej int unit = COMUNIT(dev);
466 1.113.2.2 thorpej struct com_softc *sc;
467 1.113.2.2 thorpej struct tty *tp;
468 1.113.2.2 thorpej int s, s2;
469 1.113.2.2 thorpej int error = 0;
470 1.113.2.2 thorpej
471 1.113.2.2 thorpej if (unit >= com_cd.cd_ndevs)
472 1.113.2.2 thorpej return (ENXIO);
473 1.113.2.2 thorpej sc = com_cd.cd_devs[unit];
474 1.113.2.2 thorpej if (!sc)
475 1.113.2.2 thorpej return (ENXIO);
476 1.113.2.2 thorpej
477 1.113.2.2 thorpej #ifdef KGDB
478 1.113.2.2 thorpej /*
479 1.113.2.2 thorpej * If this is the kgdb port, no other use is permitted.
480 1.113.2.2 thorpej */
481 1.113.2.2 thorpej if (ISSET(sc->sc_hwflags, COM_HW_KGDB))
482 1.113.2.2 thorpej return (EBUSY);
483 1.113.2.2 thorpej #endif
484 1.113.2.2 thorpej
485 1.113.2.2 thorpej if (!sc->sc_tty) {
486 1.113.2.2 thorpej tp = sc->sc_tty = ttymalloc();
487 1.113.2.2 thorpej tty_attach(tp);
488 1.113.2.2 thorpej } else
489 1.113.2.2 thorpej tp = sc->sc_tty;
490 1.113.2.2 thorpej
491 1.113.2.2 thorpej if (ISSET(tp->t_state, TS_ISOPEN) &&
492 1.113.2.2 thorpej ISSET(tp->t_state, TS_XCLUDE) &&
493 1.113.2.2 thorpej p->p_ucred->cr_uid != 0)
494 1.113.2.2 thorpej return (EBUSY);
495 1.113.2.2 thorpej
496 1.113.2.2 thorpej s = spltty();
497 1.113.2.2 thorpej
498 1.113.2.2 thorpej /* We need to set this early for the benefit of comsoft(). */
499 1.113.2.2 thorpej SET(tp->t_state, TS_WOPEN);
500 1.113.2.2 thorpej
501 1.113.2.2 thorpej /*
502 1.113.2.2 thorpej * Do the following iff this is a first open.
503 1.113.2.2 thorpej */
504 1.113.2.2 thorpej if (!ISSET(tp->t_state, TS_ISOPEN)) {
505 1.113.2.2 thorpej struct termios t;
506 1.113.2.2 thorpej
507 1.113.2.2 thorpej /* Turn on interrupts. */
508 1.113.2.2 thorpej sc->sc_ier = IER_ERXRDY | IER_ERLS | IER_EMSC;
509 1.113.2.2 thorpej bus_space_write_1(sc->sc_iot, sc->sc_ioh, com_ier, sc->sc_ier);
510 1.113.2.2 thorpej
511 1.113.2.2 thorpej /* Fetch the current modem control status, needed later. */
512 1.113.2.2 thorpej sc->sc_msr = bus_space_read_1(sc->sc_iot, sc->sc_ioh, com_msr);
513 1.113.2.2 thorpej
514 1.113.2.2 thorpej /* Add some entry points needed by the tty layer. */
515 1.113.2.2 thorpej tp->t_oproc = comstart;
516 1.113.2.2 thorpej tp->t_param = comparam;
517 1.113.2.2 thorpej tp->t_hwiflow = comhwiflow;
518 1.113.2.2 thorpej tp->t_dev = dev;
519 1.113.2.2 thorpej
520 1.113.2.2 thorpej /*
521 1.113.2.2 thorpej * Initialize the termios status to the defaults. Add in the
522 1.113.2.2 thorpej * sticky bits from TIOCSFLAGS.
523 1.113.2.2 thorpej */
524 1.113.2.2 thorpej t.c_ispeed = 0;
525 1.113.2.2 thorpej if (ISSET(sc->sc_hwflags, COM_HW_CONSOLE)) {
526 1.113.2.2 thorpej t.c_ospeed = comconsrate;
527 1.113.2.2 thorpej t.c_cflag = comconscflag;
528 1.113.2.2 thorpej } else {
529 1.113.2.2 thorpej t.c_ospeed = TTYDEF_SPEED;
530 1.113.2.2 thorpej t.c_cflag = TTYDEF_CFLAG;
531 1.113.2.2 thorpej }
532 1.113.2.2 thorpej if (ISSET(sc->sc_swflags, TIOCFLAG_CLOCAL))
533 1.113.2.2 thorpej SET(t.c_cflag, CLOCAL);
534 1.113.2.2 thorpej if (ISSET(sc->sc_swflags, TIOCFLAG_CRTSCTS))
535 1.113.2.2 thorpej SET(t.c_cflag, CRTSCTS);
536 1.113.2.2 thorpej if (ISSET(sc->sc_swflags, TIOCFLAG_MDMBUF))
537 1.113.2.2 thorpej SET(t.c_cflag, MDMBUF);
538 1.113.2.2 thorpej tp->t_iflag = TTYDEF_IFLAG;
539 1.113.2.2 thorpej tp->t_oflag = TTYDEF_OFLAG;
540 1.113.2.2 thorpej tp->t_lflag = TTYDEF_LFLAG;
541 1.113.2.2 thorpej ttychars(tp);
542 1.113.2.2 thorpej (void) comparam(tp, &t);
543 1.113.2.2 thorpej ttsetwater(tp);
544 1.113.2.2 thorpej
545 1.113.2.2 thorpej s2 = splserial();
546 1.113.2.2 thorpej
547 1.113.2.2 thorpej /*
548 1.113.2.2 thorpej * Turn on DTR. We must always do this, even if carrier is not
549 1.113.2.2 thorpej * present, because otherwise we'd have to use TIOCSDTR
550 1.113.2.2 thorpej * immediately after setting CLOCAL. We will drop DTR only on
551 1.113.2.2 thorpej * the next high-low transition of DCD, or by explicit request.
552 1.113.2.2 thorpej */
553 1.113.2.2 thorpej com_modem(sc, 1);
554 1.113.2.2 thorpej
555 1.113.2.2 thorpej /* Clear the input ring, and unblock. */
556 1.113.2.2 thorpej sc->sc_rbput = sc->sc_rbget = 0;
557 1.113.2.2 thorpej sc->sc_rbavail = RXBUFSIZE;
558 1.113.2.2 thorpej com_iflush(sc);
559 1.113.2.2 thorpej CLR(sc->sc_rx_flags, RX_ANY_BLOCK);
560 1.113.2.2 thorpej com_hwiflow(sc);
561 1.113.2.2 thorpej
562 1.113.2.2 thorpej #ifdef COM_DEBUG
563 1.113.2.2 thorpej if (com_debug)
564 1.113.2.2 thorpej comstatus(sc, "comopen ");
565 1.113.2.2 thorpej #endif
566 1.113.2.2 thorpej
567 1.113.2.2 thorpej splx(s2);
568 1.113.2.2 thorpej }
569 1.113.2.2 thorpej error = 0;
570 1.113.2.2 thorpej
571 1.113.2.2 thorpej /* If we're doing a blocking open... */
572 1.113.2.2 thorpej if (!ISSET(flag, O_NONBLOCK))
573 1.113.2.2 thorpej /* ...then wait for carrier. */
574 1.113.2.2 thorpej while (!ISSET(tp->t_state, TS_CARR_ON) &&
575 1.113.2.2 thorpej !ISSET(tp->t_cflag, CLOCAL | MDMBUF)) {
576 1.113.2.2 thorpej error = ttysleep(tp, &tp->t_rawq, TTIPRI | PCATCH,
577 1.113.2.2 thorpej ttopen, 0);
578 1.113.2.2 thorpej if (error) {
579 1.113.2.2 thorpej /*
580 1.113.2.2 thorpej * If the open was interrupted and nobody
581 1.113.2.2 thorpej * else has the device open, then hang up.
582 1.113.2.2 thorpej */
583 1.113.2.2 thorpej if (!ISSET(tp->t_state, TS_ISOPEN)) {
584 1.113.2.2 thorpej com_modem(sc, 0);
585 1.113.2.2 thorpej CLR(tp->t_state, TS_WOPEN);
586 1.113.2.2 thorpej ttwakeup(tp);
587 1.113.2.2 thorpej }
588 1.113.2.2 thorpej break;
589 1.113.2.2 thorpej }
590 1.113.2.2 thorpej SET(tp->t_state, TS_WOPEN);
591 1.113.2.2 thorpej }
592 1.113.2.2 thorpej
593 1.113.2.2 thorpej splx(s);
594 1.113.2.2 thorpej if (error == 0)
595 1.113.2.2 thorpej error = (*linesw[tp->t_line].l_open)(dev, tp);
596 1.113.2.2 thorpej return (error);
597 1.113.2.2 thorpej }
598 1.113.2.2 thorpej
599 1.113.2.2 thorpej int
600 1.113.2.2 thorpej comclose(dev, flag, mode, p)
601 1.113.2.2 thorpej dev_t dev;
602 1.113.2.2 thorpej int flag, mode;
603 1.113.2.2 thorpej struct proc *p;
604 1.113.2.2 thorpej {
605 1.113.2.2 thorpej int unit = COMUNIT(dev);
606 1.113.2.2 thorpej struct com_softc *sc = com_cd.cd_devs[unit];
607 1.113.2.2 thorpej struct tty *tp = sc->sc_tty;
608 1.113.2.2 thorpej int s;
609 1.113.2.2 thorpej
610 1.113.2.2 thorpej /* XXX This is for cons.c. */
611 1.113.2.2 thorpej if (!ISSET(tp->t_state, TS_ISOPEN))
612 1.113.2.2 thorpej return (0);
613 1.113.2.2 thorpej
614 1.113.2.2 thorpej (*linesw[tp->t_line].l_close)(tp, flag);
615 1.113.2.2 thorpej ttyclose(tp);
616 1.113.2.2 thorpej
617 1.113.2.2 thorpej /* If we were asserting flow control, then deassert it. */
618 1.113.2.2 thorpej SET(sc->sc_rx_flags, RX_IBUF_BLOCKED);
619 1.113.2.2 thorpej com_hwiflow(sc);
620 1.113.2.2 thorpej /* Clear any break condition set with TIOCSBRK. */
621 1.113.2.2 thorpej com_break(sc, 0);
622 1.113.2.2 thorpej /*
623 1.113.2.2 thorpej * Hang up if necessary. Wait a bit, so the other side has time to
624 1.113.2.2 thorpej * notice even if we immediately open the port again.
625 1.113.2.2 thorpej */
626 1.113.2.2 thorpej if (ISSET(tp->t_cflag, HUPCL)) {
627 1.113.2.2 thorpej com_modem(sc, 0);
628 1.113.2.2 thorpej (void) tsleep(sc, TTIPRI, ttclos, hz);
629 1.113.2.2 thorpej }
630 1.113.2.2 thorpej
631 1.113.2.2 thorpej s = splserial();
632 1.113.2.2 thorpej /* Turn off interrupts. */
633 1.113.2.2 thorpej #ifdef DDB
634 1.113.2.2 thorpej if(ISSET(sc->sc_hwflags, COM_HW_CONSOLE))
635 1.113.2.2 thorpej sc->sc_ier = IER_ERXRDY; /* interrupt on break */
636 1.113.2.2 thorpej else
637 1.113.2.2 thorpej #else
638 1.113.2.2 thorpej sc->sc_ier = 0;
639 1.113.2.2 thorpej #endif
640 1.113.2.2 thorpej bus_space_write_1(sc->sc_iot, sc->sc_ioh, com_ier, sc->sc_ier);
641 1.113.2.2 thorpej splx(s);
642 1.113.2.2 thorpej
643 1.113.2.2 thorpej return (0);
644 1.113.2.2 thorpej }
645 1.113.2.2 thorpej
646 1.113.2.2 thorpej int
647 1.113.2.2 thorpej comread(dev, uio, flag)
648 1.113.2.2 thorpej dev_t dev;
649 1.113.2.2 thorpej struct uio *uio;
650 1.113.2.2 thorpej int flag;
651 1.113.2.2 thorpej {
652 1.113.2.2 thorpej struct com_softc *sc = com_cd.cd_devs[COMUNIT(dev)];
653 1.113.2.2 thorpej struct tty *tp = sc->sc_tty;
654 1.113.2.2 thorpej
655 1.113.2.2 thorpej return ((*linesw[tp->t_line].l_read)(tp, uio, flag));
656 1.113.2.2 thorpej }
657 1.113.2.2 thorpej
658 1.113.2.2 thorpej int
659 1.113.2.2 thorpej comwrite(dev, uio, flag)
660 1.113.2.2 thorpej dev_t dev;
661 1.113.2.2 thorpej struct uio *uio;
662 1.113.2.2 thorpej int flag;
663 1.113.2.2 thorpej {
664 1.113.2.2 thorpej struct com_softc *sc = com_cd.cd_devs[COMUNIT(dev)];
665 1.113.2.2 thorpej struct tty *tp = sc->sc_tty;
666 1.113.2.2 thorpej
667 1.113.2.2 thorpej return ((*linesw[tp->t_line].l_write)(tp, uio, flag));
668 1.113.2.2 thorpej }
669 1.113.2.2 thorpej
670 1.113.2.2 thorpej struct tty *
671 1.113.2.2 thorpej comtty(dev)
672 1.113.2.2 thorpej dev_t dev;
673 1.113.2.2 thorpej {
674 1.113.2.2 thorpej struct com_softc *sc = com_cd.cd_devs[COMUNIT(dev)];
675 1.113.2.2 thorpej struct tty *tp = sc->sc_tty;
676 1.113.2.2 thorpej
677 1.113.2.2 thorpej return (tp);
678 1.113.2.2 thorpej }
679 1.113.2.2 thorpej
680 1.113.2.2 thorpej static u_char
681 1.113.2.2 thorpej tiocm_xxx2mcr(data)
682 1.113.2.2 thorpej int data;
683 1.113.2.2 thorpej {
684 1.113.2.2 thorpej u_char m = 0;
685 1.113.2.2 thorpej
686 1.113.2.2 thorpej if (ISSET(data, TIOCM_DTR))
687 1.113.2.2 thorpej SET(m, MCR_DTR);
688 1.113.2.2 thorpej if (ISSET(data, TIOCM_RTS))
689 1.113.2.2 thorpej SET(m, MCR_RTS);
690 1.113.2.2 thorpej return m;
691 1.113.2.2 thorpej }
692 1.113.2.2 thorpej
693 1.113.2.2 thorpej int
694 1.113.2.2 thorpej comioctl(dev, cmd, data, flag, p)
695 1.113.2.2 thorpej dev_t dev;
696 1.113.2.2 thorpej u_long cmd;
697 1.113.2.2 thorpej caddr_t data;
698 1.113.2.2 thorpej int flag;
699 1.113.2.2 thorpej struct proc *p;
700 1.113.2.2 thorpej {
701 1.113.2.2 thorpej int unit = COMUNIT(dev);
702 1.113.2.2 thorpej struct com_softc *sc = com_cd.cd_devs[unit];
703 1.113.2.2 thorpej struct tty *tp = sc->sc_tty;
704 1.113.2.2 thorpej int error;
705 1.113.2.2 thorpej
706 1.113.2.2 thorpej error = (*linesw[tp->t_line].l_ioctl)(tp, cmd, data, flag, p);
707 1.113.2.2 thorpej if (error >= 0)
708 1.113.2.2 thorpej return (error);
709 1.113.2.2 thorpej
710 1.113.2.2 thorpej error = ttioctl(tp, cmd, data, flag, p);
711 1.113.2.2 thorpej if (error >= 0)
712 1.113.2.2 thorpej return (error);
713 1.113.2.2 thorpej
714 1.113.2.2 thorpej switch (cmd) {
715 1.113.2.2 thorpej case TIOCSBRK:
716 1.113.2.2 thorpej com_break(sc, 1);
717 1.113.2.2 thorpej break;
718 1.113.2.2 thorpej
719 1.113.2.2 thorpej case TIOCCBRK:
720 1.113.2.2 thorpej com_break(sc, 0);
721 1.113.2.2 thorpej break;
722 1.113.2.2 thorpej
723 1.113.2.2 thorpej case TIOCSDTR:
724 1.113.2.2 thorpej com_modem(sc, 1);
725 1.113.2.2 thorpej break;
726 1.113.2.2 thorpej
727 1.113.2.2 thorpej case TIOCCDTR:
728 1.113.2.2 thorpej com_modem(sc, 0);
729 1.113.2.2 thorpej break;
730 1.113.2.2 thorpej
731 1.113.2.2 thorpej case TIOCGFLAGS:
732 1.113.2.2 thorpej *(int *)data = sc->sc_swflags;
733 1.113.2.2 thorpej break;
734 1.113.2.2 thorpej
735 1.113.2.2 thorpej case TIOCSFLAGS:
736 1.113.2.2 thorpej error = suser(p->p_ucred, &p->p_acflag);
737 1.113.2.2 thorpej if (error)
738 1.113.2.2 thorpej return (error);
739 1.113.2.2 thorpej sc->sc_swflags = *(int *)data;
740 1.113.2.2 thorpej break;
741 1.113.2.2 thorpej
742 1.113.2.2 thorpej case TIOCMSET:
743 1.113.2.2 thorpej CLR(sc->sc_mcr, MCR_DTR | MCR_RTS);
744 1.113.2.2 thorpej /*FALLTHROUGH*/
745 1.113.2.2 thorpej
746 1.113.2.2 thorpej case TIOCMBIS:
747 1.113.2.2 thorpej SET(sc->sc_mcr, tiocm_xxx2mcr(*(int *)data));
748 1.113.2.2 thorpej bus_space_write_1(sc->sc_iot, sc->sc_ioh, com_mcr, sc->sc_mcr);
749 1.113.2.2 thorpej break;
750 1.113.2.2 thorpej
751 1.113.2.2 thorpej case TIOCMBIC:
752 1.113.2.2 thorpej CLR(sc->sc_mcr, tiocm_xxx2mcr(*(int *)data));
753 1.113.2.2 thorpej bus_space_write_1(sc->sc_iot, sc->sc_ioh, com_mcr, sc->sc_mcr);
754 1.113.2.2 thorpej break;
755 1.113.2.2 thorpej
756 1.113.2.2 thorpej case TIOCMGET: {
757 1.113.2.2 thorpej u_char m;
758 1.113.2.2 thorpej int bits = 0;
759 1.113.2.2 thorpej
760 1.113.2.2 thorpej m = sc->sc_mcr;
761 1.113.2.2 thorpej if (ISSET(m, MCR_DTR))
762 1.113.2.2 thorpej SET(bits, TIOCM_DTR);
763 1.113.2.2 thorpej if (ISSET(m, MCR_RTS))
764 1.113.2.2 thorpej SET(bits, TIOCM_RTS);
765 1.113.2.2 thorpej m = sc->sc_msr;
766 1.113.2.2 thorpej if (ISSET(m, MSR_DCD))
767 1.113.2.2 thorpej SET(bits, TIOCM_CD);
768 1.113.2.2 thorpej if (ISSET(m, MSR_CTS))
769 1.113.2.2 thorpej SET(bits, TIOCM_CTS);
770 1.113.2.2 thorpej if (ISSET(m, MSR_DSR))
771 1.113.2.2 thorpej SET(bits, TIOCM_DSR);
772 1.113.2.2 thorpej if (ISSET(m, MSR_RI | MSR_TERI))
773 1.113.2.2 thorpej SET(bits, TIOCM_RI);
774 1.113.2.2 thorpej if (bus_space_read_1(sc->sc_iot, sc->sc_ioh, com_ier))
775 1.113.2.2 thorpej SET(bits, TIOCM_LE);
776 1.113.2.2 thorpej *(int *)data = bits;
777 1.113.2.2 thorpej break;
778 1.113.2.2 thorpej }
779 1.113.2.2 thorpej default:
780 1.113.2.2 thorpej return (ENOTTY);
781 1.113.2.2 thorpej }
782 1.113.2.2 thorpej
783 1.113.2.2 thorpej #ifdef COM_DEBUG
784 1.113.2.2 thorpej if (com_debug)
785 1.113.2.2 thorpej comstatus(sc, "comioctl ");
786 1.113.2.2 thorpej #endif
787 1.113.2.2 thorpej
788 1.113.2.2 thorpej return (0);
789 1.113.2.2 thorpej }
790 1.113.2.2 thorpej
791 1.113.2.2 thorpej integrate void
792 1.113.2.2 thorpej com_schedrx(sc)
793 1.113.2.2 thorpej struct com_softc *sc;
794 1.113.2.2 thorpej {
795 1.113.2.2 thorpej
796 1.113.2.2 thorpej sc->sc_rx_ready = 1;
797 1.113.2.2 thorpej
798 1.113.2.2 thorpej /* Wake up the poller. */
799 1.113.2.2 thorpej #ifdef __GENERIC_SOFT_INTERRUPTS
800 1.113.2.2 thorpej softintr_schedule(sc->sc_si);
801 1.113.2.2 thorpej #else
802 1.113.2.2 thorpej #ifndef alpha
803 1.113.2.2 thorpej setsoftserial();
804 1.113.2.2 thorpej #else
805 1.113.2.2 thorpej if (!com_softintr_scheduled) {
806 1.113.2.2 thorpej com_softintr_scheduled = 1;
807 1.113.2.2 thorpej timeout(comsoft, NULL, 1);
808 1.113.2.2 thorpej }
809 1.113.2.2 thorpej #endif
810 1.113.2.2 thorpej #endif
811 1.113.2.2 thorpej }
812 1.113.2.2 thorpej
813 1.113.2.2 thorpej void
814 1.113.2.2 thorpej com_break(sc, onoff)
815 1.113.2.2 thorpej struct com_softc *sc;
816 1.113.2.2 thorpej int onoff;
817 1.113.2.2 thorpej {
818 1.113.2.2 thorpej int s;
819 1.113.2.2 thorpej
820 1.113.2.2 thorpej s = splserial();
821 1.113.2.2 thorpej if (onoff)
822 1.113.2.2 thorpej SET(sc->sc_lcr, LCR_SBREAK);
823 1.113.2.2 thorpej else
824 1.113.2.2 thorpej CLR(sc->sc_lcr, LCR_SBREAK);
825 1.113.2.2 thorpej
826 1.113.2.2 thorpej if (!sc->sc_heldchange) {
827 1.113.2.2 thorpej if (sc->sc_tx_busy) {
828 1.113.2.2 thorpej sc->sc_heldtbc = sc->sc_tbc;
829 1.113.2.2 thorpej sc->sc_tbc = 0;
830 1.113.2.2 thorpej sc->sc_heldchange = 1;
831 1.113.2.2 thorpej } else
832 1.113.2.2 thorpej com_loadchannelregs(sc);
833 1.113.2.2 thorpej }
834 1.113.2.2 thorpej splx(s);
835 1.113.2.2 thorpej }
836 1.113.2.2 thorpej
837 1.113.2.2 thorpej void
838 1.113.2.2 thorpej com_modem(sc, onoff)
839 1.113.2.2 thorpej struct com_softc *sc;
840 1.113.2.2 thorpej int onoff;
841 1.113.2.2 thorpej {
842 1.113.2.2 thorpej int s;
843 1.113.2.2 thorpej
844 1.113.2.2 thorpej s = splserial();
845 1.113.2.2 thorpej if (onoff)
846 1.113.2.2 thorpej SET(sc->sc_mcr, sc->sc_mcr_dtr);
847 1.113.2.2 thorpej else
848 1.113.2.2 thorpej CLR(sc->sc_mcr, sc->sc_mcr_dtr);
849 1.113.2.2 thorpej
850 1.113.2.2 thorpej if (!sc->sc_heldchange) {
851 1.113.2.2 thorpej if (sc->sc_tx_busy) {
852 1.113.2.2 thorpej sc->sc_heldtbc = sc->sc_tbc;
853 1.113.2.2 thorpej sc->sc_tbc = 0;
854 1.113.2.2 thorpej sc->sc_heldchange = 1;
855 1.113.2.2 thorpej } else
856 1.113.2.2 thorpej com_loadchannelregs(sc);
857 1.113.2.2 thorpej }
858 1.113.2.2 thorpej splx(s);
859 1.113.2.2 thorpej }
860 1.113.2.2 thorpej
861 1.113.2.2 thorpej static u_char
862 1.113.2.2 thorpej cflag2lcr(cflag)
863 1.113.2.2 thorpej tcflag_t cflag;
864 1.113.2.2 thorpej {
865 1.113.2.2 thorpej u_char lcr = 0;
866 1.113.2.2 thorpej
867 1.113.2.2 thorpej switch (ISSET(cflag, CSIZE)) {
868 1.113.2.2 thorpej case CS5:
869 1.113.2.2 thorpej SET(lcr, LCR_5BITS);
870 1.113.2.2 thorpej break;
871 1.113.2.2 thorpej case CS6:
872 1.113.2.2 thorpej SET(lcr, LCR_6BITS);
873 1.113.2.2 thorpej break;
874 1.113.2.2 thorpej case CS7:
875 1.113.2.2 thorpej SET(lcr, LCR_7BITS);
876 1.113.2.2 thorpej break;
877 1.113.2.2 thorpej case CS8:
878 1.113.2.2 thorpej SET(lcr, LCR_8BITS);
879 1.113.2.2 thorpej break;
880 1.113.2.2 thorpej }
881 1.113.2.2 thorpej if (ISSET(cflag, PARENB)) {
882 1.113.2.2 thorpej SET(lcr, LCR_PENAB);
883 1.113.2.2 thorpej if (!ISSET(cflag, PARODD))
884 1.113.2.2 thorpej SET(lcr, LCR_PEVEN);
885 1.113.2.2 thorpej }
886 1.113.2.2 thorpej if (ISSET(cflag, CSTOPB))
887 1.113.2.2 thorpej SET(lcr, LCR_STOPB);
888 1.113.2.2 thorpej
889 1.113.2.2 thorpej return (lcr);
890 1.113.2.2 thorpej }
891 1.113.2.2 thorpej
892 1.113.2.2 thorpej int
893 1.113.2.2 thorpej comparam(tp, t)
894 1.113.2.2 thorpej struct tty *tp;
895 1.113.2.2 thorpej struct termios *t;
896 1.113.2.2 thorpej {
897 1.113.2.2 thorpej struct com_softc *sc = com_cd.cd_devs[COMUNIT(tp->t_dev)];
898 1.113.2.2 thorpej int ospeed = comspeed(t->c_ospeed, sc->sc_frequency);
899 1.113.2.2 thorpej u_char lcr;
900 1.113.2.2 thorpej int s;
901 1.113.2.2 thorpej
902 1.113.2.2 thorpej /* check requested parameters */
903 1.113.2.2 thorpej if (ospeed < 0)
904 1.113.2.2 thorpej return (EINVAL);
905 1.113.2.2 thorpej if (t->c_ispeed && t->c_ispeed != t->c_ospeed)
906 1.113.2.2 thorpej return (EINVAL);
907 1.113.2.2 thorpej
908 1.113.2.2 thorpej lcr = ISSET(sc->sc_lcr, LCR_SBREAK) | cflag2lcr(t->c_cflag);
909 1.113.2.2 thorpej
910 1.113.2.2 thorpej s = splserial();
911 1.113.2.2 thorpej
912 1.113.2.2 thorpej sc->sc_lcr = lcr;
913 1.113.2.2 thorpej
914 1.113.2.2 thorpej /*
915 1.113.2.2 thorpej * For the console, always force CLOCAL and !HUPCL, so that the port
916 1.113.2.2 thorpej * is always active.
917 1.113.2.2 thorpej */
918 1.113.2.2 thorpej if (ISSET(sc->sc_swflags, TIOCFLAG_SOFTCAR) ||
919 1.113.2.2 thorpej ISSET(sc->sc_hwflags, COM_HW_CONSOLE)) {
920 1.113.2.2 thorpej SET(t->c_cflag, CLOCAL);
921 1.113.2.2 thorpej CLR(t->c_cflag, HUPCL);
922 1.113.2.2 thorpej }
923 1.113.2.2 thorpej
924 1.113.2.2 thorpej /*
925 1.113.2.2 thorpej * If we're not in a mode that assumes a connection is present, then
926 1.113.2.2 thorpej * ignore carrier changes.
927 1.113.2.2 thorpej */
928 1.113.2.2 thorpej if (ISSET(t->c_cflag, CLOCAL | MDMBUF))
929 1.113.2.2 thorpej sc->sc_msr_dcd = 0;
930 1.113.2.2 thorpej else
931 1.113.2.2 thorpej sc->sc_msr_dcd = MSR_DCD;
932 1.113.2.2 thorpej /*
933 1.113.2.2 thorpej * Set the flow control pins depending on the current flow control
934 1.113.2.2 thorpej * mode.
935 1.113.2.2 thorpej */
936 1.113.2.2 thorpej if (ISSET(t->c_cflag, CRTSCTS)) {
937 1.113.2.2 thorpej sc->sc_mcr_dtr = MCR_DTR;
938 1.113.2.2 thorpej sc->sc_mcr_rts = MCR_RTS;
939 1.113.2.2 thorpej sc->sc_msr_cts = MSR_CTS;
940 1.113.2.2 thorpej sc->sc_r_hiwat = RXHIWAT;
941 1.113.2.2 thorpej sc->sc_r_lowat = RXLOWAT;
942 1.113.2.2 thorpej } else if (ISSET(t->c_cflag, MDMBUF)) {
943 1.113.2.2 thorpej /*
944 1.113.2.2 thorpej * For DTR/DCD flow control, make sure we don't toggle DTR for
945 1.113.2.2 thorpej * carrier detection.
946 1.113.2.2 thorpej */
947 1.113.2.2 thorpej sc->sc_mcr_dtr = 0;
948 1.113.2.2 thorpej sc->sc_mcr_rts = MCR_DTR;
949 1.113.2.2 thorpej sc->sc_msr_cts = MSR_DCD;
950 1.113.2.2 thorpej sc->sc_r_hiwat = RXHIWAT;
951 1.113.2.2 thorpej sc->sc_r_lowat = RXLOWAT;
952 1.113.2.2 thorpej } else {
953 1.113.2.2 thorpej /*
954 1.113.2.2 thorpej * If no flow control, then always set RTS. This will make
955 1.113.2.2 thorpej * the other side happy if it mistakenly thinks we're doing
956 1.113.2.2 thorpej * RTS/CTS flow control.
957 1.113.2.2 thorpej */
958 1.113.2.2 thorpej sc->sc_mcr_dtr = MCR_DTR | MCR_RTS;
959 1.113.2.2 thorpej sc->sc_mcr_rts = 0;
960 1.113.2.2 thorpej sc->sc_msr_cts = 0;
961 1.113.2.2 thorpej sc->sc_r_hiwat = 0;
962 1.113.2.2 thorpej sc->sc_r_lowat = 0;
963 1.113.2.2 thorpej if (ISSET(sc->sc_mcr, MCR_DTR))
964 1.113.2.2 thorpej SET(sc->sc_mcr, MCR_RTS);
965 1.113.2.2 thorpej else
966 1.113.2.2 thorpej CLR(sc->sc_mcr, MCR_RTS);
967 1.113.2.2 thorpej }
968 1.113.2.2 thorpej sc->sc_msr_mask = sc->sc_msr_cts | sc->sc_msr_dcd;
969 1.113.2.2 thorpej
970 1.113.2.2 thorpej #if 0
971 1.113.2.2 thorpej if (ospeed == 0)
972 1.113.2.2 thorpej CLR(sc->sc_mcr, sc->sc_mcr_dtr);
973 1.113.2.2 thorpej else
974 1.113.2.2 thorpej SET(sc->sc_mcr, sc->sc_mcr_dtr);
975 1.113.2.2 thorpej #endif
976 1.113.2.2 thorpej
977 1.113.2.2 thorpej sc->sc_dlbl = ospeed;
978 1.113.2.2 thorpej sc->sc_dlbh = ospeed >> 8;
979 1.113.2.2 thorpej
980 1.113.2.2 thorpej /*
981 1.113.2.2 thorpej * Set the FIFO threshold based on the receive speed.
982 1.113.2.2 thorpej *
983 1.113.2.2 thorpej * * If it's a low speed, it's probably a mouse or some other
984 1.113.2.2 thorpej * interactive device, so set the threshold low.
985 1.113.2.2 thorpej * * If it's a high speed, trim the trigger level down to prevent
986 1.113.2.2 thorpej * overflows.
987 1.113.2.2 thorpej * * Otherwise set it a bit higher.
988 1.113.2.2 thorpej */
989 1.113.2.2 thorpej if (ISSET(sc->sc_hwflags, COM_HW_HAYESP))
990 1.113.2.2 thorpej sc->sc_fifo = FIFO_DMA_MODE | FIFO_ENABLE | FIFO_TRIGGER_8;
991 1.113.2.2 thorpej else if (ISSET(sc->sc_hwflags, COM_HW_FIFO))
992 1.113.2.2 thorpej sc->sc_fifo = FIFO_ENABLE |
993 1.113.2.2 thorpej (t->c_ospeed <= 1200 ? FIFO_TRIGGER_1 :
994 1.113.2.2 thorpej t->c_ospeed <= 38400 ? FIFO_TRIGGER_8 : FIFO_TRIGGER_4);
995 1.113.2.2 thorpej else
996 1.113.2.2 thorpej sc->sc_fifo = 0;
997 1.113.2.2 thorpej
998 1.113.2.2 thorpej /* and copy to tty */
999 1.113.2.2 thorpej tp->t_ispeed = 0;
1000 1.113.2.2 thorpej tp->t_ospeed = t->c_ospeed;
1001 1.113.2.2 thorpej tp->t_cflag = t->c_cflag;
1002 1.113.2.2 thorpej
1003 1.113.2.2 thorpej if (!sc->sc_heldchange) {
1004 1.113.2.2 thorpej if (sc->sc_tx_busy) {
1005 1.113.2.2 thorpej sc->sc_heldtbc = sc->sc_tbc;
1006 1.113.2.2 thorpej sc->sc_tbc = 0;
1007 1.113.2.2 thorpej sc->sc_heldchange = 1;
1008 1.113.2.2 thorpej } else
1009 1.113.2.2 thorpej com_loadchannelregs(sc);
1010 1.113.2.2 thorpej }
1011 1.113.2.2 thorpej
1012 1.113.2.2 thorpej splx(s);
1013 1.113.2.2 thorpej
1014 1.113.2.2 thorpej /*
1015 1.113.2.2 thorpej * Update the tty layer's idea of the carrier bit, in case we changed
1016 1.113.2.2 thorpej * CLOCAL or MDMBUF. We don't hang up here; we only do that if we
1017 1.113.2.2 thorpej * lose carrier while carrier detection is on.
1018 1.113.2.2 thorpej */
1019 1.113.2.2 thorpej (void) (*linesw[tp->t_line].l_modem)(tp, ISSET(sc->sc_msr, MSR_DCD));
1020 1.113.2.2 thorpej
1021 1.113.2.2 thorpej #ifdef COM_DEBUG
1022 1.113.2.2 thorpej if (com_debug)
1023 1.113.2.2 thorpej comstatus(sc, "comparam ");
1024 1.113.2.2 thorpej #endif
1025 1.113.2.2 thorpej
1026 1.113.2.2 thorpej /* Block or unblock as needed. */
1027 1.113.2.2 thorpej if (!ISSET(t->c_cflag, CHWFLOW)) {
1028 1.113.2.2 thorpej if (ISSET(sc->sc_rx_flags, RX_TTY_OVERFLOWED)) {
1029 1.113.2.2 thorpej CLR(sc->sc_rx_flags, RX_TTY_OVERFLOWED);
1030 1.113.2.2 thorpej com_schedrx(sc);
1031 1.113.2.2 thorpej }
1032 1.113.2.2 thorpej if (ISSET(sc->sc_rx_flags, RX_TTY_BLOCKED|RX_IBUF_BLOCKED)) {
1033 1.113.2.2 thorpej CLR(sc->sc_rx_flags, RX_TTY_BLOCKED|RX_IBUF_BLOCKED);
1034 1.113.2.2 thorpej com_hwiflow(sc);
1035 1.113.2.2 thorpej }
1036 1.113.2.2 thorpej if (sc->sc_tx_stopped) {
1037 1.113.2.2 thorpej sc->sc_tx_stopped = 0;
1038 1.113.2.2 thorpej comstart(tp);
1039 1.113.2.2 thorpej }
1040 1.113.2.2 thorpej } else {
1041 1.113.2.2 thorpej /* XXXXX FIX ME */
1042 1.113.2.2 thorpej #if 0
1043 1.113.2.2 thorpej commsrint(sc, tp);
1044 1.113.2.2 thorpej #endif
1045 1.113.2.2 thorpej }
1046 1.113.2.2 thorpej
1047 1.113.2.2 thorpej return (0);
1048 1.113.2.2 thorpej }
1049 1.113.2.2 thorpej
1050 1.113.2.2 thorpej void
1051 1.113.2.2 thorpej com_iflush(sc)
1052 1.113.2.2 thorpej struct com_softc *sc;
1053 1.113.2.2 thorpej {
1054 1.113.2.2 thorpej bus_space_tag_t iot = sc->sc_iot;
1055 1.113.2.2 thorpej bus_space_handle_t ioh = sc->sc_ioh;
1056 1.113.2.2 thorpej
1057 1.113.2.2 thorpej /* flush any pending I/O */
1058 1.113.2.2 thorpej while (ISSET(bus_space_read_1(iot, ioh, com_lsr), LSR_RXRDY))
1059 1.113.2.2 thorpej (void) bus_space_read_1(iot, ioh, com_data);
1060 1.113.2.2 thorpej }
1061 1.113.2.2 thorpej
1062 1.113.2.2 thorpej void
1063 1.113.2.2 thorpej com_loadchannelregs(sc)
1064 1.113.2.2 thorpej struct com_softc *sc;
1065 1.113.2.2 thorpej {
1066 1.113.2.2 thorpej bus_space_tag_t iot = sc->sc_iot;
1067 1.113.2.2 thorpej bus_space_handle_t ioh = sc->sc_ioh;
1068 1.113.2.2 thorpej
1069 1.113.2.2 thorpej /* XXXXX necessary? */
1070 1.113.2.2 thorpej com_iflush(sc);
1071 1.113.2.2 thorpej
1072 1.113.2.2 thorpej bus_space_write_1(iot, ioh, com_ier, 0);
1073 1.113.2.2 thorpej
1074 1.113.2.2 thorpej bus_space_write_1(iot, ioh, com_lcr, sc->sc_lcr | LCR_DLAB);
1075 1.113.2.2 thorpej bus_space_write_1(iot, ioh, com_dlbl, sc->sc_dlbl);
1076 1.113.2.2 thorpej bus_space_write_1(iot, ioh, com_dlbh, sc->sc_dlbh);
1077 1.113.2.2 thorpej bus_space_write_1(iot, ioh, com_lcr, sc->sc_lcr);
1078 1.113.2.2 thorpej bus_space_write_1(iot, ioh, com_mcr, sc->sc_mcr_active = sc->sc_mcr);
1079 1.113.2.2 thorpej bus_space_write_1(iot, ioh, com_fifo, sc->sc_fifo);
1080 1.113.2.2 thorpej
1081 1.113.2.2 thorpej bus_space_write_1(iot, ioh, com_ier, sc->sc_ier);
1082 1.113.2.2 thorpej }
1083 1.113.2.2 thorpej
1084 1.113.2.2 thorpej int
1085 1.113.2.2 thorpej comhwiflow(tp, block)
1086 1.113.2.2 thorpej struct tty *tp;
1087 1.113.2.2 thorpej int block;
1088 1.113.2.2 thorpej {
1089 1.113.2.2 thorpej struct com_softc *sc = com_cd.cd_devs[COMUNIT(tp->t_dev)];
1090 1.113.2.2 thorpej int s;
1091 1.113.2.2 thorpej
1092 1.113.2.2 thorpej if (sc->sc_mcr_rts == 0)
1093 1.113.2.2 thorpej return (0);
1094 1.113.2.2 thorpej
1095 1.113.2.2 thorpej s = splserial();
1096 1.113.2.2 thorpej if (block) {
1097 1.113.2.2 thorpej if (!ISSET(sc->sc_rx_flags, RX_TTY_BLOCKED)) {
1098 1.113.2.2 thorpej SET(sc->sc_rx_flags, RX_TTY_BLOCKED);
1099 1.113.2.2 thorpej com_hwiflow(sc);
1100 1.113.2.2 thorpej }
1101 1.113.2.2 thorpej } else {
1102 1.113.2.2 thorpej if (ISSET(sc->sc_rx_flags, RX_TTY_OVERFLOWED)) {
1103 1.113.2.2 thorpej CLR(sc->sc_rx_flags, RX_TTY_OVERFLOWED);
1104 1.113.2.2 thorpej com_schedrx(sc);
1105 1.113.2.2 thorpej }
1106 1.113.2.2 thorpej if (ISSET(sc->sc_rx_flags, RX_TTY_BLOCKED)) {
1107 1.113.2.2 thorpej CLR(sc->sc_rx_flags, RX_TTY_BLOCKED);
1108 1.113.2.2 thorpej com_hwiflow(sc);
1109 1.113.2.2 thorpej }
1110 1.113.2.2 thorpej }
1111 1.113.2.2 thorpej splx(s);
1112 1.113.2.2 thorpej return (1);
1113 1.113.2.2 thorpej }
1114 1.113.2.2 thorpej
1115 1.113.2.2 thorpej /*
1116 1.113.2.2 thorpej * (un)block input via hw flowcontrol
1117 1.113.2.2 thorpej */
1118 1.113.2.2 thorpej void
1119 1.113.2.2 thorpej com_hwiflow(sc)
1120 1.113.2.2 thorpej struct com_softc *sc;
1121 1.113.2.2 thorpej {
1122 1.113.2.2 thorpej bus_space_tag_t iot = sc->sc_iot;
1123 1.113.2.2 thorpej bus_space_handle_t ioh = sc->sc_ioh;
1124 1.113.2.2 thorpej
1125 1.113.2.2 thorpej if (sc->sc_mcr_rts == 0)
1126 1.113.2.2 thorpej return;
1127 1.113.2.2 thorpej
1128 1.113.2.2 thorpej if (ISSET(sc->sc_rx_flags, RX_ANY_BLOCK)) {
1129 1.113.2.2 thorpej CLR(sc->sc_mcr, sc->sc_mcr_rts);
1130 1.113.2.2 thorpej CLR(sc->sc_mcr_active, sc->sc_mcr_rts);
1131 1.113.2.2 thorpej } else {
1132 1.113.2.2 thorpej SET(sc->sc_mcr, sc->sc_mcr_rts);
1133 1.113.2.2 thorpej SET(sc->sc_mcr_active, sc->sc_mcr_rts);
1134 1.113.2.2 thorpej }
1135 1.113.2.2 thorpej bus_space_write_1(iot, ioh, com_mcr, sc->sc_mcr_active);
1136 1.113.2.2 thorpej }
1137 1.113.2.2 thorpej
1138 1.113.2.2 thorpej
1139 1.113.2.2 thorpej void
1140 1.113.2.2 thorpej comstart(tp)
1141 1.113.2.2 thorpej struct tty *tp;
1142 1.113.2.2 thorpej {
1143 1.113.2.2 thorpej struct com_softc *sc = com_cd.cd_devs[COMUNIT(tp->t_dev)];
1144 1.113.2.2 thorpej bus_space_tag_t iot = sc->sc_iot;
1145 1.113.2.2 thorpej bus_space_handle_t ioh = sc->sc_ioh;
1146 1.113.2.2 thorpej int s;
1147 1.113.2.2 thorpej
1148 1.113.2.2 thorpej s = spltty();
1149 1.113.2.2 thorpej if (ISSET(tp->t_state, TS_BUSY))
1150 1.113.2.2 thorpej goto out;
1151 1.113.2.2 thorpej if (ISSET(tp->t_state, TS_TIMEOUT | TS_TTSTOP))
1152 1.113.2.2 thorpej goto stopped;
1153 1.113.2.2 thorpej
1154 1.113.2.2 thorpej if (sc->sc_tx_stopped)
1155 1.113.2.2 thorpej goto stopped;
1156 1.113.2.2 thorpej
1157 1.113.2.2 thorpej if (tp->t_outq.c_cc <= tp->t_lowat) {
1158 1.113.2.2 thorpej if (ISSET(tp->t_state, TS_ASLEEP)) {
1159 1.113.2.2 thorpej CLR(tp->t_state, TS_ASLEEP);
1160 1.113.2.2 thorpej wakeup(&tp->t_outq);
1161 1.113.2.2 thorpej }
1162 1.113.2.2 thorpej selwakeup(&tp->t_wsel);
1163 1.113.2.2 thorpej if (tp->t_outq.c_cc == 0)
1164 1.113.2.2 thorpej goto stopped;
1165 1.113.2.2 thorpej }
1166 1.113.2.2 thorpej
1167 1.113.2.2 thorpej /* Grab the first contiguous region of buffer space. */
1168 1.113.2.2 thorpej {
1169 1.113.2.2 thorpej u_char *tba;
1170 1.113.2.2 thorpej int tbc;
1171 1.113.2.2 thorpej
1172 1.113.2.2 thorpej tba = tp->t_outq.c_cf;
1173 1.113.2.2 thorpej tbc = ndqb(&tp->t_outq, 0);
1174 1.113.2.2 thorpej
1175 1.113.2.2 thorpej (void)splserial();
1176 1.113.2.2 thorpej
1177 1.113.2.2 thorpej sc->sc_tba = tba;
1178 1.113.2.2 thorpej sc->sc_tbc = tbc;
1179 1.113.2.2 thorpej }
1180 1.113.2.2 thorpej
1181 1.113.2.2 thorpej SET(tp->t_state, TS_BUSY);
1182 1.113.2.2 thorpej sc->sc_tx_busy = 1;
1183 1.113.2.2 thorpej
1184 1.113.2.2 thorpej /* Enable transmit completion interrupts if necessary. */
1185 1.113.2.2 thorpej if (!ISSET(sc->sc_ier, IER_ETXRDY)) {
1186 1.113.2.2 thorpej SET(sc->sc_ier, IER_ETXRDY);
1187 1.113.2.2 thorpej bus_space_write_1(iot, ioh, com_ier, sc->sc_ier);
1188 1.113.2.2 thorpej }
1189 1.113.2.2 thorpej
1190 1.113.2.2 thorpej /* Output the first chunk of the contiguous buffer. */
1191 1.113.2.2 thorpej {
1192 1.113.2.2 thorpej int n;
1193 1.113.2.2 thorpej
1194 1.113.2.2 thorpej n = sc->sc_fifolen;
1195 1.113.2.2 thorpej if (n > sc->sc_tbc)
1196 1.113.2.2 thorpej n = sc->sc_tbc;
1197 1.113.2.2 thorpej bus_space_write_multi_1(iot, ioh, com_data, sc->sc_tba, n);
1198 1.113.2.2 thorpej sc->sc_tbc -= n;
1199 1.113.2.2 thorpej sc->sc_tba += n;
1200 1.113.2.2 thorpej }
1201 1.113.2.2 thorpej splx(s);
1202 1.113.2.2 thorpej return;
1203 1.113.2.2 thorpej
1204 1.113.2.2 thorpej stopped:
1205 1.113.2.2 thorpej /* Disable transmit completion interrupts if necessary. */
1206 1.113.2.2 thorpej if (ISSET(sc->sc_ier, IER_ETXRDY)) {
1207 1.113.2.2 thorpej CLR(sc->sc_ier, IER_ETXRDY);
1208 1.113.2.2 thorpej bus_space_write_1(iot, ioh, com_ier, sc->sc_ier);
1209 1.113.2.2 thorpej }
1210 1.113.2.2 thorpej out:
1211 1.113.2.2 thorpej splx(s);
1212 1.113.2.2 thorpej return;
1213 1.113.2.2 thorpej }
1214 1.113.2.2 thorpej
1215 1.113.2.2 thorpej /*
1216 1.113.2.2 thorpej * Stop output on a line.
1217 1.113.2.2 thorpej */
1218 1.113.2.2 thorpej void
1219 1.113.2.2 thorpej comstop(tp, flag)
1220 1.113.2.2 thorpej struct tty *tp;
1221 1.113.2.2 thorpej int flag;
1222 1.113.2.2 thorpej {
1223 1.113.2.2 thorpej struct com_softc *sc = com_cd.cd_devs[COMUNIT(tp->t_dev)];
1224 1.113.2.2 thorpej int s;
1225 1.113.2.2 thorpej
1226 1.113.2.2 thorpej s = splserial();
1227 1.113.2.2 thorpej if (ISSET(tp->t_state, TS_BUSY)) {
1228 1.113.2.2 thorpej /* Stop transmitting at the next chunk. */
1229 1.113.2.2 thorpej sc->sc_tbc = 0;
1230 1.113.2.2 thorpej sc->sc_heldtbc = 0;
1231 1.113.2.2 thorpej if (!ISSET(tp->t_state, TS_TTSTOP))
1232 1.113.2.2 thorpej SET(tp->t_state, TS_FLUSH);
1233 1.113.2.2 thorpej }
1234 1.113.2.2 thorpej splx(s);
1235 1.113.2.2 thorpej }
1236 1.113.2.2 thorpej
1237 1.113.2.2 thorpej void
1238 1.113.2.2 thorpej comdiag(arg)
1239 1.113.2.2 thorpej void *arg;
1240 1.113.2.2 thorpej {
1241 1.113.2.2 thorpej struct com_softc *sc = arg;
1242 1.113.2.2 thorpej int overflows, floods;
1243 1.113.2.2 thorpej int s;
1244 1.113.2.2 thorpej
1245 1.113.2.2 thorpej s = splserial();
1246 1.113.2.2 thorpej overflows = sc->sc_overflows;
1247 1.113.2.2 thorpej sc->sc_overflows = 0;
1248 1.113.2.2 thorpej floods = sc->sc_floods;
1249 1.113.2.2 thorpej sc->sc_floods = 0;
1250 1.113.2.2 thorpej sc->sc_errors = 0;
1251 1.113.2.2 thorpej splx(s);
1252 1.113.2.2 thorpej
1253 1.113.2.2 thorpej log(LOG_WARNING,
1254 1.113.2.2 thorpej "%s: %d silo overflow%s, %d ibuf flood%s\n",
1255 1.113.2.2 thorpej sc->sc_dev.dv_xname,
1256 1.113.2.2 thorpej overflows, overflows == 1 ? "" : "s",
1257 1.113.2.2 thorpej floods, floods == 1 ? "" : "s");
1258 1.113.2.2 thorpej }
1259 1.113.2.2 thorpej
1260 1.113.2.2 thorpej integrate void
1261 1.113.2.2 thorpej comrxint(sc, tp)
1262 1.113.2.2 thorpej struct com_softc *sc;
1263 1.113.2.2 thorpej struct tty *tp;
1264 1.113.2.2 thorpej {
1265 1.113.2.2 thorpej u_int get, cc, scc;
1266 1.113.2.2 thorpej int code;
1267 1.113.2.2 thorpej u_char lsr;
1268 1.113.2.2 thorpej int s;
1269 1.113.2.2 thorpej static int lsrmap[8] = {
1270 1.113.2.2 thorpej 0, TTY_PE,
1271 1.113.2.2 thorpej TTY_FE, TTY_PE|TTY_FE,
1272 1.113.2.2 thorpej TTY_FE, TTY_PE|TTY_FE,
1273 1.113.2.2 thorpej TTY_FE, TTY_PE|TTY_FE
1274 1.113.2.2 thorpej };
1275 1.113.2.2 thorpej
1276 1.113.2.2 thorpej get = sc->sc_rbget;
1277 1.113.2.2 thorpej scc = cc = RXBUFSIZE - sc->sc_rbavail;
1278 1.113.2.2 thorpej
1279 1.113.2.2 thorpej if (cc == RXBUFSIZE) {
1280 1.113.2.2 thorpej sc->sc_floods++;
1281 1.113.2.2 thorpej if (sc->sc_errors++ == 0)
1282 1.113.2.2 thorpej timeout(comdiag, sc, 60 * hz);
1283 1.113.2.2 thorpej }
1284 1.113.2.2 thorpej
1285 1.113.2.2 thorpej while (cc) {
1286 1.113.2.2 thorpej lsr = sc->sc_lbuf[get];
1287 1.113.2.2 thorpej if (ISSET(lsr, LSR_OE)) {
1288 1.113.2.2 thorpej sc->sc_overflows++;
1289 1.113.2.2 thorpej if (sc->sc_errors++ == 0)
1290 1.113.2.2 thorpej timeout(comdiag, sc, 60 * hz);
1291 1.113.2.2 thorpej }
1292 1.113.2.2 thorpej code = sc->sc_rbuf[get] |
1293 1.113.2.2 thorpej lsrmap[(lsr & (LSR_BI|LSR_FE|LSR_PE)) >> 2];
1294 1.113.2.2 thorpej if ((*linesw[tp->t_line].l_rint)(code, tp) == -1) {
1295 1.113.2.2 thorpej /*
1296 1.113.2.2 thorpej * The line discipline's buffer is out of space.
1297 1.113.2.2 thorpej */
1298 1.113.2.2 thorpej if (!ISSET(sc->sc_rx_flags, RX_TTY_BLOCKED)) {
1299 1.113.2.2 thorpej /*
1300 1.113.2.2 thorpej * We're either not using flow control, or the
1301 1.113.2.2 thorpej * line discipline didn't tell us to block for
1302 1.113.2.2 thorpej * some reason. Either way, we have no way to
1303 1.113.2.2 thorpej * know when there's more space available, so
1304 1.113.2.2 thorpej * just drop the rest of the data.
1305 1.113.2.2 thorpej */
1306 1.113.2.2 thorpej get = (get + cc) & RXBUFMASK;
1307 1.113.2.2 thorpej cc = 0;
1308 1.113.2.2 thorpej } else {
1309 1.113.2.2 thorpej /*
1310 1.113.2.2 thorpej * Don't schedule any more receive processing
1311 1.113.2.2 thorpej * until the line discipline tells us there's
1312 1.113.2.2 thorpej * space available (through comhwiflow()).
1313 1.113.2.2 thorpej * Leave the rest of the data in the input
1314 1.113.2.2 thorpej * buffer.
1315 1.113.2.2 thorpej */
1316 1.113.2.2 thorpej SET(sc->sc_rx_flags, RX_TTY_OVERFLOWED);
1317 1.113.2.2 thorpej }
1318 1.113.2.2 thorpej break;
1319 1.113.2.2 thorpej }
1320 1.113.2.2 thorpej get = (get + 1) & RXBUFMASK;
1321 1.113.2.2 thorpej cc--;
1322 1.113.2.2 thorpej }
1323 1.113.2.2 thorpej
1324 1.113.2.2 thorpej if (cc != scc) {
1325 1.113.2.2 thorpej sc->sc_rbget = get;
1326 1.113.2.2 thorpej s = splserial();
1327 1.113.2.2 thorpej cc = sc->sc_rbavail += scc - cc;
1328 1.113.2.2 thorpej /* Buffers should be ok again, release possible block. */
1329 1.113.2.2 thorpej if (cc >= sc->sc_r_lowat) {
1330 1.113.2.2 thorpej if (ISSET(sc->sc_rx_flags, RX_IBUF_OVERFLOWED)) {
1331 1.113.2.2 thorpej CLR(sc->sc_rx_flags, RX_IBUF_OVERFLOWED);
1332 1.113.2.2 thorpej SET(sc->sc_ier, IER_ERXRDY);
1333 1.113.2.2 thorpej bus_space_write_1(sc->sc_iot, sc->sc_ioh, com_ier, sc->sc_ier);
1334 1.113.2.2 thorpej }
1335 1.113.2.2 thorpej if (ISSET(sc->sc_rx_flags, RX_IBUF_BLOCKED)) {
1336 1.113.2.2 thorpej CLR(sc->sc_rx_flags, RX_IBUF_BLOCKED);
1337 1.113.2.2 thorpej com_hwiflow(sc);
1338 1.113.2.2 thorpej }
1339 1.113.2.2 thorpej }
1340 1.113.2.2 thorpej splx(s);
1341 1.113.2.2 thorpej }
1342 1.113.2.2 thorpej }
1343 1.113.2.2 thorpej
1344 1.113.2.2 thorpej integrate void
1345 1.113.2.2 thorpej comtxint(sc, tp)
1346 1.113.2.2 thorpej struct com_softc *sc;
1347 1.113.2.2 thorpej struct tty *tp;
1348 1.113.2.2 thorpej {
1349 1.113.2.2 thorpej
1350 1.113.2.2 thorpej CLR(tp->t_state, TS_BUSY);
1351 1.113.2.2 thorpej if (ISSET(tp->t_state, TS_FLUSH))
1352 1.113.2.2 thorpej CLR(tp->t_state, TS_FLUSH);
1353 1.113.2.2 thorpej else
1354 1.113.2.2 thorpej ndflush(&tp->t_outq, (int)(sc->sc_tba - tp->t_outq.c_cf));
1355 1.113.2.2 thorpej (*linesw[tp->t_line].l_start)(tp);
1356 1.113.2.2 thorpej }
1357 1.113.2.2 thorpej
1358 1.113.2.2 thorpej integrate void
1359 1.113.2.2 thorpej commsrint(sc, tp)
1360 1.113.2.2 thorpej struct com_softc *sc;
1361 1.113.2.2 thorpej struct tty *tp;
1362 1.113.2.2 thorpej {
1363 1.113.2.2 thorpej u_char msr, delta;
1364 1.113.2.2 thorpej int s;
1365 1.113.2.2 thorpej
1366 1.113.2.2 thorpej s = splserial();
1367 1.113.2.2 thorpej msr = sc->sc_msr;
1368 1.113.2.2 thorpej delta = sc->sc_msr_delta;
1369 1.113.2.2 thorpej sc->sc_msr_delta = 0;
1370 1.113.2.2 thorpej splx(s);
1371 1.113.2.2 thorpej
1372 1.113.2.2 thorpej if (ISSET(delta, sc->sc_msr_dcd)) {
1373 1.113.2.2 thorpej /*
1374 1.113.2.2 thorpej * Inform the tty layer that carrier detect changed.
1375 1.113.2.2 thorpej */
1376 1.113.2.2 thorpej (void) (*linesw[tp->t_line].l_modem)(tp, ISSET(msr, MSR_DCD));
1377 1.113.2.2 thorpej }
1378 1.113.2.2 thorpej
1379 1.113.2.2 thorpej if (ISSET(delta, sc->sc_msr_cts)) {
1380 1.113.2.2 thorpej /* Block or unblock output according to flow control. */
1381 1.113.2.2 thorpej if (ISSET(msr, sc->sc_msr_cts)) {
1382 1.113.2.2 thorpej sc->sc_tx_stopped = 0;
1383 1.113.2.2 thorpej (*linesw[tp->t_line].l_start)(tp);
1384 1.113.2.2 thorpej } else {
1385 1.113.2.2 thorpej sc->sc_tx_stopped = 1;
1386 1.113.2.2 thorpej }
1387 1.113.2.2 thorpej }
1388 1.113.2.2 thorpej
1389 1.113.2.2 thorpej #ifdef COM_DEBUG
1390 1.113.2.2 thorpej if (com_debug)
1391 1.113.2.2 thorpej comstatus(sc, "commsrint");
1392 1.113.2.2 thorpej #endif
1393 1.113.2.2 thorpej }
1394 1.113.2.2 thorpej
1395 1.113.2.2 thorpej #ifdef __GENERIC_SOFT_INTERRUPTS
1396 1.113.2.2 thorpej void
1397 1.113.2.2 thorpej comsoft(arg)
1398 1.113.2.2 thorpej void *arg;
1399 1.113.2.2 thorpej {
1400 1.113.2.2 thorpej struct com_softc *sc = arg;
1401 1.113.2.2 thorpej struct tty *tp;
1402 1.113.2.2 thorpej
1403 1.113.2.2 thorpej {
1404 1.113.2.2 thorpej #else
1405 1.113.2.2 thorpej void
1406 1.113.2.2 thorpej #ifndef alpha
1407 1.113.2.2 thorpej comsoft()
1408 1.113.2.2 thorpej #else
1409 1.113.2.2 thorpej comsoft(arg)
1410 1.113.2.2 thorpej void *arg;
1411 1.113.2.2 thorpej #endif
1412 1.113.2.2 thorpej {
1413 1.113.2.2 thorpej struct com_softc *sc;
1414 1.113.2.2 thorpej struct tty *tp;
1415 1.113.2.2 thorpej int unit;
1416 1.113.2.2 thorpej #ifdef alpha
1417 1.113.2.2 thorpej int s;
1418 1.113.2.2 thorpej
1419 1.113.2.2 thorpej s = splsoftserial();
1420 1.113.2.2 thorpej com_softintr_scheduled = 0;
1421 1.113.2.2 thorpej #endif
1422 1.113.2.2 thorpej
1423 1.113.2.2 thorpej for (unit = 0; unit < com_cd.cd_ndevs; unit++) {
1424 1.113.2.2 thorpej sc = com_cd.cd_devs[unit];
1425 1.113.2.2 thorpej if (sc == NULL)
1426 1.113.2.2 thorpej continue;
1427 1.113.2.2 thorpej
1428 1.113.2.2 thorpej tp = sc->sc_tty;
1429 1.113.2.2 thorpej if (tp == NULL || !ISSET(tp->t_state, TS_ISOPEN | TS_WOPEN))
1430 1.113.2.2 thorpej continue;
1431 1.113.2.2 thorpej #endif
1432 1.113.2.2 thorpej tp = sc->sc_tty;
1433 1.113.2.2 thorpej
1434 1.113.2.2 thorpej if (sc->sc_rx_ready) {
1435 1.113.2.2 thorpej sc->sc_rx_ready = 0;
1436 1.113.2.2 thorpej comrxint(sc, tp);
1437 1.113.2.2 thorpej }
1438 1.113.2.2 thorpej
1439 1.113.2.2 thorpej if (sc->sc_st_check) {
1440 1.113.2.2 thorpej sc->sc_st_check = 0;
1441 1.113.2.2 thorpej commsrint(sc, tp);
1442 1.113.2.2 thorpej }
1443 1.113.2.2 thorpej
1444 1.113.2.2 thorpej if (sc->sc_tx_done) {
1445 1.113.2.2 thorpej sc->sc_tx_done = 0;
1446 1.113.2.2 thorpej comtxint(sc, tp);
1447 1.113.2.2 thorpej }
1448 1.113.2.2 thorpej }
1449 1.113.2.2 thorpej
1450 1.113.2.2 thorpej #ifndef __GENERIC_SOFT_INTERRUPTS
1451 1.113.2.2 thorpej #ifdef alpha
1452 1.113.2.2 thorpej splx(s);
1453 1.113.2.2 thorpej #endif
1454 1.113.2.2 thorpej #endif
1455 1.113.2.2 thorpej }
1456 1.113.2.2 thorpej
1457 1.113.2.2 thorpej int
1458 1.113.2.2 thorpej comintr(arg)
1459 1.113.2.2 thorpej void *arg;
1460 1.113.2.2 thorpej {
1461 1.113.2.2 thorpej struct com_softc *sc = arg;
1462 1.113.2.2 thorpej bus_space_tag_t iot = sc->sc_iot;
1463 1.113.2.2 thorpej bus_space_handle_t ioh = sc->sc_ioh;
1464 1.113.2.2 thorpej u_char lsr, iir;
1465 1.113.2.2 thorpej u_int put, cc;
1466 1.113.2.2 thorpej
1467 1.113.2.2 thorpej iir = bus_space_read_1(iot, ioh, com_iir);
1468 1.113.2.2 thorpej if (ISSET(iir, IIR_NOPEND))
1469 1.113.2.2 thorpej return (0);
1470 1.113.2.2 thorpej
1471 1.113.2.2 thorpej put = sc->sc_rbput;
1472 1.113.2.2 thorpej cc = sc->sc_rbavail;
1473 1.113.2.2 thorpej
1474 1.113.2.2 thorpej do {
1475 1.113.2.2 thorpej u_char msr, delta;
1476 1.113.2.2 thorpej
1477 1.113.2.2 thorpej lsr = bus_space_read_1(iot, ioh, com_lsr);
1478 1.113.2.2 thorpej #if defined(DDB) || defined(KGDB)
1479 1.113.2.2 thorpej if (ISSET(lsr, LSR_BI)) {
1480 1.113.2.2 thorpej #ifdef DDB
1481 1.113.2.2 thorpej if (ISSET(sc->sc_hwflags, COM_HW_CONSOLE)) {
1482 1.113.2.2 thorpej Debugger();
1483 1.113.2.2 thorpej continue;
1484 1.113.2.2 thorpej }
1485 1.113.2.2 thorpej #endif
1486 1.113.2.2 thorpej #ifdef KGDB
1487 1.113.2.2 thorpej if (ISSET(sc->sc_hwflags, COM_HW_KGDB)) {
1488 1.113.2.2 thorpej kgdb_connect(1);
1489 1.113.2.2 thorpej continue;
1490 1.113.2.2 thorpej }
1491 1.113.2.2 thorpej #endif
1492 1.113.2.2 thorpej }
1493 1.113.2.2 thorpej #endif /* DDB || KGDB */
1494 1.113.2.2 thorpej
1495 1.113.2.2 thorpej if (ISSET(lsr, LSR_RCV_MASK) &&
1496 1.113.2.2 thorpej !ISSET(sc->sc_rx_flags, RX_IBUF_OVERFLOWED)) {
1497 1.113.2.2 thorpej for (; ISSET(lsr, LSR_RCV_MASK) && cc > 0; cc--) {
1498 1.113.2.2 thorpej sc->sc_rbuf[put] =
1499 1.113.2.2 thorpej bus_space_read_1(iot, ioh, com_data);
1500 1.113.2.2 thorpej sc->sc_lbuf[put] = lsr;
1501 1.113.2.2 thorpej put = (put + 1) & RXBUFMASK;
1502 1.113.2.2 thorpej lsr = bus_space_read_1(iot, ioh, com_lsr);
1503 1.113.2.2 thorpej }
1504 1.113.2.2 thorpej /*
1505 1.113.2.2 thorpej * Current string of incoming characters ended because
1506 1.113.2.2 thorpej * no more data was available. Schedule a receive event
1507 1.113.2.2 thorpej * if any data was received. Drop any characters that
1508 1.113.2.2 thorpej * we couldn't handle.
1509 1.113.2.2 thorpej */
1510 1.113.2.2 thorpej sc->sc_rbput = put;
1511 1.113.2.2 thorpej sc->sc_rbavail = cc;
1512 1.113.2.2 thorpej if (!ISSET(sc->sc_rx_flags, RX_TTY_OVERFLOWED))
1513 1.113.2.2 thorpej sc->sc_rx_ready = 1;
1514 1.113.2.2 thorpej /*
1515 1.113.2.2 thorpej * See if we are in danger of overflowing a buffer. If
1516 1.113.2.2 thorpej * so, use hardware flow control to ease the pressure.
1517 1.113.2.2 thorpej */
1518 1.113.2.2 thorpej if (!ISSET(sc->sc_rx_flags, RX_IBUF_BLOCKED) &&
1519 1.113.2.2 thorpej cc < sc->sc_r_hiwat) {
1520 1.113.2.2 thorpej SET(sc->sc_rx_flags, RX_IBUF_BLOCKED);
1521 1.113.2.2 thorpej com_hwiflow(sc);
1522 1.113.2.2 thorpej }
1523 1.113.2.2 thorpej /*
1524 1.113.2.2 thorpej * If we're out of space, disable receive interrupts
1525 1.113.2.2 thorpej * until the queue has drained a bit.
1526 1.113.2.2 thorpej */
1527 1.113.2.2 thorpej if (!cc) {
1528 1.113.2.2 thorpej SET(sc->sc_rx_flags, RX_IBUF_OVERFLOWED);
1529 1.113.2.2 thorpej CLR(sc->sc_ier, IER_ERXRDY);
1530 1.113.2.2 thorpej bus_space_write_1(iot, ioh, com_ier, sc->sc_ier);
1531 1.113.2.2 thorpej }
1532 1.113.2.2 thorpej } else {
1533 1.113.2.2 thorpej if ((iir & IIR_IMASK) == IIR_RXRDY) {
1534 1.113.2.2 thorpej bus_space_write_1(iot, ioh, com_ier, 0);
1535 1.113.2.2 thorpej delay(10);
1536 1.113.2.2 thorpej bus_space_write_1(iot, ioh, com_ier,sc->sc_ier);
1537 1.113.2.2 thorpej iir = IIR_NOPEND;
1538 1.113.2.2 thorpej continue;
1539 1.113.2.2 thorpej }
1540 1.113.2.2 thorpej }
1541 1.113.2.2 thorpej
1542 1.113.2.2 thorpej msr = bus_space_read_1(iot, ioh, com_msr);
1543 1.113.2.2 thorpej delta = msr ^ sc->sc_msr;
1544 1.113.2.2 thorpej sc->sc_msr = msr;
1545 1.113.2.2 thorpej if (ISSET(delta, sc->sc_msr_mask)) {
1546 1.113.2.2 thorpej sc->sc_msr_delta |= delta;
1547 1.113.2.2 thorpej
1548 1.113.2.2 thorpej /*
1549 1.113.2.2 thorpej * Stop output immediately if we lose the output
1550 1.113.2.2 thorpej * flow control signal or carrier detect.
1551 1.113.2.2 thorpej */
1552 1.113.2.2 thorpej if (ISSET(~msr, sc->sc_msr_mask)) {
1553 1.113.2.2 thorpej sc->sc_tbc = 0;
1554 1.113.2.2 thorpej sc->sc_heldtbc = 0;
1555 1.113.2.2 thorpej #ifdef COM_DEBUG
1556 1.113.2.2 thorpej if (com_debug)
1557 1.113.2.2 thorpej comstatus(sc, "comintr ");
1558 1.113.2.2 thorpej #endif
1559 1.113.2.2 thorpej }
1560 1.113.2.2 thorpej
1561 1.113.2.2 thorpej sc->sc_st_check = 1;
1562 1.113.2.2 thorpej }
1563 1.113.2.2 thorpej } while (!ISSET((iir = bus_space_read_1(iot, ioh, com_iir)), IIR_NOPEND));
1564 1.113.2.2 thorpej
1565 1.113.2.2 thorpej /*
1566 1.113.2.2 thorpej * Done handling any receive interrupts. See if data can be
1567 1.113.2.2 thorpej * transmitted as well. Schedule tx done event if no data left
1568 1.113.2.2 thorpej * and tty was marked busy.
1569 1.113.2.2 thorpej */
1570 1.113.2.2 thorpej if (ISSET(lsr, LSR_TXRDY)) {
1571 1.113.2.2 thorpej /*
1572 1.113.2.2 thorpej * If we've delayed a parameter change, do it now, and restart
1573 1.113.2.2 thorpej * output.
1574 1.113.2.2 thorpej */
1575 1.113.2.2 thorpej if (sc->sc_heldchange) {
1576 1.113.2.2 thorpej com_loadchannelregs(sc);
1577 1.113.2.2 thorpej sc->sc_heldchange = 0;
1578 1.113.2.2 thorpej sc->sc_tbc = sc->sc_heldtbc;
1579 1.113.2.2 thorpej sc->sc_heldtbc = 0;
1580 1.113.2.2 thorpej }
1581 1.113.2.2 thorpej /* Output the next chunk of the contiguous buffer, if any. */
1582 1.113.2.2 thorpej if (sc->sc_tbc > 0) {
1583 1.113.2.2 thorpej int n;
1584 1.113.2.2 thorpej
1585 1.113.2.2 thorpej n = sc->sc_fifolen;
1586 1.113.2.2 thorpej if (n > sc->sc_tbc)
1587 1.113.2.2 thorpej n = sc->sc_tbc;
1588 1.113.2.2 thorpej bus_space_write_multi_1(iot, ioh, com_data, sc->sc_tba, n);
1589 1.113.2.2 thorpej sc->sc_tbc -= n;
1590 1.113.2.2 thorpej sc->sc_tba += n;
1591 1.113.2.2 thorpej } else if (sc->sc_tx_busy) {
1592 1.113.2.2 thorpej sc->sc_tx_busy = 0;
1593 1.113.2.2 thorpej sc->sc_tx_done = 1;
1594 1.113.2.2 thorpej }
1595 1.113.2.2 thorpej }
1596 1.113.2.2 thorpej
1597 1.113.2.2 thorpej /* Wake up the poller. */
1598 1.113.2.2 thorpej #ifdef __GENERIC_SOFT_INTERRUPTS
1599 1.113.2.2 thorpej softintr_schedule(sc->sc_si);
1600 1.113.2.2 thorpej #else
1601 1.113.2.2 thorpej #ifndef alpha
1602 1.113.2.2 thorpej setsoftserial();
1603 1.113.2.2 thorpej #else
1604 1.113.2.2 thorpej if (!com_softintr_scheduled) {
1605 1.113.2.2 thorpej com_softintr_scheduled = 1;
1606 1.113.2.2 thorpej timeout(comsoft, NULL, 1);
1607 1.113.2.2 thorpej }
1608 1.113.2.2 thorpej #endif
1609 1.113.2.2 thorpej #endif
1610 1.113.2.2 thorpej return (1);
1611 1.113.2.2 thorpej }
1612 1.113.2.2 thorpej
1613 1.113.2.2 thorpej /*
1614 1.113.2.2 thorpej * The following functions are polled getc and putc routines, shared
1615 1.113.2.2 thorpej * by the console and kgdb glue.
1616 1.113.2.2 thorpej */
1617 1.113.2.2 thorpej
1618 1.113.2.2 thorpej int
1619 1.113.2.2 thorpej com_common_getc(iot, ioh)
1620 1.113.2.2 thorpej bus_space_tag_t iot;
1621 1.113.2.2 thorpej bus_space_handle_t ioh;
1622 1.113.2.2 thorpej {
1623 1.113.2.2 thorpej int s = splserial();
1624 1.113.2.2 thorpej u_char stat, c;
1625 1.113.2.2 thorpej
1626 1.113.2.2 thorpej while (!ISSET(stat = bus_space_read_1(iot, ioh, com_lsr), LSR_RXRDY))
1627 1.113.2.2 thorpej ;
1628 1.113.2.2 thorpej c = bus_space_read_1(iot, ioh, com_data);
1629 1.113.2.2 thorpej stat = bus_space_read_1(iot, ioh, com_iir);
1630 1.113.2.2 thorpej splx(s);
1631 1.113.2.2 thorpej return (c);
1632 1.113.2.2 thorpej }
1633 1.113.2.2 thorpej
1634 1.113.2.2 thorpej void
1635 1.113.2.2 thorpej com_common_putc(iot, ioh, c)
1636 1.113.2.2 thorpej bus_space_tag_t iot;
1637 1.113.2.2 thorpej bus_space_handle_t ioh;
1638 1.113.2.2 thorpej int c;
1639 1.113.2.2 thorpej {
1640 1.113.2.2 thorpej int s = splserial();
1641 1.113.2.2 thorpej u_char stat;
1642 1.113.2.2 thorpej register int timo;
1643 1.113.2.2 thorpej
1644 1.113.2.2 thorpej /* wait for any pending transmission to finish */
1645 1.113.2.2 thorpej timo = 50000;
1646 1.113.2.2 thorpej while (!ISSET(stat = bus_space_read_1(iot, ioh, com_lsr), LSR_TXRDY)
1647 1.113.2.2 thorpej && --timo)
1648 1.113.2.2 thorpej ;
1649 1.113.2.2 thorpej bus_space_write_1(iot, ioh, com_data, c);
1650 1.113.2.2 thorpej /* wait for this transmission to complete */
1651 1.113.2.2 thorpej timo = 1500000;
1652 1.113.2.2 thorpej while (!ISSET(stat = bus_space_read_1(iot, ioh, com_lsr), LSR_TXRDY)
1653 1.113.2.2 thorpej && --timo)
1654 1.113.2.2 thorpej ;
1655 1.113.2.2 thorpej /* clear any interrupts generated by this transmission */
1656 1.113.2.2 thorpej stat = bus_space_read_1(iot, ioh, com_iir);
1657 1.113.2.2 thorpej splx(s);
1658 1.113.2.2 thorpej }
1659 1.113.2.2 thorpej
1660 1.113.2.2 thorpej /*
1661 1.113.2.2 thorpej * Initialize UART to known state.
1662 1.113.2.2 thorpej */
1663 1.113.2.2 thorpej int
1664 1.113.2.2 thorpej cominit(iot, iobase, rate, frequency, cflag, iohp)
1665 1.113.2.2 thorpej bus_space_tag_t iot;
1666 1.113.2.2 thorpej int iobase;
1667 1.113.2.2 thorpej int rate, frequency;
1668 1.113.2.2 thorpej tcflag_t cflag;
1669 1.113.2.2 thorpej bus_space_handle_t *iohp;
1670 1.113.2.2 thorpej {
1671 1.113.2.2 thorpej bus_space_handle_t ioh;
1672 1.113.2.2 thorpej
1673 1.113.2.2 thorpej if (bus_space_map(iot, iobase, COM_NPORTS, 0, &ioh))
1674 1.113.2.2 thorpej return (ENOMEM); /* ??? */
1675 1.113.2.2 thorpej
1676 1.113.2.2 thorpej bus_space_write_1(iot, ioh, com_lcr, LCR_DLAB);
1677 1.113.2.2 thorpej rate = comspeed(rate, frequency);
1678 1.113.2.2 thorpej bus_space_write_1(iot, ioh, com_dlbl, rate);
1679 1.113.2.2 thorpej bus_space_write_1(iot, ioh, com_dlbh, rate >> 8);
1680 1.113.2.2 thorpej bus_space_write_1(iot, ioh, com_lcr, cflag2lcr(cflag));
1681 1.113.2.2 thorpej bus_space_write_1(iot, ioh, com_mcr, 0);
1682 1.113.2.2 thorpej bus_space_write_1(iot, ioh, com_fifo,
1683 1.113.2.2 thorpej FIFO_ENABLE | FIFO_RCV_RST | FIFO_XMT_RST | FIFO_TRIGGER_1);
1684 1.113.2.2 thorpej bus_space_write_1(iot, ioh, com_ier, 0);
1685 1.113.2.2 thorpej
1686 1.113.2.2 thorpej *iohp = ioh;
1687 1.113.2.2 thorpej return (0);
1688 1.113.2.2 thorpej }
1689 1.113.2.2 thorpej
1690 1.113.2.2 thorpej /*
1691 1.113.2.2 thorpej * Following are all routines needed for COM to act as console
1692 1.113.2.2 thorpej */
1693 1.113.2.2 thorpej
1694 1.113.2.2 thorpej int
1695 1.113.2.2 thorpej comcnattach(iot, iobase, rate, frequency, cflag)
1696 1.113.2.2 thorpej bus_space_tag_t iot;
1697 1.113.2.2 thorpej int iobase;
1698 1.113.2.2 thorpej int rate, frequency;
1699 1.113.2.2 thorpej tcflag_t cflag;
1700 1.113.2.2 thorpej {
1701 1.113.2.2 thorpej int res;
1702 1.113.2.2 thorpej static struct consdev comcons = { NULL, NULL,
1703 1.113.2.2 thorpej comcngetc, comcnputc, comcnpollc, NODEV, CN_NORMAL};
1704 1.113.2.2 thorpej
1705 1.113.2.2 thorpej res = cominit(iot, iobase, rate, frequency, cflag, &comconsioh);
1706 1.113.2.2 thorpej if (res)
1707 1.113.2.2 thorpej return (res);
1708 1.113.2.2 thorpej
1709 1.113.2.2 thorpej cn_tab = &comcons;
1710 1.113.2.2 thorpej
1711 1.113.2.2 thorpej comconstag = iot;
1712 1.113.2.2 thorpej comconsaddr = iobase;
1713 1.113.2.2 thorpej comconsrate = rate;
1714 1.113.2.2 thorpej comconscflag = cflag;
1715 1.113.2.2 thorpej
1716 1.113.2.2 thorpej return (0);
1717 1.113.2.2 thorpej }
1718 1.113.2.2 thorpej
1719 1.113.2.2 thorpej int
1720 1.113.2.2 thorpej comcngetc(dev)
1721 1.113.2.2 thorpej dev_t dev;
1722 1.113.2.2 thorpej {
1723 1.113.2.2 thorpej
1724 1.113.2.2 thorpej return (com_common_getc(comconstag, comconsioh));
1725 1.113.2.2 thorpej }
1726 1.113.2.2 thorpej
1727 1.113.2.2 thorpej /*
1728 1.113.2.2 thorpej * Console kernel output character routine.
1729 1.113.2.2 thorpej */
1730 1.113.2.2 thorpej void
1731 1.113.2.2 thorpej comcnputc(dev, c)
1732 1.113.2.2 thorpej dev_t dev;
1733 1.113.2.2 thorpej int c;
1734 1.113.2.2 thorpej {
1735 1.113.2.2 thorpej
1736 1.113.2.2 thorpej com_common_putc(comconstag, comconsioh, c);
1737 1.113.2.2 thorpej }
1738 1.113.2.2 thorpej
1739 1.113.2.2 thorpej void
1740 1.113.2.2 thorpej comcnpollc(dev, on)
1741 1.113.2.2 thorpej dev_t dev;
1742 1.113.2.2 thorpej int on;
1743 1.113.2.2 thorpej {
1744 1.113.2.2 thorpej
1745 1.113.2.2 thorpej }
1746 1.113.2.2 thorpej
1747 1.113.2.2 thorpej #ifdef KGDB
1748 1.113.2.2 thorpej int
1749 1.113.2.2 thorpej com_kgdb_attach(iot, iobase, rate, frequency, cflag)
1750 1.113.2.2 thorpej bus_space_tag_t iot;
1751 1.113.2.2 thorpej int iobase;
1752 1.113.2.2 thorpej int rate, frequency;
1753 1.113.2.2 thorpej tcflag_t cflag;
1754 1.113.2.2 thorpej {
1755 1.113.2.2 thorpej int res;
1756 1.113.2.2 thorpej
1757 1.113.2.2 thorpej if (iot == comconstag && iobase == comconsaddr)
1758 1.113.2.2 thorpej return (EBUSY); /* cannot share with console */
1759 1.113.2.2 thorpej
1760 1.113.2.2 thorpej res = cominit(iot, iobase, rate, frequency, cflag, &com_kgdb_ioh);
1761 1.113.2.2 thorpej if (res)
1762 1.113.2.2 thorpej return (res);
1763 1.113.2.2 thorpej
1764 1.113.2.2 thorpej kgdb_attach(com_kgdb_getc, com_kgdb_putc, NULL);
1765 1.113.2.2 thorpej kgdb_dev = 123; /* unneeded, only to satisfy some tests */
1766 1.113.2.2 thorpej
1767 1.113.2.2 thorpej com_kgdb_iot = iot;
1768 1.113.2.2 thorpej com_kgdb_addr = iobase;
1769 1.113.2.2 thorpej
1770 1.113.2.2 thorpej return (0);
1771 1.113.2.2 thorpej }
1772 1.113.2.2 thorpej
1773 1.113.2.2 thorpej /* ARGSUSED */
1774 1.113.2.2 thorpej int
1775 1.113.2.2 thorpej com_kgdb_getc(arg)
1776 1.113.2.2 thorpej void *arg;
1777 1.113.2.2 thorpej {
1778 1.113.2.2 thorpej
1779 1.113.2.2 thorpej return (com_common_getc(com_kgdb_iot, com_kgdb_ioh));
1780 1.113.2.2 thorpej }
1781 1.113.2.2 thorpej
1782 1.113.2.2 thorpej /* ARGSUSED */
1783 1.113.2.2 thorpej void
1784 1.113.2.2 thorpej com_kgdb_putc(arg, c)
1785 1.113.2.2 thorpej void *arg;
1786 1.113.2.2 thorpej int c;
1787 1.113.2.2 thorpej {
1788 1.113.2.2 thorpej
1789 1.113.2.2 thorpej return (com_common_putc(com_kgdb_iot, com_kgdb_ioh, c));
1790 1.113.2.2 thorpej }
1791 1.113.2.2 thorpej #endif /* KGDB */
1792 1.113.2.2 thorpej
1793 1.113.2.2 thorpej /* helper function to identify the com ports used by
1794 1.113.2.2 thorpej console or KGDB (and not yet autoconf attached) */
1795 1.113.2.2 thorpej int
1796 1.113.2.2 thorpej com_is_console(iot, iobase, ioh)
1797 1.113.2.2 thorpej bus_space_tag_t iot;
1798 1.113.2.2 thorpej int iobase;
1799 1.113.2.2 thorpej bus_space_handle_t *ioh;
1800 1.113.2.2 thorpej {
1801 1.113.2.2 thorpej bus_space_handle_t help;
1802 1.113.2.2 thorpej
1803 1.113.2.2 thorpej if (!comconsattached &&
1804 1.113.2.2 thorpej iot == comconstag && iobase == comconsaddr)
1805 1.113.2.2 thorpej help = comconsioh;
1806 1.113.2.2 thorpej #ifdef KGDB
1807 1.113.2.2 thorpej else if (!com_kgdb_attached &&
1808 1.113.2.2 thorpej iot == com_kgdb_iot && iobase == com_kgdb_addr)
1809 1.113.2.2 thorpej help = com_kgdb_ioh;
1810 1.113.2.2 thorpej #endif
1811 1.113.2.2 thorpej else
1812 1.113.2.2 thorpej return (0);
1813 1.113.2.2 thorpej
1814 1.113.2.2 thorpej if (ioh)
1815 1.113.2.2 thorpej *ioh = help;
1816 1.113.2.2 thorpej return (1);
1817 1.113.2.2 thorpej }
1818