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