ahc_isa.c revision 1.16.2.2 1 1.16.2.2 thorpej /* $NetBSD: ahc_isa.c,v 1.16.2.2 2002/01/07 21:47:02 thorpej Exp $ */
2 1.16.2.2 thorpej
3 1.16.2.2 thorpej /*
4 1.16.2.2 thorpej * Product specific probe and attach routines for:
5 1.16.2.2 thorpej * AHA-284X VL-bus SCSI controllers
6 1.16.2.2 thorpej *
7 1.16.2.2 thorpej * Copyright (c) 1994, 1995, 1996, 1997, 1998 Justin T. Gibbs.
8 1.16.2.2 thorpej * All rights reserved.
9 1.16.2.2 thorpej *
10 1.16.2.2 thorpej * Redistribution and use in source and binary forms, with or without
11 1.16.2.2 thorpej * modification, are permitted provided that the following conditions
12 1.16.2.2 thorpej * are met:
13 1.16.2.2 thorpej * 1. Redistributions of source code must retain the above copyright
14 1.16.2.2 thorpej * notice immediately at the beginning of the file, without modification,
15 1.16.2.2 thorpej * this list of conditions, and the following disclaimer.
16 1.16.2.2 thorpej * 2. The name of the author may not be used to endorse or promote products
17 1.16.2.2 thorpej * derived from this software without specific prior written permission.
18 1.16.2.2 thorpej *
19 1.16.2.2 thorpej * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
20 1.16.2.2 thorpej * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 1.16.2.2 thorpej * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 1.16.2.2 thorpej * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
23 1.16.2.2 thorpej * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 1.16.2.2 thorpej * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 1.16.2.2 thorpej * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 1.16.2.2 thorpej * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 1.16.2.2 thorpej * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 1.16.2.2 thorpej * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 1.16.2.2 thorpej * SUCH DAMAGE.
30 1.16.2.2 thorpej *
31 1.16.2.2 thorpej * $FreeBSD: src/sys/dev/aic7xxx/ahc_eisa.c,v 1.15 2000/01/29 14:22:19 peter Exp $
32 1.16.2.2 thorpej */
33 1.16.2.2 thorpej
34 1.16.2.2 thorpej /*-
35 1.16.2.2 thorpej * Copyright (c) 1996, 1997 The NetBSD Foundation, Inc.
36 1.16.2.2 thorpej * All rights reserved.
37 1.16.2.2 thorpej *
38 1.16.2.2 thorpej * This code is derived from software contributed to The NetBSD Foundation
39 1.16.2.2 thorpej * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
40 1.16.2.2 thorpej * NASA Ames Research Center.
41 1.16.2.2 thorpej *
42 1.16.2.2 thorpej * Redistribution and use in source and binary forms, with or without
43 1.16.2.2 thorpej * modification, are permitted provided that the following conditions
44 1.16.2.2 thorpej * are met:
45 1.16.2.2 thorpej * 1. Redistributions of source code must retain the above copyright
46 1.16.2.2 thorpej * notice, this list of conditions and the following disclaimer.
47 1.16.2.2 thorpej * 2. Redistributions in binary form must reproduce the above copyright
48 1.16.2.2 thorpej * notice, this list of conditions and the following disclaimer in the
49 1.16.2.2 thorpej * documentation and/or other materials provided with the distribution.
50 1.16.2.2 thorpej * 3. All advertising materials mentioning features or use of this software
51 1.16.2.2 thorpej * must display the following acknowledgement:
52 1.16.2.2 thorpej * This product includes software developed by the NetBSD
53 1.16.2.2 thorpej * Foundation, Inc. and its contributors.
54 1.16.2.2 thorpej * 4. Neither the name of The NetBSD Foundation nor the names of its
55 1.16.2.2 thorpej * contributors may be used to endorse or promote products derived
56 1.16.2.2 thorpej * from this software without specific prior written permission.
57 1.16.2.2 thorpej *
58 1.16.2.2 thorpej * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
59 1.16.2.2 thorpej * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
60 1.16.2.2 thorpej * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
61 1.16.2.2 thorpej * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
62 1.16.2.2 thorpej * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
63 1.16.2.2 thorpej * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
64 1.16.2.2 thorpej * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
65 1.16.2.2 thorpej * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
66 1.16.2.2 thorpej * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
67 1.16.2.2 thorpej * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
68 1.16.2.2 thorpej * POSSIBILITY OF SUCH DAMAGE.
69 1.16.2.2 thorpej */
70 1.16.2.2 thorpej
71 1.16.2.2 thorpej /*
72 1.16.2.2 thorpej * Copyright (c) 1995, 1996 Christopher G. Demetriou
73 1.16.2.2 thorpej * All rights reserved.
74 1.16.2.2 thorpej *
75 1.16.2.2 thorpej * Redistribution and use in source and binary forms, with or without
76 1.16.2.2 thorpej * modification, are permitted provided that the following conditions
77 1.16.2.2 thorpej * are met:
78 1.16.2.2 thorpej * 1. Redistributions of source code must retain the above copyright
79 1.16.2.2 thorpej * notice, this list of conditions and the following disclaimer.
80 1.16.2.2 thorpej * 2. Redistributions in binary form must reproduce the above copyright
81 1.16.2.2 thorpej * notice, this list of conditions and the following disclaimer in the
82 1.16.2.2 thorpej * documentation and/or other materials provided with the distribution.
83 1.16.2.2 thorpej * 3. All advertising materials mentioning features or use of this software
84 1.16.2.2 thorpej * must display the following acknowledgement:
85 1.16.2.2 thorpej * This product includes software developed by Christopher G. Demetriou
86 1.16.2.2 thorpej * for the NetBSD Project.
87 1.16.2.2 thorpej * 4. The name of the author may not be used to endorse or promote products
88 1.16.2.2 thorpej * derived from this software without specific prior written permission
89 1.16.2.2 thorpej *
90 1.16.2.2 thorpej * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
91 1.16.2.2 thorpej * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
92 1.16.2.2 thorpej * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
93 1.16.2.2 thorpej * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
94 1.16.2.2 thorpej * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
95 1.16.2.2 thorpej * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
96 1.16.2.2 thorpej * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
97 1.16.2.2 thorpej * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
98 1.16.2.2 thorpej * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
99 1.16.2.2 thorpej * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
100 1.16.2.2 thorpej */
101 1.16.2.2 thorpej
102 1.16.2.2 thorpej /*
103 1.16.2.2 thorpej * This front-end driver is really sort of a hack. The AHA-284X likes
104 1.16.2.2 thorpej * to masquerade as an EISA device. However, on VLbus machines with
105 1.16.2.2 thorpej * no EISA signature in the BIOS, the EISA bus will never be scanned.
106 1.16.2.2 thorpej * This is intended to catch the 284X controllers on those systems
107 1.16.2.2 thorpej * by looking in "EISA i/o space" for 284X controllers.
108 1.16.2.2 thorpej *
109 1.16.2.2 thorpej * This relies heavily on i/o port accounting. We also just use the
110 1.16.2.2 thorpej * EISA macros for everything ... it's a real waste to redefine them.
111 1.16.2.2 thorpej *
112 1.16.2.2 thorpej * Note: there isn't any #ifdef for FreeBSD in this file, since the
113 1.16.2.2 thorpej * FreeBSD EISA driver handles all cases of the 284X.
114 1.16.2.2 thorpej *
115 1.16.2.2 thorpej * -- Jason R. Thorpe <thorpej (at) NetBSD.ORG>
116 1.16.2.2 thorpej * July 12, 1996
117 1.16.2.2 thorpej */
118 1.16.2.2 thorpej
119 1.16.2.2 thorpej #include <sys/cdefs.h>
120 1.16.2.2 thorpej __KERNEL_RCSID(0, "$NetBSD: ahc_isa.c,v 1.16.2.2 2002/01/07 21:47:02 thorpej Exp $");
121 1.16.2.2 thorpej
122 1.16.2.2 thorpej #include <sys/param.h>
123 1.16.2.2 thorpej #include <sys/systm.h>
124 1.16.2.2 thorpej #include <sys/kernel.h>
125 1.16.2.2 thorpej #include <sys/device.h>
126 1.16.2.2 thorpej #include <sys/queue.h>
127 1.16.2.2 thorpej #include <sys/malloc.h>
128 1.16.2.2 thorpej #include <sys/reboot.h>
129 1.16.2.2 thorpej
130 1.16.2.2 thorpej #include <machine/bus.h>
131 1.16.2.2 thorpej #include <machine/intr.h>
132 1.16.2.2 thorpej
133 1.16.2.2 thorpej #include <dev/scsipi/scsi_all.h>
134 1.16.2.2 thorpej #include <dev/scsipi/scsipi_all.h>
135 1.16.2.2 thorpej #include <dev/scsipi/scsiconf.h>
136 1.16.2.2 thorpej
137 1.16.2.2 thorpej #include <dev/isa/isavar.h>
138 1.16.2.2 thorpej
139 1.16.2.2 thorpej #include <dev/eisa/eisareg.h>
140 1.16.2.2 thorpej #include <dev/eisa/eisavar.h>
141 1.16.2.2 thorpej #include <dev/eisa/eisadevs.h>
142 1.16.2.2 thorpej
143 1.16.2.2 thorpej #include <dev/microcode/aic7xxx/aic7xxx_reg.h>
144 1.16.2.2 thorpej #include <dev/ic/aic7xxxvar.h>
145 1.16.2.2 thorpej #include <dev/ic/aic77xxreg.h>
146 1.16.2.2 thorpej #include <dev/ic/aic77xxvar.h>
147 1.16.2.2 thorpej #include <dev/ic/smc93cx6var.h>
148 1.16.2.2 thorpej
149 1.16.2.2 thorpej /* IO port address setting range as EISA slot number */
150 1.16.2.2 thorpej #define AHC_ISA_MIN_SLOT 0x1 /* from iobase = 0x1c00 */
151 1.16.2.2 thorpej #define AHC_ISA_MAX_SLOT 0xe /* to iobase = 0xec00 */
152 1.16.2.2 thorpej
153 1.16.2.2 thorpej #define AHC_ISA_SLOT_OFFSET AHC_EISA_SLOT_OFFSET
154 1.16.2.2 thorpej #define AHC_ISA_IOSIZE AHC_EISA_IOSIZE
155 1.16.2.2 thorpej
156 1.16.2.2 thorpej /*
157 1.16.2.2 thorpej * I/O port offsets
158 1.16.2.2 thorpej */
159 1.16.2.2 thorpej #define AHC_ISA_VID (EISA_SLOTOFF_VID - AHC_ISA_SLOT_OFFSET)
160 1.16.2.2 thorpej #define AHC_ISA_PID (EISA_SLOTOFF_PID - AHC_ISA_SLOT_OFFSET)
161 1.16.2.2 thorpej #define AHC_ISA_PRIMING AHC_ISA_VID /* enable vendor/product ID */
162 1.16.2.2 thorpej
163 1.16.2.2 thorpej /*
164 1.16.2.2 thorpej * AHC_ISA_PRIMING register values (write)
165 1.16.2.2 thorpej */
166 1.16.2.2 thorpej #define AHC_ISA_PRIMING_VID(index) (AHC_ISA_VID + (index))
167 1.16.2.2 thorpej #define AHC_ISA_PRIMING_PID(index) (AHC_ISA_PID + (index))
168 1.16.2.2 thorpej
169 1.16.2.2 thorpej int ahc_isa_idstring __P((bus_space_tag_t, bus_space_handle_t, char *));
170 1.16.2.2 thorpej int ahc_isa_match __P((struct isa_attach_args *, bus_addr_t));
171 1.16.2.2 thorpej
172 1.16.2.2 thorpej int ahc_isa_probe __P((struct device *, struct cfdata *, void *));
173 1.16.2.2 thorpej void ahc_isa_attach __P((struct device *, struct device *, void *));
174 1.16.2.2 thorpej void aha2840_load_seeprom __P((struct ahc_softc *ahc));
175 1.16.2.2 thorpej
176 1.16.2.2 thorpej struct cfattach ahc_isa_ca = {
177 1.16.2.2 thorpej sizeof(struct ahc_softc), ahc_isa_probe, ahc_isa_attach
178 1.16.2.2 thorpej };
179 1.16.2.2 thorpej
180 1.16.2.2 thorpej /*
181 1.16.2.2 thorpej * This keeps track of which slots are to be checked next if the
182 1.16.2.2 thorpej * iobase locator is a wildcard. A simple static variable isn't enough,
183 1.16.2.2 thorpej * since it's conceivable that a system might have more than one ISA
184 1.16.2.2 thorpej * bus.
185 1.16.2.2 thorpej *
186 1.16.2.2 thorpej * The "bus" member is the unit number of the parent ISA bus, e.g. "0"
187 1.16.2.2 thorpej * for "isa0".
188 1.16.2.2 thorpej */
189 1.16.2.2 thorpej struct ahc_isa_slot {
190 1.16.2.2 thorpej LIST_ENTRY(ahc_isa_slot) link;
191 1.16.2.2 thorpej int bus;
192 1.16.2.2 thorpej int slot;
193 1.16.2.2 thorpej };
194 1.16.2.2 thorpej static LIST_HEAD(, ahc_isa_slot) ahc_isa_all_slots;
195 1.16.2.2 thorpej static int ahc_isa_slot_initialized;
196 1.16.2.2 thorpej
197 1.16.2.2 thorpej int
198 1.16.2.2 thorpej ahc_isa_idstring(iot, ioh, idstring)
199 1.16.2.2 thorpej bus_space_tag_t iot;
200 1.16.2.2 thorpej bus_space_handle_t ioh;
201 1.16.2.2 thorpej char *idstring;
202 1.16.2.2 thorpej {
203 1.16.2.2 thorpej u_int8_t vid[EISA_NVIDREGS], pid[EISA_NPIDREGS];
204 1.16.2.2 thorpej int i;
205 1.16.2.2 thorpej
206 1.16.2.2 thorpej /* Get the vendor ID bytes */
207 1.16.2.2 thorpej for (i = 0; i < EISA_NVIDREGS; i++) {
208 1.16.2.2 thorpej bus_space_write_1(iot, ioh, AHC_ISA_PRIMING,
209 1.16.2.2 thorpej AHC_ISA_PRIMING_VID(i));
210 1.16.2.2 thorpej vid[i] = bus_space_read_1(iot, ioh, AHC_ISA_VID + i);
211 1.16.2.2 thorpej }
212 1.16.2.2 thorpej
213 1.16.2.2 thorpej /* Check for device existence */
214 1.16.2.2 thorpej if (EISA_VENDID_NODEV(vid)) {
215 1.16.2.2 thorpej #if 0
216 1.16.2.2 thorpej printf("ahc_isa_idstring: no device at 0x%lx\n",
217 1.16.2.2 thorpej ioh); /* XXX knows about ioh guts */
218 1.16.2.2 thorpej printf("\t(0x%x, 0x%x)\n", vid[0], vid[1]);
219 1.16.2.2 thorpej #endif
220 1.16.2.2 thorpej return (0);
221 1.16.2.2 thorpej }
222 1.16.2.2 thorpej
223 1.16.2.2 thorpej /* And check that the firmware didn't biff something badly */
224 1.16.2.2 thorpej if (EISA_VENDID_IDDELAY(vid)) {
225 1.16.2.2 thorpej printf("ahc_isa_idstring: BIOS biffed it at 0x%lx\n",
226 1.16.2.2 thorpej ioh); /* XXX knows about ioh guts */
227 1.16.2.2 thorpej return (0);
228 1.16.2.2 thorpej }
229 1.16.2.2 thorpej
230 1.16.2.2 thorpej /* Get the product ID bytes */
231 1.16.2.2 thorpej for (i = 0; i < EISA_NPIDREGS; i++) {
232 1.16.2.2 thorpej bus_space_write_1(iot, ioh, AHC_ISA_PRIMING,
233 1.16.2.2 thorpej AHC_ISA_PRIMING_PID(i));
234 1.16.2.2 thorpej pid[i] = bus_space_read_1(iot, ioh, AHC_ISA_PID + i);
235 1.16.2.2 thorpej }
236 1.16.2.2 thorpej
237 1.16.2.2 thorpej /* Create the ID string from the vendor and product IDs */
238 1.16.2.2 thorpej idstring[0] = EISA_VENDID_0(vid);
239 1.16.2.2 thorpej idstring[1] = EISA_VENDID_1(vid);
240 1.16.2.2 thorpej idstring[2] = EISA_VENDID_2(vid);
241 1.16.2.2 thorpej idstring[3] = EISA_PRODID_0(pid);
242 1.16.2.2 thorpej idstring[4] = EISA_PRODID_1(pid);
243 1.16.2.2 thorpej idstring[5] = EISA_PRODID_2(pid);
244 1.16.2.2 thorpej idstring[6] = EISA_PRODID_3(pid);
245 1.16.2.2 thorpej idstring[7] = '\0'; /* sanity */
246 1.16.2.2 thorpej
247 1.16.2.2 thorpej return (1);
248 1.16.2.2 thorpej }
249 1.16.2.2 thorpej
250 1.16.2.2 thorpej int
251 1.16.2.2 thorpej ahc_isa_match(ia, iobase)
252 1.16.2.2 thorpej struct isa_attach_args *ia;
253 1.16.2.2 thorpej bus_addr_t iobase;
254 1.16.2.2 thorpej {
255 1.16.2.2 thorpej bus_space_tag_t iot = ia->ia_iot;
256 1.16.2.2 thorpej bus_space_handle_t ioh;
257 1.16.2.2 thorpej int irq;
258 1.16.2.2 thorpej char idstring[EISA_IDSTRINGLEN];
259 1.16.2.2 thorpej
260 1.16.2.2 thorpej /*
261 1.16.2.2 thorpej * Get a mapping for the while slot-specific address
262 1.16.2.2 thorpej * space. If we can't, assume nothing's there, but
263 1.16.2.2 thorpej * warn about it.
264 1.16.2.2 thorpej */
265 1.16.2.2 thorpej if (bus_space_map(iot, iobase, AHC_ISA_IOSIZE, 0, &ioh)) {
266 1.16.2.2 thorpej #if 0
267 1.16.2.2 thorpej /*
268 1.16.2.2 thorpej * Don't print anything out here, since this could
269 1.16.2.2 thorpej * be common on machines configured to look for
270 1.16.2.2 thorpej * ahc_eisa and ahc_isa.
271 1.16.2.2 thorpej */
272 1.16.2.2 thorpej printf("ahc_isa_match: can't map I/O space for 0x%x\n",
273 1.16.2.2 thorpej iobase);
274 1.16.2.2 thorpej #endif
275 1.16.2.2 thorpej return (0);
276 1.16.2.2 thorpej }
277 1.16.2.2 thorpej
278 1.16.2.2 thorpej if (!ahc_isa_idstring(iot, ioh, idstring))
279 1.16.2.2 thorpej irq = -1; /* cannot get the ID string */
280 1.16.2.2 thorpej else if (strcmp(idstring, "ADP7756") &&
281 1.16.2.2 thorpej strcmp(idstring, "ADP7757"))
282 1.16.2.2 thorpej irq = -1; /* unknown ID strings */
283 1.16.2.2 thorpej else
284 1.16.2.2 thorpej irq = ahc_aic77xx_irq(iot, ioh);
285 1.16.2.2 thorpej
286 1.16.2.2 thorpej bus_space_unmap(iot, ioh, AHC_ISA_IOSIZE);
287 1.16.2.2 thorpej
288 1.16.2.2 thorpej if (irq < 0)
289 1.16.2.2 thorpej return (0);
290 1.16.2.2 thorpej
291 1.16.2.2 thorpej if (ia->ia_irq[0].ir_irq != ISACF_IRQ_DEFAULT &&
292 1.16.2.2 thorpej ia->ia_irq[0].ir_irq != irq) {
293 1.16.2.2 thorpej printf("ahc_isa_match: irq mismatch (kernel %d, card %d)\n",
294 1.16.2.2 thorpej ia->ia_irq[0].ir_irq, irq);
295 1.16.2.2 thorpej return (0);
296 1.16.2.2 thorpej }
297 1.16.2.2 thorpej
298 1.16.2.2 thorpej /* We have a match */
299 1.16.2.2 thorpej ia->ia_nio = 1;
300 1.16.2.2 thorpej ia->ia_io[0].ir_addr = iobase;
301 1.16.2.2 thorpej ia->ia_io[0].ir_size = AHC_ISA_IOSIZE;
302 1.16.2.2 thorpej
303 1.16.2.2 thorpej ia->ia_nirq = 1;
304 1.16.2.2 thorpej ia->ia_irq[0].ir_irq = irq;
305 1.16.2.2 thorpej
306 1.16.2.2 thorpej ia->ia_ndrq = 0;
307 1.16.2.2 thorpej ia->ia_niomem = 0;
308 1.16.2.2 thorpej
309 1.16.2.2 thorpej return (1);
310 1.16.2.2 thorpej }
311 1.16.2.2 thorpej
312 1.16.2.2 thorpej /*
313 1.16.2.2 thorpej * Check the slots looking for a board we recognise
314 1.16.2.2 thorpej * If we find one, note it's address (slot) and call
315 1.16.2.2 thorpej * the actual probe routine to check it out.
316 1.16.2.2 thorpej */
317 1.16.2.2 thorpej int
318 1.16.2.2 thorpej ahc_isa_probe(parent, match, aux)
319 1.16.2.2 thorpej struct device *parent;
320 1.16.2.2 thorpej struct cfdata *match;
321 1.16.2.2 thorpej void *aux;
322 1.16.2.2 thorpej {
323 1.16.2.2 thorpej struct isa_attach_args *ia = aux;
324 1.16.2.2 thorpej struct ahc_isa_slot *as;
325 1.16.2.2 thorpej
326 1.16.2.2 thorpej if (ahc_isa_slot_initialized == 0) {
327 1.16.2.2 thorpej LIST_INIT(&ahc_isa_all_slots);
328 1.16.2.2 thorpej ahc_isa_slot_initialized = 1;
329 1.16.2.2 thorpej }
330 1.16.2.2 thorpej
331 1.16.2.2 thorpej if (ia->ia_nio < 1)
332 1.16.2.2 thorpej return (0);
333 1.16.2.2 thorpej if (ia->ia_nirq < 1)
334 1.16.2.2 thorpej return (0);
335 1.16.2.2 thorpej
336 1.16.2.2 thorpej if (ISA_DIRECT_CONFIG(ia))
337 1.16.2.2 thorpej return (0);
338 1.16.2.2 thorpej
339 1.16.2.2 thorpej if (ia->ia_io[0].ir_addr != ISACF_PORT_DEFAULT)
340 1.16.2.2 thorpej return (ahc_isa_match(ia, ia->ia_io[0].ir_addr));
341 1.16.2.2 thorpej
342 1.16.2.2 thorpej /*
343 1.16.2.2 thorpej * Find this bus's state. If we don't yet have a slot
344 1.16.2.2 thorpej * marker, allocate and initialize one.
345 1.16.2.2 thorpej */
346 1.16.2.2 thorpej for (as = ahc_isa_all_slots.lh_first; as != NULL;
347 1.16.2.2 thorpej as = as->link.le_next)
348 1.16.2.2 thorpej if (as->bus == parent->dv_unit)
349 1.16.2.2 thorpej goto found_slot_marker;
350 1.16.2.2 thorpej
351 1.16.2.2 thorpej /*
352 1.16.2.2 thorpej * Don't have one, so make one.
353 1.16.2.2 thorpej */
354 1.16.2.2 thorpej as = (struct ahc_isa_slot *)
355 1.16.2.2 thorpej malloc(sizeof(struct ahc_isa_slot), M_DEVBUF, M_NOWAIT);
356 1.16.2.2 thorpej if (as == NULL)
357 1.16.2.2 thorpej panic("ahc_isa_probe: can't allocate slot marker");
358 1.16.2.2 thorpej
359 1.16.2.2 thorpej as->bus = parent->dv_unit;
360 1.16.2.2 thorpej as->slot = AHC_ISA_MIN_SLOT;
361 1.16.2.2 thorpej LIST_INSERT_HEAD(&ahc_isa_all_slots, as, link);
362 1.16.2.2 thorpej
363 1.16.2.2 thorpej found_slot_marker:
364 1.16.2.2 thorpej
365 1.16.2.2 thorpej for (; as->slot <= AHC_ISA_MAX_SLOT; as->slot++) {
366 1.16.2.2 thorpej if (ahc_isa_match(ia, EISA_SLOT_ADDR(as->slot) +
367 1.16.2.2 thorpej AHC_ISA_SLOT_OFFSET)) {
368 1.16.2.2 thorpej as->slot++; /* next slot to search */
369 1.16.2.2 thorpej return (1);
370 1.16.2.2 thorpej }
371 1.16.2.2 thorpej }
372 1.16.2.2 thorpej
373 1.16.2.2 thorpej /* No matching cards were found. */
374 1.16.2.2 thorpej return (0);
375 1.16.2.2 thorpej }
376 1.16.2.2 thorpej
377 1.16.2.2 thorpej void
378 1.16.2.2 thorpej ahc_isa_attach(parent, self, aux)
379 1.16.2.2 thorpej struct device *parent, *self;
380 1.16.2.2 thorpej void *aux;
381 1.16.2.2 thorpej {
382 1.16.2.2 thorpej struct ahc_softc *ahc = (void *)self;
383 1.16.2.2 thorpej struct isa_attach_args *ia = aux;
384 1.16.2.2 thorpej bus_space_tag_t iot = ia->ia_iot;
385 1.16.2.2 thorpej bus_space_handle_t ioh;
386 1.16.2.2 thorpej int irq, intrtype;
387 1.16.2.2 thorpej const char *intrtypestr;
388 1.16.2.2 thorpej char idstring[EISA_IDSTRINGLEN];
389 1.16.2.2 thorpej
390 1.16.2.2 thorpej if (bus_space_map(iot, ia->ia_io[0].ir_addr, ia->ia_io[0].ir_size,
391 1.16.2.2 thorpej 0, &ioh)) {
392 1.16.2.2 thorpej printf(": can't map i/o space\n");
393 1.16.2.2 thorpej return;
394 1.16.2.2 thorpej }
395 1.16.2.2 thorpej if (!ahc_isa_idstring(iot, ioh, idstring)) {
396 1.16.2.2 thorpej printf(": can't read ID string\n");
397 1.16.2.2 thorpej goto free_io;
398 1.16.2.2 thorpej }
399 1.16.2.2 thorpej if ((irq = ahc_aic77xx_irq(iot, ioh)) < 0) {
400 1.16.2.2 thorpej printf(": ahc_aic77xx_irq failed\n");
401 1.16.2.2 thorpej goto free_io;
402 1.16.2.2 thorpej }
403 1.16.2.2 thorpej
404 1.16.2.2 thorpej if (strcmp(idstring, "ADP7756") == 0) {
405 1.16.2.2 thorpej printf(": %s\n", EISA_PRODUCT_ADP7756);
406 1.16.2.2 thorpej } else if (strcmp(idstring, "ADP7757") == 0) {
407 1.16.2.2 thorpej printf(": %s\n", EISA_PRODUCT_ADP7757);
408 1.16.2.2 thorpej } else {
409 1.16.2.2 thorpej printf(": unknown device type %s\n", idstring);
410 1.16.2.2 thorpej goto free_io;
411 1.16.2.2 thorpej }
412 1.16.2.2 thorpej
413 1.16.2.2 thorpej if (ahc_alloc(ahc, ioh, iot, ia->ia_dmat,
414 1.16.2.2 thorpej AHC_AIC7770|AHC_VL, AHC_AIC7770_FE, AHC_FNONE))
415 1.16.2.2 thorpej goto free_io;
416 1.16.2.2 thorpej
417 1.16.2.2 thorpej /*
418 1.16.2.2 thorpej * Tell the bus-dma interface that we can do 32bit dma
419 1.16.2.2 thorpej * NOTE: this variable is first referenced in ahc_init().
420 1.16.2.2 thorpej */
421 1.16.2.2 thorpej ahc->sc_dmaflags = ISABUS_DMA_32BIT;
422 1.16.2.2 thorpej
423 1.16.2.2 thorpej ahc->channel = 'A';
424 1.16.2.2 thorpej ahc->channel_b = 'B';
425 1.16.2.2 thorpej if (ahc_reset(ahc) != 0)
426 1.16.2.2 thorpej goto free_ahc;
427 1.16.2.2 thorpej
428 1.16.2.2 thorpej /*
429 1.16.2.2 thorpej * The IRQMS bit enables level sensitive interrupts. Only allow
430 1.16.2.2 thorpej * IRQ sharing if it's set.
431 1.16.2.2 thorpej * NOTE: ahc->pause is initialized in ahc_alloc().
432 1.16.2.2 thorpej */
433 1.16.2.2 thorpej if (ahc->pause & IRQMS) {
434 1.16.2.2 thorpej intrtype = IST_LEVEL;
435 1.16.2.2 thorpej intrtypestr = "level sensitive";
436 1.16.2.2 thorpej } else {
437 1.16.2.2 thorpej intrtype = IST_EDGE;
438 1.16.2.2 thorpej intrtypestr = "edge triggered";
439 1.16.2.2 thorpej }
440 1.16.2.2 thorpej ahc->ih = isa_intr_establish(ia->ia_ic, irq,
441 1.16.2.2 thorpej intrtype, IPL_BIO, ahc_intr, ahc);
442 1.16.2.2 thorpej if (ahc->ih == NULL) {
443 1.16.2.2 thorpej printf("%s: couldn't establish %s interrupt\n",
444 1.16.2.2 thorpej ahc->sc_dev.dv_xname, intrtypestr);
445 1.16.2.2 thorpej goto free_ahc;
446 1.16.2.2 thorpej }
447 1.16.2.2 thorpej
448 1.16.2.2 thorpej /*
449 1.16.2.2 thorpej * Tell the user what type of interrupts we're using.
450 1.16.2.2 thorpej * usefull for debugging irq problems
451 1.16.2.2 thorpej */
452 1.16.2.2 thorpej if (bootverbose) {
453 1.16.2.2 thorpej printf("%s: Using %s interrupts\n",
454 1.16.2.2 thorpej ahc->sc_dev.dv_xname, intrtypestr);
455 1.16.2.2 thorpej }
456 1.16.2.2 thorpej
457 1.16.2.2 thorpej /*
458 1.16.2.2 thorpej * Now that we know we own the resources we need, do the
459 1.16.2.2 thorpej * card initialization.
460 1.16.2.2 thorpej */
461 1.16.2.2 thorpej aha2840_load_seeprom(ahc);
462 1.16.2.2 thorpej
463 1.16.2.2 thorpej /* Attach sub-devices */
464 1.16.2.2 thorpej if (ahc_aic77xx_attach(ahc) == 0)
465 1.16.2.2 thorpej return; /* succeed */
466 1.16.2.2 thorpej
467 1.16.2.2 thorpej /* failed */
468 1.16.2.2 thorpej isa_intr_disestablish(ia->ia_ic, ahc->ih);
469 1.16.2.2 thorpej free_ahc:
470 1.16.2.2 thorpej ahc_free(ahc);
471 1.16.2.2 thorpej free_io:
472 1.16.2.2 thorpej bus_space_unmap(iot, ioh, ia->ia_io[0].ir_size);
473 1.16.2.2 thorpej }
474 1.16.2.2 thorpej
475 1.16.2.2 thorpej /*
476 1.16.2.2 thorpej * Read the 284x SEEPROM.
477 1.16.2.2 thorpej */
478 1.16.2.2 thorpej void
479 1.16.2.2 thorpej aha2840_load_seeprom(struct ahc_softc *ahc)
480 1.16.2.2 thorpej {
481 1.16.2.2 thorpej struct seeprom_descriptor sd;
482 1.16.2.2 thorpej struct seeprom_config sc;
483 1.16.2.2 thorpej u_int16_t checksum = 0;
484 1.16.2.2 thorpej u_int8_t scsi_conf;
485 1.16.2.2 thorpej int have_seeprom;
486 1.16.2.2 thorpej
487 1.16.2.2 thorpej sd.sd_tag = ahc->tag;
488 1.16.2.2 thorpej sd.sd_bsh = ahc->bsh;
489 1.16.2.2 thorpej sd.sd_control_offset = SEECTL_2840;
490 1.16.2.2 thorpej sd.sd_status_offset = STATUS_2840;
491 1.16.2.2 thorpej sd.sd_dataout_offset = STATUS_2840;
492 1.16.2.2 thorpej sd.sd_chip = C46;
493 1.16.2.2 thorpej sd.sd_MS = 0;
494 1.16.2.2 thorpej sd.sd_RDY = EEPROM_TF;
495 1.16.2.2 thorpej sd.sd_CS = CS_2840;
496 1.16.2.2 thorpej sd.sd_CK = CK_2840;
497 1.16.2.2 thorpej sd.sd_DO = DO_2840;
498 1.16.2.2 thorpej sd.sd_DI = DI_2840;
499 1.16.2.2 thorpej
500 1.16.2.2 thorpej if (bootverbose)
501 1.16.2.2 thorpej printf("%s: Reading SEEPROM...", ahc_name(ahc));
502 1.16.2.2 thorpej have_seeprom = read_seeprom(&sd,
503 1.16.2.2 thorpej (u_int16_t *)&sc,
504 1.16.2.2 thorpej /*start_addr*/0,
505 1.16.2.2 thorpej sizeof(sc)/2);
506 1.16.2.2 thorpej
507 1.16.2.2 thorpej if (have_seeprom) {
508 1.16.2.2 thorpej /* Check checksum */
509 1.16.2.2 thorpej int i;
510 1.16.2.2 thorpej int maxaddr = (sizeof(sc)/2) - 1;
511 1.16.2.2 thorpej u_int16_t *scarray = (u_int16_t *)≻
512 1.16.2.2 thorpej
513 1.16.2.2 thorpej for (i = 0; i < maxaddr; i++)
514 1.16.2.2 thorpej checksum = checksum + scarray[i];
515 1.16.2.2 thorpej if (checksum != sc.checksum) {
516 1.16.2.2 thorpej if(bootverbose)
517 1.16.2.2 thorpej printf ("checksum error\n");
518 1.16.2.2 thorpej have_seeprom = 0;
519 1.16.2.2 thorpej } else if (bootverbose) {
520 1.16.2.2 thorpej printf("done.\n");
521 1.16.2.2 thorpej }
522 1.16.2.2 thorpej }
523 1.16.2.2 thorpej
524 1.16.2.2 thorpej if (!have_seeprom) {
525 1.16.2.2 thorpej if (bootverbose)
526 1.16.2.2 thorpej printf("%s: No SEEPROM available\n", ahc_name(ahc));
527 1.16.2.2 thorpej ahc->flags |= AHC_USEDEFAULTS;
528 1.16.2.2 thorpej } else {
529 1.16.2.2 thorpej /*
530 1.16.2.2 thorpej * Put the data we've collected down into SRAM
531 1.16.2.2 thorpej * where ahc_init will find it.
532 1.16.2.2 thorpej */
533 1.16.2.2 thorpej int i;
534 1.16.2.2 thorpej int max_targ = (ahc->features & AHC_WIDE) != 0 ? 16 : 8;
535 1.16.2.2 thorpej u_int16_t discenable;
536 1.16.2.2 thorpej
537 1.16.2.2 thorpej discenable = 0;
538 1.16.2.2 thorpej for (i = 0; i < max_targ; i++){
539 1.16.2.2 thorpej u_int8_t target_settings;
540 1.16.2.2 thorpej target_settings = (sc.device_flags[i] & CFXFER) << 4;
541 1.16.2.2 thorpej if (sc.device_flags[i] & CFSYNCH)
542 1.16.2.2 thorpej target_settings |= SOFS;
543 1.16.2.2 thorpej if (sc.device_flags[i] & CFWIDEB)
544 1.16.2.2 thorpej target_settings |= WIDEXFER;
545 1.16.2.2 thorpej if (sc.device_flags[i] & CFDISC)
546 1.16.2.2 thorpej discenable |= (0x01 << i);
547 1.16.2.2 thorpej ahc_outb(ahc, TARG_SCSIRATE + i, target_settings);
548 1.16.2.2 thorpej }
549 1.16.2.2 thorpej ahc_outb(ahc, DISC_DSB, ~(discenable & 0xff));
550 1.16.2.2 thorpej ahc_outb(ahc, DISC_DSB + 1, ~((discenable >> 8) & 0xff));
551 1.16.2.2 thorpej
552 1.16.2.2 thorpej ahc->our_id = sc.brtime_id & CFSCSIID;
553 1.16.2.2 thorpej
554 1.16.2.2 thorpej scsi_conf = (ahc->our_id & 0x7);
555 1.16.2.2 thorpej if (sc.adapter_control & CFSPARITY)
556 1.16.2.2 thorpej scsi_conf |= ENSPCHK;
557 1.16.2.2 thorpej if (sc.adapter_control & CFRESETB)
558 1.16.2.2 thorpej scsi_conf |= RESET_SCSI;
559 1.16.2.2 thorpej
560 1.16.2.2 thorpej if (sc.bios_control & CF284XEXTEND)
561 1.16.2.2 thorpej ahc->flags |= AHC_EXTENDED_TRANS_A;
562 1.16.2.2 thorpej /* Set SCSICONF info */
563 1.16.2.2 thorpej ahc_outb(ahc, SCSICONF, scsi_conf);
564 1.16.2.2 thorpej
565 1.16.2.2 thorpej if (sc.adapter_control & CF284XSTERM)
566 1.16.2.2 thorpej ahc->flags |= AHC_TERM_ENB_A;
567 1.16.2.2 thorpej }
568 1.16.2.2 thorpej }
569