Deleted Added
full compact
acpi_powerres.c (82084) acpi_powerres.c (82372)
1/*-
2 * Copyright (c) 2001 Michael Smith
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 9 unchanged lines hidden (view full) ---

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
24 * SUCH DAMAGE.
25 *
1/*-
2 * Copyright (c) 2001 Michael Smith
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 9 unchanged lines hidden (view full) ---

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
24 * SUCH DAMAGE.
25 *
26 * $FreeBSD: head/sys/dev/acpica/acpi_powerres.c 82084 2001-08-21 18:22:40Z iwasaki $
26 * $FreeBSD: head/sys/dev/acpica/acpi_powerres.c 82372 2001-08-26 22:50:15Z msmith $
27 */
28
29#include "opt_acpi.h" /* XXX trim includes */
30#include <sys/param.h>
31#include <sys/kernel.h>
32#include <sys/proc.h>
33#include <sys/lock.h>
34#include <sys/malloc.h>

--- 127 unchanged lines hidden (view full) ---

162 status = AE_NO_MEMORY;
163 goto out;
164 }
165 TAILQ_INIT(&rp->ap_references);
166 rp->ap_resource = res;
167
168 /* get the Power Resource object */
169 if ((status = acpi_EvaluateIntoBuffer(res, NULL, NULL, &buf)) != AE_OK) {
27 */
28
29#include "opt_acpi.h" /* XXX trim includes */
30#include <sys/param.h>
31#include <sys/kernel.h>
32#include <sys/proc.h>
33#include <sys/lock.h>
34#include <sys/malloc.h>

--- 127 unchanged lines hidden (view full) ---

162 status = AE_NO_MEMORY;
163 goto out;
164 }
165 TAILQ_INIT(&rp->ap_references);
166 rp->ap_resource = res;
167
168 /* get the Power Resource object */
169 if ((status = acpi_EvaluateIntoBuffer(res, NULL, NULL, &buf)) != AE_OK) {
170 DEBUG_PRINT(TRACE_OBJECTS, ("no power resource object\n"));
170 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, "no power resource object\n"));
171 goto out;
172 }
173 obj = buf.Pointer;
174 if (obj->Type != ACPI_TYPE_POWER) {
171 goto out;
172 }
173 obj = buf.Pointer;
174 if (obj->Type != ACPI_TYPE_POWER) {
175 DEBUG_PRINT(TRACE_OBJECTS, ("questionable power resource object %s\n", acpi_name(res)));
175 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, "questionable power resource object %s\n", acpi_name(res)));
176 status = AE_TYPE;
177 goto out;
178 }
179 rp->ap_systemlevel = obj->PowerResource.SystemLevel;
180 rp->ap_order = obj->PowerResource.ResourceOrder;
181
182 /* sort the resource into the list */
183 status = AE_OK;

--- 5 unchanged lines hidden (view full) ---

189 TAILQ_FOREACH(srp, &acpi_powerresources, ap_link)
190 if (rp->ap_order < srp->ap_order) {
191 TAILQ_INSERT_BEFORE(srp, rp, ap_link);
192 goto done;
193 }
194 TAILQ_INSERT_TAIL(&acpi_powerresources, rp, ap_link);
195
196 done:
176 status = AE_TYPE;
177 goto out;
178 }
179 rp->ap_systemlevel = obj->PowerResource.SystemLevel;
180 rp->ap_order = obj->PowerResource.ResourceOrder;
181
182 /* sort the resource into the list */
183 status = AE_OK;

--- 5 unchanged lines hidden (view full) ---

189 TAILQ_FOREACH(srp, &acpi_powerresources, ap_link)
190 if (rp->ap_order < srp->ap_order) {
191 TAILQ_INSERT_BEFORE(srp, rp, ap_link);
192 goto done;
193 }
194 TAILQ_INSERT_TAIL(&acpi_powerresources, rp, ap_link);
195
196 done:
197 DEBUG_PRINT(TRACE_OBJECTS, ("registered power resource %s\n", acpi_name(res)));
197 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, "registered power resource %s\n", acpi_name(res)));
198 out:
199 if (obj != NULL)
200 AcpiOsFree(obj);
201 if ((status != AE_OK) && (rp != NULL))
202 free(rp, M_ACPIPWR);
203 return_ACPI_STATUS(status);
204}
205

