1 /* 2 * Copyright (c) 1982, 1990, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * %sccs.include.redist.c% 6 * 7 * @(#)hpib.c 8.1 (Berkeley) 06/10/93 8 */ 9 10 /* 11 * HPIB driver 12 */ 13 #include "hpib.h" 14 #if NHPIB > 0 15 16 #include <sys/param.h> 17 #include <sys/systm.h> 18 #include <sys/buf.h> 19 20 #include <hp/dev/device.h> 21 #include <hp300/dev/hpibvar.h> 22 #include <hp300/dev/dmavar.h> 23 24 #include <machine/cpu.h> 25 #include <hp300/hp300/isr.h> 26 27 int hpibinit(), hpibstart(), hpibgo(), hpibintr(), hpibdone(); 28 struct driver hpibdriver = { 29 hpibinit, "hpib", hpibstart, hpibgo, hpibintr, hpibdone, 30 }; 31 32 struct hpib_softc hpib_softc[NHPIB]; 33 struct isr hpib_isr[NHPIB]; 34 int nhpibppoll(), fhpibppoll(); 35 36 int hpibtimeout = 100000; /* # of status tests before we give up */ 37 int hpibidtimeout = 10000; /* # of status tests for hpibid() calls */ 38 int hpibdmathresh = 3; /* byte count beyond which to attempt dma */ 39 40 hpibinit(hc) 41 register struct hp_ctlr *hc; 42 { 43 register struct hpib_softc *hs = &hpib_softc[hc->hp_unit]; 44 45 if (!nhpibtype(hc) && !fhpibtype(hc)) 46 return(0); 47 hs->sc_hc = hc; 48 hs->sc_dq.dq_unit = hc->hp_unit; 49 hs->sc_dq.dq_driver = &hpibdriver; 50 hs->sc_sq.dq_forw = hs->sc_sq.dq_back = &hs->sc_sq; 51 hpib_isr[hc->hp_unit].isr_intr = hpibintr; 52 hpib_isr[hc->hp_unit].isr_ipl = hc->hp_ipl; 53 hpib_isr[hc->hp_unit].isr_arg = hc->hp_unit; 54 isrlink(&hpib_isr[hc->hp_unit]); 55 hpibreset(hc->hp_unit); 56 return(1); 57 } 58 59 hpibreset(unit) 60 register int unit; 61 { 62 if (hpib_softc[unit].sc_type == HPIBC) 63 fhpibreset(unit); 64 else 65 nhpibreset(unit); 66 } 67 68 hpibreq(dq) 69 register struct devqueue *dq; 70 { 71 register struct devqueue *hq; 72 73 hq = &hpib_softc[dq->dq_ctlr].sc_sq; 74 insque(dq, hq->dq_back); 75 if (dq->dq_back == hq) 76 return(1); 77 return(0); 78 } 79 80 hpibfree(dq) 81 register struct devqueue *dq; 82 { 83 register struct devqueue *hq; 84 85 hq = &hpib_softc[dq->dq_ctlr].sc_sq; 86 remque(dq); 87 if ((dq = hq->dq_forw) != hq) 88 (dq->dq_driver->d_start)(dq->dq_unit); 89 } 90 91 hpibid(unit, slave) 92 { 93 short id; 94 int ohpibtimeout; 95 96 /* 97 * XXX shorten timeout value so autoconfig doesn't 98 * take forever on slow CPUs. 99 */ 100 ohpibtimeout = hpibtimeout; 101 hpibtimeout = hpibidtimeout * cpuspeed; 102 if (hpibrecv(unit, 31, slave, &id, 2) != 2) 103 id = 0; 104 hpibtimeout = ohpibtimeout; 105 return(id); 106 } 107 108 hpibsend(unit, slave, sec, addr, cnt) 109 register int unit; 110 { 111 if (hpib_softc[unit].sc_type == HPIBC) 112 return(fhpibsend(unit, slave, sec, addr, cnt)); 113 else 114 return(nhpibsend(unit, slave, sec, addr, cnt)); 115 } 116 117 hpibrecv(unit, slave, sec, addr, cnt) 118 register int unit; 119 { 120 if (hpib_softc[unit].sc_type == HPIBC) 121 return(fhpibrecv(unit, slave, sec, addr, cnt)); 122 else 123 return(nhpibrecv(unit, slave, sec, addr, cnt)); 124 } 125 126 hpibpptest(unit, slave) 127 register int unit; 128 { 129 int (*ppoll)(); 130 131 ppoll = (hpib_softc[unit].sc_type == HPIBC) ? fhpibppoll : nhpibppoll; 132 return((*ppoll)(unit) & (0x80 >> slave)); 133 } 134 135 hpibawait(unit) 136 int unit; 137 { 138 register struct hpib_softc *hs = &hpib_softc[unit]; 139 140 hs->sc_flags |= HPIBF_PPOLL; 141 if (hs->sc_type == HPIBC) 142 fhpibppwatch((void *)unit); 143 else 144 nhpibppwatch((void *)unit); 145 } 146 147 hpibswait(unit, slave) 148 register int unit; 149 { 150 register int timo = hpibtimeout; 151 register int mask, (*ppoll)(); 152 153 ppoll = (hpib_softc[unit].sc_type == HPIBC) ? fhpibppoll : nhpibppoll; 154 mask = 0x80 >> slave; 155 while (((ppoll)(unit) & mask) == 0) 156 if (--timo == 0) { 157 printf("hpib%d: swait timeout\n", unit); 158 return(-1); 159 } 160 return(0); 161 } 162 163 hpibustart(unit) 164 { 165 register struct hpib_softc *hs = &hpib_softc[unit]; 166 167 if (hs->sc_type == HPIBA) 168 hs->sc_dq.dq_ctlr = DMA0; 169 else 170 hs->sc_dq.dq_ctlr = DMA0 | DMA1; 171 if (dmareq(&hs->sc_dq)) 172 return(1); 173 return(0); 174 } 175 176 hpibstart(unit) 177 { 178 register struct devqueue *dq; 179 180 dq = hpib_softc[unit].sc_sq.dq_forw; 181 (dq->dq_driver->d_go)(dq->dq_unit); 182 } 183 184 hpibgo(unit, slave, sec, addr, count, rw) 185 register int unit; 186 { 187 if (hpib_softc[unit].sc_type == HPIBC) 188 fhpibgo(unit, slave, sec, addr, count, rw); 189 else 190 nhpibgo(unit, slave, sec, addr, count, rw); 191 } 192 193 hpibdone(unit) 194 register int unit; 195 { 196 if (hpib_softc[unit].sc_type == HPIBC) 197 fhpibdone(unit); 198 else 199 nhpibdone(unit); 200 } 201 202 hpibintr(unit) 203 register int unit; 204 { 205 int found; 206 207 if (hpib_softc[unit].sc_type == HPIBC) 208 found = fhpibintr(unit); 209 else 210 found = nhpibintr(unit); 211 return(found); 212 } 213 #endif 214