hpib.c revision 1.1 1 1.1 cgd /*
2 1.1 cgd * Copyright (c) 1982, 1990 The Regents of the University of California.
3 1.1 cgd * All rights reserved.
4 1.1 cgd *
5 1.1 cgd * Redistribution and use in source and binary forms, with or without
6 1.1 cgd * modification, are permitted provided that the following conditions
7 1.1 cgd * are met:
8 1.1 cgd * 1. Redistributions of source code must retain the above copyright
9 1.1 cgd * notice, this list of conditions and the following disclaimer.
10 1.1 cgd * 2. Redistributions in binary form must reproduce the above copyright
11 1.1 cgd * notice, this list of conditions and the following disclaimer in the
12 1.1 cgd * documentation and/or other materials provided with the distribution.
13 1.1 cgd * 3. All advertising materials mentioning features or use of this software
14 1.1 cgd * must display the following acknowledgement:
15 1.1 cgd * This product includes software developed by the University of
16 1.1 cgd * California, Berkeley and its contributors.
17 1.1 cgd * 4. Neither the name of the University nor the names of its contributors
18 1.1 cgd * may be used to endorse or promote products derived from this software
19 1.1 cgd * without specific prior written permission.
20 1.1 cgd *
21 1.1 cgd * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 1.1 cgd * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 1.1 cgd * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 1.1 cgd * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 1.1 cgd * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 1.1 cgd * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 1.1 cgd * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 1.1 cgd * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 1.1 cgd * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 1.1 cgd * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 1.1 cgd * SUCH DAMAGE.
32 1.1 cgd *
33 1.1 cgd * @(#)hpib.c 7.3 (Berkeley) 12/16/90
34 1.1 cgd */
35 1.1 cgd
36 1.1 cgd /*
37 1.1 cgd * HPIB driver
38 1.1 cgd */
39 1.1 cgd #include "hpib.h"
40 1.1 cgd #if NHPIB > 0
41 1.1 cgd
42 1.1 cgd #include "sys/param.h"
43 1.1 cgd #include "sys/systm.h"
44 1.1 cgd #include "sys/buf.h"
45 1.1 cgd #include "device.h"
46 1.1 cgd #include "hpibvar.h"
47 1.1 cgd #include "dmavar.h"
48 1.1 cgd
49 1.1 cgd #include "../include/cpu.h"
50 1.1 cgd #include "../hp300/isr.h"
51 1.1 cgd
52 1.1 cgd int hpibinit(), hpibstart(), hpibgo(), hpibintr(), hpibdone();
53 1.1 cgd struct driver hpibdriver = {
54 1.1 cgd hpibinit, "hpib", hpibstart, hpibgo, hpibintr, hpibdone,
55 1.1 cgd };
56 1.1 cgd
57 1.1 cgd struct hpib_softc hpib_softc[NHPIB];
58 1.1 cgd struct isr hpib_isr[NHPIB];
59 1.1 cgd int nhpibppoll(), fhpibppoll();
60 1.1 cgd
61 1.1 cgd int hpibtimeout = 100000; /* # of status tests before we give up */
62 1.1 cgd int hpibidtimeout = 20000; /* # of status tests for hpibid() calls */
63 1.1 cgd int hpibdmathresh = 3; /* byte count beyond which to attempt dma */
64 1.1 cgd
65 1.1 cgd hpibinit(hc)
66 1.1 cgd register struct hp_ctlr *hc;
67 1.1 cgd {
68 1.1 cgd register struct hpib_softc *hs = &hpib_softc[hc->hp_unit];
69 1.1 cgd
70 1.1 cgd if (!nhpibtype(hc) && !fhpibtype(hc))
71 1.1 cgd return(0);
72 1.1 cgd hs->sc_hc = hc;
73 1.1 cgd hs->sc_dq.dq_unit = hc->hp_unit;
74 1.1 cgd hs->sc_dq.dq_driver = &hpibdriver;
75 1.1 cgd hs->sc_sq.dq_forw = hs->sc_sq.dq_back = &hs->sc_sq;
76 1.1 cgd hpib_isr[hc->hp_unit].isr_intr = hpibintr;
77 1.1 cgd hpib_isr[hc->hp_unit].isr_ipl = hc->hp_ipl;
78 1.1 cgd hpib_isr[hc->hp_unit].isr_arg = hc->hp_unit;
79 1.1 cgd isrlink(&hpib_isr[hc->hp_unit]);
80 1.1 cgd hpibreset(hc->hp_unit);
81 1.1 cgd return(1);
82 1.1 cgd }
83 1.1 cgd
84 1.1 cgd hpibreset(unit)
85 1.1 cgd register int unit;
86 1.1 cgd {
87 1.1 cgd if (hpib_softc[unit].sc_type == HPIBC)
88 1.1 cgd fhpibreset(unit);
89 1.1 cgd else
90 1.1 cgd nhpibreset(unit);
91 1.1 cgd }
92 1.1 cgd
93 1.1 cgd hpibreq(dq)
94 1.1 cgd register struct devqueue *dq;
95 1.1 cgd {
96 1.1 cgd register struct devqueue *hq;
97 1.1 cgd
98 1.1 cgd hq = &hpib_softc[dq->dq_ctlr].sc_sq;
99 1.1 cgd insque(dq, hq->dq_back);
100 1.1 cgd if (dq->dq_back == hq)
101 1.1 cgd return(1);
102 1.1 cgd return(0);
103 1.1 cgd }
104 1.1 cgd
105 1.1 cgd hpibfree(dq)
106 1.1 cgd register struct devqueue *dq;
107 1.1 cgd {
108 1.1 cgd register struct devqueue *hq;
109 1.1 cgd
110 1.1 cgd hq = &hpib_softc[dq->dq_ctlr].sc_sq;
111 1.1 cgd remque(dq);
112 1.1 cgd if ((dq = hq->dq_forw) != hq)
113 1.1 cgd (dq->dq_driver->d_start)(dq->dq_unit);
114 1.1 cgd }
115 1.1 cgd
116 1.1 cgd hpibid(unit, slave)
117 1.1 cgd {
118 1.1 cgd short id;
119 1.1 cgd int ohpibtimeout;
120 1.1 cgd
121 1.1 cgd /*
122 1.1 cgd * XXX: shorten timeout value (so autoconfig doesn't take forever)
123 1.1 cgd */
124 1.1 cgd ohpibtimeout = hpibtimeout;
125 1.1 cgd hpibtimeout = hpibidtimeout;
126 1.1 cgd if (hpibrecv(unit, 31, slave, &id, 2) != 2)
127 1.1 cgd id = 0;
128 1.1 cgd hpibtimeout = ohpibtimeout;
129 1.1 cgd return(id);
130 1.1 cgd }
131 1.1 cgd
132 1.1 cgd hpibsend(unit, slave, sec, addr, cnt)
133 1.1 cgd register int unit;
134 1.1 cgd {
135 1.1 cgd if (hpib_softc[unit].sc_type == HPIBC)
136 1.1 cgd return(fhpibsend(unit, slave, sec, addr, cnt));
137 1.1 cgd else
138 1.1 cgd return(nhpibsend(unit, slave, sec, addr, cnt));
139 1.1 cgd }
140 1.1 cgd
141 1.1 cgd hpibrecv(unit, slave, sec, addr, cnt)
142 1.1 cgd register int unit;
143 1.1 cgd {
144 1.1 cgd if (hpib_softc[unit].sc_type == HPIBC)
145 1.1 cgd return(fhpibrecv(unit, slave, sec, addr, cnt));
146 1.1 cgd else
147 1.1 cgd return(nhpibrecv(unit, slave, sec, addr, cnt));
148 1.1 cgd }
149 1.1 cgd
150 1.1 cgd hpibpptest(unit, slave)
151 1.1 cgd register int unit;
152 1.1 cgd {
153 1.1 cgd int (*ppoll)();
154 1.1 cgd
155 1.1 cgd ppoll = (hpib_softc[unit].sc_type == HPIBC) ? fhpibppoll : nhpibppoll;
156 1.1 cgd return((*ppoll)(unit) & (0x80 >> slave));
157 1.1 cgd }
158 1.1 cgd
159 1.1 cgd hpibawait(unit)
160 1.1 cgd {
161 1.1 cgd register struct hpib_softc *hs = &hpib_softc[unit];
162 1.1 cgd
163 1.1 cgd hs->sc_flags |= HPIBF_PPOLL;
164 1.1 cgd if (hs->sc_type == HPIBC)
165 1.1 cgd fhpibppwatch(unit);
166 1.1 cgd else
167 1.1 cgd nhpibppwatch(unit);
168 1.1 cgd }
169 1.1 cgd
170 1.1 cgd hpibswait(unit, slave)
171 1.1 cgd register int unit;
172 1.1 cgd {
173 1.1 cgd register int timo = hpibtimeout;
174 1.1 cgd register int mask, (*ppoll)();
175 1.1 cgd
176 1.1 cgd ppoll = (hpib_softc[unit].sc_type == HPIBC) ? fhpibppoll : nhpibppoll;
177 1.1 cgd mask = 0x80 >> slave;
178 1.1 cgd while (((ppoll)(unit) & mask) == 0)
179 1.1 cgd if (--timo == 0) {
180 1.1 cgd printf("hpib%d: swait timeout\n", unit);
181 1.1 cgd return(-1);
182 1.1 cgd }
183 1.1 cgd return(0);
184 1.1 cgd }
185 1.1 cgd
186 1.1 cgd hpibustart(unit)
187 1.1 cgd {
188 1.1 cgd register struct hpib_softc *hs = &hpib_softc[unit];
189 1.1 cgd
190 1.1 cgd if (hs->sc_type == HPIBA)
191 1.1 cgd hs->sc_dq.dq_ctlr = DMA0;
192 1.1 cgd else
193 1.1 cgd hs->sc_dq.dq_ctlr = DMA0 | DMA1;
194 1.1 cgd if (dmareq(&hs->sc_dq))
195 1.1 cgd return(1);
196 1.1 cgd return(0);
197 1.1 cgd }
198 1.1 cgd
199 1.1 cgd hpibstart(unit)
200 1.1 cgd {
201 1.1 cgd register struct devqueue *dq;
202 1.1 cgd
203 1.1 cgd dq = hpib_softc[unit].sc_sq.dq_forw;
204 1.1 cgd (dq->dq_driver->d_go)(dq->dq_unit);
205 1.1 cgd }
206 1.1 cgd
207 1.1 cgd hpibgo(unit, slave, sec, addr, count, rw)
208 1.1 cgd register int unit;
209 1.1 cgd {
210 1.1 cgd if (hpib_softc[unit].sc_type == HPIBC)
211 1.1 cgd fhpibgo(unit, slave, sec, addr, count, rw);
212 1.1 cgd else
213 1.1 cgd nhpibgo(unit, slave, sec, addr, count, rw);
214 1.1 cgd }
215 1.1 cgd
216 1.1 cgd hpibdone(unit)
217 1.1 cgd register int unit;
218 1.1 cgd {
219 1.1 cgd if (hpib_softc[unit].sc_type == HPIBC)
220 1.1 cgd fhpibdone(unit);
221 1.1 cgd else
222 1.1 cgd nhpibdone(unit);
223 1.1 cgd }
224 1.1 cgd
225 1.1 cgd hpibintr(unit)
226 1.1 cgd register int unit;
227 1.1 cgd {
228 1.1 cgd int found;
229 1.1 cgd
230 1.1 cgd if (hpib_softc[unit].sc_type == HPIBC)
231 1.1 cgd found = fhpibintr(unit);
232 1.1 cgd else
233 1.1 cgd found = nhpibintr(unit);
234 1.1 cgd return(found);
235 1.1 cgd }
236 1.1 cgd #endif
237