--- 16 unchanged lines hidden (view full) ---

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);
225
226 /* pull it off the list and free it */
227 TAILQ_REMOVE(&acpi_powerresources, rp, ap_link);
228 free(rp, M_ACPIPWR);
229
198 out:
199 if (obj != NULL)
200 AcpiOsFree(obj);
201 if ((status != AE_OK) && (rp != NULL))
202 free(rp, M_ACPIPWR);
203 return_ACPI_STATUS(status);
204}
205

--- 16 unchanged lines hidden (view full) ---

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);
225
226 /* pull it off the list and free it */
227 TAILQ_REMOVE(&acpi_powerresources, rp, ap_link);
228 free(rp, M_ACPIPWR);
229
230 DEBUG_PRINT(TRACE_OBJECTS, ("deregistered power resource %s\n", acpi_name(res)));
230 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, "deregistered power resource %s\n", acpi_name(res)));
231
232 return_ACPI_STATUS(AE_OK);
233}
234
235/*
236 * Register a power consumer.
237 *
238 * It's OK to call this if we already know about the consumer.

--- 13 unchanged lines hidden (view full) ---

252 if ((pc = malloc(sizeof(*pc), M_ACPIPWR, M_NOWAIT)) == NULL)
253 return_ACPI_STATUS(AE_NO_MEMORY);
254 TAILQ_INSERT_HEAD(&acpi_powerconsumers, pc, ac_link);
255 TAILQ_INIT(&pc->ac_references);
256 pc->ac_consumer = consumer;
257
258 pc->ac_state = ACPI_STATE_UNKNOWN; /* XXX we should try to find its current state */
259
231
232 return_ACPI_STATUS(AE_OK);
233}
234
235/*
236 * Register a power consumer.
237 *
238 * It's OK to call this if we already know about the consumer.

--- 13 unchanged lines hidden (view full) ---

252 if ((pc = malloc(sizeof(*pc), M_ACPIPWR, M_NOWAIT)) == NULL)
253 return_ACPI_STATUS(AE_NO_MEMORY);
254 TAILQ_INSERT_HEAD(&acpi_powerconsumers, pc, ac_link);
255 TAILQ_INIT(&pc->ac_references);
256 pc->ac_consumer = consumer;
257
258 pc->ac_state = ACPI_STATE_UNKNOWN; /* XXX we should try to find its current state */
259
260 DEBUG_PRINT(TRACE_OBJECTS, ("registered power consumer %s\n", acpi_name(consumer)));
260 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, "registered power consumer %s\n", acpi_name(consumer)));
261
262 return_ACPI_STATUS(AE_OK);
263}
264
265/*
266 * Deregister a power consumer.
267 *
268 * This should only be done once the consumer has been powered off.

--- 12 unchanged lines hidden (view full) ---

281
282 /* make sure the consumer's not referencing anything right now */
283 if (TAILQ_FIRST(&pc->ac_references) != NULL)
284 return_ACPI_STATUS(AE_BAD_PARAMETER);
285
286 /* pull the consumer off the list and free it */
287 TAILQ_REMOVE(&acpi_powerconsumers, pc, ac_link);
288
261
262 return_ACPI_STATUS(AE_OK);
263}
264
265/*
266 * Deregister a power consumer.
267 *
268 * This should only be done once the consumer has been powered off.

--- 12 unchanged lines hidden (view full) ---

281
282 /* make sure the consumer's not referencing anything right now */
283 if (TAILQ_FIRST(&pc->ac_references) != NULL)
284 return_ACPI_STATUS(AE_BAD_PARAMETER);
285
286 /* pull the consumer off the list and free it */
287 TAILQ_REMOVE(&acpi_powerconsumers, pc, ac_link);
288
289 DEBUG_PRINT(TRACE_OBJECTS, ("deregistered power consumer %s\n", acpi_name(consumer)));
289 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, "deregistered power consumer %s\n", acpi_name(consumer)));
290
291 return_ACPI_STATUS(AE_OK);
292}
293
294/*
295 * Set a power consumer to a particular power state.
296 */
297ACPI_STATUS

