asc_vsbus.c revision 1.16 1 1.16 matt /* $NetBSD: asc_vsbus.c,v 1.16 2000/06/05 00:09:20 matt Exp $ */
2 1.1 matt
3 1.1 matt /*-
4 1.1 matt * Copyright (c) 1998 The NetBSD Foundation, Inc.
5 1.1 matt * All rights reserved.
6 1.1 matt *
7 1.1 matt * This code is derived from software contributed to The NetBSD Foundation
8 1.1 matt * by Charles M. Hannum.
9 1.1 matt *
10 1.1 matt * Redistribution and use in source and binary forms, with or without
11 1.1 matt * modification, are permitted provided that the following conditions
12 1.1 matt * are met:
13 1.1 matt * 1. Redistributions of source code must retain the above copyright
14 1.1 matt * notice, this list of conditions and the following disclaimer.
15 1.1 matt * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 matt * notice, this list of conditions and the following disclaimer in the
17 1.1 matt * documentation and/or other materials provided with the distribution.
18 1.1 matt * 3. All advertising materials mentioning features or use of this software
19 1.1 matt * must display the following acknowledgement:
20 1.1 matt * This product includes software developed by the NetBSD
21 1.1 matt * Foundation, Inc. and its contributors.
22 1.1 matt * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.1 matt * contributors may be used to endorse or promote products derived
24 1.1 matt * from this software without specific prior written permission.
25 1.1 matt *
26 1.1 matt * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.1 matt * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.1 matt * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.1 matt * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.1 matt * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.1 matt * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.1 matt * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.1 matt * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.1 matt * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.1 matt * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.1 matt * POSSIBILITY OF SUCH DAMAGE.
37 1.1 matt */
38 1.1 matt
39 1.9 ragge #include "opt_vax46.h"
40 1.9 ragge
41 1.1 matt #include <sys/cdefs.h> /* RCS ID & Copyright macro defns */
42 1.1 matt
43 1.16 matt __KERNEL_RCSID(0, "$NetBSD: asc_vsbus.c,v 1.16 2000/06/05 00:09:20 matt Exp $");
44 1.1 matt
45 1.1 matt #include <sys/types.h>
46 1.1 matt #include <sys/param.h>
47 1.1 matt #include <sys/systm.h>
48 1.1 matt #include <sys/kernel.h>
49 1.1 matt #include <sys/errno.h>
50 1.1 matt #include <sys/ioctl.h>
51 1.1 matt #include <sys/device.h>
52 1.1 matt #include <sys/buf.h>
53 1.1 matt #include <sys/proc.h>
54 1.1 matt #include <sys/user.h>
55 1.1 matt #include <sys/reboot.h>
56 1.1 matt #include <sys/queue.h>
57 1.1 matt
58 1.1 matt #include <dev/scsipi/scsi_all.h>
59 1.1 matt #include <dev/scsipi/scsipi_all.h>
60 1.1 matt #include <dev/scsipi/scsiconf.h>
61 1.1 matt #include <dev/scsipi/scsi_message.h>
62 1.1 matt
63 1.1 matt #include <machine/bus.h>
64 1.5 matt #include <machine/vmparam.h>
65 1.1 matt
66 1.1 matt #include <dev/ic/ncr53c9xreg.h>
67 1.1 matt #include <dev/ic/ncr53c9xvar.h>
68 1.1 matt
69 1.1 matt #include <machine/cpu.h>
70 1.1 matt #include <machine/sid.h>
71 1.1 matt #include <machine/scb.h>
72 1.1 matt #include <machine/vsbus.h>
73 1.9 ragge #include <machine/clock.h> /* for SCSI ctlr ID# XXX */
74 1.1 matt
75 1.1 matt struct asc_vsbus_softc {
76 1.1 matt struct ncr53c9x_softc sc_ncr53c9x; /* Must be first */
77 1.15 matt struct evcnt sc_intrcnt; /* count interrupts */
78 1.1 matt bus_space_tag_t sc_bst; /* bus space tag */
79 1.1 matt bus_space_handle_t sc_bsh; /* bus space handle */
80 1.11 matt bus_space_handle_t sc_dirh; /* scsi direction handle */
81 1.11 matt bus_space_handle_t sc_adrh; /* scsi address handle */
82 1.4 matt bus_space_handle_t sc_ncrh; /* ncr bus space handle */
83 1.1 matt bus_dma_tag_t sc_dmat; /* bus dma tag */
84 1.1 matt bus_dmamap_t sc_dmamap;
85 1.1 matt caddr_t *sc_dmaaddr;
86 1.1 matt size_t *sc_dmalen;
87 1.1 matt size_t sc_dmasize;
88 1.1 matt unsigned int sc_flags;
89 1.6 matt #define ASC_FROMMEMORY 0x0001 /* Must be 1 */
90 1.6 matt #define ASC_DMAACTIVE 0x0002
91 1.4 matt #define ASC_MAPLOADED 0x0004
92 1.6 matt unsigned long sc_xfers;
93 1.1 matt };
94 1.1 matt
95 1.11 matt #define ASC_REG_KA46_ADR 0x0000
96 1.11 matt #define ASC_REG_KA46_DIR 0x000C
97 1.13 matt #define ASC_REG_KA49_ADR 0x0000
98 1.13 matt #define ASC_REG_KA49_DIR 0x0004
99 1.1 matt #define ASC_REG_NCR 0x0080
100 1.1 matt #define ASC_REG_END 0x00B0
101 1.1 matt
102 1.1 matt #define ASC_MAXXFERSIZE 65536
103 1.5 matt #define ASC_FREQUENCY 25000000
104 1.1 matt
105 1.1 matt static int asc_vsbus_match __P((struct device *, struct cfdata *, void *));
106 1.1 matt static void asc_vsbus_attach __P((struct device *, struct device *, void *));
107 1.1 matt
108 1.1 matt struct cfattach asc_vsbus_ca = {
109 1.1 matt sizeof(struct asc_vsbus_softc), asc_vsbus_match, asc_vsbus_attach
110 1.1 matt };
111 1.1 matt
112 1.1 matt static struct scsipi_device asc_vsbus_dev = {
113 1.1 matt NULL, /* Use the default error handler */
114 1.1 matt NULL, /* have a queue, served by this */
115 1.1 matt NULL, /* have no async handler */
116 1.1 matt NULL, /* use the default done handler */
117 1.1 matt };
118 1.1 matt
119 1.1 matt /*
120 1.1 matt * Functions and the switch for the MI code
121 1.1 matt */
122 1.1 matt static u_char asc_vsbus_read_reg __P((struct ncr53c9x_softc *, int));
123 1.1 matt static void asc_vsbus_write_reg __P((struct ncr53c9x_softc *, int, u_char));
124 1.1 matt static int asc_vsbus_dma_isintr __P((struct ncr53c9x_softc *));
125 1.1 matt static void asc_vsbus_dma_reset __P((struct ncr53c9x_softc *));
126 1.1 matt static int asc_vsbus_dma_intr __P((struct ncr53c9x_softc *));
127 1.1 matt static int asc_vsbus_dma_setup __P((struct ncr53c9x_softc *, caddr_t *,
128 1.1 matt size_t *, int, size_t *));
129 1.1 matt static void asc_vsbus_dma_go __P((struct ncr53c9x_softc *));
130 1.1 matt static void asc_vsbus_dma_stop __P((struct ncr53c9x_softc *));
131 1.1 matt static int asc_vsbus_dma_isactive __P((struct ncr53c9x_softc *));
132 1.1 matt
133 1.1 matt static struct ncr53c9x_glue asc_vsbus_glue = {
134 1.1 matt asc_vsbus_read_reg,
135 1.1 matt asc_vsbus_write_reg,
136 1.1 matt asc_vsbus_dma_isintr,
137 1.1 matt asc_vsbus_dma_reset,
138 1.1 matt asc_vsbus_dma_intr,
139 1.1 matt asc_vsbus_dma_setup,
140 1.1 matt asc_vsbus_dma_go,
141 1.1 matt asc_vsbus_dma_stop,
142 1.1 matt asc_vsbus_dma_isactive,
143 1.4 matt NULL,
144 1.1 matt };
145 1.1 matt
146 1.12 matt static u_int8_t asc_attached; /* can't have more than one asc */
147 1.12 matt
148 1.1 matt static int
149 1.1 matt asc_vsbus_match( struct device *parent, struct cfdata *cf, void *aux)
150 1.1 matt {
151 1.1 matt struct vsbus_attach_args *va = aux;
152 1.12 matt volatile u_int8_t *ncr_regs;
153 1.1 matt int dummy;
154 1.12 matt
155 1.12 matt if (asc_attached)
156 1.12 matt return 0;
157 1.1 matt
158 1.14 matt if (vax_boardtype == VAX_BTYP_46 || vax_boardtype == VAX_BTYP_48) {
159 1.14 matt if (cf->cf_loc[0] != 0x200c0080)
160 1.14 matt return 0;
161 1.14 matt #if 0
162 1.14 matt } else if (vax_boardtype == VAX_BTYP_49) {
163 1.14 matt if (cf->cf_loc[0] != 0x26000080)
164 1.14 matt return 0;
165 1.14 matt #endif
166 1.14 matt } else {
167 1.12 matt return 0;
168 1.14 matt }
169 1.12 matt
170 1.3 matt ncr_regs = (volatile u_int8_t *) va->va_addr;
171 1.1 matt
172 1.1 matt /* *** need to generate an interrupt here
173 1.1 matt * From trial and error, I've determined that an INT is generated
174 1.1 matt * only when the following sequence of events occurs:
175 1.1 matt * 1) The interrupt status register (0x05) must be read.
176 1.1 matt * 2) SCSI bus reset interrupt must be enabled
177 1.1 matt * 3) SCSI bus reset command must be sent
178 1.1 matt * 4) NOP command must be sent
179 1.1 matt */
180 1.1 matt
181 1.3 matt dummy = ncr_regs[NCR_INTR << 2] & 0xFF;
182 1.8 ragge ncr_regs[NCR_CFG1 << 2] = 0x06; /* we're ID 6, turn on INT for SCSI reset */
183 1.3 matt ncr_regs[NCR_CMD << 2] = NCRCMD_RSTSCSI; /* send the reset */
184 1.3 matt ncr_regs[NCR_CMD << 2] = NCRCMD_NOP; /* send a NOP */
185 1.1 matt DELAY(10000);
186 1.1 matt
187 1.3 matt dummy = ncr_regs[NCR_INTR << 2] & 0xFF;
188 1.3 matt return (dummy & NCRINTR_SBR) != 0;
189 1.1 matt }
190 1.1 matt
191 1.1 matt
192 1.1 matt /*
193 1.1 matt * Attach this instance, and then all the sub-devices
194 1.1 matt */
195 1.1 matt static void
196 1.1 matt asc_vsbus_attach(struct device *parent, struct device *self, void *aux)
197 1.1 matt {
198 1.1 matt struct vsbus_attach_args *va = aux;
199 1.1 matt struct asc_vsbus_softc *asc = (void *)self;
200 1.1 matt struct ncr53c9x_softc *sc = &asc->sc_ncr53c9x;
201 1.1 matt int error;
202 1.1 matt
203 1.12 matt asc_attached = 1;
204 1.1 matt /*
205 1.1 matt * Set up glue for MI code early; we use some of it here.
206 1.1 matt */
207 1.1 matt sc->sc_glue = &asc_vsbus_glue;
208 1.1 matt
209 1.1 matt asc->sc_bst = va->va_iot;
210 1.1 matt asc->sc_dmat = va->va_dmat;
211 1.1 matt
212 1.1 matt error = bus_space_map(asc->sc_bst, va->va_paddr - ASC_REG_NCR,
213 1.1 matt ASC_REG_END, 0, &asc->sc_bsh);
214 1.1 matt if (error) {
215 1.1 matt printf(": failed to map registers: error=%d\n", error);
216 1.1 matt return;
217 1.1 matt }
218 1.4 matt error = bus_space_subregion(asc->sc_bst, asc->sc_bsh, ASC_REG_NCR,
219 1.4 matt ASC_REG_END - ASC_REG_NCR, &asc->sc_ncrh);
220 1.4 matt if (error) {
221 1.4 matt printf(": failed to map ncr registers: error=%d\n", error);
222 1.4 matt return;
223 1.4 matt }
224 1.11 matt if (vax_boardtype == VAX_BTYP_46 || vax_boardtype == VAX_BTYP_48) {
225 1.11 matt error = bus_space_subregion(asc->sc_bst, asc->sc_bsh,
226 1.11 matt ASC_REG_KA46_ADR, sizeof(u_int32_t), &asc->sc_adrh);
227 1.11 matt if (error) {
228 1.11 matt printf(": failed to map adr register: error=%d\n",
229 1.11 matt error);
230 1.11 matt return;
231 1.11 matt }
232 1.11 matt error = bus_space_subregion(asc->sc_bst, asc->sc_bsh,
233 1.11 matt ASC_REG_KA46_DIR, sizeof(u_int32_t), &asc->sc_dirh);
234 1.11 matt if (error) {
235 1.11 matt printf(": failed to map dir register: error=%d\n",
236 1.11 matt error);
237 1.11 matt return;
238 1.11 matt }
239 1.11 matt } else {
240 1.11 matt /* This is a gross and disgusting kludge but it'll
241 1.11 matt * save a bunch of ugly code. Unlike the VS4000/60,
242 1.11 matt * the SCSI Address and direction registers are not
243 1.11 matt * near the SCSI NCR registers and are inside the
244 1.11 matt * block of general VAXstation registers. So we grab
245 1.11 matt * them from there and knowing the internals of the
246 1.11 matt * bus_space implementation, we cast to bus_space_handles.
247 1.11 matt */
248 1.11 matt struct vsbus_softc *vsc = (struct vsbus_softc *) parent;
249 1.11 matt asc->sc_adrh = (bus_space_handle_t) (vsc->sc_vsregs + ASC_REG_KA49_ADR);
250 1.11 matt asc->sc_dirh = (bus_space_handle_t) (vsc->sc_vsregs + ASC_REG_KA49_DIR);
251 1.14 matt #if 0
252 1.14 matt printf("\n%s: adrh=0x%08lx dirh=0x%08lx", self->dv_xname,
253 1.14 matt asc->sc_adrh, asc->sc_dirh);
254 1.14 matt ncr53c9x_debug = NCR_SHOWDMA|NCR_SHOWINTS|NCR_SHOWCMDS|NCR_SHOWPHASE|NCR_SHOWSTART|NCR_SHOWMSGS;
255 1.14 matt #endif
256 1.11 matt }
257 1.4 matt error = bus_dmamap_create(asc->sc_dmat, ASC_MAXXFERSIZE, 1,
258 1.4 matt ASC_MAXXFERSIZE, 0, BUS_DMA_NOWAIT, &asc->sc_dmamap);
259 1.1 matt
260 1.9 ragge switch (vax_boardtype) {
261 1.9 ragge #if defined(VAX46)
262 1.9 ragge case VAX_BTYP_46:
263 1.9 ragge sc->sc_id = (clk_page[0xbc/2] >> clk_tweak) & 7;
264 1.9 ragge break;
265 1.9 ragge #endif
266 1.9 ragge default:
267 1.9 ragge sc->sc_id = 6; /* XXX need to get this from VMB */
268 1.9 ragge break;
269 1.9 ragge }
270 1.10 matt
271 1.1 matt sc->sc_freq = ASC_FREQUENCY;
272 1.1 matt
273 1.1 matt /* gimme Mhz */
274 1.1 matt sc->sc_freq /= 1000000;
275 1.1 matt
276 1.4 matt scb_vecalloc(va->va_cvec, (void (*)(void *)) ncr53c9x_intr,
277 1.15 matt &asc->sc_ncr53c9x, SCB_ISTACK, &asc->sc_intrcnt);
278 1.16 matt evcnt_attach_dynamic(&asc->sc_intrcnt, EVCNT_TYPE_INTR, NULL,
279 1.16 matt self->dv_xname, "intr");
280 1.1 matt
281 1.1 matt /*
282 1.1 matt * XXX More of this should be in ncr53c9x_attach(), but
283 1.1 matt * XXX should we really poke around the chip that much in
284 1.1 matt * XXX the MI code? Think about this more...
285 1.1 matt */
286 1.1 matt
287 1.1 matt /*
288 1.1 matt * Set up static configuration info.
289 1.1 matt */
290 1.1 matt sc->sc_cfg1 = sc->sc_id | NCRCFG1_PARENB;
291 1.1 matt sc->sc_cfg2 = NCRCFG2_SCSI2;
292 1.4 matt sc->sc_cfg3 = 0;
293 1.1 matt sc->sc_rev = NCR_VARIANT_NCR53C94;
294 1.1 matt
295 1.1 matt /*
296 1.1 matt * XXX minsync and maxxfer _should_ be set up in MI code,
297 1.1 matt * XXX but it appears to have some dependency on what sort
298 1.1 matt * XXX of DMA we're hooked up to, etc.
299 1.1 matt */
300 1.1 matt
301 1.1 matt /*
302 1.1 matt * This is the value used to start sync negotiations
303 1.1 matt * Note that the NCR register "SYNCTP" is programmed
304 1.1 matt * in "clocks per byte", and has a minimum value of 4.
305 1.1 matt * The SCSI period used in negotiation is one-fourth
306 1.1 matt * of the time (in nanoseconds) needed to transfer one byte.
307 1.1 matt * Since the chip's clock is given in MHz, we have the following
308 1.1 matt * formula: 4 * period = (1000 / freq) * 4
309 1.1 matt */
310 1.1 matt sc->sc_minsync = (1000 / sc->sc_freq);
311 1.5 matt sc->sc_maxxfer = 63 * 1024;
312 1.1 matt
313 1.3 matt printf("\n%s", self->dv_xname); /* Pretty print */
314 1.3 matt
315 1.1 matt /* Do the common parts of attachment. */
316 1.1 matt sc->sc_adapter.scsipi_cmd = ncr53c9x_scsi_cmd;
317 1.1 matt sc->sc_adapter.scsipi_minphys = minphys;
318 1.1 matt ncr53c9x_attach(sc, &asc_vsbus_dev);
319 1.1 matt }
320 1.1 matt
321 1.1 matt /*
322 1.1 matt * Glue functions.
323 1.1 matt */
324 1.1 matt
325 1.1 matt static u_char
326 1.1 matt asc_vsbus_read_reg(struct ncr53c9x_softc *sc, int reg)
327 1.1 matt {
328 1.1 matt struct asc_vsbus_softc *asc = (struct asc_vsbus_softc *)sc;
329 1.1 matt
330 1.4 matt return bus_space_read_1(asc->sc_bst, asc->sc_ncrh,
331 1.4 matt reg * sizeof(u_int32_t));
332 1.1 matt }
333 1.1 matt
334 1.1 matt static void
335 1.1 matt asc_vsbus_write_reg(sc, reg, val)
336 1.1 matt struct ncr53c9x_softc *sc;
337 1.1 matt int reg;
338 1.1 matt u_char val;
339 1.1 matt {
340 1.1 matt struct asc_vsbus_softc *asc = (struct asc_vsbus_softc *)sc;
341 1.1 matt
342 1.4 matt bus_space_write_1(asc->sc_bst, asc->sc_ncrh,
343 1.4 matt reg * sizeof(u_int32_t), val);
344 1.1 matt }
345 1.1 matt
346 1.1 matt static int
347 1.1 matt asc_vsbus_dma_isintr(sc)
348 1.1 matt struct ncr53c9x_softc *sc;
349 1.1 matt {
350 1.1 matt struct asc_vsbus_softc *asc = (struct asc_vsbus_softc *)sc;
351 1.4 matt return bus_space_read_1(asc->sc_bst, asc->sc_ncrh,
352 1.4 matt NCR_STAT * sizeof(u_int32_t)) & NCRSTAT_INT;
353 1.1 matt }
354 1.1 matt
355 1.1 matt static void
356 1.1 matt asc_vsbus_dma_reset(sc)
357 1.1 matt struct ncr53c9x_softc *sc;
358 1.1 matt {
359 1.1 matt struct asc_vsbus_softc *asc = (struct asc_vsbus_softc *)sc;
360 1.1 matt
361 1.4 matt if (asc->sc_flags & ASC_MAPLOADED)
362 1.4 matt bus_dmamap_unload(asc->sc_dmat, asc->sc_dmamap);
363 1.4 matt asc->sc_flags &= ~(ASC_DMAACTIVE|ASC_MAPLOADED);
364 1.1 matt }
365 1.1 matt
366 1.1 matt static int
367 1.1 matt asc_vsbus_dma_intr(sc)
368 1.1 matt struct ncr53c9x_softc *sc;
369 1.1 matt {
370 1.1 matt struct asc_vsbus_softc *asc = (struct asc_vsbus_softc *)sc;
371 1.4 matt u_int tcl, tcm;
372 1.4 matt int trans, resid;
373 1.4 matt
374 1.4 matt if ((asc->sc_flags & ASC_DMAACTIVE) == 0)
375 1.4 matt panic("asc_vsbus_dma_intr: DMA wasn't active");
376 1.4 matt
377 1.4 matt asc->sc_flags &= ~ASC_DMAACTIVE;
378 1.4 matt
379 1.4 matt if (asc->sc_dmasize == 0) {
380 1.4 matt /* A "Transfer Pad" operation completed */
381 1.4 matt tcl = NCR_READ_REG(sc, NCR_TCL);
382 1.4 matt tcm = NCR_READ_REG(sc, NCR_TCM);
383 1.4 matt NCR_DMA(("asc_vsbus_intr: discarded %d bytes (tcl=%d, tcm=%d)\n",
384 1.4 matt tcl | (tcm << 8), tcl, tcm));
385 1.4 matt return 0;
386 1.4 matt }
387 1.4 matt
388 1.4 matt resid = 0;
389 1.4 matt if ((resid = (NCR_READ_REG(sc, NCR_FFLAG) & NCRFIFO_FF)) != 0) {
390 1.4 matt NCR_DMA(("asc_vsbus_intr: empty FIFO of %d ", resid));
391 1.4 matt DELAY(1);
392 1.4 matt }
393 1.6 matt if (asc->sc_flags & ASC_MAPLOADED) {
394 1.6 matt bus_dmamap_sync(asc->sc_dmat, asc->sc_dmamap,
395 1.6 matt 0, asc->sc_dmasize,
396 1.6 matt asc->sc_flags & ASC_FROMMEMORY
397 1.6 matt ? BUS_DMASYNC_POSTWRITE
398 1.6 matt : BUS_DMASYNC_POSTREAD);
399 1.4 matt bus_dmamap_unload(asc->sc_dmat, asc->sc_dmamap);
400 1.6 matt }
401 1.4 matt asc->sc_flags &= ~ASC_MAPLOADED;
402 1.4 matt
403 1.4 matt resid += (tcl = NCR_READ_REG(sc, NCR_TCL));
404 1.4 matt resid += (tcm = NCR_READ_REG(sc, NCR_TCM)) << 8;
405 1.4 matt
406 1.4 matt trans = asc->sc_dmasize - resid;
407 1.4 matt if (trans < 0) { /* transferred < 0 ? */
408 1.5 matt printf("asc_vsbus_intr: xfer (%d) > req (%d)\n",
409 1.4 matt trans, asc->sc_dmasize);
410 1.4 matt trans = asc->sc_dmasize;
411 1.4 matt }
412 1.4 matt NCR_DMA(("asc_vsbus_intr: tcl=%d, tcm=%d; trans=%d, resid=%d\n",
413 1.4 matt tcl, tcm, trans, resid));
414 1.1 matt
415 1.4 matt *asc->sc_dmalen -= trans;
416 1.4 matt *asc->sc_dmaaddr += trans;
417 1.4 matt
418 1.6 matt asc->sc_xfers++;
419 1.1 matt return 0;
420 1.1 matt }
421 1.1 matt
422 1.1 matt static int
423 1.1 matt asc_vsbus_dma_setup(struct ncr53c9x_softc *sc, caddr_t *addr, size_t *len,
424 1.1 matt int datain, size_t *dmasize)
425 1.1 matt {
426 1.1 matt struct asc_vsbus_softc *asc = (struct asc_vsbus_softc *)sc;
427 1.1 matt
428 1.1 matt asc->sc_dmaaddr = addr;
429 1.1 matt asc->sc_dmalen = len;
430 1.1 matt if (datain) {
431 1.6 matt asc->sc_flags &= ~ASC_FROMMEMORY;
432 1.1 matt } else {
433 1.6 matt asc->sc_flags |= ASC_FROMMEMORY;
434 1.1 matt }
435 1.5 matt if ((vaddr_t) *asc->sc_dmaaddr < VM_MIN_KERNEL_ADDRESS)
436 1.5 matt panic("asc_vsbus_dma_setup: dma address (%p) outside of kernel",
437 1.5 matt *asc->sc_dmaaddr);
438 1.1 matt
439 1.1 matt NCR_DMA(("%s: start %d@%p,%d\n", sc->sc_dev.dv_xname,
440 1.6 matt (int)*asc->sc_dmalen, *asc->sc_dmaaddr, (asc->sc_flags & ASC_FROMMEMORY)));
441 1.1 matt *dmasize = asc->sc_dmasize = min(*dmasize, ASC_MAXXFERSIZE);
442 1.1 matt
443 1.1 matt if (asc->sc_dmasize) {
444 1.1 matt if (bus_dmamap_load(asc->sc_dmat, asc->sc_dmamap,
445 1.1 matt *asc->sc_dmaaddr, asc->sc_dmasize,
446 1.1 matt NULL /* kernel address */,
447 1.7 matt BUS_DMA_NOWAIT|VAX_BUS_DMA_SPILLPAGE))
448 1.1 matt panic("%s: cannot load dma map", sc->sc_dev.dv_xname);
449 1.1 matt bus_dmamap_sync(asc->sc_dmat, asc->sc_dmamap,
450 1.6 matt 0, asc->sc_dmasize,
451 1.6 matt asc->sc_flags & ASC_FROMMEMORY
452 1.6 matt ? BUS_DMASYNC_PREWRITE
453 1.6 matt : BUS_DMASYNC_PREREAD);
454 1.11 matt bus_space_write_4(asc->sc_bst, asc->sc_adrh, 0,
455 1.1 matt asc->sc_dmamap->dm_segs[0].ds_addr);
456 1.11 matt bus_space_write_4(asc->sc_bst, asc->sc_dirh, 0,
457 1.6 matt asc->sc_flags & ASC_FROMMEMORY);
458 1.14 matt NCR_DMA(("%s: dma-load %lu@0x%08lx\n", sc->sc_dev.dv_xname,
459 1.14 matt asc->sc_dmamap->dm_segs[0].ds_len,
460 1.14 matt asc->sc_dmamap->dm_segs[0].ds_addr));
461 1.4 matt asc->sc_flags |= ASC_MAPLOADED;
462 1.1 matt }
463 1.1 matt
464 1.1 matt return 0;
465 1.1 matt }
466 1.1 matt
467 1.1 matt static void
468 1.1 matt asc_vsbus_dma_go(struct ncr53c9x_softc *sc)
469 1.1 matt {
470 1.1 matt struct asc_vsbus_softc *asc = (struct asc_vsbus_softc *)sc;
471 1.1 matt
472 1.4 matt asc->sc_flags |= ASC_DMAACTIVE;
473 1.1 matt }
474 1.1 matt
475 1.1 matt static void
476 1.1 matt asc_vsbus_dma_stop(struct ncr53c9x_softc *sc)
477 1.1 matt {
478 1.1 matt struct asc_vsbus_softc *asc = (struct asc_vsbus_softc *)sc;
479 1.1 matt
480 1.6 matt if (asc->sc_flags & ASC_MAPLOADED) {
481 1.6 matt bus_dmamap_sync(asc->sc_dmat, asc->sc_dmamap,
482 1.6 matt 0, asc->sc_dmasize,
483 1.6 matt asc->sc_flags & ASC_FROMMEMORY
484 1.6 matt ? BUS_DMASYNC_POSTWRITE
485 1.6 matt : BUS_DMASYNC_POSTREAD);
486 1.4 matt bus_dmamap_unload(asc->sc_dmat, asc->sc_dmamap);
487 1.6 matt }
488 1.4 matt
489 1.4 matt asc->sc_flags &= ~(ASC_DMAACTIVE|ASC_MAPLOADED);
490 1.1 matt }
491 1.1 matt
492 1.1 matt static int
493 1.1 matt asc_vsbus_dma_isactive(struct ncr53c9x_softc *sc)
494 1.1 matt {
495 1.1 matt struct asc_vsbus_softc *asc = (struct asc_vsbus_softc *)sc;
496 1.1 matt
497 1.1 matt return (asc->sc_flags & ASC_DMAACTIVE) != 0;
498 1.1 matt }
499