PCI cleanup, part 2

Joerg Sonnenberger joerg at britannica.bec.de
Thu Dec 18 01:40:27 PST 2003


Attached patch moves the compatibility code from pci.c into
pci_compat.c and adds a new option COMPAT_OLDPCI for the
inclusion of the FreeBSD 2.2/3.x PCI compatibility layer.
It is not active by default and config will issue a warning
if you use. I'm interested of anybody using one of the drivers
needing this option. This option is in LINT, since a few drivers
depends on it.

Joerg
Index: bus/pci/pci.c
===================================================================
RCS file: /home/repository/dragonflybsd/src/sys/bus/pci/pci.c,v
retrieving revision 1.6
diff -u -r1.6 pci.c
--- bus/pci/pci.c	17 Nov 2003 00:54:39 -0000	1.6
+++ bus/pci/pci.c	18 Dec 2003 00:09:20 -0000
@@ -32,6 +32,7 @@
 #include "opt_pci.h"
 
 #include "opt_simos.h"
+#include "opt_compat_oldpci.h"
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -57,9 +58,9 @@
 #include <machine/pci_cfgreg.h>
 #endif
 
+#include <sys/pciio.h>
 #include "pcireg.h"
 #include "pcivar.h"
-#include <sys/pciio.h>
 
 #ifdef __alpha__
 #include <machine/rpb.h>
@@ -69,6 +70,8 @@
 #include <machine/smp.h>
 #endif /* APIC_IO */
 
+static devclass_t	pci_devclass;
+
 static void		pci_read_extcap(pcicfgregs *cfg);
 
 struct pci_quirk {
@@ -94,13 +97,6 @@
 #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;
@@ -1095,100 +1091,6 @@
 };
 
 #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
Index: bus/pci/pci_compat.c
===================================================================
RCS file: /home/repository/dragonflybsd/src/sys/bus/pci/pci_compat.c,v
retrieving revision 1.3
diff -u -r1.3 pci_compat.c
--- bus/pci/pci_compat.c	7 Aug 2003 21:16:47 -0000	1.3
+++ bus/pci/pci_compat.c	17 Dec 2003 23:45:54 -0000
@@ -30,21 +30,23 @@
 
 #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 <sys/param.h>
 #include <sys/systm.h>
 #include <sys/malloc.h>
+#include <sys/module.h>
 
 #include <vm/vm.h>
 #include <vm/pmap.h>
-#include <sys/interrupt.h>
 
 #include <sys/bus.h>
 #include <machine/bus.h>
 #include <sys/rman.h>
 #include <machine/resource.h>
+#include <sys/interrupt.h>
 
+#include <sys/pciio.h>
 #include "pcireg.h"
 #include "pcivar.h"
 
@@ -52,8 +54,6 @@
 #include <machine/smp.h>
 #endif
 
-#ifdef PCI_COMPAT
-
 /* ------------------------------------------------------------------------- */
 
 u_long
@@ -232,4 +232,95 @@
 	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;
+}
Index: bus/pci/pcireg.h
===================================================================
RCS file: /home/repository/dragonflybsd/src/sys/bus/pci/pcireg.h,v
retrieving revision 1.2
diff -u -r1.2 pcireg.h
--- bus/pci/pcireg.h	17 Jun 2003 04:28:57 -0000	1.2
+++ bus/pci/pcireg.h	18 Dec 2003 00:00:32 -0000
@@ -1,6 +1,3 @@
-#ifndef PCI_COMPAT
-#define PCI_COMPAT
-#endif
 /*
  * Copyright (c) 1997, Stefan Esser <se at xxxxxxxxxxx>
  * All rights reserved.
@@ -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 */
Index: bus/pci/pcivar.h
===================================================================
RCS file: /home/repository/dragonflybsd/src/sys/bus/pci/pcivar.h,v
retrieving revision 1.2
diff -u -r1.2 pcivar.h
--- bus/pci/pcivar.h	17 Jun 2003 04:28:57 -0000	1.2
+++ bus/pci/pcivar.h	18 Dec 2003 00:07:14 -0000
@@ -31,10 +31,6 @@
 #ifndef _PCIVAR_H_
 #define _PCIVAR_H_
 
-#ifndef PCI_COMPAT
-#define PCI_COMPAT
-#endif
-
 #include <sys/queue.h>
 
 /* some PCI bus constants */
@@ -143,16 +139,17 @@
     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_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 @@
 DECLARE_MODULE(name, name##_mod, SI_SUB_DRIVERS, SI_ORDER_ANY)
 
 
-#endif /* PCI_COMPAT */
+#endif /* COMPAT_OLDPCI */
 #endif /* _PCIVAR_H_ */
Index: conf/files
===================================================================
RCS file: /home/repository/dragonflybsd/src/sys/conf/files,v
retrieving revision 1.36
diff -u -r1.36 files
--- conf/files	10 Dec 2003 23:48:07 -0000	1.36
+++ conf/files	17 Dec 2003 23:29:49 -0000
@@ -1102,7 +1102,8 @@
 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 \
+	warning	"Old PCI driver compatability shims present."
 bus/pci/pcisupport.c		optional pci
 bus/pci/pci_if.m		optional pci
 dev/disk/simos/simos.c		optional simos
Index: conf/options
===================================================================
RCS file: /home/repository/dragonflybsd/src/sys/conf/options,v
retrieving revision 1.11
diff -u -r1.11 options
--- conf/options	2 Dec 2003 08:00:22 -0000	1.11
+++ conf/options	17 Dec 2003 23:30:16 -0000
@@ -427,6 +427,7 @@
 # PCI related options
 PCI_QUIET		opt_pci.h
 PCI_ENABLE_IO_MODES	opt_pci.h
+COMPAT_OLDPCI
 
 # NFS options
 NFS_MINATTRTIMO		opt_nfs.h
Index: i386/conf/LINT
===================================================================
RCS file: /home/repository/dragonflybsd/src/sys/i386/conf/LINT,v
retrieving revision 1.13
diff -u -r1.13 LINT
--- i386/conf/LINT	2 Dec 2003 08:00:22 -0000	1.13
+++ i386/conf/LINT	17 Dec 2003 23:49:32 -0000
@@ -1760,6 +1760,7 @@
 #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
 #




More information about the Submit mailing list