Home | History | Annotate | Line # | Download | only in dev
hpib.c revision 1.1.1.1
      1 /*
      2  * Copyright (c) 1982, 1990 The Regents of the University of California.
      3  * All rights reserved.
      4  *
      5  * Redistribution and use in source and binary forms, with or without
      6  * modification, are permitted provided that the following conditions
      7  * are met:
      8  * 1. Redistributions of source code must retain the above copyright
      9  *    notice, this list of conditions and the following disclaimer.
     10  * 2. Redistributions in binary form must reproduce the above copyright
     11  *    notice, this list of conditions and the following disclaimer in the
     12  *    documentation and/or other materials provided with the distribution.
     13  * 3. All advertising materials mentioning features or use of this software
     14  *    must display the following acknowledgement:
     15  *	This product includes software developed by the University of
     16  *	California, Berkeley and its contributors.
     17  * 4. 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	7.3 (Berkeley) 12/16/90
     34  */
     35 
     36 /*
     37  * HPIB driver
     38  */
     39 #include "hpib.h"
     40 #if NHPIB > 0
     41 
     42 #include "sys/param.h"
     43 #include "sys/systm.h"
     44 #include "sys/buf.h"
     45 #include "device.h"
     46 #include "hpibvar.h"
     47 #include "dmavar.h"
     48 
     49 #include "../include/cpu.h"
     50 #include "../hp300/isr.h"
     51 
     52 int	hpibinit(), hpibstart(), hpibgo(), hpibintr(), hpibdone();
     53 struct	driver hpibdriver = {
     54 	hpibinit, "hpib", hpibstart, hpibgo, hpibintr, hpibdone,
     55 };
     56 
     57 struct	hpib_softc hpib_softc[NHPIB];
     58 struct	isr hpib_isr[NHPIB];
     59 int	nhpibppoll(), fhpibppoll();
     60 
     61 int	hpibtimeout = 100000;	/* # of status tests before we give up */
     62 int	hpibidtimeout = 20000;	/* # of status tests for hpibid() calls */
     63 int	hpibdmathresh = 3;	/* byte count beyond which to attempt dma */
     64 
     65 hpibinit(hc)
     66 	register struct hp_ctlr *hc;
     67 {
     68 	register struct hpib_softc *hs = &hpib_softc[hc->hp_unit];
     69 
     70 	if (!nhpibtype(hc) && !fhpibtype(hc))
     71 		return(0);
     72 	hs->sc_hc = hc;
     73 	hs->sc_dq.dq_unit = hc->hp_unit;
     74 	hs->sc_dq.dq_driver = &hpibdriver;
     75 	hs->sc_sq.dq_forw = hs->sc_sq.dq_back = &hs->sc_sq;
     76 	hpib_isr[hc->hp_unit].isr_intr = hpibintr;
     77 	hpib_isr[hc->hp_unit].isr_ipl = hc->hp_ipl;
     78 	hpib_isr[hc->hp_unit].isr_arg = hc->hp_unit;
     79 	isrlink(&hpib_isr[hc->hp_unit]);
     80 	hpibreset(hc->hp_unit);
     81 	return(1);
     82 }
     83 
     84 hpibreset(unit)
     85 	register int unit;
     86 {
     87 	if (hpib_softc[unit].sc_type == HPIBC)
     88 		fhpibreset(unit);
     89 	else
     90 		nhpibreset(unit);
     91 }
     92 
     93 hpibreq(dq)
     94 	register struct devqueue *dq;
     95 {
     96 	register struct devqueue *hq;
     97 
     98 	hq = &hpib_softc[dq->dq_ctlr].sc_sq;
     99 	insque(dq, hq->dq_back);
    100 	if (dq->dq_back == hq)
    101 		return(1);
    102 	return(0);
    103 }
    104 
    105 hpibfree(dq)
    106 	register struct devqueue *dq;
    107 {
    108 	register struct devqueue *hq;
    109 
    110 	hq = &hpib_softc[dq->dq_ctlr].sc_sq;
    111 	remque(dq);
    112 	if ((dq = hq->dq_forw) != hq)
    113 		(dq->dq_driver->d_start)(dq->dq_unit);
    114 }
    115 
    116 hpibid(unit, slave)
    117 {
    118 	short id;
    119 	int ohpibtimeout;
    120 
    121 	/*
    122 	 * XXX: shorten timeout value (so autoconfig doesn't take forever)
    123 	 */
    124 	ohpibtimeout = hpibtimeout;
    125 	hpibtimeout = hpibidtimeout;
    126 	if (hpibrecv(unit, 31, slave, &id, 2) != 2)
    127 		id = 0;
    128 	hpibtimeout = ohpibtimeout;
    129 	return(id);
    130 }
    131 
    132 hpibsend(unit, slave, sec, addr, cnt)
    133 	register int unit;
    134 {
    135 	if (hpib_softc[unit].sc_type == HPIBC)
    136 		return(fhpibsend(unit, slave, sec, addr, cnt));
    137 	else
    138 		return(nhpibsend(unit, slave, sec, addr, cnt));
    139 }
    140 
    141 hpibrecv(unit, slave, sec, addr, cnt)
    142 	register int unit;
    143 {
    144 	if (hpib_softc[unit].sc_type == HPIBC)
    145 		return(fhpibrecv(unit, slave, sec, addr, cnt));
    146 	else
    147 		return(nhpibrecv(unit, slave, sec, addr, cnt));
    148 }
    149 
    150 hpibpptest(unit, slave)
    151 	register int unit;
    152 {
    153 	int (*ppoll)();
    154 
    155 	ppoll = (hpib_softc[unit].sc_type == HPIBC) ? fhpibppoll : nhpibppoll;
    156 	return((*ppoll)(unit) & (0x80 >> slave));
    157 }
    158 
    159 hpibawait(unit)
    160 {
    161 	register struct hpib_softc *hs = &hpib_softc[unit];
    162 
    163 	hs->sc_flags |= HPIBF_PPOLL;
    164 	if (hs->sc_type == HPIBC)
    165 		fhpibppwatch(unit);
    166 	else
    167 		nhpibppwatch(unit);
    168 }
    169 
    170 hpibswait(unit, slave)
    171 	register int unit;
    172 {
    173 	register int timo = hpibtimeout;
    174 	register int mask, (*ppoll)();
    175 
    176 	ppoll = (hpib_softc[unit].sc_type == HPIBC) ? fhpibppoll : nhpibppoll;
    177 	mask = 0x80 >> slave;
    178 	while (((ppoll)(unit) & mask) == 0)
    179 		if (--timo == 0) {
    180 			printf("hpib%d: swait timeout\n", unit);
    181 			return(-1);
    182 		}
    183 	return(0);
    184 }
    185 
    186 hpibustart(unit)
    187 {
    188 	register struct hpib_softc *hs = &hpib_softc[unit];
    189 
    190 	if (hs->sc_type == HPIBA)
    191 		hs->sc_dq.dq_ctlr = DMA0;
    192 	else
    193 		hs->sc_dq.dq_ctlr = DMA0 | DMA1;
    194 	if (dmareq(&hs->sc_dq))
    195 		return(1);
    196 	return(0);
    197 }
    198 
    199 hpibstart(unit)
    200 {
    201 	register struct devqueue *dq;
    202 
    203 	dq = hpib_softc[unit].sc_sq.dq_forw;
    204 	(dq->dq_driver->d_go)(dq->dq_unit);
    205 }
    206 
    207 hpibgo(unit, slave, sec, addr, count, rw)
    208 	register int unit;
    209 {
    210 	if (hpib_softc[unit].sc_type == HPIBC)
    211 		fhpibgo(unit, slave, sec, addr, count, rw);
    212 	else
    213 		nhpibgo(unit, slave, sec, addr, count, rw);
    214 }
    215 
    216 hpibdone(unit)
    217 	register int unit;
    218 {
    219 	if (hpib_softc[unit].sc_type == HPIBC)
    220 		fhpibdone(unit);
    221 	else
    222 		nhpibdone(unit);
    223 }
    224 
    225 hpibintr(unit)
    226 	register int unit;
    227 {
    228 	int found;
    229 
    230 	if (hpib_softc[unit].sc_type == HPIBC)
    231 		found = fhpibintr(unit);
    232 	else
    233 		found = nhpibintr(unit);
    234 	return(found);
    235 }
    236 #endif
    237