Skip to content

Commit 956ad9d

Browse files
committed
ACPI: PM: Avoid using power resources if there are none for D0
As recently reported, some platforms provide a list of power resources for device power state D3hot, through the _PR3 object, but they do not provide a list of power resources for device power state D0. Among other things, this causes acpi_device_get_power() to return D3hot as the current state of the device in question if all of the D3hot power resources are "on", because it sees the power_resources flag set and calls acpi_power_get_inferred_state() which finds that D3hot is the shallowest power state with all of the associated power resources turned "on", so that's what it returns. Moreover, that value takes precedence over the acpi_dev_pm_explicit_get() return value, because it means a deeper power state. The device may very well be in D0 physically at that point, however. Moreover, the presence of _PR3 without _PR0 for a given device means that only one D3-level power state can be supported by it. Namely, because there are no power resources to turn "off" when transitioning the device from D0 into D3cold (which should be supported since _PR3 is present), the evaluation of _PS3 should be sufficient to put it straight into D3cold, but this means that the effect of turning "on" the _PR3 power resources is unclear, so it is better to avoid doing that altogether. Consequently, there is no practical way do distinguish D3cold from D3hot for the device in question and the power states of it can be labeled so that D3hot is the deepest supported one (and Linux assumes that putting a device into D3hot via ACPI may cause power to be removed from it anyway, for legacy reasons). To work around the problem described above modify the ACPI enumeration of devices so that power resources are only used for device power management if the list of D0 power resources is not empty and make it mart D3cold as supported only if that is the case and the D3hot list of power resources is not empty too. Fixes: ef85bdb ("ACPI / scan: Consolidate extraction of power resources lists") Link: https://bugzilla.kernel.org/show_bug.cgi?id=205057 Link: https://lore.kernel.org/linux-acpi/[email protected]/ Reported-by: Hans de Goede <[email protected]> Tested-by: Hans de Goede <[email protected]> Tested-by: [email protected] Cc: 3.10+ <[email protected]> # 3.10+ Signed-off-by: Rafael J. Wysocki <[email protected]> Reviewed-by: Hans de Goede <[email protected]>
1 parent 5fcd735 commit 956ad9d

File tree

2 files changed

+20
-10
lines changed

2 files changed

+20
-10
lines changed

drivers/acpi/device_pm.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ int acpi_device_set_power(struct acpi_device *device, int state)
186186
* possibly drop references to the power resources in use.
187187
*/
188188
state = ACPI_STATE_D3_HOT;
189-
/* If _PR3 is not available, use D3hot as the target state. */
189+
/* If D3cold is not supported, use D3hot as the target state. */
190190
if (!device->power.states[ACPI_STATE_D3_COLD].flags.valid)
191191
target_state = state;
192192
} else if (!device->power.states[state].flags.valid) {

drivers/acpi/scan.c

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -919,12 +919,9 @@ static void acpi_bus_init_power_state(struct acpi_device *device, int state)
919919

920920
if (buffer.length && package
921921
&& package->type == ACPI_TYPE_PACKAGE
922-
&& package->package.count) {
923-
int err = acpi_extract_power_resources(package, 0,
924-
&ps->resources);
925-
if (!err)
926-
device->power.flags.power_resources = 1;
927-
}
922+
&& package->package.count)
923+
acpi_extract_power_resources(package, 0, &ps->resources);
924+
928925
ACPI_FREE(buffer.pointer);
929926
}
930927

@@ -971,14 +968,27 @@ static void acpi_bus_get_power_flags(struct acpi_device *device)
971968
acpi_bus_init_power_state(device, i);
972969

973970
INIT_LIST_HEAD(&device->power.states[ACPI_STATE_D3_COLD].resources);
974-
if (!list_empty(&device->power.states[ACPI_STATE_D3_HOT].resources))
975-
device->power.states[ACPI_STATE_D3_COLD].flags.valid = 1;
976971

977-
/* Set defaults for D0 and D3hot states (always valid) */
972+
/* Set the defaults for D0 and D3hot (always supported). */
978973
device->power.states[ACPI_STATE_D0].flags.valid = 1;
979974
device->power.states[ACPI_STATE_D0].power = 100;
980975
device->power.states[ACPI_STATE_D3_HOT].flags.valid = 1;
981976

977+
/*
978+
* Use power resources only if the D0 list of them is populated, because
979+
* some platforms may provide _PR3 only to indicate D3cold support and
980+
* in those cases the power resources list returned by it may be bogus.
981+
*/
982+
if (!list_empty(&device->power.states[ACPI_STATE_D0].resources)) {
983+
device->power.flags.power_resources = 1;
984+
/*
985+
* D3cold is supported if the D3hot list of power resources is
986+
* not empty.
987+
*/
988+
if (!list_empty(&device->power.states[ACPI_STATE_D3_HOT].resources))
989+
device->power.states[ACPI_STATE_D3_COLD].flags.valid = 1;
990+
}
991+
982992
if (acpi_bus_init_power(device))
983993
device->flags.power_manageable = 0;
984994
}

0 commit comments

Comments
 (0)