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