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