si.c revision 1.6.8.3 1 1.6.8.3 nathanw /* $NetBSD: si.c,v 1.6.8.3 2002/11/11 22:01:50 nathanw Exp $ */
2 1.6.8.2 nathanw
3 1.6.8.2 nathanw /*
4 1.6.8.2 nathanw * Copyright (c) 1996 The NetBSD Foundation, Inc.
5 1.6.8.2 nathanw * All rights reserved.
6 1.6.8.2 nathanw *
7 1.6.8.2 nathanw * This code is derived from software contributed to The NetBSD Foundation
8 1.6.8.2 nathanw * by Adam Glass, David Jones, Gordon W. Ross, and Jens A. Nilsson.
9 1.6.8.2 nathanw *
10 1.6.8.2 nathanw * Redistribution and use in source and binary forms, with or without
11 1.6.8.2 nathanw * modification, are permitted provided that the following conditions
12 1.6.8.2 nathanw * are met:
13 1.6.8.2 nathanw * 1. Redistributions of source code must retain the above copyright
14 1.6.8.2 nathanw * notice, this list of conditions and the following disclaimer.
15 1.6.8.2 nathanw * 2. Redistributions in binary form must reproduce the above copyright
16 1.6.8.2 nathanw * notice, this list of conditions and the following disclaimer in the
17 1.6.8.2 nathanw * documentation and/or other materials provided with the distribution.
18 1.6.8.2 nathanw * 3. All advertising materials mentioning features or use of this software
19 1.6.8.2 nathanw * must display the following acknowledgement:
20 1.6.8.2 nathanw * This product includes software developed by the NetBSD
21 1.6.8.2 nathanw * Foundation, Inc. and its contributors.
22 1.6.8.2 nathanw * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.6.8.2 nathanw * contributors may be used to endorse or promote products derived
24 1.6.8.2 nathanw * from this software without specific prior written permission.
25 1.6.8.2 nathanw *
26 1.6.8.2 nathanw * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.6.8.2 nathanw * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.6.8.2 nathanw * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.6.8.2 nathanw * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.6.8.2 nathanw * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.6.8.2 nathanw * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.6.8.2 nathanw * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.6.8.2 nathanw * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.6.8.2 nathanw * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.6.8.2 nathanw * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.6.8.2 nathanw * POSSIBILITY OF SUCH DAMAGE.
37 1.6.8.2 nathanw */
38 1.6.8.2 nathanw
39 1.6.8.2 nathanw /*
40 1.6.8.2 nathanw * This file contains the machine-dependent parts of the Sony CXD1180
41 1.6.8.2 nathanw * controller. The machine-independent parts are in ncr5380sbc.c.
42 1.6.8.2 nathanw * Written by Izumi Tsutsui.
43 1.6.8.2 nathanw *
44 1.6.8.2 nathanw * This code is based on arch/vax/vsa/ncr.c and sun3/dev/si.c
45 1.6.8.2 nathanw */
46 1.6.8.2 nathanw
47 1.6.8.2 nathanw #include <sys/param.h>
48 1.6.8.2 nathanw #include <sys/systm.h>
49 1.6.8.2 nathanw #include <sys/device.h>
50 1.6.8.2 nathanw #include <sys/buf.h>
51 1.6.8.2 nathanw
52 1.6.8.2 nathanw #include <machine/cpu.h>
53 1.6.8.3 nathanw #include <m68k/cacheops.h>
54 1.6.8.2 nathanw
55 1.6.8.2 nathanw #include <dev/scsipi/scsipi_all.h>
56 1.6.8.2 nathanw #include <dev/scsipi/scsiconf.h>
57 1.6.8.2 nathanw
58 1.6.8.2 nathanw #include <dev/ic/ncr5380reg.h>
59 1.6.8.2 nathanw #include <dev/ic/ncr5380var.h>
60 1.6.8.2 nathanw
61 1.6.8.2 nathanw #include <news68k/dev/hbvar.h>
62 1.6.8.2 nathanw #include <news68k/dev/dmac_0266.h>
63 1.6.8.2 nathanw
64 1.6.8.2 nathanw #define MIN_DMA_LEN 128
65 1.6.8.2 nathanw #define DMAC_BASE 0xe0e80000 /* XXX */
66 1.6.8.2 nathanw
67 1.6.8.2 nathanw struct si_dma_handle {
68 1.6.8.2 nathanw int dh_flags;
69 1.6.8.2 nathanw #define SIDH_BUSY 0x01
70 1.6.8.2 nathanw #define SIDH_OUT 0x02
71 1.6.8.2 nathanw caddr_t dh_addr;
72 1.6.8.2 nathanw int dh_len;
73 1.6.8.2 nathanw };
74 1.6.8.2 nathanw
75 1.6.8.2 nathanw struct si_softc {
76 1.6.8.2 nathanw struct ncr5380_softc ncr_sc;
77 1.6.8.2 nathanw int sc_options;
78 1.6.8.2 nathanw volatile struct dma_regs *sc_regs;
79 1.6.8.2 nathanw struct si_dma_handle ncr_dma[SCI_OPENINGS];
80 1.6.8.2 nathanw };
81 1.6.8.2 nathanw
82 1.6.8.2 nathanw void si_attach __P((struct device *, struct device *, void *));
83 1.6.8.2 nathanw int si_match __P((struct device *, struct cfdata *, void *));
84 1.6.8.2 nathanw int si_intr __P((int));
85 1.6.8.2 nathanw
86 1.6.8.2 nathanw void si_dma_alloc __P((struct ncr5380_softc *));
87 1.6.8.2 nathanw void si_dma_free __P((struct ncr5380_softc *));
88 1.6.8.2 nathanw void si_dma_setup __P((struct ncr5380_softc *));
89 1.6.8.2 nathanw void si_dma_start __P((struct ncr5380_softc *));
90 1.6.8.2 nathanw void si_dma_poll __P((struct ncr5380_softc *));
91 1.6.8.2 nathanw void si_dma_eop __P((struct ncr5380_softc *));
92 1.6.8.2 nathanw void si_dma_stop __P((struct ncr5380_softc *));
93 1.6.8.2 nathanw
94 1.6.8.2 nathanw CFATTACH_DECL(si, sizeof(struct si_softc),
95 1.6.8.2 nathanw si_match, si_attach, NULL, NULL);
96 1.6.8.2 nathanw
97 1.6.8.2 nathanw /*
98 1.6.8.2 nathanw * Options for disconnect/reselect, DMA, and interrupts.
99 1.6.8.2 nathanw * By default, allow disconnect/reselect on targets 4-6.
100 1.6.8.2 nathanw * Those are normally tapes that really need it enabled.
101 1.6.8.2 nathanw * The options are taken from the config file.
102 1.6.8.2 nathanw */
103 1.6.8.2 nathanw #define SI_NO_DISCONNECT 0x000ff
104 1.6.8.2 nathanw #define SI_NO_PARITY_CHK 0x0ff00
105 1.6.8.2 nathanw #define SI_FORCE_POLLING 0x10000
106 1.6.8.2 nathanw #define SI_DISABLE_DMA 0x20000
107 1.6.8.2 nathanw
108 1.6.8.2 nathanw int si_options = 0x0f;
109 1.6.8.2 nathanw
110 1.6.8.2 nathanw
111 1.6.8.2 nathanw int
112 1.6.8.2 nathanw si_match(parent, cf, aux)
113 1.6.8.2 nathanw struct device *parent;
114 1.6.8.2 nathanw struct cfdata *cf;
115 1.6.8.2 nathanw void *aux;
116 1.6.8.2 nathanw {
117 1.6.8.2 nathanw struct hb_attach_args *ha = aux;
118 1.6.8.2 nathanw int addr;
119 1.6.8.2 nathanw
120 1.6.8.2 nathanw if (strcmp(ha->ha_name, "si"))
121 1.6.8.2 nathanw return 0;
122 1.6.8.2 nathanw
123 1.6.8.2 nathanw addr = IIOV(ha->ha_address);
124 1.6.8.2 nathanw
125 1.6.8.2 nathanw if (badaddr((void *)addr, 1))
126 1.6.8.2 nathanw return 0;
127 1.6.8.2 nathanw
128 1.6.8.2 nathanw return 1;
129 1.6.8.2 nathanw }
130 1.6.8.2 nathanw
131 1.6.8.2 nathanw /*
132 1.6.8.2 nathanw * Card attach function
133 1.6.8.2 nathanw */
134 1.6.8.2 nathanw
135 1.6.8.2 nathanw void
136 1.6.8.2 nathanw si_attach(parent, self, aux)
137 1.6.8.2 nathanw struct device *parent, *self;
138 1.6.8.2 nathanw void *aux;
139 1.6.8.2 nathanw {
140 1.6.8.2 nathanw struct si_softc *sc = (struct si_softc *)self;
141 1.6.8.2 nathanw struct ncr5380_softc *ncr_sc = &sc->ncr_sc;
142 1.6.8.2 nathanw struct cfdata *cf = self->dv_cfdata;
143 1.6.8.2 nathanw struct hb_attach_args *ha = aux;
144 1.6.8.2 nathanw u_char *addr;
145 1.6.8.2 nathanw
146 1.6.8.2 nathanw /* Get options from config flags if specified. */
147 1.6.8.2 nathanw if (cf->cf_flags)
148 1.6.8.2 nathanw sc->sc_options = cf->cf_flags;
149 1.6.8.2 nathanw else
150 1.6.8.2 nathanw sc->sc_options = si_options;
151 1.6.8.2 nathanw
152 1.6.8.2 nathanw printf(": options=0x%x\n", sc->sc_options);
153 1.6.8.2 nathanw
154 1.6.8.2 nathanw ncr_sc->sc_no_disconnect = (sc->sc_options & SI_NO_DISCONNECT);
155 1.6.8.2 nathanw ncr_sc->sc_parity_disable = (sc->sc_options & SI_NO_PARITY_CHK) >> 8;
156 1.6.8.2 nathanw if (sc->sc_options & SI_FORCE_POLLING)
157 1.6.8.2 nathanw ncr_sc->sc_flags |= NCR5380_FORCE_POLLING;
158 1.6.8.2 nathanw
159 1.6.8.2 nathanw ncr_sc->sc_min_dma_len = MIN_DMA_LEN;
160 1.6.8.2 nathanw ncr_sc->sc_dma_alloc = si_dma_alloc;
161 1.6.8.2 nathanw ncr_sc->sc_dma_free = si_dma_free;
162 1.6.8.2 nathanw ncr_sc->sc_dma_poll = si_dma_poll;
163 1.6.8.2 nathanw ncr_sc->sc_dma_setup = si_dma_setup;
164 1.6.8.2 nathanw ncr_sc->sc_dma_start = si_dma_start;
165 1.6.8.2 nathanw ncr_sc->sc_dma_eop = si_dma_eop;
166 1.6.8.2 nathanw ncr_sc->sc_dma_stop = si_dma_stop;
167 1.6.8.2 nathanw
168 1.6.8.2 nathanw if (sc->sc_options & SI_DISABLE_DMA)
169 1.6.8.2 nathanw /* Override this function pointer. */
170 1.6.8.2 nathanw ncr_sc->sc_dma_alloc = NULL;
171 1.6.8.2 nathanw
172 1.6.8.2 nathanw addr = (u_char *)IIOV(ha->ha_address);
173 1.6.8.2 nathanw ncr_sc->sci_r0 = addr + 0;
174 1.6.8.2 nathanw ncr_sc->sci_r1 = addr + 1;
175 1.6.8.2 nathanw ncr_sc->sci_r2 = addr + 2;
176 1.6.8.2 nathanw ncr_sc->sci_r3 = addr + 3;
177 1.6.8.2 nathanw ncr_sc->sci_r4 = addr + 4;
178 1.6.8.2 nathanw ncr_sc->sci_r5 = addr + 5;
179 1.6.8.2 nathanw ncr_sc->sci_r6 = addr + 6;
180 1.6.8.2 nathanw ncr_sc->sci_r7 = addr + 7;
181 1.6.8.2 nathanw
182 1.6.8.2 nathanw ncr_sc->sc_rev = NCR_VARIANT_CXD1180;
183 1.6.8.2 nathanw
184 1.6.8.2 nathanw ncr_sc->sc_pio_in = ncr5380_pio_in;
185 1.6.8.2 nathanw ncr_sc->sc_pio_out = ncr5380_pio_out;
186 1.6.8.2 nathanw
187 1.6.8.2 nathanw ncr_sc->sc_adapter.adapt_minphys = minphys;
188 1.6.8.2 nathanw ncr_sc->sc_channel.chan_id = 7;
189 1.6.8.2 nathanw
190 1.6.8.2 nathanw /* soft reset DMAC */
191 1.6.8.2 nathanw sc->sc_regs = (void *)IIOV(DMAC_BASE);
192 1.6.8.2 nathanw sc->sc_regs->ctl = DC_CTL_RST;
193 1.6.8.2 nathanw
194 1.6.8.2 nathanw ncr5380_attach(ncr_sc);
195 1.6.8.2 nathanw }
196 1.6.8.2 nathanw
197 1.6.8.2 nathanw int
198 1.6.8.2 nathanw si_intr(unit)
199 1.6.8.2 nathanw int unit;
200 1.6.8.2 nathanw {
201 1.6.8.2 nathanw struct si_softc *sc;
202 1.6.8.2 nathanw extern struct cfdriver si_cd;
203 1.6.8.2 nathanw
204 1.6.8.2 nathanw if (unit >= si_cd.cd_ndevs)
205 1.6.8.2 nathanw return 0;
206 1.6.8.2 nathanw
207 1.6.8.2 nathanw sc = si_cd.cd_devs[unit];
208 1.6.8.2 nathanw (void)ncr5380_intr(&sc->ncr_sc);
209 1.6.8.2 nathanw
210 1.6.8.2 nathanw return 0;
211 1.6.8.2 nathanw }
212 1.6.8.2 nathanw
213 1.6.8.2 nathanw /*
214 1.6.8.2 nathanw * DMA routines for news1700 machines
215 1.6.8.2 nathanw */
216 1.6.8.2 nathanw
217 1.6.8.2 nathanw void
218 1.6.8.2 nathanw si_dma_alloc(ncr_sc)
219 1.6.8.2 nathanw struct ncr5380_softc *ncr_sc;
220 1.6.8.2 nathanw {
221 1.6.8.2 nathanw struct si_softc *sc = (struct si_softc *)ncr_sc;
222 1.6.8.2 nathanw struct sci_req *sr = ncr_sc->sc_current;
223 1.6.8.2 nathanw struct scsipi_xfer *xs = sr->sr_xs;
224 1.6.8.2 nathanw struct si_dma_handle *dh;
225 1.6.8.2 nathanw int xlen, i;
226 1.6.8.2 nathanw
227 1.6.8.2 nathanw #ifdef DIAGNOSTIC
228 1.6.8.2 nathanw if (sr->sr_dma_hand != NULL)
229 1.6.8.2 nathanw panic("si_dma_alloc: already have DMA handle");
230 1.6.8.2 nathanw #endif
231 1.6.8.2 nathanw
232 1.6.8.2 nathanw /* Polled transfers shouldn't allocate a DMA handle. */
233 1.6.8.2 nathanw if (sr->sr_flags & SR_IMMED)
234 1.6.8.2 nathanw return;
235 1.6.8.2 nathanw
236 1.6.8.2 nathanw xlen = ncr_sc->sc_datalen;
237 1.6.8.2 nathanw
238 1.6.8.2 nathanw /* Make sure our caller checked sc_min_dma_len. */
239 1.6.8.2 nathanw if (xlen < MIN_DMA_LEN)
240 1.6.8.2 nathanw panic("si_dma_alloc: len=0x%x", xlen);
241 1.6.8.2 nathanw
242 1.6.8.2 nathanw /*
243 1.6.8.2 nathanw * Find free DMA handle. Guaranteed to find one since we
244 1.6.8.2 nathanw * have as many DMA handles as the driver has processes.
245 1.6.8.2 nathanw * (instances?)
246 1.6.8.2 nathanw */
247 1.6.8.2 nathanw for (i = 0; i < SCI_OPENINGS; i++) {
248 1.6.8.2 nathanw if ((sc->ncr_dma[i].dh_flags & SIDH_BUSY) == 0)
249 1.6.8.2 nathanw goto found;
250 1.6.8.2 nathanw }
251 1.6.8.2 nathanw panic("si_dma_alloc(): no free DMA handles");
252 1.6.8.2 nathanw found:
253 1.6.8.2 nathanw dh = &sc->ncr_dma[i];
254 1.6.8.2 nathanw dh->dh_flags = SIDH_BUSY;
255 1.6.8.2 nathanw dh->dh_addr = ncr_sc->sc_dataptr;
256 1.6.8.2 nathanw dh->dh_len = xlen;
257 1.6.8.2 nathanw
258 1.6.8.2 nathanw /* Remember dest buffer parameters */
259 1.6.8.2 nathanw if (xs->xs_control & XS_CTL_DATA_OUT)
260 1.6.8.2 nathanw dh->dh_flags |= SIDH_OUT;
261 1.6.8.2 nathanw
262 1.6.8.2 nathanw sr->sr_dma_hand = dh;
263 1.6.8.2 nathanw }
264 1.6.8.2 nathanw
265 1.6.8.2 nathanw void
266 1.6.8.2 nathanw si_dma_free(ncr_sc)
267 1.6.8.2 nathanw struct ncr5380_softc *ncr_sc;
268 1.6.8.2 nathanw {
269 1.6.8.2 nathanw struct sci_req *sr = ncr_sc->sc_current;
270 1.6.8.2 nathanw struct si_dma_handle *dh = sr->sr_dma_hand;
271 1.6.8.2 nathanw
272 1.6.8.2 nathanw if (dh->dh_flags & SIDH_BUSY)
273 1.6.8.2 nathanw dh->dh_flags = 0;
274 1.6.8.2 nathanw else
275 1.6.8.2 nathanw printf("si_dma_free: free'ing unused buffer\n");
276 1.6.8.2 nathanw
277 1.6.8.2 nathanw sr->sr_dma_hand = NULL;
278 1.6.8.2 nathanw }
279 1.6.8.2 nathanw
280 1.6.8.2 nathanw void
281 1.6.8.2 nathanw si_dma_setup(ncr_sc)
282 1.6.8.2 nathanw struct ncr5380_softc *ncr_sc;
283 1.6.8.2 nathanw {
284 1.6.8.2 nathanw /* Do nothing here */
285 1.6.8.2 nathanw }
286 1.6.8.2 nathanw
287 1.6.8.2 nathanw void
288 1.6.8.2 nathanw si_dma_start(ncr_sc)
289 1.6.8.2 nathanw struct ncr5380_softc *ncr_sc;
290 1.6.8.2 nathanw {
291 1.6.8.2 nathanw struct si_softc *sc = (struct si_softc *)ncr_sc;
292 1.6.8.2 nathanw volatile struct dma_regs *dmac = sc->sc_regs;
293 1.6.8.2 nathanw struct sci_req *sr = ncr_sc->sc_current;
294 1.6.8.2 nathanw struct si_dma_handle *dh = sr->sr_dma_hand;
295 1.6.8.2 nathanw u_int addr, offset, rest;
296 1.6.8.2 nathanw long len;
297 1.6.8.2 nathanw int i;
298 1.6.8.2 nathanw
299 1.6.8.2 nathanw /*
300 1.6.8.2 nathanw * Set the news68k-specific registers.
301 1.6.8.2 nathanw */
302 1.6.8.2 nathanw
303 1.6.8.2 nathanw /* reset DMAC */
304 1.6.8.2 nathanw dmac->ctl = DC_CTL_RST;
305 1.6.8.2 nathanw dmac->ctl = 0;
306 1.6.8.2 nathanw
307 1.6.8.2 nathanw addr = (u_int)dh->dh_addr;
308 1.6.8.2 nathanw offset = addr & DMAC_SEG_OFFSET;
309 1.6.8.2 nathanw len = (u_int)dh->dh_len;
310 1.6.8.2 nathanw
311 1.6.8.2 nathanw /* set DMA transfer length and offset of first segment */
312 1.6.8.2 nathanw dmac->tcnt = len;
313 1.6.8.2 nathanw dmac->offset = offset;
314 1.6.8.2 nathanw
315 1.6.8.2 nathanw /* set first DMA segment address */
316 1.6.8.2 nathanw dmac->tag = 0;
317 1.6.8.2 nathanw dmac->mapent = kvtop((caddr_t)addr) >> DMAC_SEG_SHIFT;
318 1.6.8.2 nathanw rest = DMAC_SEG_SIZE - offset;
319 1.6.8.2 nathanw addr += rest;
320 1.6.8.2 nathanw len -= rest;
321 1.6.8.2 nathanw
322 1.6.8.2 nathanw /* set all the rest segments */
323 1.6.8.2 nathanw for (i = 1; len > 0; i++) {
324 1.6.8.2 nathanw dmac->tag = i;
325 1.6.8.2 nathanw dmac->mapent = kvtop((caddr_t)addr) >> DMAC_SEG_SHIFT;
326 1.6.8.2 nathanw len -= DMAC_SEG_SIZE;
327 1.6.8.2 nathanw addr += DMAC_SEG_SIZE;
328 1.6.8.2 nathanw }
329 1.6.8.2 nathanw /* terminate TAG */
330 1.6.8.2 nathanw dmac->tag = 0;
331 1.6.8.2 nathanw
332 1.6.8.2 nathanw /*
333 1.6.8.2 nathanw * Now from the 5380-internal DMA registers.
334 1.6.8.2 nathanw */
335 1.6.8.2 nathanw if (dh->dh_flags & SIDH_OUT) {
336 1.6.8.2 nathanw NCR5380_WRITE(ncr_sc, sci_tcmd, PHASE_DATA_OUT);
337 1.6.8.2 nathanw NCR5380_WRITE(ncr_sc, sci_icmd, SCI_ICMD_DATA);
338 1.6.8.2 nathanw NCR5380_WRITE(ncr_sc, sci_mode, NCR5380_READ(ncr_sc, sci_mode)
339 1.6.8.2 nathanw | SCI_MODE_DMA);
340 1.6.8.2 nathanw
341 1.6.8.2 nathanw /* set Dir */
342 1.6.8.2 nathanw dmac->ctl = 0;
343 1.6.8.2 nathanw
344 1.6.8.2 nathanw /* start DMA */
345 1.6.8.2 nathanw NCR5380_WRITE(ncr_sc, sci_dma_send, 0);
346 1.6.8.2 nathanw dmac->ctl = DC_CTL_ENB;
347 1.6.8.2 nathanw } else {
348 1.6.8.2 nathanw NCR5380_WRITE(ncr_sc, sci_tcmd, PHASE_DATA_IN);
349 1.6.8.2 nathanw NCR5380_WRITE(ncr_sc, sci_icmd, 0);
350 1.6.8.2 nathanw NCR5380_WRITE(ncr_sc, sci_mode, NCR5380_READ(ncr_sc, sci_mode)
351 1.6.8.2 nathanw | SCI_MODE_DMA);
352 1.6.8.2 nathanw
353 1.6.8.2 nathanw /* set Dir */
354 1.6.8.2 nathanw dmac->ctl = DC_CTL_MOD;
355 1.6.8.2 nathanw
356 1.6.8.2 nathanw /* start DMA */
357 1.6.8.2 nathanw NCR5380_WRITE(ncr_sc, sci_irecv, 0);
358 1.6.8.2 nathanw dmac->ctl = DC_CTL_MOD | DC_CTL_ENB;
359 1.6.8.2 nathanw }
360 1.6.8.2 nathanw ncr_sc->sc_state |= NCR_DOINGDMA;
361 1.6.8.2 nathanw }
362 1.6.8.2 nathanw
363 1.6.8.2 nathanw /*
364 1.6.8.2 nathanw * When?
365 1.6.8.2 nathanw */
366 1.6.8.2 nathanw void
367 1.6.8.2 nathanw si_dma_poll(ncr_sc)
368 1.6.8.2 nathanw struct ncr5380_softc *ncr_sc;
369 1.6.8.2 nathanw {
370 1.6.8.2 nathanw printf("si_dma_poll\n");
371 1.6.8.2 nathanw }
372 1.6.8.2 nathanw
373 1.6.8.2 nathanw /*
374 1.6.8.2 nathanw * news68k (probabry) does not use the EOP signal.
375 1.6.8.2 nathanw */
376 1.6.8.2 nathanw void
377 1.6.8.2 nathanw si_dma_eop(ncr_sc)
378 1.6.8.2 nathanw struct ncr5380_softc *ncr_sc;
379 1.6.8.2 nathanw {
380 1.6.8.2 nathanw printf("si_dma_eop\n");
381 1.6.8.2 nathanw }
382 1.6.8.2 nathanw
383 1.6.8.2 nathanw void
384 1.6.8.2 nathanw si_dma_stop(ncr_sc)
385 1.6.8.2 nathanw struct ncr5380_softc *ncr_sc;
386 1.6.8.2 nathanw {
387 1.6.8.2 nathanw struct si_softc *sc = (struct si_softc *)ncr_sc;
388 1.6.8.2 nathanw volatile struct dma_regs *dmac = sc->sc_regs;
389 1.6.8.2 nathanw struct sci_req *sr = ncr_sc->sc_current;
390 1.6.8.2 nathanw struct si_dma_handle *dh = sr->sr_dma_hand;
391 1.6.8.2 nathanw int resid, ntrans, i;
392 1.6.8.2 nathanw
393 1.6.8.2 nathanw /* check DMAC interrupt status */
394 1.6.8.2 nathanw if ((dmac->stat & DC_ST_INT) == 0) {
395 1.6.8.2 nathanw #ifdef DEBUG
396 1.6.8.2 nathanw printf("si_dma_stop: no DMA interrupt");
397 1.6.8.2 nathanw #endif
398 1.6.8.2 nathanw return; /* XXX */
399 1.6.8.2 nathanw }
400 1.6.8.2 nathanw
401 1.6.8.2 nathanw if ((ncr_sc->sc_state & NCR_DOINGDMA) == 0) {
402 1.6.8.2 nathanw #ifdef DEBUG
403 1.6.8.2 nathanw printf("si_dma_stop: dma not running\n");
404 1.6.8.2 nathanw #endif
405 1.6.8.2 nathanw return;
406 1.6.8.2 nathanw }
407 1.6.8.2 nathanw ncr_sc->sc_state &= ~NCR_DOINGDMA;
408 1.6.8.2 nathanw
409 1.6.8.2 nathanw /* OK, have either phase mis-match or end of DMA. */
410 1.6.8.2 nathanw /* Set an impossible phase to prevent data movement? */
411 1.6.8.2 nathanw NCR5380_WRITE(ncr_sc, sci_tcmd, PHASE_INVALID);
412 1.6.8.2 nathanw
413 1.6.8.2 nathanw /* Note that timeout may have set the error flag. */
414 1.6.8.2 nathanw if (ncr_sc->sc_state & NCR_ABORTING)
415 1.6.8.2 nathanw goto out;
416 1.6.8.2 nathanw
417 1.6.8.2 nathanw /*
418 1.6.8.2 nathanw * Sometimes the FIFO buffer isn't drained when the
419 1.6.8.2 nathanw * interrupt is posted. Just loop here and hope that
420 1.6.8.2 nathanw * it will drain soon.
421 1.6.8.2 nathanw */
422 1.6.8.2 nathanw for (i = 0; i < 200000; i++) { /* 2 sec */
423 1.6.8.2 nathanw resid = dmac->tcnt;
424 1.6.8.2 nathanw if (resid == 0)
425 1.6.8.2 nathanw break;
426 1.6.8.2 nathanw DELAY(10);
427 1.6.8.2 nathanw }
428 1.6.8.2 nathanw
429 1.6.8.2 nathanw if (resid)
430 1.6.8.2 nathanw printf("si_dma_stop: resid=0x%x\n", resid);
431 1.6.8.2 nathanw
432 1.6.8.2 nathanw ntrans = dh->dh_len - resid;
433 1.6.8.2 nathanw
434 1.6.8.2 nathanw ncr_sc->sc_dataptr += ntrans;
435 1.6.8.2 nathanw ncr_sc->sc_datalen -= ntrans;
436 1.6.8.2 nathanw
437 1.6.8.2 nathanw if ((dh->dh_flags & SIDH_OUT) == 0) {
438 1.6.8.2 nathanw PCIA();
439 1.6.8.2 nathanw }
440 1.6.8.2 nathanw
441 1.6.8.2 nathanw out:
442 1.6.8.2 nathanw NCR5380_WRITE(ncr_sc, sci_mode, NCR5380_READ(ncr_sc, sci_mode) &
443 1.6.8.2 nathanw ~(SCI_MODE_DMA));
444 1.6.8.2 nathanw NCR5380_WRITE(ncr_sc, sci_icmd, 0);
445 1.6.8.2 nathanw }
446