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 --- 11 unchanged lines hidden (view full) --- 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 27#include <sys/cdefs.h> |
28__FBSDID("$FreeBSD: head/sys/dev/acpica/acpi_powerres.c 130208 2004-06-07 21:39:15Z njl $"); |
29 30#include "opt_acpi.h" 31#include <sys/param.h> 32#include <sys/kernel.h> 33#include <sys/malloc.h> 34#include <sys/bus.h> 35 36#include "acpi.h" --- 284 unchanged lines hidden (view full) --- 321 } 322 } 323 324 /* Check for valid transitions */ 325 if (pc->ac_state == ACPI_STATE_D3 && state != ACPI_STATE_D0) 326 return_ACPI_STATUS (AE_BAD_PARAMETER); /* can only go to D0 from D3 */ 327 328 /* Find transition mechanism(s) */ |
329 switch (state) { |
330 case ACPI_STATE_D0: 331 method_name = "_PS0"; 332 reslist_name = "_PR0"; 333 break; 334 case ACPI_STATE_D1: 335 method_name = "_PS1"; 336 reslist_name = "_PR1"; 337 break; --- 16 unchanged lines hidden (view full) --- 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). 357 * 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 360 * D0. 361 */ |
362 status = AE_BAD_PARAMETER; |
363 reslist_buffer.Pointer = NULL; 364 reslist_object = NULL; 365 if (ACPI_FAILURE(AcpiGetHandle(consumer, method_name, &method_handle))) 366 method_handle = NULL; 367 if (ACPI_FAILURE(AcpiGetHandle(consumer, reslist_name, &reslist_handle))) 368 reslist_handle = NULL; 369 if (reslist_handle == NULL && method_handle == NULL) { 370 if (state == ACPI_STATE_D0) { 371 pc->ac_state = ACPI_STATE_D0; 372 return_ACPI_STATUS (AE_OK); 373 } 374 if (state != ACPI_STATE_D3) 375 goto bad; 376 |
377 /* 378 * Turn off the resources listed in _PR0 to go to D3. If there is 379 * no _PR0 method, this object doesn't support ACPI power states. 380 */ 381 if (ACPI_FAILURE(AcpiGetHandle(consumer, "_PR0", &pr0_handle))) { 382 status = AE_NOT_FOUND; |
383 goto bad; |
384 } |
385 reslist_buffer.Length = ACPI_ALLOCATE_BUFFER; 386 status = AcpiEvaluateObject(pr0_handle, NULL, NULL, &reslist_buffer); 387 if (ACPI_FAILURE(status)) 388 goto bad; 389 reslist_object = (ACPI_OBJECT *)reslist_buffer.Pointer; 390 if (reslist_object->Type != ACPI_TYPE_PACKAGE || |
391 reslist_object->Package.Count == 0) |
392 goto bad; |
393 AcpiOsFree(reslist_buffer.Pointer); 394 reslist_buffer.Pointer = NULL; 395 reslist_object = NULL; 396 } 397 398 /* 399 * Check that we can actually fetch the list of power resources 400 */ --- 17 unchanged lines hidden (view full) --- 418 } 419 } 420 421 /* 422 * Now we are ready to switch, so kill off any current power 423 * resource references. 424 */ 425 res_changed = 0; |
426 while ((pr = TAILQ_FIRST(&pc->ac_references)) != NULL) { |
427 res_changed = 1; 428 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, "removing reference to %s\n", 429 acpi_name(pr->ar_resource->ap_resource))); 430 TAILQ_REMOVE(&pr->ar_resource->ap_references, pr, ar_rlink); 431 TAILQ_REMOVE(&pc->ac_references, pr, ar_clink); 432 free(pr, M_ACPIPWR); 433 } 434 --- 41 unchanged lines hidden (view full) --- 476 477 /* Transition was successful */ 478 pc->ac_state = state; 479 return_ACPI_STATUS (AE_OK); 480 481 bad: 482 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, 483 "attempt to set unsupported state D%d\n", state)); |
484 485 out: 486 if (reslist_buffer.Pointer != NULL) 487 AcpiOsFree(reslist_buffer.Pointer); 488 return_ACPI_STATUS (status); 489} 490 491/* --- 189 unchanged lines hidden --- |