isapnp.c revision 1.7 1 /* $NetBSD: isapnp.c,v 1.7 1997/08/03 08:12:21 mikel Exp $ */
2
3 /*
4 * Copyright (c) 1996 Christos Zoulas. All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. All advertising materials mentioning features or use of this software
15 * must display the following acknowledgement:
16 * This product includes software developed by Christos Zoulas.
17 * 4. The name of the author may not be used to endorse or promote products
18 * derived from this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
24 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 */
31
32 /*
33 * ISA PnP bus autoconfiguration.
34 */
35
36 #include <sys/param.h>
37 #include <sys/systm.h>
38 #include <sys/device.h>
39 #include <sys/malloc.h>
40
41 #include <machine/bus.h>
42
43 #include <dev/isa/isavar.h>
44
45 #include <dev/isapnp/isapnpreg.h>
46 #include <dev/isapnp/isapnpvar.h>
47
48 static void isapnp_init __P((struct isapnp_softc *));
49 static __inline u_char isapnp_shift_bit __P((struct isapnp_softc *));
50 static int isapnp_findcard __P((struct isapnp_softc *));
51 static void isapnp_free_region __P((bus_space_tag_t, struct isapnp_region *));
52 static int isapnp_alloc_region __P((bus_space_tag_t, struct isapnp_region *));
53 static int isapnp_alloc_pin __P((struct isapnp_pin *));
54 static int isapnp_testconfig __P((bus_space_tag_t, bus_space_tag_t,
55 struct isapnp_attach_args *, int));
56 static struct isapnp_attach_args *isapnp_bestconfig __P((struct isapnp_softc *,
57 struct isapnp_attach_args **));
58 static void isapnp_print_region __P((const char *, struct isapnp_region *,
59 size_t));
60 static void isapnp_configure __P((struct isapnp_softc *,
61 const struct isapnp_attach_args *));
62 static void isapnp_print_pin __P((const char *, struct isapnp_pin *, size_t));
63 static int isapnp_print __P((void *, const char *));
64 #ifdef _KERNEL
65 static int isapnp_submatch __P((struct device *, void *, void *));
66 #endif
67 static int isapnp_find __P((struct isapnp_softc *));
68 static int isapnp_match __P((struct device *, void *, void *));
69 static void isapnp_attach __P((struct device *, struct device *, void *));
70
71 struct cfattach isapnp_ca = {
72 sizeof(struct isapnp_softc), isapnp_match, isapnp_attach
73 };
74
75 struct cfdriver isapnp_cd = {
76 NULL, "isapnp", DV_DULL
77 };
78
79
80 /* isapnp_init():
81 * Write the PNP initiation key to wake up the cards...
82 */
83 static void
84 isapnp_init(sc)
85 struct isapnp_softc *sc;
86 {
87 int i;
88 u_char v = ISAPNP_LFSR_INIT;
89
90 /* First write 0's twice to enter the Wait for Key state */
91 ISAPNP_WRITE_ADDR(sc, 0);
92 ISAPNP_WRITE_ADDR(sc, 0);
93
94 /* Send the 32 byte sequence to awake the logic */
95 for (i = 0; i < 32; i++) {
96 ISAPNP_WRITE_ADDR(sc, v);
97 v = ISAPNP_LFSR_NEXT(v);
98 }
99 }
100
101
102 /* isapnp_shift_bit():
103 * Read a bit at a time from the config card.
104 */
105 static __inline u_char
106 isapnp_shift_bit(sc)
107 struct isapnp_softc *sc;
108 {
109 u_char c1, c2;
110
111 DELAY(250);
112 c1 = ISAPNP_READ_DATA(sc);
113 DELAY(250);
114 c2 = ISAPNP_READ_DATA(sc);
115
116 if (c1 == 0x55 && c2 == 0xAA)
117 return 0x80;
118 else
119 return 0;
120 }
121
122
123 /* isapnp_findcard():
124 * Attempt to read the vendor/serial/checksum for a card
125 * If a card is found [the checksum matches], assign the
126 * next card number to it and return 1
127 */
128 static int
129 isapnp_findcard(sc)
130 struct isapnp_softc *sc;
131 {
132 u_char v = ISAPNP_LFSR_INIT, csum, w;
133 int i, b;
134
135 if (sc->sc_ncards == ISAPNP_MAX_CARDS) {
136 printf("%s: Too many pnp cards\n", sc->sc_dev.dv_xname);
137 return 0;
138 }
139
140 /* Set the read port */
141 isapnp_write_reg(sc, ISAPNP_WAKE, 0);
142 isapnp_write_reg(sc, ISAPNP_SET_RD_PORT, sc->sc_read_port >> 2);
143 sc->sc_read_port |= 3;
144 DELAY(1000);
145
146 ISAPNP_WRITE_ADDR(sc, ISAPNP_SERIAL_ISOLATION);
147 DELAY(1000);
148
149 /* Read the 8 bytes of the Vendor ID and Serial Number */
150 for(i = 0; i < 8; i++) {
151 /* Read each bit separately */
152 for (w = 0, b = 0; b < 8; b++) {
153 u_char neg = isapnp_shift_bit(sc);
154
155 w >>= 1;
156 w |= neg;
157 v = ISAPNP_LFSR_NEXT(v) ^ neg;
158 }
159 sc->sc_id[sc->sc_ncards][i] = w;
160 }
161
162 /* Read the remaining checksum byte */
163 for (csum = 0, b = 0; b < 8; b++) {
164 u_char neg = isapnp_shift_bit(sc);
165
166 csum >>= 1;
167 csum |= neg;
168 }
169 sc->sc_id[sc->sc_ncards][8] = csum;
170
171 if (csum == v) {
172 sc->sc_ncards++;
173 isapnp_write_reg(sc, ISAPNP_CARD_SELECT_NUM, sc->sc_ncards);
174 return 1;
175 }
176 return 0;
177 }
178
179
180 /* isapnp_free_region():
181 * Free a region
182 */
183 static void
184 isapnp_free_region(t, r)
185 bus_space_tag_t t;
186 struct isapnp_region *r;
187 {
188 bus_space_unmap(t, r->h, r->length);
189 }
190
191
192 /* isapnp_alloc_region():
193 * Allocate a single region if possible
194 */
195 static int
196 isapnp_alloc_region(t, r)
197 bus_space_tag_t t;
198 struct isapnp_region *r;
199 {
200 int error = 0;
201
202 for (r->base = r->minbase; r->base <= r->maxbase; r->base += r->align) {
203 error = bus_space_map(t, r->base, r->length, 0, &r->h);
204 if (error == 0)
205 return 0;
206 }
207 return error;
208 }
209
210
211 /* isapnp_alloc_pin():
212 * Allocate an irq/drq
213 * XXX: No resource conflict checks!
214 */
215 static int
216 isapnp_alloc_pin(i)
217 struct isapnp_pin *i;
218 {
219 int b;
220
221 if (i->bits == 0)
222 i->num = 0;
223 else
224 for (b = 0; b < 16; b++)
225 if (i->bits & (1 << b)) {
226 i->num = b;
227 break;
228 }
229 return 0;
230 }
231
232
233 /* isapnp_testconfig():
234 * Test/Allocate the regions used
235 */
236 static int
237 isapnp_testconfig(iot, memt, ipa, alloc)
238 bus_space_tag_t iot, memt;
239 struct isapnp_attach_args *ipa;
240 int alloc;
241 {
242 int nio = 0, nmem = 0, nmem32 = 0, nirq = 0, ndrq = 0;
243 int error = 0;
244
245 #ifdef DEBUG_ISAPNP
246 isapnp_print_attach(ipa);
247 #endif
248
249 for (; nio < ipa->ipa_nio; nio++) {
250 error = isapnp_alloc_region(iot, &ipa->ipa_io[nio]);
251 if (error)
252 goto bad;
253 }
254
255 for (; nmem < ipa->ipa_nmem; nmem++) {
256 error = isapnp_alloc_region(memt, &ipa->ipa_mem[nmem]);
257 if (error)
258 goto bad;
259 }
260
261 for (; nmem32 < ipa->ipa_nmem32; nmem32++) {
262 error = isapnp_alloc_region(memt, &ipa->ipa_mem32[nmem32]);
263 if (error)
264 goto bad;
265 }
266
267 for (; nirq < ipa->ipa_nirq; nirq++) {
268 error = isapnp_alloc_pin(&ipa->ipa_irq[nirq]);
269 if (error)
270 goto bad;
271 }
272
273 for (; ndrq < ipa->ipa_ndrq; ndrq++) {
274 error = isapnp_alloc_pin(&ipa->ipa_drq[ndrq]);
275 if (error)
276 goto bad;
277 }
278
279 if (alloc)
280 return error;
281
282 bad:
283 #ifdef notyet
284 for (ndrq--; ndrq >= 0; ndrq--)
285 isapnp_free_pin(&ipa->ipa_drq[ndrq]);
286
287 for (nirq--; nirq >= 0; nirq--)
288 isapnp_free_pin(&ipa->ipa_irq[nirq]);
289 #endif
290
291 for (nmem32--; nmem32 >= 0; nmem32--)
292 isapnp_free_region(memt, &ipa->ipa_mem32[nmem32]);
293
294 for (nmem--; nmem >= 0; nmem--)
295 isapnp_free_region(memt, &ipa->ipa_mem[nmem]);
296
297 for (nio--; nio >= 0; nio--)
298 isapnp_free_region(iot, &ipa->ipa_io[nio]);
299
300 return error;
301 }
302
303
304 /* isapnp_config():
305 * Test/Allocate the regions used
306 */
307 int
308 isapnp_config(iot, memt, ipa)
309 bus_space_tag_t iot, memt;
310 struct isapnp_attach_args *ipa;
311 {
312 return isapnp_testconfig(iot, memt, ipa, 1);
313 }
314
315
316 /* isapnp_unconfig():
317 * Free the regions used
318 */
319 void
320 isapnp_unconfig(iot, memt, ipa)
321 bus_space_tag_t iot, memt;
322 struct isapnp_attach_args *ipa;
323 {
324 int i;
325
326 #ifdef notyet
327 for (i = 0; i < ipa->ipa_ndrq; i++)
328 isapnp_free_pin(&ipa->ipa_drq[i]);
329
330 for (i = 0; i < ipa->ipa_nirq; i++)
331 isapnp_free_pin(&ipa->ipa_irq[i]);
332 #endif
333
334 for (i = 0; i < ipa->ipa_nmem32; i++)
335 isapnp_free_region(memt, &ipa->ipa_mem32[i]);
336
337 for (i = 0; i < ipa->ipa_nmem; i++)
338 isapnp_free_region(memt, &ipa->ipa_mem[i]);
339
340 for (i = 0; i < ipa->ipa_nio; i++)
341 isapnp_free_region(iot, &ipa->ipa_io[i]);
342 }
343
344
345 /* isapnp_bestconfig():
346 * Return the best configuration for each logical device, remove and
347 * free all other configurations.
348 */
349 static struct isapnp_attach_args *
350 isapnp_bestconfig(sc, ipa)
351 struct isapnp_softc *sc;
352 struct isapnp_attach_args **ipa;
353 {
354 struct isapnp_attach_args *c, *best, *f = *ipa;
355 int error;
356
357 for (;;) {
358 if (f == NULL)
359 return NULL;
360
361 #define SAMEDEV(a, b) (strcmp((a)->ipa_devlogic, (b)->ipa_devlogic) == 0)
362
363 /* Find the best config */
364 for (best = c = f; c != NULL; c = c->ipa_sibling) {
365 if (!SAMEDEV(c, f))
366 continue;
367 if (c->ipa_pref < best->ipa_pref)
368 best = c;
369 }
370
371 /* Test the best config */
372 error = isapnp_testconfig(sc->sc_iot, sc->sc_memt, best, 0);
373
374 /* Remove this config from the list */
375 if (best == f)
376 f = f->ipa_sibling;
377 else {
378 for (c = f; c->ipa_sibling != best; c = c->ipa_sibling)
379 continue;
380 c->ipa_sibling = best->ipa_sibling;
381 }
382
383 if (error) {
384 best->ipa_pref = ISAPNP_DEP_CONFLICTING;
385
386 for (c = f; c != NULL; c = c->ipa_sibling)
387 if (c != best && SAMEDEV(c, best))
388 break;
389 /* Last config for this logical device is conflicting */
390 if (c == NULL) {
391 *ipa = f;
392 return best;
393 }
394
395 ISAPNP_FREE(best);
396 continue;
397 }
398 else {
399 /* Remove all other configs for this device */
400 struct isapnp_attach_args *l = NULL, *n = NULL, *d;
401
402 for (c = f; c; ) {
403 if (c == best)
404 continue;
405 d = c->ipa_sibling;
406 if (SAMEDEV(c, best))
407 ISAPNP_FREE(c);
408 else {
409 if (n)
410 n->ipa_sibling = c;
411
412 else
413 l = c;
414 n = c;
415 c->ipa_sibling = NULL;
416 }
417 c = d;
418 }
419 f = l;
420 }
421 *ipa = f;
422 return best;
423 }
424 }
425
426
427 /* isapnp_id_to_vendor():
428 * Convert a pnp ``compressed ascii'' vendor id to a string
429 */
430 char *
431 isapnp_id_to_vendor(v, id)
432 char *v;
433 const u_char *id;
434 {
435 static const char hex[] = "0123456789ABCDEF";
436 char *p = v;
437
438 *p++ = 'A' + (id[0] >> 2) - 1;
439 *p++ = 'A' + ((id[0] & 3) << 3) + (id[1] >> 5) - 1;
440 *p++ = 'A' + (id[1] & 0x1f) - 1;
441 *p++ = hex[id[2] >> 4];
442 *p++ = hex[id[2] & 0x0f];
443 *p++ = hex[id[3] >> 4];
444 *p++ = hex[id[3] & 0x0f];
445 *p = '\0';
446
447 return v;
448 }
449
450
451 /* isapnp_print_region():
452 * Print a region allocation
453 */
454 static void
455 isapnp_print_region(str, r, n)
456 const char *str;
457 struct isapnp_region *r;
458 size_t n;
459 {
460 size_t i;
461
462 if (n == 0)
463 return;
464
465 printf(" %s ", str);
466 for (i = 0; i < n; i++, r++) {
467 printf("0x%x", r->base);
468 if (r->length)
469 printf("/%d", r->length);
470 if (i != n - 1)
471 printf(",");
472 }
473 }
474
475
476 /* isapnp_print_pin():
477 * Print an irq/drq assignment
478 */
479 static void
480 isapnp_print_pin(str, p, n)
481 const char *str;
482 struct isapnp_pin *p;
483 size_t n;
484 {
485 size_t i;
486
487 if (n == 0)
488 return;
489
490 printf(" %s ", str);
491 for (i = 0; i < n; i++, p++) {
492 printf("%d", p->num);
493 if (i != n - 1)
494 printf(",");
495 }
496 }
497
498
499 /* isapnp_print():
500 * Print the configuration line for an ISA PnP card.
501 */
502 static int
503 isapnp_print(aux, str)
504 void *aux;
505 const char *str;
506 {
507 struct isapnp_attach_args *ipa = aux;
508
509 if (str != NULL)
510 printf("%s: <%s, %s, %s, %s>",
511 str, ipa->ipa_devident, ipa->ipa_devlogic,
512 ipa->ipa_devcompat, ipa->ipa_devclass);
513
514 isapnp_print_region("port", ipa->ipa_io, ipa->ipa_nio);
515 isapnp_print_region("mem", ipa->ipa_mem, ipa->ipa_nmem);
516 isapnp_print_region("mem32", ipa->ipa_mem32, ipa->ipa_nmem32);
517 isapnp_print_pin("irq", ipa->ipa_irq, ipa->ipa_nirq);
518 isapnp_print_pin("drq", ipa->ipa_drq, ipa->ipa_ndrq);
519
520 return UNCONF;
521 }
522
523
524 #ifdef _KERNEL
525 /* isapnp_submatch():
526 * Probe the card...
527 */
528 static int
529 isapnp_submatch(parent, match, aux)
530 struct device *parent;
531 void *match, *aux;
532 {
533 struct cfdata *cf = match;
534 return ((*cf->cf_attach->ca_match)(parent, match, aux));
535 }
536 #endif
537
538
539 /* isapnp_find():
540 * Probe and add cards
541 */
542 static int
543 isapnp_find(sc)
544 struct isapnp_softc *sc;
545 {
546 int p;
547
548 isapnp_init(sc);
549
550 isapnp_write_reg(sc, ISAPNP_CONFIG_CONTROL, ISAPNP_CC_RESET_DRV);
551 DELAY(2000);
552
553 isapnp_init(sc);
554 DELAY(2000);
555
556 for (p = ISAPNP_RDDATA_MIN; p <= ISAPNP_RDDATA_MAX; p += 4) {
557 sc->sc_read_port = p;
558 if (isapnp_map_readport(sc))
559 continue;
560 DPRINTF(("%s: Trying port %x\n", sc->sc_dev.dv_xname, p));
561 if (isapnp_findcard(sc))
562 break;
563 isapnp_unmap_readport(sc);
564 }
565
566 if (p > ISAPNP_RDDATA_MAX) {
567 sc->sc_read_port = 0;
568 return 0;
569 }
570
571 while (isapnp_findcard(sc))
572 continue;
573
574 return 1;
575 }
576
577
578 /* isapnp_configure():
579 * Configure a PnP card
580 * XXX: The memory configuration code is wrong. We need to check the
581 * range/length bit an do appropriate sets.
582 */
583 static void
584 isapnp_configure(sc, ipa)
585 struct isapnp_softc *sc;
586 const struct isapnp_attach_args *ipa;
587 {
588 int i;
589 static u_char isapnp_mem_range[] = ISAPNP_MEM_DESC;
590 static u_char isapnp_io_range[] = ISAPNP_IO_DESC;
591 static u_char isapnp_irq_range[] = ISAPNP_IRQ_DESC;
592 static u_char isapnp_drq_range[] = ISAPNP_DRQ_DESC;
593 static u_char isapnp_mem32_range[] = ISAPNP_MEM32_DESC;
594 const struct isapnp_region *r;
595 const struct isapnp_pin *p;
596 struct isapnp_region rz;
597 struct isapnp_pin pz;
598
599 memset(&pz, 0, sizeof(pz));
600 memset(&rz, 0, sizeof(rz));
601
602 #define B0(a) ((a) & 0xff)
603 #define B1(a) (((a) >> 8) & 0xff)
604 #define B2(a) (((a) >> 16) & 0xff)
605 #define B3(a) (((a) >> 24) & 0xff)
606
607 for (i = 0; i < sizeof(isapnp_io_range); i++) {
608 if (i < ipa->ipa_nio)
609 r = &ipa->ipa_io[i];
610 else
611 r = &rz;
612
613 isapnp_write_reg(sc,
614 isapnp_io_range[i] + ISAPNP_IO_BASE_15_8, B1(r->base));
615 isapnp_write_reg(sc,
616 isapnp_io_range[i] + ISAPNP_IO_BASE_7_0, B0(r->base));
617 }
618
619 for (i = 0; i < sizeof(isapnp_mem_range); i++) {
620 if (i < ipa->ipa_nmem)
621 r = &ipa->ipa_mem[i];
622 else
623 r = &rz;
624
625 isapnp_write_reg(sc,
626 isapnp_mem_range[i] + ISAPNP_MEM_BASE_23_16, B2(r->base));
627 isapnp_write_reg(sc,
628 isapnp_mem_range[i] + ISAPNP_MEM_BASE_15_8, B1(r->base));
629
630 isapnp_write_reg(sc,
631 isapnp_mem_range[i] + ISAPNP_MEM_LRANGE_23_16,
632 B2(r->length));
633 isapnp_write_reg(sc,
634 isapnp_mem_range[i] + ISAPNP_MEM_LRANGE_15_8,
635 B1(r->length));
636 }
637
638 for (i = 0; i < sizeof(isapnp_irq_range); i++) {
639 u_char v;
640
641 if (i < ipa->ipa_nirq)
642 p = &ipa->ipa_irq[i];
643 else
644 p = &pz;
645
646 isapnp_write_reg(sc,
647 isapnp_irq_range[i] + ISAPNP_IRQ_NUMBER, p->num);
648
649 switch (p->flags) {
650 case ISAPNP_IRQTYPE_LEVEL_PLUS:
651 v = ISAPNP_IRQ_LEVEL|ISAPNP_IRQ_HIGH;
652 break;
653
654 case ISAPNP_IRQTYPE_EDGE_PLUS:
655 v = ISAPNP_IRQ_HIGH;
656 break;
657
658 case ISAPNP_IRQTYPE_LEVEL_MINUS:
659 v = ISAPNP_IRQ_LEVEL;
660 break;
661
662 default:
663 case ISAPNP_IRQTYPE_EDGE_MINUS:
664 v = 0;
665 break;
666 }
667 isapnp_write_reg(sc,
668 isapnp_irq_range[i] + ISAPNP_IRQ_CONTROL, v);
669 }
670
671 for (i = 0; i < sizeof(isapnp_drq_range); i++) {
672 u_char v;
673
674 if (i < ipa->ipa_ndrq)
675 v = ipa->ipa_drq[i].num;
676 else
677 v = 4;
678
679 isapnp_write_reg(sc, isapnp_drq_range[i], v);
680 }
681
682 for (i = 0; i < sizeof(isapnp_mem32_range); i++) {
683 if (i < ipa->ipa_nmem32)
684 r = &ipa->ipa_mem32[i];
685 else
686 r = &rz;
687
688 isapnp_write_reg(sc,
689 isapnp_mem32_range[i] + ISAPNP_MEM32_BASE_31_24,
690 B3(r->base));
691 isapnp_write_reg(sc,
692 isapnp_mem32_range[i] + ISAPNP_MEM32_BASE_23_16,
693 B2(r->base));
694 isapnp_write_reg(sc,
695 isapnp_mem32_range[i] + ISAPNP_MEM32_BASE_15_8,
696 B1(r->base));
697 isapnp_write_reg(sc,
698 isapnp_mem32_range[i] + ISAPNP_MEM32_BASE_7_0,
699 B0(r->base));
700
701 isapnp_write_reg(sc,
702 isapnp_mem32_range[i] + ISAPNP_MEM32_LRANGE_31_24,
703 B3(r->length));
704 isapnp_write_reg(sc,
705 isapnp_mem32_range[i] + ISAPNP_MEM32_LRANGE_23_16,
706 B2(r->length));
707 isapnp_write_reg(sc,
708 isapnp_mem32_range[i] + ISAPNP_MEM32_LRANGE_15_8,
709 B1(r->length));
710 isapnp_write_reg(sc,
711 isapnp_mem32_range[i] + ISAPNP_MEM32_LRANGE_7_0,
712 B0(r->length));
713 }
714 }
715
716
717 /* isapnp_match():
718 * Probe routine
719 */
720 static int
721 isapnp_match(parent, match, aux)
722 struct device *parent;
723 void *match, *aux;
724 {
725 int rv;
726 struct isapnp_softc sc;
727 struct isa_attach_args *ia = aux;
728
729 sc.sc_iot = ia->ia_iot;
730 ia->ia_iobase = ISAPNP_ADDR;
731 ia->ia_iosize = 1;
732 (void) strcpy(sc.sc_dev.dv_xname, "(isapnp probe)");
733
734 if (isapnp_map(&sc))
735 return 0;
736
737 rv = isapnp_find(&sc);
738
739 isapnp_unmap(&sc);
740
741 return (rv);
742 }
743
744
745 /* isapnp_attach
746 * Find and attach PnP cards.
747 */
748 static void
749 isapnp_attach(parent, self, aux)
750 struct device *parent, *self;
751 void *aux;
752 {
753 struct isapnp_softc *sc = (struct isapnp_softc *) self;
754 struct isa_attach_args *ia = aux;
755 int c, d;
756
757 sc->sc_iot = ia->ia_iot;
758 sc->sc_memt = ia->ia_memt;
759 sc->sc_ncards = 0;
760
761 if (isapnp_map(sc))
762 panic("%s: bus map failed\n", sc->sc_dev.dv_xname);
763
764 if (!isapnp_find(sc))
765 panic("%s: no devices found\n", sc->sc_dev.dv_xname);
766
767 printf(": read port 0x%x\n", sc->sc_read_port);
768
769 for (c = 0; c < sc->sc_ncards; c++) {
770 struct isapnp_attach_args *ipa, *lpa;
771
772 /* Good morning card c */
773 isapnp_write_reg(sc, ISAPNP_WAKE, c + 1);
774
775 if ((ipa = isapnp_get_resource(sc, c)) == NULL)
776 continue;
777
778
779 DPRINTF(("Selecting attachments\n"));
780 for (d = 0; (lpa = isapnp_bestconfig(sc, &ipa)) != NULL; d++) {
781 isapnp_write_reg(sc, ISAPNP_LOGICAL_DEV_NUM, d);
782 isapnp_configure(sc, lpa);
783 #ifdef DEBUG_ISAPNP
784 {
785 struct isapnp_attach_args pa;
786
787 isapnp_get_config(sc, &pa);
788 isapnp_print_config(&pa);
789 }
790 #endif
791
792 #ifdef DEBUG
793 /* XXX do we even really need this? --thorpej */
794 printf("%s: configuring <%s, %s, %s, %s>\n",
795 sc->sc_dev.dv_xname,
796 lpa->ipa_devident, lpa->ipa_devlogic,
797 lpa->ipa_devcompat, lpa->ipa_devclass);
798 #endif
799
800 if (lpa->ipa_pref == ISAPNP_DEP_CONFLICTING) {
801 printf("%s: <%s, %s, %s, %s> ignored; %s\n",
802 sc->sc_dev.dv_xname,
803 lpa->ipa_devident, lpa->ipa_devlogic,
804 lpa->ipa_devcompat, lpa->ipa_devclass,
805 "resource conflict");
806 ISAPNP_FREE(lpa);
807 continue;
808 }
809
810 lpa->ipa_ic = ia->ia_ic;
811 lpa->ipa_iot = ia->ia_iot;
812 lpa->ipa_memt = ia->ia_memt;
813 lpa->ipa_dmat = ia->ia_dmat;
814
815 isapnp_write_reg(sc, ISAPNP_ACTIVATE, 1);
816 #ifdef _KERNEL
817 if (config_found_sm(self, lpa, isapnp_print,
818 isapnp_submatch) == NULL)
819 isapnp_write_reg(sc, ISAPNP_ACTIVATE, 0);
820 #else
821 isapnp_print(lpa, NULL);
822 printf("\n");
823 #endif
824 ISAPNP_FREE(lpa);
825 }
826 isapnp_write_reg(sc, ISAPNP_WAKE, 0); /* Good night cards */
827 }
828 }
829