acpi_powerres.c (89054) | acpi_powerres.c (91125) |
---|---|
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 89054 2002-01-08 06:46:01Z msmith $ | 26 * $FreeBSD: head/sys/dev/acpica/acpi_powerres.c 91125 2002-02-23 05:28:22Z 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> --- 35 unchanged lines hidden (view full) --- 70 */ 71 72MALLOC_DEFINE(M_ACPIPWR, "acpipwr", "ACPI power resources"); 73 74/* 75 * Hooks for the ACPI CA debugging infrastructure 76 */ 77#define _COMPONENT ACPI_POWER | 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> --- 35 unchanged lines hidden (view full) --- 70 */ 71 72MALLOC_DEFINE(M_ACPIPWR, "acpipwr", "ACPI power resources"); 73 74/* 75 * Hooks for the ACPI CA debugging infrastructure 76 */ 77#define _COMPONENT ACPI_POWER |
78MODULE_NAME("POWERRES") | 78ACPI_MODULE_NAME("POWERRES") |
79 80/* return values from _STA on a power resource */ 81#define ACPI_PWR_OFF 0 82#define ACPI_PWR_ON 1 83 84/* 85 * A relationship between a power resource and a consumer. 86 */ --- 56 unchanged lines hidden (view full) --- 143static ACPI_STATUS 144acpi_pwr_register_resource(ACPI_HANDLE res) 145{ 146 ACPI_STATUS status; 147 ACPI_BUFFER buf; 148 ACPI_OBJECT *obj; 149 struct acpi_powerresource *rp, *srp; 150 | 79 80/* return values from _STA on a power resource */ 81#define ACPI_PWR_OFF 0 82#define ACPI_PWR_ON 1 83 84/* 85 * A relationship between a power resource and a consumer. 86 */ --- 56 unchanged lines hidden (view full) --- 143static ACPI_STATUS 144acpi_pwr_register_resource(ACPI_HANDLE res) 145{ 146 ACPI_STATUS status; 147 ACPI_BUFFER buf; 148 ACPI_OBJECT *obj; 149 struct acpi_powerresource *rp, *srp; 150 |
151 FUNCTION_TRACE(__func__); | 151 ACPI_FUNCTION_TRACE(__func__); |
152 153 rp = NULL; | 152 153 rp = NULL; |
154 obj = NULL; | 154 buf.Pointer = NULL; |
155 156 /* look to see if we know about this resource */ 157 if (acpi_pwr_find_resource(res) != NULL) 158 return_ACPI_STATUS(AE_OK); /* already know about it */ 159 160 /* allocate a new resource */ 161 if ((rp = malloc(sizeof(*rp), M_ACPIPWR, M_NOWAIT | M_ZERO)) == NULL) { 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 */ | 155 156 /* look to see if we know about this resource */ 157 if (acpi_pwr_find_resource(res) != NULL) 158 return_ACPI_STATUS(AE_OK); /* already know about it */ 159 160 /* allocate a new resource */ 161 if ((rp = malloc(sizeof(*rp), M_ACPIPWR, M_NOWAIT | M_ZERO)) == NULL) { 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 bzero(&buf, sizeof(buf)); 170 if ((status = acpi_EvaluateIntoBuffer(res, NULL, NULL, &buf)) != AE_OK) { | 169 buf.Length = ACPI_ALLOCATE_BUFFER; 170 if (ACPI_FAILURE(status = AcpiEvaluateObject(res, NULL, NULL, &buf))) { |
171 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, "no power resource object\n")); 172 goto out; 173 } 174 obj = buf.Pointer; 175 if (obj->Type != ACPI_TYPE_POWER) { 176 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, "questionable power resource object %s\n", acpi_name(res))); 177 status = AE_TYPE; 178 goto out; --- 13 unchanged lines hidden (view full) --- 192 TAILQ_INSERT_BEFORE(srp, rp, ap_link); 193 goto done; 194 } 195 TAILQ_INSERT_TAIL(&acpi_powerresources, rp, ap_link); 196 197 done: 198 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, "registered power resource %s\n", acpi_name(res))); 199 out: | 171 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, "no power resource object\n")); 172 goto out; 173 } 174 obj = buf.Pointer; 175 if (obj->Type != ACPI_TYPE_POWER) { 176 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, "questionable power resource object %s\n", acpi_name(res))); 177 status = AE_TYPE; 178 goto out; --- 13 unchanged lines hidden (view full) --- 192 TAILQ_INSERT_BEFORE(srp, rp, ap_link); 193 goto done; 194 } 195 TAILQ_INSERT_TAIL(&acpi_powerresources, rp, ap_link); 196 197 done: 198 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, "registered power resource %s\n", acpi_name(res))); 199 out: |
200 if (obj != NULL) 201 AcpiOsFree(obj); 202 if ((status != AE_OK) && (rp != NULL)) | 200 if (buf.Pointer != NULL) 201 AcpiOsFree(buf.Pointer); 202 if (ACPI_FAILURE(status) && (rp != NULL)) |
203 free(rp, M_ACPIPWR); 204 return_ACPI_STATUS(status); 205} 206 207/* 208 * Deregister a power resource. 209 */ 210static ACPI_STATUS 211acpi_pwr_deregister_resource(ACPI_HANDLE res) 212{ 213 struct acpi_powerresource *rp; 214 | 203 free(rp, M_ACPIPWR); 204 return_ACPI_STATUS(status); 205} 206 207/* 208 * Deregister a power resource. 209 */ 210static ACPI_STATUS 211acpi_pwr_deregister_resource(ACPI_HANDLE res) 212{ 213 struct acpi_powerresource *rp; 214 |
215 FUNCTION_TRACE(__func__); | 215 ACPI_FUNCTION_TRACE(__func__); |
216 217 rp = NULL; 218 219 /* find the resource */ 220 if ((rp = acpi_pwr_find_resource(res)) == NULL) 221 return_ACPI_STATUS(AE_BAD_PARAMETER); 222 223 /* check that there are no consumers referencing this resource */ --- 14 unchanged lines hidden (view full) --- 238 * 239 * It's OK to call this if we already know about the consumer. 240 */ 241static ACPI_STATUS 242acpi_pwr_register_consumer(ACPI_HANDLE consumer) 243{ 244 struct acpi_powerconsumer *pc; 245 | 216 217 rp = NULL; 218 219 /* find the resource */ 220 if ((rp = acpi_pwr_find_resource(res)) == NULL) 221 return_ACPI_STATUS(AE_BAD_PARAMETER); 222 223 /* check that there are no consumers referencing this resource */ --- 14 unchanged lines hidden (view full) --- 238 * 239 * It's OK to call this if we already know about the consumer. 240 */ 241static ACPI_STATUS 242acpi_pwr_register_consumer(ACPI_HANDLE consumer) 243{ 244 struct acpi_powerconsumer *pc; 245 |
246 FUNCTION_TRACE(__func__); | 246 ACPI_FUNCTION_TRACE(__func__); |
247 248 /* check to see whether we know about this consumer already */ 249 if ((pc = acpi_pwr_find_consumer(consumer)) != NULL) 250 return_ACPI_STATUS(AE_OK); 251 252 /* allocate a new power consumer */ 253 if ((pc = malloc(sizeof(*pc), M_ACPIPWR, M_NOWAIT)) == NULL) 254 return_ACPI_STATUS(AE_NO_MEMORY); --- 14 unchanged lines hidden (view full) --- 269 * This should only be done once the consumer has been powered off. 270 * (XXX is this correct? Check once implemented) 271 */ 272static ACPI_STATUS 273acpi_pwr_deregister_consumer(ACPI_HANDLE consumer) 274{ 275 struct acpi_powerconsumer *pc; 276 | 247 248 /* check to see whether we know about this consumer already */ 249 if ((pc = acpi_pwr_find_consumer(consumer)) != NULL) 250 return_ACPI_STATUS(AE_OK); 251 252 /* allocate a new power consumer */ 253 if ((pc = malloc(sizeof(*pc), M_ACPIPWR, M_NOWAIT)) == NULL) 254 return_ACPI_STATUS(AE_NO_MEMORY); --- 14 unchanged lines hidden (view full) --- 269 * This should only be done once the consumer has been powered off. 270 * (XXX is this correct? Check once implemented) 271 */ 272static ACPI_STATUS 273acpi_pwr_deregister_consumer(ACPI_HANDLE consumer) 274{ 275 struct acpi_powerconsumer *pc; 276 |
277 FUNCTION_TRACE(__func__); | 277 ACPI_FUNCTION_TRACE(__func__); |
278 279 /* find the consumer */ 280 if ((pc = acpi_pwr_find_consumer(consumer)) == NULL) 281 return_ACPI_STATUS(AE_BAD_PARAMETER); 282 283 /* make sure the consumer's not referencing anything right now */ 284 if (TAILQ_FIRST(&pc->ac_references) != NULL) 285 return_ACPI_STATUS(AE_BAD_PARAMETER); --- 16 unchanged lines hidden (view full) --- 302 struct acpi_powerreference *pr; 303 ACPI_HANDLE method_handle, reslist_handle, pr0_handle; 304 ACPI_BUFFER reslist_buffer; 305 ACPI_OBJECT *reslist_object; 306 ACPI_STATUS status; 307 char *method_name, *reslist_name; 308 int res_changed; 309 | 278 279 /* find the consumer */ 280 if ((pc = acpi_pwr_find_consumer(consumer)) == NULL) 281 return_ACPI_STATUS(AE_BAD_PARAMETER); 282 283 /* make sure the consumer's not referencing anything right now */ 284 if (TAILQ_FIRST(&pc->ac_references) != NULL) 285 return_ACPI_STATUS(AE_BAD_PARAMETER); --- 16 unchanged lines hidden (view full) --- 302 struct acpi_powerreference *pr; 303 ACPI_HANDLE method_handle, reslist_handle, pr0_handle; 304 ACPI_BUFFER reslist_buffer; 305 ACPI_OBJECT *reslist_object; 306 ACPI_STATUS status; 307 char *method_name, *reslist_name; 308 int res_changed; 309 |
310 FUNCTION_TRACE(__func__); | 310 ACPI_FUNCTION_TRACE(__func__); |
311 312 /* find the consumer */ 313 if ((pc = acpi_pwr_find_consumer(consumer)) == NULL) { | 311 312 /* find the consumer */ 313 if ((pc = acpi_pwr_find_consumer(consumer)) == NULL) { |
314 if ((status = acpi_pwr_register_consumer(consumer)) != AE_OK) | 314 if (ACPI_FAILURE(status = acpi_pwr_register_consumer(consumer))) |
315 return_ACPI_STATUS(status); 316 if ((pc = acpi_pwr_find_consumer(consumer)) == NULL) { 317 return_ACPI_STATUS(AE_ERROR); /* something very wrong */ 318 } 319 } 320 321 /* check for valid transitions */ 322 if ((pc->ac_state == ACPI_STATE_D3) && (state != ACPI_STATE_D0)) --- 28 unchanged lines hidden (view full) --- 351 * reslist must be present. We need to do this before we go 352 * dereferencing resources (since we might be trying to go to 353 * a state we don't support). 354 * 355 * Note that if any states are supported, the device has to 356 * support D0 and D3. It's never an error to try to go to 357 * D0. 358 */ | 315 return_ACPI_STATUS(status); 316 if ((pc = acpi_pwr_find_consumer(consumer)) == NULL) { 317 return_ACPI_STATUS(AE_ERROR); /* something very wrong */ 318 } 319 } 320 321 /* check for valid transitions */ 322 if ((pc->ac_state == ACPI_STATE_D3) && (state != ACPI_STATE_D0)) --- 28 unchanged lines hidden (view full) --- 351 * reslist must be present. We need to do this before we go 352 * dereferencing resources (since we might be trying to go to 353 * a state we don't support). 354 * 355 * Note that if any states are supported, the device has to 356 * support D0 and D3. It's never an error to try to go to 357 * D0. 358 */ |
359 reslist_buffer.Pointer = NULL; |
|
359 reslist_object = NULL; | 360 reslist_object = NULL; |
360 if (AcpiGetHandle(consumer, method_name, &method_handle) != AE_OK) | 361 if (ACPI_FAILURE(AcpiGetHandle(consumer, method_name, &method_handle))) |
361 method_handle = NULL; | 362 method_handle = NULL; |
362 if (AcpiGetHandle(consumer, reslist_name, &reslist_handle) != AE_OK) | 363 if (ACPI_FAILURE(AcpiGetHandle(consumer, reslist_name, &reslist_handle))) |
363 reslist_handle = NULL; 364 if ((reslist_handle == NULL) && (method_handle == NULL)) { 365 if (state == ACPI_STATE_D0) { 366 pc->ac_state = ACPI_STATE_D0; 367 return_ACPI_STATUS(AE_OK); 368 } 369 if (state != ACPI_STATE_D3) { 370 goto bad; 371 } 372 373 /* turn off the resources listed in _PR0 to go to D3. */ | 364 reslist_handle = NULL; 365 if ((reslist_handle == NULL) && (method_handle == NULL)) { 366 if (state == ACPI_STATE_D0) { 367 pc->ac_state = ACPI_STATE_D0; 368 return_ACPI_STATUS(AE_OK); 369 } 370 if (state != ACPI_STATE_D3) { 371 goto bad; 372 } 373 374 /* turn off the resources listed in _PR0 to go to D3. */ |
374 if (AcpiGetHandle(consumer, "_PR0", &pr0_handle) != AE_OK) { | 375 if (ACPI_FAILURE(AcpiGetHandle(consumer, "_PR0", &pr0_handle))) { |
375 goto bad; 376 } | 376 goto bad; 377 } |
377 bzero(&reslist_buffer, sizeof(reslist_buffer)); 378 status = acpi_EvaluateIntoBuffer(pr0_handle, NULL, NULL, &reslist_buffer); 379 if (status != AE_OK) { | 378 reslist_buffer.Length = ACPI_ALLOCATE_BUFFER; 379 if (ACPI_FAILURE(status = AcpiEvaluateObject(pr0_handle, NULL, NULL, &reslist_buffer))) { |
380 goto bad; 381 } 382 reslist_object = (ACPI_OBJECT *)reslist_buffer.Pointer; 383 if ((reslist_object->Type != ACPI_TYPE_PACKAGE) || 384 (reslist_object->Package.Count == 0)) { 385 goto bad; 386 } | 380 goto bad; 381 } 382 reslist_object = (ACPI_OBJECT *)reslist_buffer.Pointer; 383 if ((reslist_object->Type != ACPI_TYPE_PACKAGE) || 384 (reslist_object->Package.Count == 0)) { 385 goto bad; 386 } |
387 AcpiOsFree(reslist_object); | 387 AcpiOsFree(reslist_buffer.Pointer); 388 reslist_buffer.Pointer = NULL; 389 reslist_object = NULL; |
388 } 389 390 /* 391 * Check that we can actually fetch the list of power resources 392 */ 393 if (reslist_handle != NULL) { | 390 } 391 392 /* 393 * Check that we can actually fetch the list of power resources 394 */ 395 if (reslist_handle != NULL) { |
394 bzero(&reslist_buffer, sizeof(reslist_buffer)); 395 if ((status = acpi_EvaluateIntoBuffer(reslist_handle, NULL, NULL, &reslist_buffer)) != AE_OK) { | 396 reslist_buffer.Length = ACPI_ALLOCATE_BUFFER; 397 if (ACPI_FAILURE(status = AcpiEvaluateObject(reslist_handle, NULL, NULL, &reslist_buffer))) { |
396 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, "can't evaluate resource list %s\n", 397 acpi_name(reslist_handle))); | 398 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, "can't evaluate resource list %s\n", 399 acpi_name(reslist_handle))); |
398 return_ACPI_STATUS(status); | 400 goto out; |
399 } 400 reslist_object = (ACPI_OBJECT *)reslist_buffer.Pointer; 401 if (reslist_object->Type != ACPI_TYPE_PACKAGE) { 402 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, "resource list is not ACPI_TYPE_PACKAGE (%d)\n", 403 reslist_object->Type)); | 401 } 402 reslist_object = (ACPI_OBJECT *)reslist_buffer.Pointer; 403 if (reslist_object->Type != ACPI_TYPE_PACKAGE) { 404 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, "resource list is not ACPI_TYPE_PACKAGE (%d)\n", 405 reslist_object->Type)); |
404 return_ACPI_STATUS(AE_TYPE); | 406 status = AE_TYPE; 407 goto out; |
405 } | 408 } |
406 } else { 407 reslist_object = NULL; | |
408 } 409 410 /* 411 * Now we are ready to switch, so kill off any current power resource references. 412 */ 413 res_changed = 0; 414 while((pr = TAILQ_FIRST(&pc->ac_references)) != NULL) { 415 res_changed = 1; --- 14 unchanged lines hidden (view full) --- 430 acpi_ForeachPackageObject(reslist_object, acpi_pwr_reference_resource, pc); 431 res_changed = 1; 432 } 433 434 /* 435 * If we changed anything in the resource list, we need to run a switch 436 * pass now. 437 */ | 409 } 410 411 /* 412 * Now we are ready to switch, so kill off any current power resource references. 413 */ 414 res_changed = 0; 415 while((pr = TAILQ_FIRST(&pc->ac_references)) != NULL) { 416 res_changed = 1; --- 14 unchanged lines hidden (view full) --- 431 acpi_ForeachPackageObject(reslist_object, acpi_pwr_reference_resource, pc); 432 res_changed = 1; 433 } 434 435 /* 436 * If we changed anything in the resource list, we need to run a switch 437 * pass now. 438 */ |
438 if ((status = acpi_pwr_switch_power()) != AE_OK) { | 439 if (ACPI_FAILURE(status = acpi_pwr_switch_power())) { |
439 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, "failed to correctly switch resources to move %s to D%d\n", 440 acpi_name(consumer), state)); | 440 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, "failed to correctly switch resources to move %s to D%d\n", 441 acpi_name(consumer), state)); |
441 return_ACPI_STATUS(status); /* XXX is this appropriate? Should we return to previous state? */ | 442 goto out; /* XXX is this appropriate? Should we return to previous state? */ |
442 } 443 444 /* invoke power state switch method (if present) */ 445 if (method_handle != NULL) { 446 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, "invoking state transition method %s\n", 447 acpi_name(method_handle))); | 443 } 444 445 /* invoke power state switch method (if present) */ 446 if (method_handle != NULL) { 447 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, "invoking state transition method %s\n", 448 acpi_name(method_handle))); |
448 if ((status = AcpiEvaluateObject(method_handle, NULL, NULL, NULL)) != AE_OK) 449 pc->ac_state = ACPI_STATE_UNKNOWN; 450 return_ACPI_STATUS(status); /* XXX is this appropriate? Should we return to previous state? */ | 449 if (ACPI_FAILURE(status = AcpiEvaluateObject(method_handle, NULL, NULL, NULL))) { 450 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, "failed to set state - %s\n", 451 AcpiFormatException(status))); 452 pc->ac_state = ACPI_STATE_UNKNOWN; 453 goto out; /* XXX Should we return to previous state? */ 454 } |
451 } | 455 } |
452 | 456 |
453 /* transition was successful */ 454 pc->ac_state = state; 455 return_ACPI_STATUS(AE_OK); 456 457 bad: 458 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, "attempt to set unsupported state D%d\n", 459 state)); | 457 /* transition was successful */ 458 pc->ac_state = state; 459 return_ACPI_STATUS(AE_OK); 460 461 bad: 462 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, "attempt to set unsupported state D%d\n", 463 state)); |
460 if (reslist_object) 461 AcpiOsFree(reslist_object); 462 return_ACPI_STATUS(AE_BAD_PARAMETER); | 464 status = AE_BAD_PARAMETER; 465 466 out: 467 if (reslist_buffer.Pointer != NULL) 468 AcpiOsFree(reslist_buffer.Pointer); 469 return_ACPI_STATUS(status); |
463} 464 465/* 466 * Called to create a reference between a power consumer and a power resource 467 * identified in the object. 468 */ 469static void 470acpi_pwr_reference_resource(ACPI_OBJECT *obj, void *arg) 471{ 472 struct acpi_powerconsumer *pc = (struct acpi_powerconsumer *)arg; 473 struct acpi_powerreference *pr; 474 struct acpi_powerresource *rp; 475 ACPI_HANDLE res; 476 ACPI_STATUS status; 477 | 470} 471 472/* 473 * Called to create a reference between a power consumer and a power resource 474 * identified in the object. 475 */ 476static void 477acpi_pwr_reference_resource(ACPI_OBJECT *obj, void *arg) 478{ 479 struct acpi_powerconsumer *pc = (struct acpi_powerconsumer *)arg; 480 struct acpi_powerreference *pr; 481 struct acpi_powerresource *rp; 482 ACPI_HANDLE res; 483 ACPI_STATUS status; 484 |
478 FUNCTION_TRACE(__func__); | 485 ACPI_FUNCTION_TRACE(__func__); |
479 480 /* check the object type */ 481 if (obj->Type != ACPI_TYPE_STRING) { 482 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, "don't know how to create a power reference to object type %d\n", 483 obj->Type)); 484 return_VOID; 485 } 486 --- 41 unchanged lines hidden (view full) --- 528 */ 529static ACPI_STATUS 530acpi_pwr_switch_power(void) 531{ 532 struct acpi_powerresource *rp; 533 ACPI_STATUS status; 534 int cur; 535 | 486 487 /* check the object type */ 488 if (obj->Type != ACPI_TYPE_STRING) { 489 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, "don't know how to create a power reference to object type %d\n", 490 obj->Type)); 491 return_VOID; 492 } 493 --- 41 unchanged lines hidden (view full) --- 535 */ 536static ACPI_STATUS 537acpi_pwr_switch_power(void) 538{ 539 struct acpi_powerresource *rp; 540 ACPI_STATUS status; 541 int cur; 542 |
536 FUNCTION_TRACE(__func__); | 543 ACPI_FUNCTION_TRACE(__func__); |
537 538 /* 539 * Sweep the list forwards turning things on. 540 */ 541 TAILQ_FOREACH(rp, &acpi_powerresources, ap_link) { 542 if (TAILQ_FIRST(&rp->ap_references) == NULL) { 543 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, "%s has no references, not turning on\n", 544 acpi_name(rp->ap_resource))); 545 continue; 546 } 547 548 /* we could cache this if we trusted it not to change under us */ | 544 545 /* 546 * Sweep the list forwards turning things on. 547 */ 548 TAILQ_FOREACH(rp, &acpi_powerresources, ap_link) { 549 if (TAILQ_FIRST(&rp->ap_references) == NULL) { 550 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, "%s has no references, not turning on\n", 551 acpi_name(rp->ap_resource))); 552 continue; 553 } 554 555 /* we could cache this if we trusted it not to change under us */ |
549 if ((status = acpi_EvaluateInteger(rp->ap_resource, "_STA", &cur)) != AE_OK) { | 556 if (ACPI_FAILURE(status = acpi_EvaluateInteger(rp->ap_resource, "_STA", &cur))) { |
550 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, "can't get status of %s - %d\n", 551 acpi_name(rp->ap_resource), status)); 552 continue; /* XXX is this correct? Always switch if in doubt? */ 553 } 554 555 /* 556 * Switch if required. Note that we ignore the result of the switch 557 * effort; we don't know what to do if it fails, so checking wouldn't --- 17 unchanged lines hidden (view full) --- 575 TAILQ_FOREACH_REVERSE(rp, &acpi_powerresources, acpi_powerresource_list, ap_link) { 576 if (TAILQ_FIRST(&rp->ap_references) != NULL) { 577 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, "%s has references, not turning off\n", 578 acpi_name(rp->ap_resource))); 579 continue; 580 } 581 582 /* we could cache this if we trusted it not to change under us */ | 557 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, "can't get status of %s - %d\n", 558 acpi_name(rp->ap_resource), status)); 559 continue; /* XXX is this correct? Always switch if in doubt? */ 560 } 561 562 /* 563 * Switch if required. Note that we ignore the result of the switch 564 * effort; we don't know what to do if it fails, so checking wouldn't --- 17 unchanged lines hidden (view full) --- 582 TAILQ_FOREACH_REVERSE(rp, &acpi_powerresources, acpi_powerresource_list, ap_link) { 583 if (TAILQ_FIRST(&rp->ap_references) != NULL) { 584 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, "%s has references, not turning off\n", 585 acpi_name(rp->ap_resource))); 586 continue; 587 } 588 589 /* we could cache this if we trusted it not to change under us */ |
583 if ((status = acpi_EvaluateInteger(rp->ap_resource, "_STA", &cur)) != AE_OK) { | 590 if (ACPI_FAILURE(status = acpi_EvaluateInteger(rp->ap_resource, "_STA", &cur))) { |
584 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, "can't get status of %s - %d\n", 585 acpi_name(rp->ap_resource), status)); 586 continue; /* XXX is this correct? Always switch if in doubt? */ 587 } 588 589 /* 590 * Switch if required. Note that we ignore the result of the switch 591 * effort; we don't know what to do if it fails, so checking wouldn't --- 16 unchanged lines hidden (view full) --- 608/* 609 * Find a power resource's control structure. 610 */ 611static struct acpi_powerresource * 612acpi_pwr_find_resource(ACPI_HANDLE res) 613{ 614 struct acpi_powerresource *rp; 615 | 591 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, "can't get status of %s - %d\n", 592 acpi_name(rp->ap_resource), status)); 593 continue; /* XXX is this correct? Always switch if in doubt? */ 594 } 595 596 /* 597 * Switch if required. Note that we ignore the result of the switch 598 * effort; we don't know what to do if it fails, so checking wouldn't --- 16 unchanged lines hidden (view full) --- 615/* 616 * Find a power resource's control structure. 617 */ 618static struct acpi_powerresource * 619acpi_pwr_find_resource(ACPI_HANDLE res) 620{ 621 struct acpi_powerresource *rp; 622 |
616 FUNCTION_TRACE(__func__); | 623 ACPI_FUNCTION_TRACE(__func__); |
617 618 TAILQ_FOREACH(rp, &acpi_powerresources, ap_link) 619 if (rp->ap_resource == res) 620 break; 621 return_PTR(rp); 622} 623 624/* 625 * Find a power consumer's control structure. 626 */ 627static struct acpi_powerconsumer * 628acpi_pwr_find_consumer(ACPI_HANDLE consumer) 629{ 630 struct acpi_powerconsumer *pc; 631 | 624 625 TAILQ_FOREACH(rp, &acpi_powerresources, ap_link) 626 if (rp->ap_resource == res) 627 break; 628 return_PTR(rp); 629} 630 631/* 632 * Find a power consumer's control structure. 633 */ 634static struct acpi_powerconsumer * 635acpi_pwr_find_consumer(ACPI_HANDLE consumer) 636{ 637 struct acpi_powerconsumer *pc; 638 |
632 FUNCTION_TRACE(__func__); | 639 ACPI_FUNCTION_TRACE(__func__); |
633 634 TAILQ_FOREACH(pc, &acpi_powerconsumers, ac_link) 635 if (pc->ac_consumer == consumer) 636 break; 637 return_PTR(pc); 638} 639 | 640 641 TAILQ_FOREACH(pc, &acpi_powerconsumers, ac_link) 642 if (pc->ac_consumer == consumer) 643 break; 644 return_PTR(pc); 645} 646 |