Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/dev/acpi Add hw.acpi.power sysctl-node.
details: https://anonhg.NetBSD.org/src/rev/92dbe0bdb9a3
branches: trunk
changeset: 754209:92dbe0bdb9a3
user: jruoho <jruoho%NetBSD.org@localhost>
date: Fri Apr 23 18:51:31 2010 +0000
description:
Add hw.acpi.power sysctl-node.
diffstat:
sys/dev/acpi/acpi.c | 6 +-
sys/dev/acpi/acpi_power.c | 92 +++++++++++++++++++++++++++++++++++++++++++++-
sys/dev/acpi/acpi_power.h | 3 +-
3 files changed, 95 insertions(+), 6 deletions(-)
diffs (174 lines):
diff -r dd109c592ad5 -r 92dbe0bdb9a3 sys/dev/acpi/acpi.c
--- a/sys/dev/acpi/acpi.c Fri Apr 23 17:48:06 2010 +0000
+++ b/sys/dev/acpi/acpi.c Fri Apr 23 18:51:31 2010 +0000
@@ -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);
}
/*
diff -r dd109c592ad5 -r 92dbe0bdb9a3 sys/dev/acpi/acpi_power.c
--- a/sys/dev/acpi/acpi_power.c Fri Apr 23 17:48:06 2010 +0000
+++ b/sys/dev/acpi/acpi_power.c Fri Apr 23 18:51:31 2010 +0000
@@ -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.
diff -r dd109c592ad5 -r 92dbe0bdb9a3 sys/dev/acpi/acpi_power.h
--- a/sys/dev/acpi/acpi_power.h Fri Apr 23 17:48:06 2010 +0000
+++ b/sys/dev/acpi/acpi_power.h Fri Apr 23 18:51:31 2010 +0000
@@ -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 */
- Prev by Date:
[src/trunk]: src/share/misc + JBOD, NAS, OQL, OWL, RDF, SPARQL, TOS (type of ...
- Next by Date:
[src/trunk]: src/share/misc + B/W for bandwidth, ATM and PIN, TBA
- Previous by Thread:
[src/trunk]: src/share/misc + JBOD, NAS, OQL, OWL, RDF, SPARQL, TOS (type of ...
- Next by Thread:
[src/trunk]: src/share/misc + B/W for bandwidth, ATM and PIN, TBA
- Indexes:
Home |
Main Index |
Thread Index |
Old Index