Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/sommerfeld_i386mp_1]: src/sys/arch/i386/pci SIMPLEQ rototill:



details:   https://anonhg.NetBSD.org/src/rev/b0bf105898b9
branches:  sommerfeld_i386mp_1
changeset: 482539:b0bf105898b9
user:      lukem <lukem%NetBSD.org@localhost>
date:      Sat Jun 01 23:50:56 2002 +0000

description:
SIMPLEQ rototill:
- implement SIMPLEQ_REMOVE(head, elm, type, field).  whilst it's O(n),
  this mirrors the functionality of SLIST_REMOVE() (the other
  singly-linked list type) and FreeBSD's STAILQ_REMOVE()
- remove the unnecessary elm arg from SIMPLEQ_REMOVE_HEAD().
  this mirrors the functionality of SLIST_REMOVE_HEAD() (the other
  singly-linked list type) and FreeBSD's STAILQ_REMOVE_HEAD()
- remove notes about SIMPLEQ not supporting arbitrary element removal
- use SIMPLEQ_FOREACH() instead of home-grown for loops
- use SIMPLEQ_EMPTY() appropriately
- use SIMPLEQ_*() instead of accessing sqh_first,sqh_last,sqe_next directly
- reorder manual page; be consistent about how the types are listed
- other minor cleanups

diffstat:

 sys/arch/i386/pci/pci_intr_fixup.c |  878 +++++++++++++++++++++++++++++++++++++
 1 files changed, 878 insertions(+), 0 deletions(-)

diffs (truncated from 882 to 300 lines):

