Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/dev/acpi Update acpiverbose module to use module_autoloa...
details: https://anonhg.NetBSD.org/src/rev/ed409bfa090f
branches: trunk
changeset: 755472:ed409bfa090f
user: pgoyette <pgoyette%NetBSD.org@localhost>
date: Mon Jun 07 01:45:27 2010 +0000
description:
Update acpiverbose 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/acpi/acpi.c | 71 +++++++++++++++++++++++++++++---------------
sys/dev/acpi/acpi_verbose.c | 22 ++++++++++---
sys/dev/acpi/acpivar.h | 6 +++-
3 files changed, 68 insertions(+), 31 deletions(-)
diffs (190 lines):
diff -r 9b73a44ce7bb -r ed409bfa090f sys/dev/acpi/acpi.c
--- a/sys/dev/acpi/acpi.c Mon Jun 07 01:41:39 2010 +0000
+++ b/sys/dev/acpi/acpi.c Mon Jun 07 01:45:27 2010 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: acpi.c,v 1.199 2010/06/06 10:44:40 jruoho Exp $ */
+/* $NetBSD: acpi.c,v 1.200 2010/06/07 01:45:27 pgoyette Exp $ */
/*-
* Copyright (c) 2003, 2007 The NetBSD Foundation, Inc.
@@ -65,7 +65,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: acpi.c,v 1.199 2010/06/06 10:44:40 jruoho Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi.c,v 1.200 2010/06/07 01:45:27 pgoyette Exp $");
#include "opt_acpi.h"
#include "opt_pcifixup.h"
@@ -203,13 +203,19 @@
extern struct cfdriver acpi_cd;
/* Handle routine vectors and loading for acpiverbose module */
-void acpi_verbose_ctl(bool load);
void acpi_null(void);
-void (*acpi_print_devnodes)(struct acpi_softc *) = (void *)acpi_null;
-void (*acpi_print_tree)(struct acpi_devnode *, uint32_t) = (void *)acpi_null;
-void (*acpi_print_dev)(const char *) = (void *)acpi_null;
-void (*acpi_wmidump)(void *) = (void *)acpi_null;
+void acpi_print_devnodes_stub(struct acpi_softc *);
+void acpi_print_tree_stub(struct acpi_devnode *, uint32_t);
+void acpi_print_dev_stub(const char *);
+void acpi_wmidump_stub(void *);
+
+void (*acpi_print_devnodes)(struct acpi_softc *) = acpi_print_devnodes_stub;
+void (*acpi_print_tree)(struct acpi_devnode *, uint32_t) = acpi_print_tree_stub;
+void (*acpi_print_dev)(const char *) = acpi_print_dev_stub;
+void (*acpi_wmidump)(void *) = acpi_wmidump_stub;
+
+int acpi_verbose_loaded = 0;
/* acpiverbose support */
void
@@ -219,23 +225,44 @@
}
void
-acpi_verbose_ctl(bool load)
+acpi_load_verbose(void)
{
- static int loaded = 0;
+ if (acpi_verbose_loaded)
+ return;
- if (load) {
- if (loaded++ == 0)
- if (module_load("acpiverbose", MODCTL_LOAD_FORCE,
- NULL, MODULE_CLASS_MISC) != 0)
- loaded = 0;
- return;
- }
- if (loaded == 0)
- return;
- if (--loaded == 0)
- module_unload("acpiverbose");
+ mutex_enter(&module_lock);
+ if (module_autoload("acpiverbose", MODULE_CLASS_MISC) == 0)
+ acpi_verbose_loaded++;
+ mutex_exit(&module_lock);
+}
+
+void acpi_print_devnodes_stub(struct acpi_softc *sc)
+{
+ acpi_load_verbose();
+ if (acpi_verbose_loaded)
+ acpi_print_devnodes(sc);
}
+void acpi_print_tree_stub(struct acpi_devnode *ad, uint32_t level)
+{
+ acpi_load_verbose();
+ if (acpi_verbose_loaded)
+ acpi_print_tree(ad, level);
+}
+
+void acpi_print_dev_stub(const char *pnpstr)
+{
+ acpi_load_verbose();
+ if (acpi_verbose_loaded)
+ acpi_print_dev(pnpstr);
+}
+
+void acpi_wmidump_stub(void *arg)
+{
+ acpi_load_verbose();
+ if (acpi_verbose_loaded)
+ acpi_wmidump(arg);
+}
CFATTACH_DECL2_NEW(acpi, sizeof(struct acpi_softc),
acpi_match, acpi_attach, acpi_detach, NULL, acpi_rescan, acpi_childdet);
@@ -401,8 +428,6 @@
if (acpi_softc != NULL)
panic("%s: already attached", __func__);
- acpi_verbose_ctl(true);
-
rsdt = acpi_map_rsdt();
if (rsdt == NULL)
@@ -567,8 +592,6 @@
acpi_softc = NULL;
- acpi_verbose_ctl(false);
-
return 0;
}
diff -r 9b73a44ce7bb -r ed409bfa090f sys/dev/acpi/acpi_verbose.c
--- a/sys/dev/acpi/acpi_verbose.c Mon Jun 07 01:41:39 2010 +0000
+++ b/sys/dev/acpi/acpi_verbose.c Mon Jun 07 01:45:27 2010 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: acpi_verbose.c,v 1.2 2010/06/05 06:07:12 jruoho Exp $ */
+/* $NetBSD: acpi_verbose.c,v 1.3 2010/06/07 01:45:27 pgoyette Exp $ */
/*-
* Copyright (c) 2003, 2007 The NetBSD Foundation, Inc.
@@ -65,7 +65,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: acpi_verbose.c,v 1.2 2010/06/05 06:07:12 jruoho Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_verbose.c,v 1.3 2010/06/07 01:45:27 pgoyette Exp $");
#include <sys/param.h>
#include <sys/device.h>
@@ -88,18 +88,28 @@
static int
acpiverbose_modcmd(modcmd_t cmd, void *arg)
{
+ static void (*saved_print_devnodes)(struct acpi_softc *);
+ static void (*saved_print_tree)(struct acpi_devnode *, uint32_t);
+ static void (*saved_print_dev)(const char *);
+ static void (*saved_wmidump)(void *);
+
switch (cmd) {
case MODULE_CMD_INIT:
+ saved_print_devnodes = acpi_print_devnodes;
+ saved_print_tree = acpi_print_tree;
+ saved_print_dev = acpi_print_dev;
+ saved_wmidump = acpi_wmidump;
acpi_print_devnodes = acpi_print_devnodes_real;
acpi_print_tree = acpi_print_tree_real;
acpi_print_dev = acpi_print_dev_real;
acpi_wmidump = acpi_wmidump_real;
return 0;
case MODULE_CMD_FINI:
- acpi_print_devnodes = (void *)acpi_null;
- acpi_print_tree = (void *)acpi_null;
- acpi_print_dev = (void *)acpi_null;
- acpi_wmidump = (void *)acpi_null;
+ acpi_print_devnodes = saved_print_devnodes;
+ acpi_print_tree = saved_print_tree;
+ acpi_print_dev = saved_print_dev;
+ acpi_wmidump = saved_wmidump;
+ acpi_verbose_loaded = 0;
return 0;
default:
return ENOTTY;
diff -r 9b73a44ce7bb -r ed409bfa090f sys/dev/acpi/acpivar.h
--- a/sys/dev/acpi/acpivar.h Mon Jun 07 01:41:39 2010 +0000
+++ b/sys/dev/acpi/acpivar.h Mon Jun 07 01:45:27 2010 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: acpivar.h,v 1.55 2010/06/05 06:07:12 jruoho Exp $ */
+/* $NetBSD: acpivar.h,v 1.56 2010/06/07 01:45:27 pgoyette Exp $ */
/*
* Copyright 2001 Wasabi Systems, Inc.
@@ -326,6 +326,10 @@
extern void (*acpi_wmidump)(void *);
void acpi_wmidump_real(void *);
+
void acpi_null(void);
+void acpi_load_verbose(void);
+extern int acpi_verbose_loaded;
+
#endif /* !_SYS_DEV_ACPI_ACPIVAR_H */
Home |
Main Index |
Thread Index |
Old Index