summaryrefslogtreecommitdiffstats
path: root/sys/dev/pci
diff options
context:
space:
mode:
authormsmith <msmith@FreeBSD.org>2000-12-08 22:11:23 +0000
committermsmith <msmith@FreeBSD.org>2000-12-08 22:11:23 +0000
commitc27f2d3c492a3d78680bb4c52f0be2c345735e1d (patch)
treeab8e18698d3c3ee4b4443c78e8ba86065bed1ff3 /sys/dev/pci
parent3e12cdd63653239c3c71bf1e7042f1149134e630 (diff)
downloadFreeBSD-src-c27f2d3c492a3d78680bb4c52f0be2c345735e1d.zip
FreeBSD-src-c27f2d3c492a3d78680bb4c52f0be2c345735e1d.tar.gz
Next phase in the PCI subsystem cleanup.
- Move PCI core code to dev/pci. - Split bridge code out into separate modules. - Remove the descriptive strings from the bridge drivers. If you want to know what a device is, use pciconf. Add support for broadly identifying devices based on class/subclass, and for parsing a preloaded device identification database so that if you want to waste the memory, you can identify *anything* we know about. - Remove machine-dependant code from the core PCI code. APIC interrupt mapping is performed by shadowing the intline register in machine- dependant code. - Bring interrupt routing support to the Alpha (although many platforms don't yet support routing or mapping interrupts entirely correctly). This resulted in spamming <sys/bus.h> into more places than it really should have gone. - Put sys/dev on the kernel/modules include path. This avoids having to change *all* the pci*.h includes.
Diffstat (limited to 'sys/dev/pci')
-rw-r--r--sys/dev/pci/eisa_pci.c128
-rw-r--r--sys/dev/pci/fixup_pci.c116
-rw-r--r--sys/dev/pci/ignore_pci.c70
-rw-r--r--sys/dev/pci/isa_pci.c161
-rw-r--r--sys/dev/pci/pci.c352
-rw-r--r--sys/dev/pci/pci_pci.c334
-rw-r--r--sys/dev/pci/pcivar.h7
-rw-r--r--sys/dev/pci/vga_pci.c75
8 files changed, 1105 insertions, 138 deletions
diff --git a/sys/dev/pci/eisa_pci.c b/sys/dev/pci/eisa_pci.c
new file mode 100644
index 0000000..1f2186d
--- /dev/null
+++ b/sys/dev/pci/eisa_pci.c
@@ -0,0 +1,128 @@
+/*-
+ * Copyright (c) 1994,1995 Stefan Esser, Wolfgang StanglMeier
+ * Copyright (c) 2000 Michael Smith <msmith@freebsd.org>
+ * Copyright (c) 2000 BSDi
+ * 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. 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. The name of the author 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.
+ *
+ * $FreeBSD$
+ */
+
+/*
+ * PCI:EISA bridge support
+ */
+
+#include <sys/param.h>
+#include <sys/kernel.h>
+#include <sys/bus.h>
+
+#include <pci/pcivar.h>
+#include <pci/pcireg.h>
+
+static int eisab_probe(device_t dev);
+static int eisab_attach(device_t dev);
+
+static device_method_t eisab_methods[] = {
+ /* Device interface */
+ DEVMETHOD(device_probe, eisab_probe),
+ DEVMETHOD(device_attach, eisab_attach),
+ DEVMETHOD(device_shutdown, bus_generic_shutdown),
+ DEVMETHOD(device_suspend, bus_generic_suspend),
+ DEVMETHOD(device_resume, bus_generic_resume),
+
+ /* Bus interface */
+ DEVMETHOD(bus_print_child, bus_generic_print_child),
+ DEVMETHOD(bus_alloc_resource, bus_generic_alloc_resource),
+ DEVMETHOD(bus_release_resource, bus_generic_release_resource),
+ DEVMETHOD(bus_activate_resource, bus_generic_activate_resource),
+ DEVMETHOD(bus_deactivate_resource, bus_generic_deactivate_resource),
+ DEVMETHOD(bus_setup_intr, bus_generic_setup_intr),
+ DEVMETHOD(bus_teardown_intr, bus_generic_teardown_intr),
+
+ { 0, 0 }
+};
+
+static driver_t eisab_driver = {
+ "eisab",
+ eisab_methods,
+ 0,
+};
+
+static devclass_t eisab_devclass;
+
+DRIVER_MODULE(eisab, pci, eisab_driver, eisab_devclass, 0, 0);
+
+static int
+eisab_probe(device_t dev)
+{
+ int matched = 0;
+
+ /*
+ * Generic match by class/subclass.
+ */
+ if ((pci_get_class(dev) == PCIC_BRIDGE) &&
+ (pci_get_subclass(dev) == PCIS_BRIDGE_EISA))
+ matched = 1;
+
+ /*
+ * Some bridges don't correctly report their class.
+ */
+ switch (pci_get_devid(dev)) {
+ case 0x04828086: /* reports PCI-HOST class (!) */
+ matched = 1;
+ break;
+ default:
+ break;
+ }
+
+ if (matched) {
+ device_set_desc(dev, "PCI-EISA bridge");
+ return(-10000);
+ }
+ return(ENXIO);
+}
+
+static int
+eisab_attach(device_t dev)
+{
+ device_t child;
+
+ /*
+ * Attach an EISA bus. Note that we can only have one EISA bus.
+ */
+ child = device_add_child(dev, "eisa", 0);
+ if (child != NULL)
+ return(bus_generic_attach(dev));
+
+ /*
+ * Attach an ISA bus as well (should this be a child of EISA?)
+ */
+ child = device_add_child(dev, "isa", 0);
+ if (child != NULL)
+ bus_generic_attach(dev);
+
+ return(0);
+}
+
diff --git a/sys/dev/pci/fixup_pci.c b/sys/dev/pci/fixup_pci.c
new file mode 100644
index 0000000..c2b57eb
--- /dev/null
+++ b/sys/dev/pci/fixup_pci.c
@@ -0,0 +1,116 @@
+/*-
+ * Copyright (c) 1994,1995 Stefan Esser, Wolfgang StanglMeier
+ * Copyright (c) 2000 Michael Smith <msmith@freebsd.org>
+ * Copyright (c) 2000 BSDi
+ * 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. 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. The name of the author 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.
+ *
+ * $FreeBSD$
+ */
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/malloc.h>
+#include <sys/kernel.h>
+#include <sys/bus.h>
+
+#include <pci/pcivar.h>
+#include <pci/pcireg.h>
+
+/*
+ * Chipset fixups.
+ *
+ * These routines are invoked during the probe phase for devices which
+ * typically don't have specific device drivers, but which require
+ * some cleaning up.
+ */
+
+static int fixup_pci_probe(device_t dev);
+static void fixbushigh_i1225(device_t dev);
+static void fixwsc_natoma(device_t dev);
+
+static device_method_t fixup_pci_methods[] = {
+ /* Device interface */
+ DEVMETHOD(device_probe, fixup_pci_probe),
+ DEVMETHOD(device_attach, bus_generic_attach),
+ { 0, 0 }
+};
+
+static driver_t fixup_pci_driver = {
+ "fixup_pci",
+ fixup_pci_methods,
+ 0,
+};
+
+static devclass_t fixup_pci_devclass;
+
+DRIVER_MODULE(fixup_pci, pci, fixup_pci_driver, fixup_pci_devclass, 0, 0);
+
+static int
+fixup_pci_probe(device_t dev)
+{
+ switch (pci_get_devid(dev)) {
+ case 0x12258086: /* Intel 82454KX/GX (Orion) */
+ fixbushigh_i1225(dev);
+ break;
+ case 0x12378086: /* Intel 82440FX (Natoma) */
+ fixwsc_natoma(dev);
+ break;
+ }
+ return(ENXIO);
+}
+
+static void
+fixbushigh_i1225(device_t dev)
+{
+ int supbus;
+
+ supbus = pci_read_config(dev, 0x41, 1);
+ if (supbus != 0xff) {
+ pci_set_secondarybus(dev, supbus + 1);
+ pci_set_subordinatebus(dev, supbus + 1);
+ }
+}
+
+static void
+fixwsc_natoma(device_t dev)
+{
+ int pmccfg;
+
+ pmccfg = pci_read_config(dev, 0x50, 2);
+#if defined(SMP)
+ if (pmccfg & 0x8000) {
+ printf("Correcting Natoma config for SMP\n");
+ pmccfg &= ~0x8000;
+ pci_write_config(dev, 0x50, 2, pmccfg);
+ }
+#else
+ if ((pmccfg & 0x8000) == 0) {
+ printf("Correcting Natoma config for non-SMP\n");
+ pmccfg |= 0x8000;
+ pci_write_config(dev, 0x50, 2, pmccfg);
+ }
+#endif
+}
diff --git a/sys/dev/pci/ignore_pci.c b/sys/dev/pci/ignore_pci.c
new file mode 100644
index 0000000..520099d
--- /dev/null
+++ b/sys/dev/pci/ignore_pci.c
@@ -0,0 +1,70 @@
+/*-
+ * Copyright (c) 2000 Michael Smith <msmith@freebsd.org>
+ * Copyright (c) 2000 BSDi
+ * 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. 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.
+ *
+ * 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.
+ *
+ * $FreeBSD$
+ */
+
+/*
+ * 'Ignore' driver - eats devices that show up errnoeously on PCI
+ * but shouldn't ever be listed or handled by a driver.
+ */
+
+#include <sys/param.h>
+#include <sys/kernel.h>
+#include <sys/bus.h>
+
+#include <pci/pcivar.h>
+
+static int ignore_pci_probe(device_t dev);
+
+static device_method_t ignore_pci_methods[] = {
+ /* Device interface */
+ DEVMETHOD(device_probe, ignore_pci_probe),
+ DEVMETHOD(device_attach, bus_generic_attach),
+ { 0, 0 }
+};
+
+static driver_t ignore_pci_driver = {
+ "ignore_pci",
+ ignore_pci_methods,
+ 0,
+};
+
+static devclass_t ignore_pci_devclass;
+
+DRIVER_MODULE(ignore_pci, pci, ignore_pci_driver, ignore_pci_devclass, 0, 0);
+
+static int
+ignore_pci_probe(device_t dev)
+{
+ switch (pci_get_devid(dev)) {
+ case 0x10001042ul: /* SMC 37C665 */
+ device_set_desc(dev, "ignored");
+ device_quiet(dev);
+ return(-10000);
+ }
+ return(ENXIO);
+}
diff --git a/sys/dev/pci/isa_pci.c b/sys/dev/pci/isa_pci.c
new file mode 100644
index 0000000..b7e5f7c
--- /dev/null
+++ b/sys/dev/pci/isa_pci.c
@@ -0,0 +1,161 @@
+/*-
+ * Copyright (c) 1994,1995 Stefan Esser, Wolfgang StanglMeier
+ * Copyright (c) 2000 Michael Smith <msmith@freebsd.org>
+ * Copyright (c) 2000 BSDi
+ * 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. 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. The name of the author 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.
+ *
+ * $FreeBSD$
+ */
+
+/*
+ * PCI:ISA bridge support
+ */
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/kernel.h>
+#include <sys/bus.h>
+
+#include <pci/pcivar.h>
+#include <pci/pcireg.h>
+
+static int isab_probe(device_t dev);
+static int isab_attach(device_t dev);
+
+static device_method_t isab_methods[] = {
+ /* Device interface */
+ DEVMETHOD(device_probe, isab_probe),
+ DEVMETHOD(device_attach, isab_attach),
+ DEVMETHOD(device_shutdown, bus_generic_shutdown),
+ DEVMETHOD(device_suspend, bus_generic_suspend),
+ DEVMETHOD(device_resume, bus_generic_resume),
+
+ /* Bus interface */
+ DEVMETHOD(bus_print_child, bus_generic_print_child),
+ DEVMETHOD(bus_alloc_resource, bus_generic_alloc_resource),
+ DEVMETHOD(bus_release_resource, bus_generic_release_resource),
+ DEVMETHOD(bus_activate_resource, bus_generic_activate_resource),
+ DEVMETHOD(bus_deactivate_resource, bus_generic_deactivate_resource),
+ DEVMETHOD(bus_setup_intr, bus_generic_setup_intr),
+ DEVMETHOD(bus_teardown_intr, bus_generic_teardown_intr),
+
+ { 0, 0 }
+};
+
+static driver_t isab_driver = {
+ "isab",
+ isab_methods,
+ 0,
+};
+
+static devclass_t isab_devclass;
+
+DRIVER_MODULE(isab, pci, isab_driver, isab_devclass, 0, 0);
+
+/*
+ * XXX we need to add a quirk list here for bridges that don't correctly
+ * report themselves.
+ */
+static int
+isab_probe(device_t dev)
+{
+ int matched = 0;
+
+ /*
+ * Try for a generic match based on class/subclass.
+ */
+ if ((pci_get_class(dev) == PCIC_BRIDGE) &&
+ (pci_get_subclass(dev) == PCIS_BRIDGE_ISA))
+ matched = 1;
+ /*
+ * Some bridges don't report the ISA bus correctly.
+ * (Note that some of the devices listed here probably do, we will
+ * kvetch about this below and request updates.)
+ */
+ switch (pci_get_devid(dev)) {
+ case 0x04848086: /* Intel 82378ZB/82378IB */
+ case 0x122e8086: /* Intel 82371FB */
+ case 0x70008086: /* Intel 82371SB */
+ case 0x71108086: /* Intel 82371AB */
+ case 0x71988086: /* Intel 82443MX */
+ case 0x24108086: /* Intel 82801AA (ICH) */
+ case 0x24208086: /* Intel 82801AB (ICH0) */
+ case 0x24408086: /* Intel 82801BA (ICH2) */
+ case 0x00061004: /* VLSI 82C593 */
+ case 0x05861106: /* VIA 82C586 */
+ case 0x05961106: /* VIA 82C596 PCI-ISA */
+ case 0x06861106: /* VIA 82C686 PCI-ISA */
+ /* AcerLabs -- vendor 0x10b9 */
+ /* Funny : The datasheet told me vendor id is "10b8",sub-vendor */
+ /* id is '10b9" but the register always shows "10b9". -Foxfair */
+ case 0x153310b9: /* AcerLabs M1533 */
+ case 0x154310b9: /* AcerLabs M1543 */
+ case 0x00081039: /* SiS 85c503 */
+ case 0x00001078: /* Cyrix Cx5510 */
+ case 0x01001078: /* Cyrix Cx5530 */
+ case 0xc7001045: /* OPTi 82C700 (FireStar) */
+ case 0x00011033: /* NEC 0001 (C-bus) */
+ case 0x002c1033: /* NEC 002C (C-bus) */
+ case 0x003b1033: /* NEC 003B (C-bus) */
+ case 0x886a1060: /* UMC UM8886 ISA */
+ case 0x02001166: /* ServerWorks IB6566 PCI */
+ matched = 1;
+ /*
+ * Report redundant matches (debugging)
+ */
+ if ((pci_get_class(dev) == PCIC_BRIDGE) &&
+ (pci_get_subclass(dev) == PCIS_BRIDGE_ISA)) {
+ printf("** REDUNDANT ISA BRIDGE MATCH FOR DEVICE 0x%08x\n", pci_get_devid(dev));
+ printf("** Please report to msmith@freebsd.org\n");
+ }
+ break;
+
+ default:
+ break;
+ }
+
+ if (matched) {
+ device_set_desc(dev, "PCI-ISA bridge");
+ return(-10000);
+ }
+ return(ENXIO);
+}
+
+static int
+isab_attach(device_t dev)
+{
+ device_t child;
+
+ /*
+ * Attach an ISA bus. Note that we can only have one ISA bus.
+ */
+ child = device_add_child(dev, "isa", 0);
+ if (child != NULL)
+ return(bus_generic_attach(dev));
+
+ return(0);
+}
+
diff --git a/sys/dev/pci/pci.c b/sys/dev/pci/pci.c
index 2e5b9c5..4699069 100644
--- a/sys/dev/pci/pci.c
+++ b/sys/dev/pci/pci.c
@@ -29,13 +29,11 @@
#include "opt_bus.h"
-#include "opt_simos.h"
-#include "opt_compat_oldpci.h"
-
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/malloc.h>
#include <sys/module.h>
+#include <sys/linker.h>
#include <sys/fcntl.h>
#include <sys/conf.h>
#include <sys/kernel.h>
@@ -50,7 +48,6 @@
#include <machine/bus.h>
#include <sys/rman.h>
#include <machine/resource.h>
-#include <machine/md_var.h> /* For the Alpha */
#include <sys/pciio.h>
#include <pci/pcireg.h>
@@ -58,13 +55,9 @@
#include "pcib_if.h"
-#ifdef __alpha__
-#include <machine/rpb.h>
-#endif
-
-#ifdef APIC_IO
-#include <machine/smp.h>
-#endif /* APIC_IO */
+static char *pci_vendordata;
+static size_t pci_vendordata_size;
+static char *pci_describe_device(device_t dev);
static devclass_t pci_devclass;
@@ -178,52 +171,6 @@ pci_fixancient(pcicfgregs *cfg)
cfg->hdrtype = 1;
}
-/* read config data specific to header type 1 device (PCI to PCI bridge) */
-
-static void *
-pci_readppb(device_t pcib, int b, int s, int f)
-{
- pcih1cfgregs *p;
-
- p = malloc(sizeof (pcih1cfgregs), M_DEVBUF, M_WAITOK);
- if (p == NULL)
- return (NULL);
-
- bzero(p, sizeof *p);
-
- p->secstat = PCIB_READ_CONFIG(pcib, b, s, f, PCIR_SECSTAT_1, 2);
- p->bridgectl = PCIB_READ_CONFIG(pcib, b, s, f, PCIR_BRIDGECTL_1, 2);
-
- p->seclat = PCIB_READ_CONFIG(pcib, b, s, f, PCIR_SECLAT_1, 1);
-
- p->iobase = PCI_PPBIOBASE (PCIB_READ_CONFIG(pcib, b, s, f,
- PCIR_IOBASEH_1, 2),
- PCIB_READ_CONFIG(pcib, b, s, f,
- PCIR_IOBASEL_1, 1));
- p->iolimit = PCI_PPBIOLIMIT (PCIB_READ_CONFIG(pcib, b, s, f,
- PCIR_IOLIMITH_1, 2),
- PCIB_READ_CONFIG(pcib, b, s, f,
- PCIR_IOLIMITL_1, 1));
-
- p->membase = PCI_PPBMEMBASE (0,
- PCIB_READ_CONFIG(pcib, b, s, f,
- PCIR_MEMBASE_1, 2));
- p->memlimit = PCI_PPBMEMLIMIT (0,
- PCIB_READ_CONFIG(pcib, b, s, f,
- PCIR_MEMLIMIT_1, 2));
-
- p->pmembase = PCI_PPBMEMBASE (
- (pci_addr_t)PCIB_READ_CONFIG(pcib, b, s, f, PCIR_PMBASEH_1, 4),
- PCIB_READ_CONFIG(pcib, b, s, f, PCIR_PMBASEL_1, 2));
-
- p->pmemlimit = PCI_PPBMEMLIMIT (
- (pci_addr_t)PCIB_READ_CONFIG(pcib, b, s, f,
- PCIR_PMLIMITH_1, 4),
- PCIB_READ_CONFIG(pcib, b, s, f, PCIR_PMLIMITL_1, 2));
-
- return (p);
-}
-
/* read config data specific to header type 2 device (PCI to CardBus bridge) */
static void *
@@ -231,12 +178,10 @@ pci_readpcb(device_t pcib, int b, int s, int f)
{
pcih2cfgregs *p;
- p = malloc(sizeof (pcih2cfgregs), M_DEVBUF, M_WAITOK);
+ p = malloc(sizeof (pcih2cfgregs), M_DEVBUF, M_WAITOK | M_ZERO);
if (p == NULL)
return (NULL);
- bzero(p, sizeof *p);
-
p->secstat = PCIB_READ_CONFIG(pcib, b, s, f, PCIR_SECSTAT_2, 2);
p->bridgectl = PCIB_READ_CONFIG(pcib, b, s, f, PCIR_BRIDGECTL_2, 2);
@@ -271,10 +216,7 @@ pci_hdrtypedata(device_t pcib, int b, int s, int f, pcicfgregs *cfg)
case 1:
cfg->subvendor = REG(PCIR_SUBVEND_1, 2);
cfg->subdevice = REG(PCIR_SUBDEV_1, 2);
- cfg->secondarybus = REG(PCIR_SECBUS_1, 1);
- cfg->subordinatebus = REG(PCIR_SUBBUS_1, 1);
cfg->nummaps = PCI_MAXMAPS_1;
- cfg->hdrspec = pci_readppb(pcib, b, s, f);
break;
case 2:
cfg->subvendor = REG(PCIR_SUBVEND_2, 2);
@@ -304,10 +246,9 @@ pci_read_device(device_t pcib, int b, int s, int f)
if (PCIB_READ_CONFIG(pcib, b, s, f, PCIR_DEVVENDOR, 4) != -1) {
devlist_entry = malloc(sizeof(struct pci_devinfo),
- M_DEVBUF, M_WAITOK);
+ M_DEVBUF, M_WAITOK | M_ZERO);
if (devlist_entry == NULL)
return (NULL);
- bzero(devlist_entry, sizeof *devlist_entry);
cfg = &devlist_entry->cfg;
@@ -327,37 +268,6 @@ pci_read_device(device_t pcib, int b, int s, int f)
cfg->lattimer = REG(PCIR_LATTIMER, 1);
cfg->intpin = REG(PCIR_INTPIN, 1);
cfg->intline = REG(PCIR_INTLINE, 1);
-#ifdef __alpha__
- alpha_platform_assign_pciintr(cfg);
-#endif
-
-#ifdef APIC_IO
- if (cfg->intpin != 0) {
- int airq;
-
- airq = pci_apic_irq(cfg->bus, cfg->slot, cfg->intpin);
- if (airq >= 0) {
- /* PCI specific entry found in MP table */
- if (airq != cfg->intline) {
- undirect_pci_irq(cfg->intline);
- cfg->intline = airq;
- }
- } else {
- /*
- * PCI interrupts might be redirected to the
- * ISA bus according to some MP tables. Use the
- * same methods as used by the ISA devices
- * devices to find the proper IOAPIC int pin.
- */
- airq = isa_apic_irq(cfg->intline);
- if ((airq >= 0) && (airq != cfg->intline)) {
- /* XXX: undirect_pci_irq() ? */
- undirect_isa_irq(cfg->intline);
- cfg->intline = airq;
- }
- }
- }
-#endif /* APIC_IO */
cfg->mingnt = REG(PCIR_MINGNT, 1);
cfg->maxlat = REG(PCIR_MAXLAT, 1);
@@ -1076,6 +986,7 @@ static int
pci_probe(device_t dev)
{
static int once, busno;
+ caddr_t vendordata, info;
device_set_desc(dev, "PCI bus");
@@ -1095,6 +1006,14 @@ pci_probe(device_t dev)
if (!once) {
make_dev(&pcicdev, 0, UID_ROOT, GID_WHEEL, 0644, "pci");
+ if ((vendordata = preload_search_by_type("pci_vendor_data")) != NULL) {
+ info = preload_search_info(vendordata, MODINFO_ADDR);
+ pci_vendordata = *(char **)info;
+ info = preload_search_info(vendordata, MODINFO_SIZE);
+ pci_vendordata_size = *(size_t *)info;
+ /* terminate the database */
+ pci_vendordata[pci_vendordata_size] = '\n';
+ }
once++;
}
@@ -1157,42 +1076,212 @@ pci_print_child(device_t dev, device_t child)
return (retval);
}
+static struct
+{
+ int class;
+ int subclass;
+ char *desc;
+} pci_nomatch_tab[] = {
+ {PCIC_OLD, -1, "old"},
+ {PCIC_OLD, PCIS_OLD_NONVGA, "non-VGA display device"},
+ {PCIC_OLD, PCIS_OLD_VGA, "VGA-compatible display device"},
+ {PCIC_STORAGE, -1, "mass storage"},
+ {PCIC_STORAGE, PCIS_STORAGE_SCSI, "SCSI"},
+ {PCIC_STORAGE, PCIS_STORAGE_IDE, "ATA"},
+ {PCIC_STORAGE, PCIS_STORAGE_FLOPPY, "floppy disk"},
+ {PCIC_STORAGE, PCIS_STORAGE_IPI, "IPI"},
+ {PCIC_STORAGE, PCIS_STORAGE_RAID, "RAID"},
+ {PCIC_NETWORK, -1, "network"},
+ {PCIC_NETWORK, PCIS_NETWORK_ETHERNET, "ethernet"},
+ {PCIC_NETWORK, PCIS_NETWORK_TOKENRING, "token ring"},
+ {PCIC_NETWORK, PCIS_NETWORK_FDDI, "fddi"},
+ {PCIC_NETWORK, PCIS_NETWORK_ATM, "ATM"},
+ {PCIC_DISPLAY, -1, "display"},
+ {PCIC_DISPLAY, PCIS_DISPLAY_VGA, "VGA"},
+ {PCIC_DISPLAY, PCIS_DISPLAY_XGA, "XGA"},
+ {PCIC_MULTIMEDIA, -1, "multimedia"},
+ {PCIC_MULTIMEDIA, PCIS_MULTIMEDIA_VIDEO, "video"},
+ {PCIC_MULTIMEDIA, PCIS_MULTIMEDIA_AUDIO, "audio"},
+ {PCIC_MEMORY, -1, "memory"},
+ {PCIC_MEMORY, PCIS_MEMORY_RAM, "RAM"},
+ {PCIC_MEMORY, PCIS_MEMORY_FLASH, "flash"},
+ {PCIC_BRIDGE, -1, "bridge"},
+ {PCIC_BRIDGE, PCIS_BRIDGE_HOST, "HOST-PCI"},
+ {PCIC_BRIDGE, PCIS_BRIDGE_ISA, "PCI-ISA"},
+ {PCIC_BRIDGE, PCIS_BRIDGE_EISA, "PCI-EISA"},
+ {PCIC_BRIDGE, PCIS_BRIDGE_MCA, "PCI-MCA"},
+ {PCIC_BRIDGE, PCIS_BRIDGE_PCI, "PCI-PCI"},
+ {PCIC_BRIDGE, PCIS_BRIDGE_PCMCIA, "PCI-PCMCIA"},
+ {PCIC_BRIDGE, PCIS_BRIDGE_NUBUS, "PCI-NuBus"},
+ {PCIC_BRIDGE, PCIS_BRIDGE_CARDBUS, "PCI-CardBus"},
+ {PCIC_BRIDGE, PCIS_BRIDGE_OTHER, "PCI-unknown"},
+ {PCIC_SIMPLECOMM, -1, "simple comms"},
+ {PCIC_SIMPLECOMM, PCIS_SIMPLECOMM_UART, "UART"}, /* could detect 16550 */
+ {PCIC_SIMPLECOMM, PCIS_SIMPLECOMM_PAR, "parallel port"},
+ {PCIC_BASEPERIPH, -1, "base peripheral"},
+ {PCIC_BASEPERIPH, PCIS_BASEPERIPH_PIC, "interrupt controller"},
+ {PCIC_BASEPERIPH, PCIS_BASEPERIPH_DMA, "DMA controller"},
+ {PCIC_BASEPERIPH, PCIS_BASEPERIPH_TIMER, "timer"},
+ {PCIC_BASEPERIPH, PCIS_BASEPERIPH_RTC, "realtime clock"},
+ {PCIC_INPUTDEV, -1, "input device"},
+ {PCIC_INPUTDEV, PCIS_INPUTDEV_KEYBOARD, "keyboard"},
+ {PCIC_INPUTDEV, PCIS_INPUTDEV_DIGITIZER,"digitizer"},
+ {PCIC_INPUTDEV, PCIS_INPUTDEV_MOUSE, "mouse"},
+ {PCIC_DOCKING, -1, "docking station"},
+ {PCIC_PROCESSOR, -1, "processor"},
+ {PCIC_SERIALBUS, -1, "serial bus"},
+ {PCIC_SERIALBUS, PCIS_SERIALBUS_FW, "FireWire"},
+ {PCIC_SERIALBUS, PCIS_SERIALBUS_ACCESS, "AccessBus"},
+ {PCIC_SERIALBUS, PCIS_SERIALBUS_SSA, "SSA"},
+ {PCIC_SERIALBUS, PCIS_SERIALBUS_USB, "USB"},
+ {PCIC_SERIALBUS, PCIS_SERIALBUS_FC, "Fibre Channel"},
+ {PCIC_SERIALBUS, PCIS_SERIALBUS_SMBUS, "SMBus"},
+ {0, 0, NULL}
+};
+
static void
pci_probe_nomatch(device_t dev, device_t child)
{
- struct pci_devinfo *dinfo;
- pcicfgregs *cfg;
- const char *desc;
- int unknown;
+ int i;
+ char *cp, *scp, *device;
+
+ /*
+ * Look for a listing for this device in a loaded device database.
+ */
+ if ((device = pci_describe_device(child)) != NULL) {
+ printf("<%s>", device);
+ free(device, M_DEVBUF);
+ } else {
+ /*
+ * Scan the class/subclass descriptions for a general description.
+ */
+ cp = "unknown";
+ scp = NULL;
+ for (i = 0; pci_nomatch_tab[i].desc != NULL; i++) {
+ if (pci_nomatch_tab[i].class == pci_get_class(child)) {
+ if (pci_nomatch_tab[i].subclass == -1) {
+ cp = pci_nomatch_tab[i].desc;
+ } else if (pci_nomatch_tab[i].subclass == pci_get_subclass(child)) {
+ scp = pci_nomatch_tab[i].desc;
+ }
+ }
+ }
+ device_printf(dev, "<%s%s%s>",
+ cp ? : "",
+ ((cp != NULL) && (scp != NULL)) ? ", " : "",
+ scp ? : "");
+ }
+ printf(" at %d:%d (no driver attached)\n",
+ pci_get_slot(child),
+ pci_get_function(child));
+ return;
+}
- unknown = 0;
- dinfo = device_get_ivars(child);
- cfg = &dinfo->cfg;
- desc = pci_ata_match(child);
- if (!desc) desc = pci_usb_match(child);
- if (!desc) desc = pci_vga_match(child);
- if (!desc) desc = pci_chip_match(child);
- if (!desc) {
- desc = "unknown card";
- unknown++;
+/*
+ * Parse the PCI device database, if loaded, and return a pointer to a
+ * description of the device.
+ *
+ * The database is flat text formatted as follows:
+ *
+ * Any line not in a valid format is ignored.
+ * Lines are terminated with newline '\n' characters.
+ *
+ * A VENDOR line consists of the 4 digit (hex) vendor code, a TAB, then
+ * the vendor name.
+ *
+ * A DEVICE line is entered immediately below the corresponding VENDOR ID.
+ * - devices cannot be listed without a corresponding VENDOR line.
+ * A DEVICE line consists of a TAB, the 4 digit (hex) device code,
+ * another TAB, then the device name.
+ */
+
+/*
+ * Assuming (ptr) points to the beginning of a line in the database,
+ * return the vendor or device and description of the next entry.
+ * The value of (vendor) or (device) inappropriate for the entry type
+ * is set to -1. Returns nonzero at the end of the database.
+ *
+ * Note that this is slightly unrobust in the face of corrupt data;
+ * we attempt to safeguard against this by spamming the end of the
+ * database with a newline when we initialise.
+ */
+static int
+pci_describe_parse_line(char **ptr, int *vendor, int *device, char **desc)
+{
+ char *cp = *ptr;
+
+ *device = -1;
+ *vendor = -1;
+ *desc = NULL;
+ for (;;) {
+ if ((cp - pci_vendordata) >= pci_vendordata_size)
+ return(1);
+
+ /* vendor entry? */
+ if (sscanf(cp, "%x\t%80[^\n]", vendor, *desc) == 2)
+ break;
+ /* device entry? */
+ if (sscanf(cp, "\t%x\t%80[^\n]", device, *desc) == 2)
+ break;
+
+ /* skip to next line */
+ while (*cp != '\n')
+ cp++;
+ cp++;
}
- device_printf(dev, "<%s>", desc);
- if (bootverbose || unknown) {
- printf(" (vendor=0x%04x, dev=0x%04x)",
- cfg->vendor,
- cfg->device);
+ *ptr = cp;
+ return(0);
+}
+
+static char *
+pci_describe_device(device_t dev)
+{
+ int vendor, device;
+ char *desc, *vp, *dp, *line;
+
+ desc = vp = dp = NULL;
+
+ /*
+ * If we have no vendor data, we can't do anything.
+ */
+ if (pci_vendordata == NULL)
+ goto out;
+
+ /*
+ * Scan the vendor data looking for this device
+ */
+ line = pci_vendordata;
+ if ((vp = malloc(80, M_DEVBUF, M_NOWAIT)) == NULL)
+ goto out;
+ for (;;) {
+ if (pci_describe_parse_line(&line, &vendor, &device, &vp))
+ goto out;
+ if (vendor == pci_get_vendor(dev))
+ break;
}
- printf(" at %d.%d",
- pci_get_slot(child),
- pci_get_function(child));
- if (cfg->intpin > 0 && cfg->intline != 255) {
- printf(" irq %d", cfg->intline);
+ if ((dp = malloc(80, M_DEVBUF, M_NOWAIT)) == NULL)
+ goto out;
+ for (;;) {
+ if (pci_describe_parse_line(&line, &vendor, &device, &dp))
+ goto out;
+ if (vendor != -1) {
+ *dp = 0;
+ break;
+ }
+ if (device == pci_get_device(dev))
+ break;
}
- printf("\n");
-
- return;
+ if ((desc = malloc(strlen(vp) + strlen(dp) + 3, M_DEVBUF, M_NOWAIT)) != NULL)
+ sprintf(desc, "%s%s%s", vp, (dp[0] != 0) ? ", " : "", dp);
+ out:
+ if (vp != NULL)
+ free(vp, M_DEVBUF);
+ if (dp != NULL)
+ free(dp, M_DEVBUF);
+ return(desc);
}
+
static int
pci_read_ivar(device_t dev, device_t child, int which, uintptr_t *result)
{
@@ -1309,16 +1398,17 @@ pci_alloc_resource(device_t dev, device_t child, int type, int *rid,
* XXX add support here for SYS_RES_IOPORT and SYS_RES_MEMORY
*/
if (device_get_parent(child) == dev) {
- if ((type == SYS_RES_IRQ) && (cfg->intline == 255)) {
-#ifdef __i386__
- cfg->intline = PCIB_ROUTE_INTERRUPT(
- device_get_parent(dev), pci_get_slot(child),
- cfg->intpin);
-#endif /* __i386__ */
+ /*
+ * If device doesn't have an interrupt routed, and is deserving of
+ * an interrupt, try to assign it one.
+ */
+ if ((type == SYS_RES_IRQ) && (cfg->intline == 255) && (cfg->intpin != 0)) {
+ cfg->intline = PCIB_ROUTE_INTERRUPT(device_get_parent(dev), child,
+ cfg->intpin);
if (cfg->intline != 255) {
pci_write_config(child, PCIR_INTLINE, cfg->intline, 1);
resource_list_add(rl, SYS_RES_IRQ, 0,
- cfg->intline, cfg->intline, 1);
+ cfg->intline, cfg->intline, 1);
}
}
}
@@ -1419,7 +1509,7 @@ static device_method_t pci_methods[] = {
static driver_t pci_driver = {
"pci",
pci_methods,
- 1, /* no softc */
+ 0, /* no softc */
};
DRIVER_MODULE(pci, pcib, pci_driver, pci_devclass, pci_modevent, 0);
DRIVER_MODULE(pci, acpi_pcib, pci_driver, pci_devclass, pci_modevent, 0);
diff --git a/sys/dev/pci/pci_pci.c b/sys/dev/pci/pci_pci.c
new file mode 100644
index 0000000..3341a20
--- /dev/null
+++ b/sys/dev/pci/pci_pci.c
@@ -0,0 +1,334 @@
+/*-
+ * Copyright (c) 1994,1995 Stefan Esser, Wolfgang StanglMeier
+ * Copyright (c) 2000 Michael Smith <msmith@freebsd.org>
+ * Copyright (c) 2000 BSDi
+ * 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. 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. The name of the author 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.
+ *
+ * $FreeBSD$
+ */
+
+/*
+ * PCI:PCI bridge support.
+ */
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/kernel.h>
+#include <sys/bus.h>
+
+#include <machine/resource.h>
+
+#include <pci/pcivar.h>
+#include <pci/pcireg.h>
+
+#include "pcib_if.h"
+
+/*
+ * Bridge-specific data.
+ */
+struct pcib_softc
+{
+ device_t dev;
+ u_int8_t secbus; /* secondary bus number */
+ u_int8_t subbus; /* subordinate bus number */
+ pci_addr_t pmembase; /* base address of prefetchable memory */
+ pci_addr_t pmemlimit; /* topmost address of prefetchable memory */
+ u_int32_t membase; /* base address of memory window */
+ u_int32_t memlimit; /* topmost address of memory window */
+ u_int32_t iobase; /* base address of port window */
+ u_int32_t iolimit; /* topmost address of port window */
+ u_int16_t secstat; /* secondary bus status register */
+ u_int16_t bridgectl; /* bridge control register */
+ u_int8_t seclat; /* secondary bus latency timer */
+};
+
+static int pcib_probe(device_t dev);
+static int pcib_attach(device_t dev);
+static int pcib_read_ivar(device_t dev, device_t child, int which, uintptr_t *result);
+static int pcib_write_ivar(device_t dev, device_t child, int which, uintptr_t value);
+static struct resource *pcib_alloc_resource(device_t dev, device_t child, int type, int *rid,
+ u_long start, u_long end, u_long count, u_int flags);
+static int pcib_maxslots(device_t dev);
+static u_int32_t pcib_read_config(device_t dev, int b, int s, int f, int reg, int width);
+static void pcib_write_config(device_t dev, int b, int s, int f, int reg, u_int32_t val, int width);
+static int pcib_route_interrupt(device_t pcib, device_t dev, int pin);
+
+static device_method_t pcib_methods[] = {
+ /* Device interface */
+ DEVMETHOD(device_probe, pcib_probe),
+ DEVMETHOD(device_attach, pcib_attach),
+ DEVMETHOD(device_shutdown, bus_generic_shutdown),
+ DEVMETHOD(device_suspend, bus_generic_suspend),
+ DEVMETHOD(device_resume, bus_generic_resume),
+
+ /* Bus interface */
+ DEVMETHOD(bus_print_child, bus_generic_print_child),
+ DEVMETHOD(bus_read_ivar, pcib_read_ivar),
+ DEVMETHOD(bus_write_ivar, pcib_write_ivar),
+ DEVMETHOD(bus_alloc_resource, pcib_alloc_resource),
+ DEVMETHOD(bus_release_resource, bus_generic_release_resource),
+ DEVMETHOD(bus_activate_resource, bus_generic_activate_resource),
+ DEVMETHOD(bus_deactivate_resource, bus_generic_deactivate_resource),
+ DEVMETHOD(bus_setup_intr, bus_generic_setup_intr),
+ DEVMETHOD(bus_teardown_intr, bus_generic_teardown_intr),
+
+ /* pcib interface */
+ DEVMETHOD(pcib_maxslots, pcib_maxslots),
+ DEVMETHOD(pcib_read_config, pcib_read_config),
+ DEVMETHOD(pcib_write_config, pcib_write_config),
+ DEVMETHOD(pcib_route_interrupt, pcib_route_interrupt),
+
+ { 0, 0 }
+};
+
+static driver_t pcib_driver = {
+ "pcib",
+ pcib_methods,
+ sizeof(struct pcib_softc),
+};
+
+static devclass_t pcib_devclass;
+
+DRIVER_MODULE(pcib, pci, pcib_driver, pcib_devclass, 0, 0);
+
+/*
+ * Generic device interface
+ */
+static int
+pcib_probe(device_t dev)
+{
+ if ((pci_get_class(dev) == PCIC_BRIDGE) &&
+ (pci_get_subclass(dev) == PCIS_BRIDGE_PCI)) {
+ device_set_desc(dev, "PCI-PCI bridge");
+ return(-10000);
+ }
+ return(ENXIO);
+}
+
+static int
+pcib_attach(device_t dev)
+{
+ struct pcib_softc *sc;
+ device_t pcib, child;
+ int b, s, f;
+
+ sc = device_get_softc(dev);
+ sc->dev = dev;
+ pcib = device_get_parent(dev);
+ b = pci_get_bus(dev);
+ s = pci_get_slot(dev);
+ f = pci_get_function(dev);
+
+ sc->secbus = PCIB_READ_CONFIG(pcib, b, s, f, PCIR_SECBUS_1, 1);
+ sc->subbus = PCIB_READ_CONFIG(pcib, b, s, f, PCIR_SUBBUS_1, 1);
+ sc->secstat = PCIB_READ_CONFIG(pcib, b, s, f, PCIR_SECSTAT_1, 2);
+ sc->bridgectl = PCIB_READ_CONFIG(pcib, b, s, f, PCIR_BRIDGECTL_1, 2);
+ sc->seclat = PCIB_READ_CONFIG(pcib, b, s, f, PCIR_SECLAT_1, 1);
+ sc->iobase = PCI_PPBIOBASE(PCIB_READ_CONFIG(pcib, b, s, f, PCIR_IOBASEH_1, 2),
+ PCIB_READ_CONFIG(pcib, b, s, f, PCIR_IOBASEL_1, 1));
+ sc->iolimit = PCI_PPBIOLIMIT(PCIB_READ_CONFIG(pcib, b, s, f, PCIR_IOLIMITH_1, 2),
+ PCIB_READ_CONFIG(pcib, b, s, f, PCIR_IOLIMITL_1, 1));
+ sc->membase = PCI_PPBMEMBASE(0, PCIB_READ_CONFIG(pcib, b, s, f, PCIR_MEMBASE_1, 2));
+ sc->memlimit = PCI_PPBMEMLIMIT(0, PCIB_READ_CONFIG(pcib, b, s, f, PCIR_MEMLIMIT_1, 2));
+ sc->pmembase = PCI_PPBMEMBASE((pci_addr_t)PCIB_READ_CONFIG(pcib, b, s, f, PCIR_PMBASEH_1, 4),
+ PCIB_READ_CONFIG(pcib, b, s, f, PCIR_PMBASEL_1, 2));
+ sc->pmemlimit = PCI_PPBMEMLIMIT((pci_addr_t)PCIB_READ_CONFIG(pcib, b, s, f,PCIR_PMLIMITH_1, 4),
+ PCIB_READ_CONFIG(pcib, b, s, f, PCIR_PMLIMITL_1, 2));
+
+ if (bootverbose) {
+ device_printf(dev, " secondary bus %d\n", sc->secbus);
+ device_printf(dev, " subordinate bus %d\n", sc->subbus);
+ device_printf(dev, " I/O decode 0x%x-0x%x\n", sc->iobase, sc->iolimit);
+ device_printf(dev, " memory decode 0x%x-0x%x\n", sc->membase, sc->memlimit);
+ device_printf(dev, " prefetched decode 0x%x-0x%x\n", sc->pmembase, sc->pmemlimit);
+ }
+
+ /*
+ * XXX If the secondary bus number is zero, we should assign a bus number
+ * since the BIOS hasn't, then initialise the bridge.
+ */
+
+ /*
+ * XXX If the subordinate bus number is less than the secondary bus number,
+ * we should pick a better value. One sensible alternative would be to
+ * pick 255; the only tradeoff here is that configuration transactions
+ * would be more widely routed than absolutely necessary.
+ */
+
+ if (sc->secbus != 0) {
+ child = device_add_child(dev, "pci", -1);
+ if (child != NULL)
+ return(bus_generic_attach(dev));
+ }
+
+ /* no secondary bus; we should have fixed this */
+ return(0);
+}
+
+static int
+pcib_read_ivar(device_t dev, device_t child, int which, uintptr_t *result)
+{
+ struct pcib_softc *sc = device_get_softc(dev);
+
+ switch (which) {
+ case PCIB_IVAR_BUS:
+ *result = sc->secbus;
+ return(0);
+ }
+ return(ENOENT);
+}
+
+static int
+pcib_write_ivar(device_t dev, device_t child, int which, uintptr_t value)
+{
+ struct pcib_softc *sc = device_get_softc(dev);
+
+ switch (which) {
+ case PCIB_IVAR_BUS:
+ sc->secbus = value;
+ break;
+ }
+ return(ENOENT);
+}
+
+/*
+ * We have to trap resource allocation requests and ensure that the bridge
+ * is set up to, or capable of handling them.
+ */
+static struct resource *
+pcib_alloc_resource(device_t dev, device_t child, int type, int *rid,
+ u_long start, u_long end, u_long count, u_int flags)
+{
+ struct pcib_softc *sc = device_get_softc(dev);
+
+ /*
+ * If this is a "default" allocation against this rid, we can't work
+ * out where it's coming from (we should actually never see these) so we
+ * just have to punt.
+ */
+ if ((start == 0) && (end == ~0)) {
+ device_printf(dev, "can't decode default resource id %d for %s%d, bypassing\n",
+ *rid, device_get_name(child), device_get_unit(child));
+ } else {
+ /*
+ * Fail the allocation for this range if it's not supported.
+ *
+ * XXX we should probably just fix up the bridge decode and soldier on.
+ */
+ switch (type) {
+ case SYS_RES_IOPORT:
+ if ((start < sc->iobase) || (end > sc->iolimit)) {
+ device_printf(dev, "device %s%d requested unsupported I/O range 0x%lx-0x%lx"
+ " (decoding 0x%x-0x%x)\n",
+ device_get_name(child), device_get_unit(child), start, end,
+ sc->iobase, sc->iolimit);
+ return(NULL);
+ }
+ break;
+
+ /*
+ * XXX will have to decide whether the device making the request is asking
+ * for prefetchable memory or not. If it's coming from another bridge
+ * down the line, do we assume not, or ask the bridge to pass in another
+ * flag as the request bubbles up?
+ */
+ case SYS_RES_MEMORY:
+ if (((start < sc->membase) || (end > sc->memlimit)) &&
+ ((start < sc->pmembase) || (end > sc->pmemlimit))) {
+ device_printf(dev, "device %s%d requested unsupported memory range 0x%lx-0x%lx"
+ " (decoding 0x%x-0x%x, 0x%x-0x%x)\n",
+ device_get_name(child), device_get_unit(child), start, end,
+ sc->membase, sc->memlimit, sc->pmembase, sc->pmemlimit);
+ return(NULL);
+ }
+ default:
+ }
+ }
+ device_printf(sc->dev, "resource request type %d 0x%lx-0x%lx decodes OK\n",
+ type, start, end);
+ /*
+ * Bridge is OK decoding this resource, so pass it up.
+ */
+ return(bus_generic_alloc_resource(dev, child, type, rid, start, end, count, flags));
+}
+
+/*
+ * PCIB interface.
+ */
+static int
+pcib_maxslots(device_t dev)
+{
+ return(31);
+}
+
+/*
+ * Since we are a child of a PCI bus, its parent must support the pcib interface.
+ */
+static u_int32_t
+pcib_read_config(device_t dev, int b, int s, int f, int reg, int width)
+{
+ return(PCIB_READ_CONFIG(device_get_parent(device_get_parent(dev)), b, s, f, reg, width));
+}
+
+static void
+pcib_write_config(device_t dev, int b, int s, int f, int reg, u_int32_t val, int width)
+{
+ PCIB_WRITE_CONFIG(device_get_parent(device_get_parent(dev)), b, s, f, reg, val, width);
+}
+
+/*
+ * Route an interrupt across a PCI bridge.
+ */
+static int
+pcib_route_interrupt(device_t pcib, device_t dev, int pin)
+{
+ device_t bus;
+ int parent_intpin;
+ int intnum;
+
+ /*
+ *
+ * The PCI standard defines a swizzle of the child-side device/intpin to
+ * the parent-side intpin as follows.
+ *
+ * device = device on child bus
+ * child_intpin = intpin on child bus slot (0-3)
+ * parent_intpin = intpin on parent bus slot (0-3)
+ *
+ * parent_intpin = (device + child_intpin) % 4
+ */
+ parent_intpin = (pci_get_slot(pcib) + (pin - 1)) % 4;
+
+ /*
+ * Our parent is a PCI bus. Its parent must export the pcib interface
+ * which includes the ability to route interrupts.
+ */
+ bus = device_get_parent(pcib);
+ intnum = PCIB_ROUTE_INTERRUPT(device_get_parent(bus), pcib, parent_intpin + 1);
+ device_printf(pcib, "routed slot %d INT%c to irq %d\n", pci_get_slot(dev),
+ 'A' + pin - 1, intnum);
+ return(intnum);
+}
diff --git a/sys/dev/pci/pcivar.h b/sys/dev/pci/pcivar.h
index 285e4ca..4ac4dd1 100644
--- a/sys/dev/pci/pcivar.h
+++ b/sys/dev/pci/pcivar.h
@@ -144,13 +144,6 @@ struct pci_devinfo {
};
#endif
-/* externally visible functions */
-
-const char *pci_ata_match(struct device *dev);
-const char *pci_usb_match(struct device *dev);
-const char *pci_vga_match(struct device *dev);
-const char *pci_chip_match(struct device *dev);
-
/* low level PCI config register functions provided by pcibus.c */
int pci_cfgread (pcicfgregs *cfg, int reg, int bytes);
diff --git a/sys/dev/pci/vga_pci.c b/sys/dev/pci/vga_pci.c
new file mode 100644
index 0000000..d394769
--- /dev/null
+++ b/sys/dev/pci/vga_pci.c
@@ -0,0 +1,75 @@
+/*-
+ * Copyright (c) 2000 Michael Smith <msmith@freebsd.org>
+ * Copyright (c) 2000 BSDi
+ * 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. 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.
+ *
+ * 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.
+ *
+ * $FreeBSD$
+ */
+
+/*
+ * Stub handler for PCI VGA-compatible adapters.
+ */
+
+#include <sys/param.h>
+#include <sys/kernel.h>
+#include <sys/bus.h>
+
+#include <pci/pcivar.h>
+#include <pci/pcireg.h>
+
+static int vga_pci_probe(device_t dev);
+
+static device_method_t vga_pci_methods[] = {
+ /* Device interface */
+ DEVMETHOD(device_probe, vga_pci_probe),
+ DEVMETHOD(device_attach, bus_generic_attach),
+
+ { 0, 0 }
+};
+
+static driver_t vga_pci_driver = {
+ "vga_pci",
+ vga_pci_methods,
+ 0,
+};
+
+static devclass_t vga_pci_devclass;
+
+DRIVER_MODULE(vga_pci, pci, vga_pci_driver, vga_pci_devclass, 0, 0);
+
+static int
+vga_pci_probe(device_t dev)
+{
+ if ((pci_get_class(dev) == PCIC_OLD) &&
+ (pci_get_subclass(dev) == PCIS_OLD_VGA)) {
+ device_set_desc(dev, "VGA-compatible display device");
+ return(-10000);
+ }
+ if ((pci_get_class(dev) == PCIC_DISPLAY) &&
+ (pci_get_subclass(dev) == PCIS_DISPLAY_VGA)) {
+ device_set_desc(dev, "VGA-compatible display device");
+ return(-10000);
+ }
+ return(ENXIO);
+}
OpenPOWER on IntegriCloud