Annotation of Net2/arch/i386/isa/com.c, revision 1.1.1.3

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

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.