[PATCH] ACPI: PM: Use nearest power-manageable ancestor

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



When a device’s power_manageable flag is false, we currently only
fall back to the direct parent’s power state.  In a deep hierarchy
there may be a more distant ancestor that does support power
management.

Walk up the parent chain until we find the closest power_manageable
ancestor and use its power state.  If none is found, default to
ACPI_STATE_D0 (fully on).

Signed-off-by: Guan-Chun.Wu <409411716@xxxxxxxxxxxxxx>
---
 drivers/acpi/device_pm.c | 19 +++++++++++++++++--
 1 file changed, 17 insertions(+), 2 deletions(-)

diff --git a/drivers/acpi/device_pm.c b/drivers/acpi/device_pm.c
index dbd4446025ec..81b47fb00e80 100644
--- a/drivers/acpi/device_pm.c
+++ b/drivers/acpi/device_pm.c
@@ -84,8 +84,23 @@ int acpi_device_get_power(struct acpi_device *device, int *state)
 	parent = acpi_dev_parent(device);
 
 	if (!device->flags.power_manageable) {
-		/* TBD: Non-recursive algorithm for walking up hierarchy. */
-		*state = parent ? parent->power.state : ACPI_STATE_D0;
+		/*
+		 * If the device itself is not power-manageable,
+		 * walk up the parent hierarchy to find the closest
+		 * ancestor that is power-manageable.
+		 * Use that ancestor's power state as an estimate
+		 * for this device. If no such ancestor exists,
+		 * default to D0 (Fully On).
+		 */
+		struct acpi_device *ancestor = parent;
+		/*
+		 * Keep traversing up until a power-manageable ancestor
+		 * is found or the root is reached
+		 */
+		while (ancestor && !ancestor->flags.power_manageable)
+			ancestor = acpi_dev_parent(ancestor);
+		/* Use the found ancestor's power state, or D0 if none is found */
+		*state = ancestor ? ancestor->power.state : ACPI_STATE_D0;
 		goto out;
 	}
 
-- 
2.34.1





[Index of Archives]     [Linux IBM ACPI]     [Linux Power Management]     [Linux Kernel]     [Linux Laptop]     [Kernel Newbies]     [Share Photos]     [Security]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Video 4 Linux]     [Device Mapper]     [Linux Resources]
  Powered by Linux