--- 39 unchanged lines hidden (view full) ---

337 break;
338 case ACPI_STATE_D3:
339 method_name = "_PS3";
340 reslist_name = "_PR3";
341 break;
342 default:
343 return_ACPI_STATUS(AE_BAD_PARAMETER);
344 }
290
291 return_ACPI_STATUS(AE_OK);
292}
293
294/*
295 * Set a power consumer to a particular power state.
296 */
297ACPI_STATUS

--- 39 unchanged lines hidden (view full) ---

337 break;
338 case ACPI_STATE_D3:
339 method_name = "_PS3";
340 reslist_name = "_PR3";
341 break;
342 default:
343 return_ACPI_STATUS(AE_BAD_PARAMETER);
344 }
345 DEBUG_PRINT(TRACE_OBJECTS, ("setup to switch %s D%d -> D%d\n",
346 acpi_name(consumer), pc->ac_state, state));
345 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, "setup to switch %s D%d -> D%d\n",
346 acpi_name(consumer), pc->ac_state, state));
347
348 /*
349 * Verify that this state is supported, ie. one of method or
350 * reslist must be present. We need to do this before we go
351 * dereferencing resources (since we might be trying to go to
352 * a state we don't support).
353 *
354 * Note that if any states are supported, the device has to

--- 30 unchanged lines hidden (view full) ---

385 AcpiOsFree(reslist_object);
386 }
387
388 /*
389 * Check that we can actually fetch the list of power resources
390 */
391 if (reslist_handle != NULL) {
392 if ((status = acpi_EvaluateIntoBuffer(reslist_handle, NULL, NULL, &reslist_buffer)) != AE_OK) {
347
348 /*
349 * Verify that this state is supported, ie. one of method or
350 * reslist must be present. We need to do this before we go
351 * dereferencing resources (since we might be trying to go to
352 * a state we don't support).
353 *
354 * Note that if any states are supported, the device has to

--- 30 unchanged lines hidden (view full) ---

385 AcpiOsFree(reslist_object);
386 }
387
388 /*
389 * Check that we can actually fetch the list of power resources
390 */
391 if (reslist_handle != NULL) {
392 if ((status = acpi_EvaluateIntoBuffer(reslist_handle, NULL, NULL, &reslist_buffer)) != AE_OK) {
393 DEBUG_PRINT(TRACE_OBJECTS, ("can't evaluate resource list %s\n",
394 acpi_name(reslist_handle)));
393 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, "can't evaluate resource list %s\n",
394 acpi_name(reslist_handle)));
395 return_ACPI_STATUS(status);
396 }
397 reslist_object = (ACPI_OBJECT *)reslist_buffer.Pointer;
398 if (reslist_object->Type != ACPI_TYPE_PACKAGE) {
395 return_ACPI_STATUS(status);
396 }
397 reslist_object = (ACPI_OBJECT *)reslist_buffer.Pointer;
398 if (reslist_object->Type != ACPI_TYPE_PACKAGE) {
399 DEBUG_PRINT(TRACE_OBJECTS, ("resource list is not ACPI_TYPE_PACKAGE (%d)\n",
400 reslist_object->Type));
399 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, "resource list is not ACPI_TYPE_PACKAGE (%d)\n",
400 reslist_object->Type));
401 return_ACPI_STATUS(AE_TYPE);
402 }
403 } else {
404 reslist_object = NULL;
405 }
406
407 /*
408 * Now we are ready to switch, so kill off any current power resource references.
409 */
410 res_changed = 0;
411 while((pr = TAILQ_FIRST(&pc->ac_references)) != NULL) {
412 res_changed = 1;
401 return_ACPI_STATUS(AE_TYPE);
402 }
403 } else {
404 reslist_object = NULL;
405 }
406
407 /*
408 * Now we are ready to switch, so kill off any current power resource references.
409 */
410 res_changed = 0;
411 while((pr = TAILQ_FIRST(&pc->ac_references)) != NULL) {
412 res_changed = 1;
413 DEBUG_PRINT(TRACE_OBJECTS, ("removing reference to %s\n", acpi_name(pr->ar_resource->ap_resource)));
413 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, "removing reference to %s\n", acpi_name(pr->ar_resource->ap_resource)));
414 TAILQ_REMOVE(&pr->ar_resource->ap_references, pr, ar_rlink);
415 TAILQ_REMOVE(&pc->ac_references, pr, ar_clink);
416 free(pr, M_ACPIPWR);
417 }
418
419 /*
420 * Add new power resource references, if we have any. Traverse the
421 * package that we got from evaluating reslist_handle, and look up each
422 * of the resources that are referenced.
423 */
424 if (reslist_object != NULL) {
414 TAILQ_REMOVE(&pr->ar_resource->ap_references, pr, ar_rlink);
415 TAILQ_REMOVE(&pc->ac_references, pr, ar_clink);
416 free(pr, M_ACPIPWR);
417 }
418
419 /*
420 * Add new power resource references, if we have any. Traverse the
421 * package that we got from evaluating reslist_handle, and look up each
422 * of the resources that are referenced.
423 */
424 if (reslist_object != NULL) {
425 DEBUG_PRINT(TRACE_OBJECTS, ("referencing %d new resources\n",
426 reslist_object->Package.Count));
425 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, "referencing %d new resources\n",
426 reslist_object->Package.Count));
427 acpi_ForeachPackageObject(reslist_object, acpi_pwr_reference_resource, pc);
428 res_changed = 1;
429 }
430
431 /*
432 * If we changed anything in the resource list, we need to run a switch
433 * pass now.
434 */
435 if ((status = acpi_pwr_switch_power()) != AE_OK) {
427 acpi_ForeachPackageObject(reslist_object, acpi_pwr_reference_resource, pc);
428 res_changed = 1;
429 }
430
431 /*
432 * If we changed anything in the resource list, we need to run a switch
433 * pass now.
434 */
435 if ((status = acpi_pwr_switch_power()) != AE_OK) {
436 DEBUG_PRINT(TRACE_OBJECTS, ("failed to correctly switch resources to move %s to D%d\n",
437 acpi_name(consumer), state));
436 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, "failed to correctly switch resources to move %s to D%d\n",
437 acpi_name(consumer), state));
438 return_ACPI_STATUS(status); /* XXX is this appropriate? Should we return to previous state? */
439 }
440
441 /* invoke power state switch method (if present) */
442 if (method_handle != NULL) {
438 return_ACPI_STATUS(status); /* XXX is this appropriate? Should we return to previous state? */
439 }
440
441 /* invoke power state switch method (if present) */
442 if (method_handle != NULL) {
443 DEBUG_PRINT(TRACE_OBJECTS, ("invoking state transition method %s\n",
444 acpi_name(method_handle)));
443 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, "invoking state transition method %s\n",
444 acpi_name(method_handle)));
445 if ((status = AcpiEvaluateObject(method_handle, NULL, NULL, NULL)) != AE_OK)
446 pc->ac_state = ACPI_STATE_UNKNOWN;
447 return_ACPI_STATUS(status); /* XXX is this appropriate? Should we return to previous state? */
448 }
449
450 /* transition was successful */
451 pc->ac_state = state;
452 return_ACPI_STATUS(AE_OK);
453
454 bad:
445 if ((status = AcpiEvaluateObject(method_handle, NULL, NULL, NULL)) != AE_OK)
446 pc->ac_state = ACPI_STATE_UNKNOWN;
447 return_ACPI_STATUS(status); /* XXX is this appropriate? Should we return to previous state? */
448 }
449
450 /* transition was successful */
451 pc->ac_state = state;
452 return_ACPI_STATUS(AE_OK);
453
454 bad:
455 DEBUG_PRINT(TRACE_OBJECTS, ("attempt to set unsupported state D%d\n",
456 state));
455 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, "attempt to set unsupported state D%d\n",
456 state));
457 if (reslist_object)
458 AcpiOsFree(reslist_object);
459 return_ACPI_STATUS(AE_BAD_PARAMETER);
460}
461
462/*
463 * Called to create a reference between a power consumer and a power resource
464 * identified in the object.

--- 6 unchanged lines hidden (view full) ---

471 struct acpi_powerresource *rp;
472 ACPI_HANDLE res;
473 ACPI_STATUS status;
474
475 FUNCTION_TRACE(__func__);
476
477 /* check the object type */
478 if (obj->Type != ACPI_TYPE_STRING) {
457 if (reslist_object)
458 AcpiOsFree(reslist_object);
459 return_ACPI_STATUS(AE_BAD_PARAMETER);
460}
461
462/*
463 * Called to create a reference between a power consumer and a power resource
464 * identified in the object.

--- 6 unchanged lines hidden (view full) ---

471 struct acpi_powerresource *rp;
472 ACPI_HANDLE res;
473 ACPI_STATUS status;
474
475 FUNCTION_TRACE(__func__);
476
477 /* check the object type */
478 if (obj->Type != ACPI_TYPE_STRING) {
479 DEBUG_PRINT(TRACE_OBJECTS, ("don't know how to create a power reference to object type %d\n",
480 obj->Type));
479 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, "don't know how to create a power reference to object type %d\n",
480 obj->Type));
481 return_VOID;
482 }
483
481 return_VOID;
482 }
483
484 DEBUG_PRINT(TRACE_OBJECTS, ("building reference from %s to %s\n",
485 acpi_name(pc->ac_consumer), obj->String.Pointer));
484 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, "building reference from %s to %s\n",
485 acpi_name(pc->ac_consumer), obj->String.Pointer));
486
487 /* get the handle of the resource */
488 if (ACPI_FAILURE(status = AcpiGetHandle(NULL, obj->String.Pointer, &res))) {
486
487 /* get the handle of the resource */
488 if (ACPI_FAILURE(status = AcpiGetHandle(NULL, obj->String.Pointer, &res))) {
489 DEBUG_PRINT(TRACE_OBJECTS, ("couldn't find power resource %s\n",
490 obj->String.Pointer));
489 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, "couldn't find power resource %s\n",
490 obj->String.Pointer));
491 return_VOID;
492 }
493
494 /* create/look up the resource */
495 if (ACPI_FAILURE(status = acpi_pwr_register_resource(res))) {
491 return_VOID;
492 }
493
494 /* create/look up the resource */
495 if (ACPI_FAILURE(status = acpi_pwr_register_resource(res))) {
496 DEBUG_PRINT(TRACE_OBJECTS, ("couldn't register power resource %s - %s\n",
497 obj->String.Pointer, AcpiFormatException(status)));
496 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, "couldn't register power resource %s - %s\n",
497 obj->String.Pointer, AcpiFormatException(status)));
498 return_VOID;
499 }
500 if ((rp = acpi_pwr_find_resource(res)) == NULL) {
498 return_VOID;
499 }
500 if ((rp = acpi_pwr_find_resource(res)) == NULL) {
501 DEBUG_PRINT(TRACE_OBJECTS, ("power resource list corrupted\n"));
501 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, "power resource list corrupted\n"));
502 return_VOID;
503 }
502 return_VOID;
503 }
504 DEBUG_PRINT(TRACE_OBJECTS, ("found power resource %s\n", acpi_name(rp->ap_resource)));
504 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, "found power resource %s\n", acpi_name(rp->ap_resource)));
505
506 /* create a reference between the consumer and resource */
507 if ((pr = malloc(sizeof(*pr), M_ACPIPWR, M_NOWAIT | M_ZERO)) == NULL) {
505
506 /* create a reference between the consumer and resource */
507 if ((pr = malloc(sizeof(*pr), M_ACPIPWR, M_NOWAIT | M_ZERO)) == NULL) {
508 DEBUG_PRINT(TRACE_OBJECTS, ("couldn't allocate memory for a power consumer reference\n"));
508 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, "couldn't allocate memory for a power consumer reference\n"));
509 return_VOID;
510 }
511 pr->ar_consumer = pc;
512 pr->ar_resource = rp;
513 TAILQ_INSERT_TAIL(&pc->ac_references, pr, ar_clink);
514 TAILQ_INSERT_TAIL(&rp->ap_references, pr, ar_rlink);
515
516 return_VOID;

