Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/dev/acpi With the intent of making 'struct acpi_devnode'...
details: https://anonhg.NetBSD.org/src/rev/d59cee94f7e8
branches: trunk
changeset: 753117:d59cee94f7e8
user: jruoho <jruoho%NetBSD.org@localhost>
date: Tue Mar 16 05:48:42 2010 +0000
description:
With the intent of making 'struct acpi_devnode' as the central place for
information related to ACPI device nodes: (a) introduce a generic scan
function for ACPI device driver "capabilities", and (b) eliminate local data
structures from ACPI wake-devices. Discussed with jmcneill@.
diffstat:
sys/dev/acpi/acpi.c | 73 +++++++++++++++++++++-
sys/dev/acpi/acpi_wakedev.c | 141 ++++++++++---------------------------------
sys/dev/acpi/acpi_wakedev.h | 4 +-
sys/dev/acpi/acpivar.h | 20 +++++-
4 files changed, 124 insertions(+), 114 deletions(-)
diffs (truncated from 376 to 300 lines):
diff -r 681797770259 -r d59cee94f7e8 sys/dev/acpi/acpi.c
--- a/sys/dev/acpi/acpi.c Tue Mar 16 04:14:29 2010 +0000
+++ b/sys/dev/acpi/acpi.c Tue Mar 16 05:48:42 2010 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: acpi.c,v 1.159 2010/03/10 09:42:46 jruoho Exp $ */
+/* $NetBSD: acpi.c,v 1.160 2010/03/16 05:48:42 jruoho Exp $ */
/*-
* Copyright (c) 2003, 2007 The NetBSD Foundation, Inc.
@@ -70,7 +70,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: acpi.c,v 1.159 2010/03/10 09:42:46 jruoho Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi.c,v 1.160 2010/03/16 05:48:42 jruoho Exp $");
#include "opt_acpi.h"
#include "opt_pcifixup.h"
@@ -129,6 +129,7 @@
static int acpi_rescan(device_t, const char *, const int *);
static void acpi_rescan1(struct acpi_softc *, const char *, const int *);
static void acpi_rescan_nodes(struct acpi_softc *);
+static void acpi_rescan_capabilities(struct acpi_softc *);
static int acpi_print(void *aux, const char *);
@@ -697,7 +698,8 @@
}
acpi_rescan1(sc, NULL, NULL);
- acpi_wakedev_scan(sc);
+ acpi_rescan_capabilities(sc);
+
acpi_pcidev_scan(sc);
}
@@ -790,6 +792,71 @@
}
}
+#define ACPI_STA_DEV_VALID \
+ (ACPI_STA_DEV_PRESENT | ACPI_STA_DEV_ENABLED | ACPI_STA_DEV_OK)
+
+/*
+ * acpi_rescan_capabilities:
+ *
+ * Scan device capabilities.
+ */
+static void
+acpi_rescan_capabilities(struct acpi_softc *sc)
+{
+ struct acpi_devnode *ad;
+ ACPI_DEVICE_INFO *di;
+ ACPI_HANDLE tmp;
+ ACPI_STATUS rv;
+
+ SIMPLEQ_FOREACH(ad, &sc->sc_devnodes, ad_list) {
+
+ di = ad->ad_devinfo;
+
+ if (di->Type != ACPI_TYPE_DEVICE)
+ continue;
+
+ if ((di->Valid & ACPI_VALID_STA) != 0 &&
+ (di->CurrentStatus & ACPI_STA_DEV_VALID) !=
+ ACPI_STA_DEV_VALID)
+ continue;
+
+ /*
+ * Scan power resource capabilities.
+ */
+ rv = AcpiGetHandle(ad->ad_handle, "_PR0", &tmp);
+
+ if (ACPI_FAILURE(rv))
+ rv = AcpiGetHandle(ad->ad_handle, "_PSC", &tmp);
+
+ if (ACPI_SUCCESS(rv))
+ ad->ad_flags |= ACPI_DEVICE_POWER;
+
+ /*
+ * Scan wake-up capabilities.
+ */
+ rv = AcpiGetHandle(ad->ad_handle, "_PRW", &tmp);
+
+ if (ACPI_SUCCESS(rv)) {
+ ad->ad_flags |= ACPI_DEVICE_WAKEUP;
+ acpi_wakedev_add(ad);
+ }
+
+ if (ad->ad_flags != 0) {
+ aprint_debug_dev(sc->sc_dev, "%-5s ", ad->ad_name);
+
+ if ((ad->ad_flags & ACPI_DEVICE_POWER) != 0)
+ aprint_debug("power ");
+
+ if ((ad->ad_flags & ACPI_DEVICE_WAKEUP) != 0)
+ aprint_debug("wake-up ");
+
+ aprint_debug("\n");
+ }
+ }
+}
+
+#undef ACPI_STA_DEV_VALID
+
/*
* acpi_make_devnode:
*
diff -r 681797770259 -r d59cee94f7e8 sys/dev/acpi/acpi_wakedev.c
--- a/sys/dev/acpi/acpi_wakedev.c Tue Mar 16 04:14:29 2010 +0000
+++ b/sys/dev/acpi/acpi_wakedev.c Tue Mar 16 05:48:42 2010 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: acpi_wakedev.c,v 1.6 2010/03/09 18:15:22 jruoho Exp $ */
+/* $NetBSD: acpi_wakedev.c,v 1.7 2010/03/16 05:48:43 jruoho Exp $ */
/*-
* Copyright (c) 2009 Jared D. McNeill <jmcneill%invisible.ca@localhost>
@@ -27,7 +27,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: acpi_wakedev.c,v 1.6 2010/03/09 18:15:22 jruoho Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_wakedev.c,v 1.7 2010/03/16 05:48:43 jruoho Exp $");
#include <sys/param.h>
#include <sys/device.h>
@@ -43,20 +43,8 @@
#define _COMPONENT ACPI_BUS_COMPONENT
ACPI_MODULE_NAME ("acpi_wakedev")
-struct acpi_wakedev {
- struct acpi_devnode *aw_node;
- struct sysctllog *aw_sysctllog;
- int aw_enabled;
-
- TAILQ_ENTRY(acpi_wakedev) aw_list;
-};
-
-struct acpi_wakedev;
static int acpi_wakedev_node = -1;
-static TAILQ_HEAD(, acpi_wakedev) acpi_wakedevlist =
- TAILQ_HEAD_INITIALIZER(acpi_wakedevlist);
-
static const char * const acpi_wakedev_default[] = {
"PNP0C0C", /* power button */
"PNP0C0E", /* sleep button */
@@ -65,9 +53,6 @@
NULL,
};
-static void acpi_wakedev_sysctl_add(struct acpi_wakedev *);
-static bool acpi_wakedev_add(struct acpi_softc *, struct acpi_devnode *);
-static void acpi_wakedev_print(struct acpi_wakedev *);
static void acpi_wakedev_prepare(struct acpi_devnode *, int, int);
SYSCTL_SETUP(sysctl_acpi_wakedev_setup, "sysctl hw.wake subtree setup")
@@ -91,101 +76,37 @@
acpi_wakedev_node = rnode->sysctl_num;
}
-static void
-acpi_wakedev_sysctl_add(struct acpi_wakedev *aw)
+void
+acpi_wakedev_add(struct acpi_devnode *ad)
{
int err;
+ KASSERT(ad != NULL && ad->ad_parent != NULL);
+ KASSERT((ad->ad_flags & ACPI_DEVICE_WAKEUP) != 0);
+
+ ad->ad_wake.wake_enabled = 0;
+ ad->ad_wake.wake_sysctllog = NULL;
+
+ if (acpi_match_hid(ad->ad_devinfo, acpi_wakedev_default))
+ ad->ad_wake.wake_enabled = 1;
+
if (acpi_wakedev_node == -1)
return;
- err = sysctl_createv(&aw->aw_sysctllog, 0, NULL, NULL,
- CTLFLAG_READWRITE, CTLTYPE_INT, aw->aw_node->ad_name,
- NULL, NULL, 0, &aw->aw_enabled, 0,
+ err = sysctl_createv(&ad->ad_wake.wake_sysctllog, 0, NULL, NULL,
+ CTLFLAG_READWRITE, CTLTYPE_INT, ad->ad_name,
+ NULL, NULL, 0, &ad->ad_wake.wake_enabled, 0,
CTL_HW, acpi_wakedev_node, CTL_CREATE, CTL_EOL);
- if (err)
- aprint_error("%s: sysctl_createv(hw.wake.%s) failed (%d)\n",
- __func__, aw->aw_node->ad_name, err);
-}
-
-static bool
-acpi_wakedev_add(struct acpi_softc *sc, struct acpi_devnode *ad)
-{
- struct acpi_wakedev *aw;
- ACPI_HANDLE hdl;
-
- if (ACPI_FAILURE(AcpiGetHandle(ad->ad_handle, "_PRW", &hdl)))
- return false;
-
- aw = kmem_alloc(sizeof(*aw), KM_SLEEP);
- if (aw == NULL) {
- aprint_error("%s: kmem_alloc failed\n", __func__);
- return false;
- }
- aw->aw_node = ad;
- aw->aw_sysctllog = NULL;
- if (acpi_match_hid(ad->ad_devinfo, acpi_wakedev_default))
- aw->aw_enabled = 1;
- else
- aw->aw_enabled = 0;
-
- TAILQ_INSERT_TAIL(&acpi_wakedevlist, aw, aw_list);
-
- acpi_wakedev_sysctl_add(aw);
-
- return true;
-}
-static void
-acpi_wakedev_print(struct acpi_wakedev *aw)
-{
- aprint_debug(" %s", aw->aw_node->ad_name);
-}
-
-int
-acpi_wakedev_scan(struct acpi_softc *sc)
-{
- struct acpi_devnode *ad;
- struct acpi_wakedev *aw;
- ACPI_DEVICE_INFO *di;
- int count = 0;
-
-#define ACPI_STA_DEV_VALID \
- (ACPI_STA_DEV_PRESENT|ACPI_STA_DEV_ENABLED|ACPI_STA_DEV_OK)
-
- SIMPLEQ_FOREACH(ad, &sc->sc_devnodes, ad_list) {
-
- di = ad->ad_devinfo;
-
- if (di->Type != ACPI_TYPE_DEVICE)
- continue;
-
- if ((di->Valid & ACPI_VALID_STA) != 0 &&
- (di->CurrentStatus & ACPI_STA_DEV_VALID) !=
- ACPI_STA_DEV_VALID)
- continue;
-
- if (acpi_wakedev_add(sc, ad) == true)
- ++count;
- }
-
-#undef ACPI_STA_DEV_VALID
-
- if (count == 0)
- return 0;
-
- aprint_debug_dev(sc->sc_dev, "wakeup devices:");
- TAILQ_FOREACH(aw, &acpi_wakedevlist, aw_list)
- acpi_wakedev_print(aw);
- aprint_debug("\n");
-
- return count;
+ if (err != 0)
+ aprint_error_dev(ad->ad_parent, "sysctl_createv(hw.wake.%s) "
+ "failed (err %d)\n", ad->ad_name, err);
}
void
acpi_wakedev_commit(struct acpi_softc *sc, int state)
{
- struct acpi_wakedev *aw;
+ struct acpi_devnode *ad;
/*
* As noted in ACPI 3.0 (p. 243), preparing
@@ -197,16 +118,20 @@
*
* XXX: The first one is yet to be implemented.
*/
- TAILQ_FOREACH(aw, &acpi_wakedevlist, aw_list) {
+ SIMPLEQ_FOREACH(ad, &sc->sc_devnodes, ad_list) {
+
+ if ((ad->ad_flags & ACPI_DEVICE_WAKEUP) == 0)
+ continue;
- if (aw->aw_enabled) {
- aprint_debug_dev(sc->sc_dev, "set wake GPE (%s)\n",
- aw->aw_node->ad_name);
- acpi_set_wake_gpe(aw->aw_node->ad_handle);
- } else
- acpi_clear_wake_gpe(aw->aw_node->ad_handle);
+ if (ad->ad_wake.wake_enabled == 0)
+ acpi_clear_wake_gpe(ad->ad_handle);
+ else {
+ aprint_debug_dev(ad->ad_parent,
+ "set wake GPE for %s\n", ad->ad_name);
+ acpi_set_wake_gpe(ad->ad_handle);
+ }
Home |
Main Index |
Thread Index |
Old Index