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