tcds.c revision 1.1.2.2 1 1.1.2.2 bouyer /* $NetBSD: tcds.c,v 1.1.2.2 2000/11/20 11:43:17 bouyer Exp $ */
2 1.1.2.2 bouyer
3 1.1.2.2 bouyer /*-
4 1.1.2.2 bouyer * Copyright (c) 1998 The NetBSD Foundation, Inc.
5 1.1.2.2 bouyer * All rights reserved.
6 1.1.2.2 bouyer *
7 1.1.2.2 bouyer * This code is derived from software contributed to The NetBSD Foundation
8 1.1.2.2 bouyer * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
9 1.1.2.2 bouyer * NASA Ames Research Center.
10 1.1.2.2 bouyer *
11 1.1.2.2 bouyer * Redistribution and use in source and binary forms, with or without
12 1.1.2.2 bouyer * modification, are permitted provided that the following conditions
13 1.1.2.2 bouyer * are met:
14 1.1.2.2 bouyer * 1. Redistributions of source code must retain the above copyright
15 1.1.2.2 bouyer * notice, this list of conditions and the following disclaimer.
16 1.1.2.2 bouyer * 2. Redistributions in binary form must reproduce the above copyright
17 1.1.2.2 bouyer * notice, this list of conditions and the following disclaimer in the
18 1.1.2.2 bouyer * documentation and/or other materials provided with the distribution.
19 1.1.2.2 bouyer * 3. All advertising materials mentioning features or use of this software
20 1.1.2.2 bouyer * must display the following acknowledgement:
21 1.1.2.2 bouyer * This product includes software developed by the NetBSD
22 1.1.2.2 bouyer * Foundation, Inc. and its contributors.
23 1.1.2.2 bouyer * 4. Neither the name of The NetBSD Foundation nor the names of its
24 1.1.2.2 bouyer * contributors may be used to endorse or promote products derived
25 1.1.2.2 bouyer * from this software without specific prior written permission.
26 1.1.2.2 bouyer *
27 1.1.2.2 bouyer * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
28 1.1.2.2 bouyer * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
29 1.1.2.2 bouyer * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
30 1.1.2.2 bouyer * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
31 1.1.2.2 bouyer * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32 1.1.2.2 bouyer * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33 1.1.2.2 bouyer * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34 1.1.2.2 bouyer * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35 1.1.2.2 bouyer * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36 1.1.2.2 bouyer * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37 1.1.2.2 bouyer * POSSIBILITY OF SUCH DAMAGE.
38 1.1.2.2 bouyer */
39 1.1.2.2 bouyer
40 1.1.2.2 bouyer /*
41 1.1.2.2 bouyer * Copyright (c) 1994, 1995, 1996 Carnegie-Mellon University.
42 1.1.2.2 bouyer * All rights reserved.
43 1.1.2.2 bouyer *
44 1.1.2.2 bouyer * Author: Keith Bostic, Chris G. Demetriou
45 1.1.2.2 bouyer *
46 1.1.2.2 bouyer * Permission to use, copy, modify and distribute this software and
47 1.1.2.2 bouyer * its documentation is hereby granted, provided that both the copyright
48 1.1.2.2 bouyer * notice and this permission notice appear in all copies of the
49 1.1.2.2 bouyer * software, derivative works or modified versions, and any portions
50 1.1.2.2 bouyer * thereof, and that both notices appear in supporting documentation.
51 1.1.2.2 bouyer *
52 1.1.2.2 bouyer * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
53 1.1.2.2 bouyer * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
54 1.1.2.2 bouyer * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
55 1.1.2.2 bouyer *
56 1.1.2.2 bouyer * Carnegie Mellon requests users of this software to return to
57 1.1.2.2 bouyer *
58 1.1.2.2 bouyer * Software Distribution Coordinator or Software.Distribution (at) CS.CMU.EDU
59 1.1.2.2 bouyer * School of Computer Science
60 1.1.2.2 bouyer * Carnegie Mellon University
61 1.1.2.2 bouyer * Pittsburgh PA 15213-3890
62 1.1.2.2 bouyer *
63 1.1.2.2 bouyer * any improvements or extensions that they make and grant Carnegie the
64 1.1.2.2 bouyer * rights to redistribute these changes.
65 1.1.2.2 bouyer */
66 1.1.2.2 bouyer
67 1.1.2.2 bouyer #include <sys/cdefs.h> /* RCS ID & Copyright macro defns */
68 1.1.2.2 bouyer
69 1.1.2.2 bouyer __KERNEL_RCSID(0, "$NetBSD: tcds.c,v 1.1.2.2 2000/11/20 11:43:17 bouyer Exp $");
70 1.1.2.2 bouyer
71 1.1.2.2 bouyer #include <sys/param.h>
72 1.1.2.2 bouyer #include <sys/kernel.h>
73 1.1.2.2 bouyer #include <sys/systm.h>
74 1.1.2.2 bouyer #include <sys/device.h>
75 1.1.2.2 bouyer #include <sys/malloc.h>
76 1.1.2.2 bouyer
77 1.1.2.2 bouyer #ifdef __alpha__
78 1.1.2.2 bouyer #include <machine/rpb.h>
79 1.1.2.2 bouyer #endif /* __alpha__ */
80 1.1.2.2 bouyer
81 1.1.2.2 bouyer #include <dev/scsipi/scsi_all.h>
82 1.1.2.2 bouyer #include <dev/scsipi/scsipi_all.h>
83 1.1.2.2 bouyer #include <dev/scsipi/scsiconf.h>
84 1.1.2.2 bouyer
85 1.1.2.2 bouyer #include <dev/ic/ncr53c9xvar.h>
86 1.1.2.2 bouyer
87 1.1.2.2 bouyer #include <machine/bus.h>
88 1.1.2.2 bouyer
89 1.1.2.2 bouyer #include <dev/tc/tcvar.h>
90 1.1.2.2 bouyer #include <dev/tc/tcdsreg.h>
91 1.1.2.2 bouyer #include <dev/tc/tcdsvar.h>
92 1.1.2.2 bouyer
93 1.1.2.2 bouyer #include "locators.h"
94 1.1.2.2 bouyer
95 1.1.2.2 bouyer struct tcds_softc {
96 1.1.2.2 bouyer struct device sc_dv;
97 1.1.2.2 bouyer bus_space_tag_t sc_bst;
98 1.1.2.2 bouyer bus_space_handle_t sc_bsh;
99 1.1.2.2 bouyer bus_dma_tag_t sc_dmat;
100 1.1.2.2 bouyer void *sc_cookie;
101 1.1.2.2 bouyer int sc_flags;
102 1.1.2.2 bouyer struct tcds_slotconfig sc_slots[2];
103 1.1.2.2 bouyer };
104 1.1.2.2 bouyer
105 1.1.2.2 bouyer /* sc_flags */
106 1.1.2.2 bouyer #define TCDSF_BASEBOARD 0x01 /* baseboard on DEC 3000 */
107 1.1.2.2 bouyer #define TCDSF_FASTSCSI 0x02 /* supports Fast SCSI */
108 1.1.2.2 bouyer
109 1.1.2.2 bouyer /* Definition of the driver for autoconfig. */
110 1.1.2.2 bouyer int tcdsmatch __P((struct device *, struct cfdata *, void *));
111 1.1.2.2 bouyer void tcdsattach __P((struct device *, struct device *, void *));
112 1.1.2.2 bouyer int tcdsprint __P((void *, const char *));
113 1.1.2.2 bouyer int tcdssubmatch __P((struct device *, struct cfdata *, void *));
114 1.1.2.2 bouyer
115 1.1.2.2 bouyer struct cfattach tcds_ca = {
116 1.1.2.2 bouyer sizeof(struct tcds_softc), tcdsmatch, tcdsattach,
117 1.1.2.2 bouyer };
118 1.1.2.2 bouyer
119 1.1.2.2 bouyer /*static*/ int tcds_intr __P((void *));
120 1.1.2.2 bouyer /*static*/ int tcds_intrnull __P((void *));
121 1.1.2.2 bouyer
122 1.1.2.2 bouyer struct tcds_device {
123 1.1.2.2 bouyer const char *td_name;
124 1.1.2.2 bouyer int td_flags;
125 1.1.2.2 bouyer } tcds_devices[] = {
126 1.1.2.2 bouyer #ifdef __alpha__
127 1.1.2.2 bouyer { "PMAZ-DS ", TCDSF_BASEBOARD },
128 1.1.2.2 bouyer { "PMAZ-FS ", TCDSF_BASEBOARD|TCDSF_FASTSCSI },
129 1.1.2.2 bouyer #endif /* __alpha__ */
130 1.1.2.2 bouyer { "PMAZB-AA", 0 },
131 1.1.2.2 bouyer { "PMAZC-AA", TCDSF_FASTSCSI },
132 1.1.2.2 bouyer { NULL, 0 },
133 1.1.2.2 bouyer };
134 1.1.2.2 bouyer
135 1.1.2.2 bouyer struct tcds_device *tcds_lookup __P((const char *));
136 1.1.2.2 bouyer void tcds_params __P((struct tcds_softc *, int, int *, int *));
137 1.1.2.2 bouyer
138 1.1.2.2 bouyer struct tcds_device *
139 1.1.2.2 bouyer tcds_lookup(modname)
140 1.1.2.2 bouyer const char *modname;
141 1.1.2.2 bouyer {
142 1.1.2.2 bouyer struct tcds_device *td;
143 1.1.2.2 bouyer
144 1.1.2.2 bouyer for (td = tcds_devices; td->td_name != NULL; td++)
145 1.1.2.2 bouyer if (strncmp(td->td_name, modname, TC_ROM_LLEN) == 0)
146 1.1.2.2 bouyer return (td);
147 1.1.2.2 bouyer
148 1.1.2.2 bouyer return (NULL);
149 1.1.2.2 bouyer }
150 1.1.2.2 bouyer
151 1.1.2.2 bouyer int
152 1.1.2.2 bouyer tcdsmatch(parent, cfdata, aux)
153 1.1.2.2 bouyer struct device *parent;
154 1.1.2.2 bouyer struct cfdata *cfdata;
155 1.1.2.2 bouyer void *aux;
156 1.1.2.2 bouyer {
157 1.1.2.2 bouyer struct tc_attach_args *ta = aux;
158 1.1.2.2 bouyer
159 1.1.2.2 bouyer return (tcds_lookup(ta->ta_modname) != NULL);
160 1.1.2.2 bouyer }
161 1.1.2.2 bouyer
162 1.1.2.2 bouyer void
163 1.1.2.2 bouyer tcdsattach(parent, self, aux)
164 1.1.2.2 bouyer struct device *parent, *self;
165 1.1.2.2 bouyer void *aux;
166 1.1.2.2 bouyer {
167 1.1.2.2 bouyer struct tcds_softc *sc = (struct tcds_softc *)self;
168 1.1.2.2 bouyer struct tc_attach_args *ta = aux;
169 1.1.2.2 bouyer struct tcdsdev_attach_args tcdsdev;
170 1.1.2.2 bouyer struct tcds_slotconfig *slotc;
171 1.1.2.2 bouyer struct tcds_device *td;
172 1.1.2.2 bouyer bus_space_handle_t sbsh[2];
173 1.1.2.2 bouyer int i, gpi2;
174 1.1.2.2 bouyer const struct evcnt *pevcnt;
175 1.1.2.2 bouyer char *cp;
176 1.1.2.2 bouyer
177 1.1.2.2 bouyer td = tcds_lookup(ta->ta_modname);
178 1.1.2.2 bouyer if (td == NULL)
179 1.1.2.2 bouyer panic("\ntcdsattach: impossible");
180 1.1.2.2 bouyer
181 1.1.2.2 bouyer printf(": TurboChannel Dual SCSI");
182 1.1.2.2 bouyer if (td->td_flags & TCDSF_BASEBOARD)
183 1.1.2.2 bouyer printf(" (baseboard)");
184 1.1.2.2 bouyer printf("\n");
185 1.1.2.2 bouyer
186 1.1.2.2 bouyer sc->sc_flags = td->td_flags;
187 1.1.2.2 bouyer
188 1.1.2.2 bouyer sc->sc_bst = ta->ta_memt;
189 1.1.2.2 bouyer sc->sc_dmat = ta->ta_dmat;
190 1.1.2.2 bouyer
191 1.1.2.2 bouyer /*
192 1.1.2.2 bouyer * Map the device.
193 1.1.2.2 bouyer */
194 1.1.2.2 bouyer if (bus_space_map(sc->sc_bst, ta->ta_addr,
195 1.1.2.2 bouyer (TCDS_SCSI1_OFFSET + 0x100), 0, &sc->sc_bsh)) {
196 1.1.2.2 bouyer printf("%s: unable to map device\n", sc->sc_dv.dv_xname);
197 1.1.2.2 bouyer return;
198 1.1.2.2 bouyer }
199 1.1.2.2 bouyer
200 1.1.2.2 bouyer /*
201 1.1.2.2 bouyer * Now, slice off two subregions for the individual NCR SCSI chips.
202 1.1.2.2 bouyer */
203 1.1.2.2 bouyer if (bus_space_subregion(sc->sc_bst, sc->sc_bsh, TCDS_SCSI0_OFFSET,
204 1.1.2.2 bouyer 0x100, &sbsh[0]) ||
205 1.1.2.2 bouyer bus_space_subregion(sc->sc_bst, sc->sc_bsh, TCDS_SCSI1_OFFSET,
206 1.1.2.2 bouyer 0x100, &sbsh[1])) {
207 1.1.2.2 bouyer printf("%s: unable to subregion SCSI chip space\n",
208 1.1.2.2 bouyer sc->sc_dv.dv_xname);
209 1.1.2.2 bouyer return;
210 1.1.2.2 bouyer }
211 1.1.2.2 bouyer
212 1.1.2.2 bouyer sc->sc_cookie = ta->ta_cookie;
213 1.1.2.2 bouyer
214 1.1.2.2 bouyer pevcnt = tc_intr_evcnt(parent, sc->sc_cookie);
215 1.1.2.2 bouyer tc_intr_establish(parent, sc->sc_cookie, TC_IPL_BIO, tcds_intr, sc);
216 1.1.2.2 bouyer
217 1.1.2.2 bouyer /*
218 1.1.2.2 bouyer * XXX
219 1.1.2.2 bouyer * IMER apparently has some random (or, not so random, but still
220 1.1.2.2 bouyer * not useful) bits set in it when the system boots. Clear it.
221 1.1.2.2 bouyer */
222 1.1.2.2 bouyer bus_space_write_4(sc->sc_bst, sc->sc_bsh, TCDS_IMER, 0);
223 1.1.2.2 bouyer
224 1.1.2.2 bouyer /* XXX Initial contents of CIR? */
225 1.1.2.2 bouyer
226 1.1.2.2 bouyer /*
227 1.1.2.2 bouyer * Remember if GPI2 is set in the CIR; we'll need it later.
228 1.1.2.2 bouyer */
229 1.1.2.2 bouyer gpi2 = (bus_space_read_4(sc->sc_bst, sc->sc_bsh, TCDS_CIR) &
230 1.1.2.2 bouyer TCDS_CIR_GPI_2) != 0;
231 1.1.2.2 bouyer
232 1.1.2.2 bouyer /*
233 1.1.2.2 bouyer * Set up the per-slot defintions for later use.
234 1.1.2.2 bouyer */
235 1.1.2.2 bouyer
236 1.1.2.2 bouyer /* fill in common information first */
237 1.1.2.2 bouyer for (i = 0; i < 2; i++) {
238 1.1.2.2 bouyer slotc = &sc->sc_slots[i];
239 1.1.2.2 bouyer
240 1.1.2.2 bouyer bzero(slotc, sizeof *slotc); /* clear everything */
241 1.1.2.2 bouyer
242 1.1.2.2 bouyer cp = malloc(12, M_DEVBUF, M_NOWAIT);
243 1.1.2.2 bouyer if (cp == NULL)
244 1.1.2.2 bouyer panic("tcdsattach");
245 1.1.2.2 bouyer sprintf(cp, "chip %d", i);
246 1.1.2.2 bouyer evcnt_attach_dynamic(&slotc->sc_evcnt, EVCNT_TYPE_INTR,
247 1.1.2.2 bouyer pevcnt, sc->sc_dv.dv_xname, cp);
248 1.1.2.2 bouyer
249 1.1.2.2 bouyer slotc->sc_slot = i;
250 1.1.2.2 bouyer slotc->sc_bst = sc->sc_bst;
251 1.1.2.2 bouyer slotc->sc_bsh = sc->sc_bsh;
252 1.1.2.2 bouyer slotc->sc_intrhand = tcds_intrnull;
253 1.1.2.2 bouyer slotc->sc_intrarg = (void *)(long)i;
254 1.1.2.2 bouyer }
255 1.1.2.2 bouyer
256 1.1.2.2 bouyer /* information for slot 0 */
257 1.1.2.2 bouyer slotc = &sc->sc_slots[0];
258 1.1.2.2 bouyer slotc->sc_resetbits = TCDS_CIR_SCSI0_RESET;
259 1.1.2.2 bouyer slotc->sc_intrmaskbits =
260 1.1.2.2 bouyer TCDS_IMER_SCSI0_MASK | TCDS_IMER_SCSI0_ENB;
261 1.1.2.2 bouyer slotc->sc_intrbits = TCDS_CIR_SCSI0_INT;
262 1.1.2.2 bouyer slotc->sc_dmabits = TCDS_CIR_SCSI0_DMAENA;
263 1.1.2.2 bouyer slotc->sc_errorbits = 0; /* XXX */
264 1.1.2.2 bouyer slotc->sc_sda = TCDS_SCSI0_DMA_ADDR;
265 1.1.2.2 bouyer slotc->sc_dic = TCDS_SCSI0_DMA_INTR;
266 1.1.2.2 bouyer slotc->sc_dud0 = TCDS_SCSI0_DMA_DUD0;
267 1.1.2.2 bouyer slotc->sc_dud1 = TCDS_SCSI0_DMA_DUD1;
268 1.1.2.2 bouyer
269 1.1.2.2 bouyer /* information for slot 1 */
270 1.1.2.2 bouyer slotc = &sc->sc_slots[1];
271 1.1.2.2 bouyer slotc->sc_resetbits = TCDS_CIR_SCSI1_RESET;
272 1.1.2.2 bouyer slotc->sc_intrmaskbits =
273 1.1.2.2 bouyer TCDS_IMER_SCSI1_MASK | TCDS_IMER_SCSI1_ENB;
274 1.1.2.2 bouyer slotc->sc_intrbits = TCDS_CIR_SCSI1_INT;
275 1.1.2.2 bouyer slotc->sc_dmabits = TCDS_CIR_SCSI1_DMAENA;
276 1.1.2.2 bouyer slotc->sc_errorbits = 0; /* XXX */
277 1.1.2.2 bouyer slotc->sc_sda = TCDS_SCSI1_DMA_ADDR;
278 1.1.2.2 bouyer slotc->sc_dic = TCDS_SCSI1_DMA_INTR;
279 1.1.2.2 bouyer slotc->sc_dud0 = TCDS_SCSI1_DMA_DUD0;
280 1.1.2.2 bouyer slotc->sc_dud1 = TCDS_SCSI1_DMA_DUD1;
281 1.1.2.2 bouyer
282 1.1.2.2 bouyer /* find the hardware attached to the TCDS ASIC */
283 1.1.2.2 bouyer for (i = 0; i < 2; i++) {
284 1.1.2.2 bouyer tcds_params(sc, i, &tcdsdev.tcdsda_id,
285 1.1.2.2 bouyer &tcdsdev.tcdsda_fast);
286 1.1.2.2 bouyer
287 1.1.2.2 bouyer tcdsdev.tcdsda_bst = sc->sc_bst;
288 1.1.2.2 bouyer tcdsdev.tcdsda_bsh = sbsh[i];
289 1.1.2.2 bouyer tcdsdev.tcdsda_dmat = sc->sc_dmat;
290 1.1.2.2 bouyer tcdsdev.tcdsda_chip = i;
291 1.1.2.2 bouyer tcdsdev.tcdsda_sc = &sc->sc_slots[i];
292 1.1.2.2 bouyer /*
293 1.1.2.2 bouyer * Determine the chip frequency. TCDSF_FASTSCSI will be set
294 1.1.2.2 bouyer * for TC option cards. For baseboard chips, GPI2 is set, for a
295 1.1.2.2 bouyer * 25MHz clock, else a 40MHz clock.
296 1.1.2.2 bouyer */
297 1.1.2.2 bouyer if ((sc->sc_flags & TCDSF_BASEBOARD && gpi2 == 0) ||
298 1.1.2.2 bouyer sc->sc_flags & TCDSF_FASTSCSI) {
299 1.1.2.2 bouyer tcdsdev.tcdsda_freq = 40000000;
300 1.1.2.2 bouyer tcdsdev.tcdsda_period = tcdsdev.tcdsda_fast ? 4 : 8;
301 1.1.2.2 bouyer } else {
302 1.1.2.2 bouyer tcdsdev.tcdsda_freq = 25000000;
303 1.1.2.2 bouyer tcdsdev.tcdsda_period = 5;
304 1.1.2.2 bouyer }
305 1.1.2.2 bouyer if (sc->sc_flags & TCDSF_BASEBOARD)
306 1.1.2.2 bouyer tcdsdev.tcdsda_variant = NCR_VARIANT_NCR53C94;
307 1.1.2.2 bouyer else
308 1.1.2.2 bouyer tcdsdev.tcdsda_variant = NCR_VARIANT_NCR53C96;
309 1.1.2.2 bouyer
310 1.1.2.2 bouyer tcds_scsi_reset(tcdsdev.tcdsda_sc);
311 1.1.2.2 bouyer
312 1.1.2.2 bouyer config_found_sm(self, &tcdsdev, tcdsprint, tcdssubmatch);
313 1.1.2.2 bouyer #ifdef __alpha__
314 1.1.2.2 bouyer /*
315 1.1.2.2 bouyer * The second SCSI chip isn't present on the baseboard TCDS
316 1.1.2.2 bouyer * on the DEC Alpha 3000/300 series.
317 1.1.2.2 bouyer */
318 1.1.2.2 bouyer if (sc->sc_flags & TCDSF_BASEBOARD &&
319 1.1.2.2 bouyer cputype == ST_DEC_3000_300)
320 1.1.2.2 bouyer break;
321 1.1.2.2 bouyer #endif /* __alpha__ */
322 1.1.2.2 bouyer }
323 1.1.2.2 bouyer }
324 1.1.2.2 bouyer
325 1.1.2.2 bouyer int
326 1.1.2.2 bouyer tcdssubmatch(parent, cf, aux)
327 1.1.2.2 bouyer struct device *parent;
328 1.1.2.2 bouyer struct cfdata *cf;
329 1.1.2.2 bouyer void *aux;
330 1.1.2.2 bouyer {
331 1.1.2.2 bouyer struct tcdsdev_attach_args *tcdsdev = aux;
332 1.1.2.2 bouyer
333 1.1.2.2 bouyer if (cf->cf_loc[TCDSCF_CHIP] != TCDSCF_CHIP_DEFAULT &&
334 1.1.2.2 bouyer cf->cf_loc[TCDSCF_CHIP] != tcdsdev->tcdsda_chip)
335 1.1.2.2 bouyer return (0);
336 1.1.2.2 bouyer
337 1.1.2.2 bouyer return ((*cf->cf_attach->ca_match)(parent, cf, aux));
338 1.1.2.2 bouyer }
339 1.1.2.2 bouyer
340 1.1.2.2 bouyer int
341 1.1.2.2 bouyer tcdsprint(aux, pnp)
342 1.1.2.2 bouyer void *aux;
343 1.1.2.2 bouyer const char *pnp;
344 1.1.2.2 bouyer {
345 1.1.2.2 bouyer struct tcdsdev_attach_args *tcdsdev = aux;
346 1.1.2.2 bouyer
347 1.1.2.2 bouyer /* Only ASCs can attach to TCDSs; easy. */
348 1.1.2.2 bouyer if (pnp)
349 1.1.2.2 bouyer printf("asc at %s", pnp);
350 1.1.2.2 bouyer
351 1.1.2.2 bouyer printf(" chip %d", tcdsdev->tcdsda_chip);
352 1.1.2.2 bouyer
353 1.1.2.2 bouyer return (UNCONF);
354 1.1.2.2 bouyer }
355 1.1.2.2 bouyer
356 1.1.2.2 bouyer void
357 1.1.2.2 bouyer tcds_intr_establish(tcds, slot, func, arg)
358 1.1.2.2 bouyer struct device *tcds;
359 1.1.2.2 bouyer int slot;
360 1.1.2.2 bouyer int (*func) __P((void *));
361 1.1.2.2 bouyer void *arg;
362 1.1.2.2 bouyer {
363 1.1.2.2 bouyer struct tcds_softc *sc = (struct tcds_softc *)tcds;
364 1.1.2.2 bouyer
365 1.1.2.2 bouyer if (sc->sc_slots[slot].sc_intrhand != tcds_intrnull)
366 1.1.2.2 bouyer panic("tcds_intr_establish: chip %d twice", slot);
367 1.1.2.2 bouyer
368 1.1.2.2 bouyer sc->sc_slots[slot].sc_intrhand = func;
369 1.1.2.2 bouyer sc->sc_slots[slot].sc_intrarg = arg;
370 1.1.2.2 bouyer tcds_scsi_reset(&sc->sc_slots[slot]);
371 1.1.2.2 bouyer }
372 1.1.2.2 bouyer
373 1.1.2.2 bouyer void
374 1.1.2.2 bouyer tcds_intr_disestablish(tcds, slot)
375 1.1.2.2 bouyer struct device *tcds;
376 1.1.2.2 bouyer int slot;
377 1.1.2.2 bouyer {
378 1.1.2.2 bouyer struct tcds_softc *sc = (struct tcds_softc *)tcds;
379 1.1.2.2 bouyer
380 1.1.2.2 bouyer if (sc->sc_slots[slot].sc_intrhand == tcds_intrnull)
381 1.1.2.2 bouyer panic("tcds_intr_disestablish: chip %d missing intr",
382 1.1.2.2 bouyer slot);
383 1.1.2.2 bouyer
384 1.1.2.2 bouyer sc->sc_slots[slot].sc_intrhand = tcds_intrnull;
385 1.1.2.2 bouyer sc->sc_slots[slot].sc_intrarg = (void *)(u_long)slot;
386 1.1.2.2 bouyer
387 1.1.2.2 bouyer tcds_dma_enable(&sc->sc_slots[slot], 0);
388 1.1.2.2 bouyer tcds_scsi_enable(&sc->sc_slots[slot], 0);
389 1.1.2.2 bouyer }
390 1.1.2.2 bouyer
391 1.1.2.2 bouyer int
392 1.1.2.2 bouyer tcds_intrnull(val)
393 1.1.2.2 bouyer void *val;
394 1.1.2.2 bouyer {
395 1.1.2.2 bouyer
396 1.1.2.2 bouyer panic("tcds_intrnull: uncaught TCDS intr for chip %lu\n",
397 1.1.2.2 bouyer (u_long)val);
398 1.1.2.2 bouyer }
399 1.1.2.2 bouyer
400 1.1.2.2 bouyer void
401 1.1.2.2 bouyer tcds_scsi_reset(sc)
402 1.1.2.2 bouyer struct tcds_slotconfig *sc;
403 1.1.2.2 bouyer {
404 1.1.2.2 bouyer u_int32_t cir;
405 1.1.2.2 bouyer
406 1.1.2.2 bouyer tcds_dma_enable(sc, 0);
407 1.1.2.2 bouyer tcds_scsi_enable(sc, 0);
408 1.1.2.2 bouyer
409 1.1.2.2 bouyer cir = bus_space_read_4(sc->sc_bst, sc->sc_bsh, TCDS_CIR);
410 1.1.2.2 bouyer TCDS_CIR_CLR(cir, sc->sc_resetbits);
411 1.1.2.2 bouyer bus_space_write_4(sc->sc_bst, sc->sc_bsh, TCDS_CIR, cir);
412 1.1.2.2 bouyer
413 1.1.2.2 bouyer DELAY(1);
414 1.1.2.2 bouyer
415 1.1.2.2 bouyer cir = bus_space_read_4(sc->sc_bst, sc->sc_bsh, TCDS_CIR);
416 1.1.2.2 bouyer TCDS_CIR_SET(cir, sc->sc_resetbits);
417 1.1.2.2 bouyer bus_space_write_4(sc->sc_bst, sc->sc_bsh, TCDS_CIR, cir);
418 1.1.2.2 bouyer
419 1.1.2.2 bouyer tcds_scsi_enable(sc, 1);
420 1.1.2.2 bouyer tcds_dma_enable(sc, 1);
421 1.1.2.2 bouyer }
422 1.1.2.2 bouyer
423 1.1.2.2 bouyer void
424 1.1.2.2 bouyer tcds_scsi_enable(sc, on)
425 1.1.2.2 bouyer struct tcds_slotconfig *sc;
426 1.1.2.2 bouyer int on;
427 1.1.2.2 bouyer {
428 1.1.2.2 bouyer u_int32_t imer;
429 1.1.2.2 bouyer
430 1.1.2.2 bouyer imer = bus_space_read_4(sc->sc_bst, sc->sc_bsh, TCDS_IMER);
431 1.1.2.2 bouyer
432 1.1.2.2 bouyer if (on)
433 1.1.2.2 bouyer imer |= sc->sc_intrmaskbits;
434 1.1.2.2 bouyer else
435 1.1.2.2 bouyer imer &= ~sc->sc_intrmaskbits;
436 1.1.2.2 bouyer
437 1.1.2.2 bouyer bus_space_write_4(sc->sc_bst, sc->sc_bsh, TCDS_IMER, imer);
438 1.1.2.2 bouyer }
439 1.1.2.2 bouyer
440 1.1.2.2 bouyer void
441 1.1.2.2 bouyer tcds_dma_enable(sc, on)
442 1.1.2.2 bouyer struct tcds_slotconfig *sc;
443 1.1.2.2 bouyer int on;
444 1.1.2.2 bouyer {
445 1.1.2.2 bouyer u_int32_t cir;
446 1.1.2.2 bouyer
447 1.1.2.2 bouyer cir = bus_space_read_4(sc->sc_bst, sc->sc_bsh, TCDS_CIR);
448 1.1.2.2 bouyer
449 1.1.2.2 bouyer /* XXX Clear/set IOSLOT/PBS bits. */
450 1.1.2.2 bouyer if (on)
451 1.1.2.2 bouyer TCDS_CIR_SET(cir, sc->sc_dmabits);
452 1.1.2.2 bouyer else
453 1.1.2.2 bouyer TCDS_CIR_CLR(cir, sc->sc_dmabits);
454 1.1.2.2 bouyer
455 1.1.2.2 bouyer bus_space_write_4(sc->sc_bst, sc->sc_bsh, TCDS_CIR, cir);
456 1.1.2.2 bouyer }
457 1.1.2.2 bouyer
458 1.1.2.2 bouyer int
459 1.1.2.2 bouyer tcds_scsi_isintr(sc, clear)
460 1.1.2.2 bouyer struct tcds_slotconfig *sc;
461 1.1.2.2 bouyer int clear;
462 1.1.2.2 bouyer {
463 1.1.2.2 bouyer u_int32_t cir;
464 1.1.2.2 bouyer
465 1.1.2.2 bouyer cir = bus_space_read_4(sc->sc_bst, sc->sc_bsh, TCDS_CIR);
466 1.1.2.2 bouyer
467 1.1.2.2 bouyer if ((cir & sc->sc_intrbits) != 0) {
468 1.1.2.2 bouyer if (clear) {
469 1.1.2.2 bouyer TCDS_CIR_CLR(cir, sc->sc_intrbits);
470 1.1.2.2 bouyer bus_space_write_4(sc->sc_bst, sc->sc_bsh, TCDS_CIR,
471 1.1.2.2 bouyer cir);
472 1.1.2.2 bouyer }
473 1.1.2.2 bouyer return (1);
474 1.1.2.2 bouyer } else
475 1.1.2.2 bouyer return (0);
476 1.1.2.2 bouyer }
477 1.1.2.2 bouyer
478 1.1.2.2 bouyer int
479 1.1.2.2 bouyer tcds_scsi_iserr(sc)
480 1.1.2.2 bouyer struct tcds_slotconfig *sc;
481 1.1.2.2 bouyer {
482 1.1.2.2 bouyer u_int32_t cir;
483 1.1.2.2 bouyer
484 1.1.2.2 bouyer cir = bus_space_read_4(sc->sc_bst, sc->sc_bsh, TCDS_CIR);
485 1.1.2.2 bouyer return ((cir & sc->sc_errorbits) != 0);
486 1.1.2.2 bouyer }
487 1.1.2.2 bouyer
488 1.1.2.2 bouyer int
489 1.1.2.2 bouyer tcds_intr(arg)
490 1.1.2.2 bouyer void *arg;
491 1.1.2.2 bouyer {
492 1.1.2.2 bouyer struct tcds_softc *sc = arg;
493 1.1.2.2 bouyer u_int32_t ir, ir0;
494 1.1.2.2 bouyer
495 1.1.2.2 bouyer /*
496 1.1.2.2 bouyer * XXX
497 1.1.2.2 bouyer * Copy and clear (gag!) the interrupts.
498 1.1.2.2 bouyer */
499 1.1.2.2 bouyer ir = ir0 = bus_space_read_4(sc->sc_bst, sc->sc_bsh, TCDS_CIR);
500 1.1.2.2 bouyer TCDS_CIR_CLR(ir0, TCDS_CIR_ALLINTR);
501 1.1.2.2 bouyer bus_space_write_4(sc->sc_bst, sc->sc_bsh, TCDS_CIR, ir0);
502 1.1.2.2 bouyer tc_syncbus();
503 1.1.2.2 bouyer
504 1.1.2.2 bouyer #define INCRINTRCNT(slot) sc->sc_slots[slot].sc_evcnt.ev_count++
505 1.1.2.2 bouyer
506 1.1.2.2 bouyer #define CHECKINTR(slot) \
507 1.1.2.2 bouyer if (ir & sc->sc_slots[slot].sc_intrbits) { \
508 1.1.2.2 bouyer INCRINTRCNT(slot); \
509 1.1.2.2 bouyer (void)(*sc->sc_slots[slot].sc_intrhand) \
510 1.1.2.2 bouyer (sc->sc_slots[slot].sc_intrarg); \
511 1.1.2.2 bouyer }
512 1.1.2.2 bouyer CHECKINTR(0);
513 1.1.2.2 bouyer CHECKINTR(1);
514 1.1.2.2 bouyer #undef CHECKINTR
515 1.1.2.2 bouyer
516 1.1.2.2 bouyer #ifdef DIAGNOSTIC
517 1.1.2.2 bouyer /*
518 1.1.2.2 bouyer * Interrupts not currently handled, but would like to know if they
519 1.1.2.2 bouyer * occur.
520 1.1.2.2 bouyer *
521 1.1.2.2 bouyer * XXX
522 1.1.2.2 bouyer * Don't know if we have to set the interrupt mask and enable bits
523 1.1.2.2 bouyer * in the IMER to allow some of them to happen?
524 1.1.2.2 bouyer */
525 1.1.2.2 bouyer #define PRINTINTR(msg, bits) \
526 1.1.2.2 bouyer if (ir & bits) \
527 1.1.2.2 bouyer printf("%s: %s", sc->sc_dv.dv_xname, msg);
528 1.1.2.2 bouyer PRINTINTR("SCSI0 DREQ interrupt.\n", TCDS_CIR_SCSI0_DREQ);
529 1.1.2.2 bouyer PRINTINTR("SCSI1 DREQ interrupt.\n", TCDS_CIR_SCSI1_DREQ);
530 1.1.2.2 bouyer PRINTINTR("SCSI0 prefetch interrupt.\n", TCDS_CIR_SCSI0_PREFETCH);
531 1.1.2.2 bouyer PRINTINTR("SCSI1 prefetch interrupt.\n", TCDS_CIR_SCSI1_PREFETCH);
532 1.1.2.2 bouyer PRINTINTR("SCSI0 DMA error.\n", TCDS_CIR_SCSI0_DMA);
533 1.1.2.2 bouyer PRINTINTR("SCSI1 DMA error.\n", TCDS_CIR_SCSI1_DMA);
534 1.1.2.2 bouyer PRINTINTR("SCSI0 DB parity error.\n", TCDS_CIR_SCSI0_DB);
535 1.1.2.2 bouyer PRINTINTR("SCSI1 DB parity error.\n", TCDS_CIR_SCSI1_DB);
536 1.1.2.2 bouyer PRINTINTR("SCSI0 DMA buffer parity error.\n", TCDS_CIR_SCSI0_DMAB_PAR);
537 1.1.2.2 bouyer PRINTINTR("SCSI1 DMA buffer parity error.\n", TCDS_CIR_SCSI1_DMAB_PAR);
538 1.1.2.2 bouyer PRINTINTR("SCSI0 DMA read parity error.\n", TCDS_CIR_SCSI0_DMAR_PAR);
539 1.1.2.2 bouyer PRINTINTR("SCSI1 DMA read parity error.\n", TCDS_CIR_SCSI1_DMAR_PAR);
540 1.1.2.2 bouyer PRINTINTR("TC write parity error.\n", TCDS_CIR_TCIOW_PAR);
541 1.1.2.2 bouyer PRINTINTR("TC I/O address parity error.\n", TCDS_CIR_TCIOA_PAR);
542 1.1.2.2 bouyer #undef PRINTINTR
543 1.1.2.2 bouyer #endif
544 1.1.2.2 bouyer
545 1.1.2.2 bouyer /*
546 1.1.2.2 bouyer * XXX
547 1.1.2.2 bouyer * The MACH source had this, with the comment:
548 1.1.2.2 bouyer * This is wrong, but machine keeps dying.
549 1.1.2.2 bouyer */
550 1.1.2.2 bouyer DELAY(1);
551 1.1.2.2 bouyer
552 1.1.2.2 bouyer return (1);
553 1.1.2.2 bouyer }
554 1.1.2.2 bouyer
555 1.1.2.2 bouyer void
556 1.1.2.2 bouyer tcds_params(sc, chip, idp, fastp)
557 1.1.2.2 bouyer struct tcds_softc *sc;
558 1.1.2.2 bouyer int chip, *idp, *fastp;
559 1.1.2.2 bouyer {
560 1.1.2.2 bouyer int id, fast;
561 1.1.2.2 bouyer u_int32_t ids;
562 1.1.2.2 bouyer
563 1.1.2.2 bouyer #ifdef __alpha__
564 1.1.2.2 bouyer if (sc->sc_flags & TCDSF_BASEBOARD) {
565 1.1.2.2 bouyer extern u_int8_t dec_3000_scsiid[], dec_3000_scsifast[];
566 1.1.2.2 bouyer
567 1.1.2.2 bouyer id = dec_3000_scsiid[chip];
568 1.1.2.2 bouyer fast = dec_3000_scsifast[chip];
569 1.1.2.2 bouyer } else
570 1.1.2.2 bouyer #endif /* __alpha__ */
571 1.1.2.2 bouyer {
572 1.1.2.2 bouyer /*
573 1.1.2.2 bouyer * SCSI IDs are stored in the EEPROM, along with whether or
574 1.1.2.2 bouyer * not the device is "fast". Chip 0 is the high nibble,
575 1.1.2.2 bouyer * chip 1 the low nibble.
576 1.1.2.2 bouyer */
577 1.1.2.2 bouyer ids = bus_space_read_4(sc->sc_bst, sc->sc_bsh, TCDS_EEPROM_IDS);
578 1.1.2.2 bouyer if (chip == 0)
579 1.1.2.2 bouyer ids >>= 4;
580 1.1.2.2 bouyer
581 1.1.2.2 bouyer id = ids & 0x7;
582 1.1.2.2 bouyer fast = ids & 0x8;
583 1.1.2.2 bouyer }
584 1.1.2.2 bouyer
585 1.1.2.2 bouyer if (id < 0 || id > 7) {
586 1.1.2.2 bouyer printf("%s: WARNING: bad SCSI ID %d for chip %d, using 7\n",
587 1.1.2.2 bouyer sc->sc_dv.dv_xname, id, chip);
588 1.1.2.2 bouyer id = 7;
589 1.1.2.2 bouyer }
590 1.1.2.2 bouyer
591 1.1.2.2 bouyer if (fast)
592 1.1.2.2 bouyer printf("%s: fast mode set for chip %d\n",
593 1.1.2.2 bouyer sc->sc_dv.dv_xname, chip);
594 1.1.2.2 bouyer
595 1.1.2.2 bouyer *idp = id;
596 1.1.2.2 bouyer *fastp = fast;
597 1.1.2.2 bouyer }
598