Annotation of 43BSDReno/sys/hpdev/ppi.c, revision 1.1.1.1

1.1       root        1: /*
                      2:  * Copyright (c) 1982, 1990 The Regents of the University of California.
                      3:  * All rights reserved.
                      4:  *
                      5:  * Redistribution is only permitted until one year after the first shipment
                      6:  * of 4.4BSD by the Regents.  Otherwise, redistribution and use in source and
                      7:  * binary forms are permitted provided that: (1) source distributions retain
                      8:  * this entire copyright notice and comment, and (2) distributions including
                      9:  * binaries display the following acknowledgement:  This product includes
                     10:  * software developed by the University of California, Berkeley and its
                     11:  * contributors'' in the documentation or other materials provided with the
                     12:  * distribution and in all advertising materials mentioning features or use
                     13:  * of this software.  Neither the name of the University nor the names of
                     14:  * its contributors may be used to endorse or promote products derived from
                     15:  * this software without specific prior written permission.
                     16:  * THIS SOFTWARE IS PROVIDED AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
                     17:  * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
                     18:  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
                     19:  *
                     20:  *     @(#)ppi.c       7.1 (Berkeley) 5/8/90
                     21:  */
                     22: 
                     23: /*
                     24:  * Printer/Plotter HPIB interface
                     25:  */
                     26: 
                     27: #include "ppi.h"
                     28: #if NPPI > 0
                     29: 
                     30: #include "param.h"
                     31: #include "errno.h"
                     32: #include "uio.h"
                     33: #include "malloc.h"
                     34: 
                     35: #include "device.h"
                     36: 
                     37: int    ppiattach(), ppistart();
                     38: struct driver ppidriver = {
                     39:        ppiattach, "ppi", ppistart,
                     40: };
                     41: 
                     42: struct ppi_softc {
                     43:        int     sc_flags;
                     44:        struct  devqueue sc_dq;
                     45:        struct  hp_device *sc_hd;
                     46: } ppi_softc[NPPI];
                     47: 
                     48: /* sc_flags values */
                     49: #define        PPIF_ALIVE      0x1     
                     50: #define        PPIF_OPEN       0x2     
                     51: 
                     52: #define UNIT(x)                minor(x)
                     53: 
                     54: ppiattach(hd)
                     55:        register struct hp_device *hd;
                     56: {
                     57:        register struct ppi_softc *sc = &ppi_softc[hd->hp_unit];
                     58: 
                     59:        /*
                     60:         * XXX: the printer/plotter doesn't seem to really return
                     61:         * an ID but this will at least prevent us from mistaking
                     62:         * a cs80 disk or tape for a ppi device.
                     63:         */
                     64:        if (hpibid(hd->hp_ctlr, hd->hp_slave) & 0x200)
                     65:                return(0);
                     66:        sc->sc_flags = PPIF_ALIVE;
                     67:        sc->sc_dq.dq_ctlr = hd->hp_ctlr;
                     68:        sc->sc_dq.dq_unit = hd->hp_unit;
                     69:        sc->sc_dq.dq_slave = hd->hp_slave;
                     70:        sc->sc_dq.dq_driver = &ppidriver;
                     71:        sc->sc_hd = hd;
                     72:        return(1);
                     73: }
                     74: 
                     75: ppiopen(dev, flags)
                     76:        dev_t dev;
                     77: {
                     78:        register int unit = UNIT(dev);
                     79:        register struct ppi_softc *sc = &ppi_softc[unit];
                     80: 
                     81:        if (unit >= NPPI || (sc->sc_flags & PPIF_ALIVE) == 0)
                     82:                return(ENXIO);
                     83:        if (sc->sc_flags & PPIF_OPEN)
                     84:                return(EBUSY);
                     85:        sc->sc_flags |= PPIF_OPEN;
                     86:        return(0);
                     87: }
                     88: 
                     89: ppiclose(dev, flags)
                     90:        dev_t dev;
                     91: {
                     92:        register int unit = UNIT(dev);
                     93:        register struct ppi_softc *sc = &ppi_softc[unit];
                     94: 
                     95:        sc->sc_flags &= ~PPIF_OPEN;
                     96:        return(0);
                     97: }
                     98: 
                     99: ppistart(unit)
                    100:        register int unit;
                    101: {
                    102:        wakeup(&ppi_softc[unit]);
                    103: }
                    104: 
                    105: ppiread(dev, uio)
                    106:        dev_t dev;
                    107:        struct uio *uio;
                    108: {
                    109: 
                    110:        return (ppirw(dev, uio, UIO_READ));
                    111: }
                    112: 
                    113: ppiwrite(dev, uio)
                    114:        dev_t dev;
                    115:        struct uio *uio;
                    116: {
                    117: 
                    118:        return (ppirw(dev, uio, UIO_WRITE));
                    119: }
                    120: 
                    121: ppirw(dev, uio, rw)
                    122:        dev_t dev;
                    123:        register struct uio *uio;
                    124:        enum uio_rw rw;
                    125: {
                    126:        register struct ppi_softc *sc = &ppi_softc[UNIT(dev)];
                    127:        register int s, len, cnt;
                    128:        register char *cp;
                    129:        int error = 0;
                    130: 
                    131:        len = MIN(CLBYTES, uio->uio_resid);
                    132:        cp = (char *)malloc(len, M_TEMP, M_WAITOK);
                    133:        while (uio->uio_resid > 0) {
                    134:                len = MIN(CLBYTES, uio->uio_resid);
                    135:                if (rw == UIO_WRITE) {
                    136:                        error = uiomove(cp, len, uio);
                    137:                        if (error)
                    138:                                break;
                    139:                }
                    140:                s = splbio();
                    141:                if (hpibreq(&sc->sc_dq) == 0)
                    142:                        sleep(sc, PRIBIO + 1);
                    143:                splx(s);
                    144:                if (rw == UIO_WRITE)
                    145:                        cnt = hpibsend(sc->sc_hd->hp_ctlr, sc->sc_hd->hp_slave,
                    146:                                -1, cp, len);
                    147:                else
                    148:                        cnt = hpibrecv(sc->sc_hd->hp_ctlr, sc->sc_hd->hp_slave,
                    149:                                -1, cp, len);
                    150:                s = splbio();
                    151:                hpibfree(&sc->sc_dq);
                    152:                splx(s);
                    153:                if (rw == UIO_READ) {
                    154:                        error = uiomove(cp, cnt, uio);
                    155:                        if (error)
                    156:                                break;
                    157:                }
                    158:                if (cnt != len) {
                    159:                        if (rw == UIO_WRITE)
                    160:                                uio->uio_resid += len - cnt;
                    161:                        break;
                    162:                }
                    163:        }
                    164:        free(cp, M_TEMP);
                    165:        return (error);
                    166: }
                    167: #endif

unix.superglobalmegacorp.com

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