Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/netbsd-1-5]: src/sys/arch/i386/pci Pull up to netbsd-1-5 branch
details: https://anonhg.NetBSD.org/src/rev/ac9858155098
branches: netbsd-1-5
changeset: 489038:ac9858155098
user: soda <soda%NetBSD.org@localhost>
date: Thu Aug 10 22:53:44 2000 +0000
description:
Pull up to netbsd-1-5 branch
Approved by: thorpej
- Use PCIBIOS_PRINTV().
- Use PCI_INTERRUPT_PIN_MAX and I386_PCI_INTERRUPT_LINE_NO_CONNECTION
instead of magic number.
- Do not touch a PIRQ router, if the PIRQ is already routed
by the BIOS, or no appropriate IRQ is found for the PIRQ.
The latter prevents a panic on the machine of Frank van der Linden.
Do not modify a PCI Interrupt Configuration register,
if it is already set by the BIOS, even if it is inconsistent
with the PCI IRQ routing table provided by the BIOS.
(The PCI Interrupt Configuration register seems to be more reliable
than the PCI IRQ routing table.)
This is needed to prevent a incorrect header_fixup() caused
by the incorrect PIR table on a Panasonic Let's Note AL-N2T516J5.
Provide "options PCIBIOS_INTR_FIXUP_FORCE" to retain
previous behavior, i.e. believe the PCI IRQ routing table
and ignore the PCI Interrupt Configuration register.
Although I'm not sure this is really needed.
Do not modify a PCI Interrupt Configuration register,
if appropriate IRQ is not found for the link.
Move a pciintr_icu_getclink() call and a pciintr_icu_get_intr()
call from pciintr_link_fixup() to pciintr_link_alloc(),
and only allocate pciintr_link_map if those calls succeeded.
This reduces number of calls of pciintr_icu_getclink(),
and also avoid necessity to validate a clink value in
ICU's {get,set}_{intr,trigger}() functions.
The sanity checks are not removed yet, though.
Fix uninitialized usage of variable `bitmap' on stage 3
of pciintr_link_fixup().
Remove a member variable `old_irq' from struct pciintr_link_map.
Always use 0x%02x for printf format of canonical link value.
Use DIAGNOSTIC instead of PCIINTR_DEBUG for really weird situation.
Modified with UCHIYAMA Yasushi <uch%netbsd.org@localhost>.
- make PCIBIOS_IRQS_HINT patchable.
- better message from John Hawkinson <jhawk%MIT.EDU@localhost>
- Add another option PCIBIOS_INTR_GUESS for no compatible ICU found case.
Under this option, if only one IRQ is available for the link,
we assumes that the IRQ is already connected, and configure
PCI Interrupt Configuration Register accordingly.
This is what Linux pcmcia-cs-3.1.19 does by default.
This fixes unconfigured pccbb interrupt problem of
Sharp Mebius MN-5500. It's interrupt router is ITExpress Inc. IT8330G.
(http://www.ite.com.tw/, vendor=0x1283, product=0x8330)
Problem reporeted by Kitagawa <sk%kiu.ac.jp@localhost> in
http://www.kaynet.or.jp/~kay/ml/netbsd-pcmcia/msg/msg00608.html
Revision pulled up:
> cvs rdiff -r1.6 -r1.10 syssrc/sys/arch/i386/pci/pci_intr_fixup.c
diffstat:
sys/arch/i386/pci/pci_intr_fixup.c | 467 ++++++++++++++++++++++++------------
1 files changed, 306 insertions(+), 161 deletions(-)
diffs (truncated from 667 to 300 lines):
diff -r bebb70be066b -r ac9858155098 sys/arch/i386/pci/pci_intr_fixup.c
--- a/sys/arch/i386/pci/pci_intr_fixup.c Thu Aug 10 22:48:15 2000 +0000
+++ b/sys/arch/i386/pci/pci_intr_fixup.c Thu Aug 10 22:53:44 2000 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: pci_intr_fixup.c,v 1.5.6.1 2000/07/27 02:13:44 mycroft Exp $ */
+/* $NetBSD: pci_intr_fixup.c,v 1.5.6.2 2000/08/10 22:53:44 soda Exp $ */
/*-
* Copyright (c) 1999 The NetBSD Foundation, Inc.
@@ -92,20 +92,26 @@
int irq;
u_int16_t bitmap;
int fixup_stage;
- int old_irq;
SIMPLEQ_ENTRY(pciintr_link_map) list;
};
-pciintr_icu_tag_t pciintr_icu_tag;
+pciintr_icu_tag_t pciintr_icu_tag = NULL;
pciintr_icu_handle_t pciintr_icu_handle;
-struct pciintr_link_map *pciintr_link_lookup_pin
- __P((struct pcibios_intr_routing *, int));
-struct pciintr_link_map *pciintr_link_lookup_link __P((int));
+#ifdef PCIBIOS_IRQS_HINT
+int pcibios_irqs_hint = PCIBIOS_IRQS_HINT;
+#endif
+
+struct pciintr_link_map *pciintr_link_lookup __P((int));
struct pciintr_link_map *pciintr_link_alloc __P((struct pcibios_intr_routing *,
int));
struct pcibios_intr_routing *pciintr_pir_lookup __P((int, int));
+static int pciintr_bitmap_count_irq __P((int, int *));
+static int pciintr_bitmap_find_lowest_irq __P((int, int *));
int pciintr_link_init __P((void));
+#ifdef PCIBIOS_INTR_GUESS
+int pciintr_guess_irq __P((void));
+#endif
int pciintr_link_fixup __P((void));
int pciintr_link_route __P((u_int16_t *));
int pciintr_irq_release __P((u_int16_t *));
@@ -165,16 +171,7 @@
}
struct pciintr_link_map *
-pciintr_link_lookup_pin(pir, pin)
- struct pcibios_intr_routing *pir;
- int pin;
-{
-
- return (pciintr_link_lookup_link(pir->linkmap[pin].link));
-}
-
-struct pciintr_link_map *
-pciintr_link_lookup_link(link)
+pciintr_link_lookup(link)
int link;
{
struct pciintr_link_map *l;
@@ -193,16 +190,64 @@
struct pcibios_intr_routing *pir;
int pin;
{
+ int link = pir->linkmap[pin].link, clink, irq;
struct pciintr_link_map *l, *lstart;
+ if (pciintr_icu_tag != NULL) { /* compatible PCI ICU found */
+ /*
+ * Get the canonical link value for this entry.
+ */
+ if (pciintr_icu_getclink(pciintr_icu_tag, pciintr_icu_handle,
+ link, &clink) != 0) {
+ /*
+ * ICU doesn't understand the link value.
+ * Just ignore this PIR entry.
+ */
+#ifdef DIAGNOSTIC
+ printf("pciintr_link_alloc: bus %d device %d: "
+ "link 0x%02x invalid\n",
+ pir->bus, PIR_DEVFUNC_DEVICE(pir->device), link);
+#endif
+ return (NULL);
+ }
+
+ /*
+ * Check the link value by asking the ICU for the
+ * canonical link value.
+ * Also, determine if this PIRQ is mapped to an IRQ.
+ */
+ if (pciintr_icu_get_intr(pciintr_icu_tag, pciintr_icu_handle,
+ clink, &irq) != 0) {
+ /*
+ * ICU doesn't understand the canonical link value.
+ * Just ignore this PIR entry.
+ */
+#ifdef DIAGNOSTIC
+ printf("pciintr_link_alloc: "
+ "bus %d device %d link 0x%02x: "
+ "PIRQ 0x%02x invalid\n",
+ pir->bus, PIR_DEVFUNC_DEVICE(pir->device), link,
+ clink);
+#endif
+ return (NULL);
+ }
+ }
+
l = malloc(sizeof(*l), M_DEVBUF, M_NOWAIT);
if (l == NULL)
panic("pciintr_link_alloc");
memset(l, 0, sizeof(*l));
- l->link = pir->linkmap[pin].link;
+ l->link = link;
l->bitmap = pir->linkmap[pin].bitmap;
+ if (pciintr_icu_tag != NULL) { /* compatible PCI ICU found */
+ l->clink = clink;
+ l->irq = irq; /* maybe I386_PCI_INTERRUPT_LINE_NO_CONNECTION */
+ } else {
+ l->clink = link; /* only for PCIBIOSVERBOSE diagnostic */
+ l->irq = I386_PCI_INTERRUPT_LINE_NO_CONNECTION;
+ }
lstart = SIMPLEQ_FIRST(&pciintr_link_map_list);
if (lstart == NULL || lstart->link < l->link)
@@ -225,17 +270,53 @@
for (entry = 0; entry < pcibios_pir_table_nentries; entry++) {
pir = &pcibios_pir_table[entry];
- if (pir->bus == bus && ((pir->device >> 3) & 0x1f) == device)
+ if (pir->bus == bus &&
+ PIR_DEVFUNC_DEVICE(pir->device) == device)
return (pir);
}
return (NULL);
}
+static int
+pciintr_bitmap_count_irq(irq_bitmap, irqp)
+ int irq_bitmap, *irqp;
+{
+ int i, bit, count = 0, irq = I386_PCI_INTERRUPT_LINE_NO_CONNECTION;
+
+ if (irq_bitmap != 0) {
+ for (i = 0, bit = 1; i < 16; i++, bit <<= 1) {
+ if (irq_bitmap & bit) {
+ irq = i;
+ count++;
+ }
+ }
+ }
+ *irqp = irq;
+ return (count);
+}
+
+static int
+pciintr_bitmap_find_lowest_irq(irq_bitmap, irqp)
+ int irq_bitmap, *irqp;
+{
+ int i, bit;
+
+ if (irq_bitmap != 0) {
+ for (i = 0, bit = 1; i < 16; i++, bit <<= 1) {
+ if (irq_bitmap & bit) {
+ *irqp = i;
+ return (1); /* found */
+ }
+ }
+ }
+ return (0); /* not found */
+}
+
int
pciintr_link_init()
{
- int entry, pin, error, link, clink;
+ int entry, pin, link;
struct pcibios_intr_routing *pir;
struct pciintr_link_map *l;
@@ -245,138 +326,129 @@
return (1);
}
- error = 0;
SIMPLEQ_INIT(&pciintr_link_map_list);
for (entry = 0; entry < pcibios_pir_table_nentries; entry++) {
pir = &pcibios_pir_table[entry];
- for (pin = 0; pin < 4; pin++) {
+ for (pin = 0; pin < PCI_INTERRUPT_PIN_MAX; pin++) {
link = pir->linkmap[pin].link;
if (link == 0) {
/* No connection for this pin. */
continue;
}
-
- /*
- * Check the link value by asking the ICU for
- * the canonical link value.
- */
- if (pciintr_icu_getclink(pciintr_icu_tag,
- pciintr_icu_handle, link, &clink) != 0) {
- /*
- * Table entry is bogus. Just ignore it.
- */
-#ifdef PCIINTR_DEBUG
- printf("pciintr_link_init: bad table entry: "
- "bus %d device %d link 0x%02x\n",
- pir->bus, (pir->device >> 3 & 0x1f), link);
-#endif
- continue;
- }
-
/*
* Multiple devices may be wired to the same
* interrupt; check to see if we've seen this
* one already. If not, allocate a new link
* map entry and stuff it in the map.
*/
- l = pciintr_link_lookup_pin(pir, pin);
- if (l == NULL)
+ l = pciintr_link_lookup(link);
+ if (l == NULL) {
(void) pciintr_link_alloc(pir, pin);
+ } else if (pir->linkmap[pin].bitmap != l->bitmap) {
+ /*
+ * violates PCI IRQ Routing Table Specification
+ */
+#ifdef DIAGNOSTIC
+ printf("pciintr_link_init: "
+ "bus %d device %d link 0x%02x: "
+ "bad irq bitmap 0x%04x, "
+ "should be 0x%04x\n",
+ pir->bus, PIR_DEVFUNC_DEVICE(pir->device),
+ link, pir->linkmap[pin].bitmap, l->bitmap);
+#endif
+ /* safer value. */
+ l->bitmap &= pir->linkmap[pin].bitmap;
+ /* XXX - or, should ignore this entry? */
+ }
}
}
- return (error);
+ return (0);
}
+#ifdef PCIBIOS_INTR_GUESS
+/*
+ * No compatible PCI ICU found.
+ * Hopes the BIOS already setup the ICU.
+ */
+int
+pciintr_guess_irq()
+{
+ struct pciintr_link_map *l;
+ int irq, guessed = 0;
+
+ /*
+ * Stage 1: If only one IRQ is available for the link, use it.
+ */
+ for (l = SIMPLEQ_FIRST(&pciintr_link_map_list); l != NULL;
+ l = SIMPLEQ_NEXT(l, list)) {
+ if (l->irq != I386_PCI_INTERRUPT_LINE_NO_CONNECTION)
+ continue;
+ if (pciintr_bitmap_count_irq(l->bitmap, &irq) == 1) {
+ l->irq = irq;
+ l->fixup_stage = 1;
+#ifdef PCIINTR_DEBUG
+ printf("pciintr_guess_irq (stage 1): "
+ "guessing PIRQ 0x%02x to be IRQ %d\n",
+ l->clink, l->irq);
+#endif
+ guessed = 1;
+ }
+ }
+
+ return (guessed ? 0 : -1);
+}
+#endif /* PCIBIOS_INTR_GUESS */
+
int
pciintr_link_fixup()
{
struct pciintr_link_map *l;
- u_int16_t pciirq, bitmap;
- int i, j, cnt, irq;
+ int irq;
+ u_int16_t pciirq = 0;
/*
* First stage: Attempt to connect PIRQs which aren't
* yet connected.
*/
- pciirq = 0;
-
for (l = SIMPLEQ_FIRST(&pciintr_link_map_list); l != NULL;
l = SIMPLEQ_NEXT(l, list)) {
Home |
Main Index |
Thread Index |
Old Index