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