summaryrefslogtreecommitdiff
path: root/sys/dev
diff options
context:
space:
mode:
authorjruoho <jruoho@NetBSD.org>2010-04-23 18:51:31 +0000
committerjruoho <jruoho@NetBSD.org>2010-04-23 18:51:31 +0000
commit16bdc3ff0f1a0d01636b585b0ad7fa94b0bc2ff6 (patch)
tree344f0c44bff16e37fda556b0e251b524ccd9ea13 /sys/dev
parent4e32f54f3c9e57d8a28ee0cfa40bc806dd87ec70 (diff)
Add hw.acpi.power sysctl-node.
Diffstat (limited to 'sys/dev')
-rw-r--r--sys/dev/acpi/acpi.c6
-rw-r--r--sys/dev/acpi/acpi_power.c92
-rw-r--r--sys/dev/acpi/acpi_power.h3
3 files changed, 95 insertions, 6 deletions
diff --git a/sys/dev/acpi/acpi.c b/sys/dev/acpi/acpi.c
index 97e76ab077c..c4fa6ba3e1b 100644
--- a/sys/dev/acpi/acpi.c
+++ b/sys/dev/acpi/acpi.c
@@ -1,4 +1,4 @@
-/* $NetBSD: acpi.c,v 1.183 2010/04/23 07:04:18 jruoho Exp $ */
+/* $NetBSD: acpi.c,v 1.184 2010/04/23 18:51:31 jruoho 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.183 2010/04/23 07:04:18 jruoho Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi.c,v 1.184 2010/04/23 18:51:31 jruoho Exp $");
#include "opt_acpi.h"
#include "opt_pcifixup.h"
@@ -1056,7 +1056,7 @@ acpi_rescan_capabilities(struct acpi_softc *sc)
if (ACPI_SUCCESS(rv)) {
ad->ad_flags |= ACPI_DEVICE_POWER;
- (void)acpi_power_get(ad, NULL);
+ acpi_power_add(ad);
}
/*
diff --git a/sys/dev/acpi/acpi_power.c b/sys/dev/acpi/acpi_power.c
index f40245a218a..950e754c6d0 100644
--- a/sys/dev/acpi/acpi_power.c
+++ b/sys/dev/acpi/acpi_power.c
@@ -1,4 +1,4 @@
-/* $NetBSD: acpi_power.c,v 1.3 2010/04/23 15:37:01 jruoho Exp $ */
+/* $NetBSD: acpi_power.c,v 1.4 2010/04/23 18:51:31 jruoho Exp $ */
/*-
* Copyright (c) 2009, 2010 The NetBSD Foundation, Inc.
@@ -56,11 +56,12 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: acpi_power.c,v 1.3 2010/04/23 15:37:01 jruoho Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_power.c,v 1.4 2010/04/23 18:51:31 jruoho Exp $");
#include <sys/param.h>
#include <sys/kmem.h>
#include <sys/mutex.h>
+#include <sys/sysctl.h>
#include <dev/acpi/acpireg.h>
#include <dev/acpi/acpivar.h>
@@ -95,6 +96,8 @@ struct acpi_power_res {
static TAILQ_HEAD(, acpi_power_res) res_head =
TAILQ_HEAD_INITIALIZER(res_head);
+static const struct sysctlnode *anode = NULL;
+
static struct acpi_power_res *acpi_power_res_init(ACPI_HANDLE);
static struct acpi_power_res *acpi_power_res_get(ACPI_HANDLE);
@@ -114,6 +117,7 @@ static ACPI_STATUS acpi_power_res_deref(struct acpi_power_res *,
static ACPI_STATUS acpi_power_res_sta(ACPI_OBJECT *, void *);
static ACPI_OBJECT *acpi_power_pkg_get(ACPI_HANDLE, int);
+static int acpi_power_sysctl(SYSCTLFN_ARGS);
static const char *acpi_xname(ACPI_HANDLE);
void
@@ -701,6 +705,90 @@ fail:
return NULL;
}
+SYSCTL_SETUP(sysctl_acpi_power_setup, "sysctl hw.acpi.power subtree setup")
+{
+ int err;
+
+ err = sysctl_createv(NULL, 0, NULL, &anode,
+ CTLFLAG_PERMANENT, CTLTYPE_NODE, "hw",
+ NULL, NULL, 0, NULL, 0,
+ CTL_HW, CTL_EOL);
+
+ if (err != 0)
+ goto fail;
+
+ err = sysctl_createv(NULL, 0, &anode, &anode,
+ CTLFLAG_PERMANENT, CTLTYPE_NODE, "acpi",
+ NULL, NULL, 0, NULL, 0,
+ CTL_CREATE, CTL_EOL);
+
+ if (err != 0)
+ goto fail;
+
+ err = sysctl_createv(NULL, 0, &anode, &anode,
+ CTLFLAG_PERMANENT, CTLTYPE_NODE,
+ "power", SYSCTL_DESCR("ACPI device power states"),
+ NULL, 0, NULL, 0,
+ CTL_CREATE, CTL_EOL);
+
+ if (err != 0)
+ goto fail;
+
+ return;
+
+fail:
+ anode = NULL;
+}
+
+void
+acpi_power_add(struct acpi_devnode *ad)
+{
+ int err;
+
+ KASSERT(ad != NULL && ad->ad_root != NULL);
+ KASSERT((ad->ad_flags & ACPI_DEVICE_POWER) != 0);
+
+ if (anode == NULL)
+ return;
+
+ /*
+ * Make this read-only: because a single power resource
+ * may power multiple devices, it is unclear whether
+ * power resources should be controllable by an user.
+ */
+ err = sysctl_createv(NULL, 0, &anode, NULL,
+ CTLFLAG_READONLY, CTLTYPE_STRING, ad->ad_name,
+ NULL, acpi_power_sysctl, 0, &ad->ad_state, 0,
+ CTL_CREATE, CTL_EOL);
+
+ if (err != 0)
+ aprint_error_dev(ad->ad_root, "sysctl_createv"
+ "(hw.acpi.power.%s) failed (err %d)\n", ad->ad_name, err);
+}
+
+static int
+acpi_power_sysctl(SYSCTLFN_ARGS)
+{
+ struct sysctlnode node;
+ int err, state;
+ char t[3];
+
+ node = *rnode;
+ state = *(int *)rnode->sysctl_data;
+
+ (void)memset(t, '\0', sizeof(t));
+ (void)snprintf(t, sizeof(t), "D%d", state);
+
+ node.sysctl_data = &t;
+
+ err = sysctl_lookup(SYSCTLFN_CALL(&node));
+
+ if (err || newp == NULL)
+ return err;
+
+ return 0;
+}
+
/*
* XXX: Move this to acpi_util.c by refactoring
* acpi_name() to optionally return a single name.
diff --git a/sys/dev/acpi/acpi_power.h b/sys/dev/acpi/acpi_power.h
index a0495e7aadb..8e7ae65e21b 100644
--- a/sys/dev/acpi/acpi_power.h
+++ b/sys/dev/acpi/acpi_power.h
@@ -1,4 +1,4 @@
-/* $NetBSD: acpi_power.h,v 1.1 2010/04/22 18:40:09 jruoho Exp $ */
+/* $NetBSD: acpi_power.h,v 1.2 2010/04/23 18:51:31 jruoho Exp $ */
/*-
* Copyright (c) 2009, 2010 The NetBSD Foundation, Inc.
@@ -40,5 +40,6 @@ void acpi_power_deregister(struct acpi_devnode *);
bool acpi_power_get(struct acpi_devnode *, int *);
bool acpi_power_set(struct acpi_devnode *, int);
bool acpi_power_set_from_handle(ACPI_HANDLE, int);
+void acpi_power_add(struct acpi_devnode *);
#endif /* !_SYS_DEV_ACPI_ACPI_POWER_H */