This source file includes following definitions.
- SIMPLEQ_HEAD
- pciintr_icu_lookup
- pciintr_link_lookup
- pciintr_link_alloc
- pciintr_pir_lookup
- pciintr_bitmap_count_irq
- pciintr_link_init
- pciintr_guess_irq
- pciintr_link_fixup
- pci_intr_route_link
- pci_intr_post_fixup
- pci_intr_header_fixup
- pci_intr_fixup
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94 #include <sys/param.h>
95 #include <sys/systm.h>
96 #include <sys/kernel.h>
97 #include <sys/malloc.h>
98 #include <sys/queue.h>
99 #include <sys/device.h>
100
101 #include <machine/bus.h>
102 #include <machine/intr.h>
103 #include <machine/i8259.h>
104 #include <machine/i82093var.h>
105
106 #include <dev/pci/pcireg.h>
107 #include <dev/pci/pcivar.h>
108 #include <dev/pci/pcidevs.h>
109
110 #include <i386/pci/pcibiosvar.h>
111
112 struct pciintr_link_map {
113 int link, clink, irq, fixup_stage;
114 u_int16_t bitmap;
115 SIMPLEQ_ENTRY(pciintr_link_map) list;
116 };
117
118 pciintr_icu_tag_t pciintr_icu_tag = NULL;
119 pciintr_icu_handle_t pciintr_icu_handle;
120
121 #ifdef PCIBIOS_IRQS_HINT
122 int pcibios_irqs_hint = PCIBIOS_IRQS_HINT;
123 #endif
124
125 struct pciintr_link_map *pciintr_link_lookup(int);
126 struct pcibios_intr_routing *pciintr_pir_lookup(int, int);
127 int pciintr_bitmap_count_irq(int, int *);
128
129 SIMPLEQ_HEAD(, pciintr_link_map) pciintr_link_map_list;
130
131 const struct pciintr_icu_table {
132 pci_vendor_id_t piit_vendor;
133 pci_product_id_t piit_product;
134 int (*piit_init)(pci_chipset_tag_t,
135 bus_space_tag_t, pcitag_t, pciintr_icu_tag_t *,
136 pciintr_icu_handle_t *);
137 } pciintr_icu_table[] = {
138 { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_6300ESB_LPC,
139 piix_init },
140 { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_6321ESB_LPC,
141 piix_init },
142 { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82371MX,
143 piix_init },
144 { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82371AB_ISA,
145 piix_init },
146 { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82371FB_ISA,
147 piix_init },
148 { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82371SB_ISA,
149 piix_init },
150 { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82440MX_ISA,
151 piix_init },
152 { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82801AA_LPC,
153 piix_init },
154 { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82801AB_LPC,
155 piix_init },
156 { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82801BA_LPC,
157 piix_init },
158 { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82801BAM_LPC,
159 piix_init },
160 { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82801CA_LPC,
161 piix_init },
162 { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82801CAM_LPC,
163 piix_init },
164 { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82801DB_LPC,
165 piix_init },
166 { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82801DBM_LPC,
167 piix_init },
168 { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82801E_LPC,
169 piix_init },
170 { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82801EB_LPC,
171 piix_init },
172 { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82801FB_LPC,
173 piix_init },
174 { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82801FBM_LPC,
175 piix_init },
176 { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82801GB_LPC,
177 piix_init },
178 { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82801GBM_LPC,
179 piix_init },
180 { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82801GH_LPC,
181 piix_init },
182 { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82801GHM_LPC,
183 piix_init },
184
185 { PCI_VENDOR_OPTI, PCI_PRODUCT_OPTI_82C558,
186 opti82c558_init },
187 { PCI_VENDOR_OPTI, PCI_PRODUCT_OPTI_82C700,
188 opti82c700_init },
189
190 { PCI_VENDOR_RCC, PCI_PRODUCT_RCC_OSB4,
191 osb4_init },
192 { PCI_VENDOR_RCC, PCI_PRODUCT_RCC_CSB5,
193 osb4_init },
194
195 { PCI_VENDOR_VIATECH, PCI_PRODUCT_VIATECH_VT82C586_ISA,
196 via82c586_init, },
197 { PCI_VENDOR_VIATECH, PCI_PRODUCT_VIATECH_VT82C596A,
198 via82c586_init, },
199 { PCI_VENDOR_VIATECH, PCI_PRODUCT_VIATECH_VT82C686A_ISA,
200 via82c586_init },
201
202 { PCI_VENDOR_VIATECH, PCI_PRODUCT_VIATECH_VT8231_ISA,
203 via8231_init },
204 { PCI_VENDOR_VIATECH, PCI_PRODUCT_VIATECH_VT8233_ISA,
205 via8231_init },
206 { PCI_VENDOR_VIATECH, PCI_PRODUCT_VIATECH_VT8233A_ISA,
207 via8231_init },
208 { PCI_VENDOR_VIATECH, PCI_PRODUCT_VIATECH_VT8235_ISA,
209 via8231_init },
210 { PCI_VENDOR_VIATECH, PCI_PRODUCT_VIATECH_VT8237_ISA,
211 via8231_init },
212 { PCI_VENDOR_VIATECH, PCI_PRODUCT_VIATECH_VT8237A_ISA,
213 via8231_init },
214
215 { PCI_VENDOR_SIS, PCI_PRODUCT_SIS_85C503,
216 sis85c503_init },
217 { PCI_VENDOR_SIS, PCI_PRODUCT_SIS_962,
218 sis85c503_init },
219 { PCI_VENDOR_SIS, PCI_PRODUCT_SIS_963,
220 sis85c503_init },
221
222 { PCI_VENDOR_AMD, PCI_PRODUCT_AMD_PBC756_PMC,
223 amd756_init },
224 { PCI_VENDOR_AMD, PCI_PRODUCT_AMD_766_PMC,
225 amd756_init },
226 { PCI_VENDOR_AMD, PCI_PRODUCT_AMD_PBC768_PMC,
227 amd756_init },
228
229 { PCI_VENDOR_ALI, PCI_PRODUCT_ALI_M1533,
230 ali1543_init },
231
232 { PCI_VENDOR_ALI, PCI_PRODUCT_ALI_M1543,
233 ali1543_init },
234
235 { 0, 0,
236 NULL },
237 };
238
239 const struct pciintr_icu_table *pciintr_icu_lookup(pcireg_t);
240
241 const struct pciintr_icu_table *
242 pciintr_icu_lookup(id)
243 pcireg_t id;
244 {
245 const struct pciintr_icu_table *piit;
246
247 for (piit = pciintr_icu_table; piit->piit_init != NULL; piit++)
248 if (PCI_VENDOR(id) == piit->piit_vendor &&
249 PCI_PRODUCT(id) == piit->piit_product)
250 return (piit);
251
252 return (NULL);
253 }
254
255 struct pciintr_link_map *
256 pciintr_link_lookup(int link)
257 {
258 struct pciintr_link_map *l;
259
260 for (l = SIMPLEQ_FIRST(&pciintr_link_map_list); l != NULL;
261 l = SIMPLEQ_NEXT(l, list))
262 if (l->link == link)
263 return (l);
264
265 return (NULL);
266 }
267
268 static __inline struct pciintr_link_map *
269 pciintr_link_alloc(pci_chipset_tag_t pc, struct pcibios_intr_routing *pir, int pin)
270 {
271 int link = pir->linkmap[pin].link, clink, irq;
272 struct pciintr_link_map *l, *lstart;
273
274 if (pciintr_icu_tag != NULL) {
275
276
277
278 if (pciintr_icu_getclink(pciintr_icu_tag, pciintr_icu_handle,
279 link, &clink) != 0) {
280
281
282
283
284 PCIBIOS_PRINTV(("pciintr_link_alloc: bus %d device %d: "
285 "ignoring link 0x%02x\n", pir->bus,
286 PIR_DEVFUNC_DEVICE(pir->device), link));
287 return (NULL);
288 }
289
290
291
292
293
294
295 if (pciintr_icu_get_intr(pciintr_icu_tag, pciintr_icu_handle,
296 clink, &irq) != 0) {
297
298
299
300
301 PCIBIOS_PRINTV(("pciintr_link_alloc: "
302 "bus %d device %d link 0x%02x: "
303 "ignoring PIRQ 0x%02x\n", pir->bus,
304 PIR_DEVFUNC_DEVICE(pir->device), link, clink));
305 return (NULL);
306 }
307 }
308
309 if ((l = malloc(sizeof(*l), M_DEVBUF, M_NOWAIT)) == NULL)
310 return (NULL);
311
312 memset(l, 0, sizeof(*l));
313
314 l->link = link;
315 l->bitmap = pir->linkmap[pin].bitmap;
316 if (pciintr_icu_tag != NULL) {
317 l->clink = clink;
318 l->irq = irq;
319 } else {
320 l->clink = link;
321 l->irq = I386_PCI_INTERRUPT_LINE_NO_CONNECTION;
322 }
323
324 lstart = SIMPLEQ_FIRST(&pciintr_link_map_list);
325 if (lstart == NULL || lstart->link < l->link)
326 SIMPLEQ_INSERT_TAIL(&pciintr_link_map_list, l, list);
327 else
328 SIMPLEQ_INSERT_HEAD(&pciintr_link_map_list, l, list);
329
330 return (l);
331 }
332
333 struct pcibios_intr_routing *
334 pciintr_pir_lookup(int bus, int device)
335 {
336 struct pcibios_intr_routing *pir;
337 int entry;
338
339 if (pcibios_pir_table == NULL)
340 return (NULL);
341
342 for (entry = 0; entry < pcibios_pir_table_nentries; entry++) {
343 pir = &pcibios_pir_table[entry];
344 if (pir->bus == bus &&
345 PIR_DEVFUNC_DEVICE(pir->device) == device)
346 return (pir);
347 }
348
349 return (NULL);
350 }
351
352 int
353 pciintr_bitmap_count_irq(int irq_bitmap, int *irqp)
354 {
355 int i, bit, count = 0, irq = I386_PCI_INTERRUPT_LINE_NO_CONNECTION;
356
357 if (irq_bitmap != 0)
358 for (i = 0, bit = 1; i < 16; i++, bit <<= 1)
359 if (irq_bitmap & bit) {
360 irq = i;
361 count++;
362 }
363
364 *irqp = irq;
365 return (count);
366 }
367
368 static __inline int
369 pciintr_link_init(pci_chipset_tag_t pc)
370 {
371 int entry, pin, link;
372 struct pcibios_intr_routing *pir;
373 struct pciintr_link_map *l;
374
375 if (pcibios_pir_table == NULL) {
376
377 printf("pciintr_link_init: no PIR table\n");
378 return (1);
379 }
380
381 SIMPLEQ_INIT(&pciintr_link_map_list);
382
383 for (entry = 0; entry < pcibios_pir_table_nentries; entry++) {
384 pir = &pcibios_pir_table[entry];
385 for (pin = 0; pin < PCI_INTERRUPT_PIN_MAX; pin++) {
386 if ((link = pir->linkmap[pin].link) == 0)
387
388 continue;
389
390
391
392
393
394
395
396 if ((l = pciintr_link_lookup(link)) == NULL)
397 pciintr_link_alloc(pc, pir, pin);
398 else if (pir->linkmap[pin].bitmap != l->bitmap) {
399
400
401
402 PCIBIOS_PRINTV(("pciintr_link_init: "
403 "bus %d device %d link 0x%02x: "
404 "bad irq bitmap 0x%04x, "
405 "should be 0x%04x\n", pir->bus,
406 PIR_DEVFUNC_DEVICE(pir->device), link,
407 pir->linkmap[pin].bitmap, l->bitmap));
408
409 l->bitmap &= pir->linkmap[pin].bitmap;
410
411 }
412 }
413 }
414
415 return (0);
416 }
417
418
419
420
421
422 static __inline int
423 pciintr_guess_irq(void)
424 {
425 struct pciintr_link_map *l;
426 int irq, guessed = 0;
427
428
429
430
431 for (l = SIMPLEQ_FIRST(&pciintr_link_map_list); l != NULL;
432 l = SIMPLEQ_NEXT(l, list)) {
433 if (l->irq != I386_PCI_INTERRUPT_LINE_NO_CONNECTION)
434 continue;
435 if (pciintr_bitmap_count_irq(l->bitmap, &irq) == 1) {
436 l->irq = irq;
437 l->fixup_stage = 1;
438 if (pcibios_flags & PCIBIOS_INTRDEBUG)
439 printf("pciintr_guess_irq (stage 1): "
440 "guessing PIRQ 0x%02x to be IRQ %d\n",
441 l->clink, l->irq);
442 guessed = 1;
443 }
444 }
445
446 return (guessed ? 0 : -1);
447 }
448
449 static __inline int
450 pciintr_link_fixup(void)
451 {
452 struct pciintr_link_map *l;
453 u_int16_t pciirq = 0;
454 int irq;
455
456
457
458
459
460 for (l = SIMPLEQ_FIRST(&pciintr_link_map_list); l != NULL;
461 l = SIMPLEQ_NEXT(l, list)) {
462 if (l->irq != I386_PCI_INTERRUPT_LINE_NO_CONNECTION) {
463
464
465
466
467
468 pciirq |= 1 << l->irq;
469 if (pcibios_flags & PCIBIOS_INTRDEBUG)
470 printf("pciintr_link_fixup: PIRQ 0x%02x is "
471 "already connected to IRQ %d\n",
472 l->clink, l->irq);
473 continue;
474 }
475
476
477
478 if (pcibios_flags & PCIBIOS_INTRDEBUG)
479 printf("pciintr_link_fixup: PIRQ 0x%02x not connected",
480 l->clink);
481
482
483
484
485
486 if (pciintr_bitmap_count_irq(l->bitmap, &irq) == 1) {
487 l->irq = irq;
488 l->fixup_stage = 1;
489 pciirq |= 1 << irq;
490 if (pcibios_flags & PCIBIOS_INTRDEBUG)
491 printf(", assigning IRQ %d", l->irq);
492 }
493 if (pcibios_flags & PCIBIOS_INTRDEBUG)
494 printf("\n");
495 }
496
497
498
499
500
501 for (l = SIMPLEQ_FIRST(&pciintr_link_map_list); l != NULL;
502 l = SIMPLEQ_NEXT(l, list))
503 if (l->irq == I386_PCI_INTERRUPT_LINE_NO_CONNECTION &&
504 (irq = ffs(l->bitmap & pciirq)) > 0) {
505
506
507
508
509
510 l->fixup_stage = 2;
511 l->irq = irq - 1;
512 if (pcibios_flags & PCIBIOS_INTRDEBUG)
513 printf("pciintr_link_fixup (stage 2): "
514 "assigning IRQ %d to PIRQ 0x%02x\n",
515 l->irq, l->clink);
516 }
517
518 #ifdef PCIBIOS_IRQS_HINT
519
520
521
522
523 for (l = SIMPLEQ_FIRST(&pciintr_link_map_list); l != NULL;
524 l = SIMPLEQ_NEXT(l, list)) {
525 if (l->irq == I386_PCI_INTERRUPT_LINE_NO_CONNECTION &&
526 (irq = ffs(l->bitmap & pcibios_irqs_hint)) > 0) {
527 l->fixup_stage = 3;
528 l->irq = irq - 1;
529 if (pcibios_flags & PCIBIOS_INTRDEBUG)
530 printf("pciintr_link_fixup (stage 3): "
531 "assigning IRQ %d to PIRQ 0x%02x\n",
532 l->irq, l->clink);
533 }
534 }
535 #endif
536
537 if (pcibios_flags & PCIBIOS_INTRDEBUG)
538 printf("pciintr_link_fixup: piirq 0x%04x\n", pciirq);
539
540 return (0);
541 }
542
543 int
544 pci_intr_route_link(pci_chipset_tag_t pc, pci_intr_handle_t *ihp)
545 {
546 struct pciintr_link_map *l;
547 pcireg_t intr;
548 int irq, rv = 1;
549 char *p = NULL;
550
551 if (pcibios_flags & PCIBIOS_INTR_FIXUP)
552 return 1;
553
554 irq = ihp->line & APIC_INT_LINE_MASK;
555 if (irq != 0 && irq != I386_PCI_INTERRUPT_LINE_NO_CONNECTION)
556 pcibios_pir_header.exclusive_irq |= 1 << irq;
557
558 l = ihp->link;
559 if (!l || pciintr_icu_tag == NULL)
560 return (1);
561
562 if (l->fixup_stage == 0) {
563 if (l->irq == I386_PCI_INTERRUPT_LINE_NO_CONNECTION) {
564
565 if (pcibios_flags & PCIBIOS_INTRDEBUG)
566 printf("pci_intr_route_link: PIRQ 0x%02x: "
567 "no IRQ, try "
568 "\"option PCIBIOS_IRQS_HINT=0x%04x\"\n",
569 l->clink,
570
571 (l->bitmap & 0x0e00) ? (l->bitmap & 0x0e00)
572 : l->bitmap);
573 } else
574 p = " preserved BIOS setting";
575 } else {
576
577 if (pciintr_icu_set_intr(pciintr_icu_tag, pciintr_icu_handle,
578 l->clink, l->irq) != 0 ||
579 pciintr_icu_set_trigger(pciintr_icu_tag, pciintr_icu_handle,
580 l->irq, IST_LEVEL) != 0) {
581 p = " failed";
582 rv = 0;
583 } else
584 p = "";
585 }
586 if (p && pcibios_flags & PCIBIOS_INTRDEBUG)
587 printf("pci_intr_route_link: route PIRQ 0x%02x -> IRQ %d%s\n",
588 l->clink, l->irq, p);
589
590 if (!rv)
591 return (0);
592
593
594
595
596
597 if (irq == 14 || irq == 15)
598 return (1);
599
600 intr = pci_conf_read(pc, ihp->tag, PCI_INTERRUPT_REG);
601 if (irq != PCI_INTERRUPT_LINE(intr)) {
602 intr &= ~(PCI_INTERRUPT_LINE_MASK << PCI_INTERRUPT_LINE_SHIFT);
603 intr |= irq << PCI_INTERRUPT_LINE_SHIFT;
604 pci_conf_write(pc, ihp->tag, PCI_INTERRUPT_REG, intr);
605 }
606
607 return (1);
608 }
609
610 int
611 pci_intr_post_fixup(void)
612 {
613 struct pciintr_link_map *l;
614 int i, pciirq;
615
616 if (pcibios_flags & PCIBIOS_INTR_FIXUP)
617 return 1;
618
619 if (!pciintr_icu_handle)
620 return 0;
621
622 pciirq = pcibios_pir_header.exclusive_irq;
623 if (pcibios_flags & PCIBIOS_INTRDEBUG)
624 printf("pci_intr_post_fixup: PCI IRQs:");
625 for (l = SIMPLEQ_FIRST(&pciintr_link_map_list);
626 l != NULL; l = SIMPLEQ_NEXT(l, list))
627 if (l->fixup_stage == 0 && l->irq != 0 &&
628 l->irq != I386_PCI_INTERRUPT_LINE_NO_CONNECTION) {
629 if (pcibios_flags & PCIBIOS_INTRDEBUG)
630 printf(" %d", l->irq);
631 pciirq |= (1 << l->irq);
632 }
633
634 if (pcibios_flags & PCIBIOS_INTRDEBUG)
635 printf("; ISA IRQs:");
636 for (i = 0; i < 16; i++)
637 if (!(pciirq & (1 << i))) {
638 if (pcibios_flags & PCIBIOS_INTRDEBUG)
639 printf(" %d", i);
640 pciintr_icu_set_trigger(pciintr_icu_tag,
641 pciintr_icu_handle, i, IST_EDGE);
642 }
643
644 if (pcibios_flags & PCIBIOS_INTRDEBUG)
645 printf("\n");
646
647 return (0);
648 }
649
650 int
651 pci_intr_header_fixup(pci_chipset_tag_t pc, pcitag_t tag,
652 pci_intr_handle_t *ihp)
653 {
654 struct pcibios_intr_routing *pir;
655 struct pciintr_link_map *l;
656 int irq, link, bus, device, function;
657 char *p = NULL;
658
659 if (pcibios_flags & PCIBIOS_INTR_FIXUP)
660 return 1;
661
662 irq = ihp->line & APIC_INT_LINE_MASK;
663 ihp->link = NULL;
664 ihp->tag = tag;
665 pci_decompose_tag(pc, tag, &bus, &device, &function);
666
667 if ((pir = pciintr_pir_lookup(bus, device)) == NULL ||
668 (link = pir->linkmap[ihp->pin - 1].link) == 0) {
669 PCIBIOS_PRINTV(("Interrupt not connected; no need to change."));
670 return 1;
671 }
672
673 if ((l = pciintr_link_lookup(link)) == NULL) {
674
675
676
677
678
679 if (pcibios_flags & PCIBIOS_INTRDEBUG)
680 printf("pci_intr_header_fixup: no entry for link "
681 "0x%02x (%d:%d:%d:%c)\n",
682 link, bus, device, function, '@' + ihp->pin);
683 return 1;
684 }
685
686 ihp->link = l;
687 if (irq == 14 || irq == 15) {
688 p = " WARNING: ignored";
689 ihp->link = NULL;
690 } else if (l->irq == I386_PCI_INTERRUPT_LINE_NO_CONNECTION) {
691
692
693 if (pciintr_icu_tag == NULL && irq != 0 &&
694 irq != I386_PCI_INTERRUPT_LINE_NO_CONNECTION)
695
696
697
698
699
700 p = "";
701 else
702 p = " WARNING: missing";
703 } else if (irq == 0 || irq == I386_PCI_INTERRUPT_LINE_NO_CONNECTION) {
704
705 p = " fixed up";
706 ihp->line = irq = l->irq;
707
708 } else if (pcibios_flags & PCIBIOS_FIXUP_FORCE) {
709
710
711 p = " WARNING: overriding";
712 ihp->line = irq = l->irq;
713 } else {
714
715 p = " WARNING: preserving";
716 ihp->line = (l->irq = irq) | (l->clink & PCI_INT_VIA_ISA);
717 }
718
719 if (pcibios_flags & PCIBIOS_INTRDEBUG) {
720 pcireg_t id = pci_conf_read(pc, tag, PCI_ID_REG);
721
722 printf("\n%d:%d:%d %04x:%04x pin %c clink 0x%02x irq %d "
723 "stage %d %s irq %d\n", bus, device, function,
724 PCI_VENDOR(id), PCI_PRODUCT(id), '@' + ihp->pin, l->clink,
725 ((l->irq == I386_PCI_INTERRUPT_LINE_NO_CONNECTION)?
726 -1 : l->irq), l->fixup_stage, p, irq);
727 }
728
729 return (1);
730 }
731
732 int
733 pci_intr_fixup(struct pcibios_softc *sc, pci_chipset_tag_t pc,
734 bus_space_tag_t iot)
735 {
736 struct pcibios_pir_header *pirh = &pcibios_pir_header;
737 const struct pciintr_icu_table *piit = NULL;
738 pcitag_t icutag;
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756 if (pirh->signature != 0 && (pirh->router_bus != 0 ||
757 pirh->router_devfunc != 0 || pirh->compat_router != 0)) {
758
759 icutag = pci_make_tag(pc, pirh->router_bus,
760 PIR_DEVFUNC_DEVICE(pirh->router_devfunc),
761 PIR_DEVFUNC_FUNCTION(pirh->router_devfunc));
762 if (pirh->compat_router == 0 ||
763 (piit = pciintr_icu_lookup(pirh->compat_router)) == NULL) {
764
765
766
767
768 pirh->compat_router = pci_conf_read(pc, icutag,
769 PCI_ID_REG);
770 }
771 if (piit == NULL)
772 piit = pciintr_icu_lookup(pirh->compat_router);
773 } else {
774 int device, maxdevs = pci_bus_maxdevs(pc, 0);
775
776
777
778
779
780 for (device = 0; device < maxdevs; device++) {
781 const struct pci_quirkdata *qd;
782 int function, nfuncs;
783 pcireg_t icuid;
784 pcireg_t bhlcr;
785
786 icutag = pci_make_tag(pc, 0, device, 0);
787 icuid = pci_conf_read(pc, icutag, PCI_ID_REG);
788
789
790 if (PCI_VENDOR(icuid) == PCI_VENDOR_INVALID)
791 continue;
792
793 if (PCI_VENDOR(icuid) == 0)
794 continue;
795
796 qd = pci_lookup_quirkdata(PCI_VENDOR(icuid),
797 PCI_PRODUCT(icuid));
798
799 bhlcr = pci_conf_read(pc, icutag, PCI_BHLC_REG);
800 if (PCI_HDRTYPE_MULTIFN(bhlcr) || (qd != NULL &&
801 (qd->quirks & PCI_QUIRK_MULTIFUNCTION) != 0))
802 nfuncs = 8;
803 else
804 nfuncs = 1;
805
806 for (function = 0; function < nfuncs; function++) {
807 icutag = pci_make_tag(pc, 0, device, function);
808 icuid = pci_conf_read(pc, icutag, PCI_ID_REG);
809
810
811 if (PCI_VENDOR(icuid) == PCI_VENDOR_INVALID)
812 continue;
813
814 if (PCI_VENDOR(icuid) == 0)
815 continue;
816
817 if ((piit = pciintr_icu_lookup(icuid))) {
818 pirh->compat_router = icuid;
819 pirh->router_bus = 0;
820 pirh->router_devfunc =
821 PIR_DEVFUNC_COMPOSE(device, 0);
822 break;
823 }
824 }
825
826 if (piit != NULL)
827 break;
828 }
829 }
830
831 if (piit == NULL) {
832 printf("%s: no compatible PCI ICU found", sc->sc_dev.dv_xname);
833 if (pirh->signature != 0 && pirh->compat_router != 0)
834 printf(": ICU vendor 0x%04x product 0x%04x",
835 PCI_VENDOR(pirh->compat_router),
836 PCI_PRODUCT(pirh->compat_router));
837 printf("\n");
838 if (!(pcibios_flags & PCIBIOS_INTR_GUESS)) {
839 if (pciintr_link_init(pc))
840 return (-1);
841 if (pciintr_guess_irq())
842 return (-1);
843 }
844 return (0);
845 } else {
846 char devinfo[256];
847
848 printf("%s: PCI Interrupt Router at %03d:%02d:%01d",
849 sc->sc_dev.dv_xname, pirh->router_bus,
850 PIR_DEVFUNC_DEVICE(pirh->router_devfunc),
851 PIR_DEVFUNC_FUNCTION(pirh->router_devfunc));
852 if (pirh->compat_router != 0) {
853 pci_devinfo(pirh->compat_router, 0, 0, devinfo,
854 sizeof devinfo);
855 printf(" (%s)", devinfo);
856 }
857 printf("\n");
858 }
859
860
861
862
863 if ((*piit->piit_init)(pc, iot, icutag, &pciintr_icu_tag,
864 &pciintr_icu_handle) != 0)
865 return (-1);
866
867
868
869
870 if (pciintr_link_init(pc))
871 return (-1);
872
873
874
875
876 if (pciintr_link_fixup() != 0)
877 return (-1);
878
879 return (0);
880 }