ahc_isa.c revision 1.10 1 /* $NetBSD: ahc_isa.c,v 1.10 1998/03/09 06:20:26 mikel Exp $ */
2
3 /*
4 * Product specific probe and attach routines for:
5 * 284X VLbus SCSI controllers
6 *
7 * Copyright (c) 1994, 1995, 1996 Justin T. Gibbs.
8 * All rights reserved.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice immediately at the beginning of the file, without modification,
15 * this list of conditions, and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 * 3. The name of the author may not be used to endorse or promote products
20 * derived from this software without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
26 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * SUCH DAMAGE.
33 */
34
35 /*-
36 * Copyright (c) 1996, 1997 The NetBSD Foundation, Inc.
37 * All rights reserved.
38 *
39 * This code is derived from software contributed to The NetBSD Foundation
40 * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
41 * NASA Ames Research Center.
42 *
43 * Redistribution and use in source and binary forms, with or without
44 * modification, are permitted provided that the following conditions
45 * are met:
46 * 1. Redistributions of source code must retain the above copyright
47 * notice, this list of conditions and the following disclaimer.
48 * 2. Redistributions in binary form must reproduce the above copyright
49 * notice, this list of conditions and the following disclaimer in the
50 * documentation and/or other materials provided with the distribution.
51 * 3. All advertising materials mentioning features or use of this software
52 * must display the following acknowledgement:
53 * This product includes software developed by the NetBSD
54 * Foundation, Inc. and its contributors.
55 * 4. Neither the name of The NetBSD Foundation nor the names of its
56 * contributors may be used to endorse or promote products derived
57 * from this software without specific prior written permission.
58 *
59 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
60 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
61 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
62 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
63 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
64 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
65 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
66 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
67 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
68 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
69 * POSSIBILITY OF SUCH DAMAGE.
70 */
71
72 /*
73 * Copyright (c) 1995, 1996 Christopher G. Demetriou
74 * All rights reserved.
75 *
76 * Redistribution and use in source and binary forms, with or without
77 * modification, are permitted provided that the following conditions
78 * are met:
79 * 1. Redistributions of source code must retain the above copyright
80 * notice, this list of conditions and the following disclaimer.
81 * 2. Redistributions in binary form must reproduce the above copyright
82 * notice, this list of conditions and the following disclaimer in the
83 * documentation and/or other materials provided with the distribution.
84 * 3. All advertising materials mentioning features or use of this software
85 * must display the following acknowledgement:
86 * This product includes software developed by Christopher G. Demetriou
87 * for the NetBSD Project.
88 * 4. The name of the author may not be used to endorse or promote products
89 * derived from this software without specific prior written permission
90 *
91 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
92 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
93 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
94 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
95 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
96 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
97 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
98 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
99 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
100 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
101 */
102
103 /*
104 * This front-end driver is really sort of a hack. The AHA-284X likes
105 * to masquerade as an EISA device. However, on VLbus machines with
106 * no EISA signature in the BIOS, the EISA bus will never be scanned.
107 * This is intended to catch the 284X controllers on those systems
108 * by looking in "EISA i/o space" for 284X controllers.
109 *
110 * This relies heavily on i/o port accounting. We also just use the
111 * EISA macros for everything ... it's a real waste to redefine them.
112 *
113 * Note: there isn't any #ifdef for FreeBSD in this file, since the
114 * FreeBSD EISA driver handles all cases of the 284X.
115 *
116 * -- Jason R. Thorpe <thorpej (at) NetBSD.ORG>
117 * July 12, 1996
118 *
119 * TODO: some code could be shared with ahc_eisa.c, but it would probably
120 * be a logistical mightmare to even try.
121 */
122
123 #include <sys/param.h>
124 #include <sys/systm.h>
125 #include <sys/kernel.h>
126 #include <sys/device.h>
127 #include <sys/queue.h>
128 #include <sys/malloc.h>
129
130 #include <machine/bus.h>
131 #include <machine/intr.h>
132
133 #include <dev/scsipi/scsi_all.h>
134 #include <dev/scsipi/scsipi_all.h>
135 #include <dev/scsipi/scsiconf.h>
136
137 #include <dev/isa/isavar.h>
138
139 #include <dev/eisa/eisareg.h>
140 #include <dev/eisa/eisavar.h>
141 #include <dev/eisa/eisadevs.h>
142
143 #include <dev/ic/aic7xxxreg.h>
144 #include <dev/ic/aic7xxxvar.h>
145
146 /* IO port address setting range as EISA slot number */
147 #define AHC_ISA_MIN_SLOT 0x1 /* from iobase = 0x1c00 */
148 #define AHC_ISA_MAX_SLOT 0xe /* to iobase = 0xec00 */
149
150 #define AHC_ISA_SLOT_OFFSET 0xc00 /* offset from EISA IO space */
151 #define AHC_ISA_IOSIZE 0x100
152
153 /*
154 * I/O port offsets
155 */
156 #define INTDEF 0x5cul /* Interrupt Definition Register */
157 #define AHC_ISA_VID (EISA_SLOTOFF_VID - AHC_ISA_SLOT_OFFSET)
158 #define AHC_ISA_PID (EISA_SLOTOFF_PID - AHC_ISA_SLOT_OFFSET)
159 #define AHC_ISA_PRIMING AHC_ISA_VID /* enable vendor/product ID */
160
161 /*
162 * AHC_ISA_PRIMING register values (write)
163 */
164 #define AHC_ISA_PRIMING_VID(index) (AHC_ISA_VID + (index))
165 #define AHC_ISA_PRIMING_PID(index) (AHC_ISA_PID + (index))
166
167 int ahc_isa_irq __P((bus_space_tag_t, bus_space_handle_t));
168 int ahc_isa_idstring __P((bus_space_tag_t, bus_space_handle_t, char *));
169 int ahc_isa_match __P((struct isa_attach_args *, bus_addr_t));
170
171 int ahc_isa_probe __P((struct device *, void *, void *));
172 void ahc_isa_attach __P((struct device *, struct device *, void *));
173
174 struct cfattach ahc_isa_ca = {
175 sizeof(struct ahc_data), ahc_isa_probe, ahc_isa_attach
176 };
177
178 /*
179 * This keeps track of which slots are to be checked next if the
180 * iobase locator is a wildcard. A simple static variable isn't enough,
181 * since it's conceivable that a system might have more than one ISA
182 * bus.
183 *
184 * The "bus" member is the unit number of the parent ISA bus, e.g. "0"
185 * for "isa0".
186 */
187 struct ahc_isa_slot {
188 LIST_ENTRY(ahc_isa_slot) link;
189 int bus;
190 int slot;
191 };
192 static LIST_HEAD(, ahc_isa_slot) ahc_isa_all_slots;
193 static int ahc_isa_slot_initialized;
194
195 /*
196 * Return irq setting of the board, otherwise -1.
197 */
198 int
199 ahc_isa_irq(iot, ioh)
200 bus_space_tag_t iot;
201 bus_space_handle_t ioh;
202 {
203 int irq;
204 u_char intdef;
205
206 ahc_reset("ahc_isa", iot, ioh);
207 intdef = bus_space_read_1(iot, ioh, INTDEF);
208 switch (irq = (intdef & 0xf)) {
209 case 9:
210 case 10:
211 case 11:
212 case 12:
213 case 14:
214 case 15:
215 break;
216 default:
217 printf("ahc_isa_irq: illegal irq setting %d\n", irq);
218 return -1;
219 }
220
221 /* Note that we are going and return (to probe) */
222 return irq;
223 }
224
225 int
226 ahc_isa_idstring(iot, ioh, idstring)
227 bus_space_tag_t iot;
228 bus_space_handle_t ioh;
229 char *idstring;
230 {
231 u_int8_t vid[EISA_NVIDREGS], pid[EISA_NPIDREGS];
232 int i;
233
234 /* Get the vendor ID bytes */
235 for (i = 0; i < EISA_NVIDREGS; i++) {
236 bus_space_write_1(iot, ioh, AHC_ISA_PRIMING,
237 AHC_ISA_PRIMING_VID(i));
238 vid[i] = bus_space_read_1(iot, ioh, AHC_ISA_VID + i);
239 }
240
241 /* Check for device existence */
242 if (EISA_VENDID_NODEV(vid)) {
243 #if 0
244 printf("ahc_isa_idstring: no device at 0x%lx\n",
245 ioh); /* XXX knows about ioh guts */
246 printf("\t(0x%x, 0x%x)\n", vid[0], vid[1]);
247 #endif
248 return (0);
249 }
250
251 /* And check that the firmware didn't biff something badly */
252 if (EISA_VENDID_IDDELAY(vid)) {
253 printf("ahc_isa_idstring: BIOS biffed it at 0x%lx\n",
254 ioh); /* XXX knows about ioh guts */
255 return (0);
256 }
257
258 /* Get the product ID bytes */
259 for (i = 0; i < EISA_NPIDREGS; i++) {
260 bus_space_write_1(iot, ioh, AHC_ISA_PRIMING,
261 AHC_ISA_PRIMING_PID(i));
262 pid[i] = bus_space_read_1(iot, ioh, AHC_ISA_PID + i);
263 }
264
265 /* Create the ID string from the vendor and product IDs */
266 idstring[0] = EISA_VENDID_0(vid);
267 idstring[1] = EISA_VENDID_1(vid);
268 idstring[2] = EISA_VENDID_2(vid);
269 idstring[3] = EISA_PRODID_0(pid);
270 idstring[4] = EISA_PRODID_1(pid);
271 idstring[5] = EISA_PRODID_2(pid);
272 idstring[6] = EISA_PRODID_3(pid);
273 idstring[7] = '\0'; /* sanity */
274
275 return (1);
276 }
277
278 int
279 ahc_isa_match(ia, iobase)
280 struct isa_attach_args *ia;
281 bus_addr_t iobase;
282 {
283 bus_space_tag_t iot = ia->ia_iot;
284 bus_space_handle_t ioh;
285 int irq;
286 char idstring[EISA_IDSTRINGLEN];
287
288 /*
289 * Get a mapping for the while slot-specific address
290 * space. If we can't, assume nothing's there, but
291 * warn about it.
292 */
293 if (bus_space_map(iot, iobase, AHC_ISA_IOSIZE, 0, &ioh)) {
294 #if 0
295 /*
296 * Don't print anything out here, since this could
297 * be common on machines configured to look for
298 * ahc_eisa and ahc_isa.
299 */
300 printf("ahc_isa_match: can't map I/O space for 0x%x\n",
301 iobase);
302 #endif
303 return (0);
304 }
305
306 if (!ahc_isa_idstring(iot, ioh, idstring))
307 irq = -1; /* cannot get the ID string */
308 else if (strcmp(idstring, "ADP7756") &&
309 strcmp(idstring, "ADP7757"))
310 irq = -1; /* unknown ID strings */
311 else
312 irq = ahc_isa_irq(iot, ioh);
313
314 bus_space_unmap(iot, ioh, AHC_ISA_IOSIZE);
315
316 if (irq < 0)
317 return (0);
318
319 if (ia->ia_irq != IRQUNK &&
320 ia->ia_irq != irq) {
321 printf("ahc_isa_match: irq mismatch (kernel %d, card %d)\n",
322 ia->ia_irq, irq);
323 return (0);
324 }
325
326 /* We have a match */
327 ia->ia_iobase = iobase;
328 ia->ia_irq = irq;
329 ia->ia_iosize = AHC_ISA_IOSIZE;
330 ia->ia_msize = 0;
331 return (1);
332 }
333
334 /*
335 * Check the slots looking for a board we recognise
336 * If we find one, note it's address (slot) and call
337 * the actual probe routine to check it out.
338 */
339 int
340 ahc_isa_probe(parent, match, aux)
341 struct device *parent;
342 void *match, *aux;
343 {
344 struct isa_attach_args *ia = aux;
345 struct ahc_isa_slot *as;
346
347 if (ahc_isa_slot_initialized == 0) {
348 LIST_INIT(&ahc_isa_all_slots);
349 ahc_isa_slot_initialized = 1;
350 }
351
352 if (ia->ia_iobase != IOBASEUNK)
353 return (ahc_isa_match(ia, ia->ia_iobase));
354
355 /*
356 * Find this bus's state. If we don't yet have a slot
357 * marker, allocate and initialize one.
358 */
359 for (as = ahc_isa_all_slots.lh_first; as != NULL;
360 as = as->link.le_next)
361 if (as->bus == parent->dv_unit)
362 goto found_slot_marker;
363
364 /*
365 * Don't have one, so make one.
366 */
367 as = (struct ahc_isa_slot *)
368 malloc(sizeof(struct ahc_isa_slot), M_DEVBUF, M_NOWAIT);
369 if (as == NULL)
370 panic("ahc_isa_probe: can't allocate slot marker");
371
372 as->bus = parent->dv_unit;
373 as->slot = AHC_ISA_MIN_SLOT;
374 LIST_INSERT_HEAD(&ahc_isa_all_slots, as, link);
375
376 found_slot_marker:
377
378 for (; as->slot <= AHC_ISA_MAX_SLOT; as->slot++) {
379 if (ahc_isa_match(ia, EISA_SLOT_ADDR(as->slot) +
380 AHC_ISA_SLOT_OFFSET)) {
381 as->slot++; /* next slot to search */
382 return (1);
383 }
384 }
385
386 /* No matching cards were found. */
387 return (0);
388 }
389
390 void
391 ahc_isa_attach(parent, self, aux)
392 struct device *parent, *self;
393 void *aux;
394 {
395 ahc_type type;
396 struct ahc_data *ahc = (void *)self;
397 struct isa_attach_args *ia = aux;
398 bus_space_tag_t iot = ia->ia_iot;
399 bus_space_handle_t ioh;
400 int irq;
401 char idstring[EISA_IDSTRINGLEN];
402 const char *model;
403
404 if (bus_space_map(iot, ia->ia_iobase, ia->ia_iosize, 0, &ioh)) {
405 printf(": can't map i/o space\n");
406 return;
407 }
408 if (!ahc_isa_idstring(iot, ioh, idstring)) {
409 printf(": can't read ID string\n");
410 return;
411 }
412 if ((irq = ahc_isa_irq(iot, ioh)) < 0) {
413 printf(": ahc_isa_irq failed\n");
414 return;
415 }
416
417 if (strcmp(idstring, "ADP7756") == 0) {
418 model = EISA_PRODUCT_ADP7756;
419 type = AHC_284;
420 } else if (strcmp(idstring, "ADP7757") == 0) {
421 model = EISA_PRODUCT_ADP7757;
422 type = AHC_284;
423 } else {
424 printf(": unknown device type %s\n", idstring);
425 return;
426 }
427 printf(": %s\n", model);
428
429 ahc_construct(ahc, iot, ioh, type, AHC_FNONE);
430
431 #ifdef DEBUG
432 /*
433 * Tell the user what type of interrupts we're using.
434 * usefull for debugging irq problems
435 */
436 printf( "%s: Using %s Interrupts\n", ahc_name(ahc),
437 ahc->pause & IRQMS ? "Level Sensitive" : "Edge Triggered");
438 #endif
439
440 /*
441 * Now that we know we own the resources we need, do the
442 * card initialization.
443 *
444 * First, the aic7770 card specific setup.
445 */
446
447 /* XXX
448 * On AHA-284x,
449 * all values are automagically intialized at
450 * POST for these cards, so we can always rely
451 * on the Scratch Ram values. However, we should
452 * read the SEEPROM here (Dan has the code to do
453 * it) so we can say what kind of translation the
454 * BIOS is using. Printing out the geometry could
455 * save a lot of users the grief of failed installs.
456 */
457
458 /*
459 * See if we have a Rev E or higher aic7770. Anything below a
460 * Rev E will have a R/O autoflush disable configuration bit.
461 * It's still not clear exactly what is differenent about the Rev E.
462 * We think it allows 8 bit entries in the QOUTFIFO to support
463 * "paging" SCBs so you can have more than 4 commands active at
464 * once.
465 */
466 {
467 char *id_string;
468 u_char sblkctl;
469 u_char sblkctl_orig;
470
471 sblkctl_orig = AHC_INB(ahc, SBLKCTL);
472 sblkctl = sblkctl_orig ^ AUTOFLUSHDIS;
473 AHC_OUTB(ahc, SBLKCTL, sblkctl);
474 sblkctl = AHC_INB(ahc, SBLKCTL);
475 if(sblkctl != sblkctl_orig)
476 {
477 id_string = "aic7770 >= Rev E, ";
478 /*
479 * Ensure autoflush is enabled
480 */
481 sblkctl &= ~AUTOFLUSHDIS;
482 AHC_OUTB(ahc, SBLKCTL, sblkctl);
483
484 /* Allow paging on this adapter */
485 ahc->flags |= AHC_PAGESCBS;
486 }
487 else
488 id_string = "aic7770 <= Rev C, ";
489
490 printf("%s: %s", ahc_name(ahc), id_string);
491 }
492
493 /* Setup the FIFO threshold and the bus off time */
494 {
495 u_char hostconf = AHC_INB(ahc, HOSTCONF);
496 AHC_OUTB(ahc, BUSSPD, hostconf & DFTHRSH);
497 AHC_OUTB(ahc, BUSTIME, (hostconf << 2) & BOFF);
498 }
499
500 /*
501 * Generic aic7xxx initialization.
502 */
503 if(ahc_init(ahc)){
504 ahc_free(ahc);
505 return;
506 }
507
508 /*
509 * Enable the board's BUS drivers
510 */
511 AHC_OUTB(ahc, BCTL, ENABLE);
512
513 /*
514 * The IRQMS bit enables level sensitive interrupts only allow
515 * IRQ sharing if its set.
516 */
517 ahc->sc_ih = isa_intr_establish(ia->ia_ic, irq,
518 ahc->pause & IRQMS ? IST_LEVEL : IST_EDGE, IPL_BIO, ahc_intr, ahc);
519 if (ahc->sc_ih == NULL) {
520 printf("%s: couldn't establish interrupt\n",
521 ahc->sc_dev.dv_xname);
522 ahc_free(ahc);
523 return;
524 }
525
526 /* Attach sub-devices - always succeeds */
527 ahc_attach(ahc);
528 }
529