Annotation of Gnu-Mach/i386/i386at/lpr.c, revision 1.1.1.5

1.1       root        1: /* 
                      2:  * Mach Operating System
                      3:  * Copyright (c) 1993-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:  *     Parallel port printer driver v1.0
                     28:  *     All rights reserved.
                     29:  */ 
                     30:   
                     31: #if NLPR > 0
                     32:   
                     33: #include <mach/std_types.h>
                     34: #include <sys/types.h>
1.1.1.2   root       35: #include <kern/printf.h>
                     36: #include <kern/mach_clock.h>
1.1       root       37: #include <sys/time.h>
                     38: #include <device/conf.h>
1.1.1.2   root       39: #include <device/device_types.h>
1.1       root       40: #include <device/tty.h>
                     41: #include <device/io_req.h>
                     42:   
                     43: #include <i386/ipl.h>
                     44: #include <i386/pio.h>
                     45: #include <chips/busses.h>
1.1.1.2   root       46: #include <i386at/autoconf.h>
1.1.1.3   root       47: #include <i386at/lpr.h>
1.1       root       48:   
                     49: /* 
                     50:  * Driver information for auto-configuration stuff.
                     51:  */
                     52: 
                     53: struct bus_device *lprinfo[NLPR];      /* ??? */
                     54: 
                     55: static vm_offset_t lpr_std[NLPR] = { 0 };
                     56: static struct bus_device *lpr_info[NLPR];
                     57: struct bus_driver lprdriver = {
                     58:        lprprobe, 0, lprattach, 0, lpr_std, "lpr", lpr_info, 0, 0, 0};
                     59: 
                     60: struct tty     lpr_tty[NLPR];
                     61: 
                     62: int lpr_alive[NLPR];
                     63: 
1.1.1.2   root       64: int
1.1       root       65: lprprobe(port, dev)
1.1.1.3   root       66: vm_offset_t port;
                     67: struct bus_ctlr *dev;
1.1       root       68: {
                     69:        u_short addr = (u_short) dev->address;
                     70:        int     unit = dev->unit;
                     71:        int ret;
                     72: 
1.1.1.4   root       73:        if ((unit < 0) || (unit >= NLPR)) {
1.1       root       74:                printf("com %d out of range\n", unit);
                     75:                return(0);
                     76:        }
                     77: 
                     78:        outb(INTR_ENAB(addr),0x07);
                     79:        outb(DATA(addr),0xaa);
                     80:        ret = inb(DATA(addr)) == 0xaa;
                     81:        if (ret) {
                     82:                if (lpr_alive[unit]) {
                     83:                        printf("lpr: Multiple alive entries for unit %d.\n", unit);
                     84:                        printf("lpr: Ignoring entry with address = %x .\n", addr);
                     85:                        ret = 0;
                     86:                } else
                     87:                        lpr_alive[unit]++;
                     88:        }
                     89:        return(ret);
                     90: }
                     91: 
                     92: void lprattach(struct bus_device *dev)
                     93: {
                     94:        u_char          unit = dev->unit;
                     95:        u_short         addr = (u_short) dev->address;
                     96: 
                     97:        take_dev_irq(dev);
1.1.1.2   root       98:        printf(", port = %lx, spl = %ld, pic = %d.",
1.1       root       99:               dev->address, dev->sysdep, dev->sysdep1);
                    100:        lprinfo[unit] = dev;
                    101:   
                    102:        outb(INTR_ENAB(addr), inb(INTR_ENAB(addr)) & 0x0f);
                    103: 
                    104:        return;
                    105: }
                    106: 
