Module Name:    src
Committed By:   pgoyette
Date:           Sun Jun  6 18:58:24 UTC 2010

Modified Files:
        src/sys/dev/pci: pci.c pci_subr.c pci_verbose.c pci_verbose.h

Log Message:
Update pciverbose module to use module_autoload() rather than module_load().
Load the module right before each attempt to use its features, and let the
module subsystem handle unloading.


To generate a diff of this commit:
cvs rdiff -u -r1.128 -r1.129 src/sys/dev/pci/pci.c
cvs rdiff -u -r1.82 -r1.83 src/sys/dev/pci/pci_subr.c
cvs rdiff -u -r1.5 -r1.6 src/sys/dev/pci/pci_verbose.c
cvs rdiff -u -r1.2 -r1.3 src/sys/dev/pci/pci_verbose.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/pci/pci.c
diff -u src/sys/dev/pci/pci.c:1.128 src/sys/dev/pci/pci.c:1.129
--- src/sys/dev/pci/pci.c:1.128	Mon May 24 20:29:41 2010
+++ src/sys/dev/pci/pci.c	Sun Jun  6 18:58:23 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: pci.c,v 1.128 2010/05/24 20:29:41 pgoyette Exp $	*/
+/*	$NetBSD: pci.c,v 1.129 2010/06/06 18:58:23 pgoyette Exp $	*/
 
 /*
  * Copyright (c) 1995, 1996, 1997, 1998
@@ -36,13 +36,12 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: pci.c,v 1.128 2010/05/24 20:29:41 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pci.c,v 1.129 2010/06/06 18:58:23 pgoyette Exp $");
 
 #include "opt_pci.h"
 
 #include <sys/param.h>
 #include <sys/malloc.h>
-#include <sys/module.h>
 #include <sys/systm.h>
 #include <sys/device.h>
 
@@ -107,12 +106,8 @@
 	KASSERT(ifattr && !strcmp(ifattr, "pci"));
 	KASSERT(locators);
 
-	pci_verbose_ctl(true);	/* Try to load the pciverbose module */
-
 	pci_enumerate_bus(sc, locators, NULL, NULL);
 
-	pci_verbose_ctl(false);	/* Now try to unload it */
-
 	return 0;
 }
 

Index: src/sys/dev/pci/pci_subr.c
diff -u src/sys/dev/pci/pci_subr.c:1.82 src/sys/dev/pci/pci_subr.c:1.83
--- src/sys/dev/pci/pci_subr.c:1.82	Wed May 26 09:42:42 2010
+++ src/sys/dev/pci/pci_subr.c	Sun Jun  6 18:58:23 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: pci_subr.c,v 1.82 2010/05/26 09:42:42 martin Exp $	*/
+/*	$NetBSD: pci_subr.c,v 1.83 2010/06/06 18:58:23 pgoyette Exp $	*/
 
 /*
  * Copyright (c) 1997 Zubin D. Dittia.  All rights reserved.
@@ -40,7 +40,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: pci_subr.c,v 1.82 2010/05/26 09:42:42 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pci_subr.c,v 1.83 2010/06/06 18:58:23 pgoyette Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_pci.h"
@@ -61,8 +61,6 @@
 #include <dev/pci/pcireg.h>
 #ifdef _KERNEL
 #include <dev/pci/pcivar.h>
-#else
-const char *pci_null(pcireg_t);
 #endif
 
 /*
@@ -295,13 +293,18 @@
 	    NULL,						},
 };
 
+void pci_load_verbose(void);
+
 #if defined(_KERNEL)
 /*
  * In kernel, these routines are provided and linked via the
  * pciverbose module.
  */
-const char *(*pci_findvendor)(pcireg_t id_reg) = pci_null;
-const char *(*pci_findproduct)(pcireg_t id_reg) = pci_null;
+const char *pci_findvendor_stub(pcireg_t);
+const char *pci_findproduct_stub(pcireg_t);
+
+const char *(*pci_findvendor)(pcireg_t) = pci_findvendor_stub;
+const char *(*pci_findproduct)(pcireg_t) = pci_findproduct_stub;
 const char *pci_unmatched = "";
 #else
 /*
@@ -312,31 +315,39 @@
 const char *pci_unmatched = "unmatched ";
 #endif
 
-const char *
-pci_null(pcireg_t id_reg)
-{
-	return (NULL);
-}
+int pciverbose_loaded = 0;
 
 #if defined(_KERNEL)
 /*
- * Routine to load/unload the pciverbose kernel module as needed
+ * Routine to load the pciverbose kernel module as needed
  */
