ahc_isa.c revision 1.12 1 /* $NetBSD: ahc_isa.c,v 1.12 1998/03/22 12:53:55 drochner 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 *, struct cfdata *, 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 struct cfdata *match;
343 void *aux;
344 {
345 struct isa_attach_args *ia = aux;
346 struct ahc_isa_slot *as;
347
348 if (ahc_isa_slot_initialized == 0) {
349 LIST_INIT(&ahc_isa_all_slots);
350 ahc_isa_slot_initialized = 1;
351 }
352
353 if (ia->ia_iobase != IOBASEUNK)
354 return (ahc_isa_match(ia, ia->ia_iobase));
355
356 /*
357 * Find this bus's state. If we don't yet have a slot
358 * marker, allocate and initialize one.
359 */
360 for (as = ahc_isa_all_slots.lh_first; as != NULL;
361 as = as->link.le_next)
362 if (as->bus == parent->dv_unit)
363 goto found_slot_marker;
364
365 /*
366 * Don't have one, so make one.
367 */
368 as = (struct ahc_isa_slot *)
369 malloc(sizeof(struct ahc_isa_slot), M_DEVBUF, M_NOWAIT);
370 if (as == NULL)
371 panic("ahc_isa_probe: can't allocate slot marker");
372
373 as->bus = parent->dv_unit;
374 as->slot = AHC_ISA_MIN_SLOT;
375 LIST_INSERT_HEAD(&ahc_isa_all_slots, as, link);
376
377 found_slot_marker:
378
379 for (; as->slot <= AHC_ISA_MAX_SLOT; as->slot++) {
380 if (ahc_isa_match(ia, EISA_SLOT_ADDR(as->slot) +
381 AHC_ISA_SLOT_OFFSET)) {
382 as->slot++; /* next slot to search */
383 return (1);
384 }
385 }
386
387 /* No matching cards were found. */
388 return (0);
389 }
390
391 void
392 ahc_isa_attach(parent, self, aux)
393 struct device *parent, *self;
394 void *aux;
395 {
396 ahc_type type;
397 struct ahc_data *ahc = (void *)self;
398 struct isa_attach_args *ia = aux;
399 bus_space_tag_t iot = ia->ia_iot;
400 bus_space_handle_t ioh;
401 int irq;
402 char idstring[EISA_IDSTRINGLEN];
403 const char *model;
404
405 if (bus_space_map(iot, ia->ia_iobase, ia->ia_iosize, 0, &ioh)) {
406 printf(": can't map i/o space\n");
407 return;
408 }
409 if (!ahc_isa_idstring(iot, ioh, idstring)) {
410 printf(": can't read ID string\n");
411 return;
412 }
413 if ((irq = ahc_isa_irq(iot, ioh)) < 0) {
414 printf(": ahc_isa_irq failed\n");
415 return;
416 }
417
418 if (strcmp(idstring, "ADP7756") == 0) {
419 model = EISA_PRODUCT_ADP7756;
420 type = AHC_284;
421 } else if (strcmp(idstring, "ADP7757") == 0) {
422 model = EISA_PRODUCT_ADP7757;
423 type = AHC_284;
424 } else {
425 printf(": unknown device type %s\n", idstring);
426 return;
427 }
428 printf(": %s\n", model);
429
430 ahc_construct(ahc, iot, ioh, ia->ia_dmat, type, AHC_FNONE);
431
432 /*
433 * Tell the bus-dma interface that we can do 32bit dma
434 */
435 ahc->sc_dmaflags = ISABUS_DMA_32BIT;
436
437 #ifdef DEBUG
438 /*
439 * Tell the user what type of interrupts we're using.
440 * usefull for debugging irq problems
441 */
442 printf( "%s: Using %s Interrupts\n", ahc_name(ahc),
443 ahc->pause & IRQMS ? "Level Sensitive" : "Edge Triggered");
444 #endif
445
446 /*
447 * Now that we know we own the resources we need, do the
448 * card initialization.
449 *
450 * First, the aic7770 card specific setup.
451 */
452
453 /* XXX
454 * On AHA-284x,
455 * all values are automagically intialized at
456 * POST for these cards, so we can always rely
457 * on the Scratch Ram values. However, we should
458 * read the SEEPROM here (Dan has the code to do
459 * it) so we can say what kind of translation the
460 * BIOS is using. Printing out the geometry could
461 * save a lot of users the grief of failed installs.
462 */
463
464 /*
465 * See if we have a Rev E or higher aic7770. Anything below a
466 * Rev E will have a R/O autoflush disable configuration bit.
467 * It's still not clear exactly what is differenent about the Rev E.
468 * We think it allows 8 bit entries in the QOUTFIFO to support
469 * "paging" SCBs so you can have more than 4 commands active at
470 * once.
471 */
472 {
473 char *id_string;
474 u_char sblkctl;
475 u_char sblkctl_orig;
476
477 sblkctl_orig = AHC_INB(ahc, SBLKCTL);
478 sblkctl = sblkctl_orig ^ AUTOFLUSHDIS;
479 AHC_OUTB(ahc, SBLKCTL, sblkctl);
480 sblkctl = AHC_INB(ahc, SBLKCTL);
481 if(sblkctl != sblkctl_orig)
482 {
483 id_string = "aic7770 >= Rev E, ";
484 /*
485 * Ensure autoflush is enabled
486 */
487 sblkctl &= ~AUTOFLUSHDIS;
488 AHC_OUTB(ahc, SBLKCTL, sblkctl);
489
490 /* Allow paging on this adapter */
491 ahc->flags |= AHC_PAGESCBS;
492 }
493 else
494 id_string = "aic7770 <= Rev C, ";
495
496 printf("%s: %s", ahc_name(ahc), id_string);
497 }
498
499 /* Setup the FIFO threshold and the bus off time */
500 {
501 u_char hostconf = AHC_INB(ahc, HOSTCONF);
502 AHC_OUTB(ahc, BUSSPD, hostconf & DFTHRSH);
503 AHC_OUTB(ahc, BUSTIME, (hostconf << 2) & BOFF);
504 }
505
506 /*
507 * Generic aic7xxx initialization.
508 */
509 if(ahc_init(ahc)){
510 ahc_free(ahc);
511 return;
512 }
513
514 /*
515 * Enable the board's BUS drivers
516 */
517 AHC_OUTB(ahc, BCTL, ENABLE);
518
519 /*
520 * The IRQMS bit enables level sensitive interrupts only allow
521 * IRQ sharing if its set.
522 */
523 ahc->sc_ih = isa_intr_establish(ia->ia_ic, irq,
524 ahc->pause & IRQMS ? IST_LEVEL : IST_EDGE, IPL_BIO, ahc_intr, ahc);
525 if (ahc->sc_ih == NULL) {
526 printf("%s: couldn't establish interrupt\n",
527 ahc->sc_dev.dv_xname);
528 ahc_free(ahc);
529 return;
530 }
531
532 /* Attach sub-devices - always succeeds */
533 ahc_attach(ahc);
534 }
535