Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/dev/acpi ThermalZone improvement work by lha at stacken....



details:   https://anonhg.NetBSD.org/src/rev/ae6d91242e74
branches:  trunk
changeset: 566970:ae6d91242e74
user:      kochi <kochi%NetBSD.org@localhost>
date:      Wed May 26 17:15:17 2004 +0000

description:
ThermalZone improvement work by lha at stacken.kth.se, inspired from
FreeBSD thermal zone code.  Minor style fixes and bugfixes by me.

diffstat:

 sys/dev/acpi/acpi.c          |   48 ++-
 sys/dev/acpi/acpi_powerres.c |  685 +++++++++++++++++++++++++++++++++++++++++++
 sys/dev/acpi/acpi_tz.c       |  350 ++++++++++++++++++++-
 sys/dev/acpi/acpivar.h       |    7 +-
 sys/dev/acpi/files.acpi      |    3 +-
 5 files changed, 1067 insertions(+), 26 deletions(-)

diffs (truncated from 1261 to 300 lines):

diff -r f6a2647ae8cf -r ae6d91242e74 sys/dev/acpi/acpi.c
--- a/sys/dev/acpi/acpi.c       Wed May 26 17:12:20 2004 +0000
+++ b/sys/dev/acpi/acpi.c       Wed May 26 17:15:17 2004 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: acpi.c,v 1.64 2004/05/01 12:03:48 kochi Exp $  */
+/*     $NetBSD: acpi.c,v 1.65 2004/05/26 17:15:17 kochi Exp $  */
 
 /*-
  * Copyright (c) 2003 The NetBSD Foundation, Inc.
@@ -77,7 +77,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: acpi.c,v 1.64 2004/05/01 12:03:48 kochi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi.c,v 1.65 2004/05/26 17:15:17 kochi Exp $");
 
 #include "opt_acpi.h"
 
@@ -864,6 +864,50 @@
 }
 
 /*
+ * acpi_foreach_package_object:
+ *
+ *     Iterate over all objects in a in a packages and pass then all
+ *     to a function. If the called function returns non AE_OK, the
+ *     iteration is stopped and that value is returned.
+ */
+
+ACPI_STATUS
+acpi_foreach_package_object(ACPI_OBJECT *pkg, 
+    ACPI_STATUS (*func)(ACPI_OBJECT *, void *), 
+    void *arg)
+{
+       ACPI_STATUS rv = AE_OK;
+       int i;
+
+       if (pkg == NULL || pkg->Type != ACPI_TYPE_PACKAGE)
+               return AE_BAD_PARAMETER;
+
+       for (i = 0; i < pkg->Package.Count; i++) {
+               rv = (*func)(&pkg->Package.Elements[i], arg);
+               if (ACPI_FAILURE(rv))
+                       break;
+       }
+
+       return rv;
+}
+
+const char *
+acpi_name(ACPI_HANDLE handle)
+{
+       static char buffer[80];
+       ACPI_BUFFER buf;
+       ACPI_STATUS rv;
+
+       buf.Length = sizeof(buffer);
+       buf.Pointer = buffer;
+
+       rv = AcpiGetName(handle, ACPI_FULL_PATHNAME, &buf);
+       if (ACPI_FAILURE(rv))
+               return "(unknown acpi path)";
+       return buffer;
+}
+
+/*
  * acpi_get:
  *
  *     Fetch data info the specified (empty) ACPI buffer.
diff -r f6a2647ae8cf -r ae6d91242e74 sys/dev/acpi/acpi_powerres.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/dev/acpi/acpi_powerres.c      Wed May 26 17:15:17 2004 +0000
@@ -0,0 +1,685 @@
+/* $NetBSD: acpi_powerres.c,v 1.1 2004/05/26 17:15:17 kochi Exp $ */
+
+/*-
+ * 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.
+ *
+ *     $FreeBSD: src/sys/dev/acpica/acpi_powerres.c,v 1.14 2002/10/16 17:28:52 jhb Exp $
+ */
+
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: acpi_powerres.c,v 1.1 2004/05/26 17:15:17 kochi Exp $");
+
+#include <sys/param.h>
+#include <sys/kernel.h>
+#include <sys/proc.h>
+#include <sys/malloc.h>
+#include <sys/conf.h>
+#include <sys/systm.h>
+
+#include <dev/acpi/acpica.h>
+#include <dev/acpi/acpireg.h>
+#include <dev/acpi/acpivar.h>
+
+/*
+ * ACPI power resource management.
+ *
+ * Power resource behaviour is slightly complicated by the fact that
+ * a single power resource may provide power for more than one device.
+ * Thus, we must track the device(s) being powered by a given power
+ * resource, and only deactivate it when there are no powered devices.
+ *
+ * Note that this only manages resources for known devices.  There is an
+ * ugly case where we may turn of power to a device which is in use because
+ * we don't know that it depends on a given resource.  We should perhaps
+ * try to be smarter about this, but a more complete solution would involve
+ * scanning all of the ACPI namespace to find devices we're not currently
+ * aware of, and this raises questions about whether they should be left
+ * on, turned off, etc.
+ *
+ * XXX locking
+ */
+
+MALLOC_DEFINE(M_ACPIPWR, "acpipwr", "ACPI power resources");
+
+/*
+ * Hooks for the ACPI CA debugging infrastructure
+ */
+#define _COMPONENT     ACPI_BUS_COMPONENT
+ACPI_MODULE_NAME("POWERRES")
+
+/*
+ * A relationship between a power resource and a consumer.
+ */
+struct acpi_powerreference {
+       struct acpi_powerconsumer       *ar_consumer;
+       struct acpi_powerresource       *ar_resource;
+       TAILQ_ENTRY(acpi_powerreference) ar_rlink; /* link on resource list */
+       TAILQ_ENTRY(acpi_powerreference) ar_clink; /* link on consumer */
+};
+
+/*
+ * A power-managed device.
+ */
+struct acpi_powerconsumer {
+       ACPI_HANDLE             ac_consumer; /* device which is powered */
+       int                     ac_state;
+       TAILQ_ENTRY(acpi_powerconsumer) ac_link;
+       TAILQ_HEAD(,acpi_powerreference) ac_references;
+};
+
+/*
+ * A power resource.
+ */
+struct acpi_powerresource {
+       TAILQ_ENTRY(acpi_powerresource) ap_link;
+       TAILQ_HEAD(,acpi_powerreference) ap_references;
+       ACPI_HANDLE     ap_resource; /* the resource's handle */
+       ACPI_INTEGER    ap_systemlevel;
+       ACPI_INTEGER    ap_order;
+};
+
+static TAILQ_HEAD(acpi_powerresource_list, acpi_powerresource)
+       acpi_powerresources = TAILQ_HEAD_INITIALIZER(acpi_powerresources);
+static TAILQ_HEAD(acpi_powerconsumer_list, acpi_powerconsumer)
+       acpi_powerconsumers = TAILQ_HEAD_INITIALIZER(acpi_powerconsumers);
+
+static ACPI_STATUS     acpi_pwr_register_consumer(ACPI_HANDLE consumer);
+#if 0
+static ACPI_STATUS     acpi_pwr_register_resource(ACPI_HANDLE res);
+static ACPI_STATUS     acpi_pwr_deregister_consumer(ACPI_HANDLE consumer);
+static ACPI_STATUS     acpi_pwr_deregister_resource(ACPI_HANDLE res);
+#endif
+static ACPI_STATUS     acpi_pwr_reference_resource(ACPI_OBJECT *obj, void *arg);
+static ACPI_STATUS     acpi_pwr_switch_power(void);
+static struct acpi_powerresource *acpi_pwr_find_resource(ACPI_HANDLE res);
+static struct acpi_powerconsumer *acpi_pwr_find_consumer(ACPI_HANDLE consumer);
+
+/*
+ * Register a power resource.
+ *
+ * It's OK to call this if we already know about the resource.
+ */
+static ACPI_STATUS
+acpi_pwr_register_resource(ACPI_HANDLE res)
+{
+       ACPI_STATUS                     status;
+       ACPI_BUFFER                     buf;
+       ACPI_OBJECT                     *obj;
+       struct acpi_powerresource       *rp, *srp;
+
+       ACPI_FUNCTION_TRACE(__FUNCTION__);
+
+       rp = NULL;
+       buf.Pointer = NULL;
+
+       /* look to see if we know about this resource */
+       if (acpi_pwr_find_resource(res) != NULL)
+               return_ACPI_STATUS(AE_OK); /* already know about it */
+
+       /* allocate a new resource */
+       if ((rp = malloc(sizeof(*rp), M_ACPIPWR, M_NOWAIT | M_ZERO)) == NULL) {
+               status = AE_NO_MEMORY;
+               goto out;
+       }
+       TAILQ_INIT(&rp->ap_references);
+       rp->ap_resource = res;
+
+       /* get the Power Resource object */
+       buf.Length = ACPI_ALLOCATE_BUFFER;
+       status = AcpiEvaluateObject(res, NULL, NULL, &buf);
+       if (ACPI_FAILURE(status)) {
+               ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS,
+                                    "no power resource object\n"));
+               goto out;
+       }
+       obj = buf.Pointer;
+       if (obj->Type != ACPI_TYPE_POWER) {
+               ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS,
+                                    "questionable power resource object %s\n",
+                                    acpi_name(res)));
+               status = AE_TYPE;
+               goto out;
+       }
+       rp->ap_systemlevel = obj->PowerResource.SystemLevel;
+       rp->ap_order = obj->PowerResource.ResourceOrder;
+
+       /* sort the resource into the list */
+       status = AE_OK;
+       srp = TAILQ_FIRST(&acpi_powerresources);
+       if ((srp == NULL) || (rp->ap_order < srp->ap_order)) {
+               TAILQ_INSERT_HEAD(&acpi_powerresources, rp, ap_link);
+               goto done;
+       }
+       TAILQ_FOREACH(srp, &acpi_powerresources, ap_link)
+           if (rp->ap_order < srp->ap_order) {
+                   TAILQ_INSERT_BEFORE(srp, rp, ap_link);
+                   goto done;
+           }
+       TAILQ_INSERT_TAIL(&acpi_powerresources, rp, ap_link);
+
+ done:
+       ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, "registered power resource %s\n",
+                            acpi_name(res)));
+ out:
+       if (buf.Pointer != NULL)
+               AcpiOsFree(buf.Pointer);
+       if (ACPI_FAILURE(status) && (rp != NULL))
+               free(rp, M_ACPIPWR);
+       return_ACPI_STATUS(status);
+}
+
+#if 0
+/*
+ * Deregister a power resource.
+ */
+static ACPI_STATUS
+acpi_pwr_deregister_resource(ACPI_HANDLE res)
+{
+       struct acpi_powerresource       *rp;
+
+       ACPI_FUNCTION_TRACE(__FUNCTION__);
+
+       rp = NULL;
+
+       /* find the resource */
+       if ((rp = acpi_pwr_find_resource(res)) == NULL)
+               return_ACPI_STATUS(AE_BAD_PARAMETER);
+
+       /* check that there are no consumers referencing this resource */
+       if (TAILQ_FIRST(&rp->ap_references) != NULL)
+               return_ACPI_STATUS(AE_BAD_PARAMETER);
+
+       /* pull it off the list and free it */
+       TAILQ_REMOVE(&acpi_powerresources, rp, ap_link);
+       free(rp, M_ACPIPWR);
+
+       ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, "deregistered power resource %s\n",
+                            acpi_name(res)));
+
+       return_ACPI_STATUS(AE_OK);
+}
+#endif
+
+/*
+ * Register a power consumer.
+ *



Home | Main Index | Thread Index | Old Index