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