diff options
author | Rafael J. Wysocki <rafael.j.wysocki@intel.com> | 2013-06-28 06:58:30 -0400 |
---|---|---|
committer | Rafael J. Wysocki <rafael.j.wysocki@intel.com> | 2013-06-28 06:58:30 -0400 |
commit | 3b4550e0e0cd24d8073dc571cecb0d4aa4ca3542 (patch) | |
tree | 44af05a1ac1c85621fa1d06d50d6b127a4cc83bb /drivers/acpi | |
parent | 8e9914d5efe460600f5948da7ae4c1b6c038a4c0 (diff) | |
parent | fa1675b56537651270e79967b7f1ee4202c83bf6 (diff) |
Merge branch 'acpi-pm'
* acpi-pm:
ACPI / PM: Rework and clean up acpi_dev_pm_get_state()
ACPI / PM: Replace ACPI_STATE_D3 with ACPI_STATE_D3_COLD in device_pm.c
ACPI / PM: Rename function acpi_device_power_state() and make it static
ACPI / PM: acpi_processor_suspend() can be static
xen / ACPI / sleep: Register an acpi_suspend_lowlevel callback.
x86 / ACPI / sleep: Provide registration for acpi_suspend_lowlevel.
Diffstat (limited to 'drivers/acpi')
-rw-r--r-- | drivers/acpi/device_pm.c | 165 | ||||
-rw-r--r-- | drivers/acpi/processor_idle.c | 4 | ||||
-rw-r--r-- | drivers/acpi/sleep.c | 2 |
3 files changed, 99 insertions, 72 deletions
diff --git a/drivers/acpi/device_pm.c b/drivers/acpi/device_pm.c index 31c217a42839..5f3597b87f27 100644 --- a/drivers/acpi/device_pm.c +++ b/drivers/acpi/device_pm.c | |||
@@ -419,62 +419,73 @@ bool acpi_bus_can_wakeup(acpi_handle handle) | |||
419 | EXPORT_SYMBOL(acpi_bus_can_wakeup); | 419 | EXPORT_SYMBOL(acpi_bus_can_wakeup); |
420 | 420 | ||
421 | /** | 421 | /** |
422 | * acpi_device_power_state - Get preferred power state of ACPI device. | 422 | * acpi_dev_pm_get_state - Get preferred power state of ACPI device. |
423 | * @dev: Device whose preferred target power state to return. | 423 | * @dev: Device whose preferred target power state to return. |
424 | * @adev: ACPI device node corresponding to @dev. | 424 | * @adev: ACPI device node corresponding to @dev. |
425 | * @target_state: System state to match the resultant device state. | 425 | * @target_state: System state to match the resultant device state. |
426 | * @d_max_in: Deepest low-power state to take into consideration. | 426 | * @d_min_p: Location to store the highest power state available to the device. |
427 | * @d_min_p: Location to store the upper limit of the allowed states range. | 427 | * @d_max_p: Location to store the lowest power state available to the device. |
428 | * Return value: Preferred power state of the device on success, -ENODEV | ||
429 | * (if there's no 'struct acpi_device' for @dev) or -EINVAL on failure | ||
430 | * | 428 | * |
431 | * Find the lowest power (highest number) ACPI device power state that the | 429 | * Find the lowest power (highest number) and highest power (lowest number) ACPI |
432 | * device can be in while the system is in the state represented by | 430 | * device power states that the device can be in while the system is in the |
433 | * @target_state. If @d_min_p is set, the highest power (lowest number) device | 431 | * state represented by @target_state. Store the integer numbers representing |
434 | * power state that @dev can be in for the given system sleep state is stored | 432 | * those stats in the memory locations pointed to by @d_max_p and @d_min_p, |
435 | * at the location pointed to by it. | 433 | * respectively. |
436 | * | 434 | * |
437 | * Callers must ensure that @dev and @adev are valid pointers and that @adev | 435 | * Callers must ensure that @dev and @adev are valid pointers and that @adev |
438 | * actually corresponds to @dev before using this function. | 436 | * actually corresponds to @dev before using this function. |
437 | * | ||
438 | * Returns 0 on success or -ENODATA when one of the ACPI methods fails or | ||
439 | * returns a value that doesn't make sense. The memory locations pointed to by | ||
440 | * @d_max_p and @d_min_p are only modified on success. | ||
439 | */ | 441 | */ |
440 | int acpi_device_power_state(struct device *dev, struct acpi_device *adev, | 442 | static int acpi_dev_pm_get_state(struct device *dev, struct acpi_device *adev, |
441 | u32 target_state, int d_max_in, int *d_min_p) | 443 | u32 target_state, int *d_min_p, int *d_max_p) |
442 | { | 444 | { |
443 | char acpi_method[] = "_SxD"; | 445 | char method[] = { '_', 'S', '0' + target_state, 'D', '\0' }; |
444 | unsigned long long d_min, d_max; | 446 | acpi_handle handle = adev->handle; |
447 | unsigned long long ret; | ||
448 | int d_min, d_max; | ||
445 | bool wakeup = false; | 449 | bool wakeup = false; |
450 | acpi_status status; | ||
446 | 451 | ||
447 | if (d_max_in < ACPI_STATE_D0 || d_max_in > ACPI_STATE_D3) | ||
448 | return -EINVAL; | ||
449 | |||
450 | if (d_max_in > ACPI_STATE_D3_HOT) { | ||
451 | enum pm_qos_flags_status stat; | ||
452 | |||
453 | stat = dev_pm_qos_flags(dev, PM_QOS_FLAG_NO_POWER_OFF); | ||
454 | if (stat == PM_QOS_FLAGS_ALL) | ||
455 | d_max_in = ACPI_STATE_D3_HOT; | ||
456 | } | ||
457 | |||
458 | acpi_method[2] = '0' + target_state; | ||
459 | /* | 452 | /* |
460 | * If the sleep state is S0, the lowest limit from ACPI is D3, | 453 | * If the system state is S0, the lowest power state the device can be |
461 | * but if the device has _S0W, we will use the value from _S0W | 454 | * in is D3cold, unless the device has _S0W and is supposed to signal |
462 | * as the lowest limit from ACPI. Finally, we will constrain | 455 | * wakeup, in which case the return value of _S0W has to be used as the |
463 | * the lowest limit with the specified one. | 456 | * lowest power state available to the device. |
464 | */ | 457 | */ |
465 | d_min = ACPI_STATE_D0; | 458 | d_min = ACPI_STATE_D0; |
466 | d_max = ACPI_STATE_D3; | 459 | d_max = ACPI_STATE_D3_COLD; |
467 | 460 | ||
468 | /* | 461 | /* |
469 | * If present, _SxD methods return the minimum D-state (highest power | 462 | * If present, _SxD methods return the minimum D-state (highest power |
470 | * state) we can use for the corresponding S-states. Otherwise, the | 463 | * state) we can use for the corresponding S-states. Otherwise, the |
471 | * minimum D-state is D0 (ACPI 3.x). | 464 | * minimum D-state is D0 (ACPI 3.x). |
472 | * | ||
473 | * NOTE: We rely on acpi_evaluate_integer() not clobbering the integer | ||
474 | * provided -- that's our fault recovery, we ignore retval. | ||
475 | */ | 465 | */ |
476 | if (target_state > ACPI_STATE_S0) { | 466 | if (target_state > ACPI_STATE_S0) { |
477 | acpi_evaluate_integer(adev->handle, acpi_method, NULL, &d_min); | 467 | /* |
468 | * We rely on acpi_evaluate_integer() not clobbering the integer | ||
469 | * provided if AE_NOT_FOUND is returned. | ||
470 | */ | ||
471 | ret = d_min; | ||
472 | status = acpi_evaluate_integer(handle, method, NULL, &ret); | ||
473 | if ((ACPI_FAILURE(status) && status != AE_NOT_FOUND) | ||
474 | || ret > ACPI_STATE_D3_COLD) | ||
475 | return -ENODATA; | ||
476 | |||
477 | /* | ||
478 | * We need to handle legacy systems where D3hot and D3cold are | ||
479 | * the same and 3 is returned in both cases, so fall back to | ||
480 | * D3cold if D3hot is not a valid state. | ||
481 | */ | ||
482 | if (!adev->power.states[ret].flags.valid) { | ||
483 | if (ret == ACPI_STATE_D3_HOT) | ||
484 | ret = ACPI_STATE_D3_COLD; | ||
485 | else | ||
486 | return -ENODATA; | ||
487 | } | ||
488 | d_min = ret; | ||
478 | wakeup = device_may_wakeup(dev) && adev->wakeup.flags.valid | 489 | wakeup = device_may_wakeup(dev) && adev->wakeup.flags.valid |
479 | && adev->wakeup.sleep_state >= target_state; | 490 | && adev->wakeup.sleep_state >= target_state; |
480 | } else if (dev_pm_qos_flags(dev, PM_QOS_FLAG_REMOTE_WAKEUP) != | 491 | } else if (dev_pm_qos_flags(dev, PM_QOS_FLAG_REMOTE_WAKEUP) != |
@@ -490,38 +501,30 @@ int acpi_device_power_state(struct device *dev, struct acpi_device *adev, | |||
490 | * can wake the system. _S0W may be valid, too. | 501 | * can wake the system. _S0W may be valid, too. |
491 | */ | 502 | */ |
492 | if (wakeup) { | 503 | if (wakeup) { |
493 | acpi_status status; | 504 | method[3] = 'W'; |
494 | 505 | status = acpi_evaluate_integer(handle, method, NULL, &ret); | |
495 | acpi_method[3] = 'W'; | 506 | if (status == AE_NOT_FOUND) { |
496 | status = acpi_evaluate_integer(adev->handle, acpi_method, NULL, | 507 | if (target_state > ACPI_STATE_S0) |
497 | &d_max); | ||
498 | if (ACPI_FAILURE(status)) { | ||
499 | if (target_state != ACPI_STATE_S0 || | ||
500 | status != AE_NOT_FOUND) | ||
501 | d_max = d_min; | 508 | d_max = d_min; |
502 | } else if (d_max < d_min) { | 509 | } else if (ACPI_SUCCESS(status) && ret <= ACPI_STATE_D3_COLD) { |
503 | /* Warn the user of the broken DSDT */ | 510 | /* Fall back to D3cold if ret is not a valid state. */ |
504 | printk(KERN_WARNING "ACPI: Wrong value from %s\n", | 511 | if (!adev->power.states[ret].flags.valid) |
505 | acpi_method); | 512 | ret = ACPI_STATE_D3_COLD; |
506 | /* Sanitize it */ | 513 | |
507 | d_min = d_max; | 514 | d_max = ret > d_min ? ret : d_min; |
515 | } else { | ||
516 | return -ENODATA; | ||
508 | } | 517 | } |
509 | } | 518 | } |
510 | 519 | ||
511 | if (d_max_in < d_min) | ||
512 | return -EINVAL; | ||
513 | if (d_min_p) | 520 | if (d_min_p) |
514 | *d_min_p = d_min; | 521 | *d_min_p = d_min; |
515 | /* constrain d_max with specified lowest limit (max number) */ | 522 | |
516 | if (d_max > d_max_in) { | 523 | if (d_max_p) |
517 | for (d_max = d_max_in; d_max > d_min; d_max--) { | 524 | *d_max_p = d_max; |
518 | if (adev->power.states[d_max].flags.valid) | 525 | |
519 | break; | 526 | return 0; |
520 | } | ||
521 | } | ||
522 | return d_max; | ||
523 | } | 527 | } |
524 | EXPORT_SYMBOL_GPL(acpi_device_power_state); | ||
525 | 528 | ||
526 | /** | 529 | /** |
527 | * acpi_pm_device_sleep_state - Get preferred power state of ACPI device. | 530 | * acpi_pm_device_sleep_state - Get preferred power state of ACPI device. |
@@ -529,7 +532,8 @@ EXPORT_SYMBOL_GPL(acpi_device_power_state); | |||
529 | * @d_min_p: Location to store the upper limit of the allowed states range. | 532 | * @d_min_p: Location to store the upper limit of the allowed states range. |
530 | * @d_max_in: Deepest low-power state to take into consideration. | 533 | * @d_max_in: Deepest low-power state to take into consideration. |
531 | * Return value: Preferred power state of the device on success, -ENODEV | 534 | * Return value: Preferred power state of the device on success, -ENODEV |
532 | * (if there's no 'struct acpi_device' for @dev) or -EINVAL on failure | 535 | * if there's no 'struct acpi_device' for @dev, -EINVAL if @d_max_in is |
536 | * incorrect, or -ENODATA on ACPI method failure. | ||
533 | * | 537 | * |
534 | * The caller must ensure that @dev is valid before using this function. | 538 | * The caller must ensure that @dev is valid before using this function. |
535 | */ | 539 | */ |
@@ -537,14 +541,39 @@ int acpi_pm_device_sleep_state(struct device *dev, int *d_min_p, int d_max_in) | |||
537 | { | 541 | { |
538 | acpi_handle handle = DEVICE_ACPI_HANDLE(dev); | 542 | acpi_handle handle = DEVICE_ACPI_HANDLE(dev); |
539 | struct acpi_device *adev; | 543 | struct acpi_device *adev; |
544 | int ret, d_max; | ||
545 | |||
546 | if (d_max_in < ACPI_STATE_D0 || d_max_in > ACPI_STATE_D3_COLD) | ||
547 | return -EINVAL; | ||
548 | |||
549 | if (d_max_in > ACPI_STATE_D3_HOT) { | ||
550 | enum pm_qos_flags_status stat; | ||
551 | |||
552 | stat = dev_pm_qos_flags(dev, PM_QOS_FLAG_NO_POWER_OFF); | ||
553 | if (stat == PM_QOS_FLAGS_ALL) | ||
554 | d_max_in = ACPI_STATE_D3_HOT; | ||
555 | } | ||
540 | 556 | ||
541 | if (!handle || acpi_bus_get_device(handle, &adev)) { | 557 | if (!handle || acpi_bus_get_device(handle, &adev)) { |
542 | dev_dbg(dev, "ACPI handle without context in %s!\n", __func__); | 558 | dev_dbg(dev, "ACPI handle without context in %s!\n", __func__); |
543 | return -ENODEV; | 559 | return -ENODEV; |
544 | } | 560 | } |
545 | 561 | ||
546 | return acpi_device_power_state(dev, adev, acpi_target_system_state(), | 562 | ret = acpi_dev_pm_get_state(dev, adev, acpi_target_system_state(), |
547 | d_max_in, d_min_p); | 563 | d_min_p, &d_max); |
564 | if (ret) | ||
565 | return ret; | ||
566 | |||
567 | if (d_max_in < *d_min_p) | ||
568 | return -EINVAL; | ||
569 | |||
570 | if (d_max > d_max_in) { | ||
571 | for (d_max = d_max_in; d_max > *d_min_p; d_max--) { | ||
572 | if (adev->power.states[d_max].flags.valid) | ||
573 | break; | ||
574 | } | ||
575 | } | ||
576 | return d_max; | ||
548 | } | 577 | } |
549 | EXPORT_SYMBOL(acpi_pm_device_sleep_state); | 578 | EXPORT_SYMBOL(acpi_pm_device_sleep_state); |
550 | 579 | ||
@@ -695,17 +724,13 @@ struct acpi_device *acpi_dev_pm_get_node(struct device *dev) | |||
695 | static int acpi_dev_pm_low_power(struct device *dev, struct acpi_device *adev, | 724 | static int acpi_dev_pm_low_power(struct device *dev, struct acpi_device *adev, |
696 | u32 system_state) | 725 | u32 system_state) |
697 | { | 726 | { |
698 | int power_state; | 727 | int ret, state; |
699 | 728 | ||
700 | if (!acpi_device_power_manageable(adev)) | 729 | if (!acpi_device_power_manageable(adev)) |
701 | return 0; | 730 | return 0; |
702 | 731 | ||
703 | power_state = acpi_device_power_state(dev, adev, system_state, | 732 | ret = acpi_dev_pm_get_state(dev, adev, system_state, NULL, &state); |
704 | ACPI_STATE_D3, NULL); | 733 | return ret ? ret : acpi_device_set_power(adev, state); |
705 | if (power_state < ACPI_STATE_D0 || power_state > ACPI_STATE_D3) | ||
706 | return -EIO; | ||
707 | |||
708 | return acpi_device_set_power(adev, power_state); | ||
709 | } | 734 | } |
710 | 735 | ||
711 | /** | 736 | /** |
diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c index eb133c77aadb..0461ccc92c54 100644 --- a/drivers/acpi/processor_idle.c +++ b/drivers/acpi/processor_idle.c | |||
@@ -214,13 +214,13 @@ static void lapic_timer_state_broadcast(struct acpi_processor *pr, | |||
214 | #ifdef CONFIG_PM_SLEEP | 214 | #ifdef CONFIG_PM_SLEEP |
215 | static u32 saved_bm_rld; | 215 | static u32 saved_bm_rld; |
216 | 216 | ||
217 | int acpi_processor_suspend(void) | 217 | static int acpi_processor_suspend(void) |
218 | { | 218 | { |
219 | acpi_read_bit_register(ACPI_BITREG_BUS_MASTER_RLD, &saved_bm_rld); | 219 | acpi_read_bit_register(ACPI_BITREG_BUS_MASTER_RLD, &saved_bm_rld); |
220 | return 0; | 220 | return 0; |
221 | } | 221 | } |
222 | 222 | ||
223 | void acpi_processor_resume(void) | 223 | static void acpi_processor_resume(void) |
224 | { | 224 | { |
225 | u32 resumed_bm_rld; | 225 | u32 resumed_bm_rld; |
226 | 226 | ||
diff --git a/drivers/acpi/sleep.c b/drivers/acpi/sleep.c index 9c1a435d10e6..187ab61889e6 100644 --- a/drivers/acpi/sleep.c +++ b/drivers/acpi/sleep.c | |||
@@ -494,6 +494,8 @@ static int acpi_suspend_enter(suspend_state_t pm_state) | |||
494 | break; | 494 | break; |
495 | 495 | ||
496 | case ACPI_STATE_S3: | 496 | case ACPI_STATE_S3: |
497 | if (!acpi_suspend_lowlevel) | ||
498 | return -ENOSYS; | ||
497 | error = acpi_suspend_lowlevel(); | 499 | error = acpi_suspend_lowlevel(); |
498 | if (error) | 500 | if (error) |
499 | return error; | 501 | return error; |