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