atzsc.c revision 1.13 1 /* $NetBSD: atzsc.c,v 1.13 1995/09/04 13:04:42 chopps 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 *, struct cfdata *, 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((struct sbic_softc *));
62 int atzsc_dmago __P((struct sbic_softc *, char *, int, int));
63
64 struct scsi_adapter atzsc_scsiswitch = {
65 sbic_scsicmd,
66 sbic_minphys,
67 0, /* no lun support */
68 0, /* no lun support */
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 };
77
78
79 #ifdef DEBUG
80 int atzsc_dmadebug = 0;
81 #endif
82
83 struct cfdriver atzsccd = {
84 NULL, "atzsc", (cfmatch_t)atzscmatch, atzscattach,
85 DV_DULL, sizeof(struct sbic_softc), NULL, 0 };
86
87 /*
88 * if we are an A3000 we are here.
89 */
90 int
91 atzscmatch(pdp, cdp, auxp)
92 struct device *pdp;
93 struct cfdata *cdp;
94 void *auxp;
95 {
96 struct zbus_args *zap;
97
98 zap = auxp;
99
100 /*
101 * Check manufacturer and product id.
102 * I was informed that older boards can be 2 also.
103 */
104 if (zap->manid == 514 && (zap->prodid == 3 || zap->prodid == 2))
105 return(1);
106 else
107 return(0);
108 }
109
110 void
111 atzscattach(pdp, dp, auxp)
112 struct device *pdp, *dp;
113 void *auxp;
114 {
115 volatile struct sdmac *rp;
116 struct sbic_softc *sc;
117 struct zbus_args *zap;
118
119 zap = auxp;
120
121 sc = (struct sbic_softc *)dp;
122 sc->sc_cregs = rp = zap->va;
123 /*
124 * disable ints and reset bank register
125 */
126 rp->CNTR = CNTR_PDMD;
127 rp->DAWR = DAWR_ATZSC;
128 sc->sc_enintr = atzsc_enintr;
129 sc->sc_dmago = atzsc_dmago;
130 sc->sc_dmanext = atzsc_dmanext;
131 sc->sc_dmastop = atzsc_dmastop;
132 sc->sc_dmacmd = 0;
133
134 /*
135 * only 24 bit mem.
136 */
137 sc->sc_flags |= SBICF_BADDMA;
138 sc->sc_dmamask = ~0x00ffffff;
139 #if 0
140 /*
141 * If the users kva space is not ztwo try and allocate a bounce buffer.
142 * XXX this needs to change if we move to multiple memory segments.
143 */
144 if (kvtop(sc) & sc->sc_dmamask) {
145 sc->sc_dmabuffer = (char *)alloc_z2mem(MAXPHYS * 8); /* XXX */
146 if (isztwomem(sc->sc_dmabuffer))
147 printf(" bounce pa 0x%x", kvtop(sc->sc_dmabuffer));
148 else if (sc->sc_dmabuffer)
149 printf(" bounce pa 0x%x",
150 PREP_DMA_MEM(sc->sc_dmabuffer));
151 }
152 #endif
153 sc->sc_sbicp = (sbic_regmap_p) ((int)rp + 0x91);
154 sc->sc_clkfreq = sbic_clock_override ? sbic_clock_override : 77;
155
156 printf(": dmamask 0x%x\n", ~sc->sc_dmamask);
157
158 sc->sc_link.adapter_softc = sc;
159 sc->sc_link.adapter_target = 7;
160 sc->sc_link.adapter = &atzsc_scsiswitch;
161 sc->sc_link.device = &atzsc_scsidev;
162 sc->sc_link.openings = 2;
163
164 sbicinit(sc);
165
166 sc->sc_isr.isr_intr = atzsc_dmaintr;
167 sc->sc_isr.isr_arg = sc;
168 sc->sc_isr.isr_ipl = 2;
169 add_isr (&sc->sc_isr);
170
171 /*
172 * attach all scsi units on us
173 */
174 config_found(dp, &sc->sc_link, atzscprint);
175 }
176
177 /*
178 * print diag if pnp is NULL else just extra
179 */
180 int
181 atzscprint(auxp, pnp)
182 void *auxp;
183 char *pnp;
184 {
185 if (pnp == NULL)
186 return(UNCONF);
187 return(QUIET);
188 }
189
190
191 void
192 atzsc_enintr(dev)
193 struct sbic_softc *dev;
194 {
195 volatile struct sdmac *sdp;
196
197 sdp = dev->sc_cregs;
198
199 dev->sc_flags |= SBICF_INTR;
200 sdp->CNTR = CNTR_PDMD | CNTR_INTEN;
201 }
202
203 int
204 atzsc_dmago(dev, addr, count, flags)
205 struct sbic_softc *dev;
206 char *addr;
207 int count, flags;
208 {
209 volatile struct sdmac *sdp;
210
211 sdp = dev->sc_cregs;
212 /*
213 * Set up the command word based on flags
214 */
215 dev->sc_dmacmd = CNTR_PDMD | CNTR_INTEN;
216 if ((flags & DMAGO_READ) == 0)
217 dev->sc_dmacmd |= CNTR_DDIR;
218 #ifdef DEBUG
219 if (atzsc_dmadebug & DDB_IO)
220 printf("atzsc_dmago: cmd %x\n", dev->sc_dmacmd);
221 #endif
222
223 dev->sc_flags |= SBICF_INTR;
224 sdp->CNTR = dev->sc_dmacmd;
225 sdp->ACR = (u_int) dev->sc_cur->dc_addr;
226 sdp->ST_DMA = 1;
227
228 return(dev->sc_tcnt);
229 }
230
231 void
232 atzsc_dmastop(dev)
233 struct sbic_softc *dev;
234 {
235 volatile struct sdmac *sdp;
236 int s;
237
238 sdp = dev->sc_cregs;
239
240 #ifdef DEBUG
241 if (atzsc_dmadebug & DDB_FOLLOW)
242 printf("atzsc_dmastop()\n");
243 #endif
244 if (dev->sc_dmacmd) {
245 s = splbio();
246 if ((dev->sc_dmacmd & (CNTR_TCEN | CNTR_DDIR)) == 0) {
247 /*
248 * only FLUSH if terminal count not enabled,
249 * and reading from peripheral
250 */
251 sdp->FLUSH = 1;
252 while ((sdp->ISTR & ISTR_FE_FLG) == 0)
253 ;
254 }
255 /*
256 * clear possible interrupt and stop dma
257 */
258 sdp->CINT = 1;
259 sdp->SP_DMA = 1;
260 dev->sc_dmacmd = 0;
261 splx(s);
262 }
263 }
264
265 int
266 atzsc_dmaintr(dev)
267 struct sbic_softc *dev;
268 {
269 volatile struct sdmac *sdp;
270 int stat, found;
271
272 sdp = dev->sc_cregs;
273 stat = sdp->ISTR;
274
275 if ((stat & (ISTR_INT_F|ISTR_INT_P)) == 0)
276 return (0);
277
278 #ifdef DEBUG
279 if (atzsc_dmadebug & DDB_FOLLOW)
280 printf("%s: dmaintr 0x%x\n", dev->sc_dev.dv_xname, stat);
281 #endif
282
283 /*
284 * both, SCSI and DMA interrupts arrive here. I chose
285 * arbitrarily that DMA interrupts should have higher
286 * precedence than SCSI interrupts.
287 */
288 found = 0;
289 if (stat & ISTR_E_INT) {
290 found++;
291
292 sdp->CINT = 1; /* clear possible interrupt */
293
294 /*
295 * check for SCSI ints in the same go and
296 * eventually save an interrupt
297 */
298 }
299
300 if (dev->sc_flags & SBICF_INTR && stat & ISTR_INTS)
301 found += sbicintr(dev);
302 return(found);
303 }
304
305
306 int
307 atzsc_dmanext(dev)
308 struct sbic_softc *dev;
309 {
310 volatile struct sdmac *sdp;
311 int i, stat;
312
313 sdp = dev->sc_cregs;
314
315 if (dev->sc_cur > dev->sc_last) {
316 /* shouldn't happen !! */
317 printf("atzsc_dmanext at end !!!\n");
318 atzsc_dmastop(dev);
319 return(0);
320 }
321 if ((dev->sc_dmacmd & (CNTR_TCEN | CNTR_DDIR)) == 0) {
322 /*
323 * only FLUSH if terminal count not enabled,
324 * and reading from peripheral
325 */
326 sdp->FLUSH = 1;
327 while ((sdp->ISTR & ISTR_FE_FLG) == 0)
328 ;
329 }
330 /*
331 * clear possible interrupt and stop dma
332 */
333 sdp->CINT = 1; /* clear possible interrupt */
334 sdp->SP_DMA = 1; /* stop dma */
335 sdp->CNTR = dev->sc_dmacmd;
336 sdp->ACR = (u_int)dev->sc_cur->dc_addr;
337 sdp->ST_DMA = 1;
338
339 dev->sc_tcnt = dev->sc_cur->dc_count << 1;
340 return(dev->sc_tcnt);
341 }
342
343 #ifdef DEBUG
344 void
345 atzsc_dump()
346 {
347 int i;
348
349 for (i = 0; i < atzsccd.cd_ndevs; ++i)
350 if (atzsccd.cd_devs[i])
351 sbic_dump(atzsccd.cd_devs[i]);
352 }
353 #endif
354