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.7 (Berkeley) 09/21/92 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 "hp/dev/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 = 10000; /* # 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 97 * take forever on slow CPUs. 98 */ 99 ohpibtimeout = hpibtimeout; 100 hpibtimeout = hpibidtimeout * cpuspeed; 101 if (hpibrecv(unit, 31, slave, &id, 2) != 2) 102 id = 0; 103 hpibtimeout = ohpibtimeout; 104 return(id); 105 } 106 107 hpibsend(unit, slave, sec, addr, cnt) 108 register int unit; 109 { 110 if (hpib_softc[unit].sc_type == HPIBC) 111 return(fhpibsend(unit, slave, sec, addr, cnt)); 112 else 113 return(nhpibsend(unit, slave, sec, addr, cnt)); 114 } 115 116 hpibrecv(unit, slave, sec, addr, cnt) 117 register int unit; 118 { 119 if (hpib_softc[unit].sc_type == HPIBC) 120 return(fhpibrecv(unit, slave, sec, addr, cnt)); 121 else 122 return(nhpibrecv(unit, slave, sec, addr, cnt)); 123 } 124 125 hpibpptest(unit, slave) 126 register int unit; 127 { 128 int (*ppoll)(); 129 130 ppoll = (hpib_softc[unit].sc_type == HPIBC) ? fhpibppoll : nhpibppoll; 131 return((*ppoll)(unit) & (0x80 >> slave)); 132 } 133 134 hpibawait(unit) 135 int unit; 136 { 137 register struct hpib_softc *hs = &hpib_softc[unit]; 138 139 hs->sc_flags |= HPIBF_PPOLL; 140 if (hs->sc_type == HPIBC) 141 fhpibppwatch((void *)unit); 142 else 143 nhpibppwatch((void *)unit); 144 } 145 146 hpibswait(unit, slave) 147 register int unit; 148 { 149 register int timo = hpibtimeout; 150 register int mask, (*ppoll)(); 151 152 ppoll = (hpib_softc[unit].sc_type == HPIBC) ? fhpibppoll : nhpibppoll; 153 mask = 0x80 >> slave; 154 while (((ppoll)(unit) & mask) == 0) 155 if (--timo == 0) { 156 printf("hpib%d: swait timeout\n", unit); 157 return(-1); 158 } 159 return(0); 160 } 161 162 hpibustart(unit) 163 { 164 register struct hpib_softc *hs = &hpib_softc[unit]; 165 166 if (hs->sc_type == HPIBA) 167 hs->sc_dq.dq_ctlr = DMA0; 168 else 169 hs->sc_dq.dq_ctlr = DMA0 | DMA1; 170 if (dmareq(&hs->sc_dq)) 171 return(1); 172 return(0); 173 } 174 175 hpibstart(unit) 176 { 177 register struct devqueue *dq; 178 179 dq = hpib_softc[unit].sc_sq.dq_forw; 180 (dq->dq_driver->d_go)(dq->dq_unit); 181 } 182 183 hpibgo(unit, slave, sec, addr, count, rw) 184 register int unit; 185 { 186 if (hpib_softc[unit].sc_type == HPIBC) 187 fhpibgo(unit, slave, sec, addr, count, rw); 188 else 189 nhpibgo(unit, slave, sec, addr, count, rw); 190 } 191 192 hpibdone(unit) 193 register int unit; 194 { 195 if (hpib_softc[unit].sc_type == HPIBC) 196 fhpibdone(unit); 197 else 198 nhpibdone(unit); 199 } 200 201 hpibintr(unit) 202 register int unit; 203 { 204 int found; 205 206 if (hpib_softc[unit].sc_type == HPIBC) 207 found = fhpibintr(unit); 208 else 209 found = nhpibintr(unit); 210 return(found); 211 } 212 #endif 213