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@.
This commit is contained in:
parent
65386b7262
commit
881fa5618a
@ -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_detach(device_t, int);
|
||||
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_build_tree(struct acpi_softc *sc)
|
||||
}
|
||||
|
||||
acpi_rescan1(sc, NULL, NULL);
|
||||
acpi_wakedev_scan(sc);
|
||||
acpi_rescan_capabilities(sc);
|
||||
|
||||
acpi_pcidev_scan(sc);
|
||||
}
|
||||
|
||||
@ -790,6 +792,71 @@ acpi_rescan_nodes(struct acpi_softc *sc)
|
||||
}
|
||||
}
|
||||
|
||||
#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:
|
||||
*
|
||||
|
@ -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>
|
||||
@ -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 @@ __KERNEL_RCSID(0, "$NetBSD: acpi_wakedev.c,v 1.6 2010/03/09 18:15:22 jruoho Exp
|
||||
#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 @@ static const char * const acpi_wakedev_default[] = {
|
||||
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 @@ SYSCTL_SETUP(sysctl_acpi_wakedev_setup, "sysctl hw.wake subtree setup")
|
||||
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 @@ acpi_wakedev_commit(struct acpi_softc *sc, int state)
|
||||
*
|
||||
* 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 (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_flags & ACPI_DEVICE_WAKEUP) == 0)
|
||||
continue;
|
||||
|
||||
acpi_wakedev_prepare(aw->aw_node, aw->aw_enabled, state);
|
||||
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);
|
||||
}
|
||||
|
||||
acpi_wakedev_prepare(ad, ad->ad_wake.wake_enabled, state);
|
||||
}
|
||||
}
|
||||
|
||||
@ -259,6 +184,6 @@ acpi_wakedev_prepare(struct acpi_devnode *ad, int enable, int state)
|
||||
return;
|
||||
|
||||
fail:
|
||||
aprint_error_dev(ad->ad_device, "failed to evaluate wake "
|
||||
aprint_error_dev(ad->ad_parent, "failed to evaluate wake "
|
||||
"control method: %s\n", AcpiFormatException(rv));
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: acpi_wakedev.h,v 1.3 2010/03/05 21:01:44 jruoho Exp $ */
|
||||
/* $NetBSD: acpi_wakedev.h,v 1.4 2010/03/16 05:48:43 jruoho Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2009 Jared D. McNeill <jmcneill@invisible.ca>
|
||||
@ -29,7 +29,7 @@
|
||||
#ifndef _SYS_DEV_ACPI_ACPI_WAKEDEV_H
|
||||
#define _SYS_DEV_ACPI_ACPI_WAKEDEV_H
|
||||
|
||||
int acpi_wakedev_scan(struct acpi_softc *);
|
||||
void acpi_wakedev_add(struct acpi_devnode *);
|
||||
void acpi_wakedev_commit(struct acpi_softc *, int);
|
||||
|
||||
#endif /* !_SYS_DEV_ACPI_ACPI_WAKEDEV_H */
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: acpivar.h,v 1.43 2010/03/10 09:42:46 jruoho Exp $ */
|
||||
/* $NetBSD: acpivar.h,v 1.44 2010/03/16 05:48:43 jruoho Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright 2001 Wasabi Systems, Inc.
|
||||
@ -73,6 +73,22 @@ struct acpibus_attach_args {
|
||||
#define ACPI_SWITCH_LID 2
|
||||
#define ACPI_NSWITCHES 3
|
||||
|
||||
/*
|
||||
* ACPI driver capabilities.
|
||||
*/
|
||||
#define ACPI_DEVICE_POWER __BIT(0)
|
||||
#define ACPI_DEVICE_WAKEUP __BIT(1)
|
||||
|
||||
/*
|
||||
* acpi_wake:
|
||||
*
|
||||
* ACPI device wake.
|
||||
*/
|
||||
struct acpi_wake {
|
||||
struct sysctllog *wake_sysctllog;
|
||||
int wake_enabled;
|
||||
};
|
||||
|
||||
/*
|
||||
* acpi_devnode:
|
||||
*
|
||||
@ -81,9 +97,11 @@ struct acpibus_attach_args {
|
||||
struct acpi_devnode {
|
||||
device_t ad_device; /* Device */
|
||||
device_t ad_parent; /* Backpointer to the parent */
|
||||
struct acpi_wake ad_wake; /* Device wakeup */
|
||||
ACPI_DEVICE_INFO *ad_devinfo; /* Device info */
|
||||
ACPI_HANDLE ad_handle; /* Device handle */
|
||||
char ad_name[5]; /* Device name */
|
||||
uint32_t ad_flags; /* Device flags */
|
||||
uint32_t ad_type; /* Device type */
|
||||
|
||||
SIMPLEQ_ENTRY(acpi_devnode) ad_list;
|
||||
|
Loading…
Reference in New Issue
Block a user