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
68 /* A relationship between a power resource and a consumer. */
69 struct acpi_powerreference {
70 struct acpi_powerconsumer *ar_consumer;
71 struct acpi_powerresource *ar_resource;
72 TAILQ_ENTRY(acpi_powerreference) ar_rlink; /* link on resource list */
73 TAILQ_ENTRY(acpi_powerreference) ar_clink; /* link on consumer */
76 /* A power-managed device. */
77 struct acpi_powerconsumer {
78 /* Device which is powered */
79 ACPI_HANDLE ac_consumer;
81 TAILQ_ENTRY(acpi_powerconsumer) ac_link;
82 TAILQ_HEAD(,acpi_powerreference) ac_references;
85 /* A power resource. */
86 struct acpi_powerresource {
87 TAILQ_ENTRY(acpi_powerresource) ap_link;
88 TAILQ_HEAD(,acpi_powerreference) ap_references;
89 ACPI_HANDLE ap_resource;
90 UINT64 ap_systemlevel;
94 static TAILQ_HEAD(acpi_powerresource_list, acpi_powerresource)
95 acpi_powerresources = TAILQ_HEAD_INITIALIZER(acpi_powerresources);
96 static TAILQ_HEAD(acpi_powerconsumer_list, acpi_powerconsumer)
97 acpi_powerconsumers = TAILQ_HEAD_INITIALIZER(acpi_powerconsumers);
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);
119 * Register a power resource.
121 * It's OK to call this if we already know about the resource.
124 acpi_pwr_register_resource(ACPI_HANDLE res)
129 struct acpi_powerresource *rp, *srp;
131 ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
132 ACPI_SERIAL_ASSERT(powerres);
137 /* Look to see if we know about this resource */
138 if (acpi_pwr_find_resource(res) != NULL)
139 return_ACPI_STATUS (AE_OK); /* already know about it */
141 /* Allocate a new resource */
142 if ((rp = malloc(sizeof(*rp), M_ACPIPWR, M_NOWAIT | M_ZERO)) == NULL) {
143 status = AE_NO_MEMORY;
146 TAILQ_INIT(&rp->ap_references);
147 rp->ap_resource = res;
149 /* Get the Power Resource object */
150 buf.Length = ACPI_ALLOCATE_BUFFER;
151 if (ACPI_FAILURE(status = AcpiEvaluateObject(res, NULL, NULL, &buf))) {
152 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, "no power resource object\n"));
156 if (obj->Type != ACPI_TYPE_POWER) {
157 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS,
158 "questionable power resource object %s\n",
163 rp->ap_systemlevel = obj->PowerResource.SystemLevel;
164 rp->ap_order = obj->PowerResource.ResourceOrder;
166 /* Sort the resource into the list */
168 srp = TAILQ_FIRST(&acpi_powerresources);
169 if (srp == NULL || rp->ap_order < srp->ap_order) {
170 TAILQ_INSERT_HEAD(&acpi_powerresources, rp, ap_link);
173 TAILQ_FOREACH(srp, &acpi_powerresources, ap_link) {
174 if (rp->ap_order < srp->ap_order) {
175 TAILQ_INSERT_BEFORE(srp, rp, ap_link);
179 TAILQ_INSERT_TAIL(&acpi_powerresources, rp, ap_link);
182 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS,
183 "registered power resource %s\n", acpi_name(res)));
186 if (buf.Pointer != NULL)
187 AcpiOsFree(buf.Pointer);
188 if (ACPI_FAILURE(status) && rp != NULL)
190 return_ACPI_STATUS (status);
195 * Deregister a power resource.
198 acpi_pwr_deregister_resource(ACPI_HANDLE res)
200 struct acpi_powerresource *rp;
202 ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
203 ACPI_SERIAL_ASSERT(powerres);
207 /* Find the resource */
208 if ((rp = acpi_pwr_find_resource(res)) == NULL)
209 return_ACPI_STATUS (AE_BAD_PARAMETER);
211 /* Check that there are no consumers referencing this resource */
212 if (TAILQ_FIRST(&rp->ap_references) != NULL)
213 return_ACPI_STATUS (AE_BAD_PARAMETER);
215 /* Pull it off the list and free it */
216 TAILQ_REMOVE(&acpi_powerresources, rp, ap_link);
219 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, "deregistered power resource %s\n",
222 return_ACPI_STATUS (AE_OK);
227 * Register a power consumer.
229 * It's OK to call this if we already know about the consumer.
232 acpi_pwr_register_consumer(ACPI_HANDLE consumer)
234 struct acpi_powerconsumer *pc;
236 ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
237 ACPI_SERIAL_ASSERT(powerres);
239 /* Check to see whether we know about this consumer already */
240 if (acpi_pwr_find_consumer(consumer) != NULL)
241 return_ACPI_STATUS (AE_OK);
243 /* Allocate a new power consumer */
244 if ((pc = malloc(sizeof(*pc), M_ACPIPWR, M_NOWAIT)) == NULL)
245 return_ACPI_STATUS (AE_NO_MEMORY);
246 TAILQ_INSERT_HEAD(&acpi_powerconsumers, pc, ac_link);
247 TAILQ_INIT(&pc->ac_references);
248 pc->ac_consumer = consumer;
250 /* XXX we should try to find its current state */
251 pc->ac_state = ACPI_STATE_UNKNOWN;
253 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, "registered power consumer %s\n",
254 acpi_name(consumer)));
256 return_ACPI_STATUS (AE_OK);
261 * Deregister a power consumer.
263 * This should only be done once the consumer has been powered off.
264 * (XXX is this correct? Check once implemented)
267 acpi_pwr_deregister_consumer(ACPI_HANDLE consumer)
269 struct acpi_powerconsumer *pc;
271 ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
272 ACPI_SERIAL_ASSERT(powerres);
274 /* Find the consumer */
275 if ((pc = acpi_pwr_find_consumer(consumer)) == NULL)
276 return_ACPI_STATUS (AE_BAD_PARAMETER);
278 /* Make sure the consumer's not referencing anything right now */
279 if (TAILQ_FIRST(&pc->ac_references) != NULL)
280 return_ACPI_STATUS (AE_BAD_PARAMETER);
282 /* Pull the consumer off the list and free it */
283 TAILQ_REMOVE(&acpi_powerconsumers, pc, ac_link);
286 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, "deregistered power consumer %s\n",
287 acpi_name(consumer)));
289 return_ACPI_STATUS (AE_OK);
294 * Set a power consumer to a particular power state.
297 acpi_pwr_switch_consumer(ACPI_HANDLE consumer, int state)
299 struct acpi_powerconsumer *pc;
300 ACPI_HANDLE method_handle, reslist_handle, pr0_handle;
301 ACPI_BUFFER reslist_buffer;
302 ACPI_OBJECT *reslist_object;
304 char *method_name, *reslist_name;
306 ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
308 /* It's never ok to switch a non-existent consumer. */
309 if (consumer == NULL)
310 return_ACPI_STATUS (AE_NOT_FOUND);
311 reslist_buffer.Pointer = NULL;
312 reslist_object = NULL;
313 ACPI_SERIAL_BEGIN(powerres);
315 /* Find the consumer */
316 if ((pc = acpi_pwr_find_consumer(consumer)) == NULL) {
317 if (ACPI_FAILURE(status = acpi_pwr_register_consumer(consumer)))
319 if ((pc = acpi_pwr_find_consumer(consumer)) == NULL)
320 panic("acpi added power consumer but can't find it");
323 /* Check for valid transitions. We can only go to D0 from D3. */
324 status = AE_BAD_PARAMETER;
325 if (pc->ac_state == ACPI_STATE_D3 && state != ACPI_STATE_D0)
328 /* Find transition mechanism(s) */
331 method_name = "_PS0";
332 reslist_name = "_PR0";
335 method_name = "_PS1";
336 reslist_name = "_PR1";
339 method_name = "_PS2";
340 reslist_name = "_PR2";
343 method_name = "_PS3";
344 reslist_name = "_PR3";
349 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, "setup to switch %s D%d -> D%d\n",
350 acpi_name(consumer), pc->ac_state, state));
353 * Verify that this state is supported, ie. one of method or
354 * reslist must be present. We need to do this before we go
355 * dereferencing resources (since we might be trying to go to
356 * a state we don't support).
358 * Note that if any states are supported, the device has to
359 * support D0 and D3. It's never an error to try to go to
362 if (ACPI_FAILURE(AcpiGetHandle(consumer, method_name, &method_handle)))
363 method_handle = NULL;
364 if (ACPI_FAILURE(AcpiGetHandle(consumer, reslist_name, &reslist_handle)))
365 reslist_handle = NULL;
366 if (reslist_handle == NULL && method_handle == NULL) {
367 if (state == ACPI_STATE_D0) {
368 pc->ac_state = ACPI_STATE_D0;
372 if (state != ACPI_STATE_D3) {
373 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS,
374 "attempt to set unsupported state D%d\n", state));
379 * Turn off the resources listed in _PR0 to go to D3. If there is
380 * no _PR0 method, this object doesn't support ACPI power states.
382 if (ACPI_FAILURE(AcpiGetHandle(consumer, "_PR0", &pr0_handle))) {
383 status = AE_NOT_FOUND;
384 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS,
385 "device missing _PR0 (desired state was D%d)\n", state));
388 reslist_buffer.Length = ACPI_ALLOCATE_BUFFER;
389 status = AcpiEvaluateObject(pr0_handle, NULL, NULL, &reslist_buffer);
390 if (ACPI_FAILURE(status)) {
391 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS,
392 "can't evaluate _PR0 for device %s, state D%d\n",
393 acpi_name(consumer), state));
396 reslist_object = (ACPI_OBJECT *)reslist_buffer.Pointer;
397 if (!ACPI_PKG_VALID(reslist_object, 1)) {
398 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS,
399 "invalid package object for state D%d\n", state));
403 AcpiOsFree(reslist_buffer.Pointer);
404 reslist_buffer.Pointer = NULL;
405 reslist_object = NULL;
409 * Check that we can actually fetch the list of power resources
411 if (reslist_handle != NULL) {
412 reslist_buffer.Length = ACPI_ALLOCATE_BUFFER;
413 status = AcpiEvaluateObject(reslist_handle, NULL, NULL,
415 if (ACPI_FAILURE(status)) {
416 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS,
417 "can't evaluate resource list %s\n",
418 acpi_name(reslist_handle)));
421 reslist_object = (ACPI_OBJECT *)reslist_buffer.Pointer;
422 if (reslist_object->Type != ACPI_TYPE_PACKAGE) {
423 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS,
424 "resource list is not ACPI_TYPE_PACKAGE (%d)\n",
425 reslist_object->Type));
432 * Now we are ready to switch, so kill off any current power
433 * resource references.
435 acpi_pwr_dereference_resource(pc);
438 * Add new power resource references, if we have any. Traverse the
439 * package that we got from evaluating reslist_handle, and look up each
440 * of the resources that are referenced.
442 if (reslist_object != NULL) {
443 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, "referencing %d new resources\n",
444 reslist_object->Package.Count));
445 acpi_ForeachPackageObject(reslist_object, acpi_pwr_reference_resource,
450 * If we changed anything in the resource list, we need to run a switch
453 if (ACPI_FAILURE(status = acpi_pwr_switch_power())) {
454 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS,
455 "failed to switch resources from %s to D%d\n",
456 acpi_name(consumer), state));
458 /* XXX is this appropriate? Should we return to previous state? */
462 /* Invoke power state switch method (if present) */
463 if (method_handle != NULL) {
464 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS,
465 "invoking state transition method %s\n",
466 acpi_name(method_handle)));
467 status = AcpiEvaluateObject(method_handle, NULL, NULL, NULL);
468 if (ACPI_FAILURE(status)) {
469 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, "failed to set state - %s\n",
470 AcpiFormatException(status)));
471 pc->ac_state = ACPI_STATE_UNKNOWN;
473 /* XXX Should we return to previous state? */
478 /* Transition was successful */
479 pc->ac_state = state;
483 ACPI_SERIAL_END(powerres);
484 if (reslist_buffer.Pointer != NULL)
485 AcpiOsFree(reslist_buffer.Pointer);
486 return_ACPI_STATUS (status);
489 /* Enable or disable a power resource for wake */
491 acpi_pwr_wake_enable(ACPI_HANDLE consumer, int enable)
494 struct acpi_powerconsumer *pc;
495 struct acpi_prw_data prw;
498 ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
500 if (consumer == NULL)
501 return (AE_BAD_PARAMETER);
503 ACPI_SERIAL_BEGIN(powerres);
504 if ((pc = acpi_pwr_find_consumer(consumer)) == NULL) {
505 if (ACPI_FAILURE(status = acpi_pwr_register_consumer(consumer)))
507 if ((pc = acpi_pwr_find_consumer(consumer)) == NULL)
508 panic("acpi wake added power consumer but can't find it");
512 if (acpi_parse_prw(consumer, &prw) != 0)
514 for (i = 0; i < prw.power_res_count; i++)
516 acpi_pwr_reference_resource(&prw.power_res[i], pc);
518 acpi_pwr_dereference_resource(pc);
520 if (prw.power_res_count > 0)
521 acpi_pwr_switch_power();
524 ACPI_SERIAL_END(powerres);
529 * Called to create a reference between a power consumer and a power resource
530 * identified in the object.
533 acpi_pwr_reference_resource(ACPI_OBJECT *obj, void *arg)
535 struct acpi_powerconsumer *pc = (struct acpi_powerconsumer *)arg;
536 struct acpi_powerreference *pr;
537 struct acpi_powerresource *rp;
541 ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
542 ACPI_SERIAL_ASSERT(powerres);
544 res = acpi_GetReference(NULL, obj);
546 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS,
547 "can't create a power reference for object type %d\n",
552 /* Create/look up the resource */
553 if (ACPI_FAILURE(status = acpi_pwr_register_resource(res))) {
554 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS,
555 "couldn't register power resource %s - %s\n",
556 obj->String.Pointer, AcpiFormatException(status)));
559 if ((rp = acpi_pwr_find_resource(res)) == NULL) {
560 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, "power resource list corrupted\n"));
563 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, "found power resource %s\n",
564 acpi_name(rp->ap_resource)));
566 /* Create a reference between the consumer and resource */
567 if ((pr = malloc(sizeof(*pr), M_ACPIPWR, M_NOWAIT | M_ZERO)) == NULL) {
568 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS,
569 "allocation failed for a power consumer reference\n"));
572 pr->ar_consumer = pc;
573 pr->ar_resource = rp;
574 TAILQ_INSERT_TAIL(&pc->ac_references, pr, ar_clink);
575 TAILQ_INSERT_TAIL(&rp->ap_references, pr, ar_rlink);
581 acpi_pwr_dereference_resource(struct acpi_powerconsumer *pc)
583 struct acpi_powerreference *pr;
586 ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
587 ACPI_SERIAL_ASSERT(powerres);
590 while ((pr = TAILQ_FIRST(&pc->ac_references)) != NULL) {
591 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, "removing reference to %s\n",
592 acpi_name(pr->ar_resource->ap_resource)));
593 TAILQ_REMOVE(&pr->ar_resource->ap_references, pr, ar_rlink);
594 TAILQ_REMOVE(&pc->ac_references, pr, ar_clink);
603 * Switch power resources to conform to the desired state.
605 * Consumers may have modified the power resource list in an arbitrary
606 * fashion; we sweep it in sequence order.
609 acpi_pwr_switch_power(void)
611 struct acpi_powerresource *rp;
615 ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
616 ACPI_SERIAL_ASSERT(powerres);
619 * Sweep the list forwards turning things on.
621 TAILQ_FOREACH(rp, &acpi_powerresources, ap_link) {
622 if (TAILQ_FIRST(&rp->ap_references) == NULL) {
623 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS,
624 "%s has no references, not turning on\n",
625 acpi_name(rp->ap_resource)));
629 status = acpi_GetInteger(rp->ap_resource, "_STA", &cur);
630 if (ACPI_FAILURE(status)) {
631 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, "can't get status of %s - %d\n",
632 acpi_name(rp->ap_resource), status));
633 /* XXX is this correct? Always switch if in doubt? */
638 * Switch if required. Note that we ignore the result of the switch
639 * effort; we don't know what to do if it fails, so checking wouldn't
642 if (cur != ACPI_PWR_ON) {
643 status = AcpiEvaluateObject(rp->ap_resource, "_ON", NULL, NULL);
644 if (ACPI_FAILURE(status)) {
645 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS,
646 "failed to switch %s on - %s\n",
647 acpi_name(rp->ap_resource),
648 AcpiFormatException(status)));
650 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, "switched %s on\n",
651 acpi_name(rp->ap_resource)));
654 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, "%s is already on\n",
655 acpi_name(rp->ap_resource)));
659 /* Sweep the list backwards turning things off. */
660 TAILQ_FOREACH_REVERSE(rp, &acpi_powerresources, acpi_powerresource_list,
663 if (TAILQ_FIRST(&rp->ap_references) != NULL) {
664 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS,
665 "%s has references, not turning off\n",
666 acpi_name(rp->ap_resource)));
670 status = acpi_GetInteger(rp->ap_resource, "_STA", &cur);
671 if (ACPI_FAILURE(status)) {
672 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, "can't get status of %s - %d\n",
673 acpi_name(rp->ap_resource), status));
674 /* XXX is this correct? Always switch if in doubt? */
679 * Switch if required. Note that we ignore the result of the switch
680 * effort; we don't know what to do if it fails, so checking wouldn't
683 if (cur != ACPI_PWR_OFF) {
684 status = AcpiEvaluateObject(rp->ap_resource, "_OFF", NULL, NULL);
685 if (ACPI_FAILURE(status)) {
686 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS,
687 "failed to switch %s off - %s\n",
688 acpi_name(rp->ap_resource),
689 AcpiFormatException(status)));
691 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, "switched %s off\n",
692 acpi_name(rp->ap_resource)));
695 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, "%s is already off\n",
696 acpi_name(rp->ap_resource)));
700 return_ACPI_STATUS (AE_OK);
704 * Find a power resource's control structure.
706 static struct acpi_powerresource *
707 acpi_pwr_find_resource(ACPI_HANDLE res)
709 struct acpi_powerresource *rp;
711 ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
712 ACPI_SERIAL_ASSERT(powerres);
714 TAILQ_FOREACH(rp, &acpi_powerresources, ap_link) {
715 if (rp->ap_resource == res)
723 * Find a power consumer's control structure.
725 static struct acpi_powerconsumer *
726 acpi_pwr_find_consumer(ACPI_HANDLE consumer)
728 struct acpi_powerconsumer *pc;
730 ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
731 ACPI_SERIAL_ASSERT(powerres);
733 TAILQ_FOREACH(pc, &acpi_powerconsumers, ac_link) {
734 if (pc->ac_consumer == consumer)