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
27 #include <sys/cdefs.h>
28 __FBSDID("$FreeBSD$");
31 #include <sys/param.h>
32 #include <sys/kernel.h>
33 #include <sys/malloc.h>
36 #include <contrib/dev/acpica/include/acpi.h>
37 #include <contrib/dev/acpica/include/accommon.h>
39 #include <dev/acpica/acpivar.h>
42 * ACPI power resource management.
44 * Power resource behaviour is slightly complicated by the fact that
45 * a single power resource may provide power for more than one device.
46 * Thus, we must track the device(s) being powered by a given power
47 * resource, and only deactivate it when there are no powered devices.
49 * Note that this only manages resources for known devices. There is an
50 * ugly case where we may turn off power to a device which is in use because
51 * we don't know that it depends on a given resource. We should perhaps
52 * try to be smarter about this, but a more complete solution would involve
53 * scanning all of the ACPI namespace to find devices we're not currently
54 * aware of, and this raises questions about whether they should be left
55 * on, turned off, etc.
58 static MALLOC_DEFINE(M_ACPIPWR, "acpipwr", "ACPI power resources");
60 /* Hooks for the ACPI CA debugging infrastructure */
61 #define _COMPONENT ACPI_POWERRES
62 ACPI_MODULE_NAME("POWERRES")
64 /* Return values from _STA on a power resource */
65 #define ACPI_PWR_OFF 0
67 #define ACPI_PWR_UNK (-1)
69 /* A relationship between a power resource and a consumer. */
70 struct acpi_powerreference {
71 struct acpi_powerconsumer *ar_consumer;
72 struct acpi_powerresource *ar_resource;
73 TAILQ_ENTRY(acpi_powerreference) ar_rlink; /* link on resource list */
74 TAILQ_ENTRY(acpi_powerreference) ar_clink; /* link on consumer */
77 /* A power-managed device. */
78 struct acpi_powerconsumer {
79 /* Device which is powered */
80 ACPI_HANDLE ac_consumer;
82 TAILQ_ENTRY(acpi_powerconsumer) ac_link;
83 TAILQ_HEAD(,acpi_powerreference) ac_references;
86 /* A power resource. */
87 struct acpi_powerresource {
88 TAILQ_ENTRY(acpi_powerresource) ap_link;
89 TAILQ_HEAD(,acpi_powerreference) ap_references;
90 ACPI_HANDLE ap_resource;
91 UINT64 ap_systemlevel;
96 static TAILQ_HEAD(acpi_powerresource_list, acpi_powerresource)
98 static TAILQ_HEAD(acpi_powerconsumer_list, acpi_powerconsumer)
100 ACPI_SERIAL_DECL(powerres, "ACPI power resources");
102 static ACPI_STATUS acpi_pwr_register_consumer(ACPI_HANDLE consumer);
104 static ACPI_STATUS acpi_pwr_deregister_consumer(ACPI_HANDLE consumer);
106 static ACPI_STATUS acpi_pwr_register_resource(ACPI_HANDLE res);
108 static ACPI_STATUS acpi_pwr_deregister_resource(ACPI_HANDLE res);
110 static void acpi_pwr_reference_resource(ACPI_OBJECT *obj,
112 static int acpi_pwr_dereference_resource(struct acpi_powerconsumer
114 static ACPI_STATUS acpi_pwr_switch_power(void);
115 static struct acpi_powerresource
116 *acpi_pwr_find_resource(ACPI_HANDLE res);
117 static struct acpi_powerconsumer
118 *acpi_pwr_find_consumer(ACPI_HANDLE consumer);
120 /* Initialise our lists. */
122 acpi_pwr_init(void *junk)
124 TAILQ_INIT(&acpi_powerresources);
125 TAILQ_INIT(&acpi_powerconsumers);
127 SYSINIT(acpi_powerresource, SI_SUB_TUNABLES, SI_ORDER_ANY, acpi_pwr_init, NULL);
130 * Register a power resource.
132 * It's OK to call this if we already know about the resource.
135 acpi_pwr_register_resource(ACPI_HANDLE res)
140 struct acpi_powerresource *rp, *srp;
142 ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
143 ACPI_SERIAL_ASSERT(powerres);
148 /* Look to see if we know about this resource */
149 if (acpi_pwr_find_resource(res) != NULL)
150 return_ACPI_STATUS (AE_OK); /* already know about it */
152 /* Allocate a new resource */
153 if ((rp = malloc(sizeof(*rp), M_ACPIPWR, M_NOWAIT | M_ZERO)) == NULL) {
154 status = AE_NO_MEMORY;
157 TAILQ_INIT(&rp->ap_references);
158 rp->ap_resource = res;
160 /* Get the Power Resource object */
161 buf.Length = ACPI_ALLOCATE_BUFFER;
162 if (ACPI_FAILURE(status = AcpiEvaluateObject(res, NULL, NULL, &buf))) {
163 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, "no power resource object\n"));
167 if (obj->Type != ACPI_TYPE_POWER) {
168 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS,
169 "questionable power resource object %s\n",
174 rp->ap_systemlevel = obj->PowerResource.SystemLevel;
175 rp->ap_order = obj->PowerResource.ResourceOrder;
176 rp->ap_state = ACPI_PWR_UNK;
178 /* Sort the resource into the list */
180 srp = TAILQ_FIRST(&acpi_powerresources);
181 if (srp == NULL || rp->ap_order < srp->ap_order) {
182 TAILQ_INSERT_HEAD(&acpi_powerresources, rp, ap_link);
185 TAILQ_FOREACH(srp, &acpi_powerresources, ap_link) {
186 if (rp->ap_order < srp->ap_order) {
187 TAILQ_INSERT_BEFORE(srp, rp, ap_link);
191 TAILQ_INSERT_TAIL(&acpi_powerresources, rp, ap_link);
194 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS,
195 "registered power resource %s\n", acpi_name(res)));
198 if (buf.Pointer != NULL)
199 AcpiOsFree(buf.Pointer);
200 if (ACPI_FAILURE(status) && rp != NULL)
202 return_ACPI_STATUS (status);
207 * Deregister a power resource.
210 acpi_pwr_deregister_resource(ACPI_HANDLE res)
212 struct acpi_powerresource *rp;
214 ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
215 ACPI_SERIAL_ASSERT(powerres);
219 /* Find the resource */
220 if ((rp = acpi_pwr_find_resource(res)) == NULL)
221 return_ACPI_STATUS (AE_BAD_PARAMETER);
223 /* Check that there are no consumers referencing this resource */
224 if (TAILQ_FIRST(&rp->ap_references) != NULL)
225 return_ACPI_STATUS (AE_BAD_PARAMETER);
227 /* Pull it off the list and free it */
228 TAILQ_REMOVE(&acpi_powerresources, rp, ap_link);
231 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, "deregistered power resource %s\n",
234 return_ACPI_STATUS (AE_OK);
239 * Register a power consumer.
241 * It's OK to call this if we already know about the consumer.
244 acpi_pwr_register_consumer(ACPI_HANDLE consumer)
246 struct acpi_powerconsumer *pc;
248 ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
249 ACPI_SERIAL_ASSERT(powerres);
251 /* Check to see whether we know about this consumer already */
252 if (acpi_pwr_find_consumer(consumer) != NULL)
253 return_ACPI_STATUS (AE_OK);
255 /* Allocate a new power consumer */
256 if ((pc = malloc(sizeof(*pc), M_ACPIPWR, M_NOWAIT)) == NULL)
257 return_ACPI_STATUS (AE_NO_MEMORY);
258 TAILQ_INSERT_HEAD(&acpi_powerconsumers, pc, ac_link);
259 TAILQ_INIT(&pc->ac_references);
260 pc->ac_consumer = consumer;
262 /* XXX we should try to find its current state */
263 pc->ac_state = ACPI_STATE_UNKNOWN;
265 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, "registered power consumer %s\n",
266 acpi_name(consumer)));
268 return_ACPI_STATUS (AE_OK);
273 * Deregister a power consumer.
275 * This should only be done once the consumer has been powered off.
276 * (XXX is this correct? Check once implemented)
279 acpi_pwr_deregister_consumer(ACPI_HANDLE consumer)
281 struct acpi_powerconsumer *pc;
283 ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
284 ACPI_SERIAL_ASSERT(powerres);
286 /* Find the consumer */
287 if ((pc = acpi_pwr_find_consumer(consumer)) == NULL)
288 return_ACPI_STATUS (AE_BAD_PARAMETER);
290 /* Make sure the consumer's not referencing anything right now */
291 if (TAILQ_FIRST(&pc->ac_references) != NULL)
292 return_ACPI_STATUS (AE_BAD_PARAMETER);
294 /* Pull the consumer off the list and free it */
295 TAILQ_REMOVE(&acpi_powerconsumers, pc, ac_link);
298 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, "deregistered power consumer %s\n",
299 acpi_name(consumer)));
301 return_ACPI_STATUS (AE_OK);
306 * Set a power consumer to a particular power state.
309 acpi_pwr_switch_consumer(ACPI_HANDLE consumer, int state)
311 struct acpi_powerconsumer *pc;
312 ACPI_HANDLE method_handle, reslist_handle, pr0_handle;
313 ACPI_BUFFER reslist_buffer;
314 ACPI_OBJECT *reslist_object;
316 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 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,
462 * If we changed anything in the resource list, we need to run a switch
465 if (ACPI_FAILURE(status = acpi_pwr_switch_power())) {
466 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS,
467 "failed to switch resources from %s to D%d\n",
468 acpi_name(consumer), state));
470 /* XXX is this appropriate? Should we return to previous state? */
474 /* Invoke power state switch method (if present) */
475 if (method_handle != NULL) {
476 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS,
477 "invoking state transition method %s\n",
478 acpi_name(method_handle)));
479 status = AcpiEvaluateObject(method_handle, NULL, NULL, NULL);
480 if (ACPI_FAILURE(status)) {
481 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, "failed to set state - %s\n",
482 AcpiFormatException(status)));
483 pc->ac_state = ACPI_STATE_UNKNOWN;
485 /* XXX Should we return to previous state? */
490 /* Transition was successful */
491 pc->ac_state = state;
495 ACPI_SERIAL_END(powerres);
496 if (reslist_buffer.Pointer != NULL)
497 AcpiOsFree(reslist_buffer.Pointer);
498 return_ACPI_STATUS (status);
501 /* Enable or disable a power resource for wake */
503 acpi_pwr_wake_enable(ACPI_HANDLE consumer, int enable)
506 struct acpi_powerconsumer *pc;
507 struct acpi_prw_data prw;
510 ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
512 if (consumer == NULL)
513 return (AE_BAD_PARAMETER);
515 ACPI_SERIAL_BEGIN(powerres);
516 if ((pc = acpi_pwr_find_consumer(consumer)) == NULL) {
517 if (ACPI_FAILURE(status = acpi_pwr_register_consumer(consumer)))
519 if ((pc = acpi_pwr_find_consumer(consumer)) == NULL)
520 panic("acpi wake added power consumer but can't find it");
524 if (acpi_parse_prw(consumer, &prw) != 0)
526 for (i = 0; i < prw.power_res_count; i++)
528 acpi_pwr_reference_resource(&prw.power_res[i], pc);
530 acpi_pwr_dereference_resource(pc);
532 if (prw.power_res_count > 0)
533 acpi_pwr_switch_power();
536 ACPI_SERIAL_END(powerres);
541 * Called to create a reference between a power consumer and a power resource
542 * identified in the object.
545 acpi_pwr_reference_resource(ACPI_OBJECT *obj, void *arg)
547 struct acpi_powerconsumer *pc = (struct acpi_powerconsumer *)arg;
548 struct acpi_powerreference *pr;
549 struct acpi_powerresource *rp;
553 ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
554 ACPI_SERIAL_ASSERT(powerres);
556 res = acpi_GetReference(NULL, obj);
558 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS,
559 "can't create a power reference for object type %d\n",
564 /* Create/look up the resource */
565 if (ACPI_FAILURE(status = acpi_pwr_register_resource(res))) {
566 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS,
567 "couldn't register power resource %s - %s\n",
568 obj->String.Pointer, AcpiFormatException(status)));
571 if ((rp = acpi_pwr_find_resource(res)) == NULL) {
572 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, "power resource list corrupted\n"));
575 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, "found power resource %s\n",
576 acpi_name(rp->ap_resource)));
578 /* Create a reference between the consumer and resource */
579 if ((pr = malloc(sizeof(*pr), M_ACPIPWR, M_NOWAIT | M_ZERO)) == NULL) {
580 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS,
581 "allocation failed for a power consumer reference\n"));
584 pr->ar_consumer = pc;
585 pr->ar_resource = rp;
586 TAILQ_INSERT_TAIL(&pc->ac_references, pr, ar_clink);
587 TAILQ_INSERT_TAIL(&rp->ap_references, pr, ar_rlink);
593 acpi_pwr_dereference_resource(struct acpi_powerconsumer *pc)
595 struct acpi_powerreference *pr;
598 ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
599 ACPI_SERIAL_ASSERT(powerres);
602 while ((pr = TAILQ_FIRST(&pc->ac_references)) != NULL) {
603 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, "removing reference to %s\n",
604 acpi_name(pr->ar_resource->ap_resource)));
605 TAILQ_REMOVE(&pr->ar_resource->ap_references, pr, ar_rlink);
606 TAILQ_REMOVE(&pc->ac_references, pr, ar_clink);
615 * Switch power resources to conform to the desired state.
617 * Consumers may have modified the power resource list in an arbitrary
618 * fashion; we sweep it in sequence order.
621 acpi_pwr_switch_power(void)
623 struct acpi_powerresource *rp;
627 ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
628 ACPI_SERIAL_ASSERT(powerres);
631 * Sweep the list forwards turning things on.
633 TAILQ_FOREACH(rp, &acpi_powerresources, ap_link) {
634 if (TAILQ_FIRST(&rp->ap_references) == NULL) {
635 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS,
636 "%s has no references, not turning on\n",
637 acpi_name(rp->ap_resource)));
641 /* We could cache this if we trusted it not to change under us */
642 status = acpi_GetInteger(rp->ap_resource, "_STA", &cur);
643 if (ACPI_FAILURE(status)) {
644 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, "can't get status of %s - %d\n",
645 acpi_name(rp->ap_resource), status));
646 /* XXX is this correct? Always switch if in doubt? */
648 } else if (rp->ap_state == ACPI_PWR_UNK)
652 * Switch if required. Note that we ignore the result of the switch
653 * effort; we don't know what to do if it fails, so checking wouldn't
656 if (rp->ap_state != ACPI_PWR_ON) {
657 status = AcpiEvaluateObject(rp->ap_resource, "_ON", NULL, NULL);
658 if (ACPI_FAILURE(status)) {
659 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS,
660 "failed to switch %s on - %s\n",
661 acpi_name(rp->ap_resource),
662 AcpiFormatException(status)));
664 rp->ap_state = ACPI_PWR_ON;
665 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, "switched %s on\n",
666 acpi_name(rp->ap_resource)));
669 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, "%s is already on\n",
670 acpi_name(rp->ap_resource)));
674 /* Sweep the list backwards turning things off. */
675 TAILQ_FOREACH_REVERSE(rp, &acpi_powerresources, acpi_powerresource_list,
678 if (TAILQ_FIRST(&rp->ap_references) != NULL) {
679 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS,
680 "%s has references, not turning off\n",
681 acpi_name(rp->ap_resource)));
685 /* We could cache this if we trusted it not to change under us */
686 status = acpi_GetInteger(rp->ap_resource, "_STA", &cur);
687 if (ACPI_FAILURE(status)) {
688 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, "can't get status of %s - %d\n",
689 acpi_name(rp->ap_resource), status));
690 /* XXX is this correct? Always switch if in doubt? */
692 } else if (rp->ap_state == ACPI_PWR_UNK)
696 * Switch if required. Note that we ignore the result of the switch
697 * effort; we don't know what to do if it fails, so checking wouldn't
700 if (rp->ap_state != ACPI_PWR_OFF) {
701 status = AcpiEvaluateObject(rp->ap_resource, "_OFF", NULL, NULL);
702 if (ACPI_FAILURE(status)) {
703 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS,
704 "failed to switch %s off - %s\n",
705 acpi_name(rp->ap_resource),
706 AcpiFormatException(status)));
708 rp->ap_state = ACPI_PWR_OFF;
709 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, "switched %s off\n",
710 acpi_name(rp->ap_resource)));
713 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, "%s is already off\n",
714 acpi_name(rp->ap_resource)));
718 return_ACPI_STATUS (AE_OK);
722 * Find a power resource's control structure.
724 static struct acpi_powerresource *
725 acpi_pwr_find_resource(ACPI_HANDLE res)
727 struct acpi_powerresource *rp;
729 ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
730 ACPI_SERIAL_ASSERT(powerres);
732 TAILQ_FOREACH(rp, &acpi_powerresources, ap_link) {
733 if (rp->ap_resource == res)
741 * Find a power consumer's control structure.
743 static struct acpi_powerconsumer *
744 acpi_pwr_find_consumer(ACPI_HANDLE consumer)
746 struct acpi_powerconsumer *pc;
748 ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
749 ACPI_SERIAL_ASSERT(powerres);
751 TAILQ_FOREACH(pc, &acpi_powerconsumers, ac_link) {
752 if (pc->ac_consumer == consumer)