[BACK]Return to hpib.c CVS log [TXT][DIR] Up to [local] / sys / arch / hp300 / dev

Annotation of sys/arch/hp300/dev/hpib.c, Revision 1.1

1.1     ! nbrk        1: /*     $OpenBSD: hpib.c,v 1.13 2005/11/16 21:23:55 miod Exp $  */
        !             2: /*     $NetBSD: hpib.c,v 1.16 1997/04/27 20:58:57 thorpej Exp $        */
        !             3:
        !             4: /*
        !             5:  * Copyright (c) 1996, 1997 Jason R. Thorpe.  All rights reserved.
        !             6:  * Copyright (c) 1982, 1990, 1993
        !             7:  *     The Regents of the University of California.  All rights reserved.
        !             8:  *
        !             9:  * Redistribution and use in source and binary forms, with or without
        !            10:  * modification, are permitted provided that the following conditions
        !            11:  * are met:
        !            12:  * 1. Redistributions of source code must retain the above copyright
        !            13:  *    notice, this list of conditions and the following disclaimer.
        !            14:  * 2. Redistributions in binary form must reproduce the above copyright
        !            15:  *    notice, this list of conditions and the following disclaimer in the
        !            16:  *    documentation and/or other materials provided with the distribution.
        !            17:  * 3. 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:  *     @(#)hpib.c      8.2 (Berkeley) 1/12/94
        !            34:  */
        !            35:
        !            36: /*
        !            37:  * HP-IB bus driver
        !            38:  */
        !            39:
        !            40: #include <sys/param.h>
        !            41: #include <sys/systm.h>
        !            42: #include <sys/buf.h>
        !            43: #include <sys/malloc.h>
        !            44: #include <sys/device.h>
        !            45:
        !            46: #include <hp300/dev/dmavar.h>
        !            47:
        !            48: #include <hp300/dev/hpibvar.h>
        !            49:
        !            50: #include <machine/cpu.h>
        !            51: #include <machine/hp300spu.h>
        !            52:
        !            53: int    hpibbusmatch(struct device *, void *, void *);
        !            54: void   hpibbusattach(struct device *, struct device *, void *);
        !            55:
        !            56: struct cfattach hpibbus_ca = {
        !            57:        sizeof(struct hpibbus_softc), hpibbusmatch, hpibbusattach
        !            58: };
        !            59:
        !            60: struct cfdriver hpibbus_cd = {
        !            61:        NULL, "hpibbus", DV_DULL
        !            62: };
        !            63:
        !            64: void   hpibbus_attach_children(struct hpibbus_softc *);
        !            65: int    hpibbussubmatch(struct device *, void *, void *);
        !            66: int    hpibbusprint(void *, const char *);
        !            67:
        !            68: void   hpibstart(void *);
        !            69: void   hpibdone(void *);
        !            70:
        !            71: int    hpibtimeout = 100000;   /* # of status tests before we give up */
        !            72: int    hpibidtimeout = 10000;  /* # of status tests for hpibid() calls */
        !            73: int    hpibdmathresh = 3;      /* byte count beyond which to attempt dma */
        !            74:
        !            75: /*
        !            76:  * HP-IB is essentially an IEEE 488 bus, with an HP command
        !            77:  * set (CS/80 on `newer' devices, Amigo on before-you-were-born
        !            78:  * devices) thrown on top.  Devices that respond to CS/80 (and
        !            79:  * probably Amigo, too) are tagged with a 16-bit ID.
        !            80:  *
        !            81:  * HP-IB has a 2-level addressing scheme; slave, the analog
        !            82:  * of a SCSI ID, and punit, the analog of a SCSI LUN.  Unfortunately,
        !            83:  * IDs are on a per-slave basis; punits are often used for disk
        !            84:  * drives that have an accompanying tape drive on the second punit.
        !            85:  *
        !            86:  * In addition, not all HP-IB devices speak CS/80 or Amigo.
        !            87:  * Examples of such devices are HP-IB plotters, which simply
        !            88:  * take raw plotter commands over 488.  These devices do not
        !            89:  * have ID tags, and often the host cannot even tell if such
        !            90:  * a device is attached to the system!
        !            91:  *
        !            92:  * We nevertheless probe the whole (slave, punit) tuple space, since
        !            93:  * drivers for devices with a unique ID know exactly where to attach;
        !            94:  * and we disallow ``star'' locators for other drivers.
        !            95:  */
        !            96:
        !            97: int
        !            98: hpibbusmatch(parent, match, aux)
        !            99:        struct device *parent;
        !           100:        void *match, *aux;
        !           101: {
        !           102:
        !           103:        return (1);
        !           104: }
        !           105:
        !           106: void
        !           107: hpibbusattach(parent, self, aux)
        !           108:        struct device *parent, *self;
        !           109:        void *aux;
        !           110: {
        !           111:        struct hpibbus_softc *sc = (struct hpibbus_softc *)self;
        !           112:        struct hpibdev_attach_args *ha = aux;
        !           113:
        !           114:        printf("\n");
        !           115:
        !           116:        /* Get the operations vector for the controller. */
        !           117:        sc->sc_ops = ha->ha_ops;
        !           118:        sc->sc_type = ha->ha_type;              /* XXX */
        !           119:        sc->sc_ba = ha->ha_ba;
        !           120:        *(ha->ha_softcpp) = sc;                 /* XXX */
        !           121:
        !           122:        hpibreset(self->dv_unit);               /* XXX souldn't be here */
        !           123:
        !           124:        /*
        !           125:         * Initialize the DMA queue entry.
        !           126:         */
        !           127:        sc->sc_dq = (struct dmaqueue *)malloc(sizeof(struct dmaqueue),
        !           128:            M_DEVBUF, M_NOWAIT);
        !           129:        if (sc->sc_dq == NULL) {
        !           130:                printf("%s: can't allocate DMA queue entry\n", self->dv_xname);
        !           131:                return;
        !           132:        }
        !           133:        sc->sc_dq->dq_softc = sc;
        !           134:        sc->sc_dq->dq_start = hpibstart;
        !           135:        sc->sc_dq->dq_done = hpibdone;
        !           136:
        !           137:        /* Initialize the slave request queue. */
        !           138:        TAILQ_INIT(&sc->sc_queue);
        !           139:
        !           140:        /* Attach any devices on the bus. */
        !           141:        hpibbus_attach_children(sc);
        !           142: }
        !           143:
        !           144: void
        !           145: hpibbus_attach_children(sc)
        !           146:        struct hpibbus_softc *sc;
        !           147: {
        !           148:        struct hpibbus_attach_args ha;
        !           149:        int id, slave, punit;
        !           150:        int i;
        !           151:
        !           152:        for (slave = 0; slave < HPIB_NSLAVES; slave++) {
        !           153:                /*
        !           154:                 * Get the ID tag for the device, if any.
        !           155:                 * Plotters won't identify themselves, and
        !           156:                 * get the same value as non-existent devices.
        !           157:                 * However, aging HP-IB drives are slow to respond; try up
        !           158:                 * to three times to get a valid ID.
        !           159:                 */
        !           160:                for (i = 0; i < 3; i++) {
        !           161:                        id = hpibid(sc->sc_dev.dv_unit, slave);
        !           162:                        if ((id & 0x200) != 0)
        !           163:                                break;
        !           164:                        delay(10000);
        !           165:                }
        !           166:
        !           167:                for (punit = 0; punit < HPIB_NPUNITS; punit++) {
        !           168:                        /*
        !           169:                         * Search through all configured children for this bus.
        !           170:                         */
        !           171:                        ha.ha_id = id;
        !           172:                        ha.ha_slave = slave;
        !           173:                        ha.ha_punit = punit;
        !           174:                        (void)config_found_sm(&sc->sc_dev, &ha, hpibbusprint,
        !           175:                            hpibbussubmatch);
        !           176:                }
        !           177:        }
        !           178: }
        !           179:
        !           180: int
        !           181: hpibbussubmatch(parent, match, aux)
        !           182:        struct device *parent;
        !           183:        void *match, *aux;
        !           184: {
        !           185:        struct cfdata *cf = match;
        !           186:        struct hpibbus_attach_args *ha = aux;
        !           187:
        !           188:        if (cf->hpibbuscf_slave != HPIBBUS_SLAVE_UNK &&
        !           189:            cf->hpibbuscf_slave != ha->ha_slave)
        !           190:                return (0);
        !           191:        if (cf->hpibbuscf_punit != HPIBBUS_PUNIT_UNK &&
        !           192:            cf->hpibbuscf_punit != ha->ha_punit)
        !           193:                return (0);
        !           194:        return ((*cf->cf_attach->ca_match)(parent, match, aux));
        !           195: }
        !           196:
        !           197: int
        !           198: hpibbusprint(aux, pnp)
        !           199:        void *aux;
        !           200:        const char *pnp;
        !           201: {
        !           202:        struct hpibbus_attach_args *ha = aux;
        !           203:
        !           204:        if (pnp != NULL) {
        !           205:                if (ha->ha_id == 0 || ha->ha_punit != 0 /* XXX */)
        !           206:                        return (QUIET);
        !           207:                printf("HP-IB device (id %04X) at %s", ha->ha_id, pnp);
        !           208:        }
        !           209:        printf(" slave %d punit %d", ha->ha_slave, ha->ha_punit);
        !           210:        return (UNCONF);
        !           211: }
        !           212:
        !           213: int
        !           214: hpibdevprint(aux, pnp)
        !           215:        void *aux;
        !           216:        const char *pnp;
        !           217: {
        !           218:
        !           219:        /* only hpibbus's can attach to hpibdev's -- easy. */
        !           220:        if (pnp != NULL)
        !           221:                printf("hpibbus at %s", pnp);
        !           222:        return (UNCONF);
        !           223: }
        !           224:
        !           225: void
        !           226: hpibreset(unit)
        !           227:        int unit;
        !           228: {
        !           229:        struct hpibbus_softc *sc = hpibbus_cd.cd_devs[unit];
        !           230:
        !           231:        (*sc->sc_ops->hpib_reset)(sc);
        !           232: }
        !           233:
        !           234: int
        !           235: hpibreq(pdev, hq)
        !           236:        struct device *pdev;
        !           237:        struct hpibqueue *hq;
        !           238: {
        !           239:        struct hpibbus_softc *sc = (struct hpibbus_softc *)pdev;
        !           240:        int s;
        !           241:
        !           242:        s = splhigh();  /* XXXthorpej */
        !           243:        TAILQ_INSERT_TAIL(&sc->sc_queue, hq, hq_list);
        !           244:        splx(s);
        !           245:
        !           246:        if (TAILQ_FIRST(&sc->sc_queue) == hq)
        !           247:                return (1);
        !           248:
        !           249:        return (0);
        !           250: }
        !           251:
        !           252: void
        !           253: hpibfree(pdev, hq)
        !           254:        struct device *pdev;
        !           255:        struct hpibqueue *hq;
        !           256: {
        !           257:        struct hpibbus_softc *sc = (struct hpibbus_softc *)pdev;
        !           258:        int s;
        !           259:
        !           260:        s = splhigh();  /* XXXthorpej */
        !           261:        TAILQ_REMOVE(&sc->sc_queue, hq, hq_list);
        !           262:        splx(s);
        !           263:
        !           264:        if ((hq = TAILQ_FIRST(&sc->sc_queue)) != NULL)
        !           265:                (*hq->hq_start)(hq->hq_softc);
        !           266: }
        !           267:
        !           268: int
        !           269: hpibid(unit, slave)
        !           270:        int unit, slave;
        !           271: {
        !           272:        short id;
        !           273:        int ohpibtimeout;
        !           274:
        !           275:        /*
        !           276:         * XXX shorten timeout value so autoconfig doesn't
        !           277:         * take forever on slow CPUs.
        !           278:         */
        !           279:        ohpibtimeout = hpibtimeout;
        !           280:        hpibtimeout = hpibidtimeout * (cpuspeed / 8);
        !           281:        if (hpibrecv(unit, 31, slave, &id, 2) != 2)
        !           282:                id = 0;
        !           283:        hpibtimeout = ohpibtimeout;
        !           284:        return(id);
        !           285: }
        !           286:
        !           287: int
        !           288: hpibsend(unit, slave, sec, addr, cnt)
        !           289:        int unit, slave, sec, cnt;
        !           290:        void *addr;
        !           291: {
        !           292:        struct hpibbus_softc *sc = hpibbus_cd.cd_devs[unit];
        !           293:
        !           294:        return ((*sc->sc_ops->hpib_send)(sc, slave, sec, addr, cnt));
        !           295: }
        !           296:
        !           297: int
        !           298: hpibrecv(unit, slave, sec, addr, cnt)
        !           299:        int unit, slave, sec, cnt;
        !           300:        void *addr;
        !           301: {
        !           302:        struct hpibbus_softc *sc = hpibbus_cd.cd_devs[unit];
        !           303:
        !           304:        return ((*sc->sc_ops->hpib_recv)(sc, slave, sec, addr, cnt));
        !           305: }
        !           306:
        !           307: int
        !           308: hpibpptest(unit, slave)
        !           309:        int unit;
        !           310:        int slave;
        !           311: {
        !           312:        struct hpibbus_softc *sc = hpibbus_cd.cd_devs[unit];
        !           313:
        !           314:        return ((*sc->sc_ops->hpib_ppoll)(sc) & (0x80 >> slave));
        !           315: }
        !           316:
        !           317: void
        !           318: hpibppclear(unit)
        !           319:        int unit;
        !           320: {
        !           321:        struct hpibbus_softc *sc = hpibbus_cd.cd_devs[unit];
        !           322:
        !           323:        sc->sc_flags &= ~HPIBF_PPOLL;
        !           324: }
        !           325:
        !           326: void
        !           327: hpibawait(unit)
        !           328:        int unit;
        !           329: {
        !           330:        struct hpibbus_softc *sc = hpibbus_cd.cd_devs[unit];
        !           331:
        !           332:        sc->sc_flags |= HPIBF_PPOLL;
        !           333:        (*sc->sc_ops->hpib_ppwatch)(sc);
        !           334: }
        !           335:
        !           336: int
        !           337: hpibswait(unit, slave)
        !           338:        int unit;
        !           339:        int slave;
        !           340: {
        !           341:        struct hpibbus_softc *sc = hpibbus_cd.cd_devs[unit];
        !           342:        int timo = hpibtimeout;
        !           343:        int mask, (*ppoll)(struct hpibbus_softc *);
        !           344:
        !           345:        ppoll = sc->sc_ops->hpib_ppoll;
        !           346:        mask = 0x80 >> slave;
        !           347:        while (((*ppoll)(sc) & mask) == 0) {
        !           348:                if (--timo == 0) {
        !           349:                        printf("%s: swait timeout\n", sc->sc_dev.dv_xname);
        !           350:                        return(-1);
        !           351:                }
        !           352:        }
        !           353:        return(0);
        !           354: }
        !           355:
        !           356: int
        !           357: hpibustart(unit)
        !           358:        int unit;
        !           359: {
        !           360:        struct hpibbus_softc *sc = hpibbus_cd.cd_devs[unit];
        !           361:
        !           362:        if (sc->sc_type == HPIBA)
        !           363:                sc->sc_dq->dq_chan = DMA0;
        !           364:        else
        !           365:                sc->sc_dq->dq_chan = DMA0 | DMA1;
        !           366:        if (dmareq(sc->sc_dq))
        !           367:                return(1);
        !           368:        return(0);
        !           369: }
        !           370:
        !           371: void
        !           372: hpibstart(arg)
        !           373:        void *arg;
        !           374: {
        !           375:        struct hpibbus_softc *sc = arg;
        !           376:        struct hpibqueue *hq;
        !           377:
        !           378:        hq = TAILQ_FIRST(&sc->sc_queue);
        !           379:        (*hq->hq_go)(hq->hq_softc);
        !           380: }
        !           381:
        !           382: void
        !           383: hpibgo(unit, slave, sec, vbuf, count, rw, timo)
        !           384:        int unit, slave, sec;
        !           385:        void *vbuf;
        !           386:        int count, rw, timo;
        !           387: {
        !           388:        struct hpibbus_softc *sc = hpibbus_cd.cd_devs[unit];
        !           389:
        !           390:        (*sc->sc_ops->hpib_go)(sc, slave, sec, vbuf, count, rw, timo);
        !           391: }
        !           392:
        !           393: void
        !           394: hpibdone(arg)
        !           395:        void *arg;
        !           396: {
        !           397:        struct hpibbus_softc *sc = arg;
        !           398:
        !           399:        (*sc->sc_ops->hpib_done)(sc);
        !           400: }
        !           401:
        !           402: int
        !           403: hpibintr(arg)
        !           404:        void *arg;
        !           405: {
        !           406:        struct hpibbus_softc *sc = arg;
        !           407:
        !           408:        return ((sc->sc_ops->hpib_intr)(arg));
        !           409: }

CVSweb