atzsc.c revision 1.5 1 /*
2 * Copyright (c) 1994 Christian E. Hopps
3 * Copyright (c) 1982, 1990 The Regents of the University of California.
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. All advertising materials mentioning features or use of this software
15 * must display the following acknowledgement:
16 * This product includes software developed by the University of
17 * California, Berkeley and its contributors.
18 * 4. Neither the name of the University nor the names of its contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * SUCH DAMAGE.
33 *
34 * @(#)dma.c
35 * $Id: atzsc.c,v 1.5 1994/07/02 21:15:10 chopps Exp $
36 */
37 #include <sys/param.h>
38 #include <sys/systm.h>
39 #include <sys/kernel.h>
40 #include <sys/device.h>
41 #include <scsi/scsi_all.h>
42 #include <scsi/scsiconf.h>
43 #include <amiga/amiga/custom.h>
44 #include <amiga/amiga/cc.h>
45 #include <amiga/amiga/device.h>
46 #include <amiga/dev/dmavar.h>
47 #include <amiga/dev/sbicreg.h>
48 #include <amiga/dev/sbicvar.h>
49 #include <amiga/dev/atzscreg.h>
50 #include <amiga/dev/ztwobusvar.h>
51
52 int atzscprint __P((void *auxp, char *));
53 void atzscattach __P((struct device *, struct device *, void *));
54 int atzscmatch __P((struct device *, struct cfdata *, void *));
55
56 void atzsc_dmafree __P((struct sbic_softc *));
57 void atzsc_dmastop __P((struct sbic_softc *));
58 int atzsc_dmanext __P((struct sbic_softc *));
59 int atzsc_dmaintr __P((void));
60 int atzsc_dmago __P((struct sbic_softc *, char *, int, int));
61
62 struct scsi_adapter atzsc_scsiswitch = {
63 sbic_scsicmd,
64 sbic_minphys,
65 0, /* no lun support */
66 0, /* no lun support */
67 sbic_adinfo,
68 "atzsc",
69 };
70
71 struct scsi_device atzsc_scsidev = {
72 NULL, /* use default error handler */
73 NULL, /* do not have a start functio */
74 NULL, /* have no async handler */
75 NULL, /* Use default done routine */
76 "atzsc",
77 0,
78 };
79
80
81 #ifdef DEBUG
82 void atzsc_dmatimeout __P((void *));
83 int atzsc_dmadebug = 0;
84 #endif
85
86 struct cfdriver atzsccd = {
87 NULL, "atzsc", atzscmatch, atzscattach,
88 DV_DULL, sizeof(struct sbic_softc), NULL, 0 };
89
90 /*
91 * if we are an A3000 we are here.
92 */
93 int
94 atzscmatch(pdp, cdp, auxp)
95 struct device *pdp;
96 struct cfdata *cdp;
97 void *auxp;
98 {
99 struct ztwobus_args *zap;
100
101 zap = auxp;
102
103 /*
104 * Check manufacturer and product id.
105 * I was informed that older boards can be 2 also.
106 */
107 if (zap->manid == 514 && (zap->prodid == 3 || zap->prodid == 2))
108 return(1);
109 else
110 return(0);
111 }
112
113 void
114 atzscattach(pdp, dp, auxp)
115 struct device *pdp, *dp;
116 void *auxp;
117 {
118 volatile struct sdmac *rp;
119 struct sbic_softc *sc;
120 struct ztwobus_args *zap;
121
122 zap = auxp;
123
124 sc = (struct sbic_softc *)dp;
125 sc->sc_cregs = rp = zap->va;
126 /*
127 * disable ints and reset bank register
128 */
129 rp->CNTR = CNTR_PDMD;
130 rp->DAWR = DAWR_ATZSC;
131 sc->sc_dmafree = atzsc_dmafree;
132 sc->sc_dmago = atzsc_dmago;
133 sc->sc_dmanext = atzsc_dmanext;
134 sc->sc_dmastop = atzsc_dmastop;
135 sc->sc_dmacmd = 0;
136
137 #ifdef DEBUG
138 /* make sure timeout is really not needed */
139 timeout(atzsc_dmatimeout, 0, 30 * hz);
140 #endif
141 /*
142 * only 24 bit mem.
143 */
144 sc->sc_flags |= SBICF_BADDMA;
145 sc->sc_dmamask = ~0x00ffffff;
146 sc->sc_sbicp = (sbic_regmap_p) ((int)rp + 0x91);
147 sc->sc_clkfreq = sbic_clock_override ? sbic_clock_override : 77;
148
149 printf(": dmamask 0x%x\n", ~sc->sc_dmamask);
150
151 sbicreset(sc);
152
153 sc->sc_link.adapter_softc = sc;
154 sc->sc_link.adapter_targ = 7;
155 sc->sc_link.adapter = &atzsc_scsiswitch;
156 sc->sc_link.device = &atzsc_scsidev;
157 TAILQ_INIT(&sc->sc_xslist);
158
159 custom.intreq = INTF_PORTS;
160 custom.intena = INTF_SETCLR | INTF_PORTS;
161
162 /*
163 * attach all scsi units on us
164 */
165 config_found(dp, &sc->sc_link, atzscprint);
166 }
167
168 /*
169 * print diag if pnp is NULL else just extra
170 */
171 int
172 atzscprint(auxp, pnp)
173 void *auxp;
174 char *pnp;
175 {
176 if (pnp == NULL)
177 return(UNCONF);
178 return(QUIET);
179 }
180
181
182 void
183 atzsc_dmafree(dev)
184 struct sbic_softc *dev;
185 {
186 volatile struct sdmac *sdp;
187 int s;
188
189 sdp = dev->sc_cregs;
190
191 s = splbio();
192 #ifdef DEBUG
193 dev->sc_dmatimo = 0;
194 #endif
195 if (dev->sc_dmacmd) {
196 if ((dev->sc_dmacmd & (CNTR_TCEN | CNTR_DDIR)) == 0) {
197 /*
198 * only FLUSH if terminal count not enabled,
199 * and reading from peripheral
200 */
201 sdp->FLUSH = 1;
202 while ((sdp->ISTR & ISTR_FE_FLG) == 0)
203 ;
204 }
205 /*
206 * clear possible interrupt and stop dma
207 */
208 sdp->CINT = 1;
209 sdp->SP_DMA = 1;
210 dev->sc_dmacmd = 0;
211 }
212 /*
213 * disable interrupts
214 */
215 sdp->CNTR = CNTR_PDMD; /* disable interrupts from dma/scsi */
216 dev->sc_flags &= ~SBICF_INTR;
217 splx(s);
218 }
219
220 int
221 atzsc_dmago(dev, addr, count, flags)
222 struct sbic_softc *dev;
223 char *addr;
224 int count, flags;
225 {
226 volatile struct sdmac *sdp;
227
228 sdp = dev->sc_cregs;
229 /*
230 * Set up the command word based on flags
231 */
232 dev->sc_dmacmd = CNTR_PDMD | CNTR_INTEN;
233 if ((flags & DMAGO_READ) == 0)
234 dev->sc_dmacmd |= CNTR_DDIR;
235 #ifdef DEBUG
236 if (atzsc_dmadebug & DDB_IO)
237 printf("atzsc_dmago: cmd %x\n", dev->sc_dmacmd);
238 dev->sc_dmatimo = 1;
239 #endif
240
241 dev->sc_flags |= SBICF_INTR;
242 sdp->CNTR = dev->sc_dmacmd;
243 sdp->ACR = (u_int) dev->sc_cur->dc_addr;
244 sdp->ST_DMA = 1;
245
246 return(dev->sc_tcnt);
247 }
248
249 void
250 atzsc_dmastop(dev)
251 struct sbic_softc *dev;
252 {
253 volatile struct sdmac *sdp;
254 int s;
255
256 sdp = dev->sc_cregs;
257
258 #ifdef DEBUG
259 if (atzsc_dmadebug & DDB_FOLLOW)
260 printf("atzsc_dmastop()\n");
261 dev->sc_dmatimo = 0;
262 #endif
263 if (dev->sc_dmacmd) {
264 s = splbio();
265 if ((dev->sc_dmacmd & (CNTR_TCEN | CNTR_DDIR)) == 0) {
266 /*
267 * only FLUSH if terminal count not enabled,
268 * and reading from peripheral
269 */
270 sdp->FLUSH = 1;
271 while ((sdp->ISTR & ISTR_FE_FLG) == 0)
272 ;
273 }
274 /*
275 * clear possible interrupt and stop dma
276 */
277 sdp->CINT = 1;
278 sdp->SP_DMA = 1;
279 dev->sc_dmacmd = 0;
280 splx(s);
281 }
282 }
283
284 int
285 atzsc_dmaintr()
286 {
287 volatile struct sdmac *sdp;
288 struct sbic_softc *dev;
289 int i, stat, found;
290
291 found = 0;
292 for (i = 0; i < atzsccd.cd_ndevs; i++) {
293 dev = atzsccd.cd_devs[i];
294 if (dev == NULL)
295 continue;
296 sdp = dev->sc_cregs;
297 stat = sdp->ISTR;
298
299 if ((stat & (ISTR_INT_F|ISTR_INT_P)) == 0)
300 continue;
301
302 #ifdef DEBUG
303 if (atzsc_dmadebug & DDB_FOLLOW)
304 printf("atzsc_dmaintr (%d, 0x%x)\n", i, stat);
305 #endif
306
307 /*
308 * both, SCSI and DMA interrupts arrive here. I chose
309 * arbitrarily that DMA interrupts should have higher
310 * precedence than SCSI interrupts.
311 */
312 if (stat & ISTR_E_INT) {
313 found++;
314
315 sdp->CINT = 1; /* clear possible interrupt */
316
317 /*
318 * check for SCSI ints in the same go and
319 * eventually save an interrupt
320 */
321 }
322
323 if (dev->sc_flags & SBICF_INTR && stat & ISTR_INTS)
324 found += sbicintr(dev);
325 }
326 return(found);
327 }
328
329
330 int
331 atzsc_dmanext(dev)
332 struct sbic_softc *dev;
333 {
334 volatile struct sdmac *sdp;
335 int i, stat;
336
337 sdp = dev->sc_cregs;
338
339 if (dev->sc_cur > dev->sc_last) {
340 /* shouldn't happen !! */
341 printf("atzsc_dmanext at end !!!\n");
342 atzsc_dmastop(dev);
343 return(0);
344 }
345 #ifdef DEBUG
346 dev->sc_dmatimo = 1;
347 #endif
348 if ((dev->sc_dmacmd & (CNTR_TCEN | CNTR_DDIR)) == 0) {
349 /*
350 * only FLUSH if terminal count not enabled,
351 * and reading from peripheral
352 */
353 sdp->FLUSH = 1;
354 while ((sdp->ISTR & ISTR_FE_FLG) == 0)
355 ;
356 }
357 /*
358 * clear possible interrupt and stop dma
359 */
360 sdp->CINT = 1; /* clear possible interrupt */
361 sdp->SP_DMA = 1; /* stop dma */
362 sdp->CNTR = dev->sc_dmacmd;
363 sdp->ACR = (u_int)dev->sc_cur->dc_addr;
364 sdp->ST_DMA = 1;
365
366 dev->sc_tcnt = dev->sc_cur->dc_count << 1;
367 return(dev->sc_tcnt);
368 }
369
370 #ifdef DEBUG
371 /*ARGSUSED*/
372 void
373 atzsc_dmatimeout(arg)
374 void *arg;
375 {
376 struct sbic_softc *dev;
377 int i, s;
378
379 for (i = 0; i < atzsccd.cd_ndevs; i++) {
380 dev = atzsccd.cd_devs[i];
381 if (dev == NULL)
382 continue;
383
384 s = splbio();
385 if (dev->sc_dmatimo) {
386 if (dev->sc_dmatimo > 1)
387 printf("atzsc_dma%d: timeout #%d\n",
388 dev->sc_dev.dv_unit, dev->sc_dmatimo - 1);
389 dev->sc_dmatimo++;
390 }
391 splx(s);
392 }
393 timeout(atzsc_dmatimeout, 0, 30 * hz);
394 }
395 #endif
396