1.1.1.2   root      107: int
1.1.1.4   root      108: lpropen(dev_t dev, int flag, io_req_t ior)
1.1       root      109: {
1.1.1.4   root      110:        int unit = minor(dev);
                    111:        struct bus_device *isai;
                    112:        struct tty *tp;
                    113:        u_short addr;
                    114: 
                    115:        if (unit >= NLPR)
                    116:                return D_NO_SUCH_DEVICE;
                    117: 
                    118:        isai = lprinfo[unit];
                    119:        if (isai == NULL || !isai->alive)
                    120:                return D_NO_SUCH_DEVICE;
                    121: 
1.1       root      122:        tp = &lpr_tty[unit];
                    123:        addr = (u_short) isai->address;
                    124:        tp->t_dev = dev;
1.1.1.4   root      125:        tp->t_addr = addr;
1.1       root      126:        tp->t_oproc = lprstart;
                    127:        tp->t_state |= TS_WOPEN;
                    128:        tp->t_stop = lprstop;
                    129:        tp->t_getstat = lprgetstat;
                    130:        tp->t_setstat = lprsetstat;
                    131:        if ((tp->t_state & TS_ISOPEN) == 0)
                    132:                ttychars(tp);
                    133:        outb(INTR_ENAB(addr), inb(INTR_ENAB(addr)) | 0x10);
                    134:        tp->t_state |= TS_CARR_ON;
                    135:        return (char_open(dev, tp, flag, ior));
                    136: }
                    137: 
1.1.1.2   root      138: void
1.1       root      139: lprclose(dev, flag)
1.1.1.3   root      140: dev_t dev;
1.1       root      141: int flag;
                    142: {
                    143: int            unit = minor(dev);
                    144: struct tty     *tp = &lpr_tty[unit];
                    145: u_short                addr =  (u_short) lprinfo[unit]->address;
                    146:   
                    147:        ttyclose(tp);
                    148:        if (tp->t_state&TS_HUPCLS || (tp->t_state&TS_ISOPEN)==0) {
                    149:                outb(INTR_ENAB(addr), inb(INTR_ENAB(addr)) & 0x0f);
                    150:                tp->t_state &= ~TS_BUSY;
                    151:        } 
                    152: }
                    153: 
1.1.1.2   root      154: int
1.1       root      155: lprread(dev, ior)
1.1.1.3   root      156: dev_t  dev;
1.1       root      157: io_req_t ior;
                    158: {
                    159:        return char_read(&lpr_tty[minor(dev)], ior);
                    160: }
                    161: 
1.1.1.2   root      162: int
1.1       root      163: lprwrite(dev, ior)
1.1.1.3   root      164: dev_t  dev;
1.1       root      165: io_req_t ior;
                    166: {
                    167:        return char_write(&lpr_tty[minor(dev)], ior);
                    168: }
                    169: 
1.1.1.2   root      170: int
1.1       root      171: lprportdeath(dev, port)
                    172: dev_t          dev;
                    173: mach_port_t    port;
                    174: {
1.1.1.2   root      175:        return (tty_portdeath(&lpr_tty[minor(dev)], (ipc_port_t)port));
1.1       root      176: }
                    177: 
                    178: io_return_t
                    179: lprgetstat(dev, flavor, data, count)
                    180: dev_t          dev;
                    181: int            flavor;
                    182: int            *data;          /* pointer to OUT array */
1.1.1.2   root      183: natural_t      *count;         /* out */
1.1       root      184: {
                    185:        io_return_t     result = D_SUCCESS;
                    186:        int             unit = minor(dev);
                    187: 
                    188:        switch (flavor) {
                    189:        default:
                    190:                result = tty_get_status(&lpr_tty[unit], flavor, data, count);
                    191:                break;
                    192:        }
                    193:        return (result);
                    194: }
                    195: 
                    196: io_return_t
1.1.1.3   root      197: lprsetstat(
                    198:        dev_t           dev,
                    199:        int             flavor,
                    200:        int *           data,
                    201:        natural_t       count)
1.1       root      202: {
                    203:        io_return_t     result = D_SUCCESS;
                    204:        int             unit = minor(dev);
                    205: 
                    206:        switch (flavor) {
                    207:        default:
                    208:                result = tty_set_status(&lpr_tty[unit], flavor, data, count);
                    209: /*             if (result == D_SUCCESS && flavor == TTY_STATUS)
                    210:                        lprparam(unit);
                    211: */             return (result);
                    212:        }
                    213:        return (D_SUCCESS);
                    214: }
                    215: 
