diff --git a/sys/dev/pci/pci.c b/sys/dev/pci/pci.c index d557655ef332..f2b9c6359936 100644 --- a/sys/dev/pci/pci.c +++ b/sys/dev/pci/pci.c @@ -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 -__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 #include -#include #include #include @@ -107,12 +106,8 @@ pcirescan(device_t self, const char *ifattr, const int *locators) 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 --git a/sys/dev/pci/pci_subr.c b/sys/dev/pci/pci_subr.c index 5de2a4cfb0b8..cffe7719d463 100644 --- a/sys/dev/pci/pci_subr.c +++ b/sys/dev/pci/pci_subr.c @@ -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 -__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 @@ __KERNEL_RCSID(0, "$NetBSD: pci_subr.c,v 1.82 2010/05/26 09:42:42 martin Exp $") #include #ifdef _KERNEL #include -#else -const char *pci_null(pcireg_t); #endif /* @@ -295,13 +293,18 @@ static const struct pci_class pci_class[] = { 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_findproduct)(pcireg_t id_reg) = pci_findproduct_real; 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; - 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"); + 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 diff --git a/sys/dev/pci/pci_verbose.c b/sys/dev/pci/pci_verbose.c index 6b74d354e172..dce06050405e 100644 --- a/sys/dev/pci/pci_verbose.c +++ b/sys/dev/pci/pci_verbose.c @@ -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 -__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 @@ -74,16 +74,24 @@ MODULE(MODULE_CLASS_MISC, pciverbose, NULL); 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 --git a/sys/dev/pci/pci_verbose.h b/sys/dev/pci/pci_verbose.h index 7d1b1dd6e4d0..d1ec7558a7fa 100644 --- a/sys/dev/pci/pci_verbose.h +++ b/sys/dev/pci/pci_verbose.h @@ -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 @@ typedef u_int32_t pcireg_t; /* configuration space register XXX */ 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);