Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/dev/acpi Merge new code for ACPI power resources.
details: https://anonhg.NetBSD.org/src/rev/f966c89aaf4a
branches: trunk
changeset: 754172:f966c89aaf4a
user: jruoho <jruoho%NetBSD.org@localhost>
date: Thu Apr 22 18:40:09 2010 +0000
description:
Merge new code for ACPI power resources.
The old code served us well, but a major overhaul would have been needed for
it to cope with the increased demands of the code -- and the specifications.
ok jmcneill@, pgoyette@
diffstat:
sys/dev/acpi/acpi.c | 32 +-
sys/dev/acpi/acpi_power.c | 733 +++++++++++++++++++++++++++++++++++++++++++
sys/dev/acpi/acpi_power.h | 44 ++
sys/dev/acpi/acpi_powerres.c | 652 --------------------------------------
sys/dev/acpi/acpi_tz.c | 14 +-
sys/dev/acpi/acpivar.h | 9 +-
sys/dev/acpi/files.acpi | 4 +-
7 files changed, 813 insertions(+), 675 deletions(-)
diffs (truncated from 1638 to 300 lines):
diff -r 74172740796b -r f966c89aaf4a sys/dev/acpi/acpi.c
--- a/sys/dev/acpi/acpi.c Thu Apr 22 17:33:54 2010 +0000
+++ b/sys/dev/acpi/acpi.c Thu Apr 22 18:40:09 2010 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: acpi.c,v 1.180 2010/04/22 14:50:30 jruoho Exp $ */
+/* $NetBSD: acpi.c,v 1.181 2010/04/22 18:40:09 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.180 2010/04/22 14:50:30 jruoho Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi.c,v 1.181 2010/04/22 18:40:09 jruoho Exp $");
#include "opt_acpi.h"
#include "opt_pcifixup.h"
@@ -82,6 +82,7 @@
#include <dev/acpi/acpivar.h>
#include <dev/acpi/acpi_osd.h>
#include <dev/acpi/acpi_pci.h>
+#include <dev/acpi/acpi_power.h>
#include <dev/acpi/acpi_timer.h>
#include <dev/acpi/acpi_wakedev.h>
@@ -979,11 +980,18 @@
/*
* Handled internally.
*/
- if (ad->ad_devinfo->Type == ACPI_TYPE_PROCESSOR ||
- ad->ad_devinfo->Type == ACPI_TYPE_POWER)
+ if (ad->ad_devinfo->Type == ACPI_TYPE_PROCESSOR)
continue;
/*
+ * Ditto, but bind power resources.
+ */
+ if (ad->ad_devinfo->Type == ACPI_TYPE_POWER) {
+ acpi_power_res_add(ad);
+ continue;
+ }
+
+ /*
* Skip ignored HIDs.
*/
if (acpi_match_hid(ad->ad_devinfo, acpi_ignored_ids))
@@ -1019,14 +1027,16 @@
/*
* Scan power resource capabilities.
+ *
+ * If any power states are supported,
+ * at least _PR0 and _PR3 must be present.
*/
rv = AcpiGetHandle(ad->ad_handle, "_PR0", &tmp);
- if (ACPI_FAILURE(rv))
- rv = AcpiGetHandle(ad->ad_handle, "_PSC", &tmp);
-
- if (ACPI_SUCCESS(rv))
+ if (ACPI_SUCCESS(rv)) {
ad->ad_flags |= ACPI_DEVICE_POWER;
+ (void)acpi_power_get(ad, NULL);
+ }
/*
* Scan wake-up capabilities.
@@ -1041,12 +1051,12 @@
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 ");
+ if ((ad->ad_flags & ACPI_DEVICE_POWER) != 0)
+ aprint_debug("power (D%d) ", ad->ad_state);
+
aprint_debug("\n");
}
}
diff -r 74172740796b -r f966c89aaf4a sys/dev/acpi/acpi_power.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/dev/acpi/acpi_power.c Thu Apr 22 18:40:09 2010 +0000
@@ -0,0 +1,733 @@
+/* $NetBSD: acpi_power.c,v 1.1 2010/04/22 18:40:09 jruoho Exp $ */
+
+/*-
+ * Copyright (c) 2009, 2010 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Jukka Ruohonen.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/*-
+ * Copyright (c) 2001 Michael Smith
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: acpi_power.c,v 1.1 2010/04/22 18:40:09 jruoho Exp $");
+
+#include <sys/param.h>
+#include <sys/kmem.h>
+#include <sys/mutex.h>
+
+#include <dev/acpi/acpireg.h>
+#include <dev/acpi/acpivar.h>
+#include <dev/acpi/acpi_power.h>
+
+#define _COMPONENT ACPI_BUS_COMPONENT
+ACPI_MODULE_NAME ("acpi_power")
+
+/*
+ * References.
+ */
+struct acpi_power_ref {
+ ACPI_HANDLE ref_handle;
+
+ SIMPLEQ_ENTRY(acpi_power_ref) ref_list;
+};
+
+/*
+ * Resources.
+ */
+struct acpi_power_res {
+ ACPI_HANDLE res_handle;
+ ACPI_INTEGER res_level;
+ ACPI_INTEGER res_order;
+ char res_name[5];
+ kmutex_t res_mutex;
+
+ TAILQ_ENTRY(acpi_power_res) res_list;
+ SIMPLEQ_HEAD(, acpi_power_ref) ref_head;
+};
+
+static TAILQ_HEAD(, acpi_power_res) res_head =
+ TAILQ_HEAD_INITIALIZER(res_head);
+
+static struct acpi_power_res *acpi_power_res_init(ACPI_HANDLE);
+static struct acpi_power_res *acpi_power_res_get(ACPI_HANDLE);
+
+#if 0
+static ACPI_STATUS acpi_power_get_direct(struct acpi_devnode *);
+#endif
+
+static ACPI_STATUS acpi_power_get_indirect(struct acpi_devnode *);
+static ACPI_STATUS acpi_power_switch(struct acpi_devnode *,
+ int, bool);
+static ACPI_STATUS acpi_power_res_on(ACPI_OBJECT *, void *);
+static ACPI_STATUS acpi_power_res_off(ACPI_OBJECT *, void *);
+static ACPI_STATUS acpi_power_res_ref(struct acpi_power_res *,
+ ACPI_HANDLE);
+static ACPI_STATUS acpi_power_res_deref(struct acpi_power_res *,
+ ACPI_HANDLE);
+static ACPI_STATUS acpi_power_res_sta(ACPI_OBJECT *, void *);
+
+static ACPI_OBJECT *acpi_power_pkg_get(ACPI_HANDLE, int);
+static const char *acpi_xname(ACPI_HANDLE);
+
+void
+acpi_power_res_add(struct acpi_devnode *ad)
+{
+ struct acpi_power_res *res;
+
+ KASSERT(ad != NULL && ad->ad_root != NULL);
+ KASSERT(ad->ad_devinfo->Type == ACPI_TYPE_POWER);
+
+ res = acpi_power_res_init(ad->ad_handle);
+
+ if (res == NULL)
+ aprint_error_dev(ad->ad_root, "failed to "
+ "add power resource %s\n", ad->ad_name);
+}
+
+static struct acpi_power_res *
+acpi_power_res_init(ACPI_HANDLE hdl)
+{
+ struct acpi_power_res *tmp = NULL;
+ struct acpi_power_res *res = NULL;
+ ACPI_OBJECT *obj;
+ ACPI_BUFFER buf;
+ ACPI_STATUS rv;
+
+ rv = acpi_eval_struct(hdl, NULL, &buf);
+
+ if (ACPI_FAILURE(rv))
+ goto out;
+
+ obj = buf.Pointer;
+
+ if (obj->Type != ACPI_TYPE_POWER) {
+ rv = AE_TYPE;
+ goto out;
+ }
+
+ res = kmem_zalloc(sizeof(*res), KM_SLEEP);
+
+ if (res == NULL) {
+ rv = AE_NO_MEMORY;
+ goto out;
+ }
+
+ res->res_handle = hdl;
+ res->res_level = obj->PowerResource.SystemLevel;
+ res->res_order = obj->PowerResource.ResourceOrder;
+
+ (void)strlcpy(res->res_name,
+ acpi_xname(hdl), sizeof(res->res_name));
+
+ SIMPLEQ_INIT(&res->ref_head);
+ mutex_init(&res->res_mutex, MUTEX_DEFAULT, IPL_NONE);
+
+ /*
+ * Power resources should be ordered.
+ *
+ * These *should* be enabled from low values to high
+ * values and disabled from high values to low values.
+ */
+ TAILQ_FOREACH(tmp, &res_head, res_list) {
+
+ if (res->res_order < tmp->res_order) {
+ TAILQ_INSERT_BEFORE(tmp, res, res_list);
+ break;
+ }
+ }
+
+ if (tmp == NULL)
+ TAILQ_INSERT_TAIL(&res_head, res, res_list);
+
+out:
+ if (buf.Pointer != NULL)
+ ACPI_FREE(buf.Pointer);
+
+ return res;
+}
+
+static struct acpi_power_res *
+acpi_power_res_get(ACPI_HANDLE hdl)
+{
+ struct acpi_power_res *res;
+
+ TAILQ_FOREACH(res, &res_head, res_list) {
+
+ if (res->res_handle == hdl)
+ return res;
+ }
+
+ return acpi_power_res_init(hdl);
+}
+
+bool
+acpi_power_register(struct acpi_devnode *ad)
+{
Home |
Main Index |
Thread Index |
Old Index