Debian Codegraph @

i386/i386at/com.c

raw
1 /*
2 * Mach Operating System
3 * Copyright (c) 1994,1993,1991,1990 Carnegie Mellon University
4 * All Rights Reserved.
5 *
6 * Permission to use, copy, modify and distribute this software and its
7 * documentation is hereby granted, provided that both the copyright
8 * notice and this permission notice appear in all copies of the
9 * software, derivative works or modified versions, and any portions
10 * thereof, and that both notices appear in supporting documentation.
11 *
12 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
13 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
14 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
15 *
16 * Carnegie Mellon requests users of this software to return to
17 *
18 * Software Distribution Coordinator or [email protected]
19 * School of Computer Science
20 * Carnegie Mellon University
21 * Pittsburgh PA 15213-3890
22 *
23 * any improvements or extensions that they make and grant Carnegie Mellon
24 * the rights to redistribute these changes.
25 */
26
27 #if NCOM > 0
28
29 #include <string.h>
30 #include <util/atoi.h>
31
32 #include <mach/std_types.h>
33 #include <sys/types.h>
34 #include <kern/printf.h>
35 #include <kern/mach_clock.h>
36 #include <device/conf.h>
37 #include <device/device_types.h>
38 #include <device/tty.h>
39 #include <device/io_req.h>
40
41 #include <i386/ipl.h>
42 #include <i386/pio.h>
43 #include <i386/spl.h>
44 #include <chips/busses.h>
45 #include <i386at/autoconf.h>
46 #include <i386at/com.h>
47 #include <i386at/comreg.h>
48
49 #include <device/cons.h>
50
51 static void comparam(int);
52
53 static vm_offset_t com_std[NCOM] = { 0 };
54 struct bus_device *cominfo[NCOM];
55 struct bus_driver comdriver = {
56 comprobe, 0, comattach, 0, com_std, "com", cominfo, 0, 0, 0};
57
58 struct tty com_tty[NCOM];
59 int commodem[NCOM];
60 int comcarrier[NCOM] = {0, 0,};
61 boolean_t comfifo[NCOM];
62 boolean_t comtimer_active;
63 int comtimer_state[NCOM];
64
65 #define RCBAUD B115200
66 static int rcline = -1;
67 static struct bus_device *comcndev;
68
69 /* XX */
70 extern char *kernel_cmdline;
71
72 #define ISPEED B115200
73 #define IFLAGS (EVENP|ODDP|ECHO|CRMOD|XTABS|LITOUT)
74
75 u_short divisorreg[] = {
76 0, 2304, 1536, 1047, /* 0, 50, 75, 110*/
77 857, 768, 576, 384, 192, /* 134.5, 150, 200, 300, 600*/
78 96, 64, 48, /* 1200, 1800, 2000, 2400 */
79 24, 12, /* 3600, 4800, 7200, 9600 */
80 6, 3, 2, 1}; /* 19200, 38400, 56000,115200 */
81
82
83 /*
84 *
85 * Probes are called during kernel boot: return 1 to mean that
86 * the relevant device is present today.
87 *
88 */
89 static int
90 comprobe_general(struct bus_device *dev, int noisy)
91 {
92 u_short addr = dev->address;
93 int unit = dev->unit;
94 int oldctl, oldmsb;
95 char *type = "8250";
96 int i;
97
98 if ((unit < 0) || (unit >= NCOM)) {
99 printf("com %d out of range\n", unit);
100 return(0);
101 }
102 oldctl = inb(LINE_CTL(addr)); /* Save old value of LINE_CTL */
103 oldmsb = inb(BAUD_MSB(addr)); /* Save old value of BAUD_MSB */
104 outb(LINE_CTL(addr), 0); /* Select INTR_ENAB */
105 outb(BAUD_MSB(addr), 0);
106 if (inb(BAUD_MSB(addr)) != 0)
107 {
108 outb(LINE_CTL(addr), oldctl);
109 outb(BAUD_MSB(addr), oldmsb);
110 return 0;
111 }
112 outb(LINE_CTL(addr), iDLAB); /* Select BAUD_MSB */
113 outb(BAUD_MSB(addr), 255);
114 if (inb(BAUD_MSB(addr)) != 255)
115 {
116 outb(LINE_CTL(addr), oldctl);
117 outb(BAUD_MSB(addr), oldmsb);
118 return 0;
119 }
120 outb(LINE_CTL(addr), 0); /* Select INTR_ENAB */
121 if (inb(BAUD_MSB(addr)) != 0) /* Check that it has kept its value*/
122 {
123 outb(LINE_CTL(addr), oldctl);
124 outb(BAUD_MSB(addr), oldmsb);
125 return 0;
126 }
127
128 /* Com port found, now check what chip it has */
129
130 for(i = 0; i < 256; i++) /* Is there Scratch register */
131 {
132 outb(SCR(addr), i);
133 if (inb(SCR(addr)) != i)
134 break;
135 }
136 if (i == 256)
137 { /* Yes == 450 or 460 */
138 outb(SCR(addr), 0);
139 type = "82450 or 16450";
140 outb(FIFO_CTL(addr), iFIFOENA | iFIFO14CH); /* Enable fifo */
141 if ((inb(FIFO_CTL(addr)) & iFIFO14CH) != 0)
142 { /* Was it successful */
143 /* if both bits are not set then broken xx550 */
144 if ((inb(FIFO_CTL(addr)) & iFIFO14CH) == iFIFO14CH)
145 {
146 type = "82550 or 16550";
147 comfifo[unit] = TRUE;
148 }
149 else
150 {
151 type = "82550 or 16550 with non-working FIFO";
152 }
153 outb(INTR_ID(addr), 0x00); /* Disable fifos */
154 }
155 }
156 if (noisy)
157 printf("com%d: %s chip.\n", unit, type);
158 return 1;
159 }
160
161 /*
162 * Probe routine for use during kernel startup when it is probing
163 * all of bus_device_init
164 */
165 int
166 comprobe(vm_offset_t port, struct bus_ctlr *dev)
167 {
168 return comprobe_general((struct bus_device *)dev, /*noisy*/ 0);
169 }
170
171 /*
172 * Probe routine for use by the console
173 */
174 int
175 comcnprobe(struct consdev *cp)
176 {
177 struct bus_device *b;
178 int maj, unit, pri;
179
180 #define CONSOLE_PARAMETER " console=com"
181 u_char *console = (u_char *) strstr(kernel_cmdline, CONSOLE_PARAMETER);
182
183 if (console)
184 mach_atoi(console + strlen(CONSOLE_PARAMETER), &rcline);
185
186 if (strncmp(kernel_cmdline, CONSOLE_PARAMETER + 1,
187 strlen(CONSOLE_PARAMETER) - 1) == 0)
188 mach_atoi((u_char*)kernel_cmdline + strlen(CONSOLE_PARAMETER) - 1,
189 &rcline);
190
191 maj = 0;
192 unit = -1;
193 pri = CN_DEAD;
194
195 for (b = bus_device_init; b->driver; b++)
196 if (strcmp(b->name, "com") == 0
197 && b->unit == rcline
198 && comprobe_general(b, /*quiet*/ 0))
199 {
200 /* Found one */
201 comcndev = b;
202 unit = b->unit;
203 pri = CN_REMOTE;
204 break;
205 }
206
207 cp->cn_dev = makedev(maj, unit);
208 cp->cn_pri = pri;
209
210 return 0;
211 }
212
213
214 /*
215 *
216 * Device Attach's are called during kernel boot, but only if the matching
217 * device Probe returned a 1.
218 *
219 */
220 void
221 comattach(struct bus_device *dev)
222 {
223 u_char unit = dev->unit;
224 u_short addr = dev->address;
225
226 if (unit >= NCOM) {
227 printf(", disabled by NCOM configuration\n");
228 return;
229 }
230
231 take_dev_irq(dev);
232 printf(", port = %zx, spl = %zu, pic = %d. (DOS COM%d)",
233 dev->address, dev->sysdep, dev->sysdep1, unit+1);
234
235 /* comcarrier[unit] = addr->flags;*/
236 commodem[unit] = 0;
237
238 outb(INTR_ENAB(addr), 0);
239 outb(MODEM_CTL(addr), 0);
240 while (!(inb(INTR_ID(addr))&1)) {
241 (void) inb(LINE_STAT (addr)); /* reset overrun error etc */
242 (void) inb(TXRX (addr)); /* reset data-ready */
243 (void) inb(MODEM_STAT(addr)); /* reset modem status reg */
244 }
245 }
246
247 /*
248 * Attach/init routine for console. This isn't called by
249 * configure_bus_device which sets the alive, adaptor, and minfo
250 * fields of the bus_device struct (comattach is), therefore we do
251 * that by hand.
252 */
253 int
254 comcninit(struct consdev *cp)
255 {
256 u_char unit = comcndev->unit;
257 u_short addr = comcndev->address;
258
259 take_dev_irq(comcndev);
260
261 comcndev->alive = 1;
262 comcndev->adaptor = 0;
263 cominfo[minor(cp->cn_dev)] = comcndev;
264
265 outb(LINE_CTL(addr), iDLAB);
266 outb(BAUD_LSB(addr), divisorreg[RCBAUD] & 0xff);
267 outb(BAUD_MSB(addr), divisorreg[RCBAUD] >>8);
268 outb(LINE_CTL(addr), i8BITS);
269 outb(INTR_ENAB(addr), 0);
270 outb(MODEM_CTL(addr), iDTR|iRTS|iOUT2);
271
272 {
273 char msg[128];
274 volatile unsigned char *p = (volatile unsigned char *)phystokv(0xb8000);
275 int i;
276
277 sprintf(msg, " **** using COM port %d for console ****",
278 unit+1);
279 for (i = 0; msg[i]; i++) {
280 p[2*i] = msg[i];
281 p[2*i+1] = (0<<7) /* blink */
282 | (0x0<<4) /* bg */
283 | (1<<3) /* hi-intensity */
284 | 0x4; /* fg */
285 }
286 }
287
288 return 0;
289 }
290
291 /*
292 * Probe for COM<dev> after autoconfiguration.
293 * Used to handle PCMCIA modems, which may appear
294 * at any time.
295 */
296 static boolean_t com_reprobe(
297 int unit)
298 {
299 struct bus_device *device;
300
301 /*
302 * Look for COM device <unit> in the device
303 * initialization list. It must not be alive
304 * (otherwise we would have opened it already).
305 */
306 for (device = bus_device_init; device->driver; device++) {
307 if (device->driver == &comdriver && device->unit == unit &&
308 !device->alive && device->ctlr == (char)-1)
309 {
310 /*
311 * Found an entry for com port <unit>.
312 * Probe it.
313 */
314 if (configure_bus_device(device->name,
315 device->address,
316 device->phys_address,
317 0,
318 "atbus"))
319 return TRUE;
320 }
321 }
322 return FALSE;
323 }
324
325 io_return_t comopen(
326 dev_t dev,
327 int flag,
328 io_req_t ior)
329 {
330 int unit = minor(dev);
331 u_short addr;
332 struct bus_device *isai;
333 struct tty *tp;
334 spl_t s;
335 io_return_t result;
336
337 if (unit >= NCOM)
338 return D_NO_SUCH_DEVICE; /* no such device */
339 if ((isai = cominfo[unit]) == 0 || isai->alive == 0) {
340 /*
341 * Try to probe it again
342 */
343 if (!com_reprobe(unit))
344 return D_NO_SUCH_DEVICE;
345 if ((isai = cominfo[unit]) == 0 || isai->alive == 0)
346 return D_NO_SUCH_DEVICE;
347 }
348 tp = &com_tty[unit];
349
350 if ((tp->t_state & (TS_ISOPEN|TS_WOPEN)) == 0) {
351 ttychars(tp);
352 tp->t_addr = (char *)isai->address;
353 tp->t_dev = dev;
354 tp->t_oproc = comstart;
355 tp->t_stop = comstop;
356 tp->t_mctl = commctl;
357 tp->t_getstat = comgetstat;
358 tp->t_setstat = comsetstat;
359 if (tp->t_ispeed == 0) {
360 tp->t_ispeed = ISPEED;
361 tp->t_ospeed = ISPEED;
362 tp->t_flags = IFLAGS;
363 tp->t_state &= ~TS_BUSY;
364 }
365 }
366 /*rvb tp->t_state |= TS_WOPEN; */
367 if ((tp->t_state & TS_ISOPEN) == 0)
368 comparam(unit);
369 addr = (uintptr_t)tp->t_addr;
370
371 s = spltty();
372 if (!comcarrier[unit]) /* not originating */
373 tp->t_state |= TS_CARR_ON;
374 else {
375 int modem_stat = inb(MODEM_STAT(addr));
376 if (modem_stat & iRLSD)
377 tp->t_state |= TS_CARR_ON;
378 else
379 tp->t_state &= ~TS_CARR_ON;
380 fix_modem_state(unit, modem_stat);
381 }
382 splx(s);
383
384 result = char_open(dev, tp, flag, ior);
385
386 if (!comtimer_active) {
387 comtimer_active = TRUE;
388 comtimer(NULL);
389 }
390
391 s = spltty();
392 while(!(inb(INTR_ID(addr))&1)) { /* while pending interrupts */
393 (void) inb(LINE_STAT (addr)); /* reset overrun error */
394 (void) inb(TXRX (addr)); /* reset data-ready */
395 (void) inb(MODEM_STAT(addr)); /* reset modem status */
396 }
397 splx(s);
398 return result;
399 }
400
401 void comclose(dev_t dev, int flag)
402 {
403 struct tty *tp = &com_tty[minor(dev)];
404 u_short addr = (uintptr_t)tp->t_addr;
405
406 ttyclose(tp);
407 if (tp->t_state&TS_HUPCLS || (tp->t_state&TS_ISOPEN)==0) {
408 outb(INTR_ENAB(addr), 0);
409 outb(MODEM_CTL(addr), 0);
410 tp->t_state &= ~TS_BUSY;
411 commodem[minor(dev)] = 0;
412 if (comfifo[minor(dev)] != 0)
413 outb(INTR_ID(addr), 0x00); /* Disable fifos */
414 }
415 return;
416 }
417
418 io_return_t comread(dev_t dev, io_req_t ior)
419 {
420 return char_read(&com_tty[minor(dev)], ior);
421 }
422
423 io_return_t comwrite(dev_t dev, io_req_t ior)
424 {
425 return char_write(&com_tty[minor(dev)], ior);
426 }
427
428 io_return_t comportdeath(dev_t dev, mach_port_t port)
429 {
430 return (tty_portdeath(&com_tty[minor(dev)], (ipc_port_t)port));
431 }
432
433 io_return_t
434 comgetstat(
435 dev_t dev,
436 dev_flavor_t flavor,
437 dev_status_t data, /* pointer to OUT array */
438 mach_msg_type_number_t *count /* out */
439 )
440 {
441 io_return_t result = D_SUCCESS;
442 int unit = minor(dev);
443
444 switch (flavor) {
445 case TTY_MODEM:
446 fix_modem_state(unit, inb(MODEM_STAT(cominfo[unit]->address)));
447 *data = commodem[unit];
448 *count = 1;
449 break;
450 default:
451 result = tty_get_status(&com_tty[unit], flavor, data, count);
452 break;
453 }
454 return (result);
455 }
456
457 io_return_t
458 comsetstat(
459 dev_t dev,
460 dev_flavor_t flavor,
461 dev_status_t data,
462 mach_msg_type_number_t count)
463 {
464 io_return_t result = D_SUCCESS;
465 int unit = minor(dev);
466 struct tty *tp = &com_tty[unit];
467
468 switch (flavor) {
469 case TTY_SET_BREAK:
470 commctl(tp, TM_BRK, DMBIS);
471 break;
472 case TTY_CLEAR_BREAK:
473 commctl(tp, TM_BRK, DMBIC);
474 break;
475 case TTY_MODEM:
476 commctl(tp, *data, DMSET);
477 break;
478 default:
479 result = tty_set_status(&com_tty[unit], flavor, data, count);
480 if (result == D_SUCCESS && flavor == TTY_STATUS)
481 comparam(unit);
482 return (result);
483 }
484 return (D_SUCCESS);
485 }
486
487 void
488 comintr(int unit)
489 {
490 struct tty *tp = &com_tty[unit];
491 u_short addr = cominfo[unit]->address;
492 static char comoverrun = 0;
493 char c, line, intr_id;
494 int line_stat;
495
496 while (! ((intr_id=(inb(INTR_ID(addr))&MASKi)) & 1))
497 switch (intr_id) {
498 case MODi:
499 /* modem change */
500 commodem_intr(unit, inb(MODEM_STAT(addr)));
501 break;
502
503 case TRAi:
504 comtimer_state[unit] = 0;
505 tp->t_state &= ~(TS_BUSY|TS_FLUSH);
506 tt_write_wakeup(tp);
507 (void) comstart(tp);
508 break;
509 case RECi:
510 case CTIi: /* Character timeout indication */
511 if (tp->t_state&TS_ISOPEN) {
512 int escape = 0;
513 while ((line = inb(LINE_STAT(addr))) & iDR) {
514 c = inb(TXRX(addr));
515
516 if (c == 0x1b) {
517 escape = 1;
518 continue;
519 }
520
521 #if MACH_KDB
522 if (escape && c == 'D'-('A'-1))
523 /* ctrl-alt-d pressed,
524 invoke debugger */
525 kdb_kintr();
526 else
527 #endif /* MACH_KDB */
528 if (escape) {
529 ttyinput(0x1b, tp);
530 ttyinput(c, tp);
531 }
532 else
533 ttyinput(c, tp);
534
535 escape = 0;
536 }
537
538 if (escape)
539 /* just escape */
540 ttyinput(0x1b, tp);
541 } else
542 tt_open_wakeup(tp);
543 break;
544 case LINi:
545 line_stat = inb(LINE_STAT(addr));
546
547 if ((line_stat & iPE) &&
548 ((tp->t_flags&(EVENP|ODDP)) == EVENP ||
549 (tp->t_flags&(EVENP|ODDP)) == ODDP)) {
550 /* parity error */;
551 } else if (line_stat&iOR && !comoverrun) {
552 printf("com%d: overrun\n", unit);
553 comoverrun = 1;
554 } else if (line_stat & (iFE | iBRKINTR)) {
555 /* framing error or break */
556 ttyinput(tp->t_breakc, tp);
557 }
558 break;
559 }
560 }
561
562 static void
563 comparam(int unit)
564 {
565 struct tty *tp = &com_tty[unit];
566 u_short addr = (uintptr_t)tp->t_addr;
567 spl_t s = spltty();
568 int mode;
569
570 if (tp->t_ispeed == B0) {
571 tp->t_state |= TS_HUPCLS;
572 outb(MODEM_CTL(addr), iOUT2);
573 commodem[unit] = 0;
574 splx(s);
575 return;
576 }
577
578 /* Do input buffering */
579 if (tp->t_ispeed >= B300)
580 tp->t_state |= TS_MIN;
581
582 outb(LINE_CTL(addr), iDLAB);
583 outb(BAUD_LSB(addr), divisorreg[tp->t_ispeed] & 0xff);
584 outb(BAUD_MSB(addr), divisorreg[tp->t_ispeed] >> 8);
585
586 if (tp->t_flags & (RAW|LITOUT|PASS8))
587 mode = i8BITS;
588 else
589 mode = i7BITS | iPEN;
590 if (tp->t_flags & EVENP)
591 mode |= iEPS;
592 if (tp->t_ispeed == B110)
593 /*
594 * 110 baud uses two stop bits -
595 * all other speeds use one
596 */
597 mode |= iSTB;
598
599 outb(LINE_CTL(addr), mode);
600
601 outb(INTR_ENAB(addr), iTX_ENAB|iRX_ENAB|iMODEM_ENAB|iERROR_ENAB);
602 if (comfifo[unit])
603 outb(FIFO_CTL(addr), iFIFOENA|iFIFO14CH);
604 outb(MODEM_CTL(addr), iDTR|iRTS|iOUT2);
605 commodem[unit] |= (TM_DTR|TM_RTS);
606 splx(s);
607 }
608
609 int comst_1, comst_2, comst_3, comst_4, comst_5 = 14;
610
611 void
612 comstart(struct tty *tp)
613 {
614 int nch;
615 #if 0
616 int i;
617 #endif
618
619 if (tp->t_state & (TS_TIMEOUT|TS_TTSTOP|TS_BUSY)) {
620 comst_1++;
621 return;
622 }
623 if ((!queue_empty(&tp->t_delayed_write)) &&
624 (tp->t_outq.c_cc <= TTLOWAT(tp))) {
625 comst_2++;
626 tt_write_wakeup(tp);
627 }
628 if (!tp->t_outq.c_cc) {
629 comst_3++;
630 return;
631 }
632
633 #if 0
634 i = (comfifo[minor(tp->t_dev)]) ? /*14*/comst_5 : 1;
635
636 tp->t_state |= TS_BUSY;
637 while (i-- > 0) {
638 nch = getc(&tp->t_outq);
639 if (nch == -1) break;
640 if ((nch & 0200) && ((tp->t_flags & LITOUT) == 0)) {
641 timeout(ttrstrt, (char *)tp, (nch & 0x7f) + 6);
642 tp->t_state |= TS_TIMEOUT;
643 comst_4++;
644 return(0);
645 }
646 outb(TXRX((uintptr_t)tp->t_addr), nch);
647 }
648 #else
649 nch = getc(&tp->t_outq);
650 if (nch == -1)
651 return;
652 if ((nch & 0200) && ((tp->t_flags & LITOUT) == 0)) {
653 timeout((timer_func_t *)ttrstrt, (char *)tp, (nch & 0x7f) + 6);
654 tp->t_state |= TS_TIMEOUT;
655 comst_4++;
656 return;
657 }
658 outb(TXRX((uintptr_t)tp->t_addr), nch);
659 tp->t_state |= TS_BUSY;
660 #endif
661 }
662
663 /* Check for stuck xmitters */
664 int comtimer_interval = 5;
665
666 void
667 comtimer(void * param)
668 {
669 spl_t s = spltty();
670 struct tty *tp = com_tty;
671 int i, nch;
672
673 for (i = 0; i < NCOM; i++, tp++) {
674 if ((tp->t_state & TS_ISOPEN) == 0)
675 continue;
676 if (!tp->t_outq.c_cc)
677 continue;
678 if (++comtimer_state[i] < 2)
679 continue;
680 /* Its stuck */
681 printf("Tty %p was stuck\n", tp);
682 nch = getc(&tp->t_outq);
683 outb(TXRX((uintptr_t)tp->t_addr), nch);
684 }
685
686 splx(s);
687 timeout(comtimer, 0, comtimer_interval*hz);
688 }
689
690 /*
691 * Set receive modem state from modem status register.
692 */
693 void
694 fix_modem_state(
695 int unit,
696 int modem_stat)
697 {
698 int stat = 0;
699
700 if (modem_stat & iCTS)
701 stat |= TM_CTS; /* clear to send */
702 if (modem_stat & iDSR)
703 stat |= TM_DSR; /* data set ready */
704 if (modem_stat & iRI)
705 stat |= TM_RNG; /* ring indicator */
706 if (modem_stat & iRLSD)
707 stat |= TM_CAR; /* carrier? */
708
709 commodem[unit] = (commodem[unit] & ~(TM_CTS|TM_DSR|TM_RNG|TM_CAR))
710 | stat;
711 }
712
713 /*
714 * Modem change (input signals)
715 */
716 void
717 commodem_intr(
718 int unit,
719 int stat)
720 {
721 int changed;
722
723 changed = commodem[unit];
724 fix_modem_state(unit, stat);
725 stat = commodem[unit];
726
727 /* Assumption: if the other party can handle
728 modem signals then it should handle all
729 the necessary ones. Else fix the cable. */
730
731 changed ^= stat; /* what changed ? */
732
733 if (changed & TM_CTS)
734 tty_cts( &com_tty[unit], stat & TM_CTS );
735
736 #if 0
737 if (changed & TM_CAR)
738 ttymodem( &com_tty[unit], stat & TM_CAR );
739 #endif
740
741 }
742
743 /*
744 * Set/get modem bits
745 */
746 int
747 commctl(
748 struct tty *tp,
749 int bits,
750 int how)
751 {
752 spl_t s;
753 int unit;
754 vm_offset_t dev_addr;
755 int b = 0; /* Suppress gcc warning */
756
757 unit = minor(tp->t_dev);
758
759 if (bits == TM_HUP) { /* close line (internal) */
760 bits = TM_DTR | TM_RTS;
761 how = DMBIC;
762 }
763
764 if (how == DMGET) return commodem[unit];
765
766 dev_addr = cominfo[unit]->address;
767
768 s = spltty();
769
770 switch (how) {
771 case DMSET:
772 b = bits; break;
773 case DMBIS:
774 b = commodem[unit] | bits; break;
775 case DMBIC:
776 b = commodem[unit] & ~bits; break;
777 }
778 commodem[unit] = b;
779
780 if (bits & TM_BRK) {
781 if (b & TM_BRK) {
782 outb(LINE_CTL(dev_addr), inb(LINE_CTL(dev_addr)) | iSETBREAK);
783 } else {
784 outb(LINE_CTL(dev_addr), inb(LINE_CTL(dev_addr)) & ~iSETBREAK);
785 }
786 }
787
788 #if 0
789 /* do I need to do something on this ? */
790 if (bits & TM_LE) { /* line enable */
791 }
792 #endif
793 #if 0
794 /* Unsupported */
795 if (bits & TM_ST) { /* secondary transmit */
796 }
797 if (bits & TM_SR) { /* secondary receive */
798 }
799 #endif
800 if (bits & (TM_DTR|TM_RTS)) { /* data terminal ready, request to send */
801 how = iOUT2;
802 if (b & TM_DTR) how |= iDTR;
803 if (b & TM_RTS) how |= iRTS;
804 outb(MODEM_CTL(dev_addr), how);
805 }
806
807 splx(s);
808
809 /* the rest are inputs */
810 return commodem[unit];
811 }
812
813 void
814 comstop(
815 struct tty *tp,
816 int flags)
817 {
818 if ((tp->t_state & TS_BUSY) && (tp->t_state & TS_TTSTOP) == 0)
819 tp->t_state |= TS_FLUSH;
820 }
821
822 /*
823 *
824 * Code to be called from debugger.
825 *
826 */
827 void compr_addr(vm_offset_t addr)
828 {
829 /* The two line_stat prints may show different values, since
830 * touching some of the registers constitutes changing them.
831 */
832 printf("LINE_STAT(%zu) %x\n",
833 LINE_STAT(addr), inb(LINE_STAT(addr)));
834
835 printf("TXRX(%zu) %x, INTR_ENAB(%zu) %x, INTR_ID(%zu) %x, LINE_CTL(%zu) %x,\n\
836 MODEM_CTL(%zu) %x, LINE_STAT(%zu) %x, MODEM_STAT(%zu) %x\n",
837 TXRX(addr), inb(TXRX(addr)),
838 INTR_ENAB(addr), inb(INTR_ENAB(addr)),
839 INTR_ID(addr), inb(INTR_ID(addr)),
840 LINE_CTL(addr), inb(LINE_CTL(addr)),
841 MODEM_CTL(addr), inb(MODEM_CTL(addr)),
842 LINE_STAT(addr), inb(LINE_STAT(addr)),
843 MODEM_STAT(addr),inb(MODEM_STAT(addr)));
844 }
845
846 int compr(int unit)
847 {
848 compr_addr(cominfo[unit]->address);
849 return(0);
850 }
851
852 int
853 comgetc(int unit)
854 {
855 u_short addr = (u_short)(cominfo[unit]->address);
856 spl_t s = spltty();
857 int c;
858
859 while((inb(LINE_STAT(addr)) & iDR) == 0) ;
860
861 c = inb(TXRX(addr));
862 splx(s);
863 return c;
864 }
865
866 /*
867 * Routines for the console
868 */
869 int
870 comcnputc(dev_t dev, int c)
871 {
872 u_short addr = (u_short)(cominfo[minor(dev)]->address);
873
874 /* Wait for transmitter to empty */
875 while((inb(LINE_STAT(addr)) & iTHRE) == 0)
876 continue;
877
878 /* send the char */
879 if (c == '\n')
880 comcnputc(dev, '\r');
881 outb(addr, c);
882
883 return 0;
884 }
885
886 int
887 comcngetc(dev_t dev, int wait)
888 {
889 u_short addr = (u_short)(cominfo[minor(dev)]->address);
890 int c;
891
892 while((inb(LINE_STAT(addr)) & iDR) == 0)
893 if (! wait)
894 return 0;
895
896 c = inb(TXRX(addr));
897 return c & 0x7f;
898 }
899
900 #endif /* NCOM */