ahsc.c revision 1.11 1 /* $NetBSD: ahsc.c,v 1.11 1996/03/17 01:17:00 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 <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/ahscreg.h>
52 #include <amiga/dev/zbusvar.h>
53
54 int ahscprint __P((void *auxp, char *));
55 void ahscattach __P((struct device *, struct device *, void *));
56 int ahscmatch __P((struct device *, void *, void *));
57
58 void ahsc_enintr __P((struct sbic_softc *));
59 void ahsc_dmastop __P((struct sbic_softc *));
60 int ahsc_dmanext __P((struct sbic_softc *));
61 int ahsc_dmaintr __P((struct sbic_softc *));
62 int ahsc_dmago __P((struct sbic_softc *, char *, int, int));
63
64 struct scsi_adapter ahsc_scsiswitch = {
65 sbic_scsicmd,
66 sbic_minphys,
67 0, /* no lun support */
68 0, /* no lun support */
69 };
70
71 struct scsi_device ahsc_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 ahsc_dmadebug = 0;
81 #endif
82
83 struct cfattach ahsc_ca = {
84 sizeof(struct sbic_softc), ahscmatch, ahscattach
85 };
86
87 struct cfdriver ahsc_cd = {
88 NULL, "ahsc", DV_DULL, NULL, 0
89 };
90
91 /*
92 * if we are an A3000 we are here.
93 */
94 int
95 ahscmatch(pdp, match, auxp)
96 struct device *pdp;
97 void *match, *auxp;
98 {
99 struct cfdata *cdp = match;
100 char *mbusstr;
101
102 mbusstr = auxp;
103 if (is_a3000() && matchname(auxp, "ahsc"))
104 return(1);
105 return(0);
106 }
107
108 void
109 ahscattach(pdp, dp, auxp)
110 struct device *pdp, *dp;
111 void *auxp;
112 {
113 volatile struct sdmac *rp;
114 struct sbic_softc *sc;
115
116 printf("\n");
117
118 sc = (struct sbic_softc *)dp;
119 sc->sc_cregs = rp = ztwomap(0xdd0000);
120 /*
121 * disable ints and reset bank register
122 */
123 rp->CNTR = CNTR_PDMD;
124 rp->DAWR = DAWR_AHSC;
125 sc->sc_enintr = ahsc_enintr;
126 sc->sc_dmago = ahsc_dmago;
127 sc->sc_dmanext = ahsc_dmanext;
128 sc->sc_dmastop = ahsc_dmastop;
129 sc->sc_dmacmd = 0;
130
131 /*
132 * eveything is a valid dma address
133 */
134 sc->sc_dmamask = 0;
135 sc->sc_sbicp = (sbic_regmap_p) ((int)rp + 0x41);
136 sc->sc_clkfreq = sbic_clock_override ? sbic_clock_override : 143;
137
138 sc->sc_link.adapter_softc = sc;
139 sc->sc_link.adapter_target = 7;
140 sc->sc_link.adapter = &ahsc_scsiswitch;
141 sc->sc_link.device = &ahsc_scsidev;
142 sc->sc_link.openings = 2;
143
144 sbicinit(sc);
145
146 sc->sc_isr.isr_intr = ahsc_dmaintr;
147 sc->sc_isr.isr_arg = sc;
148 sc->sc_isr.isr_ipl = 2;
149 add_isr (&sc->sc_isr);
150
151 /*
152 * attach all scsi units on us
153 */
154 config_found(dp, &sc->sc_link, ahscprint);
155 }
156
157 /*
158 * print diag if pnp is NULL else just extra
159 */
160 int
161 ahscprint(auxp, pnp)
162 void *auxp;
163 char *pnp;
164 {
165 if (pnp == NULL)
166 return(UNCONF);
167 return(QUIET);
168 }
169
170
171 void
172 ahsc_enintr(dev)
173 struct sbic_softc *dev;
174 {
175 volatile struct sdmac *sdp;
176
177 sdp = dev->sc_cregs;
178
179 dev->sc_flags |= SBICF_INTR;
180 sdp->CNTR = CNTR_PDMD | CNTR_INTEN;
181 }
182
183 int
184 ahsc_dmago(dev, addr, count, flags)
185 struct sbic_softc *dev;
186 char *addr;
187 int count, flags;
188 {
189 volatile struct sdmac *sdp;
190
191 sdp = dev->sc_cregs;
192 /*
193 * Set up the command word based on flags
194 */
195 dev->sc_dmacmd = CNTR_PDMD | CNTR_INTEN;
196 if ((flags & DMAGO_READ) == 0)
197 dev->sc_dmacmd |= CNTR_DDIR;
198 #ifdef DEBUG
199 if (ahsc_dmadebug & DDB_IO)
200 printf("ahsc_dmago: cmd %x\n", dev->sc_dmacmd);
201 #endif
202
203 dev->sc_flags |= SBICF_INTR;
204 sdp->CNTR = dev->sc_dmacmd;
205 sdp->ACR = (u_int) dev->sc_cur->dc_addr;
206 sdp->ST_DMA = 1;
207
208 return(dev->sc_tcnt);
209 }
210
211 void
212 ahsc_dmastop(dev)
213 struct sbic_softc *dev;
214 {
215 volatile struct sdmac *sdp;
216 int s;
217
218 sdp = dev->sc_cregs;
219
220 #ifdef DEBUG
221 if (ahsc_dmadebug & DDB_FOLLOW)
222 printf("ahsc_dmastop()\n");
223 #endif
224 if (dev->sc_dmacmd) {
225 s = splbio();
226 if ((dev->sc_dmacmd & (CNTR_TCEN | CNTR_DDIR)) == 0) {
227 /*
228 * only FLUSH if terminal count not enabled,
229 * and reading from peripheral
230 */
231 sdp->FLUSH = 1;
232 while ((sdp->ISTR & ISTR_FE_FLG) == 0)
233 ;
234 }
235 /*
236 * clear possible interrupt and stop dma
237 */
238 sdp->CINT = 1;
239 sdp->SP_DMA = 1;
240 dev->sc_dmacmd = 0;
241 splx(s);
242 }
243 }
244
245 int
246 ahsc_dmaintr(dev)
247 struct sbic_softc *dev;
248 {
249 volatile struct sdmac *sdp;
250 int stat, found;
251
252 sdp = dev->sc_cregs;
253 stat = sdp->ISTR;
254
255 if ((stat & (ISTR_INT_F|ISTR_INT_P)) == 0)
256 return (0);
257
258 #ifdef DEBUG
259 if (ahsc_dmadebug & DDB_FOLLOW)
260 printf("%s: dmaintr 0x%x\n", dev->sc_dev.dv_xname, stat);
261 #endif
262
263 /*
264 * both, SCSI and DMA interrupts arrive here. I chose
265 * arbitrarily that DMA interrupts should have higher
266 * precedence than SCSI interrupts.
267 */
268 found = 0;
269 if (stat & ISTR_E_INT) {
270 ++found;
271
272 sdp->CINT = 1; /* clear possible interrupt */
273
274 /*
275 * check for SCSI ints in the same go and
276 * eventually save an interrupt
277 */
278 }
279
280 if (dev->sc_flags & SBICF_INTR && stat & ISTR_INTS)
281 found += sbicintr(dev);
282 return(found);
283 }
284
285
286 int
287 ahsc_dmanext(dev)
288 struct sbic_softc *dev;
289 {
290 volatile struct sdmac *sdp;
291 int i, stat;
292
293 sdp = dev->sc_cregs;
294
295 if (dev->sc_cur > dev->sc_last) {
296 /* shouldn't happen !! */
297 printf("ahsc_dmanext at end !!!\n");
298 ahsc_dmastop(dev);
299 return(0);
300 }
301 if ((dev->sc_dmacmd & (CNTR_TCEN | CNTR_DDIR)) == 0) {
302 /*
303 * only FLUSH if terminal count not enabled,
304 * and reading from peripheral
305 */
306 sdp->FLUSH = 1;
307 while ((sdp->ISTR & ISTR_FE_FLG) == 0)
308 ;
309 }
310 /*
311 * clear possible interrupt and stop dma
312 */
313 sdp->CINT = 1; /* clear possible interrupt */
314 sdp->SP_DMA = 1; /* stop dma */
315 sdp->CNTR = dev->sc_dmacmd;
316 sdp->ACR = (u_int)dev->sc_cur->dc_addr;
317 sdp->ST_DMA = 1;
318
319 dev->sc_tcnt = dev->sc_cur->dc_count << 1;
320 return(dev->sc_tcnt);
321 }
322
323 #ifdef DEBUG
324 void
325 ahsc_dump()
326 {
327 int i;
328
329 for (i = 0; i < ahsc_cd.cd_ndevs; ++i)
330 if (ahsc_cd.cd_devs[i])
331 sbic_dump(ahsc_cd.cd_devs[i]);
332 }
333 #endif
334