-void pci_verbose_ctl(bool load)
+void pci_load_verbose(void)
 {
-	static int loaded = 0;
-
-	if (load) {
-		if (loaded++ == 0)
-			if (module_load("pciverbose", MODCTL_LOAD_FORCE, NULL,
-				    MODULE_CLASS_MISC) !=0 )
-				loaded = 0;
-		return;
-	}
-	if (loaded == 0)
+	if (pciverbose_loaded)
 		return;
-	if (--loaded == 0)
-		module_unload("pciverbose");
+
+	mutex_enter(&module_lock);
+	if (module_autoload("pciverbose", MODULE_CLASS_MISC) == 0 )
+		pciverbose_loaded++;
+	mutex_exit(&module_lock);
+}
+
+const char *pci_findvendor_stub(pcireg_t id_reg)
+{
+	pci_load_verbose();
+	if (pciverbose_loaded)
+		return pci_findvendor(id_reg);
+	else
+		return NULL;
+}
+
+const char *pci_findproduct_stub(pcireg_t id_reg)
+{
+	pci_load_verbose();
+	if (pciverbose_loaded)
+		return pci_findproduct(id_reg);
+	else
+		return NULL;
 }
 #endif
 

Index: src/sys/dev/pci/pci_verbose.c
diff -u src/sys/dev/pci/pci_verbose.c:1.5 src/sys/dev/pci/pci_verbose.c:1.6
--- src/sys/dev/pci/pci_verbose.c:1.5	Fri May 28 02:38:41 2010
+++ src/sys/dev/pci/pci_verbose.c	Sun Jun  6 18:58:24 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: pci_verbose.c,v 1.5 2010/05/28 02:38:41 pgoyette Exp $	*/
+/*	$NetBSD: pci_verbose.c,v 1.6 2010/06/06 18:58:24 pgoyette Exp $	*/
 
 /*
  * Copyright (c) 1997 Zubin D. Dittia.  All rights reserved.
@@ -40,7 +40,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: pci_verbose.c,v 1.5 2010/05/28 02:38:41 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pci_verbose.c,v 1.6 2010/06/06 18:58:24 pgoyette Exp $");
 
 #include <sys/param.h>
 
@@ -74,16 +74,24 @@
 static int
 pciverbose_modcmd(modcmd_t cmd, void *arg)
 {
+	static const char *(*saved_findvendor)(pcireg_t);
+	static const char *(*saved_findproduct)(pcireg_t);
+	static const char *saved_unmatched;
+
 	switch (cmd) {
 	case MODULE_CMD_INIT:
+		saved_findvendor = pci_findvendor;
+		saved_findproduct = pci_findproduct;
+		saved_unmatched = pci_unmatched;
 		pci_findvendor = pci_findvendor_real;
 		pci_findproduct = pci_findproduct_real;
 		pci_unmatched = "unmatched ";
 		return 0;
 	case MODULE_CMD_FINI:
-		pci_findvendor = pci_null;
-		pci_findproduct = pci_null;
-		pci_unmatched = "";
+		pci_findvendor = saved_findvendor;
+		pci_findproduct = saved_findproduct;
+		pci_unmatched = saved_unmatched;
+		pciverbose_loaded = 0;
 		return 0;
 	default:
 		return ENOTTY;

Index: src/sys/dev/pci/pci_verbose.h
diff -u src/sys/dev/pci/pci_verbose.h:1.2 src/sys/dev/pci/pci_verbose.h:1.3
--- src/sys/dev/pci/pci_verbose.h:1.2	Fri May 28 02:24:27 2010
+++ src/sys/dev/pci/pci_verbose.h	Sun Jun  6 18:58:24 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: pci_verbose.h,v 1.2 2010/05/28 02:24:27 pgoyette Exp $ */
+/*	$NetBSD: pci_verbose.h,v 1.3 2010/06/06 18:58:24 pgoyette Exp $ */
 
 /*
  * Copyright (c) 1996, 1997 Christopher G. Demetriou.  All rights reserved.
@@ -40,8 +40,8 @@
 
 const char *pci_findvendor_real(pcireg_t);
 const char *pci_findproduct_real(pcireg_t);
-const char *pci_null(pcireg_t);
-void pci_verbose_ctl(bool);
+
+extern int pciverbose_loaded;
 
 extern const char *(*pci_findvendor)(pcireg_t);
 extern const char *(*pci_findproduct)(pcireg_t);

Reply via email to