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