Home | History | Annotate | Line # | Download | only in dev
hpib.c revision 1.19.28.2
      1  1.19.28.2  jdolecek /*	$NetBSD: hpib.c,v 1.19.28.2 2002/10/10 18:32:39 jdolecek Exp $	*/
      2       1.18   thorpej 
      3       1.18   thorpej /*-
      4       1.18   thorpej  * Copyright (c) 1996, 1997 The NetBSD Foundation, Inc.
      5       1.18   thorpej  * All rights reserved.
      6       1.18   thorpej  *
      7       1.18   thorpej  * This code is derived from software contributed to The NetBSD Foundation
      8       1.18   thorpej  * by Jason R. Thorpe.
      9       1.18   thorpej  *
     10       1.18   thorpej  * Redistribution and use in source and binary forms, with or without
     11       1.18   thorpej  * modification, are permitted provided that the following conditions
     12       1.18   thorpej  * are met:
     13       1.18   thorpej  * 1. Redistributions of source code must retain the above copyright
     14       1.18   thorpej  *    notice, this list of conditions and the following disclaimer.
     15       1.18   thorpej  * 2. Redistributions in binary form must reproduce the above copyright
     16       1.18   thorpej  *    notice, this list of conditions and the following disclaimer in the
     17       1.18   thorpej  *    documentation and/or other materials provided with the distribution.
     18       1.18   thorpej  * 3. All advertising materials mentioning features or use of this software
     19       1.18   thorpej  *    must display the following acknowledgement:
     20       1.18   thorpej  *	This product includes software developed by the NetBSD
     21       1.18   thorpej  *	Foundation, Inc. and its contributors.
     22       1.18   thorpej  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23       1.18   thorpej  *    contributors may be used to endorse or promote products derived
     24       1.18   thorpej  *    from this software without specific prior written permission.
     25       1.18   thorpej  *
     26       1.18   thorpej  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27       1.18   thorpej  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28       1.18   thorpej  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29       1.18   thorpej  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30       1.18   thorpej  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31       1.18   thorpej  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32       1.18   thorpej  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33       1.18   thorpej  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34       1.18   thorpej  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35       1.18   thorpej  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36       1.18   thorpej  * POSSIBILITY OF SUCH DAMAGE.
     37       1.18   thorpej  */
     38        1.4       cgd 
     39        1.1       cgd /*
     40        1.3   mycroft  * Copyright (c) 1982, 1990, 1993
     41        1.3   mycroft  *	The Regents of the University of California.  All rights reserved.
     42        1.1       cgd  *
     43        1.1       cgd  * Redistribution and use in source and binary forms, with or without
     44        1.1       cgd  * modification, are permitted provided that the following conditions
     45        1.1       cgd  * are met:
     46        1.1       cgd  * 1. Redistributions of source code must retain the above copyright
     47        1.1       cgd  *    notice, this list of conditions and the following disclaimer.
     48        1.1       cgd  * 2. Redistributions in binary form must reproduce the above copyright
     49        1.1       cgd  *    notice, this list of conditions and the following disclaimer in the
     50        1.1       cgd  *    documentation and/or other materials provided with the distribution.
     51        1.1       cgd  * 3. All advertising materials mentioning features or use of this software
     52        1.1       cgd  *    must display the following acknowledgement:
     53        1.1       cgd  *	This product includes software developed by the University of
     54        1.1       cgd  *	California, Berkeley and its contributors.
     55        1.1       cgd  * 4. Neither the name of the University nor the names of its contributors
     56        1.1       cgd  *    may be used to endorse or promote products derived from this software
     57        1.1       cgd  *    without specific prior written permission.
     58        1.1       cgd  *
     59        1.1       cgd  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     60        1.1       cgd  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     61        1.1       cgd  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     62        1.1       cgd  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     63        1.1       cgd  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     64        1.1       cgd  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     65        1.1       cgd  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     66        1.1       cgd  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     67        1.1       cgd  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     68        1.1       cgd  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     69        1.1       cgd  * SUCH DAMAGE.
     70        1.1       cgd  *
     71        1.4       cgd  *	@(#)hpib.c	8.2 (Berkeley) 1/12/94
     72        1.1       cgd  */
     73        1.1       cgd 
     74        1.1       cgd /*
     75       1.13   thorpej  * HP-IB bus driver
     76        1.1       cgd  */
     77        1.1       cgd 
     78  1.19.28.1  jdolecek #include <sys/cdefs.h>
     79  1.19.28.2  jdolecek __KERNEL_RCSID(0, "$NetBSD: hpib.c,v 1.19.28.2 2002/10/10 18:32:39 jdolecek Exp $");
     80  1.19.28.1  jdolecek 
     81        1.3   mycroft #include <sys/param.h>
     82        1.3   mycroft #include <sys/systm.h>
     83        1.3   mycroft #include <sys/buf.h>
     84       1.13   thorpej #include <sys/malloc.h>
     85       1.13   thorpej #include <sys/device.h>
     86       1.13   thorpej 
     87       1.13   thorpej #include <hp300/dev/dmavar.h>
     88        1.3   mycroft 
     89        1.3   mycroft #include <hp300/dev/hpibvar.h>
     90        1.1       cgd 
     91        1.3   mycroft #include <machine/cpu.h>
     92       1.16   thorpej #include <machine/hp300spu.h>
     93        1.1       cgd 
     94       1.13   thorpej int	hpibbusmatch __P((struct device *, struct cfdata *, void *));
     95       1.13   thorpej void	hpibbusattach __P((struct device *, struct device *, void *));
     96       1.13   thorpej 
     97  1.19.28.2  jdolecek CFATTACH_DECL(hpibbus, sizeof(struct hpibbus_softc),
     98  1.19.28.2  jdolecek     hpibbusmatch, hpibbusattach, NULL, NULL);
     99        1.1       cgd 
    100       1.19   thorpej extern struct cfdriver hpibbus_cd;
    101        1.6   thorpej 
    102       1.13   thorpej void	hpibbus_attach_children __P((struct hpibbus_softc *));
    103       1.13   thorpej int	hpibbussearch __P((struct device *, struct cfdata *, void *));
    104       1.13   thorpej int	hpibbusprint __P((void *, const char *));
    105       1.13   thorpej 
    106       1.13   thorpej int	hpibbus_alloc __P((struct hpibbus_softc *, int, int));
    107       1.13   thorpej void	hpibbus_free __P((struct hpibbus_softc *, int, int));
    108       1.13   thorpej 
    109       1.13   thorpej void	hpibstart __P((void *));
    110       1.13   thorpej void	hpibdone __P((void *));
    111        1.1       cgd 
    112        1.1       cgd int	hpibtimeout = 100000;	/* # of status tests before we give up */
    113        1.3   mycroft int	hpibidtimeout = 10000;	/* # of status tests for hpibid() calls */
    114        1.1       cgd int	hpibdmathresh = 3;	/* byte count beyond which to attempt dma */
    115        1.1       cgd 
    116       1.13   thorpej /*
    117       1.13   thorpej  * HP-IB is essentially an IEEE 488 bus, with an HP command
    118       1.13   thorpej  * set (CS/80 on `newer' devices, Amigo on before-you-were-born
    119       1.13   thorpej  * devices) thrown on top.  Devices that respond to CS/80 (and
    120       1.13   thorpej  * probably Amigo, too) are tagged with a 16-bit ID.
    121       1.13   thorpej  *
    122       1.13   thorpej  * HP-IB has a 2-level addressing scheme; slave, the analog
    123       1.13   thorpej  * of a SCSI ID, and punit, the analog of a SCSI LUN.  Unforunately,
    124       1.13   thorpej  * IDs are on a per-slave basis; punits are often used for disk
    125       1.13   thorpej  * drives that have an accompanying tape drive on the second punit.
    126       1.13   thorpej  *
    127       1.13   thorpej  * In addition, not all HP-IB devices speak CS/80 or Amigo.
    128       1.13   thorpej  * Examples of such devices are HP-IB plotters, which simply
    129       1.13   thorpej  * take raw plotter commands over 488.  These devices do not
    130       1.13   thorpej  * have ID tags, and often the host cannot even tell if such
    131       1.13   thorpej  * a device is attached to the system!
    132       1.13   thorpej  *
    133       1.13   thorpej  * These two nasty bits mean that we have to treat HP-IB as
    134       1.13   thorpej  * an indirect bus.  However, since we are given some ID
    135       1.13   thorpej  * information, it is unreasonable to disallow cloning of
    136       1.13   thorpej  * CS/80 devices.
    137       1.13   thorpej  *
    138       1.13   thorpej  * To deal with all of this, we use the semi-twisted scheme
    139       1.13   thorpej  * in hpibbus_attach_children().  For each HP-IB slave, we loop
    140       1.13   thorpej  * through all of the possibly-configured children, allowing
    141       1.13   thorpej  * them to modify the punit parameter (but NOT the slave!).
    142       1.13   thorpej  *
    143       1.13   thorpej  * This is evil, but what can you do?
    144       1.13   thorpej  */
    145       1.13   thorpej 
    146        1.6   thorpej int
    147       1.13   thorpej hpibbusmatch(parent, match, aux)
    148       1.13   thorpej 	struct device *parent;
    149       1.13   thorpej 	struct cfdata *match;
    150       1.13   thorpej 	void *aux;
    151        1.1       cgd {
    152        1.7   thorpej 
    153       1.13   thorpej 	return (1);
    154       1.13   thorpej }
    155       1.13   thorpej 
    156       1.13   thorpej void
    157       1.13   thorpej hpibbusattach(parent, self, aux)
    158       1.13   thorpej 	struct device *parent, *self;
    159       1.13   thorpej 	void *aux;
    160       1.13   thorpej {
    161       1.13   thorpej 	struct hpibbus_softc *sc = (struct hpibbus_softc *)self;
    162       1.13   thorpej 	struct hpibdev_attach_args *ha = aux;
    163       1.13   thorpej 
    164       1.13   thorpej 	printf("\n");
    165       1.13   thorpej 
    166       1.13   thorpej 	/* Get the operations vector for the controller. */
    167       1.13   thorpej 	sc->sc_ops = ha->ha_ops;
    168       1.13   thorpej 	sc->sc_type = ha->ha_type;		/* XXX */
    169       1.13   thorpej 	sc->sc_ba = ha->ha_ba;
    170       1.13   thorpej 	*(ha->ha_softcpp) = sc;			/* XXX */
    171       1.13   thorpej 
    172       1.13   thorpej 	hpibreset(self->dv_unit);		/* XXX souldn't be here */
    173       1.13   thorpej 
    174       1.13   thorpej 	/*
    175       1.13   thorpej 	 * Initialize the DMA queue entry.
    176       1.13   thorpej 	 */
    177  1.19.28.1  jdolecek 	MALLOC(sc->sc_dq, struct dmaqueue *, sizeof(struct dmaqueue),
    178       1.13   thorpej 	    M_DEVBUF, M_NOWAIT);
    179       1.13   thorpej 	if (sc->sc_dq == NULL) {
    180       1.13   thorpej 		printf("%s: can't allocate DMA queue entry\n", self->dv_xname);
    181       1.13   thorpej 		return;
    182        1.7   thorpej 	}
    183       1.13   thorpej 	sc->sc_dq->dq_softc = sc;
    184       1.13   thorpej 	sc->sc_dq->dq_start = hpibstart;
    185       1.13   thorpej 	sc->sc_dq->dq_done = hpibdone;
    186        1.7   thorpej 
    187       1.13   thorpej 	/* Initialize the slave request queue. */
    188       1.13   thorpej 	TAILQ_INIT(&sc->sc_queue);
    189       1.13   thorpej 
    190       1.13   thorpej 	/* Attach any devices on the bus. */
    191       1.13   thorpej 	hpibbus_attach_children(sc);
    192        1.7   thorpej }
    193        1.7   thorpej 
    194        1.7   thorpej void
    195       1.13   thorpej hpibbus_attach_children(sc)
    196       1.13   thorpej 	struct hpibbus_softc *sc;
    197        1.7   thorpej {
    198       1.13   thorpej 	struct hpibbus_attach_args ha;
    199       1.13   thorpej 	int slave;
    200        1.7   thorpej 
    201       1.13   thorpej 	for (slave = 0; slave < 8; slave++) {
    202       1.13   thorpej 		/*
    203       1.13   thorpej 		 * Get the ID tag for the device, if any.
    204       1.13   thorpej 		 * Plotters won't identify themselves, and
    205       1.13   thorpej 		 * get the same value as non-existent devices.
    206       1.13   thorpej 		 */
    207       1.13   thorpej 		ha.ha_id = hpibid(sc->sc_dev.dv_unit, slave);
    208       1.13   thorpej 
    209       1.13   thorpej 		ha.ha_slave = slave;	/* not to be modified by children */
    210       1.13   thorpej 		ha.ha_punit = 0;	/* children modify this */
    211       1.13   thorpej 
    212       1.13   thorpej 		/*
    213       1.13   thorpej 		 * Search though all configured children for this bus.
    214       1.13   thorpej 		 */
    215       1.13   thorpej 		(void)config_search(hpibbussearch, &sc->sc_dev, &ha);
    216       1.13   thorpej 	}
    217       1.13   thorpej }
    218       1.13   thorpej 
    219       1.13   thorpej int
    220       1.13   thorpej hpibbussearch(parent, cf, aux)
    221       1.13   thorpej 	struct device *parent;
    222       1.13   thorpej 	struct cfdata *cf;
    223       1.13   thorpej 	void *aux;
    224       1.13   thorpej {
    225       1.13   thorpej 	struct hpibbus_softc *sc = (struct hpibbus_softc *)parent;
    226       1.13   thorpej 	struct hpibbus_attach_args *ha = aux;
    227       1.13   thorpej 
    228       1.13   thorpej 	/* Make sure this is in a consistent state. */
    229       1.13   thorpej 	ha->ha_punit = 0;
    230       1.13   thorpej 
    231  1.19.28.2  jdolecek 	if (config_match(parent, cf, ha) > 0) {
    232       1.13   thorpej 		/*
    233       1.13   thorpej 		 * The device probe has succeeded, and filled in
    234       1.13   thorpej 		 * the punit information.  Make sure the configuration
    235       1.13   thorpej 		 * allows for this slave/punit combination.
    236       1.13   thorpej 		 */
    237       1.17       jtk 		if (cf->hpibbuscf_slave != HPIBBUSCF_SLAVE_DEFAULT &&
    238       1.13   thorpej 		    cf->hpibbuscf_slave != ha->ha_slave)
    239       1.13   thorpej 			goto out;
    240       1.17       jtk 		if (cf->hpibbuscf_punit != HPIBBUSCF_PUNIT_DEFAULT &&
    241       1.13   thorpej 		    cf->hpibbuscf_punit != ha->ha_punit)
    242       1.13   thorpej 			goto out;
    243       1.13   thorpej 
    244       1.13   thorpej 		/*
    245       1.13   thorpej 		 * Allocate the device's address from the bus's
    246       1.13   thorpej 		 * resource map.
    247       1.13   thorpej 		 */
    248       1.13   thorpej 		if (hpibbus_alloc(sc, ha->ha_slave, ha->ha_punit))
    249       1.13   thorpej 			goto out;
    250       1.13   thorpej 
    251       1.13   thorpej 		/*
    252       1.13   thorpej 		 * This device is allowed; attach it.
    253       1.13   thorpej 		 */
    254       1.13   thorpej 		config_attach(parent, cf, ha, hpibbusprint);
    255        1.7   thorpej 	}
    256       1.13   thorpej  out:
    257       1.13   thorpej 	return (0);
    258       1.13   thorpej }
    259       1.13   thorpej 
    260       1.13   thorpej int
    261       1.13   thorpej hpibbusprint(aux, pnp)
    262       1.13   thorpej 	void *aux;
    263       1.13   thorpej 	const char *pnp;
    264       1.13   thorpej {
    265       1.13   thorpej 	struct hpibbus_attach_args *ha = aux;
    266        1.6   thorpej 
    267       1.13   thorpej 	printf(" slave %d punit %d", ha->ha_slave, ha->ha_punit);
    268       1.13   thorpej 	return (UNCONF);
    269       1.13   thorpej }
    270       1.13   thorpej 
    271       1.13   thorpej int
    272       1.13   thorpej hpibdevprint(aux, pnp)
    273       1.13   thorpej 	void *aux;
    274       1.13   thorpej 	const char *pnp;
    275       1.13   thorpej {
    276       1.13   thorpej 
    277       1.13   thorpej 	/* only hpibbus's can attach to hpibdev's -- easy. */
    278       1.13   thorpej 	if (pnp != NULL)
    279       1.13   thorpej 		printf("hpibbus at %s", pnp);
    280       1.13   thorpej 	return (UNCONF);
    281        1.1       cgd }
    282        1.1       cgd 
    283        1.6   thorpej void
    284        1.1       cgd hpibreset(unit)
    285       1.14    scottr 	int unit;
    286        1.1       cgd {
    287       1.13   thorpej 	struct hpibbus_softc *sc = hpibbus_cd.cd_devs[unit];
    288        1.6   thorpej 
    289       1.13   thorpej 	(*sc->sc_ops->hpib_reset)(sc);
    290        1.1       cgd }
    291        1.1       cgd 
    292        1.6   thorpej int
    293       1.13   thorpej hpibreq(pdev, hq)
    294       1.13   thorpej 	struct device *pdev;
    295       1.13   thorpej 	struct hpibqueue *hq;
    296       1.13   thorpej {
    297       1.13   thorpej 	struct hpibbus_softc *sc = (struct hpibbus_softc *)pdev;
    298       1.13   thorpej 	int s;
    299       1.13   thorpej 
    300       1.13   thorpej 	s = splhigh();	/* XXXthorpej */
    301       1.13   thorpej 	TAILQ_INSERT_TAIL(&sc->sc_queue, hq, hq_list);
    302       1.13   thorpej 	splx(s);
    303       1.13   thorpej 
    304       1.13   thorpej 	if (sc->sc_queue.tqh_first == hq)
    305       1.13   thorpej 		return (1);
    306        1.1       cgd 
    307       1.13   thorpej 	return (0);
    308        1.1       cgd }
    309        1.1       cgd 
    310        1.6   thorpej void
    311       1.13   thorpej hpibfree(pdev, hq)
    312       1.13   thorpej 	struct device *pdev;
    313       1.13   thorpej 	struct hpibqueue *hq;
    314       1.13   thorpej {
    315       1.13   thorpej 	struct hpibbus_softc *sc = (struct hpibbus_softc *)pdev;
    316       1.13   thorpej 	int s;
    317       1.13   thorpej 
    318       1.13   thorpej 	s = splhigh();	/* XXXthorpej */
    319       1.13   thorpej 	TAILQ_REMOVE(&sc->sc_queue, hq, hq_list);
    320       1.13   thorpej 	splx(s);
    321        1.1       cgd 
    322       1.13   thorpej 	if ((hq = sc->sc_queue.tqh_first) != NULL)
    323       1.13   thorpej 		(*hq->hq_start)(hq->hq_softc);
    324        1.1       cgd }
    325        1.1       cgd 
    326        1.6   thorpej int
    327        1.1       cgd hpibid(unit, slave)
    328        1.3   mycroft 	int unit, slave;
    329        1.1       cgd {
    330        1.1       cgd 	short id;
    331        1.1       cgd 	int ohpibtimeout;
    332        1.1       cgd 
    333        1.1       cgd 	/*
    334        1.3   mycroft 	 * XXX shorten timeout value so autoconfig doesn't
    335        1.3   mycroft 	 * take forever on slow CPUs.
    336        1.1       cgd 	 */
    337        1.1       cgd 	ohpibtimeout = hpibtimeout;
    338        1.9   thorpej 	hpibtimeout = hpibidtimeout * (cpuspeed / 8);
    339        1.1       cgd 	if (hpibrecv(unit, 31, slave, &id, 2) != 2)
    340        1.1       cgd 		id = 0;
    341        1.1       cgd 	hpibtimeout = ohpibtimeout;
    342        1.1       cgd 	return(id);
    343        1.1       cgd }
    344        1.1       cgd 
    345        1.6   thorpej int
    346        1.1       cgd hpibsend(unit, slave, sec, addr, cnt)
    347        1.6   thorpej 	int unit, slave, sec, cnt;
    348        1.6   thorpej 	void *addr;
    349        1.1       cgd {
    350       1.13   thorpej 	struct hpibbus_softc *sc = hpibbus_cd.cd_devs[unit];
    351        1.6   thorpej 
    352       1.13   thorpej 	return ((*sc->sc_ops->hpib_send)(sc, slave, sec, addr, cnt));
    353        1.1       cgd }
    354        1.1       cgd 
    355        1.6   thorpej int
    356        1.1       cgd hpibrecv(unit, slave, sec, addr, cnt)
    357        1.6   thorpej 	int unit, slave, sec, cnt;
    358        1.6   thorpej 	void *addr;
    359        1.1       cgd {
    360       1.13   thorpej 	struct hpibbus_softc *sc = hpibbus_cd.cd_devs[unit];
    361        1.6   thorpej 
    362       1.13   thorpej 	return ((*sc->sc_ops->hpib_recv)(sc, slave, sec, addr, cnt));
    363        1.1       cgd }
    364        1.1       cgd 
    365        1.6   thorpej int
    366        1.1       cgd hpibpptest(unit, slave)
    367       1.14    scottr 	int unit;
    368        1.3   mycroft 	int slave;
    369        1.1       cgd {
    370       1.13   thorpej 	struct hpibbus_softc *sc = hpibbus_cd.cd_devs[unit];
    371        1.1       cgd 
    372       1.13   thorpej 	return ((*sc->sc_ops->hpib_ppoll)(sc) & (0x80 >> slave));
    373        1.1       cgd }
    374        1.1       cgd 
    375        1.6   thorpej void
    376        1.5   mycroft hpibppclear(unit)
    377        1.5   mycroft 	int unit;
    378        1.5   mycroft {
    379       1.13   thorpej 	struct hpibbus_softc *sc = hpibbus_cd.cd_devs[unit];
    380       1.13   thorpej 
    381       1.13   thorpej 	sc->sc_flags &= ~HPIBF_PPOLL;
    382        1.5   mycroft }
    383        1.5   mycroft 
    384       1.14    scottr void
    385        1.1       cgd hpibawait(unit)
    386        1.3   mycroft 	int unit;
    387        1.1       cgd {
    388       1.13   thorpej 	struct hpibbus_softc *sc = hpibbus_cd.cd_devs[unit];
    389        1.1       cgd 
    390       1.13   thorpej 	sc->sc_flags |= HPIBF_PPOLL;
    391       1.13   thorpej 	(*sc->sc_ops->hpib_ppwatch)(sc);
    392        1.1       cgd }
    393        1.1       cgd 
    394        1.6   thorpej int
    395        1.1       cgd hpibswait(unit, slave)
    396       1.14    scottr 	int unit;
    397        1.3   mycroft 	int slave;
    398        1.1       cgd {
    399       1.13   thorpej 	struct hpibbus_softc *sc = hpibbus_cd.cd_devs[unit];
    400       1.14    scottr 	int timo = hpibtimeout;
    401       1.14    scottr 	int mask, (*ppoll) __P((struct hpibbus_softc *));
    402        1.1       cgd 
    403       1.13   thorpej 	ppoll = sc->sc_ops->hpib_ppoll;
    404        1.1       cgd 	mask = 0x80 >> slave;
    405       1.13   thorpej 	while (((*ppoll)(sc) & mask) == 0) {
    406        1.1       cgd 		if (--timo == 0) {
    407       1.13   thorpej 			printf("%s: swait timeout\n", sc->sc_dev.dv_xname);
    408        1.1       cgd 			return(-1);
    409        1.1       cgd 		}
    410       1.13   thorpej 	}
    411        1.1       cgd 	return(0);
    412        1.1       cgd }
    413        1.1       cgd 
    414        1.6   thorpej int
    415        1.1       cgd hpibustart(unit)
    416        1.3   mycroft 	int unit;
    417        1.1       cgd {
    418       1.13   thorpej 	struct hpibbus_softc *sc = hpibbus_cd.cd_devs[unit];
    419        1.1       cgd 
    420       1.13   thorpej 	if (sc->sc_type == HPIBA)
    421       1.13   thorpej 		sc->sc_dq->dq_chan = DMA0;
    422        1.1       cgd 	else
    423       1.13   thorpej 		sc->sc_dq->dq_chan = DMA0 | DMA1;
    424       1.13   thorpej 	if (dmareq(sc->sc_dq))
    425        1.1       cgd 		return(1);
    426        1.1       cgd 	return(0);
    427        1.1       cgd }
    428        1.1       cgd 
    429        1.6   thorpej void
    430       1.13   thorpej hpibstart(arg)
    431       1.13   thorpej 	void *arg;
    432        1.1       cgd {
    433       1.13   thorpej 	struct hpibbus_softc *sc = arg;
    434       1.14    scottr 	struct hpibqueue *hq;
    435       1.13   thorpej 
    436       1.13   thorpej 	hq = sc->sc_queue.tqh_first;
    437       1.13   thorpej 	(*hq->hq_go)(hq->hq_softc);
    438        1.1       cgd }
    439        1.1       cgd 
    440        1.6   thorpej void
    441       1.13   thorpej hpibgo(unit, slave, sec, vbuf, count, rw, timo)
    442       1.13   thorpej 	int unit, slave, sec;
    443       1.13   thorpej 	void *vbuf;
    444       1.13   thorpej 	int count, rw, timo;
    445        1.1       cgd {
    446       1.13   thorpej 	struct hpibbus_softc *sc = hpibbus_cd.cd_devs[unit];
    447        1.6   thorpej 
    448       1.13   thorpej 	(*sc->sc_ops->hpib_go)(sc, slave, sec, vbuf, count, rw, timo);
    449        1.1       cgd }
    450        1.1       cgd 
    451        1.6   thorpej void
    452       1.13   thorpej hpibdone(arg)
    453       1.13   thorpej 	void *arg;
    454        1.1       cgd {
    455       1.13   thorpej 	struct hpibbus_softc *sc = arg;
    456        1.6   thorpej 
    457       1.13   thorpej 	(*sc->sc_ops->hpib_done)(sc);
    458        1.1       cgd }
    459        1.1       cgd 
    460        1.6   thorpej int
    461        1.8   thorpej hpibintr(arg)
    462        1.8   thorpej 	void *arg;
    463        1.1       cgd {
    464       1.13   thorpej 	struct hpibbus_softc *sc = arg;
    465       1.13   thorpej 
    466       1.13   thorpej 	return ((sc->sc_ops->hpib_intr)(arg));
    467       1.13   thorpej }
    468       1.13   thorpej 
    469       1.13   thorpej int
    470       1.13   thorpej hpibbus_alloc(sc, slave, punit)
    471       1.13   thorpej 	struct hpibbus_softc *sc;
    472       1.13   thorpej 	int slave, punit;
    473       1.13   thorpej {
    474       1.13   thorpej 
    475       1.13   thorpej 	if (slave >= HPIB_NSLAVES ||
    476       1.13   thorpej 	    punit >= HPIB_NPUNITS)
    477       1.13   thorpej 		panic("hpibbus_alloc: device address out of range");
    478       1.13   thorpej 
    479       1.13   thorpej 	if (sc->sc_rmap[slave][punit] == 0) {
    480       1.13   thorpej 		sc->sc_rmap[slave][punit] = 1;
    481       1.13   thorpej 		return (0);
    482       1.13   thorpej 	}
    483       1.13   thorpej 	return (1);
    484       1.13   thorpej }
    485       1.13   thorpej 
    486       1.13   thorpej void
    487       1.13   thorpej hpibbus_free(sc, slave, punit)
    488       1.13   thorpej 	struct hpibbus_softc *sc;
    489       1.13   thorpej 	int slave, punit;
    490       1.13   thorpej {
    491       1.13   thorpej 
    492       1.13   thorpej 	if (slave >= HPIB_NSLAVES ||
    493       1.13   thorpej 	    punit >= HPIB_NPUNITS)
    494       1.13   thorpej 		panic("hpibbus_free: device address out of range");
    495       1.13   thorpej 
    496       1.13   thorpej #ifdef DIAGNOSTIC
    497       1.13   thorpej 	if (sc->sc_rmap[slave][punit] == 0)
    498       1.13   thorpej 		panic("hpibbus_free: not allocated");
    499       1.13   thorpej #endif
    500        1.1       cgd 
    501       1.13   thorpej 	sc->sc_rmap[slave][punit] = 0;
    502        1.1       cgd }
    503