Module Name: src
Committed By: jruoho
Date: Fri Apr 23 18:51:31 UTC 2010
Modified Files:
src/sys/dev/acpi: acpi.c acpi_power.c acpi_power.h
Log Message:
Add hw.acpi.power sysctl-node.
To generate a diff of this commit:
cvs rdiff -u -r1.183 -r1.184 src/sys/dev/acpi/acpi.c
cvs rdiff -u -r1.3 -r1.4 src/sys/dev/acpi/acpi_power.c
cvs rdiff -u -r1.1 -r1.2 src/sys/dev/acpi/acpi_power.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/acpi/acpi.c
diff -u src/sys/dev/acpi/acpi.c:1.183 src/sys/dev/acpi/acpi.c:1.184
--- src/sys/dev/acpi/acpi.c:1.183 Fri Apr 23 07:04:18 2010
+++ src/sys/dev/acpi/acpi.c Fri Apr 23 18:51:31 2010
@@ -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 @@
if (ACPI_SUCCESS(rv)) {
ad->ad_flags |= ACPI_DEVICE_POWER;
- (void)acpi_power_get(ad, NULL);
+ acpi_power_add(ad);
}
/*
Index: src/sys/dev/acpi/acpi_power.c
diff -u src/sys/dev/acpi/acpi_power.c:1.3 src/sys/dev/acpi/acpi_power.c:1.4
--- src/sys/dev/acpi/acpi_power.c:1.3 Fri Apr 23 15:37:01 2010
+++ src/sys/dev/acpi/acpi_power.c Fri Apr 23 18:51:31 2010
@@ -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 @@
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_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 @@
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.
Index: src/sys/dev/acpi/acpi_power.h
diff -u src/sys/dev/acpi/acpi_power.h:1.1 src/sys/dev/acpi/acpi_power.h:1.2
--- src/sys/dev/acpi/acpi_power.h:1.1 Thu Apr 22 18:40:09 2010
+++ src/sys/dev/acpi/acpi_power.h Fri Apr 23 18:51:31 2010
@@ -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 @@
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 */