asc_vsbus.c revision 1.24.8.3 1 1.24.8.3 nathanw /* $NetBSD: asc_vsbus.c,v 1.24.8.3 2002/10/18 02:40: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.3 nathanw __KERNEL_RCSID(0, "$NetBSD: asc_vsbus.c,v 1.24.8.3 2002/10/18 02:40: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.3 nathanw CFATTACH_DECL(asc_vsbus, sizeof(struct asc_vsbus_softc),
109 1.24.8.3 nathanw asc_vsbus_match, asc_vsbus_attach, NULL, NULL);
110 1.24.8.2 nathanw
111 1.24.8.2 nathanw /*
112 1.24.8.2 nathanw * Functions and the switch for the MI code
113 1.24.8.2 nathanw */
114 1.24.8.2 nathanw static u_char asc_vsbus_read_reg(struct ncr53c9x_softc *, int);
115 1.24.8.2 nathanw static void asc_vsbus_write_reg(struct ncr53c9x_softc *, int, u_char);
116 1.24.8.2 nathanw static int asc_vsbus_dma_isintr(struct ncr53c9x_softc *);
117 1.24.8.2 nathanw static void asc_vsbus_dma_reset(struct ncr53c9x_softc *);
118 1.24.8.2 nathanw static int asc_vsbus_dma_intr(struct ncr53c9x_softc *);
119 1.24.8.2 nathanw static int asc_vsbus_dma_setup(struct ncr53c9x_softc *, caddr_t *,
120 1.24.8.2 nathanw size_t *, int, size_t *);
121 1.24.8.2 nathanw static void asc_vsbus_dma_go(struct ncr53c9x_softc *);
122 1.24.8.2 nathanw static void asc_vsbus_dma_stop(struct ncr53c9x_softc *);
123 1.24.8.2 nathanw static int asc_vsbus_dma_isactive(struct ncr53c9x_softc *);
124 1.24.8.2 nathanw
125 1.24.8.2 nathanw static struct ncr53c9x_glue asc_vsbus_glue = {
126 1.24.8.2 nathanw asc_vsbus_read_reg,
127 1.24.8.2 nathanw asc_vsbus_write_reg,
128 1.24.8.2 nathanw asc_vsbus_dma_isintr,
129 1.24.8.2 nathanw asc_vsbus_dma_reset,
130 1.24.8.2 nathanw asc_vsbus_dma_intr,
131 1.24.8.2 nathanw asc_vsbus_dma_setup,
132 1.24.8.2 nathanw asc_vsbus_dma_go,
133 1.24.8.2 nathanw asc_vsbus_dma_stop,
134 1.24.8.2 nathanw asc_vsbus_dma_isactive,
135 1.24.8.2 nathanw NULL,
136 1.24.8.2 nathanw };
137 1.24.8.2 nathanw
138 1.24.8.2 nathanw static u_int8_t asc_attached; /* can't have more than one asc */
139 1.24.8.2 nathanw
140 1.24.8.2 nathanw static int
141 1.24.8.2 nathanw asc_vsbus_match( struct device *parent, struct cfdata *cf, void *aux)
142 1.24.8.2 nathanw {
143 1.24.8.2 nathanw struct vsbus_attach_args *va = aux;
144 1.24.8.2 nathanw volatile u_int8_t *ncr_regs;
145 1.24.8.2 nathanw int dummy;
146 1.24.8.2 nathanw
147 1.24.8.2 nathanw if (asc_attached)
148 1.24.8.2 nathanw return 0;
149 1.24.8.2 nathanw
150 1.24.8.2 nathanw if (vax_boardtype == VAX_BTYP_46 || vax_boardtype == VAX_BTYP_48) {
151 1.24.8.2 nathanw if (cf->cf_loc[0] != 0x200c0080)
152 1.24.8.2 nathanw return 0;
153 1.24.8.2 nathanw } else if (vax_boardtype == VAX_BTYP_49 ||
154 1.24.8.2 nathanw vax_boardtype == VAX_BTYP_53) {
155 1.24.8.2 nathanw if (cf->cf_loc[0] != 0x26000080)
156 1.24.8.2 nathanw return 0;
157 1.24.8.2 nathanw } else {
158 1.24.8.2 nathanw return 0;
159 1.24.8.2 nathanw }
160 1.24.8.2 nathanw
161 1.24.8.2 nathanw ncr_regs = (volatile u_int8_t *) va->va_addr;
162 1.24.8.2 nathanw
163 1.24.8.2 nathanw /* *** need to generate an interrupt here
164 1.24.8.2 nathanw * From trial and error, I've determined that an INT is generated
165 1.24.8.2 nathanw * only when the following sequence of events occurs:
166 1.24.8.2 nathanw * 1) The interrupt status register (0x05) must be read.
167 1.24.8.2 nathanw * 2) SCSI bus reset interrupt must be enabled
168 1.24.8.2 nathanw * 3) SCSI bus reset command must be sent
169 1.24.8.2 nathanw * 4) NOP command must be sent
170 1.24.8.2 nathanw */
171 1.24.8.2 nathanw
172 1.24.8.2 nathanw dummy = ncr_regs[NCR_INTR << 2] & 0xFF;
173 1.24.8.2 nathanw ncr_regs[NCR_CFG1 << 2] = 0x06; /* we're ID 6, turn on INT for SCSI reset */
174 1.24.8.2 nathanw ncr_regs[NCR_CMD << 2] = NCRCMD_RSTSCSI; /* send the reset */
175 1.24.8.2 nathanw ncr_regs[NCR_CMD << 2] = NCRCMD_NOP; /* send a NOP */
176 1.24.8.2 nathanw DELAY(10000);
177 1.24.8.2 nathanw
178 1.24.8.2 nathanw dummy = ncr_regs[NCR_INTR << 2] & 0xFF;
179 1.24.8.2 nathanw return (dummy & NCRINTR_SBR) != 0;
180 1.24.8.2 nathanw }
181 1.24.8.2 nathanw
182 1.24.8.2 nathanw
183 1.24.8.2 nathanw /*
184 1.24.8.2 nathanw * Attach this instance, and then all the sub-devices
185 1.24.8.2 nathanw */
186 1.24.8.2 nathanw static void
187 1.24.8.2 nathanw asc_vsbus_attach(struct device *parent, struct device *self, void *aux)
188 1.24.8.2 nathanw {
189 1.24.8.2 nathanw struct vsbus_attach_args *va = aux;
190 1.24.8.2 nathanw struct asc_vsbus_softc *asc = (void *)self;
191 1.24.8.2 nathanw struct ncr53c9x_softc *sc = &asc->sc_ncr53c9x;
192 1.24.8.2 nathanw int error;
193 1.24.8.2 nathanw
194 1.24.8.2 nathanw asc_attached = 1;
195 1.24.8.2 nathanw /*
196 1.24.8.2 nathanw * Set up glue for MI code early; we use some of it here.
197 1.24.8.2 nathanw */
198 1.24.8.2 nathanw sc->sc_glue = &asc_vsbus_glue;
199 1.24.8.2 nathanw
200 1.24.8.2 nathanw asc->sc_bst = va->va_iot;
201 1.24.8.2 nathanw asc->sc_dmat = va->va_dmat;
202 1.24.8.2 nathanw
203 1.24.8.2 nathanw error = bus_space_map(asc->sc_bst, va->va_paddr - ASC_REG_NCR,
204 1.24.8.2 nathanw ASC_REG_END, 0, &asc->sc_bsh);
205 1.24.8.2 nathanw if (error) {
206 1.24.8.2 nathanw printf(": failed to map registers: error=%d\n", error);
207 1.24.8.2 nathanw return;
208 1.24.8.2 nathanw }
209 1.24.8.2 nathanw error = bus_space_subregion(asc->sc_bst, asc->sc_bsh, ASC_REG_NCR,
210 1.24.8.2 nathanw ASC_REG_END - ASC_REG_NCR, &asc->sc_ncrh);
211 1.24.8.2 nathanw if (error) {
212 1.24.8.2 nathanw printf(": failed to map ncr registers: error=%d\n", error);
213 1.24.8.2 nathanw return;
214 1.24.8.2 nathanw }
215 1.24.8.2 nathanw if (vax_boardtype == VAX_BTYP_46 || vax_boardtype == VAX_BTYP_48) {
216 1.24.8.2 nathanw error = bus_space_subregion(asc->sc_bst, asc->sc_bsh,
217 1.24.8.2 nathanw ASC_REG_KA46_ADR, sizeof(u_int32_t), &asc->sc_adrh);
218 1.24.8.2 nathanw if (error) {
219 1.24.8.2 nathanw printf(": failed to map adr register: error=%d\n",
220 1.24.8.2 nathanw error);
221 1.24.8.2 nathanw return;
222 1.24.8.2 nathanw }
223 1.24.8.2 nathanw error = bus_space_subregion(asc->sc_bst, asc->sc_bsh,
224 1.24.8.2 nathanw ASC_REG_KA46_DIR, sizeof(u_int32_t), &asc->sc_dirh);
225 1.24.8.2 nathanw if (error) {
226 1.24.8.2 nathanw printf(": failed to map dir register: error=%d\n",
227 1.24.8.2 nathanw error);
228 1.24.8.2 nathanw return;
229 1.24.8.2 nathanw }
230 1.24.8.2 nathanw } else {
231 1.24.8.2 nathanw /* This is a gross and disgusting kludge but it'll
232 1.24.8.2 nathanw * save a bunch of ugly code. Unlike the VS4000/60,
233 1.24.8.2 nathanw * the SCSI Address and direction registers are not
234 1.24.8.2 nathanw * near the SCSI NCR registers and are inside the
235 1.24.8.2 nathanw * block of general VAXstation registers. So we grab
236 1.24.8.2 nathanw * them from there and knowing the internals of the
237 1.24.8.2 nathanw * bus_space implementation, we cast to bus_space_handles.
238 1.24.8.2 nathanw */
239 1.24.8.2 nathanw struct vsbus_softc *vsc = (struct vsbus_softc *) parent;
240 1.24.8.2 nathanw asc->sc_adrh = (bus_space_handle_t) (vsc->sc_vsregs + ASC_REG_KA49_ADR);
241 1.24.8.2 nathanw asc->sc_dirh = (bus_space_handle_t) (vsc->sc_vsregs + ASC_REG_KA49_DIR);
242 1.24.8.2 nathanw #if 0
243 1.24.8.2 nathanw printf("\n%s: adrh=0x%08lx dirh=0x%08lx", self->dv_xname,
244 1.24.8.2 nathanw asc->sc_adrh, asc->sc_dirh);
245 1.24.8.2 nathanw ncr53c9x_debug = NCR_SHOWDMA|NCR_SHOWINTS|NCR_SHOWCMDS|NCR_SHOWPHASE|NCR_SHOWSTART|NCR_SHOWMSGS;
246 1.24.8.2 nathanw #endif
247 1.24.8.2 nathanw }
248 1.24.8.2 nathanw error = bus_dmamap_create(asc->sc_dmat, ASC_MAXXFERSIZE, 1,
249 1.24.8.2 nathanw ASC_MAXXFERSIZE, 0, BUS_DMA_NOWAIT, &asc->sc_dmamap);
250 1.24.8.2 nathanw
251 1.24.8.2 nathanw switch (vax_boardtype) {
252 1.24.8.2 nathanw #if VAX46 || VAXANY
253 1.24.8.2 nathanw case VAX_BTYP_46:
254 1.24.8.2 nathanw sc->sc_id = (clk_page[0xbc/2] >> clk_tweak) & 7;
255 1.24.8.2 nathanw break;
256 1.24.8.2 nathanw #endif
257 1.24.8.2 nathanw default:
258 1.24.8.2 nathanw sc->sc_id = 6; /* XXX need to get this from VMB */
259 1.24.8.2 nathanw break;
260 1.24.8.2 nathanw }
261 1.24.8.2 nathanw
262 1.24.8.2 nathanw sc->sc_freq = ASC_FREQUENCY;
263 1.24.8.2 nathanw
264 1.24.8.2 nathanw /* gimme Mhz */
265 1.24.8.2 nathanw sc->sc_freq /= 1000000;
266 1.24.8.2 nathanw
267 1.24.8.2 nathanw scb_vecalloc(va->va_cvec, (void (*)(void *)) ncr53c9x_intr,
268 1.24.8.2 nathanw &asc->sc_ncr53c9x, SCB_ISTACK, &asc->sc_intrcnt);
269 1.24.8.2 nathanw evcnt_attach_dynamic(&asc->sc_intrcnt, EVCNT_TYPE_INTR, NULL,
270 1.24.8.2 nathanw self->dv_xname, "intr");
271 1.24.8.2 nathanw
272 1.24.8.2 nathanw /*
273 1.24.8.2 nathanw * XXX More of this should be in ncr53c9x_attach(), but
274 1.24.8.2 nathanw * XXX should we really poke around the chip that much in
275 1.24.8.2 nathanw * XXX the MI code? Think about this more...
276 1.24.8.2 nathanw */
277 1.24.8.2 nathanw
278 1.24.8.2 nathanw /*
279 1.24.8.2 nathanw * Set up static configuration info.
280 1.24.8.2 nathanw */
281 1.24.8.2 nathanw sc->sc_cfg1 = sc->sc_id | NCRCFG1_PARENB;
282 1.24.8.2 nathanw sc->sc_cfg2 = NCRCFG2_SCSI2;
283 1.24.8.2 nathanw sc->sc_cfg3 = 0;
284 1.24.8.2 nathanw sc->sc_rev = NCR_VARIANT_NCR53C94;
285 1.24.8.2 nathanw
286 1.24.8.2 nathanw /*
287 1.24.8.2 nathanw * XXX minsync and maxxfer _should_ be set up in MI code,
288 1.24.8.2 nathanw * XXX but it appears to have some dependency on what sort
289 1.24.8.2 nathanw * XXX of DMA we're hooked up to, etc.
290 1.24.8.2 nathanw */
291 1.24.8.2 nathanw
292 1.24.8.2 nathanw /*
293 1.24.8.2 nathanw * This is the value used to start sync negotiations
294 1.24.8.2 nathanw * Note that the NCR register "SYNCTP" is programmed
295 1.24.8.2 nathanw * in "clocks per byte", and has a minimum value of 4.
296 1.24.8.2 nathanw * The SCSI period used in negotiation is one-fourth
297 1.24.8.2 nathanw * of the time (in nanoseconds) needed to transfer one byte.
298 1.24.8.2 nathanw * Since the chip's clock is given in MHz, we have the following
299 1.24.8.2 nathanw * formula: 4 * period = (1000 / freq) * 4
300 1.24.8.2 nathanw */
301 1.24.8.2 nathanw sc->sc_minsync = (1000 / sc->sc_freq);
302 1.24.8.2 nathanw sc->sc_maxxfer = 64 * 1024;
303 1.24.8.2 nathanw
304 1.24.8.2 nathanw printf("\n%s", self->dv_xname); /* Pretty print */
305 1.24.8.2 nathanw
306 1.24.8.2 nathanw /* Do the common parts of attachment. */
307 1.24.8.2 nathanw sc->sc_adapter.adapt_minphys = minphys;
308 1.24.8.2 nathanw sc->sc_adapter.adapt_request = ncr53c9x_scsipi_request;
309 1.24.8.2 nathanw ncr53c9x_attach(sc);
310 1.24.8.2 nathanw }
311 1.24.8.2 nathanw
312 1.24.8.2 nathanw /*
313 1.24.8.2 nathanw * Glue functions.
314 1.24.8.2 nathanw */
315 1.24.8.2 nathanw
316 1.24.8.2 nathanw static u_char
317 1.24.8.2 nathanw asc_vsbus_read_reg(struct ncr53c9x_softc *sc, int reg)
318 1.24.8.2 nathanw {
319 1.24.8.2 nathanw struct asc_vsbus_softc *asc = (struct asc_vsbus_softc *)sc;
320 1.24.8.2 nathanw
321 1.24.8.2 nathanw return bus_space_read_1(asc->sc_bst, asc->sc_ncrh,
322 1.24.8.2 nathanw reg * sizeof(u_int32_t));
323 1.24.8.2 nathanw }
324 1.24.8.2 nathanw
325 1.24.8.2 nathanw static void
326 1.24.8.2 nathanw asc_vsbus_write_reg(sc, reg, val)
327 1.24.8.2 nathanw struct ncr53c9x_softc *sc;
328 1.24.8.2 nathanw int reg;
329 1.24.8.2 nathanw u_char val;
330 1.24.8.2 nathanw {
331 1.24.8.2 nathanw struct asc_vsbus_softc *asc = (struct asc_vsbus_softc *)sc;
332 1.24.8.2 nathanw
333 1.24.8.2 nathanw bus_space_write_1(asc->sc_bst, asc->sc_ncrh,
334 1.24.8.2 nathanw reg * sizeof(u_int32_t), val);
335 1.24.8.2 nathanw }
336 1.24.8.2 nathanw
337 1.24.8.2 nathanw static int
338 1.24.8.2 nathanw asc_vsbus_dma_isintr(sc)
339 1.24.8.2 nathanw struct ncr53c9x_softc *sc;
340 1.24.8.2 nathanw {
341 1.24.8.2 nathanw struct asc_vsbus_softc *asc = (struct asc_vsbus_softc *)sc;
342 1.24.8.2 nathanw return bus_space_read_1(asc->sc_bst, asc->sc_ncrh,
343 1.24.8.2 nathanw NCR_STAT * sizeof(u_int32_t)) & NCRSTAT_INT;
344 1.24.8.2 nathanw }
345 1.24.8.2 nathanw
346 1.24.8.2 nathanw static void
347 1.24.8.2 nathanw asc_vsbus_dma_reset(sc)
348 1.24.8.2 nathanw struct ncr53c9x_softc *sc;
349 1.24.8.2 nathanw {
350 1.24.8.2 nathanw struct asc_vsbus_softc *asc = (struct asc_vsbus_softc *)sc;
351 1.24.8.2 nathanw
352 1.24.8.2 nathanw if (asc->sc_flags & ASC_MAPLOADED)
353 1.24.8.2 nathanw bus_dmamap_unload(asc->sc_dmat, asc->sc_dmamap);
354 1.24.8.2 nathanw asc->sc_flags &= ~(ASC_DMAACTIVE|ASC_MAPLOADED);
355 1.24.8.2 nathanw }
356 1.24.8.2 nathanw
357 1.24.8.2 nathanw static int
358 1.24.8.2 nathanw asc_vsbus_dma_intr(sc)
359 1.24.8.2 nathanw struct ncr53c9x_softc *sc;
360 1.24.8.2 nathanw {
361 1.24.8.2 nathanw struct asc_vsbus_softc *asc = (struct asc_vsbus_softc *)sc;
362 1.24.8.2 nathanw u_int tcl, tcm;
363 1.24.8.2 nathanw int trans, resid;
364 1.24.8.2 nathanw
365 1.24.8.2 nathanw if ((asc->sc_flags & ASC_DMAACTIVE) == 0)
366 1.24.8.2 nathanw panic("asc_vsbus_dma_intr: DMA wasn't active");
367 1.24.8.2 nathanw
368 1.24.8.2 nathanw asc->sc_flags &= ~ASC_DMAACTIVE;
369 1.24.8.2 nathanw
370 1.24.8.2 nathanw if (asc->sc_dmasize == 0) {
371 1.24.8.2 nathanw /* A "Transfer Pad" operation completed */
372 1.24.8.2 nathanw tcl = NCR_READ_REG(sc, NCR_TCL);
373 1.24.8.2 nathanw tcm = NCR_READ_REG(sc, NCR_TCM);
374 1.24.8.2 nathanw NCR_DMA(("asc_vsbus_intr: discarded %d bytes (tcl=%d, tcm=%d)\n",
375 1.24.8.2 nathanw tcl | (tcm << 8), tcl, tcm));
376 1.24.8.2 nathanw return 0;
377 1.24.8.2 nathanw }
378 1.24.8.2 nathanw
379 1.24.8.2 nathanw resid = 0;
380 1.24.8.2 nathanw if ((resid = (NCR_READ_REG(sc, NCR_FFLAG) & NCRFIFO_FF)) != 0) {
381 1.24.8.2 nathanw NCR_DMA(("asc_vsbus_intr: empty FIFO of %d ", resid));
382 1.24.8.2 nathanw DELAY(1);
383 1.24.8.2 nathanw }
384 1.24.8.2 nathanw if (asc->sc_flags & ASC_MAPLOADED) {
385 1.24.8.2 nathanw bus_dmamap_sync(asc->sc_dmat, asc->sc_dmamap,
386 1.24.8.2 nathanw 0, asc->sc_dmasize,
387 1.24.8.2 nathanw asc->sc_flags & ASC_FROMMEMORY
388 1.24.8.2 nathanw ? BUS_DMASYNC_POSTWRITE
389 1.24.8.2 nathanw : BUS_DMASYNC_POSTREAD);
390 1.24.8.2 nathanw bus_dmamap_unload(asc->sc_dmat, asc->sc_dmamap);
391 1.24.8.2 nathanw }
392 1.24.8.2 nathanw asc->sc_flags &= ~ASC_MAPLOADED;
393 1.24.8.2 nathanw
394 1.24.8.2 nathanw resid += (tcl = NCR_READ_REG(sc, NCR_TCL));
395 1.24.8.2 nathanw resid += (tcm = NCR_READ_REG(sc, NCR_TCM)) << 8;
396 1.24.8.2 nathanw
397 1.24.8.2 nathanw trans = asc->sc_dmasize - resid;
398 1.24.8.2 nathanw if (trans < 0) { /* transferred < 0 ? */
399 1.24.8.2 nathanw printf("asc_vsbus_intr: xfer (%d) > req (%lu)\n",
400 1.24.8.2 nathanw trans, (u_long) asc->sc_dmasize);
401 1.24.8.2 nathanw trans = asc->sc_dmasize;
402 1.24.8.2 nathanw }
403 1.24.8.2 nathanw NCR_DMA(("asc_vsbus_intr: tcl=%d, tcm=%d; trans=%d, resid=%d\n",
404 1.24.8.2 nathanw tcl, tcm, trans, resid));
405 1.24.8.2 nathanw
406 1.24.8.2 nathanw *asc->sc_dmalen -= trans;
407 1.24.8.2 nathanw *asc->sc_dmaaddr += trans;
408 1.24.8.2 nathanw
409 1.24.8.2 nathanw asc->sc_xfers++;
410 1.24.8.2 nathanw return 0;
411 1.24.8.2 nathanw }
412 1.24.8.2 nathanw
413 1.24.8.2 nathanw static int
414 1.24.8.2 nathanw asc_vsbus_dma_setup(struct ncr53c9x_softc *sc, caddr_t *addr, size_t *len,
415 1.24.8.2 nathanw int datain, size_t *dmasize)
416 1.24.8.2 nathanw {
417 1.24.8.2 nathanw struct asc_vsbus_softc *asc = (struct asc_vsbus_softc *)sc;
418 1.24.8.2 nathanw
419 1.24.8.2 nathanw asc->sc_dmaaddr = addr;
420 1.24.8.2 nathanw asc->sc_dmalen = len;
421 1.24.8.2 nathanw if (datain) {
422 1.24.8.2 nathanw asc->sc_flags &= ~ASC_FROMMEMORY;
423 1.24.8.2 nathanw } else {
424 1.24.8.2 nathanw asc->sc_flags |= ASC_FROMMEMORY;
425 1.24.8.2 nathanw }
426 1.24.8.2 nathanw if ((vaddr_t) *asc->sc_dmaaddr < VM_MIN_KERNEL_ADDRESS)
427 1.24.8.2 nathanw panic("asc_vsbus_dma_setup: dma address (%p) outside of kernel",
428 1.24.8.2 nathanw *asc->sc_dmaaddr);
429 1.24.8.2 nathanw
430 1.24.8.2 nathanw NCR_DMA(("%s: start %d@%p,%d\n", sc->sc_dev.dv_xname,
431 1.24.8.2 nathanw (int)*asc->sc_dmalen, *asc->sc_dmaaddr, (asc->sc_flags & ASC_FROMMEMORY)));
432 1.24.8.2 nathanw *dmasize = asc->sc_dmasize = min(*dmasize, ASC_MAXXFERSIZE);
433 1.24.8.2 nathanw
434 1.24.8.2 nathanw if (asc->sc_dmasize) {
435 1.24.8.2 nathanw if (bus_dmamap_load(asc->sc_dmat, asc->sc_dmamap,
436 1.24.8.2 nathanw *asc->sc_dmaaddr, asc->sc_dmasize,
437 1.24.8.2 nathanw NULL /* kernel address */,
438 1.24.8.2 nathanw BUS_DMA_NOWAIT|VAX_BUS_DMA_SPILLPAGE))
439 1.24.8.2 nathanw panic("%s: cannot load dma map", sc->sc_dev.dv_xname);
440 1.24.8.2 nathanw bus_dmamap_sync(asc->sc_dmat, asc->sc_dmamap,
441 1.24.8.2 nathanw 0, asc->sc_dmasize,
442 1.24.8.2 nathanw asc->sc_flags & ASC_FROMMEMORY
443 1.24.8.2 nathanw ? BUS_DMASYNC_PREWRITE
444 1.24.8.2 nathanw : BUS_DMASYNC_PREREAD);
445 1.24.8.2 nathanw bus_space_write_4(asc->sc_bst, asc->sc_adrh, 0,
446 1.24.8.2 nathanw asc->sc_dmamap->dm_segs[0].ds_addr);
447 1.24.8.2 nathanw bus_space_write_4(asc->sc_bst, asc->sc_dirh, 0,
448 1.24.8.2 nathanw asc->sc_flags & ASC_FROMMEMORY);
449 1.24.8.2 nathanw NCR_DMA(("%s: dma-load %lu@0x%08lx\n", sc->sc_dev.dv_xname,
450 1.24.8.2 nathanw asc->sc_dmamap->dm_segs[0].ds_len,
451 1.24.8.2 nathanw asc->sc_dmamap->dm_segs[0].ds_addr));
452 1.24.8.2 nathanw asc->sc_flags |= ASC_MAPLOADED;
453 1.24.8.2 nathanw }
454 1.24.8.2 nathanw
455 1.24.8.2 nathanw return 0;
456 1.24.8.2 nathanw }
457 1.24.8.2 nathanw
458 1.24.8.2 nathanw static void
459 1.24.8.2 nathanw asc_vsbus_dma_go(struct ncr53c9x_softc *sc)
460 1.24.8.2 nathanw {
461 1.24.8.2 nathanw struct asc_vsbus_softc *asc = (struct asc_vsbus_softc *)sc;
462 1.24.8.2 nathanw
463 1.24.8.2 nathanw asc->sc_flags |= ASC_DMAACTIVE;
464 1.24.8.2 nathanw }
465 1.24.8.2 nathanw
466 1.24.8.2 nathanw static void
467 1.24.8.2 nathanw asc_vsbus_dma_stop(struct ncr53c9x_softc *sc)
468 1.24.8.2 nathanw {
469 1.24.8.2 nathanw struct asc_vsbus_softc *asc = (struct asc_vsbus_softc *)sc;
470 1.24.8.2 nathanw
471 1.24.8.2 nathanw if (asc->sc_flags & ASC_MAPLOADED) {
472 1.24.8.2 nathanw bus_dmamap_sync(asc->sc_dmat, asc->sc_dmamap,
473 1.24.8.2 nathanw 0, asc->sc_dmasize,
474 1.24.8.2 nathanw asc->sc_flags & ASC_FROMMEMORY
475 1.24.8.2 nathanw ? BUS_DMASYNC_POSTWRITE
476 1.24.8.2 nathanw : BUS_DMASYNC_POSTREAD);
477 1.24.8.2 nathanw bus_dmamap_unload(asc->sc_dmat, asc->sc_dmamap);
478 1.24.8.2 nathanw }
479 1.24.8.2 nathanw
480 1.24.8.2 nathanw asc->sc_flags &= ~(ASC_DMAACTIVE|ASC_MAPLOADED);
481 1.24.8.2 nathanw }
482 1.24.8.2 nathanw
483 1.24.8.2 nathanw static int
484 1.24.8.2 nathanw asc_vsbus_dma_isactive(struct ncr53c9x_softc *sc)
485 1.24.8.2 nathanw {
486 1.24.8.2 nathanw struct asc_vsbus_softc *asc = (struct asc_vsbus_softc *)sc;
487 1.24.8.2 nathanw
488 1.24.8.2 nathanw return (asc->sc_flags & ASC_DMAACTIVE) != 0;
489 1.24.8.2 nathanw }
490