--- 15 unchanged lines hidden (view full) ---

532
533 FUNCTION_TRACE(__func__);
534
535 /*
536 * Sweep the list forwards turning things on.
537 */
538 TAILQ_FOREACH(rp, &acpi_powerresources, ap_link) {
539 if (TAILQ_FIRST(&rp->ap_references) == NULL) {
509 return_VOID;
510 }
511 pr->ar_consumer = pc;
512 pr->ar_resource = rp;
513 TAILQ_INSERT_TAIL(&pc->ac_references, pr, ar_clink);
514 TAILQ_INSERT_TAIL(&rp->ap_references, pr, ar_rlink);
515
516 return_VOID;

--- 15 unchanged lines hidden (view full) ---

532
533 FUNCTION_TRACE(__func__);
534
535 /*
536 * Sweep the list forwards turning things on.
537 */
538 TAILQ_FOREACH(rp, &acpi_powerresources, ap_link) {
539 if (TAILQ_FIRST(&rp->ap_references) == NULL) {
540 DEBUG_PRINT(TRACE_OBJECTS, ("%s has no references, not turning on\n",
541 acpi_name(rp->ap_resource)));
540 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, "%s has no references, not turning on\n",
541 acpi_name(rp->ap_resource)));
542 continue;
543 }
544
545 /* we could cache this if we trusted it not to change under us */
546 if ((status = acpi_EvaluateInteger(rp->ap_resource, "_STA", &cur)) != AE_OK) {
542 continue;
543 }
544
545 /* we could cache this if we trusted it not to change under us */
546 if ((status = acpi_EvaluateInteger(rp->ap_resource, "_STA", &cur)) != AE_OK) {
547 DEBUG_PRINT(TRACE_OBJECTS, ("can't get status of %s - %d\n",
548 acpi_name(rp->ap_resource), status));
547 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, "can't get status of %s - %d\n",
548 acpi_name(rp->ap_resource), status));
549 continue; /* XXX is this correct? Always switch if in doubt? */
550 }
551
552 /*
553 * Switch if required. Note that we ignore the result of the switch
554 * effort; we don't know what to do if it fails, so checking wouldn't
555 * help much.
556 */
557 if (cur != ACPI_PWR_ON) {
558 if (ACPI_FAILURE(status = AcpiEvaluateObject(rp->ap_resource, "_ON", NULL, NULL))) {
549 continue; /* XXX is this correct? Always switch if in doubt? */
550 }
551
552 /*
553 * Switch if required. Note that we ignore the result of the switch
554 * effort; we don't know what to do if it fails, so checking wouldn't
555 * help much.
556 */
557 if (cur != ACPI_PWR_ON) {
558 if (ACPI_FAILURE(status = AcpiEvaluateObject(rp->ap_resource, "_ON", NULL, NULL))) {
559 DEBUG_PRINT(TRACE_OBJECTS, ("failed to switch %s on - %s\n",
560 acpi_name(rp->ap_resource), AcpiFormatException(status)));
559 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, "failed to switch %s on - %s\n",
560 acpi_name(rp->ap_resource), AcpiFormatException(status)));
561 } else {
561 } else {
562 DEBUG_PRINT(TRACE_OBJECTS, ("switched %s on\n", acpi_name(rp->ap_resource)));
562 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, "switched %s on\n", acpi_name(rp->ap_resource)));
563 }
564 } else {
563 }
564 } else {
565 DEBUG_PRINT(TRACE_OBJECTS, ("%s is already on\n", acpi_name(rp->ap_resource)));
565 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, "%s is already on\n", acpi_name(rp->ap_resource)));
566 }
567 }
568
569 /*
570 * Sweep the list backwards turning things off.
571 */
572 TAILQ_FOREACH_REVERSE(rp, &acpi_powerresources, acpi_powerresource_list, ap_link) {
573 if (TAILQ_FIRST(&rp->ap_references) != NULL) {
566 }
567 }
568
569 /*
570 * Sweep the list backwards turning things off.
571 */
572 TAILQ_FOREACH_REVERSE(rp, &acpi_powerresources, acpi_powerresource_list, ap_link) {
573 if (TAILQ_FIRST(&rp->ap_references) != NULL) {
574 DEBUG_PRINT(TRACE_OBJECTS, ("%s has references, not turning off\n",
575 acpi_name(rp->ap_resource)));
574 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, "%s has references, not turning off\n",
575 acpi_name(rp->ap_resource)));
576 continue;
577 }
578
579 /* we could cache this if we trusted it not to change under us */
580 if ((status = acpi_EvaluateInteger(rp->ap_resource, "_STA", &cur)) != AE_OK) {
576 continue;
577 }
578
579 /* we could cache this if we trusted it not to change under us */
580 if ((status = acpi_EvaluateInteger(rp->ap_resource, "_STA", &cur)) != AE_OK) {
581 DEBUG_PRINT(TRACE_OBJECTS, ("can't get status of %s - %d\n",
582 acpi_name(rp->ap_resource), status));
581 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, "can't get status of %s - %d\n",
582 acpi_name(rp->ap_resource), status));
583 continue; /* XXX is this correct? Always switch if in doubt? */
584 }
585
586 /*
587 * Switch if required. Note that we ignore the result of the switch
588 * effort; we don't know what to do if it fails, so checking wouldn't
589 * help much.
590 */
591 if (cur != ACPI_PWR_OFF) {
592 if (ACPI_FAILURE(status = AcpiEvaluateObject(rp->ap_resource, "_OFF", NULL, NULL))) {
583 continue; /* XXX is this correct? Always switch if in doubt? */
584 }
585
586 /*
587 * Switch if required. Note that we ignore the result of the switch
588 * effort; we don't know what to do if it fails, so checking wouldn't
589 * help much.
590 */
591 if (cur != ACPI_PWR_OFF) {
592 if (ACPI_FAILURE(status = AcpiEvaluateObject(rp->ap_resource, "_OFF", NULL, NULL))) {
593 DEBUG_PRINT(TRACE_OBJECTS, ("failed to switch %s off - %s\n",
594 acpi_name(rp->ap_resource), AcpiFormatException(status)));
593 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, "failed to switch %s off - %s\n",
594 acpi_name(rp->ap_resource), AcpiFormatException(status)));
595 } else {
595 } else {
596 DEBUG_PRINT(TRACE_OBJECTS, ("switched %s off\n", acpi_name(rp->ap_resource)));
596 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, "switched %s off\n", acpi_name(rp->ap_resource)));
597 }
598 } else {
597 }
598 } else {
599 DEBUG_PRINT(TRACE_OBJECTS, ("%s is already off\n", acpi_name(rp->ap_resource)));
599 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, "%s is already off\n", acpi_name(rp->ap_resource)));
600 }
601 }
602 return_ACPI_STATUS(AE_OK);
603}
604
605/*
606 * Find a power resource's control structure.
607 */

--- 29 unchanged lines hidden ---
600 }
601 }
602 return_ACPI_STATUS(AE_OK);
603}
604
605/*
606 * Find a power resource's control structure.
607 */

--- 29 unchanged lines hidden ---