Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/dev/pci Update pciverbose module to use module_autoload(...
details: https://anonhg.NetBSD.org/src/rev/7ea657254a05
branches: trunk
changeset: 755459:7ea657254a05
user: pgoyette <pgoyette%NetBSD.org@localhost>
date: Sun Jun 06 18:58:23 2010 +0000
description:
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.
diffstat:
sys/dev/pci/pci.c | 9 +-----
sys/dev/pci/pci_subr.c | 61 +++++++++++++++++++++++++++-------------------
sys/dev/pci/pci_verbose.c | 18 ++++++++++---
sys/dev/pci/pci_verbose.h | 6 ++--
4 files changed, 54 insertions(+), 40 deletions(-)
diffs (210 lines):
diff -r dbca3edccf54 -r 7ea657254a05 sys/dev/pci/pci.c
--- a/sys/dev/pci/pci.c Sun Jun 06 18:58:22 2010 +0000
+++ b/sys/dev/pci/pci.c Sun Jun 06 18:58:23 2010 +0000
@@ -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;
}
diff -r dbca3edccf54 -r 7ea657254a05 sys/dev/pci/pci_subr.c
--- a/sys/dev/pci/pci_subr.c Sun Jun 06 18:58:22 2010 +0000
+++ b/sys/dev/pci/pci_subr.c Sun Jun 06 18:58:23 2010 +0000
@@ -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 (pciverbose_loaded)
+ return;
+
+ mutex_enter(&module_lock);
+ if (module_autoload("pciverbose", MODULE_CLASS_MISC) == 0 )
+ pciverbose_loaded++;
+ mutex_exit(&module_lock);
+}
- if (load) {
- if (loaded++ == 0)
- if (module_load("pciverbose", MODCTL_LOAD_FORCE, NULL,
- MODULE_CLASS_MISC) !=0 )
- loaded = 0;
- return;
- }
- if (loaded == 0)
- return;
- if (--loaded == 0)
- module_unload("pciverbose");
+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
diff -r dbca3edccf54 -r 7ea657254a05 sys/dev/pci/pci_verbose.c
--- a/sys/dev/pci/pci_verbose.c Sun Jun 06 18:58:22 2010 +0000
+++ b/sys/dev/pci/pci_verbose.c Sun Jun 06 18:58:23 2010 +0000
@@ -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;
diff -r dbca3edccf54 -r 7ea657254a05 sys/dev/pci/pci_verbose.h
--- a/sys/dev/pci/pci_verbose.h Sun Jun 06 18:58:22 2010 +0000
+++ b/sys/dev/pci/pci_verbose.h Sun Jun 06 18:58:23 2010 +0000
@@ -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);
Home |
Main Index |
Thread Index |
Old Index