2001-06-28 06:17:16 +00:00
|
|
|
/*-
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2003-08-24 17:55:58 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
2003-08-28 16:06:30 +00:00
|
|
|
#include "opt_acpi.h"
|
2001-06-28 06:17:16 +00:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/malloc.h>
|
|
|
|
#include <sys/bus.h>
|
|
|
|
|
|
|
|
#include "acpi.h"
|
|
|
|
#include <dev/acpica/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");
|
|
|
|
|
2003-08-28 16:06:30 +00:00
|
|
|
/* Hooks for the ACPI CA debugging infrastructure */
|
2004-03-03 03:02:17 +00:00
|
|
|
#define _COMPONENT ACPI_POWERRES
|
2002-02-23 05:28:22 +00:00
|
|
|
ACPI_MODULE_NAME("POWERRES")
|
2001-06-28 06:17:16 +00:00
|
|
|
|
2003-08-28 16:06:30 +00:00
|
|
|
/* Return values from _STA on a power resource */
|
2001-07-06 09:00:07 +00:00
|
|
|
#define ACPI_PWR_OFF 0
|
|
|
|
#define ACPI_PWR_ON 1
|
|
|
|
|
2003-08-28 16:06:30 +00:00
|
|
|
/* A relationship between a power resource and a consumer. */
|
2001-06-28 06:17:16 +00:00
|
|
|
struct acpi_powerreference {
|
2003-08-28 16:06:30 +00:00
|
|
|
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 */
|
2001-06-28 06:17:16 +00:00
|
|
|
};
|
|
|
|
|
2003-08-28 16:06:30 +00:00
|
|
|
/* A power-managed device. */
|
2001-06-28 06:17:16 +00:00
|
|
|
struct acpi_powerconsumer {
|
2003-08-28 16:06:30 +00:00
|
|
|
/* Device which is powered */
|
|
|
|
ACPI_HANDLE ac_consumer;
|
|
|
|
int ac_state;
|
|
|
|
TAILQ_ENTRY(acpi_powerconsumer) ac_link;
|
|
|
|
TAILQ_HEAD(,acpi_powerreference) ac_references;
|
2001-06-28 06:17:16 +00:00
|
|
|
};
|
|
|
|
|
2003-08-28 16:06:30 +00:00
|
|
|
/* A power resource. */
|
2001-06-28 06:17:16 +00:00
|
|
|
struct acpi_powerresource {
|
2003-08-28 16:06:30 +00:00
|
|
|
TAILQ_ENTRY(acpi_powerresource) ap_link;
|
|
|
|
TAILQ_HEAD(,acpi_powerreference) ap_references;
|
|
|
|
ACPI_HANDLE ap_resource;
|
|
|
|
ACPI_INTEGER ap_systemlevel;
|
|
|
|
ACPI_INTEGER ap_order;
|
2001-06-28 06:17:16 +00:00
|
|
|
};
|
|
|
|
|
2003-08-28 16:06:30 +00:00
|
|
|
static TAILQ_HEAD(acpi_powerresource_list, acpi_powerresource)
|
|
|
|
acpi_powerresources;
|
|
|
|
static TAILQ_HEAD(acpi_powerconsumer_list, acpi_powerconsumer)
|
|
|
|
acpi_powerconsumers;
|
|
|
|
|
|
|
|
static ACPI_STATUS acpi_pwr_register_consumer(ACPI_HANDLE consumer);
|
2004-04-14 17:47:42 +00:00
|
|
|
#ifdef notyet
|
2003-08-28 16:06:30 +00:00
|
|
|
static ACPI_STATUS acpi_pwr_deregister_consumer(ACPI_HANDLE consumer);
|
2004-04-14 17:47:42 +00:00
|
|
|
#endif /* notyet */
|
2003-08-28 16:06:30 +00:00
|
|
|
static ACPI_STATUS acpi_pwr_register_resource(ACPI_HANDLE res);
|
2004-04-14 17:47:42 +00:00
|
|
|
#ifdef notyet
|
2003-08-28 16:06:30 +00:00
|
|
|
static ACPI_STATUS acpi_pwr_deregister_resource(ACPI_HANDLE res);
|
2004-04-14 17:47:42 +00:00
|
|
|
#endif /* notyet */
|
2003-08-28 16:06:30 +00:00
|
|
|
static void acpi_pwr_reference_resource(ACPI_OBJECT *obj,
|
|
|
|
void *arg);
|
2004-06-30 16:02:40 +00:00
|
|
|
static int acpi_pwr_dereference_resource(struct acpi_powerconsumer
|
|
|
|
*pc);
|
2003-08-28 16:06:30 +00:00
|
|
|
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);
|
|
|
|
|
|
|
|
/* Initialise our lists. */
|
2001-06-28 06:17:16 +00:00
|
|
|
static void
|
|
|
|
acpi_pwr_init(void *junk)
|
|
|
|
{
|
|
|
|
TAILQ_INIT(&acpi_powerresources);
|
|
|
|
TAILQ_INIT(&acpi_powerconsumers);
|
|
|
|
}
|
|
|
|
SYSINIT(acpi_powerresource, SI_SUB_TUNABLES, SI_ORDER_ANY, acpi_pwr_init, NULL);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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;
|
2001-07-09 21:24:59 +00:00
|
|
|
ACPI_OBJECT *obj;
|
2001-06-28 06:17:16 +00:00
|
|
|
struct acpi_powerresource *rp, *srp;
|
|
|
|
|
2002-05-19 06:16:47 +00:00
|
|
|
ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
|
2001-06-28 06:17:16 +00:00
|
|
|
|
|
|
|
rp = NULL;
|
2002-02-23 05:28:22 +00:00
|
|
|
buf.Pointer = NULL;
|
2001-06-28 06:17:16 +00:00
|
|
|
|
2003-08-28 16:06:30 +00:00
|
|
|
/* Look to see if we know about this resource */
|
2001-06-28 06:17:16 +00:00
|
|
|
if (acpi_pwr_find_resource(res) != NULL)
|
2003-08-28 16:06:30 +00:00
|
|
|
return_ACPI_STATUS (AE_OK); /* already know about it */
|
2001-06-28 06:17:16 +00:00
|
|
|
|
2003-08-28 16:06:30 +00:00
|
|
|
/* Allocate a new resource */
|
2001-06-28 06:17:16 +00:00
|
|
|
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;
|
|
|
|
|
2003-08-28 16:06:30 +00:00
|
|
|
/* Get the Power Resource object */
|
2002-02-23 05:28:22 +00:00
|
|
|
buf.Length = ACPI_ALLOCATE_BUFFER;
|
|
|
|
if (ACPI_FAILURE(status = AcpiEvaluateObject(res, NULL, NULL, &buf))) {
|
2001-08-26 22:50:15 +00:00
|
|
|
ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, "no power resource object\n"));
|
2001-06-28 06:17:16 +00:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
obj = buf.Pointer;
|
2001-07-09 21:24:59 +00:00
|
|
|
if (obj->Type != ACPI_TYPE_POWER) {
|
2003-08-28 16:06:30 +00:00
|
|
|
ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS,
|
|
|
|
"questionable power resource object %s\n",
|
|
|
|
acpi_name(res)));
|
2001-07-09 21:24:59 +00:00
|
|
|
status = AE_TYPE;
|
|
|
|
goto out;
|
2001-06-28 06:17:16 +00:00
|
|
|
}
|
2001-07-09 21:24:59 +00:00
|
|
|
rp->ap_systemlevel = obj->PowerResource.SystemLevel;
|
|
|
|
rp->ap_order = obj->PowerResource.ResourceOrder;
|
2001-06-28 06:17:16 +00:00
|
|
|
|
2003-08-28 16:06:30 +00:00
|
|
|
/* Sort the resource into the list */
|
2001-06-28 06:17:16 +00:00
|
|
|
status = AE_OK;
|
|
|
|
srp = TAILQ_FIRST(&acpi_powerresources);
|
2003-08-28 16:06:30 +00:00
|
|
|
if (srp == NULL || rp->ap_order < srp->ap_order) {
|
2001-06-28 06:17:16 +00:00
|
|
|
TAILQ_INSERT_HEAD(&acpi_powerresources, rp, ap_link);
|
2001-07-06 09:00:07 +00:00
|
|
|
goto done;
|
2001-06-28 06:17:16 +00:00
|
|
|
}
|
2003-08-28 16:06:30 +00:00
|
|
|
TAILQ_FOREACH(srp, &acpi_powerresources, ap_link) {
|
2001-06-28 06:17:16 +00:00
|
|
|
if (rp->ap_order < srp->ap_order) {
|
|
|
|
TAILQ_INSERT_BEFORE(srp, rp, ap_link);
|
2001-07-06 09:00:07 +00:00
|
|
|
goto done;
|
2001-06-28 06:17:16 +00:00
|
|
|
}
|
2003-08-28 16:06:30 +00:00
|
|
|
}
|
2001-06-28 06:17:16 +00:00
|
|
|
TAILQ_INSERT_TAIL(&acpi_powerresources, rp, ap_link);
|
|
|
|
|
2001-07-06 09:00:07 +00:00
|
|
|
done:
|
2003-08-28 16:06:30 +00:00
|
|
|
ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS,
|
|
|
|
"registered power resource %s\n", acpi_name(res)));
|
|
|
|
|
2001-06-28 06:17:16 +00:00
|
|
|
out:
|
2002-02-23 05:28:22 +00:00
|
|
|
if (buf.Pointer != NULL)
|
|
|
|
AcpiOsFree(buf.Pointer);
|
2003-08-28 16:06:30 +00:00
|
|
|
if (ACPI_FAILURE(status) && rp != NULL)
|
2001-06-28 06:17:16 +00:00
|
|
|
free(rp, M_ACPIPWR);
|
2003-08-28 16:06:30 +00:00
|
|
|
return_ACPI_STATUS (status);
|
2001-06-28 06:17:16 +00:00
|
|
|
}
|
|
|
|
|
2004-04-14 17:47:42 +00:00
|
|
|
#ifdef notyet
|
2001-06-28 06:17:16 +00:00
|
|
|
/*
|
|
|
|
* Deregister a power resource.
|
|
|
|
*/
|
|
|
|
static ACPI_STATUS
|
|
|
|
acpi_pwr_deregister_resource(ACPI_HANDLE res)
|
|
|
|
{
|
|
|
|
struct acpi_powerresource *rp;
|
|
|
|
|
2002-05-19 06:16:47 +00:00
|
|
|
ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
|
2001-06-28 06:17:16 +00:00
|
|
|
|
|
|
|
rp = NULL;
|
|
|
|
|
2003-08-28 16:06:30 +00:00
|
|
|
/* Find the resource */
|
2001-06-28 06:17:16 +00:00
|
|
|
if ((rp = acpi_pwr_find_resource(res)) == NULL)
|
2003-08-28 16:06:30 +00:00
|
|
|
return_ACPI_STATUS (AE_BAD_PARAMETER);
|
2001-06-28 06:17:16 +00:00
|
|
|
|
2003-08-28 16:06:30 +00:00
|
|
|
/* Check that there are no consumers referencing this resource */
|
2001-06-28 06:17:16 +00:00
|
|
|
if (TAILQ_FIRST(&rp->ap_references) != NULL)
|
2003-08-28 16:06:30 +00:00
|
|
|
return_ACPI_STATUS (AE_BAD_PARAMETER);
|
2001-06-28 06:17:16 +00:00
|
|
|
|
2003-08-28 16:06:30 +00:00
|
|
|
/* Pull it off the list and free it */
|
2001-06-28 06:17:16 +00:00
|
|
|
TAILQ_REMOVE(&acpi_powerresources, rp, ap_link);
|
|
|
|
free(rp, M_ACPIPWR);
|
|
|
|
|
2003-08-28 16:06:30 +00:00
|
|
|
ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, "deregistered power resource %s\n",
|
|
|
|
acpi_name(res)));
|
2001-06-28 06:17:16 +00:00
|
|
|
|
2003-08-28 16:06:30 +00:00
|
|
|
return_ACPI_STATUS (AE_OK);
|
2001-06-28 06:17:16 +00:00
|
|
|
}
|
2004-04-14 17:47:42 +00:00
|
|
|
#endif /* notyet */
|
2001-06-28 06:17:16 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Register a power consumer.
|
|
|
|
*
|
|
|
|
* It's OK to call this if we already know about the consumer.
|
|
|
|
*/
|
|
|
|
static ACPI_STATUS
|
|
|
|
acpi_pwr_register_consumer(ACPI_HANDLE consumer)
|
|
|
|
{
|
|
|
|
struct acpi_powerconsumer *pc;
|
|
|
|
|
2002-05-19 06:16:47 +00:00
|
|
|
ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
|
2001-06-28 06:17:16 +00:00
|
|
|
|
2003-08-28 16:06:30 +00:00
|
|
|
/* Check to see whether we know about this consumer already */
|
2001-06-28 06:17:16 +00:00
|
|
|
if ((pc = acpi_pwr_find_consumer(consumer)) != NULL)
|
2003-08-28 16:06:30 +00:00
|
|
|
return_ACPI_STATUS (AE_OK);
|
2001-06-28 06:17:16 +00:00
|
|
|
|
2003-08-28 16:06:30 +00:00
|
|
|
/* Allocate a new power consumer */
|
2001-06-28 06:17:16 +00:00
|
|
|
if ((pc = malloc(sizeof(*pc), M_ACPIPWR, M_NOWAIT)) == NULL)
|
2003-08-28 16:06:30 +00:00
|
|
|
return_ACPI_STATUS (AE_NO_MEMORY);
|
2001-06-28 06:17:16 +00:00
|
|
|
TAILQ_INSERT_HEAD(&acpi_powerconsumers, pc, ac_link);
|
|
|
|
TAILQ_INIT(&pc->ac_references);
|
|
|
|
pc->ac_consumer = consumer;
|
|
|
|
|
2003-08-28 16:06:30 +00:00
|
|
|
/* XXX we should try to find its current state */
|
|
|
|
pc->ac_state = ACPI_STATE_UNKNOWN;
|
2001-06-28 06:17:16 +00:00
|
|
|
|
2003-08-28 16:06:30 +00:00
|
|
|
ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, "registered power consumer %s\n",
|
|
|
|
acpi_name(consumer)));
|
2001-06-28 06:17:16 +00:00
|
|
|
|
2003-08-28 16:06:30 +00:00
|
|
|
return_ACPI_STATUS (AE_OK);
|
2001-06-28 06:17:16 +00:00
|
|
|
}
|
|
|
|
|
2004-04-14 17:47:42 +00:00
|
|
|
#ifdef notyet
|
2001-06-28 06:17:16 +00:00
|
|
|
/*
|
|
|
|
* Deregister a power consumer.
|
|
|
|
*
|
|
|
|
* This should only be done once the consumer has been powered off.
|
|
|
|
* (XXX is this correct? Check once implemented)
|
|
|
|
*/
|
|
|
|
static ACPI_STATUS
|
|
|
|
acpi_pwr_deregister_consumer(ACPI_HANDLE consumer)
|
|
|
|
{
|
|
|
|
struct acpi_powerconsumer *pc;
|
|
|
|
|
2002-05-19 06:16:47 +00:00
|
|
|
ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
|
2001-06-28 06:17:16 +00:00
|
|
|
|
2003-08-28 16:06:30 +00:00
|
|
|
/* Find the consumer */
|
2001-06-28 06:17:16 +00:00
|
|
|
if ((pc = acpi_pwr_find_consumer(consumer)) == NULL)
|
2003-08-28 16:06:30 +00:00
|
|
|
return_ACPI_STATUS (AE_BAD_PARAMETER);
|
2001-06-28 06:17:16 +00:00
|
|
|
|
2003-08-28 16:06:30 +00:00
|
|
|
/* Make sure the consumer's not referencing anything right now */
|
2001-06-28 06:17:16 +00:00
|
|
|
if (TAILQ_FIRST(&pc->ac_references) != NULL)
|
2003-08-28 16:06:30 +00:00
|
|
|
return_ACPI_STATUS (AE_BAD_PARAMETER);
|
2001-06-28 06:17:16 +00:00
|
|
|
|
2003-08-28 16:06:30 +00:00
|
|
|
/* Pull the consumer off the list and free it */
|
2001-06-28 06:17:16 +00:00
|
|
|
TAILQ_REMOVE(&acpi_powerconsumers, pc, ac_link);
|
|
|
|
|
2003-08-28 16:06:30 +00:00
|
|
|
ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, "deregistered power consumer %s\n",
|
|
|
|
acpi_name(consumer)));
|
2001-06-28 06:17:16 +00:00
|
|
|
|
2003-08-28 16:06:30 +00:00
|
|
|
return_ACPI_STATUS (AE_OK);
|
2001-06-28 06:17:16 +00:00
|
|
|
}
|
2004-04-14 17:47:42 +00:00
|
|
|
#endif /* notyet */
|
2001-06-28 06:17:16 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Set a power consumer to a particular power state.
|
|
|
|
*/
|
|
|
|
ACPI_STATUS
|
|
|
|
acpi_pwr_switch_consumer(ACPI_HANDLE consumer, int state)
|
|
|
|
{
|
|
|
|
struct acpi_powerconsumer *pc;
|
2001-08-21 18:22:40 +00:00
|
|
|
ACPI_HANDLE method_handle, reslist_handle, pr0_handle;
|
2001-06-28 06:17:16 +00:00
|
|
|
ACPI_BUFFER reslist_buffer;
|
|
|
|
ACPI_OBJECT *reslist_object;
|
|
|
|
ACPI_STATUS status;
|
|
|
|
char *method_name, *reslist_name;
|
|
|
|
int res_changed;
|
|
|
|
|
2002-05-19 06:16:47 +00:00
|
|
|
ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
|
2001-06-28 06:17:16 +00:00
|
|
|
|
2004-04-14 17:58:19 +00:00
|
|
|
/* It's never ok to switch a non-existent consumer. */
|
|
|
|
if (consumer == NULL)
|
|
|
|
return_ACPI_STATUS (AE_NOT_FOUND);
|
|
|
|
|
2003-08-28 16:06:30 +00:00
|
|
|
/* Find the consumer */
|
2001-06-28 06:17:16 +00:00
|
|
|
if ((pc = acpi_pwr_find_consumer(consumer)) == NULL) {
|
2002-02-23 05:28:22 +00:00
|
|
|
if (ACPI_FAILURE(status = acpi_pwr_register_consumer(consumer)))
|
2003-08-28 16:06:30 +00:00
|
|
|
return_ACPI_STATUS (status);
|
2001-06-28 06:17:16 +00:00
|
|
|
if ((pc = acpi_pwr_find_consumer(consumer)) == NULL) {
|
2003-08-28 16:06:30 +00:00
|
|
|
return_ACPI_STATUS (AE_ERROR); /* something very wrong */
|
2001-06-28 06:17:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-08-28 16:06:30 +00:00
|
|
|
/* Check for valid transitions */
|
|
|
|
if (pc->ac_state == ACPI_STATE_D3 && state != ACPI_STATE_D0)
|
|
|
|
return_ACPI_STATUS (AE_BAD_PARAMETER); /* can only go to D0 from D3 */
|
2001-06-28 06:17:16 +00:00
|
|
|
|
2003-08-28 16:06:30 +00:00
|
|
|
/* Find transition mechanism(s) */
|
2004-06-07 21:39:15 +00:00
|
|
|
switch (state) {
|
2001-06-28 06:17:16 +00:00
|
|
|
case ACPI_STATE_D0:
|
|
|
|
method_name = "_PS0";
|
|
|
|
reslist_name = "_PR0";
|
|
|
|
break;
|
|
|
|
case ACPI_STATE_D1:
|
|
|
|
method_name = "_PS1";
|
|
|
|
reslist_name = "_PR1";
|
|
|
|
break;
|
|
|
|
case ACPI_STATE_D2:
|
|
|
|
method_name = "_PS2";
|
|
|
|
reslist_name = "_PR2";
|
|
|
|
break;
|
|
|
|
case ACPI_STATE_D3:
|
|
|
|
method_name = "_PS3";
|
|
|
|
reslist_name = "_PR3";
|
|
|
|
break;
|
|
|
|
default:
|
2003-08-28 16:06:30 +00:00
|
|
|
return_ACPI_STATUS (AE_BAD_PARAMETER);
|
2001-06-28 06:17:16 +00:00
|
|
|
}
|
2001-08-26 22:50:15 +00:00
|
|
|
ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, "setup to switch %s D%d -> D%d\n",
|
2003-08-28 16:06:30 +00:00
|
|
|
acpi_name(consumer), pc->ac_state, state));
|
2001-06-28 06:17:16 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Verify that this state is supported, ie. one of method or
|
|
|
|
* reslist must be present. We need to do this before we go
|
|
|
|
* dereferencing resources (since we might be trying to go to
|
|
|
|
* a state we don't support).
|
|
|
|
*
|
|
|
|
* Note that if any states are supported, the device has to
|
|
|
|
* support D0 and D3. It's never an error to try to go to
|
|
|
|
* D0.
|
|
|
|
*/
|
2004-06-07 21:39:15 +00:00
|
|
|
status = AE_BAD_PARAMETER;
|
2002-02-23 05:28:22 +00:00
|
|
|
reslist_buffer.Pointer = NULL;
|
2001-08-21 18:22:40 +00:00
|
|
|
reslist_object = NULL;
|
2002-02-23 05:28:22 +00:00
|
|
|
if (ACPI_FAILURE(AcpiGetHandle(consumer, method_name, &method_handle)))
|
2001-06-28 06:17:16 +00:00
|
|
|
method_handle = NULL;
|
2002-02-23 05:28:22 +00:00
|
|
|
if (ACPI_FAILURE(AcpiGetHandle(consumer, reslist_name, &reslist_handle)))
|
2001-06-28 06:17:16 +00:00
|
|
|
reslist_handle = NULL;
|
2003-08-28 16:06:30 +00:00
|
|
|
if (reslist_handle == NULL && method_handle == NULL) {
|
2001-06-28 06:17:16 +00:00
|
|
|
if (state == ACPI_STATE_D0) {
|
|
|
|
pc->ac_state = ACPI_STATE_D0;
|
2003-08-28 16:06:30 +00:00
|
|
|
return_ACPI_STATUS (AE_OK);
|
2001-06-28 06:17:16 +00:00
|
|
|
}
|
2003-08-28 16:06:30 +00:00
|
|
|
if (state != ACPI_STATE_D3)
|
2001-08-21 18:22:40 +00:00
|
|
|
goto bad;
|
|
|
|
|
2004-06-07 21:39:15 +00:00
|
|
|
/*
|
|
|
|
* Turn off the resources listed in _PR0 to go to D3. If there is
|
|
|
|
* no _PR0 method, this object doesn't support ACPI power states.
|
|
|
|
*/
|
|
|
|
if (ACPI_FAILURE(AcpiGetHandle(consumer, "_PR0", &pr0_handle))) {
|
|
|
|
status = AE_NOT_FOUND;
|
2001-08-21 18:22:40 +00:00
|
|
|
goto bad;
|
2004-06-07 21:39:15 +00:00
|
|
|
}
|
2002-02-23 05:28:22 +00:00
|
|
|
reslist_buffer.Length = ACPI_ALLOCATE_BUFFER;
|
2003-08-28 16:06:30 +00:00
|
|
|
status = AcpiEvaluateObject(pr0_handle, NULL, NULL, &reslist_buffer);
|
|
|
|
if (ACPI_FAILURE(status))
|
2001-08-21 18:22:40 +00:00
|
|
|
goto bad;
|
|
|
|
reslist_object = (ACPI_OBJECT *)reslist_buffer.Pointer;
|
2003-08-28 16:06:30 +00:00
|
|
|
if (reslist_object->Type != ACPI_TYPE_PACKAGE ||
|
2004-06-07 21:39:15 +00:00
|
|
|
reslist_object->Package.Count == 0)
|
2001-08-21 18:22:40 +00:00
|
|
|
goto bad;
|
2002-02-23 05:28:22 +00:00
|
|
|
AcpiOsFree(reslist_buffer.Pointer);
|
|
|
|
reslist_buffer.Pointer = NULL;
|
|
|
|
reslist_object = NULL;
|
2001-06-28 06:17:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check that we can actually fetch the list of power resources
|
|
|
|
*/
|
|
|
|
if (reslist_handle != NULL) {
|
2002-02-23 05:28:22 +00:00
|
|
|
reslist_buffer.Length = ACPI_ALLOCATE_BUFFER;
|
2003-08-28 16:06:30 +00:00
|
|
|
status = AcpiEvaluateObject(reslist_handle, NULL, NULL,
|
|
|
|
&reslist_buffer);
|
|
|
|
if (ACPI_FAILURE(status)) {
|
|
|
|
ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS,
|
|
|
|
"can't evaluate resource list %s\n",
|
|
|
|
acpi_name(reslist_handle)));
|
2002-02-23 05:28:22 +00:00
|
|
|
goto out;
|
2001-06-28 06:17:16 +00:00
|
|
|
}
|
|
|
|
reslist_object = (ACPI_OBJECT *)reslist_buffer.Pointer;
|
|
|
|
if (reslist_object->Type != ACPI_TYPE_PACKAGE) {
|
2003-08-28 16:06:30 +00:00
|
|
|
ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS,
|
|
|
|
"resource list is not ACPI_TYPE_PACKAGE (%d)\n",
|
|
|
|
reslist_object->Type));
|
2002-02-23 05:28:22 +00:00
|
|
|
status = AE_TYPE;
|
|
|
|
goto out;
|
2001-06-28 06:17:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2004-02-12 20:45:01 +00:00
|
|
|
* Now we are ready to switch, so kill off any current power
|
2003-08-28 16:06:30 +00:00
|
|
|
* resource references.
|
2001-06-28 06:17:16 +00:00
|
|
|
*/
|
2004-06-30 16:02:40 +00:00
|
|
|
res_changed = acpi_pwr_dereference_resource(pc);
|
2001-06-28 06:17:16 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Add new power resource references, if we have any. Traverse the
|
|
|
|
* package that we got from evaluating reslist_handle, and look up each
|
|
|
|
* of the resources that are referenced.
|
|
|
|
*/
|
|
|
|
if (reslist_object != NULL) {
|
2001-08-26 22:50:15 +00:00
|
|
|
ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, "referencing %d new resources\n",
|
|
|
|
reslist_object->Package.Count));
|
2003-08-28 16:06:30 +00:00
|
|
|
acpi_ForeachPackageObject(reslist_object, acpi_pwr_reference_resource,
|
|
|
|
pc);
|
2001-06-28 06:17:16 +00:00
|
|
|
res_changed = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If we changed anything in the resource list, we need to run a switch
|
|
|
|
* pass now.
|
|
|
|
*/
|
2002-02-23 05:28:22 +00:00
|
|
|
if (ACPI_FAILURE(status = acpi_pwr_switch_power())) {
|
2003-08-28 16:06:30 +00:00
|
|
|
ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS,
|
|
|
|
"failed to switch resources from %s to D%d\n",
|
2001-08-26 22:50:15 +00:00
|
|
|
acpi_name(consumer), state));
|
2003-08-28 16:06:30 +00:00
|
|
|
|
|
|
|
/* XXX is this appropriate? Should we return to previous state? */
|
|
|
|
goto out;
|
2001-06-28 06:17:16 +00:00
|
|
|
}
|
|
|
|
|
2003-08-28 16:06:30 +00:00
|
|
|
/* Invoke power state switch method (if present) */
|
2001-06-28 06:17:16 +00:00
|
|
|
if (method_handle != NULL) {
|
2003-08-28 16:06:30 +00:00
|
|
|
ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS,
|
|
|
|
"invoking state transition method %s\n",
|
|
|
|
acpi_name(method_handle)));
|
|
|
|
status = AcpiEvaluateObject(method_handle, NULL, NULL, NULL);
|
|
|
|
if (ACPI_FAILURE(status)) {
|
2002-02-23 05:28:22 +00:00
|
|
|
ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, "failed to set state - %s\n",
|
2003-08-28 16:06:30 +00:00
|
|
|
AcpiFormatException(status)));
|
2002-02-23 05:28:22 +00:00
|
|
|
pc->ac_state = ACPI_STATE_UNKNOWN;
|
2003-08-28 16:06:30 +00:00
|
|
|
|
|
|
|
/* XXX Should we return to previous state? */
|
|
|
|
goto out;
|
2002-02-23 05:28:22 +00:00
|
|
|
}
|
2001-06-28 06:17:16 +00:00
|
|
|
}
|
2002-02-23 05:28:22 +00:00
|
|
|
|
2003-08-28 16:06:30 +00:00
|
|
|
/* Transition was successful */
|
2001-06-28 06:17:16 +00:00
|
|
|
pc->ac_state = state;
|
2003-08-28 16:06:30 +00:00
|
|
|
return_ACPI_STATUS (AE_OK);
|
2001-08-21 18:22:40 +00:00
|
|
|
|
|
|
|
bad:
|
2003-08-28 16:06:30 +00:00
|
|
|
ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS,
|
|
|
|
"attempt to set unsupported state D%d\n", state));
|
2002-02-23 05:28:22 +00:00
|
|
|
|
|
|
|
out:
|
|
|
|
if (reslist_buffer.Pointer != NULL)
|
|
|
|
AcpiOsFree(reslist_buffer.Pointer);
|
2003-08-28 16:06:30 +00:00
|
|
|
return_ACPI_STATUS (status);
|
2001-06-28 06:17:16 +00:00
|
|
|
}
|
|
|
|
|
2004-06-30 16:02:40 +00:00
|
|
|
/* Enable or disable a power resource for wake */
|
|
|
|
ACPI_STATUS
|
|
|
|
acpi_pwr_wake_enable(ACPI_HANDLE consumer, int enable)
|
|
|
|
{
|
|
|
|
ACPI_STATUS status;
|
|
|
|
struct acpi_powerconsumer *pc;
|
|
|
|
struct acpi_prw_data prw;
|
|
|
|
int i;
|
|
|
|
|
2004-06-30 20:31:13 +00:00
|
|
|
ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
|
|
|
|
|
2004-06-30 16:02:40 +00:00
|
|
|
if (consumer == NULL)
|
|
|
|
return (AE_BAD_PARAMETER);
|
|
|
|
|
|
|
|
if ((pc = acpi_pwr_find_consumer(consumer)) == NULL) {
|
|
|
|
if (ACPI_FAILURE(status = acpi_pwr_register_consumer(consumer)))
|
|
|
|
return_ACPI_STATUS (status);
|
|
|
|
if ((pc = acpi_pwr_find_consumer(consumer)) == NULL) {
|
|
|
|
return_ACPI_STATUS (AE_ERROR); /* something very wrong */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (acpi_parse_prw(consumer, &prw) != 0)
|
|
|
|
return (AE_OK);
|
|
|
|
for (i = 0; i < prw.power_res_count; i++)
|
|
|
|
if (enable)
|
|
|
|
acpi_pwr_reference_resource(&prw.power_res[i], pc);
|
|
|
|
else
|
|
|
|
acpi_pwr_dereference_resource(pc);
|
|
|
|
|
|
|
|
if (prw.power_res_count > 0)
|
|
|
|
acpi_pwr_switch_power();
|
|
|
|
|
|
|
|
return (AE_OK);
|
|
|
|
}
|
|
|
|
|
2001-06-28 06:17:16 +00:00
|
|
|
/*
|
|
|
|
* Called to create a reference between a power consumer and a power resource
|
|
|
|
* identified in the object.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
acpi_pwr_reference_resource(ACPI_OBJECT *obj, void *arg)
|
|
|
|
{
|
|
|
|
struct acpi_powerconsumer *pc = (struct acpi_powerconsumer *)arg;
|
2001-07-06 09:00:07 +00:00
|
|
|
struct acpi_powerreference *pr;
|
|
|
|
struct acpi_powerresource *rp;
|
|
|
|
ACPI_HANDLE res;
|
|
|
|
ACPI_STATUS status;
|
2001-06-28 06:17:16 +00:00
|
|
|
|
2002-05-19 06:16:47 +00:00
|
|
|
ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
|
2001-06-28 06:17:16 +00:00
|
|
|
|
2004-04-09 06:55:50 +00:00
|
|
|
res = acpi_GetReference(NULL, obj);
|
|
|
|
if (res == NULL) {
|
2003-08-28 16:06:30 +00:00
|
|
|
ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS,
|
2004-04-09 06:55:50 +00:00
|
|
|
"can't create a power reference for object type %d\n",
|
2003-08-28 16:06:30 +00:00
|
|
|
obj->Type));
|
2001-07-06 09:00:07 +00:00
|
|
|
return_VOID;
|
|
|
|
}
|
|
|
|
|
2003-08-28 16:06:30 +00:00
|
|
|
/* Create/look up the resource */
|
2001-07-06 09:00:07 +00:00
|
|
|
if (ACPI_FAILURE(status = acpi_pwr_register_resource(res))) {
|
2003-08-28 16:06:30 +00:00
|
|
|
ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS,
|
|
|
|
"couldn't register power resource %s - %s\n",
|
|
|
|
obj->String.Pointer, AcpiFormatException(status)));
|
2001-07-06 09:00:07 +00:00
|
|
|
return_VOID;
|
|
|
|
}
|
|
|
|
if ((rp = acpi_pwr_find_resource(res)) == NULL) {
|
2001-08-26 22:50:15 +00:00
|
|
|
ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, "power resource list corrupted\n"));
|
2001-07-06 09:00:07 +00:00
|
|
|
return_VOID;
|
|
|
|
}
|
2003-08-28 16:06:30 +00:00
|
|
|
ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, "found power resource %s\n",
|
|
|
|
acpi_name(rp->ap_resource)));
|
2001-07-06 09:00:07 +00:00
|
|
|
|
2003-08-28 16:06:30 +00:00
|
|
|
/* Create a reference between the consumer and resource */
|
2001-07-06 09:00:07 +00:00
|
|
|
if ((pr = malloc(sizeof(*pr), M_ACPIPWR, M_NOWAIT | M_ZERO)) == NULL) {
|
2003-08-28 16:06:30 +00:00
|
|
|
ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS,
|
|
|
|
"allocation failed for a power consumer reference\n"));
|
2001-07-06 09:00:07 +00:00
|
|
|
return_VOID;
|
|
|
|
}
|
|
|
|
pr->ar_consumer = pc;
|
|
|
|
pr->ar_resource = rp;
|
|
|
|
TAILQ_INSERT_TAIL(&pc->ac_references, pr, ar_clink);
|
|
|
|
TAILQ_INSERT_TAIL(&rp->ap_references, pr, ar_rlink);
|
2004-06-30 16:02:40 +00:00
|
|
|
|
2001-06-28 06:17:16 +00:00
|
|
|
return_VOID;
|
|
|
|
}
|
|
|
|
|
2004-06-30 16:02:40 +00:00
|
|
|
static int
|
|
|
|
acpi_pwr_dereference_resource(struct acpi_powerconsumer *pc)
|
|
|
|
{
|
|
|
|
struct acpi_powerreference *pr;
|
|
|
|
int changed;
|
|
|
|
|
2004-06-30 20:31:13 +00:00
|
|
|
ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
|
|
|
|
|
2004-06-30 16:02:40 +00:00
|
|
|
changed = 0;
|
|
|
|
while ((pr = TAILQ_FIRST(&pc->ac_references)) != NULL) {
|
|
|
|
ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, "removing reference to %s\n",
|
|
|
|
acpi_name(pr->ar_resource->ap_resource)));
|
|
|
|
TAILQ_REMOVE(&pr->ar_resource->ap_references, pr, ar_rlink);
|
|
|
|
TAILQ_REMOVE(&pc->ac_references, pr, ar_clink);
|
|
|
|
free(pr, M_ACPIPWR);
|
|
|
|
changed = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (changed);
|
|
|
|
}
|
2001-06-28 06:17:16 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Switch power resources to conform to the desired state.
|
|
|
|
*
|
|
|
|
* Consumers may have modified the power resource list in an arbitrary
|
|
|
|
* fashion; we sweep it in sequence order.
|
|
|
|
*/
|
|
|
|
static ACPI_STATUS
|
|
|
|
acpi_pwr_switch_power(void)
|
|
|
|
{
|
|
|
|
struct acpi_powerresource *rp;
|
|
|
|
ACPI_STATUS status;
|
|
|
|
int cur;
|
|
|
|
|
2002-05-19 06:16:47 +00:00
|
|
|
ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
|
2001-06-28 06:17:16 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Sweep the list forwards turning things on.
|
|
|
|
*/
|
|
|
|
TAILQ_FOREACH(rp, &acpi_powerresources, ap_link) {
|
2001-07-06 09:00:07 +00:00
|
|
|
if (TAILQ_FIRST(&rp->ap_references) == NULL) {
|
2003-08-28 16:06:30 +00:00
|
|
|
ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS,
|
|
|
|
"%s has no references, not turning on\n",
|
|
|
|
acpi_name(rp->ap_resource)));
|
2001-07-06 09:00:07 +00:00
|
|
|
continue;
|
|
|
|
}
|
2001-06-28 06:17:16 +00:00
|
|
|
|
2003-08-28 16:06:30 +00:00
|
|
|
/* We could cache this if we trusted it not to change under us */
|
2004-03-03 18:34:42 +00:00
|
|
|
status = acpi_GetInteger(rp->ap_resource, "_STA", &cur);
|
2003-08-28 16:06:30 +00:00
|
|
|
if (ACPI_FAILURE(status)) {
|
2001-08-26 22:50:15 +00:00
|
|
|
ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, "can't get status of %s - %d\n",
|
|
|
|
acpi_name(rp->ap_resource), status));
|
2003-08-28 16:06:30 +00:00
|
|
|
|
|
|
|
/* XXX is this correct? Always switch if in doubt? */
|
|
|
|
continue;
|
2001-06-28 06:17:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Switch if required. Note that we ignore the result of the switch
|
|
|
|
* effort; we don't know what to do if it fails, so checking wouldn't
|
|
|
|
* help much.
|
|
|
|
*/
|
2001-07-06 09:00:07 +00:00
|
|
|
if (cur != ACPI_PWR_ON) {
|
2003-08-28 16:06:30 +00:00
|
|
|
status = AcpiEvaluateObject(rp->ap_resource, "_ON", NULL, NULL);
|
|
|
|
if (ACPI_FAILURE(status)) {
|
|
|
|
ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS,
|
|
|
|
"failed to switch %s on - %s\n",
|
|
|
|
acpi_name(rp->ap_resource),
|
|
|
|
AcpiFormatException(status)));
|
2001-07-06 09:00:07 +00:00
|
|
|
} else {
|
2003-08-28 16:06:30 +00:00
|
|
|
ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, "switched %s on\n",
|
|
|
|
acpi_name(rp->ap_resource)));
|
2001-07-06 09:00:07 +00:00
|
|
|
}
|
|
|
|
} else {
|
2003-08-28 16:06:30 +00:00
|
|
|
ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, "%s is already on\n",
|
|
|
|
acpi_name(rp->ap_resource)));
|
2001-07-06 09:00:07 +00:00
|
|
|
}
|
2001-06-28 06:17:16 +00:00
|
|
|
}
|
|
|
|
|
2003-08-28 16:06:30 +00:00
|
|
|
/* Sweep the list backwards turning things off. */
|
|
|
|
TAILQ_FOREACH_REVERSE(rp, &acpi_powerresources, acpi_powerresource_list,
|
|
|
|
ap_link) {
|
|
|
|
|
2001-07-06 09:00:07 +00:00
|
|
|
if (TAILQ_FIRST(&rp->ap_references) != NULL) {
|
2003-08-28 16:06:30 +00:00
|
|
|
ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS,
|
|
|
|
"%s has references, not turning off\n",
|
|
|
|
acpi_name(rp->ap_resource)));
|
2001-07-06 09:00:07 +00:00
|
|
|
continue;
|
|
|
|
}
|
2001-06-28 06:17:16 +00:00
|
|
|
|
2003-08-28 16:06:30 +00:00
|
|
|
/* We could cache this if we trusted it not to change under us */
|
2004-03-03 18:34:42 +00:00
|
|
|
status = acpi_GetInteger(rp->ap_resource, "_STA", &cur);
|
2003-08-28 16:06:30 +00:00
|
|
|
if (ACPI_FAILURE(status)) {
|
2001-08-26 22:50:15 +00:00
|
|
|
ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, "can't get status of %s - %d\n",
|
|
|
|
acpi_name(rp->ap_resource), status));
|
2003-08-28 16:06:30 +00:00
|
|
|
/* XXX is this correct? Always switch if in doubt? */
|
|
|
|
continue;
|
2001-06-28 06:17:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Switch if required. Note that we ignore the result of the switch
|
|
|
|
* effort; we don't know what to do if it fails, so checking wouldn't
|
|
|
|
* help much.
|
|
|
|
*/
|
2001-07-06 09:00:07 +00:00
|
|
|
if (cur != ACPI_PWR_OFF) {
|
2003-08-28 16:06:30 +00:00
|
|
|
status = AcpiEvaluateObject(rp->ap_resource, "_OFF", NULL, NULL);
|
|
|
|
if (ACPI_FAILURE(status)) {
|
|
|
|
ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS,
|
|
|
|
"failed to switch %s off - %s\n",
|
|
|
|
acpi_name(rp->ap_resource),
|
|
|
|
AcpiFormatException(status)));
|
2001-07-06 09:00:07 +00:00
|
|
|
} else {
|
2003-08-28 16:06:30 +00:00
|
|
|
ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, "switched %s off\n",
|
|
|
|
acpi_name(rp->ap_resource)));
|
2001-07-06 09:00:07 +00:00
|
|
|
}
|
|
|
|
} else {
|
2003-08-28 16:06:30 +00:00
|
|
|
ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, "%s is already off\n",
|
|
|
|
acpi_name(rp->ap_resource)));
|
2001-07-06 09:00:07 +00:00
|
|
|
}
|
2001-06-28 06:17:16 +00:00
|
|
|
}
|
2003-08-28 16:06:30 +00:00
|
|
|
|
|
|
|
return_ACPI_STATUS (AE_OK);
|
2001-06-28 06:17:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Find a power resource's control structure.
|
|
|
|
*/
|
|
|
|
static struct acpi_powerresource *
|
|
|
|
acpi_pwr_find_resource(ACPI_HANDLE res)
|
|
|
|
{
|
|
|
|
struct acpi_powerresource *rp;
|
|
|
|
|
2002-05-19 06:16:47 +00:00
|
|
|
ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
|
2001-06-28 06:17:16 +00:00
|
|
|
|
2003-08-28 16:06:30 +00:00
|
|
|
TAILQ_FOREACH(rp, &acpi_powerresources, ap_link) {
|
2001-06-28 06:17:16 +00:00
|
|
|
if (rp->ap_resource == res)
|
|
|
|
break;
|
2003-08-28 16:06:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return_PTR (rp);
|
2001-06-28 06:17:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Find a power consumer's control structure.
|
|
|
|
*/
|
|
|
|
static struct acpi_powerconsumer *
|
|
|
|
acpi_pwr_find_consumer(ACPI_HANDLE consumer)
|
|
|
|
{
|
|
|
|
struct acpi_powerconsumer *pc;
|
|
|
|
|
2002-05-19 06:16:47 +00:00
|
|
|
ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
|
2001-06-28 06:17:16 +00:00
|
|
|
|
2003-08-28 16:06:30 +00:00
|
|
|
TAILQ_FOREACH(pc, &acpi_powerconsumers, ac_link) {
|
2001-06-28 06:17:16 +00:00
|
|
|
if (pc->ac_consumer == consumer)
|
|
|
|
break;
|
2003-08-28 16:06:30 +00:00
|
|
|
}
|
2001-06-28 06:17:16 +00:00
|
|
|
|
2003-08-28 16:06:30 +00:00
|
|
|
return_PTR (pc);
|
|
|
|
}
|