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