1.1.1.3   root      216: void lprintr(int unit)
1.1       root      217: {
1.1.1.3   root      218:        struct tty *tp = &lpr_tty[unit];
1.1       root      219: 
                    220:        if ((tp->t_state & TS_ISOPEN) == 0)
                    221:          return;
                    222: 
                    223:        tp->t_state &= ~TS_BUSY;
                    224:        if (tp->t_state&TS_FLUSH)
                    225:                tp->t_state &=~TS_FLUSH;
                    226:        tt_write_wakeup(tp);
                    227:        lprstart(tp);
                    228: }   
                    229: 
1.1.1.3   root      230: void lprstart(struct tty *tp)
1.1       root      231: {
                    232:        spl_t s = spltty();
                    233:        u_short addr = (natural_t) tp->t_addr;
                    234:        int status = inb(STATUS(addr));
1.1.1.5 ! root      235:        int nch;
1.1       root      236: 
                    237:        if (tp->t_state & (TS_TIMEOUT|TS_TTSTOP|TS_BUSY)) {
                    238:                splx(s);
1.1.1.2   root      239:                return;
1.1       root      240:        }
                    241: 
                    242:        if (status & 0x20) {
                    243:                printf("Printer out of paper!\n");
                    244:                splx(s);
1.1.1.2   root      245:                return;
1.1       root      246:        }
                    247: 
                    248:        if (tp->t_outq.c_cc <= TTLOWAT(tp)) {
                    249:                tt_write_wakeup(tp);
                    250:        }
                    251:        if (tp->t_outq.c_cc == 0) {
                    252:                splx(s);
1.1.1.2   root      253:                return;
1.1       root      254:        }
                    255:        nch = getc(&tp->t_outq);
1.1.1.5 ! root      256:        if (nch == -1) {
        !           257:                splx(s);
        !           258:                return;
        !           259:        }
1.1       root      260:        if ((tp->t_flags & LITOUT) == 0 && (nch & 0200)) {
1.1.1.2   root      261:                timeout((timer_func_t *)ttrstrt, (char *)tp, (nch & 0x7f) + 6);
1.1       root      262:                tp->t_state |= TS_TIMEOUT;
                    263:                return;
                    264:        }
                    265:        outb(DATA(addr), nch);
                    266:        outb(INTR_ENAB(addr),inb(INTR_ENAB(addr)) | 0x01);
                    267:        outb(INTR_ENAB(addr),inb(INTR_ENAB(addr)) & 0x1e);
                    268:        tp->t_state |= TS_BUSY;
                    269:        splx(s);
1.1.1.2   root      270:        return;
1.1       root      271: }
                    272: 
1.1.1.2   root      273: void
1.1.1.3   root      274: lprstop(
                    275:        struct tty      *tp,
                    276:        int             flags)
1.1       root      277: {
                    278:        if ((tp->t_state & TS_BUSY) && (tp->t_state & TS_TTSTOP) == 0)
                    279:                tp->t_state |= TS_FLUSH;
                    280: }
1.1.1.2   root      281: int
1.1.1.3   root      282: lprpr(int unit)
1.1       root      283: {
                    284:        lprpr_addr(lprinfo[unit]->address);
                    285:        return 0;
                    286: }
                    287: 
1.1.1.2   root      288: void
1.1.1.3   root      289: lprpr_addr(unsigned short addr)
1.1       root      290: {
                    291:        printf("DATA(%x) %x, STATUS(%x) %x, INTR_ENAB(%x) %x\n",
                    292:                DATA(addr), inb(DATA(addr)),
                    293:                STATUS(addr), inb(STATUS(addr)),
                    294:                INTR_ENAB(addr), inb(INTR_ENAB(addr)));
                    295: }
1.1.1.2   root      296: #endif /* NLPR */

unix.superglobalmegacorp.com

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