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