2 * Copyright (c) 2001 Michael Smith
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 * __FBSDID("$FreeBSD: src/sys/dev/acpica/acpi_powerres.c,v 1.30.8.1 2009/04/15 03:14:26 kensmith Exp $");
28 #include <sys/cdefs.h>
31 #include <sys/param.h>
32 #include <sys/kernel.h>
33 #include <sys/malloc.h>
37 #include <dev/acpica5/acpivar.h>
40 * ACPI power resource management.
42 * Power resource behaviour is slightly complicated by the fact that
43 * a single power resource may provide power for more than one device.
44 * Thus, we must track the device(s) being powered by a given power
45 * resource, and only deactivate it when there are no powered devices.
47 * Note that this only manages resources for known devices. There is an
48 * ugly case where we may turn of power to a device which is in use because
49 * we don't know that it depends on a given resource. We should perhaps
50 * try to be smarter about this, but a more complete solution would involve
51 * scanning all of the ACPI namespace to find devices we're not currently
52 * aware of, and this raises questions about whether they should be left
53 * on, turned off, etc.
56 MALLOC_DEFINE(M_ACPIPWR, "acpipwr", "ACPI power resources");
58 /* Hooks for the ACPI CA debugging infrastructure */
59 #define _COMPONENT ACPI_POWERRES
60 ACPI_MODULE_NAME("POWERRES")
62 /* Return values from _STA on a power resource */
63 #define ACPI_PWR_OFF 0
65 #define ACPI_PWR_UNK (-1)
67 /* A relationship between a power resource and a consumer. */
68 struct acpi_powerreference {
69 struct acpi_powerconsumer *ar_consumer;
70 struct acpi_powerresource *ar_resource;
71 TAILQ_ENTRY(acpi_powerreference) ar_rlink; /* link on resource list */
72 TAILQ_ENTRY(acpi_powerreference) ar_clink; /* link on consumer */
75 /* A power-managed device. */
76 struct acpi_powerconsumer {
77 /* Device which is powered */
78 ACPI_HANDLE ac_consumer;
80 TAILQ_ENTRY(acpi_powerconsumer) ac_link;
81 TAILQ_HEAD(,acpi_powerreference) ac_references;
84 /* A power resource. */
85 struct acpi_powerresource {
86 TAILQ_ENTRY(acpi_powerresource) ap_link;
87 TAILQ_HEAD(,acpi_powerreference) ap_references;
88 ACPI_HANDLE ap_resource;
89 ACPI_INTEGER ap_systemlevel;
90 ACPI_INTEGER ap_order;
94 static TAILQ_HEAD(acpi_powerresource_list, acpi_powerresource)
96 static TAILQ_HEAD(acpi_powerconsumer_list, acpi_powerconsumer)
98 ACPI_SERIAL_DECL(powerres, "ACPI power resources");
100 static ACPI_STATUS acpi_pwr_register_consumer(ACPI_HANDLE consumer);
102 static ACPI_STATUS acpi_pwr_deregister_consumer(ACPI_HANDLE consumer);
104 static ACPI_STATUS acpi_pwr_register_resource(ACPI_HANDLE res);
106 static ACPI_STATUS acpi_pwr_deregister_resource(ACPI_HANDLE res);
108 static void acpi_pwr_reference_resource(ACPI_OBJECT *obj,
110 static int acpi_pwr_dereference_resource(struct acpi_powerconsumer
112 static ACPI_STATUS acpi_pwr_switch_power(void);
113 static struct acpi_powerresource
114 *acpi_pwr_find_resource(ACPI_HANDLE res);
115 static struct acpi_powerconsumer
116 *acpi_pwr_find_consumer(ACPI_HANDLE consumer);
118 /* Initialise our lists. */
120 acpi_pwr_init(void *junk)
122 ACPI_SERIAL_INIT(powerres);
123 TAILQ_INIT(&acpi_powerresources);
124 TAILQ_INIT(&acpi_powerconsumers);
126 SYSINIT(acpi_powerresource, SI_BOOT1_TUNABLES, SI_ORDER_ANY, acpi_pwr_init, NULL);
129 * Register a power resource.
131 * It's OK to call this if we already know about the resource.
134 acpi_pwr_register_resource(ACPI_HANDLE res)
139 struct acpi_powerresource *rp, *srp;
141 ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
142 ACPI_SERIAL_ASSERT(powerres);
147 /* Look to see if we know about this resource */
148 if (acpi_pwr_find_resource(res) != NULL)
149 return_ACPI_STATUS (AE_OK); /* already know about it */
151 /* Allocate a new resource */
152 if ((rp = kmalloc(sizeof(*rp), M_ACPIPWR, M_NOWAIT | M_ZERO)) == NULL) {
153 status = AE_NO_MEMORY;
156 TAILQ_INIT(&rp->ap_references);
157 rp->ap_resource = res;
159 /* Get the Power Resource object */
160 buf.Length = ACPI_ALLOCATE_BUFFER;
161 if (ACPI_FAILURE(status = AcpiEvaluateObject(res, NULL, NULL, &buf))) {
162 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, "no power resource object\n"));
166 if (obj->Type != ACPI_TYPE_POWER) {
167 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS,
168 "questionable power resource object %s\n",
173 rp->ap_systemlevel = obj->PowerResource.SystemLevel;
174 rp->ap_order = obj->PowerResource.ResourceOrder;
175 rp->ap_state = ACPI_PWR_UNK;
177 /* Sort the resource into the list */
179 srp = TAILQ_FIRST(&acpi_powerresources);
180 if (srp == NULL || rp->ap_order < srp->ap_order) {
181 TAILQ_INSERT_HEAD(&acpi_powerresources, rp, ap_link);
184 TAILQ_FOREACH(srp, &acpi_powerresources, ap_link) {
185 if (rp->ap_order < srp->ap_order) {
186 TAILQ_INSERT_BEFORE(srp, rp, ap_link);
190 TAILQ_INSERT_TAIL(&acpi_powerresources, rp, ap_link);
193 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS,
194 "registered power resource %s\n", acpi_name(res)));
197 if (buf.Pointer != NULL)
198 AcpiOsFree(buf.Pointer);
199 if (ACPI_FAILURE(status) && rp != NULL)
200 kfree(rp, M_ACPIPWR);
201 return_ACPI_STATUS (status);
206 * Deregister a power resource.
209 acpi_pwr_deregister_resource(ACPI_HANDLE res)
211 struct acpi_powerresource *rp;
213 ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
214 ACPI_SERIAL_ASSERT(powerres);
218 /* Find the resource */
219 if ((rp = acpi_pwr_find_resource(res)) == NULL)
220 return_ACPI_STATUS (AE_BAD_PARAMETER);
222 /* Check that there are no consumers referencing this resource */
223 if (TAILQ_FIRST(&rp->ap_references) != NULL)
224 return_ACPI_STATUS (AE_BAD_PARAMETER);
226 /* Pull it off the list and kfree it */
227 TAILQ_REMOVE(&acpi_powerresources, rp, ap_link);
228 kfree(rp, M_ACPIPWR);
230 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, "deregistered power resource %s\n",
233 return_ACPI_STATUS (AE_OK);
238 * Register a power consumer.
240 * It's OK to call this if we already know about the consumer.
243 acpi_pwr_register_consumer(ACPI_HANDLE consumer)
245 struct acpi_powerconsumer *pc;
247 ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
248 ACPI_SERIAL_ASSERT(powerres);
250 /* Check to see whether we know about this consumer already */
251 if (acpi_pwr_find_consumer(consumer) != NULL)
252 return_ACPI_STATUS (AE_OK);
254 /* Allocate a new power consumer */
255 if ((pc = kmalloc(sizeof(*pc), M_ACPIPWR, M_NOWAIT)) == NULL)
256 return_ACPI_STATUS (AE_NO_MEMORY);
257 TAILQ_INSERT_HEAD(&acpi_powerconsumers, pc, ac_link);
258 TAILQ_INIT(&pc->ac_references);
259 pc->ac_consumer = consumer;
261 /* XXX we should try to find its current state */
262 pc->ac_state = ACPI_STATE_UNKNOWN;
264 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, "registered power consumer %s\n",
265 acpi_name(consumer)));
267 return_ACPI_STATUS (AE_OK);
272 * Deregister a power consumer.
274 * This should only be done once the consumer has been powered off.
275 * (XXX is this correct? Check once implemented)
278 acpi_pwr_deregister_consumer(ACPI_HANDLE consumer)
280 struct acpi_powerconsumer *pc;
282 ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
283 ACPI_SERIAL_ASSERT(powerres);
285 /* Find the consumer */
286 if ((pc = acpi_pwr_find_consumer(consumer)) == NULL)
287 return_ACPI_STATUS (AE_BAD_PARAMETER);
289 /* Make sure the consumer's not referencing anything right now */
290 if (TAILQ_FIRST(&pc->ac_references) != NULL)
291 return_ACPI_STATUS (AE_BAD_PARAMETER);
293 /* Pull the consumer off the list and kfree it */
294 TAILQ_REMOVE(&acpi_powerconsumers, pc, ac_link);
295 kfree(pc, M_ACPIPWR);
297 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, "deregistered power consumer %s\n",
298 acpi_name(consumer)));
300 return_ACPI_STATUS (AE_OK);
305 * Set a power consumer to a particular power state.
308 acpi_pwr_switch_consumer(ACPI_HANDLE consumer, int state)
310 struct acpi_powerconsumer *pc;
311 ACPI_HANDLE method_handle, reslist_handle, pr0_handle;
312 ACPI_BUFFER reslist_buffer;
313 ACPI_OBJECT *reslist_object;
315 char *method_name, *reslist_name;
318 ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
320 /* It's never ok to switch a non-existent consumer. */
321 if (consumer == NULL)
322 return_ACPI_STATUS (AE_NOT_FOUND);
323 reslist_buffer.Pointer = NULL;
324 reslist_object = NULL;
325 ACPI_SERIAL_BEGIN(powerres);
327 /* Find the consumer */
328 if ((pc = acpi_pwr_find_consumer(consumer)) == NULL) {
329 if (ACPI_FAILURE(status = acpi_pwr_register_consumer(consumer)))
331 if ((pc = acpi_pwr_find_consumer(consumer)) == NULL)
332 panic("acpi added power consumer but can't find it");
335 /* Check for valid transitions. We can only go to D0 from D3. */
336 status = AE_BAD_PARAMETER;
337 if (pc->ac_state == ACPI_STATE_D3 && state != ACPI_STATE_D0)
340 /* Find transition mechanism(s) */
343 method_name = "_PS0";
344 reslist_name = "_PR0";
347 method_name = "_PS1";
348 reslist_name = "_PR1";
351 method_name = "_PS2";
352 reslist_name = "_PR2";
355 method_name = "_PS3";
356 reslist_name = "_PR3";
361 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, "setup to switch %s D%d -> D%d\n",
362 acpi_name(consumer), pc->ac_state, state));
365 * Verify that this state is supported, ie. one of method or
366 * reslist must be present. We need to do this before we go
367 * dereferencing resources (since we might be trying to go to
368 * a state we don't support).
370 * Note that if any states are supported, the device has to
371 * support D0 and D3. It's never an error to try to go to
374 if (ACPI_FAILURE(AcpiGetHandle(consumer, method_name, &method_handle)))
375 method_handle = NULL;
376 if (ACPI_FAILURE(AcpiGetHandle(consumer, reslist_name, &reslist_handle)))
377 reslist_handle = NULL;
378 if (reslist_handle == NULL && method_handle == NULL) {
379 if (state == ACPI_STATE_D0) {
380 pc->ac_state = ACPI_STATE_D0;
384 if (state != ACPI_STATE_D3) {
385 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS,
386 "attempt to set unsupported state D%d\n", state));
391 * Turn off the resources listed in _PR0 to go to D3. If there is
392 * no _PR0 method, this object doesn't support ACPI power states.
394 if (ACPI_FAILURE(AcpiGetHandle(consumer, "_PR0", &pr0_handle))) {
395 status = AE_NOT_FOUND;
396 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS,
397 "device missing _PR0 (desired state was D%d)\n", state));
400 reslist_buffer.Length = ACPI_ALLOCATE_BUFFER;
401 status = AcpiEvaluateObject(pr0_handle, NULL, NULL, &reslist_buffer);
402 if (ACPI_FAILURE(status)) {
403 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS,
404 "can't evaluate _PR0 for device %s, state D%d\n",
405 acpi_name(consumer), state));
408 reslist_object = (ACPI_OBJECT *)reslist_buffer.Pointer;
409 if (!ACPI_PKG_VALID(reslist_object, 1)) {
410 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS,
411 "invalid package object for state D%d\n", state));
415 AcpiOsFree(reslist_buffer.Pointer);
416 reslist_buffer.Pointer = NULL;
417 reslist_object = NULL;
421 * Check that we can actually fetch the list of power resources
423 if (reslist_handle != NULL) {
424 reslist_buffer.Length = ACPI_ALLOCATE_BUFFER;
425 status = AcpiEvaluateObject(reslist_handle, NULL, NULL,
427 if (ACPI_FAILURE(status)) {
428 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS,
429 "can't evaluate resource list %s\n",
430 acpi_name(reslist_handle)));
433 reslist_object = (ACPI_OBJECT *)reslist_buffer.Pointer;
434 if (reslist_object->Type != ACPI_TYPE_PACKAGE) {
435 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS,
436 "resource list is not ACPI_TYPE_PACKAGE (%d)\n",
437 reslist_object->Type));
444 * Now we are ready to switch, so kill off any current power
445 * resource references.
447 res_changed = acpi_pwr_dereference_resource(pc);
450 * Add new power resource references, if we have any. Traverse the
451 * package that we got from evaluating reslist_handle, and look up each
452 * of the resources that are referenced.
454 if (reslist_object != NULL) {
455 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, "referencing %d new resources\n",
456 reslist_object->Package.Count));
457 acpi_ForeachPackageObject(reslist_object, acpi_pwr_reference_resource,
463 * If we changed anything in the resource list, we need to run a switch
466 if (ACPI_FAILURE(status = acpi_pwr_switch_power())) {
467 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS,
468 "failed to switch resources from %s to D%d\n",
469 acpi_name(consumer), state));
471 /* XXX is this appropriate? Should we return to previous state? */
475 /* Invoke power state switch method (if present) */
476 if (method_handle != NULL) {
477 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS,
478 "invoking state transition method %s\n",
479 acpi_name(method_handle)));
480 status = AcpiEvaluateObject(method_handle, NULL, NULL, NULL);
481 if (ACPI_FAILURE(status)) {
482 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, "failed to set state - %s\n",
483 AcpiFormatException(status)));
484 pc->ac_state = ACPI_STATE_UNKNOWN;
486 /* XXX Should we return to previous state? */
491 /* Transition was successful */
492 pc->ac_state = state;
496 ACPI_SERIAL_END(powerres);
497 if (reslist_buffer.Pointer != NULL)
498 AcpiOsFree(reslist_buffer.Pointer);
499 return_ACPI_STATUS (status);
502 /* Enable or disable a power resource for wake */
504 acpi_pwr_wake_enable(ACPI_HANDLE consumer, int enable)
507 struct acpi_powerconsumer *pc;
508 struct acpi_prw_data prw;
511 ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
513 if (consumer == NULL)
514 return (AE_BAD_PARAMETER);
516 ACPI_SERIAL_BEGIN(powerres);
517 if ((pc = acpi_pwr_find_consumer(consumer)) == NULL) {
518 if (ACPI_FAILURE(status = acpi_pwr_register_consumer(consumer)))
520 if ((pc = acpi_pwr_find_consumer(consumer)) == NULL)
521 panic("acpi wake added power consumer but can't find it");
525 if (acpi_parse_prw(consumer, &prw) != 0)
527 for (i = 0; i < prw.power_res_count; i++)
529 acpi_pwr_reference_resource(&prw.power_res[i], pc);
531 acpi_pwr_dereference_resource(pc);
533 if (prw.power_res_count > 0)
534 acpi_pwr_switch_power();
537 ACPI_SERIAL_END(powerres);
542 * Called to create a reference between a power consumer and a power resource
543 * identified in the object.
546 acpi_pwr_reference_resource(ACPI_OBJECT *obj, void *arg)
548 struct acpi_powerconsumer *pc = (struct acpi_powerconsumer *)arg;
549 struct acpi_powerreference *pr;
550 struct acpi_powerresource *rp;
554 ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
555 ACPI_SERIAL_ASSERT(powerres);
557 res = acpi_GetReference(NULL, obj);
559 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS,
560 "can't create a power reference for object type %d\n",
565 /* Create/look up the resource */
566 if (ACPI_FAILURE(status = acpi_pwr_register_resource(res))) {
567 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS,
568 "couldn't register power resource %s - %s\n",
569 obj->String.Pointer, AcpiFormatException(status)));
572 if ((rp = acpi_pwr_find_resource(res)) == NULL) {
573 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, "power resource list corrupted\n"));
576 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, "found power resource %s\n",
577 acpi_name(rp->ap_resource)));
579 /* Create a reference between the consumer and resource */
580 if ((pr = kmalloc(sizeof(*pr), M_ACPIPWR, M_NOWAIT | M_ZERO)) == NULL) {
581 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS,
582 "allocation failed for a power consumer reference\n"));
585 pr->ar_consumer = pc;
586 pr->ar_resource = rp;
587 TAILQ_INSERT_TAIL(&pc->ac_references, pr, ar_clink);
588 TAILQ_INSERT_TAIL(&rp->ap_references, pr, ar_rlink);
594 acpi_pwr_dereference_resource(struct acpi_powerconsumer *pc)
596 struct acpi_powerreference *pr;
599 ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
600 ACPI_SERIAL_ASSERT(powerres);
603 while ((pr = TAILQ_FIRST(&pc->ac_references)) != NULL) {
604 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, "removing reference to %s\n",
605 acpi_name(pr->ar_resource->ap_resource)));
606 TAILQ_REMOVE(&pr->ar_resource->ap_references, pr, ar_rlink);
607 TAILQ_REMOVE(&pc->ac_references, pr, ar_clink);
608 kfree(pr, M_ACPIPWR);
616 * Switch power resources to conform to the desired state.
618 * Consumers may have modified the power resource list in an arbitrary
619 * fashion; we sweep it in sequence order.
622 acpi_pwr_switch_power(void)
624 struct acpi_powerresource *rp;
628 ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
629 ACPI_SERIAL_ASSERT(powerres);
632 * Sweep the list forwards turning things on.
634 TAILQ_FOREACH(rp, &acpi_powerresources, ap_link) {
635 if (TAILQ_FIRST(&rp->ap_references) == NULL) {
636 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS,
637 "%s has no references, not turning on\n",
638 acpi_name(rp->ap_resource)));
642 /* We could cache this if we trusted it not to change under us */
643 status = acpi_GetInteger(rp->ap_resource, "_STA", &cur);
644 if (ACPI_FAILURE(status)) {
645 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, "can't get status of %s - %d\n",
646 acpi_name(rp->ap_resource), status));
647 /* XXX is this correct? Always switch if in doubt? */
649 } else if (rp->ap_state == ACPI_PWR_UNK)
653 * Switch if required. Note that we ignore the result of the switch
654 * effort; we don't know what to do if it fails, so checking wouldn't
657 if (rp->ap_state != ACPI_PWR_ON) {
658 status = AcpiEvaluateObject(rp->ap_resource, "_ON", NULL, NULL);
659 if (ACPI_FAILURE(status)) {
660 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS,
661 "failed to switch %s on - %s\n",
662 acpi_name(rp->ap_resource),
663 AcpiFormatException(status)));
665 rp->ap_state = ACPI_PWR_ON;
666 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, "switched %s on\n",
667 acpi_name(rp->ap_resource)));
670 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, "%s is already on\n",
671 acpi_name(rp->ap_resource)));
675 /* Sweep the list backwards turning things off. */
676 TAILQ_FOREACH_REVERSE(rp, &acpi_powerresources, acpi_powerresource_list,
679 if (TAILQ_FIRST(&rp->ap_references) != NULL) {
680 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS,
681 "%s has references, not turning off\n",
682 acpi_name(rp->ap_resource)));
686 /* We could cache this if we trusted it not to change under us */
687 status = acpi_GetInteger(rp->ap_resource, "_STA", &cur);
688 if (ACPI_FAILURE(status)) {
689 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, "can't get status of %s - %d\n",
690 acpi_name(rp->ap_resource), status));
691 /* XXX is this correct? Always switch if in doubt? */
693 } else if (rp->ap_state == ACPI_PWR_UNK)
697 * Switch if required. Note that we ignore the result of the switch
698 * effort; we don't know what to do if it fails, so checking wouldn't
701 if (rp->ap_state != ACPI_PWR_OFF) {
702 status = AcpiEvaluateObject(rp->ap_resource, "_OFF", NULL, NULL);
703 if (ACPI_FAILURE(status)) {
704 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS,
705 "failed to switch %s off - %s\n",
706 acpi_name(rp->ap_resource),
707 AcpiFormatException(status)));
709 rp->ap_state = ACPI_PWR_OFF;
710 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, "switched %s off\n",
711 acpi_name(rp->ap_resource)));
714 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, "%s is already off\n",
715 acpi_name(rp->ap_resource)));
719 return_ACPI_STATUS (AE_OK);
723 * Find a power resource's control structure.
725 static struct acpi_powerresource *
726 acpi_pwr_find_resource(ACPI_HANDLE res)
728 struct acpi_powerresource *rp;
730 ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
731 ACPI_SERIAL_ASSERT(powerres);
733 TAILQ_FOREACH(rp, &acpi_powerresources, ap_link) {
734 if (rp->ap_resource == res)
742 * Find a power consumer's control structure.
744 static struct acpi_powerconsumer *
745 acpi_pwr_find_consumer(ACPI_HANDLE consumer)
747 struct acpi_powerconsumer *pc;
749 ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
750 ACPI_SERIAL_ASSERT(powerres);
752 TAILQ_FOREACH(pc, &acpi_powerconsumers, ac_link) {
753 if (pc->ac_consumer == consumer)