From dc5a7bd2ff66745f33c158a30870a64dca347614 Mon Sep 17 00:00:00 2001 From: Joerg Sonnenberger Date: Wed, 7 Jan 2004 18:13:19 +0000 Subject: [PATCH] Move the FreeBSD 2.2 and 3.x PCI compatibility code into pci_compat.c and let it depend on COMPAT_OLDPCI. Adjust LINT to accordingly. --- sys/bus/pci/pci.c | 108 ++------------------------------------- sys/bus/pci/pci_compat.c | 103 ++++++++++++++++++++++++++++++++++--- sys/bus/pci/pcireg.h | 15 +++--- sys/bus/pci/pcivar.h | 34 ++++++------ sys/conf/files | 4 +- sys/conf/options | 3 +- sys/config/LINT | 3 +- sys/i386/conf/LINT | 3 +- 8 files changed, 136 insertions(+), 137 deletions(-) diff --git a/sys/bus/pci/pci.c b/sys/bus/pci/pci.c index 61e5d49656..2b98e538db 100644 --- a/sys/bus/pci/pci.c +++ b/sys/bus/pci/pci.c @@ -24,7 +24,7 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD: src/sys/pci/pci.c,v 1.141.2.15 2002/04/30 17:48:18 tmm Exp $ - * $DragonFly: src/sys/bus/pci/pci.c,v 1.6 2003/11/17 00:54:39 asmodai Exp $ + * $DragonFly: src/sys/bus/pci/pci.c,v 1.7 2004/01/07 18:13:19 joerg Exp $ * */ @@ -32,6 +32,7 @@ #include "opt_pci.h" #include "opt_simos.h" +#include "opt_compat_oldpci.h" #include #include @@ -57,9 +58,9 @@ #include #endif +#include #include "pcireg.h" #include "pcivar.h" -#include #ifdef __alpha__ #include @@ -69,6 +70,8 @@ #include #endif /* APIC_IO */ +static devclass_t pci_devclass; + static void pci_read_extcap(pcicfgregs *cfg); struct pci_quirk { @@ -94,13 +97,6 @@ struct pci_quirk pci_quirks[] = { #define PCI_MAPMEMP 0x02 /* prefetchable memory map */ #define PCI_MAPPORT 0x04 /* port map */ -struct pci_devinfo { - STAILQ_ENTRY(pci_devinfo) pci_links; - struct resource_list resources; - pcicfgregs cfg; - struct pci_conf conf; -}; - static STAILQ_HEAD(devlist, pci_devinfo) pci_devq; u_int32_t pci_numdevs = 0; static u_int32_t pci_generation = 0; @@ -1096,100 +1092,6 @@ static struct cdevsw pcicdev = { #include "pci_if.h" -/* - * A simple driver to wrap the old pci driver mechanism for back-compat. - */ - -static int -pci_compat_probe(device_t dev) -{ - struct pci_device *dvp; - struct pci_devinfo *dinfo; - pcicfgregs *cfg; - const char *name; - int error; - - dinfo = device_get_ivars(dev); - cfg = &dinfo->cfg; - dvp = device_get_driver(dev)->priv; - - /* - * Do the wrapped probe. - */ - error = ENXIO; - if (dvp && dvp->pd_probe) { - name = dvp->pd_probe(cfg, (cfg->device << 16) + cfg->vendor); - if (name) { - device_set_desc_copy(dev, name); - /* Allow newbus drivers to match "better" */ - error = -200; - } - } - - return error; -} - -static int -pci_compat_attach(device_t dev) -{ - struct pci_device *dvp; - struct pci_devinfo *dinfo; - pcicfgregs *cfg; - int unit; - - dinfo = device_get_ivars(dev); - cfg = &dinfo->cfg; - dvp = device_get_driver(dev)->priv; - - unit = device_get_unit(dev); - if (unit > *dvp->pd_count) - *dvp->pd_count = unit; - if (dvp->pd_attach) - dvp->pd_attach(cfg, unit); - device_printf(dev, "driver is using old-style compatibility shims\n"); - return 0; -} - -static device_method_t pci_compat_methods[] = { - /* Device interface */ - DEVMETHOD(device_probe, pci_compat_probe), - DEVMETHOD(device_attach, pci_compat_attach), - - { 0, 0 } -}; - -static devclass_t pci_devclass; - -/* - * Create a new style driver around each old pci driver. - */ -int -compat_pci_handler(module_t mod, int type, void *data) -{ - struct pci_device *dvp = (struct pci_device *)data; - driver_t *driver; - - switch (type) { - case MOD_LOAD: - driver = malloc(sizeof(driver_t), M_DEVBUF, M_NOWAIT); - if (!driver) - return ENOMEM; - bzero(driver, sizeof(driver_t)); - driver->name = dvp->pd_name; - driver->methods = pci_compat_methods; - driver->size = sizeof(struct pci_devinfo *); - driver->priv = dvp; - devclass_add_driver(pci_devclass, driver); - break; - case MOD_UNLOAD: - printf("%s: module unload not supported!\n", dvp->pd_name); - return EOPNOTSUPP; - default: - break; - } - return 0; -} - /* * New style pci driver. Parent device is either a pci-host-bridge or a * pci-pci-bridge. Both kinds are represented by instances of pcib. diff --git a/sys/bus/pci/pci_compat.c b/sys/bus/pci/pci_compat.c index 4073666919..8a32155535 100644 --- a/sys/bus/pci/pci_compat.c +++ b/sys/bus/pci/pci_compat.c @@ -24,27 +24,29 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD: src/sys/pci/pci_compat.c,v 1.35.2.1 2001/10/14 21:14:14 luigi Exp $ - * $DragonFly: src/sys/bus/pci/pci_compat.c,v 1.3 2003/08/07 21:16:47 dillon Exp $ + * $DragonFly: src/sys/bus/pci/pci_compat.c,v 1.4 2004/01/07 18:13:19 joerg Exp $ * */ #include "opt_bus.h" -/* for compatibility to FreeBSD-2.2 version of PCI code */ +/* for compatibility to FreeBSD-2.2 and 3.x versions of PCI code */ #include #include #include +#include #include #include -#include #include #include #include #include +#include +#include #include "pcireg.h" #include "pcivar.h" @@ -52,8 +54,6 @@ #include #endif -#ifdef PCI_COMPAT - /* ------------------------------------------------------------------------- */ u_long @@ -232,4 +232,95 @@ pci_get_bus_from_tag(pcici_t tag) return tag->bus; } -#endif /* PCI_COMPAT */ +/* + * A simple driver to wrap the old pci driver mechanism for back-compat. + */ + +static int +pci_compat_probe(device_t dev) +{ + struct pci_device *dvp; + struct pci_devinfo *dinfo; + pcicfgregs *cfg; + const char *name; + int error; + + dinfo = device_get_ivars(dev); + cfg = &dinfo->cfg; + dvp = device_get_driver(dev)->priv; + + /* + * Do the wrapped probe. + */ + error = ENXIO; + if (dvp && dvp->pd_probe) { + name = dvp->pd_probe(cfg, (cfg->device << 16) + cfg->vendor); + if (name) { + device_set_desc_copy(dev, name); + /* Allow newbus drivers to match "better" */ + error = -200; + } + } + + return error; +} + +static int +pci_compat_attach(device_t dev) +{ + struct pci_device *dvp; + struct pci_devinfo *dinfo; + pcicfgregs *cfg; + int unit; + + dinfo = device_get_ivars(dev); + cfg = &dinfo->cfg; + dvp = device_get_driver(dev)->priv; + + unit = device_get_unit(dev); + if (unit > *dvp->pd_count) + *dvp->pd_count = unit; + if (dvp->pd_attach) + dvp->pd_attach(cfg, unit); + device_printf(dev, "driver is using old-style compatability shims\n"); + return 0; +} + +static device_method_t pci_compat_methods[] = { + /* Device interface */ + DEVMETHOD(device_probe, pci_compat_probe), + DEVMETHOD(device_attach, pci_compat_attach), + + { 0, 0 } +}; + +/* + * Create a new style driver around each old pci driver. + */ +int +compat_pci_handler(module_t mod, int type, void *data) +{ + struct pci_device *dvp = (struct pci_device *)data; + driver_t *driver; + devclass_t pci_devclass = devclass_find("pci"); + + switch (type) { + case MOD_LOAD: + driver = malloc(sizeof(driver_t), M_DEVBUF, M_NOWAIT); + if (!driver) + return ENOMEM; + bzero(driver, sizeof(driver_t)); + driver->name = dvp->pd_name; + driver->methods = pci_compat_methods; + driver->size = sizeof(struct pci_devinfo *); + driver->priv = dvp; + devclass_add_driver(pci_devclass, driver); + break; + case MOD_UNLOAD: + printf("%s: module unload not supported!\n", dvp->pd_name); + return EOPNOTSUPP; + default: + break; + } + return 0; +} diff --git a/sys/bus/pci/pcireg.h b/sys/bus/pci/pcireg.h index a949ce17f3..937dc4887b 100644 --- a/sys/bus/pci/pcireg.h +++ b/sys/bus/pci/pcireg.h @@ -1,6 +1,3 @@ -#ifndef PCI_COMPAT -#define PCI_COMPAT -#endif /* * Copyright (c) 1997, Stefan Esser * All rights reserved. @@ -27,7 +24,7 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD: src/sys/pci/pcireg.h,v 1.24.2.5 2002/08/31 10:06:51 gibbs Exp $ - * $DragonFly: src/sys/bus/pci/pcireg.h,v 1.2 2003/06/17 04:28:57 dillon Exp $ + * $DragonFly: src/sys/bus/pci/pcireg.h,v 1.3 2004/01/07 18:13:19 joerg Exp $ * */ @@ -315,9 +312,13 @@ #define PCID_INTEL_SATURN 0x0483 #define PCID_INTEL_ORION 0x84c4 -/* for compatibility to FreeBSD-2.2 version of PCI code */ +/* for compatibility to FreeBSD-2.2 and 3.x versions of PCI code */ + +#if defined(_KERNEL) && !defined(KLD_MODULE) +#include "opt_compat_oldpci.h" +#endif -#ifdef PCI_COMPAT +#ifdef COMPAT_OLDPCI #define PCI_ID_REG 0x00 #define PCI_COMMAND_STATUS_REG 0x04 @@ -338,4 +339,4 @@ #define PCI_MAP_IO 0x00000001 #define PCI_INTERRUPT_REG 0x3c -#endif /* PCI_COMPAT */ +#endif /* COMPAT_OLDPCI */ diff --git a/sys/bus/pci/pcivar.h b/sys/bus/pci/pcivar.h index 9232ab0b9d..96d415dc78 100644 --- a/sys/bus/pci/pcivar.h +++ b/sys/bus/pci/pcivar.h @@ -24,17 +24,13 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD: src/sys/pci/pcivar.h,v 1.41.2.2 2002/01/10 12:08:22 mdodd Exp $ - * $DragonFly: src/sys/bus/pci/pcivar.h,v 1.2 2003/06/17 04:28:57 dillon Exp $ + * $DragonFly: src/sys/bus/pci/pcivar.h,v 1.3 2004/01/07 18:13:19 joerg Exp $ * */ #ifndef _PCIVAR_H_ #define _PCIVAR_H_ -#ifndef PCI_COMPAT -#define PCI_COMPAT -#endif - #include /* some PCI bus constants */ @@ -143,16 +139,17 @@ typedef struct { u_int8_t seclat; /* CardBus latency timer */ } pcih2cfgregs; -/* PCI bus attach definitions (there could be multiple PCI bus *trees* ... */ - -typedef struct pciattach { - int unit; - int pcibushigh; - struct pciattach *next; -} pciattach; - extern u_int32_t pci_numdevs; +/* Only if the prerequisites are present */ +#if defined(_SYS_BUS_H_) && defined(_SYS_PCIIO_H_) +struct pci_devinfo { + STAILQ_ENTRY(pci_devinfo) pci_links; + struct resource_list resources; + pcicfgregs cfg; + struct pci_conf conf; +}; +#endif /* externally visible functions */ @@ -344,9 +341,14 @@ device_t pci_find_bsf(u_int8_t, u_int8_t, u_int8_t); device_t pci_find_device(u_int16_t, u_int16_t); #endif -/* for compatibility to FreeBSD-2.2 version of PCI code */ +/* for compatibility to FreeBSD-2.2 and 3.x versions of PCI code */ + +#if defined(_KERNEL) && !defined(KLD_MODULE) +#include "opt_compat_oldpci.h" +#endif -#ifdef PCI_COMPAT +#ifdef COMPAT_OLDPCI +/* all this is going some day */ typedef pcicfgregs *pcici_t; typedef unsigned pcidi_t; @@ -394,5 +396,5 @@ static moduledata_t name##_mod = { \ DECLARE_MODULE(name, name##_mod, SI_SUB_DRIVERS, SI_ORDER_ANY) -#endif /* PCI_COMPAT */ +#endif /* COMPAT_OLDPCI */ #endif /* _PCIVAR_H_ */ diff --git a/sys/conf/files b/sys/conf/files index 04c8fbb409..94b2c97c86 100644 --- a/sys/conf/files +++ b/sys/conf/files @@ -1,5 +1,5 @@ # $FreeBSD: src/sys/conf/files,v 1.340.2.137 2003/06/04 17:10:30 sam Exp $ -# $DragonFly: src/sys/conf/files,v 1.38 2004/01/06 00:56:49 dillon Exp $ +# $DragonFly: src/sys/conf/files,v 1.39 2004/01/07 18:13:19 joerg Exp $ # # The long compile-with and dependency lines are required because of # limitations in config: backslash-newline doesn't work in strings, and @@ -1103,7 +1103,7 @@ dev/disk/ncr/ncr.c optional ncr dev/disk/sym/sym_hipd.c optional sym \ dependency "$S/dev/disk/sym/sym_{conf,defs}.h" bus/pci/pci.c optional pci -bus/pci/pci_compat.c optional pci +bus/pci/pci_compat.c optional pci compat_oldpci bus/pci/pcisupport.c optional pci bus/pci/pci_if.m optional pci dev/disk/simos/simos.c optional simos diff --git a/sys/conf/options b/sys/conf/options index f3f49ff9a9..2e50f747d4 100644 --- a/sys/conf/options +++ b/sys/conf/options @@ -1,5 +1,5 @@ # $FreeBSD: src/sys/conf/options,v 1.191.2.53 2003/06/04 17:56:58 sam Exp $ -# $DragonFly: src/sys/conf/options,v 1.11 2003/12/02 08:00:22 asmodai Exp $ +# $DragonFly: src/sys/conf/options,v 1.12 2004/01/07 18:13:19 joerg Exp $ # # On the handling of kernel options # @@ -427,6 +427,7 @@ MSGBUF_SIZE opt_msgbuf.h # PCI related options PCI_QUIET opt_pci.h PCI_ENABLE_IO_MODES opt_pci.h +COMPAT_OLDPCI # NFS options NFS_MINATTRTIMO opt_nfs.h diff --git a/sys/config/LINT b/sys/config/LINT index df7039b623..d9a2da22a8 100644 --- a/sys/config/LINT +++ b/sys/config/LINT @@ -3,7 +3,7 @@ # as much of the source tree as it can. # # $FreeBSD: src/sys/i386/conf/LINT,v 1.749.2.144 2003/06/04 17:56:59 sam Exp $ -# $DragonFly: src/sys/config/LINT,v 1.15 2004/01/05 14:07:31 asmodai Exp $ +# $DragonFly: src/sys/config/LINT,v 1.16 2004/01/07 18:13:19 joerg Exp $ # # NB: You probably don't want to try running a kernel built from this # file. Instead, you should start from GENERIC, and add options from @@ -1753,6 +1753,7 @@ device pci #Enable pci resources left off by a "lazy" BIOS: options PCI_ENABLE_IO_MODES #options PCI_QUIET #quiets PCI code on chipset settings +options COMPAT_OLDPCI #FreeBSD 2.2 and 3.x compatibility shims # AGP GART support # diff --git a/sys/i386/conf/LINT b/sys/i386/conf/LINT index ebb0aeb8df..10026faef2 100644 --- a/sys/i386/conf/LINT +++ b/sys/i386/conf/LINT @@ -3,7 +3,7 @@ # as much of the source tree as it can. # # $FreeBSD: src/sys/i386/conf/LINT,v 1.749.2.144 2003/06/04 17:56:59 sam Exp $ -# $DragonFly: src/sys/i386/conf/Attic/LINT,v 1.15 2004/01/05 14:07:31 asmodai Exp $ +# $DragonFly: src/sys/i386/conf/Attic/LINT,v 1.16 2004/01/07 18:13:19 joerg Exp $ # # NB: You probably don't want to try running a kernel built from this # file. Instead, you should start from GENERIC, and add options from @@ -1753,6 +1753,7 @@ device pci #Enable pci resources left off by a "lazy" BIOS: options PCI_ENABLE_IO_MODES #options PCI_QUIET #quiets PCI code on chipset settings +options COMPAT_OLDPCI #FreeBSD 2.2 and 3.x compatibility shims # AGP GART support # -- 2.41.0