Annotation of src/sys/dev/ic/com.c, Revision 1.151
1.151 ! mycroft 1: /* $NetBSD: com.c,v 1.150 1999/01/26 17:08:37 drochner Exp $ */
1.38 cgd 2:
1.1 cgd 3: /*-
1.146 mycroft 4: * Copyright (c) 1998 The NetBSD Foundation, Inc.
5: * All rights reserved.
1.99 mycroft 6: *
1.146 mycroft 7: * This code is derived from software contributed to The NetBSD Foundation
8: * by Charles M. Hannum.
1.99 mycroft 9: *
10: * Redistribution and use in source and binary forms, with or without
11: * modification, are permitted provided that the following conditions
12: * are met:
13: * 1. Redistributions of source code must retain the above copyright
14: * notice, this list of conditions and the following disclaimer.
15: * 2. Redistributions in binary form must reproduce the above copyright
16: * notice, this list of conditions and the following disclaimer in the
17: * documentation and/or other materials provided with the distribution.
18: * 3. All advertising materials mentioning features or use of this software
19: * must display the following acknowledgement:
1.146 mycroft 20: * This product includes software developed by the NetBSD
21: * Foundation, Inc. and its contributors.
22: * 4. Neither the name of The NetBSD Foundation nor the names of its
23: * contributors may be used to endorse or promote products derived
24: * from this software without specific prior written permission.
1.99 mycroft 25: *
1.146 mycroft 26: * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27: * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28: * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29: * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30: * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31: * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32: * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33: * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34: * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35: * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36: * POSSIBILITY OF SUCH DAMAGE.
1.99 mycroft 37: */
38:
39: /*
1.1 cgd 40: * Copyright (c) 1991 The Regents of the University of California.
41: * All rights reserved.
42: *
43: * Redistribution and use in source and binary forms, with or without
44: * modification, are permitted provided that the following conditions
45: * are met:
46: * 1. Redistributions of source code must retain the above copyright
47: * notice, this list of conditions and the following disclaimer.
48: * 2. Redistributions in binary form must reproduce the above copyright
49: * notice, this list of conditions and the following disclaimer in the
50: * documentation and/or other materials provided with the distribution.
51: * 3. All advertising materials mentioning features or use of this software
52: * must display the following acknowledgement:
53: * This product includes software developed by the University of
54: * California, Berkeley and its contributors.
55: * 4. Neither the name of the University nor the names of its contributors
56: * may be used to endorse or promote products derived from this software
57: * without specific prior written permission.
58: *
59: * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
60: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
61: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
62: * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
63: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
64: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
65: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
66: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
67: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
68: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
69: * SUCH DAMAGE.
70: *
1.38 cgd 71: * @(#)com.c 7.5 (Berkeley) 5/16/91
1.1 cgd 72: */
73:
74: /*
1.99 mycroft 75: * COM driver, uses National Semiconductor NS16450/NS16550AF UART
1.116 fvdl 76: * Supports automatic hardware flow control on StarTech ST16C650A UART
1.1 cgd 77: */
1.145 jonathan 78:
79: #include "opt_ddb.h"
1.115 explorer 80:
81: #include "rnd.h"
82: #if NRND > 0 && defined(RND_COM)
83: #include <sys/rnd.h>
84: #endif
85:
1.14 mycroft 86: #include <sys/param.h>
87: #include <sys/systm.h>
88: #include <sys/ioctl.h>
89: #include <sys/select.h>
90: #include <sys/tty.h>
91: #include <sys/proc.h>
92: #include <sys/user.h>
93: #include <sys/conf.h>
94: #include <sys/file.h>
95: #include <sys/uio.h>
96: #include <sys/kernel.h>
97: #include <sys/syslog.h>
98: #include <sys/types.h>
1.21 mycroft 99: #include <sys/device.h>
1.127 mycroft 100: #include <sys/malloc.h>
1.144 jonathan 101: #include <sys/timepps.h>
1.149 thorpej 102: #include <sys/vnode.h>
1.14 mycroft 103:
1.99 mycroft 104: #include <machine/intr.h>
1.82 mycroft 105: #include <machine/bus.h>
1.14 mycroft 106:
1.113 thorpej 107: #include <dev/ic/comreg.h>
108: #include <dev/ic/comvar.h>
1.60 cgd 109: #include <dev/ic/ns16550reg.h>
1.116 fvdl 110: #include <dev/ic/st16650reg.h>
1.65 christos 111: #ifdef COM_HAYESP
112: #include <dev/ic/hayespreg.h>
113: #endif
1.62 mycroft 114: #define com_lcr com_cfcr
1.106 drochner 115: #include <dev/cons.h>
1.14 mycroft 116:
1.77 cgd 117: #include "com.h"
118:
1.65 christos 119: #ifdef COM_HAYESP
1.99 mycroft 120: int comprobeHAYESP __P((bus_space_handle_t hayespioh, struct com_softc *sc));
1.65 christos 121: #endif
1.102 thorpej 122:
1.104 drochner 123: #if defined(DDB) || defined(KGDB)
124: static void com_enable_debugport __P((struct com_softc *));
125: #endif
1.99 mycroft 126: void com_attach_subr __P((struct com_softc *sc));
1.131 marc 127: void com_config __P((struct com_softc *));
1.141 mycroft 128: void com_shutdown __P((struct com_softc *));
1.109 is 129: int comspeed __P((long, long));
1.106 drochner 130: static u_char cflag2lcr __P((tcflag_t));
1.80 christos 131: int comparam __P((struct tty *, struct termios *));
132: void comstart __P((struct tty *));
1.99 mycroft 133: void comstop __P((struct tty *, int));
134: int comhwiflow __P((struct tty *, int));
135:
136: void com_loadchannelregs __P((struct com_softc *));
1.101 mycroft 137: void com_hwiflow __P((struct com_softc *));
1.99 mycroft 138: void com_break __P((struct com_softc *, int));
139: void com_modem __P((struct com_softc *, int));
140: void com_iflush __P((struct com_softc *));
1.80 christos 141:
1.102 thorpej 142: int com_common_getc __P((bus_space_tag_t, bus_space_handle_t));
143: void com_common_putc __P((bus_space_tag_t, bus_space_handle_t, int));
144:
1.80 christos 145: /* XXX: These belong elsewhere */
146: cdev_decl(com);
147: bdev_decl(com);
148:
149: int comcngetc __P((dev_t));
150: void comcnputc __P((dev_t, int));
151: void comcnpollc __P((dev_t, int));
152:
1.99 mycroft 153: #define integrate static inline
1.127 mycroft 154: #ifdef __GENERIC_SOFT_INTERRUPTS
155: void comsoft __P((void *));
156: #else
1.133 cgd 157: #ifndef __NO_SOFT_SERIAL_INTERRUPT
1.127 mycroft 158: void comsoft __P((void));
159: #else
160: void comsoft __P((void *));
161: #endif
162: #endif
163: integrate void com_rxsoft __P((struct com_softc *, struct tty *));
164: integrate void com_txsoft __P((struct com_softc *, struct tty *));
165: integrate void com_stsoft __P((struct com_softc *, struct tty *));
1.101 mycroft 166: integrate void com_schedrx __P((struct com_softc *));
1.127 mycroft 167: void comdiag __P((void *));
168:
1.130 thorpej 169: extern struct cfdriver com_cd;
1.76 thorpej 170:
1.127 mycroft 171: /*
172: * Make this an option variable one can patch.
173: * But be warned: this must be a power of 2!
174: */
175: u_int com_rbuf_size = COM_RING_SIZE;
176:
177: /* Stop input when 3/4 of the ring is full; restart when only 1/4 is full. */
178: u_int com_rbuf_hiwat = (COM_RING_SIZE * 1) / 4;
179: u_int com_rbuf_lowat = (COM_RING_SIZE * 3) / 4;
180:
1.106 drochner 181: static int comconsaddr;
182: static bus_space_tag_t comconstag;
183: static bus_space_handle_t comconsioh;
184: static int comconsattached;
185: static int comconsrate;
186: static tcflag_t comconscflag;
1.99 mycroft 187:
1.144 jonathan 188: static int ppscap =
189: PPS_TSFMT_TSPEC |
190: PPS_CAPTUREASSERT |
191: PPS_CAPTURECLEAR |
192: #ifdef PPS_SYNC
193: PPS_HARDPPSONASSERT | PPS_HARDPPSONCLEAR |
194: #endif /* PPS_SYNC */
195: PPS_OFFSETASSERT | PPS_OFFSETCLEAR;
196:
1.111 christos 197: static u_char tiocm_xxx2mcr __P((int));
198:
1.99 mycroft 199: #ifndef __GENERIC_SOFT_INTERRUPTS
1.133 cgd 200: #ifdef __NO_SOFT_SERIAL_INTERRUPT
1.99 mycroft 201: volatile int com_softintr_scheduled;
202: #endif
203: #endif
1.1 cgd 204:
205: #ifdef KGDB
1.102 thorpej 206: #include <sys/kgdb.h>
1.106 drochner 207:
208: static int com_kgdb_addr;
209: static bus_space_tag_t com_kgdb_iot;
210: static bus_space_handle_t com_kgdb_ioh;
211: static int com_kgdb_attached;
1.102 thorpej 212:
213: int com_kgdb_getc __P((void *));
214: void com_kgdb_putc __P((void *, int));
215: #endif /* KGDB */
1.1 cgd 216:
1.149 thorpej 217: #define COMUNIT_MASK 0x7ffff
218: #define COMDIALOUT_MASK 0x80000
219:
220: #define COMUNIT(x) (minor(x) & COMUNIT_MASK)
221: #define COMDIALOUT(x) (minor(x) & COMDIALOUT_MASK)
222:
223: #define COM_ISALIVE(sc) ((sc)->enabled != 0 && \
224: ISSET((sc)->sc_dev.dv_flags, DVF_ACTIVE))
1.1 cgd 225:
1.21 mycroft 226: int
1.109 is 227: comspeed(speed, frequency)
228: long speed, frequency;
1.1 cgd 229: {
1.21 mycroft 230: #define divrnd(n, q) (((n)*2/(q)+1)/2) /* divide and round off */
231:
232: int x, err;
233:
1.99 mycroft 234: #if 0
1.21 mycroft 235: if (speed == 0)
1.99 mycroft 236: return (0);
237: #endif
238: if (speed <= 0)
239: return (-1);
1.109 is 240: x = divrnd(frequency / 16, speed);
1.21 mycroft 241: if (x <= 0)
1.99 mycroft 242: return (-1);
1.114 is 243: err = divrnd(((quad_t)frequency) * 1000 / 16, speed * x) - 1000;
1.21 mycroft 244: if (err < 0)
245: err = -err;
246: if (err > COM_TOLERANCE)
1.99 mycroft 247: return (-1);
248: return (x);
1.21 mycroft 249:
250: #undef divrnd(n, q)
251: }
252:
1.99 mycroft 253: #ifdef COM_DEBUG
1.101 mycroft 254: int com_debug = 0;
255:
1.99 mycroft 256: void comstatus __P((struct com_softc *, char *));
257: void
258: comstatus(sc, str)
259: struct com_softc *sc;
260: char *str;
261: {
262: struct tty *tp = sc->sc_tty;
263:
264: printf("%s: %s %sclocal %sdcd %sts_carr_on %sdtr %stx_stopped\n",
265: sc->sc_dev.dv_xname, str,
266: ISSET(tp->t_cflag, CLOCAL) ? "+" : "-",
267: ISSET(sc->sc_msr, MSR_DCD) ? "+" : "-",
268: ISSET(tp->t_state, TS_CARR_ON) ? "+" : "-",
269: ISSET(sc->sc_mcr, MCR_DTR) ? "+" : "-",
270: sc->sc_tx_stopped ? "+" : "-");
271:
1.101 mycroft 272: printf("%s: %s %scrtscts %scts %sts_ttstop %srts %xrx_flags\n",
1.99 mycroft 273: sc->sc_dev.dv_xname, str,
274: ISSET(tp->t_cflag, CRTSCTS) ? "+" : "-",
275: ISSET(sc->sc_msr, MSR_CTS) ? "+" : "-",
276: ISSET(tp->t_state, TS_TTSTOP) ? "+" : "-",
277: ISSET(sc->sc_mcr, MCR_RTS) ? "+" : "-",
1.101 mycroft 278: sc->sc_rx_flags);
1.99 mycroft 279: }
280: #endif
281:
1.21 mycroft 282: int
1.148 is 283: comprobe1(iot, ioh)
1.91 thorpej 284: bus_space_tag_t iot;
285: bus_space_handle_t ioh;
1.21 mycroft 286: {
287:
1.1 cgd 288: /* force access to id reg */
1.91 thorpej 289: bus_space_write_1(iot, ioh, com_lcr, 0);
290: bus_space_write_1(iot, ioh, com_iir, 0);
291: if (bus_space_read_1(iot, ioh, com_iir) & 0x38)
1.99 mycroft 292: return (0);
1.21 mycroft 293:
1.99 mycroft 294: return (1);
1.1 cgd 295: }
296:
1.65 christos 297: #ifdef COM_HAYESP
298: int
1.75 cgd 299: comprobeHAYESP(hayespioh, sc)
1.91 thorpej 300: bus_space_handle_t hayespioh;
1.64 christos 301: struct com_softc *sc;
302: {
1.65 christos 303: char val, dips;
1.64 christos 304: int combaselist[] = { 0x3f8, 0x2f8, 0x3e8, 0x2e8 };
1.91 thorpej 305: bus_space_tag_t iot = sc->sc_iot;
1.64 christos 306:
307: /*
308: * Hayes ESP cards have two iobases. One is for compatibility with
309: * 16550 serial chips, and at the same ISA PC base addresses. The
310: * other is for ESP-specific enhanced features, and lies at a
1.65 christos 311: * different addressing range entirely (0x140, 0x180, 0x280, or 0x300).
1.64 christos 312: */
313:
314: /* Test for ESP signature */
1.91 thorpej 315: if ((bus_space_read_1(iot, hayespioh, 0) & 0xf3) == 0)
1.99 mycroft 316: return (0);
1.64 christos 317:
318: /*
319: * ESP is present at ESP enhanced base address; unknown com port
320: */
321:
322: /* Get the dip-switch configurations */
1.91 thorpej 323: bus_space_write_1(iot, hayespioh, HAYESP_CMD1, HAYESP_GETDIPS);
324: dips = bus_space_read_1(iot, hayespioh, HAYESP_STATUS1);
1.64 christos 325:
326: /* Determine which com port this ESP card services: bits 0,1 of */
327: /* dips is the port # (0-3); combaselist[val] is the com_iobase */
1.65 christos 328: if (sc->sc_iobase != combaselist[dips & 0x03])
1.99 mycroft 329: return (0);
1.65 christos 330:
1.90 christos 331: printf(": ESP");
1.64 christos 332:
1.65 christos 333: /* Check ESP Self Test bits. */
1.64 christos 334: /* Check for ESP version 2.0: bits 4,5,6 == 010 */
1.91 thorpej 335: bus_space_write_1(iot, hayespioh, HAYESP_CMD1, HAYESP_GETTEST);
1.99 mycroft 336: val = bus_space_read_1(iot, hayespioh, HAYESP_STATUS1); /* Clear reg1 */
1.91 thorpej 337: val = bus_space_read_1(iot, hayespioh, HAYESP_STATUS2);
1.64 christos 338: if ((val & 0x70) < 0x20) {
1.90 christos 339: printf("-old (%o)", val & 0x70);
1.64 christos 340: /* we do not support the necessary features */
1.99 mycroft 341: return (0);
1.64 christos 342: }
343:
344: /* Check for ability to emulate 16550: bit 8 == 1 */
345: if ((dips & 0x80) == 0) {
1.90 christos 346: printf(" slave");
1.64 christos 347: /* XXX Does slave really mean no 16550 support?? */
1.99 mycroft 348: return (0);
1.64 christos 349: }
350:
351: /*
352: * If we made it this far, we are a full-featured ESP v2.0 (or
353: * better), at the correct com port address.
354: */
355:
1.65 christos 356: SET(sc->sc_hwflags, COM_HW_HAYESP);
1.90 christos 357: printf(", 1024 byte fifo\n");
1.99 mycroft 358: return (1);
1.64 christos 359: }
1.65 christos 360: #endif
1.64 christos 361:
1.104 drochner 362: #if defined(DDB) || defined(KGDB)
363: static void
364: com_enable_debugport(sc)
365: struct com_softc *sc;
366: {
367: int s;
368:
369: /* Turn on line break interrupt, set carrier. */
370: s = splserial();
371: sc->sc_ier = IER_ERXRDY;
372: bus_space_write_1(sc->sc_iot, sc->sc_ioh, com_ier, sc->sc_ier);
373: SET(sc->sc_mcr, MCR_DTR | MCR_RTS);
374: bus_space_write_1(sc->sc_iot, sc->sc_ioh, com_mcr, sc->sc_mcr);
375: splx(s);
376: }
377: #endif
1.1 cgd 378:
1.29 mycroft 379: void
1.99 mycroft 380: com_attach_subr(sc)
381: struct com_softc *sc;
1.29 mycroft 382: {
1.99 mycroft 383: int iobase = sc->sc_iobase;
384: bus_space_tag_t iot = sc->sc_iot;
385: bus_space_handle_t ioh = sc->sc_ioh;
1.127 mycroft 386: struct tty *tp;
1.118 fvdl 387: #ifdef COM16650
1.116 fvdl 388: u_int8_t lcr;
1.118 fvdl 389: #endif
1.65 christos 390: #ifdef COM_HAYESP
391: int hayesp_ports[] = { 0x140, 0x180, 0x280, 0x300, 0 };
392: int *hayespp;
393: #endif
1.117 mycroft 394:
395: /* Disable interrupts before configuring the device. */
396: sc->sc_ier = 0;
1.131 marc 397: bus_space_write_1(iot, ioh, com_ier, sc->sc_ier);
1.1 cgd 398:
1.106 drochner 399: if (iot == comconstag && iobase == comconsaddr) {
1.105 drochner 400: comconsattached = 1;
401:
1.96 mycroft 402: /* Make sure the console is always "hardwired". */
1.75 cgd 403: delay(1000); /* wait for output to finish */
404: SET(sc->sc_hwflags, COM_HW_CONSOLE);
1.99 mycroft 405: SET(sc->sc_swflags, TIOCFLAG_SOFTCAR);
1.75 cgd 406: }
1.26 cgd 407:
1.65 christos 408: #ifdef COM_HAYESP
409: /* Look for a Hayes ESP board. */
1.75 cgd 410: for (hayespp = hayesp_ports; *hayespp != 0; hayespp++) {
1.91 thorpej 411: bus_space_handle_t hayespioh;
1.75 cgd 412:
413: #define HAYESP_NPORTS 8 /* XXX XXX XXX ??? ??? ??? */
1.92 cgd 414: if (bus_space_map(iot, *hayespp, HAYESP_NPORTS, 0, &hayespioh))
1.75 cgd 415: continue;
416: if (comprobeHAYESP(hayespioh, sc)) {
417: sc->sc_hayespioh = hayespioh;
1.99 mycroft 418: sc->sc_fifolen = 1024;
419:
1.65 christos 420: break;
421: }
1.91 thorpej 422: bus_space_unmap(iot, hayespioh, HAYESP_NPORTS);
1.75 cgd 423: }
1.65 christos 424: /* No ESP; look for other things. */
1.131 marc 425: if (!ISSET(sc->sc_hwflags, COM_HW_HAYESP)) {
1.65 christos 426: #endif
1.99 mycroft 427: sc->sc_fifolen = 1;
1.1 cgd 428: /* look for a NS 16550AF UART with FIFOs */
1.91 thorpej 429: bus_space_write_1(iot, ioh, com_fifo,
1.21 mycroft 430: FIFO_ENABLE | FIFO_RCV_RST | FIFO_XMT_RST | FIFO_TRIGGER_14);
1.20 mycroft 431: delay(100);
1.99 mycroft 432: if (ISSET(bus_space_read_1(iot, ioh, com_iir), IIR_FIFO_MASK)
433: == IIR_FIFO_MASK)
434: if (ISSET(bus_space_read_1(iot, ioh, com_fifo), FIFO_TRIGGER_14)
435: == FIFO_TRIGGER_14) {
1.62 mycroft 436: SET(sc->sc_hwflags, COM_HW_FIFO);
1.116 fvdl 437:
1.118 fvdl 438: #ifdef COM16650
1.116 fvdl 439: /*
440: * IIR changes into the EFR if LCR is set to LCR_EERS
441: * on 16650s. We also know IIR != 0 at this point.
442: * Write 0 into the EFR, and read it. If the result
443: * is 0, we have a 16650.
444: *
445: * Older 16650s were broken; the test to detect them
446: * is taken from the Linux driver. Apparently
447: * setting DLAB enable gives access to the EFR on
448: * these chips.
449: */
450: lcr = bus_space_read_1(iot, ioh, com_lcr);
451: bus_space_write_1(iot, ioh, com_lcr, LCR_EERS);
452: bus_space_write_1(iot, ioh, com_efr, 0);
453: if (bus_space_read_1(iot, ioh, com_efr) == 0) {
454: bus_space_write_1(iot, ioh, com_lcr,
455: lcr | LCR_DLAB);
456: if (bus_space_read_1(iot, ioh, com_efr) == 0) {
457: CLR(sc->sc_hwflags, COM_HW_FIFO);
458: sc->sc_fifolen = 0;
459: } else {
460: SET(sc->sc_hwflags, COM_HW_FLOW);
461: sc->sc_fifolen = 32;
462: }
1.118 fvdl 463: } else
464: #endif
1.116 fvdl 465: sc->sc_fifolen = 16;
466:
1.118 fvdl 467: #ifdef COM16650
1.119 drochner 468: bus_space_write_1(iot, ioh, com_lcr, lcr);
469: if (sc->sc_fifolen == 0)
470: printf(": st16650, broken fifo\n");
471: else if (sc->sc_fifolen == 32)
472: printf(": st16650a, working fifo\n");
473: else
1.118 fvdl 474: #endif
1.119 drochner 475: printf(": ns16550a, working fifo\n");
1.21 mycroft 476: } else
1.90 christos 477: printf(": ns16550, broken fifo\n");
1.21 mycroft 478: else
1.90 christos 479: printf(": ns8250 or ns16450, no fifo\n");
1.91 thorpej 480: bus_space_write_1(iot, ioh, com_fifo, 0);
1.65 christos 481: #ifdef COM_HAYESP
482: }
483: #endif
1.21 mycroft 484:
1.127 mycroft 485: tp = ttymalloc();
486: tp->t_oproc = comstart;
487: tp->t_param = comparam;
488: tp->t_hwiflow = comhwiflow;
489:
490: sc->sc_tty = tp;
1.147 thorpej 491: sc->sc_rbuf = malloc(com_rbuf_size << 1, M_DEVBUF, M_NOWAIT);
492: if (sc->sc_rbuf == NULL) {
493: printf("%s: unable to allocate ring buffer\n",
494: sc->sc_dev.dv_xname);
495: return;
496: }
1.127 mycroft 497: sc->sc_ebuf = sc->sc_rbuf + (com_rbuf_size << 1);
1.147 thorpej 498:
499: tty_attach(tp);
500:
1.99 mycroft 501: if (!ISSET(sc->sc_hwflags, COM_HW_NOIEN))
502: SET(sc->sc_mcr, MCR_IENABLE);
1.30 mycroft 503:
1.96 mycroft 504: if (ISSET(sc->sc_hwflags, COM_HW_CONSOLE)) {
1.106 drochner 505: int maj;
506:
507: /* locate the major number */
508: for (maj = 0; maj < nchrdev; maj++)
509: if (cdevsw[maj].d_open == comopen)
510: break;
511:
512: cn_tab->cn_dev = makedev(maj, sc->sc_dev.dv_unit);
1.131 marc 513:
1.96 mycroft 514: printf("%s: console\n", sc->sc_dev.dv_xname);
515: }
516:
1.1 cgd 517: #ifdef KGDB
1.102 thorpej 518: /*
519: * Allow kgdb to "take over" this port. If this is
520: * the kgdb device, it has exclusive use.
521: */
1.106 drochner 522: if (iot == com_kgdb_iot && iobase == com_kgdb_addr) {
523: com_kgdb_attached = 1;
524:
1.104 drochner 525: SET(sc->sc_hwflags, COM_HW_KGDB);
1.103 drochner 526: printf("%s: kgdb\n", sc->sc_dev.dv_xname);
527: }
1.99 mycroft 528: #endif
529:
530: #ifdef __GENERIC_SOFT_INTERRUPTS
531: sc->sc_si = softintr_establish(IPL_SOFTSERIAL, comsoft, sc);
1.1 cgd 532: #endif
1.115 explorer 533:
534: #if NRND > 0 && defined(RND_COM)
535: rnd_attach_source(&sc->rnd_source, sc->sc_dev.dv_xname,
536: RND_TYPE_TTY);
537: #endif
1.131 marc 538:
539: /* if there are no enable/disable functions, assume the device
540: is always enabled */
541: if (!sc->enable)
542: sc->enabled = 1;
543:
544: com_config(sc);
1.132 cgd 545:
546: SET(sc->sc_hwflags, COM_HW_DEV_OK);
1.131 marc 547: }
548:
549: void
550: com_config(sc)
551: struct com_softc *sc;
552: {
553: bus_space_tag_t iot = sc->sc_iot;
554: bus_space_handle_t ioh = sc->sc_ioh;
555:
556: /* Disable interrupts before configuring the device. */
557: sc->sc_ier = 0;
558: bus_space_write_1(iot, ioh, com_ier, sc->sc_ier);
559:
560: #ifdef COM_HAYESP
561: /* Look for a Hayes ESP board. */
562: if (ISSET(sc->sc_hwflags, COM_HW_HAYESP)) {
563: sc->sc_fifolen = 1024;
564:
565: /* Set 16550 compatibility mode */
566: bus_space_write_1(iot, sc->sc_hayespioh, HAYESP_CMD1,
567: HAYESP_SETMODE);
568: bus_space_write_1(iot, sc->sc_hayespioh, HAYESP_CMD2,
569: HAYESP_MODE_FIFO|HAYESP_MODE_RTS|
570: HAYESP_MODE_SCALE);
571:
572: /* Set RTS/CTS flow control */
573: bus_space_write_1(iot, sc->sc_hayespioh, HAYESP_CMD1,
574: HAYESP_SETFLOWTYPE);
575: bus_space_write_1(iot, sc->sc_hayespioh, HAYESP_CMD2,
576: HAYESP_FLOW_RTS);
577: bus_space_write_1(iot, sc->sc_hayespioh, HAYESP_CMD2,
578: HAYESP_FLOW_CTS);
579:
580: /* Set flow control levels */
581: bus_space_write_1(iot, sc->sc_hayespioh, HAYESP_CMD1,
582: HAYESP_SETRXFLOW);
583: bus_space_write_1(iot, sc->sc_hayespioh, HAYESP_CMD2,
584: HAYESP_HIBYTE(HAYESP_RXHIWMARK));
585: bus_space_write_1(iot, sc->sc_hayespioh, HAYESP_CMD2,
586: HAYESP_LOBYTE(HAYESP_RXHIWMARK));
587: bus_space_write_1(iot, sc->sc_hayespioh, HAYESP_CMD2,
588: HAYESP_HIBYTE(HAYESP_RXLOWMARK));
589: bus_space_write_1(iot, sc->sc_hayespioh, HAYESP_CMD2,
590: HAYESP_LOBYTE(HAYESP_RXLOWMARK));
591: }
592: #endif
593:
594: #ifdef DDB
595: if (ISSET(sc->sc_hwflags, COM_HW_CONSOLE))
596: com_enable_debugport(sc);
597: #endif
598:
599: #ifdef KGDB
600: /*
601: * Allow kgdb to "take over" this port. If this is
602: * the kgdb device, it has exclusive use.
603: */
604: if (ISSET(sc->sc_hwflags, COM_HW_KGDB))
605: com_enable_debugport(sc);
606: #endif
1.1 cgd 607: }
608:
1.149 thorpej 609: int
610: com_detach(self, flags)
611: struct device *self;
612: int flags;
613: {
614: struct com_softc *sc = (struct com_softc *)self;
615: int maj, mn;
616:
617: /* locate the major number */
618: for (maj = 0; maj < nchrdev; maj++)
619: if (cdevsw[maj].d_open == comopen)
620: break;
621:
622: /* Nuke the vnodes for any open instances. */
623: mn = self->dv_unit;
624: vdevgone(maj, mn, mn, VCHR);
625:
626: mn |= COMDIALOUT_MASK;
627: vdevgone(maj, mn, mn, VCHR);
628:
629: /* Free the receive buffer. */
630: free(sc->sc_rbuf, M_DEVBUF);
631:
632: /* Detach and free the tty. */
633: tty_detach(sc->sc_tty);
634: ttyfree(sc->sc_tty);
635:
636: #ifdef __GENERIC_SOFT_INTERRUPTS
637: /* Unhook the soft interrupt handler. */
638: softintr_disestablish(sc->sc_si);
639: #endif
640:
641: #if NRND > 0 && defined(RND_COM)
642: /* Unhook the entropy source. */
643: rnd_detach_source(&sc->rnd_source);
644: #endif
645:
646: return (0);
647: }
648:
649: int
650: com_activate(self, act)
651: struct device *self;
652: enum devact act;
653: {
654: struct com_softc *sc = (struct com_softc *)self;
655: int s, rv = 0;
656:
657: s = splserial();
658: switch (act) {
659: case DVACT_ACTIVATE:
660: rv = EOPNOTSUPP;
661: break;
662:
663: case DVACT_DEACTIVATE:
664: if (sc->sc_hwflags & (COM_HW_CONSOLE|COM_HW_KGDB)) {
665: rv = EBUSY;
666: break;
667: }
668:
669: if (sc->disable != NULL && sc->enabled != 0) {
670: (*sc->disable)(sc);
671: sc->enabled = 0;
672: }
673: break;
674: }
675: splx(s);
676: return (rv);
677: }
678:
1.141 mycroft 679: void
680: com_shutdown(sc)
681: struct com_softc *sc;
682: {
683: struct tty *tp = sc->sc_tty;
684: int s;
685:
686: s = splserial();
687:
688: /* If we were asserting flow control, then deassert it. */
689: SET(sc->sc_rx_flags, RX_IBUF_BLOCKED);
690: com_hwiflow(sc);
691:
692: /* Clear any break condition set with TIOCSBRK. */
693: com_break(sc, 0);
694:
1.144 jonathan 695: /* Turn off PPS capture on last close. */
1.151 ! mycroft 696: sc->sc_ppsmask = 0;
1.144 jonathan 697: sc->ppsparam.mode = 0;
698:
1.141 mycroft 699: /*
700: * Hang up if necessary. Wait a bit, so the other side has time to
701: * notice even if we immediately open the port again.
702: */
703: if (ISSET(tp->t_cflag, HUPCL)) {
704: com_modem(sc, 0);
705: (void) tsleep(sc, TTIPRI, ttclos, hz);
706: }
707:
708: /* Turn off interrupts. */
709: #ifdef DDB
710: if (ISSET(sc->sc_hwflags, COM_HW_CONSOLE))
711: sc->sc_ier = IER_ERXRDY; /* interrupt on break */
712: else
713: #endif
714: sc->sc_ier = 0;
715: bus_space_write_1(sc->sc_iot, sc->sc_ioh, com_ier, sc->sc_ier);
716:
717: if (sc->disable) {
718: #ifdef DIAGNOSTIC
719: if (!sc->enabled)
720: panic("com_shutdown: not enabled?");
721: #endif
722: (*sc->disable)(sc);
723: sc->enabled = 0;
724: }
725:
726: splx(s);
727: }
728:
1.21 mycroft 729: int
730: comopen(dev, flag, mode, p)
731: dev_t dev;
732: int flag, mode;
733: struct proc *p;
1.1 cgd 734: {
1.21 mycroft 735: int unit = COMUNIT(dev);
736: struct com_softc *sc;
737: struct tty *tp;
1.99 mycroft 738: int s, s2;
1.142 mycroft 739: int error;
1.1 cgd 740:
1.76 thorpej 741: if (unit >= com_cd.cd_ndevs)
1.99 mycroft 742: return (ENXIO);
1.76 thorpej 743: sc = com_cd.cd_devs[unit];
1.147 thorpej 744: if (sc == 0 || !ISSET(sc->sc_hwflags, COM_HW_DEV_OK) ||
745: sc->sc_rbuf == NULL)
1.99 mycroft 746: return (ENXIO);
1.21 mycroft 747:
1.149 thorpej 748: if (ISSET(sc->sc_dev.dv_flags, DVF_ACTIVE) == 0)
749: return (ENXIO);
750:
1.102 thorpej 751: #ifdef KGDB
752: /*
753: * If this is the kgdb port, no other use is permitted.
754: */
755: if (ISSET(sc->sc_hwflags, COM_HW_KGDB))
756: return (EBUSY);
757: #endif
758:
1.120 mycroft 759: tp = sc->sc_tty;
1.21 mycroft 760:
1.99 mycroft 761: if (ISSET(tp->t_state, TS_ISOPEN) &&
762: ISSET(tp->t_state, TS_XCLUDE) &&
763: p->p_ucred->cr_uid != 0)
764: return (EBUSY);
765:
766: s = spltty();
767:
768: /*
769: * Do the following iff this is a first open.
770: */
1.141 mycroft 771: if (!ISSET(tp->t_state, TS_ISOPEN) && tp->t_wopen == 0) {
1.99 mycroft 772: struct termios t;
773:
1.127 mycroft 774: tp->t_dev = dev;
775:
1.120 mycroft 776: s2 = splserial();
777:
1.131 marc 778: if (sc->enable) {
779: if ((*sc->enable)(sc)) {
1.141 mycroft 780: splx(s2);
1.134 enami 781: splx(s);
1.131 marc 782: printf("%s: device enable failed\n",
783: sc->sc_dev.dv_xname);
784: return (EIO);
785: }
786: sc->enabled = 1;
787: com_config(sc);
788: }
789:
1.99 mycroft 790: /* Turn on interrupts. */
791: sc->sc_ier = IER_ERXRDY | IER_ERLS | IER_EMSC;
792: bus_space_write_1(sc->sc_iot, sc->sc_ioh, com_ier, sc->sc_ier);
793:
794: /* Fetch the current modem control status, needed later. */
795: sc->sc_msr = bus_space_read_1(sc->sc_iot, sc->sc_ioh, com_msr);
796:
1.144 jonathan 797: /* Clear PPS capture state on first open. */
1.151 ! mycroft 798: sc->sc_ppsmask = 0;
1.144 jonathan 799:
1.120 mycroft 800: splx(s2);
1.99 mycroft 801:
802: /*
803: * Initialize the termios status to the defaults. Add in the
804: * sticky bits from TIOCSFLAGS.
805: */
806: t.c_ispeed = 0;
1.98 mycroft 807: if (ISSET(sc->sc_hwflags, COM_HW_CONSOLE)) {
1.99 mycroft 808: t.c_ospeed = comconsrate;
809: t.c_cflag = comconscflag;
1.98 mycroft 810: } else {
1.99 mycroft 811: t.c_ospeed = TTYDEF_SPEED;
812: t.c_cflag = TTYDEF_CFLAG;
1.98 mycroft 813: }
1.99 mycroft 814: if (ISSET(sc->sc_swflags, TIOCFLAG_CLOCAL))
815: SET(t.c_cflag, CLOCAL);
816: if (ISSET(sc->sc_swflags, TIOCFLAG_CRTSCTS))
817: SET(t.c_cflag, CRTSCTS);
818: if (ISSET(sc->sc_swflags, TIOCFLAG_MDMBUF))
819: SET(t.c_cflag, MDMBUF);
1.129 mycroft 820: /* Make sure comparam() will do something. */
821: tp->t_ospeed = 0;
1.120 mycroft 822: (void) comparam(tp, &t);
1.99 mycroft 823: tp->t_iflag = TTYDEF_IFLAG;
824: tp->t_oflag = TTYDEF_OFLAG;
1.16 ws 825: tp->t_lflag = TTYDEF_LFLAG;
1.99 mycroft 826: ttychars(tp);
1.1 cgd 827: ttsetwater(tp);
1.21 mycroft 828:
1.136 mycroft 829: s2 = splserial();
830:
1.99 mycroft 831: /*
832: * Turn on DTR. We must always do this, even if carrier is not
833: * present, because otherwise we'd have to use TIOCSDTR
1.121 mycroft 834: * immediately after setting CLOCAL, which applications do not
835: * expect. We always assert DTR while the device is open
836: * unless explicitly requested to deassert it.
1.99 mycroft 837: */
838: com_modem(sc, 1);
1.65 christos 839:
1.99 mycroft 840: /* Clear the input ring, and unblock. */
1.127 mycroft 841: sc->sc_rbput = sc->sc_rbget = sc->sc_rbuf;
842: sc->sc_rbavail = com_rbuf_size;
1.99 mycroft 843: com_iflush(sc);
1.101 mycroft 844: CLR(sc->sc_rx_flags, RX_ANY_BLOCK);
845: com_hwiflow(sc);
1.65 christos 846:
1.99 mycroft 847: #ifdef COM_DEBUG
1.101 mycroft 848: if (com_debug)
849: comstatus(sc, "comopen ");
1.65 christos 850: #endif
1.21 mycroft 851:
1.99 mycroft 852: splx(s2);
853: }
1.143 mycroft 854:
855: splx(s);
1.21 mycroft 856:
1.143 mycroft 857: error = ttyopen(tp, COMDIALOUT(dev), ISSET(flag, O_NONBLOCK));
858: if (error)
859: goto bad;
1.141 mycroft 860:
861: error = (*linesw[tp->t_line].l_open)(dev, tp);
1.139 enami 862: if (error)
1.141 mycroft 863: goto bad;
1.139 enami 864:
1.141 mycroft 865: return (0);
1.139 enami 866:
1.141 mycroft 867: bad:
868: if (!ISSET(tp->t_state, TS_ISOPEN) && tp->t_wopen == 0) {
869: /*
870: * We failed to open the device, and nobody else had it opened.
871: * Clean up the state as appropriate.
872: */
873: com_shutdown(sc);
874: }
1.139 enami 875:
1.99 mycroft 876: return (error);
1.1 cgd 877: }
878:
1.21 mycroft 879: int
1.1 cgd 880: comclose(dev, flag, mode, p)
881: dev_t dev;
882: int flag, mode;
883: struct proc *p;
884: {
1.127 mycroft 885: struct com_softc *sc = com_cd.cd_devs[COMUNIT(dev)];
1.50 mycroft 886: struct tty *tp = sc->sc_tty;
1.57 mycroft 887:
888: /* XXX This is for cons.c. */
1.62 mycroft 889: if (!ISSET(tp->t_state, TS_ISOPEN))
1.99 mycroft 890: return (0);
1.21 mycroft 891:
1.1 cgd 892: (*linesw[tp->t_line].l_close)(tp, flag);
893: ttyclose(tp);
1.99 mycroft 894:
1.149 thorpej 895: if (COM_ISALIVE(sc) == 0)
896: return (0);
897:
1.143 mycroft 898: if (!ISSET(tp->t_state, TS_ISOPEN) && tp->t_wopen == 0) {
899: /*
900: * Although we got a last close, the device may still be in
901: * use; e.g. if this was the dialout node, and there are still
902: * processes waiting for carrier on the non-dialout node.
903: */
904: com_shutdown(sc);
905: }
1.120 mycroft 906:
1.99 mycroft 907: return (0);
1.1 cgd 908: }
909:
1.21 mycroft 910: int
1.1 cgd 911: comread(dev, uio, flag)
912: dev_t dev;
913: struct uio *uio;
1.21 mycroft 914: int flag;
1.1 cgd 915: {
1.76 thorpej 916: struct com_softc *sc = com_cd.cd_devs[COMUNIT(dev)];
1.52 mycroft 917: struct tty *tp = sc->sc_tty;
1.149 thorpej 918:
919: if (COM_ISALIVE(sc) == 0)
920: return (EIO);
1.1 cgd 921:
922: return ((*linesw[tp->t_line].l_read)(tp, uio, flag));
923: }
924:
1.21 mycroft 925: int
1.1 cgd 926: comwrite(dev, uio, flag)
927: dev_t dev;
928: struct uio *uio;
1.21 mycroft 929: int flag;
1.1 cgd 930: {
1.76 thorpej 931: struct com_softc *sc = com_cd.cd_devs[COMUNIT(dev)];
1.52 mycroft 932: struct tty *tp = sc->sc_tty;
1.149 thorpej 933:
934: if (COM_ISALIVE(sc) == 0)
935: return (EIO);
1.1 cgd 936:
937: return ((*linesw[tp->t_line].l_write)(tp, uio, flag));
938: }
1.50 mycroft 939:
940: struct tty *
941: comtty(dev)
942: dev_t dev;
943: {
1.76 thorpej 944: struct com_softc *sc = com_cd.cd_devs[COMUNIT(dev)];
1.52 mycroft 945: struct tty *tp = sc->sc_tty;
1.50 mycroft 946:
1.52 mycroft 947: return (tp);
1.50 mycroft 948: }
1.111 christos 949:
950: static u_char
951: tiocm_xxx2mcr(data)
952: int data;
953: {
954: u_char m = 0;
955:
956: if (ISSET(data, TIOCM_DTR))
957: SET(m, MCR_DTR);
958: if (ISSET(data, TIOCM_RTS))
959: SET(m, MCR_RTS);
960: return m;
961: }
1.1 cgd 962:
1.21 mycroft 963: int
1.19 mycroft 964: comioctl(dev, cmd, data, flag, p)
1.1 cgd 965: dev_t dev;
1.39 cgd 966: u_long cmd;
1.1 cgd 967: caddr_t data;
1.19 mycroft 968: int flag;
969: struct proc *p;
1.1 cgd 970: {
1.127 mycroft 971: struct com_softc *sc = com_cd.cd_devs[COMUNIT(dev)];
1.50 mycroft 972: struct tty *tp = sc->sc_tty;
1.21 mycroft 973: int error;
1.136 mycroft 974: int s;
1.21 mycroft 975:
1.149 thorpej 976: if (COM_ISALIVE(sc) == 0)
977: return (EIO);
978:
1.19 mycroft 979: error = (*linesw[tp->t_line].l_ioctl)(tp, cmd, data, flag, p);
1.1 cgd 980: if (error >= 0)
1.99 mycroft 981: return (error);
982:
1.19 mycroft 983: error = ttioctl(tp, cmd, data, flag, p);
1.1 cgd 984: if (error >= 0)
1.99 mycroft 985: return (error);
1.138 mycroft 986:
987: error = 0;
1.1 cgd 988:
1.136 mycroft 989: s = splserial();
990:
1.1 cgd 991: switch (cmd) {
992: case TIOCSBRK:
1.99 mycroft 993: com_break(sc, 1);
1.1 cgd 994: break;
1.99 mycroft 995:
1.1 cgd 996: case TIOCCBRK:
1.99 mycroft 997: com_break(sc, 0);
1.1 cgd 998: break;
1.99 mycroft 999:
1.1 cgd 1000: case TIOCSDTR:
1.99 mycroft 1001: com_modem(sc, 1);
1.1 cgd 1002: break;
1.99 mycroft 1003:
1.1 cgd 1004: case TIOCCDTR:
1.99 mycroft 1005: com_modem(sc, 0);
1.1 cgd 1006: break;
1.99 mycroft 1007:
1008: case TIOCGFLAGS:
1009: *(int *)data = sc->sc_swflags;
1010: break;
1011:
1012: case TIOCSFLAGS:
1013: error = suser(p->p_ucred, &p->p_acflag);
1014: if (error)
1.136 mycroft 1015: break;
1.99 mycroft 1016: sc->sc_swflags = *(int *)data;
1017: break;
1018:
1.1 cgd 1019: case TIOCMSET:
1.111 christos 1020: CLR(sc->sc_mcr, MCR_DTR | MCR_RTS);
1021: /*FALLTHROUGH*/
1022:
1.1 cgd 1023: case TIOCMBIS:
1.111 christos 1024: SET(sc->sc_mcr, tiocm_xxx2mcr(*(int *)data));
1025: bus_space_write_1(sc->sc_iot, sc->sc_ioh, com_mcr, sc->sc_mcr);
1026: break;
1027:
1.1 cgd 1028: case TIOCMBIC:
1.111 christos 1029: CLR(sc->sc_mcr, tiocm_xxx2mcr(*(int *)data));
1030: bus_space_write_1(sc->sc_iot, sc->sc_ioh, com_mcr, sc->sc_mcr);
1031: break;
1032:
1033: case TIOCMGET: {
1034: u_char m;
1035: int bits = 0;
1036:
1037: m = sc->sc_mcr;
1038: if (ISSET(m, MCR_DTR))
1039: SET(bits, TIOCM_DTR);
1040: if (ISSET(m, MCR_RTS))
1041: SET(bits, TIOCM_RTS);
1042: m = sc->sc_msr;
1043: if (ISSET(m, MSR_DCD))
1044: SET(bits, TIOCM_CD);
1045: if (ISSET(m, MSR_CTS))
1046: SET(bits, TIOCM_CTS);
1047: if (ISSET(m, MSR_DSR))
1048: SET(bits, TIOCM_DSR);
1049: if (ISSET(m, MSR_RI | MSR_TERI))
1050: SET(bits, TIOCM_RI);
1051: if (bus_space_read_1(sc->sc_iot, sc->sc_ioh, com_ier))
1052: SET(bits, TIOCM_LE);
1053: *(int *)data = bits;
1054: break;
1055: }
1.144 jonathan 1056:
1057: case PPS_CREATE:
1058: break;
1059:
1060: case PPS_DESTROY:
1061: break;
1062:
1063: case PPS_GETPARAMS: {
1064: pps_params_t *pp;
1065: pp = (pps_params_t *)data;
1066: *pp = sc->ppsparam;
1067: break;
1068: }
1069:
1070: case PPS_SETPARAMS: {
1071: pps_params_t *pp;
1072: int mode;
1073: pp = (pps_params_t *)data;
1074: if (pp->mode & ~ppscap) {
1075: error = EINVAL;
1076: break;
1077: }
1078: sc->ppsparam = *pp;
1079: /*
1080: * Compute msr masks from user-specified timestamp state.
1081: */
1082: mode = sc->ppsparam.mode;
1.151 ! mycroft 1083: #ifdef PPS_SYNC
1.144 jonathan 1084: if (mode & PPS_HARDPPSONASSERT) {
1085: mode |= PPS_CAPTUREASSERT;
1086: /* XXX revoke any previous HARDPPS source */
1087: }
1088: if (mode & PPS_HARDPPSONCLEAR) {
1089: mode |= PPS_CAPTURECLEAR;
1090: /* XXX revoke any previous HARDPPS source */
1091: }
1.151 ! mycroft 1092: #endif /* PPS_SYNC */
1.144 jonathan 1093: switch (mode & PPS_CAPTUREBOTH) {
1094: case 0:
1.151 ! mycroft 1095: sc->sc_ppsmask = 0;
1.144 jonathan 1096: break;
1097:
1098: case PPS_CAPTUREASSERT:
1.151 ! mycroft 1099: sc->sc_ppsmask = MSR_DCD;
1.144 jonathan 1100: sc->sc_ppsassert = MSR_DCD;
1.151 ! mycroft 1101: sc->sc_ppsclear = -1;
1.144 jonathan 1102: break;
1103:
1104: case PPS_CAPTURECLEAR:
1.151 ! mycroft 1105: sc->sc_ppsmask = MSR_DCD;
! 1106: sc->sc_ppsassert = -1;
1.144 jonathan 1107: sc->sc_ppsclear = 0;
1108: break;
1109:
1110: case PPS_CAPTUREBOTH:
1.151 ! mycroft 1111: sc->sc_ppsmask = MSR_DCD;
1.144 jonathan 1112: sc->sc_ppsassert = MSR_DCD;
1113: sc->sc_ppsclear = 0;
1114: break;
1115:
1116: default:
1117: error = EINVAL;
1118: break;
1119: }
1120: break;
1121: }
1122:
1123: case PPS_GETCAP:
1124: *(int*)data = ppscap;
1125: break;
1126:
1127: case PPS_FETCH: {
1128: pps_info_t *pi;
1129: pi = (pps_info_t *)data;
1130: *pi = sc->ppsinfo;
1131: break;
1132: }
1133:
1134: case PPS_WAIT:
1.151 ! mycroft 1135: /* XXX */
1.144 jonathan 1136: error = EOPNOTSUPP;
1137: break;
1138:
1139: case TIOCDCDTIMESTAMP: /* XXX old, overloaded API used by xntpd v3 */
1140: /*
1141: * Some GPS clocks models use the falling rather than
1142: * rising edge as the on-the-second signal.
1143: * The old API has no way to specify PPS polarity.
1144: */
1.151 ! mycroft 1145: sc->sc_ppsmask = MSR_DCD;
1.144 jonathan 1146: #ifndef PPS_TRAILING_EDGE
1147: sc->sc_ppsassert = MSR_DCD;
1.151 ! mycroft 1148: sc->sc_ppsclear = -1;
! 1149: TIMESPEC_TO_TIMEVAL((struct timeval *)data,
1.144 jonathan 1150: &sc->ppsinfo.assert_timestamp);
1151: #else
1.151 ! mycroft 1152: sc->sc_ppsassert = -1
1.144 jonathan 1153: sc->sc_ppsclear = 0;
1.151 ! mycroft 1154: TIMESPEC_TO_TIMEVAL((struct timeval *)data,
1.144 jonathan 1155: &sc->ppsinfo.clear_timestamp);
1156: #endif
1157: break;
1158:
1.99 mycroft 1159: default:
1.136 mycroft 1160: error = ENOTTY;
1161: break;
1.21 mycroft 1162: }
1.22 cgd 1163:
1.136 mycroft 1164: splx(s);
1165:
1.99 mycroft 1166: #ifdef COM_DEBUG
1.101 mycroft 1167: if (com_debug)
1.99 mycroft 1168: comstatus(sc, "comioctl ");
1169: #endif
1170:
1.136 mycroft 1171: return (error);
1.99 mycroft 1172: }
1173:
1.101 mycroft 1174: integrate void
1175: com_schedrx(sc)
1176: struct com_softc *sc;
1177: {
1178:
1179: sc->sc_rx_ready = 1;
1180:
1181: /* Wake up the poller. */
1182: #ifdef __GENERIC_SOFT_INTERRUPTS
1183: softintr_schedule(sc->sc_si);
1184: #else
1.133 cgd 1185: #ifndef __NO_SOFT_SERIAL_INTERRUPT
1.101 mycroft 1186: setsoftserial();
1187: #else
1188: if (!com_softintr_scheduled) {
1189: com_softintr_scheduled = 1;
1190: timeout(comsoft, NULL, 1);
1191: }
1192: #endif
1193: #endif
1194: }
1195:
1.99 mycroft 1196: void
1197: com_break(sc, onoff)
1198: struct com_softc *sc;
1199: int onoff;
1200: {
1201:
1202: if (onoff)
1203: SET(sc->sc_lcr, LCR_SBREAK);
1204: else
1205: CLR(sc->sc_lcr, LCR_SBREAK);
1.22 cgd 1206:
1.99 mycroft 1207: if (!sc->sc_heldchange) {
1208: if (sc->sc_tx_busy) {
1209: sc->sc_heldtbc = sc->sc_tbc;
1210: sc->sc_tbc = 0;
1211: sc->sc_heldchange = 1;
1212: } else
1213: com_loadchannelregs(sc);
1.22 cgd 1214: }
1.99 mycroft 1215: }
1.22 cgd 1216:
1.99 mycroft 1217: void
1218: com_modem(sc, onoff)
1219: struct com_softc *sc;
1220: int onoff;
1221: {
1.22 cgd 1222:
1.99 mycroft 1223: if (onoff)
1224: SET(sc->sc_mcr, sc->sc_mcr_dtr);
1225: else
1226: CLR(sc->sc_mcr, sc->sc_mcr_dtr);
1.22 cgd 1227:
1.99 mycroft 1228: if (!sc->sc_heldchange) {
1229: if (sc->sc_tx_busy) {
1230: sc->sc_heldtbc = sc->sc_tbc;
1231: sc->sc_tbc = 0;
1232: sc->sc_heldchange = 1;
1233: } else
1234: com_loadchannelregs(sc);
1.22 cgd 1235: }
1.1 cgd 1236: }
1237:
1.106 drochner 1238: static u_char
1239: cflag2lcr(cflag)
1.110 enami 1240: tcflag_t cflag;
1.106 drochner 1241: {
1242: u_char lcr = 0;
1243:
1244: switch (ISSET(cflag, CSIZE)) {
1.127 mycroft 1245: case CS5:
1.106 drochner 1246: SET(lcr, LCR_5BITS);
1247: break;
1.127 mycroft 1248: case CS6:
1.106 drochner 1249: SET(lcr, LCR_6BITS);
1250: break;
1.127 mycroft 1251: case CS7:
1.106 drochner 1252: SET(lcr, LCR_7BITS);
1253: break;
1.127 mycroft 1254: case CS8:
1.106 drochner 1255: SET(lcr, LCR_8BITS);
1256: break;
1257: }
1258: if (ISSET(cflag, PARENB)) {
1259: SET(lcr, LCR_PENAB);
1260: if (!ISSET(cflag, PARODD))
1261: SET(lcr, LCR_PEVEN);
1262: }
1263: if (ISSET(cflag, CSTOPB))
1264: SET(lcr, LCR_STOPB);
1265:
1.110 enami 1266: return (lcr);
1.106 drochner 1267: }
1268:
1.21 mycroft 1269: int
1.1 cgd 1270: comparam(tp, t)
1.21 mycroft 1271: struct tty *tp;
1272: struct termios *t;
1.1 cgd 1273: {
1.76 thorpej 1274: struct com_softc *sc = com_cd.cd_devs[COMUNIT(tp->t_dev)];
1.109 is 1275: int ospeed = comspeed(t->c_ospeed, sc->sc_frequency);
1.62 mycroft 1276: u_char lcr;
1.21 mycroft 1277: int s;
1278:
1.149 thorpej 1279: if (COM_ISALIVE(sc) == 0)
1280: return (EIO);
1281:
1.127 mycroft 1282: /* Check requested parameters. */
1.99 mycroft 1283: if (ospeed < 0)
1284: return (EINVAL);
1285: if (t->c_ispeed && t->c_ispeed != t->c_ospeed)
1286: return (EINVAL);
1.21 mycroft 1287:
1.99 mycroft 1288: /*
1289: * For the console, always force CLOCAL and !HUPCL, so that the port
1290: * is always active.
1291: */
1292: if (ISSET(sc->sc_swflags, TIOCFLAG_SOFTCAR) ||
1293: ISSET(sc->sc_hwflags, COM_HW_CONSOLE)) {
1294: SET(t->c_cflag, CLOCAL);
1295: CLR(t->c_cflag, HUPCL);
1.62 mycroft 1296: }
1.129 mycroft 1297:
1298: /*
1299: * If there were no changes, don't do anything. This avoids dropping
1300: * input and improves performance when all we did was frob things like
1301: * VMIN and VTIME.
1302: */
1303: if (tp->t_ospeed == t->c_ospeed &&
1304: tp->t_cflag == t->c_cflag)
1305: return (0);
1.126 mycroft 1306:
1307: lcr = ISSET(sc->sc_lcr, LCR_SBREAK) | cflag2lcr(t->c_cflag);
1308:
1309: s = splserial();
1310:
1311: sc->sc_lcr = lcr;
1.36 mycroft 1312:
1313: /*
1.99 mycroft 1314: * If we're not in a mode that assumes a connection is present, then
1315: * ignore carrier changes.
1.36 mycroft 1316: */
1.99 mycroft 1317: if (ISSET(t->c_cflag, CLOCAL | MDMBUF))
1318: sc->sc_msr_dcd = 0;
1319: else
1320: sc->sc_msr_dcd = MSR_DCD;
1321: /*
1322: * Set the flow control pins depending on the current flow control
1323: * mode.
1324: */
1325: if (ISSET(t->c_cflag, CRTSCTS)) {
1326: sc->sc_mcr_dtr = MCR_DTR;
1327: sc->sc_mcr_rts = MCR_RTS;
1328: sc->sc_msr_cts = MSR_CTS;
1.116 fvdl 1329: sc->sc_efr = EFR_AUTORTS | EFR_AUTOCTS;
1.99 mycroft 1330: } else if (ISSET(t->c_cflag, MDMBUF)) {
1331: /*
1332: * For DTR/DCD flow control, make sure we don't toggle DTR for
1333: * carrier detection.
1334: */
1335: sc->sc_mcr_dtr = 0;
1336: sc->sc_mcr_rts = MCR_DTR;
1337: sc->sc_msr_cts = MSR_DCD;
1.116 fvdl 1338: sc->sc_efr = 0;
1.99 mycroft 1339: } else {
1340: /*
1341: * If no flow control, then always set RTS. This will make
1342: * the other side happy if it mistakenly thinks we're doing
1343: * RTS/CTS flow control.
1344: */
1345: sc->sc_mcr_dtr = MCR_DTR | MCR_RTS;
1346: sc->sc_mcr_rts = 0;
1347: sc->sc_msr_cts = 0;
1.116 fvdl 1348: sc->sc_efr = 0;
1.99 mycroft 1349: if (ISSET(sc->sc_mcr, MCR_DTR))
1350: SET(sc->sc_mcr, MCR_RTS);
1351: else
1352: CLR(sc->sc_mcr, MCR_RTS);
1353: }
1354: sc->sc_msr_mask = sc->sc_msr_cts | sc->sc_msr_dcd;
1355:
1.95 mycroft 1356: #if 0
1.99 mycroft 1357: if (ospeed == 0)
1358: CLR(sc->sc_mcr, sc->sc_mcr_dtr);
1359: else
1360: SET(sc->sc_mcr, sc->sc_mcr_dtr);
1.66 mycroft 1361: #endif
1362:
1.99 mycroft 1363: sc->sc_dlbl = ospeed;
1364: sc->sc_dlbh = ospeed >> 8;
1.66 mycroft 1365:
1.99 mycroft 1366: /*
1367: * Set the FIFO threshold based on the receive speed.
1368: *
1369: * * If it's a low speed, it's probably a mouse or some other
1370: * interactive device, so set the threshold low.
1371: * * If it's a high speed, trim the trigger level down to prevent
1372: * overflows.
1373: * * Otherwise set it a bit higher.
1374: */
1375: if (ISSET(sc->sc_hwflags, COM_HW_HAYESP))
1376: sc->sc_fifo = FIFO_DMA_MODE | FIFO_ENABLE | FIFO_TRIGGER_8;
1377: else if (ISSET(sc->sc_hwflags, COM_HW_FIFO))
1378: sc->sc_fifo = FIFO_ENABLE |
1379: (t->c_ospeed <= 1200 ? FIFO_TRIGGER_1 :
1380: t->c_ospeed <= 38400 ? FIFO_TRIGGER_8 : FIFO_TRIGGER_4);
1381: else
1382: sc->sc_fifo = 0;
1.21 mycroft 1383:
1.127 mycroft 1384: /* And copy to tty. */
1.99 mycroft 1385: tp->t_ispeed = 0;
1.57 mycroft 1386: tp->t_ospeed = t->c_ospeed;
1387: tp->t_cflag = t->c_cflag;
1.25 cgd 1388:
1.99 mycroft 1389: if (!sc->sc_heldchange) {
1390: if (sc->sc_tx_busy) {
1391: sc->sc_heldtbc = sc->sc_tbc;
1392: sc->sc_tbc = 0;
1393: sc->sc_heldchange = 1;
1394: } else
1395: com_loadchannelregs(sc);
1396: }
1397:
1.124 mycroft 1398: if (!ISSET(t->c_cflag, CHWFLOW)) {
1.125 mycroft 1399: /* Disable the high water mark. */
1400: sc->sc_r_hiwat = 0;
1401: sc->sc_r_lowat = 0;
1.124 mycroft 1402: if (ISSET(sc->sc_rx_flags, RX_TTY_OVERFLOWED)) {
1403: CLR(sc->sc_rx_flags, RX_TTY_OVERFLOWED);
1404: com_schedrx(sc);
1405: }
1406: if (ISSET(sc->sc_rx_flags, RX_TTY_BLOCKED|RX_IBUF_BLOCKED)) {
1407: CLR(sc->sc_rx_flags, RX_TTY_BLOCKED|RX_IBUF_BLOCKED);
1408: com_hwiflow(sc);
1409: }
1.125 mycroft 1410: } else {
1.127 mycroft 1411: sc->sc_r_hiwat = com_rbuf_hiwat;
1412: sc->sc_r_lowat = com_rbuf_lowat;
1.124 mycroft 1413: }
1414:
1.99 mycroft 1415: splx(s);
1416:
1.25 cgd 1417: /*
1.99 mycroft 1418: * Update the tty layer's idea of the carrier bit, in case we changed
1.124 mycroft 1419: * CLOCAL or MDMBUF. We don't hang up here; we only do that by
1420: * explicit request.
1.25 cgd 1421: */
1.99 mycroft 1422: (void) (*linesw[tp->t_line].l_modem)(tp, ISSET(sc->sc_msr, MSR_DCD));
1423:
1424: #ifdef COM_DEBUG
1.101 mycroft 1425: if (com_debug)
1426: comstatus(sc, "comparam ");
1.99 mycroft 1427: #endif
1428:
1429: if (!ISSET(t->c_cflag, CHWFLOW)) {
1430: if (sc->sc_tx_stopped) {
1431: sc->sc_tx_stopped = 0;
1432: comstart(tp);
1433: }
1.21 mycroft 1434: }
1.1 cgd 1435:
1.99 mycroft 1436: return (0);
1437: }
1438:
1439: void
1440: com_iflush(sc)
1441: struct com_softc *sc;
1442: {
1443: bus_space_tag_t iot = sc->sc_iot;
1444: bus_space_handle_t ioh = sc->sc_ioh;
1.131 marc 1445: #ifdef DIAGNOSTIC
1446: int reg;
1447: #endif
1448: int timo;
1.99 mycroft 1449:
1.131 marc 1450: #ifdef DIAGNOSTIC
1451: reg = 0xffff;
1452: #endif
1453: timo = 50000;
1.99 mycroft 1454: /* flush any pending I/O */
1.131 marc 1455: while (ISSET(bus_space_read_1(iot, ioh, com_lsr), LSR_RXRDY)
1456: && --timo)
1457: #ifdef DIAGNOSTIC
1458: reg =
1459: #else
1460: (void)
1461: #endif
1462: bus_space_read_1(iot, ioh, com_data);
1463: #ifdef DIAGNOSTIC
1464: if (!timo)
1465: printf("%s: com_iflush timeout %02x\n", sc->sc_dev.dv_xname,
1466: reg);
1467: #endif
1.99 mycroft 1468: }
1469:
1470: void
1471: com_loadchannelregs(sc)
1472: struct com_softc *sc;
1473: {
1474: bus_space_tag_t iot = sc->sc_iot;
1475: bus_space_handle_t ioh = sc->sc_ioh;
1476:
1477: /* XXXXX necessary? */
1478: com_iflush(sc);
1479:
1480: bus_space_write_1(iot, ioh, com_ier, 0);
1481:
1.116 fvdl 1482: if (ISSET(sc->sc_hwflags, COM_HW_FLOW)) {
1483: bus_space_write_1(iot, ioh, com_lcr, LCR_EERS);
1484: bus_space_write_1(iot, ioh, com_efr, sc->sc_efr);
1485: }
1.99 mycroft 1486: bus_space_write_1(iot, ioh, com_lcr, sc->sc_lcr | LCR_DLAB);
1487: bus_space_write_1(iot, ioh, com_dlbl, sc->sc_dlbl);
1488: bus_space_write_1(iot, ioh, com_dlbh, sc->sc_dlbh);
1489: bus_space_write_1(iot, ioh, com_lcr, sc->sc_lcr);
1490: bus_space_write_1(iot, ioh, com_mcr, sc->sc_mcr_active = sc->sc_mcr);
1491: bus_space_write_1(iot, ioh, com_fifo, sc->sc_fifo);
1492:
1493: bus_space_write_1(iot, ioh, com_ier, sc->sc_ier);
1494: }
1495:
1496: int
1497: comhwiflow(tp, block)
1498: struct tty *tp;
1499: int block;
1500: {
1501: struct com_softc *sc = com_cd.cd_devs[COMUNIT(tp->t_dev)];
1502: int s;
1503:
1.149 thorpej 1504: if (COM_ISALIVE(sc) == 0)
1505: return (0);
1506:
1.99 mycroft 1507: if (sc->sc_mcr_rts == 0)
1508: return (0);
1509:
1510: s = splserial();
1511: if (block) {
1.101 mycroft 1512: if (!ISSET(sc->sc_rx_flags, RX_TTY_BLOCKED)) {
1513: SET(sc->sc_rx_flags, RX_TTY_BLOCKED);
1514: com_hwiflow(sc);
1515: }
1.99 mycroft 1516: } else {
1.101 mycroft 1517: if (ISSET(sc->sc_rx_flags, RX_TTY_OVERFLOWED)) {
1518: CLR(sc->sc_rx_flags, RX_TTY_OVERFLOWED);
1519: com_schedrx(sc);
1520: }
1521: if (ISSET(sc->sc_rx_flags, RX_TTY_BLOCKED)) {
1522: CLR(sc->sc_rx_flags, RX_TTY_BLOCKED);
1523: com_hwiflow(sc);
1524: }
1.99 mycroft 1525: }
1.21 mycroft 1526: splx(s);
1.99 mycroft 1527: return (1);
1528: }
1529:
1530: /*
1531: * (un)block input via hw flowcontrol
1532: */
1533: void
1.101 mycroft 1534: com_hwiflow(sc)
1.99 mycroft 1535: struct com_softc *sc;
1536: {
1537: bus_space_tag_t iot = sc->sc_iot;
1538: bus_space_handle_t ioh = sc->sc_ioh;
1539:
1540: if (sc->sc_mcr_rts == 0)
1541: return;
1542:
1.101 mycroft 1543: if (ISSET(sc->sc_rx_flags, RX_ANY_BLOCK)) {
1.99 mycroft 1544: CLR(sc->sc_mcr, sc->sc_mcr_rts);
1545: CLR(sc->sc_mcr_active, sc->sc_mcr_rts);
1546: } else {
1547: SET(sc->sc_mcr, sc->sc_mcr_rts);
1548: SET(sc->sc_mcr_active, sc->sc_mcr_rts);
1549: }
1550: bus_space_write_1(iot, ioh, com_mcr, sc->sc_mcr_active);
1.1 cgd 1551: }
1.21 mycroft 1552:
1.99 mycroft 1553:
1.12 deraadt 1554: void
1.1 cgd 1555: comstart(tp)
1.21 mycroft 1556: struct tty *tp;
1.1 cgd 1557: {
1.76 thorpej 1558: struct com_softc *sc = com_cd.cd_devs[COMUNIT(tp->t_dev)];
1.91 thorpej 1559: bus_space_tag_t iot = sc->sc_iot;
1560: bus_space_handle_t ioh = sc->sc_ioh;
1.21 mycroft 1561: int s;
1562:
1.149 thorpej 1563: if (COM_ISALIVE(sc) == 0)
1564: return;
1565:
1.1 cgd 1566: s = spltty();
1.127 mycroft 1567: if (ISSET(tp->t_state, TS_BUSY | TS_TIMEOUT | TS_TTSTOP))
1.70 mycroft 1568: goto out;
1.99 mycroft 1569: if (sc->sc_tx_stopped)
1.127 mycroft 1570: goto out;
1.99 mycroft 1571:
1.61 mycroft 1572: if (tp->t_outq.c_cc <= tp->t_lowat) {
1.62 mycroft 1573: if (ISSET(tp->t_state, TS_ASLEEP)) {
1574: CLR(tp->t_state, TS_ASLEEP);
1575: wakeup(&tp->t_outq);
1.61 mycroft 1576: }
1.99 mycroft 1577: selwakeup(&tp->t_wsel);
1.61 mycroft 1578: if (tp->t_outq.c_cc == 0)
1.127 mycroft 1579: goto out;
1.61 mycroft 1580: }
1.99 mycroft 1581:
1582: /* Grab the first contiguous region of buffer space. */
1583: {
1584: u_char *tba;
1585: int tbc;
1586:
1587: tba = tp->t_outq.c_cf;
1588: tbc = ndqb(&tp->t_outq, 0);
1589:
1590: (void)splserial();
1591:
1592: sc->sc_tba = tba;
1593: sc->sc_tbc = tbc;
1594: }
1595:
1.62 mycroft 1596: SET(tp->t_state, TS_BUSY);
1.99 mycroft 1597: sc->sc_tx_busy = 1;
1.64 christos 1598:
1.99 mycroft 1599: /* Enable transmit completion interrupts if necessary. */
1.70 mycroft 1600: if (!ISSET(sc->sc_ier, IER_ETXRDY)) {
1601: SET(sc->sc_ier, IER_ETXRDY);
1.91 thorpej 1602: bus_space_write_1(iot, ioh, com_ier, sc->sc_ier);
1.70 mycroft 1603: }
1.99 mycroft 1604:
1605: /* Output the first chunk of the contiguous buffer. */
1606: {
1607: int n;
1608:
1.127 mycroft 1609: n = sc->sc_tbc;
1610: if (n > sc->sc_fifolen)
1611: n = sc->sc_fifolen;
1.99 mycroft 1612: bus_space_write_multi_1(iot, ioh, com_data, sc->sc_tba, n);
1613: sc->sc_tbc -= n;
1614: sc->sc_tba += n;
1.64 christos 1615: }
1.99 mycroft 1616: out:
1.1 cgd 1617: splx(s);
1.99 mycroft 1618: return;
1.1 cgd 1619: }
1.21 mycroft 1620:
1.1 cgd 1621: /*
1622: * Stop output on a line.
1623: */
1.85 mycroft 1624: void
1.1 cgd 1625: comstop(tp, flag)
1.21 mycroft 1626: struct tty *tp;
1.80 christos 1627: int flag;
1.1 cgd 1628: {
1.99 mycroft 1629: struct com_softc *sc = com_cd.cd_devs[COMUNIT(tp->t_dev)];
1.21 mycroft 1630: int s;
1.1 cgd 1631:
1.99 mycroft 1632: s = splserial();
1633: if (ISSET(tp->t_state, TS_BUSY)) {
1634: /* Stop transmitting at the next chunk. */
1635: sc->sc_tbc = 0;
1636: sc->sc_heldtbc = 0;
1.62 mycroft 1637: if (!ISSET(tp->t_state, TS_TTSTOP))
1638: SET(tp->t_state, TS_FLUSH);
1.99 mycroft 1639: }
1.1 cgd 1640: splx(s);
1641: }
1642:
1.33 mycroft 1643: void
1644: comdiag(arg)
1645: void *arg;
1646: {
1647: struct com_softc *sc = arg;
1.99 mycroft 1648: int overflows, floods;
1.33 mycroft 1649: int s;
1650:
1.99 mycroft 1651: s = splserial();
1.33 mycroft 1652: overflows = sc->sc_overflows;
1653: sc->sc_overflows = 0;
1.57 mycroft 1654: floods = sc->sc_floods;
1655: sc->sc_floods = 0;
1.99 mycroft 1656: sc->sc_errors = 0;
1.57 mycroft 1657: splx(s);
1658:
1.127 mycroft 1659: log(LOG_WARNING, "%s: %d silo overflow%s, %d ibuf flood%s\n",
1.57 mycroft 1660: sc->sc_dev.dv_xname,
1661: overflows, overflows == 1 ? "" : "s",
1.99 mycroft 1662: floods, floods == 1 ? "" : "s");
1.57 mycroft 1663: }
1664:
1.99 mycroft 1665: integrate void
1.127 mycroft 1666: com_rxsoft(sc, tp)
1667: struct com_softc *sc;
1668: struct tty *tp;
1.99 mycroft 1669: {
1.127 mycroft 1670: int (*rint) __P((int c, struct tty *tp)) = linesw[tp->t_line].l_rint;
1671: u_char *get, *end;
1672: u_int cc, scc;
1673: u_char lsr;
1674: int code;
1675: int s;
1.57 mycroft 1676:
1.127 mycroft 1677: end = sc->sc_ebuf;
1.99 mycroft 1678: get = sc->sc_rbget;
1.127 mycroft 1679: scc = cc = com_rbuf_size - sc->sc_rbavail;
1.99 mycroft 1680:
1.127 mycroft 1681: if (cc == com_rbuf_size) {
1.99 mycroft 1682: sc->sc_floods++;
1683: if (sc->sc_errors++ == 0)
1684: timeout(comdiag, sc, 60 * hz);
1685: }
1686:
1.101 mycroft 1687: while (cc) {
1.128 mycroft 1688: code = get[0];
1.127 mycroft 1689: lsr = get[1];
1.128 mycroft 1690: if (ISSET(lsr, LSR_OE | LSR_BI | LSR_FE | LSR_PE)) {
1691: if (ISSET(lsr, LSR_OE)) {
1692: sc->sc_overflows++;
1693: if (sc->sc_errors++ == 0)
1694: timeout(comdiag, sc, 60 * hz);
1695: }
1.127 mycroft 1696: if (ISSET(lsr, LSR_BI | LSR_FE))
1697: SET(code, TTY_FE);
1698: if (ISSET(lsr, LSR_PE))
1699: SET(code, TTY_PE);
1700: }
1701: if ((*rint)(code, tp) == -1) {
1.101 mycroft 1702: /*
1703: * The line discipline's buffer is out of space.
1704: */
1705: if (!ISSET(sc->sc_rx_flags, RX_TTY_BLOCKED)) {
1706: /*
1707: * We're either not using flow control, or the
1708: * line discipline didn't tell us to block for
1709: * some reason. Either way, we have no way to
1710: * know when there's more space available, so
1711: * just drop the rest of the data.
1712: */
1.127 mycroft 1713: get += cc << 1;
1714: if (get >= end)
1715: get -= com_rbuf_size << 1;
1.101 mycroft 1716: cc = 0;
1717: } else {
1718: /*
1719: * Don't schedule any more receive processing
1720: * until the line discipline tells us there's
1721: * space available (through comhwiflow()).
1722: * Leave the rest of the data in the input
1723: * buffer.
1724: */
1725: SET(sc->sc_rx_flags, RX_TTY_OVERFLOWED);
1726: }
1727: break;
1728: }
1.127 mycroft 1729: get += 2;
1730: if (get >= end)
1731: get = sc->sc_rbuf;
1.101 mycroft 1732: cc--;
1.99 mycroft 1733: }
1734:
1.101 mycroft 1735: if (cc != scc) {
1736: sc->sc_rbget = get;
1737: s = splserial();
1738: cc = sc->sc_rbavail += scc - cc;
1739: /* Buffers should be ok again, release possible block. */
1740: if (cc >= sc->sc_r_lowat) {
1741: if (ISSET(sc->sc_rx_flags, RX_IBUF_OVERFLOWED)) {
1742: CLR(sc->sc_rx_flags, RX_IBUF_OVERFLOWED);
1743: SET(sc->sc_ier, IER_ERXRDY);
1744: bus_space_write_1(sc->sc_iot, sc->sc_ioh, com_ier, sc->sc_ier);
1745: }
1746: if (ISSET(sc->sc_rx_flags, RX_IBUF_BLOCKED)) {
1747: CLR(sc->sc_rx_flags, RX_IBUF_BLOCKED);
1748: com_hwiflow(sc);
1749: }
1750: }
1751: splx(s);
1.57 mycroft 1752: }
1.99 mycroft 1753: }
1754:
1755: integrate void
1.127 mycroft 1756: com_txsoft(sc, tp)
1757: struct com_softc *sc;
1758: struct tty *tp;
1.99 mycroft 1759: {
1.33 mycroft 1760:
1.99 mycroft 1761: CLR(tp->t_state, TS_BUSY);
1762: if (ISSET(tp->t_state, TS_FLUSH))
1763: CLR(tp->t_state, TS_FLUSH);
1764: else
1765: ndflush(&tp->t_outq, (int)(sc->sc_tba - tp->t_outq.c_cf));
1766: (*linesw[tp->t_line].l_start)(tp);
1767: }
1.57 mycroft 1768:
1.99 mycroft 1769: integrate void
1.127 mycroft 1770: com_stsoft(sc, tp)
1771: struct com_softc *sc;
1772: struct tty *tp;
1.99 mycroft 1773: {
1774: u_char msr, delta;
1775: int s;
1.57 mycroft 1776:
1.99 mycroft 1777: s = splserial();
1778: msr = sc->sc_msr;
1779: delta = sc->sc_msr_delta;
1780: sc->sc_msr_delta = 0;
1781: splx(s);
1.57 mycroft 1782:
1.99 mycroft 1783: if (ISSET(delta, sc->sc_msr_dcd)) {
1784: /*
1785: * Inform the tty layer that carrier detect changed.
1786: */
1787: (void) (*linesw[tp->t_line].l_modem)(tp, ISSET(msr, MSR_DCD));
1788: }
1.61 mycroft 1789:
1.99 mycroft 1790: if (ISSET(delta, sc->sc_msr_cts)) {
1791: /* Block or unblock output according to flow control. */
1792: if (ISSET(msr, sc->sc_msr_cts)) {
1793: sc->sc_tx_stopped = 0;
1794: (*linesw[tp->t_line].l_start)(tp);
1795: } else {
1796: sc->sc_tx_stopped = 1;
1.61 mycroft 1797: }
1.99 mycroft 1798: }
1799:
1800: #ifdef COM_DEBUG
1.101 mycroft 1801: if (com_debug)
1.127 mycroft 1802: comstatus(sc, "com_stsoft");
1.99 mycroft 1803: #endif
1804: }
1805:
1806: #ifdef __GENERIC_SOFT_INTERRUPTS
1807: void
1808: comsoft(arg)
1809: void *arg;
1810: {
1811: struct com_softc *sc = arg;
1812: struct tty *tp;
1813:
1.149 thorpej 1814: if (COM_ISALIVE(sc) == 0)
1.131 marc 1815: return;
1816:
1.99 mycroft 1817: {
1818: #else
1819: void
1.133 cgd 1820: #ifndef __NO_SOFT_SERIAL_INTERRUPT
1.99 mycroft 1821: comsoft()
1822: #else
1823: comsoft(arg)
1824: void *arg;
1825: #endif
1826: {
1827: struct com_softc *sc;
1828: struct tty *tp;
1829: int unit;
1.133 cgd 1830: #ifdef __NO_SOFT_SERIAL_INTERRUPT
1.99 mycroft 1831: int s;
1832:
1833: s = splsoftserial();
1834: com_softintr_scheduled = 0;
1835: #endif
1.57 mycroft 1836:
1.99 mycroft 1837: for (unit = 0; unit < com_cd.cd_ndevs; unit++) {
1838: sc = com_cd.cd_devs[unit];
1.132 cgd 1839: if (sc == NULL || !ISSET(sc->sc_hwflags, COM_HW_DEV_OK))
1.99 mycroft 1840: continue;
1.57 mycroft 1841:
1.149 thorpej 1842: if (COM_ISALIVE(sc) == 0)
1.131 marc 1843: continue;
1844:
1.99 mycroft 1845: tp = sc->sc_tty;
1.141 mycroft 1846: if (tp == NULL)
1847: continue;
1848: if (!ISSET(tp->t_state, TS_ISOPEN) && tp->t_wopen == 0)
1.57 mycroft 1849: continue;
1.108 is 1850: #endif
1851: tp = sc->sc_tty;
1.99 mycroft 1852:
1853: if (sc->sc_rx_ready) {
1854: sc->sc_rx_ready = 0;
1.127 mycroft 1855: com_rxsoft(sc, tp);
1.57 mycroft 1856: }
1857:
1.99 mycroft 1858: if (sc->sc_st_check) {
1859: sc->sc_st_check = 0;
1.127 mycroft 1860: com_stsoft(sc, tp);
1.62 mycroft 1861: }
1.57 mycroft 1862:
1.99 mycroft 1863: if (sc->sc_tx_done) {
1864: sc->sc_tx_done = 0;
1.127 mycroft 1865: com_txsoft(sc, tp);
1.57 mycroft 1866: }
1867: }
1868:
1.99 mycroft 1869: #ifndef __GENERIC_SOFT_INTERRUPTS
1.133 cgd 1870: #ifdef __NO_SOFT_SERIAL_INTERRUPT
1.99 mycroft 1871: splx(s);
1872: #endif
1873: #endif
1.21 mycroft 1874: }
1.140 ross 1875:
1876: #ifdef __ALIGN_BRACKET_LEVEL_FOR_CTAGS
1877: /* there has got to be a better way to do comsoft() */
1878: }}
1879: #endif
1.1 cgd 1880:
1.21 mycroft 1881: int
1.49 cgd 1882: comintr(arg)
1.127 mycroft 1883: void *arg;
1.21 mycroft 1884: {
1.49 cgd 1885: struct com_softc *sc = arg;
1.91 thorpej 1886: bus_space_tag_t iot = sc->sc_iot;
1887: bus_space_handle_t ioh = sc->sc_ioh;
1.127 mycroft 1888: u_char *put, *end;
1889: u_int cc;
1890: u_char lsr, iir;
1.55 mycroft 1891:
1.149 thorpej 1892: if (COM_ISALIVE(sc) == 0)
1.131 marc 1893: return (0);
1894:
1.91 thorpej 1895: iir = bus_space_read_1(iot, ioh, com_iir);
1.88 mycroft 1896: if (ISSET(iir, IIR_NOPEND))
1.55 mycroft 1897: return (0);
1.21 mycroft 1898:
1.127 mycroft 1899: end = sc->sc_ebuf;
1.99 mycroft 1900: put = sc->sc_rbput;
1901: cc = sc->sc_rbavail;
1902:
1903: do {
1904: u_char msr, delta;
1.21 mycroft 1905:
1.91 thorpej 1906: lsr = bus_space_read_1(iot, ioh, com_lsr);
1.103 drochner 1907: #if defined(DDB) || defined(KGDB)
1908: if (ISSET(lsr, LSR_BI)) {
1909: #ifdef DDB
1910: if (ISSET(sc->sc_hwflags, COM_HW_CONSOLE)) {
1.150 drochner 1911: console_debugger();
1.103 drochner 1912: continue;
1913: }
1914: #endif
1915: #ifdef KGDB
1916: if (ISSET(sc->sc_hwflags, COM_HW_KGDB)) {
1917: kgdb_connect(1);
1918: continue;
1919: }
1920: #endif
1.102 thorpej 1921: }
1.103 drochner 1922: #endif /* DDB || KGDB */
1.102 thorpej 1923:
1.101 mycroft 1924: if (ISSET(lsr, LSR_RCV_MASK) &&
1925: !ISSET(sc->sc_rx_flags, RX_IBUF_OVERFLOWED)) {
1.127 mycroft 1926: while (cc > 0) {
1927: put[0] = bus_space_read_1(iot, ioh, com_data);
1928: put[1] = lsr;
1929: put += 2;
1930: if (put >= end)
1931: put = sc->sc_rbuf;
1932: cc--;
1933:
1.99 mycroft 1934: lsr = bus_space_read_1(iot, ioh, com_lsr);
1.127 mycroft 1935: if (!ISSET(lsr, LSR_RCV_MASK))
1936: break;
1.99 mycroft 1937: }
1.127 mycroft 1938:
1.99 mycroft 1939: /*
1940: * Current string of incoming characters ended because
1.127 mycroft 1941: * no more data was available or we ran out of space.
1942: * Schedule a receive event if any data was received.
1943: * If we're out of space, turn off receive interrupts.
1.99 mycroft 1944: */
1945: sc->sc_rbput = put;
1946: sc->sc_rbavail = cc;
1.101 mycroft 1947: if (!ISSET(sc->sc_rx_flags, RX_TTY_OVERFLOWED))
1948: sc->sc_rx_ready = 1;
1.127 mycroft 1949:
1.99 mycroft 1950: /*
1951: * See if we are in danger of overflowing a buffer. If
1952: * so, use hardware flow control to ease the pressure.
1953: */
1.101 mycroft 1954: if (!ISSET(sc->sc_rx_flags, RX_IBUF_BLOCKED) &&
1.99 mycroft 1955: cc < sc->sc_r_hiwat) {
1.101 mycroft 1956: SET(sc->sc_rx_flags, RX_IBUF_BLOCKED);
1957: com_hwiflow(sc);
1.99 mycroft 1958: }
1.127 mycroft 1959:
1.99 mycroft 1960: /*
1.101 mycroft 1961: * If we're out of space, disable receive interrupts
1962: * until the queue has drained a bit.
1.99 mycroft 1963: */
1964: if (!cc) {
1.101 mycroft 1965: SET(sc->sc_rx_flags, RX_IBUF_OVERFLOWED);
1966: CLR(sc->sc_ier, IER_ERXRDY);
1967: bus_space_write_1(iot, ioh, com_ier, sc->sc_ier);
1.99 mycroft 1968: }
1.88 mycroft 1969: } else {
1970: if ((iir & IIR_IMASK) == IIR_RXRDY) {
1.91 thorpej 1971: bus_space_write_1(iot, ioh, com_ier, 0);
1.88 mycroft 1972: delay(10);
1.99 mycroft 1973: bus_space_write_1(iot, ioh, com_ier,sc->sc_ier);
1.88 mycroft 1974: iir = IIR_NOPEND;
1975: continue;
1976: }
1977: }
1.55 mycroft 1978:
1.99 mycroft 1979: msr = bus_space_read_1(iot, ioh, com_msr);
1980: delta = msr ^ sc->sc_msr;
1981: sc->sc_msr = msr;
1982: if (ISSET(delta, sc->sc_msr_mask)) {
1.127 mycroft 1983: SET(sc->sc_msr_delta, delta);
1.144 jonathan 1984:
1985: /*
1.151 ! mycroft 1986: * Pulse-per-second clock signal on edge of DCD?
1.144 jonathan 1987: */
1.151 ! mycroft 1988: if (ISSET(delta, sc->sc_ppsmask)) {
1.144 jonathan 1989: struct timeval tv;
1.151 ! mycroft 1990: if (ISSET(msr, sc->sc_ppsmask) ==
1.144 jonathan 1991: sc->sc_ppsassert) {
1992: /* XXX nanotime() */
1993: microtime(&tv);
1994: TIMEVAL_TO_TIMESPEC(&tv,
1995: &sc->ppsinfo.assert_timestamp);
1996: if (sc->ppsparam.mode & PPS_OFFSETASSERT) {
1997: timespecadd(&sc->ppsinfo.assert_timestamp,
1998: &sc->ppsparam.assert_offset,
1999: &sc->ppsinfo.assert_timestamp);
2000: TIMESPEC_TO_TIMEVAL(&tv, &sc->ppsinfo.assert_timestamp);
2001: }
2002:
2003: #ifdef PPS_SYNC
2004: if (sc->ppsparam.mode & PPS_HARDPPSONASSERT)
2005: hardpps(&tv, tv.tv_usec);
2006: #endif
2007: sc->ppsinfo.assert_sequence++;
2008: sc->ppsinfo.current_mode =
2009: sc->ppsparam.mode;
2010:
1.151 ! mycroft 2011: } else if (ISSET(msr, sc->sc_ppsmask) ==
1.144 jonathan 2012: sc->sc_ppsclear) {
2013: /* XXX nanotime() */
2014: microtime(&tv);
2015: TIMEVAL_TO_TIMESPEC(&tv,
2016: &sc->ppsinfo.clear_timestamp);
2017: if (sc->ppsparam.mode & PPS_OFFSETCLEAR) {
2018: timespecadd(&sc->ppsinfo.clear_timestamp,
2019: &sc->ppsparam.clear_offset,
2020: &sc->ppsinfo.clear_timestamp);
2021: TIMESPEC_TO_TIMEVAL(&tv, &sc->ppsinfo.clear_timestamp);
2022: }
2023:
2024: #ifdef PPS_SYNC
2025: if (sc->ppsparam.mode & PPS_HARDPPSONCLEAR)
2026: hardpps(&tv, tv.tv_usec);
2027: #endif
2028: sc->ppsinfo.clear_sequence++;
2029: sc->ppsinfo.current_mode =
2030: sc->ppsparam.mode;
2031: }
2032: }
1.99 mycroft 2033:
2034: /*
2035: * Stop output immediately if we lose the output
2036: * flow control signal or carrier detect.
2037: */
2038: if (ISSET(~msr, sc->sc_msr_mask)) {
2039: sc->sc_tbc = 0;
2040: sc->sc_heldtbc = 0;
1.69 mycroft 2041: #ifdef COM_DEBUG
1.101 mycroft 2042: if (com_debug)
2043: comstatus(sc, "comintr ");
1.69 mycroft 2044: #endif
1.99 mycroft 2045: }
1.55 mycroft 2046:
1.99 mycroft 2047: sc->sc_st_check = 1;
1.55 mycroft 2048: }
1.99 mycroft 2049: } while (!ISSET((iir = bus_space_read_1(iot, ioh, com_iir)), IIR_NOPEND));
1.55 mycroft 2050:
1.99 mycroft 2051: /*
2052: * Done handling any receive interrupts. See if data can be
2053: * transmitted as well. Schedule tx done event if no data left
2054: * and tty was marked busy.
2055: */
2056: if (ISSET(lsr, LSR_TXRDY)) {
2057: /*
2058: * If we've delayed a parameter change, do it now, and restart
2059: * output.
2060: */
2061: if (sc->sc_heldchange) {
2062: com_loadchannelregs(sc);
2063: sc->sc_heldchange = 0;
2064: sc->sc_tbc = sc->sc_heldtbc;
2065: sc->sc_heldtbc = 0;
2066: }
1.127 mycroft 2067:
1.99 mycroft 2068: /* Output the next chunk of the contiguous buffer, if any. */
2069: if (sc->sc_tbc > 0) {
2070: int n;
2071:
1.127 mycroft 2072: n = sc->sc_tbc;
2073: if (n > sc->sc_fifolen)
2074: n = sc->sc_fifolen;
1.99 mycroft 2075: bus_space_write_multi_1(iot, ioh, com_data, sc->sc_tba, n);
2076: sc->sc_tbc -= n;
2077: sc->sc_tba += n;
1.127 mycroft 2078: } else {
2079: /* Disable transmit completion interrupts if necessary. */
2080: if (ISSET(sc->sc_ier, IER_ETXRDY)) {
2081: CLR(sc->sc_ier, IER_ETXRDY);
2082: bus_space_write_1(iot, ioh, com_ier, sc->sc_ier);
2083: }
2084: if (sc->sc_tx_busy) {
2085: sc->sc_tx_busy = 0;
2086: sc->sc_tx_done = 1;
2087: }
1.62 mycroft 2088: }
1.99 mycroft 2089: }
1.62 mycroft 2090:
1.99 mycroft 2091: /* Wake up the poller. */
2092: #ifdef __GENERIC_SOFT_INTERRUPTS
2093: softintr_schedule(sc->sc_si);
2094: #else
1.133 cgd 2095: #ifndef __NO_SOFT_SERIAL_INTERRUPT
1.99 mycroft 2096: setsoftserial();
2097: #else
2098: if (!com_softintr_scheduled) {
2099: com_softintr_scheduled = 1;
2100: timeout(comsoft, NULL, 1);
1.1 cgd 2101: }
1.99 mycroft 2102: #endif
2103: #endif
1.115 explorer 2104:
2105: #if NRND > 0 && defined(RND_COM)
2106: rnd_add_uint32(&sc->rnd_source, iir | lsr);
2107: #endif
2108:
1.88 mycroft 2109: return (1);
1.1 cgd 2110: }
2111:
2112: /*
1.102 thorpej 2113: * The following functions are polled getc and putc routines, shared
2114: * by the console and kgdb glue.
2115: */
2116:
2117: int
2118: com_common_getc(iot, ioh)
2119: bus_space_tag_t iot;
2120: bus_space_handle_t ioh;
2121: {
2122: int s = splserial();
2123: u_char stat, c;
2124:
1.135 thorpej 2125: /* block until a character becomes available */
2126: while (!ISSET(stat = bus_space_read_1(iot, ioh, com_lsr), LSR_RXRDY))
1.102 thorpej 2127: ;
1.135 thorpej 2128:
1.102 thorpej 2129: c = bus_space_read_1(iot, ioh, com_data);
2130: stat = bus_space_read_1(iot, ioh, com_iir);
2131: splx(s);
2132: return (c);
2133: }
2134:
2135: void
2136: com_common_putc(iot, ioh, c)
2137: bus_space_tag_t iot;
2138: bus_space_handle_t ioh;
2139: int c;
2140: {
2141: int s = splserial();
2142: u_char stat;
1.127 mycroft 2143: int timo;
1.102 thorpej 2144:
2145: /* wait for any pending transmission to finish */
2146: timo = 50000;
2147: while (!ISSET(stat = bus_space_read_1(iot, ioh, com_lsr), LSR_TXRDY)
2148: && --timo)
2149: ;
1.135 thorpej 2150:
1.102 thorpej 2151: bus_space_write_1(iot, ioh, com_data, c);
2152: /* wait for this transmission to complete */
2153: timo = 1500000;
2154: while (!ISSET(stat = bus_space_read_1(iot, ioh, com_lsr), LSR_TXRDY)
2155: && --timo)
2156: ;
1.135 thorpej 2157:
1.102 thorpej 2158: /* clear any interrupts generated by this transmission */
2159: stat = bus_space_read_1(iot, ioh, com_iir);
2160: splx(s);
2161: }
2162:
2163: /*
1.99 mycroft 2164: * Initialize UART to known state.
2165: */
1.106 drochner 2166: int
1.109 is 2167: cominit(iot, iobase, rate, frequency, cflag, iohp)
1.91 thorpej 2168: bus_space_tag_t iot;
1.106 drochner 2169: int iobase;
1.109 is 2170: int rate, frequency;
1.106 drochner 2171: tcflag_t cflag;
2172: bus_space_handle_t *iohp;
1.1 cgd 2173: {
1.106 drochner 2174: bus_space_handle_t ioh;
2175:
2176: if (bus_space_map(iot, iobase, COM_NPORTS, 0, &ioh))
1.110 enami 2177: return (ENOMEM); /* ??? */
1.1 cgd 2178:
1.116 fvdl 2179: bus_space_write_1(iot, ioh, com_lcr, LCR_EERS);
2180: bus_space_write_1(iot, ioh, com_efr, 0);
1.91 thorpej 2181: bus_space_write_1(iot, ioh, com_lcr, LCR_DLAB);
1.109 is 2182: rate = comspeed(rate, frequency);
1.91 thorpej 2183: bus_space_write_1(iot, ioh, com_dlbl, rate);
2184: bus_space_write_1(iot, ioh, com_dlbh, rate >> 8);
1.106 drochner 2185: bus_space_write_1(iot, ioh, com_lcr, cflag2lcr(cflag));
1.99 mycroft 2186: bus_space_write_1(iot, ioh, com_mcr, 0);
1.91 thorpej 2187: bus_space_write_1(iot, ioh, com_fifo,
1.87 mycroft 2188: FIFO_ENABLE | FIFO_RCV_RST | FIFO_XMT_RST | FIFO_TRIGGER_1);
1.99 mycroft 2189: bus_space_write_1(iot, ioh, com_ier, 0);
1.106 drochner 2190:
2191: *iohp = ioh;
1.110 enami 2192: return (0);
1.99 mycroft 2193: }
2194:
2195: /*
1.106 drochner 2196: * Following are all routines needed for COM to act as console
1.99 mycroft 2197: */
1.106 drochner 2198:
2199: int
1.109 is 2200: comcnattach(iot, iobase, rate, frequency, cflag)
1.99 mycroft 2201: bus_space_tag_t iot;
1.106 drochner 2202: int iobase;
1.109 is 2203: int rate, frequency;
1.106 drochner 2204: tcflag_t cflag;
1.99 mycroft 2205: {
1.106 drochner 2206: int res;
1.120 mycroft 2207: static struct consdev comcons = {
2208: NULL, NULL, comcngetc, comcnputc, comcnpollc, NODEV, CN_NORMAL
2209: };
1.106 drochner 2210:
1.109 is 2211: res = cominit(iot, iobase, rate, frequency, cflag, &comconsioh);
1.110 enami 2212: if (res)
2213: return (res);
1.106 drochner 2214:
2215: cn_tab = &comcons;
2216:
2217: comconstag = iot;
2218: comconsaddr = iobase;
2219: comconsrate = rate;
2220: comconscflag = cflag;
1.99 mycroft 2221:
1.110 enami 2222: return (0);
1.1 cgd 2223: }
2224:
1.80 christos 2225: int
1.1 cgd 2226: comcngetc(dev)
1.21 mycroft 2227: dev_t dev;
1.1 cgd 2228: {
2229:
1.102 thorpej 2230: return (com_common_getc(comconstag, comconsioh));
1.1 cgd 2231: }
2232:
2233: /*
2234: * Console kernel output character routine.
2235: */
1.48 mycroft 2236: void
1.1 cgd 2237: comcnputc(dev, c)
2238: dev_t dev;
1.21 mycroft 2239: int c;
1.1 cgd 2240: {
2241:
1.102 thorpej 2242: com_common_putc(comconstag, comconsioh, c);
1.37 mycroft 2243: }
2244:
2245: void
2246: comcnpollc(dev, on)
2247: dev_t dev;
2248: int on;
2249: {
2250:
1.106 drochner 2251: }
2252:
2253: #ifdef KGDB
2254: int
1.109 is 2255: com_kgdb_attach(iot, iobase, rate, frequency, cflag)
1.106 drochner 2256: bus_space_tag_t iot;
2257: int iobase;
1.112 mikel 2258: int rate, frequency;
1.106 drochner 2259: tcflag_t cflag;
2260: {
2261: int res;
1.107 drochner 2262:
2263: if (iot == comconstag && iobase == comconsaddr)
1.110 enami 2264: return (EBUSY); /* cannot share with console */
1.106 drochner 2265:
1.109 is 2266: res = cominit(iot, iobase, rate, frequency, cflag, &com_kgdb_ioh);
1.110 enami 2267: if (res)
2268: return (res);
1.106 drochner 2269:
2270: kgdb_attach(com_kgdb_getc, com_kgdb_putc, NULL);
2271: kgdb_dev = 123; /* unneeded, only to satisfy some tests */
2272:
2273: com_kgdb_iot = iot;
2274: com_kgdb_addr = iobase;
2275:
1.110 enami 2276: return (0);
1.106 drochner 2277: }
2278:
2279: /* ARGSUSED */
2280: int
2281: com_kgdb_getc(arg)
2282: void *arg;
2283: {
2284:
2285: return (com_common_getc(com_kgdb_iot, com_kgdb_ioh));
2286: }
2287:
2288: /* ARGSUSED */
2289: void
2290: com_kgdb_putc(arg, c)
2291: void *arg;
2292: int c;
2293: {
2294:
2295: return (com_common_putc(com_kgdb_iot, com_kgdb_ioh, c));
2296: }
2297: #endif /* KGDB */
2298:
2299: /* helper function to identify the com ports used by
2300: console or KGDB (and not yet autoconf attached) */
2301: int
2302: com_is_console(iot, iobase, ioh)
1.110 enami 2303: bus_space_tag_t iot;
2304: int iobase;
2305: bus_space_handle_t *ioh;
1.106 drochner 2306: {
2307: bus_space_handle_t help;
2308:
1.110 enami 2309: if (!comconsattached &&
2310: iot == comconstag && iobase == comconsaddr)
1.106 drochner 2311: help = comconsioh;
2312: #ifdef KGDB
1.110 enami 2313: else if (!com_kgdb_attached &&
2314: iot == com_kgdb_iot && iobase == com_kgdb_addr)
1.106 drochner 2315: help = com_kgdb_ioh;
2316: #endif
2317: else
1.110 enami 2318: return (0);
1.106 drochner 2319:
1.110 enami 2320: if (ioh)
2321: *ioh = help;
2322: return (1);
1.2 cgd 2323: }
CVSweb <webmaster@jp.NetBSD.org>