com.c revision 1.12.2.15 1 /*-
2 * Copyright (c) 1993 Charles Hannum.
3 * Copyright (c) 1991 The Regents of the University of California.
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. All advertising materials mentioning features or use of this software
15 * must display the following acknowledgement:
16 * This product includes software developed by the University of
17 * California, Berkeley and its contributors.
18 * 4. Neither the name of the University nor the names of its contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * SUCH DAMAGE.
33 *
34 * from: @(#)com.c 7.5 (Berkeley) 5/16/91
35 * $Id: com.c,v 1.12.2.15 1993/10/29 17:57:05 mycroft Exp $
36 */
37
38 /*
39 * COM driver, based originally on HP dca driver
40 * uses National Semiconductor NS16450/NS16550AF UART
41 */
42 #include <sys/param.h>
43 #include <sys/systm.h>
44 #include <sys/ioctl.h>
45 #include <sys/select.h>
46 #include <sys/tty.h>
47 #include <sys/proc.h>
48 #include <sys/user.h>
49 #include <sys/conf.h>
50 #include <sys/file.h>
51 #include <sys/uio.h>
52 #include <sys/kernel.h>
53 #include <sys/syslog.h>
54 #include <sys/types.h>
55 #include <sys/device.h>
56
57 #include <machine/cpu.h>
58 #include <machine/pio.h>
59
60 #include <i386/isa/isavar.h>
61 #include <i386/isa/icu.h>
62 #include <i386/isa/comreg.h>
63
64 struct com_softc {
65 struct device sc_dev;
66 struct isadev sc_id;
67 struct intrhand sc_ih;
68
69 u_short sc_iobase;
70 u_char sc_flags;
71 #define COM_SOFTCAR 0x01
72 #define COM_FIFO 0x02
73 u_char sc_bufn;
74 u_char *sc_buf;
75 };
76 /* XXXX should be in com_softc, but not ready for that yet */
77 #include "com.h"
78 struct tty *com_tty[NCOM];
79
80 int comdefaultrate = TTYDEF_SPEED;
81
82 static int comprobe __P((struct device *, struct cfdata *, void *));
83 static void comforceintr __P((void *));
84 static void comattach __P((struct device *, struct device *, void *));
85 static int comintr __P((struct com_softc *));
86
87 struct cfdriver comcd =
88 { NULL, "com", comprobe, comattach, DV_TTY, sizeof (struct com_softc) };
89
90 int comparam __P((struct tty *, struct termios *));
91 void comstart __P((struct tty *));
92
93 int comconsole = -1;
94 int comconsinit;
95 int commajor;
96 extern struct tty *constty;
97
98 #define COMUNIT(x) (minor(x))
99
100 #define bis(c, b) do { const register u_short com_ad = (c); \
101 outb(com_ad, inb(com_ad) | (b)); } while(0)
102 #define bic(c, b) do { const register u_short com_ad = (c); \
103 outb(com_ad, inb(com_ad) &~ (b)); } while(0)
104
105 static int
106 comspeed(speed)
107 long speed;
108 {
109 #define divrnd(n, q) (((n)*2/(q)+1)/2) /* divide and round off */
110
111 int x, err;
112
113 if (speed == 0)
114 return 0;
115 if (speed < 0)
116 return -1;
117 x = divrnd((COM_FREQ / 16), speed);
118 if (x <= 0)
119 return -1;
120 err = divrnd((COM_FREQ / 16) * 1000, speed * x) - 1000;
121 if (err < 0)
122 err = -err;
123 if (err > COM_TOLERANCE)
124 return -1;
125 return x;
126
127 #undef divrnd(n, q)
128 }
129
130 static int
131 _comprobe(iobase)
132 u_short iobase;
133 {
134
135 /* force access to id reg */
136 outb(iobase + com_cfcr, 0);
137 outb(iobase + com_iir, 0);
138 if (inb(iobase + com_iir) & 0x38)
139 return 0;
140 outb(iobase + com_ier, 0);
141 return 1;
142 }
143
144 static int
145 comprobe(parent, cf, aux)
146 struct device *parent;
147 struct cfdata *cf;
148 void *aux;
149 {
150 struct isa_attach_args *ia = aux;
151 u_short iobase = ia->ia_iobase;
152
153 if (iobase == IOBASEUNK)
154 return 0;
155
156 if (!_comprobe(iobase))
157 return 0;
158
159 if (ia->ia_irq == IRQUNK) {
160 ia->ia_irq = isa_discoverintr(comforceintr, aux);
161 if (ia->ia_irq == IRQNONE)
162 return 0;
163 }
164
165 /* disable interrupts */
166 outb(iobase + com_ier, 0);
167 outb(iobase + com_mcr, 0);
168
169 ia->ia_iosize = COM_NPORTS;
170 ia->ia_drq = DRQUNK;
171 ia->ia_msize = 0;
172 return 1;
173 }
174
175 static void
176 comforceintr(aux)
177 void *aux;
178 {
179 struct isa_attach_args *ia = aux;
180 u_short iobase = ia->ia_iobase;
181
182 #if 0
183 /*
184 * As usual, the PC compatible world isn't. We'd like to use the
185 * loopback feature to generate an interrupt, but alas, some lame
186 * clones don't support it.
187 */
188 outb(iobase + com_mcr, MCR_IENABLE | MCR_LOOPBACK);
189 outb(iobase + com_ier, IER_EMSC);
190 outb(iobase + com_mcr, MCR_IENABLE | MCR_LOOPBACK | MCR_DRS);
191 outb(iobase + com_mcr, MCR_IENABLE | MCR_LOOPBACK);
192 #else
193 /*
194 * So instead we try to force the transmit buffer empty (though
195 * it probably is already) and get a transmit interrupt.
196 */
197 outb(iobase + com_cfcr, CFCR_8BITS); /* turn off DLAB */
198 outb(iobase + com_ier, 0);
199 outb(iobase + com_fifo, 0);
200 outb(iobase + com_lsr, LSR_TXRDY | LSR_TSRE);
201 outb(iobase + com_mcr, MCR_IENABLE);
202 outb(iobase + com_ier, IER_ETXRDY);
203 #endif
204 }
205
206 static void
207 comattach(parent, self, aux)
208 struct device *parent, *self;
209 void *aux;
210 {
211 struct com_softc *sc = (struct com_softc *)self;
212 struct isa_attach_args *ia = aux;
213 u_short iobase = ia->ia_iobase;
214 struct tty *tp;
215 u_char unit = sc->sc_dev.dv_unit;
216
217 if (iobase == comconsole)
218 delay(1000);
219
220 sc->sc_iobase = iobase;
221 sc->sc_flags = 0;
222
223 /* look for a NS 16550AF UART with FIFOs */
224 outb(iobase + com_fifo,
225 FIFO_ENABLE | FIFO_RCV_RST | FIFO_XMT_RST | FIFO_TRIGGER_14);
226 delay(100);
227 if ((inb(iobase + com_iir) & IIR_FIFO_MASK) == IIR_FIFO_MASK)
228 if ((inb(iobase + com_fifo) & FIFO_TRIGGER_14) == FIFO_TRIGGER_14) {
229 sc->sc_flags |= COM_FIFO;
230 printf(": ns16550a, working fifo\n");
231 } else
232 printf(": ns82550 or ns16550, broken fifo\n");
233 else
234 printf(": ns82450 or ns16450, no fifo\n");
235 outb(iobase + com_fifo, 0);
236 isa_establish(&sc->sc_id, &sc->sc_dev);
237
238 outb(iobase + com_ier, 0);
239 outb(iobase + com_mcr, 0);
240
241 sc->sc_ih.ih_fun = comintr;
242 sc->sc_ih.ih_arg = sc;
243 intr_establish(ia->ia_irq, &sc->sc_ih, DV_TTY);
244
245 /*
246 * Need to reset baud rate, etc. of next print so reset comconsinit.
247 * Also make sure console is always "hardwired"
248 */
249 if (iobase == comconsole) {
250 constty = com_tty[unit] = ttymalloc();
251 comconsinit = 0;
252 sc->sc_flags |= COM_SOFTCAR;
253 }
254 }
255
256 int
257 comopen(dev, flag, mode, p)
258 dev_t dev;
259 int flag, mode;
260 struct proc *p;
261 {
262 int unit = COMUNIT(dev);
263 struct com_softc *sc;
264 u_short iobase;
265 struct tty *tp;
266 int s;
267 int error = 0;
268
269 if (unit >= comcd.cd_ndevs)
270 return ENXIO;
271 sc = comcd.cd_devs[unit];
272 if (!sc)
273 return ENXIO;
274
275 if (!com_tty[unit])
276 tp = com_tty[unit] = ttymalloc();
277 else
278 tp = com_tty[unit];
279
280 tp->t_oproc = comstart;
281 tp->t_param = comparam;
282 tp->t_dev = dev;
283 if ((tp->t_state & TS_ISOPEN) == 0) {
284 tp->t_state |= TS_WOPEN;
285 ttychars(tp);
286 /* preserve previous speed, if any */
287 if (tp->t_ispeed == 0) {
288 tp->t_iflag = TTYDEF_IFLAG;
289 tp->t_oflag = TTYDEF_OFLAG;
290 tp->t_cflag = TTYDEF_CFLAG;
291 tp->t_lflag = TTYDEF_LFLAG;
292 tp->t_ispeed = tp->t_ospeed = comdefaultrate;
293 }
294 comparam(tp, &tp->t_termios);
295 ttsetwater(tp);
296 } else if (tp->t_state & TS_XCLUDE && p->p_ucred->cr_uid != 0)
297 return EBUSY;
298
299 s = spltty();
300 iobase = sc->sc_iobase;
301 /* flush any pending I/O */
302 if (sc->sc_flags & COM_FIFO)
303 outb(iobase + com_fifo,
304 FIFO_ENABLE | FIFO_RCV_RST | FIFO_XMT_RST | FIFO_TRIGGER_8);
305 (void) inb(iobase + com_lsr);
306 (void) inb(iobase + com_data);
307 /* you turn me on, baby */
308 outb(iobase + com_mcr, MCR_DTR | MCR_RTS | MCR_IENABLE);
309 outb(iobase + com_ier, IER_ERXRDY | IER_ETXRDY | IER_ERLS | IER_EMSC);
310
311 if (sc->sc_flags & COM_SOFTCAR || inb(iobase + com_msr) & MSR_DCD)
312 tp->t_state |= TS_CARR_ON;
313 else
314 tp->t_state &=~ TS_CARR_ON;
315 while ((flag & O_NONBLOCK) == 0 && (tp->t_cflag & CLOCAL) == 0 &&
316 (tp->t_state & TS_CARR_ON) == 0) {
317 /* wait for carrier; allow signals */
318 tp->t_state |= TS_WOPEN;
319 if (error = ttysleep(tp, (caddr_t)&tp->t_rawq, TTIPRI | PCATCH,
320 ttopen, 0)) {
321 splx(s);
322 return error;
323 }
324 }
325 splx(s);
326
327 return (*linesw[tp->t_line].l_open)(dev, tp);
328 }
329
330 int
331 comclose(dev, flag)
332 dev_t dev;
333 int flag;
334 {
335 int unit = COMUNIT(dev);
336 struct com_softc *sc = comcd.cd_devs[unit];
337 u_short iobase = sc->sc_iobase;
338 struct tty *tp = com_tty[unit];
339
340 (*linesw[tp->t_line].l_close)(tp, flag);
341 bic(iobase + com_cfcr, CFCR_SBREAK);
342 outb(iobase + com_ier, 0);
343 if (tp->t_cflag & HUPCL)
344 outb(iobase + com_mcr, 0);
345 ttyclose(tp);
346 #ifdef notyet /* XXXX */
347 if (iobase != comconsole) {
348 ttyfree(tp);
349 com_tty[unit] = (struct tty *)NULL;
350 }
351 #endif
352 return 0;
353 }
354
355 int
356 comread(dev, uio, flag)
357 dev_t dev;
358 struct uio *uio;
359 int flag;
360 {
361 struct tty *tp = com_tty[COMUNIT(dev)];
362
363 return (*linesw[tp->t_line].l_read)(tp, uio, flag);
364 }
365
366 int
367 comwrite(dev, uio, flag)
368 dev_t dev;
369 struct uio *uio;
370 int flag;
371 {
372 struct tty *tp = com_tty[COMUNIT(dev)];
373
374 #if 0
375 /* XXXX what is this for? */
376 if (constty == tp)
377 constty = NULL;
378 #endif
379 return (*linesw[tp->t_line].l_write)(tp, uio, flag);
380 }
381
382 static u_char
383 tiocm_xxx2mcr(data)
384 int data;
385 {
386 u_char m = 0;
387 if (data & TIOCM_DTR)
388 m |= MCR_DTR;
389 if (data & TIOCM_RTS)
390 m |= MCR_RTS;
391 return m;
392 }
393
394 int
395 comioctl(dev, cmd, data, flag)
396 dev_t dev;
397 int cmd;
398 caddr_t data;
399 int flag;
400 {
401 int unit = COMUNIT(dev);
402 struct com_softc *sc = comcd.cd_devs[unit];
403 u_short iobase = sc->sc_iobase;
404 struct tty *tp = com_tty[unit];
405 int error;
406
407 error = (*linesw[tp->t_line].l_ioctl)(tp, cmd, data, flag);
408 if (error >= 0)
409 return error;
410 error = ttioctl(tp, cmd, data, flag);
411 if (error >= 0)
412 return error;
413
414 switch (cmd) {
415 case TIOCSBRK:
416 bis(iobase + com_cfcr, CFCR_SBREAK);
417 break;
418 case TIOCCBRK:
419 bic(iobase + com_cfcr, CFCR_SBREAK);
420 break;
421 case TIOCSDTR:
422 bis(iobase + com_mcr, MCR_DTR | MCR_RTS);
423 break;
424 case TIOCCDTR:
425 bic(iobase + com_mcr, MCR_DTR | MCR_RTS);
426 break;
427 case TIOCMSET:
428 outb(iobase + com_mcr, tiocm_xxx2mcr(*(int *)data) | MCR_IENABLE);
429 break;
430 case TIOCMBIS:
431 bis(iobase + com_mcr, tiocm_xxx2mcr(*(int *)data));
432 break;
433 case TIOCMBIC:
434 bic(iobase + com_mcr, tiocm_xxx2mcr(*(int *)data));
435 break;
436 case TIOCMGET:
437 {
438 u_char m = inb(iobase + com_mcr);
439 int bits = 0;
440
441 m = inb(iobase + com_mcr);
442 if (m & MCR_DTR)
443 bits |= TIOCM_DTR;
444 if (m & MCR_RTS)
445 bits |= TIOCM_RTS;
446 m = inb(iobase + com_msr);
447 if (m & MSR_DCD)
448 bits |= TIOCM_CD;
449 if (m & MSR_CTS)
450 bits |= TIOCM_CTS;
451 if (m & MSR_DSR)
452 bits |= TIOCM_DSR;
453 if (m & (MSR_RI | MSR_TERI))
454 bits |= TIOCM_RI;
455 if (inb(iobase + com_ier))
456 bits |= TIOCM_LE;
457 *(int *)data = bits;
458 break;
459 }
460 break;
461 default:
462 return ENOTTY;
463 }
464
465 return 0;
466 }
467
468 int
469 comparam(tp, t)
470 struct tty *tp;
471 struct termios *t;
472 {
473 int unit = COMUNIT(tp->t_dev);
474 struct com_softc *sc = comcd.cd_devs[unit];
475 u_short iobase = sc->sc_iobase;
476 int ospeed = comspeed(t->c_ospeed);
477 tcflag_t cflag = t->c_cflag;
478 u_char cfcr;
479 int s;
480
481 /* check requested parameters */
482 if (ospeed < 0 || (t->c_ispeed && t->c_ispeed != t->c_ospeed))
483 return EINVAL;
484
485 switch (cflag & CSIZE) {
486 case CS5:
487 cfcr = CFCR_5BITS;
488 break;
489 case CS6:
490 cfcr = CFCR_6BITS;
491 break;
492 case CS7:
493 cfcr = CFCR_7BITS;
494 break;
495 case CS8:
496 cfcr = CFCR_8BITS;
497 break;
498 }
499 if (cflag & PARENB) {
500 cfcr |= CFCR_PENAB;
501 if ((cflag & PARODD) == 0)
502 cfcr |= CFCR_PEVEN;
503 }
504 if (cflag & CSTOPB)
505 cfcr |= CFCR_STOPB;
506
507 s = spltty();
508
509 /* and copy to tty */
510 tp->t_ispeed = t->c_ispeed;
511 tp->t_ospeed = t->c_ospeed;
512 tp->t_cflag = cflag;
513
514 if (ospeed == 0)
515 bic(iobase + com_mcr, MCR_DTR | MCR_RTS);
516 else
517 bis(iobase + com_mcr, MCR_DTR | MCR_RTS);
518
519 outb(iobase + com_cfcr, cfcr | CFCR_DLAB);
520 outb(iobase + com_dlbl, ospeed);
521 outb(iobase + com_dlbh, ospeed>>8);
522 outb(iobase + com_cfcr, cfcr);
523
524 /* when not using CRTS_IFLOW, RTS follows DTR */
525 if ((cflag & CRTS_IFLOW) == 0) {
526 u_char mcr = inb(iobase + com_mcr);
527
528 if (mcr & MCR_DTR)
529 if ((mcr & MCR_RTS) == 0)
530 outb(iobase + com_mcr, mcr | MCR_RTS);
531 else
532 ;
533 else
534 if (mcr & MCR_RTS)
535 outb(iobase + com_mcr, mcr &~ MCR_RTS);
536 else
537 ;
538 }
539
540 splx(s);
541
542 return 0;
543 }
544
545 void
546 comstart(tp)
547 struct tty *tp;
548 {
549 int unit = COMUNIT(tp->t_dev);
550 struct com_softc *sc = comcd.cd_devs[unit];
551 u_short iobase = sc->sc_iobase;
552 int s;
553
554 s = spltty();
555 if (tp->t_state & (TS_TTSTOP | TS_BUSY))
556 goto out;
557 if (tp->t_cflag & CCTS_OFLOW && (inb(iobase + com_mcr) & MSR_CTS) == 0)
558 goto out;
559 if (tp->t_outq.c_cc <= tp->t_lowat) {
560 if (tp->t_state & TS_ASLEEP) {
561 tp->t_state &=~ TS_ASLEEP;
562 wakeup((caddr_t)&tp->t_outq);
563 }
564 selwakeup(&tp->t_wsel);
565 }
566 if (tp->t_outq.c_cc == 0)
567 goto out;
568 tp->t_state |= TS_BUSY;
569 if ((inb(iobase + com_lsr) & LSR_TXRDY) == 0)
570 goto out;
571 if (sc->sc_flags & COM_FIFO) {
572 u_char buffer[16], *cp = buffer;
573 int n = q_to_b(&tp->t_outq, cp, sizeof buffer);
574 do {
575 outb(iobase + com_data, *cp++);
576 } while (--n);
577 } else
578 outb(iobase + com_data, getc(&tp->t_outq));
579 out:
580 splx(s);
581 }
582
583 /*
584 * Stop output on a line.
585 */
586 void
587 comstop(tp, flag)
588 struct tty *tp;
589 {
590 int s;
591
592 s = spltty();
593 if (tp->t_state & TS_BUSY)
594 if ((tp->t_state & TS_TTSTOP) == 0)
595 tp->t_state |= TS_FLUSH;
596 splx(s);
597 }
598
599 static void
600 comeint(sc, stat)
601 struct com_softc *sc;
602 int stat;
603 {
604 u_short iobase = sc->sc_iobase;
605 struct tty *tp = com_tty[sc->sc_dev.dv_unit];
606 int c;
607
608 c = inb(iobase + com_data);
609 if ((tp->t_state & TS_ISOPEN) == 0)
610 return;
611 if (stat & (LSR_BI | LSR_FE))
612 c |= TTY_FE;
613 else if (stat & LSR_PE)
614 c |= TTY_PE;
615 else if (stat & LSR_OE) {
616 c |= TTY_PE; /* XXX ought to have its own define */
617 log(LOG_WARNING, "%s: silo overflow\n", sc->sc_dev.dv_xname);
618 }
619 /* XXXX put in FIFO and process later */
620 (*linesw[tp->t_line].l_rint)(c, tp);
621 }
622
623 static void
624 commint(sc)
625 struct com_softc *sc;
626 {
627 u_short iobase = sc->sc_iobase;
628 struct tty *tp = com_tty[sc->sc_dev.dv_unit];
629 u_char stat;
630
631 stat = inb(iobase + com_msr);
632 if (stat & MSR_DDCD && (sc->sc_flags & COM_SOFTCAR) == 0) {
633 if (stat & MSR_DCD)
634 (void)(*linesw[tp->t_line].l_modem)(tp, 1);
635 else if ((*linesw[tp->t_line].l_modem)(tp, 0) == 0)
636 bic(iobase + com_mcr, MCR_DTR | MCR_RTS);
637 }
638 if (stat & MSR_DCTS && tp->t_state & TS_ISOPEN && tp->t_cflag & CRTSCTS) {
639 /* the line is up and we want to do rts/cts flow control */
640 if (stat & MSR_CTS) {
641 tp->t_state &=~ TS_TTSTOP;
642 ttstart(tp);
643 } else
644 tp->t_state |= TS_TTSTOP;
645 }
646 }
647
648 static int
649 comintr(sc)
650 struct com_softc *sc;
651 {
652 u_short iobase = sc->sc_iobase;
653 struct tty *tp;
654 u_char code;
655
656 code = inb(iobase + com_iir);
657 if (code & IIR_NOPEND)
658 return 0;
659
660 for (;;) {
661 switch (code & IIR_IMASK) {
662 case IIR_RXRDY:
663 case IIR_RXTOUT:
664 tp = com_tty[sc->sc_dev.dv_unit];
665 /* XXXX put in FIFO and process later */
666 #define RCVBYTE() \
667 code = inb(iobase + com_data); \
668 if (tp->t_state & TS_ISOPEN) \
669 (*linesw[tp->t_line].l_rint)(code, tp)
670 RCVBYTE();
671 if (sc->sc_flags & COM_FIFO)
672 while (code = inb(iobase + com_lsr) & LSR_RCV_MASK) {
673 if (code == LSR_RXRDY) {
674 RCVBYTE();
675 } else
676 comeint(sc, code);
677 }
678 break;
679 case IIR_TXRDY:
680 tp = com_tty[sc->sc_dev.dv_unit];
681 tp->t_state &=~ TS_BUSY;
682 if (tp->t_state & TS_FLUSH)
683 tp->t_state &=~ TS_FLUSH;
684 else
685 if (tp->t_line)
686 (*linesw[tp->t_line].l_start)(tp);
687 else
688 comstart(tp);
689 break;
690 case IIR_MLSC:
691 commint(sc);
692 break;
693 case IIR_RLS:
694 comeint(sc, inb(iobase + com_lsr));
695 break;
696 default:
697 log(LOG_WARNING, "%s: weird iir=0x%x\n",
698 sc->sc_dev.dv_xname, code);
699 /* fall through */
700 }
701
702 code = inb(iobase + com_iir);
703 if (code & IIR_NOPEND)
704 return 1;
705 }
706 }
707
708 /* XXXXXXXXXXXXXXXX ---- gremlins below here ---- XXXXXXXXXXXXXXXX */
709
710 #if 0
711 /*
712 * Following are all routines needed for COM to act as console
713 */
714 #include "i386/i386/cons.h"
715
716 comcnprobe(cp)
717 struct consdev *cp;
718 {
719 /* XXXX */
720 if (!_comprobe(CONADDR))
721 return CN_DEAD;
722
723 /* locate the major number */
724 for (commajor = 0; commajor < nchrdev; commajor++)
725 if (cdevsw[commajor].d_open == comopen)
726 break;
727
728 /* initialize required fields */
729 cp->cn_dev = makedev(commajor, unit);
730 #ifdef COMCONSOLE
731 cp->cn_pri = CN_REMOTE; /* Force a serial port console */
732 #else
733 cp->cn_pri = CN_NORMAL;
734 #endif
735 }
736
737 comcninit(cp)
738 struct consdev *cp;
739 {
740 int unit = COMUNIT(cp->cn_dev);
741
742 comconsole = CONADDR;
743 comconsinit = 0;
744 }
745
746 cominit(unit, rate)
747 int unit, rate;
748 {
749 int com;
750 int s;
751 short stat;
752
753 com = com_addr[unit];
754 s = splhigh();
755 outb(com+com_cfcr, CFCR_DLAB);
756 rate = COM_BAUDDIV(rate);
757 outb(com+com_data, rate & 0xFF);
758 outb(com+com_ier, rate >> 8);
759 outb(com+com_cfcr, CFCR_8BITS);
760 outb(com+com_ier, IER_ERXRDY | IER_ETXRDY);
761 outb(com+com_fifo, FIFO_ENABLE|FIFO_RCV_RST|FIFO_XMT_RST|FIFO_TRIGGER_4);
762 stat = inb(com+com_iir);
763 splx(s);
764 }
765
766 comcngetc(dev)
767 {
768 com = com_addr[COMUNIT(dev)];
769 short stat;
770 int c, s;
771
772 s = splhigh();
773 while (((stat = inb(com+com_lsr)) & LSR_RXRDY) == 0)
774 ;
775 c = inb(com+com_data);
776 stat = inb(com+com_iir);
777 splx(s);
778 return c;
779 }
780
781 /*
782 * Console kernel output character routine.
783 */
784 comcnputc(dev, c)
785 dev_t dev;
786 int c;
787 {
788 com = com_addr[COMUNIT(dev)];
789 int timo;
790 short stat;
791 int s = splhigh();
792
793 if (comconsinit == 0) {
794 (void) cominit(COMUNIT(dev), comdefaultrate);
795 comconsinit = 1;
796 }
797 /* wait for any pending transmission to finish */
798 timo = 50000;
799 while (((stat = inb(com+com_lsr)) & LSR_TXRDY) == 0 && --timo)
800 ;
801 outb(com+com_data, c);
802 /* wait for this transmission to complete */
803 timo = 1500000;
804 while (((stat = inb(com+com_lsr)) & LSR_TXRDY) == 0 && --timo)
805 ;
806 /* clear any interrupts generated by this transmission */
807 stat = inb(com+com_iir);
808 splx(s);
809 }
810 #endif
811