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