diff -r 003bc1841d65 -r b0bf105898b9 sys/arch/i386/pci/pci_intr_fixup.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/i386/pci/pci_intr_fixup.c        Sat Jun 01 23:50:56 2002 +0000
@@ -0,0 +1,878 @@
+/*     $NetBSD: pci_intr_fixup.c,v 1.20.2.2 2002/06/01 23:50:56 lukem Exp $    */
+
+/*-
+ * Copyright (c) 1999 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
+ * NASA Ames Research Center.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the NetBSD
+ *     Foundation, Inc. and its contributors.
+ * 4. Neither the name of The NetBSD Foundation nor the names of its
+ *    contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/*
+ * Copyright (c) 1999, by UCHIYAMA Yasushi
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. The name of the developer may NOT be used to endorse or promote products
+ *    derived from this software without specific prior written permission.
+ * 
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 
+ * SUCH DAMAGE. 
+ */
+
+/*
+ * PCI Interrupt Router support.
+ */
+
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: pci_intr_fixup.c,v 1.20.2.2 2002/06/01 23:50:56 lukem Exp $");
+
+#include "opt_pcibios.h"
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/kernel.h>
+#include <sys/malloc.h>
+#include <sys/queue.h>
+#include <sys/device.h>
+
+#include <machine/bus.h>
+#include <machine/intr.h>
+
+#include <dev/pci/pcireg.h>
+#include <dev/pci/pcivar.h>
+#include <dev/pci/pcidevs.h>
+
+#include <i386/isa/icu.h>
+#include <i386/pci/pci_intr_fixup.h>
+#include <i386/pci/pcibios.h>
+
+struct pciintr_link_map {
+       int link;
+       int clink;
+       int irq;
+       u_int16_t bitmap;
+       int fixup_stage;
+       SIMPLEQ_ENTRY(pciintr_link_map) list;
+};
+
+pciintr_icu_tag_t pciintr_icu_tag;
+pciintr_icu_handle_t pciintr_icu_handle;
+
+#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 *));
+int    pciintr_header_fixup __P((pci_chipset_tag_t));
+void   pciintr_do_header_fixup __P((pci_chipset_tag_t, pcitag_t, void*));
+
+SIMPLEQ_HEAD(, pciintr_link_map) pciintr_link_map_list;
+
+const struct pciintr_icu_table {
+       pci_vendor_id_t piit_vendor;
+       pci_product_id_t piit_product;
+       int (*piit_init) __P((pci_chipset_tag_t,
+               bus_space_tag_t, pcitag_t, pciintr_icu_tag_t *,
+               pciintr_icu_handle_t *));
+} pciintr_icu_table[] = {
+       { PCI_VENDOR_INTEL,     PCI_PRODUCT_INTEL_82371MX,
+         piix_init },
+       { PCI_VENDOR_INTEL,     PCI_PRODUCT_INTEL_82371AB_ISA,
+         piix_init },
+       { PCI_VENDOR_INTEL,     PCI_PRODUCT_INTEL_82371FB_ISA,
+         piix_init },
+       { PCI_VENDOR_INTEL,     PCI_PRODUCT_INTEL_82371SB_ISA,
+         piix_init },
+       { PCI_VENDOR_INTEL,     PCI_PRODUCT_INTEL_82801BA_LPC,
+         piix_init },
+       { PCI_VENDOR_INTEL,     PCI_PRODUCT_INTEL_82801BAM_LPC,
+         piix_init },
+
+       { PCI_VENDOR_OPTI,      PCI_PRODUCT_OPTI_82C558,
+         opti82c558_init },
+       { PCI_VENDOR_OPTI,      PCI_PRODUCT_OPTI_82C700,
+         opti82c700_init },
+
+       { PCI_VENDOR_VIATECH,   PCI_PRODUCT_VIATECH_VT82C586_ISA,
+         via82c586_init },
+       { PCI_VENDOR_VIATECH,   PCI_PRODUCT_VIATECH_VT82C686A_ISA,
+         via82c586_init },
+
+       { PCI_VENDOR_SIS,       PCI_PRODUCT_SIS_85C503,
+         sis85c503_init },
+
+       { PCI_VENDOR_AMD,       PCI_PRODUCT_AMD_PBC756_PMC,
+         amd756_init },
+
+       { PCI_VENDOR_ALI,       PCI_PRODUCT_ALI_M1543,
+         ali1543_init },
+
+       { 0,                    0,
+         NULL },
+};
+
+const struct pciintr_icu_table *pciintr_icu_lookup __P((pcireg_t));
+
+const struct pciintr_icu_table *
+pciintr_icu_lookup(id)
+       pcireg_t id;
+{
+       const struct pciintr_icu_table *piit;
+
+       for (piit = pciintr_icu_table;
+            piit->piit_init != NULL;
+            piit++) {
+               if (PCI_VENDOR(id) == piit->piit_vendor &&
+                   PCI_PRODUCT(id) == piit->piit_product)
+                       return (piit);
+       }
+
+       return (NULL);
+}
+
+struct pciintr_link_map *
+pciintr_link_lookup(link)
+       int link;
+{
+       struct pciintr_link_map *l;
+
+       SIMPLEQ_FOREACH(l, &pciintr_link_map_list, list) {
+               if (l->link == link)
+                       return (l);
+       }
+
+       return (NULL);
+}
+
+struct pciintr_link_map *
+pciintr_link_alloc(pir, pin)
+       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 = 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)
+               SIMPLEQ_INSERT_TAIL(&pciintr_link_map_list, l, list);
+       else
+               SIMPLEQ_INSERT_HEAD(&pciintr_link_map_list, l, list);
+
+       return (l);
+}
+
+struct pcibios_intr_routing *
+pciintr_pir_lookup(bus, device)
+       int bus, device;
+{
+       struct pcibios_intr_routing *pir;
+       int entry;
+
+       if (pcibios_pir_table == NULL)
+               return (NULL);
+
+       for (entry = 0; entry < pcibios_pir_table_nentries; entry++) {
+               pir = &pcibios_pir_table[entry];
+               if (pir->bus == bus &&
+                   PIR_DEVFUNC_DEVICE(pir->device) == device)
+                       return (pir);
+       }
+
+       return (NULL);
+}
+
+static int
+pciintr_bitmap_count_irq(irq_bitmap, irqp)



Home | Main Index | Thread Index | Old Index