[BACK]Return to promcons.c CVS log [TXT][DIR] Up to [local] / sys / arch / alpha / alpha

Annotation of sys/arch/alpha/alpha/promcons.c, Revision 1.1.1.1

1.1       nbrk        1: /*     $OpenBSD: promcons.c,v 1.9 2005/11/21 18:16:36 millert Exp $    */
                      2: /*     $NetBSD: promcons.c,v 1.5 1996/11/13 22:20:55 cgd Exp $ */
                      3:
                      4: /*
                      5:  * Copyright (c) 1994, 1995, 1996 Carnegie-Mellon University.
                      6:  * All rights reserved.
                      7:  *
                      8:  * Author: Chris G. Demetriou
                      9:  *
                     10:  * Permission to use, copy, modify and distribute this software and
                     11:  * its documentation is hereby granted, provided that both the copyright
                     12:  * notice and this permission notice appear in all copies of the
                     13:  * software, derivative works or modified versions, and any portions
                     14:  * thereof, and that both notices appear in supporting documentation.
                     15:  *
                     16:  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
                     17:  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
                     18:  * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
                     19:  *
                     20:  * Carnegie Mellon requests users of this software to return to
                     21:  *
                     22:  *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
                     23:  *  School of Computer Science
                     24:  *  Carnegie Mellon University
                     25:  *  Pittsburgh PA 15213-3890
                     26:  *
                     27:  * any improvements or extensions that they make and grant Carnegie the
                     28:  * rights to redistribute these changes.
                     29:  */
                     30:
                     31: #include <sys/param.h>
                     32: #include <sys/systm.h>
                     33: #include <sys/ioctl.h>
                     34: #include <sys/selinfo.h>
                     35: #include <sys/tty.h>
                     36: #include <sys/proc.h>
                     37: #include <sys/user.h>
                     38: #include <sys/conf.h>
                     39: #include <sys/file.h>
                     40: #include <sys/uio.h>
                     41: #include <sys/kernel.h>
                     42: #include <sys/syslog.h>
                     43: #include <sys/types.h>
                     44: #include <sys/device.h>
                     45: #include <sys/timeout.h>
                     46:
                     47: #include <dev/cons.h>
                     48:
                     49: #include <machine/rpb.h>
                     50: #include <machine/prom.h>
                     51:
                     52: static struct  tty *prom_tty[1];
                     53: static struct  timeout prom_to;
                     54:
                     55: void promstart(struct tty *);
                     56: void promtimeout(void *);
                     57: int promparam(struct tty *, struct termios *);
                     58: cdev_decl(prom);
                     59: cons_decl(prom);
                     60:
                     61: int
                     62: promopen(dev, flag, mode, p)
                     63:        dev_t dev;
                     64:        int flag, mode;
                     65:        struct proc *p;
                     66: {
                     67:        int unit = minor(dev);
                     68:        struct tty *tp;
                     69:        int s;
                     70:        int error = 0, setuptimeout = 0;
                     71:
                     72:        if (unit >= 1)
                     73:                return ENXIO;
                     74:
                     75:        s = spltty();
                     76:
                     77:        if (prom_tty[unit] == NULL) {
                     78:                tp = prom_tty[unit] = ttymalloc();
                     79:        } else
                     80:                tp = prom_tty[unit];
                     81:
                     82:        tp->t_oproc = promstart;
                     83:        tp->t_param = promparam;
                     84:        tp->t_dev = dev;
                     85:        if ((tp->t_state & TS_ISOPEN) == 0) {
                     86:                tp->t_state |= TS_WOPEN|TS_CARR_ON;
                     87:                ttychars(tp);
                     88:                tp->t_iflag = TTYDEF_IFLAG;
                     89:                tp->t_oflag = TTYDEF_OFLAG;
                     90:                tp->t_cflag = TTYDEF_CFLAG|CLOCAL;
                     91:                tp->t_lflag = TTYDEF_LFLAG;
                     92:                tp->t_ispeed = tp->t_ospeed = 9600;
                     93:                ttsetwater(tp);
                     94:
                     95:                setuptimeout = 1;
                     96:        } else if (tp->t_state&TS_XCLUDE && p->p_ucred->cr_uid != 0) {
                     97:                splx(s);
                     98:                return EBUSY;
                     99:        }
                    100:
                    101:        splx(s);
                    102:
                    103:        error = (*linesw[tp->t_line].l_open)(dev, tp);
                    104:        if (error == 0 && setuptimeout) {
                    105:                timeout_set(&prom_to, promtimeout, tp);
                    106:                timeout_add(&prom_to, 1);
                    107:        }
                    108:        return error;
                    109: }
                    110:
                    111: int
                    112: promclose(dev, flag, mode, p)
                    113:        dev_t dev;
                    114:        int flag, mode;
                    115:        struct proc *p;
                    116: {
                    117:        int unit = minor(dev);
                    118:        struct tty *tp = prom_tty[unit];
                    119:
                    120:        timeout_del(&prom_to);
                    121:        (*linesw[tp->t_line].l_close)(tp, flag);
                    122:        ttyclose(tp);
                    123:        return 0;
                    124: }
                    125:
                    126: int
                    127: promread(dev, uio, flag)
                    128:        dev_t dev;
                    129:        struct uio *uio;
                    130:        int flag;
                    131: {
                    132:        struct tty *tp = prom_tty[minor(dev)];
                    133:
                    134:        return ((*linesw[tp->t_line].l_read)(tp, uio, flag));
                    135: }
                    136:
                    137: int
                    138: promwrite(dev, uio, flag)
                    139:        dev_t dev;
                    140:        struct uio *uio;
                    141:        int flag;
                    142: {
                    143:        struct tty *tp = prom_tty[minor(dev)];
                    144:
                    145:        return ((*linesw[tp->t_line].l_write)(tp, uio, flag));
                    146: }
                    147:
                    148: int
                    149: promioctl(dev, cmd, data, flag, p)
                    150:        dev_t dev;
                    151:        u_long cmd;
                    152:        caddr_t data;
                    153:        int flag;
                    154:        struct proc *p;
                    155: {
                    156:        int unit = minor(dev);
                    157:        struct tty *tp = prom_tty[unit];
                    158:        int error;
                    159:
                    160:        error = (*linesw[tp->t_line].l_ioctl)(tp, cmd, data, flag, p);
                    161:        if (error >= 0)
                    162:                return error;
                    163:        error = ttioctl(tp, cmd, data, flag, p);
                    164:        if (error >= 0)
                    165:                return error;
                    166:
                    167:        return ENOTTY;
                    168: }
                    169:
                    170: int
                    171: promparam(tp, t)
                    172:        struct tty *tp;
                    173:        struct termios *t;
                    174: {
                    175:
                    176:        return 0;
                    177: }
                    178:
                    179: void
                    180: promstart(tp)
                    181:        struct tty *tp;
                    182: {
                    183:        int s;
                    184:
                    185:        s = spltty();
                    186:        if (tp->t_state & (TS_TTSTOP | TS_BUSY))
                    187:                goto out;
                    188:        if (tp->t_outq.c_cc <= tp->t_lowat) {
                    189:                if (tp->t_state & TS_ASLEEP) {
                    190:                        tp->t_state &= ~TS_ASLEEP;
                    191:                        wakeup((caddr_t)&tp->t_outq);
                    192:                }
                    193:                selwakeup(&tp->t_wsel);
                    194:        }
                    195:        tp->t_state |= TS_BUSY;
                    196:        while (tp->t_outq.c_cc != 0)
                    197:                promcnputc(tp->t_dev, getc(&tp->t_outq));
                    198:        tp->t_state &= ~TS_BUSY;
                    199: out:
                    200:        splx(s);
                    201: }
                    202:
                    203: /*
                    204:  * Stop output on a line.
                    205:  */
                    206: int
                    207: promstop(tp, flag)
                    208:        struct tty *tp;
                    209:        int flag;
                    210: {
                    211:        int s;
                    212:
                    213:        s = spltty();
                    214:        if (tp->t_state & TS_BUSY)
                    215:                if ((tp->t_state & TS_TTSTOP) == 0)
                    216:                        tp->t_state |= TS_FLUSH;
                    217:        splx(s);
                    218:        return 0;
                    219: }
                    220:
                    221: void
                    222: promtimeout(v)
                    223:        void *v;
                    224: {
                    225:        struct tty *tp = v;
                    226:        u_char c;
                    227:
                    228:        while (promcnlookc(tp->t_dev, &c)) {
                    229:                if (tp->t_state & TS_ISOPEN)
                    230:                        (*linesw[tp->t_line].l_rint)(c, tp);
                    231:        }
                    232:        timeout_add(&prom_to, 1);
                    233: }
                    234:
                    235: struct tty *
                    236: promtty(dev)
                    237:        dev_t dev;
                    238: {
                    239:
                    240:        if (minor(dev) != 0)
                    241:                panic("promtty: bogus");
                    242:
                    243:        return prom_tty[0];
                    244: }

CVSweb