com.c revision 1.12.2.16 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.16 1993/10/29 19:59:09 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 u_char cfcr;
478 int s;
479
480 /* check requested parameters */
481 if (ospeed < 0 || (t->c_ispeed && t->c_ispeed != t->c_ospeed))
482 return EINVAL;
483
484 switch (t->c_cflag & CSIZE) {
485 case CS5:
486 cfcr = CFCR_5BITS;
487 break;
488 case CS6:
489 cfcr = CFCR_6BITS;
490 break;
491 case CS7:
492 cfcr = CFCR_7BITS;
493 break;
494 case CS8:
495 cfcr = CFCR_8BITS;
496 break;
497 }
498 if (t->c_cflag & PARENB) {
499 cfcr |= CFCR_PENAB;
500 if ((t->c_cflag & PARODD) == 0)
501 cfcr |= CFCR_PEVEN;
502 }
503 if (t->c_cflag & CSTOPB)
504 cfcr |= CFCR_STOPB;
505
506 s = spltty();
507
508 /* and copy to tty */
509 tp->t_ispeed = t->c_ispeed;
510 tp->t_ospeed = t->c_ospeed;
511 tp->t_cflag = t->c_cflag;
512
513 if (ospeed == 0)
514 bic(iobase + com_mcr, MCR_DTR | MCR_RTS);
515 else
516 bis(iobase + com_mcr, MCR_DTR | MCR_RTS);
517
518 outb(iobase + com_cfcr, cfcr | CFCR_DLAB);
519 outb(iobase + com_dlbl, ospeed);
520 outb(iobase + com_dlbh, ospeed>>8);
521 outb(iobase + com_cfcr, cfcr);
522
523 /* when not using CRTS_IFLOW, RTS follows DTR */
524 if ((t->c_cflag & CRTS_IFLOW) == 0) {
525 u_char mcr = inb(iobase + com_mcr);
526
527 if (mcr & MCR_DTR)
528 if ((mcr & MCR_RTS) == 0)
529 outb(iobase + com_mcr, mcr | MCR_RTS);
530 else
531 ;
532 else
533 if (mcr & MCR_RTS)
534 outb(iobase + com_mcr, mcr &~ MCR_RTS);
535 else
536 ;
537 }
538
539 splx(s);
540
541 return 0;
542 }
543
544 void
545 comstart(tp)
546 struct tty *tp;
547 {
548 int unit = COMUNIT(tp->t_dev);
549 struct com_softc *sc = comcd.cd_devs[unit];
550 u_short iobase = sc->sc_iobase;
551 int s;
552
553 s = spltty();
554 if (tp->t_state & (TS_TTSTOP | TS_BUSY))
555 goto out;
556 if (tp->t_cflag & CCTS_OFLOW && (inb(iobase + com_mcr) & MSR_CTS) == 0)
557 goto out;
558 if (tp->t_outq.c_cc <= tp->t_lowat) {
559 if (tp->t_state & TS_ASLEEP) {
560 tp->t_state &=~ TS_ASLEEP;
561 wakeup((caddr_t)&tp->t_outq);
562 }
563 selwakeup(&tp->t_wsel);
564 }
565 if (tp->t_outq.c_cc == 0)
566 goto out;
567 tp->t_state |= TS_BUSY;
568 if ((inb(iobase + com_lsr) & LSR_TXRDY) == 0)
569 goto out;
570 if (sc->sc_flags & COM_FIFO) {
571 u_char buffer[16], *cp = buffer;
572 int n = q_to_b(&tp->t_outq, cp, sizeof buffer);
573 do {
574 outb(iobase + com_data, *cp++);
575 } while (--n);
576 } else
577 outb(iobase + com_data, getc(&tp->t_outq));
578 out:
579 splx(s);
580 }
581
582 /*
583 * Stop output on a line.
584 */
585 void
586 comstop(tp, flag)
587 struct tty *tp;
588 {
589 int s;
590
591 s = spltty();
592 if (tp->t_state & TS_BUSY)
593 if ((tp->t_state & TS_TTSTOP) == 0)
594 tp->t_state |= TS_FLUSH;
595 splx(s);
596 }
597
598 static void
599 comeint(sc, stat)
600 struct com_softc *sc;
601 int stat;
602 {
603 u_short iobase = sc->sc_iobase;
604 struct tty *tp = com_tty[sc->sc_dev.dv_unit];
605 int c;
606
607 c = inb(iobase + com_data);
608 if ((tp->t_state & TS_ISOPEN) == 0)
609 return;
610 if (stat & (LSR_BI | LSR_FE))
611 c |= TTY_FE;
612 else if (stat & LSR_PE)
613 c |= TTY_PE;
614 else if (stat & LSR_OE) {
615 c |= TTY_PE; /* XXX ought to have its own define */
616 log(LOG_WARNING, "%s: silo overflow\n", sc->sc_dev.dv_xname);
617 }
618 /* XXXX put in FIFO and process later */
619 (*linesw[tp->t_line].l_rint)(c, tp);
620 }
621
622 static void
623 commint(sc)
624 struct com_softc *sc;
625 {
626 u_short iobase = sc->sc_iobase;
627 struct tty *tp = com_tty[sc->sc_dev.dv_unit];
628 u_char stat;
629
630 stat = inb(iobase + com_msr);
631 if (stat & MSR_DDCD && (sc->sc_flags & COM_SOFTCAR) == 0) {
632 if (stat & MSR_DCD)
633 (void)(*linesw[tp->t_line].l_modem)(tp, 1);
634 else if ((*linesw[tp->t_line].l_modem)(tp, 0) == 0)
635 bic(iobase + com_mcr, MCR_DTR | MCR_RTS);
636 }
637 if (stat & MSR_DCTS && tp->t_state & TS_ISOPEN && tp->t_cflag & CRTSCTS) {
638 /* the line is up and we want to do rts/cts flow control */
639 if (stat & MSR_CTS) {
640 tp->t_state &=~ TS_TTSTOP;
641 ttstart(tp);
642 } else
643 tp->t_state |= TS_TTSTOP;
644 }
645 }
646
647 static int
648 comintr(sc)
649 struct com_softc *sc;
650 {
651 u_short iobase = sc->sc_iobase;
652 struct tty *tp;
653 u_char code;
654
655 code = inb(iobase + com_iir);
656 if (code & IIR_NOPEND)
657 return 0;
658
659 for (;;) {
660 switch (code & IIR_IMASK) {
661 case IIR_RXRDY:
662 case IIR_RXTOUT:
663 tp = com_tty[sc->sc_dev.dv_unit];
664 /* XXXX put in FIFO and process later */
665 #define RCVBYTE() \
666 code = inb(iobase + com_data); \
667 if (tp->t_state & TS_ISOPEN) \
668 (*linesw[tp->t_line].l_rint)(code, tp)
669 RCVBYTE();
670 if (sc->sc_flags & COM_FIFO)
671 while (code = inb(iobase + com_lsr) & LSR_RCV_MASK) {
672 if (code == LSR_RXRDY) {
673 RCVBYTE();
674 } else
675 comeint(sc, code);
676 }
677 break;
678 case IIR_TXRDY:
679 tp = com_tty[sc->sc_dev.dv_unit];
680 tp->t_state &=~ TS_BUSY;
681 if (tp->t_state & TS_FLUSH)
682 tp->t_state &=~ TS_FLUSH;
683 else
684 if (tp->t_line)
685 (*linesw[tp->t_line].l_start)(tp);
686 else
687 comstart(tp);
688 break;
689 case IIR_MLSC:
690 commint(sc);
691 break;
692 case IIR_RLS:
693 comeint(sc, inb(iobase + com_lsr));
694 break;
695 default:
696 log(LOG_WARNING, "%s: weird iir=0x%x\n",
697 sc->sc_dev.dv_xname, code);
698 /* fall through */
699 }
700
701 code = inb(iobase + com_iir);
702 if (code & IIR_NOPEND)
703 return 1;
704 }
705 }
706
707 /* XXXXXXXXXXXXXXXX ---- gremlins below here ---- XXXXXXXXXXXXXXXX */
708
709 #if 0
710 /*
711 * Following are all routines needed for COM to act as console
712 */
713 #include "i386/i386/cons.h"
714
715 comcnprobe(cp)
716 struct consdev *cp;
717 {
718 /* XXXX */
719 if (!_comprobe(CONADDR))
720 return CN_DEAD;
721
722 /* locate the major number */
723 for (commajor = 0; commajor < nchrdev; commajor++)
724 if (cdevsw[commajor].d_open == comopen)
725 break;
726
727 /* initialize required fields */
728 cp->cn_dev = makedev(commajor, unit);
729 #ifdef COMCONSOLE
730 cp->cn_pri = CN_REMOTE; /* Force a serial port console */
731 #else
732 cp->cn_pri = CN_NORMAL;
733 #endif
734 }
735
736 comcninit(cp)
737 struct consdev *cp;
738 {
739 int unit = COMUNIT(cp->cn_dev);
740
741 comconsole = CONADDR;
742 comconsinit = 0;
743 }
744
745 cominit(unit, rate)
746 int unit, rate;
747 {
748 int com;
749 int s;
750 short stat;
751
752 com = com_addr[unit];
753 s = splhigh();
754 outb(com+com_cfcr, CFCR_DLAB);
755 rate = COM_BAUDDIV(rate);
756 outb(com+com_data, rate & 0xFF);
757 outb(com+com_ier, rate >> 8);
758 outb(com+com_cfcr, CFCR_8BITS);
759 outb(com+com_ier, IER_ERXRDY | IER_ETXRDY);
760 outb(com+com_fifo, FIFO_ENABLE|FIFO_RCV_RST|FIFO_XMT_RST|FIFO_TRIGGER_4);
761 stat = inb(com+com_iir);
762 splx(s);
763 }
764
765 comcngetc(dev)
766 {
767 com = com_addr[COMUNIT(dev)];
768 short stat;
769 int c, s;
770
771 s = splhigh();
772 while (((stat = inb(com+com_lsr)) & LSR_RXRDY) == 0)
773 ;
774 c = inb(com+com_data);
775 stat = inb(com+com_iir);
776 splx(s);
777 return c;
778 }
779
780 /*
781 * Console kernel output character routine.
782 */
783 comcnputc(dev, c)
784 dev_t dev;
785 int c;
786 {
787 com = com_addr[COMUNIT(dev)];
788 int timo;
789 short stat;
790 int s = splhigh();
791
792 if (comconsinit == 0) {
793 (void) cominit(COMUNIT(dev), comdefaultrate);
794 comconsinit = 1;
795 }
796 /* wait for any pending transmission to finish */
797 timo = 50000;
798 while (((stat = inb(com+com_lsr)) & LSR_TXRDY) == 0 && --timo)
799 ;
800 outb(com+com_data, c);
801 /* wait for this transmission to complete */
802 timo = 1500000;
803 while (((stat = inb(com+com_lsr)) & LSR_TXRDY) == 0 && --timo)
804 ;
805 /* clear any interrupts generated by this transmission */
806 stat = inb(com+com_iir);
807 splx(s);
808 }
809 #endif
810